blob: 239e27733d6ccd42482c0cda35e28ec052ef730e [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;
Eric W. Biederman98f842e2011-06-15 10:21:48 -070026 unsigned int proc_inum;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070027};
28extern struct uts_namespace init_uts_ns;
29
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080030#ifdef CONFIG_UTS_NS
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070031static inline void get_uts_ns(struct uts_namespace *ns)
32{
33 kref_get(&ns->kref);
34}
35
Eric W. Biederman213dd262007-07-15 23:41:15 -070036extern struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070037 struct user_namespace *user_ns, struct uts_namespace *old_ns);
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070038extern void free_uts_ns(struct kref *kref);
39
40static inline void put_uts_ns(struct uts_namespace *ns)
41{
42 kref_put(&ns->kref, free_uts_ns);
43}
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080044#else
45static inline void get_uts_ns(struct uts_namespace *ns)
46{
47}
48
49static inline void put_uts_ns(struct uts_namespace *ns)
50{
51}
52
53static inline struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070054 struct user_namespace *user_ns, struct uts_namespace *old_ns)
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080055{
56 if (flags & CLONE_NEWUTS)
57 return ERR_PTR(-EINVAL);
58
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070059 return old_ns;
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080060}
61#endif
62
Lucas De Marchif1ecf062011-11-02 13:39:22 -070063#ifdef CONFIG_PROC_SYSCTL
64extern void uts_proc_notify(enum uts_proc proc);
65#else
66static inline void uts_proc_notify(enum uts_proc proc)
67{
68}
69#endif
70
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070071static inline struct new_utsname *utsname(void)
72{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070073 return &current->nsproxy->uts_ns->name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070074}
75
76static inline struct new_utsname *init_utsname(void)
77{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070078 return &init_uts_ns.name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070079}
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081extern struct rw_semaphore uts_sem;
Cedric Le Goaterb119f132006-10-04 02:15:19 -070082
Cedric Le Goaterb119f132006-10-04 02:15:19 -070083#endif /* _LINUX_UTSNAME_H */