From: Masatake YAMATO Date: Thu, 6 May 2021 13:19:11 +0000 (+0900) Subject: lsfd: introduce new association SHM representing shared file mapping X-Git-Tag: v2.38-rc1~144^2~150 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=202a50e6cbc850ffbbaf29a64d7f658103cfe7ea;p=thirdparty%2Futil-linux.git lsfd: introduce new association SHM representing shared file mapping MEM is kept for representing private file mapping. Signed-off-by: Masatake YAMATO --- diff --git a/misc-utils/lsfd-file.c b/misc-utils/lsfd-file.c index e1b5309e30..16f6ab9145 100644 --- a/misc-utils/lsfd-file.c +++ b/misc-utils/lsfd-file.c @@ -47,6 +47,7 @@ static const char *assocstr[N_ASSOCS] = { [ASSOC_NS_USER] = "user", [ASSOC_NS_UTS] = "uts", [ASSOC_MEM] = "mem", + [ASSOC_SHM] = "shm", }; static const char *strftype(mode_t ftype) diff --git a/misc-utils/lsfd.c b/misc-utils/lsfd.c index 5f33868ad6..0a76066143 100644 --- a/misc-utils/lsfd.c +++ b/misc-utils/lsfd.c @@ -420,12 +420,29 @@ static struct file *collect_fd_file(int dd, struct dirent *dp, void *data) return f; } +static struct map *find_map(struct list_head *maps, unsigned long start_addr) +{ + struct list_head *m; + + list_for_each(m, maps) { + struct map *map = list_entry(m, struct map, maps); + if (map->mem_addr_start == start_addr) + return map; + } + return NULL; +} + static struct file *collect_mem_file(int dd, struct dirent *dp, - void *data __attribute__((__unused__))) + void *data) { + struct list_head *maps = data; struct stat sb; ssize_t len; char sym[PATH_MAX]; + struct file *f; + unsigned long start, end; + struct map *map; + enum association assoc; if (fstatat(dd, dp->d_name, &sb, 0) < 0) return NULL; @@ -434,7 +451,16 @@ static struct file *collect_mem_file(int dd, struct dirent *dp, if ((len = readlinkat(dd, dp->d_name, sym, sizeof(sym) - 1)) < 0) return NULL; - return collect_file(&sb, sym, -ASSOC_MEM); + + map = NULL; + if (sscanf(dp->d_name, "%lx-%lx", &start, &end) == 2) + map = find_map(maps, start); + + assoc = (map && map->shared)? ASSOC_SHM: ASSOC_MEM; + f = collect_file(&sb, sym, -assoc); + if (!f) + return NULL; + return f; } static void enqueue_file(struct proc *proc, struct file * file) diff --git a/misc-utils/lsfd.h b/misc-utils/lsfd.h index 99037c5d0f..d6a35f660c 100644 --- a/misc-utils/lsfd.h +++ b/misc-utils/lsfd.h @@ -91,7 +91,8 @@ enum association { ASSOC_NS_TIME4C, ASSOC_NS_USER, ASSOC_NS_UTS, - ASSOC_MEM, + ASSOC_MEM, /* private file mapping */ + ASSOC_SHM, /* shared file mapping */ N_ASSOCS, };