hos/kernel/fs/vfs.cpp

117 lines
2.0 KiB
C++

// vfs.c
// Author: Josh Holtrop
// Date: 03/11/04
// Modified: 03/16/04
#include "vfs.h"
#include "fs/vfat.h"
#include "hos_defines.h"
#include "block/rd.h"
#include "block/loop.h"
Volume *firstVolume = 0;
Volume *rootVolume = 0;
MountPoint *firstMountPoint = 0;
void vfs_init()
{
if(*(byte *)BOOT_HASRD) //bootloader loaded an initial ram disk
{
Volume *initrd = vfs_newVolume();
RamDisk *rd = rd_newDisk(0xC0200000, 1440*1024);
initrd->diskDevice = rd;
initrd->deviceType = VFS_RD;
strcpy(initrd->label, "rd0");
initrd->link = 0;
rootVolume = initrd;
}
}
Volume *vfs_newVolume()
{
Volume *vol = malloc(sizeof(Volume));
vfs_getLastVolume()->link = vol;
return vol;
}
Volume *vfs_getLastVolume()
{
Volume *vol = firstVolume;
while (vol)
vol = vol->link;
return vol;
}
int vfs_readSector(Volume *vol, dword sector, byte *buffer)
{
switch(vol->deviceType)
{
case VFS_RD:
return rd_readSector(vol->diskDevice, sector, buffer);
case VFS_LOOP:
return loop_readSector(vol->diskDevice, sector, buffer);
default:
return -1;
}
}
int vfs_writeSector(Volume *vol, dword sector, byte *buffer)
{
switch(vol->deviceType)
{
case VFS_RD:
return rd_writeSector(vol->diskDevice, sector, buffer);
case VFS_LOOP:
return loop_writeSector(vol->diskDevice, sector, buffer);
default:
return -1;
}
}
int vfs_readSectorn(Volume *vol, dword sector, byte *buffer, int n)
{
int r;
for (; n > 0; --n, ++sector, buffer += 512)
{
r = vfs_readSector(vol, sector, buffer);
if (r) return r;
}
return 0;
}
int vfs_writeSectorn(Volume *vol, dword sector, byte *buffer, int n)
{
int r;
for (; n > 0; --n, ++sector, buffer += 512)
{
r = vfs_writeSector(vol, sector, buffer);
if (r) return r;
}
return 0;
}
int vfs_readFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize)
{
switch(vol->fsType)
{
default:
return -1;
}
}
int vfs_writeFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize)
{
switch(vol->fsType)
{
default:
return -1;
}
}