samples-vfs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SAMPLES_VFS_H
  3. #define __SAMPLES_VFS_H
  4. #include <errno.h>
  5. #include <linux/types.h>
  6. #include <sys/ioctl.h>
  7. #include <sys/syscall.h>
  8. #define die_errno(format, ...) \
  9. do { \
  10. fprintf(stderr, "%m | %s: %d: %s: " format "\n", __FILE__, \
  11. __LINE__, __func__, ##__VA_ARGS__); \
  12. exit(EXIT_FAILURE); \
  13. } while (0)
  14. struct statmount {
  15. __u32 size; /* Total size, including strings */
  16. __u32 mnt_opts; /* [str] Options (comma separated, escaped) */
  17. __u64 mask; /* What results were written */
  18. __u32 sb_dev_major; /* Device ID */
  19. __u32 sb_dev_minor;
  20. __u64 sb_magic; /* ..._SUPER_MAGIC */
  21. __u32 sb_flags; /* SB_{RDONLY,SYNCHRONOUS,DIRSYNC,LAZYTIME} */
  22. __u32 fs_type; /* [str] Filesystem type */
  23. __u64 mnt_id; /* Unique ID of mount */
  24. __u64 mnt_parent_id; /* Unique ID of parent (for root == mnt_id) */
  25. __u32 mnt_id_old; /* Reused IDs used in proc/.../mountinfo */
  26. __u32 mnt_parent_id_old;
  27. __u64 mnt_attr; /* MOUNT_ATTR_... */
  28. __u64 mnt_propagation; /* MS_{SHARED,SLAVE,PRIVATE,UNBINDABLE} */
  29. __u64 mnt_peer_group; /* ID of shared peer group */
  30. __u64 mnt_master; /* Mount receives propagation from this ID */
  31. __u64 propagate_from; /* Propagation from in current namespace */
  32. __u32 mnt_root; /* [str] Root of mount relative to root of fs */
  33. __u32 mnt_point; /* [str] Mountpoint relative to current root */
  34. __u64 mnt_ns_id; /* ID of the mount namespace */
  35. __u32 fs_subtype; /* [str] Subtype of fs_type (if any) */
  36. __u32 sb_source; /* [str] Source string of the mount */
  37. __u32 opt_num; /* Number of fs options */
  38. __u32 opt_array; /* [str] Array of nul terminated fs options */
  39. __u32 opt_sec_num; /* Number of security options */
  40. __u32 opt_sec_array; /* [str] Array of nul terminated security options */
  41. __u32 mnt_uidmap_num; /* Number of uid mappings */
  42. __u32 mnt_uidmap; /* [str] Array of uid mappings */
  43. __u32 mnt_gidmap_num; /* Number of gid mappings */
  44. __u32 mnt_gidmap; /* [str] Array of gid mappings */
  45. __u64 __spare2[44];
  46. char str[]; /* Variable size part containing strings */
  47. };
  48. struct mnt_id_req {
  49. __u32 size;
  50. __u32 spare;
  51. __u64 mnt_id;
  52. __u64 param;
  53. __u64 mnt_ns_id;
  54. };
  55. #ifndef MNT_ID_REQ_SIZE_VER0
  56. #define MNT_ID_REQ_SIZE_VER0 24 /* sizeof first published struct */
  57. #endif
  58. #ifndef MNT_ID_REQ_SIZE_VER1
  59. #define MNT_ID_REQ_SIZE_VER1 32 /* sizeof second published struct */
  60. #endif
  61. /* Get the id for a mount namespace */
  62. #ifndef NS_GET_MNTNS_ID
  63. #define NS_GET_MNTNS_ID _IO(0xb7, 0x5)
  64. #endif
  65. struct mnt_ns_info {
  66. __u32 size;
  67. __u32 nr_mounts;
  68. __u64 mnt_ns_id;
  69. };
  70. #ifndef MNT_NS_INFO_SIZE_VER0
  71. #define MNT_NS_INFO_SIZE_VER0 16 /* size of first published struct */
  72. #endif
  73. #ifndef NS_MNT_GET_INFO
  74. #define NS_MNT_GET_INFO _IOR(0xb7, 10, struct mnt_ns_info)
  75. #endif
  76. #ifndef NS_MNT_GET_NEXT
  77. #define NS_MNT_GET_NEXT _IOR(0xb7, 11, struct mnt_ns_info)
  78. #endif
  79. #ifndef NS_MNT_GET_PREV
  80. #define NS_MNT_GET_PREV _IOR(0xb7, 12, struct mnt_ns_info)
  81. #endif
  82. #ifndef PIDFD_GET_MNT_NAMESPACE
  83. #define PIDFD_GET_MNT_NAMESPACE _IO(0xFF, 3)
  84. #endif
  85. #ifndef __NR_listmount
  86. #define __NR_listmount 458
  87. #endif
  88. #ifndef __NR_statmount
  89. #define __NR_statmount 457
  90. #endif
  91. #ifndef LSMT_ROOT
  92. #define LSMT_ROOT 0xffffffffffffffff /* root mount */
  93. #endif
  94. /* @mask bits for statmount(2) */
  95. #ifndef STATMOUNT_SB_BASIC
  96. #define STATMOUNT_SB_BASIC 0x00000001U /* Want/got sb_... */
  97. #endif
  98. #ifndef STATMOUNT_MNT_BASIC
  99. #define STATMOUNT_MNT_BASIC 0x00000002U /* Want/got mnt_... */
  100. #endif
  101. #ifndef STATMOUNT_PROPAGATE_FROM
  102. #define STATMOUNT_PROPAGATE_FROM 0x00000004U /* Want/got propagate_from */
  103. #endif
  104. #ifndef STATMOUNT_MNT_ROOT
  105. #define STATMOUNT_MNT_ROOT 0x00000008U /* Want/got mnt_root */
  106. #endif
  107. #ifndef STATMOUNT_MNT_POINT
  108. #define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */
  109. #endif
  110. #ifndef STATMOUNT_FS_TYPE
  111. #define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */
  112. #endif
  113. #ifndef STATMOUNT_MNT_NS_ID
  114. #define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */
  115. #endif
  116. #ifndef STATMOUNT_MNT_OPTS
  117. #define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
  118. #endif
  119. #ifndef STATMOUNT_FS_SUBTYPE
  120. #define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */
  121. #endif
  122. #ifndef STATMOUNT_SB_SOURCE
  123. #define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */
  124. #endif
  125. #ifndef STATMOUNT_OPT_ARRAY
  126. #define STATMOUNT_OPT_ARRAY 0x00000400U /* Want/got opt_... */
  127. #endif
  128. #ifndef STATMOUNT_OPT_SEC_ARRAY
  129. #define STATMOUNT_OPT_SEC_ARRAY 0x00000800U /* Want/got opt_sec... */
  130. #endif
  131. #ifndef STATX_MNT_ID_UNIQUE
  132. #define STATX_MNT_ID_UNIQUE 0x00004000U /* Want/got extended stx_mount_id */
  133. #endif
  134. #ifndef STATMOUNT_MNT_UIDMAP
  135. #define STATMOUNT_MNT_UIDMAP 0x00002000U /* Want/got uidmap... */
  136. #endif
  137. #ifndef STATMOUNT_MNT_GIDMAP
  138. #define STATMOUNT_MNT_GIDMAP 0x00004000U /* Want/got gidmap... */
  139. #endif
  140. #ifndef MOUNT_ATTR_RDONLY
  141. #define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only */
  142. #endif
  143. #ifndef MOUNT_ATTR_NOSUID
  144. #define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits */
  145. #endif
  146. #ifndef MOUNT_ATTR_NODEV
  147. #define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files */
  148. #endif
  149. #ifndef MOUNT_ATTR_NOEXEC
  150. #define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution */
  151. #endif
  152. #ifndef MOUNT_ATTR__ATIME
  153. #define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated */
  154. #endif
  155. #ifndef MOUNT_ATTR_RELATIME
  156. #define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
  157. #endif
  158. #ifndef MOUNT_ATTR_NOATIME
  159. #define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
  160. #endif
  161. #ifndef MOUNT_ATTR_STRICTATIME
  162. #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
  163. #endif
  164. #ifndef MOUNT_ATTR_NODIRATIME
  165. #define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times */
  166. #endif
  167. #ifndef MOUNT_ATTR_IDMAP
  168. #define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
  169. #endif
  170. #ifndef MOUNT_ATTR_NOSYMFOLLOW
  171. #define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks */
  172. #endif
  173. #ifndef MS_RDONLY
  174. #define MS_RDONLY 1 /* Mount read-only */
  175. #endif
  176. #ifndef MS_SYNCHRONOUS
  177. #define MS_SYNCHRONOUS 16 /* Writes are synced at once */
  178. #endif
  179. #ifndef MS_MANDLOCK
  180. #define MS_MANDLOCK 64 /* Allow mandatory locks on an FS */
  181. #endif
  182. #ifndef MS_DIRSYNC
  183. #define MS_DIRSYNC 128 /* Directory modifications are synchronous */
  184. #endif
  185. #ifndef MS_UNBINDABLE
  186. #define MS_UNBINDABLE (1<<17) /* change to unbindable */
  187. #endif
  188. #ifndef MS_PRIVATE
  189. #define MS_PRIVATE (1<<18) /* change to private */
  190. #endif
  191. #ifndef MS_SLAVE
  192. #define MS_SLAVE (1<<19) /* change to slave */
  193. #endif
  194. #ifndef MS_SHARED
  195. #define MS_SHARED (1<<20) /* change to shared */
  196. #endif
  197. #ifndef MS_LAZYTIME
  198. #define MS_LAZYTIME (1<<25) /* Update the on-disk [acm]times lazily */
  199. #endif
  200. #endif /* __SAMPLES_VFS_H */