fix: persist datas on disk

This commit is contained in:
Guamss 2026-05-04 18:03:24 +02:00
parent bb2ea44383
commit c82deb402c
3 changed files with 18 additions and 5 deletions

View File

@ -391,3 +391,13 @@ disk open_disk(char *filename) {
fclose(fptr);
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");
}
}

View File

@ -18,4 +18,5 @@ int do_ls(disk *d, char* path);
int do_touch(disk *d, char *filepath);
int do_mkdir(disk* d, char *dirpath);
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);

View File

@ -89,13 +89,15 @@ int do_echo(char **args) {
int child_process_job(disk *d, char **args) {
if (strcmp("ls", args[0]) == 0) {
return do_ls(d, args[1]);
do_ls(d, args[1]);
} 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) {
return do_touch(d, args[1]);
do_touch(d, args[1]);
persist_on_disk(d);
} else if (strcmp("df", args[0]) == 0) {
return do_df(d);
do_df(d);
} else {
dprintf(STDERR_FILENO, "%s: no such command\n", args[0]);
}