utsname.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef _LINUX_UTSNAME_H
  2. #define _LINUX_UTSNAME_H
  3. #include <linux/sched.h>
  4. #include <linux/kref.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_OSTYPE,
  11. UTS_PROC_OSRELEASE,
  12. UTS_PROC_VERSION,
  13. UTS_PROC_HOSTNAME,
  14. UTS_PROC_DOMAINNAME,
  15. };
  16. struct user_namespace;
  17. extern struct user_namespace init_user_ns;
  18. struct uts_namespace {
  19. struct kref kref;
  20. struct new_utsname name;
  21. struct user_namespace *user_ns;
  22. struct ucounts *ucounts;
  23. struct ns_common ns;
  24. };
  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. kref_get(&ns->kref);
  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 kref *kref);
  34. static inline void put_uts_ns(struct uts_namespace *ns)
  35. {
  36. kref_put(&ns->kref, free_uts_ns);
  37. }
  38. #else
  39. static inline void get_uts_ns(struct uts_namespace *ns)
  40. {
  41. }
  42. static inline void put_uts_ns(struct uts_namespace *ns)
  43. {
  44. }
  45. static inline struct uts_namespace *copy_utsname(unsigned long flags,
  46. struct user_namespace *user_ns, struct uts_namespace *old_ns)
  47. {
  48. if (flags & CLONE_NEWUTS)
  49. return ERR_PTR(-EINVAL);
  50. return old_ns;
  51. }
  52. #endif
  53. #ifdef CONFIG_PROC_SYSCTL
  54. extern void uts_proc_notify(enum uts_proc proc);
  55. #else
  56. static inline void uts_proc_notify(enum uts_proc proc)
  57. {
  58. }
  59. #endif
  60. static inline struct new_utsname *utsname(void)
  61. {
  62. return &current->nsproxy->uts_ns->name;
  63. }
  64. static inline struct new_utsname *init_utsname(void)
  65. {
  66. return &init_uts_ns.name;
  67. }
  68. extern struct rw_semaphore uts_sem;
  69. #endif /* _LINUX_UTSNAME_H */