diff options
Diffstat (limited to 'fs/sysfs')
-rw-r--r-- | fs/sysfs/file.c | 16 | ||||
-rw-r--r-- | fs/sysfs/group.c | 83 | ||||
-rw-r--r-- | fs/sysfs/inode.c | 2 | ||||
-rw-r--r-- | fs/sysfs/mount.c | 2 | ||||
-rw-r--r-- | fs/sysfs/sysfs.h | 2 |
5 files changed, 85 insertions, 20 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c index ade9a7e6a757..e7735f643cd1 100644 --- a/fs/sysfs/file.c +++ b/fs/sysfs/file.c | |||
@@ -135,7 +135,7 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos) | |||
135 | goto out; | 135 | goto out; |
136 | } | 136 | } |
137 | pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", | 137 | pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n", |
138 | __FUNCTION__, count, *ppos, buffer->page); | 138 | __func__, count, *ppos, buffer->page); |
139 | retval = simple_read_from_buffer(buf, count, ppos, buffer->page, | 139 | retval = simple_read_from_buffer(buf, count, ppos, buffer->page, |
140 | buffer->count); | 140 | buffer->count); |
141 | out: | 141 | out: |
@@ -477,11 +477,10 @@ const struct file_operations sysfs_file_operations = { | |||
477 | .poll = sysfs_poll, | 477 | .poll = sysfs_poll, |
478 | }; | 478 | }; |
479 | 479 | ||
480 | 480 | int sysfs_add_file_mode(struct sysfs_dirent *dir_sd, | |
481 | int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, | 481 | const struct attribute *attr, int type, mode_t amode) |
482 | int type) | ||
483 | { | 482 | { |
484 | umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG; | 483 | umode_t mode = (amode & S_IALLUGO) | S_IFREG; |
485 | struct sysfs_addrm_cxt acxt; | 484 | struct sysfs_addrm_cxt acxt; |
486 | struct sysfs_dirent *sd; | 485 | struct sysfs_dirent *sd; |
487 | int rc; | 486 | int rc; |
@@ -502,6 +501,13 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, | |||
502 | } | 501 | } |
503 | 502 | ||
504 | 503 | ||
504 | int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr, | ||
505 | int type) | ||
506 | { | ||
507 | return sysfs_add_file_mode(dir_sd, attr, type, attr->mode); | ||
508 | } | ||
509 | |||
510 | |||
505 | /** | 511 | /** |
506 | * sysfs_create_file - create an attribute file for an object. | 512 | * sysfs_create_file - create an attribute file for an object. |
507 | * @kobj: object we're creating for. | 513 | * @kobj: object we're creating for. |
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 477904915032..eeba38417b1d 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c | |||
@@ -23,35 +23,50 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, | |||
23 | int i; | 23 | int i; |
24 | 24 | ||
25 | for (i = 0, attr = grp->attrs; *attr; i++, attr++) | 25 | for (i = 0, attr = grp->attrs; *attr; i++, attr++) |
26 | if (!grp->is_visible || | 26 | sysfs_hash_and_remove(dir_sd, (*attr)->name); |
27 | grp->is_visible(kobj, *attr, i)) | ||
28 | sysfs_hash_and_remove(dir_sd, (*attr)->name); | ||
29 | } | 27 | } |
30 | 28 | ||
31 | static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, | 29 | static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, |
32 | const struct attribute_group *grp) | 30 | const struct attribute_group *grp, int update) |
33 | { | 31 | { |
34 | struct attribute *const* attr; | 32 | struct attribute *const* attr; |
35 | int error = 0, i; | 33 | int error = 0, i; |
36 | 34 | ||
37 | for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) | 35 | for (i = 0, attr = grp->attrs; *attr && !error; i++, attr++) { |
38 | if (!grp->is_visible || | 36 | mode_t mode = 0; |
39 | grp->is_visible(kobj, *attr, i)) | 37 | |
40 | error |= | 38 | /* in update mode, we're changing the permissions or |
41 | sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR); | 39 | * visibility. Do this by first removing then |
40 | * re-adding (if required) the file */ | ||
41 | if (update) | ||
42 | sysfs_hash_and_remove(dir_sd, (*attr)->name); | ||
43 | if (grp->is_visible) { | ||
44 | mode = grp->is_visible(kobj, *attr, i); | ||
45 | if (!mode) | ||
46 | continue; | ||
47 | } | ||
48 | error = sysfs_add_file_mode(dir_sd, *attr, SYSFS_KOBJ_ATTR, | ||
49 | (*attr)->mode | mode); | ||
50 | if (unlikely(error)) | ||
51 | break; | ||
52 | } | ||
42 | if (error) | 53 | if (error) |
43 | remove_files(dir_sd, kobj, grp); | 54 | remove_files(dir_sd, kobj, grp); |
44 | return error; | 55 | return error; |
45 | } | 56 | } |
46 | 57 | ||
47 | 58 | ||
48 | int sysfs_create_group(struct kobject * kobj, | 59 | static int internal_create_group(struct kobject *kobj, int update, |
49 | const struct attribute_group * grp) | 60 | const struct attribute_group *grp) |
50 | { | 61 | { |
51 | struct sysfs_dirent *sd; | 62 | struct sysfs_dirent *sd; |
52 | int error; | 63 | int error; |
53 | 64 | ||
54 | BUG_ON(!kobj || !kobj->sd); | 65 | BUG_ON(!kobj || (!update && !kobj->sd)); |
66 | |||
67 | /* Updates may happen before the object has been instantiated */ | ||
68 | if (unlikely(update && !kobj->sd)) | ||
69 | return -EINVAL; | ||
55 | 70 | ||
56 | if (grp->name) { | 71 | if (grp->name) { |
57 | error = sysfs_create_subdir(kobj, grp->name, &sd); | 72 | error = sysfs_create_subdir(kobj, grp->name, &sd); |
@@ -60,7 +75,7 @@ int sysfs_create_group(struct kobject * kobj, | |||
60 | } else | 75 | } else |
61 | sd = kobj->sd; | 76 | sd = kobj->sd; |
62 | sysfs_get(sd); | 77 | sysfs_get(sd); |
63 | error = create_files(sd, kobj, grp); | 78 | error = create_files(sd, kobj, grp, update); |
64 | if (error) { | 79 | if (error) { |
65 | if (grp->name) | 80 | if (grp->name) |
66 | sysfs_remove_subdir(sd); | 81 | sysfs_remove_subdir(sd); |
@@ -69,6 +84,47 @@ int sysfs_create_group(struct kobject * kobj, | |||
69 | return error; | 84 | return error; |
70 | } | 85 | } |
71 | 86 | ||
87 | /** | ||
88 | * sysfs_create_group - given a directory kobject, create an attribute group | ||
89 | * @kobj: The kobject to create the group on | ||
90 | * @grp: The attribute group to create | ||
91 | * | ||
92 | * This function creates a group for the first time. It will explicitly | ||
93 | * warn and error if any of the attribute files being created already exist. | ||
94 | * | ||
95 | * Returns 0 on success or error. | ||
96 | */ | ||
97 | int sysfs_create_group(struct kobject *kobj, | ||
98 | const struct attribute_group *grp) | ||
99 | { | ||
100 | return internal_create_group(kobj, 0, grp); | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * sysfs_update_group - given a directory kobject, create an attribute group | ||
105 | * @kobj: The kobject to create the group on | ||
106 | * @grp: The attribute group to create | ||
107 | * | ||
108 | * This function updates an attribute group. Unlike | ||
109 | * sysfs_create_group(), it will explicitly not warn or error if any | ||
110 | * of the attribute files being created already exist. Furthermore, | ||
111 | * if the visibility of the files has changed through the is_visible() | ||
112 | * callback, it will update the permissions and add or remove the | ||
113 | * relevant files. | ||
114 | * | ||
115 | * The primary use for this function is to call it after making a change | ||
116 | * that affects group visibility. | ||
117 | * | ||
118 | * Returns 0 on success or error. | ||
119 | */ | ||
120 | int sysfs_update_group(struct kobject *kobj, | ||
121 | const struct attribute_group *grp) | ||
122 | { | ||
123 | return internal_create_group(kobj, 1, grp); | ||
124 | } | ||
125 | |||
126 | |||
127 | |||
72 | void sysfs_remove_group(struct kobject * kobj, | 128 | void sysfs_remove_group(struct kobject * kobj, |
73 | const struct attribute_group * grp) | 129 | const struct attribute_group * grp) |
74 | { | 130 | { |
@@ -95,4 +151,5 @@ void sysfs_remove_group(struct kobject * kobj, | |||
95 | 151 | ||
96 | 152 | ||
97 | EXPORT_SYMBOL_GPL(sysfs_create_group); | 153 | EXPORT_SYMBOL_GPL(sysfs_create_group); |
154 | EXPORT_SYMBOL_GPL(sysfs_update_group); | ||
98 | EXPORT_SYMBOL_GPL(sysfs_remove_group); | 155 | EXPORT_SYMBOL_GPL(sysfs_remove_group); |
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c index d9262f74f94e..f8b82e73b3bf 100644 --- a/fs/sysfs/inode.c +++ b/fs/sysfs/inode.c | |||
@@ -30,7 +30,7 @@ static const struct address_space_operations sysfs_aops = { | |||
30 | 30 | ||
31 | static struct backing_dev_info sysfs_backing_dev_info = { | 31 | static struct backing_dev_info sysfs_backing_dev_info = { |
32 | .ra_pages = 0, /* No readahead */ | 32 | .ra_pages = 0, /* No readahead */ |
33 | .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK, | 33 | .capabilities = BDI_CAP_NO_ACCT_AND_WRITEBACK, |
34 | }; | 34 | }; |
35 | 35 | ||
36 | static const struct inode_operations sysfs_inode_operations ={ | 36 | static const struct inode_operations sysfs_inode_operations ={ |
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index 74168266cd59..14f0023984d7 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c | |||
@@ -61,7 +61,7 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent) | |||
61 | /* instantiate and link root dentry */ | 61 | /* instantiate and link root dentry */ |
62 | root = d_alloc_root(inode); | 62 | root = d_alloc_root(inode); |
63 | if (!root) { | 63 | if (!root) { |
64 | pr_debug("%s: could not get root dentry!\n",__FUNCTION__); | 64 | pr_debug("%s: could not get root dentry!\n",__func__); |
65 | iput(inode); | 65 | iput(inode); |
66 | return -ENOMEM; | 66 | return -ENOMEM; |
67 | } | 67 | } |
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index ff17f8da9b43..ce4e15f8aaeb 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -154,6 +154,8 @@ extern const struct file_operations sysfs_file_operations; | |||
154 | int sysfs_add_file(struct sysfs_dirent *dir_sd, | 154 | int sysfs_add_file(struct sysfs_dirent *dir_sd, |
155 | const struct attribute *attr, int type); | 155 | const struct attribute *attr, int type); |
156 | 156 | ||
157 | int sysfs_add_file_mode(struct sysfs_dirent *dir_sd, | ||
158 | const struct attribute *attr, int type, mode_t amode); | ||
157 | /* | 159 | /* |
158 | * bin.c | 160 | * bin.c |
159 | */ | 161 | */ |