Blame view
include/linux/sysfs.h
8.7 KB
1da177e4c
|
1 2 3 4 5 |
/* * sysfs.h - definitions for the device driver filesystem * * Copyright (c) 2001,2002 Patrick Mochel * Copyright (c) 2004 Silicon Graphics, Inc. |
6d66f5cd2
|
6 7 |
* Copyright (c) 2007 SUSE Linux Products GmbH * Copyright (c) 2007 Tejun Heo <teheo@suse.de> |
1da177e4c
|
8 9 10 11 12 13 |
* * Please see Documentation/filesystems/sysfs.txt for more information. */ #ifndef _SYSFS_H_ #define _SYSFS_H_ |
4a7fb6363
|
14 |
#include <linux/compiler.h> |
5851fadce
|
15 |
#include <linux/errno.h> |
bf0acc330
|
16 |
#include <linux/list.h> |
6992f5334
|
17 |
#include <linux/lockdep.h> |
8488a38f4
|
18 |
#include <linux/kobject_ns.h> |
1da177e4c
|
19 20 21 22 |
#include <asm/atomic.h> struct kobject; struct module; |
3ff195b01
|
23 |
enum kobj_ns_type; |
1da177e4c
|
24 25 |
struct attribute { |
59f690156
|
26 |
const char *name; |
1da177e4c
|
27 |
mode_t mode; |
6992f5334
|
28 29 30 31 |
#ifdef CONFIG_DEBUG_LOCK_ALLOC struct lock_class_key *key; struct lock_class_key skey; #endif |
1da177e4c
|
32 |
}; |
35960258e
|
33 34 35 36 37 38 39 40 41 42 |
/** * sysfs_attr_init - initialize a dynamically allocated sysfs attribute * @attr: struct attribute to initialize * * Initialize a dynamically allocated struct attribute so we can * make lockdep happy. This is a new requirement for attributes * and initially this is only needed when lockdep is enabled. * Lockdep gives a nice error when your attribute is added to * sysfs if you don't have this. */ |
6992f5334
|
43 44 45 46 47 48 49 50 51 52 |
#ifdef CONFIG_DEBUG_LOCK_ALLOC #define sysfs_attr_init(attr) \ do { \ static struct lock_class_key __key; \ \ (attr)->key = &__key; \ } while(0) #else #define sysfs_attr_init(attr) do {} while(0) #endif |
1da177e4c
|
53 |
struct attribute_group { |
59f690156
|
54 |
const char *name; |
0f4238958
|
55 |
mode_t (*is_visible)(struct kobject *, |
d4acd722b
|
56 |
struct attribute *, int); |
59f690156
|
57 |
struct attribute **attrs; |
1da177e4c
|
58 59 60 61 62 63 64 65 66 67 |
}; /** * Use these macros to make defining attributes easier. See include/linux/device.h * for examples.. */ #define __ATTR(_name,_mode,_show,_store) { \ |
7b595756e
|
68 |
.attr = {.name = __stringify(_name), .mode = _mode }, \ |
1da177e4c
|
69 70 71 72 73 |
.show = _show, \ .store = _store, \ } #define __ATTR_RO(_name) { \ |
7b595756e
|
74 75 |
.attr = { .name = __stringify(_name), .mode = 0444 }, \ .show = _name##_show, \ |
1da177e4c
|
76 77 78 79 80 |
} #define __ATTR_NULL { .attr = { .name = NULL } } #define attr_name(_attr) (_attr).attr.name |
2c3c8bea6
|
81 |
struct file; |
1da177e4c
|
82 83 84 85 86 87 |
struct vm_area_struct; struct bin_attribute { struct attribute attr; size_t size; void *private; |
2c3c8bea6
|
88 |
ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *, |
91a690295
|
89 |
char *, loff_t, size_t); |
2c3c8bea6
|
90 |
ssize_t (*write)(struct file *,struct kobject *, struct bin_attribute *, |
91a690295
|
91 |
char *, loff_t, size_t); |
2c3c8bea6
|
92 |
int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr, |
1da177e4c
|
93 94 |
struct vm_area_struct *vma); }; |
35960258e
|
95 96 97 98 99 100 101 102 103 104 |
/** * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute * @attr: struct bin_attribute to initialize * * Initialize a dynamically allocated struct bin_attribute so we * can make lockdep happy. This is a new requirement for * attributes and initially this is only needed when lockdep is * enabled. Lockdep gives a nice error when your attribute is * added to sysfs if you don't have this. */ |
62e877b89
|
105 |
#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) |
6992f5334
|
106 |
|
1da177e4c
|
107 108 109 110 |
struct sysfs_ops { ssize_t (*show)(struct kobject *, struct attribute *,char *); ssize_t (*store)(struct kobject *,struct attribute *,const char *, size_t); }; |
f1282c844
|
111 |
struct sysfs_dirent; |
1da177e4c
|
112 |
#ifdef CONFIG_SYSFS |
59f690156
|
113 114 |
int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), void *data, struct module *owner); |
1da177e4c
|
115 |
|
59f690156
|
116 117 118 119 120 |
int __must_check sysfs_create_dir(struct kobject *kobj); void sysfs_remove_dir(struct kobject *kobj); int __must_check sysfs_rename_dir(struct kobject *kobj, const char *new_name); int __must_check sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj); |
31e5abe9a
|
121 |
|
59f690156
|
122 123 |
int __must_check sysfs_create_file(struct kobject *kobj, const struct attribute *attr); |
1c205ae18
|
124 125 |
int __must_check sysfs_create_files(struct kobject *kobj, const struct attribute **attr); |
49c19400f
|
126 127 |
int __must_check sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr, mode_t mode); |
59f690156
|
128 |
void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr); |
1c205ae18
|
129 |
void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr); |
1da177e4c
|
130 |
|
4a7fb6363
|
131 |
int __must_check sysfs_create_bin_file(struct kobject *kobj, |
66ecb92be
|
132 133 134 |
const struct bin_attribute *attr); void sysfs_remove_bin_file(struct kobject *kobj, const struct bin_attribute *attr); |
1da177e4c
|
135 |
|
59f690156
|
136 137 |
int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, const char *name); |
36ce6dad6
|
138 139 140 |
int __must_check sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target, const char *name); |
59f690156
|
141 |
void sysfs_remove_link(struct kobject *kobj, const char *name); |
7cb32942d
|
142 143 |
int sysfs_rename_link(struct kobject *kobj, struct kobject *target, const char *old_name, const char *new_name); |
746edb7ae
|
144 145 |
void sysfs_delete_link(struct kobject *dir, struct kobject *targ, const char *name); |
59f690156
|
146 147 |
int __must_check sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp); |
0f4238958
|
148 149 |
int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp); |
59f690156
|
150 151 |
void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp); |
dfa87c824
|
152 |
int sysfs_add_file_to_group(struct kobject *kobj, |
59f690156
|
153 |
const struct attribute *attr, const char *group); |
dfa87c824
|
154 |
void sysfs_remove_file_from_group(struct kobject *kobj, |
59f690156
|
155 |
const struct attribute *attr, const char *group); |
dfa87c824
|
156 |
|
8c0e3998f
|
157 |
void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); |
f1282c844
|
158 159 |
void sysfs_notify_dirent(struct sysfs_dirent *sd); struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, |
3ff195b01
|
160 |
const void *ns, |
f1282c844
|
161 162 163 |
const unsigned char *name); struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd); void sysfs_put(struct sysfs_dirent *sd); |
ae87221d3
|
164 |
void sysfs_printk_last_file(void); |
3ff195b01
|
165 |
|
be867b194
|
166 |
/* Called to clear a ns tag when it is no longer valid */ |
3ff195b01
|
167 |
void sysfs_exit_ns(enum kobj_ns_type type, const void *tag); |
f1282c844
|
168 |
int __must_check sysfs_init(void); |
f20a9ead0
|
169 |
|
1da177e4c
|
170 |
#else /* CONFIG_SYSFS */ |
d9a9cdfb0
|
171 |
static inline int sysfs_schedule_callback(struct kobject *kobj, |
523ded71d
|
172 |
void (*func)(void *), void *data, struct module *owner) |
d9a9cdfb0
|
173 174 175 |
{ return -ENOSYS; } |
59f690156
|
176 |
static inline int sysfs_create_dir(struct kobject *kobj) |
1da177e4c
|
177 178 179 |
{ return 0; } |
59f690156
|
180 |
static inline void sysfs_remove_dir(struct kobject *kobj) |
1da177e4c
|
181 |
{ |
1da177e4c
|
182 |
} |
59f690156
|
183 |
static inline int sysfs_rename_dir(struct kobject *kobj, const char *new_name) |
1da177e4c
|
184 |
{ |
0b4a4fea2
|
185 |
return 0; |
1da177e4c
|
186 |
} |
59f690156
|
187 188 |
static inline int sysfs_move_dir(struct kobject *kobj, struct kobject *new_parent_kobj) |
8a82472f8
|
189 190 191 |
{ return 0; } |
59f690156
|
192 193 |
static inline int sysfs_create_file(struct kobject *kobj, const struct attribute *attr) |
1da177e4c
|
194 195 196 |
{ return 0; } |
1c205ae18
|
197 198 199 200 201 |
static inline int sysfs_create_files(struct kobject *kobj, const struct attribute **attr) { return 0; } |
59f690156
|
202 |
static inline int sysfs_chmod_file(struct kobject *kobj, |
49c19400f
|
203 |
const struct attribute *attr, mode_t mode) |
31e5abe9a
|
204 205 206 |
{ return 0; } |
1da177e4c
|
207 |
|
59f690156
|
208 209 |
static inline void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr) |
1da177e4c
|
210 |
{ |
1da177e4c
|
211 |
} |
1c205ae18
|
212 213 214 215 |
static inline void sysfs_remove_files(struct kobject *kobj, const struct attribute **attr) { } |
59f690156
|
216 |
static inline int sysfs_create_bin_file(struct kobject *kobj, |
66ecb92be
|
217 |
const struct bin_attribute *attr) |
1da177e4c
|
218 219 220 |
{ return 0; } |
3612e06b2
|
221 |
static inline void sysfs_remove_bin_file(struct kobject *kobj, |
66ecb92be
|
222 |
const struct bin_attribute *attr) |
1da177e4c
|
223 |
{ |
1da177e4c
|
224 |
} |
59f690156
|
225 226 |
static inline int sysfs_create_link(struct kobject *kobj, struct kobject *target, const char *name) |
1da177e4c
|
227 228 229 |
{ return 0; } |
36ce6dad6
|
230 231 232 233 234 235 |
static inline int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target, const char *name) { return 0; } |
59f690156
|
236 |
static inline void sysfs_remove_link(struct kobject *kobj, const char *name) |
1da177e4c
|
237 |
{ |
1da177e4c
|
238 |
} |
7cb32942d
|
239 240 241 242 243 |
static inline int sysfs_rename_link(struct kobject *k, struct kobject *t, const char *old_name, const char *new_name) { return 0; } |
746edb7ae
|
244 245 246 247 |
static inline void sysfs_delete_link(struct kobject *k, struct kobject *t, const char *name) { } |
59f690156
|
248 249 |
static inline int sysfs_create_group(struct kobject *kobj, const struct attribute_group *grp) |
1da177e4c
|
250 251 252 |
{ return 0; } |
1cbfb7a5a
|
253 254 255 256 257 |
static inline int sysfs_update_group(struct kobject *kobj, const struct attribute_group *grp) { return 0; } |
59f690156
|
258 259 |
static inline void sysfs_remove_group(struct kobject *kobj, const struct attribute_group *grp) |
1da177e4c
|
260 |
{ |
1da177e4c
|
261 |
} |
dfa87c824
|
262 263 264 265 266 267 268 |
static inline int sysfs_add_file_to_group(struct kobject *kobj, const struct attribute *attr, const char *group) { return 0; } static inline void sysfs_remove_file_from_group(struct kobject *kobj, |
d701d8a3b
|
269 |
const struct attribute *attr, const char *group) |
dfa87c824
|
270 |
{ |
dfa87c824
|
271 |
} |
8c0e3998f
|
272 273 |
static inline void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr) |
4508a7a73
|
274 275 |
{ } |
f1282c844
|
276 277 278 279 280 |
static inline void sysfs_notify_dirent(struct sysfs_dirent *sd) { } static inline struct sysfs_dirent *sysfs_get_dirent(struct sysfs_dirent *parent_sd, |
3ff195b01
|
281 |
const void *ns, |
f1282c844
|
282 283 284 285 286 287 288 289 290 291 292 |
const unsigned char *name) { return NULL; } static inline struct sysfs_dirent *sysfs_get(struct sysfs_dirent *sd) { return NULL; } static inline void sysfs_put(struct sysfs_dirent *sd) { } |
4508a7a73
|
293 |
|
27eabc7cb
|
294 |
static inline void sysfs_exit_ns(int type, const void *tag) |
3ff195b01
|
295 296 |
{ } |
f20a9ead0
|
297 298 299 300 |
static inline int __must_check sysfs_init(void) { return 0; } |
ae87221d3
|
301 302 303 |
static inline void sysfs_printk_last_file(void) { } |
1da177e4c
|
304 305 306 |
#endif /* CONFIG_SYSFS */ #endif /* _SYSFS_H_ */ |