]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add PARTITION column
authorMasatake YAMATO <yamato@redhat.com>
Fri, 7 May 2021 18:28:46 +0000 (03:28 +0900)
committerKarel Zak <kzak@redhat.com>
Wed, 6 Oct 2021 09:01:53 +0000 (11:01 +0200)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lsfd-bdev.c
misc-utils/lsfd-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index 56fa6dbfb6f9c498e56c70a20034fa0c535fa3eb..d5e8e12ade2b1fd226d065754b85cf44f86eb03d 100644 (file)
@@ -40,11 +40,20 @@ static bool bdev_fill_column(struct proc *proc __attribute__((__unused__)),
                             size_t column_index)
 {
        char *str = NULL;
+       const char *partition;
+
        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_PARTITION:
+               partition = get_partition(file->stat.st_rdev);
+               if (partition) {
+                       str = strdup(partition);
+                       break;
+               }
+               /* FALL THROUGH */
        case COL_DEVICE:
                xasprintf(&str, "%u:%u",
                          major(file->stat.st_rdev),
index 2bc0ee51575444c54733b25d8c90e997a90ef440..c832af39c45084da015e2c4e32d9b968e8c86a58 100644 (file)
@@ -180,6 +180,7 @@ static bool file_fill_column(struct proc *proc,
 {
        char *str = NULL;
        mode_t ftype;
+       const char *partition;
 
        switch(column_id) {
        case COL_COMMAND:
@@ -221,6 +222,13 @@ static bool file_fill_column(struct proc *proc,
        case COL_INODE:
                xasprintf(&str, "%llu", (unsigned long long)file->stat.st_ino);
                break;
+       case COL_PARTITION:
+               partition = get_partition(file->stat.st_dev);
+               if (partition) {
+                       str = strdup(partition);
+                       break;
+               }
+               /* FALL THROUGH */
        case COL_DEV:
        case COL_DEVICE:
                xasprintf(&str, "%u:%u",
index cc6adc78ff5b58ddd91cff4ab0bf157e01e1c616..c82faf038419e7e00525cd0fe0e9e36f76d28d15 100644 (file)
@@ -115,6 +115,8 @@ static struct colinfo infos[] = {
                N_("link count") },
        [COL_PID]     = { "PID",      5, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
                N_("PID of the process opening the file") },
+       [COL_PARTITION]={ "PARTITION",0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
+               N_("block device name resolved by /proc/partition") },
        [COL_POS]     = { "POS",      5, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER,
                N_("file position") },
        [COL_PROTONAME]={ "PROTONAME",0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING,
index b07bd4b9e49098b25d4057ff1d76d46ef18d384b..b7dc585e413d5ada1248ef1919ce6fa68720c919 100644 (file)
@@ -63,6 +63,7 @@ enum {
        COL_MODE,
        COL_NAME,
        COL_NLINK,
+       COL_PARTITION,
        COL_PID,
        COL_POS,
        COL_PROTONAME,