2004-01-20 06:46:26 +03:00
/*
2009-08-01 17:39:18 +04:00
* Copyright ( C ) 2004 - 2009 Kay Sievers < kay . sievers @ vrfy . org >
2004-01-20 06:46:26 +03:00
*
2008-09-10 04:40:42 +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 , either version 2 of the License , or
* ( at your option ) any later version .
2004-01-20 06:46:26 +03:00
*
2008-09-10 04:40:42 +04:00
* 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 , see < http : //www.gnu.org/licenses/>.
2004-01-20 06:46:26 +03:00
*/
# include <stdlib.h>
# include <string.h>
# include <stdio.h>
2006-01-09 23:18:00 +03:00
# include <stddef.h>
2004-01-23 14:01:02 +03:00
# include <ctype.h>
2004-01-27 05:20:12 +03:00
# include <stdarg.h>
# include <unistd.h>
2006-01-09 23:18:00 +03:00
# include <dirent.h>
2004-01-27 05:20:12 +03:00
# include <errno.h>
2006-09-03 06:05:20 +04:00
# include <getopt.h>
2009-05-20 20:58:52 +04:00
# include <fcntl.h>
2006-09-05 15:54:08 +04:00
# include <sys/stat.h>
# include <sys/types.h>
2004-01-20 06:46:26 +03:00
2004-01-27 05:55:37 +03:00
# include "udev.h"
2004-01-20 06:46:26 +03:00
2011-03-05 01:00:52 +03:00
static bool skip_attribute ( const char * name )
{
2011-03-08 11:57:17 +03:00
static const char const * skip [ ] = {
2011-03-05 01:00:52 +03:00
" uevent " ,
" dev " ,
" modalias " ,
" resource " ,
" driver " ,
" subsystem " ,
" module " ,
} ;
unsigned int i ;
for ( i = 0 ; i < ARRAY_SIZE ( skip ) ; i + + )
if ( strcmp ( name , skip [ i ] ) = = 0 )
return true ;
return false ;
}
2008-09-13 23:09:28 +04:00
static void print_all_attributes ( struct udev_device * device , const char * key )
2004-01-20 06:46:26 +03:00
{
2011-03-04 19:06:43 +03:00
struct udev_list_entry * sysattr ;
2006-01-09 23:18:00 +03:00
2011-03-04 19:06:43 +03:00
udev_list_entry_foreach ( sysattr , udev_device_get_sysattr_list_entry ( device ) ) {
2011-03-05 01:00:52 +03:00
struct udev * udev = udev_device_get_udev ( device ) ;
2011-03-04 19:06:43 +03:00
const char * name ;
const char * value ;
size_t len ;
2006-01-09 23:18:00 +03:00
2011-03-04 19:06:43 +03:00
name = udev_list_entry_get_name ( sysattr ) ;
2011-03-05 01:00:52 +03:00
if ( skip_attribute ( name ) )
2011-03-04 19:06:43 +03:00
continue ;
2007-10-24 18:51:33 +04:00
2011-03-04 19:06:43 +03:00
value = udev_device_get_sysattr_value ( device , name ) ;
if ( value = = NULL )
continue ;
2011-03-05 01:00:52 +03:00
dbg ( udev , " attr '%s'='%s' \n " , name , value ) ;
2006-09-05 15:54:08 +04:00
2011-03-04 19:06:43 +03:00
/* skip nonprintable attributes */
len = strlen ( value ) ;
while ( len > 0 & & isprint ( value [ len - 1 ] ) )
len - - ;
if ( len > 0 ) {
2011-03-05 01:00:52 +03:00
dbg ( udev , " attribute value of '%s' non-printable, skip \n " , name ) ;
2011-03-04 19:06:43 +03:00
continue ;
2005-03-27 03:29:10 +04:00
}
2011-03-04 19:06:43 +03:00
printf ( " %s{%s}== \" %s \" \n " , key , name , value ) ;
2004-01-20 06:46:26 +03:00
}
printf ( " \n " ) ;
}
2008-09-13 23:09:28 +04:00
static int print_device_chain ( struct udev_device * device )
2004-01-27 05:20:12 +03:00
{
2008-09-12 02:58:40 +04:00
struct udev_device * device_parent ;
2008-09-11 19:08:12 +04:00
const char * str ;
2005-03-05 07:35:31 +03:00
2006-01-09 23:18:00 +03:00
printf ( " \n "
2009-01-05 14:28:09 +03:00
" Udevadm info starts with the device specified by the devpath and then \n "
2006-06-16 13:11:07 +04:00
" walks up the chain of parent devices. It prints for every device \n "
" found, all possible attributes in the udev rules key format. \n "
" A rule to match, can be composed by the attributes of the device \n "
" and the attributes from one single parent device. \n "
2004-03-02 11:08:28 +03:00
" \n " ) ;
[PATCH] hmm, handle net devices with udev?
Hmm, Arndt Bergmann sent a patch like this one a few weeks ago and
I want to bring the question back, if we want to handle net device
naming with udev.
With this patch it is actually possible to specify something like this
in udev.rules:
KERNEL="dummy*", SYSFS{address}="00:00:00:00:00:00", SYSFS{features}="0x0", NAME="blind%n"
KERNEL="eth*", SYSFS{address}="00:0d:60:77:30:91", NAME="private"
and you will get:
[root@pim udev.kay]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 1500 30 0 0 0 0 0 0 1500 30 0 0 0 0 0 0
private: 278393 1114 0 0 0 0 0 0 153204 1468 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
blind0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
The udevinfo program is also working:
[root@pim udev.kay]# ./udevinfo -a -p /sys/class/net/private
looking at class device '/sys/class/net/private':
SYSFS{addr_len}="6"
SYSFS{address}="00:0d:60:77:30:91"
SYSFS{broadcast}="ff:ff:ff:ff:ff:ff"
SYSFS{features}="0x3a9"
SYSFS{flags}="0x1003"
SYSFS{ifindex}="2"
SYSFS{iflink}="2"
SYSFS{mtu}="1500"
SYSFS{tx_queue_len}="1000"
SYSFS{type}="1"
follow the class device's "device"
looking at the device chain at '/sys/devices/pci0000:00/0000:00:1e.0/0000:02:01.0':
BUS="pci"
ID="0000:02:01.0"
SYSFS{class}="0x020000"
SYSFS{detach_state}="0"
SYSFS{device}="0x101e"
SYSFS{irq}="11"
SYSFS{subsystem_device}="0x0549"
SYSFS{subsystem_vendor}="0x1014"
SYSFS{vendor}="0x8086"
The matching device will be renamed to the given name. The device name
will not be put into the udev database, cause the kernel renames the
device and the sysfs name disappears.
I like it, cause it plugs in nicely. We have all the naming features
and sysfs queries and walks inside of udev. The sysfs timing races
are already solved and the management tools are working for net devices
too. nameif can only match the MAC address now. udev can match any sysfs
value of the device tree the net device is connected to.
But right, net devices do not have device nodes :)
2004-03-25 10:19:39 +03:00
2008-09-11 19:08:12 +04:00
printf ( " looking at device '%s': \n " , udev_device_get_devpath ( device ) ) ;
printf ( " KERNEL== \" %s \" \n " , udev_device_get_sysname ( device ) ) ;
str = udev_device_get_subsystem ( device ) ;
if ( str = = NULL )
str = " " ;
printf ( " SUBSYSTEM== \" %s \" \n " , str ) ;
str = udev_device_get_driver ( device ) ;
if ( str = = NULL )
str = " " ;
printf ( " DRIVER== \" %s \" \n " , str ) ;
2008-09-13 23:09:28 +04:00
print_all_attributes ( device , " ATTR " ) ;
2008-09-11 19:08:12 +04:00
2008-09-12 02:58:40 +04:00
device_parent = device ;
do {
device_parent = udev_device_get_parent ( device_parent ) ;
2008-09-11 19:08:12 +04:00
if ( device_parent = = NULL )
2004-01-23 14:01:02 +03:00
break ;
2008-09-12 02:58:40 +04:00
printf ( " looking at parent device '%s': \n " , udev_device_get_devpath ( device_parent ) ) ;
printf ( " KERNELS== \" %s \" \n " , udev_device_get_sysname ( device_parent ) ) ;
str = udev_device_get_subsystem ( device_parent ) ;
2008-09-11 19:08:12 +04:00
if ( str = = NULL )
str = " " ;
printf ( " SUBSYSTEMS== \" %s \" \n " , str ) ;
2008-09-12 02:58:40 +04:00
str = udev_device_get_driver ( device_parent ) ;
2008-09-11 19:08:12 +04:00
if ( str = = NULL )
str = " " ;
printf ( " DRIVERS== \" %s \" \n " , str ) ;
2008-09-13 23:09:28 +04:00
print_all_attributes ( device_parent , " ATTRS " ) ;
2008-09-12 02:58:40 +04:00
} while ( device_parent ! = NULL ) ;
2004-01-20 06:46:26 +03:00
2006-01-09 23:18:00 +03:00
return 0 ;
}
2008-09-13 23:09:28 +04:00
static void print_record ( struct udev_device * device )
2007-03-17 12:08:25 +03:00
{
2008-09-13 23:09:28 +04:00
size_t len ;
2008-10-03 12:33:15 +04:00
const char * str ;
2008-09-13 23:09:28 +04:00
int i ;
2008-09-28 03:34:55 +04:00
struct udev_list_entry * list_entry ;
2008-09-13 23:09:28 +04:00
printf ( " P: %s \n " , udev_device_get_devpath ( device ) ) ;
2008-09-25 15:20:27 +04:00
2008-09-13 23:09:28 +04:00
len = strlen ( udev_get_dev_path ( udev_device_get_udev ( device ) ) ) ;
2008-10-03 12:33:15 +04:00
str = udev_device_get_devnode ( device ) ;
if ( str ! = NULL )
printf ( " N: %s \n " , & str [ len + 1 ] ) ;
2008-09-25 15:20:27 +04:00
2008-10-16 19:16:58 +04:00
i = udev_device_get_devlink_priority ( device ) ;
2008-09-13 23:09:28 +04:00
if ( i ! = 0 )
printf ( " L: %i \n " , i ) ;
2008-09-25 15:20:27 +04:00
2008-09-28 03:34:55 +04:00
udev_list_entry_foreach ( list_entry , udev_device_get_devlinks_list_entry ( device ) ) {
2008-09-25 15:20:27 +04:00
len = strlen ( udev_get_dev_path ( udev_device_get_udev ( device ) ) ) ;
2008-09-28 03:34:55 +04:00
printf ( " S: %s \n " , & udev_list_entry_get_name ( list_entry ) [ len + 1 ] ) ;
2007-03-17 12:08:25 +03:00
}
2008-09-13 23:09:28 +04:00
2008-09-28 03:34:55 +04:00
udev_list_entry_foreach ( list_entry , udev_device_get_properties_list_entry ( device ) )
printf ( " E: %s=%s \n " ,
udev_list_entry_get_name ( list_entry ) ,
udev_list_entry_get_value ( list_entry ) ) ;
2008-09-25 15:20:27 +04:00
printf ( " \n " ) ;
2007-03-17 12:08:25 +03:00
}
2010-12-09 23:10:30 +03:00
static int stat_device ( const char * name , bool export , const char * prefix )
2007-11-09 12:22:30 +03:00
{
struct stat statbuf ;
if ( stat ( name , & statbuf ) ! = 0 )
return - 1 ;
2008-07-15 13:54:18 +04:00
if ( export ) {
if ( prefix = = NULL )
prefix = " INFO_ " ;
printf ( " %sMAJOR=%d \n "
" %sMINOR=%d \n " ,
prefix , major ( statbuf . st_dev ) ,
prefix , minor ( statbuf . st_dev ) ) ;
} else
2008-09-03 21:50:36 +04:00
printf ( " %d:%d \n " , major ( statbuf . st_dev ) , minor ( statbuf . st_dev ) ) ;
2007-11-09 12:22:30 +03:00
return 0 ;
}
2008-09-25 15:20:27 +04:00
static int export_devices ( struct udev * udev )
{
2008-09-29 04:00:17 +04:00
struct udev_enumerate * udev_enumerate ;
2008-09-28 03:34:55 +04:00
struct udev_list_entry * list_entry ;
2008-09-25 15:20:27 +04:00
2008-09-29 04:00:17 +04:00
udev_enumerate = udev_enumerate_new ( udev ) ;
if ( udev_enumerate = = NULL )
2008-09-25 15:20:27 +04:00
return - 1 ;
2008-09-30 15:42:26 +04:00
udev_enumerate_scan_devices ( udev_enumerate ) ;
2008-09-29 04:00:17 +04:00
udev_list_entry_foreach ( list_entry , udev_enumerate_get_list_entry ( udev_enumerate ) ) {
2008-09-25 15:20:27 +04:00
struct udev_device * device ;
2008-09-28 03:34:55 +04:00
device = udev_device_new_from_syspath ( udev , udev_list_entry_get_name ( list_entry ) ) ;
2008-09-25 15:20:27 +04:00
if ( device ! = NULL ) {
2009-02-27 00:59:40 +03:00
print_record ( device ) ;
2008-09-25 15:20:27 +04:00
udev_device_unref ( device ) ;
}
}
2008-09-29 04:00:17 +04:00
udev_enumerate_unref ( udev_enumerate ) ;
2008-09-25 15:20:27 +04:00
return 0 ;
}
2011-04-14 00:33:01 +04:00
static void cleanup_dir ( DIR * dir , mode_t mask , int depth )
{
struct dirent * dent ;
if ( depth < = 0 )
return ;
for ( dent = readdir ( dir ) ; dent ! = NULL ; dent = readdir ( dir ) ) {
struct stat stats ;
if ( dent - > d_name [ 0 ] = = ' . ' )
continue ;
if ( fstatat ( dirfd ( dir ) , dent - > d_name , & stats , AT_SYMLINK_NOFOLLOW ) ! = 0 )
continue ;
if ( ( stats . st_mode & mask ) ! = 0 )
continue ;
if ( S_ISDIR ( stats . st_mode ) ) {
DIR * dir2 ;
dir2 = fdopendir ( openat ( dirfd ( dir ) , dent - > d_name , O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC ) ) ;
if ( dir2 ! = NULL ) {
cleanup_dir ( dir2 , mask , depth - 1 ) ;
closedir ( dir2 ) ;
}
unlinkat ( dirfd ( dir ) , dent - > d_name , AT_REMOVEDIR ) ;
} else {
unlinkat ( dirfd ( dir ) , dent - > d_name , 0 ) ;
}
}
}
static void cleanup_db ( struct udev * udev )
{
char filename [ UTIL_PATH_SIZE ] ;
DIR * dir ;
util_strscpyl ( filename , sizeof ( filename ) , udev_get_run_path ( udev ) , " /queue.bin " , NULL ) ;
unlink ( filename ) ;
util_strscpyl ( filename , sizeof ( filename ) , udev_get_run_path ( udev ) , " /data " , NULL ) ;
dir = opendir ( filename ) ;
if ( dir ! = NULL ) {
cleanup_dir ( dir , S_ISVTX , 1 ) ;
closedir ( dir ) ;
}
util_strscpyl ( filename , sizeof ( filename ) , udev_get_run_path ( udev ) , " /links " , NULL ) ;
dir = opendir ( filename ) ;
if ( dir ! = NULL ) {
cleanup_dir ( dir , 0 , 2 ) ;
closedir ( dir ) ;
}
util_strscpyl ( filename , sizeof ( filename ) , udev_get_run_path ( udev ) , " /tags " , NULL ) ;
dir = opendir ( filename ) ;
if ( dir ! = NULL ) {
cleanup_dir ( dir , 0 , 2 ) ;
closedir ( dir ) ;
}
util_strscpyl ( filename , sizeof ( filename ) , udev_get_run_path ( udev ) , " /watch " , NULL ) ;
dir = opendir ( filename ) ;
if ( dir ! = NULL ) {
cleanup_dir ( dir , 0 , 1 ) ;
closedir ( dir ) ;
}
util_strscpyl ( filename , sizeof ( filename ) , udev_get_run_path ( udev ) , " /firmware-missing " , NULL ) ;
dir = opendir ( filename ) ;
if ( dir ! = NULL ) {
cleanup_dir ( dir , 0 , 1 ) ;
closedir ( dir ) ;
}
}
2011-07-14 03:53:23 +04:00
static int uinfo ( struct udev * udev , int argc , char * argv [ ] )
2004-01-27 05:20:12 +03:00
{
2008-09-13 23:09:28 +04:00
struct udev_device * device = NULL ;
2010-12-09 23:10:30 +03:00
bool root = 0 ;
bool export = 0 ;
2008-07-15 13:54:18 +04:00
const char * export_prefix = NULL ;
2008-09-13 23:09:28 +04:00
char path [ UTIL_PATH_SIZE ] ;
char name [ UTIL_PATH_SIZE ] ;
2008-09-28 03:34:55 +04:00
struct udev_list_entry * list_entry ;
2008-09-13 23:09:28 +04:00
int rc = 0 ;
2005-08-29 17:01:08 +04:00
2006-09-03 16:12:51 +04:00
static const struct option options [ ] = {
2008-10-02 18:49:05 +04:00
{ " name " , required_argument , NULL , ' n ' } ,
{ " path " , required_argument , NULL , ' p ' } ,
2009-06-10 17:55:24 +04:00
{ " query " , required_argument , NULL , ' q ' } ,
2008-10-02 18:49:05 +04:00
{ " attribute-walk " , no_argument , NULL , ' a ' } ,
2011-04-14 00:33:01 +04:00
{ " cleanup-db " , no_argument , NULL , ' c ' } ,
2008-10-02 18:49:05 +04:00
{ " export-db " , no_argument , NULL , ' e ' } ,
{ " root " , no_argument , NULL , ' r ' } ,
2011-03-23 04:31:09 +03:00
{ " run " , no_argument , NULL , ' R ' } ,
2008-10-02 18:49:05 +04:00
{ " device-id-of-file " , required_argument , NULL , ' d ' } ,
{ " export " , no_argument , NULL , ' x ' } ,
{ " export-prefix " , required_argument , NULL , ' P ' } ,
2008-11-13 09:31:04 +03:00
{ " version " , no_argument , NULL , ' V ' } ,
2008-10-02 18:49:05 +04:00
{ " help " , no_argument , NULL , ' h ' } ,
2006-09-03 06:05:20 +04:00
{ }
} ;
2005-08-29 17:01:08 +04:00
enum action_type {
ACTION_NONE ,
ACTION_QUERY ,
ACTION_ATTRIBUTE_WALK ,
ACTION_ROOT ,
2007-11-09 12:22:30 +03:00
ACTION_DEVICE_ID_FILE ,
2005-08-29 17:01:08 +04:00
} action = ACTION_NONE ;
2005-06-26 20:55:24 +04:00
enum query_type {
QUERY_NONE ,
QUERY_NAME ,
QUERY_PATH ,
QUERY_SYMLINK ,
2009-06-07 04:39:54 +04:00
QUERY_PROPERTY ,
2005-06-26 20:55:24 +04:00
QUERY_ALL ,
} query = QUERY_NONE ;
2005-08-29 17:01:08 +04:00
2010-05-27 17:11:00 +04:00
for ( ; ; ) {
2008-09-06 17:45:31 +04:00
int option ;
2008-09-25 15:20:27 +04:00
struct stat statbuf ;
2008-09-06 17:45:31 +04:00
2011-04-14 00:33:01 +04:00
option = getopt_long ( argc , argv , " aced:n:p:q:rxP:RVh " , options , NULL ) ;
2004-01-27 05:20:12 +03:00
if ( option = = - 1 )
break ;
2008-09-06 17:45:31 +04:00
dbg ( udev , " option '%c' \n " , option ) ;
2004-01-27 05:20:12 +03:00
switch ( option ) {
case ' n ' :
2008-09-13 23:09:28 +04:00
if ( device ! = NULL ) {
fprintf ( stderr , " device already specified \n " ) ;
rc = 2 ;
goto exit ;
}
2006-08-18 04:33:46 +04:00
/* remove /dev if given */
2009-05-20 19:57:52 +04:00
if ( strncmp ( optarg , udev_get_dev_path ( udev ) , strlen ( udev_get_dev_path ( udev ) ) ) ! = 0 )
util_strscpyl ( name , sizeof ( name ) , udev_get_dev_path ( udev ) , " / " , optarg , NULL ) ;
else
util_strscpy ( name , sizeof ( name ) , optarg ) ;
2008-09-10 20:39:23 +04:00
util_remove_trailing_chars ( name , ' / ' ) ;
2008-09-25 15:20:27 +04:00
if ( stat ( name , & statbuf ) < 0 ) {
fprintf ( stderr , " device node not found \n " ) ;
rc = 2 ;
goto exit ;
} else {
char type ;
if ( S_ISBLK ( statbuf . st_mode ) ) {
type = ' b ' ;
} else if ( S_ISCHR ( statbuf . st_mode ) ) {
type = ' c ' ;
} else {
fprintf ( stderr , " device node has wrong file type \n " ) ;
rc = 2 ;
goto exit ;
}
device = udev_device_new_from_devnum ( udev , type , statbuf . st_rdev ) ;
if ( device = = NULL ) {
fprintf ( stderr , " device node not found \n " ) ;
rc = 2 ;
goto exit ;
}
}
2004-01-27 05:20:12 +03:00
break ;
case ' p ' :
2008-09-13 23:09:28 +04:00
if ( device ! = NULL ) {
fprintf ( stderr , " device already specified \n " ) ;
rc = 2 ;
goto exit ;
}
2008-09-28 19:39:31 +04:00
/* add sys dir if needed */
2009-05-20 19:57:52 +04:00
if ( strncmp ( optarg , udev_get_sys_path ( udev ) , strlen ( udev_get_sys_path ( udev ) ) ) ! = 0 )
util_strscpyl ( path , sizeof ( path ) , udev_get_sys_path ( udev ) , optarg , NULL ) ;
else
util_strscpy ( path , sizeof ( path ) , optarg ) ;
2008-09-10 20:39:23 +04:00
util_remove_trailing_chars ( path , ' / ' ) ;
2008-09-16 04:12:47 +04:00
device = udev_device_new_from_syspath ( udev , path ) ;
2008-09-25 15:20:27 +04:00
if ( device = = NULL ) {
fprintf ( stderr , " device path not found \n " ) ;
rc = 2 ;
goto exit ;
}
2004-01-27 05:20:12 +03:00
break ;
case ' q ' :
2005-08-29 17:01:08 +04:00
action = ACTION_QUERY ;
2009-06-10 17:55:24 +04:00
if ( strcmp ( optarg , " property " ) = = 0 | | strcmp ( optarg , " env " ) = = 0 ) {
2009-06-07 04:39:54 +04:00
query = QUERY_PROPERTY ;
} else if ( strcmp ( optarg , " name " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_NAME ;
2009-06-07 04:39:54 +04:00
} else if ( strcmp ( optarg , " symlink " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_SYMLINK ;
2009-06-07 04:39:54 +04:00
} else if ( strcmp ( optarg , " path " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_PATH ;
2009-06-07 04:39:54 +04:00
} else if ( strcmp ( optarg , " all " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_ALL ;
2009-06-07 04:39:54 +04:00
} else {
fprintf ( stderr , " unknown query type \n " ) ;
rc = 3 ;
goto exit ;
2004-03-02 10:47:59 +03:00
}
2009-06-07 04:39:54 +04:00
break ;
2004-01-27 05:20:12 +03:00
case ' r ' :
2005-08-29 17:01:08 +04:00
if ( action = = ACTION_NONE )
action = ACTION_ROOT ;
2010-12-09 23:10:30 +03:00
root = true ;
2004-01-27 05:20:12 +03:00
break ;
2011-03-23 04:31:09 +03:00
case ' R ' :
printf ( " %s \n " , udev_get_run_path ( udev ) ) ;
goto exit ;
2007-11-09 12:22:30 +03:00
case ' d ' :
action = ACTION_DEVICE_ID_FILE ;
2009-05-20 19:57:52 +04:00
util_strscpy ( name , sizeof ( name ) , optarg ) ;
2007-11-09 12:22:30 +03:00
break ;
2004-01-27 05:20:12 +03:00
case ' a ' :
2005-08-29 17:01:08 +04:00
action = ACTION_ATTRIBUTE_WALK ;
2004-01-27 05:20:12 +03:00
break ;
2005-08-29 17:01:08 +04:00
case ' e ' :
2008-09-25 15:20:27 +04:00
export_devices ( udev ) ;
2005-03-05 07:35:31 +03:00
goto exit ;
2011-04-14 00:33:01 +04:00
case ' c ' :
cleanup_db ( udev ) ;
goto exit ;
2008-07-15 13:54:18 +04:00
case ' x ' :
2010-12-09 23:10:30 +03:00
export = true ;
2008-07-15 13:54:18 +04:00
break ;
case ' P ' :
export_prefix = optarg ;
break ;
2004-01-27 05:20:12 +03:00
case ' V ' :
2008-11-13 09:31:04 +03:00
printf ( " %s \n " , VERSION ) ;
2005-03-05 07:35:31 +03:00
goto exit ;
2004-01-27 05:20:12 +03:00
case ' h ' :
2007-11-08 19:51:59 +03:00
printf ( " Usage: udevadm info OPTIONS \n "
2008-09-26 21:41:50 +04:00
" --query=<type> query device information: \n "
2007-11-09 12:22:30 +03:00
" name name of device node \n "
" symlink pointing to node \n "
2008-09-26 21:41:50 +04:00
" path sys device path \n "
2009-06-07 04:39:54 +04:00
" property the device properties \n "
2007-11-09 12:22:30 +03:00
" all all values \n "
2008-09-26 21:41:50 +04:00
" --path=<syspath> sys device path used for query or attribute walk \n "
" --name=<name> node or symlink name used for query or attribute walk \n "
" --root prepend dev directory to path names \n "
" --attribute-walk print all key matches while walking along the chain \n "
2007-11-09 12:22:30 +03:00
" of parent devices \n "
2008-09-26 21:41:50 +04:00
" --device-id-of-file=<file> print major:minor of device containing this file \n "
2010-12-10 03:13:35 +03:00
" --export export key/value pairs \n "
" --export-prefix export the key name with a prefix \n "
2007-11-09 12:22:30 +03:00
" --export-db export the content of the udev database \n "
2011-04-14 00:33:01 +04:00
" --cleanup-db cleanup the udev database \n "
2009-03-07 04:32:40 +03:00
" --help \n \n " ) ;
2006-08-21 04:38:20 +04:00
goto exit ;
2004-01-27 05:20:12 +03:00
default :
2011-06-30 17:17:09 +04:00
rc = 1 ;
2005-08-29 17:01:08 +04:00
goto exit ;
2004-01-27 05:20:12 +03:00
}
}
2005-08-29 17:01:08 +04:00
switch ( action ) {
case ACTION_QUERY :
2008-09-13 23:09:28 +04:00
if ( device = = NULL ) {
2008-09-15 23:01:35 +04:00
fprintf ( stderr , " query needs a valid device specified by --path= or --name= \n " ) ;
2006-01-09 23:18:00 +03:00
rc = 4 ;
2005-08-29 17:01:08 +04:00
goto exit ;
2004-01-27 05:20:12 +03:00
}
switch ( query ) {
2009-12-24 22:42:02 +03:00
case QUERY_NAME : {
const char * node = udev_device_get_devnode ( device ) ;
if ( node = = NULL ) {
fprintf ( stderr , " no device node found \n " ) ;
rc = 5 ;
goto exit ;
}
2008-09-13 23:09:28 +04:00
if ( root ) {
2008-09-20 11:01:20 +04:00
printf ( " %s \n " , udev_device_get_devnode ( device ) ) ;
2008-09-13 23:09:28 +04:00
} else {
2009-12-24 22:42:02 +03:00
size_t len = strlen ( udev_get_dev_path ( udev ) ) ;
printf ( " %s \n " , & udev_device_get_devnode ( device ) [ len + 1 ] ) ;
2007-09-20 17:25:29 +04:00
}
2005-08-29 17:01:08 +04:00
break ;
2009-12-24 22:42:02 +03:00
}
2008-09-13 23:09:28 +04:00
case QUERY_SYMLINK :
2008-09-28 03:34:55 +04:00
list_entry = udev_device_get_devlinks_list_entry ( device ) ;
while ( list_entry ! = NULL ) {
2008-09-25 15:20:27 +04:00
if ( root ) {
2008-09-28 03:34:55 +04:00
printf ( " %s " , udev_list_entry_get_name ( list_entry ) ) ;
2008-09-25 15:20:27 +04:00
} else {
size_t len ;
len = strlen ( udev_get_dev_path ( udev_device_get_udev ( device ) ) ) ;
2008-09-28 03:34:55 +04:00
printf ( " %s " , & udev_list_entry_get_name ( list_entry ) [ len + 1 ] ) ;
2008-09-25 15:20:27 +04:00
}
2008-09-28 03:34:55 +04:00
list_entry = udev_list_entry_get_next ( list_entry ) ;
if ( list_entry ! = NULL )
2008-09-25 15:20:27 +04:00
printf ( " " ) ;
}
printf ( " \n " ) ;
2008-09-13 23:09:28 +04:00
break ;
2005-06-26 20:55:24 +04:00
case QUERY_PATH :
2008-09-13 23:09:28 +04:00
printf ( " %s \n " , udev_device_get_devpath ( device ) ) ;
2005-03-05 07:35:31 +03:00
goto exit ;
2009-06-07 04:39:54 +04:00
case QUERY_PROPERTY :
2008-09-28 03:34:55 +04:00
list_entry = udev_device_get_properties_list_entry ( device ) ;
while ( list_entry ! = NULL ) {
2010-12-09 23:10:30 +03:00
if ( export ) {
const char * prefix = export_prefix ;
if ( prefix = = NULL )
prefix = " " ;
printf ( " %s%s='%s' \n " , prefix ,
udev_list_entry_get_name ( list_entry ) ,
udev_list_entry_get_value ( list_entry ) ) ;
} else {
printf ( " %s=%s \n " , udev_list_entry_get_name ( list_entry ) , udev_list_entry_get_value ( list_entry ) ) ;
}
2008-09-28 03:34:55 +04:00
list_entry = udev_list_entry_get_next ( list_entry ) ;
2008-09-25 15:20:27 +04:00
}
2005-08-29 17:01:08 +04:00
break ;
2005-06-26 20:55:24 +04:00
case QUERY_ALL :
2008-09-13 23:09:28 +04:00
print_record ( device ) ;
2005-08-29 17:01:08 +04:00
break ;
2004-01-27 05:20:12 +03:00
default :
2006-08-21 04:38:20 +04:00
fprintf ( stderr , " unknown query type \n " ) ;
2005-08-29 17:01:08 +04:00
break ;
2004-01-27 05:20:12 +03:00
}
2005-08-29 17:01:08 +04:00
break ;
case ACTION_ATTRIBUTE_WALK :
2008-09-13 23:09:28 +04:00
if ( device = = NULL ) {
2008-09-15 23:01:35 +04:00
fprintf ( stderr , " query needs a valid device specified by --path= or --name= \n " ) ;
2008-10-01 12:22:47 +04:00
rc = 4 ;
2006-08-18 04:31:37 +04:00
goto exit ;
}
2008-09-13 23:09:28 +04:00
print_device_chain ( device ) ;
2005-08-29 17:01:08 +04:00
break ;
2007-11-09 12:22:30 +03:00
case ACTION_DEVICE_ID_FILE :
2008-07-15 13:54:18 +04:00
if ( stat_device ( name , export , export_prefix ) ! = 0 )
2008-10-01 12:22:47 +04:00
rc = 1 ;
2007-11-09 12:22:30 +03:00
break ;
2005-08-29 17:01:08 +04:00
case ACTION_ROOT :
2008-09-06 17:45:31 +04:00
printf ( " %s \n " , udev_get_dev_path ( udev ) ) ;
2005-08-29 17:01:08 +04:00
break ;
default :
2006-08-21 04:38:20 +04:00
fprintf ( stderr , " missing option \n " ) ;
2006-01-09 23:18:00 +03:00
rc = 1 ;
2005-08-29 17:01:08 +04:00
break ;
2004-01-27 05:20:12 +03:00
}
2005-03-05 07:35:31 +03:00
exit :
2008-09-13 23:09:28 +04:00
udev_device_unref ( device ) ;
2006-01-09 23:18:00 +03:00
return rc ;
2004-01-27 05:20:12 +03:00
}
2011-07-14 03:53:23 +04:00
const struct udevadm_cmd udevadm_info = {
. name = " info " ,
. cmd = uinfo ,
. help = " query sysfs or the udev database " ,
} ;