From: Masatake YAMATO Date: Fri, 7 May 2021 18:28:46 +0000 (+0900) Subject: lsfd: add PARTITION column X-Git-Tag: v2.38-rc1~144^2~140 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b3a23f4d3a536101175390bd5d5899ae1468f5d1;p=thirdparty%2Futil-linux.git lsfd: add PARTITION column Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-bdev.c b/misc-utils/lsfd-bdev.c index 56fa6dbfb6..d5e8e12ade 100644 --- a/misc-utils/lsfd-bdev.c +++ b/misc-utils/lsfd-bdev.c @@ -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), diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index 2bc0ee5157..c832af39c4 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -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", diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index cc6adc78ff..c82faf0384 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -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, diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index b07bd4b9e4..b7dc585e41 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -63,6 +63,7 @@ enum { COL_MODE, COL_NAME, COL_NLINK, + COL_PARTITION, COL_PID, COL_POS, COL_PROTONAME,