chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
4ad47b2
)
sysfs: handle bus/class top-level directories
author
Kay Sievers
<kay.sievers@vrfy.org>
Mon, 4 Jun 2007 08:50:05 +0000
(10:50 +0200)
committer
Kay Sievers
<kay.sievers@vrfy.org>
Mon, 4 Jun 2007 08:50:05 +0000
(10:50 +0200)
udev_sysfs.c
patch
|
blob
|
history
diff --git
a/udev_sysfs.c
b/udev_sysfs.c
index 98be9a5352e9f7807ce6c4c72a24d925389f04ff..6e6f16c16fd2266b42b52c33926518a93f30f2b3 100644
(file)
--- a/
udev_sysfs.c
+++ b/
udev_sysfs.c
@@
-215,7
+215,7
@@
struct sysfs_device *sysfs_device_get(const char *devpath)
if (pos != NULL)
pos[0] = '\0';
else
if (pos != NULL)
pos[0] = '\0';
else
-
dev->subsystem[0] = '\0'
;
+
strlcpy(dev->subsystem, "subsystem", sizeof(dev->subsystem))
;
} else if (strncmp(dev->devpath, "/block/", 7) == 0) {
strlcpy(dev->subsystem, "block", sizeof(dev->subsystem));
} else if (strncmp(dev->devpath, "/devices/", 9) == 0) {
} else if (strncmp(dev->devpath, "/block/", 7) == 0) {
strlcpy(dev->subsystem, "block", sizeof(dev->subsystem));
} else if (strncmp(dev->devpath, "/devices/", 9) == 0) {
@@
-235,6
+235,14
@@
struct sysfs_device *sysfs_device_get(const char *devpath)
strlcpy(dev->subsystem, "drivers", sizeof(dev->subsystem));
} else if (strncmp(dev->devpath, "/module/", 8) == 0) {
strlcpy(dev->subsystem, "module", sizeof(dev->subsystem));
strlcpy(dev->subsystem, "drivers", sizeof(dev->subsystem));
} else if (strncmp(dev->devpath, "/module/", 8) == 0) {
strlcpy(dev->subsystem, "module", sizeof(dev->subsystem));
+ } else if (strncmp(dev->devpath, "/subsystem/", 11) == 0) {
+ pos = strrchr(dev->devpath, '/');
+ if (pos == &dev->devpath[10])
+ strlcpy(dev->subsystem, "subsystem", sizeof(dev->subsystem));
+ } else if (strncmp(dev->devpath, "/bus/", 5) == 0) {
+ pos = strrchr(dev->devpath, '/');
+ if (pos == &dev->devpath[4])
+ strlcpy(dev->subsystem, "subsystem", sizeof(dev->subsystem));
}
/* get driver name */
}
/* get driver name */
@@
-267,9
+275,10
@@
struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev)
if (dev->parent != NULL)
return dev->parent;
if (dev->parent != NULL)
return dev->parent;
- /* requesting a parent is only valid for
devic
es */
+ /* requesting a parent is only valid for
these devpath
es */
if ((strncmp(dev->devpath, "/devices/", 9) != 0) &&
(strncmp(dev->devpath, "/subsystem/", 11) != 0) &&
if ((strncmp(dev->devpath, "/devices/", 9) != 0) &&
(strncmp(dev->devpath, "/subsystem/", 11) != 0) &&
+ (strncmp(dev->devpath, "/bus/", 5) != 0) &&
(strncmp(dev->devpath, "/class/", 7) != 0) &&
(strncmp(dev->devpath, "/block/", 7) != 0))
return NULL;
(strncmp(dev->devpath, "/class/", 7) != 0) &&
(strncmp(dev->devpath, "/block/", 7) != 0))
return NULL;
@@
-283,20
+292,6
@@
struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev)
return NULL;
pos[0] = '\0';
return NULL;
pos[0] = '\0';
- /* are we at the top level of /devices */
- if (strcmp(parent_devpath, "/devices") == 0) {
- dbg("/devices top level");
- return NULL;
- }
-
- /* at the subsystems top level we want to follow the old-style "device" link */
- if (strncmp(parent_devpath, "/subsystem", 10) == 0) {
- pos = strrchr(parent_devpath, '/');
- if (pos == &parent_devpath[10] || pos == parent_devpath || strcmp(pos, "/devices") == 0) {
- dbg("/subsystem top level, look for device link");
- goto device_link;
- }
- }
if (strncmp(parent_devpath, "/class", 6) == 0) {
pos = strrchr(parent_devpath, '/');
if (pos == &parent_devpath[6] || pos == parent_devpath) {
if (strncmp(parent_devpath, "/class", 6) == 0) {
pos = strrchr(parent_devpath, '/');
if (pos == &parent_devpath[6] || pos == parent_devpath) {
@@
-309,6
+304,11
@@
struct sysfs_device *sysfs_device_get_parent(struct sysfs_device *dev)
goto device_link;
}
goto device_link;
}
+ /* are we at the top level? */
+ pos = strrchr(parent_devpath, '/');
+ if (pos == NULL || pos == parent_devpath)
+ return NULL;
+
/* get parent and remember it */
dev->parent = sysfs_device_get(parent_devpath);
return dev->parent;
/* get parent and remember it */
dev->parent = sysfs_device_get(parent_devpath);
return dev->parent;