Espresso 0.0.1c

This commit is contained in:
2025-07-01 20:39:38 -05:00
parent f9f3faca4f
commit 8648637b51
23 changed files with 384 additions and 419 deletions

94
drivers/fs/sfs.c Normal file
View File

@ -0,0 +1,94 @@
#include <drivers/ide.h>
#include <stdio.h>
#include <stdlib.h>
#include <fs/sfs.h>
#define SFS_BEGINNING_LBA 8
#pragma pack(push, 1)
typedef struct sfs_file_header {
uint16_t magic; /* 0xBEEF */
/*
32 chars for the filename itself,
4 chars for the file's extension,
and 1 char for the null zero.
*/
char filename[37];
uint64_t data_beginning; /* Actually a 48 bit LBA mind you */
uint32_t num_sectors; /* Number of sectors after data_beginning that are this file's data */
uint8_t padding[13]; /* Padding to 64 bytes total */
} sfs_file_header_t;
#pragma pack(pop)
static sfs_file_header_t* base;
int32_t sfs_init(bool format)
{
uint8_t buffer[512] = { 0 };
int32_t kl = read_sector(SFS_BEGINNING_LBA, buffer);
if (kl != 0)
{
return -1;
}
volatile sfs_file_header_t null_file;
memcpy(&null_file, buffer, sizeof(sfs_file_header_t));
if ((&null_file)->magic != 0xBEEF)
{
if (!format)
{
return -2;
}
//sfs_format();
return -2;
}
memcpy(base, &null_file, sizeof(sfs_file_header_t));
return 0;
}
bool sfs_get_formatted_name(const char* raw_name, char output[37])
{
size_t len = strlen(raw_name);
if (len > 36 || strchr(raw_name, '/') || strchr(raw_name, '*') || strchr(raw_name, '\\')) {
return false;
}
memset(output, ' ', 36);
output[36] = '\0';
memcpy(output, raw_name, len);
return true;
}
/*
Note: if a negative value is passed for num, then read the whole file
*/
int32_t sfs_read_file(char* _name, void* buffer, uint32_t num)
{
char name[37] = { '\0' };
if (sfs_get_formatted_name(_name, name))
{
return -128;
}
printf("%s", name);
return 0;
}