1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-21 23:18:00 -08:00

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@
This commit is contained in:
krw 2023-04-24 14:06:01 +00:00
parent 36d351c1f3
commit a17b2361ce
2 changed files with 25 additions and 6 deletions

View File

@ -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

View File

@ -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 <sunil@openbsd.org>
@ -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);
}