udevinfo.c revision 2b41e68a08548ce44b4d145900dab2bb04cd34f7
/*
* udevinfo - fetches attributes for a device
*
* Copyright (C) 2004 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.h"
#include "udev_lib.h"
#include "udev_version.h"
#include "logging.h"
#include "udevdb.h"
# define SYSFS_VALUE_MAX 200
char **main_argv;
int main_argc;
#ifdef LOG
unsigned char logname[LOGNAME_SIZE];
{
}
#endif
static int print_all_attributes(const char *path)
{
struct dlist *attributes;
struct sysfs_attribute *attr;
struct sysfs_directory *sysfs_dir;
char value[SYSFS_VALUE_MAX];
int len;
int retval = 0;
return -1;
if (attributes == NULL) {
retval = -1;
goto exit;
}
if (len == 0)
continue;
/* remove trailing newline */
len--;
}
/* skip nonprintable values */
while (len) {
break;
len--;
}
if (len == 0)
}
}
printf("\n");
exit:
return retval;
}
{
printf("\n");
return 0;
}
enum query_type {
NONE,
NAME,
PATH,
};
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;
struct sysfs_device *sysfs_dev_parent;
int retval = 0;
char type;
/* get the class dev */
printf("couldn't get the class device\n");
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");
printf("couldn't get the \"dev\" file\n");
retval = -1;
goto exit;
}
}
/* open sysfs class device directory and print all attributes */
printf("couldn't open class device directory\n");
retval = -1;
goto exit;
}
/* get the device link (if parent exists look here) */
if (class_dev_parent != NULL)
else
printf("follow the class device's \"device\"\n");
/* look the device chain upwards */
/* open sysfs device directory and print all attributes */
if (sysfs_dev_parent == NULL)
break;
}
exit:
return retval;
}
static int process_options(void)
{
static const char short_options[] = "adn:p:q:rVh";
int option;
int retval = 1;
int root = 0;
int attributes = 0;
char *pos;
/* get command line options */
while (1) {
if (option == -1)
break;
switch (option) {
case 'n':
break;
case 'p':
break;
case 'q':
break;
}
break;
}
break;
}
break;
}
printf("unknown query type\n");
exit(1);
case 'r':
root = 1;
break;
case 'a':
attributes = 1;
break;
case 'V':
exit(0);
case 'h':
retval = 0;
case '?':
default:
goto help;
}
}
/* process options */
if (path[0] != '\0') {
/* remove sysfs_path if given */
} else {
if (path[0] != '/') {
/* prepend '/' if missing */
} else {
}
}
if (retval != 0) {
printf("device not found in database\n");
goto exit;
}
goto print;
}
if (name[0] != '\0') {
/* remove udev_root if given */
} else
if (retval != 0) {
printf("device not found in database\n");
goto exit;
}
goto print;
}
printf("query needs device path(-p) or node name(-n) specified\n");
goto exit;
switch(query) {
case NAME:
if (root) {
} else {
}
break;
case SYMLINK:
break;
case PATH:
break;
case ALL:
print_record(&udev);
goto exit;
default:
goto exit;
}
exit:
return retval;
}
if (attributes) {
if (path[0] == '\0') {
printf("attribute walk on device chain needs path(-p) specified\n");
return -EINVAL;
} else {
/* prepend sysfs mountpoint if not given */
}
return 0;
}
}
if (root) {
return 0;
}
help:
printf("Usage: [-anpqrdVh]\n"
" -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"
" 'all' all values\n"
"\n"
" -p PATH sysfs device path used for query or chain\n"
"\n"
" -r print udev root\n"
" -a print all SYSFS_attributes along the device chain\n"
" -V print udev version\n"
" -h print this help text\n"
"\n");
return retval;
}
{
int rc = 0;
logging_init("udevinfo");
/* initialize our configuration */
rc = process_options();
}