2013-06-27 05:42:39 +04:00
|
|
|
/*
|
|
|
|
* Author: Gabriel de Perthuis <g2p.code@gmail.com>
|
|
|
|
*
|
|
|
|
* GPLv2
|
|
|
|
*/
|
|
|
|
|
2013-07-06 01:59:21 +04:00
|
|
|
|
2013-03-09 16:22:24 +04:00
|
|
|
#define _FILE_OFFSET_BITS 64
|
|
|
|
#define __USE_FILE_OFFSET64
|
|
|
|
#define _XOPEN_SOURCE 500
|
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
#include <ctype.h>
|
2013-03-09 16:22:24 +04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <uuid/uuid.h>
|
|
|
|
|
|
|
|
#include "bcache.h"
|
|
|
|
|
2014-09-26 05:34:24 +04:00
|
|
|
void usage()
|
2013-03-09 16:22:24 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: bcache-super-show [-f] <device>\n");
|
|
|
|
}
|
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int o;
|
|
|
|
extern char *optarg;
|
|
|
|
struct cache_sb sb_stack, *sb = &sb_stack;
|
|
|
|
size_t bytes = sizeof(*sb);
|
2014-09-26 05:34:24 +04:00
|
|
|
bool force_csum = false;
|
2014-08-26 06:11:59 +04:00
|
|
|
|
|
|
|
while ((o = getopt(argc, argv, "f")) != EOF)
|
|
|
|
switch (o) {
|
|
|
|
case 'f':
|
|
|
|
force_csum = 1;
|
2013-05-01 21:15:18 +04:00
|
|
|
break;
|
2014-08-26 06:11:59 +04:00
|
|
|
|
2013-05-01 21:15:18 +04:00
|
|
|
default:
|
2014-08-26 06:11:59 +04:00
|
|
|
usage();
|
|
|
|
exit(1);
|
2013-03-09 17:58:57 +04:00
|
|
|
}
|
2013-05-01 21:20:03 +04:00
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
argv += optind;
|
|
|
|
argc -= optind;
|
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
usage();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = open(argv[0], O_RDONLY);
|
|
|
|
if (fd < 0) {
|
|
|
|
printf("Can't open dev %s: %s\n", argv[0], strerror(errno));
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pread(fd, sb, bytes, SB_START) != bytes) {
|
|
|
|
fprintf(stderr, "Couldn't read\n");
|
|
|
|
exit(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sb->keys) {
|
|
|
|
bytes = sizeof(*sb) + sb->keys * sizeof(uint64_t);
|
|
|
|
sb = malloc(bytes);
|
|
|
|
|
|
|
|
if (pread(fd, sb, bytes, SB_START) != bytes) {
|
|
|
|
fprintf(stderr, "Couldn't read\n");
|
|
|
|
exit(2);
|
2013-05-01 21:20:03 +04:00
|
|
|
}
|
2013-03-09 18:51:17 +04:00
|
|
|
}
|
2013-03-09 16:22:24 +04:00
|
|
|
|
2014-08-26 06:11:59 +04:00
|
|
|
if (!SB_IS_BDEV(sb))
|
2014-09-26 05:34:24 +04:00
|
|
|
show_super_cache(sb, force_csum);
|
2014-08-26 06:11:59 +04:00
|
|
|
else
|
2014-09-26 05:34:24 +04:00
|
|
|
show_super_backingdev(sb, force_csum);
|
2013-03-09 16:22:24 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|