* lsblk(8) - list block devices
*
* Copyright (C) 2010-2018 Red Hat, Inc. All rights reserved.
- * Written by Milan Broz <mbroz@redhat.com>
+ * Written by Milan Broz <gmazyland@gmail.com>
* Karel Zak <kzak@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
COL_DALIGN,
COL_DAX,
COL_DGRAN,
+ COL_DISKSEQ,
COL_DMAX,
COL_DZERO,
COL_FSAVAIL,
COL_OWNER,
COL_PARTFLAGS,
COL_PARTLABEL,
+ COL_PARTN,
COL_PARTTYPE,
COL_PARTTYPENAME,
COL_PARTUUID,
[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 },
+ [COL_DISKSEQ] = { "DISK-SEQ", 1, SCOLS_FL_RIGHT, N_("disk sequence number"), COLTYPE_NUM },
[COL_DMAX] = { "DISC-MAX", 6, SCOLS_FL_RIGHT, N_("discard max bytes"), COLTYPE_SIZE },
[COL_DZERO] = { "DISC-ZERO", 1, SCOLS_FL_RIGHT, N_("discard zeroes data"), COLTYPE_BOOL },
[COL_FSAVAIL] = { "FSAVAIL", 5, SCOLS_FL_RIGHT, N_("filesystem size available"), COLTYPE_SIZE },
[COL_OWNER] = { "OWNER", 0.1, SCOLS_FL_TRUNC, N_("user name"), },
[COL_PARTFLAGS] = { "PARTFLAGS", 36, 0, N_("partition flags") },
[COL_PARTLABEL] = { "PARTLABEL", 0.1, 0, N_("partition LABEL") },
+ [COL_PARTN] = { "PARTN", 2, SCOLS_FL_RIGHT, N_("partition number as read from the partition table"), COLTYPE_NUM },
[COL_PARTTYPENAME] = { "PARTTYPENAME", 0.1, 0, N_("partition type name") },
[COL_PARTTYPE] = { "PARTTYPE", 36, 0, N_("partition type code or UUID") },
[COL_PARTUUID] = { "PARTUUID", 36, 0, N_("partition UUID") },
[COL_START] = { "START", 5, SCOLS_FL_RIGHT, N_("partition start offset"), COLTYPE_NUM },
[COL_STATE] = { "STATE", 7, SCOLS_FL_TRUNC, N_("state of the device") },
[COL_SUBSYS] = { "SUBSYSTEMS", 0.1, SCOLS_FL_NOEXTREMES, N_("de-duplicated chain of subsystems") },
- [COL_TARGETS] = { "MOUNTPOINTS", 0.10, SCOLS_FL_WRAP, N_("all locations where device is mounted") },
- [COL_TARGET] = { "MOUNTPOINT", 0.10, SCOLS_FL_TRUNC, N_("where the device is mounted") },
+ [COL_TARGETS] = { "MOUNTPOINTS", 0.10, SCOLS_FL_WRAP | SCOLS_FL_NOEXTREMES, N_("all locations where device is mounted") },
+ [COL_TARGET] = { "MOUNTPOINT", 0.10, SCOLS_FL_TRUNC | SCOLS_FL_NOEXTREMES, N_("where the device is mounted") },
[COL_TRANSPORT] = { "TRAN", 6, 0, N_("device transport type") },
[COL_TYPE] = { "TYPE", 4, 0, N_("device type") },
[COL_UUID] = { "UUID", 36, 0, N_("filesystem UUID") },
}
/* Thanks to lsscsi code for idea of detection logic used here */
-static char *get_transport(struct lsblk_device *dev)
+static const char *get_transport(struct lsblk_device *dev)
{
struct path_cxt *sysfs = dev->sysfs;
char *attr = NULL;
} else if (strncmp(dev->name, "vd", 2) == 0)
trans = "virtio";
- return trans ? xstrdup(trans) : NULL;
+ return trans;
}
static char *get_subsystems(struct lsblk_device *dev)
static void process_mq(struct lsblk_device *dev, char **str)
{
- DIR *dir;
- struct dirent *d;
unsigned int queues = 0;
DBG(DEV, ul_debugobj(dev, "%s: process mq", dev->name));
- dir = ul_path_opendir(dev->sysfs, "mq");
- if (!dir) {
+ queues = ul_path_count_dirents(dev->sysfs, "mq");
+ if (!queues) {
*str = xstrdup("1");
DBG(DEV, ul_debugobj(dev, "%s: no mq supported, use a single queue", dev->name));
return;
}
- while ((d = xreaddir(dir))) {
- if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
- continue;
-
- queues++;
- }
-
- closedir(dir);
-
DBG(DEV, ul_debugobj(dev, "%s: has %d queues", dev->name, queues));
xasprintf(str, "%3u", queues);
}
if (prop && prop->partflags)
str = xstrdup(prop->partflags);
break;
+ case COL_PARTN:
+ prop = lsblk_device_get_properties(dev);
+ if (prop && prop->partn)
+ str = xstrdup(prop->partn);
+ break;
case COL_WWN:
prop = lsblk_device_get_properties(dev);
if (prop && prop->wwn)
}
break;
case COL_REV:
- if (!device_is_partition(dev) && dev->nslaves == 0)
- ul_path_read_string(dev->sysfs, &str, "device/rev");
+ if (!device_is_partition(dev) && dev->nslaves == 0) {
+ prop = lsblk_device_get_properties(dev);
+ if (prop && prop->revision)
+ str = xstrdup(prop->revision);
+ else
+ ul_path_read_string(dev->sysfs, &str, "device/rev");
+ }
break;
case COL_VENDOR:
if (!device_is_partition(dev) && dev->nslaves == 0)
break;
}
case COL_TRANSPORT:
- str = get_transport(dev);
+ {
+ const char *trans = get_transport(dev);
+ if (trans)
+ str = xstrdup(trans);
break;
+ }
case COL_SUBSYS:
str = get_subsystems(dev);
break;
case COL_MQ:
process_mq(dev, &str);
break;
+ case COL_DISKSEQ:
+ ul_path_read_string(dev->sysfs, &str, "diskseq");
+ if (sortdata)
+ str2u64(str, sortdata);
+ break;
};
return str;
/* ignore non-NVMe devices */
if (lsblk->nvme) {
- char *transport = get_transport(dev);
+ const char *transport = get_transport(dev);
if (!transport || strcmp(transport, "nvme")) {
DBG(DEV, ul_debugobj(dev, "non-nvme device -- ignore"));
/* ignore non-virtio devices */
if (lsblk->virtio) {
- char *transport = get_transport(dev);
+ const char *transport = get_transport(dev);
if (!transport || strcmp(transport, "virtio")) {
DBG(DEV, ul_debugobj(dev, "non-virtio device -- ignore"));
add_uniq_column(COL_TYPE);
add_uniq_column(COL_MODEL);
add_uniq_column(COL_SERIAL);
+ add_uniq_column(COL_REV);
add_uniq_column(COL_TRANSPORT);
add_uniq_column(COL_RQ_SIZE);
+ add_uniq_column(COL_MQ);
break;
case 'v':
lsblk->nodeps = 1;
add_uniq_column(COL_TRANSPORT);
add_uniq_column(COL_SIZE);
add_uniq_column(COL_RQ_SIZE);
+ add_uniq_column(COL_MQ);
break;
case 'T':
force_tree = 1;