~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/fsnotify.h

Version: ~ [ linux-5.13-rc7 ] ~ [ linux-5.12.12 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.45 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.127 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.195 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.237 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.273 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.273 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef _LINUX_FS_NOTIFY_H
  3 #define _LINUX_FS_NOTIFY_H
  4 
  5 /*
  6  * include/linux/fsnotify.h - generic hooks for filesystem notification, to
  7  * reduce in-source duplication from both dnotify and inotify.
  8  *
  9  * We don't compile any of this away in some complicated menagerie of ifdefs.
 10  * Instead, we rely on the code inside to optimize away as needed.
 11  *
 12  * (C) Copyright 2005 Robert Love
 13  */
 14 
 15 #include <linux/fsnotify_backend.h>
 16 #include <linux/audit.h>
 17 #include <linux/slab.h>
 18 #include <linux/bug.h>
 19 
 20 /* Notify this dentry's parent about a child's events. */
 21 static inline int fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask)
 22 {
 23         if (!dentry)
 24                 dentry = path->dentry;
 25 
 26         return __fsnotify_parent(path, dentry, mask);
 27 }
 28 
 29 /* simple call site for access decisions */
 30 static inline int fsnotify_perm(struct file *file, int mask)
 31 {
 32         const struct path *path = &file->f_path;
 33         struct inode *inode = file_inode(file);
 34         __u32 fsnotify_mask = 0;
 35         int ret;
 36 
 37         if (file->f_mode & FMODE_NONOTIFY)
 38                 return 0;
 39         if (!(mask & (MAY_READ | MAY_OPEN)))
 40                 return 0;
 41         if (mask & MAY_OPEN)
 42                 fsnotify_mask = FS_OPEN_PERM;
 43         else if (mask & MAY_READ)
 44                 fsnotify_mask = FS_ACCESS_PERM;
 45         else
 46                 BUG();
 47 
 48         ret = fsnotify_parent(path, NULL, fsnotify_mask);
 49         if (ret)
 50                 return ret;
 51 
 52         return fsnotify(inode, fsnotify_mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
 53 }
 54 
 55 /*
 56  * fsnotify_link_count - inode's link count changed
 57  */
 58 static inline void fsnotify_link_count(struct inode *inode)
 59 {
 60         fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
 61 }
 62 
 63 /*
 64  * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir
 65  */
 66 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
 67                                  const unsigned char *old_name,
 68                                  int isdir, struct inode *target, struct dentry *moved)
 69 {
 70         struct inode *source = moved->d_inode;
 71         u32 fs_cookie = fsnotify_get_cookie();
 72         __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM);
 73         __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO);
 74         const unsigned char *new_name = moved->d_name.name;
 75 
 76         if (old_dir == new_dir)
 77                 old_dir_mask |= FS_DN_RENAME;
 78 
 79         if (isdir) {
 80                 old_dir_mask |= FS_ISDIR;
 81                 new_dir_mask |= FS_ISDIR;
 82         }
 83 
 84         fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name,
 85                  fs_cookie);
 86         fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name,
 87                  fs_cookie);
 88 
 89         if (target)
 90                 fsnotify_link_count(target);
 91 
 92         if (source)
 93                 fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0);
 94         audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE);
 95 }
 96 
 97 /*
 98  * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
 99  */
