aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/sysfs/dir.c33
-rw-r--r--fs/sysfs/inode.c8
-rw-r--r--fs/sysfs/mount.c2
-rw-r--r--fs/sysfs/sysfs.h7
-rw-r--r--include/linux/sysfs.h3
5 files changed, 34 insertions, 19 deletions
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index b4074adbab01..eb9bc0a8717b 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -218,9 +218,9 @@ void release_sysfs_dirent(struct sysfs_dirent * sd)
218 repeat: 218 repeat:
219 parent_sd = sd->s_parent; 219 parent_sd = sd->s_parent;
220 220
221 if (sd->s_type & SYSFS_KOBJ_LINK) 221 if (sysfs_type(sd) == SYSFS_KOBJ_LINK)
222 sysfs_put(sd->s_elem.symlink.target_sd); 222 sysfs_put(sd->s_elem.symlink.target_sd);
223 if (sd->s_type & SYSFS_COPY_NAME) 223 if (sysfs_type(sd) & SYSFS_COPY_NAME)
224 kfree(sd->s_name); 224 kfree(sd->s_name);
225 kfree(sd->s_iattr); 225 kfree(sd->s_iattr);
226 sysfs_free_ino(sd->s_ino); 226 sysfs_free_ino(sd->s_ino);
@@ -282,7 +282,7 @@ struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type)
282 282
283 sd->s_name = name; 283 sd->s_name = name;
284 sd->s_mode = mode; 284 sd->s_mode = mode;
285 sd->s_type = type; 285 sd->s_flags = type;
286 286
287 return sd; 287 return sd;
288 288
@@ -330,7 +330,7 @@ int sysfs_dirent_exist(struct sysfs_dirent *parent_sd,
330 struct sysfs_dirent * sd; 330 struct sysfs_dirent * sd;
331 331
332 for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) { 332 for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) {
333 if (sd->s_type) { 333 if (sysfs_type(sd)) {
334 if (strcmp(sd->s_name, new)) 334 if (strcmp(sd->s_name, new))
335 continue; 335 continue;
336 else 336 else
@@ -446,11 +446,12 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
446{ 446{
447 struct sysfs_dirent * parent_sd = dentry->d_parent->d_fsdata; 447 struct sysfs_dirent * parent_sd = dentry->d_parent->d_fsdata;
448 struct sysfs_dirent * sd; 448 struct sysfs_dirent * sd;
449 struct bin_attribute *bin_attr;
449 struct inode *inode; 450 struct inode *inode;
450 int found = 0; 451 int found = 0;
451 452
452 for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) { 453 for (sd = parent_sd->s_children; sd; sd = sd->s_sibling) {
453 if ((sd->s_type & SYSFS_NOT_PINNED) && 454 if ((sysfs_type(sd) & SYSFS_NOT_PINNED) &&
454 !strcmp(sd->s_name, dentry->d_name.name)) { 455 !strcmp(sd->s_name, dentry->d_name.name)) {
455 found = 1; 456 found = 1;
456 break; 457 break;
@@ -468,16 +469,22 @@ static struct dentry * sysfs_lookup(struct inode *dir, struct dentry *dentry,
468 469
469 if (inode->i_state & I_NEW) { 470 if (inode->i_state & I_NEW) {
470 /* initialize inode according to type */ 471 /* initialize inode according to type */
471 if (sd->s_type & SYSFS_KOBJ_ATTR) { 472 switch (sysfs_type(sd)) {
473 case SYSFS_KOBJ_ATTR:
472 inode->i_size = PAGE_SIZE; 474 inode->i_size = PAGE_SIZE;
473 inode->i_fop = &sysfs_file_operations; 475 inode->i_fop = &sysfs_file_operations;
474 } else if (sd->s_type & SYSFS_KOBJ_BIN_ATTR) { 476 break;
475 struct bin_attribute *bin_attr = 477 case SYSFS_KOBJ_BIN_ATTR:
476 sd->s_elem.bin_attr.bin_attr; 478 bin_attr = sd->s_elem.bin_attr.bin_attr;
477 inode->i_size = bin_attr->size; 479 inode->i_size = bin_attr->size;
478 inode->i_fop = &bin_fops; 480 inode->i_fop = &bin_fops;
479 } else if (sd->s_type & SYSFS_KOBJ_LINK) 481 break;
482 case SYSFS_KOBJ_LINK:
480 inode->i_op = &sysfs_symlink_inode_operations; 483 inode->i_op = &sysfs_symlink_inode_operations;
484 break;
485 default:
486 BUG();
487 }
481 } 488 }
482 489
483 sysfs_instantiate(dentry, inode); 490 sysfs_instantiate(dentry, inode);
@@ -532,7 +539,7 @@ static void __sysfs_remove_dir(struct dentry *dentry)
532 while (*pos) { 539 while (*pos) {
533 struct sysfs_dirent *sd = *pos; 540 struct sysfs_dirent *sd = *pos;
534 541
535 if (sd->s_type && (sd->s_type & SYSFS_NOT_PINNED)) { 542 if (sysfs_type(sd) && (sysfs_type(sd) & SYSFS_NOT_PINNED)) {
536 *pos = sd->s_sibling; 543 *pos = sd->s_sibling;
537 sd->s_sibling = removed; 544 sd->s_sibling = removed;
538 removed = sd; 545 removed = sd;
@@ -775,7 +782,7 @@ static int sysfs_readdir(struct file * filp, void * dirent, filldir_t filldir)
775 const char * name; 782 const char * name;
776 int len; 783 int len;
777 784
778 if (!next->s_type) 785 if (!sysfs_type(next))
779 continue; 786 continue;
780 787
781 name = next->s_name; 788 name = next->s_name;
@@ -824,7 +831,7 @@ static loff_t sysfs_dir_lseek(struct file * file, loff_t offset, int origin)
824 pos = &sd->s_children; 831 pos = &sd->s_children;
825 while (n && *pos) { 832 while (n && *pos) {
826 struct sysfs_dirent *next = *pos; 833 struct sysfs_dirent *next = *pos;
827 if (next->s_type) 834 if (sysfs_type(next))
828 n--; 835 n--;
829 pos = &(*pos)->s_sibling; 836 pos = &(*pos)->s_sibling;
830 } 837 }
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index 63daa06c4194..ee3a5d957051 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -242,7 +242,7 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
242 242
243 dput(dentry); 243 dput(dentry);
244 /* XXX: unpin if directory, this will go away soon */ 244 /* XXX: unpin if directory, this will go away soon */
245 if (sd->s_type & SYSFS_DIR) 245 if (sysfs_type(sd) == SYSFS_DIR)
246 dput(dentry); 246 dput(dentry);
247 247
248 /* adjust nlink and update timestamp */ 248 /* adjust nlink and update timestamp */
@@ -254,7 +254,7 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
254 254
255 inode->i_ctime = curtime; 255 inode->i_ctime = curtime;
256 drop_nlink(inode); 256 drop_nlink(inode);
257 if (sd->s_type & SYSFS_DIR) 257 if (sysfs_type(sd) == SYSFS_DIR)
258 drop_nlink(inode); 258 drop_nlink(inode);
259 259
260 mutex_unlock(&inode->i_mutex); 260 mutex_unlock(&inode->i_mutex);
@@ -267,7 +267,7 @@ void sysfs_drop_dentry(struct sysfs_dirent *sd)
267 mutex_lock(&inode->i_mutex); 267 mutex_lock(&inode->i_mutex);
268 268
269 inode->i_ctime = inode->i_mtime = curtime; 269 inode->i_ctime = inode->i_mtime = curtime;
270 if (sd->s_type & SYSFS_DIR) 270 if (sysfs_type(sd) == SYSFS_DIR)
271 drop_nlink(inode); 271 drop_nlink(inode);
272 272
273 mutex_unlock(&inode->i_mutex); 273 mutex_unlock(&inode->i_mutex);
@@ -293,7 +293,7 @@ int sysfs_hash_and_remove(struct dentry * dir, const char * name)
293 for (pos = &parent_sd->s_children; *pos; pos = &(*pos)->s_sibling) { 293 for (pos = &parent_sd->s_children; *pos; pos = &(*pos)->s_sibling) {
294 sd = *pos; 294 sd = *pos;
295 295
296 if (!sd->s_type) 296 if (!sysfs_type(sd))
297 continue; 297 continue;
298 if (!strcmp(sd->s_name, name)) { 298 if (!strcmp(sd->s_name, name)) {
299 *pos = sd->s_sibling; 299 *pos = sd->s_sibling;
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index 4be9593ea000..078537e5d696 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -26,7 +26,7 @@ static const struct super_operations sysfs_ops = {
26 26
27static struct sysfs_dirent sysfs_root = { 27static struct sysfs_dirent sysfs_root = {
28 .s_count = ATOMIC_INIT(1), 28 .s_count = ATOMIC_INIT(1),
29 .s_type = SYSFS_ROOT, 29 .s_flags = SYSFS_ROOT,
30 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO, 30 .s_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
31 .s_ino = 1, 31 .s_ino = 1,
32}; 32};
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 6f8aaf3805d2..06b5085804a1 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -34,7 +34,7 @@ struct sysfs_dirent {
34 struct sysfs_elem_bin_attr bin_attr; 34 struct sysfs_elem_bin_attr bin_attr;
35 } s_elem; 35 } s_elem;
36 36
37 int s_type; 37 unsigned int s_flags;
38 umode_t s_mode; 38 umode_t s_mode;
39 ino_t s_ino; 39 ino_t s_ino;
40 struct dentry * s_dentry; 40 struct dentry * s_dentry;
@@ -86,6 +86,11 @@ extern const struct file_operations bin_fops;
86extern const struct inode_operations sysfs_dir_inode_operations; 86extern const struct inode_operations sysfs_dir_inode_operations;
87extern const struct inode_operations sysfs_symlink_inode_operations; 87extern const struct inode_operations sysfs_symlink_inode_operations;
88 88
89static inline unsigned int sysfs_type(struct sysfs_dirent *sd)
90{
91 return sd->s_flags & SYSFS_TYPE_MASK;
92}
93
89static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) 94static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd)
90{ 95{
91 if (sd) { 96 if (sd) {
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 161e19aa2b4f..58135509023e 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -74,6 +74,7 @@ struct sysfs_ops {
74 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); 74 ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t);
75}; 75};
76 76
77#define SYSFS_TYPE_MASK 0x00ff
77#define SYSFS_ROOT 0x0001 78#define SYSFS_ROOT 0x0001
78#define SYSFS_DIR 0x0002 79#define SYSFS_DIR 0x0002
79#define SYSFS_KOBJ_ATTR 0x0004 80#define SYSFS_KOBJ_ATTR 0x0004
@@ -82,6 +83,8 @@ struct sysfs_ops {
82#define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK) 83#define SYSFS_NOT_PINNED (SYSFS_KOBJ_ATTR | SYSFS_KOBJ_BIN_ATTR | SYSFS_KOBJ_LINK)
83#define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK) 84#define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK)
84 85
86#define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK
87
85#ifdef CONFIG_SYSFS 88#ifdef CONFIG_SYSFS
86 89
87extern int sysfs_schedule_callback(struct kobject *kobj, 90extern int sysfs_schedule_callback(struct kobject *kobj,