mount.h 12 KB

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