]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/lsblk-properties.c
findmnt: keep it easy for static analyzers
[thirdparty/util-linux.git] / misc-utils / lsblk-properties.c
index 10a9846e5b65f18bf2ca831949245b6b7ae33fdb..530332fec8e2e198ccc46c072852cdd861bc4959 100644 (file)
@@ -36,18 +36,18 @@ void lsblk_device_free_properties(struct lsblk_devprop *p)
 }
 
 #ifndef HAVE_LIBUDEV
-static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt
+static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *dev
                                __attribute__((__unused__)))
 {
        return NULL;
 }
 #else
-static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt)
+static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
 {
        struct udev_device *dev;
 
-       if (cxt->udev_requested)
-               return cxt->properties;
+       if (ld->udev_requested)
+               return ld->properties;
 
        if (lsblk->sysroot)
                goto done;
@@ -56,14 +56,14 @@ static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt)
        if (!udev)
                goto done;
 
-       dev = udev_device_new_from_subsystem_sysname(udev, "block", cxt->name);
+       dev = udev_device_new_from_subsystem_sysname(udev, "block", ld->name);
        if (dev) {
                const char *data;
                struct lsblk_devprop *prop;
 
-               if (cxt->properties)
-                       lsblk_device_free_properties(cxt->properties);
-               prop = cxt->properties = xcalloc(1, sizeof(*cxt->properties));
+               if (ld->properties)
+                       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"))) {
                        prop->label = xstrdup(data);
@@ -96,34 +96,38 @@ static struct lsblk_devprop *get_properties_by_udev(struct blkdev_cxt *cxt)
                if (data)
                        prop->wwn = xstrdup(data);
 
-               if ((data = udev_device_get_property_value(dev, "ID_SERIAL_SHORT")))
+               data = udev_device_get_property_value(dev, "ID_SCSI_SERIAL");
+               if(!data)
+                       data = udev_device_get_property_value(dev, "ID_SERIAL_SHORT");
+               if (data)
                        prop->serial = xstrdup(data);
+
                if ((data = udev_device_get_property_value(dev, "ID_MODEL")))
                        prop->model = xstrdup(data);
 
                udev_device_unref(dev);
-               DBG(DEV, ul_debugobj(cxt, "%s: found udev properties", cxt->name));
+               DBG(DEV, ul_debugobj(ld, "%s: found udev properties", ld->name));
        }
 
 done:
-       cxt->udev_requested = 1;
-       return cxt->properties;
+       ld->udev_requested = 1;
+       return ld->properties;
 }
 #endif /* HAVE_LIBUDEV */
 
-static struct lsblk_devprop *get_properties_by_blkid(struct blkdev_cxt *cxt)
+static struct lsblk_devprop *get_properties_by_blkid(struct lsblk_device *dev)
 {
        blkid_probe pr = NULL;
 
-       if (cxt->blkid_requested)
-               return cxt->properties;
+       if (dev->blkid_requested)
+               return dev->properties;
 
-       if (!cxt->size)
+       if (!dev->size)
                goto done;
        if (getuid() != 0)
                goto done;;                             /* no permissions to read from the device */
 
-       pr = blkid_new_probe_from_filename(cxt->filename);
+       pr = blkid_new_probe_from_filename(dev->filename);
        if (!pr)
                goto done;
 
@@ -138,9 +142,9 @@ static struct lsblk_devprop *get_properties_by_blkid(struct blkdev_cxt *cxt)
                const char *data = NULL;
                struct lsblk_devprop *prop;
 
-               if (cxt->properties)
-                       lsblk_device_free_properties(cxt->properties);
-               prop = cxt->properties = xcalloc(1, sizeof(*cxt->properties));
+               if (dev->properties)
+                       lsblk_device_free_properties(dev->properties);
+               prop = dev->properties = xcalloc(1, sizeof(*dev->properties));
 
                if (!blkid_probe_lookup_value(pr, "TYPE", &data, NULL))
                        prop->fstype = xstrdup(data);
@@ -161,22 +165,22 @@ static struct lsblk_devprop *get_properties_by_blkid(struct blkdev_cxt *cxt)
                if (!blkid_probe_lookup_value(pr, "PART_ENTRY_FLAGS", &data, NULL))
                        prop->partflags = xstrdup(data);
 
-               DBG(DEV, ul_debugobj(cxt, "%s: found blkid properties", cxt->name));
+               DBG(DEV, ul_debugobj(dev, "%s: found blkid properties", dev->name));
        }
 
 done:
        blkid_free_probe(pr);
 
-       cxt->blkid_requested = 1;
-       return cxt->properties;
+       dev->blkid_requested = 1;
+       return dev->properties;
 }
 
-struct lsblk_devprop *lsblk_device_get_properties(struct blkdev_cxt *cxt)
+struct lsblk_devprop *lsblk_device_get_properties(struct lsblk_device *dev)
 {
-       struct lsblk_devprop *p = get_properties_by_udev(cxt);
+       struct lsblk_devprop *p = get_properties_by_udev(dev);
 
        if (!p)
-               p = get_properties_by_blkid(cxt);
+               p = get_properties_by_blkid(dev);
        return p;
 }