Import backup from 2004-04-03
This commit is contained in:
1 parent
7110307896
commit
6236c341dd
21 files changed
+1778
-82
No files matched your search
@@ -1,7 +0,0 @@
|
||||
// fat12.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/11/04
|
||||
|
||||
#include "fat12.h"
|
||||
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// fat12.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/11/04
|
||||
|
||||
#ifndef __HOS_FAT12__
|
||||
#define __HOS_FAT12__ __HOS_FAT12__
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// vfat.c
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/11/04
|
||||
// Modified: 03/22/04
|
||||
|
||||
#include "vfat.h"
|
||||
#include "hos_defines.h"
|
||||
#include "fs/vfs.h"
|
||||
#include "mm/vmm.h"
|
||||
#include "string/string.h"
|
||||
|
||||
//From Microsoft's FAT32 File System Specification
|
||||
DSKSZTOSECPERCLUS DskTableFAT16 [] =
|
||||
{
|
||||
{ 8400, 0}, /* disks up to 4.1 MB, the 0 value for SecPerClusVal trips an error */
|
||||
{ 32680, 2}, /* disks up to 16 MB, 1k cluster */
|
||||
{ 262144, 4}, /* disks up to 128 MB, 2k cluster */
|
||||
{ 524288, 8}, /* disks up to 256 MB, 4k cluster */
|
||||
{ 1048576, 16}, /* disks up to 512 MB, 8k cluster */
|
||||
/* The entries after this point are not used unless FAT16 is forced */
|
||||
// { 2097152, 32}, /* disks up to 1 GB, 16k cluster */
|
||||
// { 4194304, 64}, /* disks up to 2 GB, 32k cluster */
|
||||
{ 0xFFFFFFFF, 0} /* any disk greater than 2GB, 0 value for SecPerClusVal trips an error */
|
||||
};
|
||||
|
||||
//From Microsoft's FAT32 File System Specification
|
||||
DSKSZTOSECPERCLUS DskTableFAT32 [] =
|
||||
{
|
||||
{ 66600, 0}, /* disks up to 32.5 MB, the 0 value for SecPerClusVal trips an error */
|
||||
{ 532480, 1}, /* disks up to 260 MB, .5k cluster */
|
||||
{ 16777216, 8}, /* disks up to 8 GB, 4k cluster */
|
||||
{ 33554432, 16}, /* disks up to 16 GB, 8k cluster */
|
||||
{ 67108864, 32}, /* disks up to 32 GB, 16k cluster */
|
||||
{ 0xFFFFFFFF, 64}/* disks greater than 32GB, 32k cluster */
|
||||
};
|
||||
|
||||
int vfat_identify(vfat_bpb *bpb)
|
||||
{
|
||||
int rootDirSectors = ((bpb->rootEntries * 32) + (bpb->bytesPerSector - 1)) / bpb->bytesPerSector;
|
||||
int totalSectors = bpb->totalSectors16 ? bpb->totalSectors16 : bpb->totalSectors32;
|
||||
int fatSectors = bpb->sectorsPerFAT16 ? bpb->sectorsPerFAT16 : bpb->sectorsPerFAT32;
|
||||
int dataSectors = totalSectors - (bpb->reservedSectors + bpb->numFATs * fatSectors + rootDirSectors);
|
||||
int clusters = dataSectors / bpb->sectorsPerCluster;
|
||||
if (clusters < 4085)
|
||||
return 12;
|
||||
if (clusters < 65525)
|
||||
return 16;
|
||||
return 32;
|
||||
}
|
||||
|
||||
|
||||
int vfat_format(Volume *vol)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FILE *vfat_open(char *fileName, dword attributes, Volume *vol)
|
||||
{
|
||||
while (*fileName == '/')
|
||||
++fileName;
|
||||
if (strlen(fileName) < 1)
|
||||
return 0;
|
||||
vfat_bpb *bpb = vfat_getBootSector(vol);
|
||||
if (!bpb) return 0;
|
||||
byte *fat = vfat_loadFAT(vol, bpb);
|
||||
if (!fat)
|
||||
{
|
||||
free(bpb);
|
||||
return 0;
|
||||
}
|
||||
int segs = string_split(fileName); //number of sections of path (1=file is in root directory)
|
||||
int me = vfat_identify(bpb);
|
||||
if (me != 32)
|
||||
{
|
||||
if (segs == 1) //we are looking for the file in the root directory
|
||||
{
|
||||
vfat_getEntryInRoot(vol, bpb, fileName, 0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
byte *vfat_loadFAT(Volume *vol, vfat_bpb *bpb)
|
||||
{
|
||||
int fatSize = bpb->sectorsPerFAT16 ? bpb->sectorsPerFAT16 : bpb->sectorsPerFAT32;
|
||||
byte *fat = malloc(fatSize << 9); //512 bytes per sector
|
||||
if (!fat) return 0;
|
||||
if (vfs_readSectorn(vol, bpb->reservedSectors, fat, fatSize))
|
||||
{
|
||||
free(fat);
|
||||
return 0;
|
||||
}
|
||||
return fat;
|
||||
}
|
||||
|
||||
vfat_bpb *vfat_getBootSector(Volume *vol)
|
||||
{
|
||||
vfat_bpb *bs;
|
||||
if (!(bs = malloc(512)))
|
||||
return 0;
|
||||
vfs_readSector(vol, 0, bs);
|
||||
return bs;
|
||||
}
|
||||
|
||||
int vfat_close(FILE *fp)
|
||||
{
|
||||
return free(fp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
// vfat.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/11/04
|
||||
// Modified: 03/22/04
|
||||
|
||||
#ifndef __HOS_VFAT__
|
||||
#define __HOS_VFAT__ __HOS_VFAT__
|
||||
|
||||
#include "hos_defines.h"
|
||||
#include "fs/vfs.h"
|
||||
|
||||
#define VFAT_FAT12_EOCL 0x0FF8 // end-of-cluster chain reached if FatValue >= EOCL
|
||||
#define VFAT_FAT16_EOCL 0xFFF8
|
||||
#define VFAT_FAT32_EOCL 0x0FFFFFF8
|
||||
|
||||
#define VFAT_FAT12_EOC 0x0FFF // end-of-cluster chain value
|
||||
#define VFAT_FAT16_EOC 0xFFFF
|
||||
#define VFAT_FAT32_EOC 0x0FFFFFFF
|
||||
|
||||
#define VFAT_FAT12_BAD 0x0FF7 // bad cluster mark
|
||||
#define VFAT_FAT16_BAD 0xFFF7
|
||||
#define VFAT_FAT32_BAD 0x0FFFFFF7
|
||||
|
||||
#define VFAT_DIRENTRY_FREE 0xE5
|
||||
#define VFAT_DIRENTRY_FREE_LAST 0x00
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte jmpBoot[3]; // {0xEB, 0x??, 0x90} or {0xE9, 0x??, 0x??}
|
||||
char OEMName[8]; // any 8-char string (def. "MSWIN4.1")
|
||||
word bytesPerSector; // 512 (default), 1024, 2048, 4096
|
||||
byte sectorsPerCluster; // 1 (default), 2, 4, 8, 16, 32, 64, 128
|
||||
word reservedSectors; // 1 (fat12/16), 32 (fat32)
|
||||
byte numFATs; // 2
|
||||
word rootEntries; // number of 32-byte root directory entries (224 for 1440k floppy) - 0 for fat32
|
||||
word totalSectors16; // total number of sectors in volume (2880 for floppy) - 0 for fat32
|
||||
byte media; // >= 0xF0 valid, 0xF8 (default non-removable), 0xF0 (default removable), must match lsb of FAT[0]
|
||||
word sectorsPerFAT16; // number of sectors in FAT (9 for floppy)
|
||||
word sectorsPerTrack; // (18 for floppy)
|
||||
word numHeads; // number of heads (2 for floppy)
|
||||
dword hiddenSectors; // 0
|
||||
dword totalSectors32; // 0, non-zero for fat32 volumes
|
||||
|
||||
/* FAT32 specific members */
|
||||
dword sectorsPerFAT32; // number of sectors in a fat for fat32 volumes
|
||||
word extFlags; // bits 0-3 active fat, bit 7 {0 = mirror all FATs, 1 = only use 1 FAT}
|
||||
word fsVersion; // fat32 version (0:0)
|
||||
dword rootCluster; // first cluster of root directory (default 2)
|
||||
word fsInfo; // sector number of FSINFO block (default 1)
|
||||
word bootCopy; // sector of backup boot record (default 6)
|
||||
} __attribute__ ((packed)) vfat_bpb;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
dword leadSignature; // 0x41615252
|
||||
byte reserved1[480];
|
||||
dword structSignature; // 0x61417272
|
||||
dword lastFree; // last known free cluster (0xFFFFFFFF == unknown)
|
||||
dword nextFree; // start looking for free clusters here (0xFFFFFFFF == unknown)
|
||||
byte reserved2[12];
|
||||
dword trailSignature; // 0xAA550000
|
||||
} __attribute__ ((packed)) vfat_fsinfo;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char fileName[8]; // file name, 8 char. max, pad w/ spaces
|
||||
char fileExt[3]; // file extension, 3 char. max, pad w/ spaces
|
||||
byte attributes; // file attributes, read-only, etc.
|
||||
byte reserved; // 0
|
||||
byte timeTenths; // 0-199
|
||||
word time; // time of creation
|
||||
word date; // date of creation
|
||||
word adate; // last accessed date
|
||||
word clusterHigh; // 0 for fat12/16
|
||||
word wtime; // last write time
|
||||
word wdate; // last write date
|
||||
word clusterLow; // LSW of first cluster of file data
|
||||
dword fileSize;
|
||||
} __attribute__ ((packed)) vfat_dirEntry;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
byte order;
|
||||
word name0_4[5]; // filename - first 5 characters (unicode)
|
||||
byte attributes; // must be VFAT_LONG_NAME
|
||||
byte type; // 0 = part of long name
|
||||
byte checksum; // checksum of short entry at end of long entry set
|
||||
word name5_10[6]; // filename - next 6 characters (unicode)
|
||||
word clusterLow; // 0
|
||||
word name11_12[2]; // filename - next 2 characters
|
||||
} __attribute__ ((packed)) vfat_lfnEntry;
|
||||
|
||||
#define VFAT_READ_ONLY 0x01
|
||||
#define VFAT_HIDDEN 0x02
|
||||
#define VFAT_SYSTEM 0x04
|
||||
#define VFAT_VOLUME 0x08
|
||||
#define VFAT_DIRECTORY 0x10
|
||||
#define VFAT_ARCHIVE 0x20
|
||||
|
||||
#define VFAT_LONG_NAME 0x0F // VFAT_READ_ONLY | VFAT_HIDDEN | VFAT_SYSTEM | VFAT_VOLUME
|
||||
#define VFAT_ATTR_MASK 0x3F // VFAT_READ_ONLY | VFAT_HIDDEN | VFAT_SYSTEM | VFAT_VOLUME | VFAT_DIRECTORY | VFAT_ARCHIVE
|
||||
|
||||
#define VFAT_ORDER_MASK 0x40
|
||||
|
||||
/*
|
||||
* Illegal file name characters:
|
||||
* Values less than 0x20 except for 0x05. 0x05 signifies that the actual filename character is 0xE5
|
||||
* 0x22 ("), 0x2A (*)
|
||||
* 0x2E (.), 0x2F (/), 0x3A (:)
|
||||
* 0x3C (<), 0x3E (>), 0x3F (?), 0x5C (\), 0x7C (|)
|
||||
* The following are illegal in 8.3 but legal in LFN:
|
||||
* 0x2B (+), 0x2C (,), 0x3B (;), 0x3D (=), 0x5B ([), 0x5D (])
|
||||
*/
|
||||
|
||||
//From Microsoft's FAT32 File System Specification
|
||||
typedef struct
|
||||
{
|
||||
dword diskSize;
|
||||
byte sectorsPerCluster;
|
||||
} DSKSZTOSECPERCLUS;
|
||||
|
||||
// sector[510] == 0x55
|
||||
// sector[511] == 0xAA
|
||||
|
||||
int vfat_identify(vfat_bpb *bpb);
|
||||
int vfat_format(Volume *vol);
|
||||
FILE *vfat_open(char *fileName, dword attributes, Volume *vol);
|
||||
vfat_bpb *vfat_getBootSector(Volume *vol);
|
||||
int vfat_close(FILE *fp);
|
||||
byte *vfat_loadFAT(Volume *vol, vfat_bpb *bpb)
|
||||
vfat_getEntryInRoot(vol, bpb, fileName, 0);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
// 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;
|
||||
@@ -39,4 +43,73 @@ Volume *vfs_getLastVolume()
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+31
-5
@@ -1,25 +1,51 @@
|
||||
// vfs.h
|
||||
// Author: Josh Holtrop
|
||||
// Date: 03/11/04
|
||||
// Modified: 03/16/04
|
||||
|
||||
#ifndef __HOS_VFS__
|
||||
#define __HOS_VFS__ __HOS_VFS__
|
||||
|
||||
#include "hos_defines.h"
|
||||
|
||||
#define VFS_LABEL_LENGTH 8
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *diskDevice;
|
||||
int deviceType;
|
||||
char label[12];
|
||||
void *link;
|
||||
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;
|
||||
|
||||
enum VFS_DISK_TYPES {VFS_RD, VFS_FD, VFS_HD, VFS_NUM_DISK_TYPES};
|
||||
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;
|
||||
|
||||
#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);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user