add: df command
This commit is contained in:
parent
2645c3368c
commit
b82d00d651
@ -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
|
||||
|
||||
31
src/disk.c
31
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;
|
||||
|
||||
@ -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);
|
||||
@ -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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user