From nobody Tue Jan 24 22:10:56 2023 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4P1h4c6KQQz3bf9L; Tue, 24 Jan 2023 22:10:56 +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 4P1h4c2pRpz4LtF; Tue, 24 Jan 2023 22:10:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=74m304WYYbR0tyH2OxOm+MKQ6vPW8BR+SyyFeFiqpig=; b=i+eZtAlsUADDb4B2/Me5jnWpuPahSqXuqzmC/DuqOZ3NoSr77mEU51rhNQuvOijvlvTrc2 HPtyMUzw8ZzzgKRz24C5U6INZflyxbU2zM0kagEHs8pgzFqnwLs2RI/ws5wP+eWc3xaLq/ AITwAaW6rZjdjlFvUp1FGQ9EHvFJMddGu+yf6k12nu1QyYR9GDxYdhtS7wvZG2KbPrxk1T IQkCSsSbqBt74wFT/Vv0EhIZoSTayBGSSPv/xbxJNg+bOYUEQYbgc2DUoz+l6G8BJfzNEk R/V6hwQXleoPp21JNgTQNO8vpt5luYxWLb+m3/XeCa6Bu/i5cxXrCLxzyIzvVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=74m304WYYbR0tyH2OxOm+MKQ6vPW8BR+SyyFeFiqpig=; b=DeTfJQqMB+FoKzpBfiOJ7M1u+eDZl7nbDfGgDsFsW45ypgB1SN9t2pa59Z9fNNLBxiE/ld aPObsldzL1vk22RKq4FHlK0Dr4cE/JnQtVgKEGOT7gvAcWd/GCdRcRfO2yNcmDCe/Leog9 TyiOJDYR4Qz/J5tkdWC949Ongb6lxovlpgCtrgZD8kJu4dpY5ifcWhH6TuXMKA9W6ueBuQ bdUgbLllDastL87kyYrm/rCENdTGYjqJ5XCH3AqGmoxyuFs8e0iTNI1G4AV/sPwHetOkl8 EioSULluyjnb/isO9MS//cffWnemMFFzPNUbnKbba21ypNpDJdrtO0tiWrMO+Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598256; a=rsa-sha256; cv=none; b=BSzFMr7d6BGs6WvLSjqv3GcJoLRGkbsdQanuwF2FlbosCeT4y7Z0dxq1xQJlu2yZVZGmKn qjCoqm9GKM5zF8EUtYgGvscKxEhPNfvsGcOFNY4Y0nkxIZ1Inxo5t0JihVZ99/Fd3tstUN 5spZgIJZGP0t673CL7mSNIrxftiZEl5miSc64qxFLDRAR5FTzc+SKIkondU1R3mJJ15Pl+ UNaLFIyqaUWWDY8hy4pI2wK5rf4DHz5YoYQsRC0AhLJRBkThp1Rne2VR4R2k/dmIrD3Ls0 Tu5A9p9ixomAL8eHKXFOp9AqRnlnfbj5ZJqcjc+i1EHTlDjSJ1FUgR10trYvig== 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 4P1h4c1vQCzPmp; Tue, 24 Jan 2023 22:10:56 +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 30OMAuGP083215; Tue, 24 Jan 2023 22:10:56 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMAueL083214; Tue, 24 Jan 2023 22:10:56 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:10:56 GMT Message-Id: <202301242210.30OMAueL083214@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Warner Losh Subject: git: 4084c293c175 - stable/13 - kboot: Implement stat(2) and fstat(2) system calls List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4084c293c17568178201057a12d4f821f9e55bea Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=4084c293c17568178201057a12d4f821f9e55bea commit 4084c293c17568178201057a12d4f821f9e55bea Author: Warner Losh AuthorDate: 2022-07-15 05:19:18 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:24 +0000 kboot: Implement stat(2) and fstat(2) system calls Implement stat(2) and fstat(2) in terms of newfstatat and newfstat system calls respectively (assume we have a compat #define when there's no newfstat and just a regular fstat and do so for ppc). Snag struct kstat (the Linux kernel stat(2), et al interface) from musl and attribute properly. Sponsored by: Netflix (cherry picked from commit a647d4a4d15df856d590c39c19d3973ec2e18825) --- stand/kboot/arch/amd64/stat_arch.h | 31 +++++++++++++++++++++++++++++++ stand/kboot/arch/amd64/syscall_nr.h | 2 ++ stand/kboot/arch/powerpc64/stat_arch.h | 27 +++++++++++++++++++++++++++ stand/kboot/arch/powerpc64/syscall_nr.h | 3 +++ stand/kboot/host_syscall.h | 17 +++++++++++++++++ stand/kboot/host_syscalls.c | 12 ++++++++++++ 6 files changed, 92 insertions(+) diff --git a/stand/kboot/arch/amd64/stat_arch.h b/stand/kboot/arch/amd64/stat_arch.h new file mode 100644 index 000000000000..ae180322fab4 --- /dev/null +++ b/stand/kboot/arch/amd64/stat_arch.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2005-2020 Rich Felker, et al. + * + * SPDX-Licnse-Identifier: MIT + * + * Note: From the musl project + */ + +struct host_kstat { + host_dev_t st_dev; + host_ino_t st_ino; + host_nlink_t st_nlink; + + host_mode_t st_mode; + host_uid_t st_uid; + host_gid_t st_gid; + unsigned int __pad0; + host_dev_t st_rdev; + host_off_t st_size; + host_blksize_t st_blksize; + host_blkcnt_t st_blocks; + + long st_atime_sec; + long st_atime_nsec; + long st_mtime_sec; + long st_mtime_nsec; + long st_ctime_sec; + long st_ctime_nsec; + long __pad_for_future[3]; +}; + diff --git a/stand/kboot/arch/amd64/syscall_nr.h b/stand/kboot/arch/amd64/syscall_nr.h index 506f85b3e731..c22c80ea7cb9 100644 --- a/stand/kboot/arch/amd64/syscall_nr.h +++ b/stand/kboot/arch/amd64/syscall_nr.h @@ -4,6 +4,8 @@ #define SYS_kexec_load 246 #define SYS_lseek 8 #define SYS_mmap 9 +#define SYS_newfstat 5 +#define SYS_newfstatat 262 #define SYS_openat 257 #define SYS_pselect6 270 #define SYS_read 0 diff --git a/stand/kboot/arch/powerpc64/stat_arch.h b/stand/kboot/arch/powerpc64/stat_arch.h new file mode 100644 index 000000000000..f22787b45feb --- /dev/null +++ b/stand/kboot/arch/powerpc64/stat_arch.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2005-2020 Rich Felker, et al. + * + * SPDX-Licnse-Identifier: MIT + * + * Note: From the musl project + */ + +struct host_kstat { + host_dev_t st_dev; + host_ino_t st_ino; + host_nlink_t st_nlink; + host_mode_t st_mode; + host_uid_t st_uid; + host_gid_t st_gid; + host_dev_t st_rdev; + host_off_t st_size; + host_blksize_t st_blksize; + host_blkcnt_t st_blocks; + long st_atime_sec; + long st_atime_nsec; + long st_mtime_sec; + long st_mtime_nsec; + long st_ctime_sec; + long st_ctime_nsec; + long __pad_for_future[3]; +}; diff --git a/stand/kboot/arch/powerpc64/syscall_nr.h b/stand/kboot/arch/powerpc64/syscall_nr.h index 592f3d6a7631..aa94e6a82bb7 100644 --- a/stand/kboot/arch/powerpc64/syscall_nr.h +++ b/stand/kboot/arch/powerpc64/syscall_nr.h @@ -1,9 +1,12 @@ #define SYS_close 6 +#define SYS_fstat 108 #define SYS_getdents 141 #define SYS_gettimeofday 78 #define SYS_kexec_load 268 #define SYS_llseek 140 #define SYS_mmap 90 +#define SYS_newfstat SYS_fstat +#define SYS_newfstatat 291 #define SYS_openat 286 #define SYS_pselect6 280 #define SYS_read 3 diff --git a/stand/kboot/host_syscall.h b/stand/kboot/host_syscall.h index 24b966b34ed8..6ff20f7ba393 100644 --- a/stand/kboot/host_syscall.h +++ b/stand/kboot/host_syscall.h @@ -32,6 +32,21 @@ long host_syscall(int number, ...); +/* + * Sizes taken from musl's include/alltypes.h.in and expanded for LP64 hosts + */ +typedef uint64_t host_dev_t; +typedef uint64_t host_ino_t; +typedef int64_t host_nlink_t; +typedef unsigned int host_mode_t; +typedef unsigned int host_uid_t; +typedef unsigned int host_gid_t; +typedef int64_t host_off_t; +typedef long host_blksize_t; +typedef int64_t host_blkcnt_t; + +#include "stat_arch.h" + /* * Constants for open, fcntl, etc * @@ -75,6 +90,7 @@ struct host_timeval { * System Calls */ int host_close(int fd); +int host_fstat(int fd, struct host_kstat *sb); int host_getdents(int fd, void *dirp, int count); int host_gettimeofday(struct host_timeval *a, void *b); int host_kexec_load(uint32_t start, int nsegs, uint32_t segs, uint32_t flags); @@ -85,6 +101,7 @@ ssize_t host_read(int fd, void *buf, size_t nbyte); int host_reboot(int, int, int, uintptr_t); int host_select(int nfds, long *readfds, long *writefds, long *exceptfds, struct host_timeval *timeout); +int host_stat(const char *path, struct host_kstat *sb); int host_uname(struct old_utsname *); ssize_t host_write(int fd, const void *buf, size_t nbyte); diff --git a/stand/kboot/host_syscalls.c b/stand/kboot/host_syscalls.c index 3db066acb781..9cc6c6cd873e 100644 --- a/stand/kboot/host_syscalls.c +++ b/stand/kboot/host_syscalls.c @@ -13,6 +13,12 @@ host_close(int fd) return host_syscall(SYS_close, fd); } +int +host_fstat(int fd, struct host_kstat *sb) +{ + return host_syscall(SYS_newfstat, fd, (uintptr_t)sb); +} + int host_getdents(int fd, void *dirp, int count) { @@ -86,6 +92,12 @@ host_select(int nfds, long *readfds, long *writefds, long *exceptfds, (uintptr_t)exceptfds, (uintptr_t)&ts, (uintptr_t)NULL); } +int +host_stat(const char *path, struct host_kstat *sb) +{ + return host_syscall(SYS_newfstatat, HOST_AT_FDCWD, (uintptr_t)path, (uintptr_t)sb, 0); +} + int host_uname(struct old_utsname *uts) {