]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsblk: add state attribute
authorMilan Broz <mbroz@redhat.com>
Tue, 5 Jul 2011 21:29:30 +0000 (23:29 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 15 Jul 2011 13:35:10 +0000 (15:35 +0200)
Add device state column. For normal disk it could be running or offline,
for device-mapper devices running or suspended.

Signed-off-by: Milan Broz <mbroz@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
misc-utils/lsblk.c

index b6bc28b7d0eeb2c41c1ec98169cfff8f0a81fb7f..259b77093a70f30a3d3a7476e19c958c23228808 100644 (file)
@@ -67,6 +67,7 @@ enum {
        COL_RM,
        COL_MODEL,
        COL_SIZE,
+       COL_STATE,
        COL_OWNER,
        COL_GROUP,
        COL_MODE,
@@ -108,6 +109,7 @@ static struct colinfo infos[__NCOLUMNS] = {
        [COL_ROTA]   = { "ROTA",    1, TT_FL_RIGHT, N_("rotational device") },
        [COL_MODEL]  = { "MODEL",   0.1, TT_FL_TRUNC, N_("device identifier") },
        [COL_SIZE]   = { "SIZE",    6, TT_FL_RIGHT, N_("size of the device") },
+       [COL_STATE]  = { "STATE",   7, TT_FL_TRUNC, N_("state of the device") },
        [COL_OWNER]  = { "OWNER",   0.1, TT_FL_TRUNC, N_("user name"), },
        [COL_GROUP]  = { "GROUP",   0.1, TT_FL_TRUNC, N_("group name") },
        [COL_MODE]   = { "MODE",    10,   0, N_("device node permissions") },
@@ -522,6 +524,17 @@ static void set_tt_data(struct blkdev_cxt *cxt, int col, int id, struct tt_line
                                tt_line_set_data(ln, col, p);
                }
                break;
+       case COL_STATE:
+               if (!cxt->partition && !cxt->dm_name) {
+                       p = sysfs_strdup(&cxt->sysfs, "device/state");
+               } else if (cxt->dm_name) {
+                       int x = 0;
+                       if (sysfs_read_int(&cxt->sysfs, "dm/suspended", &x) == 0)
+                               p = x ? xstrdup("suspended") : xstrdup("running");
+               }
+               if (p)
+                       tt_line_set_data(ln, col, p);
+               break;
        case COL_ALIOFF:
                p = sysfs_strdup(&cxt->sysfs, "alignment_offset");
                if (p)