2005-04-27 07:59:47 +04:00
/*
* Copyright ( C ) 2003 Greg Kroah - Hartman < greg @ kroah . com >
2006-08-28 02:29:11 +04:00
* Copyright ( C ) 2003 - 2006 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
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-01-09 23:18:00 +03:00
# include "logging.h"
2006-08-16 04:04:04 +04:00
# include "udev_sysdeps.h"
2006-01-09 23:18:00 +03:00
# include "udev_version.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
2006-01-16 08:12:49 +03:00
# define NAME_SIZE 128
# define VALUE_SIZE 128
2004-02-27 06:40:32 +03:00
2006-01-16 08:12:49 +03:00
# define DEFAULT_PARTITIONS_COUNT 15
# define UDEV_ALARM_TIMEOUT 180
2005-02-09 10:43:18 +03:00
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
2006-01-16 08:12:49 +03:00
# define DB_DIR ".udev / db"
2007-03-15 04:09:39 +03:00
# define DB_NAME_INDEX_DIR ".udev / names"
2005-11-16 06:14:15 +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 {
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 ] ;
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 ;
2004-10-19 06:11:51 +04:00
int test_run ;
2003-10-21 09:48:44 +04:00
} ;
2006-01-09 23:18:00 +03:00
/* udev_config.c */
extern char udev_root [ PATH_SIZE ] ;
extern char udev_config_filename [ PATH_SIZE ] ;
2006-12-08 11:48:53 +03:00
extern char udev_rules_dir [ PATH_SIZE ] ;
2006-01-09 23:18:00 +03:00
extern int udev_log_priority ;
extern int udev_run ;
extern void udev_config_init ( void ) ;
/* udev_device.c */
extern struct udevice * udev_device_init ( void ) ;
extern void udev_device_cleanup ( struct udevice * udev ) ;
extern int udev_device_event ( struct udev_rules * rules , struct udevice * udev ) ;
extern dev_t udev_device_get_devt ( struct udevice * udev ) ;
/* udev_sysfs.c */
extern char sysfs_path [ PATH_SIZE ] ;
extern int sysfs_init ( void ) ;
extern void sysfs_cleanup ( void ) ;
2006-08-13 07:32:09 +04:00
extern void sysfs_device_set_values ( struct sysfs_device * dev , const char * devpath ,
const char * subsystem , const char * driver ) ;
2006-01-09 23:18:00 +03:00
extern struct sysfs_device * sysfs_device_get ( const char * devpath ) ;
extern struct sysfs_device * sysfs_device_get_parent ( struct sysfs_device * dev ) ;
2006-01-18 06:24:48 +03:00
extern struct sysfs_device * sysfs_device_get_parent_with_subsystem ( struct sysfs_device * dev , const char * subsystem ) ;
2006-01-09 23:18:00 +03:00
extern char * sysfs_attr_get_value ( const char * devpath , const char * attr_name ) ;
2006-09-19 19:46:04 +04:00
extern int sysfs_resolve_link ( char * path , size_t size ) ;
2006-01-09 23:18:00 +03:00
2006-04-06 00:29:33 +04:00
/* udev_node.c */
extern int udev_node_mknod ( struct udevice * udev , const char * file , dev_t devt , mode_t mode , uid_t uid , gid_t gid ) ;
2006-04-13 00:08:05 +04:00
extern int udev_node_add ( struct udevice * udev , struct udevice * udev_old ) ;
extern void udev_node_remove_symlinks ( struct udevice * udev ) ;
2006-04-06 00:29:33 +04:00
extern int udev_node_remove ( struct udevice * udev ) ;
2003-04-11 07:04:38 +04:00
2006-01-09 23:18:00 +03:00
/* udev_db.c */
2005-11-16 06:14:15 +03:00
extern int udev_db_add_device ( struct udevice * dev ) ;
extern int udev_db_delete_device ( struct udevice * dev ) ;
extern int udev_db_get_device ( struct udevice * udev , const char * devpath ) ;
extern int udev_db_lookup_name ( const char * name , char * devpath , size_t len ) ;
extern int udev_db_get_all_entries ( struct list_head * name_list ) ;
2006-01-09 23:18:00 +03:00
/* udev_utils.c */
struct name_entry {
struct list_head node ;
char name [ PATH_SIZE ] ;
} ;
extern int log_priority ( const char * priority ) ;
2006-04-15 21:32:05 +04:00
extern char * name_list_add ( struct list_head * name_list , const char * name , int sort ) ;
extern char * name_list_key_add ( struct list_head * name_list , const char * key , const char * value ) ;
2006-01-09 23:18:00 +03:00
extern void name_list_cleanup ( struct list_head * name_list ) ;
extern int add_matching_files ( struct list_head * name_list , const char * dirname , const char * suffix ) ;
2006-08-20 20:25:57 +04:00
extern uid_t lookup_user ( const char * user ) ;
extern gid_t lookup_group ( 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 ) ;
extern int replace_untrusted_chars ( char * str ) ;
/* udev_utils_file.c */
extern int create_path ( const char * path ) ;
extern int delete_path ( const char * path ) ;
extern int file_map ( const char * filename , char * * buf , size_t * bufsize ) ;
extern void file_unmap ( void * buf , size_t bufsize ) ;
extern int unlink_secure ( const char * filename ) ;
extern size_t buf_get_line ( const char * buf , size_t buflen , size_t cur ) ;
/* udev_utils_run.c */
extern int pass_env_to_socket ( const char * name , const char * devpath , const char * action ) ;
extern int run_program ( const char * command , const char * subsystem ,
char * result , size_t ressize , size_t * reslen , int log ) ;
2003-10-22 07:19:09 +04:00
2005-04-27 07:59:47 +04:00
# endif