-int udev_db_search_name(char *devpath, size_t len, const char *name)
-{
- DIR *dir;
-
- dir = opendir(udev_db_path);
- if (dir == NULL) {
- err("unable to open udev_db '%s'", udev_db_path);
- return -1;
- }
-
- while (1) {
- struct dirent *ent;
- char filename[PATH_SIZE];
- char path[PATH_SIZE];
- char nodename[PATH_SIZE];
- char *bufline;
- char *buf;
- size_t bufsize;
- size_t cur;
- size_t count;
-
- ent = readdir(dir);
- if (ent == NULL || ent->d_name[0] == '\0')
- break;
-
- if (ent->d_name[0] == '.')
- continue;
-
- snprintf(filename, sizeof(filename), "%s/%s", udev_db_path, ent->d_name);
- filename[sizeof(filename)-1] = '\0';
- dbg("looking at '%s'", filename);
-
- if (file_map(filename, &buf, &bufsize) != 0) {
- err("unable to read db file '%s'", filename);
- continue;
- }
-
- cur = 0;
- while (cur < bufsize) {
- count = buf_get_line(buf, bufsize, cur);
- bufline = &buf[cur];
- cur += count+1;
-
- switch(bufline[0]) {
- case 'P':
- if (count > sizeof(path))
- count = sizeof(path);
- strlcpy(path, &bufline[2], count-1);
- break;
- case 'N':
- case 'S':
- if (count > sizeof(nodename))
- count = sizeof(nodename);
- strlcpy(nodename, &bufline[2], count-1);
- dbg("compare '%s' '%s'", nodename, name);
- if (strcmp(nodename, name) == 0) {
- strlcpy(devpath, path, len);
- file_unmap(buf, bufsize);
- closedir(dir);
- return 0;
- }
- break;
- default:
- continue;
- }
- }
- file_unmap(buf, bufsize);
- }
-
- closedir(dir);
- return -1;
-}
-
-int udev_db_dump_names(int (*handler_function)(const char *path, const char *name))