summaryrefslogtreecommitdiffstats
path: root/atasmart.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2009-04-14 22:11:15 +0200
committerLennart Poettering <lennart@poettering.net>2009-04-14 22:11:15 +0200
commit9da1b3dd07682dcd77320b658a2addc95b6973e8 (patch)
tree29974c011ac398a5d3f1ba3caa7f5b56e9cde564 /atasmart.c
parent7c90816de0a2cd7269b71b50dfcaf1f83e9bb3ac (diff)
don't depend on udev's ID_BUS variable when figuring out device type
Diffstat (limited to 'atasmart.c')
-rw-r--r--atasmart.c62
1 files changed, 25 insertions, 37 deletions
diff --git a/atasmart.c b/atasmart.c
index 2d8b820..456e4d3 100644
--- a/atasmart.c
+++ b/atasmart.c
@@ -1539,7 +1539,6 @@ int sk_disk_smart_parse_attributes(SkDisk *d, SkSmartAttributeParseCallback cb,
}
cb(d, &a, userdata);
-
free(an);
}
@@ -2060,9 +2059,8 @@ int sk_disk_get_size(SkDisk *d, uint64_t *bytes) {
static int disk_find_type(SkDisk *d, dev_t devnum) {
struct udev *udev;
- struct udev_device *dev = NULL;
+ struct udev_device *dev = NULL, *usb;
int r = -1;
- const char *bus;
assert(d);
@@ -2076,44 +2074,34 @@ static int disk_find_type(SkDisk *d, dev_t devnum) {
goto finish;
}
- if (!(bus = udev_device_get_property_value(dev, "ID_BUS")))
- d->type = SK_DISK_TYPE_UNKNOWN;
- else {
- if (strcmp(bus, "ata") == 0)
- d->type = SK_DISK_TYPE_ATA;
- else if (strcmp(bus, "scsi") == 0)
- d->type = SK_DISK_TYPE_ATA_PASSTHROUGH_16;
- else if (strcmp(bus, "usb") == 0) {
- struct udev_device *usb;
- const char *product, *vendor;
- uint32_t pid, vid;
-
- if (!(usb = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device"))) {
- errno = ENODEV;
- goto finish;
- }
+ if ((usb = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device"))) {
+ const char *product, *vendor;
+ uint32_t pid, vid;
- if (!(product = udev_device_get_sysattr_value(usb, "idProduct")) ||
- sscanf(product, "%04x", &pid) != 1) {
- errno = ENODEV;
- goto finish;
- }
+ if (!(product = udev_device_get_sysattr_value(usb, "idProduct")) ||
+ sscanf(product, "%04x", &pid) != 1) {
+ errno = ENODEV;
+ goto finish;
+ }
- if (!(vendor = udev_device_get_sysattr_value(usb, "idVendor")) ||
- sscanf(vendor, "%04x", &vid) != 1) {
- errno = ENODEV;
- goto finish;
- }
+ if (!(vendor = udev_device_get_sysattr_value(usb, "idVendor")) ||
+ sscanf(vendor, "%04x", &vid) != 1) {
+ errno = ENODEV;
+ goto finish;
+ }
- if ((vid == 0x0c0b && pid == 0xb159) ||
- (vid == 0x04fc && pid == 0x0c25))
- d->type = SK_DISK_TYPE_SUNPLUS;
- else
- d->type = SK_DISK_TYPE_ATA_PASSTHROUGH_12;
+ if ((vid == 0x0c0b && pid == 0xb159) ||
+ (vid == 0x04fc && pid == 0x0c25))
+ d->type = SK_DISK_TYPE_SUNPLUS;
+ else
+ d->type = SK_DISK_TYPE_ATA_PASSTHROUGH_12;
- } else
- d->type = SK_DISK_TYPE_UNKNOWN;
- }
+ } else if (udev_device_get_parent_with_subsystem_devtype(dev, "ide", NULL))
+ d->type = SK_DISK_TYPE_ATA;
+ else if (udev_device_get_parent_with_subsystem_devtype(dev, "scsi", NULL))
+ d->type = SK_DISK_TYPE_ATA_PASSTHROUGH_16;
+ else
+ d->type = SK_DISK_TYPE_UNKNOWN;
r = 0;