Mercurial > lcfOS
diff cos/kernel/initrd.c @ 41:35cc54e078dd
Added memory functions
author | windel |
---|---|
date | Fri, 03 Feb 2012 17:56:41 +0100 |
parents | 3a6a9b929db0 |
children | e47bfef80baf |
line wrap: on
line diff
--- a/cos/kernel/initrd.c Tue Jan 24 17:54:16 2012 +0100 +++ b/cos/kernel/initrd.c Fri Feb 03 17:56:41 2012 +0100 @@ -4,22 +4,81 @@ #include "kernel.h" -fs_node_t *initrd_root = 0; - -typedef struct -{ - uint32_t magic; - uint32_t numfiles; -} initrd_header_t; +// Global data struct: +initrd_file_header_t *files; fs_node_t* initialize_initrd(uint64_t location) { - // We need a valid malloc here! - initrd_root = (fs_node_t*)kmalloc(sizeof(fs_node_t)); + uint32_t *u32ptr; + + u32ptr = (uint32_t*)location; + if (*u32ptr != 0x1337babe) + { + printf("Invalid ramdisk magic\n"); + return 0; + } - initrd_header_t *header = (initrd_header_t*)location; - initrd_root->length = header->numfiles; + // Allocate root dir: + fs_node_t *root = (fs_node_t*)kmalloc(sizeof(fs_node_t)); + memset(root, 0, sizeof(fs_node_t)); + root->flags = FS_DIRECTORY; + root->readdir = initrd_readdir; + + u32ptr++; + root->length = *u32ptr; + + // Allocate an node for each file. + void *x = kmalloc(sizeof(fs_node_t) * root->length); + memset(x, 0, sizeof(fs_node_t) * root->length); - return initrd_root; + for (i = 0; i < root->length; i++) + { + + } + + return root; } +void load_ramdisk() +{ + printf("Ramdisk location: %p\n", ramdisk_location); + + fs_node_t *root = initialize_initrd(ramdisk_location); + + if (root != 0) + { + fs_node_t *node = 0; + int i = 0; + while ( (node = readdir_fs(root, i)) != 0) + { + printf("File %s\n", node->name); + } + } +} + +static uint64_t initrd_read(fs_node_t *node, uint64_t offset, uint64_t size, void *buffer) +{ + // TODO: check errors + + if (size > node->length) + { + return 0; + } + + if (size + offset > node->length) + { + size = node->length - offset; + } + + memcpy(buffer, node.data + offset, size); + return size; +} + +fs_node_t *readdir(fs_node_t *dir, int index) +{ + if (index >= dir->length) + { + return 0; + } +} +