udevinfo.c revision 726687ad48bdececed1e7e44387c50e009e28208
/*
* Copyright (C) 2004-2006 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stddef.h>
#include <ctype.h>
#include <stdarg.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
#include <getopt.h>
#include "udev.h"
{
char *attr_value;
continue;
continue;
continue;
continue;
continue;
if (attr_value == NULL)
continue;
/* remove trailing newlines */
/* skip nonprintable attributes */
len--;
if (len) {
continue;
}
}
}
printf("\n");
}
static int print_device_chain(const char *devpath)
{
struct sysfs_device *dev;
return -1;
printf("\n"
"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"
"\n");
/* walk up the chain of devices */
while (1) {
break;
}
return 0;
}
{
struct name_entry *name_loop;
if (udev->link_priority != 0)
if (udev->partitions != 0)
if (udev->ignore_remove)
}
static void export_db(void) {
struct name_entry *name_loop;
continue;
printf("\n");
}
}
{
int count;
struct name_entry *device;
int rc = -1;
if (count <= 0)
goto out;
/* select the device that seems to match */
continue;
/* make sure, we don't get a link of a differnt device */
continue;
continue;
}
rc = 0;
break;
}
out:
return rc;
}
{
return -1;
if (export) {
prefix = "INFO_";
printf("%sMAJOR=%d\n"
"%sMINOR=%d\n",
} else
return 0;
}
{
int option;
int root = 0;
int export = 0;
const char *export_prefix = NULL;
{}
};
enum action_type {
} action = ACTION_NONE;
enum query_type {
} query = QUERY_NONE;
struct name_entry *name_loop;
int rc = 0;
logging_init("udevinfo");
sysfs_init();
rc = 1;
goto exit;
}
while (1) {
if (option == -1)
break;
switch (option) {
case 'n':
/* remove /dev if given */
else
break;
case 'p':
/* remove /sys if given */
else
/* possibly resolve to real devpath */
char *pos;
/* also check if the parent is a link */
if (pos != 0) {
pos[0] = '\0';
}
}
}
break;
case 'q':
query = QUERY_NAME;
break;
}
break;
}
query = QUERY_PATH;
break;
}
break;
}
break;
}
rc = 2;
goto exit;
case 'r':
if (action == ACTION_NONE)
root = 1;
break;
case 'd':
break;
case 'a':
break;
case 'e':
export_db();
goto exit;
case 'x':
export = 1;
break;
case 'P':
break;
case 1:
goto exit;
case 'V':
goto exit;
case 'h':
printf("Usage: udevadm info OPTIONS\n"
" --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"
" --export-db export the content of the udev database\n"
" --help print this text\n"
"\n");
goto exit;
default:
goto exit;
}
}
/* run action */
switch (action) {
case ACTION_QUERY:
if (path[0] != '\0') {
rc = 3;
goto exit;
}
} else if (name[0] != '\0') {
rc = 4;
goto exit;
}
} else {
rc = 4;
goto exit;
}
switch(query) {
case QUERY_NAME:
if (root)
else
break;
case QUERY_SYMLINK:
if (root)
else
}
break;
case QUERY_PATH:
goto exit;
case QUERY_ENV:
break;
case QUERY_ALL:
break;
default:
break;
}
break;
case ACTION_ATTRIBUTE_WALK:
if (path[0] != '\0') {
if (print_device_chain(path) != 0) {
rc = 4;
goto exit;
}
} else if (name[0] != '\0') {
rc = 4;
goto exit;
}
rc = 4;
goto exit;
}
} else {
rc = 5;
goto exit;
}
break;
case ACTION_DEVICE_ID_FILE:
rc = 6;
break;
case ACTION_ROOT:
break;
default:
rc = 1;
break;
}
exit:
return rc;
}