Skip to contentSkip to conversation

inotify_add_watch_at

PATCH In review [email protected] 2 participants 5 messages Sep 22, 2010 – Sep 23, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover inotify_add_watch_at

I had use for this system call recently when I was trying to monitor a lockfile to see when it disappeared. Its semantics are as you'd expect; it has over inotify_add_watch what openat(2) has over open(2).

Currently compile-tested only, and missing hookups for arches I don't have around.

--CJD

#1 lore raw

PATCH 1/3 Introduce inotify_add_watch_at system call

From: Casey Dahlin <[email protected]>

This adds inotify to the *at family of system calls (openat(2), unlinkat(2), etc) and lets you specify a directory file descriptor as a root for the pathname argument. It is otherwise the same as the inotify_add_watch system call.

---
 fs/notify/inotify/inotify_user.c |   18 ++++++++++++------
 1 files changed, 12 insertions(+), 6 deletions(-)
fs/notify/inotify/inotify_user.c +12 -6
index bf7f6d7..ed110ca 100644
@@ -108,7 +108,7 @@ static inline u32 inotify_mask_to_arg(__u32 mask)
 		       IN_Q_OVERFLOW);
 }
 
-/* intofiy userspace file descriptor functions */
+/* inotfiy userspace file descriptor functions */
 static unsigned int inotify_poll(struct file *file, poll_table *wait)
 {
 	struct fsnotify_group *group = file->private_data;
@@ -350,11 +350,11 @@ static const struct file_operations inotify_fops = {
 /*
  * find_inode - resolve a user-given path to a specific inode
  */
-static int inotify_find_inode(const char __user *dirname, struct path *path, unsigned flags)
+static int inotify_find_inode(int dfd, const char __user *dirname, struct path *path, unsigned flags)
 {
 	int error;
 
-	error = user_path_at(AT_FDCWD, dirname, flags, path);
+	error = user_path_at(dfd, dirname, flags, path);
 	if (error)
 		return error;
 	/* you can only watch an inode if you have read permissions on it */
@@ -762,8 +762,8 @@ SYSCALL_DEFINE0(inotify_init)
 	return sys_inotify_init1(0);
 }
 
-SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
-		u32, mask)
+SYSCALL_DEFINE4(inotify_add_watch_at, int, fd, int, dfd, const char __user *,
+		pathname, u32, mask)
 {
 	struct fsnotify_group *group;
 	struct inode *inode;
@@ -787,7 +787,7 @@ SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
 	if (mask & IN_ONLYDIR)
 		flags |= LOOKUP_DIRECTORY;
 
-	ret = inotify_find_inode(pathname, &path, flags);
+	ret = inotify_find_inode(dfd, pathname, &path, flags);
 	if (ret)
 		goto fput_and_out;
 
@@ -803,6 +803,12 @@ fput_and_out:
 	return ret;
 }
 
+SYSCALL_DEFINE3(inotify_add_watch, int, fd, const char __user *, pathname,
+		u32, mask)
+{
+	return sys_inotify_add_watch_at(fd, AT_FDCWD, pathname, mask);
+}
+
 SYSCALL_DEFINE2(inotify_rm_watch, int, fd, __s32, wd)
 {
 	struct fsnotify_group *group;
Signature · 1 line
1.7.2.3
#2 lore raw

PATCH 2/3 Add inotify_add_watch_at to asm-generic/unistd.h

In reply to [email protected]

From: Casey Dahlin <[email protected]>

---
 include/asm-generic/unistd.h |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
include/asm-generic/unistd.h +3 -1
index b969770..fd7b127 100644
@@ -646,9 +646,11 @@ __SYSCALL(__NR_prlimit64, sys_prlimit64)
 __SYSCALL(__NR_fanotify_init, sys_fanotify_init)
 #define __NR_fanotify_mark 263
 __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
+#define __NR_inotify_add_watch_at 264
+__SYSCALL(__NR_inotify_add_watch_at, sys_inotify_add_watch)
 
 #undef __NR_syscalls
-#define __NR_syscalls 264
+#define __NR_syscalls 265
 
 /*
  * All syscalls below here should go away really,
Signature · 1 line
1.7.2.3
#3 lore raw

PATCH 3/3 hook up inotify_add_watch_at for x86

In reply to [email protected]

From: Casey Dahlin <[email protected]>

---
 arch/x86/ia32/ia32entry.S          |    1 +
 arch/x86/include/asm/unistd_32.h   |    3 ++-
 arch/x86/include/asm/unistd_64.h   |    2 ++
 arch/x86/kernel/syscall_table_32.S |    1 +
 4 files changed, 6 insertions(+), 1 deletions(-)
arch/x86/ia32/ia32entry.S +1 -0
index 518bb99..1edff69 100644
@@ -851,4 +851,5 @@ ia32_sys_call_table:
 	.quad sys_fanotify_init
 	.quad sys32_fanotify_mark
 	.quad sys_prlimit64		/* 340 */
+	.quad sys_inotify_add_watch_at
 ia32_syscall_end:
arch/x86/include/asm/unistd_32.h +2 -1
index b766a5e..ae82b2b 100644
@@ -346,10 +346,11 @@
 #define __NR_fanotify_init	338
 #define __NR_fanotify_mark	339
 #define __NR_prlimit64		340
+#define __NR_inotify_add_watch_at	341
 
 #ifdef __KERNEL__
 
-#define NR_syscalls 341
+#define NR_syscalls 342
 
 #define __ARCH_WANT_IPC_PARSE_VERSION
 #define __ARCH_WANT_OLD_READDIR
arch/x86/include/asm/unistd_64.h +2 -0
index 363e9b8..f9c704a 100644
@@ -669,6 +669,8 @@ __SYSCALL(__NR_fanotify_init, sys_fanotify_init)
 __SYSCALL(__NR_fanotify_mark, sys_fanotify_mark)
 #define __NR_prlimit64				302
 __SYSCALL(__NR_prlimit64, sys_prlimit64)
+#define __NR_inotify_add_watch_at		303
+__SYSCALL(__NR_inotify_add_watch_at, sys_inotify_add_watch_at)
 
 #ifndef __NO_STUBS
 #define __ARCH_WANT_OLD_READDIR
arch/x86/kernel/syscall_table_32.S +1 -0
index b35786d..a9b3682 100644
@@ -340,3 +340,4 @@ ENTRY(sys_call_table)
 	.long sys_fanotify_init
 	.long sys_fanotify_mark
 	.long sys_prlimit64		/* 340 */
+	.long sys_inotify_add_watch_at
Signature · 1 line
1.7.2.3
#4 lore raw
In reply to [email protected]
Quoted 6 lines · On Wed, 22 Sep 2010 01:16:55 -0400 [email protected] wrote:

I had use for this system call recently when I was trying to monitor a lockfile to see when it disappeared. Its semantics are as you'd expect; it has over inotify_add_watch what openat(2) has over open(2).

Currently compile-tested only, and missing hookups for arches I don't have around.

When adding new syscalls it's nice to include a testcase for the arch maintainers, please. Paste it into the changelog, add a link to it, etc.

Also please cc [email protected] so they find out about it earlier.