vfs: initcpio: read initramfs.cpio file into vfs

Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
Michael Shaw 2026-07-09 21:18:57 -04:00
commit acf469ff71
7 changed files with 28 additions and 14 deletions

View file

@ -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: