Re: [RFC 01/11] add generic versions of debugfs file operations

2008-02-24 Thread Greg KH
On Sun, Feb 24, 2008 at 11:46:07AM +0100, Arnd Bergmann wrote:
> On Saturday 23 February 2008, Al Viro wrote:
> 
> > Ewww - caps, \n...  BTW, \0 is pointless here - simple_read_from_buffer() 
> > will
> > not access it with these arguments)...
> 
> > ... 
> 
> > Please, check the length; sloppy input grammar is a bad idea.  Hell, at the
> > very least you want -EINVAL if input is not recognized...
> 
> Ok, these two come straight from debugfs, but of course I can fix them
> anyway. Should I do a fix for debugfs in 2.6.25 first, or rather do a
> patch on top of the libfs rework?

I'll gladly take a patch to debugfs for it :)

thanks,

greg k-h
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC 01/11] add generic versions of debugfs file operations

2008-02-24 Thread Arnd Bergmann
On Saturday 23 February 2008, Al Viro wrote:

> Ewww - caps, \n...  BTW, \0 is pointless here - simple_read_from_buffer() will
> not access it with these arguments)...

> ... 

> Please, check the length; sloppy input grammar is a bad idea.  Hell, at the
> very least you want -EINVAL if input is not recognized...

Ok, these two come straight from debugfs, but of course I can fix them
anyway. Should I do a fix for debugfs in 2.6.25 first, or rather do a
patch on top of the libfs rework?

I'd rather not have any semantic changes during the conversion, so
it would be better to keep that separate imho.

Arnd <><
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC 01/11] add generic versions of debugfs file operations

2008-02-23 Thread Al Viro
On Tue, Feb 19, 2008 at 05:04:36AM +0100, Arnd Bergmann wrote:
> The file operations in debugfs are rather generic and can
> be used by other file systems, so it can be interesting to
> include them in libfs, with more generic names, and exported
> to modules.
> 
> This patch adds a new copy of these operations to libfs,
> so that the debugfs version can later be cut down.

BTW, where does CONFIG_LIBFS come from?
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [RFC 01/11] add generic versions of debugfs file operations

2008-02-23 Thread Al Viro
On Tue, Feb 19, 2008 at 05:04:36AM +0100, Arnd Bergmann wrote:
> + char buf[3];
> + u32 *val = file->private_data;
> +
> + if (*val)
> + buf[0] = 'Y';
> + else
> + buf[0] = 'N';
> + buf[1] = '\n';
> + buf[2] = 0x00;
> + return simple_read_from_buffer(user_buf, count, ppos, buf, 2);

Ewww - caps, \n...  BTW, \0 is pointless here - simple_read_from_buffer() will
not access it with these arguments)...

