1 /* Generic implementation of statx based on fstatat64.
2 Copyright (C) 2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
22 #include <sys/sysmacros.h>
24 static inline struct statx_timestamp
25 statx_convert_timestamp (struct timespec tv
)
27 return (struct statx_timestamp
) { tv
.tv_sec
, tv
.tv_nsec
};
30 /* Approximate emulation of statx. This will always fill in
31 POSIX-mandated attributes even if the underlying file system does
32 not actually support it (for example, GID and UID on file systems
33 without UNIX-style permissions). */
34 static __attribute__ ((unused
)) int
35 statx_generic (int fd
, const char *path
, int flags
,
36 unsigned int mask
, struct statx
*buf
)
38 /* Flags which need to be cleared before passing them to
40 static const int clear_flags
= AT_STATX_SYNC_AS_STAT
;
42 /* Flags supported by our emulation. */
43 static const int supported_flags
44 = AT_EMPTY_PATH
| AT_NO_AUTOMOUNT
| AT_SYMLINK_NOFOLLOW
| clear_flags
;
46 if (__glibc_unlikely ((flags
& ~supported_flags
) != 0))
53 int ret
= __fstatat64 (fd
, path
, &st
, flags
& ~clear_flags
);
57 /* The interface is defined in such a way that unused (padding)
58 fields have to be cleared. STATX_BASIC_STATS corresponds to the
59 data which is available via fstatat64. */
62 .stx_mask
= STATX_BASIC_STATS
,
63 .stx_blksize
= st
.st_blksize
,
64 .stx_nlink
= st
.st_nlink
,
67 .stx_mode
= st
.st_mode
,
69 .stx_size
= st
.st_size
,
70 .stx_blocks
= st
.st_blocks
,
71 .stx_atime
= statx_convert_timestamp (st
.st_atim
),
72 .stx_ctime
= statx_convert_timestamp (st
.st_ctim
),
73 .stx_mtime
= statx_convert_timestamp (st
.st_mtim
),
74 .stx_rdev_major
= major (st
.st_rdev
),
75 .stx_rdev_minor
= minor (st
.st_rdev
),
76 .stx_dev_major
= major (st
.st_dev
),
77 .stx_dev_minor
= minor (st
.st_dev
),