Mercurial > lcfOS
comparison cos/kernel/initrd.c @ 41:35cc54e078dd
Added memory functions
author | windel |
---|---|
date | Fri, 03 Feb 2012 17:56:41 +0100 |
parents | 3a6a9b929db0 |
children | e47bfef80baf |
comparison
equal
deleted
inserted
replaced
40:24ce177e01e8 | 41:35cc54e078dd |
---|---|
2 * Initial ramdisk filesystem driver. | 2 * Initial ramdisk filesystem driver. |
3 * */ | 3 * */ |
4 | 4 |
5 #include "kernel.h" | 5 #include "kernel.h" |
6 | 6 |
7 fs_node_t *initrd_root = 0; | 7 // Global data struct: |
8 | 8 initrd_file_header_t *files; |
9 typedef struct | |
10 { | |
11 uint32_t magic; | |
12 uint32_t numfiles; | |
13 } initrd_header_t; | |
14 | 9 |
15 fs_node_t* initialize_initrd(uint64_t location) | 10 fs_node_t* initialize_initrd(uint64_t location) |
16 { | 11 { |
17 // We need a valid malloc here! | 12 uint32_t *u32ptr; |
18 initrd_root = (fs_node_t*)kmalloc(sizeof(fs_node_t)); | |
19 | 13 |
20 initrd_header_t *header = (initrd_header_t*)location; | 14 u32ptr = (uint32_t*)location; |
21 initrd_root->length = header->numfiles; | 15 if (*u32ptr != 0x1337babe) |
16 { | |
17 printf("Invalid ramdisk magic\n"); | |
18 return 0; | |
19 } | |
22 | 20 |
23 return initrd_root; | 21 // Allocate root dir: |
22 fs_node_t *root = (fs_node_t*)kmalloc(sizeof(fs_node_t)); | |
23 memset(root, 0, sizeof(fs_node_t)); | |
24 root->flags = FS_DIRECTORY; | |
25 root->readdir = initrd_readdir; | |
26 | |
27 u32ptr++; | |
28 root->length = *u32ptr; | |
29 | |
30 // Allocate an node for each file. | |
31 void *x = kmalloc(sizeof(fs_node_t) * root->length); | |
32 memset(x, 0, sizeof(fs_node_t) * root->length); | |
33 | |
34 for (i = 0; i < root->length; i++) | |
35 { | |
36 | |
37 } | |
38 | |
39 return root; | |
24 } | 40 } |
25 | 41 |
42 void load_ramdisk() | |
43 { | |
44 printf("Ramdisk location: %p\n", ramdisk_location); | |
45 | |
46 fs_node_t *root = initialize_initrd(ramdisk_location); | |
47 | |
48 if (root != 0) | |
49 { | |
50 fs_node_t *node = 0; | |
51 int i = 0; | |
52 while ( (node = readdir_fs(root, i)) != 0) | |
53 { | |
54 printf("File %s\n", node->name); | |
55 } | |
56 } | |
57 } | |
58 | |
59 static uint64_t initrd_read(fs_node_t *node, uint64_t offset, uint64_t size, void *buffer) | |
60 { | |
61 // TODO: check errors | |
62 | |
63 if (size > node->length) | |
64 { | |
65 return 0; | |
66 } | |
67 | |
68 if (size + offset > node->length) | |
69 { | |
70 size = node->length - offset; | |
71 } | |
72 | |
73 memcpy(buffer, node.data + offset, size); | |
74 return size; | |
75 } | |
76 | |
77 fs_node_t *readdir(fs_node_t *dir, int index) | |
78 { | |
79 if (index >= dir->length) | |
80 { | |
81 return 0; | |
82 } | |
83 } | |
84 |