utsname.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef _LINUX_UTSNAME_H
  2. #define _LINUX_UTSNAME_H
  3. #define __OLD_UTS_LEN 8
  4. struct oldold_utsname {
  5. char sysname[9];
  6. char nodename[9];
  7. char release[9];
  8. char version[9];
  9. char machine[9];
  10. };
  11. #define __NEW_UTS_LEN 64
  12. struct old_utsname {
  13. char sysname[65];
  14. char nodename[65];
  15. char release[65];
  16. char version[65];
  17. char machine[65];
  18. };
  19. struct new_utsname {
  20. char sysname[__NEW_UTS_LEN + 1];
  21. char nodename[__NEW_UTS_LEN + 1];
  22. char release[__NEW_UTS_LEN + 1];
  23. char version[__NEW_UTS_LEN + 1];
  24. char machine[__NEW_UTS_LEN + 1];
  25. char domainname[__NEW_UTS_LEN + 1];
  26. };
  27. #ifdef __KERNEL__
  28. #include <linux/sched.h>
  29. #include <linux/kref.h>
  30. #include <linux/nsproxy.h>
  31. #include <linux/err.h>
  32. struct uts_namespace {
  33. struct kref kref;
  34. struct new_utsname name;
  35. };
  36. extern struct uts_namespace init_uts_ns;
  37. #ifdef CONFIG_UTS_NS
  38. static inline void get_uts_ns(struct uts_namespace *ns)
  39. {
  40. kref_get(&ns->kref);
  41. }
  42. extern struct uts_namespace *copy_utsname(unsigned long flags,
  43. struct uts_namespace *ns);
  44. extern void free_uts_ns(struct kref *kref);
  45. static inline void put_uts_ns(struct uts_namespace *ns)
  46. {
  47. kref_put(&ns->kref, free_uts_ns);
  48. }
  49. #else
  50. static inline void get_uts_ns(struct uts_namespace *ns)
  51. {
  52. }
  53. static inline void put_uts_ns(struct uts_namespace *ns)
  54. {
  55. }
  56. static inline struct uts_namespace *copy_utsname(unsigned long flags,
  57. struct uts_namespace *ns)
  58. {
  59. if (flags & CLONE_NEWUTS)
  60. return ERR_PTR(-EINVAL);
  61. return ns;
  62. }
  63. #endif
  64. static inline struct new_utsname *utsname(void)
  65. {
  66. return &current->nsproxy->uts_ns->name;
  67. }
  68. static inline struct new_utsname *init_utsname(void)
  69. {
  70. return &init_uts_ns.name;
  71. }
  72. extern struct rw_semaphore uts_sem;
  73. #endif /* __KERNEL__ */
  74. #endif /* _LINUX_UTSNAME_H */