Browse Source

lsblk: make ID-LINK code more readable

Signed-off-by: Karel Zak <kzak@redhat.com>
pull/1664/head
Karel Zak 4 months ago
parent
commit
e054895f4a
  1. 6
      misc-utils/lsblk-properties.c
  2. 10
      misc-utils/lsblk.c
  3. 2
      misc-utils/lsblk.h

6
misc-utils/lsblk-properties.c

@ -36,7 +36,7 @@ void lsblk_device_free_properties(struct lsblk_devprop *p)
free(p->serial);
free(p->model);
free(p->partflags);
free(p->byid);
free(p->idlink);
free(p->mode);
free(p->owner);
@ -150,8 +150,8 @@ static struct lsblk_devprop *get_properties_by_udev(struct lsblk_device *ld)
sz = strlen(name);
if (!len || sz < len) {
len = sz;
free(prop->byid);
prop->byid = xstrdup(name);
free(prop->idlink);
prop->idlink = xstrdup(name);
}
}

10
misc-utils/lsblk.c

@ -66,7 +66,7 @@ static int column_id_to_number(int id);
/* column IDs */
enum {
COL_ALIOFF = 0,
COL_BYID,
COL_IDLINK,
COL_DALIGN,
COL_DAX,
COL_DGRAN,
@ -164,7 +164,7 @@ struct colinfo {
/* columns descriptions */
static struct colinfo infos[] = {
[COL_ALIOFF] = { "ALIGNMENT", 6, SCOLS_FL_RIGHT, N_("alignment offset"), COLTYPE_NUM },
[COL_BYID] = { "ID-LINK", 0.1, SCOLS_FL_NOEXTREMES, N_("udev by-id link") },
[COL_IDLINK] = { "ID-LINK", 0.1, SCOLS_FL_NOEXTREMES, N_("the shortest udev /dev/disk/by-id link name") },
[COL_DALIGN] = { "DISC-ALN", 6, SCOLS_FL_RIGHT, N_("discard alignment offset"), COLTYPE_NUM },
[COL_DAX] = { "DAX", 1, SCOLS_FL_RIGHT, N_("dax-capable device"), COLTYPE_BOOL },
[COL_DGRAN] = { "DISC-GRAN", 6, SCOLS_FL_RIGHT, N_("discard granularity"), COLTYPE_SIZE },
@ -929,10 +929,10 @@ static char *device_get_data(
if (prop && prop->wwn)
str = xstrdup(prop->wwn);
break;
case COL_BYID:
case COL_IDLINK:
prop = lsblk_device_get_properties(dev);
if (prop && prop->byid)
str = xstrdup(prop->byid);
if (prop && prop->idlink)
str = xstrdup(prop->idlink);
break;
case COL_RA:
ul_path_read_string(dev->sysfs, &str, "queue/read_ahead_kb");

2
misc-utils/lsblk.h

@ -75,7 +75,7 @@ struct lsblk_devprop {
char *wwn; /* storage WWN */
char *serial; /* disk serial number */
char *model; /* disk model */
char *byid; /* /dev/disk/by-id/<name> */
char *idlink; /* /dev/disk/by-id/<name> */
/* lsblk specific (for --sysroot only) */
char *owner; /* user name */

Loading…
Cancel
Save