forked from yhzhang0128/egos-2000
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sys_file.c
46 lines (39 loc) · 1.25 KB
/
sys_file.c
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
/*
* (C) 2022, Cornell University
* All rights reserved.
*/
/* Author: Yunhao Zhang
* Description: inode layer of the file system
*/
#include "app.h"
#include "file.h"
#include <string.h>
int main() {
SUCCESS("Enter kernel process GPID_FILE");
/* Initialize the file system */
block_if disk = fs_disk_init();
if (treedisk_create(disk, 0, NINODES) < 0)
FATAL("proc_file: can't create treedisk file system");
block_if fs = treedisk_init(disk, 0);
/* Send notification to GPID_PROCESS */
char buf[SYSCALL_MSG_LEN];
strcpy(buf, "Finish GPID_FILE initialization");
sys_send(GPID_PROCESS, buf, 32);
/* Wait for file requests */
while (1) {
int sender, r;
struct file_request *req = (void*)buf;
struct file_reply *reply = (void*)buf;
sys_recv(&sender, buf, SYSCALL_MSG_LEN);
switch (req->type) {
case FILE_READ:
r = fs->read(fs, req->ino, req->offset, (void*)&reply->block);
reply->status = r == 0 ? FILE_OK : FILE_ERROR;
sys_send(sender, (void*)reply, sizeof(struct file_reply));
break;
case FILE_WRITE:
default:
FATAL("Request type=%d not implemented in GPID_FILE", req->type);
}
}
}