diff options
Diffstat (limited to 'include/linux/sysfs.h')
| -rw-r--r-- | include/linux/sysfs.h | 100 |
1 files changed, 88 insertions, 12 deletions
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index cfa83083a2d4..96eb576d82fd 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h | |||
| @@ -15,22 +15,44 @@ | |||
| 15 | #include <linux/compiler.h> | 15 | #include <linux/compiler.h> |
| 16 | #include <linux/errno.h> | 16 | #include <linux/errno.h> |
| 17 | #include <linux/list.h> | 17 | #include <linux/list.h> |
| 18 | #include <linux/lockdep.h> | ||
| 19 | #include <linux/kobject_ns.h> | ||
| 18 | #include <asm/atomic.h> | 20 | #include <asm/atomic.h> |
| 19 | 21 | ||
| 20 | struct kobject; | 22 | struct kobject; |
| 21 | struct module; | 23 | struct module; |
| 24 | enum kobj_ns_type; | ||
| 22 | 25 | ||
| 23 | /* FIXME | ||
| 24 | * The *owner field is no longer used. | ||
| 25 | * x86 tree has been cleaned up. The owner | ||
| 26 | * attribute is still left for other arches. | ||
| 27 | */ | ||
| 28 | struct attribute { | 26 | struct attribute { |
| 29 | const char *name; | 27 | const char *name; |
| 30 | struct module *owner; | ||
| 31 | mode_t mode; | 28 | mode_t mode; |
| 29 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
| 30 | struct lock_class_key *key; | ||
| 31 | struct lock_class_key skey; | ||
| 32 | #endif | ||
| 32 | }; | 33 | }; |
| 33 | 34 | ||
| 35 | /** | ||
| 36 | * sysfs_attr_init - initialize a dynamically allocated sysfs attribute | ||
| 37 | * @attr: struct attribute to initialize | ||
| 38 | * | ||
| 39 | * Initialize a dynamically allocated struct attribute so we can | ||
| 40 | * make lockdep happy. This is a new requirement for attributes | ||
| 41 | * and initially this is only needed when lockdep is enabled. | ||
| 42 | * Lockdep gives a nice error when your attribute is added to | ||
| 43 | * sysfs if you don't have this. | ||
| 44 | */ | ||
| 45 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
| 46 | #define sysfs_attr_init(attr) \ | ||
| 47 | do { \ | ||
| 48 | static struct lock_class_key __key; \ | ||
| 49 | \ | ||
| 50 | (attr)->key = &__key; \ | ||
| 51 | } while(0) | ||
| 52 | #else | ||
| 53 | #define sysfs_attr_init(attr) do {} while(0) | ||
| 54 | #endif | ||
| 55 | |||
| 34 | struct attribute_group { | 56 | struct attribute_group { |
| 35 | const char *name; | 57 | const char *name; |
| 36 | mode_t (*is_visible)(struct kobject *, | 58 | mode_t (*is_visible)(struct kobject *, |
| @@ -60,20 +82,33 @@ struct attribute_group { | |||
| 60 | 82 | ||
| 61 | #define attr_name(_attr) (_attr).attr.name | 83 | #define attr_name(_attr) (_attr).attr.name |
| 62 | 84 | ||
| 85 | struct file; | ||
| 63 | struct vm_area_struct; | 86 | struct vm_area_struct; |
| 64 | 87 | ||
| 65 | struct bin_attribute { | 88 | struct bin_attribute { |
| 66 | struct attribute attr; | 89 | struct attribute attr; |
| 67 | size_t size; | 90 | size_t size; |
| 68 | void *private; | 91 | void *private; |
| 69 | ssize_t (*read)(struct kobject *, struct bin_attribute *, | 92 | ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, |
| 70 | char *, loff_t, size_t); | 93 | char *, loff_t, size_t); |
| 71 | ssize_t (*write)(struct kobject *, struct bin_attribute *, | 94 | ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *, |
| 72 | char *, loff_t, size_t); | 95 | char *, loff_t, size_t); |
| 73 | int (*mmap)(struct kobject *, struct bin_attribute *attr, | 96 | int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr, |
| 74 | struct vm_area_struct *vma); | 97 | struct vm_area_struct *vma); |
| 75 | }; | 98 | }; |
| 76 | 99 | ||
| 100 | /** | ||
| 101 | * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute | ||
| 102 | * @attr: struct bin_attribute to initialize | ||
| 103 | * | ||
| 104 | * Initialize a dynamically allocated struct bin_attribute so we | ||
| 105 | * can make lockdep happy. This is a new requirement for | ||
| 106 | * attributes and initially this is only needed when lockdep is | ||
| 107 | * enabled. Lockdep gives a nice error when your attribute is | ||
| 108 | * added to sysfs if you don't have this. | ||
| 109 | */ | ||
| 110 | #define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) | ||
| 111 | |||
| 77 | struct sysfs_ops { | 112 | struct sysfs_ops { |
| 78 | ssize_t (*show)(struct kobject *, struct attribute *,char *); | 113 | ssize_t (*show)(struct kobject *, struct attribute *,char *); |
| 79 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); | 114 | ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); |
| @@ -94,9 +129,12 @@ int __must_check sysfs_move_dir(struct kobject *kobj, | |||
| 94 | 129 | ||
| 95 | int __must_check sysfs_create_file(struct kobject *kobj, | 130 | int __must_check sysfs_create_file(struct kobject *kobj, |
| 96 | const struct attribute *attr); | 131 | const struct attribute *attr); |
| 97 | int __must_check sysfs_chmod_file(struct kobject *kobj, struct attribute *attr, | 132 | int __must_check sysfs_create_files(struct kobject *kobj, |
| 98 | mode_t mode); | 133 | const struct attribute **attr); |
| 134 | int __must_check sysfs_chmod_file(struct kobject *kobj, | ||
| 135 | const struct attribute *attr, mode_t mode); | ||
| 99 | void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr); | 136 | void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr); |
| 137 | void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr); | ||
| 100 | 138 | ||
| 101 | int __must_check sysfs_create_bin_file(struct kobject *kobj, | 139 | int __must_check sysfs_create_bin_file(struct kobject *kobj, |
| 102 | const struct bin_attribute *attr); | 140 | const struct bin_attribute *attr); |
| @@ -110,6 +148,12 @@ int __must_check sysfs_create_link_nowarn(struct kobject *kobj, | |||
| 110 | const char *name); | 148 | const char *name); |
| 111 | void sysfs_remove_link(struct kobject *kobj, const char *name); | 149 | void sysfs_remove_link(struct kobject *kobj, const char *name); |
| 112 | 150 | ||
| 151 | int sysfs_rename_link(struct kobject *kobj, struct kobject *target, | ||
| 152 | const char *old_name, const char *new_name); | ||
| 153 | |||
| 154 | void sysfs_delete_link(struct kobject *dir, struct kobject *targ, | ||
| 155 | const char *name); | ||
| 156 | |||
| 113 | int __must_check sysfs_create_group(struct kobject *kobj, | 157 | int __must_check sysfs_create_group(struct kobject *kobj, |
| 114 | const struct attribute_group *grp); | 158 | const struct attribute_group *grp); |
| 115 | int sysfs_update_group(struct kobject *kobj, | 159 | int sysfs_update_group(struct kobject *kobj, |
| @@ -124,10 +168,15 @@ void sysfs_remove_file_from_group(struct kobject *kobj, | |||
| 124 | void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); | 168 | void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); |
| 125 | void sysfs_notify_dirent(struct sysfs_dirent *sd); | 169 | void sysfs_notify_dirent(struct sysfs_dirent *sd); |
| 126 | struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, | 170 | struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, |
| 171 | const void *ns, | ||
| 127 | const unsigned char *name); | 172 | const unsigned char *name); |
| 128 | struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd); | 173 | struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd); |
| 129 | void sysfs_put(struct sysfs_dirent *sd); | 174 | void sysfs_put(struct sysfs_dirent *sd); |
| 130 | void sysfs_printk_last_file(void); | 175 | void sysfs_printk_last_file(void); |
| 176 | |||
| 177 | /* Called to clear a ns tag when it is no longer valid */ | ||
| 178 | void sysfs_exit_ns(enum kobj_ns_type type, const void *tag); | ||
| 179 | |||
| 131 | int __must_check sysfs_init(void); | 180 | int __must_check sysfs_init(void); |
| 132 | 181 | ||
| 133 | #else /* CONFIG_SYSFS */ | 182 | #else /* CONFIG_SYSFS */ |
| @@ -164,8 +213,14 @@ static inline int sysfs_create_file(struct kobject *kobj, | |||
| 164 | return 0; | 213 | return 0; |
| 165 | } | 214 | } |
| 166 | 215 | ||
| 216 | static inline int sysfs_create_files(struct kobject *kobj, | ||
| 217 | const struct attribute **attr) | ||
| 218 | { | ||
| 219 | return 0; | ||
| 220 | } | ||
| 221 | |||
| 167 | static inline int sysfs_chmod_file(struct kobject *kobj, | 222 | static inline int sysfs_chmod_file(struct kobject *kobj, |
| 168 | struct attribute *attr, mode_t mode) | 223 | const struct attribute *attr, mode_t mode) |
| 169 | { | 224 | { |
| 170 | return 0; | 225 | return 0; |
| 171 | } | 226 | } |
| @@ -175,6 +230,11 @@ static inline void sysfs_remove_file(struct kobject *kobj, | |||
| 175 | { | 230 | { |
| 176 | } | 231 | } |
| 177 | 232 | ||
| 233 | static inline void sysfs_remove_files(struct kobject *kobj, | ||
| 234 | const struct attribute **attr) | ||
| 235 | { | ||
| 236 | } | ||
| 237 | |||
| 178 | static inline int sysfs_create_bin_file(struct kobject *kobj, | 238 | static inline int sysfs_create_bin_file(struct kobject *kobj, |
| 179 | const struct bin_attribute *attr) | 239 | const struct bin_attribute *attr) |
| 180 | { | 240 | { |
| @@ -203,6 +263,17 @@ static inline void sysfs_remove_link(struct kobject *kobj, const char *name) | |||
| 203 | { | 263 | { |
| 204 | } | 264 | } |
| 205 | 265 | ||
| 266 | static inline int sysfs_rename_link(struct kobject *k, struct kobject *t, | ||
| 267 | const char *old_name, const char *new_name) | ||
| 268 | { | ||
| 269 | return 0; | ||
| 270 | } | ||
| 271 | |||
| 272 | static inline void sysfs_delete_link(struct kobject *k, struct kobject *t, | ||
| 273 | const char *name) | ||
| 274 | { | ||
| 275 | } | ||
| 276 | |||
| 206 | static inline int sysfs_create_group(struct kobject *kobj, | 277 | static inline int sysfs_create_group(struct kobject *kobj, |
| 207 | const struct attribute_group *grp) | 278 | const struct attribute_group *grp) |
| 208 | { | 279 | { |
| @@ -240,6 +311,7 @@ static inline void sysfs_notify_dirent(struct sysfs_dirent *sd) | |||
| 240 | } | 311 | } |
| 241 | static inline | 312 | static inline |
| 242 | struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, | 313 | struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, |
| 314 | const void *ns, | ||
| 243 | const unsigned char *name) | 315 | const unsigned char *name) |
| 244 | { | 316 | { |
| 245 | return NULL; | 317 | return NULL; |
| @@ -252,6 +324,10 @@ static inline void sysfs_put(struct sysfs_dirent *sd) | |||
| 252 | { | 324 | { |
| 253 | } | 325 | } |
| 254 | 326 | ||
| 327 | static inline void sysfs_exit_ns(int type, const void *tag) | ||
| 328 | { | ||
| 329 | } | ||
| 330 | |||
| 255 | static inline int __must_check sysfs_init(void) | 331 | static inline int __must_check sysfs_init(void) |
| 256 | { | 332 | { |
| 257 | return 0; | 333 | return 0; |
