From: Aleksa Sarai <cyphar@cyphar.com>
To: Alejandro Colomar <alx@kernel.org>
Cc: "Michael T. Kerrisk" <mtk.manpages@gmail.com>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Jan Kara <jack@suse.cz>, Askar Safin <safinaskar@zohomail.com>,
"G. Branden Robinson" <g.branden.robinson@gmail.com>,
linux-man@vger.kernel.org, linux-api@vger.kernel.org,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
David Howells <dhowells@redhat.com>,
Christian Brauner <brauner@kernel.org>,
Aleksa Sarai <cyphar@cyphar.com>
Subject: [PATCH v2 06/11] fsmount.2: document 'new' mount api
Date: Thu, 07 Aug 2025 03:44:40 +1000 [thread overview]
Message-ID: <20250807-new-mount-api-v2-6-558a27b8068c@cyphar.com> (raw)
In-Reply-To: <20250807-new-mount-api-v2-0-558a27b8068c@cyphar.com>
This is loosely based on the original documentation written by David
Howells and later maintained by Christian Brauner, but has been
rewritten to be more from a user perspective (as well as fixing a few
critical mistakes).
Co-developed-by: David Howells <dhowells@redhat.com>
Co-developed-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
---
man/man2/fsmount.2 | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 209 insertions(+)
diff --git a/man/man2/fsmount.2 b/man/man2/fsmount.2
new file mode 100644
index 000000000000..8c264c3d5aba
--- /dev/null
+++ b/man/man2/fsmount.2
@@ -0,0 +1,209 @@
+.\" Copyright, the authors of the Linux man-pages project
+.\"
+.\" SPDX-License-Identifier: Linux-man-pages-copyleft
+.\"
+.TH fsmount 2 (date) "Linux man-pages (unreleased)"
+.SH NAME
+fsmount \- instantiate mount object from filesystem context
+.SH LIBRARY
+Standard C library
+.RI ( libc ,\~ \-lc )
+.SH SYNOPSIS
+.nf
+.BR "#include <sys/mount.h>"
+.P
+.BI "int fsmount(int " fsfd ", unsigned int " flags ", \
+unsigned int " attr_flags ");"
+.fi
+.SH DESCRIPTION
+The
+.BR fsmount ()
+system call is part of the suite of file descriptor based mount facilities
+in Linux.
+.P
+.BR fsmount ()
+takes the created filesystem instance
+referenced by the filesystem context
+associated with the file descriptor
+.I fsfd
+and creates a new mount object
+for the root of the filesystem instance,
+which is then attached to a new file descriptor
+and returned.
+In order to create a mount object with
+.BR fsmount (),
+the calling process must have the
+.BR \%CAP_SYS_ADMIN
+capability.
+.P
+The filesystem context must have been created with a call to
+.BR fsopen (2)
+and then had a filesystem instance instantiated with a call to
+.BR fsconfig (2)
+with
+.B \%FSCONFIG_CMD_CREATE
+or
+.B \%FSCONFIG_CMD_CREATE_EXCL
+in order to be in the correct state
+for this operation.
+.P
+As with file descriptors returned from
+.BR open_tree (2)
+called with
+.BR OPEN_TREE_CLONE ,
+the returned file descriptor
+can then be used with
+.BR move_mount (2),
+.BR mount_setattr (2),
+or other such system calls
+to do further mount operations.
+This mount object will be unmounted and destroyed
+when the file descriptor is closed
+if it was not otherwise mounted somewhere else
+by calling
+.BR move_mount (2).
+The returned file descriptor
+also acts the same as one produced by
+.BR open (2)
+with
+.BR O_PATH ,
+meaning it can also be used as a
+.I dirfd
+argument
+to "*at()" system calls.
+.P
+.I flags
+controls the creation of the returned file descriptor.
+A value for
+.I flags
+is constructed by bitwise ORing
+zero or more of the following constants:
+.RS
+.TP
+.B FSMOUNT_CLOEXEC
+Set the close-on-exec
+.RB ( FD_CLOEXEC )
+flag on the new file descriptor.
+See the description of the
+.B O_CLOEXEC
+flag in
+.BR open (2)
+for reasons why this may be useful.
+.RE
+.P
+.I attr_flags
+specifies the mount attributes
+for the created mount object
+and accepts the same set of
+.BI \%MOUNT_ATTR_ *
+flags as
+.BR mount_setattr (2),
+except for flags such as
+.B \%MOUNT_ATTR_IDMAP
+which require specifying additional fields in
+.BR mount_attr (2type).
+.P
+If the
+.BR fsmount ()
+operation is successful,
+the filesystem context
+associated with the file descriptor
+.I fsfd
+is reset
+and placed into a reconfiguration state,
+similar to the one produced by
+.BR fspick (2).
+You may coninue to use
+.BR fsconfig (2)
+with the
+.B \%FSCONFIG_CMD_RECONFIGURE
+command
+to reconfigure the filesystem instance.
+.P
+Unlike
+.BR open_tree (2),
+.BR fsmount ()
+can only be called once
+to produce a mount object
+for a given filesystem configuration context.
+.SH RETURN VALUE
+On success, a new file descriptor is returned.
+On error, \-1 is returned, and
+.I errno
+is set to indicate the error.
+.SH ERRORS
+.TP
+.B EBUSY
+The filesystem context attached to
+.I fsfd
+is not in the right state
+to be used by
+.BR fsmount ().
+.TP
+.B EINVAL
+.I flags
+had an invalid flag set.
+.TP
+.B EINVAL
+.I attr_flags
+had an invalid
+.BI MOUNT_ATTR_ *
+flag set.
+.TP
+.B EMFILE
+The calling process has too many open files to create more.
+.TP
+.B ENFILE
+The system has too many open files to create more.
+.TP
+.B ENOSPC
+The "anonymous" mount namespace
+necessary to contain the new mount object
+could not be allocated,
+as doing so would
+exceed the configured per-user limit
+on the number of mount namespaces
+in the current user namespace.
+(See also
+.BR namespaces (7).)
+.TP
+.B ENOMEM
+The kernel could not allocate sufficient memory to complete the operation.
+.TP
+.B EPERM
+The calling process does not have the required
+.B CAP_SYS_ADMIN
+capability.
+.SH STANDARDS
+Linux.
+.SH HISTORY
+Linux 5.2.
+.\" commit 93766fbd2696c2c4453dd8e1070977e9cd4e6b6d
+glibc 2.36.
+.SH EXAMPLES
+.in +4n
+.EX
+int fsfd, mntfd, tmpfd;
+\&
+fsfd = fsopen("tmpfs", FSOPEN_CLOEXEC);
+fsconfig(fsfd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
+mntfd = fsmount(fsfd, FSMOUNT_CLOEXEC, MOUNT_ATTR_NODEV | MOUNT_ATTR_NOEXEC);
+\&
+/* Create a new file without attaching the mount object. */
+int tmpfd = openat(mntfd, "tmpfile", O_CREAT | O_EXCL | O_RDWR, 0600);
+unlinkat(mntfd, "tmpfile", 0);
+\&
+/* Attach the mount object to "/tmp". */
+move_mount(mntfd, "", AT_FDCWD, "/tmp", MOVE_MOUNT_F_EMPTY_PATH);
+.EE
+.in
+.SH SEE ALSO
+.BR fsconfig (2),
+.BR fsopen (2),
+.BR fspick (2),
+.BR mount (2),
+.BR mount_setattr (2),
+.BR move_mount (2),
+.BR open_tree (2),
+.BR mount_namespaces (7)
+
--
2.50.1
next prev parent reply other threads:[~2025-08-06 17:45 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-06 17:44 [PATCH v2 00/11] man2: add man pages for 'new' mount API Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 01/11] mount_setattr.2: document glibc >= 2.36 syscall wrappers Aleksa Sarai
2025-08-07 10:39 ` Alejandro Colomar
2025-08-08 9:23 ` Askar Safin
2025-08-08 11:55 ` Aleksa Sarai
2025-08-09 10:42 ` Alejandro Colomar
2025-08-09 10:44 ` Alejandro Colomar
2025-08-06 17:44 ` [PATCH v2 02/11] mount_setattr.2: move mount_attr struct to mount_attr.2type Aleksa Sarai
2025-08-07 11:11 ` Alejandro Colomar
2025-08-07 12:38 ` Aleksa Sarai
2025-08-07 13:33 ` Alejandro Colomar
2025-08-06 17:44 ` [PATCH v2 03/11] fsopen.2: document 'new' mount api Aleksa Sarai
2025-08-07 11:38 ` Alejandro Colomar
2025-08-07 12:50 ` Aleksa Sarai
2025-08-07 13:42 ` Alejandro Colomar
2025-08-07 13:27 ` Aleksa Sarai
2025-08-07 13:52 ` Alejandro Colomar
2025-08-07 14:26 ` Aleksa Sarai
2025-08-07 19:27 ` Konstantin Ryabitsev
2025-08-07 19:39 ` Aleksa Sarai
2025-08-08 9:07 ` Askar Safin
2025-08-08 11:57 ` Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 04/11] fspick.2: " Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 05/11] fsconfig.2: " Aleksa Sarai
2025-08-08 14:00 ` Askar Safin
2025-08-08 15:22 ` Aleksa Sarai
2025-08-08 19:07 ` Aleksa Sarai
2025-08-06 17:44 ` Aleksa Sarai [this message]
2025-08-06 17:44 ` [PATCH v2 07/11] move_mount.2: " Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 08/11] open_tree.2: " Aleksa Sarai
2025-08-08 12:32 ` Askar Safin
2025-08-08 13:26 ` Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 09/11] mount_setattr.2: mirror opening sentence from fsopen(2) Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 10/11] open_tree_attr.2, open_tree.2: document new open_tree_attr() api Aleksa Sarai
2025-08-06 17:44 ` [PATCH v2 11/11] fsconfig.2, mount_setattr.2: add note about attribute-parameter distinction Aleksa Sarai
2025-08-08 12:53 ` [PATCH v2 00/11] man2: add man pages for 'new' mount API Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250807-new-mount-api-v2-6-558a27b8068c@cyphar.com \
--to=cyphar@cyphar.com \
--cc=alx@kernel.org \
--cc=brauner@kernel.org \
--cc=dhowells@redhat.com \
--cc=g.branden.robinson@gmail.com \
--cc=jack@suse.cz \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
--cc=safinaskar@zohomail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).