-.\" $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
.\"
.\" 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
.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
.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
-/* $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>
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;
argc -= optind;
argv += optind;
+ if (sflag && (debug || xflag || argc > 1))
+ usage();
+
if (argc == 1)
kernel = argv[0];
else if (argc == 2) {
*/
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,
if (debug)
fprintf(stderr, "...copied %d bytes\n", n);
+ done:
elf_end(e);
return 0;
}
{
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);
}