diff options
author | Ian Moffett <ian@osmora.org> | 2025-10-04 01:42:52 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-10-04 01:42:52 -0400 |
commit | 96dd76a375942b6748a132e638665e000afec7e9 (patch) | |
tree | ad4bf447d3d71f09220116897f0a79d172d997f1 /omar.c | |
parent | 75e49afb15fbbe792afdaeae9a33a03674c7ea03 (diff) |
core: Introduce the -m flag for MBR imagesmain
Introduce a new flag (-m) to stick master boot record binaries at the
start of the OMAR archive
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'omar.c')
-rw-r--r-- | omar.c | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -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"); } @@ -289,6 +291,29 @@ archive_create(const char *base, const char *dirname) } /* + * 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 * * @hp: File header @@ -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; |