From 14acbf6159c3efa8ce3965bb1211d4232af3fb4f Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Wed, 16 Apr 2025 22:03:34 -0600 Subject: [PATCH] kboot: Add option to parse 32-bit quantity The type that's exposed from sysfs' memory map is 32-bit and so is the data-type of memory description. Sponsored by: Netflix Reviewed by: kevans, andrew, jhibbits Differential Revision: https://reviews.freebsd.org/D49856 --- stand/kboot/include/util.h | 1 + stand/kboot/libkboot/util.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/stand/kboot/include/util.h b/stand/kboot/include/util.h index ca71277bc66..682ab8830bf 100644 --- a/stand/kboot/include/util.h +++ b/stand/kboot/include/util.h @@ -7,4 +7,5 @@ #pragma once bool file2str(const char *fn, char *buffer, size_t buflen); +bool file2u32(const char *fn, uint32_t *val); bool file2u64(const char *fn, uint64_t *val); diff --git a/stand/kboot/libkboot/util.c b/stand/kboot/libkboot/util.c index 0100a7cc5d8..c7fe8b54264 100644 --- a/stand/kboot/libkboot/util.c +++ b/stand/kboot/libkboot/util.c @@ -44,3 +44,16 @@ file2u64(const char *fn, uint64_t *val) *val = v; return true; } + +bool +file2u32(const char *fn, uint32_t *val) +{ + unsigned long v; + char buffer[80]; + + if (!file2str(fn, buffer, sizeof(buffer))) + return false; + v = strtoul(buffer, NULL, 0); /* XXX check return values? */ + *val = v; + return true; +}