proc_ns.h 2.0 KB

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