Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 207656
b: refs/heads/master
c: 52c923d
h: refs/heads/master
v: v3
  • Loading branch information
Eric Paris committed Jul 28, 2010
1 parent b6ac4b5 commit 7667226
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 11637e4b7dc098e9a863f0a619d55ebc60f5949e
refs/heads/master: 52c923dd079df49f58016a9e56df184b132611d6
2 changes: 2 additions & 0 deletions trunk/fs/notify/fanotify/fanotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <linux/kernel.h>
#include <linux/types.h>

extern const struct fsnotify_ops fanotify_fsnotify_ops;

static inline bool fanotify_mask_valid(__u32 mask)
{
if (mask & ~((__u32)FAN_ALL_INCOMING_EVENTS))
Expand Down
61 changes: 60 additions & 1 deletion trunk/fs/notify/fanotify/fanotify_user.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,72 @@
#include <linux/fcntl.h>
#include <linux/fs.h>
#include <linux/anon_inodes.h>
#include <linux/fsnotify_backend.h>
#include <linux/security.h>
#include <linux/syscalls.h>

#include "fanotify.h"

static int fanotify_release(struct inode *ignored, struct file *file)
{
struct fsnotify_group *group = file->private_data;

pr_debug("%s: file=%p group=%p\n", __func__, file, group);

/* matches the fanotify_init->fsnotify_alloc_group */
fsnotify_put_group(group);

return 0;
}

static const struct file_operations fanotify_fops = {
.poll = NULL,
.read = NULL,
.fasync = NULL,
.release = fanotify_release,
.unlocked_ioctl = NULL,
.compat_ioctl = NULL,
};

/* fanotify syscalls */
SYSCALL_DEFINE3(fanotify_init, unsigned int, flags, unsigned int, event_f_flags,
unsigned int, priority)
{
return -ENOSYS;
struct fsnotify_group *group;
int f_flags, fd;

pr_debug("%s: flags=%d event_f_flags=%d priority=%d\n",
__func__, flags, event_f_flags, priority);

if (event_f_flags)
return -EINVAL;
if (priority)
return -EINVAL;

if (!capable(CAP_SYS_ADMIN))
return -EACCES;

if (flags & ~FAN_ALL_INIT_FLAGS)
return -EINVAL;

f_flags = (O_RDONLY | FMODE_NONOTIFY);
if (flags & FAN_CLOEXEC)
f_flags |= O_CLOEXEC;
if (flags & FAN_NONBLOCK)
f_flags |= O_NONBLOCK;

/* fsnotify_alloc_group takes a ref. Dropped in fanotify_release */
group = fsnotify_alloc_group(&fanotify_fsnotify_ops);
if (IS_ERR(group))
return PTR_ERR(group);

fd = anon_inode_getfd("[fanotify]", &fanotify_fops, group, f_flags);
if (fd < 0)
goto out_put_group;

return fd;

out_put_group:
fsnotify_put_group(group);
return fd;
}
4 changes: 4 additions & 0 deletions trunk/include/linux/fanotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
/* helper events */
#define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) /* close */

#define FAN_CLOEXEC 0x00000001
#define FAN_NONBLOCK 0x00000002

#define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK)
/*
* All of the events - we build the list by hand so that we can add flags in
* the future and not break backward compatibility. Apps will get only the
Expand Down

0 comments on commit 7667226

Please sign in to comment.