From nobody Tue Jan 24 22:13:33 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 4P1h7d6KHSz3bgMY; Tue, 24 Jan 2023 22:13:33 +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 4P1h7d5Wlsz3HXD; Tue, 24 Jan 2023 22:13:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598413; 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=x+3pyo3qFXfbePrjBeLJXUUHDY65l0ZEicObcu39byM=; b=fF1nCnIEKf5iC2VLzz5fRx16Bta4JE95nR2snu22mnhTqzQrAAtNOCApOHVuKqu80dkWj6 eqMYzQQv36qttW+J7i+qDKMleGHoOkDCgxNKSbSkccXhlOZ8czLIjasaDp7qx3hRGyejVo 2GdOSqRxQt2UHd0Ve9weI7QWU3Yy9STaKFr6Dx8DOemDWUTPZ9n0Sgu1yh5T9185V99poj BHCgGqVIcRsT/DQDbIRagCHascYSmdz9elLAsC0IPyg+MYlEOcMIQy0XxFmmCjVAyC3eVJ Ig6js7xjgcCX2s3sahRNQEqelSroKCIb0e4ElAovqFLxeVzKZKBEEGTDRha9ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1674598413; 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=x+3pyo3qFXfbePrjBeLJXUUHDY65l0ZEicObcu39byM=; b=eei1xajFXyRH79XTnIhaqecmyzpgXio4l1G0RQ+81x4IQFOcvKUnu42xbLvv7LBil2/6NQ NNqitJelVeHFdgGDcvH4gHakjNNiHF78kqgPXDc+rOuezsqq5nYALS6pOEte4eVw/DhXN7 E2/PMvjI8O5t0Lbkpm3YxvIwSZ/bPvh2MvErnmO8+c1TdvGxcFdWaG2Q38JYs/ouGwo+rk /Yen3wsjqBH0Do/7nnsJ+mBwiM59BeM+tCJf3YZ+/Gx7Q2vcodPzHtKDS/mrEtf9bdFZVD 31oKP3Ft2YbUlieveXBOYXBv701O+Nx7byPmiMIUB8OF8UQLx8ldnzPIc4QPsg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1674598413; a=rsa-sha256; cv=none; b=SNJPtqddXSHrPJ2IZ7Ex52V8p5+cLH+XFolQa3f4Ta1qiX13wybL0+XfIqIq1Ae6abosf/ TXQkTxJZWNHvPY1rH1pK3wmQ0C/gONK5vPOKO58yiPSH8TuSsZkrglG3bd/3kffSmMPJ5b DXMPAr07CUrqIGpKpuLMQUPh2SSZYXrRm7cTRD4x/Z1NjEXTO+TwPfTa2Ev9S0ZCTrjj7C ykuWgDVBMm2DAxZU6SWc/+pZuxhR6R1z2McD/xpqnXFWVwPCJnxoz7vQkvBSZuXPAQXnMN HPJx6AxxBXPyzgwXfq4O3cOD2RaHDNj7gkCG3oBkrIhMlqAs6ZxtR6UdwtBVUg== 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 4P1h7d4YQPzQYq; Tue, 24 Jan 2023 22:13:33 +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 30OMDXFF088594; Tue, 24 Jan 2023 22:13:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 30OMDXLq088593; Tue, 24 Jan 2023 22:13:33 GMT (envelope-from git) Date: Tue, 24 Jan 2023 22:13:33 GMT Message-Id: <202301242213.30OMDXLq088593@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: 4777b87c13e0 - stable/13 - kboot: Create routines to read Linux tiny files 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: 4777b87c13e060ff04a4fdb0eac0f5fc75371de3 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=4777b87c13e060ff04a4fdb0eac0f5fc75371de3 commit 4777b87c13e060ff04a4fdb0eac0f5fc75371de3 Author: Warner Losh AuthorDate: 2022-12-02 18:05:58 +0000 Commit: Warner Losh CommitDate: 2023-01-24 21:49:40 +0000 kboot: Create routines to read Linux tiny files Most of the files in /sys/ and /proc/ are small with one value. Create two routines to help us read the file and decode that value. Sponsored by: Netflix (cherry picked from commit 7e1a2e46aa9a2f834c33b5c50de0437ac19d7b41) --- stand/kboot/Makefile | 3 ++- stand/kboot/kboot.h | 4 ++++ stand/kboot/util.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/stand/kboot/Makefile b/stand/kboot/Makefile index c8bd313d1d1d..42385c9caf76 100644 --- a/stand/kboot/Makefile +++ b/stand/kboot/Makefile @@ -30,7 +30,8 @@ SRCS= \ kbootfdt.c \ main.c \ termios.c \ - vers.c \ + util.c \ + vers.c CFLAGS.gfx_fb_stub.c += -I${SRCTOP}/contrib/pnglite -I${SRCTOP}/sys/teken diff --git a/stand/kboot/kboot.h b/stand/kboot/kboot.h index 5441c90eaecc..e3d169ee5ac0 100644 --- a/stand/kboot/kboot.h +++ b/stand/kboot/kboot.h @@ -19,4 +19,8 @@ void fdt_arch_fixups(void *fdtp); uint64_t kboot_get_phys_load_segment(void); uint8_t kboot_get_kernel_machine_bits(void); +/* util.c */ +bool file2str(const char *fn, char *buffer, size_t buflen); +bool file2u64(const char *fn, uint64_t *val); + #endif /* KBOOT_H */ diff --git a/stand/kboot/util.c b/stand/kboot/util.c new file mode 100644 index 000000000000..938aad599e19 --- /dev/null +++ b/stand/kboot/util.c @@ -0,0 +1,46 @@ +/*- + * Copyright 2022 Netflix, Inc + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "stand.h" +#include "host_syscall.h" +#include "kboot.h" + +bool +file2str(const char *fn, char *buffer, size_t buflen) +{ + int fd; + ssize_t len; + + fd = host_open(fn, HOST_O_RDONLY, 0); + if (fd == -1) + return false; + len = host_read(fd, buffer, buflen - 1); + if (len < 0) { + host_close(fd); + return false; + } + buffer[len] = '\0'; + /* + * Trim trailing white space + */ + while (isspace(buffer[len - 1])) + buffer[--len] = '\0'; + host_close(fd); + return true; +} + +bool +file2u64(const char *fn, uint64_t *val) +{ + unsigned long v; + char buffer[80]; + + if (!file2str(fn, buffer, sizeof(buffer))) + return false; + v = strtoull(buffer, NULL, 0); /* XXX check return values? */ + *val = v; + return true; +}