From patchwork Tue Mar 6 07:45:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 881949 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-90833-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="v2jkJPYV"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zwTNS5Sw7z9ryl for ; Tue, 6 Mar 2018 18:46:00 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=EiwIPoAIlOFG/14pA81XJhifdBqFAibPfccO/TcYXGm W3nHstiQ5ff4VKyBwQrTEZlz9TOzcOf5L98n7iH5Fx4IYxEu4n4YLeTMJr1+HY7J t1ZabTRh/tX1HQk2mjtzHzGk30i1ZSxkmHmZKmgreI4RvfrwRvtkFdrdBj1HaYto = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=rA0v1UWI0ZdSVWOZx59IgFsySuY=; b=v2jkJPYVAnK9UZ+eh Y+QWMgF14Pu/peXxUwS7JAm20RVkVGjyd4+1auuwDiLb5iphp1dJSZXLgU/7YerG rIbRXcLhZIP0Yik3rTq050EA9YNpsB0bA1sJwWO1tir/PJB1jvJT6l/KP1HS5EZB 9aKqpyiwbtT+IJ3pI5D//ppHeM= Received: (qmail 38028 invoked by alias); 6 Mar 2018 07:45:38 -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 35078 invoked by uid 89); 6 Mar 2018 07:45:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=tvp X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: =?utf-8?q?Fl=C3=A1vio_Cruz?= Subject: [hurd, commited 1/2] hurd: Define and pass UTIME_NOW and UTIME_OMIT to new file_utimens RPC Date: Tue, 6 Mar 2018 08:45:18 +0100 Message-Id: <20180306074519.6980-2-samuel.thibault@ens-lyon.org> In-Reply-To: <20180306074519.6980-1-samuel.thibault@ens-lyon.org> References: <20180306074519.6980-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 From: Flávio Cruz * sysdeps/mach/hurd/bits/stat.h [__USE_ATFILE] (UTIME_NOW, UTIME_OMIT): New macros. * sysdeps/mach/hurd/futimens.c (__futimens): Try to use __file_utimens before reverting to converting time spec to time value and calling __file_utimes. * sysdeps/mach/hurd/utime-helper.c: New file. * sysdeps/mach/hurd/futimes.c: Include "utime-helper.c". (__futimes): Try to use utime_ts_from_tval and __file_utimens before reverting to utime_tvalue_from_tval and __file_utimes. * sysdeps/mach/hurd/lutimes.c: Include "utime-helper.c". (__lutimes): Just call hurd_futimens after lookup. * sysdeps/mach/hurd/utimes.c: Likewise. --- ChangeLog | 15 +++++++ sysdeps/mach/hurd/bits/stat.h | 5 +++ sysdeps/mach/hurd/futimens.c | 45 +++++++++++++++++---- sysdeps/mach/hurd/futimes.c | 26 ++++++------- sysdeps/mach/hurd/lutimes.c | 21 +++------- sysdeps/mach/hurd/utime-helper.c | 84 ++++++++++++++++++++++++++++++++++++++++ sysdeps/mach/hurd/utimes.c | 21 +++------- 7 files changed, 164 insertions(+), 53 deletions(-) create mode 100644 sysdeps/mach/hurd/utime-helper.c diff --git a/ChangeLog b/ChangeLog index f586c3f55e..989881e972 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2018-03-05 Flávio Cruz + + * sysdeps/mach/hurd/bits/stat.h [__USE_ATFILE] (UTIME_NOW, + UTIME_OMIT): New macros. + * sysdeps/mach/hurd/futimens.c (__futimens): Try to use __file_utimens + before reverting to converting time spec to time value and calling + __file_utimes. + * sysdeps/mach/hurd/utime-helper.c: New file. + * sysdeps/mach/hurd/futimes.c: Include "utime-helper.c". + (__futimes): Try to use utime_ts_from_tval and __file_utimens before + reverting to utime_tvalue_from_tval and __file_utimes. + * sysdeps/mach/hurd/lutimes.c: Include "utime-helper.c". + (__lutimes): Just call hurd_futimens after lookup. + * sysdeps/mach/hurd/utimes.c: Likewise. + 2018-03-05 Samuel Thibault * bits/sigaction.h: Add include guard. diff --git a/sysdeps/mach/hurd/bits/stat.h b/sysdeps/mach/hurd/bits/stat.h index 7296cd2dcc..e354a05237 100644 --- a/sysdeps/mach/hurd/bits/stat.h +++ b/sysdeps/mach/hurd/bits/stat.h @@ -244,6 +244,11 @@ struct stat64 # define SF_NOUNLINK 0x00100000 /* file may not be removed or renamed */ # define SF_SNAPSHOT 0x00200000 /* snapshot inode */ +#ifdef __USE_ATFILE +# define UTIME_NOW -1 /* corresponds to the current time */ +# define UTIME_OMIT -2 /* target time is omitted */ +#endif + __BEGIN_DECLS /* Set file flags for FILE to FLAGS. */ diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c index 44ba7f15f1..4a8b0f7fa4 100644 --- a/sysdeps/mach/hurd/futimens.c +++ b/sysdeps/mach/hurd/futimens.c @@ -27,24 +27,53 @@ int __futimens (int fd, const struct timespec tsp[2]) { - time_value_t atime, mtime; + struct timespec atime, mtime; error_t err; if (tsp == NULL) { - /* Setting the number of microseconds to `-1' tells the + /* Setting the number of nanoseconds to UTIME_NOW tells the underlying filesystems to use the current time. */ - atime.microseconds = mtime.microseconds = -1; + atime.tv_sec = 0; + atime.tv_nsec = UTIME_NOW; + mtime.tv_sec = 0; + mtime.tv_nsec = UTIME_NOW; } else { - atime.seconds = tsp[0].tv_sec; - atime.microseconds = tsp[0].tv_nsec / 1000; - mtime.seconds = tsp[1].tv_sec; - mtime.microseconds = tsp[1].tv_nsec / 1000; + atime = tsp[0]; + mtime = tsp[1]; } - err = HURD_DPORT_USE (fd, __file_utimes (port, atime, mtime)); + err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime)); + + if (err == MIG_BAD_ID || err == EOPNOTSUPP) + { + time_value_t atim, mtim; + + if (tsp == NULL) + /* Setting the number of microseconds to `-1' tells the + underlying filesystems to use the current time. */ + atim.microseconds = mtim.microseconds = -1; + else + { + if (tsp[0].tv_nsec == UTIME_NOW) + atim.microseconds = -1; + else if (tsp[0].tv_nsec == UTIME_OMIT) + atim.microseconds = -2; + else + TIMESPEC_TO_TIME_VALUE (&atim, &(tsp[0])); + if (tsp[1].tv_nsec == UTIME_NOW) + mtim.microseconds = -1; + else if (tsp[1].tv_nsec == UTIME_OMIT) + mtim.microseconds = -2; + else + TIMESPEC_TO_TIME_VALUE (&mtim, &(tsp[1])); + } + + err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim)); + } + return err ? __hurd_dfail (fd, err) : 0; } weak_alias (__futimens, futimens) diff --git a/sysdeps/mach/hurd/futimes.c b/sysdeps/mach/hurd/futimes.c index cc2a68f641..1b521e3e51 100644 --- a/sysdeps/mach/hurd/futimes.c +++ b/sysdeps/mach/hurd/futimes.c @@ -22,29 +22,29 @@ #include #include +#include "utime-helper.c" + /* Change the access time of FD to TVP[0] and the modification time of FD to TVP[1]. */ int __futimes (int fd, const struct timeval tvp[2]) { - union tv - { - struct timeval tv; - time_value_t tvt; - }; - const union tv *u = (const union tv *) tvp; - union tv nulltv[2]; + struct timespec atime, mtime; error_t err; - if (tvp == NULL) + utime_ts_from_tval (tvp, &atime, &mtime); + + err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime)); + + if (err == EMIG_BAD_ID || err == EOPNOTSUPP) { - /* Setting the number of microseconds to `-1' tells the - underlying filesystems to use the current time. */ - nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1; - u = nulltv; + time_value_t atim, mtim; + + utime_tvalue_from_tval (tvp, &atim, &mtim); + + err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim)); } - err = HURD_DPORT_USE (fd, __file_utimes (port, u[0].tvt, u[1].tvt)); return err ? __hurd_dfail (fd, err) : 0; } weak_alias (__futimes, futimes) diff --git a/sysdeps/mach/hurd/lutimes.c b/sysdeps/mach/hurd/lutimes.c index e6b0f04172..23b00c1739 100644 --- a/sysdeps/mach/hurd/lutimes.c +++ b/sysdeps/mach/hurd/lutimes.c @@ -22,33 +22,22 @@ #include #include +#include "utime-helper.c" + /* Change the access time of FILE to TVP[0] and the modification time of FILE to TVP[1]. */ int __lutimes (const char *file, const struct timeval tvp[2]) { - union tv - { - struct timeval tv; - time_value_t tvt; - }; - const union tv *u = (const union tv *) tvp; - union tv nulltv[2]; error_t err; file_t port; - if (tvp == NULL) - { - /* Setting the number of microseconds to `-1' tells the - underlying filesystems to use the current time. */ - nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1; - u = nulltv; - } - port = __file_name_lookup (file, O_NOLINK, 0); if (port == MACH_PORT_NULL) return -1; - err = __file_utimes (port, u[0].tvt, u[1].tvt); + + err = hurd_futimens (port, tvp); + __mach_port_deallocate (__mach_task_self (), port); if (err) return __hurd_fail (err); diff --git a/sysdeps/mach/hurd/utime-helper.c b/sysdeps/mach/hurd/utime-helper.c new file mode 100644 index 0000000000..357dfe9705 --- /dev/null +++ b/sysdeps/mach/hurd/utime-helper.c @@ -0,0 +1,84 @@ +/* Helpers for utimes/utimens conversions. + Copyright (C) 2015-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 + +/* Initializes atime/mtime timespec structures from an array of timeval. */ +static inline void +utime_ts_from_tval (const struct timeval tvp[2], + struct timespec *atime, struct timespec *mtime) +{ + if (tvp == NULL) + { + /* Setting the number of nanoseconds to UTIME_NOW tells the + underlying filesystems to use the current time. */ + atime->tv_sec = 0; + atime->tv_nsec = UTIME_NOW; + mtime->tv_sec = 0; + mtime->tv_nsec = UTIME_NOW; + } + else + { + TIMEVAL_TO_TIMESPEC (&tvp[0], atime); + TIMEVAL_TO_TIMESPEC (&tvp[1], mtime); + } +} + +/* Initializes atime/mtime time_value_t structures from an array of timeval. */ +static inline void +utime_tvalue_from_tval (const struct timeval tvp[2], + time_value_t *atime, time_value_t *mtime) +{ + if (tvp == NULL) + /* Setting the number of microseconds to `-1' tells the + underlying filesystems to use the current time. */ + atime->microseconds = mtime->microseconds = -1; + else + { + atime->seconds = tvp[0].tv_sec; + atime->microseconds = tvp[0].tv_usec; + mtime->seconds = tvp[1].tv_sec; + mtime->microseconds = tvp[1].tv_usec; + } +} + +/* Changes the access time of the file behind PORT using a timeval array. */ +static inline error_t +hurd_futimens (const file_t port, const struct timeval tvp[2]) +{ + error_t err; + struct timespec atime, mtime; + + utime_ts_from_tval (tvp, &atime, &mtime); + + err = __file_utimens (port, atime, mtime); + + if (err == MIG_BAD_ID || err == EOPNOTSUPP) + { + time_value_t atim, mtim; + + utime_tvalue_from_tval (tvp, &atim, &mtim); + + err = __file_utimes (port, atim, mtim); + } + + return err; +} diff --git a/sysdeps/mach/hurd/utimes.c b/sysdeps/mach/hurd/utimes.c index 2f7c8c228d..25e47539fe 100644 --- a/sysdeps/mach/hurd/utimes.c +++ b/sysdeps/mach/hurd/utimes.c @@ -20,33 +20,22 @@ #include #include +#include "utime-helper.c" + /* Change the access time of FILE to TVP[0] and the modification time of FILE to TVP[1]. */ int __utimes (const char *file, const struct timeval tvp[2]) { - union tv - { - struct timeval tv; - time_value_t tvt; - }; - const union tv *u = (const union tv *) tvp; - union tv nulltv[2]; error_t err; file_t port; - if (tvp == NULL) - { - /* Setting the number of microseconds to `-1' tells the - underlying filesystems to use the current time. */ - nulltv[0].tvt.microseconds = nulltv[1].tvt.microseconds = -1; - u = nulltv; - } - port = __file_name_lookup (file, 0, 0); if (port == MACH_PORT_NULL) return -1; - err = __file_utimes (port, u[0].tvt, u[1].tvt); + + err = hurd_futimens (port, tvp); + __mach_port_deallocate (__mach_task_self (), port); if (err) return __hurd_fail (err); From patchwork Tue Mar 6 07:45:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 881948 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-90832-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ens-lyon.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="bAFXlVt7"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zwTNH49pGz9sZy for ; Tue, 6 Mar 2018 18:45:51 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; q=dns; s=default; b=TZpdfyeaGoNovI9x5nz1POoTrjHewudquWFr0osSNE/ P0Qsf5mZOqePZYO6E441ZDL4bLLZPEJt0+NaYYpwErYMw++QdcM1/aLDu2kIJxEd 96BnXquMVwOn60OXYB7DT/SBFoHjX90KQtnj8BiZwVdig5KKOZYsTErv5MLcnSUU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; s=default; bh=UB1pqnvNbSpoMDjg03JhOnXyufQ=; b=bAFXlVt7NyFqAu+zL meL9Yj5brohtSknsujnWXB3x39DDKv5L1XSf+r4I+drAb+QtP+QbP4gZWEjDlgIA TY9Fje+BrvgtBFaEkbJj6eetmqsbMhIpnG5t31fpO0vllJEME3EGvWoY/avnd88P Q7XLtoPHsBG5Vts0M3EGFdLDxw= Received: (qmail 37839 invoked by alias); 6 Mar 2018 07:45:37 -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 35075 invoked by uid 89); 6 Mar 2018 07:45:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_HELO_PASS, SPF_NEUTRAL autolearn=ham version=3.3.2 spammy=tvp, 8273 X-HELO: hera.aquilenet.fr From: Samuel Thibault To: libc-alpha@sourceware.org Cc: Samuel Thibault Subject: [hurd,commited 2/2] hurd: Add futimesat and utimensat support Date: Tue, 6 Mar 2018 08:45:19 +0100 Message-Id: <20180306074519.6980-3-samuel.thibault@ens-lyon.org> In-Reply-To: <20180306074519.6980-1-samuel.thibault@ens-lyon.org> References: <20180306074519.6980-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 * sysdeps/mach/hurd/utime-helper.c (hurd_futimens): Rename function to hurd_futimes. * sysdeps/mach/hurd/utimes.c (__utimes): Update call accordingly. * sysdeps/mach/hurd/lutimes.c (__lutimes): Likewise. * sysdeps/mach/hurd/futimens.c: Include "utime-helper.c". (__futimens): Move implementation to... * sysdeps/mach/hurd/utime-helper.c (utime_ts_from_tspec, utime_tvalue_from_tspec): ... new helper functions. (hurd_futimens): New function. * sysdeps/mach/hurd/futimesat.c: New file. * sysdeps/mach/hurd/utimensat.c: New file. --- ChangeLog | 14 ++++++++ sysdeps/mach/hurd/futimens.c | 37 +++------------------ sysdeps/mach/hurd/futimesat.c | 44 ++++++++++++++++++++++++ sysdeps/mach/hurd/lutimes.c | 2 +- sysdeps/mach/hurd/utime-helper.c | 72 +++++++++++++++++++++++++++++++++++++++- sysdeps/mach/hurd/utimensat.c | 46 +++++++++++++++++++++++++ sysdeps/mach/hurd/utimes.c | 2 +- 7 files changed, 181 insertions(+), 36 deletions(-) create mode 100644 sysdeps/mach/hurd/futimesat.c create mode 100644 sysdeps/mach/hurd/utimensat.c diff --git a/ChangeLog b/ChangeLog index 989881e972..27ca1dcbfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2018-03-05 Samuel Thibault + + * sysdeps/mach/hurd/utime-helper.c (hurd_futimens): Rename function to + hurd_futimes. + * sysdeps/mach/hurd/utimes.c (__utimes): Update call accordingly. + * sysdeps/mach/hurd/lutimes.c (__lutimes): Likewise. + * sysdeps/mach/hurd/futimens.c: Include "utime-helper.c". + (__futimens): Move implementation to... + * sysdeps/mach/hurd/utime-helper.c (utime_ts_from_tspec, + utime_tvalue_from_tspec): ... new helper functions. + (hurd_futimens): New function. + * sysdeps/mach/hurd/futimesat.c: New file. + * sysdeps/mach/hurd/utimensat.c: New file. + 2018-03-05 Flávio Cruz * sysdeps/mach/hurd/bits/stat.h [__USE_ATFILE] (UTIME_NOW, diff --git a/sysdeps/mach/hurd/futimens.c b/sysdeps/mach/hurd/futimens.c index 4a8b0f7fa4..4a3943e673 100644 --- a/sysdeps/mach/hurd/futimens.c +++ b/sysdeps/mach/hurd/futimens.c @@ -22,6 +22,8 @@ #include #include +#include "utime-helper.c" + /* Change the access time of FD to TSP[0] and the modification time of FD to TSP[1]. */ int @@ -30,20 +32,7 @@ __futimens (int fd, const struct timespec tsp[2]) struct timespec atime, mtime; error_t err; - if (tsp == NULL) - { - /* Setting the number of nanoseconds to UTIME_NOW tells the - underlying filesystems to use the current time. */ - atime.tv_sec = 0; - atime.tv_nsec = UTIME_NOW; - mtime.tv_sec = 0; - mtime.tv_nsec = UTIME_NOW; - } - else - { - atime = tsp[0]; - mtime = tsp[1]; - } + utime_ts_from_tspec (tsp, &atime, &mtime); err = HURD_DPORT_USE (fd, __file_utimens (port, atime, mtime)); @@ -51,25 +40,7 @@ __futimens (int fd, const struct timespec tsp[2]) { time_value_t atim, mtim; - if (tsp == NULL) - /* Setting the number of microseconds to `-1' tells the - underlying filesystems to use the current time. */ - atim.microseconds = mtim.microseconds = -1; - else - { - if (tsp[0].tv_nsec == UTIME_NOW) - atim.microseconds = -1; - else if (tsp[0].tv_nsec == UTIME_OMIT) - atim.microseconds = -2; - else - TIMESPEC_TO_TIME_VALUE (&atim, &(tsp[0])); - if (tsp[1].tv_nsec == UTIME_NOW) - mtim.microseconds = -1; - else if (tsp[1].tv_nsec == UTIME_OMIT) - mtim.microseconds = -2; - else - TIMESPEC_TO_TIME_VALUE (&mtim, &(tsp[1])); - } + utime_tvalue_from_tspec (tsp, &atim, &mtim); err = HURD_DPORT_USE (fd, __file_utimes (port, atim, mtim)); } diff --git a/sysdeps/mach/hurd/futimesat.c b/sysdeps/mach/hurd/futimesat.c new file mode 100644 index 0000000000..99c4c63633 --- /dev/null +++ b/sysdeps/mach/hurd/futimesat.c @@ -0,0 +1,44 @@ +/* Copyright (C) 1991-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 "utime-helper.c" + +/* Change the access time of FILE relative to FD to TVP[0] and + the modification time of FILE to TVP[1]. */ +int +futimesat (int fd, const char *file, const struct timeval tvp[2]) +{ + error_t err; + file_t port; + + port = __file_name_lookup_at (fd, 0, file, 0, 0); + if (port == MACH_PORT_NULL) + return -1; + + err = hurd_futimes (port, tvp); + + __mach_port_deallocate (__mach_task_self (), port); + if (err) + return __hurd_fail (err); + return 0; +} diff --git a/sysdeps/mach/hurd/lutimes.c b/sysdeps/mach/hurd/lutimes.c index 23b00c1739..375ab3feb3 100644 --- a/sysdeps/mach/hurd/lutimes.c +++ b/sysdeps/mach/hurd/lutimes.c @@ -36,7 +36,7 @@ __lutimes (const char *file, const struct timeval tvp[2]) if (port == MACH_PORT_NULL) return -1; - err = hurd_futimens (port, tvp); + err = hurd_futimes (port, tvp); __mach_port_deallocate (__mach_task_self (), port); if (err) diff --git a/sysdeps/mach/hurd/utime-helper.c b/sysdeps/mach/hurd/utime-helper.c index 357dfe9705..6aed3316a7 100644 --- a/sysdeps/mach/hurd/utime-helper.c +++ b/sysdeps/mach/hurd/utime-helper.c @@ -62,7 +62,7 @@ utime_tvalue_from_tval (const struct timeval tvp[2], /* Changes the access time of the file behind PORT using a timeval array. */ static inline error_t -hurd_futimens (const file_t port, const struct timeval tvp[2]) +hurd_futimes (const file_t port, const struct timeval tvp[2]) { error_t err; struct timespec atime, mtime; @@ -82,3 +82,73 @@ hurd_futimens (const file_t port, const struct timeval tvp[2]) return err; } + +/* Initializes atime/mtime timespec structures from an array of timespec. */ +static inline void +utime_ts_from_tspec (const struct timespec tsp[2], + struct timespec *atime, struct timespec *mtime) +{ + if (tsp == NULL) + { + /* Setting the number of nanoseconds to UTIME_NOW tells the + underlying filesystems to use the current time. */ + atime->tv_sec = 0; + atime->tv_nsec = UTIME_NOW; + mtime->tv_sec = 0; + mtime->tv_nsec = UTIME_NOW; + } + else + { + *atime = tsp[0]; + *mtime = tsp[1]; + } +} + +/* Initializes atime/mtime time_value_t structures from an array of timespec. */ +static inline void +utime_tvalue_from_tspec (const struct timespec tsp[2], + time_value_t *atime, time_value_t *mtime) +{ + if (tsp == NULL) + /* Setting the number of microseconds to `-1' tells the + underlying filesystems to use the current time. */ + atime->microseconds = mtime->microseconds = -1; + else + { + if (tsp[0].tv_nsec == UTIME_NOW) + atime->microseconds = -1; + else if (tsp[0].tv_nsec == UTIME_OMIT) + atime->microseconds = -2; + else + TIMESPEC_TO_TIME_VALUE (atime, &(tsp[0])); + if (tsp[1].tv_nsec == UTIME_NOW) + mtime->microseconds = -1; + else if (tsp[1].tv_nsec == UTIME_OMIT) + mtime->microseconds = -2; + else + TIMESPEC_TO_TIME_VALUE (mtime, &(tsp[1])); + } +} + +/* Changes the access time of the file behind PORT using a timespec array. */ +static inline error_t +hurd_futimens (const file_t port, const struct timespec tsp[2]) +{ + error_t err; + struct timespec atime, mtime; + + utime_ts_from_tspec (tsp, &atime, &mtime); + + err = __file_utimens (port, atime, mtime); + + if (err == MIG_BAD_ID || err == EOPNOTSUPP) + { + time_value_t atim, mtim; + + utime_tvalue_from_tspec (tsp, &atim, &mtim); + + err = __file_utimes (port, atim, mtim); + } + + return err; +} diff --git a/sysdeps/mach/hurd/utimensat.c b/sysdeps/mach/hurd/utimensat.c new file mode 100644 index 0000000000..ac9bc534c8 --- /dev/null +++ b/sysdeps/mach/hurd/utimensat.c @@ -0,0 +1,46 @@ +/* Change access and modification times of open file. Hurd version. + Copyright (C) 1991-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 "utime-helper.c" + +/* Change the access time of FILE to TSP[0] and + the modification time of FILE to TSP[1]. */ +int +utimensat (int fd, const char *file, const struct timespec tsp[2], + int flags) +{ + error_t err; + file_t port; + + port = __file_name_lookup_at (fd, flags, file, 0, 0); + if (port == MACH_PORT_NULL) + return -1; + + err = hurd_futimens (port, tsp); + + __mach_port_deallocate (__mach_task_self (), port); + if (err) + return __hurd_fail (err); + return 0; +} diff --git a/sysdeps/mach/hurd/utimes.c b/sysdeps/mach/hurd/utimes.c index 25e47539fe..fa8a79239b 100644 --- a/sysdeps/mach/hurd/utimes.c +++ b/sysdeps/mach/hurd/utimes.c @@ -34,7 +34,7 @@ __utimes (const char *file, const struct timeval tvp[2]) if (port == MACH_PORT_NULL) return -1; - err = hurd_futimens (port, tvp); + err = hurd_futimes (port, tvp); __mach_port_deallocate (__mach_task_self (), port); if (err)