udevinfo \- query device information from the udev database
.SH "SYNOPSIS"
.HP 9
-\fBudevinfo\fR [\fB\-q\ \fR\fB\fIquery\-type\fR\fR] [\fB\-a\ \fR] [\fB\-p\ \fR\fB\fIdevpath\fR\fR] [\fB\-n\ \fR\fB\fInode\fR\fR] [\fB\-r\fR] [\fB\-e\fR] [\fB\-V\fR] [\fB\-h\fR]
+\fBudevinfo\fR [\fB\-\-query=\fR\fB\fIquery\-type\fR\fR] [\fB\-\-attribute\-walk\fR] [\fB\-\-path=\fR\fB\fIdevpath\fR\fR] [\fB\-\-name=\fR\fB\fInode\fR\fR] [\fB\-\-root\fR] [\fB\-\-export\-db\fR] [\fB\-\-version\fR] [\fB\-\-help\fR]
.SH "DESCRIPTION"
.PP
udevinfo queries the udev database for device information stored in the udev database. It can also query the properties of a device from its sysfs representation to help creating udev rules that match this device.
.SH "OPTIONS"
.TP 3n
-\fB\-q\fR
+\fB\-\-query=\fR\fB\fItype\fR\fR
Query the database for specified type of device data. It needs the
-\fB\-p\fR
+\fB\-\-path\fR
or
-\fB\-n\fR
+\fB\-\-name\fR
to identify the specified device. Valid queries are:
\fBname\fR,
\fBsymlink\fR,
\fBenv\fR,
\fBall\fR.
.TP 3n
-\fB\-a\fR
-Print all sysfs properties of the specified device that can be used in udev rules to match the specified device. It prints all devices along the chain, up to the root of sysfs that can be used in udev rules.
-.TP 3n
-\fB\-p \fR\fB\fIdevpath\fR\fR
+\fB\-\-path=\fR\fB\fIdevpath\fR\fR
The devpath of the device to query.
.TP 3n
-\fB\-n \fR\fB\fInode\fR\fR
+\fB\-\-name=\fR\fB\fInode\fR\fR
The name of the device node or a symlink to query
.TP 3n
-\fB\-r\fR
+\fB\-\-root\fR
The udev root directory:
\fI/dev\fR. If used in conjunction with a
\fBname\fR
or
\fBsymlink\fR
-query, the query returns the absolute path.
+query, the query returns the absolute path including the root directory.
+.TP 3n
+\fB\-\-attribute\-walk\fR
+Print all sysfs properties of the specified device that can be used in udev rules to match the specified device. It prints all devices along the chain, up to the root of sysfs that can be used in udev rules.
.TP 3n
-\fB\-e\fR
+\fB\-\-export\fR
Export the content of the udev database.
.TP 3n
-\fB\-h\fR
+\fB\-\-help\fR
Print help text.
.SH "AUTHOR"
.PP
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
+#include <getopt.h>
#include "udev.h"
struct udevice *udev;
int root = 0;
+ struct option options[] = {
+ { "name", 1, NULL, 'n' },
+ { "path", 1, NULL, 'p' },
+ { "query", 1, NULL, 'q' },
+ { "attribute-walk", 0, NULL, 'a' },
+ { "export-db", 0, NULL, 'e' },
+ { "root", 0, NULL, 'r' },
+ { "version", 0, NULL, 'V' },
+ { "help", 0, NULL, 'h' },
+ {}
+ };
+
enum action_type {
ACTION_NONE,
ACTION_QUERY,
}
/* get command line options */
- opterr = 0;
while (1) {
- option = getopt(argc, argv, ":aden:p:q:rVh");
+ option = getopt_long(argc, argv, "aden:p:q:rVh", options, NULL);
if (option == -1)
break;
printf("udevinfo, version %s\n", UDEV_VERSION);
goto exit;
case 'h':
- printf("Usage: udevinfo [-anpqrVh]\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"
- " 'env' the device related imported environment\n"
- " 'all' all values\n"
+ printf("Usage: udevinfo 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"
"\n"
- " -p PATH sysfs device path used for query or chain\n"
- " -n NAME node/symlink name used for query\n"
+ " --path=<devpath> sysfs device path used for query or chain\n"
+ " --name=<name> node or symlink name used for query\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"
+ " --root prepend to query result or print udev_root\n"
+ " --attribute-walk print all SYSFS_attributes along the device chain\n"
+ " --export-db export the content of the udev database\n"
+ " --verision print udev version\n"
+ " --help print this text\n"
"\n");
goto exit;
- case ':':
- fprintf(stderr, "missing argument for '%c'\n", optopt);
- goto exit;
- case '?':
default:
- fprintf(stderr, "unrecognized option '%c'\n", optopt);
goto exit;
}
}
}
udev_db_get_device(udev, devpath);
} else {
- fprintf(stderr, "query needs device path(-p) or node name(-n) specified\n");
+ fprintf(stderr, "query needs --path or node --name specified\n");
rc = 4;
goto exit;
}
}
print_device_chain(devpath);
} else {
- fprintf(stderr, "attribute walk needs device path(-p) or node name(-n) specified\n");
+ fprintf(stderr, "attribute walk needs --path or node --name specified\n");
rc = 5;
goto exit;
}
<refsynopsisdiv>
<cmdsynopsis>
<command>udevinfo</command>
- <arg><option>-q <replaceable>query-type</replaceable></option></arg>
- <arg><option>-a </option></arg>
- <arg><option>-p <replaceable>devpath</replaceable></option></arg>
- <arg><option>-n <replaceable>node</replaceable></option></arg>
- <arg><option>-r</option></arg>
- <arg><option>-e</option></arg>
- <arg><option>-V</option></arg>
- <arg><option>-h</option></arg>
+ <arg><option>--query=<replaceable>query-type</replaceable></option></arg>
+ <arg><option>--attribute-walk</option></arg>
+ <arg><option>--path=<replaceable>devpath</replaceable></option></arg>
+ <arg><option>--name=<replaceable>node</replaceable></option></arg>
+ <arg><option>--root</option></arg>
+ <arg><option>--export-db</option></arg>
+ <arg><option>--version</option></arg>
+ <arg><option>--help</option></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1><title>OPTIONS</title>
<variablelist>
<varlistentry>
- <term><option>-q</option></term>
+ <term><option>--query=<replaceable>type</replaceable></option></term>
<listitem>
<para>Query the database for specified type of device data. It needs the
- <option>-p</option> or <option>-n</option> to identify the specified
+ <option>--path</option> or <option>--name</option> to identify the specified
device. Valid queries are:
<command>name</command>, <command>symlink</command>, <command>path</command>,
<command>env</command>, <command>all</command>.</para>
</listitem>
</varlistentry>
-
- <varlistentry>
- <term><option>-a</option></term>
- <listitem>
- <para>Print all sysfs properties of the specified device that can be used
- in udev rules to match the specified device. It prints all devices
- along the chain, up to the root of sysfs that can be used in udev rules.</para>
- </listitem>
- </varlistentry>
-
<varlistentry>
- <term><option>-p <replaceable>devpath</replaceable></option></term>
+ <term><option>--path=<replaceable>devpath</replaceable></option></term>
<listitem>
<para>The devpath of the device to query.</para>
</listitem>
</varlistentry>
-
<varlistentry>
- <term><option>-n <replaceable>node</replaceable></option></term>
+ <term><option>--name=<replaceable>node</replaceable></option></term>
<listitem>
<para>The name of the device node or a symlink to query</para>
</listitem>
</varlistentry>
-
<varlistentry>
- <term><option>-r</option></term>
+ <term><option>--root</option></term>
<listitem>
<para>The udev root directory: <filename>/dev</filename>. If used in conjunction
with a <command>name</command> or <command>symlink</command> query, the
- query returns the absolute path.</para>
+ query returns the absolute path including the root directory.</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><option>--attribute-walk</option></term>
+ <listitem>
+ <para>Print all sysfs properties of the specified device that can be used
+ in udev rules to match the specified device. It prints all devices
+ along the chain, up to the root of sysfs that can be used in udev rules.</para>
</listitem>
</varlistentry>
-
<varlistentry>
- <term><option>-e</option></term>
+ <term><option>--export</option></term>
<listitem>
<para>Export the content of the udev database.</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><option>-h</option></term>
+ <term><option>--help</option></term>
<listitem>
<para>Print help text.</para>
</listitem>