mount.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include <linux/mount.h>
  2. #include <linux/seq_file.h>
  3. #include <linux/poll.h>
  4. struct mnt_namespace {
  5. atomic_t count;
  6. unsigned int proc_inum;
  7. struct mount * root;
  8. struct list_head list;
  9. struct user_namespace *user_ns;
  10. u64 seq; /* Sequence number to prevent loops */
  11. wait_queue_head_t poll;
  12. u64 event;
  13. };
  14. struct mnt_pcp {
  15. int mnt_count;
  16. int mnt_writers;
  17. };
  18. struct mountpoint {
  19. struct hlist_node m_hash;
  20. struct dentry *m_dentry;
  21. struct hlist_head m_list;
  22. int m_count;
  23. };
  24. struct mount {
  25. struct hlist_node mnt_hash;
  26. struct mount *mnt_parent;
  27. struct dentry *mnt_mountpoint;
  28. struct vfsmount mnt;
  29. union {
  30. struct rcu_head mnt_rcu;
  31. struct llist_node mnt_llist;
  32. };
  33. #ifdef CONFIG_SMP
  34. struct mnt_pcp __percpu *mnt_pcp;
  35. #else
  36. int mnt_count;
  37. int mnt_writers;
  38. #endif
  39. struct list_head mnt_mounts; /* list of children, anchored here */
  40. struct list_head mnt_child; /* and going through their mnt_child */
  41. struct list_head mnt_instance; /* mount instance on sb->s_mounts */
  42. const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
  43. struct list_head mnt_list;
  44. struct list_head mnt_expire; /* link in fs-specific expiry list */
  45. struct list_head mnt_share; /* circular list of shared mounts */
  46. struct list_head mnt_slave_list;/* list of slave mounts */
  47. struct list_head mnt_slave; /* slave list entry */
  48. struct mount *mnt_master; /* slave is on master->mnt_slave_list */
  49. struct mnt_namespace *mnt_ns; /* containing namespace */
  50. struct mountpoint *mnt_mp; /* where is it mounted */
  51. struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
  52. #ifdef CONFIG_FSNOTIFY
  53. struct hlist_head mnt_fsnotify_marks;
  54. __u32 mnt_fsnotify_mask;
  55. #endif
  56. int mnt_id; /* mount identifier */
  57. int mnt_group_id; /* peer group identifier */
  58. int mnt_expiry_mark; /* true if marked for expiry */
  59. struct hlist_head mnt_pins;
  60. struct path mnt_ex_mountpoint;
  61. };
  62. #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
  63. static inline struct mount *real_mount(struct vfsmount *mnt)
  64. {
  65. return container_of(mnt, struct mount, mnt);
  66. }
  67. static inline int mnt_has_parent(struct mount *mnt)
  68. {
  69. return mnt != mnt->mnt_parent;
  70. }
  71. static inline int is_mounted(struct vfsmount *mnt)
  72. {
  73. /* neither detached nor internal? */
  74. return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
  75. }
  76. extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
  77. extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *);
  78. extern bool legitimize_mnt(struct vfsmount *, unsigned);
  79. extern void __detach_mounts(struct dentry *dentry);
  80. static inline void detach_mounts(struct dentry *dentry)
  81. {
  82. if (!d_mountpoint(dentry))
  83. return;
  84. __detach_mounts(dentry);
  85. }
  86. static inline void get_mnt_ns(struct mnt_namespace *ns)
  87. {
  88. atomic_inc(&ns->count);
  89. }
  90. extern seqlock_t mount_lock;
  91. static inline void lock_mount_hash(void)
  92. {
  93. write_seqlock(&mount_lock);
  94. }
  95. static inline void unlock_mount_hash(void)
  96. {
  97. write_sequnlock(&mount_lock);
  98. }
  99. struct proc_mounts {
  100. struct seq_file m;
  101. struct mnt_namespace *ns;
  102. struct path root;
  103. int (*show)(struct seq_file *, struct vfsmount *);
  104. void *cached_mount;
  105. u64 cached_event;
  106. loff_t cached_index;
  107. };
  108. #define proc_mounts(p) (container_of((p), struct proc_mounts, m))
  109. extern const struct seq_operations mounts_op;
  110. extern bool __is_local_mountpoint(struct dentry *dentry);
  111. static inline bool is_local_mountpoint(struct dentry *dentry)
  112. {
  113. if (!d_mountpoint(dentry))
  114. return false;
  115. return __is_local_mountpoint(dentry);
  116. }