udevinfo.c revision fc55cf68ca0c0db5172a9de7e827c6c3f7c2a308
/*
* udevinfo.c - fetches stored device information or sysfs attributes
*
* Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
*
* 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.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdarg.h>
#include <unistd.h>
#include <errno.h>
#include "libsysfs/sysfs/libsysfs.h"
#include "udev_libc_wrapper.h"
#include "udev.h"
#include "udev_utils.h"
#include "udev_version.h"
#include "logging.h"
#ifdef USE_LOG
{
if (priority > udev_log_priority)
return;
}
#endif
{
struct sysfs_attribute *attr;
char value[VALUE_SIZE];
continue;
continue;
}
/* remove trailing newlines */
/* skip nonprintable attributes */
len--;
if (len) {
continue;
}
}
printf("\n");
}
{
struct name_entry *name_loop;
}
static int print_device_chain(const char *path)
{
struct sysfs_class_device *class_dev;
struct sysfs_class_device *class_dev_parent;
struct sysfs_attribute *attr;
struct sysfs_device *sysfs_dev;
int retval = 0;
/* get the class dev */
return -1;
}
printf("\nudevinfo starts with the device the node belongs to and then walks up the\n"
"device chain, to print for every device found, all possibly useful attributes\n"
"in the udev key format.\n"
"Only attributes within one device section may be used together in one rule,\n"
"to match the device for which the node will be created.\n"
"\n");
/* look for the 'dev' file */
/* open sysfs class device directory and print all attributes */
retval = -1;
goto exit;
}
/* get the device link (if parent exists look here) */
if (class_dev_parent != NULL)
else
printf("follow the \"device\"-link to the physical device:\n");
/* look the device chain upwards */
else
printf("\n");
break;
}
exit:
return retval;
}
}
printf("\n");
}
struct name_entry *name_loop;
}
}
static void print_help(void)
{
" -q 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"
"\n"
" -p PATH sysfs device path used for query or chain\n"
"\n"
" -r prepend to query result or print udev_root\n"
" -a print all SYSFS_attributes along the device chain\n"
" -e export the content of the udev database\n"
" -V print udev version\n"
" -h print this help text\n"
"\n");
}
{
static const char short_options[] = "aden:p:q:rVh";
int option;
int root = 0;
enum action_type {
} action = ACTION_NONE;
enum query_type {
} query = QUERY_NONE;
struct name_entry *name_loop;
char *pos;
int retval = 0;
logging_init("udevinfo");
/* get command line options */
while (1) {
if (option == -1)
break;
switch (option) {
case 'n':
break;
case 'p':
break;
case 'q':
query = QUERY_NAME;
break;
}
break;
}
query = QUERY_PATH;
break;
}
break;
}
break;
}
retval = 2;
goto exit;
case 'r':
if (action == ACTION_NONE)
root = 1;
break;
case 'a':
break;
case 'd':
goto exit;
case 'e':
goto exit;
case 'V':
goto exit;
case 'h':
case '?':
default:
print_help();
goto exit;
}
}
/* run action */
switch (action) {
case ACTION_QUERY:
if (path[0] != '\0') {
/* remove sysfs_path if given */
} else {
if (path[0] != '/') {
/* prepend '/' if missing */
} else {
}
}
if (retval != 0) {
retval = 3;
goto exit;
}
} else if (name[0] != '\0') {
int len;
/* remove udev_root if given */
} else
if (retval != 0) {
retval = 3;
goto exit;
}
} else {
retval = 4;
goto exit;
}
switch(query) {
case QUERY_NAME:
if (root)
else
break;
case QUERY_SYMLINK:
goto exit;
if (root)
else
printf("\n");
break;
case QUERY_PATH:
goto exit;
case QUERY_ENV:
break;
case QUERY_ALL:
print_record(&udev);
break;
default:
print_help();
break;
}
break;
case ACTION_ATTRIBUTE_WALK:
if (path[0] == '\0') {
retval = 4;
goto exit;
} else {
/* prepend sysfs mountpoint if not given */
}
}
break;
case ACTION_ROOT:
break;
default:
print_help();
retval = 1;
break;
}
exit:
return retval;
}