]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: add MODE column
authorMasatake YAMATO <yamato@redhat.com>
Thu, 6 May 2021 05:29:43 +0000 (14:29 +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-file.c
misc-utils/lsfd.c
misc-utils/lsfd.h

index ab55d25eb28fb6f5890638256f5f1d8eaca7ecdd..e1b5309e304cc349ff705e75bd7826bb9725697f 100644 (file)
@@ -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);
index 9259974a251aeb10589fbcc3f41c7187aa165716..d345825760e3c8b0860b32bb06a58b3535b190d3 100644 (file)
@@ -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;
 
index 473d477ad4ad13568c5abaef7a59064449c46a2e..45ebed04a68dc5192252d271103e5f614b9ac76f 100644 (file)
@@ -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;