Add more long options and improve usage()

This commit is contained in:
Kent Overstreet 2011-08-09 17:33:03 -07:00
parent e8c85bb806
commit 18e46dc1c3

View File

@ -20,8 +20,6 @@
#include "bcache.h" #include "bcache.h"
char zero[4096];
uint64_t getblocks(int fd) uint64_t getblocks(int fd)
{ {
uint64_t ret; uint64_t ret;
@ -63,19 +61,25 @@ uint64_t hatoi(const char *s)
void usage() void usage()
{ {
printf("Usage: make-bcache [options] device\n" printf("Usage: make-bcache [options] device\n"
" -C Format a cache device\n" " -C, --cache Format a cache device\n"
" -B Format a backing device\n" " -B, --bdev Format a backing device\n"
" -b bucket size\n" " -b, --bucket bucket size\n"
" -w block size (hard sector size of SSD, often 2k)\n" " -w, --block block size (hard sector size of SSD, often 2k)\n"
" -U UUID\n" " -U UUID\n"
" --writeback Enable writeback\n"); " --writeback enable writeback\n"
" -h, --help display this help and exit\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int writeback; int writeback;
struct option opts[2] = { struct option opts[7] = {
{ "writeback", 0, &writeback, 1 } { "cache", 0, NULL, 'C' },
{ "bdev", 0, NULL, 'B' },
{ "bucket", 1, NULL, 'b' },
{ "block", 1, NULL, 'w' },
{ "writeback", 0, &writeback, 0 },
{ "help", 0, NULL, 'h' },
}; };
void write_sb(char *dev, struct cache_sb *sb) void write_sb(char *dev, struct cache_sb *sb)
@ -167,7 +171,7 @@ int main(int argc, char **argv)
uuid_generate(sb.set_uuid); uuid_generate(sb.set_uuid);
while ((c = getopt_long(argc, argv, while ((c = getopt_long(argc, argv,
"-CBU:w:b:", "-hCBU:w:b:",
opts, NULL)) != -1) opts, NULL)) != -1)
switch (c) { switch (c) {
case 'C': case 'C':
@ -188,6 +192,9 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; break;
case 'h':
usage();
break;
case 1: case 1:
write_sb(optarg, &sb); write_sb(optarg, &sb);
written = true; written = true;
@ -196,7 +203,7 @@ int main(int argc, char **argv)
if (!written) { if (!written) {
printf("Please supply a device\n"); printf("Please supply a device\n");
exit(EXIT_FAILURE); usage();
} }
return 0; return 0;