X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Modules%2FFDD%2Ffdd.c;h=69d3a5592c1f8f68ce5c74de128a4665665625fa;hb=ef8e2023c5ccda376398348600a5a5364fe2841b;hp=c33b2818456197a834608f9d94ce08c554b4798c;hpb=75e87cf46a3899f76bae5c64e130cfc033562e9a;p=tpg%2Facess2.git diff --git a/Modules/FDD/fdd.c b/Modules/FDD/fdd.c index c33b2818..69d3a559 100644 --- a/Modules/FDD/fdd.c +++ b/Modules/FDD/fdd.c @@ -3,10 +3,10 @@ * Floppy Disk Access Code */ #define DEBUG 0 -#include +#include #include #include -#include +#include #include #include @@ -17,7 +17,7 @@ #define FDD_VERSION ((0<<8)|(75)) // --- Options -#define USE_CACHE 1 // Use Sector Cache +#define USE_CACHE 0 // Use Sector Cache #define CACHE_SIZE 32 // Number of cachable sectors #define FDD_SEEK_TIMEOUT 10 // Timeout for a seek operation #define MOTOR_ON_DELAY 500 // Miliseconds @@ -33,6 +33,9 @@ typedef struct { int track[2]; int timer; tVFS_Node Node; + #if !USE_CACHE + tIOCache *CacheHandle; + #endif } t_floppyDevice; /** @@ -83,6 +86,8 @@ char *FDD_ReadDir(tVFS_Node *Node, int pos); tVFS_Node *FDD_FindDir(tVFS_Node *dirNode, char *Name); int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data); Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer); +// --- 1st Level Disk Access +Uint FDD_ReadSectors(Uint64 SectorAddr, Uint Count, void *Buffer, Uint Disk); // --- Raw Disk Access int FDD_ReadSector(Uint32 disk, Uint64 lba, void *Buffer); int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer); @@ -146,7 +151,7 @@ int FDD_Install(char **Arguments) gFDD_Devices[0].track[0] = -1; gFDD_Devices[1].track[1] = -1; - Log("[FDD ] Detected Disk 0: %s and Disk 1: %s\n", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]); + Log("[FDD ] Detected Disk 0: %s and Disk 1: %s", cFDD_TYPES[data>>4], cFDD_TYPES[data&0xF]); // Clear FDD IRQ Flag FDD_SensInt(0x3F0, NULL, NULL); @@ -195,7 +200,7 @@ int FDD_Install(char **Arguments) // Register with devfs DevFS_AddDevice(&gFDD_DriverInfo); - return 0; + return 1; } /** @@ -225,26 +230,26 @@ char *FDD_ReadDir(tVFS_Node *Node, int pos) * \fn tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *filename); * \brief Find File Routine (for vfs_node) */ -tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *filename) +tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *Filename) { int i; - ENTER("sfilename", filename); + ENTER("sFilename", Filename); // Sanity check string - if(filename == NULL) { + if(Filename == NULL) { LEAVE('n'); return NULL; } // Check string length (should be 1) - if(filename[0] == '\0' || filename[1] != '\0') { + if(Filename[0] == '\0' || Filename[1] != '\0') { LEAVE('n'); return NULL; } // Get First character - i = filename[0] - '0'; + i = Filename[0] - '0'; // Check for 1st disk and if it is present return if(i == 0 && gFDD_Devices[0].type != 0) { @@ -263,103 +268,153 @@ tVFS_Node *FDD_FindDir(tVFS_Node *Node, char *filename) return NULL; } +static const char *casIOCTLS[] = {DRV_IOCTLNAMES,DRV_DISK_IOCTLNAMES,NULL}; /** - * \fn int FDD_IOCtl(tVFS_Node *node, int id, void *data) + * \fn int FDD_IOCtl(tVFS_Node *Node, int id, void *data) * \brief Stub ioctl function */ -int FDD_IOCtl(tVFS_Node *node, int id, void *data) +int FDD_IOCtl(tVFS_Node *Node, int ID, void *Data) { - switch(id) + switch(ID) { - case DRV_IOCTL_TYPE: return DRV_TYPE_DISK; - case DRV_IOCTL_IDENT: memcpy(data, "FDD\0", 4); return 1; - case DRV_IOCTL_VERSION: return FDD_VERSION; - default: return 0; + case DRV_IOCTL_TYPE: + return DRV_TYPE_DISK; + + case DRV_IOCTL_IDENT: + if(!CheckMem(Data, 4)) return -1; + memcpy(Data, "FDD\0", 4); + return 1; + + case DRV_IOCTL_VERSION: + return FDD_VERSION; + + case DRV_IOCTL_LOOKUP: + if(!CheckString(Data)) return -1; + return LookupString((char**)casIOCTLS, Data); + + case DISK_IOCTL_GETBLOCKSIZE: + return 512; + + default: + return 0; } } /** - * \fn Uint64 fdd_readFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) + * \fn Uint64 FDD_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) * \brief Read Data from a disk */ -Uint64 FDD_ReadFS(tVFS_Node *node, Uint64 off, Uint64 len, void *buffer) +Uint64 FDD_ReadFS(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Buffer) { - int i = 0; - int disk; - Uint32 buf[128]; + int i = 0; + int disk; + //Uint32 buf[128]; - ENTER("xoff xlen pbuffer", off, len, buffer); + ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer); - if(node == NULL) { + if(Node == NULL) { LEAVE('i', -1); return -1; } - if(node->Inode != 0 && node->Inode != 1) { + if(Node->Inode != 0 && Node->Inode != 1) { LEAVE('i', -1); return -1; } - disk = node->Inode; + disk = Node->Inode; // Update Accessed Time - node->ATime = now(); + Node->ATime = now(); - if((off & 0x1FF) || (len & 0x1FF)) + #if 0 + if((Offset & 0x1FF) || (Length & 0x1FF)) { // Un-Aligned Offset/Length - int startOff = off>>9; - int sectOff = off&0x1FF; - int sectors = (len+0x1FF)>>9; + int startOff = Offset >> 9; + int sectOff = Offset & 0x1FF; + int sectors = (Length + 0x1FF) >> 9; LOG("Non-aligned Read"); //Read Starting Sector if(!FDD_ReadSector(disk, startOff, buf)) return 0; - memcpy(buffer, (char*)(buf+sectOff), len>512-sectOff?512-sectOff:len); + memcpy(Buffer, (char*)(buf+sectOff), Length > 512-sectOff ? 512-sectOff : Length); - //If the data size is one sector or less - if(len <= 512-sectOff) { - LEAVE('X', len); - return len; //Return + // If the data size is one sector or less + if(Length <= 512-sectOff) + { + LEAVE('X', Length); + return Length; //Return } - buffer += 512-sectOff; + Buffer += 512-sectOff; //Read Middle Sectors - for(i=1;i> 9; - int sector = off >> 9; + int count = Length >> 9; + int sector = Offset >> 9; LOG("Aligned Read"); //Aligned Offset and Length - Simple Code - for(i=0;i>1]; LOG("Calculating Disk Dimensions"); - //Get CHS position + // Get CHS position if(FDD_int_GetDims(gFDD_Devices[Disk].type, lba, &cyl, &head, &sec, &spt) != 1) { LEAVE('i', -1); return -1; @@ -497,6 +552,17 @@ int FDD_ReadSector(Uint32 Disk, Uint64 SectorAddr, void *Buffer) return 1; } +/** + * \fn int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer) + * \brief Write a sector to the floppy disk + * \note Not Implemented + */ +int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer) +{ + Warning("[FDD ] Read Only at the moment"); + return -1; +} + /** * \fn int FDD_int_SeekTrack(int disk, int track) * \brief Seek disk to selected track @@ -569,6 +635,7 @@ int FDD_int_GetDims(int type, int lba, int *c, int *h, int *s, int *spt) *s = (lba % 18) + 1; *c = lba / 36; *h = (lba / 18) & 1; + //Log("1440k - lba=%i(0x%x), *s=%i,*c=%i,*h=%i", lba, lba, *s, *c, *h); break; // 2880Kb 3.5"