-#include "tdb.h"
-
-static TDB_CONTEXT *busdb;
-static TDB_CONTEXT *classdb;
-static TDB_CONTEXT *namedb;
-
-/**
- * busdb_record - bus and id are keys to look up name of device
- */
-struct busdb_record {
- char name[NAME_SIZE];
-};
-
-/**
- * classdb_record - class name and class device name used as keys to find
- * device name.
- */
-struct classdb_record {
- char name[NAME_SIZE];
-};
-
-/**
- * namedb_record - device name is key, remaining udevice info stored here.
- */
-struct namedb_record {
- char sysfs_path[PATH_SIZE];
- char class_dev_name[NAME_SIZE];
- char class_name[NAME_SIZE];
- char bus[BUS_SIZE];
- char id[ID_SIZE];
- char driver[NAME_SIZE];
- char type;
- int major;
- int minor;
- int mode;
-};
-
-/**
- * busdb_close: close busdb database
- */
-static void busdb_close(void)
-{
- if (busdb != NULL) {
- tdb_close(busdb);
- busdb = NULL;
- }
-}
-
-/**
- * classdb_close: close classdb database
- */
-static void classdb_close(void)
-{
- if (classdb != NULL) {
- tdb_close(classdb);
- classdb = NULL;
- }
-}
-
-/**
- * namedb_close: close name database
- */
-static void namedb_close(void)
-{
- if (namedb != NULL) {
- tdb_close(namedb);
- namedb = NULL;
- }
-}
-
-/**
- * busdb_open: open busdb's database
- */
-static int busdb_open(void)
-{
- busdb = tdb_open(BUS_DB, 0, 0, O_RDWR | O_CREAT, 0644);
- if (busdb == NULL)
- return -1;
- return 0;
-}
-
-/**
- * classdb_open: open classdb's database
- */
-static int classdb_open(void)
-{
- classdb = tdb_open(CLASS_DB, 0, 0, O_RDWR | O_CREAT, 0644);
- if (classdb == NULL)
- return -1;
- return 0;
-}
-
-/**
- * namedb_open: open name database
- */
-static int namedb_open(void)
-{
- namedb = tdb_open(NAME_DB, 0, 0, O_RDWR | O_CREAT, 0644);
- if (namedb == NULL)
- return -1;
- return 0;
-}
-
-/**
- * busdb_fetch
- */
-static struct busdb_record *busdb_fetch(const char *bus, const char *id)
-{
- TDB_DATA key, data;
- char keystr[BUS_SIZE+ID_SIZE+2];
- struct busdb_record *rec = NULL;
-
- if (bus == NULL || id == NULL)
- return NULL;
- if (strlen(bus) >= BUS_SIZE || strlen(id) >= ID_SIZE)
- return NULL;
-
- if ((busdb_open()) != 0)
- return NULL;
-
- memset(keystr, 0, (BUS_SIZE+ID_SIZE+2));
- strcpy(keystr, bus);
- strcat(keystr, UDEVDB_DEL);
- strcat(keystr, id);