aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2005-04-18 21:57:32 -0700
committerGreg KH <greg@press.kroah.org>2005-04-18 21:57:32 -0700
commit31e5abe9a6dab1ed3a5c30352bdb001353146318 (patch)
tree941317d6f91fe2bd0cb605692230b65686ca13e0
parent6897089c5f7989603ccb9c696050470ba1dbd262 (diff)
[PATCH] sysfs: add sysfs_chmod_file()
sysfs: allow changing the permissions for already created attributes Signed-off-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--fs/sysfs/file.c35
-rw-r--r--include/linux/sysfs.h7
2 files changed, 42 insertions, 0 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 352f966a117..da25aeb0e06 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -428,6 +428,41 @@ int sysfs_update_file(struct kobject * kobj, const struct attribute * attr)
/**
+ * sysfs_chmod_file - update the modified mode value on an object attribute.
+ * @kobj: object we're acting for.
+ * @attr: attribute descriptor.
+ * @mode: file permissions.
+ *
+ */
+int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
+{
+ struct dentry *dir = kobj->dentry;
+ struct dentry *victim;
+ struct sysfs_dirent *sd;
+ umode_t umode = (mode & S_IALLUGO) | S_IFREG;
+ int res = -ENOENT;
+
+ down(&dir->d_inode->i_sem);
+ victim = sysfs_get_dentry(dir, attr->name);
+ if (!IS_ERR(victim)) {
+ if (victim->d_inode &&
+ (victim->d_parent->d_inode == dir->d_inode)) {
+ sd = victim->d_fsdata;
+ attr->mode = mode;
+ sd->s_mode = umode;
+ victim->d_inode->i_mode = umode;
+ dput(victim);
+ res = 0;
+ }
+ }
+ up(&dir->d_inode->i_sem);
+
+ return res;
+}
+EXPORT_SYMBOL_GPL(sysfs_chmod_file);
+
+
+/**
* sysfs_remove_file - remove an object attribute.
* @kobj: object we're acting for.
* @attr: attribute descriptor.
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 6f502ff7902..38b58b30814 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -99,6 +99,9 @@ sysfs_create_file(struct kobject *, const struct attribute *);
extern int
sysfs_update_file(struct kobject *, const struct attribute *);
+extern int
+sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode);
+
extern void
sysfs_remove_file(struct kobject *, const struct attribute *);
@@ -140,6 +143,10 @@ static inline int sysfs_update_file(struct kobject * k, const struct attribute *
{
return 0;
}
+static inline int sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, mode_t mode)
+{
+ return 0;
+}
static inline void sysfs_remove_file(struct kobject * k, const struct attribute * a)
{