utsname.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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/err.h>
  7. #include <uapi/linux/utsname.h>
  8. enum uts_proc {
  9. UTS_PROC_OSTYPE,
  10. UTS_PROC_OSRELEASE,
  11. UTS_PROC_VERSION,
  12. UTS_PROC_HOSTNAME,
  13. UTS_PROC_DOMAINNAME,
  14. };
  15. struct user_namespace;
  16. extern struct user_namespace init_user_ns;
  17. struct uts_namespace {
  18. struct kref kref;
  19. struct new_utsname name;
  20. struct user_namespace *user_ns;
  21. unsigned int proc_inum;
  22. };
  23. extern struct uts_namespace init_uts_ns;
  24. #ifdef CONFIG_UTS_NS
  25. static inline void get_uts_ns(struct uts_namespace *ns)
  26. {
  27. kref_get(&ns->kref);
  28. }
  29. extern struct uts_namespace *copy_utsname(unsigned long flags,
  30. struct user_namespace *user_ns, struct uts_namespace *old_ns);
  31. extern void free_uts_ns(struct kref *kref);
  32. static inline void put_uts_ns(struct uts_namespace *ns)
  33. {
  34. kref_put(&ns->kref, free_uts_ns);
  35. }
  36. #else
  37. static inline void get_uts_ns(struct uts_namespace *ns)
  38. {
  39. }
  40. static inline void put_uts_ns(struct uts_namespace *ns)
  41. {
  42. }
  43. static inline struct uts_namespace *copy_utsname(unsigned long flags,
  44. struct user_namespace *user_ns, struct uts_namespace *old_ns)
  45. {
  46. if (flags & CLONE_NEWUTS)
  47. return ERR_PTR(-EINVAL);
  48. return old_ns;
  49. }
  50. #endif
  51. #ifdef CONFIG_PROC_SYSCTL
  52. extern void uts_proc_notify(enum uts_proc proc);
  53. #else
  54. static inline void uts_proc_notify(enum uts_proc proc)
  55. {
  56. }
  57. #endif
  58. static inline struct new_utsname *utsname(void)
  59. {
  60. return &current->nsproxy->uts_ns->name;
  61. }
  62. static inline struct new_utsname *init_utsname(void)
  63. {
  64. return &init_uts_ns.name;
  65. }
  66. extern struct rw_semaphore uts_sem;
  67. #endif /* _LINUX_UTSNAME_H */