1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

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

This commit is contained in:
Jonas 'Sortie' Termansen 2018-09-26 23:31:48 +02:00
parent d0ab651fbd
commit 9993a1c0fc
2 changed files with 30 additions and 5 deletions

View file

@ -703,9 +703,10 @@ static int ExtractTo_mkdir(Ref<Descriptor> desc, ioctx_t* ctx,
static void ExtractTo(Ref<Descriptor> desc,
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));
if ( !file && errno == ENOENT )
{
@ -718,9 +719,16 @@ static void ExtractTo(Ref<Descriptor> desc,
file = desc->open(&ctx->ioctx, path, oflags, 0644);
}
if ( !file )
{
if ( errno == EEXIST && (oflags & O_EXCL) )
return;
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;
while ( sofar < ctx->initrd_size )
{
@ -771,7 +779,13 @@ static void ExtractModule(struct multiboot_mod_list* module,
if ( !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 &&
!memcmp(ctx->initrd, "sortix-initrd-2", strlen("sortix-initrd-2")) )
ExtractInitrd(desc, ctx);

View file

@ -78,6 +78,17 @@ binary package.
.Pp
Each multiboot module has its own command line where the options are as follows:
.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
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