From patchwork Fri Mar 19 18:31:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42700 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 784D13842400; Fri, 19 Mar 2021 18:31:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 784D13842400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616178690; bh=WFcqp9W19NBB0qgfk2DUmMGyQp3blEps8+OX7WUKDT8=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fOE3DEyReqqinHAZ+VglELP2ltmH/fp1TPwFeu2Swx6qYTHq9vkdt+1mqNPdm8HR/ SZnsPd6ak93MZ7x0cG/Trllk/EWqzgZEzB1nLJYOfUB7tFgqQhO0q/BtFxlnDNYK8O okUha1PKa1T5jXHwN7gjvp8Xi95pjcCHc45ewhjE= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72e.google.com (mail-qk1-x72e.google.com [IPv6:2607:f8b0:4864:20::72e]) by sourceware.org (Postfix) with ESMTPS id 6639D3857C7F for ; Fri, 19 Mar 2021 18:31:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6639D3857C7F Received: by mail-qk1-x72e.google.com with SMTP id z10so3932746qkz.13 for ; Fri, 19 Mar 2021 11:31:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WFcqp9W19NBB0qgfk2DUmMGyQp3blEps8+OX7WUKDT8=; b=DQmzqEPd2YkRrbDo521k/cNWLi4khTR/hejuiFG4253Kqcw2KuV22CzEJoiFE20gy+ hytxGW1D+oSwqMystGuK6ektD34S73c6sWfzpDGMPoXpHjuMkchWes3RRPvtAa5zcdbF C4RBB+H0WXMWDudWNNkun9i+txkwg7pbMb5+18nRsNAdYHJ8avTzftrKVLnxPPBNk6B+ ojRGu4S6cKzZWoqgOZHd4v8+wgKi10YMniPJxVpConrt3wWFDl7N8MMdsRuVQCRKQ0+b Ekj7LS1RIA2ZdJnfhojwfJrqUngzOn6x0CugjqpOmieYTprwoaUjBhZhvv3UDgr4Dkon aYYw== X-Gm-Message-State: AOAM53346Qdfj989nXxmjUW/Ivh8R622paGafy5T8ixWDF8/PS4gCZ7T sW5YhhysYiuQgRvnF0vIAc2tkYIwPbtHzKW/ X-Google-Smtp-Source: ABdhPJyaDXNrambtgrBeIDRbQ6s/kyvkTsmj5aLhluKFc8ox9ZuZboZpfnMTRpNjPAHsp4JxGo9p+w== X-Received: by 2002:a05:620a:c11:: with SMTP id l17mr10882217qki.487.1616178687711; Fri, 19 Mar 2021 11:31:27 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z11sm5205747qkg.52.2021.03.19.11.31.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 11:31:27 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 1/5] linux: Implement fstatat with __fstatat64_time64 Date: Fri, 19 Mar 2021 15:31:17 -0300 Message-Id: <20210319183121.2252064-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> References: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It makes fstatat use __NR_statx, which fix the s390 issue with missing nanoxsecond support on compat stat syscalls (at least on recent kernels) and limits the statx call to only one function (which simplifies the __ASSUME_STATX support). Checked on i686-linux-gnu and on powerpc-linux-gnu. --- sysdeps/unix/sysv/linux/fstatat.c | 52 +++++++------------------------ 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fstatat.c b/sysdeps/unix/sysv/linux/fstatat.c index 59efff615f..618c254d6f 100644 --- a/sysdeps/unix/sysv/linux/fstatat.c +++ b/sysdeps/unix/sysv/linux/fstatat.c @@ -26,33 +26,19 @@ int __fstatat (int fd, const char *file, struct stat *buf, int flag) { - int r; - -# if STAT_IS_KERNEL_STAT - /* New kABIs which uses generic pre 64-bit time Linux ABI, e.g. - csky, nios2 */ - r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, buf, flag); - if (r == 0 && (buf->__st_ino_pad != 0 - || buf->__st_size_pad != 0 - || buf->__st_blocks_pad != 0)) - return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); -# else -# ifdef __NR_fstatat64 - /* Old KABIs with old non-LFS support, e.g. arm, i386, hppa, m68k, mips32, - microblaze, s390, sh, powerpc, and sparc. */ - struct stat64 st64; - r = INTERNAL_SYSCALL_CALL (fstatat64, fd, file, &st64, flag); + struct __stat64_t64 st64; + int r = __fstatat64_time64 (fd, file, &st64, flag); if (r == 0) { if (! in_ino_t_range (st64.st_ino) || ! in_off_t_range (st64.st_size) - || ! in_blkcnt_t_range (st64.st_blocks)) + || ! in_blkcnt_t_range (st64.st_blocks) + || ! in_time_t_range (st64.st_atim.tv_sec) + || ! in_time_t_range (st64.st_mtim.tv_sec) + || ! in_time_t_range (st64.st_ctim.tv_sec)) return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW); - /* Clear internal pad and reserved fields. */ - memset (buf, 0, sizeof (*buf)); - - buf->st_dev = st64.st_dev, + buf->st_dev = st64.st_dev; buf->st_ino = st64.st_ino; buf->st_mode = st64.st_mode; buf->st_nlink = st64.st_nlink; @@ -62,27 +48,11 @@ __fstatat (int fd, const char *file, struct stat *buf, int flag) 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; - - return 0; + buf->st_atim = valid_timespec64_to_timespec (st64.st_atim); + buf->st_mtim = valid_timespec64_to_timespec (st64.st_mtim); + buf->st_ctim = valid_timespec64_to_timespec (st64.st_ctim); } -# else - /* 64-bit kabi outlier, e.g. mips64 and mips64-n32. */ - struct kernel_stat kst; - r = INTERNAL_SYSCALL_CALL (newfstatat, fd, file, &kst, flag); - if (r == 0) - r = __cp_kstat_stat (&kst, buf); -# endif /* __nr_fstatat64 */ -# endif /* STAT_IS_KERNEL_STAT */ - - return INTERNAL_SYSCALL_ERROR_P (r) - ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r) - : 0; + return r; } weak_alias (__fstatat, fstatat) From patchwork Fri Mar 19 18:31:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42701 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 292973842412; Fri, 19 Mar 2021 18:31:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 292973842412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616178692; bh=otFmZ2ut81OsywCLEaLe/5pejTse5aHwdynEIFOFELU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=x09AqGQeJiDAbOVVPVjnS5W24oBINNZZf/D/fDv3mBF2SWEQMY2kn/qR3sqWHbVql v7X/4u4VUnM6Ql8LCEz5XjZIs5iuhRgD7JKHp6RTTVDteHhvpZ0LPFQr6bXgBN+wni MRL+h5THJ76oTgPSU5AcQDWmIO4VOFU74Tc+H7xo= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by sourceware.org (Postfix) with ESMTPS id 736203851C2E for ; Fri, 19 Mar 2021 18:31:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 736203851C2E Received: by mail-qk1-x731.google.com with SMTP id c3so3943102qkc.5 for ; Fri, 19 Mar 2021 11:31:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=otFmZ2ut81OsywCLEaLe/5pejTse5aHwdynEIFOFELU=; b=XkMVhL0A4Gl5dzVBy/e+6lbHsFSzZ4gv+HwfjcyWa3tvXA6G5FJV6Ji72l6QLOw7eA FOXQvzIyal6s3/V0n7c35WPqGr2b7/u/mWK80RQX4zvX58/+8wmk+rx09T5CP9vLvZQA Px4HdL8DkzMckZKXodckKjhfd3KuHc0bUORyaHNkXJJx1yspX3zDf1OsTUzaX6/1sPAK qAdkKmwjMJBHxLanjpTMDs8ta3+wIAleobeK9uGGKNiu+DzRJqQwnWN/mJvgE5gptBb2 hZboyPMnJBJsK1K5t5fxgfQRl3ofDOujdPQBo2SLaHNl2lFrikwUgHD/+CxkYM3oQJMw lOyw== X-Gm-Message-State: AOAM533gT8qH2eP3h56txrQXRPKXEA3ZnsoCEO+bU4bzY9d3mUZTd1Pj qIHXZHzZS2yFZIv+tRQV19+8K2+cXMHkWjfo X-Google-Smtp-Source: ABdhPJwPPO1hnjPAO2BszkB4vCwszmN8Wyl79mqdDj+vT5Acbpbwgkc983PIIRzyY6r0mG/6SfneBA== X-Received: by 2002:a05:620a:2206:: with SMTP id m6mr10663980qkh.176.1616178688829; Fri, 19 Mar 2021 11:31:28 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z11sm5205747qkg.52.2021.03.19.11.31.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 11:31:28 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 2/5] linux: Disable fstatat64 fallback if __ASSUME_STATX is defined Date: Fri, 19 Mar 2021 15:31:18 -0300 Message-Id: <20210319183121.2252064-3-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> References: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" If the minimum kernel supports statx there is no need to call the fallback stat legacy syscalls. The statx is also called on compat xstat syscall, but different than the fstatat it calls no fallback and it is assumed to be always present. Checked on powerpc-linux-gnu (with and without --enable-kernel=4.11) and on powerpc64-linux-gnu. --- sysdeps/unix/sysv/linux/fstatat64.c | 57 +++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 16 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c index 490226a8ec..c3a030af58 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -31,6 +31,7 @@ #if __TIMESIZE == 64 \ && (__WORDSIZE == 32 \ && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define FSTATAT_USE_STATX 1 /* Sanity check to avoid newer 32-bit ABI to support non-LFS calls. */ _Static_assert (sizeof (__off_t) == sizeof (__off64_t), "__blkcnt_t and __blkcnt64_t must match"); @@ -40,27 +41,25 @@ _Static_assert (sizeof (__blkcnt_t) == sizeof (__blkcnt64_t), "__blkcnt_t and __blkcnt64_t must match"); #endif -int -__fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf, - int flag) +static inline int +fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, + int flag) { - int r; - -#if (__WORDSIZE == 32 \ - && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) /* 32-bit kABI with default 64-bit time_t, e.g. arc, riscv32. Also 64-bit time_t support is done through statx syscall. */ struct statx tmp; - r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, - STATX_BASIC_STATS, &tmp); + int r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, + STATX_BASIC_STATS, &tmp); if (r == 0) - { - __cp_stat64_t64_statx (buf, &tmp); - return 0; - } - if (-r != ENOSYS) - return INLINE_SYSCALL_ERROR_RETURN_VALUE (-r); -#endif + __cp_stat64_t64_statx (buf, &tmp); + return r; +} + +static inline int +fstatat64_time64_stat (int fd, const char *file, struct __stat64_t64 *buf, + int flag) +{ + int r; #if XSTAT_IS_XSTAT64 # ifdef __NR_newfstatat @@ -114,6 +113,32 @@ __fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf, # endif #endif + return r; +} + +#if (__WORDSIZE == 32 \ + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) +# define FSTATAT_USE_STATX 1 +#else +# define FSTATAT_USE_STATX 0 +#endif + +int +__fstatat64_time64 (int fd, const char *file, struct __stat64_t64 *buf, + int flag) +{ + int r; + +#if FSTATAT_USE_STATX + r = fstatat64_time64_statx (fd, file, buf, flag); +# ifndef __ASSUME_STATX + if (r == -ENOSYS) + r = fstatat64_time64_stat (fd, file, buf, flag); +# endif +#else + r = fstatat64_time64_stat (fd, file, buf, flag); +#endif + return INTERNAL_SYSCALL_ERROR_P (r) ? INLINE_SYSCALL_ERROR_RETURN_VALUE (-r) : 0; From patchwork Fri Mar 19 18:31:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42702 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 751703842427; Fri, 19 Mar 2021 18:31:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 751703842427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616178693; bh=7PmVmilm354rQQzOGmios62WXSzVAwqBLj/dnMbTHyw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=t2OymayIcg/glmfrb+9FWX8rTms7wN+zfxwQ2LFmSL61G8mO37YQaXuxhRVHg82wb eyB3Fd4lAMNuoDZoWu2C8jm77uf49mlBciQu6xX0aMsBhm4FN61sCctDNEg3/WDYIe O1d8/kAQiwSoya0nikaIQOW3puMzI6S8YD4PNgV8= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qv1-xf34.google.com (mail-qv1-xf34.google.com [IPv6:2607:f8b0:4864:20::f34]) by sourceware.org (Postfix) with ESMTPS id 9D5613842412 for ; Fri, 19 Mar 2021 18:31:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9D5613842412 Received: by mail-qv1-xf34.google.com with SMTP id cx5so5502561qvb.10 for ; Fri, 19 Mar 2021 11:31:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7PmVmilm354rQQzOGmios62WXSzVAwqBLj/dnMbTHyw=; b=nh1ok0tp96M95+TM7HUfXGlpcTELzerzfPHctbXMJv06HKCk34TFvMQdbU4tKQiXVC qNuoV/hp9EGoBPitC41Et2deLDeFoUQ8afifCLbciWG3JYkxFIBRRFK2b+GeI4uNlJYl DWHMqFyaTlEPuwF6F80eFq5VqIR8LksPd+Bgx8v01N8nYsLN2irC25TpQeJ36m0kALMB 2CvrvK86vxz1LbUcFXH3IROYBZtvTuvghOgQSn6TQt6RKDRnhuTlu6f37CAHHqrRM4BV ZnsTPyK/NQ77c5EfAtflZR4Z22GQzZRE0Jrx2mxO+7BS0wz84sY2WmRSO64a8ueIG8tI dLLQ== X-Gm-Message-State: AOAM533Czq5vzGqPma5jaBKCuAhkDO8q7d5SIy2xJF0dd0HQurQowmr8 hW7XcGsea0oSW5SUQG56uMMJNGsgQoF0wATA X-Google-Smtp-Source: ABdhPJykwh6Ta/mJK43+Hbd570sRcBgyingfxIQ1YUpoVZQb3gyMhmUl7b2TjB9Illk15uO5/MbgRQ== X-Received: by 2002:a0c:9ad7:: with SMTP id k23mr10643228qvf.52.1616178689956; Fri, 19 Mar 2021 11:31:29 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z11sm5205747qkg.52.2021.03.19.11.31.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 11:31:29 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 3/5] linux: Use statx for MIPSn64 Date: Fri, 19 Mar 2021 15:31:19 -0300 Message-Id: <20210319183121.2252064-4-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> References: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" MIPSn64 kernel ABI for legacy stat uses unsigned 32 bit for second timestamp, which limits the maximum value to y2106. This patch make mips64 use statx as for 32-bit architectures. Thie __cp_stat64_t64_statx is open coded, its usage is solely on fstatat64 and it avoid the need to redefine the name for mips64 (which will call __cp_stat64_statx since its does not use __stat64_t64 internally). --- sysdeps/unix/sysv/linux/fstatat64.c | 29 +++++++++++++++++++--- sysdeps/unix/sysv/linux/fxstat64.c | 1 + sysdeps/unix/sysv/linux/mips/kernel_stat.h | 4 +++ sysdeps/unix/sysv/linux/statx_cp.c | 29 ---------------------- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/sysdeps/unix/sysv/linux/fstatat64.c b/sysdeps/unix/sysv/linux/fstatat64.c index c3a030af58..b9b8cd994b 100644 --- a/sysdeps/unix/sysv/linux/fstatat64.c +++ b/sysdeps/unix/sysv/linux/fstatat64.c @@ -24,9 +24,9 @@ #include #include #include -#include #include #include +#include #if __TIMESIZE == 64 \ && (__WORDSIZE == 32 \ @@ -50,8 +50,28 @@ fstatat64_time64_statx (int fd, const char *file, struct __stat64_t64 *buf, struct statx tmp; int r = INTERNAL_SYSCALL_CALL (statx, fd, file, AT_NO_AUTOMOUNT | flag, STATX_BASIC_STATS, &tmp); - if (r == 0) - __cp_stat64_t64_statx (buf, &tmp); + if (r != 0) + return r; + + *buf = (struct __stat64_t64) { + .st_dev = makedev (tmp.stx_dev_major, tmp.stx_dev_minor), + .st_rdev = makedev (tmp.stx_rdev_major, tmp.stx_rdev_minor), + .st_ino = tmp.stx_ino, + .st_mode = tmp.stx_mode, + .st_nlink = tmp.stx_nlink, + .st_uid = tmp.stx_uid, + .st_gid = tmp.stx_gid, + .st_atime = tmp.stx_atime.tv_sec, + .st_atim.tv_nsec = tmp.stx_atime.tv_nsec, + .st_mtime = tmp.stx_mtime.tv_sec, + .st_mtim.tv_nsec = tmp.stx_mtime.tv_nsec, + .st_ctime = tmp.stx_ctime.tv_sec, + .st_ctim.tv_nsec = tmp.stx_ctime.tv_nsec, + .st_size = tmp.stx_size, + .st_blocks = tmp.stx_blocks, + .st_blksize = tmp.stx_blksize, + }; + return r; } @@ -117,7 +137,8 @@ fstatat64_time64_stat (int fd, const char *file, struct __stat64_t64 *buf, } #if (__WORDSIZE == 32 \ - && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) + && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) \ + || defined STAT_HAS_TIME32 # define FSTATAT_USE_STATX 1 #else # define FSTATAT_USE_STATX 0 diff --git a/sysdeps/unix/sysv/linux/fxstat64.c b/sysdeps/unix/sysv/linux/fxstat64.c index be12798273..23d9d92b00 100644 --- a/sysdeps/unix/sysv/linux/fxstat64.c +++ b/sysdeps/unix/sysv/linux/fxstat64.c @@ -25,6 +25,7 @@ #include #include #include +#include #if LIB_COMPAT(libc, GLIBC_2_0, GLIBC_2_33) diff --git a/sysdeps/unix/sysv/linux/mips/kernel_stat.h b/sysdeps/unix/sysv/linux/mips/kernel_stat.h index e4b0f211ca..19524f7ea4 100644 --- a/sysdeps/unix/sysv/linux/mips/kernel_stat.h +++ b/sysdeps/unix/sysv/linux/mips/kernel_stat.h @@ -67,5 +67,9 @@ struct kernel_stat #else # define STATFS_IS_STATFS64 0 #endif +/* MIPS64 has unsigned 32 bit timestamps fields, so use statx as well. */ +#if _MIPS_SIM == _ABI64 +# define STAT_HAS_TIME32 +#endif #endif diff --git a/sysdeps/unix/sysv/linux/statx_cp.c b/sysdeps/unix/sysv/linux/statx_cp.c index 53068704c6..73405a9612 100644 --- a/sysdeps/unix/sysv/linux/statx_cp.c +++ b/sysdeps/unix/sysv/linux/statx_cp.c @@ -48,32 +48,3 @@ __cp_stat64_statx (struct stat64 *to, struct statx *from) } #endif -#if (__WORDSIZE == 32 \ - && (!defined __SYSCALL_WORDSIZE || __SYSCALL_WORDSIZE == 32)) -void -__cp_stat64_t64_statx (struct __stat64_t64 *to, const struct statx *from) -{ - /* Clear both pad and reserved fields. */ - memset (to, 0, sizeof (*to)); - - to->st_dev = ((from->stx_dev_minor & 0xff) | (from->stx_dev_major << 8) - | ((from->stx_dev_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_rdev = ((from->stx_rdev_minor & 0xff) | (from->stx_rdev_major << 8) - | ((from->stx_rdev_minor & ~0xff) << 12)); - to->st_size = from->stx_size; - to->st_blksize = from->stx_blksize; - to->st_blocks = from->stx_blocks; - - 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; -} -#endif From patchwork Fri Mar 19 18:31:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42703 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0692F384242C; Fri, 19 Mar 2021 18:31:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0692F384242C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616178694; bh=oUn20d6fyqsYvQif8F6rO1yliwNe/i97tM8owFw4YIY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=NMnvGxEzMISm3teCUHP5enW8DbaJT06lslOrJoA7T6m1QgHO+RTkChnkCDugwa/V9 ZCPcsRjHExIzQ0kNOO3wI5fVD85qvKqSmoge+b01B1t5NtsDwjHGf0BQhIdFbSh+Ro sOYEeGlbSlJKqniQsHo4j0kqyWlk4+wg8xDNvdHI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id B6E24386F446 for ; Fri, 19 Mar 2021 18:31:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B6E24386F446 Received: by mail-qk1-x72a.google.com with SMTP id v70so3945755qkb.8 for ; Fri, 19 Mar 2021 11:31:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oUn20d6fyqsYvQif8F6rO1yliwNe/i97tM8owFw4YIY=; b=jRcfJDF8XfRJeLxwPkbQxDCFeSMDGEfu27q5JnPCMOcgAA6NHiCJEoeiiiTyvWUTd8 YDwizwWC8LVX7mJcumLP3oO6Ci34LllauHqpitRD8rA6gZJ381/bIZeyWGLpyLC0Swbu agFGZmIKsHUWp/73EbEUbh6xQgADrwjcUbxj+h8eGkAEa/bpO3ssUdVS7K4oUUDKopDZ E9wuByVKd3ghwZVaXpZrQIAojFKgLY3k9TxQ0yQP7fGX3TLcOw5HsatTEgrrz1aRhpqG m6vD2zwbAfQKrCn4D7p8i3Q6WMdQ0Q3xGvDsc8iSAf/QifKspUqxxcr14cVQlFQ6K3kd 6j/w== X-Gm-Message-State: AOAM532Ivo6nT7CeT2YskEvFHKwXrECi5HvIGIcYCzgpK/+QMZS0c9MB ZpVWBH4Nb0N35Tvw+6HvYuh2jnXsMDv6XNGt X-Google-Smtp-Source: ABdhPJz3zYeLsfUBaxzk6AQ18GKrK4lS8POrz/d+MLCWdd3M/+qTa4xDxQ3XTnNlrgAzBqSmr7OtvQ== X-Received: by 2002:a37:a38e:: with SMTP id m136mr10743990qke.250.1616178691149; Fri, 19 Mar 2021 11:31:31 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z11sm5205747qkg.52.2021.03.19.11.31.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 11:31:30 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 4/5] support: Add support_path_support_time64_value Date: Fri, 19 Mar 2021 15:31:20 -0300 Message-Id: <20210319183121.2252064-5-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> References: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" It allows to check for support on arbitrary timestamp values. --- support/support.h | 11 +++++++++-- support/support_path_support_time64.c | 10 +++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/support/support.h b/support/support.h index 2e477c9e7c..5757c40833 100644 --- a/support/support.h +++ b/support/support.h @@ -130,9 +130,16 @@ extern void support_copy_file (const char *from, const char *to); extern ssize_t support_copy_file_range (int, off64_t *, int, off64_t *, size_t, unsigned int); -/* Return true is PATH supports 64-bit time_t interfaces for file +/* Return true if PATH supports 64-bit time_t interfaces for file operations (such as fstatat or utimensat). */ -extern bool support_path_support_time64 (const char *path); +extern bool support_path_support_time64_value (const char *path, int64_t at, + int64_t mt); +static __inline bool support_path_support_time64 (const char *path) +{ + /* 1s and 2s after y2038 limit. */ + return support_path_support_time64_value (path, 0x80000001ULL, + 0x80000002ULL); +} __END_DECLS diff --git a/support/support_path_support_time64.c b/support/support_path_support_time64.c index 452fedcde5..33b2bdff66 100644 --- a/support/support_path_support_time64.c +++ b/support/support_path_support_time64.c @@ -36,19 +36,15 @@ utimesat_call (const char *path, const struct __timespec64 tsp[2]) #endif bool -support_path_support_time64 (const char *path) +support_path_support_time64_value (const char *path, int64_t at, int64_t mt) { #ifdef __linux__ /* Obtain the original timestamps to restore at the end. */ struct statx ostx; TEST_VERIFY_EXIT (statx (AT_FDCWD, path, 0, STATX_BASIC_STATS, &ostx) == 0); - const struct __timespec64 tsp[] = - { - /* 1s and 2s after y2038 limit. */ - { 0x80000001ULL, 0 }, - { 0x80000002ULL, 0 } - }; + const struct __timespec64 tsp[] = { { at, 0 }, { mt, 0 } }; + /* Return is kernel does not support __NR_utimensat_time64. */ if (utimesat_call (path, tsp) == -1) return false; From patchwork Fri Mar 19 18:31:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42704 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 91E9E384241C; Fri, 19 Mar 2021 18:31:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 91E9E384241C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616178696; bh=5INoyruRuVsXLeymKy4HUvGFq2C9kSXdYvtpFIEVZrg=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=XA4c1ksnMmiGPs9vtHSuVoG0jITlhznBRO/TcDYBMwj3iA5UUOaGvpXW2XM/yfRIB erONJhKC1rkdmwa6RWfWOceyswmdhAbWZDkdzWz8b6xp70r9XPuwvgRXt6SppvHbUU GccPAJvb5BxRCY7YM9+irAHfEu8ixH3HYvaFVusg= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82d.google.com (mail-qt1-x82d.google.com [IPv6:2607:f8b0:4864:20::82d]) by sourceware.org (Postfix) with ESMTPS id 2C85C384241E for ; Fri, 19 Mar 2021 18:31:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2C85C384241E Received: by mail-qt1-x82d.google.com with SMTP id u7so7477372qtq.12 for ; Fri, 19 Mar 2021 11:31:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5INoyruRuVsXLeymKy4HUvGFq2C9kSXdYvtpFIEVZrg=; b=LmQwSKsOxD0dXBPvLTrCPmDxKimt8t29m+HgdUJVTPaMHDcNJJy/evE6w2N6YG3Dhj 4TAKTz/e80yb3lCqPROEhznqh3oUlYRhblbuWw+b7S6gCB9nDMGp91op2qqSFcDtDOQn q7CLpTnYg+cV/NG13Z7dKRAftoG1h1oWgBgn8fqxkpge/MO+FLV1UGjZcmhV6MCIUAKn seJga76ygUwPSNlS5JOaYFU3mQlJsi/VMJLyDKHDxU5zNNfVK3onPdUVaUfXdvU0bSwt xn+MSevcoz+42qgAkpgoFhzBcG6iXw7DEd3BoDRQpRXMSgI/rjXcpwvWUzAMoY6yuXmC cjcQ== X-Gm-Message-State: AOAM530c2HRnABrQIXu2s9GyluKWYeRsyi/3K3r7fRK3C1f2nXlwhMI1 VC84M8EbRllvVqXiTC9Tme+fcF4BRgSV4CFk X-Google-Smtp-Source: ABdhPJw9IsFIQEEyK2Kw5GXaQ1XKnVLSO0LHJMchM1wnsGfPRzwy2zSskmEAkaX7Qd9X46V10OC4AA== X-Received: by 2002:ac8:498d:: with SMTP id f13mr9333325qtq.54.1616178692318; Fri, 19 Mar 2021 11:31:32 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id z11sm5205747qkg.52.2021.03.19.11.31.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Mar 2021 11:31:32 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH 5/5] linux: Add y2106 support on utimensat tests Date: Fri, 19 Mar 2021 15:31:21 -0300 Message-Id: <20210319183121.2252064-6-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> References: <20210319183121.2252064-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" The tests are refactored to use a common skeleton that handles whether the underlying filesystem supports 64 bit time, skips 64 bit time tests when the TU only supports 32 bit, and also skip 64 bit time tests larger than 32 unsigned int (y2106) if the system does not support it (MIPSn64 on kernels without statx support). Checked on x86_64-linux-gnu and i686-linux-gnu. I also checked on a mips64el-linux-gnu with 4.1.4 and 5.10.0-4-5kc-malta kernel to verify if the y2106 are indeed skipped. --- sysdeps/unix/sysv/linux/tst-futimens.c | 63 ++----------- sysdeps/unix/sysv/linux/tst-utime.c | 63 ++----------- .../unix/sysv/linux/tst-utimensat-skeleton.c | 92 +++++++++++++++++++ sysdeps/unix/sysv/linux/tst-utimes.c | 68 +++----------- 4 files changed, 120 insertions(+), 166 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/tst-utimensat-skeleton.c diff --git a/sysdeps/unix/sysv/linux/tst-futimens.c b/sysdeps/unix/sysv/linux/tst-futimens.c index 785cd87557..ac7a980017 100644 --- a/sysdeps/unix/sysv/linux/tst-futimens.c +++ b/sysdeps/unix/sysv/linux/tst-futimens.c @@ -16,57 +16,18 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include #include -#include #include -#include - -static int temp_fd = -1; -static char *testfile; - -/* struct timespec array with Y2038 threshold minus 2 and 1 seconds. */ -const struct timespec t1[2] = { { 0x7FFFFFFE, 0 }, { 0x7FFFFFFF, 0 } }; - -/* struct timespec array with Y2038 threshold plus 1 and 2 seconds. */ -const struct timespec t2[2] = { { 0x80000001ULL, 0 }, { 0x80000002ULL, 0 } }; - -/* struct timespec array around Y2038 threshold. */ -const struct timespec t3[2] = { { 0x7FFFFFFE, 0 }, { 0x80000002ULL, 0 } }; - -#define PREPARE do_prepare -static void -do_prepare (int argc, char *argv[]) -{ - temp_fd = create_temp_file ("futimensat", &testfile); - TEST_VERIFY_EXIT (temp_fd > 0); -} +#include static int -test_futimens_helper (const struct timespec *ts) +test_futimens_helper (const char *file, int fd, const struct timespec *ts) { - if (!support_path_support_time64 (testfile)) - FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps", - testfile); - - struct stat64 st; - int result; - time_t t; - - /* Check if we run on port with 32 bit time_t size */ - if (__builtin_add_overflow (ts->tv_sec, 0, &t)) - { - printf("time_t overflow!"); - return 0; - } - - result = futimens (temp_fd, ts); + int result = futimens (fd, ts); TEST_VERIFY_EXIT (result == 0); - xfstat (temp_fd, &st); + struct stat64 st; + xfstat (fd, &st); /* Check if seconds for atime match */ TEST_COMPARE (st.st_atime, ts[0].tv_sec); @@ -77,14 +38,8 @@ test_futimens_helper (const struct timespec *ts) return 0; } -static int -do_test (void) -{ - test_futimens_helper (&t1[0]); - test_futimens_helper (&t2[0]); - test_futimens_helper (&t3[0]); - - return 0; -} +#define TEST_CALL(fname, fd, v1, v2) \ + test_futimens_helper (fname, fd, (struct timespec[]) { { v1, 0 }, \ + { v2, 0 } }) -#include +#include "tst-utimensat-skeleton.c" diff --git a/sysdeps/unix/sysv/linux/tst-utime.c b/sysdeps/unix/sysv/linux/tst-utime.c index 21e4e41dea..c1c7e75a29 100644 --- a/sysdeps/unix/sysv/linux/tst-utime.c +++ b/sysdeps/unix/sysv/linux/tst-utime.c @@ -16,59 +16,19 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include #include #include -#include #include -#include - -static int temp_fd = -1; -static char *testfile; - -/* struct utimbuf with Y2038 threshold minus 2 and 1 seconds. */ -const static struct utimbuf t1 = { 0x7FFFFFFE, 0x7FFFFFFF }; - -/* struct utimbuf with Y2038 threshold plus 1 and 2 seconds. */ -const static struct utimbuf t2 = { 0x80000001ULL, 0x80000002ULL }; - -/* struct utimbuf around Y2038 threshold. */ -const static struct utimbuf t3 = { 0x7FFFFFFE, 0x80000002ULL }; - -#define PREPARE do_prepare -static void -do_prepare (int argc, char *argv[]) -{ - temp_fd = create_temp_file ("utime", &testfile); - TEST_VERIFY_EXIT (temp_fd > 0); -} +#include static int -test_utime_helper (const struct utimbuf *ut) +test_utime_helper (const char *file, int fd, const struct utimbuf *ut) { - if (!support_path_support_time64 (testfile)) - FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps", - testfile); - - struct stat64 st; - int result; - time_t t; - - /* Check if we run on port with 32 bit time_t size */ - if (__builtin_add_overflow (ut->actime, 0, &t)) - { - printf("time_t overflow!"); - return 0; - } - - result = utime (testfile, ut); + int result = utime (file, ut); TEST_VERIFY_EXIT (result == 0); - xfstat (temp_fd, &st); + struct stat64 st; + xfstat (fd, &st); /* Check if seconds for actime match */ TEST_COMPARE (st.st_atime, ut->actime); @@ -79,14 +39,7 @@ test_utime_helper (const struct utimbuf *ut) return 0; } -static int -do_test (void) -{ - test_utime_helper (&t1); - test_utime_helper (&t2); - test_utime_helper (&t3); - - return 0; -} +#define TEST_CALL(fname, fd, v1, v2) \ + test_utime_helper (fname, fd, &(struct utimbuf) { (v1), (v2) }) -#include +#include "tst-utimensat-skeleton.c" diff --git a/sysdeps/unix/sysv/linux/tst-utimensat-skeleton.c b/sysdeps/unix/sysv/linux/tst-utimensat-skeleton.c new file mode 100644 index 0000000000..ed3d537b1f --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-utimensat-skeleton.c @@ -0,0 +1,92 @@ +/* Common tests for utimensat routines. + Copyright (C) 2021 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 + +static int temp_fd = -1; +static char *testfile; + +const static struct { + int64_t v1; + int64_t v2; +} tests[] = { + /* Y2038 threshold minus 2 and 1 seconds. */ + { 0x7FFFFFFELL, 0x7FFFFFFFLL }, + /* Y2038 threshold plus 1 and 2 seconds. */ + { 0x80000001LL, 0x80000002LL }, + /* Around Y2038 threshold. */ + { 0x7FFFFFFELL, 0x80000002LL }, + /* Y2106 threshold minus 2 and 1 seconds. */ + { 0x100000000LL, 0xFFFFFFFELL }, + /* Y2106 threshold plus 1 and 2 seconds. */ + { 0x100000001LL, 0x100000002LL }, + /* Around Y2106 threshold. */ + { 0xFFFFFFFELL, 0xFFFFFFFELL }, +}; + +#define PREPARE do_prepare +static void +do_prepare (int argc, char *argv[]) +{ + temp_fd = create_temp_file ("utime", &testfile); + TEST_VERIFY_EXIT (temp_fd > 0); +} + +static int +do_test (void) +{ + if (!support_path_support_time64 (testfile)) + FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps", + testfile); + + bool y2106 = support_path_support_time64_value (testfile, + 0x100000001LL, + 0x100000002LL); + + for (int i = 0; i < array_length (tests); i++) + { + /* Check if we run on port with 32 bit time_t size. */ + time_t t; + if (__builtin_add_overflow (tests[i].v1, 0, &t) + || __builtin_add_overflow (tests[i].v2, 0, &t)) + { + printf ("warning: skipping tests[%d] { %" PRIx64 ", %" PRIx64 " }: " + "time_t overflows\n", i, tests[i].v1, tests[i].v2); + continue; + } + + if (tests[i].v1 >= 0x100000000LL && !y2106) + { + printf ("warning: skipping tests[%d] { %" PRIx64 ", %" PRIx64 " }: " + "unsupported timestamp value\n", + i, tests[i].v1, tests[i].v2); + continue; + } + + //test_utime_helper (&(struct utimbuf) { tests[i].v1, tests[i].v2 }); + TEST_CALL (testfile, temp_fd, tests[i].v1, tests[i].v2); + } + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/tst-utimes.c b/sysdeps/unix/sysv/linux/tst-utimes.c index 0f23e44897..ba710508b7 100644 --- a/sysdeps/unix/sysv/linux/tst-utimes.c +++ b/sysdeps/unix/sysv/linux/tst-utimes.c @@ -16,60 +16,20 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include #include -#include #include -#include - -static int temp_fd = -1; -static char *testfile; - -/* struct timeval array with Y2038 threshold minus 2 and 1 seconds. */ -const static struct timeval t1[2] = { { 0x7FFFFFFE, 0 }, { 0x7FFFFFFF, 0 } }; - -/* struct timeval array with Y2038 threshold plus 1 and 2 seconds. */ -const static -struct timeval t2[2] = { { 0x80000001ULL, 0 }, { 0x80000002ULL, 0 } }; - -/* struct timeval array around Y2038 threshold. */ -const static -struct timeval t3[2] = { { 0x7FFFFFFE, 0 }, { 0x80000002ULL, 0 } }; - -#define PREPARE do_prepare -static void -do_prepare (int argc, char *argv[]) -{ - temp_fd = create_temp_file ("utimes", &testfile); - TEST_VERIFY_EXIT (temp_fd > 0); -} +#include +#include +#include static int -test_utime_helper (const struct timeval *tv) +test_utimes_helper (const char *file, int fd, const struct timeval *tv) { - if (!support_path_support_time64 (testfile)) - FAIL_UNSUPPORTED ("File %s does not support 64-bit timestamps", - testfile); - - struct stat64 st; - int result; - time_t t; - - /* Check if we run on port with 32 bit time_t size */ - if (__builtin_add_overflow (tv->tv_sec, 0, &t)) - { - printf("time_t overflow!"); - return 0; - } - - result = utimes (testfile, tv); + int result = utimes (file, tv); TEST_VERIFY_EXIT (result == 0); - xfstat (temp_fd, &st); + struct stat64 st; + xfstat (fd, &st); /* Check if seconds for atime match */ TEST_COMPARE (st.st_atime, tv[0].tv_sec); @@ -80,14 +40,8 @@ test_utime_helper (const struct timeval *tv) return 0; } -static int -do_test (void) -{ - test_utime_helper (&t1[0]); - test_utime_helper (&t2[0]); - test_utime_helper (&t3[0]); - - return 0; -} +#define TEST_CALL(fname, fd, v1, v2) \ + test_utimes_helper (fname, fd, (struct timeval[]) { { v1, 0 }, \ + { v2, 0 } }) -#include +#include "tst-utimensat-skeleton.c"