From 96dd76a375942b6748a132e638665e000afec7e9 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Sat, 4 Oct 2025 01:42:52 -0400 Subject: core: Introduce the -m flag for MBR images Introduce a new flag (-m) to stick master boot record binaries at the start of the OMAR archive Signed-off-by: Ian Moffett --- omar.1 | 3 +++ omar.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/omar.1 b/omar.1 index d3b39af..4dc084b 100644 --- a/omar.1 +++ b/omar.1 @@ -44,6 +44,9 @@ Prepare files for use in an initramfs .Ft -x extract an archive +.Ft -m + stick a master boot record at the start + Upon creation of the archive image, OMAR will produce pathnames through stdout with the following types in square brackets ([]) diff --git a/omar.c b/omar.c index a4c7ad6..9efff53 100644 --- a/omar.c +++ b/omar.c @@ -63,6 +63,7 @@ static int mode = OMAR_ARCHIVE; static int outfd; static const char *inpath = NULL; static const char *outpath = NULL; +static const char *mbrpath = NULL; /* * The OMAR file header, describes the basics @@ -91,6 +92,7 @@ help(void) printf("Usage: omar -i [input_dir] -o [output]\n"); printf("-h Show this help screen\n"); printf("-x Extract an OMAR archive\n"); + printf("-m Stick an MBR image at the start\n"); printf("--------------------------------------\n"); } @@ -288,6 +290,29 @@ archive_create(const char *base, const char *dirname) return 0; } +/* + * Push an MBR to the start of the OMAR image + */ +static int +mbr_push(const char *path) +{ + int fd, error; + char mbr[512]; + + fd = open(path, O_RDONLY); + if (fd < 0) { + return fd; + } + + /* Read the MBR */ + if ((error = read(fd, mbr, sizeof(mbr))) < 0) { + return error; + } + + write(outfd, mbr, sizeof(mbr)); + return 0; +} + /* * Extract a single file * @@ -408,7 +433,7 @@ main(int argc, char **argv) return -1; } - while ((optc = getopt(argc, argv, "xhi:o:")) != -1) { + while ((optc = getopt(argc, argv, "xhi:m:o:")) != -1) { switch (optc) { case 'x': mode = OMAR_EXTRACT; @@ -419,6 +444,9 @@ main(int argc, char **argv) case 'o': outpath = optarg; break; + case 'm': + mbrpath = optarg; + break; case 'h': help(); return 0; @@ -452,6 +480,14 @@ main(int argc, char **argv) return outfd; } + /* If we can, push an MBR */ + if (mbrpath != NULL) { + retval = mbr_push(mbrpath); + } + if (retval != 0) { + return retval; + } + retval = archive_create(inpath, basename((char *)inpath)); file_push(NULL, "EOF"); break; -- cgit v1.2.3