From 1daa8e62633344799127e011fcbb22e99ab7f617 Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Sat, 23 Apr 2022 21:37:54 +0200 Subject: [PATCH] feat(iso): add close function --- k/fd.c | 6 ++++-- k/fd.h | 5 +++-- k/iso.c | 7 ++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/k/fd.c b/k/fd.c index eaeddbb..63c7396 100644 --- a/k/fd.c +++ b/k/fd.c @@ -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; } diff --git a/k/fd.h b/k/fd.h index 2fb418c..be1db1a 100644 --- a/k/fd.h +++ b/k/fd.h @@ -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 */ diff --git a/k/iso.c b/k/iso.c index 38111fd..c9bc8ca 100644 --- a/k/iso.c +++ b/k/iso.c @@ -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); +}