From nobody Fri Jul 15 18:03:57 2022 X-Original-To: dev-commits-src-all@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 4Lkzkj2cB4z4TGb7; Fri, 15 Jul 2022 18:03:57 +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 4Lkzkj1ysjz3Rbm; Fri, 15 Jul 2022 18:03:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657908237; 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=VMfttgWS5v4a/XeI8gUpIJ66aQ9dgG/H+/VQ51BNCfs=; b=i7F1xCB4JZIQ0ohXcbIo84fdOFbGoDlBSA018zBBXI/1/tFt2/oOu1MGgUPjnVVGLm0o/1 M1Ia5yz4v7FO08nPsyjzZc8Ibpj/9RDq3kIeTUJFoW5zGGpUqECwUPJH88t3oqZfNXoO5t BTz9uKU2maKMy2HjTBjHUk5T5AFrnbCvU8tHMNeywZx4Pikxx90ghqNC3Z6KTKp6uVvLYA 1ZtU28UbSLyG1gdJDRBT5Vt4XSnvg+/VjZe9xxACIAzYoCmE5ZKK5EhWDy8G4D1hRZ4qzm uvbVTbk+hQI2FOkLtgMirXP8dN5v+nlH/LdhcGUx3mublEv/6iNCDkg//jWkSQ== 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 4Lkzkj10BPzrlx; Fri, 15 Jul 2022 18:03:57 +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 26FI3vvV060189; Fri, 15 Jul 2022 18:03:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 26FI3vRQ060188; Fri, 15 Jul 2022 18:03:57 GMT (envelope-from git) Date: Fri, 15 Jul 2022 18:03:57 GMT Message-Id: <202207151803.26FI3vRQ060188@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: a647d4a4d15d - main - kboot: Implement stat(2) and fstat(2) system calls List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: a647d4a4d15df856d590c39c19d3973ec2e18825 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1657908237; 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=VMfttgWS5v4a/XeI8gUpIJ66aQ9dgG/H+/VQ51BNCfs=; b=nMXf2oyji7QhKHZ/7ZWJdYpWhVbmg3qM7zaN60jhGOU9PgLGm4U2SuI8JSvPiQ/Ab7s7iK gqbL7hPLVsw7Kzqmk10qf4DgtcaCVm6ZfobLG9n7lDP2pa4YybXoQzlCuUu1vrT74iyqdr nsb6xA2M4ZLL4FX7d6DAZykvj8SRvCJpT9ooSkuQidxkdwAYIHY6h1wr8L2UYpEHNWRl4s 1yHToEk4yCKl0ieKW6kJ4riErDpmqf+j4eHXz7GG1KhBbwSaNjbAWH0JgJkA87dwklpK9/ ce3gs4PVp0JRuv1O26/I8f4VI9oTCNtmMkVHPeKRnSGoHuhteN8zNeMNSrfrNQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1657908237; a=rsa-sha256; cv=none; b=JlIrfGk3gcosqBsiXnWPC+yQAqGmoAE3RPXM6HLdd4Mdaw9Hs6oX6KQd+M9bwIHPg7kbf9 oQMpMzJtMNm2IFIlwii8JC8aBn2RIwZSMOjkjYfKpuISrHO4aOB+sEFdW/5WZYJDiFJhf+ Bgz8a512QXCsFBrrQVoj/d1ByzlCY+LiS4kNlah78XR1OmMN/+xl4aRz00qe6hpUSYn6EJ vvBRAM2hR02crsr7biNeTMVgeX6sdHh/tQMmZl7qAMUJLdJtYujzxdKxdCGyXm3Be558n/ RA/OcJ6cRFaxWvzqh/gJ3LB+wcw3x22v2syGNf0eomHU4LghU2RI+x4RIgPnNg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=a647d4a4d15df856d590c39c19d3973ec2e18825 commit a647d4a4d15df856d590c39c19d3973ec2e18825 Author: Warner Losh AuthorDate: 2022-07-15 05:19:18 +0000 Commit: Warner Losh CommitDate: 2022-07-15 18:00:50 +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 --- 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) {