blob: 5093f58ae192c379b13b9e5e74605a0e6c571d25 [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>
Al Viro435d5f42014-10-31 22:56:04 -04008#include <linux/ns_common.h>
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -08009#include <linux/err.h>
David Howells607ca462012-10-13 10:46:48 +010010#include <uapi/linux/utsname.h>
Cedric Le Goaterb119f132006-10-04 02:15:19 -070011
Lucas De Marchif1ecf062011-11-02 13:39:22 -070012enum uts_proc {
13 UTS_PROC_OSTYPE,
14 UTS_PROC_OSRELEASE,
15 UTS_PROC_VERSION,
16 UTS_PROC_HOSTNAME,
17 UTS_PROC_DOMAINNAME,
18};
19
Serge E. Hallyn59607db2011-03-23 16:43:16 -070020struct user_namespace;
21extern struct user_namespace init_user_ns;
22
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070023struct uts_namespace {
24 struct kref kref;
25 struct new_utsname name;
Serge E. Hallyn59607db2011-03-23 16:43:16 -070026 struct user_namespace *user_ns;
Al Viro435d5f42014-10-31 22:56:04 -040027 struct ns_common ns;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070028};
29extern struct uts_namespace init_uts_ns;
30
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080031#ifdef CONFIG_UTS_NS
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070032static inline void get_uts_ns(struct uts_namespace *ns)
33{
34 kref_get(&ns->kref);
35}
36
Eric W. Biederman213dd262007-07-15 23:41:15 -070037extern struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070038 struct user_namespace *user_ns, struct uts_namespace *old_ns);
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070039extern void free_uts_ns(struct kref *kref);
40
41static inline void put_uts_ns(struct uts_namespace *ns)
42{
43 kref_put(&ns->kref, free_uts_ns);
44}
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080045#else
46static inline void get_uts_ns(struct uts_namespace *ns)
47{
48}
49
50static inline void put_uts_ns(struct uts_namespace *ns)
51{
52}
53
54static inline struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070055 struct user_namespace *user_ns, struct uts_namespace *old_ns)
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080056{
57 if (flags & CLONE_NEWUTS)
58 return ERR_PTR(-EINVAL);
59
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070060 return old_ns;
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080061}
62#endif
63
Lucas De Marchif1ecf062011-11-02 13:39:22 -070064#ifdef CONFIG_PROC_SYSCTL
65extern void uts_proc_notify(enum uts_proc proc);
66#else
67static inline void uts_proc_notify(enum uts_proc proc)
68{
69}
70#endif
71
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070072static inline struct new_utsname *utsname(void)
73{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070074 return &current->nsproxy->uts_ns->name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070075}
76
77static inline struct new_utsname *init_utsname(void)
78{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070079 return &init_uts_ns.name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070080}
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082extern struct rw_semaphore uts_sem;
Cedric Le Goaterb119f132006-10-04 02:15:19 -070083
Cedric Le Goaterb119f132006-10-04 02:15:19 -070084#endif /* _LINUX_UTSNAME_H */