72 lines
1.3 KiB
C
72 lines
1.3 KiB
C
// vfs.c
|
|
// Author: Josh Holtrop
|
|
// Created: 12/31/03
|
|
|
|
|
|
void vfs_init()
|
|
{
|
|
byte ramDiskPresent = *(byte *)0xC0090000;
|
|
if (ramDiskPresent)
|
|
{
|
|
strcpy(rootDirectory, "rd0");
|
|
firstDevice = malloc(sizeof(DeviceEntry));
|
|
firstDevice->link = 0;
|
|
firstDevice->diskDevice = malloc(sizeof(DiskDevice));
|
|
firstDevice->diskDevice->type = VFS_DISK_RD;
|
|
firstDevice->diskDevice->fileSystem = VFS_FS_FAT12;
|
|
strcpy(firstDevice->diskDevice->id, "rd0");
|
|
firstDevice->diskDevice->location = 0xC0200000;
|
|
}
|
|
else
|
|
{
|
|
rootDirectory[0] = 0;
|
|
}
|
|
}
|
|
|
|
|
|
byte *vfs_readFile(char *fileName)
|
|
{
|
|
char *newFileName = fileName;
|
|
char device[4];
|
|
if (fileName[0] == '/')
|
|
{
|
|
newFileName = malloc(strlen(fileName)+4);
|
|
strcpy(newFileName, rootDirectory);
|
|
strcat(newFileName, fileName);
|
|
}
|
|
strcpy(device, newFileName);
|
|
DiskDevice *dd = vfs_getDiskDeviceByID(device);
|
|
|
|
if (newFileName != fileName)
|
|
free(newFileName);
|
|
}
|
|
|
|
|
|
byte *vfs_readSector(DiskDevice *dd, dword sector)
|
|
{
|
|
switch(dd->type)
|
|
{
|
|
case VFS_DISK_RD:
|
|
return rd_readSector(dd, sector);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
DiskDevice *vfs_getDiskDeviceByID(char *id)
|
|
{
|
|
DeviceEntry *de = firstDevice;
|
|
for (;;)
|
|
{
|
|
if (strcmp(de->diskDevice->id, id))
|
|
return de->diskDevice;
|
|
de = (DeviceEntry *)de->link;
|
|
if (!de)
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|