100 static inline void fsnotify_inode_delete(struct inode *inode)
101 {
102         __fsnotify_inode_delete(inode);
103 }
104 
105 /*
106  * fsnotify_vfsmount_delete - a vfsmount is being destroyed, clean up is needed
107  */
108 static inline void fsnotify_vfsmount_delete(struct vfsmount *mnt)
109 {
110         __fsnotify_vfsmount_delete(mnt);
111 }
112 
113 /*
114  * fsnotify_nameremove - a filename was removed from a directory
115  */
116 static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
117 {
118         __u32 mask = FS_DELETE;
119 
120         if (isdir)
121                 mask |= FS_ISDIR;
122 
123         fsnotify_parent(NULL, dentry, mask);
124 }
125 
126 /*
127  * fsnotify_inoderemove - an inode is going away
128  */
129 static inline void fsnotify_inoderemove(struct inode *inode)
130 {
131         fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
132         __fsnotify_inode_delete(inode);
133 }
134 
135 /*
136  * fsnotify_create - 'name' was linked in
137  */
138 static inline void fsnotify_create(struct inode *inode, struct dentry *dentry)
139 {
140         audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
141 
142         fsnotify(inode, FS_CREATE, dentry->d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
143 }
144 
145 /*
146  * fsnotify_link - new hardlink in 'inode' directory
147  * Note: We have to pass also the linked inode ptr as some filesystems leave
148  *   new_dentry->d_inode NULL and instantiate inode pointer later
149  */
150 static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct dentry *new_dentry)
151 {
152         fsnotify_link_count(inode);
153         audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE);
154 
155         fsnotify(dir, FS_CREATE, inode, FSNOTIFY_EVENT_INODE, new_dentry->d_name.name, 0);
156 }
157 
158 /*
159  * fsnotify_mkdir - directory 'name' was created
160  */
161 static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry)
162 {
163         __u32 mask = (FS_CREATE | FS_ISDIR);
164         struct inode *d_inode = dentry->d_inode;
165 
166         audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE);
167 
168         fsnotify(inode, mask, d_inode, FSNOTIFY_EVENT_INODE, dentry->d_name.name, 0);
169 }
170 
171 /*
172  * fsnotify_access - file was read
173  */
174 static inline void fsnotify_access(struct file *file)
175 {
176         const struct path *path = &file->f_path;
177         struct inode *inode = file_inode(file);
178         __u32 mask = FS_ACCESS;
179 
180         if (S_ISDIR(inode->i_mode))
181                 mask |= FS_ISDIR;
182 
183         if (!(file->f_mode & FMODE_NONOTIFY)) {
184                 fsnotify_parent(path, NULL, mask);
185                 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
186         }
187 }
188 
189 /*
190  * fsnotify_modify - file was modified
191  */
192 static inline void fsnotify_modify(struct file *file)
193 {
194         const struct path *path = &file->f_path;
195         struct inode *inode = file_inode(file);
196         __u32 mask = FS_MODIFY;
197 
198         if (S_ISDIR(inode->i_mode))
199                 mask |= FS_ISDIR;
200 
201         if (!(file->f_mode & FMODE_NONOTIFY)) {
202                 fsnotify_parent(path, NULL, mask);
203                 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
204         }
205 }
206 
207 /*
208  * fsnotify_open - file was opened
209  */
210 static inline void fsnotify_open(struct file *file)
211 {
212         const struct path *path = &file->f_path;
213         struct inode *inode = file_inode(file);
214         __u32 mask = FS_OPEN;
215 
216         if (S_ISDIR(inode->i_mode))
217                 mask |= FS_ISDIR;
218 
219         fsnotify_parent(path, NULL, mask);
220         fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
221 }
222 
223 /*
224  * fsnotify_close - file was closed
225  */
226 static inline void fsnotify_close(struct file *file)
227 {
228         const struct path *path = &file->f_path;
229         struct inode *inode = file_inode(file);
230         fmode_t mode = file->f_mode;
231         __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;
232 
233         if (S_ISDIR(inode->i_mode))
234                 mask |= FS_ISDIR;
235 
236         if (!(file->f_mode & FMODE_NONOTIFY)) {
237                 fsnotify_parent(path, NULL, mask);
238                 fsnotify(inode, mask, path, FSNOTIFY_EVENT_PATH, NULL, 0);
239         }
240 }
241 
242 /*
243  * fsnotify_xattr - extended attributes were changed
244  */
245 static inline void fsnotify_xattr(struct dentry *dentry)
246 {
247         struct inode *inode = dentry->d_inode;
248         __u32 mask = FS_ATTRIB;
249 
250         if (S_ISDIR(inode->i_mode))
251                 mask |= FS_ISDIR;
252 
253         fsnotify_parent(NULL, dentry, mask);
254         fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
255 }
256 
257 /*
258  * fsnotify_change - notify_change event.  file was modified and/or metadata
259  * was changed.
260  */
261 static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
262 {
263         struct inode *inode = dentry->d_inode;
264         __u32 mask = 0;
265 
266         if (ia_valid & ATTR_UID)
267                 mask |= FS_ATTRIB;
268         if (ia_valid & ATTR_GID)
269                 mask |= FS_ATTRIB;
270         if (ia_valid & ATTR_SIZE)
271                 mask |= FS_MODIFY;
272 
273         /* both times implies a utime(s) call */
274         if ((ia_valid & (ATTR_ATIME | ATTR_MTIME)) == (ATTR_ATIME | ATTR_MTIME))
275                 mask |= FS_ATTRIB;
276         else if (ia_valid & ATTR_ATIME)
277                 mask |= FS_ACCESS;
278         else if (ia_valid & ATTR_MTIME)
279                 mask |= FS_MODIFY;
280 
281         if (ia_valid & ATTR_MODE)
282                 mask |= FS_ATTRIB;
283 
284         if (mask) {
285                 if (S_ISDIR(inode->i_mode))
286                         mask |= FS_ISDIR;
287 
288                 fsnotify_parent(NULL, dentry, mask);
289                 fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0);
290         }
291 }
292 
293 #endif  /* _LINUX_FS_NOTIFY_H */
294 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp