From a17b2361ce87dfbf3d5e3df72c4d77d0df1d35eb Mon Sep 17 00:00:00 2001 From: krw Date: Mon, 24 Apr 2023 14:06:01 +0000 Subject: [PATCH] Add '-s' option to simply display the number of bytes available for the rdroot filesystem in the specified kernel. No behaviour change to existing uses of rdsetroot. Improved option handling & ok kn@ --- usr.sbin/rdsetroot/rdsetroot.8 | 10 ++++++++-- usr.sbin/rdsetroot/rdsetroot.c | 21 +++++++++++++++++---- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/usr.sbin/rdsetroot/rdsetroot.8 b/usr.sbin/rdsetroot/rdsetroot.8 index 9ec02988dff..0457b1b4d24 100644 --- a/usr.sbin/rdsetroot/rdsetroot.8 +++ b/usr.sbin/rdsetroot/rdsetroot.8 @@ -1,4 +1,4 @@ -.\" $OpenBSD: rdsetroot.8,v 1.3 2023/01/20 17:15:22 kn Exp $ +.\" $OpenBSD: rdsetroot.8,v 1.4 2023/04/24 14:06:01 krw Exp $ .\" .\" Copyright (c) 2019 Theo de Raadt .\" @@ -14,7 +14,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: January 20 2023 $ +.Dd $Mdocdate: April 24 2023 $ .Dt RDSETROOT 8 .Os .Sh NAME @@ -22,6 +22,9 @@ .Nd insert disk image into RAMDISK kernel .Sh SYNOPSIS .Nm rdsetroot +.Fl s +.Ar kernel +.Nm rdsetroot .Op Fl dx .Ar kernel .Op Ar disk.fs @@ -41,6 +44,9 @@ The options are as follows: .Bl -tag -width Ds .It Fl d Debug. +.It Fl s +Print the size in bytes of the reserved space in the RAMDISK kernel. +No insertion or extraction is attempted. .It Fl x Rather than inserting, extract the .Ar disk.fs diff --git a/usr.sbin/rdsetroot/rdsetroot.c b/usr.sbin/rdsetroot/rdsetroot.c index fc2e7e0940d..bbb8701fb66 100644 --- a/usr.sbin/rdsetroot/rdsetroot.c +++ b/usr.sbin/rdsetroot/rdsetroot.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rdsetroot.c,v 1.4 2023/01/20 17:15:22 kn Exp $ */ +/* $OpenBSD: rdsetroot.c,v 1.5 2023/04/24 14:06:01 krw Exp $ */ /* * Copyright (c) 2019 Sunil Nimmagadda @@ -47,13 +47,16 @@ main(int argc, char **argv) size_t shstrndx, mmap_size; uint64_t rd_root_size_off, rd_root_image_off; uint32_t *ip; - int ch, debug = 0, fsfd, kfd, n, xflag = 0; + int ch, debug = 0, fsfd, kfd, n, sflag = 0, xflag = 0; - while ((ch = getopt(argc, argv, "dx")) != -1) { + while ((ch = getopt(argc, argv, "dsx")) != -1) { switch (ch) { case 'd': debug = 1; break; + case 's': + sflag = 1; + break; case 'x': xflag = 1; break; @@ -64,6 +67,9 @@ main(int argc, char **argv) argc -= optind; argv += optind; + if (sflag && (debug || xflag || argc > 1)) + usage(); + if (argc == 1) kernel = argv[0]; else if (argc == 2) { @@ -161,6 +167,11 @@ main(int argc, char **argv) */ ip = (uint32_t *) (dataseg + rd_root_size_off); rd_root_size_val = *ip; + if (sflag) { + fprintf(stdout, "%llu\n", (unsigned long long)rd_root_size_val); + goto done; + } + if (debug) { fprintf(stderr, "rd_root_size val: 0x%llx (%lld blocks)\n", (unsigned long long)rd_root_size_val, @@ -196,6 +207,7 @@ main(int argc, char **argv) if (debug) fprintf(stderr, "...copied %d bytes\n", n); + done: elf_end(e); return 0; } @@ -294,6 +306,7 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-dx] kernel [disk.fs]\n", __progname); + fprintf(stderr, "usage: %s -s kernel\n", __progname); + fprintf(stderr, " %s [-dx] kernel [disk.fs]\n", __progname); exit(1); } -- 2.20.1