From 57d5ee16fffac5265db6a4d6785116358c16b5ea Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Wed, 8 Dec 2021 23:41:52 +0900 Subject: [PATCH] lsfd: use the list of block devices in /proc/devices for decoding SOURCE column For decoding the SOURCE column of a fd opening a block devices, the origina code uses /proc/partitions only. However, this is not enough for decoding /dev/nullb0. Though is is a block device node, the block device behind the node is not listed in /proc/partitions. This change uses the information min /proc/devices as the fallback of /proc/partitions. Signed-off-by: Masatake YAMATO --- misc-utils/lsfd-bdev.c | 16 +++++++++++++++- misc-utils/lsfd.1.adoc | 3 +++ misc-utils/lsfd.c | 2 ++ misc-utils/lsfd.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/misc-utils/lsfd-bdev.c b/misc-utils/lsfd-bdev.c index 073a58e1ac..442e2ee8c6 100644 --- a/misc-utils/lsfd-bdev.c +++ b/misc-utils/lsfd-bdev.c @@ -40,13 +40,21 @@ static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)), size_t column_index) { char *str = NULL; - const char *partition; + const char *partition, *devdrv; switch(column_id) { case COL_TYPE: if (scols_line_set_data(ln, column_index, "BLK")) err(EXIT_FAILURE, _("failed to add output data")); return true; + case COL_BLKDRV: + devdrv = get_blkdrv(major(file->stat.st_rdev)); + if (devdrv) + str = strdup(devdrv); + else + xasprintf(&str, "%u", + major(file->stat.st_rdev)); + break; case COL_DEVTYPE: if (scols_line_set_data(ln, column_index, "blk")) @@ -59,6 +67,12 @@ static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)), str = strdup(partition); break; } + devdrv = get_blkdrv(major(file->stat.st_rdev)); + if (devdrv) { + xasprintf(&str, "%s:%u", devdrv, + minor(file->stat.st_rdev)); + break; + } /* FALL THROUGH */ case COL_MAJMIN: xasprintf(&str, "%u:%u", diff --git a/misc-utils/lsfd.1.adoc b/misc-utils/lsfd.1.adoc index 5836d8645f..1ac02aa0fa 100644 --- a/misc-utils/lsfd.1.adoc +++ b/misc-utils/lsfd.1.adoc @@ -119,6 +119,9 @@ They may be changed in the future releases. ASSOC <__string__>:: Association between file and process. +BLKDRV <__string__>:: +Block device driver name resolved by _/proc/devices_. + CHRDRV <__string__>:: Character device driver name resolved by _/proc/devices_. diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 4dec0f8082..73d59bfb62 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -109,6 +109,8 @@ struct colinfo { static struct colinfo infos[] = { [COL_ASSOC] = { "ASSOC", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("association between file and process") }, + [COL_BLKDRV] = { "BLKDRV", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, + N_("block device driver name resolved by /proc/devices") }, [COL_CHRDRV] = { "CHRDRV", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, N_("character device driver name resolved by /proc/devices") }, [COL_COMMAND] = { "COMMAND",0.3, SCOLS_FL_TRUNC, SCOLS_JSON_STRING, diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 997687939c..a2c8646655 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -36,6 +36,7 @@ */ enum { COL_ASSOC, + COL_BLKDRV, COL_CHRDRV, COL_COMMAND, COL_DELETED, -- 2.47.3