Mercurial > lcfOS
annotate cos/kernel/initrd.c @ 41:35cc54e078dd
Added memory functions
author | windel |
---|---|
date | Fri, 03 Feb 2012 17:56:41 +0100 |
parents | 3a6a9b929db0 |
children | e47bfef80baf |
rev | line source |
---|---|
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
1 /* |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
2 * Initial ramdisk filesystem driver. |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
3 * */ |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
4 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
5 #include "kernel.h" |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
6 |
41 | 7 // Global data struct: |
8 initrd_file_header_t *files; | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
9 |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
10 fs_node_t* initialize_initrd(uint64_t location) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
11 { |
41 | 12 uint32_t *u32ptr; |
13 | |
14 u32ptr = (uint32_t*)location; | |
15 if (*u32ptr != 0x1337babe) | |
16 { | |
17 printf("Invalid ramdisk magic\n"); | |
18 return 0; | |
19 } | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
20 |
41 | 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); | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
33 |
41 | 34 for (i = 0; i < root->length; i++) |
35 { | |
36 | |
37 } | |
38 | |
39 return root; | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
40 } |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
41 |
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 |