From: Milan Broz Date: Tue, 5 Jul 2011 21:29:30 +0000 (+0200) Subject: lsblk: add state attribute X-Git-Tag: v2.20-rc1~93 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=01e487c02085a2a4efbc8b1475cd22052e32de2d;p=thirdparty%2Futil-linux.git 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 Signed-off-by: Karel Zak --- diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c index b6bc28b7d0..259b77093a 100644 --- a/misc-utils/lsblk.c +++ b/misc-utils/lsblk.c @@ -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)