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