utsname.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 user_namespace;
  33. extern struct user_namespace init_user_ns;
  34. struct uts_namespace {
  35. struct kref kref;
  36. struct new_utsname name;
  37. struct user_namespace *user_ns;
  38. };
  39. extern struct uts_namespace init_uts_ns;
  40. #ifdef CONFIG_UTS_NS
  41. static inline void get_uts_ns(struct uts_namespace *ns)
  42. {
  43. kref_get(&ns->kref);
  44. }
  45. extern struct uts_namespace *copy_utsname(unsigned long flags,
  46. struct uts_namespace *ns);
  47. extern void free_uts_ns(struct kref *kref);
  48. static inline void put_uts_ns(struct uts_namespace *ns)
  49. {
  50. kref_put(&ns->kref, free_uts_ns);
  51. }
  52. #else
  53. static inline void get_uts_ns(struct uts_namespace *ns)
  54. {
  55. }
  56. static inline void put_uts_ns(struct uts_namespace *ns)
  57. {
  58. }
  59. static inline struct uts_namespace *copy_utsname(unsigned long flags,
  60. struct uts_namespace *ns)
  61. {
  62. if (flags & CLONE_NEWUTS)
  63. return ERR_PTR(-EINVAL);
  64. return ns;
  65. }
  66. #endif
  67. static inline struct new_utsname *utsname(void)
  68. {
  69. return &current->nsproxy->uts_ns->name;
  70. }
  71. static inline struct new_utsname *init_utsname(void)
  72. {
  73. return &init_uts_ns.name;
  74. }
  75. extern struct rw_semaphore uts_sem;
  76. #endif /* __KERNEL__ */
  77. #endif /* _LINUX_UTSNAME_H */