add: read in files
This commit is contained in:
parent
b18a6aef72
commit
ba12753402
2
Makefile
2
Makefile
@ -1,7 +1,7 @@
|
||||
NAME := seyshell
|
||||
DRIVE := disk
|
||||
CC := gcc
|
||||
CFLAGS := -Wall -Wextra -Werror -g
|
||||
CFLAGS :=
|
||||
OBJ_DIR := obj
|
||||
SRC_DIR := src
|
||||
|
||||
|
||||
32
src/disk.c
32
src/disk.c
@ -140,15 +140,44 @@ void do_ls(disk *d, int dir_index) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: chercher sur tous les blocs possédés
|
||||
int bloc = dir.blocs[0];
|
||||
|
||||
for (int i = 0; i < MAX_BYTES_PER_BLOC; i += MAX_INODE_NAME + sizeof(int)) {
|
||||
if (d->blocs[bloc].datas[i] != '\0') {
|
||||
printf("%s\n", &d->blocs[bloc].datas[i]);
|
||||
int inode_id;
|
||||
memcpy(&inode_id, &d->blocs[bloc].datas[i + MAX_INODE_NAME], sizeof(int));
|
||||
dprintf(STDOUT_FILENO, "%-16s %d\n", &d->blocs[bloc].datas[i], inode_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char *read_in_file(disk *d, int file_index) {
|
||||
inode file = d->inodes[file_index];
|
||||
if (file.filetype != TYPE_FILE) {
|
||||
dprintf(STDERR_FILENO, "Can only read in files\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO: chercher sur tous les blocs possédés
|
||||
int bloc = file.blocs[0];
|
||||
char *out;
|
||||
int c_index = 0;
|
||||
while (d->blocs[bloc].datas[c_index] != '\0' || c_index < MAX_BYTES_PER_BLOC) {
|
||||
c_index++;
|
||||
}
|
||||
|
||||
out = malloc(c_index * sizeof(char));
|
||||
if (out == NULL) {
|
||||
dprintf(STDERR_FILENO, "Error while allocating with malloc\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
strncpy(out, d->blocs[bloc].datas, c_index);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
void init_env_var_file(disk *d) {
|
||||
int inode_idx = create_inode(d, &d->inodes[0], TYPE_FILE, "env");
|
||||
write_in_file(d, inode_idx, "PWD=/\nUSER=user");
|
||||
@ -159,7 +188,6 @@ void init_env_var_file(disk *d) {
|
||||
* renvoi ce disque
|
||||
* @return Le disque créé
|
||||
*/
|
||||
|
||||
disk create_disk() {
|
||||
FILE *fptr;
|
||||
fptr = fopen("disk", "wb");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user