chiark / gitweb /
[PATCH] added libsysfs code from sysutils-0.1.1-071803 release
[elogind.git] / libsysfs / libsysfs.h
1 /*
2  * libsysfs.h
3  *
4  * Header Definitions for libsysfs
5  *
6  * Copyright (C) 2003 International Business Machines, Inc.
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
28 /*
29  * Generic #defines go here..
30  */ 
31 #define SYSFS_FSTYPE_NAME       "sysfs"
32 #define SYSFS_PROC_MNTS         "/proc/mounts"
33 #define SYSFS_BUS_DIR           "/bus"
34 #define SYSFS_CLASS_DIR         "/class"
35 #define SYSFS_DEVICES_DIR       "/devices"
36 #define SYSFS_DEVICES_NAME      "devices"
37 #define SYSFS_DRIVERS_DIR       "/drivers"
38 #define SYSFS_DRIVERS_NAME      "drivers"
39 #define SYSFS_NAME_ATTRIBUTE    "name"
40
41 #define SYSFS_PATH_MAX          255
42 #define SYSFS_NAME_LEN          50
43 #define SYSFS_BUS_ID_SIZE       20
44
45 #define SYSFS_METHOD_SHOW       0x01    /* attr can be read by user */
46 #define SYSFS_METHOD_STORE      0x02    /* attr can be changed by user */
47
48 struct sysfs_attribute {
49         struct sysfs_attribute *next;
50         char path[SYSFS_PATH_MAX];
51         char *value;
52         unsigned short len;             /* value length */
53         unsigned short method;          /* show and store */
54 };
55
56 struct sysfs_dlink {
57         struct sysfs_dlink *next;
58         char name[SYSFS_NAME_LEN];
59         struct sysfs_directory *target;
60 };
61
62 struct sysfs_directory {
63         struct sysfs_directory *next;
64         char path[SYSFS_PATH_MAX];
65         struct sysfs_directory *subdirs;
66         struct sysfs_dlink *links;
67         struct sysfs_attribute *attributes;
68 };
69
70 struct sysfs_driver {
71         struct sysfs_driver *next;
72         char name[SYSFS_NAME_LEN];
73         struct sysfs_directory *directory;
74         struct sysfs_device *device;
75 };
76
77 struct sysfs_device {
78         struct sysfs_device *next;
79         char name[SYSFS_NAME_LEN];
80         char bus_id[SYSFS_NAME_LEN];
81         struct sysfs_driver *driver;
82         struct sysfs_directory *directory;
83         struct sysfs_device *parent;
84         struct sysfs_device *children;
85 };
86
87 struct sysfs_bus {
88         struct sysfs_bus *next;
89         char name[SYSFS_NAME_LEN];
90         struct sysfs_directory *directory;
91         struct sysfs_driver *drivers;
92         struct sysfs_device *devices;
93 };
94
95 struct sysfs_class_device {
96         struct sysfs_class_device *next;
97         char name[SYSFS_NAME_LEN];
98         struct sysfs_directory *directory;
99         struct sysfs_device *sysdevice;         /* NULL if virtual */
100         struct sysfs_driver *driver;            /* NULL if not implemented */
101 };
102
103 struct sysfs_class {
104         struct sysfs_class *next;
105         char name[SYSFS_NAME_LEN];
106         struct sysfs_directory *directory;
107         struct sysfs_class_device *devices;
108 };
109
110 #ifdef __cplusplus
111 extern "C" {
112 #endif
113
114 /*
115  * Function Prototypes
116  */
117 extern int sysfs_get_mnt_path(char *mnt_path, size_t len);
118 extern int sysfs_get_name_from_path(const char *path, char *name, size_t len);
119 extern int sysfs_get_link(const char *path, char *target, size_t len);
120
121 /* sysfs directory and file access */
122 extern void sysfs_close_attribute(struct sysfs_attribute *sysattr);
123 extern struct sysfs_attribute *sysfs_open_attribute(const char *path);
124 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
125 extern int sysfs_read_attribute_value(const char *attrpath, char *value, 
126                                                                 size_t vsize);
127 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr, 
128                                                         const char * name);
129 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
130 extern struct sysfs_directory *sysfs_open_directory(const char *path);
131 extern int sysfs_read_directory(struct sysfs_directory *sysdir);
132 extern void sysfs_close_dlink(struct sysfs_dlink *dlink);
133 extern struct sysfs_dlink *sysfs_open_dlink(const char *linkpath);
134 extern int sysfs_read_dlinks(struct sysfs_dlink *dlink);
135
136 /* sysfs driver access */
137 extern void sysfs_close_driver(struct sysfs_driver *driver);
138 extern struct sysfs_driver *sysfs_open_driver(const char *path);
139
140 /* generic sysfs device access */
141 extern void sysfs_close_device(struct sysfs_device *dev);
142 extern void sysfs_close_device_tree(struct sysfs_device *dev);
143 extern struct sysfs_device *sysfs_open_device(const char *path);
144 extern struct sysfs_device *sysfs_open_device_tree(const char *path);
145 extern struct sysfs_attribute *sysfs_get_device_attr
146                                 (struct sysfs_device *dev, const char *name);
147
148 /* generic sysfs bus access */
149 extern void sysfs_close_bus(struct sysfs_bus *bus);
150 extern struct sysfs_bus *sysfs_open_bus(const char *name);
151
152 /* generic sysfs class access */
153 extern void sysfs_close_class_device(struct sysfs_class_device *dev);
154 extern struct sysfs_class_device *sysfs_open_class_device(const char *path);
155 extern void sysfs_close_class(struct sysfs_class *cls);
156 extern struct sysfs_class *sysfs_open_class(const char *name);
157
158 #ifdef __cplusplus
159 }
160 #endif
161
162 #endif /* _LIBSYSFS_H_ */