lsblk: add state attribute

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>
This commit is contained in:
Milan Broz 2011-07-05 23:29:30 +02:00 committed by Karel Zak
parent 872a1575e8
commit 01e487c020
1 changed files with 13 additions and 0 deletions

View 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)