chiark / gitweb /
[PATCH] pre-libsysfs-0.4.0 patch
[elogind.git] / libsysfs / libsysfs.h
1 /*
2  * libsysfs.h
3  *
4  * Header Definitions for libsysfs
5  *
6  * Copyright (C) IBM Corp. 2003
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>
27 #include "dlist.h"
28
29 /*
30  * Generic #defines go here..
31  */ 
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"
42
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 {
51         unsigned char *value;
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];
56 };
57
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];
62 };
63
64 struct sysfs_directory {
65         struct dlist *subdirs;  
66         struct dlist *links;            
67         struct dlist *attributes;
68         unsigned char name[SYSFS_NAME_LEN];
69         unsigned char path[SYSFS_PATH_MAX];
70 };
71
72 struct sysfs_driver {
73         unsigned char name[SYSFS_NAME_LEN];
74         unsigned char path[SYSFS_PATH_MAX];
75
76         /* for internal use only */
77         struct dlist *devices;
78         struct sysfs_directory *directory;      
79 };
80
81 struct sysfs_device {
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];
87
88         /* for internal use only */
89         struct sysfs_device *parent;            
90         struct dlist *children; 
91         struct sysfs_directory *directory;      
92 };
93
94 struct sysfs_root_device {
95         unsigned char name[SYSFS_NAME_LEN];
96         unsigned char path[SYSFS_PATH_MAX];
97
98         /* for internal use only */
99         struct dlist *devices;
100         struct sysfs_directory *directory;
101 };
102
103 struct sysfs_bus {
104         unsigned char name[SYSFS_NAME_LEN];
105         unsigned char path[SYSFS_PATH_MAX];
106
107         /* internal use only */
108         struct dlist *drivers;
109         struct dlist *devices;
110         struct sysfs_directory *directory;      
111 };
112
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];
117
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;      
123 };
124
125 struct sysfs_class {
126         unsigned char name[SYSFS_NAME_LEN];
127         unsigned char path[SYSFS_PATH_MAX];
128
129         /* for internal use only */
130         struct dlist *devices;
131         struct sysfs_directory *directory;      
132 };
133
134 #ifdef __cplusplus
135 extern "C" {
136 #endif
137
138 /*
139  * Function Prototypes
140  */
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, 
149                                                                 size_t len);
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);
153
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);
182
183 /* sysfs driver access */
184 extern void sysfs_close_driver(struct sysfs_driver *driver);
185 extern struct sysfs_driver *sysfs_open_driver(const unsigned char *path);
186 extern struct sysfs_attribute *sysfs_get_driver_attr
187                 (struct sysfs_driver *drv, const unsigned char *name);
188 extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver);
189 extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver);
190 extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver);
191 extern struct sysfs_device *sysfs_get_driver_device
192         (struct sysfs_driver *driver, const unsigned char *name);
193 extern struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus, 
194                 const unsigned char *drv, const unsigned char *attrib);
195
196 /* generic sysfs device access */
197 extern void sysfs_close_root_device(struct sysfs_root_device *root);
198 extern struct sysfs_root_device *sysfs_open_root_device
199                                                 (const unsigned char *name);
200 extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root);
201 extern void sysfs_close_device(struct sysfs_device *dev);
202 extern struct sysfs_device *sysfs_open_device(const unsigned char *path);
203 extern struct sysfs_attribute *sysfs_get_device_attr
204                         (struct sysfs_device *dev, const unsigned char *name);
205 extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device);
206 extern struct sysfs_device *sysfs_open_device_by_id
207                 (const unsigned char *bus_id, const unsigned char *bus);
208 extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus, 
209                 const unsigned char *bus_id, const unsigned char *attrib);
210
211 /* generic sysfs bus access */
212 extern void sysfs_close_bus(struct sysfs_bus *bus);
213 extern struct sysfs_bus *sysfs_open_bus(const unsigned char *name);
214 extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
215                                                 unsigned char *id);
216 extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
217                                                 unsigned char *drvname);
218 extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus);
219 extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus);
220 extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus);
221 extern struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus,
222                                                 unsigned char *attrname);
223 extern struct sysfs_device *sysfs_open_bus_device(unsigned char *busname, 
224                                                         unsigned char *dev_id);
225 extern int sysfs_find_driver_bus(const unsigned char *driver, 
226                                         unsigned char *busname, size_t bsize);
227
228 /* generic sysfs class access */
229 extern void sysfs_close_class_device(struct sysfs_class_device *dev);
230 extern struct sysfs_class_device *sysfs_open_class_device
231                                         (const unsigned char *path);
232 extern struct sysfs_device *sysfs_get_classdev_device
233                                 (struct sysfs_class_device *clsdev);
234 extern struct sysfs_driver *sysfs_get_classdev_driver
235                                 (struct sysfs_class_device *clsdev);
236 extern struct sysfs_class_device *sysfs_get_classdev_parent
237                                 (struct sysfs_class_device *clsdev);
238 extern void sysfs_close_class(struct sysfs_class *cls);
239 extern struct sysfs_class *sysfs_open_class(const unsigned char *name);
240 extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls);
241 extern struct sysfs_class_device *sysfs_get_class_device
242         (struct sysfs_class *class, unsigned char *name);
243 extern struct sysfs_class_device *sysfs_open_class_device_by_name
244         (const unsigned char *class, const unsigned char *name);
245 extern struct dlist *sysfs_get_classdev_attributes
246         (struct sysfs_class_device *cdev);
247 extern struct sysfs_attribute *sysfs_get_classdev_attr
248         (struct sysfs_class_device *clsdev, const unsigned char *name);
249 extern struct sysfs_attribute *sysfs_open_classdev_attr
250         (const unsigned char *classname, const unsigned char *dev, 
251                                                 const unsigned char *attrib); 
252
253 #ifdef __cplusplus
254 }
255 #endif
256
257 #endif /* _LIBSYSFS_H_ */