udevinfo.c revision b1e95455d2683f43f47ea94a7b79af64f0738d36
/*
* 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_utils.h"
#include "udev_version.h"
#include "udev_db.h"
#include "logging.h"
#define SYSFS_VALUE_SIZE 256
#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_SIZE];
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;
/* 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");
/* look for the 'dev' file */
/* 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 print_sysfs_devices(void)
{
struct dlist *subsyslist;
char *class;
if (!subsyslist)
return -1;
struct sysfs_class *cls;
struct dlist *class_devices;
struct sysfs_class_device *class_dev;
struct sysfs_device *phys_dev;
if (!cls)
continue;
if (!class_devices)
continue;
struct sysfs_attribute *attr;
printf("\n");
if (attr) {
}
if (phys_dev) {
}
}
}
return 0;
}
{
static const char short_options[] = "adn:p:q:rsVh";
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 's':
exit(0);
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:
if (root) {
int slen;
char *spos;
}
} else {
}
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 */
}