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_DIR "/bus"
35 #define SYSFS_BUS_NAME "bus"
36 #define SYSFS_CLASS_DIR "/class"
37 #define SYSFS_CLASS_NAME "class"
38 #define SYSFS_BLOCK_DIR "/block"
39 #define SYSFS_BLOCK_NAME "block"
40 #define SYSFS_DEVICES_DIR "/devices"
41 #define SYSFS_DEVICES_NAME "devices"
42 #define SYSFS_DRIVERS_DIR "/drivers"
43 #define SYSFS_DRIVERS_NAME "drivers"
44 #define SYSFS_NAME_ATTRIBUTE "name"
45 #define SYSFS_UNKNOWN "unknown"
46 #define SYSFS_PATH_ENV "SYSFS_PATH"
48 #define SYSFS_PATH_MAX 255
49 #define SYSFS_NAME_LEN 50
50 #define SYSFS_BUS_ID_SIZE 20
52 #define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */
53 #define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */
55 struct sysfs_attribute {
57 unsigned short len; /* value length */
58 unsigned short method; /* show and store */
59 unsigned char name[SYSFS_NAME_LEN];
60 unsigned char path[SYSFS_PATH_MAX];
64 unsigned char name[SYSFS_NAME_LEN];
65 unsigned char path[SYSFS_PATH_MAX];
66 unsigned char target[SYSFS_PATH_MAX];
69 struct sysfs_directory {
70 struct dlist *subdirs;
72 struct dlist *attributes;
73 unsigned char name[SYSFS_NAME_LEN];
74 unsigned char path[SYSFS_PATH_MAX];
78 struct dlist *devices;
79 unsigned char name[SYSFS_NAME_LEN];
80 unsigned char path[SYSFS_PATH_MAX];
82 /* for internal use only */
83 struct sysfs_directory *directory;
87 struct sysfs_device *parent;
88 struct dlist *children;
89 unsigned char name[SYSFS_NAME_LEN];
90 unsigned char bus_id[SYSFS_NAME_LEN];
91 unsigned char bus[SYSFS_NAME_LEN];
92 unsigned char driver_name[SYSFS_NAME_LEN];
93 unsigned char path[SYSFS_PATH_MAX];
95 /* for internal use only */
96 struct sysfs_directory *directory;
99 struct sysfs_root_device {
100 struct dlist *devices;
101 unsigned char name[SYSFS_NAME_LEN];
102 unsigned char path[SYSFS_PATH_MAX];
104 /* for internal use only */
105 struct sysfs_directory *directory;
109 struct dlist *drivers;
110 struct dlist *devices;
111 unsigned char name[SYSFS_NAME_LEN];
112 unsigned char path[SYSFS_PATH_MAX];
114 /* internal use only */
115 struct sysfs_directory *directory;
118 struct sysfs_class_device {
119 struct sysfs_device *sysdevice; /* NULL if virtual */
120 struct sysfs_driver *driver; /* NULL if not implemented */
121 unsigned char name[SYSFS_NAME_LEN];
122 unsigned char classname[SYSFS_NAME_LEN];
123 unsigned char path[SYSFS_PATH_MAX];
125 /* for internal use only */
126 struct sysfs_directory *directory;
130 struct dlist *devices;
131 unsigned char name[SYSFS_NAME_LEN];
132 unsigned char path[SYSFS_PATH_MAX];
134 /* for internal use only */
135 struct sysfs_directory *directory;
143 * Function Prototypes
145 extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len);
146 extern int sysfs_get_name_from_path(const unsigned char *path,
147 unsigned char *name, size_t len);
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 void sysfs_close_directory(struct sysfs_directory *sysdir);
165 extern struct sysfs_directory *sysfs_open_directory(const unsigned char *path);
166 extern int sysfs_read_directory(struct sysfs_directory *sysdir);
167 extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir);
168 extern struct sysfs_directory *sysfs_get_subdirectory
169 (struct sysfs_directory *dir, unsigned char *subname);
170 extern void sysfs_close_link(struct sysfs_link *ln);
171 extern struct sysfs_link *sysfs_open_link(const unsigned char *lnpath);
172 extern struct sysfs_link *sysfs_get_directory_link(struct sysfs_directory *dir,
173 unsigned char *linkname);
174 extern struct sysfs_link *sysfs_get_subdirectory_link
175 (struct sysfs_directory *dir, unsigned char *linkname);
176 extern struct sysfs_attribute *sysfs_get_directory_attribute
177 (struct sysfs_directory *dir, unsigned char *attrname);
179 /* sysfs driver access */
180 extern void sysfs_close_driver(struct sysfs_driver *driver);
181 extern struct sysfs_driver *sysfs_open_driver(const unsigned char *path);
182 extern struct sysfs_attribute *sysfs_get_driver_attr
183 (struct sysfs_driver *drv, const unsigned char *name);
184 extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver);
185 extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver);
186 extern void sysfs_close_driver_by_name(struct sysfs_driver *driver);
187 extern struct sysfs_driver *sysfs_open_driver_by_name
188 (const unsigned char *drv_name, const unsigned char *bus, size_t bsize);
189 extern struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus,
190 const unsigned char *drv, const unsigned char *attrib);
192 /* generic sysfs device access */
193 extern void sysfs_close_root_device(struct sysfs_root_device *root);
194 extern struct sysfs_root_device *sysfs_open_root_device
195 (const unsigned char *name);
196 extern void sysfs_close_device(struct sysfs_device *dev);
197 extern struct sysfs_device *sysfs_open_device(const unsigned char *path);
198 extern struct sysfs_attribute *sysfs_get_device_attr
199 (struct sysfs_device *dev, const unsigned char *name);
200 extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device);
201 extern struct sysfs_device *sysfs_open_device_by_id
202 (const unsigned char *bus_id, const unsigned char *bus, size_t bsize);
203 extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus,
204 const unsigned char *bus_id, const unsigned char *attrib);
206 /* generic sysfs bus access */
207 extern void sysfs_close_bus(struct sysfs_bus *bus);
208 extern struct sysfs_bus *sysfs_open_bus(const unsigned char *name);
209 extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
211 extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
212 unsigned char *drvname);
213 extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus);
214 extern struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus,
215 unsigned char *attrname);
216 extern struct sysfs_device *sysfs_open_bus_device(unsigned char *busname,
217 unsigned char *dev_id);
218 extern int sysfs_find_driver_bus(const unsigned char *driver,
219 unsigned char *busname, size_t bsize);
221 /* generic sysfs class access */
222 extern void sysfs_close_class_device(struct sysfs_class_device *dev);
223 extern struct sysfs_class_device *sysfs_open_class_device
224 (const unsigned char *path);
225 extern void sysfs_close_class(struct sysfs_class *cls);
226 extern struct sysfs_class *sysfs_open_class(const unsigned char *name);
227 extern struct sysfs_class_device *sysfs_get_class_device
228 (struct sysfs_class *class, unsigned char *name);
229 extern struct sysfs_class_device *sysfs_open_class_device_by_name
230 (const unsigned char *class, const unsigned char *name);
231 extern struct dlist *sysfs_get_classdev_attributes
232 (struct sysfs_class_device *cdev);
233 extern struct sysfs_attribute *sysfs_get_classdev_attr
234 (struct sysfs_class_device *clsdev, const unsigned char *name);
235 extern struct sysfs_attribute *sysfs_open_classdev_attr
236 (const unsigned char *classname, const unsigned char *dev,
237 const unsigned char *attrib);
243 #endif /* _LIBSYSFS_H_ */