-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileSystem.c
More file actions
58 lines (46 loc) · 1.1 KB
/
Copy pathFileSystem.c
File metadata and controls
58 lines (46 loc) · 1.1 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
#include "FileSystem.h"
#include "Directory.h"
#include "Disk.h"
#include <stdio.h>
#include <string.h>
void fs_init() {
disk_init();
directory_init();
}
void fs_format() {
disk_format();
directory_init();
}
int fs_create(const char *name) {
FileEntry* f = directory_create(name);
if (!f) return -1;
return 0;
}
int fs_write(const char *name, const char *data) {
FileEntry *f = directory_lookup(name);
if (!f) return -1;
char buffer[BLOCK_SIZE];
memset(buffer, 0, BLOCK_SIZE);
strncpy(buffer, data, BLOCK_SIZE - 1);
disk_write_block(f->block, buffer);
directory_update_timestamp(f);
return 0;
}
int fs_read(const char *name) {
FileEntry *f = directory_lookup(name);
if (!f) return -1;
char buffer[BLOCK_SIZE];
disk_read_block(f->block, buffer);
printf("--- Content of '%s' ---\n%s\n", name, buffer);
directory_update_timestamp(f);
return 0;
}
int fs_delete(const char *name) {
FileEntry *f = directory_lookup(name);
if (!f) return -1;
directory_delete(name);
return 0;
}
void fs_ls() {
directory_list();
}