From patchwork Tue Jul 17 14:18:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 28440 Received: (qmail 12978 invoked by alias); 17 Jul 2018 14:18:47 -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 12966 invoked by uid 89); 17 Jul 2018 14:18:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=HTo:U*hch X-HELO: mail-lj1-f196.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=zHf3aHpBXHmAyhRzA9nCbitpYivGtPHBAJUpFPVUNHk=; b=a+u+pgjzABtYiZEMlooT4PIuxRYxYhxhfcEnFtVPn+tq3qrmmTM4/JVC4WNedUjXnZ 2DQVkXIn08D6tXfDqQjxRiQ0RMj6GS77Rv86cpX1uwQa76cJYJsbAKLyuQic6WVcoxYf gDrhzP413VZ0aZSElD/yQHn2KgMCdVcQBrBIaWXCKPiIg4FKiDiUbCrb7ntjS8dLYjd8 egfT2v4HD3BoZXFfrE8ZWABbZT6SyD00HEq335kDzin/9+/PXSGPrYl2IBcVvBA1Vvih NBdo/G/+AMsvNrEgZ25j3tWJG5dtZUuSPi3Z5tuegaLr8ycmNBIWnbeoA/01FZXiPguF KwXQ== MIME-Version: 1.0 Sender: arndbergmann@gmail.com In-Reply-To: <20180717125039.GB25416@infradead.org> References: <20180716161103.16239-1-arnd@arndb.de> <20180716161103.16239-3-arnd@arndb.de> <20180717125039.GB25416@infradead.org> From: Arnd Bergmann Date: Tue, 17 Jul 2018 16:18:41 +0200 Message-ID: Subject: Re: [PATCH v2 02/17] y2038: Remove newstat family from default syscall set To: Christoph Hellwig Cc: Thomas Gleixner , y2038 Mailman List , Linux API , linux-arch , GNU C Library , Albert ARIBAUD , Networking , Al Viro , Peter Zijlstra , Darren Hart , "Eric W . Biederman" , Dominik Brodowski On Tue, Jul 17, 2018 at 2:50 PM, Christoph Hellwig wrote: > On Mon, Jul 16, 2018 at 06:10:48PM +0200, Arnd Bergmann wrote: >> We have four generations of stat() syscalls: >> - the oldstat syscalls that are only used on the older architectures >> - the newstat family that is used on all 64-bit architectures but >> lacked support for large files on 32-bit architectures. >> - the stat64 family that is used mostly on 32-bit architectures to >> replace newstat >> - statx() to replace all of the above, adding 64-bit timestamps among >> other things. >> >> We already compile stat64 only on those architectures that need it, >> but newstat is always built, including on those that don't reference >> it. This adds a new __ARCH_WANT_NEW_STAT symbol along the lines of >> __ARCH_WANT_OLD_STAT and __ARCH_WANT_STAT64 to control compilation of >> newstat. All architectures that need it use an explict define, the >> others now get a little bit smaller, and future architecture (including >> 64-bit targets) won't ever see it. >> >> Acked-by: Geert Uytterhoeven >> Signed-off-by: Arnd Bergmann > > Do I read this right that you only want to provide statx by default? Yes, that is correct. > It is a little different from the traditional stat calls, so I'd like > to know this is actually ok from libc folks first. That would definitely help. See below for the stat implementation I did in my musl libc prototype based on statx(). It passes the LTP syscall tests, but that doesn't mean all the corner cases are correct. Arnd diff --git a/src/stat/fstat.c b/src/stat/fstat.c index ab4afc0..b4f2027 100644 --- a/src/stat/fstat.c +++ b/src/stat/fstat.c @@ -1,3 +1,4 @@ +#define _BSD_SOURCE #include #include #include @@ -8,6 +9,9 @@ void __procfdname(char *, unsigned); int fstat(int fd, struct stat *st) { +#ifdef __USE_TIME_BITS64 + return __statx(fd, "", st, AT_EMPTY_PATH | AT_STATX_SYNC_AS_STAT); +#else int ret = __syscall(SYS_fstat, fd, st); if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) return __syscall_ret(ret); @@ -19,6 +23,7 @@ int fstat(int fd, struct stat *st) #else return syscall(SYS_fstatat, AT_FDCWD, buf, st, 0); #endif +#endif } LFS64(fstat); diff --git a/src/stat/fstatat.c b/src/stat/fstatat.c index 863d526..80add64 100644 --- a/src/stat/fstatat.c +++ b/src/stat/fstatat.c @@ -1,10 +1,53 @@ +#define _BSD_SOURCE #include +#include +#include +#include #include "syscall.h" #include "libc.h" +#ifdef __USE_TIME_BITS64 + +#define AT_FLAGS (AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_EMPTY_PATH) + +int __statx(int fd, const char *restrict path, struct stat *restrict buf, int flag) +{ + struct statx stx; + int ret; + + ret = syscall(SYS_statx, fd, path, flag, STATX_BASIC_STATS, &stx); + + buf->st_dev = (dev_t)stx.stx_dev_major << 32 | stx.stx_dev_minor; + buf->st_ino = stx.stx_ino; + buf->st_mode = stx.stx_mode; + buf->st_nlink = stx.stx_nlink; + buf->st_uid = stx.stx_uid; + buf->st_gid = stx.stx_gid; + buf->st_rdev = (dev_t)stx.stx_rdev_major << 32 | stx.stx_rdev_minor; + buf->st_size = stx.stx_size; + buf->st_blksize = stx.stx_blksize; + buf->st_blocks = stx.stx_blocks; + buf->st_atim.tv_sec = stx.stx_atime.tv_sec; + buf->st_mtim.tv_sec = stx.stx_atime.tv_sec; + buf->st_ctim.tv_sec = stx.stx_atime.tv_sec; + buf->st_atim.tv_nsec = stx.stx_atime.tv_nsec; + buf->st_mtim.tv_nsec = stx.stx_atime.tv_nsec; + buf->st_ctim.tv_nsec = stx.stx_atime.tv_nsec; + + return ret; +} +#endif + int fstatat(int fd, const char *restrict path, struct stat *restrict buf, int flag) { +#ifdef __USE_TIME_BITS64 + if (flag & ~AT_FLAGS) + return __syscall_ret(-EINVAL); + + return __statx(fd, path, buf, flag); +#else return syscall(SYS_fstatat, fd, path, buf, flag); +#endif } LFS64(fstatat); diff --git a/src/stat/lstat.c b/src/stat/lstat.c index 5e8b84f..ad2bddd 100644 --- a/src/stat/lstat.c +++ b/src/stat/lstat.c @@ -1,3 +1,4 @@ +#define _BSD_SOURCE #include #include #include "syscall.h" @@ -5,7 +6,9 @@ int lstat(const char *restrict path, struct stat *restrict buf) { -#ifdef SYS_lstat +#ifdef __USE_TIME_BITS64 + return __statx(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW | AT_STATX_SYNC_AS_STAT); +#elif defined(SYS_lstat) return syscall(SYS_lstat, path, buf); #else return syscall(SYS_fstatat, AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW); diff --git a/src/stat/stat.c b/src/stat/stat.c index b4433a0..599903a 100644 --- a/src/stat/stat.c +++ b/src/stat/stat.c @@ -1,3 +1,4 @@ +#define _BSD_SOURCE #include #include #include "syscall.h" @@ -5,7 +6,9 @@ int stat(const char *restrict path, struct stat *restrict buf) { -#ifdef SYS_stat +#ifdef __USE_TIME_BITS64 + return __statx(AT_FDCWD, path, buf, AT_STATX_SYNC_AS_STAT); +#elif defined(SYS_stat) return syscall(SYS_stat, path, buf); #else return syscall(SYS_fstatat, AT_FDCWD, path, buf, 0);