* Moved helper function to check initialization parameters to separate

source file. Added function to check the volume name.
* Removed bfs_validate_initialize(). This functionality is to be implemented
  in a userland add-on.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22871 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2007-11-10 17:33:47 +00:00
parent 117c680d90
commit 57225f0367
5 changed files with 89 additions and 69 deletions

View File

@ -28,6 +28,7 @@ UsePrivateHeaders [ FDirName kernel disk_device_manager ] ;
UsePrivateHeaders [ FDirName storage ] ;
KernelAddon bfs :
bfs_disk_system.cpp
BlockAllocator.cpp
BPlusTree.cpp
kernel_cpp.cpp

View File

@ -0,0 +1,57 @@
/*
* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#include "bfs_disk_system.h"
#include "bfs.h"
#include "Volume.h"
status_t
parse_initialize_parameters(const char* parameterString,
initialize_parameters& parameters)
{
parameters.flags = 0;
parameters.verbose = false;
void *handle = parse_driver_settings_string(parameterString);
if (handle == NULL)
return B_ERROR;
if (get_driver_boolean_parameter(handle, "noindex", false, true))
parameters.flags |= VOLUME_NO_INDICES;
if (get_driver_boolean_parameter(handle, "verbose", false, true))
parameters.verbose = true;
const char *string = get_driver_parameter(handle, "block_size",
NULL, NULL);
uint32 blockSize = 1024;
if (string != NULL)
blockSize = strtoul(string, NULL, 0);
delete_driver_settings(handle);
if (blockSize != 1024 && blockSize != 2048 && blockSize != 4096
&& blockSize != 8192) {
return B_BAD_VALUE;
}
parameters.blockSize = blockSize;
return B_OK;
}
status_t
check_volume_name(const char* name)
{
if (name == NULL || strlen(name) >= BFS_DISK_NAME_LENGTH
|| strchr(name, '/') != NULL) {
return B_BAD_VALUE;
}
return B_OK;
}

View File

@ -0,0 +1,22 @@
/*
* Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de.
* Distributed under the terms of the MIT License.
*/
#ifndef _BFS_DISK_SYSTEM_H
#define _BFS_DISK_SYSTEM_H
#include "system_dependencies.h"
struct initialize_parameters {
uint32 blockSize;
uint32 flags;
bool verbose;
};
status_t parse_initialize_parameters(const char* parameterString,
initialize_parameters& parameters);
status_t check_volume_name(const char* name);
#endif // _BFS_DISK_SYSTEM_H

View File

@ -14,6 +14,7 @@
#include "Query.h"
#include "Attribute.h"
#include "bfs_control.h"
#include "bfs_disk_system.h"
#define BFS_IO_SIZE 65536
@ -2014,49 +2015,6 @@ bfs_rewind_query(void */*fs*/, void *cookie)
// #pragma mark -
struct initialize_parameters {
uint32 blockSize;
uint32 flags;
bool verbose;
};
static status_t
parse_initialize_parameters(const char* parameterString,
initialize_parameters& parameters)
{
parameters.flags = 0;
parameters.verbose = false;
void *handle = parse_driver_settings_string(parameterString);
if (handle == NULL)
return B_ERROR;
if (get_driver_boolean_parameter(handle, "noindex", false, true))
parameters.flags |= VOLUME_NO_INDICES;
if (get_driver_boolean_parameter(handle, "verbose", false, true))
parameters.verbose = true;
const char *string = get_driver_parameter(handle, "block_size",
NULL, NULL);
uint32 blockSize = 1024;
if (string != NULL)
blockSize = strtoul(string, NULL, 0);
delete_driver_settings(handle);
if (blockSize != 1024 && blockSize != 2048 && blockSize != 4096
&& blockSize != 8192) {
INFORM(("valid block sizes are: 1024, 2048, 4096, and 8192\n"));
return B_BAD_VALUE;
}
parameters.blockSize = blockSize;
return B_OK;
}
static uint32
bfs_get_supported_operations(partition_data* partition, uint32 mask)
{
@ -2066,37 +2024,18 @@ bfs_get_supported_operations(partition_data* partition, uint32 mask)
}
static bool
bfs_validate_initialize(partition_data *partition, char *name,
const char *parameterString)
{
if (name == NULL)
return B_BAD_VALUE;
// truncate the name, if it is too long
size_t nameLen = strlen(name);
if (nameLen >= BFS_DISK_NAME_LENGTH) {
nameLen = BFS_DISK_NAME_LENGTH - 1;
name[nameLen] = '\0';
}
// replace '/' by '-'
while ((name = strchr(name, '/')) != NULL)
*name = '-';
// parse parameters
initialize_parameters parameters;
return (parse_initialize_parameters(parameterString, parameters) == B_OK);
}
static status_t
bfs_initialize(int fd, partition_id partitionID, const char *name,
const char *parameterString, off_t /*partitionSize*/, disk_job_id job)
{
// check name
status_t status = check_volume_name(name);
if (status != B_OK)
return status;
// parse parameters
initialize_parameters parameters;
status_t status = parse_initialize_parameters(parameterString, parameters);
status = parse_initialize_parameters(parameterString, parameters);
if (status != B_OK)
return status;
@ -2296,7 +2235,7 @@ static file_system_module_info sBeFileSystem = {
NULL, // validate_move
NULL, // validate_set_content_name
NULL, // validate_set_content_parameters
&bfs_validate_initialize,
NULL, // validate_initialize,
/* shadow partition modification */
NULL, // shadow_changed

View File

@ -28,6 +28,7 @@ UsePrivateHeaders fs_shell ;
BuildPlatformMain <build>bfs_shell
:
bfs_disk_system.cpp
BlockAllocator.cpp
BPlusTree.cpp
Attribute.cpp