udevinfo.c revision 16378373cb9d96e5d424921806ff71f218e92694
/*
* 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 "udev.h"
#include "udev_version.h"
#include "logging.h"
#include "udevdb.h"
#include "libsysfs/libsysfs.h"
# define SYSFS_VALUE_MAX 200
char **main_argv;
int main_argc;
#ifdef LOG
unsigned char logname[42];
{
}
#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;
}
/* callback for database dump */
{
printf("\n");
return 0;
}
enum query_type {
NONE,
NAME,
PATH,
MODE,
};
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("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) {
//sysfs_close_class_device(class_dev);
}
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;
//sysfs_close_device(sysfs_dev);
}
exit:
//sysfs_close_class_device(class_dev);
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;
}
break;
}
break;
}
printf("unknown query type\n");
exit(1);
case 'r':
root = 1;
break;
case 'a':
attributes = 1;
break;
case 'd':
retval = udevdb_open_ro();
if (retval != 0) {
printf("unable to open udev database\n");
exit(2);
}
udevdb_exit();
exit(0);
case 'V':
exit(0);
case 'h':
retval = 0;
case '?':
default:
goto help;
}
}
/* process options */
retval = udevdb_open_ro();
if (retval != 0) {
printf("unable to open udev database\n");
return -EACCES;
}
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)
break;
case SYMLINK:
break;
case MODE:
break;
case GROUP:
break;
case OWNER:
break;
case PATH:
break;
default:
goto exit;
}
exit:
udevdb_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"
" 'mode' permissions of node\n"
" 'owner' of node\n"
" 'group' of node\n"
" 'path' sysfs device path\n"
" -p PATH sysfs device path used for query or chain\n"
" -n NAME node name used for query\n"
"\n"
" -r print udev root\n"
" -a print all SYSFS_attributes along the device chain\n"
" -d dump whole database\n"
" -V print udev version\n"
" -h print this help text\n"
"\n");
return retval;
}
{
int retval;
init_logging("udevinfo");
/* initialize our configuration */
retval = process_options();
if (retval != 0)
exit(1);
exit(0);
}