- Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathkernel_filesystem.c
More file actions
Latest commit
80 lines (66 loc) · 1.79 KB
/
Copy pathkernel_filesystem.c
File metadata and controls
80 lines (66 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include"kernel_filesystem.h"
#include"memory.h"
#include"kernel_stdio.h"
#include"stdlib.h"
#include"stdlib/string.h"
structfile_t*first_file;
structfile_t*last_file;
structfile_t*parse_file(char**cursor) {
if (strncmp(*cursor, "FILE ", 5) !=0) {
fprintf(LOG, "ERROR: First bytes of metadata should be `FILE ` but were `");
for (inti=0; i<5; i++) {
fprintf(LOG, "%c", (*cursor)[i]);
}
fprintf(LOG, "`\n");
fprintf(LOG, "strncmp returned %i\n", strncmp(*cursor, "FILE ", 5));
fprintf(LOG, "cursor: %s", cursor);
while(1){}
}
(*cursor) +=5;
structfile_t*file=malloc(sizeof(structfile_t));
uint32_tfile_name_length=0;
while (*(*cursor) !=' '&&file_name_length<FILE_NAME_MAX_LENGTH) {
file->name[file_name_length] =*(*cursor);
(*cursor)++;
file_name_length++;
}
(*cursor)++;
uint32_tfile_size=atoi(*cursor);
file->size=file_size;
while (*(*cursor) !='\n') {
(*cursor)++;
}
(*cursor)++;
file->bytes= (*cursor);
(*cursor) +=file->size+1;
returnfile;
}
voidinitialize_filesystem(structmodule*mod) {
void*mod_virtual_start= (void*) (mod->mod_start+UPPER_GB_START);
char*mod_virtual_end= (mod->mod_end+UPPER_GB_START);
char*cursor= (char*) mod_virtual_start;
while (cursor<mod_virtual_end) {
structfile_t*new_file=parse_file(&cursor);
if (!first_file) {
first_file=new_file;
}
if (last_file) {
last_file->next_sibling=new_file;
} else {
last_file=new_file;
}
}
}
structfile_t*get_file(char*name) {
structfile_t*file=first_file;
while (file) {
if (strcmp(file->name, name) ==0) {
returnfile;
}
file=file->next_sibling;
}
return0;
}
structfile_t*get_first_file() {
returnfirst_file;
}