Started fleshing out the storage API
This commit is contained in:
41
kernel/storage/vfs/FileSystem.cpp
Normal file
41
kernel/storage/vfs/FileSystem.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
//
|
||||
// Created by nigel on 21/02/23.
|
||||
//
|
||||
#include "FileSystem.h"
|
||||
|
||||
void FileSystem::WriteFile(int file, unsigned char* buffer, unsigned int length) {
|
||||
|
||||
}
|
||||
|
||||
void FileSystem::ReadFile(int file, unsigned char* buffer, unsigned int length) {
|
||||
|
||||
}
|
||||
|
||||
FILE FileSystem::OpenFile(const char* fname){
|
||||
if(fname){
|
||||
unsigned char device = 'a';
|
||||
char* filename = (char*) fname;
|
||||
|
||||
if(fname[1]== ':'){
|
||||
device = fname[0];
|
||||
filename += 2; // strip the volume component from the path
|
||||
}
|
||||
|
||||
if(_filesystems[device - 'a']){
|
||||
FILE file = _filesystems[device-'a']->Open(filename);
|
||||
file.device = device;
|
||||
return file;
|
||||
}
|
||||
}
|
||||
FILE file;
|
||||
file.flags = FS_INVALID;
|
||||
return file;
|
||||
}
|
||||
|
||||
void FileSystem::CloseFile(PFILE file) {
|
||||
if(file->device < DEVICE_MAX){
|
||||
// _filesystems[file->device]->Close(file);
|
||||
}
|
||||
}
|
||||
|
||||
|
18
kernel/storage/vfs/FileSystem.h
Normal file
18
kernel/storage/vfs/FileSystem.h
Normal file
@ -0,0 +1,18 @@
|
||||
//
|
||||
// Created by nigel on 21/02/23.
|
||||
//
|
||||
#pragma once
|
||||
#include "StorageTypes.h"
|
||||
|
||||
class FileSystem {
|
||||
public:
|
||||
static void WriteFile(PFILE file, unsigned char* beffer, unsigned int length);
|
||||
static void ReadFile(PFILE file, unsigned char* buffer, unsigned int length);
|
||||
static FILE OpenFile(const char* fname);
|
||||
static void CloseFile(PFILE file);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
5
kernel/storage/vfs/Inode.cpp
Normal file
5
kernel/storage/vfs/Inode.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
//
|
||||
// Created by nigel on 21/02/23.
|
||||
//
|
||||
|
||||
#include "Inode.h"
|
24
kernel/storage/vfs/Inode.h
Normal file
24
kernel/storage/vfs/Inode.h
Normal file
@ -0,0 +1,24 @@
|
||||
//
|
||||
// Created by nigel on 21/02/23.
|
||||
//
|
||||
#pragma once
|
||||
enum struct NODE_TYPE {
|
||||
FILESYSTEM,
|
||||
FILE,
|
||||
DIRECTORY
|
||||
};
|
||||
|
||||
enum struct PERMISSIONS {
|
||||
READ,
|
||||
WRITE,
|
||||
EXECUTE
|
||||
};
|
||||
|
||||
struct Inode {
|
||||
NODE_TYPE type;
|
||||
PERMISSIONS permissions;
|
||||
Inode* Parent;
|
||||
Inode* sibling;
|
||||
};
|
||||
|
||||
|
32
kernel/storage/vfs/StorageTypes.h
Normal file
32
kernel/storage/vfs/StorageTypes.h
Normal file
@ -0,0 +1,32 @@
|
||||
//
|
||||
// Created by nigel on 21/02/23.
|
||||
//
|
||||
#pragma once
|
||||
#include <stdint-gcc.h>
|
||||
|
||||
enum FS_TYPES {
|
||||
FS_FILE =0,
|
||||
FS_DIRECTORY =1,
|
||||
FS_INVALID=2
|
||||
};
|
||||
|
||||
typedef struct _FILE {
|
||||
char name [32];
|
||||
uint32_t flags;
|
||||
uint32_t filelength;
|
||||
uint32_t id;
|
||||
uint32_t eof;
|
||||
uint32_t position;
|
||||
uint32_t currentCluster;
|
||||
uint32_t device;
|
||||
}FILE, *PFILE;
|
||||
|
||||
typedef struct _FILE_SYSTEM{
|
||||
char name[8];
|
||||
FILE (*Directory) (const char* Directoryname);
|
||||
void (*Mount) ();
|
||||
void (*Read) (PFILE file, unsigned char* buffer, unsigned int length);
|
||||
void (Close) (PFILE);
|
||||
FILE (*Open) (const char* filename);
|
||||
}FILESYSTEM, *PFS;
|
||||
|
54
kernel/storage/vfs/VFS.cpp
Normal file
54
kernel/storage/vfs/VFS.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "VFS.h"
|
||||
#include <stdint-gcc.h>
|
||||
#include "../../memory/KernelHeap.h"
|
||||
#include <CoreLib/Memory.h>
|
||||
|
||||
PFS VirtualFileSystem::_filesystems[VirtualFileSystem::DEVICE_MAX];
|
||||
|
||||
void VirtualFileSystem::initialize()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VirtualFileSystem::ResolvePath(Path &path)
|
||||
{
|
||||
// See reference material (1) https://man7.org/linux/man-pages/man7/path_resolution.7.html
|
||||
|
||||
char* string_path = path.str();
|
||||
void* cpy = string_path;
|
||||
|
||||
bool isAbsolutePath = string_path[0] == '/';
|
||||
if(isAbsolutePath)
|
||||
{
|
||||
// strip the first slash
|
||||
string_path++;
|
||||
}
|
||||
|
||||
char* tokstate = NULL;
|
||||
char* nextdir = strtok(string_path, "/", &tokstate);
|
||||
while (nextdir)
|
||||
{
|
||||
printf("First entry to look for: %s\n", nextdir);
|
||||
nextdir = strtok(NULL, "/", &tokstate);
|
||||
}
|
||||
|
||||
free(cpy);
|
||||
}
|
||||
|
||||
void VirtualFileSystem::Mount(PFS filesystemDescriptor, unsigned int DeviceID)
|
||||
{
|
||||
if(DeviceID < DEVICE_MAX)
|
||||
if(filesystemDescriptor)
|
||||
_filesystems[DeviceID] = filesystemDescriptor;
|
||||
}
|
||||
|
||||
|
||||
void VirtualFileSystem::Unmount(unsigned int DeviceID) {
|
||||
if(DeviceID < DEVICE_MAX)
|
||||
_filesystems[DeviceID] = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
17
kernel/storage/vfs/VFS.h
Normal file
17
kernel/storage/vfs/VFS.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <stdint-gcc.h>
|
||||
#include "../../../CoreLib/Path.h"
|
||||
#include "StorageTypes.h"
|
||||
class VirtualFileSystem
|
||||
{
|
||||
public:
|
||||
static void initialize();
|
||||
static void Mount(PFS fs, unsigned int DeviceID);
|
||||
static void Unmount(unsigned int DeviceID);
|
||||
static void ResolvePath(Path& path);
|
||||
|
||||
private:
|
||||
static const unsigned int DEVICE_MAX = 26;
|
||||
static PFS _filesystems[DEVICE_MAX];
|
||||
|
||||
};
|
Reference in New Issue
Block a user