diff --git a/src/fs/file.c b/src/fs/file.c index 5428478..db5ddcc 100644 --- a/src/fs/file.c +++ b/src/fs/file.c @@ -198,6 +198,21 @@ int fstat(int fd, struct file_stat* stat) return res; } +int fclose(int fd) +{ + int res = 0; + struct file_descriptor* desc = file_get_descriptor(fd); + if (!desc) + { + res = -EIO; + goto out; + } + + res = desc->filesystem->close(desc->private); +out: + return res; +} + int fseek(int fd, int offset, FILE_SEEK_MODE whence) { int res = 0; diff --git a/src/fs/file.h b/src/fs/file.h index e013a5b..6284666 100644 --- a/src/fs/file.h +++ b/src/fs/file.h @@ -34,6 +34,8 @@ typedef void*(*FS_OPEN_FUNCTION)(struct disk* disk, struct path_part* path, FILE typedef int (*FS_READ_FUNCTION)(struct disk* disk, void* private, uint32_t size, uint32_t nmemb, char* out); typedef int (*FS_RESOLVE_FUNCTION)(struct disk* disk); +typedef int (*FS_CLOSE_FUNCTION)(void* private); + typedef int (*FS_SEEK_FUNCTION)(void* private, uint32_t offset, FILE_SEEK_MODE seek_mode); @@ -53,6 +55,7 @@ struct filesystem FS_READ_FUNCTION read; FS_SEEK_FUNCTION seek; FS_STAT_FUNCTION stat; + FS_CLOSE_FUNCTION close; char name[20]; }; @@ -76,6 +79,7 @@ int fopen(const char* filename, const char* mode_str); int fseek(int fd, int offset, FILE_SEEK_MODE whence); int fread(void* ptr, uint32_t size, uint32_t nmemb, int fd); int fstat(int fd, struct file_stat* stat); +int fclose(int fd); void fs_insert_filesystem(struct filesystem* filesystem); struct filesystem* fs_resolve(struct disk* disk);