utsname.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. };
  22. extern struct uts_namespace init_uts_ns;
  23. #ifdef CONFIG_UTS_NS
  24. static inline void get_uts_ns(struct uts_namespace *ns)
  25. {
  26. kref_get(&ns->kref);
  27. }
  28. extern struct uts_namespace *copy_utsname(unsigned long flags,
  29. struct user_namespace *user_ns, struct uts_namespace *old_ns);
  30. extern void free_uts_ns(struct kref *kref);
  31. static inline void put_uts_ns(struct uts_namespace *ns)
  32. {
  33. kref_put(&ns->kref, free_uts_ns);
  34. }
  35. #else
  36. static inline void get_uts_ns(struct uts_namespace *ns)
  37. {
  38. }
  39. static inline void put_uts_ns(struct uts_namespace *ns)
  40. {
  41. }
  42. static inline struct uts_namespace *copy_utsname(unsigned long flags,
  43. struct user_namespace *user_ns, struct uts_namespace *old_ns)
  44. {
  45. if (flags & CLONE_NEWUTS)
  46. return ERR_PTR(-EINVAL);
  47. return old_ns;
  48. }
  49. #endif
  50. #ifdef CONFIG_PROC_SYSCTL
  51. extern void uts_proc_notify(enum uts_proc proc);
  52. #else
  53. static inline void uts_proc_notify(enum uts_proc proc)
  54. {
  55. }
  56. #endif
  57. static inline struct new_utsname *utsname(void)
  58. {
  59. return &current->nsproxy->uts_ns->name;
  60. }
  61. static inline struct new_utsname *init_utsname(void)
  62. {
  63. return &init_uts_ns.name;
  64. }
  65. extern struct rw_semaphore uts_sem;
  66. #endif /* _LINUX_UTSNAME_H */