summaryrefslogtreecommitdiffstats
path: root/boot/initrd.c
diff options
context:
space:
mode:
Diffstat (limited to 'boot/initrd.c')
-rw-r--r--boot/initrd.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/boot/initrd.c b/boot/initrd.c
index dc16d98..7f7a50c 100644
--- a/boot/initrd.c
+++ b/boot/initrd.c
@@ -1,8 +1,10 @@
#include "initrd.h"
+#include "arch/x86_64/hal/obj.h"
#include "init.h"
#include "jove.h"
#include "lib/printf.h"
#include "lib/tar.h"
+#include "lib/string.h"
#include "hal/obj.h"
#include "hal/memory.h"
@@ -15,31 +17,54 @@ PAGEALIGN jove_objdir_t s_initrd_objdir = { 0 };
reterr(EBADOBJ); \
}
-int
-initrd_file_name(jove_owned_obj_t *obj, const char **nameptr)
+const char*
+initrd_file_name(jove_owned_obj_t *obj)
{
CHECK_IF_INITRD(obj);
struct tar_header *file = obj_deref(obj);
- *nameptr = tar_filename(file);
- return 0;
+ return tar_filename(file);
}
-int
-initrd_file_size(jove_owned_obj_t *obj, size_t *sizeptr)
+size_t
+initrd_file_size(jove_owned_obj_t *obj)
{
CHECK_IF_INITRD(obj);
struct tar_header *file = obj_deref(obj);
- *sizeptr = tar_filesize(file);
- return 0;
+ return tar_filesize(file);
}
-int
-initrd_file_data(jove_owned_obj_t *obj, uintptr_t *dataptr)
+void*
+initrd_file_data(jove_owned_obj_t *obj)
{
CHECK_IF_INITRD(obj);
union tar_block *file = obj_deref(obj);
- *dataptr = (uintptr_t)&file[1];
- return 0;
+ return &(file[1]);
+}
+
+jove_owned_obj_t*
+initrd_seek(jove_owned_obj_t *objdir, const char *path)
+{
+ if(obj_gettype(objdir) != JOVE_OBJ_OBJDIR) {
+ reterr(EBADOBJ);
+ }
+ for(size_t i = 0; i < JOVE_OBJDIR_ENTRIES; i++) {
+ jove_owned_obj_t *file_obj = obj_take(objdir_getlocal(objdir, i));
+ if(obj_gettype(file_obj) != JOVE_OBJ_INITRD_FILE) {
+ goto loop_continue;
+ }
+ const char *filepath = initrd_file_name(file_obj);
+ if(filepath == NULL) {
+ goto loop_continue;
+ }
+
+ if(strncmp(path, filepath, strlen(filepath)+1) == 0) {
+ return file_obj;
+ }
+loop_continue:
+ obj_release(file_obj);
+ }
+
+ return NULL;
}
void initrd_setup(void)