From patchwork Wed Apr 18 20:17:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert ARIBAUD X-Patchwork-Id: 26813 Received: (qmail 116447 invoked by alias); 18 Apr 2018 20:21:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116395 invoked by uid 89); 18 Apr 2018 20:21:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW, RCVD_IN_RP_RNBL autolearn=ham version=3.3.2 spammy= X-HELO: smtp3-g21.free.fr From: "Albert ARIBAUD (3ADEV)" To: libc-alpha@sourceware.org Cc: "Albert ARIBAUD (3ADEV)" Subject: [[PATCH RFC 2] 34/63] Y2038: add function __lstat64_t64 (and __lxstat64_t64) Date: Wed, 18 Apr 2018 22:17:50 +0200 Message-Id: <20180418201819.15952-35-albert.aribaud@3adev.fr> In-Reply-To: <20180418201819.15952-34-albert.aribaud@3adev.fr> References: <20180418201819.15952-1-albert.aribaud@3adev.fr> <20180418201819.15952-2-albert.aribaud@3adev.fr> <20180418201819.15952-3-albert.aribaud@3adev.fr> <20180418201819.15952-4-albert.aribaud@3adev.fr> <20180418201819.15952-5-albert.aribaud@3adev.fr> <20180418201819.15952-6-albert.aribaud@3adev.fr> <20180418201819.15952-7-albert.aribaud@3adev.fr> <20180418201819.15952-8-albert.aribaud@3adev.fr> <20180418201819.15952-9-albert.aribaud@3adev.fr> <20180418201819.15952-10-albert.aribaud@3adev.fr> <20180418201819.15952-11-albert.aribaud@3adev.fr> <20180418201819.15952-12-albert.aribaud@3adev.fr> <20180418201819.15952-13-albert.aribaud@3adev.fr> <20180418201819.15952-14-albert.aribaud@3adev.fr> <20180418201819.15952-15-albert.aribaud@3adev.fr> <20180418201819.15952-16-albert.aribaud@3adev.fr> <20180418201819.15952-17-albert.aribaud@3adev.fr> <20180418201819.15952-18-albert.aribaud@3adev.fr> <20180418201819.15952-19-albert.aribaud@3adev.fr> <20180418201819.15952-20-albert.aribaud@3adev.fr> <20180418201819.15952-21-albert.aribaud@3adev.fr> <20180418201819.15952-22-albert.aribaud@3adev.fr> <20180418201819.15952-23-albert.aribaud@3adev.fr> <20180418201819.15952-24-albert.aribaud@3adev.fr> <20180418201819.15952-25-albert.aribaud@3adev.fr> <20180418201819.15952-26-albert.aribaud@3adev.fr> <20180418201819.15952-27-albert.aribaud@3adev.fr> <20180418201819.15952-28-albert.aribaud@3adev.fr> <20180418201819.15952-29-albert.aribaud@3adev.fr> <20180418201819.15952-30-albert.aribaud@3adev.fr> <20180418201819.15952-31-albert.aribaud@3adev.fr> <20180418201819.15952-32-albert.aribaud@3adev.fr> <20180418201819.15952-33-albert.aribaud@3adev.fr> <20180418201819.15952-34-albert.aribaud@3adev.fr> There is no Y2038-proof linux struct stat for now, so these implementations just use the existing syscalls and convert from kernel 32-bit-time struct stat64 to GLIBC Y2038-ready struct __stat64_t64. --- include/sys/stat.h | 2 ++ io/Versions | 1 + io/lstat64.c | 7 ++++++ sysdeps/unix/sysv/linux/lxstat64.c | 50 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/include/sys/stat.h b/include/sys/stat.h index b2a0fb594f..b83189a22c 100644 --- a/include/sys/stat.h +++ b/include/sys/stat.h @@ -42,6 +42,8 @@ extern int __fxstat64_t64 (int __ver, int __fildes, struct __stat64_t64 *__stat_buf); extern int __xstat64_t64 (int __ver, const char *__filename, struct __stat64_t64 *__stat_buf); +extern int __lxstat64_t64 (int __ver, const char *__filename, + struct __stat64_t64 *__stat_buf); #if IS_IN (libc) || (IS_IN (rtld) && !defined NO_RTLD_HIDDEN) hidden_proto (__fxstat) diff --git a/io/Versions b/io/Versions index c00f9849c2..e71167e932 100644 --- a/io/Versions +++ b/io/Versions @@ -129,5 +129,6 @@ libc { copy_file_range; __fxstat64_t64; __xstat64_t64; + __lxstat64_t64; } } diff --git a/io/lstat64.c b/io/lstat64.c index c3eb7a76f5..549208c153 100644 --- a/io/lstat64.c +++ b/io/lstat64.c @@ -50,3 +50,10 @@ lstat64 (const char *file, struct stat64 *buf) { return __lxstat64 (_STAT_VER, file, buf); } + +int +attribute_hidden +__lstat64_t64 (const char *file, struct __stat64_t64 *buf) +{ + return __lxstat64_t64 (_STAT_VER, file, buf); +} diff --git a/sysdeps/unix/sysv/linux/lxstat64.c b/sysdeps/unix/sysv/linux/lxstat64.c index d05fa14537..d98b1d5909 100644 --- a/sysdeps/unix/sysv/linux/lxstat64.c +++ b/sysdeps/unix/sysv/linux/lxstat64.c @@ -50,3 +50,53 @@ hidden_ver (___lxstat64, __lxstat64) strong_alias (___lxstat64, __lxstat64); hidden_def (__lxstat64) #endif + +/* 64-bit time version */ + +extern int __y2038_linux_support; + +int +__lxstat64_t64 (int vers, const char *name, struct __stat64_t64 *buf) +{ + int result; + struct stat64 st64; + + if (__y2038_linux_support) + { + // TODO: use 64-bit syscalls when they become available + } + + result = INLINE_SYSCALL (lstat64, 2, name, &st64); +#if defined _HAVE_STAT64___ST_INO && !__ASSUME_ST_INO_64_BIT + if (__builtin_expect (!result, 1) && st64.__st_ino != (__ino_t) st64.st_ino) + st64.st_ino = st64.__st_ino; +#endif + if (!result) + { + buf->st_dev = st64.st_dev; + //buf->__pad1 = st64.__pad1; + +#if defined _HAVE_STAT64___ST_INO + buf->__st_ino = st64.__st_ino; +#endif + buf->st_mode = st64.st_mode; + buf->st_nlink = st64.st_nlink; + buf->st_uid = st64.st_uid; + buf->st_gid = st64.st_gid; + buf->st_rdev = st64.st_rdev; + buf->__pad2 = st64.__pad2; + buf->st_size = st64.st_size; + buf->st_blksize = st64.st_blksize; + + buf->st_blocks = st64.st_blocks; + buf->st_atim.tv_sec = st64.st_atim.tv_sec; + buf->st_atim.tv_nsec = st64.st_atim.tv_nsec; + buf->st_mtim.tv_sec = st64.st_mtim.tv_sec; + buf->st_mtim.tv_nsec = st64.st_mtim.tv_nsec; + buf->st_ctim.tv_sec = st64.st_ctim.tv_sec; + buf->st_ctim.tv_nsec = st64.st_ctim.tv_nsec; + + buf->st_ino = st64.st_ino; + } + return result; +}