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 unsigned char name
[SYSFS_NAME_LEN
];
66 unsigned char path
[SYSFS_PATH_MAX
];
68 /* Private: for internal use only */
69 struct dlist
*subdirs
;
71 struct dlist
*attributes
;
75 unsigned char name
[SYSFS_NAME_LEN
];
76 unsigned char path
[SYSFS_PATH_MAX
];
78 /* Private: for internal use only */
79 struct dlist
*devices
;
80 struct sysfs_directory
*directory
;
84 unsigned char name
[SYSFS_NAME_LEN
];
85 unsigned char bus_id
[SYSFS_NAME_LEN
];
86 unsigned char bus
[SYSFS_NAME_LEN
];
87 unsigned char driver_name
[SYSFS_NAME_LEN
];
88 unsigned char path
[SYSFS_PATH_MAX
];
90 /* Private: for internal use only */
91 struct sysfs_device
*parent
;
92 struct dlist
*children
;
93 struct sysfs_directory
*directory
;
96 struct sysfs_root_device
{
97 unsigned char name
[SYSFS_NAME_LEN
];
98 unsigned char path
[SYSFS_PATH_MAX
];
100 /* Private: for internal use only */
101 struct dlist
*devices
;
102 struct sysfs_directory
*directory
;
106 unsigned char name
[SYSFS_NAME_LEN
];
107 unsigned char path
[SYSFS_PATH_MAX
];
109 /* Private: for internal use only */
110 struct dlist
*drivers
;
111 struct dlist
*devices
;
112 struct sysfs_directory
*directory
;
115 struct sysfs_class_device
{
116 unsigned char name
[SYSFS_NAME_LEN
];
117 unsigned char classname
[SYSFS_NAME_LEN
];
118 unsigned char path
[SYSFS_PATH_MAX
];
120 /* Private: for internal use only */
121 struct sysfs_class_device
*parent
;
122 struct sysfs_device
*sysdevice
; /* NULL if virtual */
123 struct sysfs_driver
*driver
; /* NULL if not implemented */
124 struct sysfs_directory
*directory
;
128 unsigned char name
[SYSFS_NAME_LEN
];
129 unsigned char path
[SYSFS_PATH_MAX
];
131 /* Private: for internal use only */
132 struct dlist
*devices
;
133 struct sysfs_directory
*directory
;
141 * Function Prototypes
143 extern int sysfs_get_mnt_path(unsigned char *mnt_path
, size_t len
);
144 extern int sysfs_remove_trailing_slash(unsigned char *path
);
145 extern int sysfs_get_name_from_path(const unsigned char *path
,
146 unsigned char *name
, size_t len
);
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
);
150 extern int sysfs_get_link(const unsigned char *path
, unsigned char *target
,
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
);
156 /* sysfs directory and file access */
157 extern void sysfs_close_attribute(struct sysfs_attribute
*sysattr
);
158 extern struct sysfs_attribute
*sysfs_open_attribute(const unsigned char *path
);
159 extern int sysfs_read_attribute(struct sysfs_attribute
*sysattr
);
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
);
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
);
169 extern void sysfs_close_directory(struct sysfs_directory
*sysdir
);
170 extern struct sysfs_directory
*sysfs_open_directory(const unsigned char *path
);
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
);
174 extern int sysfs_read_directory(struct sysfs_directory
*sysdir
);
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
);
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
);
190 /* sysfs driver access */
191 extern void sysfs_close_driver(struct sysfs_driver
*driver
);
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
);
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
);
198 extern struct dlist
*sysfs_get_driver_devices(struct sysfs_driver
*driver
);
199 extern struct dlist
*sysfs_refresh_driver_devices(struct sysfs_driver
*driver
);
200 extern struct dlist
*sysfs_get_driver_links(struct sysfs_driver
*driver
);
201 extern struct sysfs_device
*sysfs_get_driver_device
202 (struct sysfs_driver
*driver
, const unsigned char *name
);
203 extern struct dlist
*sysfs_refresh_driver_attributes
204 (struct sysfs_driver
*driver
);
205 extern struct sysfs_attribute
*sysfs_open_driver_attr(const unsigned char *bus
,
206 const unsigned char *drv
, const unsigned char *attrib
);
208 /* generic sysfs device access */
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
);
212 extern struct dlist
*sysfs_get_root_devices(struct sysfs_root_device
*root
);
213 extern void sysfs_close_device(struct sysfs_device
*dev
);
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
);
218 extern int sysfs_get_device_bus(struct sysfs_device
*dev
);
219 extern struct sysfs_attribute
*sysfs_get_device_attr
220 (struct sysfs_device
*dev
, const unsigned char *name
);
221 extern struct dlist
*sysfs_get_device_attributes(struct sysfs_device
*device
);
222 extern struct dlist
*sysfs_refresh_device_attributes
223 (struct sysfs_device
*device
);
224 extern struct sysfs_attribute
*sysfs_open_device_attr(const unsigned char *bus
,
225 const unsigned char *bus_id
, const unsigned char *attrib
);
227 /* generic sysfs bus access */
228 extern void sysfs_close_bus(struct sysfs_bus
*bus
);
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
,
232 extern struct sysfs_driver
*sysfs_get_bus_driver(struct sysfs_bus
*bus
,
233 unsigned char *drvname
);
234 extern struct dlist
*sysfs_get_bus_drivers(struct sysfs_bus
*bus
);
235 extern struct dlist
*sysfs_get_bus_devices(struct sysfs_bus
*bus
);
236 extern struct dlist
*sysfs_get_bus_attributes(struct sysfs_bus
*bus
);
237 extern struct dlist
*sysfs_refresh_bus_attributes(struct sysfs_bus
*bus
);
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
);
242 extern int sysfs_find_driver_bus(const unsigned char *driver
,
243 unsigned char *busname
, size_t bsize
);
245 /* generic sysfs class access */
246 extern void sysfs_close_class_device(struct sysfs_class_device
*dev
);
247 extern struct sysfs_class_device
*sysfs_open_class_device_path
248 (const unsigned char *path
);
249 extern struct sysfs_class_device
*sysfs_open_class_device
250 (const unsigned char *class, const unsigned char *name
);
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
);
257 extern void sysfs_close_class(struct sysfs_class
*cls
);
258 extern struct sysfs_class
*sysfs_open_class(const unsigned char *name
);
259 extern struct dlist
*sysfs_get_class_devices(struct sysfs_class
*cls
);
260 extern struct sysfs_class_device
*sysfs_get_class_device
261 (struct sysfs_class
*class, unsigned char *name
);
262 extern struct dlist
*sysfs_get_classdev_attributes
263 (struct sysfs_class_device
*cdev
);
264 extern struct dlist
*sysfs_refresh_classdev_attributes
265 (struct sysfs_class_device
*cdev
);
266 extern struct sysfs_attribute
*sysfs_get_classdev_attr
267 (struct sysfs_class_device
*clsdev
, const unsigned char *name
);
268 extern struct sysfs_attribute
*sysfs_open_classdev_attr
269 (const unsigned char *classname
, const unsigned char *dev
,
270 const unsigned char *attrib
);
276 #endif /* _LIBSYSFS_H_ */