proc_ns.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * procfs namespace bits
  3. */
  4. #ifndef _LINUX_PROC_NS_H
  5. #define _LINUX_PROC_NS_H
  6. #include <linux/ns_common.h>
  7. struct pid_namespace;
  8. struct nsproxy;
  9. struct path;
  10. struct proc_ns_operations {
  11. const char *name;
  12. int type;
  13. struct ns_common *(*get)(struct task_struct *task);
  14. void (*put)(struct ns_common *ns);
  15. int (*install)(struct nsproxy *nsproxy, struct ns_common *ns);
  16. };
  17. extern const struct proc_ns_operations netns_operations;
  18. extern const struct proc_ns_operations utsns_operations;
  19. extern const struct proc_ns_operations ipcns_operations;
  20. extern const struct proc_ns_operations pidns_operations;
  21. extern const struct proc_ns_operations userns_operations;
  22. extern const struct proc_ns_operations mntns_operations;
  23. /*
  24. * We always define these enumerators
  25. */
  26. enum {
  27. PROC_ROOT_INO = 1,
  28. PROC_IPC_INIT_INO = 0xEFFFFFFFU,
  29. PROC_UTS_INIT_INO = 0xEFFFFFFEU,
  30. PROC_USER_INIT_INO = 0xEFFFFFFDU,
  31. PROC_PID_INIT_INO = 0xEFFFFFFCU,
  32. };
  33. #ifdef CONFIG_PROC_FS
  34. extern int pid_ns_prepare_proc(struct pid_namespace *ns);
  35. extern void pid_ns_release_proc(struct pid_namespace *ns);
  36. extern int proc_alloc_inum(unsigned int *pino);
  37. extern void proc_free_inum(unsigned int inum);
  38. #else /* CONFIG_PROC_FS */
  39. static inline int pid_ns_prepare_proc(struct pid_namespace *ns) { return 0; }
  40. static inline void pid_ns_release_proc(struct pid_namespace *ns) {}
  41. static inline int proc_alloc_inum(unsigned int *inum)
  42. {
  43. *inum = 1;
  44. return 0;
  45. }
  46. static inline void proc_free_inum(unsigned int inum) {}
  47. #endif /* CONFIG_PROC_FS */
  48. static inline int ns_alloc_inum(struct ns_common *ns)
  49. {
  50. atomic_long_set(&ns->stashed, 0);
  51. return proc_alloc_inum(&ns->inum);
  52. }
  53. #define ns_free_inum(ns) proc_free_inum((ns)->inum)
  54. extern struct file *proc_ns_fget(int fd);
  55. #define get_proc_ns(inode) ((struct ns_common *)(inode)->i_private)
  56. extern void *ns_get_path(struct path *path, struct task_struct *task,
  57. const struct proc_ns_operations *ns_ops);
  58. extern int ns_get_name(char *buf, size_t size, struct task_struct *task,
  59. const struct proc_ns_operations *ns_ops);
  60. extern void nsfs_init(void);
  61. #endif /* _LINUX_PROC_NS_H */