89 lines
2.0 KiB
C
89 lines
2.0 KiB
C
// vfs.c
|
|
// Author: Josh Holtrop
|
|
// Created: 12/31/03
|
|
// Modified: 01/04/04
|
|
|
|
|
|
void vfs_init()
|
|
{
|
|
firstDiskDevice = malloc(sizeof(DiskDevice));
|
|
firstDiskDevice->type = VFS_DISK_FD;
|
|
firstDiskDevice->fileSystem = VFS_FS_FAT12;
|
|
firstDiskDevice->location = VFS_LOC_FD0;
|
|
firstDiskDevice->link = 0;
|
|
strcpy(firstDiskDevice->id, "fd0");
|
|
rootDevice = firstDiskDevice;
|
|
if (*(byte *)0xC0090000) // the user chose to load an initial ram disk from the floppy
|
|
{
|
|
DiskDevice *rd = malloc(sizeof(DiskDevice));
|
|
firstDiskDevice->link = (dword)rd;
|
|
rd->type = VFS_DISK_RD;
|
|
rd->fileSystem = VFS_FS_FAT12;
|
|
rd->location = 0xC0200000;
|
|
rd->link = 0;
|
|
strcpy(rd->id, "rd0");
|
|
rootDevice = rd;
|
|
}
|
|
}
|
|
|
|
|
|
byte *vfs_readFile(char *fileName)
|
|
{
|
|
DiskDevice *dd;
|
|
dword fileStartPosition;
|
|
if (fileName[0] == '/')
|
|
{
|
|
dd = rootDevice;
|
|
fileStartPosition = 1;
|
|
}
|
|
else
|
|
{
|
|
if (strlen(fileName) < 5) //not a long enough file name
|
|
return 0;
|
|
if (!((fileName[3] == ':') && (fileName[4] == '/'))) //if we aren't using the root directory, then there must be a 3 character device explicitly specified
|
|
return 0; // followed by a colon and then a slash
|
|
char device[4];
|
|
memcpy((dword)device, (dword)fileName, 3); //copy the 3 digit device id to device
|
|
device[3] = 0; //null-terminating character for device string
|
|
dd = vfs_getDiskDeviceByID(device);
|
|
if (!dd) //the specified device was not found
|
|
return 0;
|
|
fileStartPosition = 5;
|
|
}
|
|
switch (dd->fileSystem)
|
|
{
|
|
case VFS_FS_FAT12:
|
|
return fat12_readFile(fileName+fileStartPosition, dd);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
byte *vfs_readSector(DiskDevice *dd, dword sector, byte *dest)
|
|
{
|
|
switch (dd->type)
|
|
{
|
|
case VFS_DISK_RD:
|
|
return rd_readSector(dd, sector, dest);
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
DiskDevice *vfs_getDiskDeviceByID(char *id)
|
|
{
|
|
DiskDevice *dd = firstDiskDevice;
|
|
for (;;)
|
|
{
|
|
if (strcmp(dd->id, id))
|
|
return dd;
|
|
dd = (DiskDevice *)dd->link;
|
|
if (!dd)
|
|
break;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
|