lsblk: remove huge all-function if-condition
Let's make it more readable and easy to extend. Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
24e896c140
commit
d1574dae64
1 changed files with 59 additions and 59 deletions
|
@ -54,6 +54,8 @@ static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *dev
|
||||||
static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
|
static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
|
||||||
{
|
{
|
||||||
struct udev_device *dev;
|
struct udev_device *dev;
|
||||||
|
const char *data;
|
||||||
|
struct lsblk_devprop *prop;
|
||||||
|
|
||||||
if (ld->udev_requested)
|
if (ld->udev_requested)
|
||||||
return ld->properties;
|
return ld->properties;
|
||||||
|
@ -64,72 +66,70 @@ static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
dev = udev_device_new_from_subsystem_sysname(udev, "block", ld->name);
|
dev = udev_device_new_from_subsystem_sysname(udev, "block", ld->name);
|
||||||
if (dev) {
|
if (!dev)
|
||||||
const char *data;
|
goto done;
|
||||||
struct lsblk_devprop *prop;
|
|
||||||
|
|
||||||
if (ld->properties)
|
DBG(DEV, ul_debugobj(ld, "%s: found udev properties", ld->name));
|
||||||
lsblk_device_free_properties(ld->properties);
|
|
||||||
prop = ld->properties = xcalloc(1, sizeof(*ld->properties));
|
|
||||||
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_FS_LABEL_ENC"))) {
|
if (ld->properties)
|
||||||
prop->label = xstrdup(data);
|
lsblk_device_free_properties(ld->properties);
|
||||||
unhexmangle_string(prop->label);
|
prop = ld->properties = xcalloc(1, sizeof(*ld->properties));
|
||||||
}
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_FS_UUID_ENC"))) {
|
|
||||||
prop->uuid = xstrdup(data);
|
|
||||||
unhexmangle_string(prop->uuid);
|
|
||||||
}
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_PART_TABLE_UUID")))
|
|
||||||
prop->ptuuid = xstrdup(data);
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_PART_TABLE_TYPE")))
|
|
||||||
prop->pttype = xstrdup(data);
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME"))) {
|
|
||||||
prop->partlabel = xstrdup(data);
|
|
||||||
unhexmangle_string(prop->partlabel);
|
|
||||||
}
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_FS_TYPE")))
|
|
||||||
prop->fstype = xstrdup(data);
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_FS_VERSION")))
|
|
||||||
prop->fsversion = xstrdup(data);
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_TYPE")))
|
|
||||||
prop->parttype = xstrdup(data);
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_UUID")))
|
|
||||||
prop->partuuid = xstrdup(data);
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_FLAGS")))
|
|
||||||
prop->partflags = xstrdup(data);
|
|
||||||
|
|
||||||
data = udev_device_get_property_value(dev, "ID_WWN_WITH_EXTENSION");
|
if ((data = udev_device_get_property_value(dev, "ID_FS_LABEL_ENC"))) {
|
||||||
if (!data)
|
prop->label = xstrdup(data);
|
||||||
data = udev_device_get_property_value(dev, "ID_WWN");
|
unhexmangle_string(prop->label);
|
||||||
if (data)
|
}
|
||||||
prop->wwn = xstrdup(data);
|
if ((data = udev_device_get_property_value(dev, "ID_FS_UUID_ENC"))) {
|
||||||
|
prop->uuid = xstrdup(data);
|
||||||
|
unhexmangle_string(prop->uuid);
|
||||||
|
}
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_PART_TABLE_UUID")))
|
||||||
|
prop->ptuuid = xstrdup(data);
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_PART_TABLE_TYPE")))
|
||||||
|
prop->pttype = xstrdup(data);
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_NAME"))) {
|
||||||
|
prop->partlabel = xstrdup(data);
|
||||||
|
unhexmangle_string(prop->partlabel);
|
||||||
|
}
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_FS_TYPE")))
|
||||||
|
prop->fstype = xstrdup(data);
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_FS_VERSION")))
|
||||||
|
prop->fsversion = xstrdup(data);
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_TYPE")))
|
||||||
|
prop->parttype = xstrdup(data);
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_UUID")))
|
||||||
|
prop->partuuid = xstrdup(data);
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_PART_ENTRY_FLAGS")))
|
||||||
|
prop->partflags = xstrdup(data);
|
||||||
|
|
||||||
data = udev_device_get_property_value(dev, "SCSI_IDENT_SERIAL"); /* sg3_utils do not use I_D prefix */
|
data = udev_device_get_property_value(dev, "ID_WWN_WITH_EXTENSION");
|
||||||
if (!data)
|
if (!data)
|
||||||
data = udev_device_get_property_value(dev, "ID_SCSI_SERIAL");
|
data = udev_device_get_property_value(dev, "ID_WWN");
|
||||||
if(!data)
|
if (data)
|
||||||
data = udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
|
prop->wwn = xstrdup(data);
|
||||||
if(!data)
|
|
||||||
data = udev_device_get_property_value(dev, "ID_SERIAL");
|
|
||||||
if (data) {
|
|
||||||
prop->serial = xstrdup(data);
|
|
||||||
normalize_whitespace((unsigned char *) prop->serial);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((data = udev_device_get_property_value(dev, "ID_MODEL_ENC"))) {
|
data = udev_device_get_property_value(dev, "SCSI_IDENT_SERIAL"); /* sg3_utils do not use I_D prefix */
|
||||||
prop->model = xstrdup(data);
|
if (!data)
|
||||||
unhexmangle_string(prop->model);
|
data = udev_device_get_property_value(dev, "ID_SCSI_SERIAL");
|
||||||
normalize_whitespace((unsigned char *) prop->model);
|
if(!data)
|
||||||
} else if ((data = udev_device_get_property_value(dev, "ID_MODEL"))) {
|
data = udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
|
||||||
prop->model = xstrdup(data);
|
if(!data)
|
||||||
normalize_whitespace((unsigned char *) prop->model);
|
data = udev_device_get_property_value(dev, "ID_SERIAL");
|
||||||
}
|
if (data) {
|
||||||
|
prop->serial = xstrdup(data);
|
||||||
udev_device_unref(dev);
|
normalize_whitespace((unsigned char *) prop->serial);
|
||||||
DBG(DEV, ul_debugobj(ld, "%s: found udev properties", ld->name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((data = udev_device_get_property_value(dev, "ID_MODEL_ENC"))) {
|
||||||
|
prop->model = xstrdup(data);
|
||||||
|
unhexmangle_string(prop->model);
|
||||||
|
normalize_whitespace((unsigned char *) prop->model);
|
||||||
|
} else if ((data = udev_device_get_property_value(dev, "ID_MODEL"))) {
|
||||||
|
prop->model = xstrdup(data);
|
||||||
|
normalize_whitespace((unsigned char *) prop->model);
|
||||||
|
}
|
||||||
|
|
||||||
|
udev_device_unref(dev);
|
||||||
done:
|
done:
|
||||||
ld->udev_requested = 1;
|
ld->udev_requested = 1;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue