Mercurial > lcfOS
annotate cos/kernel/initrd.c @ 162:d8c735dc31f9
Used new editor in ide
author | Windel Bouwman |
---|---|
date | Sun, 10 Mar 2013 11:36:55 +0100 |
parents | e47bfef80baf |
children |
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: |
43 | 8 //initrd_file_header_t *files; |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
9 |
43 | 10 /* |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
11 fs_node_t* initialize_initrd(uint64_t location) |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
12 { |
41 | 13 uint32_t *u32ptr; |
14 | |
15 u32ptr = (uint32_t*)location; | |
16 if (*u32ptr != 0x1337babe) | |
17 { | |
18 printf("Invalid ramdisk magic\n"); | |
19 return 0; | |
20 } | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
21 |
41 | 22 // Allocate root dir: |
23 fs_node_t *root = (fs_node_t*)kmalloc(sizeof(fs_node_t)); | |
24 memset(root, 0, sizeof(fs_node_t)); | |
25 root->flags = FS_DIRECTORY; | |
26 root->readdir = initrd_readdir; | |
27 | |
28 u32ptr++; | |
29 root->length = *u32ptr; | |
30 | |
31 // Allocate an node for each file. | |
32 void *x = kmalloc(sizeof(fs_node_t) * root->length); | |
33 memset(x, 0, sizeof(fs_node_t) * root->length); | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
34 |
41 | 35 for (i = 0; i < root->length; i++) |
36 { | |
37 | |
38 } | |
39 | |
40 return root; | |
32
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
41 } |
3a6a9b929db0
Added initial ramdisk and some virtual file system functions
windel
parents:
diff
changeset
|
42 |
43 | 43 */ |
44 | |
41 | 45 void load_ramdisk() |
46 { | |
47 printf("Ramdisk location: %p\n", ramdisk_location); | |
48 | |
43 | 49 /* |
41 | 50 fs_node_t *root = initialize_initrd(ramdisk_location); |
51 | |
52 if (root != 0) | |
53 { | |
54 fs_node_t *node = 0; | |
55 int i = 0; | |
56 while ( (node = readdir_fs(root, i)) != 0) | |
57 { | |
58 printf("File %s\n", node->name); | |
59 } | |
60 } | |
43 | 61 */ |
41 | 62 } |
63 | |
43 | 64 /* |
41 | 65 static uint64_t initrd_read(fs_node_t *node, uint64_t offset, uint64_t size, void *buffer) |
66 { | |
67 // TODO: check errors | |
68 | |
69 if (size > node->length) | |
70 { | |
71 return 0; | |
72 } | |
73 | |
74 if (size + offset > node->length) | |
75 { | |
76 size = node->length - offset; | |
77 } | |
78 | |
79 memcpy(buffer, node.data + offset, size); | |
80 return size; | |
81 } | |
82 | |
83 fs_node_t *readdir(fs_node_t *dir, int index) | |
84 { | |
85 if (index >= dir->length) | |
86 { | |
87 return 0; | |
88 } | |
89 } | |
43 | 90 */ |
41 | 91 |