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
pathis absolute, thendirfdis ignored. (She said what she said.) - If the pathname given in
pathis relative anddirfdis the special valueAT_FDCWD, thenpathis interpreted relative to the current working directory of the calling process (likeopen(2)). - If the pathname given in
pathis relative, then it is interpreted relative to the directory referred to by the file descriptordirfd(rather than relative to the current working directory of the calling process, as is done byopen(2)for a relative pathname). In this case,dirfdmust be a directory that was opened for reading (O_RDONLY) or using theO_PATHflag. - If
pathis an empty string, andflagscontainsFSPICK_EMPTY_PATH, then the file descriptordirfdis operated on directly. In this case,dirfdmay 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 theO_CLOEXECflag inopen(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β Ifpathis an empty string, operate on the file referred to bydirfd(which may have been obtained fromopen(2),fsmount(2), oropen_tree(2)). In this case,dirfdmay refer to any type of file, not just a directory. IfdirfdisAT_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 ofpath. Ifpathreferences 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 ofpathif 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 ofpath. (See alsopath_resolution(7).)EBADFβpathis relative butdirfdis neitherAT_FDCWDnor a valid file descriptor.EFAULTβpathisNULLor a pointer to a location outside the calling process's accessible address space.EINVALβ Invalid flag specified inflags.ELOOPβ Too many symbolic links encountered when resolvingpath.EMFILEβ The calling process has too many open files to create more.ENAMETOOLONGβpathis longer thanPATH_MAX.ENFILEβ The system has too many open files to create more.ENOENTβ A component ofpathdoes not exist, or is a dangling symbolic link.ENOENTβpathis an empty string, butFSPICK_EMPTY_PATHis not specified inflags. (Yes she's listed twice, they're different crimes, don't @ me. π)ENOTDIRβ A component of the path prefix ofpathis not a directory; orpathis relative anddirfdis 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 requiredCAP_SYS_ADMINcapability.
π 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 asMS_DIRSYNCorMS_SYNCHRONOUS);fsconfig(2)will only modify theroparameter. 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