blob: c8060c2ecd04b574bb2b6a795bb758a34f778f91 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#ifndef _LINUX_UTSNAME_H
3#define _LINUX_UTSNAME_H
4
Cedric Le Goaterb119f132006-10-04 02:15:19 -07005
6#include <linux/sched.h>
7#include <linux/kref.h>
8#include <linux/nsproxy.h>
Al Viro435d5f42014-10-31 22:56:04 -04009#include <linux/ns_common.h>
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080010#include <linux/err.h>
David Howells607ca462012-10-13 10:46:48 +010011#include <uapi/linux/utsname.h>
Cedric Le Goaterb119f132006-10-04 02:15:19 -070012
Lucas De Marchif1ecf062011-11-02 13:39:22 -070013enum uts_proc {
14 UTS_PROC_OSTYPE,
15 UTS_PROC_OSRELEASE,
16 UTS_PROC_VERSION,
17 UTS_PROC_HOSTNAME,
18 UTS_PROC_DOMAINNAME,
19};
20
Serge E. Hallyn59607db2011-03-23 16:43:16 -070021struct user_namespace;
22extern struct user_namespace init_user_ns;
23
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070024struct uts_namespace {
25 struct kref kref;
26 struct new_utsname name;
Serge E. Hallyn59607db2011-03-23 16:43:16 -070027 struct user_namespace *user_ns;
Eric W. Biedermanf7af3d12016-08-08 14:11:25 -050028 struct ucounts *ucounts;
Al Viro435d5f42014-10-31 22:56:04 -040029 struct ns_common ns;
Kees Cook3859a272016-10-28 01:22:25 -070030} __randomize_layout;
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070031extern struct uts_namespace init_uts_ns;
32
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080033#ifdef CONFIG_UTS_NS
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070034static inline void get_uts_ns(struct uts_namespace *ns)
35{
36 kref_get(&ns->kref);
37}
38
Eric W. Biederman213dd262007-07-15 23:41:15 -070039extern struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070040 struct user_namespace *user_ns, struct uts_namespace *old_ns);
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070041extern void free_uts_ns(struct kref *kref);
42
43static inline void put_uts_ns(struct uts_namespace *ns)
44{
45 kref_put(&ns->kref, free_uts_ns);
46}
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080047#else
48static inline void get_uts_ns(struct uts_namespace *ns)
49{
50}
51
52static inline void put_uts_ns(struct uts_namespace *ns)
53{
54}
55
56static inline struct uts_namespace *copy_utsname(unsigned long flags,
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070057 struct user_namespace *user_ns, struct uts_namespace *old_ns)
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080058{
59 if (flags & CLONE_NEWUTS)
60 return ERR_PTR(-EINVAL);
61
Eric W. Biedermanbcf58e72012-07-26 04:02:49 -070062 return old_ns;
Pavel Emelyanov58bfdd6d2008-02-08 04:18:21 -080063}
64#endif
65
Lucas De Marchif1ecf062011-11-02 13:39:22 -070066#ifdef CONFIG_PROC_SYSCTL
67extern void uts_proc_notify(enum uts_proc proc);
68#else
69static inline void uts_proc_notify(enum uts_proc proc)
70{
71}
72#endif
73
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070074static inline struct new_utsname *utsname(void)
75{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070076 return &current->nsproxy->uts_ns->name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070077}
78
79static inline struct new_utsname *init_utsname(void)
80{
Serge E. Hallyn4865ecf2006-10-02 02:18:14 -070081 return &init_uts_ns.name;
Serge E. Hallyn0bdd7aa2006-10-02 02:18:10 -070082}
83
Linus Torvalds1da177e2005-04-16 15:20:36 -070084extern struct rw_semaphore uts_sem;
Cedric Le Goaterb119f132006-10-04 02:15:19 -070085
Cedric Le Goaterb119f132006-10-04 02:15:19 -070086#endif /* _LINUX_UTSNAME_H */