]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: introduce a data structure for storing common fdinfo data
authorMasatake YAMATO <yamato@redhat.com>
Mon, 10 May 2021 02:07:23 +0000 (11:07 +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.h

index a0adb23cfb6e8785d90cb58dbfb539885cf4aa3f..3147a6440c15d78a1e07ba8b219f60a65fd79fde 100644 (file)
@@ -269,7 +269,7 @@ static bool file_fill_column(struct proc *proc,
                xasprintf(&str, "%d", file->stat.st_nlink == 0);
                break;
        case COL_MNT_ID:
-               xasprintf(&str, "%d", file->association < 0? 0: file->mnt_id);
+               xasprintf(&str, "%d", file->association < 0? 0: file->assoc_data.fdinfo.mnt_id);
                break;
        case COL_MODE:
                if (does_file_has_fdinfo_alike(file))
@@ -292,10 +292,10 @@ static bool file_fill_column(struct proc *proc,
                if (file->association < 0)
                        return true;
 
-               if (file->flags == 0)
+               if (file->assoc_data.fdinfo.flags == 0)
                        return true;
 
-               file_fill_flags_buf(&buf, file->flags);
+               file_fill_flags_buf(&buf, file->assoc_data.fdinfo.flags);
                if (ul_buffer_is_empty(&buf))
                        return true;
                str = ul_buffer_get_data(&buf, NULL, NULL);
@@ -318,10 +318,10 @@ static int file_handle_fdinfo(struct file *file, const char *key, const char* va
                file->pos = strtoull(value, NULL, 10);
                return 1;
        } else if (strcmp(key, "flags") == 0) {
-               file->flags = (int)strtol(value, NULL, 8);
+               file->assoc_data.fdinfo.flags = (int)strtol(value, NULL, 8);
                return 1;
        } else if (strcmp(key, "mnt_id") == 0) {
-               file->mnt_id = (int)strtol(value, NULL, 10);
+               file->assoc_data.fdinfo.mnt_id = (int)strtol(value, NULL, 10);
                return 1;
        }
        return 0;
index f36e17df738bc64da96ebaed67026be6931a7816..624b90dd91c2107f4fa6b9434e124fbd6bcdb578 100644 (file)
@@ -113,6 +113,11 @@ struct proc {
 /*
  * File classes
  */
+struct fdinfo_data {
+       int flags;
+       int mnt_id;
+};
+
 struct file {
        struct list_head files;
        const struct file_class *class;
@@ -121,8 +126,9 @@ struct file {
        struct stat stat;
        mode_t mode;
        unsigned long long pos;
-       int flags;              /* in fdinfo */
-       int mnt_id;             /* in fdinfo */
+       union assoc_data {
+               struct fdinfo_data fdinfo;
+       } assoc_data;
 };
 
 struct file_class {