From: Masatake YAMATO Date: Thu, 6 May 2021 05:29:43 +0000 (+0900) Subject: lsfd: add MODE column X-Git-Tag: v2.38-rc1~144^2~156 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=17adf20f126914e2c3f83523d2761ec53e3a9360;p=thirdparty%2Futil-linux.git lsfd: add MODE column Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index ab55d25eb2..e1b5309e30 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -244,6 +244,14 @@ static bool file_fill_column(struct proc *proc, case COL_MNT_ID: xasprintf(&str, "%d", file->association < 0? 0: file->mnt_id); break; + case COL_MODE: + if (file->association < 0) + xasprintf(&str, "---"); + else + xasprintf(&str, "%c%c-", + file->mode & S_IRUSR? 'r': '-', + file->mode & S_IWUSR? 'w': '-'); + break; case COL_POS: xasprintf(&str, "%llu", file->association < 0? 0: file->pos); diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 9259974a25..d345825760 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -102,6 +102,8 @@ static struct colinfo infos[] = { N_("inode number") }, [COL_MNT_ID] = { "MNTID", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, N_("mount id") }, + [COL_MODE] = { "MODE", 0, SCOLS_FL_RIGHT, SCOLS_JSON_STRING, + N_("access mode (rwx)") }, [COL_NAME] = { "NAME", 45, 0, SCOLS_JSON_STRING, N_("name of the file") }, [COL_NLINK] = { "NLINK", 0, SCOLS_FL_RIGHT, SCOLS_JSON_NUMBER, @@ -129,6 +131,7 @@ static int default_columns[] = { COL_PID, COL_USER, COL_ASSOC, + COL_MODE, COL_TYPE, COL_DEVICE, COL_POS, @@ -142,6 +145,7 @@ static int default_threads_columns[] = { COL_TID, COL_USER, COL_ASSOC, + COL_MODE, COL_TYPE, COL_DEVICE, COL_POS, @@ -363,7 +367,7 @@ static struct file *collect_fd_file(int dd, struct dirent *dp, void *data) { long num; char *endptr = NULL; - struct stat sb; + struct stat sb, lsb; ssize_t len; char sym[PATH_MAX]; struct file *f; @@ -386,6 +390,9 @@ static struct file *collect_fd_file(int dd, struct dirent *dp, void *data) if (!f) return NULL; + if (fstatat(dd, dp->d_name, &lsb, AT_SYMLINK_NOFOLLOW) == 0) + f->mode = lsb.st_mode; + if (*fdinfo_dd < 0) return f; diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 473d477ad4..45ebed04a6 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -60,6 +60,7 @@ enum { COL_FLAGS, COL_INODE, COL_MNT_ID, + COL_MODE, COL_NAME, COL_NLINK, COL_PID, @@ -111,6 +112,7 @@ struct file { int association; char *name; struct stat stat; + mode_t mode; unsigned long long pos; int flags; int mnt_id;