]> git.sesse.net Git - bcachefs-tools-debian/blob - bcache-super-show.c
Add multiple bucket_sizes to make-bcache
[bcachefs-tools-debian] / bcache-super-show.c
1 /*
2  * Author: Gabriel de Perthuis <g2p.code@gmail.com>
3  *
4  * GPLv2
5  */
6
7
8 #define _FILE_OFFSET_BITS       64
9 #define __USE_FILE_OFFSET64
10 #define _XOPEN_SOURCE 500
11
12 #include <ctype.h>
13 #include <errno.h>
14 #include <fcntl.h>
15 #include <inttypes.h>
16 #include <linux/fs.h>
17 #include <stdbool.h>
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <sys/ioctl.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <uuid/uuid.h>
27
28 #include "bcache.h"
29
30 void usage()
31 {
32         fprintf(stderr, "Usage: bcache-super-show [-f] <device>\n");
33 }
34
35 int main(int argc, char **argv)
36 {
37         int o;
38         extern char *optarg;
39         struct cache_sb sb_stack, *sb = &sb_stack;
40         size_t bytes = sizeof(*sb);
41         bool force_csum = false;
42
43         while ((o = getopt(argc, argv, "f")) != EOF)
44                 switch (o) {
45                         case 'f':
46                                 force_csum = 1;
47                                 break;
48
49                         default:
50                                 usage();
51                                 exit(1);
52                 }
53
54         argv += optind;
55         argc -= optind;
56
57         if (argc != 1) {
58                 usage();
59                 exit(1);
60         }
61
62         int fd = open(argv[0], O_RDONLY);
63         if (fd < 0) {
64                 printf("Can't open dev %s: %s\n", argv[0], strerror(errno));
65                 exit(2);
66         }
67
68         if (pread(fd, sb, bytes, SB_START) != bytes) {
69                 fprintf(stderr, "Couldn't read\n");
70                 exit(2);
71         }
72
73         if (sb->keys) {
74                 bytes = sizeof(*sb) + sb->keys * sizeof(uint64_t);
75                 sb = malloc(bytes);
76
77                 if (pread(fd, sb, bytes, SB_START) != bytes) {
78                         fprintf(stderr, "Couldn't read\n");
79                         exit(2);
80                 }
81         }
82
83         if (!SB_IS_BDEV(sb))
84                 show_super_cache(sb, force_csum);
85         else
86                 show_super_backingdev(sb, force_csum);
87
88         return 0;
89 }