utsname.h 1.8 KB

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