mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-10 05:03:06 +03:00
It implements all the required syscall for the all Linux kABIS on fstatat{64} instead of calling fxstatat{64}. On non-LFS implementation, it handles 3 cases: 1. New kABIs which uses generic pre 64-bit time Linux ABI (csky and nios): it issues __NR_fstat64 plus handle the overflow on st_ino, st_size, or st_blocks. 2. Old KABIs with old non-LFS support (arm, i386, hppa, m68k, microblaze, mips32, s390, sh, powerpc, and sparc32): it issues __NR_fstatat64 and convert the result to struct stat. 3. 64-bit kABI outliers (mips64 and mips64-n32): it issues __NR_newfstatat and convert the result to struct stat. The generic LFS implementation handles multiple cases: 1. XSTAT_IS_XSTAT64 being 1: 1.1. 64-bit kABI (aarch64, ia64, powerpc64*, s390x, riscv64, and x86_64): it issues __NR_newfstatat. 1.2. 64-bit kABI outlier (alpha): it issues __NR_fstatat64. 1.3. 64-bit kABI outlier where struct stat64 does not match kernel one (sparc64): it issues __NR_fstatat64 and convert the result to struct stat64. 1.4. 32-bit kABI with default 64-bit time_t (arc, riscv32): it issues __NR_statx and convert the result to struct stat64. 2. Old ABIs with XSTAT_IS_XSTAT64 being 0: 2.1. All kABIs with non-LFS support (arm, csky, i386, hppa, m68k, microblaze, nios2, sh, powerpc32, and sparc32): it issues __NR_fstatat64. 2.2. 64-bit kABI outliers (mips64 and mips64-n32): it issues __NR_newfstatat and convert the result to struct stat64. It allows to remove all the hidden definitions from the {f,l}xstat{64} (some are still kept because Hurd requires it). Checked with a build for all affected ABIs. I also checked on x86_64, i686, powerpc, powerpc64le, sparcv9, sparc64, s390, and s390x. Reviewed-by: Lukasz Majewski <lukma@denx.de>
81 lines
2.8 KiB
C
81 lines
2.8 KiB
C
/* Struct stat/stat64 to stat/stat64 conversion for Linux.
|
|
Copyright (C) 2020 Free Software Foundation, Inc.
|
|
This file is part of the GNU C Library.
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Lesser General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Lesser General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
License along with the GNU C Library. If not, see
|
|
<https://www.gnu.org/licenses/>. */
|
|
|
|
#include <sys/stat.h>
|
|
#include <kernel_stat.h>
|
|
|
|
static inline int
|
|
__cp_kstat_stat (const struct kernel_stat *kst, struct stat *st)
|
|
{
|
|
st->st_dev = kst->st_dev;
|
|
memset (&st->st_pad1, 0, sizeof (st->st_pad1));
|
|
st->st_ino = kst->st_ino;
|
|
if (st->st_ino != kst->st_ino)
|
|
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
|
|
st->st_mode = kst->st_mode;
|
|
st->st_nlink = kst->st_nlink;
|
|
st->st_uid = kst->st_uid;
|
|
st->st_gid = kst->st_gid;
|
|
st->st_rdev = kst->st_rdev;
|
|
memset (&st->st_pad2, 0, sizeof (st->st_pad2));
|
|
st->st_size = kst->st_size;
|
|
if (st->st_size != kst->st_size)
|
|
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
|
|
st->st_pad3 = 0;
|
|
st->st_atim.tv_sec = kst->st_atime_sec;
|
|
st->st_atim.tv_nsec = kst->st_atime_nsec;
|
|
st->st_mtim.tv_sec = kst->st_mtime_sec;
|
|
st->st_mtim.tv_nsec = kst->st_mtime_nsec;
|
|
st->st_ctim.tv_sec = kst->st_ctime_sec;
|
|
st->st_ctim.tv_nsec = kst->st_ctime_nsec;
|
|
st->st_blksize = kst->st_blksize;
|
|
st->st_blocks = kst->st_blocks;
|
|
if (st->st_blocks != kst->st_blocks)
|
|
return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
|
|
memset (&st->st_pad5, 0, sizeof (st->st_pad5));
|
|
|
|
return 0;
|
|
}
|
|
|
|
static inline int
|
|
__cp_kstat_stat64 (const struct kernel_stat *kst, struct stat64 *st)
|
|
{
|
|
st->st_dev = kst->st_dev;
|
|
memset (&st->st_pad1, 0, sizeof (st->st_pad1));
|
|
st->st_ino = kst->st_ino;
|
|
st->st_mode = kst->st_mode;
|
|
st->st_nlink = kst->st_nlink;
|
|
st->st_uid = kst->st_uid;
|
|
st->st_gid = kst->st_gid;
|
|
st->st_rdev = kst->st_rdev;
|
|
memset (&st->st_pad2, 0, sizeof (st->st_pad2));
|
|
st->st_pad3 = 0;
|
|
st->st_size = kst->st_size;
|
|
st->st_blksize = kst->st_blksize;
|
|
st->st_blocks = kst->st_blocks;
|
|
st->st_atim.tv_sec = kst->st_atime_sec;
|
|
st->st_atim.tv_nsec = kst->st_atime_nsec;
|
|
st->st_mtim.tv_sec = kst->st_mtime_sec;
|
|
st->st_mtim.tv_nsec = kst->st_mtime_nsec;
|
|
st->st_ctim.tv_sec = kst->st_ctime_sec;
|
|
st->st_ctim.tv_nsec = kst->st_ctime_nsec;
|
|
memset (&st->st_pad4, 0, sizeof (st->st_pad4));
|
|
|
|
return 0;
|
|
}
|