1/*
2 * Copyright 2007-2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Copyright 2019, Les De Ridder, les@lesderid.net
4 *
5 * Distributed under the terms of the MIT License.
6 */
7
8#include "btrfs_disk_system.h"
9
10#include "btrfs.h"
11#include "Volume.h"
12
13
14status_t
15parse_initialize_parameters(const char* parameterString,
16	initialize_parameters& parameters)
17{
18	parameters.verbose = false;
19
20	void *handle = parse_driver_settings_string(parameterString);
21	if (handle == NULL)
22		return B_ERROR;
23
24	if (get_driver_boolean_parameter(handle, "verbose", false, true))
25		parameters.verbose = true;
26
27	const char *ss_string = get_driver_parameter(handle, "sector_size",
28		NULL, NULL);
29	uint32 sectorSize = B_PAGE_SIZE;
30	if (ss_string != NULL)
31		sectorSize = strtoul(ss_string, NULL, 0);
32
33	const char *bs_string = get_driver_parameter(handle, "block_size",
34		NULL, NULL);
35	uint32 blockSize = max_c(16384, B_PAGE_SIZE);
36	if (bs_string != NULL)
37		blockSize = strtoul(bs_string, NULL, 0);
38
39	// TODO(lesderid): accept more settings (allocation profiles, uuid, etc.)
40
41	delete_driver_settings(handle);
42
43	if ((blockSize != 1024 && blockSize != 2048 && blockSize != 4096
44		&& blockSize != 8192 && blockSize != 16384)
45		|| blockSize % sectorSize != 0) {
46		return B_BAD_VALUE;
47	}
48
49	parameters.sectorSize = sectorSize;
50	parameters.blockSize = blockSize;
51
52	return B_OK;
53}
54
55
56status_t
57check_volume_name(const char* name)
58{
59	if (name == NULL || strlen(name) >= BTRFS_LABEL_SIZE
60		|| strchr(name, '/') != NULL
61		|| strchr(name, '\\') != NULL) {
62		return B_BAD_VALUE;
63	}
64
65	return B_OK;
66}
67
68