chiark / gitweb /
[PATCH] another patch for path problem
[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_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"
47
48 #define SYSFS_PATH_MAX          255
49 #define SYSFS_NAME_LEN          50
50 #define SYSFS_BUS_ID_SIZE       20
51
52 #define SYSFS_METHOD_SHOW       0x01    /* attr can be read by user */
53 #define SYSFS_METHOD_STORE      0x02    /* attr can be changed by user */
54
55 struct sysfs_attribute {
56         unsigned char *value;
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];
61 };
62
63 struct sysfs_link {
64         unsigned char name[SYSFS_NAME_LEN];
65         unsigned char path[SYSFS_PATH_MAX];
66         unsigned char target[SYSFS_PATH_MAX];
67 };
68
69 struct sysfs_directory {
70         struct dlist *subdirs;  
71         struct dlist *links;            
72         struct dlist *attributes;
73         unsigned char name[SYSFS_NAME_LEN];
74         unsigned char path[SYSFS_PATH_MAX];
75 };
76
77 struct sysfs_driver {
78         struct dlist *devices;
79         unsigned char name[SYSFS_NAME_LEN];
80         unsigned char path[SYSFS_PATH_MAX];
81
82         /* for internal use only */
83         struct sysfs_directory *directory;      
84 };
85
86 struct sysfs_device {
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];
94
95         /* for internal use only */
96         struct sysfs_directory *directory;      
97 };
98
99 struct sysfs_root_device {
100         struct dlist *devices;
101         unsigned char name[SYSFS_NAME_LEN];
102         unsigned char path[SYSFS_PATH_MAX];
103
104         /* for internal use only */
105         struct sysfs_directory *directory;
106 };
107
108 struct sysfs_bus {
109         struct dlist *drivers;
110         struct dlist *devices;
111         unsigned char name[SYSFS_NAME_LEN];
112         unsigned char path[SYSFS_PATH_MAX];
113
114         /* internal use only */
115         struct sysfs_directory *directory;      
116 };
117
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];
124
125         /* for internal use only */
126         struct sysfs_directory *directory;      
127 };
128
129 struct sysfs_class {
130         struct dlist *devices;
131         unsigned char name[SYSFS_NAME_LEN];
132         unsigned char path[SYSFS_PATH_MAX];
133
134         /* for internal use only */
135         struct sysfs_directory *directory;      
136 };
137
138 #ifdef __cplusplus
139 extern "C" {
140 #endif
141
142 /*
143  * Function Prototypes
144  */
145 extern int sysfs_trailing_slash(unsigned char *path);
146 extern int sysfs_get_mnt_path(unsigned char *mnt_path, size_t len);
147 extern int sysfs_get_name_from_path(const unsigned char *path, 
148                                         unsigned char *name, size_t len);
149 extern int sysfs_get_link(const unsigned char *path, unsigned char *target, 
150                                                                 size_t len);
151 extern struct dlist *sysfs_open_subsystem_list(unsigned char *name);
152 extern struct dlist *sysfs_open_bus_devices_list(unsigned char *name);
153 extern void sysfs_close_list(struct dlist *list);
154
155 /* sysfs directory and file access */
156 extern void sysfs_close_attribute(struct sysfs_attribute *sysattr);
157 extern struct sysfs_attribute *sysfs_open_attribute(const unsigned char *path);
158 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
159 extern int sysfs_read_attribute_value(const unsigned char *attrpath, 
160                                 unsigned char *value, size_t vsize);
161 extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,
162                 const unsigned char *new_value, size_t len);
163 extern unsigned char *sysfs_get_value_from_attributes(struct dlist *attr, 
164                                                 const unsigned char * name);
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_directory(struct sysfs_directory *sysdir);
168 extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir);
169 extern struct sysfs_directory *sysfs_get_subdirectory
170                         (struct sysfs_directory *dir, unsigned char *subname);
171 extern void sysfs_close_link(struct sysfs_link *ln);
172 extern struct sysfs_link *sysfs_open_link(const unsigned char *lnpath);
173 extern struct sysfs_link *sysfs_get_directory_link(struct sysfs_directory *dir,
174                                                 unsigned char *linkname);
175 extern struct sysfs_link *sysfs_get_subdirectory_link
176                         (struct sysfs_directory *dir, unsigned char *linkname);
177 extern struct sysfs_attribute *sysfs_get_directory_attribute
178                         (struct sysfs_directory *dir, unsigned char *attrname);
179
180 /* sysfs driver access */
181 extern void sysfs_close_driver(struct sysfs_driver *driver);
182 extern struct sysfs_driver *sysfs_open_driver(const unsigned char *path);
183 extern struct sysfs_attribute *sysfs_get_driver_attr
184                 (struct sysfs_driver *drv, const unsigned char *name);
185 extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver);
186 extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver);
187 extern void sysfs_close_driver_by_name(struct sysfs_driver *driver);
188 extern struct sysfs_driver *sysfs_open_driver_by_name
189         (const unsigned char *drv_name, const unsigned char *bus, size_t bsize);
190 extern struct sysfs_attribute *sysfs_open_driver_attr(const unsigned char *bus, 
191                 const unsigned char *drv, const unsigned char *attrib);
192
193 /* generic sysfs device access */
194 extern void sysfs_close_root_device(struct sysfs_root_device *root);
195 extern struct sysfs_root_device *sysfs_open_root_device
196                                                 (const unsigned char *name);
197 extern void sysfs_close_device(struct sysfs_device *dev);
198 extern struct sysfs_device *sysfs_open_device(const unsigned char *path);
199 extern struct sysfs_attribute *sysfs_get_device_attr
200                         (struct sysfs_device *dev, const unsigned char *name);
201 extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device);
202 extern struct sysfs_device *sysfs_open_device_by_id
203         (const unsigned char *bus_id, const unsigned char *bus, size_t bsize);
204 extern struct sysfs_attribute *sysfs_open_device_attr(const unsigned char *bus, 
205                 const unsigned char *bus_id, const unsigned char *attrib);
206
207 /* generic sysfs bus access */
208 extern void sysfs_close_bus(struct sysfs_bus *bus);
209 extern struct sysfs_bus *sysfs_open_bus(const unsigned char *name);
210 extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus,
211                                                 unsigned char *id);
212 extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus,
213                                                 unsigned char *drvname);
214 extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus);
215 extern struct sysfs_attribute *sysfs_get_bus_attribute(struct sysfs_bus *bus,
216                                                 unsigned char *attrname);
217 extern struct sysfs_device *sysfs_open_bus_device(unsigned char *busname, 
218                                                         unsigned char *dev_id);
219 extern int sysfs_find_driver_bus(const unsigned char *driver, 
220                                         unsigned char *busname, size_t bsize);
221
222 /* generic sysfs class access */
223 extern void sysfs_close_class_device(struct sysfs_class_device *dev);
224 extern struct sysfs_class_device *sysfs_open_class_device
225                                         (const unsigned char *path);
226 extern void sysfs_close_class(struct sysfs_class *cls);
227 extern struct sysfs_class *sysfs_open_class(const unsigned char *name);
228 extern struct sysfs_class_device *sysfs_get_class_device
229         (struct sysfs_class *class, unsigned char *name);
230 extern struct sysfs_class_device *sysfs_open_class_device_by_name
231         (const unsigned char *class, const unsigned char *name);
232 extern struct dlist *sysfs_get_classdev_attributes
233         (struct sysfs_class_device *cdev);
234 extern struct sysfs_attribute *sysfs_get_classdev_attr
235         (struct sysfs_class_device *clsdev, const unsigned char *name);
236 extern struct sysfs_attribute *sysfs_open_classdev_attr
237         (const unsigned char *classname, const unsigned char *dev, 
238                                                 const unsigned char *attrib); 
239
240 #ifdef __cplusplus
241 }
242 #endif
243
244 #endif /* _LIBSYSFS_H_ */