summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/ublk/metadata_size.c
blob: 76ecddf04d25ee6bbe301429c8b3124afe7fb4da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// SPDX-License-Identifier: GPL-2.0
#include <fcntl.h>
#include <linux/fs.h>
#include <stdio.h>
#include <sys/ioctl.h>

int main(int argc, char **argv)
{
	struct logical_block_metadata_cap cap = {};
	const char *filename;
	int fd;
	int result;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s BLOCK_DEVICE\n", argv[0]);
		return 1;
	}

	filename = argv[1];
	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		perror(filename);
		return 1;
	}

	result = ioctl(fd, FS_IOC_GETLBMD_CAP, &cap);
	if (result < 0) {
		perror("ioctl");
		return 1;
	}

	printf("metadata_size: %u\n", cap.lbmd_size);
	printf("pi_offset: %u\n", cap.lbmd_pi_offset);
	printf("pi_tuple_size: %u\n", cap.lbmd_pi_size);
	return 0;
}