fix: persist datas on disk
This commit is contained in:
parent
bb2ea44383
commit
c82deb402c
10
src/disk.c
10
src/disk.c
@ -391,3 +391,13 @@ disk open_disk(char *filename) {
|
|||||||
fclose(fptr);
|
fclose(fptr);
|
||||||
return d;
|
return d;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void persist_on_disk(disk* d) {
|
||||||
|
FILE *fptr;
|
||||||
|
fptr = fopen("disk", "wb");
|
||||||
|
|
||||||
|
int n = fwrite(d, sizeof(disk), 1, fptr);
|
||||||
|
if (n != 1) {
|
||||||
|
dprintf(STDERR_FILENO, "Failed to persist datas on disk\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,4 +18,5 @@ int do_ls(disk *d, char* path);
|
|||||||
int do_touch(disk *d, char *filepath);
|
int do_touch(disk *d, char *filepath);
|
||||||
int do_mkdir(disk* d, char *dirpath);
|
int do_mkdir(disk* d, char *dirpath);
|
||||||
int do_df(disk *d);
|
int do_df(disk *d);
|
||||||
int find_dir_inode_by_name(char *name, int dir_index, disk *d);
|
int find_dir_inode_by_name(char *name, int dir_index, disk *d);
|
||||||
|
void persist_on_disk(disk* d);
|
||||||
10
src/exec.c
10
src/exec.c
@ -89,13 +89,15 @@ int do_echo(char **args) {
|
|||||||
|
|
||||||
int child_process_job(disk *d, char **args) {
|
int child_process_job(disk *d, char **args) {
|
||||||
if (strcmp("ls", args[0]) == 0) {
|
if (strcmp("ls", args[0]) == 0) {
|
||||||
return do_ls(d, args[1]);
|
do_ls(d, args[1]);
|
||||||
} else if (strcmp("mkdir", args[0]) == 0) {
|
} else if (strcmp("mkdir", args[0]) == 0) {
|
||||||
return do_mkdir(d, args[1]);
|
do_mkdir(d, args[1]);
|
||||||
|
persist_on_disk(d);
|
||||||
} else if (strcmp("touch", args[0]) == 0) {
|
} else if (strcmp("touch", args[0]) == 0) {
|
||||||
return do_touch(d, args[1]);
|
do_touch(d, args[1]);
|
||||||
|
persist_on_disk(d);
|
||||||
} else if (strcmp("df", args[0]) == 0) {
|
} else if (strcmp("df", args[0]) == 0) {
|
||||||
return do_df(d);
|
do_df(d);
|
||||||
} else {
|
} else {
|
||||||
dprintf(STDERR_FILENO, "%s: no such command\n", args[0]);
|
dprintf(STDERR_FILENO, "%s: no such command\n", args[0]);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user