xref: /linux/tools/testing/selftests/ublk/metadata_size.c (revision 0c00ed308d0559fc216be0442a3df124e9e13533)
1 // SPDX-License-Identifier: GPL-2.0
2 #include <fcntl.h>
3 #include <linux/fs.h>
4 #include <stdio.h>
5 #include <sys/ioctl.h>
6 
7 int main(int argc, char **argv)
8 {
9 	struct logical_block_metadata_cap cap = {};
10 	const char *filename;
11 	int fd;
12 	int result;
13 
14 	if (argc != 2) {
15 		fprintf(stderr, "Usage: %s BLOCK_DEVICE\n", argv[0]);
16 		return 1;
17 	}
18 
19 	filename = argv[1];
20 	fd = open(filename, O_RDONLY);
21 	if (fd < 0) {
22 		perror(filename);
23 		return 1;
24 	}
25 
26 	result = ioctl(fd, FS_IOC_GETLBMD_CAP, &cap);
27 	if (result < 0) {
28 		perror("ioctl");
29 		return 1;
30 	}
31 
32 	printf("metadata_size: %u\n", cap.lbmd_size);
33 	printf("pi_offset: %u\n", cap.lbmd_pi_offset);
34 	printf("pi_tuple_size: %u\n", cap.lbmd_pi_size);
35 	return 0;
36 }
37