[GOOD] BUILD 0.1.0.470 DATE 8/30/2011 AT 6:40 PM

====================================================
Mainly changed: HAL.VFS
+ Designed virtual file system
+ Completed the VFS
+ Added verbose mode for VFS
+ Updated shell script, now shows build number when building
? TODO: Implement one file system (most likely FAT12)
? TODO: Mount floppy device
This commit is contained in:
2021-09-14 18:50:50 +03:00
parent 913e65b856
commit 0372dcee81
75 changed files with 377 additions and 636 deletions

View File

@ -0,0 +1,8 @@
/*
* fat12.c
*
* Created on: Aug 29, 2011
* Author: Tiberiu
*/

View File

@ -8,6 +8,7 @@
#include "keyboard/keyboard.h"
#include "mouse/mouse.h"
#include <fileio.h>
#include <debugio.h>
void HalInitialize()
@ -32,4 +33,7 @@ void HalInitialize()
// Install mouse driver
MouseInstall(); Log("%#[HAL] %#Installed mouse driver\n", ColorYellow, ColorLightGreen);
// Install VFS
VfsInstall();
}

View File

@ -8,13 +8,9 @@
*/
#include <stdio.h>
#include <multiboot.h>
#include <debugio.h>
#include <memory.h>
#include <../drivers/cmos/cmos.h>
#include "keyboard/keyboard.h"
void SystemReboot()
{
Log("Rebooting system...\n");

View File

@ -1,40 +1,208 @@
#include<fileio.h>
#include<storage.h>
#include <memory.h>
#include <stdlib.h>
#include <fileio.h>
#include <debugio.h>
#define MAX_FS_COUNT 64
#define BAD 0xffffffff
uint32 FsRead(FsNode *node, uint32 offset, uint32 size, uint8 *buffer)
FileSystem* fsArray;
uint32 fsCount;
MountPoint* mpArray;
uint32 mpCount;
uint32 mpAllocated;
#define LogVfs(...) { Log("%#[Vfs] ", ColorLightBlue); Log(__VA_ARGS__); }
#define ErrorVfs(...) { Error("%#[Vfs] ", ColorLightBlue); Error(__VA_ARGS__); }
void VfsInstall ()
{
if (node->Read != NULL) return node->Read(node, offset, size, buffer);
return NULL;
fsArray = (FileSystem*) kmalloc(MAX_FS_COUNT * sizeof(FileSystem));
fsCount = 0;
mpArray = (MountPoint*) kmalloc(32 * sizeof(MountPoint));
mpCount = 0;
mpAllocated = 32;
LogVfs("%#VFS now in business.\n", ColorLightGreen);
}
uint32 FsWrite(FsNode *node, uint32 offset, uint32 size, uint8 *buffer)
uint8 VfsInstallFs (FileSystem* fs)
{
if (node->Write != NULL) return node->Write(node, offset, size, buffer);
return NULL;
if (fsCount >= MAX_FS_COUNT) {
ErrorVfs("%#Failed to install file system '%s': FS count reached.\n", ColorLightRed, fs->Name);
return 0;
}
memcpy(&fsArray[fsCount], fs, sizeof(FileSystem));
fsArray[fsCount].Id = fsCount;
++fsCount;
LogVfs("Installed file system %#.\n", ColorWhite, fs->Name);
return 1;
}
void FsOpen(FsNode *node, uint8 read, uint8 write)
uint32 VfsFindDevice (string dev)
{
if (node->Open != NULL) return node->Open(node, read, write);
uint32 i;
for (i = 0; i < mpCount; i++)
if (strcmp(dev, mpArray[i].Name) == 0)
return i;
return BAD;
}
void FsClose(FsNode *node)
// Returns mount point index, removes dev name from path
uint32 VfsParsePath (string* path)
{
if (node->Close != NULL) return node->Close();
// Sanity check
if (!path || !(*path)) return BAD;
string dev = *path, p = strchr(*path, ':');
if (p == NULL) return BAD; // invalid path
// Split string
*path = p+1; *p = '\0';
return VfsFindDevice(dev);
}
DirectoryEntry *FsReadDir(FsNode *node, uint32 index)
uint8 VfsMount (string Name, DevReadRoutine R, DevWriteRoutine W, uint32 BlockSize)
{
if (node->ReadDir != NULL && (node->Flags&7) == FsDirectory)
return node->ReadDir(node, index);
return NULL;
uint32 i, fsId = BAD, mpIndex = BAD;
// Try to figure out the file system
for (i = 0; i < fsCount && fsId == BAD; i++)
if (fsArray->Detect && fsArray->Detect(R, BlockSize)) fsId = i;
if (fsId == BAD) {
ErrorVfs("%#Failed to mount device %s: no file system found.\n", ColorLightRed, Name)
return 0; // No file system, no good
}
// Try to find an empty slot to fill
for (i = 0; i < mpCount && mpIndex == BAD; i++)
if (mpArray[i].Id == BAD) mpIndex = i;
// No empty slots?
if (mpIndex == BAD)
{
// Make sure we have enough space
if (mpCount == mpAllocated) {
mpAllocated += 4;
mpArray = kmrealloc(mpArray, mpAllocated * sizeof(MountPoint));
}
mpIndex = mpCount++;
}
// Add to mount point list, set up data
mpArray[mpIndex].Id = mpIndex;
mpArray[mpIndex].FsId = fsId;
mpArray[mpIndex].BlockSize = BlockSize;
mpArray[mpIndex].Read = R;
mpArray[mpIndex].Write = W;
// Change name if it already exists
uint32 find = VfsFindDevice(Name);
if (find != BAD)
{
uint32 len = strlen(Name);
uint8 success = 0;
Name[len+1] = '\0';
// Try to find a number index
for (find = '0'; find <= '9' && !success; find++)
{
Name[len] = find;
if (VfsFindDevice(Name) == BAD) success = 1;
}
// What? Haven't found anything yet? Try the alphabet
for (find = 'a'; find <= 'z' && !success; find++)
{
Name[len] = find;
if (VfsFindDevice(Name) == BAD) success = 1;
}
// Still nothing? How in the world is this even possible ?!?!?!
if (!success) return 0;
}
memcpy(mpArray[mpCount].Name, Name, sizeof(char) * 128);
LogVfs("Mounted device %#%s", ColorWhite, Name);
return 1;
}
FsNode *FsFindDir(FsNode *node, char *name)
void VfsUnmount (uint32 dev_id)
{
if (node->FindDir != NULL && (node->Flags&7) == FsDirectory)
return node->FindDir(node, name);
return NULL;
mpArray[dev_id].Id = BAD;
mpCount--;
}
// Returns pointer to FILE structure that was inputed if success, null otherwise
FILE* VfsOpen (FILE* file, string path)
{
if (!file) return NULL;
// Parse string
uint32 dev = VfsParsePath(&path);
file->DeviceId = dev;
// Device not found, or Open routine doesn't exist
if (dev == BAD || !fsArray[mpArray[dev].FsId].Open) return NULL;
// Ask the FS to do the 'opening'
return fsArray[mpArray[dev].FsId].Open(&mpArray[dev],file,path);
}
DirectoryEntry* VfsTest (string path)
{
// Parse string
uint32 dev = VfsParsePath(&path);
// Device not found, or Open routine doesn't exist
if (dev == BAD || !fsArray[mpArray[dev].FsId].Test) return NULL;
// Ask the FS to do the 'opening'
return fsArray[mpArray[dev].FsId].Test(&mpArray[dev],path);
}
FILE* VfsClose (FILE* file)
{
if (!file) return NULL;
MountPoint* mp = &(mpArray[file->DeviceId]);
if (!fsArray[mp->FsId].Close) return NULL;
return fsArray[mp->FsId].Close(mp,file);
}
uint32 VfsRead (FILE* file, uint32 bsz, uint32 n, uint8* buffer)
{
if (!file) return NULL;
MountPoint* mp = &(mpArray[file->DeviceId]);
if (!fsArray[mp->FsId].Read) return NULL;
return fsArray[mp->FsId].Read(mp, file, bsz, n, buffer);
}
uint32 VfsWrite (FILE* file, uint32 bsz, uint32 n, uint8* buffer)
{
if (!file) return NULL;
MountPoint* mp = &(mpArray[file->DeviceId]);
if (!fsArray[mp->FsId].Write) return NULL;
return fsArray[mp->FsId].Write(mp, file, bsz, n, buffer);
}
DirectoryEntry* VfsReadDirectory (FILE* handle, uint32 index)
{
if (!handle) return NULL;
MountPoint* mp = &(mpArray[handle->DeviceId]);
if (!fsArray[mp->FsId].ReadDirectory) return NULL;
return fsArray[mp->FsId].ReadDirectory(mp, handle, index);
}