Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] inotify: add MOVE_SELF event

This adds a MOVE_SELF event to inotify. It is sent whenever the inode
you are watching is moved. We need this event so that we can catch
something like this:

- app1:
watch /etc/mtab

- app2:
cp /etc/mtab /tmp/mtab-work
mv /etc/mtab /etc/mtab~
mv /tmp/mtab-work /etc/mtab

app1 still thinks it's watching /etc/mtab but it's actually watching
/etc/mtab~.

Signed-off-by: John McCutchan <ttb@tentacle.dhs.org>
Signed-off-by: Robert Love <rml@novell.com>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

John McCutchan and committed by
Linus Torvalds
89204c40 0bf955ce

+10 -3
+2 -1
fs/namei.c
··· 2216 2216 error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry); 2217 2217 if (!error) { 2218 2218 const char *new_name = old_dentry->d_name.name; 2219 - fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir, new_dentry->d_inode); 2219 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir, 2220 + new_dentry->d_inode, old_dentry->d_inode); 2220 2221 } 2221 2222 fsnotify_oldname_free(old_name); 2222 2223
+5 -1
include/linux/fsnotify.h
··· 21 21 */ 22 22 static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, 23 23 const char *old_name, const char *new_name, 24 - int isdir, struct inode *target) 24 + int isdir, struct inode *target, struct inode *source) 25 25 { 26 26 u32 cookie = inotify_get_cookie(); 27 27 ··· 40 40 if (target) { 41 41 inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL); 42 42 inotify_inode_is_dead(target); 43 + } 44 + 45 + if (source) { 46 + inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL); 43 47 } 44 48 } 45 49
+3 -1
include/linux/inotify.h
··· 35 35 #define IN_CREATE 0x00000100 /* Subfile was created */ 36 36 #define IN_DELETE 0x00000200 /* Subfile was deleted */ 37 37 #define IN_DELETE_SELF 0x00000400 /* Self was deleted */ 38 + #define IN_MOVE_SELF 0x00000800 /* Self was moved */ 38 39 39 40 /* the following are legal events. they are sent as needed to any watch */ 40 41 #define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */ ··· 57 56 */ 58 57 #define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \ 59 58 IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \ 60 - IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF) 59 + IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \ 60 + IN_MOVE_SELF) 61 61 62 62 #ifdef __KERNEL__ 63 63