CTAOS v6
This commit is contained in:
34
SysCore/drivers/filesys/fat.c
Normal file
34
SysCore/drivers/filesys/fat.c
Normal file
@@ -0,0 +1,34 @@
|
||||
#include "../floppy/floppy.h"
|
||||
//#include "vfs.h"
|
||||
#include "fat.h"
|
||||
|
||||
#include <conio.h>
|
||||
|
||||
// Detect what FAT is used
|
||||
unsigned FATDetect(unsigned TotalClusters)
|
||||
{
|
||||
if (TotalClusters == 0) return 0;
|
||||
if (TotalClusters < 4085) return 12;
|
||||
if (TotalClusters < 65525) return 16;
|
||||
return 32;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*FatMountInfo FloppyMount(int drive)
|
||||
{
|
||||
FatMountInfo a;
|
||||
FATBootSectorPointer fat = (FATBootSectorPointer)0x7e00;
|
||||
FloppyReadSector((unsigned*)fat, drive, 0);
|
||||
|
||||
// Write mount info
|
||||
a.FATEntrySize = 8;
|
||||
a.FATOffset = 1;
|
||||
a.FATSize = (unsigned)fat->SectorsPerFAT;
|
||||
a.NumberOfRootEntries = (unsigned)fat->NumberOfDirectoryEntries;
|
||||
a.NumberOfSectors = (unsigned)(fat->NumberOfSectors == 0) ? (fat->NumberOfSectorsLong) : (fat->NumberOfSectors);
|
||||
a.RootOffset = (unsigned)(fat->NumberOfFATs)*a.FATSize + 1;
|
||||
a.RootSize = (a.NumberOfRootEntries * 32) / (unsigned)fat->BytesPerSector;
|
||||
|
||||
return a;
|
||||
}*/
|
91
SysCore/drivers/filesys/fat.h
Normal file
91
SysCore/drivers/filesys/fat.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#ifndef __FAT_H__
|
||||
#define __FAT_H__
|
||||
|
||||
typedef struct {
|
||||
unsigned char Drive; //useless
|
||||
unsigned char FlagsNT;
|
||||
unsigned char Signature; // 0x28 or 0x29
|
||||
unsigned SerialNumber;
|
||||
char VolumeLabel[11];
|
||||
char SysIDString[8]; // unreliable
|
||||
} __attribute__((packed)) BPB_EXT_16;
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned SectorsPerFAT;
|
||||
unsigned short Flags;
|
||||
unsigned short Version;
|
||||
unsigned ClusterOfRootDirectory;
|
||||
unsigned short ClusterOfFSInfo;
|
||||
unsigned short ClusterOfBackupBootSector;
|
||||
unsigned char Reserved[12]; // Should be 0 at format
|
||||
unsigned char Drive;
|
||||
unsigned char FlagsNT;
|
||||
unsigned char Signature; // 0x28 or 0x29
|
||||
unsigned SerialNumber;
|
||||
char VolumeLabel[11];
|
||||
char SysIDString[8]; // always FAT12
|
||||
|
||||
} __attribute__((packed)) BPB_EXT_32;
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned char _ignore[3];
|
||||
|
||||
// Bios Parameter Block
|
||||
char OEMIdentify[8];
|
||||
unsigned short BytesPerSector;
|
||||
unsigned char SectorsPerCluster;
|
||||
unsigned short ReservedSectors;
|
||||
unsigned char NumberOfFATs;
|
||||
unsigned short NumberOfDirectoryEntries;
|
||||
unsigned short NumberOfSectors;
|
||||
unsigned char MediaDescriptorType;
|
||||
unsigned short SectorsPerFAT;
|
||||
unsigned short SectorsPerTrack;
|
||||
unsigned short HeadsPerCylinder;
|
||||
unsigned HiddenSectors;
|
||||
unsigned NumberOfSectorsLong;
|
||||
|
||||
union {
|
||||
BPB_EXT_16 Ext16;
|
||||
BPB_EXT_32 Ext32;
|
||||
} Extended;
|
||||
|
||||
} __attribute__((packed)) FATBootSector, *FATBootSectorPointer;
|
||||
|
||||
|
||||
typedef struct {
|
||||
unsigned NumberOfSectors;
|
||||
unsigned SizeOfSector;
|
||||
unsigned FatOffset;
|
||||
unsigned NumberOfRootEntries;
|
||||
unsigned RootOffset;
|
||||
unsigned SizeOfRoot;
|
||||
unsigned SizeOfFat;
|
||||
unsigned SizeOfFatEntry;
|
||||
unsigned SizeOfCluster;
|
||||
void (*ReadSector) (void* buffer, int lba);
|
||||
} FatMountInfo, *FatMountInfoPointer;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char FileName[8];
|
||||
char Extension[3];
|
||||
unsigned char Atributes;
|
||||
unsigned char Reserved;
|
||||
unsigned char CreateTimeFine;
|
||||
unsigned short CreateTime;
|
||||
unsigned short CreateDate;
|
||||
unsigned short LastAccessedDate;
|
||||
unsigned short EAIndex;
|
||||
unsigned short LastModifiedTime;
|
||||
unsigned short LastModifiedDate;
|
||||
unsigned short FirstCluster;
|
||||
unsigned FileSize;
|
||||
} __attribute__((packed)) FatDirectoryEntry, *FatDirectoryEntryPointer;
|
||||
|
||||
|
||||
extern FatMountInfo FloppyMount(int drive);
|
||||
|
||||
#endif
|
98
SysCore/drivers/filesys/vfs.c
Normal file
98
SysCore/drivers/filesys/vfs.c
Normal file
@@ -0,0 +1,98 @@
|
||||
#include "vfs.h"
|
||||
#define MaxDevices 256
|
||||
|
||||
#define ReturnInvalid() { File ret; ret.Type = FileTypeInvalid; return ret;}
|
||||
|
||||
unsigned CurrentDevice = 0;
|
||||
unsigned DeviceCount = 0;
|
||||
|
||||
FileSystemPointer _FileSystems[MaxDevices];
|
||||
|
||||
File VFSOpenFile (const char* FileName)
|
||||
{
|
||||
unsigned Device = CurrentDevice;
|
||||
|
||||
// No filename specified.
|
||||
if (!FileName) ReturnInvalid();
|
||||
|
||||
// File length
|
||||
int len = strlen(FileName);
|
||||
// File name without drive
|
||||
char* Name = 0;
|
||||
|
||||
// Check if relative or absolute path
|
||||
int i;
|
||||
for (i=0; i < len; i++)
|
||||
if (FileName[i] == ':') {
|
||||
Name = &FileName[i+1];
|
||||
FileName[i] = 0;
|
||||
len = i;
|
||||
}
|
||||
|
||||
// If absolute path, find device
|
||||
if (Name != 0) {
|
||||
for (i=0; i < MaxDevices; i++)
|
||||
if (_FileSystems[i]) {
|
||||
if (strcmp(_FileSystems[i]->Name, FileName) == 0) Device = i;
|
||||
}
|
||||
}
|
||||
// Drive is nonexistant or current drive not mounted
|
||||
if (i==MaxDevices || !_FileSystems[Device]) ReturnInvalid();
|
||||
|
||||
// Open file
|
||||
return _FileSystems[Device]->Open((Name) ? Name : FileName);
|
||||
}
|
||||
|
||||
|
||||
int VFSInstallFileSystem(FileSystemPointer fs)
|
||||
{
|
||||
// Sanity check
|
||||
if (!fs) return 0;
|
||||
|
||||
// Verify device does not exist
|
||||
int i;
|
||||
for (i=0; i < DeviceCount; i++)
|
||||
if (_FileSystems[i])
|
||||
if (strcmp (fs->Name, _FileSystems[i]->Name) == 0) return 0;
|
||||
|
||||
_FileSystems[DeviceCount] = fs; DeviceCount++;
|
||||
}
|
||||
|
||||
void VFSUninstallFileSystem(FileSystemPointer fs)
|
||||
{
|
||||
if (!fs) return;
|
||||
|
||||
int i;
|
||||
for (i=0; i<DeviceCount; i++)
|
||||
if (_FileSystems[i] == fs) {
|
||||
_FileSystems[i] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void VFSUninstallFileSystemByName(const char* fs)
|
||||
{
|
||||
if (!fs) return;
|
||||
|
||||
int i;
|
||||
for (i=0; i<DeviceCount; i++)
|
||||
if (_FileSystems[i])
|
||||
if (strcmp(_FileSystems[i]->Name, fs) == 0){
|
||||
_FileSystems[i] = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void VFSReadFile (FilePointer f, unsigned char* buffer, unsigned len)
|
||||
{
|
||||
if (!f || !_FileSystems[f->Device]) return;
|
||||
_FileSystems[f->Device]->Read (f, buffer, len);
|
||||
}
|
||||
|
||||
void VFSCloseFile (FilePointer f)
|
||||
{
|
||||
if (!f || !_FileSystems[f->Device]) return;
|
||||
_FileSystems[f->Device]->Close(f);
|
||||
}
|
||||
|
57
SysCore/drivers/filesys/vfs.h
Normal file
57
SysCore/drivers/filesys/vfs.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/***** vfs.h *********************************************************
|
||||
* (c) 2010 CTA Systems Inc. All rights reserved. Glory To God *
|
||||
* *
|
||||
* Virtual File System (VFS) Implementation *
|
||||
* ======================================== *
|
||||
* *
|
||||
************************************************************ cta os */
|
||||
#ifndef __VFS__H___
|
||||
#define __VFS__H___
|
||||
|
||||
#include <time.h>
|
||||
|
||||
typedef enum {
|
||||
FileTypeInvalid,
|
||||
FileTypeFile,
|
||||
FileTypeDirectory,
|
||||
FileTypeSymbolicLink
|
||||
} FileType;
|
||||
|
||||
enum FileFlags {
|
||||
FileFlagReadOnly = 0x1,
|
||||
FileFlagHidden = 0x2,
|
||||
FileFlagSystem = 0x4,
|
||||
FileFlagVolumeID = 0x8,
|
||||
FileFlagDirectory = 0x10,
|
||||
FileFlagArchive = 0x20
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
char Name[256];
|
||||
FileType Type;
|
||||
unsigned Flags;
|
||||
unsigned Length;
|
||||
unsigned EndOfFile;
|
||||
unsigned ID;
|
||||
unsigned Position, CurrentCluster;
|
||||
unsigned Device;
|
||||
TIME Created;
|
||||
DATE LastAccessed;
|
||||
TIME LastModified;
|
||||
} File, *FilePointer;
|
||||
|
||||
|
||||
typedef struct {
|
||||
char Name[256];
|
||||
|
||||
File (*Directory) (const char* DirectoryName);
|
||||
void (*Mount) ();
|
||||
void (*Read) (FilePointer, unsigned char*, unsigned);
|
||||
void (*Close) (FilePointer);
|
||||
FILE (*Open) (const char*);
|
||||
|
||||
} FileSystem, *FileSystemPointer;
|
||||
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user