blob: b5f41d4c2eec71a3d3c786128f0f980f0b41317d [file] [log] [blame]
Cedric Le Goateracce2922007-07-15 23:40:59 -07001#ifndef _LINUX_USER_NAMESPACE_H
2#define _LINUX_USER_NAMESPACE_H
3
4#include <linux/kref.h>
5#include <linux/nsproxy.h>
6#include <linux/sched.h>
Serge E. Hallyn77ec7392007-07-15 23:41:01 -07007#include <linux/err.h>
Cedric Le Goateracce2922007-07-15 23:40:59 -07008
9#define UIDHASH_BITS (CONFIG_BASE_SMALL ? 3 : 8)
10#define UIDHASH_SZ (1 << UIDHASH_BITS)
11
12struct user_namespace {
13 struct kref kref;
Pavel Emelyanov735de222007-09-18 22:46:44 -070014 struct hlist_head uidhash_table[UIDHASH_SZ];
Cedric Le Goateracce2922007-07-15 23:40:59 -070015 struct user_struct *root_user;
16};
17
18extern struct user_namespace init_user_ns;
19
20#ifdef CONFIG_USER_NS
21
22static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
23{
24 if (ns)
25 kref_get(&ns->kref);
26 return ns;
27}
28
29extern struct user_namespace *copy_user_ns(int flags,
30 struct user_namespace *old_ns);
31extern void free_user_ns(struct kref *kref);
32
33static inline void put_user_ns(struct user_namespace *ns)
34{
35 if (ns)
36 kref_put(&ns->kref, free_user_ns);
37}
38
39#else
40
41static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
42{
43 return &init_user_ns;
44}
45
46static inline struct user_namespace *copy_user_ns(int flags,
47 struct user_namespace *old_ns)
48{
Serge E. Hallyn77ec7392007-07-15 23:41:01 -070049 if (flags & CLONE_NEWUSER)
50 return ERR_PTR(-EINVAL);
51
Serge E. Hallyn626ac542007-07-17 15:28:17 -040052 return old_ns;
Cedric Le Goateracce2922007-07-15 23:40:59 -070053}
54
55static inline void put_user_ns(struct user_namespace *ns)
56{
57}
58
59#endif
60
61#endif /* _LINUX_USER_H */