]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: use the list of block devices in /proc/devices for decoding SOURCE column
authorMasatake YAMATO <yamato@redhat.com>
Wed, 8 Dec 2021 14:41:52 +0000 (23:41 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Wed, 8 Dec 2021 15:39:38 +0000 (00:39 +0900)
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 <yamato@redhat.com>
misc-utils/lsfd-bdev.c
misc-utils/lsfd.1.adoc
misc-utils/lsfd.c
misc-utils/lsfd.h

index 073a58e1ace0af1fdbcfb1409335e3b3453e2572..442e2ee8c643bcd9db0841138ceca544a5795bd6 100644 (file)
@@ -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",
index 5836d8645fdf338f60d38614f574e8bc9a387d7e..1ac02aa0faad5cd49ee12a8915e1adc9e3c80eb6 100644 (file)
@@ -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_.
 
index 4dec0f80827dde04c74a447f23000ce000857200..73d59bfb6270c182b266a6330d921f5c949f7b7c 100644 (file)
@@ -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,
index 997687939c78e9d66c2a024df8bdac9ae6e7b810..a2c8646655fd0e5dfbbeb543d5cae30a38908df1 100644 (file)
@@ -36,6 +36,7 @@
  */
 enum {
        COL_ASSOC,
+       COL_BLKDRV,
        COL_CHRDRV,
        COL_COMMAND,
        COL_DELETED,