blob: 2b345206722a2ff374bf690a84be4a20a2ffabfe [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_UTSNAME_H
2#define _LINUX_UTSNAME_H
3
Cedric Le Goaterb119f132006-10-04 02:15:19 -07004
5#include <linux/sched.h>
6#include <linux/kref.h>
7#include <linux/nsproxy.h>
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -08008#include <linux/err.h>
David Howells607ca462012-10-13 10:46:48 +01009#include <uapi/linux/utsname.h>
Cedric Le Goaterb119f132006-10-04 02:15:19 -070010
Lucas De Marchif1ecf062011-11-02 13:39:22 -070011enum uts_proc {
12 UTS_PROC_OSTYPE,
13 UTS_PROC_OSRELEASE,
14 UTS_PROC_VERSION,
15 UTS_PROC_HOSTNAME,
16 UTS_PROC_DOMAINNAME,
17};
18
Serge E. Hallyn59607db2011-03-23 16:43:16 -070019struct user_namespace;
20extern struct user_namespace init_user_ns;
21
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070022struct uts_namespace {
23 struct kref kref;
24 struct new_utsname name;
Serge E. Hallyn59607db2011-03-23 16:43:16 -070025 struct user_namespace *user_ns;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070026};
27extern struct uts_namespace init_uts_ns;
28
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080029#ifdef CONFIG_UTS_NS
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070030static inline void get_uts_ns(struct uts_namespace *ns)
31{
32 kref_get(&ns->kref);
33}
34
Eric W. Biederman213dd262007-07-15 23:41:15 -070035extern struct uts_namespace *copy_utsname(unsigned long flags,
Serge E. Hallynbb96a6f2011-03-23 16:43:18 -070036 struct task_struct *tsk);
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070037extern void free_uts_ns(struct kref *kref);
38
39static inline void put_uts_ns(struct uts_namespace *ns)
40{
41 kref_put(&ns->kref, free_uts_ns);
42}
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080043#else
44static inline void get_uts_ns(struct uts_namespace *ns)
45{
46}
47
48static inline void put_uts_ns(struct uts_namespace *ns)
49{
50}
51
52static inline struct uts_namespace *copy_utsname(unsigned long flags,
Serge E. Hallynbb96a6f2011-03-23 16:43:18 -070053 struct task_struct *tsk)
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080054{
55 if (flags & CLONE_NEWUTS)
56 return ERR_PTR(-EINVAL);
57
Serge E. Hallynbb96a6f2011-03-23 16:43:18 -070058 return tsk->nsproxy->uts_ns;
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080059}
60#endif
61
Lucas De Marchif1ecf062011-11-02 13:39:22 -070062#ifdef CONFIG_PROC_SYSCTL
63extern void uts_proc_notify(enum uts_proc proc);
64#else
65static inline void uts_proc_notify(enum uts_proc proc)
66{
67}
68#endif
69
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070070static inline struct new_utsname *utsname(void)
71{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070072 return &current->nsproxy->uts_ns->name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070073}
74
75static inline struct new_utsname *init_utsname(void)
76{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070077 return &init_uts_ns.name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070078}
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080extern struct rw_semaphore uts_sem;
Cedric Le Goaterb119f132006-10-04 02:15:19 -070081
Cedric Le Goaterb119f132006-10-04 02:15:19 -070082#endif /* _LINUX_UTSNAME_H */