Added SimpleFS read support
This commit is contained in:
parent
758d681005
commit
4ec95a6a52
8 changed files with 174 additions and 107 deletions
|
@ -30,74 +30,29 @@
|
|||
|
||||
#define MAX_MOUNTS 32
|
||||
|
||||
struct vfs_mount **mountpoints = NULL;
|
||||
uint8_t last_mount = 0;
|
||||
struct vfs_drive *boot_drive = NULL;
|
||||
|
||||
size_t str_backspace(char *str, char c)
|
||||
int vfs_init(char *root_mountpoint)
|
||||
{
|
||||
size_t i = strlen(str) - 1;
|
||||
|
||||
while (--i) {
|
||||
if (str[i] == c) {
|
||||
str[i+1] = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Returns UINT8_MAX incase an error happens */
|
||||
uint8_t find_mntpoint_from_filename(char *filename, uint32_t *s_off)
|
||||
{
|
||||
char *orig = (char *)mem_alloc(strlen(filename) + 1);
|
||||
if (!orig) {
|
||||
debug("find_mntpoint_from_filename(): Failed to allocate memory for filename!\n");
|
||||
return UINT8_MAX;
|
||||
}
|
||||
|
||||
memset(orig, 0, strlen(filename) + 1);
|
||||
memcpy(orig, filename, strlen(filename) + 1);
|
||||
|
||||
if (orig[strlen(orig)] == '/')
|
||||
str_backspace(orig, '/');
|
||||
|
||||
// TODO: Check if there's a way to stay in this loop forever
|
||||
while (1) {
|
||||
for (int i = 0; i < MAX_MOUNTS; i++) {
|
||||
if (!mountpoints[i])
|
||||
break;
|
||||
|
||||
if (strcmp(mountpoints[i]->mnt, orig) == 0) {
|
||||
/* Adjust the orig to make it relative to the partition */
|
||||
*s_off = (strlen(orig) - 1);
|
||||
mem_free(orig);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
if (strcmp(orig, "/") == 0)
|
||||
break;
|
||||
str_backspace(orig, '/');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void vfs_init(void)
|
||||
{
|
||||
mountpoints = (struct vfs_mount **)mem_alloc(sizeof(struct vfs_mount) * MAX_MOUNTS);
|
||||
if (!mountpoints) {
|
||||
boot_drive = mount_boot_volume(root_mountpoint);
|
||||
if (boot_drive == NULL) {
|
||||
debug("vfs_init(): Failed to allocate memory for VFS!\n");
|
||||
// TODO: Panic and halt
|
||||
// fuck off and boot out early.
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug("vfs_init(): Mounted boot drive to \"/\"\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int vfs_read(char *filename, char *buf, size_t len)
|
||||
size_t vfs_read(char *filename, char *buf)
|
||||
{
|
||||
uint32_t s_off = 0;
|
||||
int i = find_mntpoint_from_filename(filename, &s_off);
|
||||
filename += s_off;
|
||||
if (boot_drive->fs->read == NULL) {
|
||||
debug("vfs_read(): Filesystem didn't set up a read function!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
return mountpoints[i]->drive->fs->read(filename, buf, mountpoints[i]->drive, mountpoints[i]->drive->fs->fs_data);
|
||||
return boot_drive->fs->read(filename, buf, boot_drive, boot_drive->fs->fsdata);
|
||||
}
|
||||
|
||||
int vfs_write(char *filename, char *buf, size_t len)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue