4 * Header Definitions for libsysfs
6 * Copyright (C) 2003 International Business Machines, Inc.
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>
29 * Generic #defines go here..
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"
41 #define SYSFS_PATH_MAX 255
42 #define SYSFS_NAME_LEN 50
43 #define SYSFS_BUS_ID_SIZE 20
45 #define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */
46 #define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */
48 struct sysfs_attribute {
49 struct sysfs_attribute *next;
50 char path[SYSFS_PATH_MAX];
52 unsigned short len; /* value length */
53 unsigned short method; /* show and store */
57 struct sysfs_dlink *next;
58 char name[SYSFS_NAME_LEN];
59 struct sysfs_directory *target;
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;
71 struct sysfs_driver *next;
72 char name[SYSFS_NAME_LEN];
73 struct sysfs_directory *directory;
74 struct sysfs_device *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;
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;
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 */
104 struct sysfs_class *next;
105 char name[SYSFS_NAME_LEN];
106 struct sysfs_directory *directory;
107 struct sysfs_class_device *devices;
115 * Function Prototypes
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);
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,
127 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr,
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);
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);
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);
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);
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);
162 #endif /* _LIBSYSFS_H_ */