don't store devpath in udevdb, we don't need it

Signed-off-by: Kay Sievers <kay.sievers@suse.de>
This commit is contained in:
Kay Sievers 2005-08-27 23:27:43 +02:00
parent fb17920701
commit 7104c558da
4 changed files with 30 additions and 39 deletions

View File

@ -39,10 +39,11 @@
#define PATH_TO_NAME_CHAR '@' #define PATH_TO_NAME_CHAR '@'
static int get_db_filename(const char *devpath, char *filename, size_t len) static int devpath_to_db_path(const char *devpath, char *filename, size_t len)
{ {
size_t start, end, i; size_t start, end, i;
/* add location of db files */
start = strlcpy(filename, udev_db_path, len); start = strlcpy(filename, udev_db_path, len);
end = strlcat(filename, devpath, len); end = strlcat(filename, devpath, len);
if (end > len) if (end > len)
@ -56,6 +57,21 @@ static int get_db_filename(const char *devpath, char *filename, size_t len)
return 0; return 0;
} }
static int db_file_to_devpath(const char *filename, char *devpath, size_t len)
{
size_t end, i;
strlcpy(devpath, "/", len);
end = strlcat(devpath, filename, len);
/* replace PATH_TO_NAME_CHAR to transform name into devpath */
for (i = 1; i < end; i++)
if (devpath[i] == PATH_TO_NAME_CHAR)
devpath[i] = '/';
return 0;
}
int udev_db_add_device(struct udevice *udev) int udev_db_add_device(struct udevice *udev)
{ {
char filename[PATH_SIZE]; char filename[PATH_SIZE];
@ -75,7 +91,7 @@ int udev_db_add_device(struct udevice *udev)
goto exit; goto exit;
} }
get_db_filename(udev->devpath, filename, sizeof(filename)); devpath_to_db_path(udev->devpath, filename, sizeof(filename));
create_path(filename); create_path(filename);
f = fopen(filename, "w"); f = fopen(filename, "w");
if (f == NULL) { if (f == NULL) {
@ -84,7 +100,6 @@ int udev_db_add_device(struct udevice *udev)
} }
dbg("storing data for device '%s' in '%s'", udev->devpath, filename); dbg("storing data for device '%s' in '%s'", udev->devpath, filename);
fprintf(f, "P:%s\n", udev->devpath);
fprintf(f, "N:%s\n", udev->name); fprintf(f, "N:%s\n", udev->name);
list_for_each_entry(name_loop, &udev->symlink_list, node) list_for_each_entry(name_loop, &udev->symlink_list, node)
fprintf(f, "S:%s\n", name_loop->name); fprintf(f, "S:%s\n", name_loop->name);
@ -101,8 +116,9 @@ exit:
return 0; return 0;
} }
static int parse_db_file(struct udevice *udev, const char *filename) int udev_db_get_device(struct udevice *udev, const char *devpath)
{ {
char filename[PATH_SIZE];
char line[PATH_SIZE]; char line[PATH_SIZE];
unsigned int major, minor; unsigned int major, minor;
char *bufline; char *bufline;
@ -111,11 +127,13 @@ static int parse_db_file(struct udevice *udev, const char *filename)
size_t cur; size_t cur;
size_t count; size_t count;
devpath_to_db_path(devpath, filename, sizeof(filename));
if (file_map(filename, &buf, &bufsize) != 0) { if (file_map(filename, &buf, &bufsize) != 0) {
dbg("no db file to read '%s'", filename); dbg("no db file to read '%s'", filename);
return -1; return -1;
} }
strlcpy(udev->devpath, devpath, sizeof(udev->devpath));
cur = 0; cur = 0;
while (cur < bufsize) { while (cur < bufsize) {
count = buf_get_line(buf, bufsize, cur); count = buf_get_line(buf, bufsize, cur);
@ -123,12 +141,6 @@ static int parse_db_file(struct udevice *udev, const char *filename)
cur += count+1; cur += count+1;
switch(bufline[0]) { switch(bufline[0]) {
case 'P':
if (count > sizeof(udev->devpath))
count = sizeof(udev->devpath);
memcpy(udev->devpath, &bufline[2], count-2);
udev->devpath[count-2] = '\0';
break;
case 'N': case 'N':
if (count > sizeof(udev->name)) if (count > sizeof(udev->name))
count = sizeof(udev->name); count = sizeof(udev->name);
@ -185,27 +197,15 @@ int udev_db_delete_device(struct udevice *udev)
{ {
char filename[PATH_SIZE]; char filename[PATH_SIZE];
get_db_filename(udev->devpath, filename, sizeof(filename)); devpath_to_db_path(udev->devpath, filename, sizeof(filename));
unlink(filename); unlink(filename);
return 0; return 0;
} }
int udev_db_get_device(struct udevice *udev, const char *devpath) int udev_db_lookup_name(const char *name, char *devpath, size_t len)
{
char filename[PATH_SIZE];
get_db_filename(devpath, filename, sizeof(filename));
if (parse_db_file(udev, filename) != 0)
return -1;
return 0;
}
int udev_db_search_name(const char *name, char *devpath, size_t len)
{ {
DIR *dir; DIR *dir;
char path[PATH_SIZE];
int found = 0; int found = 0;
dir = opendir(udev_db_path); dir = opendir(udev_db_path);
@ -227,7 +227,6 @@ int udev_db_search_name(const char *name, char *devpath, size_t len)
ent = readdir(dir); ent = readdir(dir);
if (ent == NULL || ent->d_name[0] == '\0') if (ent == NULL || ent->d_name[0] == '\0')
break; break;
if (ent->d_name[0] == '.') if (ent->d_name[0] == '.')
continue; continue;
@ -247,12 +246,6 @@ int udev_db_search_name(const char *name, char *devpath, size_t len)
cur += count+1; cur += count+1;
switch(bufline[0]) { switch(bufline[0]) {
case 'P':
if (count > sizeof(path))
count = sizeof(path);
memcpy(path, &bufline[2], count-2);
path[count-2] = '\0';
break;
case 'N': case 'N':
case 'S': case 'S':
if (count > sizeof(nodename)) if (count > sizeof(nodename))
@ -261,8 +254,8 @@ int udev_db_search_name(const char *name, char *devpath, size_t len)
nodename[count-2] = '\0'; nodename[count-2] = '\0';
dbg("compare '%s' '%s'", nodename, name); dbg("compare '%s' '%s'", nodename, name);
if (strcmp(nodename, name) == 0) { if (strcmp(nodename, name) == 0) {
db_file_to_devpath(ent->d_name, devpath, len);
found = 1; found = 1;
break;
} }
break; break;
default: default:
@ -273,10 +266,9 @@ int udev_db_search_name(const char *name, char *devpath, size_t len)
} }
closedir(dir); closedir(dir);
if (found) { if (found)
strlcpy(devpath, path, len);
return 0; return 0;
} else else
return -1; return -1;
} }
@ -298,7 +290,6 @@ int udev_db_get_all_entries(struct list_head *name_list)
ent = readdir(dir); ent = readdir(dir);
if (ent == NULL || ent->d_name[0] == '\0') if (ent == NULL || ent->d_name[0] == '\0')
break; break;
if (ent->d_name[0] == '.') if (ent->d_name[0] == '.')
continue; continue;

View File

@ -27,7 +27,7 @@ extern int udev_db_add_device(struct udevice *dev);
extern int udev_db_delete_device(struct udevice *dev); extern int udev_db_delete_device(struct udevice *dev);
extern int udev_db_get_device(struct udevice *udev, const char *devpath); extern int udev_db_get_device(struct udevice *udev, const char *devpath);
extern int udev_db_search_name(const char *name, char *devpath, size_t len); extern int udev_db_lookup_name(const char *name, char *devpath, size_t len);
extern int udev_db_get_all_entries(struct list_head *name_list); extern int udev_db_get_all_entries(struct list_head *name_list);
#endif /* _UDEV_DB_H_ */ #endif /* _UDEV_DB_H_ */

View File

@ -279,7 +279,7 @@ static int find_free_number(const char *name, const char *devpath)
strlcpy(filename, name, sizeof(filename)); strlcpy(filename, name, sizeof(filename));
while (1) { while (1) {
dbg("look for existing node '%s'", filename); dbg("look for existing node '%s'", filename);
if (udev_db_search_name(filename, db_devpath, sizeof(db_devpath)) != 0) { if (udev_db_lookup_name(filename, db_devpath, sizeof(db_devpath)) != 0) {
dbg("free num=%d", num); dbg("free num=%d", num);
break; break;
} }

View File

@ -319,7 +319,7 @@ int main(int argc, char *argv[], char *envp[])
} else } else
pos = name; pos = name;
retval = udev_db_search_name(pos, devpath, sizeof(devpath)); retval = udev_db_lookup_name(pos, devpath, sizeof(devpath));
if (retval != 0) { if (retval != 0) {
fprintf(stderr, "no record for '%s' in database\n", pos); fprintf(stderr, "no record for '%s' in database\n", pos);
goto exit; goto exit;