inotify.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  2. * Inode based directory notification for Linux
  3. *
  4. * Copyright (C) 2005 John McCutchan
  5. */
  6. #ifndef _LINUX_INOTIFY_H
  7. #define _LINUX_INOTIFY_H
  8. /* For O_CLOEXEC */
  9. #include <linux/fcntl.h>
  10. #include <linux/types.h>
  11. /*
  12. * struct inotify_event - structure read from the inotify device for each event
  13. *
  14. * When you are watching a directory, you will receive the filename for events
  15. * such as IN_CREATE, IN_DELETE, IN_OPEN, IN_CLOSE, ..., relative to the wd.
  16. */
  17. struct inotify_event {
  18. __s32 wd; /* watch descriptor */
  19. __u32 mask; /* watch mask */
  20. __u32 cookie; /* cookie to synchronize two events */
  21. __u32 len; /* length (including nulls) of name */
  22. char name[0]; /* stub for possible name */
  23. };
  24. /* the following are legal, implemented events that user-space can watch for */
  25. #define IN_ACCESS 0x00000001 /* File was accessed */
  26. #define IN_MODIFY 0x00000002 /* File was modified */
  27. #define IN_ATTRIB 0x00000004 /* Metadata changed */
  28. #define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */
  29. #define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */
  30. #define IN_OPEN 0x00000020 /* File was opened */
  31. #define IN_MOVED_FROM 0x00000040 /* File was moved from X */
  32. #define IN_MOVED_TO 0x00000080 /* File was moved to Y */
  33. #define IN_CREATE 0x00000100 /* Subfile was created */
  34. #define IN_DELETE 0x00000200 /* Subfile was deleted */
  35. #define IN_DELETE_SELF 0x00000400 /* Self was deleted */
  36. #define IN_MOVE_SELF 0x00000800 /* Self was moved */
  37. /* the following are legal events. they are sent as needed to any watch */
  38. #define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
  39. #define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */
  40. #define IN_IGNORED 0x00008000 /* File was ignored */
  41. /* helper events */
  42. #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */
  43. #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */
  44. /* special flags */
  45. #define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */
  46. #define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */
  47. #define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */
  48. #define IN_ISDIR 0x40000000 /* event occurred against dir */
  49. #define IN_ONESHOT 0x80000000 /* only send event once */
  50. /*
  51. * All of the events - we build the list by hand so that we can add flags in
  52. * the future and not break backward compatibility. Apps will get only the
  53. * events that they originally wanted. Be sure to add new events here!
  54. */
  55. #define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
  56. IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
  57. IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \
  58. IN_MOVE_SELF)
  59. /* Flags for sys_inotify_init1. */
  60. #define IN_CLOEXEC O_CLOEXEC
  61. #ifdef __KERNEL__
  62. #include <linux/dcache.h>
  63. #include <linux/fs.h>
  64. /*
  65. * struct inotify_watch - represents a watch request on a specific inode
  66. *
  67. * h_list is protected by ih->mutex of the associated inotify_handle.
  68. * i_list, mask are protected by inode->inotify_mutex of the associated inode.
  69. * ih, inode, and wd are never written to once the watch is created.
  70. *
  71. * Callers must use the established inotify interfaces to access inotify_watch
  72. * contents. The content of this structure is private to the inotify
  73. * implementation.
  74. */
  75. struct inotify_watch {
  76. struct list_head h_list; /* entry in inotify_handle's list */
  77. struct list_head i_list; /* entry in inode's list */
  78. atomic_t count; /* reference count */
  79. struct inotify_handle *ih; /* associated inotify handle */
  80. struct inode *inode; /* associated inode */
  81. __s32 wd; /* watch descriptor */
  82. __u32 mask; /* event mask for this watch */
  83. };
  84. struct inotify_operations {
  85. void (*handle_event)(struct inotify_watch *, u32, u32, u32,
  86. const char *, struct inode *);
  87. void (*destroy_watch)(struct inotify_watch *);
  88. };
  89. #ifdef CONFIG_INOTIFY
  90. /* Kernel API for producing events */
  91. extern void inotify_d_instantiate(struct dentry *, struct inode *);
  92. extern void inotify_d_move(struct dentry *);
  93. extern void inotify_inode_queue_event(struct inode *, __u32, __u32,
  94. const char *, struct inode *);
  95. extern void inotify_dentry_parent_queue_event(struct dentry *, __u32, __u32,
  96. const char *);
  97. extern void inotify_unmount_inodes(struct list_head *);
  98. extern void inotify_inode_is_dead(struct inode *);
  99. extern u32 inotify_get_cookie(void);
  100. /* Kernel Consumer API */
  101. extern struct inotify_handle *inotify_init(const struct inotify_operations *);
  102. extern void inotify_init_watch(struct inotify_watch *);
  103. extern void inotify_destroy(struct inotify_handle *);
  104. extern __s32 inotify_find_watch(struct inotify_handle *, struct inode *,
  105. struct inotify_watch **);
  106. extern __s32 inotify_find_update_watch(struct inotify_handle *, struct inode *,
  107. u32);
  108. extern __s32 inotify_add_watch(struct inotify_handle *, struct inotify_watch *,
  109. struct inode *, __u32);
  110. extern __s32 inotify_clone_watch(struct inotify_watch *, struct inotify_watch *);
  111. extern void inotify_evict_watch(struct inotify_watch *);
  112. extern int inotify_rm_watch(struct inotify_handle *, struct inotify_watch *);
  113. extern int inotify_rm_wd(struct inotify_handle *, __u32);
  114. extern void inotify_remove_watch_locked(struct inotify_handle *,
  115. struct inotify_watch *);
  116. extern void get_inotify_watch(struct inotify_watch *);
  117. extern void put_inotify_watch(struct inotify_watch *);
  118. #else
  119. static inline void inotify_d_instantiate(struct dentry *dentry,
  120. struct inode *inode)
  121. {
  122. }
  123. static inline void inotify_d_move(struct dentry *dentry)
  124. {
  125. }
  126. static inline void inotify_inode_queue_event(struct inode *inode,
  127. __u32 mask, __u32 cookie,
  128. const char *filename,
  129. struct inode *n_inode)
  130. {
  131. }
  132. static inline void inotify_dentry_parent_queue_event(struct dentry *dentry,
  133. __u32 mask, __u32 cookie,
  134. const char *filename)
  135. {
  136. }
  137. static inline void inotify_unmount_inodes(struct list_head *list)
  138. {
  139. }
  140. static inline void inotify_inode_is_dead(struct inode *inode)
  141. {
  142. }
  143. static inline u32 inotify_get_cookie(void)
  144. {
  145. return 0;
  146. }
  147. static inline struct inotify_handle *inotify_init(const struct inotify_operations *ops)
  148. {
  149. return ERR_PTR(-EOPNOTSUPP);
  150. }
  151. static inline void inotify_init_watch(struct inotify_watch *watch)
  152. {
  153. }
  154. static inline void inotify_destroy(struct inotify_handle *ih)
  155. {
  156. }
  157. static inline __s32 inotify_find_watch(struct inotify_handle *ih, struct inode *inode,
  158. struct inotify_watch **watchp)
  159. {
  160. return -EOPNOTSUPP;
  161. }
  162. static inline __s32 inotify_find_update_watch(struct inotify_handle *ih,
  163. struct inode *inode, u32 mask)
  164. {
  165. return -EOPNOTSUPP;
  166. }
  167. static inline __s32 inotify_add_watch(struct inotify_handle *ih,
  168. struct inotify_watch *watch,
  169. struct inode *inode, __u32 mask)
  170. {
  171. return -EOPNOTSUPP;
  172. }
  173. static inline int inotify_rm_watch(struct inotify_handle *ih,
  174. struct inotify_watch *watch)
  175. {
  176. return -EOPNOTSUPP;
  177. }
  178. static inline int inotify_rm_wd(struct inotify_handle *ih, __u32 wd)
  179. {
  180. return -EOPNOTSUPP;
  181. }
  182. static inline void inotify_remove_watch_locked(struct inotify_handle *ih,
  183. struct inotify_watch *watch)
  184. {
  185. }
  186. static inline void get_inotify_watch(struct inotify_watch *watch)
  187. {
  188. }
  189. static inline void put_inotify_watch(struct inotify_watch *watch)
  190. {
  191. }
  192. #endif /* CONFIG_INOTIFY */
  193. #endif /* __KERNEL __ */
  194. #endif /* _LINUX_INOTIFY_H */