xref: /openbmc/linux/include/linux/utsname.h (revision 7ae9fb1b7ecbb5d85d07857943f677fd1a559b18)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21da177e4SLinus Torvalds #ifndef _LINUX_UTSNAME_H
31da177e4SLinus Torvalds #define _LINUX_UTSNAME_H
41da177e4SLinus Torvalds 
5b119f13fSCedric Le Goater 
6b119f13fSCedric Le Goater #include <linux/sched.h>
7b119f13fSCedric Le Goater #include <linux/nsproxy.h>
8435d5f4bSAl Viro #include <linux/ns_common.h>
958bfdd6dSPavel Emelyanov #include <linux/err.h>
10607ca46eSDavid Howells #include <uapi/linux/utsname.h>
11b119f13fSCedric Le Goater 
12f1ecf068SLucas De Marchi enum uts_proc {
13*52826d3bSLinus Torvalds 	UTS_PROC_ARCH,
14f1ecf068SLucas De Marchi 	UTS_PROC_OSTYPE,
15f1ecf068SLucas De Marchi 	UTS_PROC_OSRELEASE,
16f1ecf068SLucas De Marchi 	UTS_PROC_VERSION,
17f1ecf068SLucas De Marchi 	UTS_PROC_HOSTNAME,
18f1ecf068SLucas De Marchi 	UTS_PROC_DOMAINNAME,
19f1ecf068SLucas De Marchi };
20f1ecf068SLucas De Marchi 
2159607db3SSerge E. Hallyn struct user_namespace;
2259607db3SSerge E. Hallyn extern struct user_namespace init_user_ns;
2359607db3SSerge E. Hallyn 
244865ecf1SSerge E. Hallyn struct uts_namespace {
254865ecf1SSerge E. Hallyn 	struct new_utsname name;
2659607db3SSerge E. Hallyn 	struct user_namespace *user_ns;
27f7af3d1cSEric W. Biederman 	struct ucounts *ucounts;
28435d5f4bSAl Viro 	struct ns_common ns;
293859a271SKees Cook } __randomize_layout;
304865ecf1SSerge E. Hallyn extern struct uts_namespace init_uts_ns;
314865ecf1SSerge E. Hallyn 
3258bfdd6dSPavel Emelyanov #ifdef CONFIG_UTS_NS
get_uts_ns(struct uts_namespace * ns)334865ecf1SSerge E. Hallyn static inline void get_uts_ns(struct uts_namespace *ns)
344865ecf1SSerge E. Hallyn {
359a56493fSKirill Tkhai 	refcount_inc(&ns->ns.count);
364865ecf1SSerge E. Hallyn }
374865ecf1SSerge E. Hallyn 
38213dd266SEric W. Biederman extern struct uts_namespace *copy_utsname(unsigned long flags,
39bcf58e72SEric W. Biederman 	struct user_namespace *user_ns, struct uts_namespace *old_ns);
409a56493fSKirill Tkhai extern void free_uts_ns(struct uts_namespace *ns);
414865ecf1SSerge E. Hallyn 
put_uts_ns(struct uts_namespace * ns)424865ecf1SSerge E. Hallyn static inline void put_uts_ns(struct uts_namespace *ns)
434865ecf1SSerge E. Hallyn {
449a56493fSKirill Tkhai 	if (refcount_dec_and_test(&ns->ns.count))
459a56493fSKirill Tkhai 		free_uts_ns(ns);
464865ecf1SSerge E. Hallyn }
473ea056c5SAlexey Dobriyan 
483ea056c5SAlexey Dobriyan void uts_ns_init(void);
4958bfdd6dSPavel Emelyanov #else
get_uts_ns(struct uts_namespace * ns)5058bfdd6dSPavel Emelyanov static inline void get_uts_ns(struct uts_namespace *ns)
5158bfdd6dSPavel Emelyanov {
5258bfdd6dSPavel Emelyanov }
5358bfdd6dSPavel Emelyanov 
put_uts_ns(struct uts_namespace * ns)5458bfdd6dSPavel Emelyanov static inline void put_uts_ns(struct uts_namespace *ns)
5558bfdd6dSPavel Emelyanov {
5658bfdd6dSPavel Emelyanov }
5758bfdd6dSPavel Emelyanov 
copy_utsname(unsigned long flags,struct user_namespace * user_ns,struct uts_namespace * old_ns)5858bfdd6dSPavel Emelyanov static inline struct uts_namespace *copy_utsname(unsigned long flags,
59bcf58e72SEric W. Biederman 	struct user_namespace *user_ns, struct uts_namespace *old_ns)
6058bfdd6dSPavel Emelyanov {
6158bfdd6dSPavel Emelyanov 	if (flags & CLONE_NEWUTS)
6258bfdd6dSPavel Emelyanov 		return ERR_PTR(-EINVAL);
6358bfdd6dSPavel Emelyanov 
64bcf58e72SEric W. Biederman 	return old_ns;
6558bfdd6dSPavel Emelyanov }
663ea056c5SAlexey Dobriyan 
uts_ns_init(void)673ea056c5SAlexey Dobriyan static inline void uts_ns_init(void)
683ea056c5SAlexey Dobriyan {
693ea056c5SAlexey Dobriyan }
7058bfdd6dSPavel Emelyanov #endif
7158bfdd6dSPavel Emelyanov 
72f1ecf068SLucas De Marchi #ifdef CONFIG_PROC_SYSCTL
73f1ecf068SLucas De Marchi extern void uts_proc_notify(enum uts_proc proc);
74f1ecf068SLucas De Marchi #else
uts_proc_notify(enum uts_proc proc)75f1ecf068SLucas De Marchi static inline void uts_proc_notify(enum uts_proc proc)
76f1ecf068SLucas De Marchi {
77f1ecf068SLucas De Marchi }
78f1ecf068SLucas De Marchi #endif
79f1ecf068SLucas De Marchi 
utsname(void)800bdd7aabSSerge E. Hallyn static inline struct new_utsname *utsname(void)
810bdd7aabSSerge E. Hallyn {
824865ecf1SSerge E. Hallyn 	return &current->nsproxy->uts_ns->name;
830bdd7aabSSerge E. Hallyn }
840bdd7aabSSerge E. Hallyn 
init_utsname(void)850bdd7aabSSerge E. Hallyn static inline struct new_utsname *init_utsname(void)
860bdd7aabSSerge E. Hallyn {
874865ecf1SSerge E. Hallyn 	return &init_uts_ns.name;
880bdd7aabSSerge E. Hallyn }
890bdd7aabSSerge E. Hallyn 
901da177e4SLinus Torvalds extern struct rw_semaphore uts_sem;
91b119f13fSCedric Le Goater 
92b119f13fSCedric Le Goater #endif /* _LINUX_UTSNAME_H */
93