1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_MNT_IDMAPPING_H
3 #define _LINUX_MNT_IDMAPPING_H
5 #include <linux/types.h>
6 #include <linux/uidgid.h>
9 extern struct user_namespace init_user_ns;
12 * kuid_into_mnt - map a kuid down into a mnt_userns
13 * @mnt_userns: user namespace of the relevant mount
14 * @kuid: kuid to be mapped
16 * Return: @kuid mapped according to @mnt_userns.
17 * If @kuid has no mapping INVALID_UID is returned.
19 static inline kuid_t kuid_into_mnt(struct user_namespace *mnt_userns,
22 return make_kuid(mnt_userns, __kuid_val(kuid));
26 * kgid_into_mnt - map a kgid down into a mnt_userns
27 * @mnt_userns: user namespace of the relevant mount
28 * @kgid: kgid to be mapped
30 * Return: @kgid mapped according to @mnt_userns.
31 * If @kgid has no mapping INVALID_GID is returned.
33 static inline kgid_t kgid_into_mnt(struct user_namespace *mnt_userns,
36 return make_kgid(mnt_userns, __kgid_val(kgid));
40 * kuid_from_mnt - map a kuid up into a mnt_userns
41 * @mnt_userns: user namespace of the relevant mount
42 * @kuid: kuid to be mapped
44 * Return: @kuid mapped up according to @mnt_userns.
45 * If @kuid has no mapping INVALID_UID is returned.
47 static inline kuid_t kuid_from_mnt(struct user_namespace *mnt_userns,
50 return KUIDT_INIT(from_kuid(mnt_userns, kuid));
54 * kgid_from_mnt - map a kgid up into a mnt_userns
55 * @mnt_userns: user namespace of the relevant mount
56 * @kgid: kgid to be mapped
58 * Return: @kgid mapped up according to @mnt_userns.
59 * If @kgid has no mapping INVALID_GID is returned.
61 static inline kgid_t kgid_from_mnt(struct user_namespace *mnt_userns,
64 return KGIDT_INIT(from_kgid(mnt_userns, kgid));
68 * mapped_fsuid - return caller's fsuid mapped up into a mnt_userns
69 * @mnt_userns: user namespace of the relevant mount
71 * Use this helper to initialize a new vfs or filesystem object based on
72 * the caller's fsuid. A common example is initializing the i_uid field of
73 * a newly allocated inode triggered by a creation event such as mkdir or
74 * O_CREAT. Other examples include the allocation of quotas for a specific
77 * Return: the caller's current fsuid mapped up according to @mnt_userns.
79 static inline kuid_t mapped_fsuid(struct user_namespace *mnt_userns)
81 return kuid_from_mnt(mnt_userns, current_fsuid());
85 * mapped_fsgid - return caller's fsgid mapped up into a mnt_userns
86 * @mnt_userns: user namespace of the relevant mount
88 * Use this helper to initialize a new vfs or filesystem object based on
89 * the caller's fsgid. A common example is initializing the i_gid field of
90 * a newly allocated inode triggered by a creation event such as mkdir or
91 * O_CREAT. Other examples include the allocation of quotas for a specific
94 * Return: the caller's current fsgid mapped up according to @mnt_userns.
96 static inline kgid_t mapped_fsgid(struct user_namespace *mnt_userns)
98 return kgid_from_mnt(mnt_userns, current_fsgid());
101 #endif /* _LINUX_MNT_IDMAPPING_H */