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
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
# 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"
2007-07-15 21:10:06 +04:00
# define RULES_DYN_DIR ".udev / rules.d"
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 ] ;
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 ;
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 */
2007-03-17 12:08:25 +03:00
extern struct udevice * udev_device_init ( struct udevice * udev ) ;
2006-01-09 23:18:00 +03:00
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 ) ;
2007-06-03 02:01:46 +04:00
extern int sysfs_lookup_devpath_by_subsys_id ( 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 */
extern int udev_node_mknod ( struct udevice * udev , const char * file , dev_t devt , mode_t mode , uid_t uid , gid_t gid ) ;
priority based symlink handling
Symlinks can have priorities now, the priority is assigned to the device
and specified with OPTIONS="link_priority=100". Devices with higher
priorities overwrite the symlinks of devices with lower priorities.
If the device, that currently owns the link goes away, the symlink
will be removed, and recreated, pointing to the next device with the
highest actual priority.
This should solve the issue, that inserting an USB-stick may overwrite the
/dev/disk/by-id/-link of another disk, and removes the entire link after the
USB-stick is disconnected. If no priorities are specified, the new link will
overwrite the current one, and if the device goes away, it will restore
the old link. It should be possible to assign lower priorities to removable
devices, if needed.
In multipath setups, we see several devices, which all connect to the same
volume, and therefore all try to create the same metadata-links. The
different path-devices are combined into one device-mapper device, which also
contains the same metadata. It should be possible, to assign multipath-table
device-mapper devices a higher priority, so path-devices that appear and
disappear, will not overwrite or delete the device-mapper device links.
2007-03-18 14:51:57 +03:00
extern void udev_node_update_symlinks ( struct udevice * udev , struct udevice * udev_old ) ;
extern int udev_node_add ( 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 ) ;
2007-08-26 07:22:35 +04:00
extern int udev_db_rename ( const char * devpath_old , const char * devpath ) ;
2005-11-16 06:14:15 +03:00
extern int udev_db_get_device ( struct udevice * udev , const char * devpath ) ;
2007-03-17 12:08:25 +03:00
extern int udev_db_get_devices_by_name ( const char * name , struct list_head * name_list ) ;
2005-11-16 06:14:15 +03:00
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 ] ;
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 ) ;
2007-07-14 22:43:01 +04:00
extern struct name_entry * name_list_add ( struct list_head * name_list , const char * name , int sort ) ;
extern struct name_entry * name_list_key_add ( struct list_head * name_list , const char * key , const char * value ) ;
2007-04-25 03:52:00 +04:00
extern int name_list_key_remove ( struct list_head * name_list , const char * key ) ;
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 ) ;
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 */
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 ) ;
2007-11-08 19:51:59 +03:00
/* udev commands */
extern int udevmonitor ( int argc , char * argv [ ] , char * envp [ ] ) ;
extern int udevinfo ( int argc , char * argv [ ] , char * envp [ ] ) ;
extern int udevcontrol ( int argc , char * argv [ ] , char * envp [ ] ) ;
extern int udevtrigger ( int argc , char * argv [ ] , char * envp [ ] ) ;
extern int udevsettle ( int argc , char * argv [ ] , char * envp [ ] ) ;
extern int udevtest ( int argc , char * argv [ ] , char * envp [ ] ) ;
2005-04-27 07:59:47 +04:00
# endif