feat(iso): add close function

This commit is contained in:
Malo Lecomte 2022-04-23 21:37:54 +02:00
parent 99f290634f
commit 1daa8e6263
3 changed files with 13 additions and 5 deletions

6
k/fd.c
View File

@ -13,13 +13,14 @@ static int find_next_fd(void)
return -1;
}
int register_fd(u32 lba)
int register_fd(u32 lba, u32 file_size)
{
int free_fd = find_next_fd();
if (free_fd < 0)
return -1;
struct file_entry f = { .open = 1, .lba = lba, .file_offset = 0 };
struct file_entry f = { .open = 0, .lba = lba, .file_offset = 0,
.file_size = file_size };
fd_table[free_fd] = f;
return free_fd;
}
@ -32,6 +33,7 @@ int destroy_fd(int fd)
fd_table[fd].open = 0;
fd_table[fd].lba = 0;
fd_table[fd].file_offset = 0;
fd_table[fd].file_size = 0;
return 0;
}

5
k/fd.h
View File

@ -9,10 +9,11 @@ struct file_entry
{
u8 open;
u32 lba;
u64 file_offset;
u32 file_offset;
u32 file_size;
};
int register_fd(u32 lba);
int register_fd(u32 lba, u32 file_size);
int destroy_fd(int fd);
#endif /* !FD_H */

View File

@ -49,7 +49,7 @@ int open(const char *pathname, int flags)
// we found the file
if (!length)
return register_fd(curr->data_blk.le);
return register_fd(curr->data_blk.le, curr->data_size.le);
// iteration for one directory
while (curr->dir_size != 0)
@ -71,3 +71,8 @@ int open(const char *pathname, int flags)
return -1;
}
int close(int fd)
{
return destroy_fd(fd);
}