From 57427191e2cf0f08724b74fba3a35aa41ceda40d Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 13 Aug 2022 16:21:02 +0200 Subject: user: plan9-style /bin/ union --- Makefile | 10 +++++----- initrd/bin/sh/catall | 19 +++++++++++++++++++ initrd/catall.sh | 19 ------------------- src/user/app/init/init.c | 8 +++++++- src/user/bootstrap/main.c | 5 +++-- 5 files changed, 34 insertions(+), 27 deletions(-) create mode 100644 initrd/bin/sh/catall delete mode 100644 initrd/catall.sh diff --git a/Makefile b/Makefile index a37f474..6e10960 100644 --- a/Makefile +++ b/Makefile @@ -90,10 +90,10 @@ out/hdd: define userbin_template = -out/initrd/bin/$(1): src/user/linker.ld \ - $(call from_sources, src/user/app/$(1)/) \ - $(call from_sources, src/user/lib/) \ - $(call from_sources, src/shared/) +out/initrd/bin/amd64/$(1): src/user/linker.ld \ + $(call from_sources, src/user/app/$(1)/) \ + $(call from_sources, src/user/lib/) \ + $(call from_sources, src/shared/) @mkdir -p $$(@D) @$(CC) $(LFLAGS) -Wl,-pie -Wl,-no-dynamic-linker -T $$^ -o $$@ endef @@ -108,7 +108,7 @@ out/initrd/font.psf: /usr/share/kbd/consolefonts/default8x16.psfu.gz @gunzip $< -c > $@ out/initrd.tar: $(patsubst %,out/%,$(shell find initrd/ -type f)) \ - $(patsubst %,out/initrd/bin/%,$(USERBINS)) \ + $(patsubst %,out/initrd/bin/amd64/%,$(USERBINS)) \ out/initrd/font.psf @cd out/initrd; tar chf ../initrd.tar * diff --git a/initrd/bin/sh/catall b/initrd/bin/sh/catall new file mode 100644 index 0000000..a1c8c76 --- /dev/null +++ b/initrd/bin/sh/catall @@ -0,0 +1,19 @@ +#!/bin/shell +# equalivent to the old "catall" builtin, meant to demo shadowing +# TODO shadow here +echo /init/fake.txt: +cat /init/fake.txt +echo + +echo /init/1.txt: +cat /init/1.txt +echo + +echo /init/2.txt: +cat /init/2.txt +echo + +echo /init/dir/3.txt: +cat /init/dir/3.txt +echo + diff --git a/initrd/catall.sh b/initrd/catall.sh deleted file mode 100644 index a1c8c76..0000000 --- a/initrd/catall.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/shell -# equalivent to the old "catall" builtin, meant to demo shadowing -# TODO shadow here -echo /init/fake.txt: -cat /init/fake.txt -echo - -echo /init/1.txt: -cat /init/1.txt -echo - -echo /init/2.txt: -cat /init/2.txt -echo - -echo /init/dir/3.txt: -cat /init/dir/3.txt -echo - diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c index c788cb6..2ae8048 100644 --- a/src/user/app/init/init.c +++ b/src/user/app/init/init.c @@ -30,7 +30,13 @@ int main(void) { printf("in init (stage 2), main at 0x%x\n", &main); MOUNT_AT("/keyboard") { ps2_drv(); } - MOUNT_AT("/bin/") { fs_passthru("/init/bin"); } + MOUNT_AT("/bin/") { + fs_union((const char*[]){ + "/init/bin/amd64/", + "/init/bin/sh/", + NULL + }); + } MOUNT_AT("/tmp/") { const char *argv[] = {"/bin/tmpfs", NULL}; execv(argv[0], (void*)argv); diff --git a/src/user/bootstrap/main.c b/src/user/bootstrap/main.c index fbcb641..f06401b 100644 --- a/src/user/bootstrap/main.c +++ b/src/user/bootstrap/main.c @@ -23,9 +23,10 @@ void _start(void) { MOUNT_AT("/init/") { tar_driver(&_initrd); } - void *init = tar_find("bin/init", 8, &_initrd, ~0) + 512; + const char *initpath = "bin/amd64/init"; + void *init = tar_find(initpath, strlen(initpath), &_initrd, ~0) + 512; if (init) { - _klogf("execing init.elf"); + _klogf("execing init"); elf_exec(init, NULL, NULL); _klogf("elf_exec failed"); } else { -- cgit v1.2.3