Import backup from 2004-05-22

This commit is contained in:
josh committed 2017-07-25 22:23:46 -04:00
1 parent 6b6e19effd
commit a982312d2c
11 files changed
+225 -170

No files matched your search

+7 -102
View File
@@ -3,112 +3,17 @@
// 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"
#include "vfs.h"
//#include "fs/vfat.h"
//#include "block/rd.h"
//#include "block/loop.h"
#include "lang/LinkedList.h"
#include "kio.h"
Volume *firstVolume = 0;
Volume *rootVolume = 0;
MountPoint *firstMountPoint = 0;
void vfs_init()
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;
}
}
+2 -46
View File
@@ -1,58 +1,14 @@
// vfs.h
// Author: Josh Holtrop
// Date: 03/11/04
// Modified: 03/16/04
// Modified: 05/21/04
#ifndef __HOS_VFS__
#define __HOS_VFS__ __HOS_VFS__
#include "hos_defines.h"
#define VFS_LABEL_LENGTH 8
typedef struct
{
void *diskDevice; //pointer to device-dependent structure
int length; //size of the volume in bytes
int deviceType; //one of VFS_DISK_TYPES
int fsType; //one of VFS_FS_TYPES
char label[VFS_LABEL_LENGTH]; //descriptive volume label
void *link; //link to next volume in linked list
} Volume;
typedef struct
{
dword location; //location used by disk driver
dword dataLocation; //location used by disk driver
dword position; //read/write position in file
dword attributes; //read/write
dword fileSize; //number of bytes the file takes
Volume *vol; //what volume this file is on
} FILE;
typedef struct
{
char *device;
char *mount;
void *mp;
} MountPoint;
#define FILE_READ 1
#define FILE_WRITE 2
#define FILE_READ_WRITE 3
enum VFS_DISK_TYPES {VFS_NODISK, VFS_RD, VFS_FD, VFS_HD, VFS_LOOP, VFS_NUM_DISK_TYPES};
enum VFS_FS_TYPES {VFS_NOFS, VFS_VFAT, VFS_EXT2, VFS_NUM_FS_TYPES};
void vfs_init();
Volume *vfs_newVolume();
Volume *vfs_getLastVolume();
int vfs_readSector(Volume *vol, dword sector, byte *buffer);
int vfs_writeSector(Volume *vol, dword sector, byte *buffer);
int vfs_readSectorn(Volume *vol, dword sector, byte *buffer, int n);
int vfs_writeSectorn(Volume *vol, dword sector, byte *buffer, int n);
int vfs_readFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize);
int vfs_writeFileBlock(Volume *vol, char *file, dword start, byte *buffer, dword blockSize);
void vfs_init();
#endif