lsfd: use constants defined in asm/fctl.h flags field of a fdinfo
Close #1709.
The original code decoded the field using constants defined in
/usr/include/fcntl.h. The constants defined in /usr/include/fcntl.h
was suitable for passing to the kernel as a part of arguments of
system calls like open(2). However, they were not suitable for
decoding the field.
Let's think about decoding
0300000 in
$ cat /proc/157067/fdinfo/3
pos: 0
flags:
0300000
$ lsfd -p 157067 -o+flags -Q -Q 'ASSOC == "3"'
COMMAND PID USER ASSOC MODE TYPE SOURCE MNTID INODE NAME FLAGS
test_mkfds 125128 jet 3 r-- DIR dm-0 96 96 / ???????????????????
The decoded string is printed at ???????????????????.
Quoted from /usr/include/bits/fcntl-linux.h:
#ifndef __O_LARGEFILE
# define __O_LARGEFILE
0100000
#endif
#ifndef __O_DIRECTORY
# define __O_DIRECTORY
0200000
#endif
#ifndef __O_TMPFILE
# define __O_TMPFILE (
020000000 | __O_DIRECTORY)
#endif
...
#ifdef __USE_XOPEN2K8
# define O_DIRECTORY __O_DIRECTORY /* Must be a directory. */
...
#endif
...
#ifdef __USE_LARGEFILE64
# define O_LARGEFILE __O_LARGEFILE
#endif
With these constants,
0300000 is decoded as "directory,_tmpfile" or
"largefile,directory,_tmpfile".
Unexpectedly the decoded string has "_tmpfile".
It has "largefile" only when we define __USE_LARGEFILE64 when building
lsfd though it should have "largefile" always.
Quoted from /usr/include/asm-generic/fcntl.h:
#ifndef O_LARGEFILE
#define O_LARGEFILE
00100000
#endif
#ifndef O_DIRECTORY
#define O_DIRECTORY
00200000 /* must be a directory */
#endif
#ifndef __O_TMPFILE
#define __O_TMPFILE
020000000
#endif
The decoded string is "largefile,directory". It doesn't depend on
__USE_LARGEFILE64.
This change adds lsfd-decode-file-flags.c, a new small and isolated
source file, in which lsfd_decode_file_flags(), the function for
decoding the field is defined.
include/c.h includes /usr/include/fcntl.h. Almost all lsfd related
source files includes include/c.h indirectly. On the other hand,
lsfd-decode-file-flags.c includes only /usr/include/asm-generic/fcntl.h
or /usr/include/asm/fcntl.h. So the function can decode the field
expectedly.
Signed-off-by: Masatake YAMATO <yamato@redhat.com>