Google Groups Home
Help | Sign in
Message from discussion disallow seeks and appends on sysfs files
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Mitch Williams  
View profile
 More options Jan 21 2005, 6:00 pm
Newsgroups: linux.kernel
From: Mitch Williams <mitch.a.willi...@intel.com>
Date: Sat, 22 Jan 2005 00:00:15 +0100
Local: Fri, Jan 21 2005 6:00 pm
Subject: [PATCH 1/3] disallow seeks and appends on sysfs files
This patch causes sysfs to return errors if the caller attempts to append
to or seek on a sysfs file.

Generated from 2.6.11-rc1.

Signed-off-by: Mitch Williams <mitch.a.willi...@intel.com>

diff -uprN -X dontdiff linux-2.6.11-clean/fs/sysfs/file.c linux-2.6.11/fs/sysfs/file.c
--- linux-2.6.11-clean/fs/sysfs/file.c  2004-12-24 13:33:50.000000000 -0800
+++ linux-2.6.11/fs/sysfs/file.c        2005-01-21 13:09:21.000000000 -0800
@@ -281,6 +281,11 @@ static int check_perm(struct inode * ino
        if (!ops)
                goto Eaccess;

+       /* Is the file is open for append?  Sorry, we don't do that. */
+       if (file->f_flags & O_APPEND) {
+               goto Einval;
+       }
+
        /* File needs write support.
         * The inode's perms must say it's ok,
         * and we must have a store method.
@@ -312,6 +302,10 @@ static int check_perm(struct inode * ino
                file->private_data = buffer;
        } else
                error = -ENOMEM;
+
+       /*  Set mode bits to disallow seeking.  */
+       file->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
+
        goto Done;

  Einval:
@@ -368,7 +343,7 @@ static int sysfs_release(struct inode *
 struct file_operations sysfs_file_operations = {
        .read           = sysfs_read_file,
        .write          = sysfs_write_file,
-       .llseek         = generic_file_llseek,
+       .llseek         = no_llseek,
        .open           = sysfs_open_file,
        .release        = sysfs_release,
 };
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google