statmount(2)
๐ statmount(2) โ System Calls Manual ๐
okay bestie, buckle UP, because today we're learning about statmount โ the syscall that's basically a glow-up for reading mount info. no cap, it's giving "I know exactly what's mounted and where" energy. ๐๏ธโจ
โจ NAME โจ
statmount โ get a mount status ๐ซถ
๐ LIBRARY ๐
Standard C library (libc, -lc)
๐ SYNOPSIS ๐
#include <linux/mount.h> /* Definition of STATMOUNT_* constants */
#include <unistd.h>
int syscall(SYS_statmount, struct mnt_id_req *req,
struct statmount *smbuf, size_t bufsize,
unsigned int flags);
#include <linux/mount.h>
struct mnt_id_req {
__u32 size; /* sizeof(struct mnt_id_req) */
union {
__u32 mnt_ns_fd; /* fd of mnt_ns to query the mnt_id in */
__u32 mnt_fd; /* fd on the mount being queried */
};
__u64 mnt_id; /* The mnt_id being queried */
__u64 param; /* ORed combination of the STATMOUNT_ constants */
__u32 mnt_ns_id; /* The id of mnt_ns to query the mnt_id in */
};
struct statmount {
__u32 size;
__u32 mnt_opts;
__u64 mask;
__u32 sb_dev_major;
__u32 sb_dev_minor;
__u64 sb_magic;
__u32 sb_flags;
__u32 fs_type;
__u64 mnt_id;
__u64 mnt_parent_id;
__u32 mnt_id_old;
__u32 mnt_parent_id_old;
__u64 mnt_attr;
__u64 mnt_propagation;
__u64 mnt_peer_group;
__u64 mnt_master;
__u64 propagate_from;
__u32 mnt_root;
__u32 mnt_point;
__u64 mnt_ns_id;
__u32 fs_subtype;
__u32 sb_source;
__u32 opt_num;
__u32 opt_array;
__u32 opt_sec_num;
__u32 opt_sec_array;
__u32 mnt_uidmap_num;
__u32 mnt_uidmap;
__u32 mnt_gidmap_num;
__u32 mnt_gidmap;
__u64 supported_mask;
char str[];
};
๐ Note:glibcprovides no wrapper forstatmount(), so you're gonna have to go throughsyscall(2). yes, manually. it's fine. it's iconic. ๐
๐ธ DESCRIPTION ๐ธ
So, to peek at a mount's status, the caller needs CAP_SYS_ADMIN in the user namespace. and if you're tryna reach a mount in a foreign mount namespace (the one you specify via req.mnt_ns_id or req.mnt_ns_fd), that foreign mount namespace should be a child of the current namespace. family tree rules, bestie. ๐ณ
This function returns info about a mount, dropping it into the buffer pointed to by smbuf. What you get back is a struct statmount that's of size bufsize, with the fields filled in like we describe below. and flags? it must either be 0 or STATMOUNT_BY_FD. no third option, fr fr.
๐ซง (Note that reserved space and padding is omitted.)
๐ฆ The mnt_id_req structure ๐ฆ
req.sizeโ the kernel uses this to figure out whichstruct mnt_id_reqyou're actually passing in, so it should always be set tosizeof(struct mnt_id_req). don't skip it, it's the vibe check. ๐คreq.mnt_ns_fdโ you can get this from thePIDFD_GET_MNT_NAMESPACEioctl(2)operation, or by opening a file descriptor to/proc/pid/ns/mnt. it's used to specify a foreign mount namespace in which to queryreq.mnt_id(since Linux 6.18). โจreq.mnt_fdโ a file descriptor on a mount. if theSTATMOUNT_BY_FDflag is specified andreq.mnt_idandreq.mnt_ns_idare zeroed, the function returns information about the mount that the file descriptor is on (since Linux 7.0). ๐
The fd can also be on a mount that has been lazily unmounted (peep umount2(2) with MNT_DETACH). In that case, STATMOUNT_MNT_POINT and STATMOUNT_MNT_NS_ID will be unset, since an unmounted mount is no longer a part of the filesystem. it's giving ghosted. ๐ป
req.mnt_idโ you can get this from eitherstatx(2)usingSTATX_MNT_ID_UNIQUE, or fromlistmount(2). it's used as the identifier to query the status of the mount point you want. ๐ฏreq.paramโ tells the kernel which fields you're interested in. it's an ORed combination of the following constants:
STATMOUNT_SB_BASIC /* Want/got sb_* */
STATMOUNT_MNT_BASIC /* Want/got mnt_* */
STATMOUNT_PROPAGATE_FROM /* Want/got propagate_from */
STATMOUNT_MNT_ROOT /* Want/got mnt_root */
STATMOUNT_MNT_POINT /* Want/got mnt_point */
STATMOUNT_FS_TYPE /* Want/got fs_type */
STATMOUNT_MNT_NS_ID /* Want/got mnt_ns_id */
STATMOUNT_MNT_OPTS /* Want/got mnt_opts */
STATMOUNT_FS_SUBTYPE /* Want/got fs_subtype */
STATMOUNT_SB_SOURCE /* Want/got sb_source */
STATMOUNT_OPT_ARRAY /* Want/got opt_{num,array} */
STATMOUNT_OPT_SEC_ARRAY /* Want/got opt_sec_{num,array} */
STATMOUNT_MNT_UIDMAP /* Want/got uidmap{_num,} */
STATMOUNT_MNT_GIDMAP /* Want/got gidmap{_num,} */
STATMOUNT_SUPPORTED_MASK /* Want/got supported mask flags */
Generally speaking, the kernel does not reject values in req.param other than the ones above. (for the exception, see EINVAL in errors.) Instead, it just tells you which values are supported by this kernel and filesystem via the statmount.mask field. So likeโฆ do NOT just set req.param to UINT_MAX (all bits set), because one or more of those bits might, in the future, be used to specify an extension to the buffer. that's a trap, bestie, do not fall in it. ๐
req.mnt_ns_idโ you can get this from theNS_GET_MNTNS_IDioctl(2)operation. it's used to specify a foreign mount namespace in which to queryreq.mnt_id(since Linux 6.11). ๐
๐ The returned information ๐
The status info for the target mount comes back in the statmount structure pointed to by smbuf. The fields go a little something like this:
smbuf.sizeโ the size of the returnedsmbufstructure, including any of the strings fields that were filled. ๐smbuf.mnt_opts(since Linux 6.11) โ the offset to the location in thesmbuf.strbuffer that contains a comma separated list of mount options, similiar to those inproc_pid_mountinfo(5). it's a null-terminated string. ๐งพsmbuf.maskโ the ORed combination ofSTATMOUNT_*flags indicating which fields were filled in and are therefore valid. The kernel may return fields that weren't requested, and may fail to return fields that were requested, depending on what the backing file system and kernel supports. either way,req.paramwill not be equal tomask. keep that in mind, it's a whole thing. ๐ญsmbuf.sb_dev_majorsmbuf.sb_dev_minorโ the device that is mounted at this mount point. ๐พsmbuf.sb_magicโ the file system specific super block magic. ๐ฎsmbuf.sb_flagsโ the flags that are set on the super block, an ORed combination ofSB_RDONLY,SB_SYNCHRONOUS,SB_DIRSYNC,SB_LAZYTIME. ๐ฉsmbuf.fs_typeโ the offset to the location in thesmbuf.strbuffer that contains the string representation of the mounted file system. it's a null-terminated string. ๐smbuf.mnt_idโ the unique mount ID of the mount. ๐smbuf.mnt_parent_idโ the unique mount ID of the parent mount point of this mount. if this is the root mount point thensmbuf.mnt_id == smbuf.parent_mount_id. ๐งฌsmbuf.mnt_id_oldโ this corresponds to the mount ID that is exported by/proc/pid/mountinfo. ๐smbuf.mnt_parent_id_oldโ this corresponds to the parent mount ID that is exported by/proc/pid/mountinfo. ๐smbuf.mnt_attrโ theMOUNT_ATTR_*flags set on this mount point. ๐ท๏ธsmbuf.mnt_propagationโ the mount propagation flags, which can be one ofMS_SHARED,MS_SLAVE,MS_PRIVATE,MS_UNBINDABLE. ๐กsmbuf.mnt_peer_groupโ the ID of the shared peer group. ๐ฏsmbuf.mnt_masterโ the mount point receives its propagation from this mount ID. ๐smbuf.propagate_fromโ the ID from the namespace we propagated from. ๐smbuf.mnt_rootโ the offset to the location in thesmbuf.strbuffer that contains the string representation of the mount relative to the root of the file system. it's a null-terminated string. ๐ฑsmbuf.mnt_pointโ the offset to the location in thesmbuf.strbuffer that contains the string representation of the mount relative to the current root (ie if you are in achroot). it's a null-terminated string. ๐smbuf.mnt_ns_id(since Linux 6.11) โ the unique ID of the mount namespace the mount belongs to. ๐smbuf.fs_subtype(since Linux 6.13) โ the offset to the location in thesmbuf.strbuffer that contains the string representation of the file system subtype. this is particularly useful for disambiguating FUSE mounts. it's a null-terminated string. ๐smbuf.sb_source(since Linux 6.13) โ the offset to the location in thesmbuf.strthat contains the source of the mount. it's a null-terminated string. ๐smbuf.opt_num(since Linux 6.13) โ the number of filesystem options set on the mount. ๐ขsmbuf.opt_array(since Linux 6.13) โ the offset to the location in thesmbuf.strbuffer that contains file system options separated by null bytes. they can be iterated over with the help ofsmbuf.opt_num. ๐smbuf.opt_sec_num(since Linux 6.13) โ the number of security options set on the mount. ๐smbuf.opt_sec_array(since Linux 6.13) โ the offset to the location in thesmbuf.strbuffer that contains security options separated by null bytes. they can be iterated over with the help ofsmbuf.opt_sec_num. ๐smbuf.mnt_uidmap_num(since Linux 6.15) โ the number of uid mappings applied on the mount. ifsmbuf.maskhasSTATMOUNT_MNT_UIDMAPset and this field is0, then uid mappings applied on the mount cannot be resolved in the user namespace of the caller. ๐ซฅsmbuf.mnt_uidmap(since Linux 6.15) โ the offset to the location in thesmbuf.strbuffer that contains uid mappings as consecutive null-terminated strings. they can be iterated over with the help ofsmbuf.mnt_uidmap_num. the whole range of uid mappings must be resolvable in the user namespace of the caller. โ ๏ธsmbuf.mnt_gidmap_num(since Linux 6.15) โ the number of gid mappings applied on the mount. ifsmbuf.maskhasSTATMOUNT_MNT_GIDMAPset and this field is0, then gid mappings applied on the mount cannot be resolved in the user namespace of the caller. ๐ซฅsmbuf.mnt_gidmap(since Linux 6.15) โ the offset to the location in thesmbuf.strbuffer that contains gid mappings as consecutive null-terminated strings. they can be iterated over with the help ofsmbuf.mnt_gidmap_num. the whole range of gid mappings must be resolvable in the user namespace of the caller. โ ๏ธsmbuf.supported_mask(since Linux 6.15) โ the ORed combination ofSTATMOUNT_*flags supported by the current kernel. โจ
๐ RETURN VALUE ๐
On success, zero is returned. ๐ On error, -1 is returned, and errno is set to indicate the error. ๐
๐ฅ ERRORS ๐ฅ
okay bestie, here's the vibe check for when things go sideways. every one of these is <errno>-core, and they all come at you via the usual return-value situation (you know the one โ that's the previous section's whole thing, we're not re-litigating it ๐
).
EPERMโ permission said no to accessing this mount. rude, but okay. ๐ซEFAULTโ bad pointer alert ๐ eitherreqorsmbufis pointing at a location outside the process's accessible address space. like, bestie, that memory is not yours to touch.EINVALโ you passed an invalid flag inflags. nope, not a real one, try again. โจEINVALโreqis of insufficient size to be utilized. too smol to even work with, tragic. ๐ญEINVALโ you set bothreq.mnt_ns_idandreq.mnt_ns_fd. pick one, it's giving indecisive ๐.EINVALโreq.mnt_idorreq.mnt_ns_idgot specified alongsidereq.mnt_fd. that's a conflicting-fit situation and the kernel is not here for it. ๐EBADFโreq.mnt_fdis an invalid file descriptor. that fd is not fd-ing, fr fr.E2BIGโreqis too large. big. too big. too much main character energy for this call. ๐EOVERFLOWโ the size ofsmbufis too small to contain either thesmbuf.fs_type,smbuf.mnt_root, orsmbuf.mnt_point. so the move here is: allocate a larger buffer and retry the call. glow-up the buffer, then run it back. ๐ฆENOENTโ the specifiedreq.mnt_iddoesn't exist. it's not there. never was. gone girl. ๐ENOMEMโ out of memory (i.e., kernel memory). the kernel is broke, not you (well, maybe a little you). ๐ญ
๐ STANDARDS ๐
Linux. that's it, that's the standard, she's iconic and she knows it ๐
๐ SEE ALSO ๐
go read these next, they're the besties of this page:
and that's a wrap on statmount(2), bestie!! ๐ you were reading the Linux man-pages 6.20 version, dated 2026-08-22 โ go slay some mounts, stay hydrated, and don't @ me unless you've actually read the ERRORS section ๐ซถโจ๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms