2005-04-27 07:59:47 +04:00
/*
* Copyright ( C ) 2003 Greg Kroah - Hartman < greg @ kroah . com >
2008-09-10 02:46:17 +04:00
* Copyright ( C ) 2003 - 2008 Kay Sievers < kay . sievers @ vrfy . org >
2005-04-27 07:59:47 +04:00
*
* This program is free software ; you can redistribute it and / or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 of the License .
*
* This program 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
* General Public License for more details .
*
* You should have received a copy of the GNU General Public License along
* with this program ; if not , write to the Free Software Foundation , Inc . ,
2006-08-28 02:29:11 +04:00
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2005-04-27 07:59:47 +04:00
*
*/
2004-03-23 09:22:20 +03:00
# ifndef _UDEV_H_
# define _UDEV_H_
2005-04-27 07:59:47 +04:00
2008-09-06 17:45:31 +04:00
# include "config.h"
2005-02-09 06:37:32 +03:00
# include <sys/types.h>
2003-12-02 11:26:46 +03:00
# include <sys/param.h>
2006-01-09 23:18:00 +03:00
2005-02-21 16:48:12 +03:00
# include "list.h"
2006-08-16 04:04:04 +04:00
# include "udev_sysdeps.h"
2008-09-06 17:45:31 +04:00
# define LIBUDEV_I_KNOW_THE_API_IS_SUBJECT_TO_CHANGE 1
# include "lib/libudev.h"
# include "lib/libudev-private.h"
2005-04-27 07:59:47 +04:00
2006-01-16 08:12:49 +03:00
# define COMMENT_CHARACTER '#'
# define LINE_SIZE 512
2006-07-06 15:49:43 +04:00
# define PATH_SIZE 512
2007-05-16 21:51:13 +04:00
# define NAME_SIZE 256
2006-01-16 08:12:49 +03:00
# define VALUE_SIZE 128
2004-02-27 06:40:32 +03:00
2007-05-21 09:59:40 +04:00
# define ALLOWED_CHARS "#+-.:=@_"
2007-05-17 22:01:54 +04:00
# define ALLOWED_CHARS_FILE ALLOWED_CHARS " / "
2007-05-21 09:59:40 +04:00
# define ALLOWED_CHARS_INPUT ALLOWED_CHARS_FILE " $%?,"
2007-05-17 22:01:54 +04:00
2006-01-16 08:12:49 +03:00
# define DEFAULT_PARTITIONS_COUNT 15
2008-04-21 21:00:54 +04:00
# define UDEV_EVENT_TIMEOUT 180
2005-02-09 10:43:18 +03:00
2008-09-08 19:59:00 +04:00
/* linux/include/linux/kobject.h */
# define UEVENT_BUFFER_SIZE 2048
# define UEVENT_NUM_ENVP 32
# define UDEV_CTRL_SOCK_PATH "@" UDEV_PREFIX " / org / kernel / udev / udevd"
2006-01-09 23:18:00 +03:00
# define UDEV_MAX(a,b) ((a) > (b) ? (a) : (b))
/* pipes */
2006-01-16 08:12:49 +03:00
# define READ_END 0
# define WRITE_END 1
2006-01-09 23:18:00 +03:00
2005-07-22 20:35:58 +04:00
struct udev_rules ;
2006-01-09 23:18:00 +03:00
struct sysfs_device {
2006-01-16 08:12:49 +03:00
struct list_head node ; /* for device cache */
2006-01-29 04:09:35 +03:00
struct sysfs_device * parent ; /* already cached parent*/
2006-01-09 23:18:00 +03:00
char devpath [ PATH_SIZE ] ;
2006-08-19 18:06:25 +04:00
char subsystem [ NAME_SIZE ] ; /* $class, $bus, drivers, module */
char kernel [ NAME_SIZE ] ; /* device instance name */
2006-01-09 23:18:00 +03:00
char kernel_number [ NAME_SIZE ] ;
2006-01-16 08:12:49 +03:00
char driver [ NAME_SIZE ] ; /* device driver name */
2005-02-21 15:45:04 +03:00
} ;
2003-10-21 09:48:44 +04:00
struct udevice {
2008-09-06 17:45:31 +04:00
struct udev * udev ;
2006-01-09 23:18:00 +03:00
/* device event */
2006-01-16 08:12:49 +03:00
struct sysfs_device * dev ; /* points to dev_local by default */
2006-01-09 23:18:00 +03:00
struct sysfs_device dev_local ;
2006-01-16 08:12:49 +03:00
struct sysfs_device * dev_parent ; /* current parent device used for matching */
2005-04-02 19:45:35 +04:00
char action [ NAME_SIZE ] ;
2007-08-26 07:22:35 +04:00
char * devpath_old ;
2004-11-29 04:15:55 +03:00
2006-01-09 23:18:00 +03:00
/* node */
2005-03-07 06:29:43 +03:00
char name [ PATH_SIZE ] ;
2005-03-05 07:35:31 +03:00
struct list_head symlink_list ;
2005-06-05 06:57:03 +04:00
int symlink_final ;
2006-07-06 15:49:43 +04:00
char owner [ NAME_SIZE ] ;
2005-06-05 06:57:03 +04:00
int owner_final ;
2006-07-06 15:49:43 +04:00
char group [ NAME_SIZE ] ;
2005-06-05 06:57:03 +04:00
int group_final ;
2004-11-29 04:15:55 +03:00
mode_t mode ;
2005-06-05 06:57:03 +04:00
int mode_final ;
2005-02-21 15:44:39 +03:00
dev_t devt ;
2006-01-09 23:18:00 +03:00
/* event processing */
2005-04-02 19:45:35 +04:00
struct list_head run_list ;
2005-06-05 06:57:03 +04:00
int run_final ;
2005-06-26 20:55:24 +04:00
struct list_head env_list ;
2005-03-07 06:29:43 +03:00
char tmp_node [ PATH_SIZE ] ;
2004-02-17 08:44:28 +03:00
int partitions ;
2005-04-02 19:45:35 +04:00
int ignore_device ;
2004-11-13 16:43:24 +03:00
int ignore_remove ;
2005-03-07 06:29:43 +03:00
char program_result [ PATH_SIZE ] ;
2007-03-16 17:16:08 +03:00
int link_priority ;
2008-04-21 21:00:54 +04:00
int event_timeout ;
2004-10-19 06:11:51 +04:00
int test_run ;
2003-10-21 09:48:44 +04:00
} ;
2008-09-06 17:45:31 +04:00
static inline void logging_init ( const char * program_name )
{
openlog ( program_name , LOG_PID | LOG_CONS , LOG_DAEMON ) ;
}
static inline void logging_msg ( struct udev * udev , int priority ,
const char * file , int line , const char * fn ,
const char * format , va_list args )
{
vsyslog ( priority , format , args ) ;
}
static inline void logging_close ( void )
{
closelog ( ) ;
}
2006-01-09 23:18:00 +03:00
/* udev_device.c */
2008-09-06 17:45:31 +04:00
extern struct udevice * udev_device_init ( struct udev * udev ) ;
extern void udev_device_cleanup ( struct udevice * udevice ) ;
extern dev_t udev_device_get_devt ( struct udevice * udevice ) ;
2006-01-09 23:18:00 +03:00
2008-08-29 22:32:05 +04:00
/* udev_device_event.c */
2008-09-06 17:45:31 +04:00
extern int udev_device_event ( struct udev_rules * rules , struct udevice * udevice ) ;
2008-08-29 22:32:05 +04:00
2006-01-09 23:18:00 +03:00
/* udev_sysfs.c */
extern int sysfs_init ( void ) ;
extern void sysfs_cleanup ( void ) ;
2008-09-06 17:45:31 +04:00
extern void sysfs_device_set_values ( struct udev * udev ,
struct sysfs_device * dev , const char * devpath ,
2006-08-13 07:32:09 +04:00
const char * subsystem , const char * driver ) ;
2008-09-06 17:45:31 +04:00
extern struct sysfs_device * sysfs_device_get ( struct udev * udev , const char * devpath ) ;
extern struct sysfs_device * sysfs_device_get_parent ( struct udev * udev , struct sysfs_device * dev ) ;
extern struct sysfs_device * sysfs_device_get_parent_with_subsystem ( struct udev * udev , struct sysfs_device * dev , const char * subsystem ) ;
extern char * sysfs_attr_get_value ( struct udev * udev , const char * devpath , const char * attr_name ) ;
extern int sysfs_resolve_link ( struct udev * udev , char * path , size_t size ) ;
extern int sysfs_lookup_devpath_by_subsys_id ( struct udev * udev , char * devpath , size_t len , const char * subsystem , const char * id ) ;
2006-01-09 23:18:00 +03:00
2006-04-06 00:29:33 +04:00
/* udev_node.c */
2008-09-06 17:45:31 +04:00
extern int udev_node_mknod ( struct udevice * udevice , const char * file , dev_t devt , mode_t mode , uid_t uid , gid_t gid ) ;
extern void udev_node_update_symlinks ( struct udevice * udevice , struct udevice * udev_old ) ;
extern int udev_node_add ( struct udevice * udevice ) ;
extern int udev_node_remove ( struct udevice * udevice ) ;
2003-04-11 07:04:38 +04:00
2006-01-09 23:18:00 +03:00
/* udev_db.c */
2008-09-06 17:45:31 +04:00
extern int udev_db_add_device ( struct udevice * udevice ) ;
extern int udev_db_delete_device ( struct udevice * udevice ) ;
extern int udev_db_rename ( struct udev * udev , const char * devpath_old , const char * devpath ) ;
extern int udev_db_get_device ( struct udevice * udevice , const char * devpath ) ;
extern int udev_db_get_devices_by_name ( struct udev * udev , const char * name , struct list_head * name_list ) ;
extern int udev_db_get_all_entries ( struct udev * udevconst , struct list_head * name_list ) ;
2005-11-16 06:14:15 +03:00
2006-01-09 23:18:00 +03:00
/* udev_utils.c */
struct name_entry {
struct list_head node ;
char name [ PATH_SIZE ] ;
2007-07-14 22:43:01 +04:00
unsigned int ignore_error : 1 ;
2006-01-09 23:18:00 +03:00
} ;
2007-07-14 22:43:01 +04:00
2006-01-09 23:18:00 +03:00
extern int log_priority ( const char * priority ) ;
2008-09-06 17:45:31 +04:00
extern struct name_entry * name_list_add ( struct udev * udev , struct list_head * name_list , const char * name , int sort ) ;
extern struct name_entry * name_list_key_add ( struct udev * udev , struct list_head * name_list , const char * key , const char * value ) ;
extern int name_list_key_remove ( struct udev * udev , struct list_head * name_list , const char * key ) ;
extern void name_list_cleanup ( struct udev * udev , struct list_head * name_list ) ;
extern int add_matching_files ( struct udev * udev , struct list_head * name_list , const char * dirname , const char * suffix ) ;
extern uid_t lookup_user ( struct udev * udev , const char * user ) ;
extern gid_t lookup_group ( struct udev * udev , const char * group ) ;
2006-01-09 23:18:00 +03:00
/* udev_utils_string.c */
extern int string_is_true ( const char * str ) ;
extern void remove_trailing_chars ( char * path , char c ) ;
2007-03-14 23:41:33 +03:00
extern size_t path_encode ( char * s , size_t len ) ;
extern size_t path_decode ( char * s ) ;
2006-01-09 23:18:00 +03:00
extern int utf8_encoded_valid_unichar ( const char * str ) ;
2007-05-17 22:01:54 +04:00
extern int replace_chars ( char * str , const char * white ) ;
2006-01-09 23:18:00 +03:00
/* udev_utils_file.c */
2008-09-06 17:45:31 +04:00
extern int create_path ( struct udev * udev , const char * path ) ;
extern int delete_path ( struct udev * udev , const char * path ) ;
extern int unlink_secure ( struct udev * udev , const char * filename ) ;
2006-01-09 23:18:00 +03:00
extern int file_map ( const char * filename , char * * buf , size_t * bufsize ) ;
extern void file_unmap ( void * buf , size_t bufsize ) ;
extern size_t buf_get_line ( const char * buf , size_t buflen , size_t cur ) ;
2008-09-04 01:38:32 +04:00
/* udevadm commands */
2008-09-06 17:45:31 +04:00
extern int udevadm_monitor ( struct udev * udev , int argc , char * argv [ ] ) ;
extern int udevadm_info ( struct udev * udev , int argc , char * argv [ ] ) ;
extern int udevadm_control ( struct udev * udev , int argc , char * argv [ ] ) ;
extern int udevadm_trigger ( struct udev * udev , int argc , char * argv [ ] ) ;
extern int udevadm_settle ( struct udev * udev , int argc , char * argv [ ] ) ;
extern int udevadm_test ( struct udev * udev , int argc , char * argv [ ] ) ;
2007-11-08 19:51:59 +03:00
2005-04-27 07:59:47 +04:00
# endif