bcachefs-tools/bcache.c

110 lines
3.0 KiB
C
Raw Normal View History

2016-03-12 09:18:42 +03:00
/*
* Authors: Kent Overstreet <kent.overstreet@gmail.com>
* Gabriel de Perthuis <g2p.code@gmail.com>
* Jacob Malevich <jam@datera.io>
*
* GPLv2
*/
2016-03-12 09:18:42 +03:00
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <limits.h>
2016-03-12 09:18:42 +03:00
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
2016-03-12 09:18:42 +03:00
#include <stdint.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
2017-02-02 06:16:42 +03:00
#include "cmds.h"
2016-08-24 06:50:31 +03:00
static void usage(void)
{
puts("bcache - tool for managing bcache volumes/filesystems\n"
"usage: bcache <command> [<args>]\n"
"\n"
2017-01-08 12:13:18 +03:00
"Commands for formatting, startup and shutdown:\n"
2016-08-24 06:50:31 +03:00
" format Format a new filesystem\n"
2016-10-04 06:22:17 +03:00
" unlock Unlock an encrypted filesystem prior to running/mounting\n"
2016-08-24 06:50:31 +03:00
" assemble Assemble an existing multi device filesystem\n"
" incremental Incrementally assemble an existing multi device filesystem\n"
" run Start a partially assembled filesystem\n"
" stop Stop a running filesystem\n"
"\n"
2017-01-08 12:13:18 +03:00
"Commands for managing a running filesystem:\n"
2016-08-24 06:50:31 +03:00
" fs_show Show various information about a filesystem\n"
" fs_set Modify filesystem options\n"
"\n"
2017-01-08 12:13:18 +03:00
"Commands for managing a specific device in a filesystem:\n"
2016-08-24 06:50:31 +03:00
" device_show Show information about a formatted device\n"
" device_add Add a device to an existing (running) filesystem\n"
2017-01-08 12:13:18 +03:00
" device_remove Remove a device from an existing (running) filesystem\n"
"\n"
"Repair:\n"
" bcache fsck Check an existing filesystem for errors\n"
2016-10-04 06:22:17 +03:00
"\n"
"Debug:\n"
" bcache dump Dump filesystem metadata to a qcow2 image\n"
" bcache list List filesystem metadata in textual form\n");
2016-03-12 09:18:42 +03:00
}
int main(int argc, char *argv[])
{
2016-08-24 06:50:31 +03:00
char *cmd;
2017-01-08 12:13:18 +03:00
setvbuf(stdout, NULL, _IOLBF, 0);
2016-08-24 06:50:31 +03:00
if (argc < 2) {
printf("%s: missing command\n", argv[0]);
2017-01-08 12:13:18 +03:00
usage();
exit(EXIT_FAILURE);
2016-08-24 06:50:31 +03:00
}
cmd = argv[1];
memmove(&argv[1], &argv[2], argc * sizeof(argv[0]));
argc--;
if (!strcmp(cmd, "format"))
return cmd_format(argc, argv);
if (!strcmp(cmd, "assemble"))
return cmd_assemble(argc, argv);
if (!strcmp(cmd, "incremental"))
return cmd_incremental(argc, argv);
if (!strcmp(cmd, "run"))
return cmd_run(argc, argv);
if (!strcmp(cmd, "stop"))
return cmd_stop(argc, argv);
if (!strcmp(cmd, "fs_show"))
return cmd_fs_show(argc, argv);
if (!strcmp(cmd, "fs_set"))
return cmd_fs_set(argc, argv);
if (!strcmp(cmd, "device_show"))
return cmd_device_show(argc, argv);
if (!strcmp(cmd, "device_add"))
return cmd_device_add(argc, argv);
if (!strcmp(cmd, "device_remove"))
return cmd_device_remove(argc, argv);
2017-01-08 12:13:18 +03:00
if (!strcmp(cmd, "fsck"))
return cmd_fsck(argc, argv);
2016-10-04 06:22:17 +03:00
if (!strcmp(cmd, "unlock"))
return cmd_unlock(argc, argv);
if (!strcmp(cmd, "dump"))
return cmd_dump(argc, argv);
if (!strcmp(cmd, "list"))
return cmd_list(argc, argv);
2016-08-24 06:50:31 +03:00
usage();
return 0;
}