From d40b7b4f9282df45e0f7e255c11c087c553399f0 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Tue, 12 Oct 2021 06:42:37 +0900 Subject: [PATCH] lsfd: add FUID and OWNER columns UID and USER is for processes. FUID and OWNER is for owners of files. Signed-off-by: Masatake YAMATO --- misc-utils/lsfd-file.c | 10 ++++++++++ misc-utils/lsfd.1.adoc | 6 ++++++ misc-utils/lsfd.c | 4 ++++ misc-utils/lsfd.h | 6 ++++-- 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index e609d67091..9b860340dc 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -224,6 +224,13 @@ static bool file_fill_column(struct proc *proc, (int)proc->uid)->name)) err(EXIT_FAILURE, _("failed to add output data")); return true; + case COL_OWNER: + add_uid(username_cache, (int)file->stat.st_uid); + if (scols_line_set_data(ln, column_index, + get_id(username_cache, + (int)file->stat.st_uid)->name)) + err(EXIT_FAILURE, _("failed to add output data")); + return true; case COL_DEVTYPE: if (scols_line_set_data(ln, column_index, "nodev")) @@ -282,6 +289,9 @@ static bool file_fill_column(struct proc *proc, case COL_UID: xasprintf(&str, "%d", (int)proc->uid); break; + case COL_FUID: + xasprintf(&str, "%d", (int)file->stat.st_uid); + break; case COL_SIZE: xasprintf(&str, "%ju", file->stat.st_size); break; diff --git a/misc-utils/lsfd.1.adoc b/misc-utils/lsfd.1.adoc index 56b8c01ffd..364d2450ba 100644 --- a/misc-utils/lsfd.1.adoc +++ b/misc-utils/lsfd.1.adoc @@ -89,6 +89,9 @@ File descriptor for the file. FLAGS:: Flags specified when opening the file. +FUID:: +User ID number of the file's owner. + INODE:: Inode number. @@ -113,6 +116,9 @@ Name of the file. NLINK:: Link count. +OWNER:: +Owner of the file. + PARTITION:: Block device name resolved by _/proc/partition_. diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index cf2a1497db..251456f9b3 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -104,6 +104,8 @@ static struct colinfo infos[] = { N_("flags specified when opening the file") }, [COL_FD] = { "FD", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("file descriptor for the file") }, + [COL_FUID] = { "FUID", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, + N_("user ID number of the file's owner") }, [COL_INODE] = { "INODE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("inode number") }, [COL_MAJMIN] = { "MAJ:MIN", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, @@ -120,6 +122,8 @@ static struct colinfo infos[] = { N_("name of the file") }, [COL_NLINK] = { "NLINK", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("link count") }, + [COL_OWNER] = { "OWNER", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, + N_("owner of the file") }, [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, diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 368b5be28b..7dbc4220b4 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -66,8 +66,10 @@ enum { COL_SOURCE, COL_TID, COL_TYPE, - COL_UID, - COL_USER, + COL_UID, /* proess */ + COL_USER, /* process */ + COL_FUID, /* file */ + COL_OWNER, /* file */ LSFD_N_COLS /* This must be at last. */ }; -- 2.47.3