fsmap.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /*
  3. * FS_IOC_GETFSMAP ioctl infrastructure.
  4. *
  5. * Copyright (C) 2017 Oracle. All Rights Reserved.
  6. *
  7. * Author: Darrick J. Wong <darrick.wong@oracle.com>
  8. */
  9. #ifndef _LINUX_FSMAP_H
  10. #define _LINUX_FSMAP_H
  11. #include <linux/types.h>
  12. /*
  13. * Structure for FS_IOC_GETFSMAP.
  14. *
  15. * The memory layout for this call are the scalar values defined in
  16. * struct fsmap_head, followed by two struct fsmap that describe
  17. * the lower and upper bound of mappings to return, followed by an
  18. * array of struct fsmap mappings.
  19. *
  20. * fmh_iflags control the output of the call, whereas fmh_oflags report
  21. * on the overall record output. fmh_count should be set to the
  22. * length of the fmh_recs array, and fmh_entries will be set to the
  23. * number of entries filled out during each call. If fmh_count is
  24. * zero, the number of reverse mappings will be returned in
  25. * fmh_entries, though no mappings will be returned. fmh_reserved
  26. * must be set to zero.
  27. *
  28. * The two elements in the fmh_keys array are used to constrain the
  29. * output. The first element in the array should represent the
  30. * lowest disk mapping ("low key") that the user wants to learn
  31. * about. If this value is all zeroes, the filesystem will return
  32. * the first entry it knows about. For a subsequent call, the
  33. * contents of fsmap_head.fmh_recs[fsmap_head.fmh_count - 1] should be
  34. * copied into fmh_keys[0] to have the kernel start where it left off.
  35. *
  36. * The second element in the fmh_keys array should represent the
  37. * highest disk mapping ("high key") that the user wants to learn
  38. * about. If this value is all ones, the filesystem will not stop
  39. * until it runs out of mapping to return or runs out of space in
  40. * fmh_recs.
  41. *
  42. * fmr_device can be either a 32-bit cookie representing a device, or
  43. * a 32-bit dev_t if the FMH_OF_DEV_T flag is set. fmr_physical,
  44. * fmr_offset, and fmr_length are expressed in units of bytes.
  45. * fmr_owner is either an inode number, or a special value if
  46. * FMR_OF_SPECIAL_OWNER is set in fmr_flags.
  47. */
  48. struct fsmap {
  49. __u32 fmr_device; /* device id */
  50. __u32 fmr_flags; /* mapping flags */
  51. __u64 fmr_physical; /* device offset of segment */
  52. __u64 fmr_owner; /* owner id */
  53. __u64 fmr_offset; /* file offset of segment */
  54. __u64 fmr_length; /* length of segment */
  55. __u64 fmr_reserved[3]; /* must be zero */
  56. };
  57. struct fsmap_head {
  58. __u32 fmh_iflags; /* control flags */
  59. __u32 fmh_oflags; /* output flags */
  60. __u32 fmh_count; /* # of entries in array incl. input */
  61. __u32 fmh_entries; /* # of entries filled in (output). */
  62. __u64 fmh_reserved[6]; /* must be zero */
  63. struct fsmap fmh_keys[2]; /* low and high keys for the mapping search */
  64. struct fsmap fmh_recs[]; /* returned records */
  65. };
  66. /* Size of an fsmap_head with room for nr records. */
  67. static inline size_t
  68. fsmap_sizeof(
  69. unsigned int nr)
  70. {
  71. return sizeof(struct fsmap_head) + nr * sizeof(struct fsmap);
  72. }
  73. /* Start the next fsmap query at the end of the current query results. */
  74. static inline void
  75. fsmap_advance(
  76. struct fsmap_head *head)
  77. {
  78. head->fmh_keys[0] = head->fmh_recs[head->fmh_entries - 1];
  79. }
  80. /* fmh_iflags values - set by FS_IOC_GETFSMAP caller in the header. */
  81. /* no flags defined yet */
  82. #define FMH_IF_VALID 0
  83. /* fmh_oflags values - returned in the header segment only. */
  84. #define FMH_OF_DEV_T 0x1 /* fmr_device values will be dev_t */
  85. /* fmr_flags values - returned for each non-header segment */
  86. #define FMR_OF_PREALLOC 0x1 /* segment = unwritten pre-allocation */
  87. #define FMR_OF_ATTR_FORK 0x2 /* segment = attribute fork */
  88. #define FMR_OF_EXTENT_MAP 0x4 /* segment = extent map */
  89. #define FMR_OF_SHARED 0x8 /* segment = shared with another file */
  90. #define FMR_OF_SPECIAL_OWNER 0x10 /* owner is a special value */
  91. #define FMR_OF_LAST 0x20 /* segment is the last in the dataset */
  92. /* Each FS gets to define its own special owner codes. */
  93. #define FMR_OWNER(type, code) (((__u64)type << 32) | \
  94. ((__u64)code & 0xFFFFFFFFULL))
  95. #define FMR_OWNER_TYPE(owner) ((__u32)((__u64)owner >> 32))
  96. #define FMR_OWNER_CODE(owner) ((__u32)(((__u64)owner & 0xFFFFFFFFULL)))
  97. #define FMR_OWN_FREE FMR_OWNER(0, 1) /* free space */
  98. #define FMR_OWN_UNKNOWN FMR_OWNER(0, 2) /* unknown owner */
  99. #define FMR_OWN_METADATA FMR_OWNER(0, 3) /* metadata */
  100. #define FS_IOC_GETFSMAP _IOWR('X', 59, struct fsmap_head)
  101. #endif /* _LINUX_FSMAP_H */