summaryrefslogtreecommitdiff
path: root/udevdb.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-01-13 01:01:19 -0800
committerGreg KH <gregkh@suse.de>2005-04-26 21:13:15 -0700
commitee1db00d07ed1db55061ba5e2cb54800cc3e2495 (patch)
tree716356410740f3c13a498ae1d8350b5fef367919 /udevdb.c
parenta2505f4d1da4793991a4d2b2dc8f93b9b89d9672 (diff)
[PATCH] more advanced user query options
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:
Diffstat (limited to 'udevdb.c')
-rw-r--r--udevdb.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/udevdb.c b/udevdb.c
index ca9e63c97e..8d077ea94f 100644
--- a/udevdb.c
+++ b/udevdb.c
@@ -124,7 +124,7 @@ int udevdb_init(int init_flag)
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 @@ int udevdb_open_ro(void)
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;
}