All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] udev - advanced user query options
Date: Mon, 12 Jan 2004 23:56:27 +0000	[thread overview]
Message-ID: <20040112235627.GA9432@vrfy.org> (raw)
In-Reply-To: <20040111023300.GA4762@vrfy.org>

[-- Attachment #1: Type: text/plain, Size: 1671 bytes --]

On Mon, Jan 12, 2004 at 01:21:30PM -0800, Greg KH wrote:
> On Sun, Jan 11, 2004 at 03:33:00AM +0100, Kay Sievers wrote:
> > This patch improves the user options for udev.
> > It is possible now to query for the name, the symlinks or owner/group.
> > If asked for the name of the node we are able to prepend the udev_root
> > with the -r option.
> > 
> > SAMPLE:
> > 
> >   kay@pim:~/src/udev.test$ ./udev -V
> >   udev, version 012_bk
> > 
> >   kay@pim:~/src/udev.test$ ./udev -h
> >   Usage: [-qrVh]
> >     -q <name>  query database for the specified value
> >     -p <path>  device path used for query
> >     -r         print udev root
> >     -V         print udev version
> >     -h         print this help text
> > 
> >   kay@pim:~/src/udev.test$ ./udev -r
> >   /udev/
> > 
> >   kay@pim:~/src/udev.test$ ./udev -q name -p /class/video4linux/video0
> >   video/webcam0
> > 
> >   kay@pim:~/src/udev.test$ ./udev -q symlink -p /class/video4linux/video0
> >   camera0 kamera0
> > 
> >   kay@pim:~/src/udev.test$ ./udev -q owner -p /class/video4linux/video0
> >   501
> > 
> >   kay@pim:~/src/udev.test$ ./udev -r -q name -p /class/video4linux/video0
> >   /udev/video/webcam0
> 
> Very nice, applied, thanks.
> 
> Hm, care to update the man page with this information, and the '-h'
> option to explain queries a bit more?

Yes, I'll take the man page in the next two hours.

Here is the '-h' and a '-d' to dump the whole database:

  kay@pim:~/src/udev.kay$ ./udev -d
  P: /block/hdb/hdb1
  N: hdb1
  S: 
  O: 
  G: 

  P: /class/video4linux/video0
  N: video/webcam0
  S: camera0 kamera0
  O: 500
  G: 500

  P: /block/hdc
  N: hdc
  S: 
  O: 
  G: 

thanks,
Kay

[-- Attachment #2: 00-dumpdb.diff --]
[-- Type: text/plain, Size: 3578 bytes --]

diff -Nru a/udev.c b/udev.c
--- a/udev.c	Tue Jan 13 00:40:56 2004
+++ b/udev.c	Tue Jan 13 00:40:56 2004
@@ -82,6 +82,16 @@
 	return seqnum;
 }
 
+static void print_record(char *path, struct udevice *dev)
+{
+	printf("P: %s\n", path);
+	printf("N: %s\n", dev->name);
+	printf("S: %s\n", dev->symlink);
+	printf("O: %s\n", dev->owner);
+	printf("G: %s\n", dev->group);
+	printf("\n");
+}
+
 enum query_type {
 	NONE,
 	NAME,
@@ -92,7 +102,7 @@
 
 static inline int udev_user(int argc, char **argv)
 {
-	static const char short_options[] = "p:q:rVh";
+	static const char short_options[] = "dp:q:rVh";
 	int option;
 	int retval = -EINVAL;
 	struct udevice dev;
@@ -144,6 +154,16 @@
 			root = 1;
 			break;
 
+		case 'd':
+			retval = udevdb_open_ro();
+			if (retval != 0) {
+				printf("unable to open udev database\n");
+				return -EACCES;
+			}
+			retval = udevdb_dump(print_record);
+			udevdb_exit();
+			return retval;
+
 		case 'V':
 			printf("udev, version %s\n", UDEV_VERSION);
 			return 0;
@@ -206,12 +226,17 @@
 	}
 
 help:
-	printf("Usage: [-qrVh]\n"
-	       "  -q <name>  query database for the specified value\n"
-	       "  -p <path>  device path used for query\n"
-	       "  -r         print udev root\n"
-	       "  -V         print udev version\n"
-	       "  -h         print this help text\n"
+	printf("Usage: [-pqrdVh]\n"
+	       "  -q TYPE  query database for the specified value:\n"
+	       "             'name'    name of device node\n"
+	       "             'symlink' pointing to node\n"
+	       "             'owner'   of node\n"
+	       "             'group'   of node\n"
+	       "  -p PATH  sysfs device path used for query\n"
+	       "  -r       print udev root\n"
+	       "  -d       dump whole database\n"
+	       "  -V       print udev version\n"
+	       "  -h       print this help text\n"
 	       "\n");
 	return retval;
 }
diff -Nru a/udevdb.c b/udevdb.c
--- a/udevdb.c	Tue Jan 13 00:40:56 2004
+++ b/udevdb.c	Tue Jan 13 00:40:56 2004
@@ -124,7 +124,7 @@
 			dbg("unable to initialize in-memory database");
 		else
 			dbg("unable to initialize database at '%s'", udev_db_filename);
-		return -EINVAL;
+		return -EACCES;
 	}
 	return 0;
 }
