diff --git a/PROTOCOL.md b/PROTOCOL.md index 70d6b2f6..88ae006b 100644 --- a/PROTOCOL.md +++ b/PROTOCOL.md @@ -502,6 +502,8 @@ struct limine_module_response { * `modules` - Pointer to an array of `module_count` pointers to `struct limine_module` structures. +Note: The first module (module 0) is always the kernel file. + ```c struct limine_module { void *base; @@ -514,7 +516,7 @@ struct limine_module { * `base` - The address of the module. * `length` - The size of the module. -* `path` - The bootloader-specific path of the module. +* `path` - The path of the module within the volume, with a leading slash. * `cmdline` - A command line associated with the module. * `file_location` - A pointer to the file location structure for the module. diff --git a/common/fs/file.h b/common/fs/file.h index f17b5b27..a464c34e 100644 --- a/common/fs/file.h +++ b/common/fs/file.h @@ -9,12 +9,15 @@ # include #endif +#define PATH_MAX 4096 + bool fs_get_guid(struct guid *guid, struct volume *part); struct file_handle { bool is_memfile; bool readall; struct volume *vol; + char path[PATH_MAX]; void *fd; void (*read)(void *fd, void *buf, uint64_t loc, uint64_t count); void (*close)(void *fd); diff --git a/common/fs/file.s2.c b/common/fs/file.s2.c index 3f6841f9..3adf1891 100644 --- a/common/fs/file.s2.c +++ b/common/fs/file.s2.c @@ -32,6 +32,14 @@ struct file_handle *fopen(struct volume *part, const char *filename) { ret->vol = part; + if (strlen(filename) + 2 > PATH_MAX) { + panic(true, "fopen: Path too long"); + } + + ret->path[0] = '/'; + + strcpy(ret->path + 1, filename); + #if bios == 1 if (part->pxe) { if (!tftp_open(ret, 0, 69, filename)) { diff --git a/common/protos/limine.c b/common/protos/limine.c index 54a1612f..9713882b 100644 --- a/common/protos/limine.c +++ b/common/protos/limine.c @@ -120,6 +120,9 @@ bool limine_load(char *config, char *cmdline) { if ((kernel_file = uri_open(kernel_path)) == NULL) panic(true, "limine: Failed to open kernel with path `%s`. Is the path correct?", kernel_path); + char *kpath = ext_mem_alloc(strlen(kernel_file->path) + 1); + strcpy(kpath, kernel_file->path); + uint8_t *kernel = freadall(kernel_file, MEMMAP_BOOTLOADER_RECLAIMABLE); size_t kernel_file_size = kernel_file->size; @@ -369,7 +372,7 @@ FEAT_START modules[0].base = reported_addr(kernel); modules[0].length = kernel_file_size; - modules[0].path = reported_addr(kernel_path); + modules[0].path = reported_addr(kpath); modules[0].cmdline = reported_addr(cmdline); modules[0].file_location = reported_addr(kl); @@ -396,7 +399,11 @@ FEAT_START m->base = reported_addr(freadall(f, MEMMAP_KERNEL_AND_MODULES)); m->length = f->size; - m->path = reported_addr(module_path); + + char *mpath = ext_mem_alloc(strlen(f->path) + 1); + strcpy(mpath, f->path); + m->path = reported_addr(mpath); + m->cmdline = reported_addr(module_cmdline); struct limine_file_location *l = ext_mem_alloc(sizeof(struct limine_file_location));