vfs: initcpio: read initramfs.cpio file into vfs
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
bbf23100fc
commit
acf469ff71
7 changed files with 28 additions and 14 deletions
|
|
@ -29,9 +29,6 @@ static bool cpio_verify_header_footer(const char *file, size_t len)
|
|||
if (offset_footer == sizeof(struct cpio_newc_header))
|
||||
return false;
|
||||
|
||||
if (strncmp(file + offset_footer, CPIO_TRAILER, footer_len))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -56,21 +53,18 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t **
|
|||
return -ENAMETOOLONG;
|
||||
|
||||
const char *cursor = file + sizeof(struct cpio_newc_header);
|
||||
size_t data_offset = sizeof(struct cpio_newc_header) + ALIGN_UP(name_len, 4);
|
||||
|
||||
if (!strncmp(cursor, "./", 2)) {
|
||||
cursor += 2;
|
||||
name_len -= 2;
|
||||
} else if (!strcmp(cursor, ".")) {
|
||||
/* is root */
|
||||
cursor += name_len;
|
||||
cursor = file + ALIGN_UP(cursor - file, 4);
|
||||
return cursor - file;
|
||||
return data_offset;
|
||||
}
|
||||
|
||||
memcpy(name, cursor, name_len);
|
||||
cursor += name_len;
|
||||
|
||||
cursor = file + ALIGN_UP(cursor - file, 4);
|
||||
cursor = file + data_offset;
|
||||
|
||||
char *parent_path = dirname(name);
|
||||
char *leaf = basename(name);
|
||||
|
|
@ -127,7 +121,7 @@ static ssize_t read_next(fs_t *fs, const char *file, rbtree_t *list, dirent_t **
|
|||
|
||||
/* advance past file data and align to next entry */
|
||||
cursor += file_len;
|
||||
cursor = file + ALIGN_UP(cursor - file, 4);
|
||||
cursor = file + data_offset + ALIGN_UP(file_len, 4);
|
||||
res = cursor - file;
|
||||
|
||||
out_tidy:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ extern struct limine_executable_address_response *kern_addr_res;
|
|||
extern struct limine_memmap_response *kern_map_res;
|
||||
extern struct limine_hhdm_response *kern_hhdm_res;
|
||||
extern struct limine_rsdp_response *kern_rsdp_res;
|
||||
extern struct limine_module_response *module_res;
|
||||
|
||||
void requests_init();
|
||||
|
||||
|
|
|
|||
10
init/main.c
10
init/main.c
|
|
@ -23,6 +23,7 @@
|
|||
#include <drivers/apic.h>
|
||||
|
||||
#include <fs/vfs.h>
|
||||
#include <fs/cpio.h>
|
||||
|
||||
#include <lib/stdio.h>
|
||||
#include <lib/list.h>
|
||||
|
|
@ -67,6 +68,15 @@ static void kmain()
|
|||
page_init();
|
||||
do_initcalls();
|
||||
|
||||
struct limine_file *file = module_res->modules[0];
|
||||
|
||||
fs_t *initramfs;
|
||||
|
||||
int res = cpio_read_and_init(file->address, file->size, &initramfs);
|
||||
|
||||
if (res < 0)
|
||||
panic("failed to load initramfs: %s\n", strerror(-res));
|
||||
|
||||
/* do nothing, for now :) */
|
||||
yield();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,17 +4,22 @@
|
|||
|
||||
#define REQUEST __attribute__((used, section(".limine_requests"))) volatile
|
||||
|
||||
REQUEST u64 _limine_requests_start[] = LIMINE_REQUESTS_START_MARKER;
|
||||
|
||||
REQUEST struct limine_executable_address_request kern_addr_req = {.id = LIMINE_EXECUTABLE_ADDRESS_REQUEST_ID, .revision = 0};
|
||||
REQUEST struct limine_memmap_request memmap_req = {.id = LIMINE_MEMMAP_REQUEST_ID, .revision = 0};
|
||||
REQUEST struct limine_hhdm_request hhdm_req = {.id = LIMINE_HHDM_REQUEST_ID, .revision = 0};
|
||||
REQUEST struct limine_rsdp_request rsdp_req = {.id = LIMINE_RSDP_REQUEST_ID, .revision = 0};
|
||||
|
||||
REQUEST struct limine_module_request module_req = {.id = LIMINE_MODULE_REQUEST_ID, .revision = 0};
|
||||
REQUEST u64 limine_base_revision[] = LIMINE_BASE_REVISION(6);
|
||||
|
||||
REQUEST u64 _limine_requests_end[] = LIMINE_REQUESTS_END_MARKER;
|
||||
|
||||
struct limine_executable_address_response *kern_addr_res = NULL;
|
||||
struct limine_memmap_response *kern_map_res = NULL;
|
||||
struct limine_hhdm_response *kern_hhdm_res = NULL;
|
||||
struct limine_rsdp_response *kern_rsdp_res = NULL;
|
||||
struct limine_module_response *module_res = NULL;
|
||||
|
||||
vaddr_t hhdm_start = 0;
|
||||
|
||||
|
|
@ -24,6 +29,7 @@ void requests_init()
|
|||
kern_map_res = memmap_req.response;
|
||||
kern_hhdm_res = hhdm_req.response;
|
||||
kern_rsdp_res = rsdp_req.response;
|
||||
module_res = module_req.response;
|
||||
|
||||
hhdm_start = kern_hhdm_res->offset;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ SECTIONS
|
|||
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
||||
__kernel_end = .;
|
||||
|
||||
.limine_requests : { KEEP(*(.limine_requests)) }
|
||||
|
||||
/DISCARD/ : {
|
||||
*(.eh_frame)
|
||||
*(.note .note.*)
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ void *kalloc(size_t size, u64 flags)
|
|||
ret = slab_alloc(slab);
|
||||
if (ret)
|
||||
size = slab->item_size;
|
||||
alloc_type = ALLOC_TYPE_SLAB;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ $(IMG): limine/limine $(KERNEL)
|
|||
mformat -F -v "ESP" -H 2048 -i $(IMG)@@1M
|
||||
|
||||
mmd -i $(IMG)@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine
|
||||
mcopy -i $(IMG)@@1M kernel.elf ::/
|
||||
mcopy -i $(IMG)@@1M kernel.elf initramfs.cpio ::/
|
||||
mcopy -i $(IMG)@@1M limine.conf ::/boot/limine
|
||||
mcopy -i $(IMG)@@1M limine/limine-bios.sys ::/boot/limine
|
||||
mcopy -i $(IMG)@@1M limine/BOOTX64.EFI ::/EFI/BOOT
|
||||
|
|
|
|||
Loading…
Reference in a new issue