From nobody Fri Dec 02 18:08:54 2022 X-Original-To: dev-commits-src-main@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 4NP1Cp4jqhz4hqfD; Fri, 2 Dec 2022 18:08:54 +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 4NP1Cp4134z40F1; Fri, 2 Dec 2022 18:08:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670004534; 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=e6mNLruruamhIdKFCmo9HkAS6pQxlSAnaghvpsrCxMc=; b=LAhNKTeQxEnTHj4u+XVdRkEFSRDF2dCfE33nLMixzehlSP2ow350W0/jaVmWREQIABY7Rg rZRmtaGXtackRQDYLrvRK3zSE+RVxHmJRKXUCwHUJF5k0VDa/BwOb+bfgg2MJq0IaUpvCn z0QVtKL4SyYwE9hXUahVf0PCG39iJ7kjKjrJ9qxbjVuw87LVMFQbFpjtMrHUz0m7khmq+p fbENTg8AAWFIsN76+aiVS+j2P9GqH8oKLtyHN5g/JsVTIW8rw8z+/eXp5nX6+YMYy754qA LtE5FVxJgX3CmnMwfV8d6RWfRKpAtLDoVGjzmEuz0KV/P1ObtAM4t7UiKbGLDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1670004534; 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=e6mNLruruamhIdKFCmo9HkAS6pQxlSAnaghvpsrCxMc=; b=EUScSHLXiV4YGwhuGVfbvwx55HUz/xV4aexoBvwnbQb+vZhvcJPH0ItnFwiZwRQ79Tkahf JNUGlLrMI/fC3th77K5sDu75W3TMcnFSzKeiIuCbCHphTn73DNNqOcnrQDj9bz4S124vKu UNeb3BrPrVF5jfdVOLa4HKVtG/hlPwFEUHpM6f1DfUPuR2ibxTGVQxEWEv48czLLV6Idkq 5RwaSOKRRt0t9DbhivX6vLMorNZ/bSSRA+jp5+GPAkJRnjy7A5cV+PL/sJ1ZSrTc2YndQO Qjyf/igZpnCszQYQLwltsvm2HFjWnhjNaORAgOuJYwGm5FQ8rS+/YyrwUQmfWQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1670004534; a=rsa-sha256; cv=none; b=nDbXkurQiw+FSTKwB7DmQXtG8ST4tOrHjFORCetM7DeNMqCWxuRxXGh+h1Ag+AVC9Ut+T7 t/xO0QdCQVWSs4M1KcT36V6FV0WBCwXpLS85OxjY14q7uoP3KgDVTpAZPzB5mSh3aGGFkv ckrzkWKifc5GpmBzh8foraoZgkhzmXQcKsLowT2FLLXh0oNMPOqVjU+GS/E/Hfnw7XaDof w1HxjNRIH9Cs3mCVO0thxk0gN+AFJyTcRcxSwPOB+s0uHKzyGAwvAlVMtcZhhsLPGpII5n K4hZPThSQHI8mB3jG0ySykJJ/lmIa6AkkvyMJS/cEIMjoDhALlSdZNB+7jRvYg== 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 4NP1Cp35XqzQ8P; Fri, 2 Dec 2022 18:08:54 +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 2B2I8sML034896; Fri, 2 Dec 2022 18:08:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 2B2I8si0034895; Fri, 2 Dec 2022 18:08:54 GMT (envelope-from git) Date: Fri, 2 Dec 2022 18:08:54 GMT Message-Id: <202212021808.2B2I8si0034895@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: 7e1a2e46aa9a - main - kboot: Create routines to read Linux tiny files List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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: 7e1a2e46aa9a2f834c33b5c50de0437ac19d7b41 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7e1a2e46aa9a2f834c33b5c50de0437ac19d7b41 commit 7e1a2e46aa9a2f834c33b5c50de0437ac19d7b41 Author: Warner Losh AuthorDate: 2022-12-02 18:05:58 +0000 Commit: Warner Losh CommitDate: 2022-12-02 18:08:11 +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 --- 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; +}