]>
Commit | Line | Data |
---|---|---|
070f5422 GKH |
1 | /* |
2 | * libsysfs.h | |
3 | * | |
4 | * Header Definitions for libsysfs | |
5 | * | |
fe3fe3b2 | 6 | * Copyright (C) IBM Corp. 2003 |
070f5422 GKH |
7 | * |
8 | * This library is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License as published by the Free Software Foundation; either | |
11 | * version 2.1 of the License, or (at your option) any later version. | |
12 | * | |
13 | * This library is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * Lesser General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU Lesser General Public | |
19 | * License along with this library; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | */ | |
23 | #ifndef _LIBSYSFS_H_ | |
24 | #define _LIBSYSFS_H_ | |
25 | ||
26 | #include <sys/types.h> | |
fe3fe3b2 | 27 | #include "dlist.h" |
070f5422 GKH |
28 | |
29 | /* | |
30 | * Generic #defines go here.. | |
31 | */ | |
32 | #define SYSFS_FSTYPE_NAME "sysfs" | |
33 | #define SYSFS_PROC_MNTS "/proc/mounts" | |
ff44a6b0 | 34 | #define SYSFS_BUS_NAME "bus" |
ff44a6b0 | 35 | #define SYSFS_CLASS_NAME "class" |
ff44a6b0 | 36 | #define SYSFS_BLOCK_NAME "block" |
070f5422 | 37 | #define SYSFS_DEVICES_NAME "devices" |
070f5422 GKH |
38 | #define SYSFS_DRIVERS_NAME "drivers" |
39 | #define SYSFS_NAME_ATTRIBUTE "name" | |
fe3fe3b2 | 40 | #define SYSFS_UNKNOWN "unknown" |
8d817251 | 41 | #define SYSFS_PATH_ENV "SYSFS_PATH" |
fe3fe3b2 | 42 | |
070f5422 GKH |
43 | #define SYSFS_PATH_MAX 255 |
44 | #define SYSFS_NAME_LEN 50 | |
45 | #define SYSFS_BUS_ID_SIZE 20 | |
46 | ||
47 | #define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */ | |
48 | #define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */ | |
49 | ||
50 | struct sysfs_attribute { | |
fe3fe3b2 | 51 | unsigned char *value; |
070f5422 GKH |
52 | unsigned short len; /* value length */ |
53 | unsigned short method; /* show and store */ | |
fe3fe3b2 DS |
54 | unsigned char name[SYSFS_NAME_LEN]; |
55 | unsigned char path[SYSFS_PATH_MAX]; | |
070f5422 GKH |
56 | }; |
57 | ||
fe3fe3b2 DS |
58 | struct sysfs_link { |
59 | unsigned char name[SYSFS_NAME_LEN]; | |
60 | unsigned char path[SYSFS_PATH_MAX]; | |
61 | unsigned char target[SYSFS_PATH_MAX]; | |
070f5422 GKH |
62 | }; |
63 | ||
64 | struct sysfs_directory { | |
616a7078 AM |
65 | unsigned char name[SYSFS_NAME_LEN]; |
66 | unsigned char path[SYSFS_PATH_MAX]; | |
67 | ||
68 | /* Private: for internal use only */ | |
fe3fe3b2 DS |
69 | struct dlist *subdirs; |
70 | struct dlist *links; | |
71 | struct dlist *attributes; | |
070f5422 GKH |
72 | }; |
73 | ||
74 | struct sysfs_driver { | |
fe3fe3b2 DS |
75 | unsigned char name[SYSFS_NAME_LEN]; |
76 | unsigned char path[SYSFS_PATH_MAX]; | |
77 | ||
616a7078 | 78 | /* Private: for internal use only */ |
5d4754f1 | 79 | struct dlist *devices; |
fe3fe3b2 | 80 | struct sysfs_directory *directory; |
070f5422 GKH |
81 | }; |
82 | ||
83 | struct sysfs_device { | |
fe3fe3b2 DS |
84 | unsigned char name[SYSFS_NAME_LEN]; |
85 | unsigned char bus_id[SYSFS_NAME_LEN]; | |
ff44a6b0 | 86 | unsigned char bus[SYSFS_NAME_LEN]; |
fe3fe3b2 | 87 | unsigned char driver_name[SYSFS_NAME_LEN]; |
ff44a6b0 | 88 | unsigned char path[SYSFS_PATH_MAX]; |
fe3fe3b2 | 89 | |
616a7078 | 90 | /* Private: for internal use only */ |
5d4754f1 DS |
91 | struct sysfs_device *parent; |
92 | struct dlist *children; | |
fe3fe3b2 DS |
93 | struct sysfs_directory *directory; |
94 | }; | |
95 | ||
96 | struct sysfs_root_device { | |
fe3fe3b2 DS |
97 | unsigned char name[SYSFS_NAME_LEN]; |
98 | unsigned char path[SYSFS_PATH_MAX]; | |
99 | ||
616a7078 | 100 | /* Private: for internal use only */ |
5d4754f1 | 101 | struct dlist *devices; |
070f5422 | 102 | struct sysfs_directory *directory; |
070f5422 GKH |
103 | }; |
104 | ||
105 | struct sysfs_bus { | |
fe3fe3b2 DS |
106 | unsigned char name[SYSFS_NAME_LEN]; |
107 | unsigned char path[SYSFS_PATH_MAX]; | |
108 | ||
616a7078 | 109 | /* Private: for internal use only */ |
5d4754f1 DS |
110 | struct dlist *drivers; |
111 | struct dlist *devices; | |
fe3fe3b2 | 112 | struct sysfs_directory *directory; |
070f5422 GKH |
113 | }; |
114 | ||
115 | struct sysfs_class_device { | |
fe3fe3b2 | 116 | unsigned char name[SYSFS_NAME_LEN]; |
ff44a6b0 | 117 | unsigned char classname[SYSFS_NAME_LEN]; |
fe3fe3b2 DS |
118 | unsigned char path[SYSFS_PATH_MAX]; |
119 | ||
616a7078 | 120 | /* Private: for internal use only */ |
5d4754f1 DS |
121 | struct sysfs_class_device *parent; |
122 | struct sysfs_device *sysdevice; /* NULL if virtual */ | |
123 | struct sysfs_driver *driver; /* NULL if not implemented */ | |
fe3fe3b2 | 124 | struct sysfs_directory *directory; |
070f5422 GKH |
125 | }; |
126 | ||
127 | struct sysfs_class { | |
fe3fe3b2 DS |
128 | unsigned char name[SYSFS_NAME_LEN]; |
129 | unsigned char path[SYSFS_PATH_MAX]; | |
130 | ||
616a7078 | 131 | /* Private: for internal use only */ |
5d4754f1 | 132 | struct dlist *devices; |
fe3fe3b2 | 133 | struct sysfs_directory *directory; |
070f5422 GKH |
134 | }; |
135 | ||
136 | #ifdef __cplusplus | |
137 | extern "C" { | |
138 | #endif | |
139 | ||
140 | /* | |
141 | * Function Prototypes | |
142 | */ | |
fe3fe3b2 | 143 | extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len); |
616a7078 | 144 | extern int sysfs_remove_trailing_slash(unsigned char *path); |
fe3fe3b2 DS |
145 | extern int sysfs_get_name_from_path(const unsigned char *path, |
146 | unsigned char *name, size_t len); | |
5d4754f1 DS |
147 | extern int sysfs_path_is_dir(const unsigned char *path); |
148 | extern int sysfs_path_is_link(const unsigned char *path); | |
149 | extern int sysfs_path_is_file(const unsigned char *path); | |
fe3fe3b2 DS |
150 | extern int sysfs_get_link(const unsigned char *path, unsigned char *target, |
151 | size_t len); | |
152 | extern struct dlist *sysfs_open_subsystem_list(unsigned char *name); | |
153 | extern struct dlist *sysfs_open_bus_devices_list(unsigned char *name); | |
154 | extern void sysfs_close_list(struct dlist *list); | |
070f5422 GKH |
155 | |
156 | /* sysfs directory and file access */ | |
157 | extern void sysfs_close_attribute(struct sysfs_attribute *sysattr); | |
fe3fe3b2 | 158 | extern struct sysfs_attribute *sysfs_open_attribute(const unsigned char *path); |
070f5422 | 159 | extern int sysfs_read_attribute(struct sysfs_attribute *sysattr); |
fe3fe3b2 DS |
160 | extern int sysfs_read_attribute_value(const unsigned char *attrpath, |
161 | unsigned char *value, size_t vsize); | |
162 | extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, | |
163 | const unsigned char *new_value, size_t len); | |
164 | extern unsigned char *sysfs_get_value_from_attributes(struct dlist *attr, | |
165 | const unsigned char * name); | |
616a7078 AM |
166 | extern int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir); |
167 | extern int sysfs_refresh_dir_links(struct sysfs_directory *sysdir); | |
168 | extern int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir); | |
070f5422 | 169 | extern void sysfs_close_directory(struct sysfs_directory *sysdir); |
fe3fe3b2 | 170 | extern struct sysfs_directory *sysfs_open_directory(const unsigned char *path); |
5d4754f1 DS |
171 | extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir); |
172 | extern int sysfs_read_dir_links(struct sysfs_directory *sysdir); | |
173 | extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir); | |
070f5422 | 174 | extern int sysfs_read_directory(struct sysfs_directory *sysdir); |
fe3fe3b2 DS |
175 | extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir); |
176 | extern struct sysfs_directory *sysfs_get_subdirectory | |
177 | (struct sysfs_directory *dir, unsigned char *subname); | |
178 | extern void sysfs_close_link(struct sysfs_link *ln); | |
179 | extern struct sysfs_link *sysfs_open_link(const unsigned char *lnpath); | |
180 | extern struct sysfs_link *sysfs_get_directory_link(struct sysfs_directory *dir, | |
181 | unsigned char *linkname); | |
182 | extern struct sysfs_link *sysfs_get_subdirectory_link | |
183 | (struct sysfs_directory *dir, unsigned char *linkname); | |
184 | extern struct sysfs_attribute *sysfs_get_directory_attribute | |
185 | (struct sysfs_directory *dir, unsigned char *attrname); | |
616a7078 AM |
186 | extern struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir); |
187 | extern struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir); | |
188 | extern struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir); | |
070f5422 GKH |
189 | |
190 | /* sysfs driver access */ | |
191 | extern void sysfs_close_driver(struct sysfs_driver *driver); | |
bcbe2d8e DS |
192 | extern struct sysfs_driver *sysfs_open_driver |
193 | (const unsigned char *drv_name, const unsigned char *bus_name); | |
194 | extern struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path); | |
fe3fe3b2 DS |
195 | extern struct sysfs_attribute *sysfs_get_driver_attr |
196 | (struct sysfs_driver *drv, const unsigned char *name); | |
197 | extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver); | |
5d4754f1 | 198 | extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver); |
616a7078 | 199 | extern struct dlist *sysfs_refresh_driver_devices(struct sysfs_driver *driver); |
fe3fe3b2 | 200 | extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver); |
5d4754f1 DS |
201 | extern struct sysfs_device *sysfs_get_driver_device |
202 | (struct sysfs_driver *driver, const unsigned char *name); | |
616a7078 AM |
203 | extern struct dlist *sysfs_refresh_driver_attributes |
204 | (struct sysfs_driver *driver); | |
ff44a6b0 DS |
205 | extern struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus, |
206 | const unsigned char *drv, const unsigned char *attrib); | |
070f5422 GKH |
207 | |
208 | /* generic sysfs device access */ | |
fe3fe3b2 DS |
209 | extern void sysfs_close_root_device(struct sysfs_root_device *root); |
210 | extern struct sysfs_root_device *sysfs_open_root_device | |
211 | (const unsigned char *name); | |
5d4754f1 | 212 | extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root); |
070f5422 | 213 | extern void sysfs_close_device(struct sysfs_device *dev); |
bcbe2d8e DS |
214 | extern struct sysfs_device *sysfs_open_device |
215 | (const unsigned char *bus_id, const unsigned char *bus); | |
216 | extern struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev); | |
217 | extern struct sysfs_device *sysfs_open_device_path(const unsigned char *path); | |
616a7078 | 218 | extern int sysfs_get_device_bus(struct sysfs_device *dev); |
070f5422 | 219 | extern struct sysfs_attribute *sysfs_get_device_attr |
fe3fe3b2 DS |
220 | (struct sysfs_device *dev, const unsigned char *name); |
221 | extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device); | |
616a7078 AM |
222 | extern struct dlist *sysfs_refresh_device_attributes |
223 | (struct sysfs_device *device); | |
ff44a6b0 DS |
224 | extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus, |
225 | const unsigned char *bus_id, const unsigned char *attrib); | |
070f5422 GKH |
226 | |
227 | /* generic sysfs bus access */ | |
228 | extern void sysfs_close_bus(struct sysfs_bus *bus); | |
fe3fe3b2 DS |
229 | extern struct sysfs_bus *sysfs_open_bus(const unsigned char *name); |
230 | extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus, | |
231 | unsigned char *id); | |
232 | extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus, | |
233 | unsigned char *drvname); | |
5d4754f1 DS |
234 | extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus); |
235 | extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus); | |
fe3fe3b2 | 236 | extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus); |
616a7078 | 237 | extern struct dlist *sysfs_refresh_bus_attributes(struct sysfs_bus *bus); |
fe3fe3b2 DS |
238 | extern struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus, |
239 | unsigned char *attrname); | |
240 | extern struct sysfs_device *sysfs_open_bus_device(unsigned char *busname, | |
241 | unsigned char *dev_id); | |
fe3fe3b2 DS |
242 | extern int sysfs_find_driver_bus(const unsigned char *driver, |
243 | unsigned char *busname, size_t bsize); | |
070f5422 GKH |
244 | |
245 | /* generic sysfs class access */ | |
246 | extern void sysfs_close_class_device(struct sysfs_class_device *dev); | |
bcbe2d8e | 247 | extern struct sysfs_class_device *sysfs_open_class_device_path |
fe3fe3b2 | 248 | (const unsigned char *path); |
bcbe2d8e DS |
249 | extern struct sysfs_class_device *sysfs_open_class_device |
250 | (const unsigned char *class, const unsigned char *name); | |
5d4754f1 DS |
251 | extern struct sysfs_device *sysfs_get_classdev_device |
252 | (struct sysfs_class_device *clsdev); | |
253 | extern struct sysfs_driver *sysfs_get_classdev_driver | |
254 | (struct sysfs_class_device *clsdev); | |
255 | extern struct sysfs_class_device *sysfs_get_classdev_parent | |
256 | (struct sysfs_class_device *clsdev); | |
070f5422 | 257 | extern void sysfs_close_class(struct sysfs_class *cls); |
fe3fe3b2 | 258 | extern struct sysfs_class *sysfs_open_class(const unsigned char *name); |
5d4754f1 | 259 | extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls); |
fe3fe3b2 DS |
260 | extern struct sysfs_class_device *sysfs_get_class_device |
261 | (struct sysfs_class *class, unsigned char *name); | |
fe3fe3b2 DS |
262 | extern struct dlist *sysfs_get_classdev_attributes |
263 | (struct sysfs_class_device *cdev); | |
616a7078 AM |
264 | extern struct dlist *sysfs_refresh_classdev_attributes |
265 | (struct sysfs_class_device *cdev); | |
fe3fe3b2 DS |
266 | extern struct sysfs_attribute *sysfs_get_classdev_attr |
267 | (struct sysfs_class_device *clsdev, const unsigned char *name); | |
ff44a6b0 DS |
268 | extern struct sysfs_attribute *sysfs_open_classdev_attr |
269 | (const unsigned char *classname, const unsigned char *dev, | |
270 | const unsigned char *attrib); | |
070f5422 GKH |
271 | |
272 | #ifdef __cplusplus | |
273 | } | |
274 | #endif | |
275 | ||
276 | #endif /* _LIBSYSFS_H_ */ |