Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_UTSNAME_H |
3 | #define _LINUX_UTSNAME_H | |
4 | ||
b119f13f CLG |
5 | |
6 | #include <linux/sched.h> | |
b119f13f | 7 | #include <linux/nsproxy.h> |
435d5f4b | 8 | #include <linux/ns_common.h> |
58bfdd6d | 9 | #include <linux/err.h> |
607ca46e | 10 | #include <uapi/linux/utsname.h> |
b119f13f | 11 | |
f1ecf068 LDM |
12 | enum uts_proc { |
13 | UTS_PROC_OSTYPE, | |
14 | UTS_PROC_OSRELEASE, | |
15 | UTS_PROC_VERSION, | |
16 | UTS_PROC_HOSTNAME, | |
17 | UTS_PROC_DOMAINNAME, | |
18 | }; | |
19 | ||
59607db3 SH |
20 | struct user_namespace; |
21 | extern struct user_namespace init_user_ns; | |
22 | ||
4865ecf1 | 23 | struct uts_namespace { |
4865ecf1 | 24 | struct new_utsname name; |
59607db3 | 25 | struct user_namespace *user_ns; |
f7af3d1c | 26 | struct ucounts *ucounts; |
435d5f4b | 27 | struct ns_common ns; |
3859a271 | 28 | } __randomize_layout; |
4865ecf1 SH |
29 | extern struct uts_namespace init_uts_ns; |
30 | ||
58bfdd6d | 31 | #ifdef CONFIG_UTS_NS |
4865ecf1 SH |
32 | static inline void get_uts_ns(struct uts_namespace *ns) |
33 | { | |
9a56493f | 34 | refcount_inc(&ns->ns.count); |
4865ecf1 SH |
35 | } |
36 | ||
213dd266 | 37 | extern struct uts_namespace *copy_utsname(unsigned long flags, |
bcf58e72 | 38 | struct user_namespace *user_ns, struct uts_namespace *old_ns); |
9a56493f | 39 | extern void free_uts_ns(struct uts_namespace *ns); |
4865ecf1 SH |
40 | |
41 | static inline void put_uts_ns(struct uts_namespace *ns) | |
42 | { | |
9a56493f KT |
43 | if (refcount_dec_and_test(&ns->ns.count)) |
44 | free_uts_ns(ns); | |
4865ecf1 | 45 | } |
3ea056c5 AD |
46 | |
47 | void uts_ns_init(void); | |
58bfdd6d PE |
48 | #else |
49 | static inline void get_uts_ns(struct uts_namespace *ns) | |
50 | { | |
51 | } | |
52 | ||
53 | static inline void put_uts_ns(struct uts_namespace *ns) | |
54 | { | |
55 | } | |
56 | ||
57 | static inline struct uts_namespace *copy_utsname(unsigned long flags, | |
bcf58e72 | 58 | struct user_namespace *user_ns, struct uts_namespace *old_ns) |
58bfdd6d PE |
59 | { |
60 | if (flags & CLONE_NEWUTS) | |
61 | return ERR_PTR(-EINVAL); | |
62 | ||
bcf58e72 | 63 | return old_ns; |
58bfdd6d | 64 | } |
3ea056c5 AD |
65 | |
66 | static inline void uts_ns_init(void) | |
67 | { | |
68 | } | |
58bfdd6d PE |
69 | #endif |
70 | ||
f1ecf068 LDM |
71 | #ifdef CONFIG_PROC_SYSCTL |
72 | extern void uts_proc_notify(enum uts_proc proc); | |
73 | #else | |
74 | static inline void uts_proc_notify(enum uts_proc proc) | |
75 | { | |
76 | } | |
77 | #endif | |
78 | ||
0bdd7aab SH |
79 | static inline struct new_utsname *utsname(void) |
80 | { | |
4865ecf1 | 81 | return ¤t->nsproxy->uts_ns->name; |
0bdd7aab SH |
82 | } |
83 | ||
84 | static inline struct new_utsname *init_utsname(void) | |
85 | { | |
4865ecf1 | 86 | return &init_uts_ns.name; |
0bdd7aab SH |
87 | } |
88 | ||
1da177e4 | 89 | extern struct rw_semaphore uts_sem; |
b119f13f | 90 | |
b119f13f | 91 | #endif /* _LINUX_UTSNAME_H */ |