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 for listmount(), so you literally have to go through syscall(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 which struct mnt_id_req you're passing in. it should always be set to sizeof(struct mnt_id_req). don't be cute about it πŸ’…
  • req.mnt_id β€” this is the parent mnt_id we're listing from. it can either be LSMT_ROOT, which means the root mount of the current mount namespace, or a mount ID you got from either statx(2) using STATX_MNT_ID_UNIQUE or from listmount(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 to listmount(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_ids is returned πŸŽ‰ β€” and it's 0 if there are no more mounts left (the list just ends, iconic of her).
  • On error: -1 is returned, and errno is set to indicate the error 😭

πŸ’€ ERRORS πŸ’€

  • EPERM β€” the caller does not have CAP_SYS_ADMIN in the user namespace. (permission denied, bestie, go get your credentials πŸ’…)
  • EFAULT β€” req or mnt_ids points to a location outside the process's accessible address space. (points to the void πŸ™ˆ)
  • EINVAL β€” invalid flag specified in flags.
  • EINVAL β€” req is of insufficient size to be utilized.
  • E2BIG β€” req is too large; the limit is the architectures page size.
  • ENOENT β€” the specified req.mnt_id doesn'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