From: Maneesh Soni <maneesh@in.ibm.com>
To: linux-hotplug@vger.kernel.org
Subject: [patch 2/3] sysfs-iattr: add sysfs_setattr
Date: Tue, 31 May 2005 05:21:14 +0000 [thread overview]
Message-ID: <20050531050914.GC3631@in.ibm.com> (raw)
o This adds ->i_op->setattr VFS method for sysfs inodes. The changed
attribues are saved in the persistent sysfs_dirent structure as a pointer
to struct iattr. The struct iattr is allocated only for those sysfs_dirent's
for which default attributes are getting changed. Thanks to Jon Smirl for
this suggestion.
Signed-off-by: Maneesh Soni <maneesh@in.ibm.com>
---
linux-2.6.12-rc5-mm1-maneesh/fs/sysfs/dir.c | 1
linux-2.6.12-rc5-mm1-maneesh/fs/sysfs/inode.c | 65 +++++++++++++++++++++
linux-2.6.12-rc5-mm1-maneesh/fs/sysfs/sysfs.h | 2
linux-2.6.12-rc5-mm1-maneesh/include/linux/sysfs.h | 1
4 files changed, 69 insertions(+)
diff -puN include/linux/sysfs.h~sysfs-iattr-add-sysfs_setattr include/linux/sysfs.h
--- linux-2.6.12-rc5-mm1/include/linux/sysfs.h~sysfs-iattr-add-sysfs_setattr 2005-05-31 09:08:23.554728872 +0530
+++ linux-2.6.12-rc5-mm1-maneesh/include/linux/sysfs.h 2005-05-31 09:13:17.020115352 +0530
@@ -73,6 +73,7 @@ struct sysfs_dirent {
int s_type;
umode_t s_mode;
struct dentry * s_dentry;
+ struct iattr * s_iattr;
};
#define SYSFS_ROOT 0x0001
diff -puN fs/sysfs/inode.c~sysfs-iattr-add-sysfs_setattr fs/sysfs/inode.c
--- linux-2.6.12-rc5-mm1/fs/sysfs/inode.c~sysfs-iattr-add-sysfs_setattr 2005-05-31 09:08:34.481067816 +0530
+++ linux-2.6.12-rc5-mm1-maneesh/fs/sysfs/inode.c 2005-05-31 09:31:16.781966600 +0530
@@ -26,6 +26,71 @@ static struct backing_dev_info sysfs_bac
.capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK,
};
+static struct inode_operations sysfs_inode_operations ={
+ .setattr = sysfs_setattr,
+};
+
+int sysfs_setattr(struct dentry * dentry, struct iattr * iattr)
+{
+ struct inode * inode = dentry->d_inode;
+ struct sysfs_dirent * sd = dentry->d_fsdata;
+ struct iattr * sd_iattr;
+ unsigned int ia_valid = iattr->ia_valid;
+ int error;
+
+ if (!sd)
+ return -EINVAL;
+
+ sd_iattr = sd->s_iattr;
+
+ error = inode_change_ok(inode, iattr);
+ if (error)
+ return error;
+
+ error = inode_setattr(inode, iattr);
+ if (error)
+ return error;
+
+ if (!sd_iattr) {
+ /* setting attributes for the first time, allocate now */
+ sd_iattr = kmalloc(sizeof(struct iattr), GFP_KERNEL);
+ if (!sd_iattr)
+ return -ENOMEM;
+ /* assign default attributes */
+ memset(sd_iattr, 0, sizeof(struct iattr));
+ sd_iattr->ia_mode = sd->s_mode;
+ sd_iattr->ia_uid = 0;
+ sd_iattr->ia_gid = 0;
+ sd_iattr->ia_atime = sd_iattr->ia_mtime = sd_iattr->ia_ctime = CURRENT_TIME;
+ sd->s_iattr = sd_iattr;
+ }
+
+ /* attributes were changed atleast once in past */
+
+ if (ia_valid & ATTR_UID)
+ sd_iattr->ia_uid = iattr->ia_uid;
+ if (ia_valid & ATTR_GID)
+ sd_iattr->ia_gid = iattr->ia_gid;
+ if (ia_valid & ATTR_ATIME)
+ sd_iattr->ia_atime = timespec_trunc(iattr->ia_atime,
+ inode->i_sb->s_time_gran);
+ if (ia_valid & ATTR_MTIME)
+ sd_iattr->ia_mtime = timespec_trunc(iattr->ia_mtime,
+ inode->i_sb->s_time_gran);
+ if (ia_valid & ATTR_CTIME)
+ sd_iattr->ia_ctime = timespec_trunc(iattr->ia_ctime,
+ inode->i_sb->s_time_gran);
+ if (ia_valid & ATTR_MODE) {
+ umode_t mode = iattr->ia_mode;
+
+ if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
+ mode &= ~S_ISGID;
+ sd_iattr->ia_mode = mode;
+ }
+
+ return error;
+}
+
struct inode * sysfs_new_inode(mode_t mode)
{
struct inode * inode = new_inode(sysfs_sb);
diff -puN fs/sysfs/dir.c~sysfs-iattr-add-sysfs_setattr fs/sysfs/dir.c
--- linux-2.6.12-rc5-mm1/fs/sysfs/dir.c~sysfs-iattr-add-sysfs_setattr 2005-05-31 09:08:38.276490824 +0530
+++ linux-2.6.12-rc5-mm1-maneesh/fs/sysfs/dir.c 2005-05-31 09:11:19.644959088 +0530
@@ -234,6 +234,7 @@ static struct dentry * sysfs_lookup(stru
struct inode_operations sysfs_dir_inode_operations = {
.lookup = sysfs_lookup,
+ .setattr = sysfs_setattr,
};
static void remove_dir(struct dentry * d)
diff -puN fs/sysfs/sysfs.h~sysfs-iattr-add-sysfs_setattr fs/sysfs/sysfs.h
--- linux-2.6.12-rc5-mm1/fs/sysfs/sysfs.h~sysfs-iattr-add-sysfs_setattr 2005-05-31 09:08:46.236280752 +0530
+++ linux-2.6.12-rc5-mm1-maneesh/fs/sysfs/sysfs.h 2005-05-31 09:31:16.782966448 +0530
@@ -16,6 +16,7 @@ extern void sysfs_remove_subdir(struct d
extern const unsigned char * sysfs_get_name(struct sysfs_dirent *sd);
extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent);
+extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
extern struct rw_semaphore sysfs_rename_sem;
extern struct super_block * sysfs_sb;
@@ -74,6 +75,7 @@ static inline void release_sysfs_dirent(
kobject_put(sl->target_kobj);
kfree(sl);
}
+ kfree(sd->s_iattr);
kmem_cache_free(sysfs_dir_cachep, sd);
}
_
--
Maneesh Soni
Linux Technology Center,
IBM India Software Labs,
Bangalore, India
email: maneesh@in.ibm.com
Phone: 91-80-25044990
-------------------------------------------------------
This SF.Net email is sponsored by Yahoo.
Introducing Yahoo! Search Developer Network - Create apps using Yahoo!
Search APIs Find out how you can build Yahoo! directly into your own
Applications - visit http://developer.yahoo.net/?fr=offad-ysdn-ostg-q22005
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
reply other threads:[~2005-05-31 5:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20050531050914.GC3631@in.ibm.com \
--to=maneesh@in.ibm.com \
--cc=linux-hotplug@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).