summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2010-12-16 01:22:45 -0800
committerKent Overstreet <kent.overstreet@gmail.com>2010-12-16 01:22:45 -0800
commit04a54144fd304cfd8b4d54c72bdfa076b18d57b2 (patch)
treea27437b884ba7e8188255ba9b02f1fa71e4a7541
parent7e9790107563dfa88ccd89aa0d0fa33266848400 (diff)
Documentation
-rw-r--r--Makefile10
-rw-r--r--bcache.h5
-rw-r--r--make-bcache.c28
3 files changed, 32 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 62e0fb9..a85a807 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 448b6a5..0054f7d 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 a7381d0..9b9b0a1 100644
--- a/make-bcache.c
+++ b/make-bcache.c
@@ -4,6 +4,7 @@
#include <fcntl.h>
#include <linux/fs.h>
+#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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;