Skip to content

Commit 89204c4

Browse files
John McCutchanLinus Torvalds
authored andcommitted
[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>
1 parent 0bf955c commit 89204c4

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎fs/namei.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2216,7 +2216,8 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
22162216
error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
22172217
if (!error) {
22182218
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);
22202221
}
22212222
fsnotify_oldname_free(old_name);
22222223

‎include/linux/fsnotify.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
2323
const char *old_name, const char *new_name,
24-
int isdir, struct inode *target)
24+
int isdir, struct inode *target, struct inode *source)
2525
{
2626
u32 cookie = inotify_get_cookie();
2727

@@ -41,6 +41,10 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir,
4141
inotify_inode_queue_event(target, IN_DELETE_SELF, 0, NULL);
4242
inotify_inode_is_dead(target);
4343
}
44+
45+
if (source) {
46+
inotify_inode_queue_event(source, IN_MOVE_SELF, 0, NULL);
47+
}
4448
}
4549

4650
/*

‎include/linux/inotify.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct inotify_event {
3535
#define IN_CREATE 0x00000100 /* Subfile was created */
3636
#define IN_DELETE 0x00000200 /* Subfile was deleted */
3737
#define IN_DELETE_SELF 0x00000400 /* Self was deleted */
38+
#define IN_MOVE_SELF 0x00000800 /* Self was moved */
3839

3940
/* the following are legal events. they are sent as needed to any watch */
4041
#define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */
@@ -56,7 +57,8 @@ struct inotify_event {
5657
*/
5758
#define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
5859
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \
59-
IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF)
60+
IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \
61+
IN_MOVE_SELF)
6062

6163
#ifdef __KERNEL__
6264

0 commit comments

Comments
 (0)