Merge commit 'v2.6.39-rc3' into for-2.6.39
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / linux / user_namespace.h
blobfaf467944bafc0937ee7710b154e1ad91e07f847
1 #ifndef _LINUX_USER_NAMESPACE_H
2 #define _LINUX_USER_NAMESPACE_H
4 #include <linux/kref.h>
5 #include <linux/nsproxy.h>
6 #include <linux/sched.h>
7 #include <linux/err.h>
9 #define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 7)
10 #define UIDHASH_SZ (1 << UIDHASH_BITS)
12 struct user_namespace {
13 struct kref kref;
14 struct hlist_head uidhash_table[UIDHASH_SZ];
15 struct user_struct *creator;
16 struct work_struct destroyer;
19 extern struct user_namespace init_user_ns;
21 #ifdef CONFIG_USER_NS
23 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
25 if (ns)
26 kref_get(&ns->kref);
27 return ns;
30 extern int create_user_ns(struct cred *new);
31 extern void free_user_ns(struct kref *kref);
33 static inline void put_user_ns(struct user_namespace *ns)
35 if (ns)
36 kref_put(&ns->kref, free_user_ns);
39 uid_t user_ns_map_uid(struct user_namespace *to, const struct cred *cred, uid_t uid);
40 gid_t user_ns_map_gid(struct user_namespace *to, const struct cred *cred, gid_t gid);
42 #else
44 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
46 return &init_user_ns;
49 static inline int create_user_ns(struct cred *new)
51 return -EINVAL;
54 static inline void put_user_ns(struct user_namespace *ns)
58 static inline uid_t user_ns_map_uid(struct user_namespace *to,
59 const struct cred *cred, uid_t uid)
61 return uid;
63 static inline gid_t user_ns_map_gid(struct user_namespace *to,
64 const struct cred *cred, gid_t gid)
66 return gid;
69 #endif
71 #endif /* _LINUX_USER_H */