1 #define _FILE_OFFSET_BITS 64
2 #define __USE_FILE_OFFSET64
3 #define _XOPEN_SOURCE 500
14 #include <sys/ioctl.h>
15 #include <sys/types.h>
18 #include <uuid/uuid.h>
25 fprintf(stderr, "Usage: bcache-super-show [-f] <device>\n");
29 int main(int argc, char **argv)
31 bool force_csum = false;
36 uint64_t expected_csum;
38 while ((o = getopt(argc, argv, "f")) != EOF)
57 int fd = open(argv[0], O_RDONLY);
59 printf("Can't open dev %s: %s\n", argv[0], strerror(errno));
63 if (pread(fd, &sb, sizeof(sb), 4096) != sizeof(sb)) {
64 fprintf(stderr, "Couldn't read\n");
68 printf("sb.magic\t\t");
69 if (! memcmp(sb.magic, bcache_magic, 16)) {
72 printf("bad magic\n");
73 fprintf(stderr, "Invalid superblock (bad magic)\n");
77 printf("sb.first_sector\t\t%" PRIu64, sb.offset);
78 if (sb.offset == SB_SECTOR) {
81 printf(" [expected %ds]\n", SB_SECTOR);
82 fprintf(stderr, "Invalid superblock (bad sector)\n");
86 printf("sb.csum\t\t\t0x%" PRIx64, sb.csum);
87 expected_csum = csum_set(&sb);
88 if (sb.csum == expected_csum) {
91 printf(" [expected %" PRIX64 "]\n", expected_csum);
93 fprintf(stderr, "Corrupt superblock (bad csum)\n");
98 printf("sb.version\t\t%" PRIu64, sb.version);
101 printf(" [cache device]\n");
104 case CACHE_BACKING_DEV: // 1
105 printf(" [backing device]\n");
109 printf(" [backing device with offset]\n");
110 // XXX Kernel side bcache.h says different, and implements neither
114 printf(" [unknown]\n");
121 uuid_unparse(sb.uuid, uuid);
122 printf("dev.uuid\t\t%s\n", uuid);
125 "dev.sectors_per_block\t%u\n"
126 "dev.sectors_per_bucket\t%u\n"
127 "dev.bucket_count\t%ju\n"
128 "dev.cache_count\t\t%u\n", // expect version == 0 ? 1 : 0
134 if (sb.version == 0) {
136 "dev.cache.first_bucket\t%u\n"
137 "dev.cache.first_sector\t%u\n",
139 sb.bucket_size * sb.first_bucket);
140 } else if (sb.version == CACHE_BACKING_DEV) {
142 "dev.data.first_sector\t%u\n",
147 uuid_unparse(sb.set_uuid, uuid);
148 printf("cset.uuid\t\t%s\n", uuid);
150 printf("cset.cache_count\t%u\n\n", sb.nr_in_set);