You can now specify all important options on the command line.
Now does a sync() after the changes. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6382 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -11,27 +11,104 @@
|
|||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
usage(char *programName)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "usage: %s [-vn] [-b block-size] device-path volume-name\n"
|
||||||
|
"Creates a new BFS file system on the specified device (or image)\n"
|
||||||
|
"\t-b\tblock size (defaults to 1024)\n"
|
||||||
|
"\t-n\tdisable indices (long option --noindex)\n"
|
||||||
|
"\t-v\tfor verbose output.\n",
|
||||||
|
programName);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
char *deviceName = "/boot/home/test-device";
|
char *programName = argv[0];
|
||||||
uint32 blockSize = 1024;
|
if (strrchr(programName, '/'))
|
||||||
|
programName = strrchr(programName, '/') + 1;
|
||||||
|
|
||||||
// ToDo: evaluate arguments!
|
if (argc < 2)
|
||||||
|
usage(programName);
|
||||||
|
|
||||||
|
uint32 blockSize = 1024;
|
||||||
|
uint32 flags = 0;
|
||||||
|
bool verbose = false;
|
||||||
|
|
||||||
|
while (*++argv) {
|
||||||
|
char *arg = *argv;
|
||||||
|
if (*arg == '-') {
|
||||||
|
if (arg[1] == '-') {
|
||||||
|
if (!strcmp(arg, "--noindex"))
|
||||||
|
flags |= VOLUME_NO_INDICES;
|
||||||
|
else
|
||||||
|
usage(programName);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (*++arg && isalpha(*arg)) {
|
||||||
|
switch (*arg) {
|
||||||
|
case 'v':
|
||||||
|
verbose = true;
|
||||||
|
break;
|
||||||
|
case 'b':
|
||||||
|
if (*++argv == NULL || !isdigit(**argv))
|
||||||
|
usage(programName);
|
||||||
|
|
||||||
|
blockSize = atol(*argv);
|
||||||
|
break;
|
||||||
|
case 'n':
|
||||||
|
flags |= VOLUME_NO_INDICES;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *deviceName = argv[0];
|
||||||
|
if (deviceName == NULL) {
|
||||||
|
fprintf(stderr, "%s: You must at least specify a device where "
|
||||||
|
"the image is going to be created\n", programName);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *volumeName = "Unnamed";
|
||||||
|
if (argv[1] != NULL)
|
||||||
|
volumeName = argv[1];
|
||||||
|
|
||||||
|
if (blockSize != 1024 && blockSize != 2048 && blockSize != 4096 && blockSize != 8192) {
|
||||||
|
fprintf(stderr, "%s: valid block sizes are: 1024, 2048, 4096, and 8192\n", programName);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// set up tiny VFS and initialize the device/image
|
||||||
|
|
||||||
init_block_cache(4096, 0);
|
init_block_cache(4096, 0);
|
||||||
init_vnode_layer();
|
init_vnode_layer();
|
||||||
|
|
||||||
Volume volume(1);
|
Volume volume(1);
|
||||||
status_t status = volume.Initialize(deviceName, "New Disk", blockSize, 0);
|
status_t status = volume.Initialize(deviceName, volumeName, blockSize, flags);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
fprintf(stderr, "Initializing volume failed: %s\n", strerror(status));
|
fprintf(stderr, "%s: Initializing volume failed: %s\n", programName, strerror(status));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (verbose) {
|
||||||
|
// ToDo: dump disk info
|
||||||
|
}
|
||||||
|
|
||||||
shutdown_block_cache();
|
shutdown_block_cache();
|
||||||
|
sync();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user