-
bourbaki0404 authored3e4b5586
#include "fs.h"
#include "vfs.h"
#include "mm.h"
#include "string.h"
#include "printk.h"
#include "fat32.h"
struct files_struct *file_init() {
// todo: alloc pages for files_struct, and initialize stdin, stdout, stderr
struct files_struct *ret = NULL;
return ret;
}
uint32_t get_fs_type(const char *filename) {
uint32_t ret;
if (memcmp(filename, "/fat32/", 7) == 0) {
ret = FS_TYPE_FAT32;
} else if (memcmp(filename, "/ext2/", 6) == 0) {
ret = FS_TYPE_EXT2;
} else {
ret = -1;
}
return ret;
}
int32_t file_open(struct file* file, const char* path, int flags) {
file->opened = 1;
file->perms = flags;
file->cfo = 0;
file->fs_type = get_fs_type(path);
memcpy(file->path, path, strlen(path) + 1);
if (file->fs_type == FS_TYPE_FAT32) {
file->lseek = fat32_lseek;
file->write = fat32_write;
file->read = fat32_read;
file->fat32_file = fat32_open_file(path);
// todo: check if fat32_file is valid (i.e. successfully opened) and return
} else if (file->fs_type == FS_TYPE_EXT2) {
printk(RED "Unsupport ext2\n" CLEAR);
return -1;
} else {
printk(RED "Unknown fs type: %s\n" CLEAR, path);
return -1;
}
}