listmount(2)
π« listmount(2) β the Linux girlies' guide to listing mount IDs π«
okay so bestie, welcome to listmount(2) π this one lives in the System Calls Manual and honestly? she's giving backstage pass to your mount namespace energy. let's get into it.
β¨ NAME β¨
listmount β get a list of mount ID's πΈ
π LIBRARY π
Standard C library (libc, -lc) π
π¦ SYNOPSIS π¦
#include <linux/mount.h> /* Definition of struct mnt_id_req constants */
#include <unistd.h>
int syscall(size_t n;
SYS_listmount, struct mnt_id_req *req,
uint64_t mnt_ids[n], size_t n,
unsigned long flags);
#include <linux/mount.h>
struct mnt_id_req {
__u32 size; /* sizeof(struct mnt_id_req) */
__u64 mnt_id; /* The parent mnt_id being searched */
__u64 param; /* The next mnt_id we want to find */
};
Note: glibc provides no wrapper forlistmount(), so you literally have to go throughsyscall(2)π no shortcuts, no cap. you're raw-dogging the syscall interface, periodt.
π₯ DESCRIPTION π₯
so to access the mounts in your namespace, you must have CAP_SYS_ADMIN in the user namespace π no cap, no list.
This function returns a list of mount IDs under the req.mnt_id. And the whole point? it's meant to be used in conjuction with statmount(2) so you have a way to iterate and discover mounted file systems π§ the iconic duo fr fr.
π The mnt_id_req structure π
req.sizeβ the kernel uses this to figure out whichstruct mnt_id_reqyou're passing in. it should always be set tosizeof(struct mnt_id_req). don't be cute about it πreq.mnt_idβ this is the parentmnt_idwe're listing from. it can either beLSMT_ROOT, which means the root mount of the current mount namespace, or a mount ID you got from eitherstatx(2)usingSTATX_MNT_ID_UNIQUEor fromlistmount(2)itself. we love a self-sustaining ecosystem β¨req.paramβ tells the kernel which mount ID to start the list from. super useful if you need multiple calls tolistmount(2)(and bestie, you will). set it to the last mount ID returned and you resume right from where you left off, like a bookmark in your fave fic π
π RETURN VALUE π
- On success: the number of entries filled into
mnt_idsis returned π β and it's0if there are no more mounts left (the list just ends, iconic of her). - On error:
-1is returned, anderrnois set to indicate the error π
π ERRORS π
EPERMβ the caller does not haveCAP_SYS_ADMINin the user namespace. (permission denied, bestie, go get your credentials π )EFAULTβreqormnt_idspoints to a location outside the process's accessible address space. (points to the void π)EINVALβ invalid flag specified inflags.EINVALβreqis of insufficient size to be utilized.E2BIGβreqis too large; the limit is the architectures page size.ENOENTβ the specifiedreq.mnt_iddoesn't exist. (she's not there, she never was πΈ)ENOMEMβ out of memory (i.e., kernel memory). (no thoughts, kernel empty π«Ά)
β STANDARDS β
Linux. that's it, that's the standard π§
πΈ SEE ALSO πΈ
statmount(2), statx(2) β go read these too, they're part of the lore iykyk π
mwah, that's the whole page bestie π go forth and enumerate those mounts, you absolute main character π
this gem was brought to you by Linux man-pages 6.20, dated 2025-09-06 β wrote it, shipped it, slayed it π β¨
π¦ 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