2 * lsfd(1) - list file descriptors
4 * Copyright (C) 2021 Red Hat, Inc. All rights reserved.
5 * Written by Masatake YAMATO <yamato@redhat.com>
7 * Very generally based on lsof(8) by Victor A. Abell <abe@purdue.edu>
8 * It supports multiple OSes. lsfd specializes to Linux.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it would be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software Foundation,
22 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef UTIL_LINUX_LSFD_H
25 #define UTIL_LINUX_LSFD_H
32 #include "libsmartcols.h"
52 COL_BPF_PROG_TYPE_RAW
,
70 COL_INOTIFY_INODES_RAW
,
112 COL_TIMERFD_INTERVAL
,
113 COL_TIMERFD_REMAINING
,
124 COL_UID
, /* process */
126 COL_USER
, /* process */
128 LSFD_N_COLS
/* This must be at last. */
148 ASSOC_MEM
, /* private file mapping */
149 ASSOC_SHM
, /* shared file mapping */
155 struct proc
* leader
;
159 struct list_head procs
;
160 struct list_head files
;
161 unsigned int kthread
: 1;
162 struct list_head eventpolls
;
165 struct proc
*get_proc(pid_t pid
);
171 struct list_head files
;
172 const struct file_class
*class;
183 unsigned int sys_flags
;
187 uint8_t read
:1, write
:1;
192 #define is_opened_file(_f) ((_f)->association >= 0)
193 #define is_mapped_file(_f) (is_association((_f), SHM) || is_association((_f), MEM))
194 #define is_association(_f, a) ((_f)->association < 0 && (_f)->association == -ASSOC_ ## a)
197 const struct file_class
*super
;
199 void (*initialize_class
)(void);
200 void (*finalize_class
)(void);
201 bool (*fill_column
)(struct proc
*proc
,
203 struct libscols_line
*ln
,
205 size_t column_index
);
206 int (*handle_fdinfo
)(struct file
*file
, const char *key
, const char* value
);
207 void (*attach_xinfo
)(struct file
*file
);
208 void (*initialize_content
)(struct file
*file
);
209 void (*free_content
)(struct file
*file
);
210 const struct ipc_class
*(*get_ipc_class
)(struct file
*file
);
213 extern const struct file_class file_class
, cdev_class
, bdev_class
, sock_class
, unkn_class
, fifo_class
,
214 nsfs_file_class
, mqueue_file_class
;
220 const struct ipc_class
*class;
221 struct list_head endpoints
;
222 struct list_head ipcs
;
225 struct ipc_endpoint
{
227 struct list_head endpoints
;
232 unsigned int (*get_hash
)(struct file
*file
);
233 bool (*is_suitable_ipc
)(struct ipc
*ipc
, struct file
*file
);
234 void (*free
)(struct ipc
*ipc
);
237 struct ipc
*new_ipc(const struct ipc_class
*class);
238 struct ipc
*get_ipc(struct file
*file
);
239 void add_ipc(struct ipc
*ipc
, unsigned int hash
);
240 void init_endpoint(struct ipc_endpoint
*endpoint
);
241 void add_endpoint(struct ipc_endpoint
*endpoint
, struct ipc
*ipc
);
242 #define foreach_endpoint(E,ENDPOINT) list_for_each_backwardly(E, &((ENDPOINT).ipc->endpoints))
244 enum decode_source_bit
{
245 DECODE_SOURCE_MAJMIN_BIT
= 1 << 0,
246 DECODE_SOURCE_PARTITION_BIT
= 1 << 1,
247 DECODE_SOURCE_FILESYS_BIT
= 1 << 2,
250 enum decode_source_level
{
251 DECODE_SOURCE_MAJMIN
= DECODE_SOURCE_MAJMIN_BIT
,
252 DECODE_SOURCE_PARTITION
= DECODE_SOURCE_PARTITION_BIT
| DECODE_SOURCE_MAJMIN
,
253 DECODE_SOURCE_FILESYS
= DECODE_SOURCE_FILESYS_BIT
| DECODE_SOURCE_PARTITION
,
254 DECODE_SOURCE_FULL
= DECODE_SOURCE_FILESYS
,
257 void decode_source(char *buf
, size_t bufsize
, unsigned int dev_major
, unsigned int dev_minor
,
258 enum decode_source_level level
);
264 struct name_manager
*new_name_manager(void);
265 void free_name_manager(struct name_manager
*nm
);
266 const char *get_name(struct name_manager
*nm
, unsigned long id
);
267 unsigned long add_name(struct name_manager
*nm
, const char *name
);
269 const char *get_partition(dev_t dev
);
270 const char *get_blkdrv(unsigned long major
);
271 const char *get_chrdrv(unsigned long major
);
272 const char *get_miscdev(unsigned long minor
);
273 const char *get_nodev_filesystem(unsigned long minor
);
274 void add_nodev(unsigned long minor
, const char *filesystem
);
276 static inline void xstrappend(char **a
, const char *b
)
278 if (strappend(a
, b
) < 0)
279 err(XALLOC_EXIT_CODE
, _("failed to allocate memory for string"));
282 static inline void xstrputc(char **a
, char c
)
284 char b
[] = {c
, '\0'};
289 __attribute__((__format__(printf
, 2, 0)))
290 int xstrvfappend(char **a
, const char *format
, va_list ap
)
292 int ret
= strvfappend(a
, format
, ap
);
295 err(XALLOC_EXIT_CODE
, "cannot allocate string");
301 __attribute__ ((__format__ (__printf__
, 2, 3)))
302 int xstrfappend(char **a
, const char *format
, ...)
307 va_start(ap
, format
);
308 ret
= xstrvfappend(a
, format
, ap
);
317 void load_sock_xinfo(struct path_cxt
*pc
, const char *name
, ino_t netns
);
318 bool is_nsfs_dev(dev_t dev
);
323 /* 0 is assumed as the major dev for DEV. */
324 bool is_mqueue_dev(dev_t dev
);
329 bool is_multiplexed_by_eventpoll(int fd
, struct list_head
*eventpolls
);
331 #endif /* UTIL_LINUX_LSFD_H */