diff options
Diffstat (limited to 'fs/sysfs/sysfs.h')
-rw-r--r-- | fs/sysfs/sysfs.h | 169 |
1 files changed, 83 insertions, 86 deletions
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 502c949c402d..6a37f2386a8d 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -1,9 +1,40 @@ | |||
1 | struct sysfs_elem_dir { | ||
2 | struct kobject * kobj; | ||
3 | }; | ||
4 | |||
5 | struct sysfs_elem_symlink { | ||
6 | struct sysfs_dirent * target_sd; | ||
7 | }; | ||
8 | |||
9 | struct sysfs_elem_attr { | ||
10 | struct attribute * attr; | ||
11 | }; | ||
12 | |||
13 | struct sysfs_elem_bin_attr { | ||
14 | struct bin_attribute * bin_attr; | ||
15 | }; | ||
16 | |||
17 | /* | ||
18 | * As long as s_count reference is held, the sysfs_dirent itself is | ||
19 | * accessible. Dereferencing s_elem or any other outer entity | ||
20 | * requires s_active reference. | ||
21 | */ | ||
1 | struct sysfs_dirent { | 22 | struct sysfs_dirent { |
2 | atomic_t s_count; | 23 | atomic_t s_count; |
3 | struct list_head s_sibling; | 24 | atomic_t s_active; |
4 | struct list_head s_children; | 25 | struct sysfs_dirent * s_parent; |
5 | void * s_element; | 26 | struct sysfs_dirent * s_sibling; |
6 | int s_type; | 27 | struct sysfs_dirent * s_children; |
28 | const char * s_name; | ||
29 | |||
30 | union { | ||
31 | struct sysfs_elem_dir dir; | ||
32 | struct sysfs_elem_symlink symlink; | ||
33 | struct sysfs_elem_attr attr; | ||
34 | struct sysfs_elem_bin_attr bin_attr; | ||
35 | } s_elem; | ||
36 | |||
37 | unsigned int s_flags; | ||
7 | umode_t s_mode; | 38 | umode_t s_mode; |
8 | ino_t s_ino; | 39 | ino_t s_ino; |
9 | struct dentry * s_dentry; | 40 | struct dentry * s_dentry; |
@@ -11,30 +42,60 @@ struct sysfs_dirent { | |||
11 | atomic_t s_event; | 42 | atomic_t s_event; |
12 | }; | 43 | }; |
13 | 44 | ||
45 | #define SD_DEACTIVATED_BIAS INT_MIN | ||
46 | |||
47 | struct sysfs_addrm_cxt { | ||
48 | struct sysfs_dirent *parent_sd; | ||
49 | struct inode *parent_inode; | ||
50 | struct sysfs_dirent *removed; | ||
51 | int cnt; | ||
52 | }; | ||
53 | |||
14 | extern struct vfsmount * sysfs_mount; | 54 | extern struct vfsmount * sysfs_mount; |
55 | extern struct sysfs_dirent sysfs_root; | ||
15 | extern struct kmem_cache *sysfs_dir_cachep; | 56 | extern struct kmem_cache *sysfs_dir_cachep; |
16 | 57 | ||
17 | extern void sysfs_delete_inode(struct inode *inode); | 58 | extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); |
18 | extern struct inode * sysfs_new_inode(mode_t mode, struct sysfs_dirent *); | 59 | extern void sysfs_link_sibling(struct sysfs_dirent *sd); |
19 | extern int sysfs_create(struct dentry *, int mode, int (*init)(struct inode *)); | 60 | extern void sysfs_unlink_sibling(struct sysfs_dirent *sd); |
61 | extern struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); | ||
62 | extern void sysfs_put_active(struct sysfs_dirent *sd); | ||
63 | extern struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd); | ||
64 | extern void sysfs_put_active_two(struct sysfs_dirent *sd); | ||
65 | extern void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, | ||
66 | struct sysfs_dirent *parent_sd); | ||
67 | extern void sysfs_add_one(struct sysfs_addrm_cxt *acxt, | ||
68 | struct sysfs_dirent *sd); | ||
69 | extern void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, | ||
70 | struct sysfs_dirent *sd); | ||
71 | extern int sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); | ||
20 | 72 | ||
21 | extern int sysfs_dirent_exist(struct sysfs_dirent *, const unsigned char *); | 73 | extern void sysfs_delete_inode(struct inode *inode); |
22 | extern int sysfs_make_dirent(struct sysfs_dirent *, struct dentry *, void *, | 74 | extern void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode); |
23 | umode_t, int); | 75 | extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd); |
24 | 76 | extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode); | |
25 | extern int sysfs_add_file(struct dentry *, const struct attribute *, int); | 77 | |
26 | extern int sysfs_hash_and_remove(struct dentry * dir, const char * name); | 78 | extern void release_sysfs_dirent(struct sysfs_dirent * sd); |
79 | extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, | ||
80 | const unsigned char *name); | ||
81 | extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, | ||
82 | const unsigned char *name); | ||
83 | extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, | ||
84 | int type); | ||
85 | |||
86 | extern int sysfs_add_file(struct sysfs_dirent *dir_sd, | ||
87 | const struct attribute *attr, int type); | ||
88 | extern int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); | ||
27 | extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); | 89 | extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); |
28 | 90 | ||
29 | extern int sysfs_create_subdir(struct kobject *, const char *, struct dentry **); | 91 | extern int sysfs_create_subdir(struct kobject *kobj, const char *name, |
30 | extern void sysfs_remove_subdir(struct dentry *); | 92 | struct sysfs_dirent **p_sd); |
93 | extern void sysfs_remove_subdir(struct sysfs_dirent *sd); | ||
31 | 94 | ||
32 | extern const unsigned char * sysfs_get_name(struct sysfs_dirent *sd); | ||
33 | extern void sysfs_drop_dentry(struct sysfs_dirent *sd, struct dentry *parent); | ||
34 | extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); | 95 | extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); |
35 | 96 | ||
36 | extern spinlock_t sysfs_lock; | 97 | extern spinlock_t sysfs_assoc_lock; |
37 | extern struct rw_semaphore sysfs_rename_sem; | 98 | extern struct mutex sysfs_mutex; |
38 | extern struct super_block * sysfs_sb; | 99 | extern struct super_block * sysfs_sb; |
39 | extern const struct file_operations sysfs_dir_operations; | 100 | extern const struct file_operations sysfs_dir_operations; |
40 | extern const struct file_operations sysfs_file_operations; | 101 | extern const struct file_operations sysfs_file_operations; |
@@ -42,73 +103,9 @@ extern const struct file_operations bin_fops; | |||
42 | extern const struct inode_operations sysfs_dir_inode_operations; | 103 | extern const struct inode_operations sysfs_dir_inode_operations; |
43 | extern const struct inode_operations sysfs_symlink_inode_operations; | 104 | extern const struct inode_operations sysfs_symlink_inode_operations; |
44 | 105 | ||
45 | struct sysfs_symlink { | 106 | static inline unsigned int sysfs_type(struct sysfs_dirent *sd) |
46 | char * link_name; | ||
47 | struct kobject * target_kobj; | ||
48 | }; | ||
49 | |||
50 | struct sysfs_buffer { | ||
51 | struct list_head associates; | ||
52 | size_t count; | ||
53 | loff_t pos; | ||
54 | char * page; | ||
55 | struct sysfs_ops * ops; | ||
56 | struct semaphore sem; | ||
57 | int orphaned; | ||
58 | int needs_read_fill; | ||
59 | int event; | ||
60 | }; | ||
61 | |||
62 | struct sysfs_buffer_collection { | ||
63 | struct list_head associates; | ||
64 | }; | ||
65 | |||
66 | static inline struct kobject * to_kobj(struct dentry * dentry) | ||
67 | { | ||
68 | struct sysfs_dirent * sd = dentry->d_fsdata; | ||
69 | return ((struct kobject *) sd->s_element); | ||
70 | } | ||
71 | |||
72 | static inline struct attribute * to_attr(struct dentry * dentry) | ||
73 | { | 107 | { |
74 | struct sysfs_dirent * sd = dentry->d_fsdata; | 108 | return sd->s_flags & SYSFS_TYPE_MASK; |
75 | return ((struct attribute *) sd->s_element); | ||
76 | } | ||
77 | |||
78 | static inline struct bin_attribute * to_bin_attr(struct dentry * dentry) | ||
79 | { | ||
80 | struct sysfs_dirent * sd = dentry->d_fsdata; | ||
81 | return ((struct bin_attribute *) sd->s_element); | ||
82 | } | ||
83 | |||
84 | static inline struct kobject *sysfs_get_kobject(struct dentry *dentry) | ||
85 | { | ||
86 | struct kobject * kobj = NULL; | ||
87 | |||
88 | spin_lock(&dcache_lock); | ||
89 | if (!d_unhashed(dentry)) { | ||
90 | struct sysfs_dirent * sd = dentry->d_fsdata; | ||
91 | if (sd->s_type & SYSFS_KOBJ_LINK) { | ||
92 | struct sysfs_symlink * sl = sd->s_element; | ||
93 | kobj = kobject_get(sl->target_kobj); | ||
94 | } else | ||
95 | kobj = kobject_get(sd->s_element); | ||
96 | } | ||
97 | spin_unlock(&dcache_lock); | ||
98 | |||
99 | return kobj; | ||
100 | } | ||
101 | |||
102 | static inline void release_sysfs_dirent(struct sysfs_dirent * sd) | ||
103 | { | ||
104 | if (sd->s_type & SYSFS_KOBJ_LINK) { | ||
105 | struct sysfs_symlink * sl = sd->s_element; | ||
106 | kfree(sl->link_name); | ||
107 | kobject_put(sl->target_kobj); | ||
108 | kfree(sl); | ||
109 | } | ||
110 | kfree(sd->s_iattr); | ||
111 | kmem_cache_free(sysfs_dir_cachep, sd); | ||
112 | } | 109 | } |
113 | 110 | ||
114 | static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) | 111 | static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) |
@@ -122,7 +119,7 @@ static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) | |||
122 | 119 | ||
123 | static inline void sysfs_put(struct sysfs_dirent * sd) | 120 | static inline void sysfs_put(struct sysfs_dirent * sd) |
124 | { | 121 | { |
125 | if (atomic_dec_and_test(&sd->s_count)) | 122 | if (sd && atomic_dec_and_test(&sd->s_count)) |
126 | release_sysfs_dirent(sd); | 123 | release_sysfs_dirent(sd); |
127 | } | 124 | } |
128 | 125 | ||