diff --git a/Makefile b/Makefile index 62e0fb9d..a85a8076 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,19 @@ -#PREFIX=/usr/local +PREFIX=/usr CFLAGS=-O2 -Wall -g all: make-bcache probe-bcache -clean: - rm -f make-bcache bcache-test *.o - install: make-bcache probe-bcache install -m0755 make-bcache ${PREFIX}/sbin/ - install -m0755 probe-bcache ${PREFIX}/sbin/ + install -m0755 probe-bcache /sbin/ install -m0644 61-bcache.rules /lib/udev/rules.d/ install -m0755 initramfs /usr/share/initramfs-tools/hooks/bcache + install -m0644 make-bcache.8 ${PREFIX}/share/man/man8 # install -m0755 bcache-test ${PREFIX}/sbin/ +clean: + rm -f make-bcache bcache-test *.o bcache-test: LDFLAGS += -lm -lssl -lcrypto make-bcache: LDFLAGS += -luuid diff --git a/bcache.h b/bcache.h index 448b6a50..0054f7d8 100644 --- a/bcache.h +++ b/bcache.h @@ -7,8 +7,9 @@ static const char bcache_magic[] = { struct cache_sb { uint8_t magic[16]; -#define CACHE_CLEAN 1 -#define CACHE_SYNC 2 +#define CACHE_CLEAN 1 +#define CACHE_SYNC 2 +#define CACHE_BACKING_DEVICE 4 uint32_t version; uint16_t block_size; /* sectors */ uint16_t bucket_size; /* sectors */ diff --git a/make-bcache.c b/make-bcache.c index a7381d0a..9b9b0a17 100644 --- a/make-bcache.c +++ b/make-bcache.c @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -58,21 +59,32 @@ long hatoi(const char *s) void usage() { - printf(""); + printf("Usage: make-bcache [options] device\n" + " -C Format a cache device\n" + " -B Format a backing device\n" + " -b bucket size\n" + " -U UUID\n"); exit(EXIT_FAILURE); } int main(int argc, char **argv) { - int64_t nblocks, bucketsize = 32, blocksize = 8; + bool cache = false, backingdev = false; + int64_t nblocks, bucketsize = 0, blocksize = 8; int fd, i, c; struct cache_sb sb; char uuid[40]; uuid_generate(sb.uuid); - while ((c = getopt(argc, argv, "U:b:")) != -1) + while ((c = getopt(argc, argv, "CBU:b:")) != -1) switch (c) { + case 'C': + cache = true; + break; + case 'B': + backingdev = true; + break; case 'b': bucketsize = hatoi(optarg) / 512; break; @@ -84,6 +96,14 @@ int main(int argc, char **argv) break; } + if (!bucketsize) + bucketsize = cache ? 256 : 8192; + + if (cache == backingdev) { + printf("Must specify one of -C or -B\n"); + exit(EXIT_FAILURE); + } + if (argc <= optind) { printf("Please supply a device\n"); exit(EXIT_FAILURE); @@ -104,7 +124,7 @@ int main(int argc, char **argv) } memcpy(sb.magic, bcache_magic, 16); - sb.version = 0; + sb.version = backingdev ? CACHE_BACKING_DEVICE : 0; sb.block_size = blocksize; sb.bucket_size = bucketsize; sb.nbuckets = nblocks / sb.bucket_size;