Blame view
include/linux/kobject.h
6.79 KB
1da177e4c
|
1 2 3 |
/* * kobject.h - generic kernel object infrastructure. * |
f0e7e1bd7
|
4 5 |
* Copyright (c) 2002-2003 Patrick Mochel * Copyright (c) 2002-2003 Open Source Development Labs |
79a6ee42f
|
6 7 |
* Copyright (c) 2006-2008 Greg Kroah-Hartman <greg@kroah.com> * Copyright (c) 2006-2008 Novell Inc. |
1da177e4c
|
8 9 10 |
* * This file is released under the GPLv2. * |
1da177e4c
|
11 12 |
* Please read Documentation/kobject.txt before using the kobject * interface, ESPECIALLY the parts about reference counts and object |
79a6ee42f
|
13 |
* destructors. |
1da177e4c
|
14 15 16 17 |
*/ #ifndef _KOBJECT_H_ #define _KOBJECT_H_ |
1da177e4c
|
18 19 20 |
#include <linux/types.h> #include <linux/list.h> #include <linux/sysfs.h> |
4a7fb6363
|
21 |
#include <linux/compiler.h> |
1da177e4c
|
22 |
#include <linux/spinlock.h> |
1da177e4c
|
23 |
#include <linux/kref.h> |
8488a38f4
|
24 |
#include <linux/kobject_ns.h> |
1da177e4c
|
25 |
#include <linux/kernel.h> |
4508a7a73
|
26 |
#include <linux/wait.h> |
60063497a
|
27 |
#include <linux/atomic.h> |
c817a67ec
|
28 |
#include <linux/workqueue.h> |
1da177e4c
|
29 |
|
312c004d3
|
30 |
#define UEVENT_HELPER_PATH_LEN 256 |
7eff2e7a8
|
31 32 |
#define UEVENT_NUM_ENVP 32 /* number of env pointers */ #define UEVENT_BUFFER_SIZE 2048 /* buffer for the variables */ |
0296b2281
|
33 |
|
86d56134f
|
34 |
#ifdef CONFIG_UEVENT_HELPER |
0296b2281
|
35 |
/* path to the userspace helper executed on an event */ |
312c004d3
|
36 |
extern char uevent_helper[]; |
86d56134f
|
37 |
#endif |
0296b2281
|
38 |
|
312c004d3
|
39 40 |
/* counter to tag the uevent, read only except for the kobject core */ extern u64 uevent_seqnum; |
1da177e4c
|
41 |
|
60a96a595
|
42 43 44 45 46 47 48 49 50 51 |
/* * The actions here must match the index to the string array * in lib/kobject_uevent.c * * Do not add new actions here without checking with the driver-core * maintainers. Action strings are not meant to express subsystem * or device specific properties. In most cases you want to send a * kobject_uevent_env(kobj, KOBJ_CHANGE, env) with additional event * specific variables added to the event environment. */ |
0296b2281
|
52 |
enum kobject_action { |
60a96a595
|
53 54 55 56 57 58 59 |
KOBJ_ADD, KOBJ_REMOVE, KOBJ_CHANGE, KOBJ_MOVE, KOBJ_ONLINE, KOBJ_OFFLINE, KOBJ_MAX |
0296b2281
|
60 |
}; |
1da177e4c
|
61 |
struct kobject { |
af5ca3f4e
|
62 |
const char *name; |
1da177e4c
|
63 |
struct list_head entry; |
79a6ee42f
|
64 65 66 |
struct kobject *parent; struct kset *kset; struct kobj_type *ktype; |
f7025709e
|
67 |
struct kernfs_node *sd; /* sysfs directory entry */ |
a231934bd
|
68 |
struct kref kref; |
c817a67ec
|
69 70 71 |
#ifdef CONFIG_DEBUG_KOBJECT_RELEASE struct delayed_work release; #endif |
0f4dafc05
|
72 |
unsigned int state_initialized:1; |
0f4dafc05
|
73 74 75 |
unsigned int state_in_sysfs:1; unsigned int state_add_uevent_sent:1; unsigned int state_remove_uevent_sent:1; |
f67f129e5
|
76 |
unsigned int uevent_suppress:1; |
1da177e4c
|
77 |
}; |
b9075fa96
|
78 79 |
extern __printf(2, 3) int kobject_set_name(struct kobject *kobj, const char *name, ...); |
8db148606
|
80 81 82 |
extern __printf(2, 0) int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, va_list vargs); |
1da177e4c
|
83 |
|
79a6ee42f
|
84 |
static inline const char *kobject_name(const struct kobject *kobj) |
1da177e4c
|
85 |
{ |
af5ca3f4e
|
86 |
return kobj->name; |
1da177e4c
|
87 |
} |
f9cb074bf
|
88 |
extern void kobject_init(struct kobject *kobj, struct kobj_type *ktype); |
b9075fa96
|
89 90 91 92 93 94 95 |
extern __printf(3, 4) __must_check int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...); extern __printf(4, 5) __must_check int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, struct kobject *parent, const char *fmt, ...); |
c11c4154e
|
96 |
|
79a6ee42f
|
97 |
extern void kobject_del(struct kobject *kobj); |
1da177e4c
|
98 |
|
43968d2f1
|
99 |
extern struct kobject * __must_check kobject_create(void); |
3f9e3ee9d
|
100 101 |
extern struct kobject * __must_check kobject_create_and_add(const char *name, struct kobject *parent); |
4a7fb6363
|
102 |
extern int __must_check kobject_rename(struct kobject *, const char *new_name); |
8a82472f8
|
103 |
extern int __must_check kobject_move(struct kobject *, struct kobject *); |
1da177e4c
|
104 |
|
79a6ee42f
|
105 106 |
extern struct kobject *kobject_get(struct kobject *kobj); extern void kobject_put(struct kobject *kobj); |
1da177e4c
|
107 |
|
e34ff4906
|
108 |
extern const void *kobject_namespace(struct kobject *kobj); |
79a6ee42f
|
109 |
extern char *kobject_get_path(struct kobject *kobj, gfp_t flag); |
1da177e4c
|
110 111 |
struct kobj_type { |
79a6ee42f
|
112 |
void (*release)(struct kobject *kobj); |
52cf25d0a
|
113 |
const struct sysfs_ops *sysfs_ops; |
79a6ee42f
|
114 |
struct attribute **default_attrs; |
bc451f205
|
115 116 |
const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj); const void *(*namespace)(struct kobject *kobj); |
1da177e4c
|
117 |
}; |
7eff2e7a8
|
118 |
struct kobj_uevent_env { |
bcccff93a
|
119 |
char *argv[3]; |
7eff2e7a8
|
120 121 122 123 124 |
char *envp[UEVENT_NUM_ENVP]; int envp_idx; char buf[UEVENT_BUFFER_SIZE]; int buflen; }; |
a56156489
|
125 |
struct kset_uevent_ops { |
9cd43611c
|
126 127 128 |
int (* const filter)(struct kset *kset, struct kobject *kobj); const char *(* const name)(struct kset *kset, struct kobject *kobj); int (* const uevent)(struct kset *kset, struct kobject *kobj, |
7eff2e7a8
|
129 |
struct kobj_uevent_env *env); |
a56156489
|
130 |
}; |
1da177e4c
|
131 |
|
23b5212cc
|
132 133 134 135 136 137 138 |
struct kobj_attribute { struct attribute attr; ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf); ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count); }; |
52cf25d0a
|
139 |
extern const struct sysfs_ops kobj_sysfs_ops; |
23b5212cc
|
140 |
|
bc451f205
|
141 |
struct sock; |
be867b194
|
142 |
|
6adf7554b
|
143 144 |
/** * struct kset - a set of kobjects of a specific type, belonging to a specific subsystem. |
1da177e4c
|
145 |
* |
6adf7554b
|
146 147 148 149 150 |
* A kset defines a group of kobjects. They can be individually * different "types" but overall these kobjects all want to be grouped * together and operated on in the same manner. ksets are used to * define the attribute callbacks and other common events that happen to * a kobject. |
1da177e4c
|
151 |
* |
6adf7554b
|
152 153 154 155 156 157 158 |
* @list: the list of all kobjects for this kset * @list_lock: a lock for iterating over the kobjects * @kobj: the embedded kobject for this kset (recursion, isn't it fun...) * @uevent_ops: the set of uevent operations for this kset. These are * called whenever a kobject has something happen to it so that the kset * can add new environment variables, or filter out the uevents if so * desired. |
1da177e4c
|
159 |
*/ |
1da177e4c
|
160 |
struct kset { |
79a6ee42f
|
161 162 163 |
struct list_head list; spinlock_t list_lock; struct kobject kobj; |
9cd43611c
|
164 |
const struct kset_uevent_ops *uevent_ops; |
1da177e4c
|
165 |
}; |
79a6ee42f
|
166 167 168 |
extern void kset_init(struct kset *kset); extern int __must_check kset_register(struct kset *kset); extern void kset_unregister(struct kset *kset); |
b727c7028
|
169 |
extern struct kset * __must_check kset_create_and_add(const char *name, |
9cd43611c
|
170 |
const struct kset_uevent_ops *u, |
b727c7028
|
171 |
struct kobject *parent_kobj); |
1da177e4c
|
172 |
|
79a6ee42f
|
173 |
static inline struct kset *to_kset(struct kobject *kobj) |
1da177e4c
|
174 |
{ |
79a6ee42f
|
175 |
return kobj ? container_of(kobj, struct kset, kobj) : NULL; |
1da177e4c
|
176 |
} |
79a6ee42f
|
177 |
static inline struct kset *kset_get(struct kset *k) |
1da177e4c
|
178 179 180 |
{ return k ? to_kset(kobject_get(&k->kobj)) : NULL; } |
79a6ee42f
|
181 |
static inline void kset_put(struct kset *k) |
1da177e4c
|
182 183 184 |
{ kobject_put(&k->kobj); } |
3514faca1
|
185 |
static inline struct kobj_type *get_ktype(struct kobject *kobj) |
1da177e4c
|
186 |
{ |
3514faca1
|
187 |
return kobj->ktype; |
1da177e4c
|
188 |
} |
79a6ee42f
|
189 |
extern struct kobject *kset_find_obj(struct kset *, const char *); |
1da177e4c
|
190 |
|
0ff21e466
|
191 192 |
/* The global /sys/kernel/ kobject for people to chain off of */ extern struct kobject *kernel_kobj; |
ff7ea79cf
|
193 194 |
/* The global /sys/kernel/mm/ kobject for people to chain off of */ extern struct kobject *mm_kobj; |
2d72fc00a
|
195 196 |
/* The global /sys/hypervisor/ kobject for people to chain off of */ extern struct kobject *hypervisor_kobj; |
d76e15fb2
|
197 198 |
/* The global /sys/power/ kobject for people to chain off of */ extern struct kobject *power_kobj; |
f62ed9e33
|
199 200 |
/* The global /sys/firmware/ kobject for people to chain off of */ extern struct kobject *firmware_kobj; |
1da177e4c
|
201 |
|
542cfce6f
|
202 203 |
int kobject_uevent(struct kobject *kobj, enum kobject_action action); int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, |
8a82472f8
|
204 |
char *envp[]); |
0296b2281
|
205 |
|
b9075fa96
|
206 207 |
__printf(2, 3) int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...); |
5c5daf657
|
208 209 210 |
int kobject_action_type(const char *buf, size_t count, enum kobject_action *type); |
1da177e4c
|
211 |
|
1da177e4c
|
212 |
#endif /* _KOBJECT_H_ */ |