]>
git.ipfire.org Git - thirdparty/util-linux.git/blob - misc-utils/lsfd-decode-file-flags.c
2 * lsfd(1) - list file descriptors
4 * Copyright (C) 2022 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
25 /* lsfd_decode_file_flags() is for decoding `flags' field of
26 * /proc/$pid/fdinfo/$fd. Bits of the field have name defined
28 * A system on which lsfd is built may have multiple
31 * - /usr/include/asm/fcntl.h (a part of Linux kernel)
32 * - /usr/include/asm-generic/fcntl.h (a part of Linux kernel)
33 * - /usr/include/fcntl.h (a part of glibc)
34 * - /usr/include/bits/fcntl.h (a part of glibc)
36 * For decoding purpose, /usr/include/asm/fcntl.h or
37 * /usr/include/asm-generic/fcntl.h is needed.
39 * /usr/include/bits/fcntl.h and /usr/include/fcntl.h are
40 * not suitable for decoding. They should not be included.
41 * /usr/include/fcntl.h includes /usr/include/bits/fcntl.h.
44 #if defined HAVE_ASM_FCNTL_H
45 #include <asm/fcntl.h>
46 #elif defined HAVE_ASM_GENERIC_FCNTL_H
47 #include <asm-generic/fcntl.h>
49 #error "kernel's fcntl.h is not available"
52 #include <stddef.h> /* for size_t */
55 void lsfd_decode_file_flags(struct ul_buffer
*buf
, int flags
);
57 /* We cannot include buffer.h because buffer.h includes
58 * /usr/include/fcntl.h indirectly. */
59 extern int ul_buffer_is_empty(struct ul_buffer
*buf
);
60 extern int ul_buffer_append_data(struct ul_buffer
*buf
, const char *data
, size_t sz
);
61 extern int ul_buffer_append_string(struct ul_buffer
*buf
, const char *str
);
63 void lsfd_decode_file_flags(struct ul_buffer
*buf
, int flags
)
65 #define SET_FLAG_FULL(L,s) \
68 if (!ul_buffer_is_empty(buf)) \
69 ul_buffer_append_data(buf, ",", 1); \
70 ul_buffer_append_string(buf, #s); \
74 #define SET_FLAG(L,s) SET_FLAG_FULL(O_##L,s)
77 SET_FLAG(WRONLY
,wronly
);
85 SET_FLAG(CREAT
,creat
);
93 SET_FLAG(NOCTTY
,noctty
);
97 SET_FLAG(APPEND
,append
);
101 SET_FLAG(NONBLOCK
,nonblock
);
105 SET_FLAG(DSYNC
,dsync
);
109 SET_FLAG_FULL(FASYNC
,fasync
);
113 SET_FLAG(DIRECT
,direct
);
117 SET_FLAG(LARGEFILE
,largefile
);
121 SET_FLAG(DIRECTORY
,directory
);
125 SET_FLAG(NOFOLLOW
,nofollow
);
129 SET_FLAG(NOATIME
,noatime
);
133 SET_FLAG(CLOEXEC
,cloexec
);
137 SET_FLAG_FULL(__O_SYNC
,_sync
);
145 SET_FLAG_FULL(__O_TMPFILE
,_tmpfile
);