From patchwork Mon Nov 19 05:22:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5q+b5pmX?= X-Patchwork-Id: 30191 Received: (qmail 40573 invoked by alias); 19 Nov 2018 05:25:10 -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 29288 invoked by uid 89); 19 Nov 2018 05:24:45 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.8 required=5.0 tests=AWL, BAYES_00, FSL_HELO_NON_FQDN_1, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT autolearn=ham version=3.3.2 spammy=hide, H*r:Unknown, at_fdcwd, sk:__glibc X-HELO: vmh-VirtualBox From: Mao Han To: libc-alpha@sourceware.org Cc: Mao Han , c-sky_gcc_upstream@c-sky.com, gnu-csky@mentor.com Subject: [PATCH v5 14/14] C-SKY: several stat interface implemented with statx system call Date: Mon, 19 Nov 2018 13:22:41 +0800 Message-Id: In-Reply-To: References: In-Reply-To: References: --- sysdeps/unix/sysv/linux/csky/fxstat.c | 54 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/fxstat64.c | 68 ++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/fxstatat.c | 52 +++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/fxstatat64.c | 54 ++++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/lxstat.c | 50 +++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/lxstat64.c | 60 +++++++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/statx_cp.c | 75 +++++++++++++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/xstat.c | 51 +++++++++++++++++++++ sysdeps/unix/sysv/linux/csky/xstat64.c | 60 +++++++++++++++++++++++++ 9 files changed, 524 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/csky/fxstat.c create mode 100644 sysdeps/unix/sysv/linux/csky/fxstat64.c create mode 100644 sysdeps/unix/sysv/linux/csky/fxstatat.c create mode 100644 sysdeps/unix/sysv/linux/csky/fxstatat64.c create mode 100644 sysdeps/unix/sysv/linux/csky/lxstat.c create mode 100644 sysdeps/unix/sysv/linux/csky/lxstat64.c create mode 100644 sysdeps/unix/sysv/linux/csky/statx_cp.c create mode 100644 sysdeps/unix/sysv/linux/csky/xstat.c create mode 100644 sysdeps/unix/sysv/linux/csky/xstat64.c diff --git a/sysdeps/unix/sysv/linux/csky/fxstat.c b/sysdeps/unix/sysv/linux/csky/fxstat.c new file mode 100644 index 0000000..986b6fd --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/fxstat.c @@ -0,0 +1,54 @@ +/* fxstat implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#if !XSTAT_IS_XSTAT64 +#include "overflow.h" + + +extern void __cp_stat_statx (struct stat *to, struct statx *from); + +/* Get information about the file FD in BUF. */ +int +__fxstat (int vers, int fd, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + { + struct statx tmp; + int rc = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH, + STATX_BASIC_STATS, &tmp); + __cp_stat_statx (buf, &tmp); + return rc ?: stat_overflow (buf); + } + + errno = EINVAL; + return -1; +} + +hidden_def (__fxstat) +weak_alias (__fxstat, _fxstat); +#endif diff --git a/sysdeps/unix/sysv/linux/csky/fxstat64.c b/sysdeps/unix/sysv/linux/csky/fxstat64.c new file mode 100644 index 0000000..6d4ff61 --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/fxstat64.c @@ -0,0 +1,68 @@ +/* fxstat64 implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +/* Get information about the file FD in BUF. */ + +extern void __cp_stat64_statx (struct stat64 *to, struct statx *from); + +int +___fxstat64 (int vers, int fd, struct stat64 *buf) +{ + int result; + struct statx tmp; + result = INLINE_SYSCALL (statx, 5, fd, "", AT_EMPTY_PATH, STATX_BASIC_STATS, + &tmp); + __cp_stat64_statx (buf, &tmp); +#if defined _HAVE_STAT64___ST_INO && !__ASSUME_ST_INO_64_BIT + if (__builtin_expect (!result, 1) && buf->__st_ino != (__ino_t) buf->st_ino) + buf->st_ino = buf->__st_ino; +#endif + return result; +} + +#include + +#if SHLIB_COMPAT(libc, GLIBC_2_1, GLIBC_2_2) +versioned_symbol (libc, ___fxstat64, __fxstat64, GLIBC_2_2); +strong_alias (___fxstat64, __old__fxstat64) +compat_symbol (libc, __old__fxstat64, __fxstat64, GLIBC_2_1); +hidden_ver (___fxstat64, __fxstat64) +#else +strong_alias (___fxstat64, __fxstat64) +hidden_def (__fxstat64) +#endif + +#undef __fxstat +#undef _fxstat +#if XSTAT_IS_XSTAT64 +weak_alias (__fxstat64, __fxstat) +weak_alias (__fxstat64, _fxstat) +hidden_ver (__fxstat64, __fxstat) +#endif diff --git a/sysdeps/unix/sysv/linux/csky/fxstatat.c b/sysdeps/unix/sysv/linux/csky/fxstatat.c new file mode 100644 index 0000000..d57334c --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/fxstatat.c @@ -0,0 +1,52 @@ +/* fxstatat implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#if !XSTAT_IS_XSTAT64 +#include "overflow.h" + +extern void __cp_stat_statx (struct stat *to, struct statx *from); + +/* Get information about the file NAME in BUF. */ +int +__fxstatat (int vers, int fd, const char *file, struct stat *buf, int flag) +{ + if (vers == _STAT_VER_KERNEL) + { + struct statx tmp; + int rc = INLINE_SYSCALL (statx, 5, fd, file, + AT_NO_AUTOMOUNT | flag, + STATX_BASIC_STATS, &tmp); + __cp_stat_statx (buf, &tmp); + return rc ?: stat_overflow (buf); + } + + errno = EINVAL; + return -1; +} +libc_hidden_def (__fxstatat) +#endif diff --git a/sysdeps/unix/sysv/linux/csky/fxstatat64.c b/sysdeps/unix/sysv/linux/csky/fxstatat64.c new file mode 100644 index 0000000..533438a --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/fxstatat64.c @@ -0,0 +1,54 @@ +/* fxstatat64 implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +extern void __cp_stat64_statx (struct stat64 *to, struct statx *from); + +/* Get information about the file NAME in BUF. */ + +int +__fxstatat64 (int vers, int fd, const char *file, struct stat64 *st, int flag) +{ + if (__glibc_unlikely (vers != _STAT_VER_LINUX)) + return INLINE_SYSCALL_ERROR_RETURN_VALUE (EINVAL); + + int result; + struct statx tmp; + INTERNAL_SYSCALL_DECL (err); + + result = INTERNAL_SYSCALL (statx, err, 5, fd, file, + AT_NO_AUTOMOUNT | flag, + STATX_BASIC_STATS, &tmp); + __cp_stat64_statx (st, &tmp); + if (!__builtin_expect (INTERNAL_SYSCALL_ERROR_P (result, err), 1)) + return 0; + else + return INLINE_SYSCALL_ERROR_RETURN_VALUE (INTERNAL_SYSCALL_ERRNO (result, + err)); +} +libc_hidden_def (__fxstatat64) diff --git a/sysdeps/unix/sysv/linux/csky/lxstat.c b/sysdeps/unix/sysv/linux/csky/lxstat.c new file mode 100644 index 0000000..22063b5 --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/lxstat.c @@ -0,0 +1,50 @@ +/* lxstat implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include + +#include +#include + +#if !XSTAT_IS_XSTAT64 +#include "overflow.h" + +extern void __cp_stat_statx (struct stat *to, struct statx *from); + +/* Get information about the file NAME in BUF. */ +int +__lxstat (int vers, const char *name, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + { + struct statx tmp; + int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, name, + AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW, + STATX_BASIC_STATS, &tmp); + __cp_stat_statx (buf, &tmp); + return rc ?: stat_overflow (buf); + } + errno = EINVAL; + return -1; +} +hidden_def (__lxstat) +#endif diff --git a/sysdeps/unix/sysv/linux/csky/lxstat64.c b/sysdeps/unix/sysv/linux/csky/lxstat64.c new file mode 100644 index 0000000..aabf630 --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/lxstat64.c @@ -0,0 +1,60 @@ +/* lxstat64 implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +/* Hide the prototype for __lxstat so that GCC will not complain about + the different function signature if it is aliased to __lxstat64. + If XSTAT_IS_XSTAT64 is set to non-zero then the stat and stat64 + structures have an identical layout but different type names. */ + +#define __lxstat __lxstat_disable + +#include +#include +#include +#include +#include + +#include +#include + +extern void __cp_stat64_statx (struct stat64 *to, struct statx *from); + +/* Get information about the file NAME in BUF. */ +int +__lxstat64 (int vers, const char *name, struct stat64 *buf) +{ + int ret; + struct statx tmp; + if (vers == _STAT_VER_KERNEL) + { + ret = INLINE_SYSCALL (statx, 5, AT_FDCWD, name, + AT_NO_AUTOMOUNT | AT_SYMLINK_NOFOLLOW, + STATX_BASIC_STATS, &tmp); + __cp_stat64_statx (buf, &tmp); + return ret; + } + errno = EINVAL; + return -1; +} +hidden_def (__lxstat64) + +#undef __lxstat +#if XSTAT_IS_XSTAT64 +strong_alias (__lxstat64, __lxstat) +hidden_ver (__lxstat64, __lxstat) +#endif diff --git a/sysdeps/unix/sysv/linux/csky/statx_cp.c b/sysdeps/unix/sysv/linux/csky/statx_cp.c new file mode 100644 index 0000000..eff147c --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/statx_cp.c @@ -0,0 +1,75 @@ +/* Struct statx to stat/stat64 conversion for Linux. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +void +__cp_stat_statx (struct stat *to, struct statx *from) +{ + memset(to, 0, sizeof(struct stat)); + to->st_dev = (from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8) | + ((from->stx_dev_minor & ~0xff) << 12); + to->st_rdev = (from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8) | + ((from->stx_rdev_minor & ~0xff) << 12); + to->st_ino = from->stx_ino; + to->st_mode = from->stx_mode; + to->st_nlink = from->stx_nlink; + to->st_uid = from->stx_uid; + to->st_gid = from->stx_gid; + to->st_atime = from->stx_atime.tv_sec; + to->st_atim.tv_nsec = from->stx_atime.tv_nsec; + to->st_mtime = from->stx_mtime.tv_sec; + to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec; + to->st_ctime = from->stx_ctime.tv_sec; + to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec; + to->st_size = from->stx_size; + to->st_blocks = from->stx_blocks; + to->st_blksize = from->stx_blksize; +} + +void +__cp_stat64_statx (struct stat64 *to, struct statx *from) +{ + memset(to, 0, sizeof(struct stat64)); + to->st_dev = (from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8) | + ((from->stx_dev_minor & ~0xff) << 12); + to->st_rdev = (from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8) | + ((from->stx_rdev_minor & ~0xff) << 12); + to->st_ino = from->stx_ino; + to->st_mode = from->stx_mode; + to->st_nlink = from->stx_nlink; + to->st_uid = from->stx_uid; + to->st_gid = from->stx_gid; + to->st_atime = from->stx_atime.tv_sec; + to->st_atim.tv_nsec = from->stx_atime.tv_nsec; + to->st_mtime = from->stx_mtime.tv_sec; + to->st_mtim.tv_nsec = from->stx_mtime.tv_nsec; + to->st_ctime = from->stx_ctime.tv_sec; + to->st_ctim.tv_nsec = from->stx_ctime.tv_nsec; + to->st_size = from->stx_size; + to->st_blocks = from->stx_blocks; + to->st_blksize = from->stx_blksize; +} diff --git a/sysdeps/unix/sysv/linux/csky/xstat.c b/sysdeps/unix/sysv/linux/csky/xstat.c new file mode 100644 index 0000000..5cae11f --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/xstat.c @@ -0,0 +1,51 @@ +/* xstat implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#if !XSTAT_IS_XSTAT64 +#include "overflow.h" + +extern void __cp_stat_statx (struct stat *to, struct statx *from); + +/* Get information about the file NAME in BUF. */ +int +__xstat (int vers, const char *name, struct stat *buf) +{ + if (vers == _STAT_VER_KERNEL) + { + struct statx tmp; + int rc = INLINE_SYSCALL (statx, 5, AT_FDCWD, name, AT_NO_AUTOMOUNT, + STATX_BASIC_STATS, &tmp); + __cp_stat_statx (buf, &tmp); + return rc; + } + + errno = EINVAL; + return -1; +} +hidden_def (__xstat) +#endif diff --git a/sysdeps/unix/sysv/linux/csky/xstat64.c b/sysdeps/unix/sysv/linux/csky/xstat64.c new file mode 100644 index 0000000..cf81462 --- /dev/null +++ b/sysdeps/unix/sysv/linux/csky/xstat64.c @@ -0,0 +1,60 @@ +/* xstat64 implemented with statx system call. C-SKY version. + Copyright (C) 2018 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 + . */ + +/* Hide the prototype for __xstat so that GCC will not complain about + the different function signature if it is aliased to __xstat64. + If XSTAT_IS_XSTAT64 is set to non-zero then the stat and stat64 + structures have an identical layout but different type names. */ + +#define __xstat __xstat_disable + +#include +#include +#include +#include +#include + +#include +#include + +extern void __cp_stat64_statx (struct stat64 *to, struct statx *from); + +/* Get information about the file NAME in BUF. */ +int +__xstat64 (int vers, const char *name, struct stat64 *buf) +{ + int ret; + struct statx tmp; + if (vers == _STAT_VER_KERNEL) + { + ret = INLINE_SYSCALL (statx, 5, AT_FDCWD, name, AT_NO_AUTOMOUNT, + STATX_BASIC_STATS, &tmp); + __cp_stat64_statx (buf, &tmp); + return ret; + } + + errno = EINVAL; + return -1; +} +hidden_def (__xstat64) + +#undef __xstat +#if XSTAT_IS_XSTAT64 +strong_alias (__xstat64, __xstat) +hidden_ver (__xstat64, __xstat) +#endif