2003-07-19 07:08:00 +04:00
/*
* libsysfs . h
*
* Header Definitions for libsysfs
*
2003-10-21 12:19:14 +04:00
* Copyright ( C ) IBM Corp . 2003
2003-07-19 07:08:00 +04:00
*
* This library is free software ; you can redistribute it and / or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation ; either
* version 2.1 of the License , or ( at your option ) any later version .
*
* This library is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
* Lesser General Public License for more details .
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place , Suite 330 , Boston , MA 02111 - 1307 USA
*
*/
# ifndef _LIBSYSFS_H_
# define _LIBSYSFS_H_
# include <sys/types.h>
2004-03-12 11:57:30 +03:00
# include <string.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)
[PATCH] more Libsysfs updates
On Thu, Mar 11, 2004 at 02:36:23PM +0100, Kay Sievers wrote:
> On Thu, 2004-03-11 at 15:02, Ananth N Mavinakayanahalli wrote:
> > On Thu, Mar 11, 2004 at 02:04:36PM +0100, Kay Sievers wrote:
> > > On Thu, Mar 11, 2004 at 11:53:50AM +0500, Ananth N Mavinakayanahalli wrote:
> > >
> > > > +#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1)
> > > > +#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
> > >
> > > These strings are not terminated with '\0' if from is longer than
> > > the sizeof to.
> >
> > Did not do it on purpose as the "to" elements are either calloc'd or memset to
> > '0' explicitly in the library. Thats the reason I mentioned "scaled down" :)
>
> Ahh, sounds good.
>
> > > > +#define safestrncpy(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncpy(to, from, maxsize-1); \
> > > > +} while (0)
> > > > +
> > > > +#define safestrncat(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncat(to, from, maxsize - strlen(to)-1); \
> > > > +} while (0)
> > >
> > > We all expect a similar behavior like strncat/strncpy according to the
> > > names, but these macros are limiting by the target size and do not limit
> > > the count of chars copied.
> > > This is confusing I think and suggest using a different name like
> > > 'safestrcopymax()' or something.
> >
> > Good point.. will make the change
>
> Nice. I've had these *n* names too and I forgot about the logic and only
> 10 days later I introduced a ugly bug cause I can't limit the count of
> copied chars :)
Inlined is the patch for this... applies on the earlier _BIG_ patch.
2004-03-12 11:57:36 +03:00
# define safestrcpymax(to, from, max) \
2004-03-12 11:57:30 +03:00
do { \
[PATCH] more Libsysfs updates
On Thu, Mar 11, 2004 at 02:36:23PM +0100, Kay Sievers wrote:
> On Thu, 2004-03-11 at 15:02, Ananth N Mavinakayanahalli wrote:
> > On Thu, Mar 11, 2004 at 02:04:36PM +0100, Kay Sievers wrote:
> > > On Thu, Mar 11, 2004 at 11:53:50AM +0500, Ananth N Mavinakayanahalli wrote:
> > >
> > > > +#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1)
> > > > +#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
> > >
> > > These strings are not terminated with '\0' if from is longer than
> > > the sizeof to.
> >
> > Did not do it on purpose as the "to" elements are either calloc'd or memset to
> > '0' explicitly in the library. Thats the reason I mentioned "scaled down" :)
>
> Ahh, sounds good.
>
> > > > +#define safestrncpy(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncpy(to, from, maxsize-1); \
> > > > +} while (0)
> > > > +
> > > > +#define safestrncat(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncat(to, from, maxsize - strlen(to)-1); \
> > > > +} while (0)
> > >
> > > We all expect a similar behavior like strncat/strncpy according to the
> > > names, but these macros are limiting by the target size and do not limit
> > > the count of chars copied.
> > > This is confusing I think and suggest using a different name like
> > > 'safestrcopymax()' or something.
> >
> > Good point.. will make the change
>
> Nice. I've had these *n* names too and I forgot about the logic and only
> 10 days later I introduced a ugly bug cause I can't limit the count of
> copied chars :)
Inlined is the patch for this... applies on the earlier _BIG_ patch.
2004-03-12 11:57:36 +03:00
to [ max - 1 ] = ' \0 ' ; \
strncpy ( to , from , max - 1 ) ; \
2004-03-12 11:57:30 +03:00
} while ( 0 )
[PATCH] more Libsysfs updates
On Thu, Mar 11, 2004 at 02:36:23PM +0100, Kay Sievers wrote:
> On Thu, 2004-03-11 at 15:02, Ananth N Mavinakayanahalli wrote:
> > On Thu, Mar 11, 2004 at 02:04:36PM +0100, Kay Sievers wrote:
> > > On Thu, Mar 11, 2004 at 11:53:50AM +0500, Ananth N Mavinakayanahalli wrote:
> > >
> > > > +#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1)
> > > > +#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
> > >
> > > These strings are not terminated with '\0' if from is longer than
> > > the sizeof to.
> >
> > Did not do it on purpose as the "to" elements are either calloc'd or memset to
> > '0' explicitly in the library. Thats the reason I mentioned "scaled down" :)
>
> Ahh, sounds good.
>
> > > > +#define safestrncpy(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncpy(to, from, maxsize-1); \
> > > > +} while (0)
> > > > +
> > > > +#define safestrncat(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncat(to, from, maxsize - strlen(to)-1); \
> > > > +} while (0)
> > >
> > > We all expect a similar behavior like strncat/strncpy according to the
> > > names, but these macros are limiting by the target size and do not limit
> > > the count of chars copied.
> > > This is confusing I think and suggest using a different name like
> > > 'safestrcopymax()' or something.
> >
> > Good point.. will make the change
>
> Nice. I've had these *n* names too and I forgot about the logic and only
> 10 days later I introduced a ugly bug cause I can't limit the count of
> copied chars :)
Inlined is the patch for this... applies on the earlier _BIG_ patch.
2004-03-12 11:57:36 +03:00
# define safestrcatmax(to, from, max) \
2004-03-12 11:57:30 +03:00
do { \
[PATCH] more Libsysfs updates
On Thu, Mar 11, 2004 at 02:36:23PM +0100, Kay Sievers wrote:
> On Thu, 2004-03-11 at 15:02, Ananth N Mavinakayanahalli wrote:
> > On Thu, Mar 11, 2004 at 02:04:36PM +0100, Kay Sievers wrote:
> > > On Thu, Mar 11, 2004 at 11:53:50AM +0500, Ananth N Mavinakayanahalli wrote:
> > >
> > > > +#define safestrcpy(to, from) strncpy(to, from, sizeof(to)-1)
> > > > +#define safestrcat(to, from) strncat(to, from, sizeof(to) - strlen(to)-1)
> > >
> > > These strings are not terminated with '\0' if from is longer than
> > > the sizeof to.
> >
> > Did not do it on purpose as the "to" elements are either calloc'd or memset to
> > '0' explicitly in the library. Thats the reason I mentioned "scaled down" :)
>
> Ahh, sounds good.
>
> > > > +#define safestrncpy(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncpy(to, from, maxsize-1); \
> > > > +} while (0)
> > > > +
> > > > +#define safestrncat(to, from, maxsize) \
> > > > +do { \
> > > > + to[maxsize-1] = '\0'; \
> > > > + strncat(to, from, maxsize - strlen(to)-1); \
> > > > +} while (0)
> > >
> > > We all expect a similar behavior like strncat/strncpy according to the
> > > names, but these macros are limiting by the target size and do not limit
> > > the count of chars copied.
> > > This is confusing I think and suggest using a different name like
> > > 'safestrcopymax()' or something.
> >
> > Good point.. will make the change
>
> Nice. I've had these *n* names too and I forgot about the logic and only
> 10 days later I introduced a ugly bug cause I can't limit the count of
> copied chars :)
Inlined is the patch for this... applies on the earlier _BIG_ patch.
2004-03-12 11:57:36 +03:00
to [ max - 1 ] = ' \0 ' ; \
strncat ( to , from , max - strlen ( to ) - 1 ) ; \
2004-03-12 11:57:30 +03:00
} while ( 0 )
2003-07-19 07:08:00 +04:00
/*
* Generic # defines go here . .
*/
# define SYSFS_FSTYPE_NAME "sysfs"
# define SYSFS_PROC_MNTS " / proc / mounts"
2003-11-25 10:47:43 +03:00
# define SYSFS_BUS_NAME "bus"
# define SYSFS_CLASS_NAME "class"
# define SYSFS_BLOCK_NAME "block"
2003-07-19 07:08:00 +04:00
# define SYSFS_DEVICES_NAME "devices"
# define SYSFS_DRIVERS_NAME "drivers"
# define SYSFS_NAME_ATTRIBUTE "name"
2003-10-21 12:19:14 +04:00
# define SYSFS_UNKNOWN "unknown"
2003-11-12 16:37:24 +03:00
# define SYSFS_PATH_ENV "SYSFS_PATH"
2003-10-21 12:19:14 +04:00
2003-07-19 07:08:00 +04:00
# define SYSFS_PATH_MAX 255
# define SYSFS_NAME_LEN 50
# define SYSFS_BUS_ID_SIZE 20
# define SYSFS_METHOD_SHOW 0x01 /* attr can be read by user */
# define SYSFS_METHOD_STORE 0x02 /* attr can be changed by user */
2004-03-12 11:57:30 +03:00
/*
* NOTE : We have the statically allocated " name " as the first element of all
* the structures . This feature is used in the " sorter " function for dlists
*/
2004-02-24 06:06:49 +03:00
2003-07-19 07:08:00 +04:00
struct sysfs_attribute {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
char * value ;
2003-07-19 07:08:00 +04:00
unsigned short len ; /* value length */
unsigned short method ; /* show and store */
} ;
2003-10-21 12:19:14 +04:00
struct sysfs_link {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
char target [ SYSFS_PATH_MAX ] ;
2003-07-19 07:08:00 +04:00
} ;
struct sysfs_directory {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-10-21 12:19:14 +04:00
struct dlist * subdirs ;
struct dlist * links ;
struct dlist * attributes ;
2003-07-19 07:08:00 +04:00
} ;
struct sysfs_driver {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2003-10-21 12:19:14 +04:00
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-12-16 08:53:28 +03:00
struct dlist * devices ;
2003-10-21 12:19:14 +04:00
struct sysfs_directory * directory ;
2003-07-19 07:08:00 +04:00
} ;
struct sysfs_device {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char bus_id [ SYSFS_NAME_LEN ] ;
char bus [ SYSFS_NAME_LEN ] ;
char driver_name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2003-10-21 12:19:14 +04:00
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-12-16 08:53:28 +03:00
struct sysfs_device * parent ;
struct dlist * children ;
2003-10-21 12:19:14 +04:00
struct sysfs_directory * directory ;
} ;
struct sysfs_root_device {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2003-10-21 12:19:14 +04:00
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-12-16 08:53:28 +03:00
struct dlist * devices ;
2003-07-19 07:08:00 +04:00
struct sysfs_directory * directory ;
} ;
struct sysfs_bus {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2003-10-21 12:19:14 +04:00
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-12-16 08:53:28 +03:00
struct dlist * drivers ;
struct dlist * devices ;
2003-10-21 12:19:14 +04:00
struct sysfs_directory * directory ;
2003-07-19 07:08:00 +04:00
} ;
struct sysfs_class_device {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char classname [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2003-10-21 12:19:14 +04:00
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-12-16 08:53:28 +03:00
struct sysfs_class_device * parent ;
struct sysfs_device * sysdevice ; /* NULL if virtual */
struct sysfs_driver * driver ; /* NULL if not implemented */
2003-10-21 12:19:14 +04:00
struct sysfs_directory * directory ;
2003-07-19 07:08:00 +04:00
} ;
struct sysfs_class {
2004-03-12 11:57:30 +03:00
char name [ SYSFS_NAME_LEN ] ;
char path [ SYSFS_PATH_MAX ] ;
2003-10-21 12:19:14 +04:00
2004-01-15 09:21:38 +03:00
/* Private: for internal use only */
2003-12-16 08:53:28 +03:00
struct dlist * devices ;
2003-10-21 12:19:14 +04:00
struct sysfs_directory * directory ;
2003-07-19 07:08:00 +04:00
} ;
# ifdef __cplusplus
extern " C " {
# endif
/*
* Function Prototypes
*/
2004-03-12 11:57:30 +03:00
extern int sysfs_get_mnt_path ( char * mnt_path , size_t len ) ;
extern int sysfs_remove_trailing_slash ( char * path ) ;
extern int sysfs_get_name_from_path ( const char * path , char * name , size_t len ) ;
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 ) ;
2003-10-21 12:19:14 +04:00
extern void sysfs_close_list ( struct dlist * list ) ;
2003-07-19 07:08:00 +04:00
/* sysfs directory and file access */
extern void sysfs_close_attribute ( struct sysfs_attribute * sysattr ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_attribute * sysfs_open_attribute ( const char * path ) ;
2003-07-19 07:08:00 +04:00
extern int sysfs_read_attribute ( struct sysfs_attribute * sysattr ) ;
2004-03-12 11:57:30 +03:00
extern int sysfs_read_attribute_value ( const char * attrpath ,
char * value , size_t vsize ) ;
2003-10-21 12:19:14 +04:00
extern int sysfs_write_attribute ( struct sysfs_attribute * sysattr ,
2004-03-12 11:57:30 +03:00
const char * new_value , size_t len ) ;
extern char * sysfs_get_value_from_attributes ( struct dlist * attr ,
const char * name ) ;
2004-01-15 09:21:38 +03:00
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 ) ;
2003-07-19 07:08:00 +04:00
extern void sysfs_close_directory ( struct sysfs_directory * sysdir ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_directory * sysfs_open_directory ( const char * path ) ;
2003-12-16 08:53:28 +03:00
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 ) ;
2003-07-19 07:08:00 +04:00
extern int sysfs_read_directory ( struct sysfs_directory * sysdir ) ;
2003-10-21 12:19:14 +04:00
extern int sysfs_read_all_subdirs ( struct sysfs_directory * sysdir ) ;
extern struct sysfs_directory * sysfs_get_subdirectory
2004-03-12 11:57:30 +03:00
( struct sysfs_directory * dir , char * subname ) ;
2003-10-21 12:19:14 +04:00
extern void sysfs_close_link ( struct sysfs_link * ln ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_link * sysfs_open_link ( const char * lnpath ) ;
extern struct sysfs_link * sysfs_get_directory_link
( struct sysfs_directory * dir , char * linkname ) ;
2003-10-21 12:19:14 +04:00
extern struct sysfs_link * sysfs_get_subdirectory_link
2004-03-12 11:57:30 +03:00
( struct sysfs_directory * dir , char * linkname ) ;
2003-10-21 12:19:14 +04:00
extern struct sysfs_attribute * sysfs_get_directory_attribute
2004-03-12 11:57:30 +03:00
( struct sysfs_directory * dir , char * attrname ) ;
2004-01-15 09:21:38 +03:00
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 ) ;
2003-07-19 07:08:00 +04:00
/* sysfs driver access */
extern void sysfs_close_driver ( struct sysfs_driver * driver ) ;
2003-12-20 05:29:10 +03:00
extern struct sysfs_driver * sysfs_open_driver
2004-03-12 11:57:30 +03:00
( const char * bus_name , const char * drv_name ) ;
extern struct sysfs_driver * sysfs_open_driver_path ( const char * path ) ;
2003-10-21 12:19:14 +04:00
extern struct sysfs_attribute * sysfs_get_driver_attr
2004-03-12 11:57:30 +03:00
( struct sysfs_driver * drv , const char * name ) ;
2003-10-21 12:19:14 +04:00
extern struct dlist * sysfs_get_driver_attributes ( struct sysfs_driver * driver ) ;
2003-12-16 08:53:28 +03:00
extern struct dlist * sysfs_get_driver_devices ( struct sysfs_driver * driver ) ;
2004-01-15 09:21:38 +03:00
extern struct dlist * sysfs_refresh_driver_devices ( struct sysfs_driver * driver ) ;
2003-10-21 12:19:14 +04:00
extern struct dlist * sysfs_get_driver_links ( struct sysfs_driver * driver ) ;
2003-12-16 08:53:28 +03:00
extern struct sysfs_device * sysfs_get_driver_device
2004-03-12 11:57:30 +03:00
( struct sysfs_driver * driver , const char * name ) ;
2004-01-15 09:21:38 +03:00
extern struct dlist * sysfs_refresh_driver_attributes
2004-03-12 11:57:30 +03:00
( struct sysfs_driver * driver ) ;
extern struct sysfs_attribute * sysfs_open_driver_attr
( const char * bus , const char * drv , const char * attrib ) ;
2003-07-19 07:08:00 +04:00
/* generic sysfs device access */
2003-10-21 12:19:14 +04:00
extern void sysfs_close_root_device ( struct sysfs_root_device * root ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_root_device * sysfs_open_root_device ( const char * name ) ;
2003-12-16 08:53:28 +03:00
extern struct dlist * sysfs_get_root_devices ( struct sysfs_root_device * root ) ;
2004-03-12 11:57:30 +03:00
extern void sysfs_close_device_tree ( struct sysfs_device * device ) ;
extern struct sysfs_device * sysfs_open_device_tree ( const char * path ) ;
2003-07-19 07:08:00 +04:00
extern void sysfs_close_device ( struct sysfs_device * dev ) ;
2003-12-20 05:29:10 +03:00
extern struct sysfs_device * sysfs_open_device
2004-03-12 11:57:30 +03:00
( const char * bus , const char * bus_id ) ;
2003-12-20 05:29:10 +03:00
extern struct sysfs_device * sysfs_get_device_parent ( struct sysfs_device * dev ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_device * sysfs_open_device_path ( const char * path ) ;
2004-01-15 09:21:38 +03:00
extern int sysfs_get_device_bus ( struct sysfs_device * dev ) ;
2003-07-19 07:08:00 +04:00
extern struct sysfs_attribute * sysfs_get_device_attr
2004-03-12 11:57:30 +03:00
( struct sysfs_device * dev , const char * name ) ;
2003-10-21 12:19:14 +04:00
extern struct dlist * sysfs_get_device_attributes ( struct sysfs_device * device ) ;
2004-01-15 09:21:38 +03:00
extern struct dlist * sysfs_refresh_device_attributes
2004-03-12 11:57:30 +03:00
( struct sysfs_device * device ) ;
extern struct sysfs_attribute * sysfs_open_device_attr ( const char * bus ,
const char * bus_id , const char * attrib ) ;
2003-07-19 07:08:00 +04:00
/* generic sysfs bus access */
extern void sysfs_close_bus ( struct sysfs_bus * bus ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_bus * sysfs_open_bus ( const char * name ) ;
extern struct sysfs_device * sysfs_get_bus_device ( struct sysfs_bus * bus ,
char * id ) ;
2003-10-21 12:19:14 +04:00
extern struct sysfs_driver * sysfs_get_bus_driver ( struct sysfs_bus * bus ,
2004-03-12 11:57:30 +03:00
char * drvname ) ;
2003-12-16 08:53:28 +03:00
extern struct dlist * sysfs_get_bus_drivers ( struct sysfs_bus * bus ) ;
extern struct dlist * sysfs_get_bus_devices ( struct sysfs_bus * bus ) ;
2003-10-21 12:19:14 +04:00
extern struct dlist * sysfs_get_bus_attributes ( struct sysfs_bus * bus ) ;
2004-01-15 09:21:38 +03:00
extern struct dlist * sysfs_refresh_bus_attributes ( struct sysfs_bus * bus ) ;
2004-03-12 11:57:30 +03:00
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 ) ;
2003-07-19 07:08:00 +04:00
/* generic sysfs class access */
extern void sysfs_close_class_device ( struct sysfs_class_device * dev ) ;
2003-12-20 05:29:10 +03:00
extern struct sysfs_class_device * sysfs_open_class_device_path
2004-03-12 11:57:30 +03:00
( const char * path ) ;
2003-12-20 05:29:10 +03:00
extern struct sysfs_class_device * sysfs_open_class_device
2004-03-12 11:57:30 +03:00
( const char * classname , const char * name ) ;
2003-12-16 08:53:28 +03:00
extern struct sysfs_device * sysfs_get_classdev_device
2004-03-12 11:57:30 +03:00
( struct sysfs_class_device * clsdev ) ;
2003-12-16 08:53:28 +03:00
extern struct sysfs_driver * sysfs_get_classdev_driver
2004-03-12 11:57:30 +03:00
( struct sysfs_class_device * clsdev ) ;
2003-12-16 08:53:28 +03:00
extern struct sysfs_class_device * sysfs_get_classdev_parent
2004-03-12 11:57:30 +03:00
( struct sysfs_class_device * clsdev ) ;
2003-07-19 07:08:00 +04:00
extern void sysfs_close_class ( struct sysfs_class * cls ) ;
2004-03-12 11:57:30 +03:00
extern struct sysfs_class * sysfs_open_class ( const char * name ) ;
2003-12-16 08:53:28 +03:00
extern struct dlist * sysfs_get_class_devices ( struct sysfs_class * cls ) ;
2003-10-21 12:19:14 +04:00
extern struct sysfs_class_device * sysfs_get_class_device
2004-03-12 11:57:30 +03:00
( struct sysfs_class * cls , char * name ) ;
2003-10-21 12:19:14 +04:00
extern struct dlist * sysfs_get_classdev_attributes
( struct sysfs_class_device * cdev ) ;
2004-01-15 09:21:38 +03:00
extern struct dlist * sysfs_refresh_classdev_attributes
( struct sysfs_class_device * cdev ) ;
2003-10-21 12:19:14 +04:00
extern struct sysfs_attribute * sysfs_get_classdev_attr
2004-03-12 11:57:30 +03:00
( struct sysfs_class_device * clsdev , const char * name ) ;
2003-11-25 10:47:43 +03:00
extern struct sysfs_attribute * sysfs_open_classdev_attr
2004-03-12 11:57:30 +03:00
( const char * classname , const char * dev ,
const char * attrib ) ;
/**
* sort_list : sorter function to keep list elements sorted in alphabetical
* order . Just does a strncmp as you can see : )
*
* Returns 1 if less than 0 otherwise
*
* NOTE : We take care to have a statically allocated " name " as the first
* lement of all libsysfs structures . Hence , this function will work
* AS IS for _ALL_ the lists that have to be sorted .
*/
static inline int sort_list ( void * new_elem , void * old_elem )
{
return ( ( strncmp ( ( ( struct sysfs_attribute * ) new_elem ) - > name ,
( ( struct sysfs_attribute * ) old_elem ) - > name ,
strlen ( ( ( struct sysfs_attribute * ) new_elem ) - > name ) ) ) < 0 ? 1 : 0 ) ;
}
2003-07-19 07:08:00 +04:00
# ifdef __cplusplus
}
# endif
# endif /* _LIBSYSFS_H_ */