From: Maneesh Soni <maneesh@in.ibm.com>
To: Al Viro <viro@parcelfarce.linux.theplanet.co.uk>,
Patrick Mochel <mochel@osdl.org>, Greg KH <gregkh@us.ibm.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
Dipankar Sarma <dipankar@in.ibm.com>
Subject: [RFC 3/6] sysfs-file.patch
Date: Mon, 6 Oct 2003 14:31:07 +0530 [thread overview]
Message-ID: <20031006090107.GH4220@in.ibm.com> (raw)
In-Reply-To: <20031006090030.GG4220@in.ibm.com>
o This patch modifies the externals sysfs_create_file and
sysfs_create_bin_file. Now these don't actually create files but just links
the attribute to the kobject. There is no change in the definition but
actual function. These should be actually part of kobject code but as of
now for not changing the interfaces there are kept as part of sysfs code.
fs/sysfs/bin.c | 40 +++++++++++++++++-----------------------
fs/sysfs/file.c | 45 +++++++++++++++++++--------------------------
2 files changed, 36 insertions(+), 49 deletions(-)
diff -puN fs/sysfs/file.c~sysfs-file fs/sysfs/file.c
--- linux-2.6.0-test6/fs/sysfs/file.c~sysfs-file 2003-10-06 11:58:10.000000000 +0530
+++ linux-2.6.0-test6-maneesh/fs/sysfs/file.c 2003-10-06 11:58:50.000000000 +0530
@@ -11,7 +11,7 @@
static struct file_operations sysfs_file_operations;
-static int init_file(struct inode * inode)
+int sysfs_init_file(struct inode * inode)
{
inode->i_size = PAGE_SIZE;
inode->i_fop = &sysfs_file_operations;
@@ -345,27 +345,6 @@ static struct file_operations sysfs_file
};
-int sysfs_add_file(struct dentry * dir, const struct attribute * attr)
-{
- struct dentry * dentry;
- int error;
-
- down(&dir->d_inode->i_sem);
- dentry = sysfs_get_dentry(dir,attr->name);
- if (!IS_ERR(dentry)) {
- error = sysfs_create(dentry,
- (attr->mode & S_IALLUGO) | S_IFREG,
- init_file);
- if (!error)
- dentry->d_fsdata = (void *)attr;
- dput(dentry);
- } else
- error = PTR_ERR(dentry);
- up(&dir->d_inode->i_sem);
- return error;
-}
-
-
/**
* sysfs_create_file - create an attribute file for an object.
* @kobj: object we're creating for.
@@ -374,11 +353,25 @@ int sysfs_add_file(struct dentry * dir,
int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
{
- if (kobj && attr)
- return sysfs_add_file(kobj->dentry,attr);
- return -EINVAL;
-}
+ struct kobject_attr * k_attr;
+
+ if (!kobj || !attr)
+ return -EINVAL;
+ k_attr = kmalloc(sizeof(k_attr), GFP_KERNEL);
+ if (!k_attr)
+ return -ENOMEM;
+ memset(k_attr, 0, sizeof(k_attr));
+ INIT_LIST_HEAD(&k_attr->list);
+ k_attr->flags |= KOBJ_TEXT_ATTR;
+ k_attr->attr_u.attr = attr;
+
+ down_write(&kobj->k_rwsem);
+ list_add(&k_attr->list, &kobj->attr);
+ up_write(&kobj->k_rwsem);
+
+ return 0;
+}
/**
* sysfs_update_file - update the modified timestamp on an object attribute.
diff -puN fs/sysfs/bin.c~sysfs-file fs/sysfs/bin.c
--- linux-2.6.0-test6/fs/sysfs/bin.c~sysfs-file 2003-10-06 11:58:13.000000000 +0530
+++ linux-2.6.0-test6-maneesh/fs/sysfs/bin.c 2003-10-06 11:58:50.000000000 +0530
@@ -9,6 +9,7 @@
#include <linux/kobject.h>
#include <linux/module.h>
#include <linux/slab.h>
+#include <linux/namei.h>
#include <asm/uaccess.h>
@@ -131,7 +132,7 @@ static int release(struct inode * inode,
return 0;
}
-static struct file_operations bin_fops = {
+struct file_operations bin_fops = {
.read = read,
.write = write,
.llseek = generic_file_llseek,
@@ -148,31 +149,24 @@ static struct file_operations bin_fops =
int sysfs_create_bin_file(struct kobject * kobj, struct bin_attribute * attr)
{
- struct dentry * dentry;
- struct dentry * parent;
- int error = 0;
+ struct kobject_attr * k_attr;
if (!kobj || !attr)
return -EINVAL;
-
- parent = kobj->dentry;
-
- down(&parent->d_inode->i_sem);
- dentry = sysfs_get_dentry(parent,attr->attr.name);
- if (!IS_ERR(dentry)) {
- dentry->d_fsdata = (void *)attr;
- error = sysfs_create(dentry,
- (attr->attr.mode & S_IALLUGO) | S_IFREG,
- NULL);
- if (!error) {
- dentry->d_inode->i_size = attr->size;
- dentry->d_inode->i_fop = &bin_fops;
- }
- dput(dentry);
- } else
- error = PTR_ERR(dentry);
- up(&parent->d_inode->i_sem);
- return error;
+
+ k_attr = kmalloc(sizeof(k_attr), GFP_KERNEL);
+ if (!k_attr)
+ return -ENOMEM;
+ memset(k_attr, 0, sizeof(k_attr));
+ INIT_LIST_HEAD(&k_attr->list);
+ k_attr->flags |= KOBJ_BINARY_ATTR;
+ k_attr->attr_u.bin_attr = attr;
+
+ down_write(&kobj->k_rwsem);
+ list_add(&k_attr->list, &kobj->attr);
+ up_write(&kobj->k_rwsem);
+
+ return 0;
}
_
--
Maneesh Soni
Linux Technology Center,
IBM Software Lab, Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-5044999 Fax: 91-80-5268553
T/L : 9243696
next prev parent reply other threads:[~2003-10-06 9:01 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-06 8:59 [RFC 0/6] Backing Store for sysfs Maneesh Soni
2003-10-06 9:00 ` [RFC 1/6] sysfs-kobject.patch Maneesh Soni
2003-10-06 9:00 ` [RFC 2/6] sysfs-mount.patch Maneesh Soni
2003-10-06 9:01 ` Maneesh Soni [this message]
2003-10-06 9:01 ` [RFC 4/6] sysfs-symlink.patch Maneesh Soni
2003-10-06 9:02 ` [RFC 5/6] sysfs-attr_group.patch Maneesh Soni
2003-10-06 9:03 ` [RFC 6/6] sysfs-dir.patch Maneesh Soni
2003-10-06 13:43 ` [RFC 2/6] sysfs-mount.patch viro
2003-10-07 7:17 ` Maneesh Soni
2003-10-06 13:41 ` [RFC 1/6] sysfs-kobject.patch viro
2003-10-06 16:16 ` Greg KH
2003-10-06 17:41 ` Dipankar Sarma
2003-10-06 17:44 ` Greg KH
2003-10-06 16:08 ` [RFC 0/6] Backing Store for sysfs Greg KH
2003-10-06 17:31 ` Dipankar Sarma
2003-10-06 17:38 ` Greg KH
2003-10-06 18:01 ` Dipankar Sarma
2003-10-06 18:09 ` Greg KH
2003-10-06 18:31 ` Dipankar Sarma
2003-10-06 18:34 ` Greg KH
2003-10-07 9:08 ` Andreas Jellinghaus
2003-10-06 18:44 ` Patrick Mochel
2003-10-06 19:27 ` Dipankar Sarma
2003-10-06 19:30 ` viro
2003-10-06 20:01 ` Dipankar Sarma
2003-10-06 20:34 ` viro
2003-10-07 4:47 ` Maneesh Soni
2003-10-06 19:33 ` Patrick Mochel
2003-10-06 20:26 ` Dipankar Sarma
2003-10-06 20:29 ` Patrick Mochel
2003-10-07 4:31 ` Maneesh Soni
2003-10-07 5:25 ` Nick Piggin
2003-10-07 7:17 ` Maneesh Soni
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20031006090107.GH4220@in.ibm.com \
--to=maneesh@in.ibm.com \
--cc=dipankar@in.ibm.com \
--cc=gregkh@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mochel@osdl.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox