2004-01-20 06:46:26 +03:00
/*
2008-09-10 04:40:42 +04:00
* Copyright ( C ) 2004 - 2008 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>
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
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
{
2006-01-09 23:18:00 +03:00
DIR * dir ;
struct dirent * dent ;
2008-09-13 23:09:28 +04:00
dir = opendir ( udev_device_get_syspath ( device ) ) ;
2006-01-09 23:18:00 +03:00
if ( dir ! = NULL ) {
for ( dent = readdir ( dir ) ; dent ! = NULL ; dent = readdir ( dir ) ) {
2006-09-05 15:54:08 +04:00
struct stat statbuf ;
2008-09-10 23:50:21 +04:00
char filename [ UTIL_PATH_SIZE ] ;
2008-09-13 23:09:28 +04:00
const char * value ;
2006-01-09 23:18:00 +03:00
size_t len ;
2006-09-05 15:54:08 +04:00
if ( dent - > d_name [ 0 ] = = ' . ' )
continue ;
2007-10-24 18:51:33 +04:00
if ( strcmp ( dent - > d_name , " uevent " ) = = 0 )
continue ;
2008-04-28 07:07:47 +04:00
if ( strcmp ( dent - > d_name , " dev " ) = = 0 )
continue ;
2007-10-24 18:51:33 +04:00
2008-09-13 23:09:28 +04:00
util_strlcpy ( filename , udev_device_get_syspath ( device ) , sizeof ( filename ) ) ;
2008-09-10 20:59:42 +04:00
util_strlcat ( filename , " / " , sizeof ( filename ) ) ;
util_strlcat ( filename , dent - > d_name , sizeof ( filename ) ) ;
2006-09-05 15:54:08 +04:00
if ( lstat ( filename , & statbuf ) ! = 0 )
continue ;
if ( S_ISLNK ( statbuf . st_mode ) )
continue ;
2008-09-13 23:09:28 +04:00
value = udev_device_get_attr_value ( device , dent - > d_name ) ;
if ( value = = NULL )
2006-01-09 23:18:00 +03:00
continue ;
2008-09-06 17:45:31 +04:00
dbg ( udev , " attr '%s'='%s'(%zi) \n " , dent - > d_name , value , len ) ;
2006-01-09 23:18:00 +03:00
/* skip nonprintable attributes */
2008-09-13 23:09:28 +04:00
len = strlen ( value ) ;
while ( len > 0 & & isprint ( value [ len - 1 ] ) )
2006-01-09 23:18:00 +03:00
len - - ;
2008-09-13 23:09:28 +04:00
if ( len > 0 ) {
dbg ( info , " attribute value of '%s' non-printable, skip \n " , dent - > d_name ) ;
2006-01-09 23:18:00 +03:00
continue ;
}
2005-03-27 03:29:10 +04:00
2006-08-19 18:06:25 +04:00
printf ( " %s{%s}== \" %s \" \n " , key , dent - > d_name , value ) ;
2005-03-27 03:29:10 +04:00
}
2008-09-11 19:08:12 +04:00
closedir ( dir ) ;
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 "
2006-06-16 13:11:07 +04:00
" Udevinfo starts with the device specified by the devpath and then \n "
" 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 ;
int i ;
2008-09-25 15:20:27 +04:00
struct udev_list * list ;
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-09-20 11:01:20 +04:00
printf ( " N: %s \n " , & udev_device_get_devnode ( device ) [ len + 1 ] ) ;
2008-09-25 15:20:27 +04:00
2008-09-13 23:09:28 +04:00
i = device_get_devlink_priority ( device ) ;
if ( i ! = 0 )
printf ( " L: %i \n " , i ) ;
2008-09-25 15:20:27 +04:00
2008-09-13 23:09:28 +04:00
i = device_get_num_fake_partitions ( device ) ;
if ( i ! = 0 )
printf ( " A:%u \n " , i ) ;
2008-09-25 15:20:27 +04:00
2008-09-13 23:09:28 +04:00
i = device_get_ignore_remove ( device ) ;
if ( i ! = 0 )
printf ( " R:%u \n " , i ) ;
2008-09-25 15:20:27 +04:00
list = udev_device_get_devlinks_list ( device ) ;
while ( list ! = NULL ) {
len = strlen ( udev_get_dev_path ( udev_device_get_udev ( device ) ) ) ;
printf ( " S: %s \n " , & udev_list_get_name ( list ) [ len + 1 ] ) ;
list = udev_list_get_next ( list ) ;
2007-03-17 12:08:25 +03:00
}
2008-09-13 23:09:28 +04:00
2008-09-25 15:20:27 +04:00
list = udev_device_get_properties_list ( device ) ;
while ( list ! = NULL ) {
printf ( " E: %s=%s \n " , udev_list_get_name ( list ) , udev_list_get_value ( list ) ) ;
list = udev_list_get_next ( list ) ;
2008-09-13 23:09:28 +04:00
}
2008-09-25 15:20:27 +04:00
printf ( " \n " ) ;
2007-03-17 12:08:25 +03:00
}
2008-07-15 13:54:18 +04:00
static int stat_device ( const char * name , int 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 )
{
struct udev_enumerate * enumerate ;
struct udev_list * list ;
enumerate = udev_enumerate_new_from_subsystems ( udev , NULL ) ;
if ( enumerate = = NULL )
return - 1 ;
list = udev_enumerate_get_devices_list ( enumerate ) ;
while ( list ! = NULL ) {
struct udev_device * device ;
device = udev_device_new_from_syspath ( udev , udev_list_get_name ( list ) ) ;
if ( device ! = NULL ) {
if ( udev_device_get_devnode ( device ) ! = NULL )
print_record ( device ) ;
udev_device_unref ( device ) ;
}
list = udev_list_get_next ( list ) ;
}
udev_enumerate_unref ( enumerate ) ;
return 0 ;
}
2008-09-06 17:45:31 +04:00
int udevadm_info ( 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 ;
2004-01-27 05:20:12 +03:00
int root = 0 ;
2008-07-15 13:54:18 +04:00
int export = 0 ;
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-25 15:20:27 +04:00
struct udev_list * list ;
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 [ ] = {
2006-09-03 06:05:20 +04:00
{ " name " , 1 , NULL , ' n ' } ,
{ " path " , 1 , NULL , ' p ' } ,
{ " query " , 1 , NULL , ' q ' } ,
{ " attribute-walk " , 0 , NULL , ' a ' } ,
{ " export-db " , 0 , NULL , ' e ' } ,
{ " root " , 0 , NULL , ' r ' } ,
2007-11-09 12:22:30 +03:00
{ " device-id-of-file " , 1 , NULL , ' d ' } ,
2008-07-15 13:54:18 +04:00
{ " export " , 0 , NULL , ' x ' } ,
{ " export-prefix " , 1 , NULL , ' P ' } ,
2007-03-07 20:00:12 +03:00
{ " version " , 0 , NULL , 1 } , /* -V outputs braindead format */
2006-09-03 06:05:20 +04:00
{ " help " , 0 , NULL , ' h ' } ,
{ }
} ;
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 ,
QUERY_ENV ,
QUERY_ALL ,
} query = QUERY_NONE ;
2005-08-29 17:01:08 +04:00
2004-01-27 05:20:12 +03:00
while ( 1 ) {
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
2008-07-15 13:54:18 +04:00
option = getopt_long ( argc , argv , " aed:n:p:q:rxPVh " , 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 */
2008-09-25 15:20:27 +04:00
if ( strncmp ( optarg , udev_get_dev_path ( udev ) , strlen ( udev_get_dev_path ( udev ) ) ) ! = 0 ) {
util_strlcpy ( name , udev_get_dev_path ( udev ) , sizeof ( name ) ) ;
util_strlcat ( name , " / " , sizeof ( name ) ) ;
util_strlcat ( name , optarg , sizeof ( name ) ) ;
} else {
2008-09-10 20:59:42 +04:00
util_strlcpy ( name , optarg , sizeof ( name ) ) ;
2008-09-25 15:20:27 +04:00
}
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-16 04:12:47 +04:00
/* add /sys if needed */
if ( strncmp ( optarg , udev_get_sys_path ( udev ) , strlen ( udev_get_sys_path ( udev ) ) ) ! = 0 ) {
util_strlcpy ( path , udev_get_sys_path ( udev ) , sizeof ( path ) ) ;
util_strlcat ( path , optarg , sizeof ( path ) ) ;
} else {
2008-09-10 20:59:42 +04:00
util_strlcpy ( path , optarg , sizeof ( path ) ) ;
2008-09-16 04:12:47 +04:00
}
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 ;
2004-01-27 05:20:12 +03:00
if ( strcmp ( optarg , " name " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_NAME ;
2004-01-27 05:20:12 +03:00
break ;
}
if ( strcmp ( optarg , " symlink " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_SYMLINK ;
2004-01-27 05:20:12 +03:00
break ;
}
if ( strcmp ( optarg , " path " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_PATH ;
break ;
}
if ( strcmp ( optarg , " env " ) = = 0 ) {
query = QUERY_ENV ;
2004-01-27 05:20:12 +03:00
break ;
}
2004-03-02 10:47:59 +03:00
if ( strcmp ( optarg , " all " ) = = 0 ) {
2005-06-26 20:55:24 +04:00
query = QUERY_ALL ;
2004-03-02 10:47:59 +03:00
break ;
}
2005-03-27 03:12:55 +04:00
fprintf ( stderr , " unknown query type \n " ) ;
2006-01-09 23:18:00 +03:00
rc = 2 ;
2005-03-05 07:35:31 +03:00
goto exit ;
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 ;
2004-01-27 05:20:12 +03:00
root = 1 ;
break ;
2007-11-09 12:22:30 +03:00
case ' d ' :
action = ACTION_DEVICE_ID_FILE ;
2008-09-10 20:59:42 +04:00
util_strlcpy ( name , optarg , sizeof ( name ) ) ;
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 ;
2008-07-15 13:54:18 +04:00
case ' x ' :
export = 1 ;
break ;
case ' P ' :
export_prefix = optarg ;
break ;
2007-03-07 20:00:12 +03:00
case 1 :
2008-07-30 03:45:23 +04:00
printf ( " %s \n " , VERSION ) ;
2007-03-07 20:00:12 +03:00
goto exit ;
2004-01-27 05:20:12 +03:00
case ' V ' :
2008-07-30 03:45:23 +04:00
printf ( " udevinfo, version %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 "
2007-11-09 12:22:30 +03:00
" --query=<type> query database for the specified value: \n "
" name name of device node \n "
" symlink pointing to node \n "
" path sysfs device path \n "
" env the device related imported environment \n "
" all all values \n "
" --path=<devpath> sysfs device path used for query or chain \n "
" --name=<name> node or symlink name used for query \n "
" --root prepend to query result or print udev_root \n "
" --attribute-walk print all key matches while walking along chain \n "
" of parent devices \n "
" --device-id-of-file=<file> print major/minor of underlying device \n "
" --export-db export the content of the udev database \n "
" --help print this text \n "
2006-08-21 04:38:20 +04:00
" \n " ) ;
goto exit ;
2004-01-27 05:20:12 +03:00
default :
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 ) {
2005-06-26 20:55:24 +04:00
case QUERY_NAME :
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 {
size_t len ;
2007-09-20 17:25:29 +04:00
2008-09-13 23:09:28 +04:00
len = strlen ( udev_get_dev_path ( udev ) ) ;
2008-09-20 11:01:20 +04:00
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 ;
2008-09-13 23:09:28 +04:00
case QUERY_SYMLINK :
2008-09-25 15:20:27 +04:00
list = udev_device_get_devlinks_list ( device ) ;
while ( list ! = NULL ) {
if ( root ) {
printf ( " %s " , udev_list_get_name ( list ) ) ;
} else {
size_t len ;
len = strlen ( udev_get_dev_path ( udev_device_get_udev ( device ) ) ) ;
printf ( " %s " , & udev_list_get_name ( list ) [ len + 1 ] ) ;
}
list = udev_list_get_next ( list ) ;
if ( list ! = NULL )
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 ;
2005-06-26 20:55:24 +04:00
case QUERY_ENV :
2008-09-25 15:20:27 +04:00
list = udev_device_get_properties_list ( device ) ;
while ( list ! = NULL ) {
printf ( " %s=%s \n " , udev_list_get_name ( list ) , udev_list_get_value ( list ) ) ;
list = udev_list_get_next ( list ) ;
}
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 " ) ;
2006-08-18 04:31:37 +04:00
rc = 5 ;
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 )
2007-11-09 12:22:30 +03:00
rc = 6 ;
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
}