[patch] inotify: add sysfs store support

From: Robert Love
Date: Wed Nov 17 2004 - 15:21:57 EST


Attached patch implements the final chunk of our sysfs solution: store
support. I added basic write support with some simple checking (do not
allow zero) to the existing sysfs attributes.

I made a few other changes. I added a newline after the values in the
show function. The other sysfs attributes do this and it makes
sense--do a "cat *" in our sysfs directory before and after. I also
just return sprintf() directly instead of the strlen(). I also made
max_queued_events unsigned, since dev->max_events is unsigned. If we
don't do this we need to add checking in store_max_queued_events to
ensure that the given value is less than or equal to INT_MAX so this
seems easier and more optimal anyhow. The other values I kept at int
since that is the range of atomic_t's.

I am running it now. I can read and write the values fine. Works
great.

Robert Love


Add store support to our sysfs attributes and a few other changes.

inotify.c | 35 +++++++++++++++++++++++++----------
1 files changed, 25 insertions(+), 10 deletions(-)

diff -u linux/drivers/char/inotify.c linux/drivers/char/inotify.c
--- linux/drivers/char/inotify.c 2004-11-16 14:42:11.929575168 -0500
+++ linux/drivers/char/inotify.c 2004-11-17 12:28:27.921136656 -0500
@@ -40,7 +40,7 @@

static int sysfs_attrib_max_user_devices;
static int sysfs_attrib_max_user_watches;
-static int sysfs_attrib_max_queued_events;
+static unsigned int sysfs_attrib_max_queued_events;

/*
* struct inotify_device - represents an open instance of an inotify device
@@ -82,38 +82,53 @@

static ssize_t show_max_queued_events(struct class_device *class, char *buf)
{
- sprintf(buf, "%d", sysfs_attrib_max_queued_events);
- return strlen(buf) + 1;
+ return sprintf(buf, "%d\n", sysfs_attrib_max_queued_events);
}

static ssize_t store_max_queued_events(struct class_device *class,
const char *buf, size_t count)
{
- return 0;
+ unsigned int max;
+
+ if (sscanf(buf, "%u", &max) > 0 && max > 0) {
+ sysfs_attrib_max_queued_events = max;
+ return strlen(buf);
+ }
+ return -EINVAL;
}

static ssize_t show_max_user_devices(struct class_device *class, char *buf)
{
- sprintf(buf, "%d", sysfs_attrib_max_user_devices);
- return strlen(buf) + 1;
+ return sprintf(buf, "%d\n", sysfs_attrib_max_user_devices);
}

static ssize_t store_max_user_devices(struct class_device *class,
const char *buf, size_t count)
{
- return 0;
+ int max;
+
+ if (sscanf(buf, "%d", &max) > 0 && max > 0) {
+ sysfs_attrib_max_user_devices = max;
+ return strlen(buf);
+ }
+ return -EINVAL;
}

static ssize_t show_max_user_watches(struct class_device *class, char *buf)
{
- sprintf(buf, "%d", sysfs_attrib_max_user_watches);
- return strlen(buf) + 1;
+ return sprintf(buf, "%d\n", sysfs_attrib_max_user_watches);
}

static ssize_t store_max_user_watches(struct class_device *class,
const char *buf, size_t count)
{
- return 0;
+ int max;
+
+ if (sscanf(buf, "%d", &max) > 0 && max > 0) {
+ sysfs_attrib_max_user_watches = max;
+ return strlen(buf);
+ }
+ return -EINVAL;
}

static CLASS_DEVICE_ATTR(max_queued_events, S_IRUGO | S_IWUSR,


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/