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