Files
RockOS/kernel/initrd.c

34 lines
1.1 KiB
C

#include "initrd.h"
#include <stdint.h>
#include <lib/print.h>
#include <lib/memory.h>
void parse_cpio(void *initrd_start) {
cpio_header_t *head = (cpio_header_t *)initrd_start;
while (strncmp(head->c_magic, "070701", 6) == 0) {
// If we hit the trailer, we are done
char *filename = (char *)(head + 1);
if (strncmp(filename, "TRAILER!!!", 10) == 0) {
break;
}
uint32_t filesize = parse_hex(head->c_filesize);
uint32_t namesize = parse_hex(head->c_namesize);
kprintf("found file of size %d\n", filesize);
// Calculate where the data begins (accounting for 4-byte padding)
uint32_t header_plus_name = 110 + namesize;
header_plus_name = (header_plus_name + 3) & ~3; // Align to 4 bytes
char *file_data = (char *)head + header_plus_name;
uint32_t total_record_size = header_plus_name + filesize;
total_record_size = (total_record_size + 3) & ~3; // Align to 4 bytes
head = (cpio_header_t *)((char *)head + total_record_size);
}
}