diff options
author | kay.sievers@vrfy.org <kay.sievers@vrfy.org> | 2005-02-23 12:21:39 +0100 |
---|---|---|
committer | Greg KH <gregkh@suse.de> | 2005-04-26 23:36:13 -0700 |
commit | f385ff6512012a75b8381938dd3f55f991b53e9a (patch) | |
tree | dc244352cda7c9b52f86917d1b311c386fc9e71c /libsysfs/sysfs | |
parent | 8d1b4df2192915dc94442c1ef3327a28a57b3615 (diff) |
[PATCH] big libsysfs diet (pre 2.0 version)
Diffstat (limited to 'libsysfs/sysfs')
-rw-r--r-- | libsysfs/sysfs/libsysfs.h | 177 |
1 files changed, 36 insertions, 141 deletions
diff --git a/libsysfs/sysfs/libsysfs.h b/libsysfs/sysfs/libsysfs.h index 29194f61a6..6140c3aecb 100644 --- a/libsysfs/sysfs/libsysfs.h +++ b/libsysfs/sysfs/libsysfs.h @@ -3,7 +3,7 @@ * * Header Definitions for libsysfs * - * Copyright (C) IBM Corp. 2003 + * Copyright (C) IBM Corp. 2004-2005 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -27,27 +27,6 @@ #include <string.h> #include "dlist.h" -/* - * Defines to prevent buffer overruns - */ -#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1) -#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1) - -#define safestrcpymax(to, from, max) \ -do { \ - to[max-1] = '\0'; \ - strncpy(to, from, max-1); \ -} while (0) - -#define safestrcatmax(to, from, max) \ -do { \ - to[max-1] = '\0'; \ - strncat(to, from, max - strlen(to)-1); \ -} while (0) - -/* - * Generic #defines go here.. - */ #define SYSFS_FSTYPE_NAME "sysfs" #define SYSFS_PROC_MNTS "/proc/mounts" #define SYSFS_BUS_NAME "bus" @@ -55,106 +34,92 @@ do { \ #define SYSFS_BLOCK_NAME "block" #define SYSFS_DEVICES_NAME "devices" #define SYSFS_DRIVERS_NAME "drivers" +#define SYSFS_MODULE_NAME "module" #define SYSFS_NAME_ATTRIBUTE "name" #define SYSFS_UNKNOWN "unknown" #define SYSFS_PATH_ENV "SYSFS_PATH" -#define SYSFS_PATH_MAX 255 -#define SYSFS_NAME_LEN 50 -#define SYSFS_BUS_ID_SIZE 20 +#define SYSFS_PATH_MAX 256 +#define SYSFS_NAME_LEN 64 +#define SYSFS_BUS_ID_SIZE 32 -#define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */ -#define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */ +enum sysfs_attribute_method { + SYSFS_METHOD_SHOW = 0x01, /* attr can be read by user */ + SYSFS_METHOD_STORE = 0x02, /* attr can be changed by user */ +}; + +/* NOTE: statically define mnt path for sysfs */ +#define SYSFS_MNT_PATH "/sys" /* - * NOTE: We have the statically allocated "name" as the first element of all + * NOTE: + * 1. We have the statically allocated "name" as the first element of all * the structures. This feature is used in the "sorter" function for dlists + * 2. As is the case with attrlist + * 3. As is the case with path */ - struct sysfs_attribute { char name[SYSFS_NAME_LEN]; char path[SYSFS_PATH_MAX]; char *value; - unsigned short len; /* value length */ - unsigned short method; /* show and store */ -}; - -struct sysfs_link { - char name[SYSFS_NAME_LEN]; - char path[SYSFS_PATH_MAX]; - char target[SYSFS_PATH_MAX]; -}; - -struct sysfs_directory { - char name[SYSFS_NAME_LEN]; - char path[SYSFS_PATH_MAX]; - - /* Private: for internal use only */ - struct dlist *subdirs; - struct dlist *links; - struct dlist *attributes; + unsigned short len; /* value length */ + enum sysfs_attribute_method method; /* show and store */ }; struct sysfs_driver { char name[SYSFS_NAME_LEN]; char path[SYSFS_PATH_MAX]; + struct dlist *attrlist; + char bus[SYSFS_NAME_LEN]; /* Private: for internal use only */ struct dlist *devices; - struct sysfs_directory *directory; }; struct sysfs_device { char name[SYSFS_NAME_LEN]; + char path[SYSFS_PATH_MAX]; + struct dlist *attrlist; char bus_id[SYSFS_NAME_LEN]; char bus[SYSFS_NAME_LEN]; char driver_name[SYSFS_NAME_LEN]; - char path[SYSFS_PATH_MAX]; /* Private: for internal use only */ struct sysfs_device *parent; + /* NOTE - we still don't populate this */ struct dlist *children; - struct sysfs_directory *directory; -}; - -struct sysfs_root_device { - char name[SYSFS_NAME_LEN]; - char path[SYSFS_PATH_MAX]; - - /* Private: for internal use only */ - struct dlist *devices; - struct sysfs_directory *directory; }; +/* NOTE: not used as of now */ struct sysfs_bus { char name[SYSFS_NAME_LEN]; char path[SYSFS_PATH_MAX]; + struct dlist *attrlist; /* Private: for internal use only */ struct dlist *drivers; struct dlist *devices; - struct sysfs_directory *directory; }; struct sysfs_class_device { char name[SYSFS_NAME_LEN]; - char classname[SYSFS_NAME_LEN]; char path[SYSFS_PATH_MAX]; + struct dlist *attrlist; + char classname[SYSFS_NAME_LEN]; /* Private: for internal use only */ struct sysfs_class_device *parent; struct sysfs_device *sysdevice; /* NULL if virtual */ - struct sysfs_driver *driver; /* NULL if not implemented */ - struct sysfs_directory *directory; }; +/* NOTE: not used as of now */ struct sysfs_class { char name[SYSFS_NAME_LEN]; char path[SYSFS_PATH_MAX]; + struct dlist *attrlist; /* Private: for internal use only */ struct dlist *devices; - struct sysfs_directory *directory; }; #ifdef __cplusplus @@ -171,43 +136,15 @@ extern int sysfs_path_is_dir(const char *path); extern int sysfs_path_is_link(const char *path); extern int sysfs_path_is_file(const char *path); extern int sysfs_get_link(const char *path, char *target, size_t len); -extern struct dlist *sysfs_open_subsystem_list(char *name); -extern struct dlist *sysfs_open_bus_devices_list(char *name); +extern struct dlist *sysfs_open_directory_list(const char *path); extern void sysfs_close_list(struct dlist *list); /* sysfs directory and file access */ extern void sysfs_close_attribute(struct sysfs_attribute *sysattr); extern struct sysfs_attribute *sysfs_open_attribute(const char *path); extern int sysfs_read_attribute(struct sysfs_attribute *sysattr); -extern int sysfs_read_attribute_value(const char *attrpath, - char *value, size_t vsize); extern int sysfs_write_attribute(struct sysfs_attribute *sysattr, const char *new_value, size_t len); -extern char *sysfs_get_value_from_attributes(struct dlist *attr, - const char *name); -extern int sysfs_refresh_dir_attributes(struct sysfs_directory *sysdir); -extern int sysfs_refresh_dir_links(struct sysfs_directory *sysdir); -extern int sysfs_refresh_dir_subdirs(struct sysfs_directory *sysdir); -extern void sysfs_close_directory(struct sysfs_directory *sysdir); -extern struct sysfs_directory *sysfs_open_directory(const char *path); -extern int sysfs_read_dir_attributes(struct sysfs_directory *sysdir); -extern int sysfs_read_dir_links(struct sysfs_directory *sysdir); -extern int sysfs_read_dir_subdirs(struct sysfs_directory *sysdir); -extern int sysfs_read_directory(struct sysfs_directory *sysdir); -extern int sysfs_read_all_subdirs(struct sysfs_directory *sysdir); -extern struct sysfs_directory *sysfs_get_subdirectory - (struct sysfs_directory *dir, char *subname); -extern void sysfs_close_link(struct sysfs_link *ln); -extern struct sysfs_link *sysfs_open_link(const char *lnpath); -extern struct sysfs_link *sysfs_get_directory_link - (struct sysfs_directory *dir, char *linkname); -extern struct sysfs_link *sysfs_get_subdirectory_link - (struct sysfs_directory *dir, char *linkname); -extern struct sysfs_attribute *sysfs_get_directory_attribute - (struct sysfs_directory *dir, char *attrname); -extern struct dlist *sysfs_get_dir_attributes(struct sysfs_directory *dir); -extern struct dlist *sysfs_get_dir_links(struct sysfs_directory *dir); -extern struct dlist *sysfs_get_dir_subdirs(struct sysfs_directory *dir); /* sysfs driver access */ extern void sysfs_close_driver(struct sysfs_driver *driver); @@ -218,19 +155,8 @@ extern struct sysfs_attribute *sysfs_get_driver_attr (struct sysfs_driver *drv, const char *name); extern struct dlist *sysfs_get_driver_attributes(struct sysfs_driver *driver); extern struct dlist *sysfs_get_driver_devices(struct sysfs_driver *driver); -extern struct dlist *sysfs_refresh_driver_devices(struct sysfs_driver *driver); -extern struct dlist *sysfs_get_driver_links(struct sysfs_driver *driver); -extern struct sysfs_device *sysfs_get_driver_device - (struct sysfs_driver *driver, const char *name); -extern struct dlist *sysfs_refresh_driver_attributes - (struct sysfs_driver *driver); -extern struct sysfs_attribute *sysfs_open_driver_attr - (const char *bus, const char *drv, const char *attrib); /* generic sysfs device access */ -extern void sysfs_close_root_device(struct sysfs_root_device *root); -extern struct sysfs_root_device *sysfs_open_root_device(const char *name); -extern struct dlist *sysfs_get_root_devices(struct sysfs_root_device *root); extern void sysfs_close_device_tree(struct sysfs_device *device); extern struct sysfs_device *sysfs_open_device_tree(const char *path); extern void sysfs_close_device(struct sysfs_device *dev); @@ -241,27 +167,8 @@ extern struct sysfs_device *sysfs_open_device_path(const char *path); extern int sysfs_get_device_bus(struct sysfs_device *dev); extern struct sysfs_attribute *sysfs_get_device_attr (struct sysfs_device *dev, const char *name); -extern struct dlist *sysfs_get_device_attributes(struct sysfs_device *device); -extern struct dlist *sysfs_refresh_device_attributes - (struct sysfs_device *device); -extern struct sysfs_attribute *sysfs_open_device_attr(const char *bus, - const char *bus_id, const char *attrib); - -/* generic sysfs bus access */ -extern void sysfs_close_bus(struct sysfs_bus *bus); -extern struct sysfs_bus *sysfs_open_bus(const char *name); -extern struct sysfs_device *sysfs_get_bus_device(struct sysfs_bus *bus, - char *id); -extern struct sysfs_driver *sysfs_get_bus_driver(struct sysfs_bus *bus, - char *drvname); -extern struct dlist *sysfs_get_bus_drivers(struct sysfs_bus *bus); -extern struct dlist *sysfs_get_bus_devices(struct sysfs_bus *bus); -extern struct dlist *sysfs_get_bus_attributes(struct sysfs_bus *bus); -extern struct dlist *sysfs_refresh_bus_attributes(struct sysfs_bus *bus); -extern struct sysfs_attribute *sysfs_get_bus_attribute - (struct sysfs_bus *bus, char *attrname); -extern int sysfs_find_driver_bus(const char *driver, char *busname, - size_t bsize); +extern struct dlist *sysfs_get_device_attributes + (struct sysfs_device *dev); /* generic sysfs class access */ extern void sysfs_close_class_device(struct sysfs_class_device *dev); @@ -269,26 +176,14 @@ extern struct sysfs_class_device *sysfs_open_class_device_path (const char *path); extern struct sysfs_class_device *sysfs_open_class_device (const char *classname, const char *name); -extern struct sysfs_device *sysfs_get_classdev_device - (struct sysfs_class_device *clsdev); -extern struct sysfs_driver *sysfs_get_classdev_driver - (struct sysfs_class_device *clsdev); extern struct sysfs_class_device *sysfs_get_classdev_parent (struct sysfs_class_device *clsdev); -extern void sysfs_close_class(struct sysfs_class *cls); -extern struct sysfs_class *sysfs_open_class(const char *name); -extern struct dlist *sysfs_get_class_devices(struct sysfs_class *cls); -extern struct sysfs_class_device *sysfs_get_class_device - (struct sysfs_class *cls, char *name); -extern struct dlist *sysfs_get_classdev_attributes - (struct sysfs_class_device *cdev); -extern struct dlist *sysfs_refresh_classdev_attributes - (struct sysfs_class_device *cdev); extern struct sysfs_attribute *sysfs_get_classdev_attr (struct sysfs_class_device *clsdev, const char *name); -extern struct sysfs_attribute *sysfs_open_classdev_attr - (const char *classname, const char *dev, - const char *attrib); +extern struct dlist *sysfs_get_classdev_attributes + (struct sysfs_class_device *clsdev); +extern struct sysfs_device *sysfs_get_classdev_device + (struct sysfs_class_device *clsdev); /** * sort_list: sorter function to keep list elements sorted in alphabetical |