Added VFS read and started UEFI SFS driver

This commit is contained in:
Jozef Nagy 2025-01-26 18:05:21 +01:00
parent b4289c429e
commit 758d681005
Signed by untrusted user who does not match committer: crz
GPG key ID: 459A4811CEAC7068
6 changed files with 145 additions and 9 deletions

36
boot/common/fs/uefi_sfs.c Normal file
View file

@ -0,0 +1,36 @@
/*********************************************************************************/
/* Module Name: uefi_sfs.c */
/* Project: AurixOS */
/* */
/* Copyright (c) 2024-2025 Jozef Nagy */
/* */
/* This source is subject to the MIT License. */
/* See License.txt in the root of this repository. */
/* All other rights reserved. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/*********************************************************************************/
#ifndef AXBOOT_UEFI
#include <vfs/drive.h>
#include <vfs/vfs.h>
#include <efi.h>
#include <efilib.h>
struct sfs_fsdata {
};
uint8_t sfs_read(char *filename, char *buffer, struct device *dev, void *fsdata)
{
(void)dev;
(void)fsdata;
}
#endif

View file

@ -17,7 +17,10 @@
/* SOFTWARE. */
/*********************************************************************************/
#include <vfs/vfs.h>
void axboot_init()
{
vfs_init();
while (1);
}

View file

@ -24,7 +24,7 @@
#include <stddef.h>
// NOTE: If any allocations fail, try increasing this number.
#define MAX_ALLOCATIONS 256
#define MAX_ALLOCATIONS 64
struct alloc_header allocation_list[MAX_ALLOCATIONS] = {0};

View file

@ -17,22 +17,87 @@
/* SOFTWARE. */
/*********************************************************************************/
/* VFS originally written by Levente Kurusa, stripped down for AxBoot */
/* https://github.com/levex/osdev */
#include <mm/mman.h>
#include <vfs/drive.h>
#include <vfs/vfs.h>
#include <lib/string.h>
#include <print.h>
#include <stdint.h>
#include <stddef.h>
#define MAX_MOUNTS 32
struct vfs_mount **mountpoints = NULL;
uint8_t last_mount = 0;
size_t str_backspace(char *str, char c)
{
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) {
debug("vfs_init(): Failed to allocate memory for VFS!\n");
// TODO: Panic and halt
}
}
int vfs_read(char *filename, char *buf, size_t len)
{
(void)filename;
(void)buf;
(void)len;
uint32_t s_off = 0;
int i = find_mntpoint_from_filename(filename, &s_off);
filename += s_off;
return 0;
return mountpoints[i]->drive->fs->read(filename, buf, mountpoints[i]->drive, mountpoints[i]->drive->fs->fs_data);
}
int vfs_write(char *filename, char *buf, size_t len)