[PATCH 15/16] linux: Add {f}stat{at} y2038 support
Adhemerval Zanella
adhemerval.zanella@linaro.org
Thu Jul 30 12:42:51 GMT 2020
On 24/07/2020 07:53, Lukasz Majewski wrote:
>>
>> diff --git a/sysdeps/unix/sysv/linux/fstatat.c
>> b/sysdeps/unix/sysv/linux/fstatat.c index 03ddb3f493..f65d3b74a6
>> 100644 --- a/sysdeps/unix/sysv/linux/fstatat.c
>> +++ b/sysdeps/unix/sysv/linux/fstatat.c
>> -# ifdef __NR_fstatat64
>> - /* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k,
>> mips32,
>> - microblaze, s390, sh, powerpc, and sparc. */
>> + struct statx stx;
>> + int r = INLINE_SYSCALL_CALL (statx, fd, file, flag,
>> STATX_BASIC_STATS,
>> + &stx);
>
> I'm wondering about the indentation here - I do see 3*TAB and some
> spaces. Shouldn't we only use spaces?
Afaik the GNU code guidelines requires to use TAB indentations instead
of space in this case.
>
> And one more question what is the correct alignment:
> (statx, fd, file, flag
> &stx);
>
> or
> (statx, fd, file, flag
> &stx);
My understanding the latter.
>
>> + if (r == 0 || errno != ENOSYS)
>> + {
>> + if (r == 0)
>> + __cp_stat_t64_statx (st, &stx);
>> + return r;
>> + }
>
> Great that the statx is used here.
>
>> +
>> +# ifdef __NR_fstatat64
>> + /* Both new kABI which uses generic pre 64-bit time Linux ABI
>> (e.g. csky
>> + and nios) and old kABI with non-LFS support (e.g. arm, i386,
>> hppa, m68k,
>> + mips32, microblaze, s390, sh, powerpc, and sparc32). */
>> struct stat64 st64;
>> - int r = INLINE_SYSCALL_CALL (fstatat64, fd, file, &st64, flag);
>> + r = INLINE_SYSCALL_CALL (fstatat64, fd, file, &st64, flag);
>> if (r == 0)
>> {
>> if (! in_ino_t_range (st64.st_ino)
>> @@ -48,7 +51,7 @@ __fstatat (int fd, const char *file, struct stat
>> *st, int flag) || ! in_blkcnt_t_range (st64.st_blocks))
>> return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
>>
>> - /* Clear internal pad and reserved fields. */
>> + /* Clear both pad and reserved fields. */
>> memset (st, 0, sizeof (*st));
>>
>> st->st_dev = st64.st_dev,
>> @@ -61,22 +64,29 @@ __fstatat (int fd, const char *file, struct stat
>> *st, int flag) st->st_size = st64.st_size;
>> st->st_blksize = st64.st_blksize;
>> st->st_blocks = st64.st_blocks;
>> - st->st_atim.tv_sec = st64.st_atim.tv_sec;
>> - st->st_atim.tv_nsec = st64.st_atim.tv_nsec;
>> - st->st_mtim.tv_sec = st64.st_mtim.tv_sec;
>> - st->st_mtim.tv_nsec = st64.st_mtim.tv_nsec;
>> - st->st_ctim.tv_sec = st64.st_ctim.tv_sec;
>> - st->st_ctim.tv_nsec = st64.st_ctim.tv_nsec;
>> + st->st_atim = valid_timespec_to_timespec64 (st64.st_atim);
>> + st->st_mtim = valid_timespec_to_timespec64 (st64.st_mtim);
>> + st->st_ctim = valid_timespec_to_timespec64 (st64.st_ctim);
>> }
>> return r;
>> -# else
>> +# else
>> /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */
>> struct kernel_stat kst;
>> - int r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag);
>> - return r ?: __cp_kstat_stat (&kst, st);
>> -# endif /* __nr_fstatat64 */
>> -# endif /* STAT_IS_KERNEL_STAT */
>> + r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag);
>> + return r ?: __cp_kstat_stat_t64 (&kst, st);
>> +# endif /* __NR_fstatat64 */
>> +}
>> +# if __TIMESIZE != 64
>> +libc_hidden_def (__fstatat_time64)
>> +
>> +int
>> +__fstatat (int fd, const char *file, struct stat *buf, int flags)
>> +{
>> + struct __stat_t64 st_t64;
>> + return __fstatat_time64 (fd, file, &st_t64, flags)
>> + ?: __cp_stat_t64_stat (&st_t64, buf);
>> }
>> +# endif
>>
>> weak_alias (__fstatat, fstatat)
>> #endif
>> diff --git a/sysdeps/unix/sysv/linux/fstatat64.c
>> b/sysdeps/unix/sysv/linux/fstatat64.c index 82fab107a5..b3940f0d20
>> 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c
>> +++ b/sysdeps/unix/sysv/linux/fstatat64.c
>> @@ -19,56 +19,102 @@
>> #define __fstatat __redirect___fstatat
>> #define fstatat __redirect_fstatat
>> #include <sys/stat.h>
>> -#undef __fstatat
>> -#undef fstatat
>> #include <fcntl.h>
>> -
>> +#include <string.h>
>> #include <kernel_stat.h>
>> #include <sysdep.h>
>> -
>> +#include <time.h>
>> #include <statx_cp.h>
>> #include <kstat_cp.h>
>> +#include <stat_t64_cp.h>
>>
>> int
>> -__fstatat64 (int fd, const char *file, struct stat64 *st, int flag)
>> +__fstatat64_time64 (int fd, const char *file, struct __stat64_t64
>> *st,
>> + int flag)
>> {
>> + int r;
>> +
>> +#if (__WORDSIZE == 32 \
>> + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32))
>
> I do guess that the above condition is to ensure that 32 bit archs
> (excluding x86_64-x32 - e.g. arm, riscv, etc) use statx?
Yes, this is similar for what is done by SysVIPC fixes.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/libc-alpha/attachments/20200730/6606f070/attachment-0001.sig>
More information about the Libc-alpha
mailing list