diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-12 18:49:37 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-12 18:49:37 -0400 |
commit | efefc6eb38d43b8e5daef482f575d767b002004e (patch) | |
tree | 8a3933db1f8721f9bcc9912c800dc8406f4bdf94 /fs/sysfs/sysfs.h | |
parent | 117494a1b65183f0e3fcc817b07944bc5c465050 (diff) | |
parent | cd59abfcc441b2abb4cf2cd62c1eb0f02a60e8dd (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6
* master.kernel.org:/pub/scm/linux/kernel/git/gregkh/driver-2.6: (75 commits)
PM: merge device power-management source files
sysfs: add copyrights
kobject: update the copyrights
kset: add some kerneldoc to help describe what these strange things are
Driver core: rename ktype_edd and ktype_efivar
Driver core: rename ktype_driver
Driver core: rename ktype_device
Driver core: rename ktype_class
driver core: remove subsystem_init()
sysfs: move sysfs file poll implementation to sysfs_open_dirent
sysfs: implement sysfs_open_dirent
sysfs: move sysfs_dirent->s_children into sysfs_dirent->s_dir
sysfs: make sysfs_root a regular directory dirent
sysfs: open code sysfs_attach_dentry()
sysfs: make s_elem an anonymous union
sysfs: make bin attr open get active reference of parent too
sysfs: kill unnecessary NULL pointer check in sysfs_release()
sysfs: kill unnecessary sysfs_get() in open paths
sysfs: reposition sysfs_dirent->s_mode.
sysfs: kill sysfs_update_file()
...
Diffstat (limited to 'fs/sysfs/sysfs.h')
-rw-r--r-- | fs/sysfs/sysfs.h | 184 |
1 files changed, 111 insertions, 73 deletions
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h index 6b8c8d76d308..f0326f281d1c 100644 --- a/fs/sysfs/sysfs.h +++ b/fs/sysfs/sysfs.h | |||
@@ -1,20 +1,39 @@ | |||
1 | /* | ||
2 | * fs/sysfs/sysfs.h - sysfs internal header file | ||
3 | * | ||
4 | * Copyright (c) 2001-3 Patrick Mochel | ||
5 | * Copyright (c) 2007 SUSE Linux Products GmbH | ||
6 | * Copyright (c) 2007 Tejun Heo <teheo@suse.de> | ||
7 | * | ||
8 | * This file is released under the GPLv2. | ||
9 | */ | ||
10 | |||
11 | struct sysfs_open_dirent; | ||
12 | |||
13 | /* type-specific structures for sysfs_dirent->s_* union members */ | ||
1 | struct sysfs_elem_dir { | 14 | struct sysfs_elem_dir { |
2 | struct kobject * kobj; | 15 | struct kobject *kobj; |
16 | /* children list starts here and goes through sd->s_sibling */ | ||
17 | struct sysfs_dirent *children; | ||
3 | }; | 18 | }; |
4 | 19 | ||
5 | struct sysfs_elem_symlink { | 20 | struct sysfs_elem_symlink { |
6 | struct sysfs_dirent * target_sd; | 21 | struct sysfs_dirent *target_sd; |
7 | }; | 22 | }; |
8 | 23 | ||
9 | struct sysfs_elem_attr { | 24 | struct sysfs_elem_attr { |
10 | struct attribute * attr; | 25 | struct attribute *attr; |
26 | struct sysfs_open_dirent *open; | ||
11 | }; | 27 | }; |
12 | 28 | ||
13 | struct sysfs_elem_bin_attr { | 29 | struct sysfs_elem_bin_attr { |
14 | struct bin_attribute * bin_attr; | 30 | struct bin_attribute *bin_attr; |
15 | }; | 31 | }; |
16 | 32 | ||
17 | /* | 33 | /* |
34 | * sysfs_dirent - the building block of sysfs hierarchy. Each and | ||
35 | * every sysfs node is represented by single sysfs_dirent. | ||
36 | * | ||
18 | * As long as s_count reference is held, the sysfs_dirent itself is | 37 | * As long as s_count reference is held, the sysfs_dirent itself is |
19 | * accessible. Dereferencing s_elem or any other outer entity | 38 | * accessible. Dereferencing s_elem or any other outer entity |
20 | * requires s_active reference. | 39 | * requires s_active reference. |
@@ -22,28 +41,43 @@ struct sysfs_elem_bin_attr { | |||
22 | struct sysfs_dirent { | 41 | struct sysfs_dirent { |
23 | atomic_t s_count; | 42 | atomic_t s_count; |
24 | atomic_t s_active; | 43 | atomic_t s_active; |
25 | struct sysfs_dirent * s_parent; | 44 | struct sysfs_dirent *s_parent; |
26 | struct sysfs_dirent * s_sibling; | 45 | struct sysfs_dirent *s_sibling; |
27 | struct sysfs_dirent * s_children; | 46 | const char *s_name; |
28 | const char * s_name; | ||
29 | 47 | ||
30 | union { | 48 | union { |
31 | struct sysfs_elem_dir dir; | 49 | struct sysfs_elem_dir s_dir; |
32 | struct sysfs_elem_symlink symlink; | 50 | struct sysfs_elem_symlink s_symlink; |
33 | struct sysfs_elem_attr attr; | 51 | struct sysfs_elem_attr s_attr; |
34 | struct sysfs_elem_bin_attr bin_attr; | 52 | struct sysfs_elem_bin_attr s_bin_attr; |
35 | } s_elem; | 53 | }; |
36 | 54 | ||
37 | unsigned int s_flags; | 55 | unsigned int s_flags; |
38 | umode_t s_mode; | ||
39 | ino_t s_ino; | 56 | ino_t s_ino; |
40 | struct dentry * s_dentry; | 57 | umode_t s_mode; |
41 | struct iattr * s_iattr; | 58 | struct iattr *s_iattr; |
42 | atomic_t s_event; | ||
43 | }; | 59 | }; |
44 | 60 | ||
45 | #define SD_DEACTIVATED_BIAS INT_MIN | 61 | #define SD_DEACTIVATED_BIAS INT_MIN |
62 | |||
63 | #define SYSFS_TYPE_MASK 0x00ff | ||
64 | #define SYSFS_DIR 0x0001 | ||
65 | #define SYSFS_KOBJ_ATTR 0x0002 | ||
66 | #define SYSFS_KOBJ_BIN_ATTR 0x0004 | ||
67 | #define SYSFS_KOBJ_LINK 0x0008 | ||
68 | #define SYSFS_COPY_NAME (SYSFS_DIR | SYSFS_KOBJ_LINK) | ||
69 | |||
70 | #define SYSFS_FLAG_MASK ~SYSFS_TYPE_MASK | ||
71 | #define SYSFS_FLAG_REMOVED 0x0200 | ||
72 | |||
73 | static inline unsigned int sysfs_type(struct sysfs_dirent *sd) | ||
74 | { | ||
75 | return sd->s_flags & SYSFS_TYPE_MASK; | ||
76 | } | ||
46 | 77 | ||
78 | /* | ||
79 | * Context structure to be used while adding/removing nodes. | ||
80 | */ | ||
47 | struct sysfs_addrm_cxt { | 81 | struct sysfs_addrm_cxt { |
48 | struct sysfs_dirent *parent_sd; | 82 | struct sysfs_dirent *parent_sd; |
49 | struct inode *parent_inode; | 83 | struct inode *parent_inode; |
@@ -51,63 +85,47 @@ struct sysfs_addrm_cxt { | |||
51 | int cnt; | 85 | int cnt; |
52 | }; | 86 | }; |
53 | 87 | ||
54 | extern struct vfsmount * sysfs_mount; | 88 | /* |
89 | * mount.c | ||
90 | */ | ||
55 | extern struct sysfs_dirent sysfs_root; | 91 | extern struct sysfs_dirent sysfs_root; |
92 | extern struct super_block *sysfs_sb; | ||
56 | extern struct kmem_cache *sysfs_dir_cachep; | 93 | extern struct kmem_cache *sysfs_dir_cachep; |
57 | 94 | ||
58 | extern struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); | 95 | /* |
59 | extern void sysfs_link_sibling(struct sysfs_dirent *sd); | 96 | * dir.c |
60 | extern void sysfs_unlink_sibling(struct sysfs_dirent *sd); | 97 | */ |
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); | ||
72 | |||
73 | extern void sysfs_delete_inode(struct inode *inode); | ||
74 | extern struct inode * sysfs_get_inode(struct sysfs_dirent *sd); | ||
75 | extern void sysfs_instantiate(struct dentry *dentry, struct inode *inode); | ||
76 | |||
77 | extern void release_sysfs_dirent(struct sysfs_dirent * sd); | ||
78 | extern struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, | ||
79 | const unsigned char *name); | ||
80 | extern struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, | ||
81 | const unsigned char *name); | ||
82 | extern struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, | ||
83 | int type); | ||
84 | |||
85 | extern int sysfs_add_file(struct sysfs_dirent *dir_sd, | ||
86 | const struct attribute *attr, int type); | ||
87 | extern int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); | ||
88 | extern struct sysfs_dirent *sysfs_find(struct sysfs_dirent *dir, const char * name); | ||
89 | |||
90 | extern int sysfs_create_subdir(struct kobject *kobj, const char *name, | ||
91 | struct sysfs_dirent **p_sd); | ||
92 | extern void sysfs_remove_subdir(struct sysfs_dirent *sd); | ||
93 | |||
94 | extern int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); | ||
95 | |||
96 | extern spinlock_t sysfs_assoc_lock; | ||
97 | extern struct mutex sysfs_mutex; | 98 | extern struct mutex sysfs_mutex; |
98 | extern struct super_block * sysfs_sb; | 99 | extern struct mutex sysfs_rename_mutex; |
100 | extern spinlock_t sysfs_assoc_lock; | ||
101 | |||
99 | extern const struct file_operations sysfs_dir_operations; | 102 | extern const struct file_operations sysfs_dir_operations; |
100 | extern const struct file_operations sysfs_file_operations; | ||
101 | extern const struct file_operations bin_fops; | ||
102 | extern const struct inode_operations sysfs_dir_inode_operations; | 103 | extern const struct inode_operations sysfs_dir_inode_operations; |
103 | extern const struct inode_operations sysfs_symlink_inode_operations; | ||
104 | |||
105 | static inline unsigned int sysfs_type(struct sysfs_dirent *sd) | ||
106 | { | ||
107 | return sd->s_flags & SYSFS_TYPE_MASK; | ||
108 | } | ||
109 | 104 | ||
110 | static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) | 105 | struct dentry *sysfs_get_dentry(struct sysfs_dirent *sd); |
106 | struct sysfs_dirent *sysfs_get_active(struct sysfs_dirent *sd); | ||
107 | void sysfs_put_active(struct sysfs_dirent *sd); | ||
108 | struct sysfs_dirent *sysfs_get_active_two(struct sysfs_dirent *sd); | ||
109 | void sysfs_put_active_two(struct sysfs_dirent *sd); | ||
110 | void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, | ||
111 | struct sysfs_dirent *parent_sd); | ||
112 | int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); | ||
113 | void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); | ||
114 | void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); | ||
115 | |||
116 | struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd, | ||
117 | const unsigned char *name); | ||
118 | struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, | ||
119 | const unsigned char *name); | ||
120 | struct sysfs_dirent *sysfs_new_dirent(const char *name, umode_t mode, int type); | ||
121 | |||
122 | void release_sysfs_dirent(struct sysfs_dirent *sd); | ||
123 | |||
124 | int sysfs_create_subdir(struct kobject *kobj, const char *name, | ||
125 | struct sysfs_dirent **p_sd); | ||
126 | void sysfs_remove_subdir(struct sysfs_dirent *sd); | ||
127 | |||
128 | static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) | ||
111 | { | 129 | { |
112 | if (sd) { | 130 | if (sd) { |
113 | WARN_ON(!atomic_read(&sd->s_count)); | 131 | WARN_ON(!atomic_read(&sd->s_count)); |
@@ -116,13 +134,33 @@ static inline struct sysfs_dirent * sysfs_get(struct sysfs_dirent * sd) | |||
116 | return sd; | 134 | return sd; |
117 | } | 135 | } |
118 | 136 | ||
119 | static inline void sysfs_put(struct sysfs_dirent * sd) | 137 | static inline void sysfs_put(struct sysfs_dirent *sd) |
120 | { | 138 | { |
121 | if (sd && atomic_dec_and_test(&sd->s_count)) | 139 | if (sd && atomic_dec_and_test(&sd->s_count)) |
122 | release_sysfs_dirent(sd); | 140 | release_sysfs_dirent(sd); |
123 | } | 141 | } |
124 | 142 | ||
125 | static inline int sysfs_is_shadowed_inode(struct inode *inode) | 143 | /* |
126 | { | 144 | * inode.c |
127 | return S_ISDIR(inode->i_mode) && inode->i_op->follow_link; | 145 | */ |
128 | } | 146 | struct inode *sysfs_get_inode(struct sysfs_dirent *sd); |
147 | int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); | ||
148 | int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); | ||
149 | |||
150 | /* | ||
151 | * file.c | ||
152 | */ | ||
153 | extern const struct file_operations sysfs_file_operations; | ||
154 | |||
155 | int sysfs_add_file(struct sysfs_dirent *dir_sd, | ||
156 | const struct attribute *attr, int type); | ||
157 | |||
158 | /* | ||
159 | * bin.c | ||
160 | */ | ||
161 | extern const struct file_operations bin_fops; | ||
162 | |||
163 | /* | ||
164 | * symlink.c | ||
165 | */ | ||
166 | extern const struct inode_operations sysfs_symlink_inode_operations; | ||