chiark / gitweb /
[PATCH] added udev vs devfs supid document to the tree.
[elogind.git] / udevdb.c
index 5be3c2515126efb327d2276bbaddfbdb98963597..0f9de661a4916a4bbd92a862b0670a1064db6356 100644 (file)
--- a/udevdb.c
+++ b/udevdb.c
@@ -62,29 +62,22 @@ int udevdb_add_dev(const char *path, const struct udevice *dev)
        return tdb_store(udevdb, key, data, TDB_REPLACE); 
 }
 
-struct udevice *udevdb_get_dev(const char *path)
+int udevdb_get_dev(const char *path, struct udevice *dev)
 {
        TDB_DATA key, data;
-       struct udevice *dev;
 
        if (path == NULL)
-               return NULL;
+               return -ENODEV;
 
        key.dptr = (void *)path;
        key.dsize = strlen(path) + 1;
 
        data = tdb_fetch(udevdb, key);
        if (data.dptr == NULL || data.dsize == 0)
-               return NULL;
-
-       dev = malloc(sizeof(*dev));
-       if (dev == NULL)
-               goto exit;
+               return -ENODEV;
 
        memcpy(dev, data.dptr, sizeof(*dev));
-exit:
-       free(data.dptr);
-       return dev;
+       return 0;
 }
 
 int udevdb_delete_dev(const char *path)
@@ -135,3 +128,16 @@ int udevdb_init(int init_flag)
        }
        return 0;
 }
+
+/**
+ * udevdb_init: open database for reading
+ */
+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 -EINVAL;
+       }
+       return 0;
+}