diff options
-rw-r--r-- | hscript/disk.cc | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/hscript/disk.cc b/hscript/disk.cc index 446714e..3fdeb2a 100644 --- a/hscript/disk.cc +++ b/hscript/disk.cc @@ -97,25 +97,23 @@ bool DiskId::execute() const { if(!script->options().test(InstallEnvironment)) return true; #ifdef HAS_INSTALL_ENV - struct udev *udev; - struct udev_device *device; - const char *serial; struct stat blk_stat; - const char *block_c = _block.c_str(); - if(stat(block_c, &blk_stat) != 0) { + if(stat(_block.c_str(), &blk_stat) != 0) { output_error(pos, "diskid: error opening device " + _block, strerror(errno)); return false; } assert(S_ISBLK(blk_stat.st_mode)); - udev = udev_new(); + struct udev *udev = udev_new(); if(!udev) { output_error(pos, "diskid: failed to communicate with udevd", "cannot read disk information"); return false; } - device = udev_device_new_from_devnum(udev, 'b', blk_stat.st_rdev); + + struct udev_device *device = + udev_device_new_from_devnum(udev, 'b', blk_stat.st_rdev); if(!device) { udev_unref(udev); output_error(pos, "diskid: failed to retrieve disk from udevd", @@ -123,14 +121,19 @@ bool DiskId::execute() const { return false; } - serial = udev_device_get_property_value(device, "ID_SERIAL"); - /* If we can't get the serial for this device, it's not a disk */ - if(serial) { - std::string full_str(serial); - match = (full_str.find(_ident) != std::string::npos); - } else { - output_error(pos, "diskid: failed to retrieve disk identification", - "cannot read disk information"); + const char *value; + for(const auto &prop : {"ID_SERIAL", "ID_MODEL_ENC"}) { + value = udev_device_get_property_value(device, prop); + /* If we can't get the serial for this device, it's not a disk */ + if(value) { + std::string full_str(value); + match = (full_str.find(_ident) != std::string::npos); + } else { + output_error(pos, "diskid: failed to retrieve disk identification", + "cannot read disk information"); + } + + if(match) break; } if(!match) { |