Commit 6f9ea986 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Add some comments (!) and reindent FileSwitch interface

OpsGetPut
  DOSFS_put_bytes no longer passes an unnecessary dummy argument.
  Reindented.
  Doxygen comments added to FileSwitch layer.
OpsFind
  Suggested buffer to FileSwitch is now 1x512 sector (rather than 256).
  Note - nothing seems to use the cluster buffering code in DOSFS,
indeed nothing ever malloc()s a buffer.
  Check at line 237 of OpFind would never be true since FILE_subdir is
not 1, fixed.
  Return an error if the handle to close is invalid.
  Reindented.
  Doxygen comments added to FileSwitch layer.
OpsFile
  Reindented.
  Doxygen comments added to FileSwitch layer.
OpsFunc
  A failure to find a slot to set the disc title now reports "Dir full"
not "Disc full"
  Reindented.
  Doxygen comments added to FileSwitch layer.

Version 0.99. Tagged as 'DOSFS-0_99'
parent 41c45883
......@@ -26,10 +26,11 @@ CMHGDEPENDS = DOSFS MsgTrans
ASMHDRS = DOSFS
HDRS =
CINCLUDES = -IC:
LIBS += ${ASMUTILS}
LIBS = ${ASMUTILS}
include CModule
DBG_LIBS += ${NET5LIBS}
ASFLAGS += -pd "PCMCIATRUE SETL {${PCMCIA}}"
CFLAGS += -DPCMCIA${PCMCIA}
CDFLAGS += -DPCMCIA${PCMCIA} -DDEBUGLIB
......
/* (0.98)
/* (0.99)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 0.98
#define Module_MajorVersion_CMHG 0.99
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 13 Jan 2013
#define Module_MajorVersion "0.98"
#define Module_Version 98
#define Module_MajorVersion "0.99"
#define Module_Version 99
#define Module_MinorVersion ""
#define Module_Date "13 Jan 2013"
......@@ -18,6 +18,6 @@
#define Module_ComponentName "DOSFS"
#define Module_ComponentPath "castle/RiscOS/Sources/FileSys/ImageFS/DOSFS"
#define Module_FullVersion "0.98"
#define Module_HelpVersion "0.98 (13 Jan 2013)"
#define Module_LibraryVersionInfo "0:98"
#define Module_FullVersion "0.99"
#define Module_HelpVersion "0.99 (13 Jan 2013)"
#define Module_LibraryVersionInfo "0:99"
......@@ -26,7 +26,11 @@
#include "swis.h"
#include "DebugLib/DebugLib.h"
#include "AsmUtils/rminfo.h"
#include "Global/CMOS.h"
#include "Global/OsBytes.h"
#include "Global/Keyboard.h"
#include "Interface/HighFSI.h"
#include "Global/Variables.h"
#undef DOSFS_DiscFormat
#undef DOSFS_LayoutStructure
......@@ -56,9 +60,7 @@
FILEhand *FILE_list = NULL ; /* Open file handle list */
mapentry *maplist = NULL ; /* DOS/RISC OS filetype mapping chain */
int discopswi = FileCore_DiscOp; /* Choice of whether we attempt a DiscOp64 or just DiscOp */
#if 1 /* SMC_TRUNCATE */
int module_flags = 0 ; /* Global flags */
#endif
/* The following are used for parameter returns to the RISC OS world. They
* are provided as static structures to ensure they are not de-allocated
......@@ -85,16 +87,11 @@ FS_free_space fspace ;
static _kernel_oserror *declare_FS(void *privateword)
{
_kernel_swi_regs rset ;
#if 1 /* SMC_TRUNCATE */
_kernel_oserror *err;
#endif
word infoblock[9] ; /* nasty constant */
#if 1 /* SMC_TRUNCATE */
/* Read the CMOS RAM truncate bit state */
#define FileSwitchCMOS 0x1C
#define FileSwitchTruncateNamesCMOSBit 0x01
rset.r[0] = 161; /* Reason code "ReadCMOS" */
rset.r[0] = OsByte_ReadCMOS;
rset.r[1] = FileSwitchCMOS;
if ((err = _kernel_swi(OS_Byte, &rset, &rset)) != NULL)
return err;
......@@ -105,7 +102,6 @@ static _kernel_oserror *declare_FS(void *privateword)
dprintf(("","Long file names will generate an error.\n"));
module_flags &= ~TRUNCATE_NAMES;
}
#endif
/* register our module as an image filing system */
/* "OS_FSControl" reason 35 */
......@@ -119,7 +115,7 @@ static _kernel_oserror *declare_FS(void *privateword)
infoblock[7] = ((word)DOSFS_File - (word)Image_RO_Base) ;
infoblock[8] = ((word)DOSFS_Func - (word)Image_RO_Base) ;
rset.r[0] = 35 ; /* reason code "FSControl_AddImage" */
rset.r[0] = FSControl_RegisterImageFS;
rset.r[1] = (word)Image_RO_Base ;
rset.r[2] = ((word)infoblock - (word)Image_RO_Base) ;
rset.r[3] = (word)privateword ;
......@@ -1435,9 +1431,8 @@ _kernel_oserror *fs_commands(const char *argv,int argc,int command,void *private
/* Load the BOOT BLOCK from the source drive */
sprintf(tmpstr,"adfs::%d",srcdrive) ;
rset.r[0] = 0x40;
rset.r[0] = open_read | open_default;
rset.r[1] = (int)tmpstr;
rset.r[2] = 0;
rerror = _kernel_swi(OS_Find, &rset, &rset);
fhand = rset.r[0];
if (rerror != NULL || fhand == 0)
......@@ -1448,7 +1443,7 @@ _kernel_oserror *fs_commands(const char *argv,int argc,int command,void *private
else
{
/* read the BOOT BLOCK from the image */
rset.r[0] = 3;
rset.r[0] = OSGBPB_ReadFromGiven;
rset.r[1] = fhand;
rset.r[2] = (int)srcblock;
rset.r[3] = sizeof(DOS_bootsector);
......@@ -1500,15 +1495,15 @@ _kernel_oserror *fs_commands(const char *argv,int argc,int command,void *private
}
fwrite( buf, 1, bufsz, stdout );
/* We need to take account of ESCAPE here */
rset.r[0] = 122;
rset.r[0] = OsByte_ScanKeyboardFrom16;
do
{
{
rerror = _kernel_swi(OS_Byte,&rset,&rset) ;
} while ((rerror == NULL) && (rset.r[1] != 98) && (rset.r[1] != 112)) ;
} while ((rerror == NULL) && (rset.r[1] != KeyScan_Space) && (rset.r[1] != KeyScan_Escape)) ;
putchar( '\n' );
if (rerror != NULL)
rerror = global_error(err_keyboardread);
else if (rset.r[1] == 112) {
else if (rset.r[1] == KeyScan_Escape) {
dprintf(("","CMD_CopyBoot: Escape\n")) ;
_gerror.errnum = 17 ; /* NASTY CONSTANT */
buf = _gerror.errmess;
......@@ -1525,9 +1520,8 @@ _kernel_oserror *fs_commands(const char *argv,int argc,int command,void *private
{
/* Load the BOOT BLOCK from the destination drive */
sprintf(tmpstr,"adfs::%d",destdrive) ;
rset.r[0] = 0xC0;
rset.r[0] = open_write | open_read | open_default;
rset.r[1] = (int)tmpstr;
rset.r[2] = 0;
rerror = _kernel_swi(OS_Find, &rset, &rset);
fhand = rset.r[0];
if (rerror != NULL || fhand == 0)
......@@ -1538,7 +1532,7 @@ _kernel_oserror *fs_commands(const char *argv,int argc,int command,void *private
else
{
/* read the BOOT BLOCK from the image */
rset.r[0] = 3;
rset.r[0] = OSGBPB_ReadFromGiven;
rset.r[1] = fhand;
rset.r[2] = (int)destblock;
rset.r[3] = sizeof(DOS_bootsector);
......@@ -1565,7 +1559,7 @@ _kernel_oserror *fs_commands(const char *argv,int argc,int command,void *private
destblock->BOOT_extra.fat12.code[loop] = srcblock->BOOT_extra.fat12.code[loop] ;
/* Save the BOOT BLOCK back to the destination drive */
rset.r[0] = 1;
rset.r[0] = OSGBPB_WriteAtGiven;
rset.r[1] = fhand;
rset.r[2] = (int)destblock;
rset.r[3] = sizeof(DOS_bootsector);
......@@ -1618,8 +1612,8 @@ static void shutdown_fs(void)
free(cptr) ;
}
/* OS_FSControl 36 with image type */
rset.r[0] = 36 ; /* reason code "FSControl_RemoveImage" */
/* OS_FSControl with image type */
rset.r[0] = FSControl_DeRegisterImageFS;
rset.r[1] = (word)imagetype ; /* image type we provide support for */
/* ignore any errors */
......@@ -1661,7 +1655,7 @@ _kernel_oserror *init_fs(const char *cmd_tail,int podule_base,void *privateword)
r.r[1] = (int)"DOSDisc";
r.r[2] = 7;
r.r[3] = 0;
r.r[4] = 0;
r.r[4] = VarType_String;
/* Ignore error here, if setting the variable fails then "fc8" will be used. */
(void)_kernel_swi(OS_SetVarVal, &r, &r);
......@@ -1669,7 +1663,7 @@ _kernel_oserror *init_fs(const char *cmd_tail,int podule_base,void *privateword)
r.r[1] = (int)"DOS";
r.r[2] = 3;
r.r[3] = 0;
r.r[4] = 0;
r.r[4] = VarType_String;
/* Ignore error here, if setting the variable fails then "fc4" will be used. */
(void)_kernel_swi(OS_SetVarVal, &r, &r);
......
......@@ -21,6 +21,8 @@
#include <stdlib.h>
#include <string.h>
#include "kernel.h"
#include "swis.h"
#include "Interface/HighFSI.h"
#include "DebugLib/DebugLib.h"
#include "DOSFS.h"
......@@ -331,17 +333,123 @@ int ensure_FATs(DOSdisc *ihand)
return(0) ;
}
/*-------------------------------------------------------------------------*/
/* DOS_cluster_RW:
* load/save the specified (possibly partial) cluster to/from the given memory address
* returns n : next cluster
* returns 0 : no more clusters (cluster 0 never holds data)
* returns -1 : failed to load any data
* NB. len MUST always be <= the cluster size (in bytes)
/*!
* \param memaddr Source or destination of the data
* \param bytes Number of bytes
* \param foff File offset
* \param fhand Fileswitch handle
* \param op Reads, writes, or zeroes
* \brief Read or write a group of bytes to a file inside the image filing system
* \return 0 for success, -1 for failure
*/
int DOS_bytes_RW(int op, char *memaddr, word bytes, word foff, FILEhand *fhand)
{
int clustercount = 0;
DOSdisc *ihand = fhand->ihand;
int clustersize, nextcluster;
word size;
int zero = 0;
int result = 0;
dprintf(("","DOS_bytes_RW: op = %c, memaddr = &%08X, bytes = %d, foff = %d, fhand = &%08X\n", (op == Rdata ? 'R' : 'W'), (int)memaddr, bytes, foff, (int)fhand));
if (bytes == 0)
return 0;
if (op == Wzero) {
zero = 1;
op = Wdata;
}
/* Check if the request is outside the file. */
if (foff + bytes > fhand->filelen) {
if (op == Rdata) {
/* If reading then generate an error for an offset outside the file but just
* truncate the request if the requested number of bytes is too large.
*/
if (foff > fhand->filelen) {
return_error0(int, err_EOF);
} else
bytes = fhand->filelen - foff;
} else {
/* If writing then extend the file. */
if (DOSFS_ensure(fhand, foff + bytes) < (foff + bytes))
return -1;
}
}
/* Determine which cluster the operation is to start in (on exit foff will contain
* the offset within that cluster).
*/
if ((nextcluster = clusterfromoffset(fhand->startCLUSTER, &foff, ihand)) < 0)
return -1;
/* If the operation is to write zeros then allocate a suitable block of memory and zero it. */
clustersize = secsalloc(ihand) * DOSsecsize;
if (zero) {
size = (bytes < clustersize ? bytes : clustersize);
if ((memaddr = (char *)calloc(size, 1)) == NULL)
return_errorT(int, err_heapexhausted, tok_heapexhausted, 0, 0);
}
while (bytes > 0) {
if (nextcluster >= CLUSTER_end(ihand))
{
global_error0(err_EOF);
result = -1;
break;
}
dprintf(("","DOS_bytes_RW: cluster offset = %d, bytes left = %d\n",foff,bytes));
int DOS_cluster_RW(int op,int cluster,int coff,char *memaddr,int len,DOSdisc *ihand)
/* Terminate loops in bad FAT. */
if ( (++clustercount > ihand->disc_FATentries) || (nextcluster < CLUSTER_first(ihand)) )
{
global_error0(err_clusterchain);
result = -1;
break;
}
if (bytes > clustersize-foff) {
/* Try to read/write as much as possible straight to/from memory using a cluster multiple op. */
size = (zero ? clustersize-foff : bytes);
dprintf(("","DOS_bytes_RW: trying %d bytes starting at cluster %d\n",size,nextcluster));
if ((nextcluster = DOS_multiple_RW(op, nextcluster, foff, memaddr, size, &size, ihand)) < 0)
{
result = -1;
break;
}
} else {
/* Do the last partial cluster. */
size = bytes;
dprintf(("","DOS_bytes_RW: transferring %d bytes in cluster %d\n",size,nextcluster));
if ((nextcluster = DOS_cluster_RW(op, nextcluster, foff, memaddr, size, ihand)) < 0)
{
result = -1;
break;
}
}
foff = 0; /* if we go round again then must have stopped at cluster boundary */
if (!zero)
memaddr += size;
bytes -= size;
}
if (zero) free(memaddr);
return result;
}
/*!
* \param memaddr Source or destination of the data
* \param len Number of bytes
* \param coff Cluster offset
* \param cluster Cluster number to start from
* \param op Reads, writes, or zeroes
* \brief Load/save the specified (possibly partial) cluster to/from the given memory address
* \return 0 if no more clusters, n next cluster number, or -1 if error
*/
int DOS_cluster_RW(int op, int cluster, int coff, char *memaddr, word len, DOSdisc *ihand)
{
int nextcluster = -1 ;
int startsector = CLUSTERtoSECTOR(cluster,ihand) ;
......@@ -350,26 +458,32 @@ int DOS_cluster_RW(int op,int cluster,int coff,char *memaddr,int len,DOSdisc *ih
dprintf(("","DOS_cluster_RW: startsector = %x\n",startsector));
dprintf(("","DOS_cluster_RW: sector = %x\n",startsector+(coff>>log2DOSsecsize)));
if (DOS_image_RW(op,startsector+(coff>>log2DOSsecsize),coff&(DOSsecsize-1),(byte *)memaddr,len,ihand) < 0)
return(-1) ;
/* NB. len MUST always be <= the cluster size (in bytes) */
if (DOS_image_RW(op, startsector + (coff>>log2DOSsecsize), coff & (DOSsecsize - 1), (byte *)memaddr, len, ihand) < 0)
{
return(-1) ;
}
nextcluster = getnextCLUSTER(cluster,ihand) ;
if ( (nextcluster >= CLUSTER_end(ihand)) || (nextcluster < CLUSTER_first(ihand)) )
return(0) ;
return(nextcluster) ;
if ((nextcluster >= CLUSTER_end(ihand)) || (nextcluster < CLUSTER_first(ihand)))
{
return (0) ;
}
return (nextcluster) ;
}
/*---------------------------------------------------------------------------*/
/* DOS_multiple_RW:
* load/save as many consecutive CLUSTERs as possible, starting at the specified
* cluster, to/from the given memory address.
* returns n : next cluster
* returns 0 : no more clusters (cluster 0 never holds data)
* returns -1 : failed to load all the data
/*!
* \param ihand Image handle
* \param memaddr Source or destination of the data
* \param ta Variable to accept number of bytes actually transferred
* \param limit Number of bytes in buffer 'ma'
* \param coff Cluster offset
* \param cluster Cluster number to start from
* \param op Reads, writes, or zeroes
* \brief Load/save as many consecutive CLUSTERs as possible, starting at the specified
* cluster, to/from the given memory address.
* \return 0 if no more clusters, n next cluster number, or -1 if error
*/
int DOS_multiple_RW(int op,int cluster,int coff,char *ma,int limit,word *ta,DOSdisc *ihand)
int DOS_multiple_RW(int op, int cluster, int coff, char *memaddr, word limit, word *ta, DOSdisc *ihand)
{
int count = 0;
int nextcluster = cluster ;
......@@ -408,7 +522,7 @@ int DOS_multiple_RW(int op,int cluster,int coff,char *ma,int limit,word *ta,DOSd
*ta = limit;
*ta-=coff;
dprintf(("","DOS_multiple_RW: ss:%x sec:%x offset:%x\n",startsector+(coff>>log2DOSsecsize),startsector,coff&(DOSsecsize-1)));
if (DOS_image_RW(op,startsector+(coff>>log2DOSsecsize),coff&(DOSsecsize-1),(byte *)ma,*ta,ihand) < 0)
if (DOS_image_RW(op,startsector+(coff>>log2DOSsecsize),coff&(DOSsecsize-1),(byte *)memaddr,*ta,ihand) < 0)
{
dprintf(("","DOS_multiple_RW: DOS_image_RW failed \n"));
return(-1) ;
......@@ -417,15 +531,23 @@ int DOS_multiple_RW(int op,int cluster,int coff,char *ma,int limit,word *ta,DOSd
return(nextcluster) ;
}
/*---------------------------------------------------------------------------*/
int DOS_object_RW(int op,int startcluster,char *ma,word bytelength,DOSdisc *ihand)
/*!
* \param ihand Image handle
* \param memaddr Source or destination of the data
* \param bytelength Number of bytes in buffer 'ma'
* \param startcluster Cluster number to start from
* \param op Reads, writes, or zeroes
* \brief Load/save as many consecutive CLUSTERs as possible, starting at the specified
* cluster, to/from the given memory address.
* \return 0 if no more clusters, n next cluster number, or -1 if error
*/
int DOS_object_RW(int op, int startcluster, char *memaddr, word bytelength, DOSdisc *ihand)
{
word allocsize = secsalloc(ihand) * DOSsecsize;
word tamount ;
int nextcluster = startcluster ;
dprintf(("","DOS_object_RW: op = %c, startCLUSTER = &%03X, ma = &%08X, bytelength = &%08X, ihand = &%08X\n",(op == Rdata ? 'R' : 'W'),startcluster,(word)ma,bytelength,(word)ihand));
dprintf(("","DOS_object_RW: op = %c, startCLUSTER = &%03X, ma = &%08X, bytelength = &%08X, ihand = &%08X\n",(op == Rdata ? 'R' : 'W'),startcluster,(word)memaddr,bytelength,(word)ihand));
/* load whole clusters directly into memory */
while ((bytelength != 0) && (nextcluster > 0))
......@@ -434,19 +556,19 @@ int DOS_object_RW(int op,int startcluster,char *ma,word bytelength,DOSdisc *ihan
{
tamount = bytelength ;
dprintf(("","DOS_object_RW: Calling Cluster_RW\n"));
nextcluster = DOS_cluster_RW(op,nextcluster,0,ma,bytelength,ihand) ;
nextcluster = DOS_cluster_RW(op,nextcluster,0,memaddr,bytelength,ihand) ;
}
else
{
dprintf(("","DOS_object_RW: Calling Multiple_RW\n"));
nextcluster = DOS_multiple_RW(op,nextcluster,0,ma,bytelength,&tamount,ihand) ;
nextcluster = DOS_multiple_RW(op,nextcluster,0,memaddr,bytelength,&tamount,ihand) ;
}
/* cluster op failure */
if (nextcluster == -1)
return(-1) ; /* assumes error message already defined */
bytelength -= tamount ;
ma += tamount ;
memaddr += tamount ;
}
dprintf(("","DOS_object_RW: nextcluster = &%03X, bytelength = &%08X\n",nextcluster,bytelength));
......@@ -459,6 +581,65 @@ int DOS_object_RW(int op,int startcluster,char *ma,word bytelength,DOSdisc *ihan
return(0) ;
}
/*!
* \param ihand Image handle
* \param memaddr Source or destination of the data
* \param nbytes Number of bytes in buffer 'ma'
* \param off Offset from sector start
* \param sec Sector number to start from
* \param op Reads, writes, or zeroes
* \brief Read or write a block from the specified image file
* \return -1 if error occurred
*/
int DOS_image_RW(int op,word sec,word off,byte *memaddr,word nbytes,DOSdisc *ihand)
{
word discaddress ;
_kernel_swi_regs reglist ;
_kernel_oserror *rerror ;
dprintf(("","DOS_image_RW: %c sec: %x ma: &%08X nbytes: &%08X ihand: &%08X\n",((op == Rdata) ? 'R' : 'W'),sec,(int)memaddr,nbytes,(word)ihand));
/* NOTE: the "disc_winioffset" value SHOULD be 0x00000000 for floppies */
discaddress = ((sec - 1) * DOSsecsize) + ihand->disc_winioffset + off ;
dprintf(("","DOS_image_RW: handle = &%08X, disc address = &%08X\n",ihand->disc_fhand,discaddress));
/* transfer the bytes */
reglist.r[0] = ((op == Rdata) ? OSGBPB_ReadFromGiven : OSGBPB_WriteAtGiven) ;
reglist.r[1] = ihand->disc_fhand ; /* FileSwitch handle */
reglist.r[2] = (word)memaddr ;
reglist.r[3] = nbytes ;
reglist.r[4] = discaddress ;
reglist.r[5] = NULL ;
reglist.r[6] = NULL ;
if ((rerror = _kernel_swi(OS_GBPB,&reglist,&reglist)) != NULL)
{
dprintf(("","DOS_image_RW: (&%08X) \"%s\"\n",rerror->errnum,rerror->errmess));
return_errorX(int,rerror) ;
}
dprintf(("","DOS_image_RW: transfer complete, &%08X bytes left\n",reglist.r[3]));
if (reglist.r[3] != 0)
{
return_error0(int,((op == Rdata) ? err_readfailed : err_writefailed)) ;
}
/* If this call has written data to the image (op == Wdata) and the new image
* ID flag is set then we must generate a new disc ID and tell FileSwitch
* about it.
* OS_Args
* r0 = 8
* r1 = image file handle
* r2 = new image identity
*/
if ((op == Wdata) && (ihand->disc_flags & disc_UPDATEID))
return(update_imageID(ihand)) ;
return(0) ;
}
/*---------------------------------------------------------------------------*/
int saveFILE(char *fname,char *leafname,word ld,word ex,char *bs,word len,DIR_info **cdir,DOS_direntry **dentry,int fzero,DOSdisc *ihand)
......@@ -801,103 +982,3 @@ word max_sector(DOS_bootsector *bb)
return max_sect;
}
int DOS_bytes_RW(int op, char *memaddr, word bytes, word foff, FILEhand *fhand)
{
int clustercount = 0;
DOSdisc *ihand = fhand->ihand;
int clustersize, nextcluster;
word size;
int zero = 0;
int result = 0;
dprintf(("","DOS_bytes_RW: op = %c, memaddr = &%08X, bytes = %d, foff = %d, fhand = &%08X\n", (op == Rdata ? 'R' : 'W'), (int)memaddr, bytes, foff, (int)fhand));
if (bytes == 0)
return 0;
if (op == Wzero) {
zero = 1;
op = Wdata;
}
/* Check if the request is outside the file. */
if (foff + bytes > fhand->filelen) {
if (op == Rdata) {
/* If reading then generate an error for an offset outside the file but just
* truncate the request if the requested number of bytes is too large.
*/
if (foff > fhand->filelen) {
return_error0(int, err_EOF);
} else
bytes = fhand->filelen - foff;
} else {
/* If writing then extend the file. */
if (DOSFS_ensure(fhand, foff + bytes) < (foff + bytes))
return -1;
}
}
/* Determine which cluster the operation is to start in (on exit foff will contain
* the offset within that cluster).
*/
if ((nextcluster = clusterfromoffset(fhand->startCLUSTER, &foff, ihand)) < 0)
return -1;
/* If the operation is to write zeros then allocate a suitable block of memory and zero it. */
clustersize = secsalloc(ihand) * DOSsecsize;
if (zero) {
char *cp;
size = (bytes < clustersize ? bytes : clustersize);
if ((cp = memaddr = (char *)malloc(size)) == NULL)
return_errorT(int, err_heapexhausted, tok_heapexhausted, 0, 0);
while (size--)
*(cp++) = '\0';
}
while (bytes > 0) {
if (nextcluster >= CLUSTER_end(ihand))
{
global_error0(err_EOF);
result = -1;
break;
}
dprintf(("","DOS_bytes_RW: cluster offset = %d, bytes left = %d\n",foff,bytes));
/* Terminate loops in bad FAT. */
if ( (++clustercount > ihand->disc_FATentries) || (nextcluster < CLUSTER_first(ihand)) )
{
global_error0(err_clusterchain);
result = -1;
break;
}
if (bytes > clustersize-foff) {
/* Try to read/write as much as possible straight to/from memory using a cluster multiple op. */
size = (zero ? clustersize-foff : bytes);
dprintf(("","DOS_bytes_RW: trying %d bytes starting at cluster %d\n",size,nextcluster));
if ((nextcluster = DOS_multiple_RW(op, nextcluster, foff, memaddr, size, &size, ihand)) < 0)
{
result = -1;
break;
}
} else {
/* Do the last partial cluster. */
size = bytes;
dprintf(("","DOS_bytes_RW: transferring %d bytes in cluster %d\n",size,nextcluster));
if ((nextcluster = DOS_cluster_RW(op, nextcluster, foff, memaddr, size, ihand)) < 0)
{
result = -1;
break;
}
}
foff = 0; /* if we go round again then must have stopped at cluster boundary */
if (!zero)
memaddr += size;
bytes -= size;
}
if (zero) free(memaddr);
return result;
}
......@@ -675,15 +675,15 @@ static DIR_info *read_cache_dir(
i=1;
while((fentry+i)->FILE_status != 0)// There are still directory entrys I have not looked at
{
if(((fentry+(i-1))->FILE_attribute ==