@@ -137,7 +137,30 @@
 	udevdb = tdb_open(udev_db_filename, 0, 0, O_RDONLY, 0);
 	if (udevdb == NULL) {
 		dbg("unable to open database at '%s'", udev_db_filename);
+		return -EACCES;
+	}
+	return 0;
+}
+
+void (*user_record_callback) (char *path, struct udevice *dev);
+
+static int traverse_callback(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA dbuf, void *state)
+{
+	user_record_callback((char*) key.dptr, (struct udevice*) dbuf.dptr);
+	return 0;
+}
+
+/**
+ * udevdb_dump: dumps whole database by passing record data to user function
+ * @user_record_handler: user function called for every record in the database
+ */
+int udevdb_dump(void (*user_record_handler) (char *path, struct udevice *dev))
+{
+	if (user_record_handler == NULL) {
+		dbg("invalid user record handling function");
 		return -EINVAL;
 	}
+	user_record_callback = user_record_handler;
+	tdb_traverse(udevdb, traverse_callback, NULL);
 	return 0;
 }
diff -Nru a/udevdb.h b/udevdb.h
--- a/udevdb.h	Tue Jan 13 00:40:56 2004
+++ b/udevdb.h	Tue Jan 13 00:40:56 2004
@@ -12,6 +12,7 @@
 extern void udevdb_exit(void);
 extern int udevdb_init(int init_flag);
 extern int udevdb_open_ro(void);
+extern int udevdb_dump(void (*user_record_handler) (char *path, struct udevice *dev));
 
 extern int udevdb_add_dev(const char *path, const struct udevice *dev);
 extern int udevdb_get_dev(const char *path, struct udevice *dev);

  parent reply	other threads:[~2004-01-12 23:56 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-01-11  2:33 [PATCH] udev - advanced user query options Kay Sievers
2004-01-11  2:37 ` Robert Love
2004-01-11  3:17 ` Kay Sievers
2004-01-12 18:05 ` David Zeuthen
2004-01-12 21:21 ` Greg KH
2004-01-12 21:22 ` Greg KH
2004-01-12 23:56 ` Kay Sievers [this message]
2004-01-13  1:04 ` Greg KH
2004-01-13  1:21 ` Kay Sievers
2004-01-13  4:35 ` Kay Sievers
2004-01-13 18:29 ` Greg KH
2004-01-13 19:47 ` Greg KH
2004-01-15 13:54 ` Olaf Hering
2004-01-15 20:56 ` Greg KH
2004-01-15 21:16 ` Kay Sievers
2004-01-15 21:21 ` Greg KH
2004-01-16  9:49 ` Olaf Hering
2004-01-16  9:57 ` Kay Sievers
2004-01-16 21:54 ` Greg KH
2004-01-19  9:11 ` Olaf Hering
2004-01-19 17:47 ` Greg KH
2004-01-19 19:23 ` Olaf Hering
2004-01-20  0:08 ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040112235627.GA9432@vrfy.org \
    --to=kay.sievers@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.