From: Masatake YAMATO Date: Mon, 10 May 2021 02:07:23 +0000 (+0900) Subject: lsfd: introduce a data structure for storing common fdinfo data X-Git-Tag: v2.38-rc1~144^2~131 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=056ae40f8cb8af8f926cac16c325543f1c890955;p=thirdparty%2Futil-linux.git lsfd: introduce a data structure for storing common fdinfo data Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index a0adb23cfb..3147a6440c 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -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; diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index f36e17df73..624b90dd91 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -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 {