Import backup from 2004-07-09

This commit is contained in:
josh committed 2017-07-25 22:23:47 -04:00
1 parent f3fe4ef3b8
commit 0729754659
76 files changed
+470 -7676

No files matched your search

-28
View File
@@ -1,28 +0,0 @@
// Mount.cpp
// Author: Josh Holtrop
// Date: 06/16/04
// Modified: 06/16/04
#include "lang/string.h"
#include "Mount.h"
Mount::Mount()
{
}
Mount::Mount(string dev, string mount)
{
mountPoint = mount;
device = dev;
}
bool Mount::operator==(const Mount & second) const
{
/* Match *either* device or mountPoint to signal an invalid mount attempt */
return (device == second.device || mountPoint == second.mountPoint);
}
-28
View File
@@ -1,28 +0,0 @@
// Mount.h
// Author: Josh Holtrop
// Date: 06/16/04
// Modified: 06/16/04
#ifndef __HOS_MOUNT__
#define __HOS_MOUNT__ __HOS_MOUNT__
#include "hos_defines.h"
class Mount
{
public:
string mountPoint;
string device;
dword major;
dword minor;
Mount();
Mount(string dev, string mount);
bool operator==(const Mount & second) const;
};
#endif
-25
View File
@@ -1,25 +0,0 @@
// devfs.cpp
// device filesystem for HOS
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/16/04
#include "devfs.h"
#include "kio.h"
#include "lang/string.h"
#include "vfs.h"
void devfs_init(string mountPoint)
{
vfs_mount("devfs ", mountPoint);
vfs_mount("testdev ", "/mnt/win");
vfs_mount("/dev/hda6", "/scratch");
vfs_mount("/dev/rd0 ", "/");
vfs_mount("/dev/sda1", "/mnt/usb");
vfs_mount("sysfs ", "/sys");
vfs_mount("sysfs ", "/tmp");
vfs_mount("otherfs ", "/sys");
}
-17
View File
@@ -1,17 +0,0 @@
// devfs.h
// device filesystem for HOS
// Author: Josh Holtrop
// Date: 06/03/04
// Modified: 06/08/04
#ifndef __HOS_DEVFS__
#define __HOS_DEVFS__ __HOS_DEVFS__
#include "lang/string.h"
void devfs_init(string mountPoint);
#endif
-113
View File
@@ -1,113 +0,0 @@
// 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 "lang/cstring.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);
}
-134
View File
@@ -1,134 +0,0 @@
// 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)
#endif
-55
View File
@@ -1,55 +0,0 @@
// vfs.cpp
// Author: Josh Holtrop
// Date: 03/11/04
// Modified: 04/16/04
#include "hos_defines.h"
#include "vfs.h"
//#include "fs/vfat.h"
//#include "block/rd.h"
//#include "block/loop.h"
#include "lang/LinkedList.h"
#include "lang/string.h"
#include "devfs.h"
#include "kio.h"
#include "Mount.h"
LinkedList<Mount> *mounts;
void vfs_init()
{
mounts = new LinkedList<Mount>;
}
void list()
{
LinkedList<Mount>::iterator it = mounts->begin();
while (it != mounts->end())
{
printf("%s\t%s\n", (*it).device.data(), (*it).mountPoint.data());
++it;
}
}
int vfs_mount(string device, string mountPoint)
{
Mount mount(device, mountPoint);
LinkedList<Mount>::iterator it = mounts->begin();
int i = 0;
while (it != mounts->end() && (*it).mountPoint <= mount.mountPoint)
{
if (*it == mount)
return 1; //device already mounted or mount point already taken
i++;
++it;
}
mounts->insert(i, mount);
return 0;
}
-19
View File
@@ -1,19 +0,0 @@
// vfs.h
// Author: Josh Holtrop
// Date: 03/11/04
// Modified: 06/16/04
#ifndef __HOS_VFS__
#define __HOS_VFS__ __HOS_VFS__
#include "hos_defines.h"
#include "lang/string.h"
void vfs_init();
int vfs_mount(string device, string mountPoint);
void list();
#endif