Skip to content

Commit 5b49050

Browse files
author
Christian Brauner
committed
fs: add attr_flags_to_mnt_flags helper
Add a simple helper to translate uapi MOUNT_ATTR_* flags to MNT_* flags which we will use in follow-up patches too. Link: https://lore.kernel.org/r/[email protected] Cc: David Howells <[email protected]> Cc: Al Viro <[email protected]> Cc: [email protected] Suggested-by: Christoph Hellwig <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent fbdc2f6 commit 5b49050

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

fs/namespace.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3465,6 +3465,28 @@ SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
34653465
return ret;
34663466
}
34673467

3468+
#define FSMOUNT_VALID_FLAGS \
3469+
(MOUNT_ATTR_RDONLY | MOUNT_ATTR_NOSUID | MOUNT_ATTR_NODEV | \
3470+
MOUNT_ATTR_NOEXEC | MOUNT_ATTR__ATIME | MOUNT_ATTR_NODIRATIME)
3471+
3472+
static unsigned int attr_flags_to_mnt_flags(u64 attr_flags)
3473+
{
3474+
unsigned int mnt_flags = 0;
3475+
3476+
if (attr_flags & MOUNT_ATTR_RDONLY)
3477+
mnt_flags |= MNT_READONLY;
3478+
if (attr_flags & MOUNT_ATTR_NOSUID)
3479+
mnt_flags |= MNT_NOSUID;
3480+
if (attr_flags & MOUNT_ATTR_NODEV)
3481+
mnt_flags |= MNT_NODEV;
3482+
if (attr_flags & MOUNT_ATTR_NOEXEC)
3483+
mnt_flags |= MNT_NOEXEC;
3484+
if (attr_flags & MOUNT_ATTR_NODIRATIME)
3485+
mnt_flags |= MNT_NODIRATIME;
3486+
3487+
return mnt_flags;
3488+
}
3489+
34683490
/*
34693491
* Create a kernel mount representation for a new, prepared superblock
34703492
* (specified by fs_fd) and attach to an open_tree-like file descriptor.
@@ -3487,24 +3509,10 @@ SYSCALL_DEFINE3(fsmount, int, fs_fd, unsigned int, flags,
34873509
if ((flags & ~(FSMOUNT_CLOEXEC)) != 0)
34883510
return -EINVAL;
34893511

3490-
if (attr_flags & ~(MOUNT_ATTR_RDONLY |
3491-
MOUNT_ATTR_NOSUID |
3492-
MOUNT_ATTR_NODEV |
3493-
MOUNT_ATTR_NOEXEC |
3494-
MOUNT_ATTR__ATIME |
3495-
MOUNT_ATTR_NODIRATIME))
3512+
if (attr_flags & ~FSMOUNT_VALID_FLAGS)
34963513
return -EINVAL;
34973514

3498-
if (attr_flags & MOUNT_ATTR_RDONLY)
3499-
mnt_flags |= MNT_READONLY;
3500-
if (attr_flags & MOUNT_ATTR_NOSUID)
3501-
mnt_flags |= MNT_NOSUID;
3502-
if (attr_flags & MOUNT_ATTR_NODEV)
3503-
mnt_flags |= MNT_NODEV;
3504-
if (attr_flags & MOUNT_ATTR_NOEXEC)
3505-
mnt_flags |= MNT_NOEXEC;
3506-
if (attr_flags & MOUNT_ATTR_NODIRATIME)
3507-
mnt_flags |= MNT_NODIRATIME;
3515+
mnt_flags = attr_flags_to_mnt_flags(attr_flags);
35083516

35093517
switch (attr_flags & MOUNT_ATTR__ATIME) {
35103518
case MOUNT_ATTR_STRICTATIME:

0 commit comments

Comments
 (0)