Commit 9993a1c0 authored by Jonas Termansen's avatar Jonas Termansen

Add --append-to kernel(7) multiboot module option.

parent d0ab651f
...@@ -703,9 +703,10 @@ static int ExtractTo_mkdir(Ref<Descriptor> desc, ioctx_t* ctx, ...@@ -703,9 +703,10 @@ static int ExtractTo_mkdir(Ref<Descriptor> desc, ioctx_t* ctx,
static void ExtractTo(Ref<Descriptor> desc, static void ExtractTo(Ref<Descriptor> desc,
struct initrd_context* ctx, struct initrd_context* ctx,
const char* path) const char* path,
int extra_oflags)
{ {
int oflags = O_WRITE | O_CREATE | O_TRUNC; int oflags = O_WRITE | O_CREATE | extra_oflags;
Ref<Descriptor> file(desc->open(&ctx->ioctx, path, oflags, 0644)); Ref<Descriptor> file(desc->open(&ctx->ioctx, path, oflags, 0644));
if ( !file && errno == ENOENT ) if ( !file && errno == ENOENT )
{ {
...@@ -718,9 +719,16 @@ static void ExtractTo(Ref<Descriptor> desc, ...@@ -718,9 +719,16 @@ static void ExtractTo(Ref<Descriptor> desc,
file = desc->open(&ctx->ioctx, path, oflags, 0644); file = desc->open(&ctx->ioctx, path, oflags, 0644);
} }
if ( !file ) if ( !file )
{
if ( errno == EEXIST && (oflags & O_EXCL) )
return;
PanicF("%s: %m", path); PanicF("%s: %m", path);
if ( file->truncate(&ctx->ioctx, ctx->initrd_size) != 0 ) }
PanicF("truncate: %s: %m", path); if ( !(oflags & O_APPEND) )
{
if ( file->truncate(&ctx->ioctx, ctx->initrd_size) != 0 )
PanicF("truncate: %s: %m", path);
}
size_t sofar = 0; size_t sofar = 0;
while ( sofar < ctx->initrd_size ) while ( sofar < ctx->initrd_size )
{ {
...@@ -771,7 +779,13 @@ static void ExtractModule(struct multiboot_mod_list* module, ...@@ -771,7 +779,13 @@ static void ExtractModule(struct multiboot_mod_list* module,
if ( !strncmp(cmdline, "--to ", strlen("--to ")) || if ( !strncmp(cmdline, "--to ", strlen("--to ")) ||
!strncmp(cmdline, "--to=", strlen("--to=")) ) !strncmp(cmdline, "--to=", strlen("--to=")) )
ExtractTo(desc, ctx, cmdline + strlen("--to ")); ExtractTo(desc, ctx, cmdline + strlen("--to "), O_TRUNC);
else if ( !strncmp(cmdline, "--append-to ", strlen("--append-to ")) ||
!strncmp(cmdline, "--append-to=", strlen("--append-to=")) )
ExtractTo(desc, ctx, cmdline + strlen("--append-to "), O_APPEND);
else if ( !strncmp(cmdline, "--create-to ", strlen("--create-to ")) ||
!strncmp(cmdline, "--create-to=", strlen("--create-to=")) )
ExtractTo(desc, ctx, cmdline + strlen("--create-to "), O_EXCL);
else if ( sizeof(struct initrd_superblock) <= ctx->initrd_size && else if ( sizeof(struct initrd_superblock) <= ctx->initrd_size &&
!memcmp(ctx->initrd, "sortix-initrd-2", strlen("sortix-initrd-2")) ) !memcmp(ctx->initrd, "sortix-initrd-2", strlen("sortix-initrd-2")) )
ExtractInitrd(desc, ctx); ExtractInitrd(desc, ctx);
......
...@@ -78,6 +78,17 @@ binary package. ...@@ -78,6 +78,17 @@ binary package.
.Pp .Pp
Each multiboot module has its own command line where the options are as follows: Each multiboot module has its own command line where the options are as follows:
.Bl -tag -width "12345678" .Bl -tag -width "12345678"
.It Fl \-append-to Ns "=" Ns Ar file
Append the contents of the module to the specifed
.Ar file ,
creating it with mode 644 if it doesn't exist.
Non-existent parent directories are created with mode 755 as needed.
.It Fl \-create-to Ns "=" Ns Ar file
Create the specified
.Ar file
with mode 644 with contents of the module, but only if it doesn't already exist.
No action is taken if the file already existed.
Non-existent parent directories are created with mode 755 as needed.
.It Fl \-random-seed .It Fl \-random-seed
The module contains random data used to seed the kernel entropy gathering. The module contains random data used to seed the kernel entropy gathering.
This file is supposed to contain 256 bytes of secret randomness that hasn't been This file is supposed to contain 256 bytes of secret randomness that hasn't been
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment