4 * Header Definitions for libsysfs
6 * Copyright (C) IBM Corp. 2003
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.
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.
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
26 #include <sys/types.h>
29 * Generic #defines go here..
31 #define SYSFS_FSTYPE_NAME "sysfs"
32 #define SYSFS_PROC_MNTS "/proc/mounts"
33 #define SYSFS_BUS_NAME "bus"
34 #define SYSFS_CLASS_NAME "class"
35 #define SYSFS_BLOCK_NAME "block"
36 #define SYSFS_DEVICES_NAME "devices"
37 #define SYSFS_DRIVERS_NAME "drivers"
38 #define SYSFS_NAME_ATTRIBUTE "name"
39 #define SYSFS_UNKNOWN "unknown"
40 #define SYSFS_PATH_ENV "SYSFS_PATH"
42 #define SYSFS_PATH_MAX 255
43 #define SYSFS_NAME_LEN 50
44 #define SYSFS_BUS_ID_SIZE 20
46 #define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */
47 #define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */
51 struct sysfs_attribute {
53 unsigned short len; /* value length */
54 unsigned short method; /* show and store */
55 unsigned char name[SYSFS_NAME_LEN];
56 unsigned char path[SYSFS_PATH_MAX];
60 unsigned char name[SYSFS_NAME_LEN];
61 unsigned char path[SYSFS_PATH_MAX];
62 unsigned char target[SYSFS_PATH_MAX];
65 struct sysfs_directory {
66 unsigned char name[SYSFS_NAME_LEN];
67 unsigned char path[SYSFS_PATH_MAX];
69 /* Private: for internal use only */
70 struct dlist *subdirs;
72 struct dlist *attributes;
76 unsigned char name[SYSFS_NAME_LEN];
77 unsigned char path[SYSFS_PATH_MAX];
79 /* Private: for internal use only */
80 struct dlist *devices;
81 struct sysfs_directory *directory;
85 unsigned char name[SYSFS_NAME_LEN];
86 unsigned char bus_id[SYSFS_NAME_LEN];
87 unsigned char bus[SYSFS_NAME_LEN];
88 unsigned char driver_name[SYSFS_NAME_LEN];
89 unsigned char path[SYSFS_PATH_MAX];
91 /* Private: for internal use only */
92 struct sysfs_device *parent;
93 struct dlist *children;
94 struct sysfs_directory *directory;
97 struct sysfs_root_device {
98 unsigned char name[SYSFS_NAME_LEN];
99 unsigned char path[SYSFS_PATH_MAX];
101 /* Private: for internal use only */
102 struct dlist *devices;
103 struct sysfs_directory *directory;
107 unsigned char name[SYSFS_NAME_LEN];
108 unsigned char path[SYSFS_PATH_MAX];
110 /* Private: for internal use only */
111 struct dlist *drivers;
112 struct dlist *devices;
113 struct sysfs_directory *directory;
116 struct sysfs_class_device {
117 unsigned char name[SYSFS_NAME_LEN];
118 unsigned char classname[SYSFS_NAME_LEN];
119 unsigned char path[SYSFS_PATH_MAX];
121 /* Private: for internal use only */
122 struct sysfs_class_device *parent;
123 struct sysfs_device *sysdevice; /* NULL if virtual */
124 struct sysfs_driver *driver; /* NULL if not implemented */
125 struct sysfs_directory *directory;
129 unsigned char name[SYSFS_NAME_LEN];
130 unsigned char path[SYSFS_PATH_MAX];
132 /* Private: for internal use only */
133 struct dlist *devices;
134 struct sysfs_directory *directory;
142 * Function Prototypes
144 extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len);
145 extern int sysfs_remove_trailing_slash(unsigned char *path);
146 extern int sysfs_get_name_from_path(const unsigned char *path,
147 unsigned char *name, size_t len);
148 extern int sysfs_path_is_dir(const unsigned char *path);
149 extern int sysfs_path_is_link(const unsigned char *path);
150 extern int sysfs_path_is_file(const unsigned char *path);
151 extern int sysfs_get_link(const unsigned char *path, unsigned char *target,
153 extern struct dlist *sysfs_open_subsystem_list(unsigned char *name);
154 extern struct dlist *sysfs_open_bus_devices_list(unsigned char *name);
155 extern void sysfs_close_list(struct dlist *list);
157 /* sysfs directory and file access */
158 extern void sysfs_close_attribute(struct sysfs_attribute *sysattr);
159 extern struct sysfs_attribute *sysfs_open_attribute(const unsigned char *path);
160 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
161 extern int sysfs_read_attribute_value(const unsigned char *attrpath,
162 unsigned char *value, size_t vsize);
163 extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,
164 const unsigned char *new_value, size_t len);
165 extern unsigned char *sysfs_get_value_from_attributes(struct dlist *attr,
166 const unsigned char * name);
167 extern int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir);
168 extern int sysfs_refresh_dir_links(struct sysfs_directory *sysdir);
169 extern int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir);
170 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
171 extern struct sysfs_directory *sysfs_open_directory(const unsigned char *path);
172 extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir);
173 extern int sysfs_read_dir_links(struct sysfs_directory *sysdir);
174 extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir);
175 extern int sysfs_read_directory(struct sysfs_directory *sysdir);
176 extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir);
177 extern struct sysfs_directory *sysfs_get_subdirectory
178 (struct sysfs_directory *dir, unsigned char *subname);
179 extern void sysfs_close_link(struct sysfs_link *ln);
180 extern struct sysfs_link *sysfs_open_link(const unsigned char *lnpath);
181 extern struct sysfs_link *sysfs_get_directory_link(struct sysfs_directory *dir,
182 unsigned char *linkname);
183 extern struct sysfs_link *sysfs_get_subdirectory_link
184 (struct sysfs_directory *dir, unsigned char *linkname);
185 extern struct sysfs_attribute *sysfs_get_directory_attribute
186 (struct sysfs_directory *dir, unsigned char *attrname);
187 extern struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir);
188 extern struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir);
189 extern struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir);
191 /* sysfs driver access */
192 extern void sysfs_close_driver(struct sysfs_driver *driver);
193 extern struct sysfs_driver *sysfs_open_driver
194 (const unsigned char *drv_name, const unsigned char *bus_name);
195 extern struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path);
196 extern struct sysfs_attribute *sysfs_get_driver_attr
197 (struct sysfs_driver *drv, const unsigned char *name);
198 extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver);
199 extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver);
200 extern struct dlist *sysfs_refresh_driver_devices(struct sysfs_driver *driver);
201 extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver);
202 extern struct sysfs_device *sysfs_get_driver_device
203 (struct sysfs_driver *driver, const unsigned char *name);
204 extern struct dlist *sysfs_refresh_driver_attributes
205 (struct sysfs_driver *driver);
206 extern struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
207 const unsigned char *drv, const unsigned char *attrib);
209 /* generic sysfs device access */
210 extern void sysfs_close_root_device(struct sysfs_root_device *root);
211 extern struct sysfs_root_device *sysfs_open_root_device
212 (const unsigned char *name);
213 extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root);
214 extern void sysfs_close_device(struct sysfs_device *dev);
215 extern struct sysfs_device *sysfs_open_device
216 (const unsigned char *bus_id, const unsigned char *bus);
217 extern struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev);
218 extern struct sysfs_device *sysfs_open_device_path(const unsigned char *path);
219 extern int sysfs_get_device_bus(struct sysfs_device *dev);
220 extern struct sysfs_attribute *sysfs_get_device_attr
221 (struct sysfs_device *dev, const unsigned char *name);
222 extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device);
223 extern struct dlist *sysfs_refresh_device_attributes
224 (struct sysfs_device *device);
225 extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus,
226 const unsigned char *bus_id, const unsigned char *attrib);
228 /* generic sysfs bus access */
229 extern void sysfs_close_bus(struct sysfs_bus *bus);
230 extern struct sysfs_bus *sysfs_open_bus(const unsigned char *name);
231 extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
233 extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
234 unsigned char *drvname);
235 extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus);
236 extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus);
237 extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus);
238 extern struct dlist *sysfs_refresh_bus_attributes(struct sysfs_bus *bus);
239 extern struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus,
240 unsigned char *attrname);
241 extern struct sysfs_device *sysfs_open_bus_device(unsigned char *busname,
242 unsigned char *dev_id);
243 extern int sysfs_find_driver_bus(const unsigned char *driver,
244 unsigned char *busname, size_t bsize);
246 /* generic sysfs class access */
247 extern void sysfs_close_class_device(struct sysfs_class_device *dev);
248 extern struct sysfs_class_device *sysfs_open_class_device_path
249 (const unsigned char *path);
250 extern struct sysfs_class_device *sysfs_open_class_device
251 (const unsigned char *class, const unsigned char *name);
252 extern struct sysfs_device *sysfs_get_classdev_device
253 (struct sysfs_class_device *clsdev);
254 extern struct sysfs_driver *sysfs_get_classdev_driver
255 (struct sysfs_class_device *clsdev);
256 extern struct sysfs_class_device *sysfs_get_classdev_parent
257 (struct sysfs_class_device *clsdev);
258 extern void sysfs_close_class(struct sysfs_class *cls);
259 extern struct sysfs_class *sysfs_open_class(const unsigned char *name);
260 extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls);
261 extern struct sysfs_class_device *sysfs_get_class_device
262 (struct sysfs_class *class, unsigned char *name);
263 extern struct dlist *sysfs_get_classdev_attributes
264 (struct sysfs_class_device *cdev);
265 extern struct dlist *sysfs_refresh_classdev_attributes
266 (struct sysfs_class_device *cdev);
267 extern struct sysfs_attribute *sysfs_get_classdev_attr
268 (struct sysfs_class_device *clsdev, const unsigned char *name);
269 extern struct sysfs_attribute *sysfs_open_classdev_attr
270 (const unsigned char *classname, const unsigned char *dev,
271 const unsigned char *attrib);
277 #endif /* _LIBSYSFS_H_ */