metadata_size.c 698 B

123456789101112131415161718192021222324252627282930313233343536
  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. int main(int argc, char **argv)
  7. {
  8. struct logical_block_metadata_cap cap = {};
  9. const char *filename;
  10. int fd;
  11. int result;
  12. if (argc != 2) {
  13. fprintf(stderr, "Usage: %s BLOCK_DEVICE\n", argv[0]);
  14. return 1;
  15. }
  16. filename = argv[1];
  17. fd = open(filename, O_RDONLY);
  18. if (fd < 0) {
  19. perror(filename);
  20. return 1;
  21. }
  22. result = ioctl(fd, FS_IOC_GETLBMD_CAP, &cap);
  23. if (result < 0) {
  24. perror("ioctl");
  25. return 1;
  26. }
  27. printf("metadata_size: %u\n", cap.lbmd_size);
  28. printf("pi_offset: %u\n", cap.lbmd_pi_offset);
  29. printf("pi_tuple_size: %u\n", cap.lbmd_pi_size);
  30. return 0;
  31. }