summaryrefslogtreecommitdiff
path: root/udev_db.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2007-03-17 10:08:25 +0100
committerKay Sievers <kay.sievers@vrfy.org>2007-03-17 10:08:25 +0100
commit31de3a2ba18ffa011f5054016ccc4a500cbe0cc3 (patch)
treef945058d7aad9cbe45fba6e496c73d948255e729 /udev_db.c
parentd7fdcd61927e9439ad7079bb0967e0b6edac7646 (diff)
read list of devices from index, make index private to database
Diffstat (limited to 'udev_db.c')
-rw-r--r--udev_db.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/udev_db.c b/udev_db.c
index 40082abf03..8c9e474ad4 100644
--- a/udev_db.c
+++ b/udev_db.c
@@ -77,6 +77,46 @@ static int name_index(const char *devpath, const char *name, int add)
return 0;
}
+int udev_db_get_devices_by_name(const char *name, struct list_head *name_list)
+{
+ char dirname[PATH_MAX];
+ size_t start;
+ DIR *dir;
+ int rc = 0;
+
+ strlcpy(dirname, udev_root, sizeof(dirname));
+ start = strlcat(dirname, "/"DB_NAME_INDEX_DIR"/", sizeof(dirname));
+ strlcat(dirname, name, sizeof(dirname));
+ path_encode(&dirname[start], sizeof(dirname) - start);
+
+ dir = opendir(dirname);
+ if (dir == NULL) {
+ info("no index directory '%s': %s", dirname, strerror(errno));
+ rc = -1;
+ goto out;
+ }
+
+ info("found index directory '%s'", dirname);
+ while (1) {
+ struct dirent *ent;
+ char device[PATH_SIZE];
+
+ ent = readdir(dir);
+ if (ent == NULL || ent->d_name[0] == '\0')
+ break;
+ if (ent->d_name[0] == '.')
+ continue;
+
+ strlcpy(device, ent->d_name, sizeof(device));
+ path_decode(device);
+ name_list_add(name_list, device, 0);
+ rc++;
+ }
+ closedir(dir);
+out:
+ return rc;
+}
+
int udev_db_add_device(struct udevice *udev)
{
char filename[PATH_SIZE];
@@ -288,7 +328,7 @@ int udev_db_lookup_name(const char *name, char *devpath, size_t len)
strlcpy(device, ent->d_name, sizeof(device));
path_decode(device);
- udev = udev_device_init();
+ udev = udev_device_init(NULL);
if (udev == NULL)
break;
if (udev_db_get_device(udev, device) == 0) {