summaryrefslogtreecommitdiff
path: root/libudev/libudev-device.c
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2009-08-19 20:49:49 +0200
committerKay Sievers <kay.sievers@vrfy.org>2009-08-19 20:49:49 +0200
commit2ffc9cc1917b1bb6fe86881a94a47dce9aa15168 (patch)
tree842ba77f43018179ce42e5433ce1c6cd63559c60 /libudev/libudev-device.c
parent24d1fea8bd609f9eb7901efd7cba7f2dee05f557 (diff)
change database file names
With very deeply nested devices, We can not use a single file name to carry an entire DEVPATH. Use <subsystem>:<sysname> as the database filename, which should also simplify the handling of devices moving around, as these values will not change but still be unique. For the name stack we use the <maj>:<min> now as the filename. > On Tue, Aug 18, 2009 at 09:59:56AM -0400, Ric Wheeler wrote: > The first is that udev grumbles during boot about "file name too long" > like the following: > > Aug 17 06:49:58 megadeth udevd-event[20447]: unable to create db file > '/dev/.udev/db/\x2fdevices\x2fpci0000:00\x2f0000:00:04.0\x2f0000:17:00.0\x2f0000:18:0a.0\x2f0000:1f:00.0\x2fhost11\x2fport-11:0\x2fexpander-11:0\x2fport-11:0:0\x2fexpander-11:1\x2fport-11:1:0\x2fexpander-11:2\x2fport-11:2:17\x2fexpander-11:3\x2fport-11:3:1\x2fend_device-11:3:1\x2fbsg\x2fend_device-11:3:1': > File name too long
Diffstat (limited to 'libudev/libudev-device.c')
-rw-r--r--libudev/libudev-device.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/libudev/libudev-device.c b/libudev/libudev-device.c
index eac6bd6041..22d8349275 100644
--- a/libudev/libudev-device.c
+++ b/libudev/libudev-device.c
@@ -51,6 +51,7 @@ struct udev_device {
char *driver;
char *action;
char *devpath_old;
+ char *sysname_old;
char *knodename;
char **envp;
char *monitor_buf;
@@ -76,16 +77,6 @@ struct udev_device {
unsigned int ignore_remove:1;
};
-static size_t devpath_to_db_path(struct udev *udev, const char *devpath, char *filename, size_t len)
-{
- char *s;
- size_t l;
-
- s = filename;
- l = util_strpcpyl(&s, len, udev_get_dev_path(udev), "/.udev/db/", NULL);
- return util_path_encode(devpath, s, l);
-}
-
int udev_device_read_db(struct udev_device *udev_device)
{
struct stat stats;
@@ -93,7 +84,8 @@ int udev_device_read_db(struct udev_device *udev_device)
char line[UTIL_LINE_SIZE];
FILE *f;
- devpath_to_db_path(udev_device->udev, udev_device->devpath, filename, sizeof(filename));
+ util_strscpyl(filename, sizeof(filename), udev_get_dev_path(udev_device->udev), "/.udev/db/",
+ udev_device_get_subsystem(udev_device), ":", udev_device_get_sysname(udev_device), NULL);
if (lstat(filename, &stats) != 0) {
dbg(udev_device->udev, "no db file to read %s: %m\n", filename);
@@ -677,6 +669,7 @@ void udev_device_unref(struct udev_device *udev_device)
free(udev_device->action);
free(udev_device->driver);
free(udev_device->devpath_old);
+ free(udev_device->sysname_old);
free(udev_device->knodename);
udev_list_cleanup_entries(udev_device->udev, &udev_device->sysattr_list);
free(udev_device->envp);
@@ -1282,14 +1275,39 @@ const char *udev_device_get_devpath_old(struct udev_device *udev_device)
int udev_device_set_devpath_old(struct udev_device *udev_device, const char *devpath_old)
{
+ const char *pos;
+ size_t len;
+
free(udev_device->devpath_old);
udev_device->devpath_old = strdup(devpath_old);
if (udev_device->devpath_old == NULL)
return -ENOMEM;
udev_device_add_property(udev_device, "DEVPATH_OLD", udev_device->devpath_old);
+
+ pos = strrchr(udev_device->devpath_old, '/');
+ if (pos == NULL)
+ return -EINVAL;
+ udev_device->sysname_old = strdup(&pos[1]);
+ if (udev_device->sysname_old == NULL)
+ return -ENOMEM;
+
+ /* some devices have '!' in their name, change that to '/' */
+ len = 0;
+ while (udev_device->sysname_old[len] != '\0') {
+ if (udev_device->sysname_old[len] == '!')
+ udev_device->sysname_old[len] = '/';
+ len++;
+ }
return 0;
}
+const char *udev_device_get_sysname_old(struct udev_device *udev_device)
+{
+ if (udev_device == NULL)
+ return NULL;
+ return udev_device->sysname_old;
+}
+
const char *udev_device_get_knodename(struct udev_device *udev_device)
{
return udev_device->knodename;