diff --git a/src/const.h b/src/const.h index ef4cf89..0a5b522 100644 --- a/src/const.h +++ b/src/const.h @@ -1,8 +1,8 @@ /** @file */ #define BUFSIZE 1024 #define MAX_BLOCS 30 -#define MAX_BYTES_PER_BLOC 1024 -#define MAX_INODE 10 +#define MAX_BYTES_PER_BLOC 512 +#define MAX_INODE 20 #define MAX_INODE_NAME 28 // 27 caractères + '\0' + numero de l'inode ref #define TYPE_NULL 0 diff --git a/src/disk.c b/src/disk.c index dc35d31..d5448df 100644 --- a/src/disk.c +++ b/src/disk.c @@ -194,6 +194,37 @@ void write_in_file(disk *d, int file_index, char *data /*, char mode*/) { strncpy(&d->blocs[bloc_index_to_overwrite].datas[0], data, strlen(data)); } +int get_number_of_free_blocs(disk *d) { + int out = 0; + for (int i = 0; i < MAX_BLOCS; i++) { + if (d->owned_blocs[i] == 0) { + out++; + } + } + return out; +} + +int get_number_of_inode_left(disk *d) { + int out = 0; + for (int i = 0; i < MAX_INODE; i++) { + if (d->inodes[i].filetype == TYPE_NULL) { + out++; + } + } + return out; +} + +int do_df(disk *d) { + int free_blocs = get_number_of_free_blocs(d); + printf(" Free blocs : %i\n", free_blocs); + printf(" Inode left : %i\n", get_number_of_inode_left(d)); + // N'est pas la taille réelle à proprement parlé mais plutot l'espace + // possiblement occupable par le reste d'inode sur le disque + printf(" Space left : %.2fKb\n", + (float)(free_blocs * MAX_BYTES_PER_BLOC) / 1000); + return 0; +} + int find_dir_inode_by_name(char *name, int dir_index, disk *d) { if (dir_index < 0 || dir_index >= MAX_INODE) return -1; diff --git a/src/disk.h b/src/disk.h index 74a4ee4..48a7910 100644 --- a/src/disk.h +++ b/src/disk.h @@ -17,4 +17,5 @@ disk open_disk(char* filename); 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); \ No newline at end of file diff --git a/src/exec.c b/src/exec.c index e53930e..cec72da 100644 --- a/src/exec.c +++ b/src/exec.c @@ -38,6 +38,8 @@ int child_process_job(disk *d, char **args) { do_mkdir(d, args[1]); } else if (strcmp("touch", args[0]) == 0) { do_touch(d, args[1]); + } else if (strcmp("df", args[0]) == 0) { + do_df(d); } else { dprintf(STDERR_FILENO, "%s: no such command\n", args[0]); } @@ -49,7 +51,7 @@ int execute_cmd(disk *d, char **args) { return do_cd(d, args[1]); } - int pid = 0; + int pid = fork(); if (pid == 1) { return -1;