From owner-dev-commits-src-main@freebsd.org Sun Jun 6 13:59:24 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8C9B465EFA2; Sun, 6 Jun 2021 13:59:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FydR03KXqz4qBH; Sun, 6 Jun 2021 13:59:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5A8A324B98; Sun, 6 Jun 2021 13:59:24 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 156DxOUH005876; Sun, 6 Jun 2021 13:59:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 156DxOX8005875; Sun, 6 Jun 2021 13:59:24 GMT (envelope-from git) Date: Sun, 6 Jun 2021 13:59:24 GMT Message-Id: <202106061359.156DxOX8005875@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Dmitry Chagin Subject: git: e4bffb80bbc6 - main - linux(4): Implement utimensat_time64 system call. MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dchagin X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: e4bffb80bbc6a2e4b3be89aefcbd5bb2c2fc0ba0 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 06 Jun 2021 13:59:24 -0000 The branch main has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=e4bffb80bbc6a2e4b3be89aefcbd5bb2c2fc0ba0 commit e4bffb80bbc6a2e4b3be89aefcbd5bb2c2fc0ba0 Author: Dmitry Chagin AuthorDate: 2021-06-07 01:54:30 +0000 Commit: Dmitry Chagin CommitDate: 2021-06-07 01:54:30 +0000 linux(4): Implement utimensat_time64 system call. MFC after: 2 weeks --- sys/amd64/linux32/linux32_dummy_machdep.c | 1 - sys/amd64/linux32/syscalls.master | 7 +- sys/compat/linux/linux_misc.c | 181 ++++++++++++++++++++---------- sys/i386/linux/linux_dummy_machdep.c | 1 - sys/i386/linux/syscalls.master | 7 +- 5 files changed, 134 insertions(+), 63 deletions(-) diff --git a/sys/amd64/linux32/linux32_dummy_machdep.c b/sys/amd64/linux32/linux32_dummy_machdep.c index 5eb54fefd276..be07eb033e77 100644 --- a/sys/amd64/linux32/linux32_dummy_machdep.c +++ b/sys/amd64/linux32/linux32_dummy_machdep.c @@ -76,7 +76,6 @@ DUMMY(timer_gettime64); DUMMY(timer_settime64); DUMMY(timerfd_gettime64); DUMMY(timerfd_settime64); -DUMMY(utimensat_time64); DUMMY(pselect6_time64); DUMMY(ppoll_time64); DUMMY(io_pgetevents_time64); diff --git a/sys/amd64/linux32/syscalls.master b/sys/amd64/linux32/syscalls.master index d7002ed5ac72..67591b487652 100644 --- a/sys/amd64/linux32/syscalls.master +++ b/sys/amd64/linux32/syscalls.master @@ -2368,7 +2368,12 @@ int linux_timerfd_settime64(void); } 412 AUE_NULL STD { - int linux_utimensat_time64(void); + int linux_utimensat_time64( + l_int dfd, + const char *pathname, + const struct l_timespec64 *times64, + l_int flags + ); } 413 AUE_NULL STD { int linux_pselect6_time64(void); diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index c3f783694d84..bfa7bb659d5f 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -130,7 +130,14 @@ struct l_pselect6arg { l_size_t ss_len; }; -static int linux_utimensat_nsec_valid(l_long); +static int linux_utimensat_lts_to_ts(struct l_timespec *, + struct timespec *); +#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) +static int linux_utimensat_lts64_to_ts(struct l_timespec64 *, + struct timespec *); +#endif +static int linux_common_utimensat(struct thread *, int, + const char *, struct timespec *, int); int linux_sysinfo(struct thread *td, struct linux_sysinfo_args *args) @@ -780,89 +787,66 @@ linux_utimes(struct thread *td, struct linux_utimes_args *args) #endif static int -linux_utimensat_nsec_valid(l_long nsec) +linux_utimensat_lts_to_ts(struct l_timespec *l_times, struct timespec *times) { - if (nsec == LINUX_UTIME_OMIT || nsec == LINUX_UTIME_NOW) - return (0); - if (nsec >= 0 && nsec <= 999999999) - return (0); - return (1); + if (l_times->tv_nsec != LINUX_UTIME_OMIT && + l_times->tv_nsec != LINUX_UTIME_NOW && + (l_times->tv_nsec < 0 || l_times->tv_nsec > 999999999)) + return (EINVAL); + + times->tv_sec = l_times->tv_sec; + switch (l_times->tv_nsec) + { + case LINUX_UTIME_OMIT: + times->tv_nsec = UTIME_OMIT; + break; + case LINUX_UTIME_NOW: + times->tv_nsec = UTIME_NOW; + break; + default: + times->tv_nsec = l_times->tv_nsec; + } + + return (0); } -int -linux_utimensat(struct thread *td, struct linux_utimensat_args *args) +static int +linux_common_utimensat(struct thread *td, int ldfd, const char *pathname, + struct timespec *timesp, int lflags) { - struct l_timespec l_times[2]; - struct timespec times[2], *timesp = NULL; char *path = NULL; int error, dfd, flags = 0; - dfd = (args->dfd == LINUX_AT_FDCWD) ? AT_FDCWD : args->dfd; + dfd = (ldfd == LINUX_AT_FDCWD) ? AT_FDCWD : ldfd; - if (args->flags & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH)) + if (lflags & ~(LINUX_AT_SYMLINK_NOFOLLOW | LINUX_AT_EMPTY_PATH)) return (EINVAL); - if (args->times != NULL) { - error = copyin(args->times, l_times, sizeof(l_times)); - if (error != 0) - return (error); - - if (linux_utimensat_nsec_valid(l_times[0].tv_nsec) != 0 || - linux_utimensat_nsec_valid(l_times[1].tv_nsec) != 0) - return (EINVAL); - - times[0].tv_sec = l_times[0].tv_sec; - switch (l_times[0].tv_nsec) - { - case LINUX_UTIME_OMIT: - times[0].tv_nsec = UTIME_OMIT; - break; - case LINUX_UTIME_NOW: - times[0].tv_nsec = UTIME_NOW; - break; - default: - times[0].tv_nsec = l_times[0].tv_nsec; - } - - times[1].tv_sec = l_times[1].tv_sec; - switch (l_times[1].tv_nsec) - { - case LINUX_UTIME_OMIT: - times[1].tv_nsec = UTIME_OMIT; - break; - case LINUX_UTIME_NOW: - times[1].tv_nsec = UTIME_NOW; - break; - default: - times[1].tv_nsec = l_times[1].tv_nsec; - break; - } - timesp = times; - + if (timesp != NULL) { /* This breaks POSIX, but is what the Linux kernel does * _on purpose_ (documented in the man page for utimensat(2)), * so we must follow that behaviour. */ - if (times[0].tv_nsec == UTIME_OMIT && - times[1].tv_nsec == UTIME_OMIT) + if (timesp[0].tv_nsec == UTIME_OMIT && + timesp[1].tv_nsec == UTIME_OMIT) return (0); } - if (args->flags & LINUX_AT_SYMLINK_NOFOLLOW) + if (lflags & LINUX_AT_SYMLINK_NOFOLLOW) flags |= AT_SYMLINK_NOFOLLOW; - if (args->flags & LINUX_AT_EMPTY_PATH) + if (lflags & LINUX_AT_EMPTY_PATH) flags |= AT_EMPTY_PATH; if (!LUSECONVPATH(td)) { - if (args->pathname != NULL) { - return (kern_utimensat(td, dfd, args->pathname, + if (pathname != NULL) { + return (kern_utimensat(td, dfd, pathname, UIO_USERSPACE, timesp, UIO_SYSSPACE, flags)); } } - if (args->pathname != NULL) - LCONVPATHEXIST_AT(td, args->pathname, &path, dfd); - else if (args->flags != 0) + if (pathname != NULL) + LCONVPATHEXIST_AT(td, pathname, &path, dfd); + else if (lflags != 0) return (EINVAL); if (path == NULL) @@ -876,6 +860,85 @@ linux_utimensat(struct thread *td, struct linux_utimensat_args *args) return (error); } +int +linux_utimensat(struct thread *td, struct linux_utimensat_args *args) +{ + struct l_timespec l_times[2]; + struct timespec times[2], *timesp; + int error; + + if (args->times != NULL) { + error = copyin(args->times, l_times, sizeof(l_times)); + if (error != 0) + return (error); + + error = linux_utimensat_lts_to_ts(&l_times[0], ×[0]); + if (error != 0) + return (error); + error = linux_utimensat_lts_to_ts(&l_times[1], ×[1]); + if (error != 0) + return (error); + timesp = times; + } else + timesp = NULL; + + return (linux_common_utimensat(td, args->dfd, args->pathname, + timesp, args->flags)); +} + +#if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32)) +static int +linux_utimensat_lts64_to_ts(struct l_timespec64 *l_times, struct timespec *times) +{ + + if (l_times->tv_nsec != LINUX_UTIME_OMIT && + l_times->tv_nsec != LINUX_UTIME_NOW && + (l_times->tv_nsec < 0 || l_times->tv_nsec > 999999999)) + return (EINVAL); + + times->tv_sec = l_times->tv_sec; + switch (l_times->tv_nsec) + { + case LINUX_UTIME_OMIT: + times->tv_nsec = UTIME_OMIT; + break; + case LINUX_UTIME_NOW: + times->tv_nsec = UTIME_NOW; + break; + default: + times->tv_nsec = l_times->tv_nsec; + } + + return (0); +} + +int +linux_utimensat_time64(struct thread *td, struct linux_utimensat_time64_args *args) +{ + struct l_timespec64 l_times[2]; + struct timespec times[2], *timesp; + int error; + + if (args->times64 != NULL) { + error = copyin(args->times64, l_times, sizeof(l_times)); + if (error != 0) + return (error); + + error = linux_utimensat_lts64_to_ts(&l_times[0], ×[0]); + if (error != 0) + return (error); + error = linux_utimensat_lts64_to_ts(&l_times[1], ×[1]); + if (error != 0) + return (error); + timesp = times; + } else + timesp = NULL; + + return (linux_common_utimensat(td, args->dfd, args->pathname, + timesp, args->flags)); +} +#endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */ + #ifdef LINUX_LEGACY_SYSCALLS int linux_futimesat(struct thread *td, struct linux_futimesat_args *args) diff --git a/sys/i386/linux/linux_dummy_machdep.c b/sys/i386/linux/linux_dummy_machdep.c index dfcc691a3582..d479ecde7a01 100644 --- a/sys/i386/linux/linux_dummy_machdep.c +++ b/sys/i386/linux/linux_dummy_machdep.c @@ -78,7 +78,6 @@ DUMMY(timer_gettime64); DUMMY(timer_settime64); DUMMY(timerfd_gettime64); DUMMY(timerfd_settime64); -DUMMY(utimensat_time64); DUMMY(pselect6_time64); DUMMY(ppoll_time64); DUMMY(io_pgetevents_time64); diff --git a/sys/i386/linux/syscalls.master b/sys/i386/linux/syscalls.master index e2732d211235..5ba21877f42c 100644 --- a/sys/i386/linux/syscalls.master +++ b/sys/i386/linux/syscalls.master @@ -2386,7 +2386,12 @@ int linux_timerfd_settime64(void); } 412 AUE_NULL STD { - int linux_utimensat_time64(void); + int linux_utimensat_time64( + l_int dfd, + const char *pathname, + const struct l_timespec64 *times64, + l_int flags + ); } 413 AUE_NULL STD { int linux_pselect6_time64(void);