Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_UTSNAME_H
0003 #define _LINUX_UTSNAME_H
0004 
0005 
0006 #include <linux/sched.h>
0007 #include <linux/nsproxy.h>
0008 #include <linux/ns_common.h>
0009 #include <linux/err.h>
0010 #include <uapi/linux/utsname.h>
0011 
0012 enum uts_proc {
0013     UTS_PROC_OSTYPE,
0014     UTS_PROC_OSRELEASE,
0015     UTS_PROC_VERSION,
0016     UTS_PROC_HOSTNAME,
0017     UTS_PROC_DOMAINNAME,
0018 };
0019 
0020 struct user_namespace;
0021 extern struct user_namespace init_user_ns;
0022 
0023 struct uts_namespace {
0024     struct new_utsname name;
0025     struct user_namespace *user_ns;
0026     struct ucounts *ucounts;
0027     struct ns_common ns;
0028 } __randomize_layout;
0029 extern struct uts_namespace init_uts_ns;
0030 
0031 #ifdef CONFIG_UTS_NS
0032 static inline void get_uts_ns(struct uts_namespace *ns)
0033 {
0034     refcount_inc(&ns->ns.count);
0035 }
0036 
0037 extern struct uts_namespace *copy_utsname(unsigned long flags,
0038     struct user_namespace *user_ns, struct uts_namespace *old_ns);
0039 extern void free_uts_ns(struct uts_namespace *ns);
0040 
0041 static inline void put_uts_ns(struct uts_namespace *ns)
0042 {
0043     if (refcount_dec_and_test(&ns->ns.count))
0044         free_uts_ns(ns);
0045 }
0046 
0047 void uts_ns_init(void);
0048 #else
0049 static inline void get_uts_ns(struct uts_namespace *ns)
0050 {
0051 }
0052 
0053 static inline void put_uts_ns(struct uts_namespace *ns)
0054 {
0055 }
0056 
0057 static inline struct uts_namespace *copy_utsname(unsigned long flags,
0058     struct user_namespace *user_ns, struct uts_namespace *old_ns)
0059 {
0060     if (flags & CLONE_NEWUTS)
0061         return ERR_PTR(-EINVAL);
0062 
0063     return old_ns;
0064 }
0065 
0066 static inline void uts_ns_init(void)
0067 {
0068 }
0069 #endif
0070 
0071 #ifdef CONFIG_PROC_SYSCTL
0072 extern void uts_proc_notify(enum uts_proc proc);
0073 #else
0074 static inline void uts_proc_notify(enum uts_proc proc)
0075 {
0076 }
0077 #endif
0078 
0079 static inline struct new_utsname *utsname(void)
0080 {
0081     return &current->nsproxy->uts_ns->name;
0082 }
0083 
0084 static inline struct new_utsname *init_utsname(void)
0085 {
0086     return &init_uts_ns.name;
0087 }
0088 
0089 extern struct rw_semaphore uts_sem;
0090 
0091 #endif /* _LINUX_UTSNAME_H */