nsfs.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef __LINUX_NSFS_H
  3. #define __LINUX_NSFS_H
  4. #include <linux/ioctl.h>
  5. #include <linux/types.h>
  6. #define NSIO 0xb7
  7. /* Returns a file descriptor that refers to an owning user namespace */
  8. #define NS_GET_USERNS _IO(NSIO, 0x1)
  9. /* Returns a file descriptor that refers to a parent namespace */
  10. #define NS_GET_PARENT _IO(NSIO, 0x2)
  11. /* Returns the type of namespace (CLONE_NEW* value) referred to by
  12. file descriptor */
  13. #define NS_GET_NSTYPE _IO(NSIO, 0x3)
  14. /* Get owner UID (in the caller's user namespace) for a user namespace */
  15. #define NS_GET_OWNER_UID _IO(NSIO, 0x4)
  16. /* Translate pid from target pid namespace into the caller's pid namespace. */
  17. #define NS_GET_PID_FROM_PIDNS _IOR(NSIO, 0x6, int)
  18. /* Return thread-group leader id of pid in the callers pid namespace. */
  19. #define NS_GET_TGID_FROM_PIDNS _IOR(NSIO, 0x7, int)
  20. /* Translate pid from caller's pid namespace into a target pid namespace. */
  21. #define NS_GET_PID_IN_PIDNS _IOR(NSIO, 0x8, int)
  22. /* Return thread-group leader id of pid in the target pid namespace. */
  23. #define NS_GET_TGID_IN_PIDNS _IOR(NSIO, 0x9, int)
  24. struct mnt_ns_info {
  25. __u32 size;
  26. __u32 nr_mounts;
  27. __u64 mnt_ns_id;
  28. };
  29. #define MNT_NS_INFO_SIZE_VER0 16 /* size of first published struct */
  30. /* Get information about namespace. */
  31. #define NS_MNT_GET_INFO _IOR(NSIO, 10, struct mnt_ns_info)
  32. /* Get next namespace. */
  33. #define NS_MNT_GET_NEXT _IOR(NSIO, 11, struct mnt_ns_info)
  34. /* Get previous namespace. */
  35. #define NS_MNT_GET_PREV _IOR(NSIO, 12, struct mnt_ns_info)
  36. /* Retrieve namespace identifiers. */
  37. #define NS_GET_MNTNS_ID _IOR(NSIO, 5, __u64)
  38. #define NS_GET_ID _IOR(NSIO, 13, __u64)
  39. enum init_ns_ino {
  40. IPC_NS_INIT_INO = 0xEFFFFFFFU,
  41. UTS_NS_INIT_INO = 0xEFFFFFFEU,
  42. USER_NS_INIT_INO = 0xEFFFFFFDU,
  43. PID_NS_INIT_INO = 0xEFFFFFFCU,
  44. CGROUP_NS_INIT_INO = 0xEFFFFFFBU,
  45. TIME_NS_INIT_INO = 0xEFFFFFFAU,
  46. NET_NS_INIT_INO = 0xEFFFFFF9U,
  47. MNT_NS_INIT_INO = 0xEFFFFFF8U,
  48. #ifdef __KERNEL__
  49. MNT_NS_ANON_INO = 0xEFFFFFF7U,
  50. #endif
  51. };
  52. struct nsfs_file_handle {
  53. __u64 ns_id;
  54. __u32 ns_type;
  55. __u32 ns_inum;
  56. };
  57. #define NSFS_FILE_HANDLE_SIZE_VER0 16 /* sizeof first published struct */
  58. #define NSFS_FILE_HANDLE_SIZE_LATEST sizeof(struct nsfs_file_handle) /* sizeof latest published struct */
  59. enum init_ns_id {
  60. IPC_NS_INIT_ID = 1ULL,
  61. UTS_NS_INIT_ID = 2ULL,
  62. USER_NS_INIT_ID = 3ULL,
  63. PID_NS_INIT_ID = 4ULL,
  64. CGROUP_NS_INIT_ID = 5ULL,
  65. TIME_NS_INIT_ID = 6ULL,
  66. NET_NS_INIT_ID = 7ULL,
  67. MNT_NS_INIT_ID = 8ULL,
  68. #ifdef __KERNEL__
  69. NS_LAST_INIT_ID = MNT_NS_INIT_ID,
  70. #endif
  71. };
  72. enum ns_type {
  73. TIME_NS = (1ULL << 7), /* CLONE_NEWTIME */
  74. MNT_NS = (1ULL << 17), /* CLONE_NEWNS */
  75. CGROUP_NS = (1ULL << 25), /* CLONE_NEWCGROUP */
  76. UTS_NS = (1ULL << 26), /* CLONE_NEWUTS */
  77. IPC_NS = (1ULL << 27), /* CLONE_NEWIPC */
  78. USER_NS = (1ULL << 28), /* CLONE_NEWUSER */
  79. PID_NS = (1ULL << 29), /* CLONE_NEWPID */
  80. NET_NS = (1ULL << 30), /* CLONE_NEWNET */
  81. };
  82. /**
  83. * struct ns_id_req - namespace ID request structure
  84. * @size: size of this structure
  85. * @spare: reserved for future use
  86. * @filter: filter mask
  87. * @ns_id: last namespace id
  88. * @user_ns_id: owning user namespace ID
  89. *
  90. * Structure for passing namespace ID and miscellaneous parameters to
  91. * statns(2) and listns(2).
  92. *
  93. * For statns(2) @param represents the request mask.
  94. * For listns(2) @param represents the last listed mount id (or zero).
  95. */
  96. struct ns_id_req {
  97. __u32 size;
  98. __u32 spare;
  99. __u64 ns_id;
  100. struct /* listns */ {
  101. __u32 ns_type;
  102. __u32 spare2;
  103. __u64 user_ns_id;
  104. };
  105. };
  106. /*
  107. * Special @user_ns_id value that can be passed to listns()
  108. */
  109. #define LISTNS_CURRENT_USER 0xffffffffffffffff /* Caller's userns */
  110. /* List of all ns_id_req versions. */
  111. #define NS_ID_REQ_SIZE_VER0 32 /* sizeof first published struct */
  112. #endif /* __LINUX_NSFS_H */