mount.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* Header file for mounting/unmount Linux filesystems.
  2. Copyright (C) 1996-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /* This is taken from /usr/include/linux/fs.h. */
  16. #ifndef _SYS_MOUNT_H
  17. #define _SYS_MOUNT_H 1
  18. #include <fcntl.h>
  19. #include <features.h>
  20. #include <stdint.h>
  21. #include <stddef.h>
  22. #include <sys/ioctl.h>
  23. #ifdef __has_include
  24. # if __has_include ("linux/mount.h")
  25. # include "linux/mount.h"
  26. # endif
  27. #endif
  28. #define BLOCK_SIZE_BITS 10
  29. #define BLOCK_SIZE (1<<BLOCK_SIZE_BITS)
  30. /* These are the fs-independent mount-flags: up to 16 flags are
  31. supported */
  32. enum
  33. {
  34. #undef MS_RDONLY
  35. MS_RDONLY = 1, /* Mount read-only. */
  36. #define MS_RDONLY MS_RDONLY
  37. #undef MS_NOSUID
  38. MS_NOSUID = 2, /* Ignore suid and sgid bits. */
  39. #define MS_NOSUID MS_NOSUID
  40. #undef MS_NODEV
  41. MS_NODEV = 4, /* Disallow access to device special files. */
  42. #define MS_NODEV MS_NODEV
  43. #undef MS_NOEXEC
  44. MS_NOEXEC = 8, /* Disallow program execution. */
  45. #define MS_NOEXEC MS_NOEXEC
  46. #undef MS_SYNCHRONOUS
  47. MS_SYNCHRONOUS = 16, /* Writes are synced at once. */
  48. #define MS_SYNCHRONOUS MS_SYNCHRONOUS
  49. #undef MS_REMOUNT
  50. MS_REMOUNT = 32, /* Alter flags of a mounted FS. */
  51. #define MS_REMOUNT MS_REMOUNT
  52. #undef MS_MANDLOCK
  53. MS_MANDLOCK = 64, /* Allow mandatory locks on an FS. */
  54. #define MS_MANDLOCK MS_MANDLOCK
  55. #undef MS_DIRSYNC
  56. MS_DIRSYNC = 128, /* Directory modifications are synchronous. */
  57. #define MS_DIRSYNC MS_DIRSYNC
  58. #undef MS_NOSYMFOLLOW
  59. MS_NOSYMFOLLOW = 256, /* Do not follow symlinks. */
  60. #define MS_NOSYMFOLLOW MS_NOSYMFOLLOW
  61. #undef MS_NOATIME
  62. MS_NOATIME = 1024, /* Do not update access times. */
  63. #define MS_NOATIME MS_NOATIME
  64. #undef MS_NODIRATIME
  65. MS_NODIRATIME = 2048, /* Do not update directory access times. */
  66. #define MS_NODIRATIME MS_NODIRATIME
  67. #undef MS_BIND
  68. MS_BIND = 4096, /* Bind directory at different place. */
  69. #define MS_BIND MS_BIND
  70. #undef MS_MOVE
  71. MS_MOVE = 8192,
  72. #define MS_MOVE MS_MOVE
  73. #undef MS_REC
  74. MS_REC = 16384,
  75. #define MS_REC MS_REC
  76. #undef MS_SILENT
  77. MS_SILENT = 32768,
  78. #define MS_SILENT MS_SILENT
  79. #undef MS_POSIXACL
  80. MS_POSIXACL = 1 << 16, /* VFS does not apply the umask. */
  81. #define MS_POSIXACL MS_POSIXACL
  82. #undef MS_UNBINDABLE
  83. MS_UNBINDABLE = 1 << 17, /* Change to unbindable. */
  84. #define MS_UNBINDABLE MS_UNBINDABLE
  85. #undef MS_PRIVATE
  86. MS_PRIVATE = 1 << 18, /* Change to private. */
  87. #define MS_PRIVATE MS_PRIVATE
  88. #undef MS_SLAVE
  89. MS_SLAVE = 1 << 19, /* Change to slave. */
  90. #define MS_SLAVE MS_SLAVE
  91. #undef MS_SHARED
  92. MS_SHARED = 1 << 20, /* Change to shared. */
  93. #define MS_SHARED MS_SHARED
  94. #undef MS_RELATIME
  95. MS_RELATIME = 1 << 21, /* Update atime relative to mtime/ctime. */
  96. #define MS_RELATIME MS_RELATIME
  97. #undef MS_KERNMOUNT
  98. MS_KERNMOUNT = 1 << 22, /* This is a kern_mount call. */
  99. #define MS_KERNMOUNT MS_KERNMOUNT
  100. #undef MS_I_VERSION
  101. MS_I_VERSION = 1 << 23, /* Update inode I_version field. */
  102. #define MS_I_VERSION MS_I_VERSION
  103. #undef MS_STRICTATIME
  104. MS_STRICTATIME = 1 << 24, /* Always perform atime updates. */
  105. #define MS_STRICTATIME MS_STRICTATIME
  106. #undef MS_LAZYTIME
  107. MS_LAZYTIME = 1 << 25, /* Update the on-disk [acm]times lazily. */
  108. #define MS_LAZYTIME MS_LAZYTIME
  109. #undef MS_ACTIVE
  110. MS_ACTIVE = 1 << 30,
  111. #define MS_ACTIVE MS_ACTIVE
  112. #undef MS_NOUSER
  113. MS_NOUSER = 1U << 31
  114. #define MS_NOUSER MS_NOUSER
  115. };
  116. /* Flags that can be altered by MS_REMOUNT */
  117. #undef MS_RMT_MASK
  118. #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION \
  119. |MS_LAZYTIME)
  120. /* Magic mount flag number. Has to be or-ed to the flag values. */
  121. #undef MS_MGC_VAL
  122. #define MS_MGC_VAL 0xc0ed0000 /* Magic flag number to indicate "new" flags */
  123. #define MS_MGC_MSK 0xffff0000 /* Magic flag number mask */
  124. /* The read-only stuff doesn't really belong here, but any other place
  125. is probably as bad and I don't want to create yet another include
  126. file. */
  127. #undef BLKROSET
  128. #define BLKROSET _IO(0x12, 93) /* Set device read-only (0 = read-write). */
  129. #undef BLKROGET
  130. #define BLKROGET _IO(0x12, 94) /* Get read-only status (0 = read_write). */
  131. #undef BLKRRPART
  132. #define BLKRRPART _IO(0x12, 95) /* Re-read partition table. */
  133. #undef BLKGETSIZE
  134. #define BLKGETSIZE _IO(0x12, 96) /* Return device size. */
  135. #undef BLKFLSBUF
  136. #define BLKFLSBUF _IO(0x12, 97) /* Flush buffer cache. */
  137. #undef BLKRASET
  138. #define BLKRASET _IO(0x12, 98) /* Set read ahead for block device. */
  139. #undef BLKRAGET
  140. #define BLKRAGET _IO(0x12, 99) /* Get current read ahead setting. */
  141. #undef BLKFRASET
  142. #define BLKFRASET _IO(0x12,100) /* Set filesystem read-ahead. */
  143. #undef BLKFRAGET
  144. #define BLKFRAGET _IO(0x12,101) /* Get filesystem read-ahead. */
  145. #undef BLKSECTSET
  146. #define BLKSECTSET _IO(0x12,102) /* Set max sectors per request. */
  147. #undef BLKSECTGET
  148. #define BLKSECTGET _IO(0x12,103) /* Get max sectors per request. */
  149. #undef BLKSSZGET
  150. #define BLKSSZGET _IO(0x12,104) /* Get block device sector size. */
  151. #undef BLKBSZGET
  152. #define BLKBSZGET _IOR(0x12,112,size_t)
  153. #undef BLKBSZSET
  154. #define BLKBSZSET _IOW(0x12,113,size_t)
  155. #undef BLKGETSIZE64
  156. #define BLKGETSIZE64 _IOR(0x12,114,size_t) /* return device size. */
  157. /* Possible value for FLAGS parameter of `umount2'. */
  158. enum
  159. {
  160. MNT_FORCE = 1, /* Force unmounting. */
  161. #define MNT_FORCE MNT_FORCE
  162. MNT_DETACH = 2, /* Just detach from the tree. */
  163. #define MNT_DETACH MNT_DETACH
  164. MNT_EXPIRE = 4, /* Mark for expiry. */
  165. #define MNT_EXPIRE MNT_EXPIRE
  166. UMOUNT_NOFOLLOW = 8 /* Don't follow symlink on umount. */
  167. #define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
  168. };
  169. /* fsmount flags. */
  170. #define FSMOUNT_CLOEXEC 0x00000001
  171. /* mount attributes used on fsmount. */
  172. #define MOUNT_ATTR_RDONLY 0x00000001 /* Mount read-only. */
  173. #define MOUNT_ATTR_NOSUID 0x00000002 /* Ignore suid and sgid bits. */
  174. #define MOUNT_ATTR_NODEV 0x00000004 /* Disallow access to device special files. */
  175. #define MOUNT_ATTR_NOEXEC 0x00000008 /* Disallow program execution. */
  176. #define MOUNT_ATTR__ATIME 0x00000070 /* Setting on how atime should be updated. */
  177. #define MOUNT_ATTR_RELATIME 0x00000000 /* - Update atime relative to mtime/ctime. */
  178. #define MOUNT_ATTR_NOATIME 0x00000010 /* - Do not update access times. */
  179. #define MOUNT_ATTR_STRICTATIME 0x00000020 /* - Always perform atime updates */
  180. #define MOUNT_ATTR_NODIRATIME 0x00000080 /* Do not update directory access times. */
  181. #define MOUNT_ATTR_IDMAP 0x00100000 /* Idmap mount to @userns_fd in struct mount_attr. */
  182. #define MOUNT_ATTR_NOSYMFOLLOW 0x00200000 /* Do not follow symlinks. */
  183. #ifndef MOUNT_ATTR_SIZE_VER0
  184. /* For mount_setattr. */
  185. struct mount_attr
  186. {
  187. uint64_t attr_set;
  188. uint64_t attr_clr;
  189. uint64_t propagation;
  190. uint64_t userns_fd;
  191. };
  192. #endif
  193. #define MOUNT_ATTR_SIZE_VER0 32 /* sizeof first published struct */
  194. /* move_mount flags. */
  195. #define MOVE_MOUNT_F_SYMLINKS 0x00000001 /* Follow symlinks on from path */
  196. #define MOVE_MOUNT_F_AUTOMOUNTS 0x00000002 /* Follow automounts on from path */
  197. #define MOVE_MOUNT_F_EMPTY_PATH 0x00000004 /* Empty from path permitted */
  198. #define MOVE_MOUNT_T_SYMLINKS 0x00000010 /* Follow symlinks on to path */
  199. #define MOVE_MOUNT_T_AUTOMOUNTS 0x00000020 /* Follow automounts on to path */
  200. #define MOVE_MOUNT_T_EMPTY_PATH 0x00000040 /* Empty to path permitted */
  201. #define MOVE_MOUNT_SET_GROUP 0x00000100 /* Set sharing group instead */
  202. #define MOVE_MOUNT_BENEATH 0x00000200 /* Mount beneath top mount */
  203. /* fspick flags. */
  204. #define FSPICK_CLOEXEC 0x00000001
  205. #define FSPICK_SYMLINK_NOFOLLOW 0x00000002
  206. #define FSPICK_NO_AUTOMOUNT 0x00000004
  207. #define FSPICK_EMPTY_PATH 0x00000008
  208. #ifndef FSOPEN_CLOEXEC
  209. /* The type of fsconfig call made. */
  210. enum fsconfig_command
  211. {
  212. FSCONFIG_SET_FLAG = 0, /* Set parameter, supplying no value */
  213. # define FSCONFIG_SET_FLAG FSCONFIG_SET_FLAG
  214. FSCONFIG_SET_STRING = 1, /* Set parameter, supplying a string value */
  215. # define FSCONFIG_SET_STRING FSCONFIG_SET_STRING
  216. FSCONFIG_SET_BINARY = 2, /* Set parameter, supplying a binary blob value */
  217. # define FSCONFIG_SET_BINARY FSCONFIG_SET_BINARY
  218. FSCONFIG_SET_PATH = 3, /* Set parameter, supplying an object by path */
  219. # define FSCONFIG_SET_PATH FSCONFIG_SET_PATH
  220. FSCONFIG_SET_PATH_EMPTY = 4, /* Set parameter, supplying an object by (empty) path */
  221. # define FSCONFIG_SET_PATH_EMPTY FSCONFIG_SET_PATH_EMPTY
  222. FSCONFIG_SET_FD = 5, /* Set parameter, supplying an object by fd */
  223. # define FSCONFIG_SET_FD FSCONFIG_SET_FD
  224. FSCONFIG_CMD_CREATE = 6, /* Invoke superblock creation */
  225. # define FSCONFIG_CMD_CREATE FSCONFIG_CMD_CREATE
  226. FSCONFIG_CMD_RECONFIGURE = 7, /* Invoke superblock reconfiguration */
  227. # define FSCONFIG_CMD_RECONFIGURE FSCONFIG_CMD_RECONFIGURE
  228. FSCONFIG_CMD_CREATE_EXCL = 8, /* Create new superblock, fail if reusing existing superblock */
  229. # define FSCONFIG_CMD_CREATE_EXCL FSCONFIG_CMD_CREATE_EXCL
  230. };
  231. #endif
  232. /* fsopen flags. */
  233. #define FSOPEN_CLOEXEC 0x00000001
  234. /* open_tree flags. */
  235. #define OPEN_TREE_CLONE 1 /* Clone the target tree and attach the clone */
  236. #define OPEN_TREE_CLOEXEC O_CLOEXEC /* Close the file on execve() */
  237. __BEGIN_DECLS
  238. /* Mount a filesystem. */
  239. extern int mount (const char *__special_file, const char *__dir,
  240. const char *__fstype, unsigned long int __rwflag,
  241. const void *__data) __THROW;
  242. /* Unmount a filesystem. */
  243. extern int umount (const char *__special_file) __THROW;
  244. /* Unmount a filesystem. Force unmounting if FLAGS is set to MNT_FORCE. */
  245. extern int umount2 (const char *__special_file, int __flags) __THROW;
  246. /* Open the filesystem referenced by FS_NAME so it can be configured for
  247. mouting. */
  248. extern int fsopen (const char *__fs_name, unsigned int __flags) __THROW;
  249. /* Create a mount representation for the FD created by fsopen using
  250. FLAGS with ATTR_FLAGS describing how the mount is to be performed. */
  251. extern int fsmount (int __fd, unsigned int __flags,
  252. unsigned int __ms_flags) __THROW;
  253. /* Add the mounted FROM_DFD referenced by FROM_PATHNAME filesystem returned
  254. by fsmount in the hierarchy in the place TO_DFD reference by TO_PATHNAME
  255. using FLAGS. */
  256. extern int move_mount (int __from_dfd, const char *__from_pathname,
  257. int __to_dfd, const char *__to_pathname,
  258. unsigned int flags) __THROW;
  259. /* Set parameters and trigger CMD action on the FD context. KEY, VALUE,
  260. and AUX are used depending ng of the CMD. */
  261. extern int fsconfig (int __fd, unsigned int __cmd, const char *__key,
  262. const void *__value, int __aux) __THROW;
  263. /* Equivalent of fopen for an existing mount point. */
  264. extern int fspick (int __dfd, const char *__path, unsigned int __flags)
  265. __THROW;
  266. /* Open the mount point FILENAME in directory DFD using FLAGS. */
  267. extern int open_tree (int __dfd, const char *__filename, unsigned int __flags)
  268. __THROW;
  269. /* Change the mount properties of the mount or an entire mount tree. If
  270. PATH is a relative pathname, then it is interpreted relative to the
  271. directory referred to by the file descriptor dirfd. Otherwise if DFD is
  272. the special value AT_FDCWD then PATH is interpreted relative to the current
  273. working directory of the calling process. */
  274. extern int mount_setattr (int __dfd, const char *__path, unsigned int __flags,
  275. struct mount_attr *__uattr, size_t __usize)
  276. __THROW;
  277. __END_DECLS
  278. #endif /* _SYS_MOUNT_H */