fspick(2)

πŸ’… fspick(2) β€” the girlies' guide to picking a filesystem for reconfiguration

Okay so bestie, gather round, because we're talking about fspick(2), a real one from the Linux System Calls Manual. It lives in the Standard C library (libc, -lc) and it's lowkey iconic. πŸ¦‹


✨ NAME ✨

fspick β€” select filesystem for reconfiguration


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)


πŸŽ€ SYNOPSIS πŸŽ€

#include <fcntl.h>          /* Definition of AT_* constants */
#include <sys/mount.h>

int fspick(int dirfd, const char *path, unsigned int flags);

🌸 DESCRIPTION 🌸

So fspick() is part of the whole suite of file-descriptor-based mount facilities in Linux β€” the cool kids' table, if you will. πŸ‘‘

What it does: fspick() creates a new filesystem configuration context for the extant filesystem instance associated with the path described by dirfd and path, and it drops that context straight into reconfiguration mode (basically the same energy as mount(8) with the -o remount option). Then it hands you back a brand-new file descriptor attached to that filesystem configuration context. ✨

Heads up though: the calling process must have the CAP_SYS_ADMIN capability in order to create a new filesystem configuration context. No cap, no context, no vibes. πŸ’€

Once you have that file descriptor, you can use it with fsconfig(2) to specify the exact set of changes you want made to the filesystem parameters of that filesystem instance. And once the desired set of changes have been configured, you can actually effectuate them by calling fsconfig(2) with the FSCONFIG_CMD_RECONFIGURE command. Periodt. πŸ’…

Not me explaining the glow-up here: in contrast to the behavior of MS_REMOUNT with mount(2), fspick() instantiates the filesystem configuration context with a copy of the extant filesystem's filesystem parameters. So subsequent FSCONFIG_CMD_RECONFIGURE operations will only update the filesystem parameters you explicitly modified with fsconfig(2). Everyone else stays untouched, minding their own business. 🫢

🧚 How dirfd + path actually work together 🧚

As with *at() system calls, fspick() uses the dirfd argument in conjunction with the path argument to determine the path to operate on, as follows:

  • If the pathname given in path is absolute, then dirfd is ignored. (She said what she said.)
  • If the pathname given in path is relative and dirfd is the special value AT_FDCWD, then path is interpreted relative to the current working directory of the calling process (like open(2)).
  • If the pathname given in path is relative, then it is interpreted relative to the directory referred to by the file descriptor dirfd (rather than relative to the current working directory of the calling process, as is done by open(2) for a relative pathname). In this case, dirfd must be a directory that was opened for reading (O_RDONLY) or using the O_PATH flag.
  • If path is an empty string, and flags contains FSPICK_EMPTY_PATH, then the file descriptor dirfd is operated on directly. In this case, dirfd may refer to any type of file, not just a directory. 🌈

See openat(2) for an explanation of why the dirfd argument is useful.


🌟 the flags, bestie 🌟

flags can be used to control aspects of how path is resolved and properties of the returned file descriptor. A value for flags is constructed by bitwise ORing zero or more of the following constants:

  • FSPICK_CLOEXEC β€” Set the close-on-exec (FD_CLOEXEC) flag on the new file descriptor. See the description of the O_CLOEXEC flag in open(2) for reasons why this may be useful. (Spoiler: it's the "don't leak me into my children" flag. Responsible queen behavior. πŸ’–)
  • FSPICK_EMPTY_PATH β€” If path is an empty string, operate on the file referred to by dirfd (which may have been obtained from open(2), fsmount(2), or open_tree(2)). In this case, dirfd may refer to any type of file, not just a directory. If dirfd is AT_FDCWD, fspick() will operate on the current working directory of the calling process.
  • FSPICK_SYMLINK_NOFOLLOW β€” Do not follow symbolic links in the terminal component of path. If path references a symbolic link, the returned filesystem context will reference the filesystem that the symbolic link itself resides on. (We're staying on this side of the link, thank you. πŸš«πŸ”—)
  • FSPICK_NO_AUTOMOUNT β€” Do not automount the terminal ("basename") component of path if it is a directory that is an automount point. This allows you to reconfigure an automount point, rather than the location that would be mounted. This flag has no effect if the automount point has already been mounted over.

πŸ“¬ message retrieval, iykyk πŸ“¬

As with filesystem contexts created with fsopen(2), the file descriptor returned by fspick() may be queried for message strings at any time by calling read(2) on the file descriptor. (See the "Message retrieval interface" subsection in fsopen(2) for more details on the message format.)


πŸ”₯ RETURN VALUE πŸ”₯

On success, a new file descriptor is returned. πŸŽ‰

On error, -1 is returned, and errno is set to indicate the error. 😭


πŸ’€ ERRORS πŸ’€

  • EACCES β€” Search permission is denied for one of the directories in the path prefix of path. (See also path_resolution(7).)
  • EBADF β€” path is relative but dirfd is neither AT_FDCWD nor a valid file descriptor.
  • EFAULT β€” path is NULL or a pointer to a location outside the calling process's accessible address space.
  • EINVAL β€” Invalid flag specified in flags.
  • ELOOP β€” Too many symbolic links encountered when resolving path.
  • EMFILE β€” The calling process has too many open files to create more.
  • ENAMETOOLONG β€” path is longer than PATH_MAX.
  • ENFILE β€” The system has too many open files to create more.
  • ENOENT β€” A component of path does not exist, or is a dangling symbolic link.
  • ENOENT β€” path is an empty string, but FSPICK_EMPTY_PATH is not specified in flags. (Yes she's listed twice, they're different crimes, don't @ me. πŸ™ˆ)
  • ENOTDIR β€” A component of the path prefix of path is not a directory; or path is relative and dirfd is a file descriptor referring to a file other than a directory.
  • ENOMEM β€” The kernel could not allocate sufficient memory to complete the operation.
  • EPERM β€” The calling process does not have the required CAP_SYS_ADMIN capability.

πŸ‘‘ STANDARDS πŸ‘‘

Linux. That's it, that's the standard.


πŸ•°οΈ HISTORY πŸ•°οΈ

Linux 5.2. glibc 2.36.


πŸ“ EXAMPLES πŸ“

The following example sets the read-only flag on the filesystem instance referenced by the mount object attached at /tmp.

int fsfd = fspick(AT_FDCWD, "/tmp", FSPICK_CLOEXEC);
fsconfig(fsfd, FSCONFIG_SET_FLAG, "ro", NULL, 0);
fsconfig(fsfd, FSCONFIG_CMD_RECONFIGURE, NULL, NULL, 0);

The above procedure is roughly equivalent to the following mount operation using mount(2):

mount(NULL, "/tmp", NULL, MS_REMOUNT | MS_RDONLY, NULL);
With the notable caveat that in this example, mount(2) will clear all other filesystem parameters (such as MS_DIRSYNC or MS_SYNCHRONOUS); fsconfig(2) will only modify the ro parameter. So like… one of these is a glow-up and one of these is a makeover gone wrong. Choose wisely. ⭐

🫢 SEE ALSO 🫢

fsconfig(2), fsmount(2), fsopen(2), mount(2), mount_setattr(2), move_mount(2), open_tree(2), mount_namespaces(7)


and that's the whole page, bestie πŸ’– brought to you by Linux man-pages 6.20, dated 2025-12-25 β€” yes, a Christmas Day release, the devs really said "gift for the girlies" 🎁✨ go forth and remount responsibly, mwah πŸ’…πŸŒΈ

πŸ“¦ 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