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>
30 * Generic #defines go here..
32 #define SYSFS_FSTYPE_NAME "sysfs"
33 #define SYSFS_PROC_MNTS "/proc/mounts"
34 #define SYSFS_BUS_NAME "bus"
35 #define SYSFS_CLASS_NAME "class"
36 #define SYSFS_BLOCK_NAME "block"
37 #define SYSFS_DEVICES_NAME "devices"
38 #define SYSFS_DRIVERS_NAME "drivers"
39 #define SYSFS_NAME_ATTRIBUTE "name"
40 #define SYSFS_UNKNOWN "unknown"
41 #define SYSFS_PATH_ENV "SYSFS_PATH"
43 #define SYSFS_PATH_MAX 255
44 #define SYSFS_NAME_LEN 50
45 #define SYSFS_BUS_ID_SIZE 20
47 #define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */
48 #define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */
50 struct sysfs_attribute {
52 unsigned short len; /* value length */
53 unsigned short method; /* show and store */
54 unsigned char name[SYSFS_NAME_LEN];
55 unsigned char path[SYSFS_PATH_MAX];
59 unsigned char name[SYSFS_NAME_LEN];
60 unsigned char path[SYSFS_PATH_MAX];
61 unsigned char target[SYSFS_PATH_MAX];
64 struct sysfs_directory {
65 struct dlist *subdirs;
67 struct dlist *attributes;
68 unsigned char name[SYSFS_NAME_LEN];
69 unsigned char path[SYSFS_PATH_MAX];
73 unsigned char name[SYSFS_NAME_LEN];
74 unsigned char path[SYSFS_PATH_MAX];
76 /* for internal use only */
77 struct dlist *devices;
78 struct sysfs_directory *directory;
82 unsigned char name[SYSFS_NAME_LEN];
83 unsigned char bus_id[SYSFS_NAME_LEN];
84 unsigned char bus[SYSFS_NAME_LEN];
85 unsigned char driver_name[SYSFS_NAME_LEN];
86 unsigned char path[SYSFS_PATH_MAX];
88 /* for internal use only */
89 struct sysfs_device *parent;
90 struct dlist *children;
91 struct sysfs_directory *directory;
94 struct sysfs_root_device {
95 unsigned char name[SYSFS_NAME_LEN];
96 unsigned char path[SYSFS_PATH_MAX];
98 /* for internal use only */
99 struct dlist *devices;
100 struct sysfs_directory *directory;
104 unsigned char name[SYSFS_NAME_LEN];
105 unsigned char path[SYSFS_PATH_MAX];
107 /* internal use only */
108 struct dlist *drivers;
109 struct dlist *devices;
110 struct sysfs_directory *directory;
113 struct sysfs_class_device {
114 unsigned char name[SYSFS_NAME_LEN];
115 unsigned char classname[SYSFS_NAME_LEN];
116 unsigned char path[SYSFS_PATH_MAX];
118 /* for internal use only */
119 struct sysfs_class_device *parent;
120 struct sysfs_device *sysdevice; /* NULL if virtual */
121 struct sysfs_driver *driver; /* NULL if not implemented */
122 struct sysfs_directory *directory;
126 unsigned char name[SYSFS_NAME_LEN];
127 unsigned char path[SYSFS_PATH_MAX];
129 /* for internal use only */
130 struct dlist *devices;
131 struct sysfs_directory *directory;
139 * Function Prototypes
141 extern int sysfs_trailing_slash(unsigned char *path);
142 extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len);
143 extern int sysfs_get_name_from_path(const unsigned char *path,
144 unsigned char *name, size_t len);
145 extern int sysfs_path_is_dir(const unsigned char *path);
146 extern int sysfs_path_is_link(const unsigned char *path);
147 extern int sysfs_path_is_file(const unsigned char *path);
148 extern int sysfs_get_link(const unsigned char *path, unsigned char *target,
150 extern struct dlist *sysfs_open_subsystem_list(unsigned char *name);
151 extern struct dlist *sysfs_open_bus_devices_list(unsigned char *name);
152 extern void sysfs_close_list(struct dlist *list);
154 /* sysfs directory and file access */
155 extern void sysfs_close_attribute(struct sysfs_attribute *sysattr);
156 extern struct sysfs_attribute *sysfs_open_attribute(const unsigned char *path);
157 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
158 extern int sysfs_read_attribute_value(const unsigned char *attrpath,
159 unsigned char *value, size_t vsize);
160 extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,
161 const unsigned char *new_value, size_t len);
162 extern unsigned char *sysfs_get_value_from_attributes(struct dlist *attr,
163 const unsigned char * name);
164 extern int sysfs_refresh_attributes(struct dlist *attrlist);
165 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
166 extern struct sysfs_directory *sysfs_open_directory(const unsigned char *path);
167 extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir);
168 extern int sysfs_read_dir_links(struct sysfs_directory *sysdir);
169 extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir);
170 extern int sysfs_read_directory(struct sysfs_directory *sysdir);
171 extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir);
172 extern struct sysfs_directory *sysfs_get_subdirectory
173 (struct sysfs_directory *dir, unsigned char *subname);
174 extern void sysfs_close_link(struct sysfs_link *ln);
175 extern struct sysfs_link *sysfs_open_link(const unsigned char *lnpath);
176 extern struct sysfs_link *sysfs_get_directory_link(struct sysfs_directory *dir,
177 unsigned char *linkname);
178 extern struct sysfs_link *sysfs_get_subdirectory_link
179 (struct sysfs_directory *dir, unsigned char *linkname);
180 extern struct sysfs_attribute *sysfs_get_directory_attribute
181 (struct sysfs_directory *dir, unsigned char *attrname);
183 /* sysfs driver access */
184 extern void sysfs_close_driver(struct sysfs_driver *driver);
185 extern struct sysfs_driver *sysfs_open_driver
186 (const unsigned char *drv_name, const unsigned char *bus_name);
187 extern struct sysfs_driver *sysfs_open_driver_path(const unsigned char *path);
188 extern struct sysfs_attribute *sysfs_get_driver_attr
189 (struct sysfs_driver *drv, const unsigned char *name);
190 extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver);
191 extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver);
192 extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver);
193 extern struct sysfs_device *sysfs_get_driver_device
194 (struct sysfs_driver *driver, const unsigned char *name);
195 extern struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
196 const unsigned char *drv, const unsigned char *attrib);
198 /* generic sysfs device access */
199 extern void sysfs_close_root_device(struct sysfs_root_device *root);
200 extern struct sysfs_root_device *sysfs_open_root_device
201 (const unsigned char *name);
202 extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root);
203 extern void sysfs_close_device(struct sysfs_device *dev);
204 extern struct sysfs_device *sysfs_open_device
205 (const unsigned char *bus_id, const unsigned char *bus);
206 extern struct sysfs_device *sysfs_get_device_parent(struct sysfs_device *dev);
207 extern struct sysfs_device *sysfs_open_device_path(const unsigned char *path);
208 extern struct sysfs_attribute *sysfs_get_device_attr
209 (struct sysfs_device *dev, const unsigned char *name);
210 extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device);
211 extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus,
212 const unsigned char *bus_id, const unsigned char *attrib);
214 /* generic sysfs bus access */
215 extern void sysfs_close_bus(struct sysfs_bus *bus);
216 extern struct sysfs_bus *sysfs_open_bus(const unsigned char *name);
217 extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
219 extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
220 unsigned char *drvname);
221 extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus);
222 extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus);
223 extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus);
224 extern struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus,
225 unsigned char *attrname);
226 extern struct sysfs_device *sysfs_open_bus_device(unsigned char *busname,
227 unsigned char *dev_id);
228 extern int sysfs_find_driver_bus(const unsigned char *driver,
229 unsigned char *busname, size_t bsize);
231 /* generic sysfs class access */
232 extern void sysfs_close_class_device(struct sysfs_class_device *dev);
233 extern struct sysfs_class_device *sysfs_open_class_device_path
234 (const unsigned char *path);
235 extern struct sysfs_class_device *sysfs_open_class_device
236 (const unsigned char *class, const unsigned char *name);
237 extern struct sysfs_device *sysfs_get_classdev_device
238 (struct sysfs_class_device *clsdev);
239 extern struct sysfs_driver *sysfs_get_classdev_driver
240 (struct sysfs_class_device *clsdev);
241 extern struct sysfs_class_device *sysfs_get_classdev_parent
242 (struct sysfs_class_device *clsdev);
243 extern void sysfs_close_class(struct sysfs_class *cls);
244 extern struct sysfs_class *sysfs_open_class(const unsigned char *name);
245 extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls);
246 extern struct sysfs_class_device *sysfs_get_class_device
247 (struct sysfs_class *class, unsigned char *name);
248 extern struct dlist *sysfs_get_classdev_attributes
249 (struct sysfs_class_device *cdev);
250 extern struct sysfs_attribute *sysfs_get_classdev_attr
251 (struct sysfs_class_device *clsdev, const unsigned char *name);
252 extern struct sysfs_attribute *sysfs_open_classdev_attr
253 (const unsigned char *classname, const unsigned char *dev,
254 const unsigned char *attrib);
260 #endif /* _LIBSYSFS_H_ */