> +{
> + char buf[32];
> + int buf_size;
> + u32 *val = file->private_data;
> +
> + buf_size = min(count, (sizeof(buf)-1));
> + if (copy_from_user(buf, user_buf, buf_size))
> + return -EFAULT;
> +
> + switch (buf[0]) {
> + case 'y':
> + case 'Y':
> + case '1':
> + *val = 1;
> + break;
> + case 'n':
> + case 'N':
> + case '0':
> + *val = 0;
> + break;

Please, check the length; sloppy input grammar is a bad idea.  Hell, at the
very least you want -EINVAL if input is not recognized...
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[RFC 01/11] add generic versions of debugfs file operations

2008-02-18 Thread Arnd Bergmann
The file operations in debugfs are rather generic and can
be used by other file systems, so it can be interesting to
include them in libfs, with more generic names, and exported
to modules.

This patch adds a new copy of these operations to libfs,
so that the debugfs version can later be cut down.

Signed-off-by: Arnd Bergmann <[EMAIL PROTECTED]>

Index: linux-2.6/fs/Makefile
===
--- linux-2.6.orig/fs/Makefile
+++ linux-2.6/fs/Makefile
@@ -13,6 +13,8 @@ obj-y :=  open.o read_write.o file_table.
pnode.o drop_caches.o splice.o sync.o utimes.o \
stack.o
 
+obj-$(CONFIG_LIBFS) += libfs/
+
 ifeq ($(CONFIG_BLOCK),y)
 obj-y +=   buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o
 else
Index: linux-2.6/include/linux/libfs.h
===
--- /dev/null
+++ linux-2.6/include/linux/libfs.h
@@ -0,0 +1,21 @@
+#ifndef __LIBFS_H__
+#define __LIBFS_H__
+
+#include 
+
+extern const struct file_operations simple_fops_u8;
+extern const struct file_operations simple_fops_x8;
+extern const struct file_operations simple_fops_u16;
+extern const struct file_operations simple_fops_x16;
+extern const struct file_operations simple_fops_u32;
+extern const struct file_operations simple_fops_x32;
+extern const struct file_operations simple_fops_u64;
+extern const struct file_operations simple_fops_bool;
+extern const struct file_operations simple_fops_blob;
+
+struct simple_blob_wrapper {
+   void *data;
+   unsigned long size;
+};
+
+#endif /* __LIBFS_H__ */
Index: linux-2.6/fs/libfs/Makefile
===
--- /dev/null
+++ linux-2.6/fs/libfs/Makefile
@@ -0,0 +1,3 @@
+libfs-y += file.o
+
+obj-$(CONFIG_LIBFS) += libfs.o
Index: linux-2.6/fs/libfs/file.c
===
--- /dev/null
+++ linux-2.6/fs/libfs/file.c
@@ -0,0 +1,126 @@
+/*
+ * fs/libfs/file.c
+ * Library for filesystems writers.
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+
+/* commonly used attribute file operations */
+static int simple_u8_set(void *data, u64 val)
+{
+   *(u8 *)data = val;
+   return 0;
+}
+static int simple_u8_get(void *data, u64 *val)
+{
+   *val = *(u8 *)data;
+   return 0;
+}
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_u8, simple_u8_get, simple_u8_set, 
"%llu\n");
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_x8, simple_u8_get, simple_u8_set, 
"0x%02llx\n");
+
+static int simple_u16_set(void *data, u64 val)
+{
+   *(u16 *)data = val;
+   return 0;
+}
+static int simple_u16_get(void *data, u64 *val)
+{
+   *val = *(u16 *)data;
+   return 0;
+}
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_u16, simple_u16_get, 
simple_u16_set, "%llu\n");
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_x16, simple_u16_get, 
simple_u16_set, "0x%04llx\n");
+
+static int simple_u32_set(void *data, u64 val)
+{
+   *(u32 *)data = val;
+   return 0;
+}
+static int simple_u32_get(void *data, u64 *val)
+{
+   *val = *(u32 *)data;
+   return 0;
+}
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_u32, simple_u32_get, 
simple_u32_set, "%llu\n");
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_x32, simple_u32_get, 
simple_u32_set, "0x%08llx\n");
+
+static int simple_u64_set(void *data, u64 val)
+{
+   *(u64 *)data = val;
+   return 0;
+}
+
+static int simple_u64_get(void *data, u64 *val)
+{
+   return *(u64 *)data;
+   return 0;
+}
+DEFINE_SIMPLE_EXPORTED_ATTRIBUTE(simple_fops_u64, simple_u64_get, 
simple_u64_set, "%llu\n");
+
+static ssize_t read_file_bool(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+   char buf[3];
+   u32 *val = file->private_data;
+
+   if (*val)
+   buf[0] = 'Y';
+   else
+   buf[0] = 'N';
+   buf[1] = '\n';
+   buf[2] = 0x00;
+   return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t write_file_bool(struct file *file, const char __user *user_buf,
+  size_t count, loff_t *ppos)
+{
+   char buf[32];
+   int buf_size;
+   u32 *val = file->private_data;
+
+   buf_size = min(count, (sizeof(buf)-1));
+   if (copy_from_user(buf, user_buf, buf_size))
+   return -EFAULT;
+
+   switch (buf[0]) {
+   case 'y':
+   case 'Y':
+   case '1':
+   *val = 1;
+   break;
+   case 'n':
+   case 'N':
+   case '0':
+   *val = 0;
+   break;
+   }
+
+   return count;
+}
+
+const struct file_operations simple_fops_bool = {
+   .read = read_file_bool,
+   .write =write_file_bool,
+   .open = simple_open,
+};
+EXPORT_SYMBOL_GPL(simple_fops_bool);
+
+static ssize_t read_file_blob(struct file *file, char __user *user_buf,
+