Change FcbReadWrite to handle multiple records at once; this allows

for the optimization of FcbRandomBlockIO.


git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@718 6ac86273-5f31-0410-b378-82cca8765d1b
This commit is contained in:
Bart Oldeman 2003-10-16 15:03:16 +00:00
parent dd9df1f3a6
commit 492fef1f72
3 changed files with 39 additions and 32 deletions

View File

@ -244,39 +244,50 @@ UBYTE FcbReadWrite(xfcb FAR * lpXfcb, UCOUNT recno, int mode)
{ {
ULONG lPosit; ULONG lPosit;
long nTransfer; long nTransfer;
BYTE FAR * FcbIoPtr = dta;
fcb FAR *lpFcb; fcb FAR *lpFcb;
unsigned size;
FcbIoPtr += recno * lpFcb->fcb_recsiz; unsigned long bigsize;
unsigned recsiz;
if ((ULONG)recno * lpFcb->fcb_recsiz >= 0x10000ul ||
FP_OFF(FcbIoPtr) < FP_OFF(dta))
return FCB_ERR_SEGMENT_WRAP;
/* Convert to fcb if necessary */ /* Convert to fcb if necessary */
lpFcb = ExtFcbToFcb(lpXfcb); lpFcb = ExtFcbToFcb(lpXfcb);
recsiz = lpFcb->fcb_recsiz;
bigsize = (ULONG)recsiz * recno;
if (bigsize > 0xffff)
return FCB_ERR_SEGMENT_WRAP;
size = (unsigned)bigsize;
if (FP_OFF(dta) + size < FP_OFF(dta))
return FCB_ERR_SEGMENT_WRAP;
/* Now update the fcb and compute where we need to position */ /* Now update the fcb and compute where we need to position */
/* to. */ /* to. */
lPosit = FcbRec(lpFcb) * lpFcb->fcb_recsiz; lPosit = FcbRec(lpFcb) * recsiz;
if ((CritErrCode = -SftSeek(lpFcb->fcb_sftno, lPosit, 0)) != SUCCESS) if ((CritErrCode = -SftSeek(lpFcb->fcb_sftno, lPosit, 0)) != SUCCESS)
return FCB_ERR_NODATA; return FCB_ERR_NODATA;
/* Do the read */ /* Do the read */
nTransfer = DosRWSft(lpFcb->fcb_sftno, lpFcb->fcb_recsiz, FcbIoPtr, mode); nTransfer = DosRWSft(lpFcb->fcb_sftno, size, dta, mode & ~XFR_FCB_RANDOM);
if (nTransfer < 0) if (nTransfer < 0)
CritErrCode = -(int)nTransfer; CritErrCode = -(int)nTransfer;
/* Now find out how we will return and do it. */ /* Now find out how we will return and do it. */
if (nTransfer == lpFcb->fcb_recsiz) if (mode & XFR_WRITE)
lpFcb->fcb_fsize = SftGetFsize(lpFcb->fcb_sftno);
/* if end-of-file, then partial read should count last record */
if (mode & XFR_FCB_RANDOM && recsiz > 0)
lpFcb->fcb_rndm += ((unsigned)nTransfer + recsiz - 1) / recsiz;
size -= (unsigned)nTransfer;
if (size == 0)
{ {
if (mode == XFR_WRITE) lpFcb->fcb_fsize = SftGetFsize(lpFcb->fcb_sftno);
FcbNextRecord(lpFcb); FcbNextRecord(lpFcb);
return FCB_SUCCESS; return FCB_SUCCESS;
} }
if (mode == XFR_READ && nTransfer > 0) size %= lpFcb->fcb_recsiz;
if (mode & XFR_READ && size > 0)
{ {
fmemset(FcbIoPtr + (unsigned)nTransfer, 0, lpFcb->fcb_recsiz - (unsigned)nTransfer); fmemset((char FAR *)dta + (unsigned)nTransfer, 0, size);
FcbNextRecord(lpFcb); FcbNextRecord(lpFcb);
return FCB_ERR_EOF; return FCB_ERR_EOF;
} }
@ -340,28 +351,21 @@ void FcbCalcRec(xfcb FAR * lpXfcb)
UBYTE FcbRandomBlockIO(xfcb FAR * lpXfcb, UWORD *nRecords, int mode) UBYTE FcbRandomBlockIO(xfcb FAR * lpXfcb, UWORD *nRecords, int mode)
{ {
unsigned recno; UBYTE nErrorCode;
UBYTE nErrorCode = FCB_SUCCESS;
fcb FAR *lpFcb; fcb FAR *lpFcb;
unsigned long old;
FcbCalcRec(lpXfcb); FcbCalcRec(lpXfcb);
/* Convert to fcb if necessary */ /* Convert to fcb if necessary */
lpFcb = ExtFcbToFcb(lpXfcb); lpFcb = ExtFcbToFcb(lpXfcb);
for (recno = 0; recno < *nRecords; recno++) old = lpFcb->fcb_rndm;
{ nErrorCode = FcbReadWrite(lpXfcb, *nRecords, mode);
nErrorCode = FcbReadWrite(lpXfcb, recno, mode); *nRecords = lpFcb->fcb_rndm - old;
/* end-of-file, partial read should count last record */
if (nErrorCode == FCB_ERR_EOF)
recno++;
if (nErrorCode != FCB_SUCCESS)
break;
}
*nRecords = recno;
/* Now update the fcb */ /* Now update the fcb */
lpFcb->fcb_rndm = FcbRec(lpFcb); FcbCalcRec(lpXfcb);
return nErrorCode; return nErrorCode;
} }
@ -381,7 +385,7 @@ UBYTE FcbRandomIO(xfcb FAR * lpXfcb, int mode)
uwCurrentBlock = lpFcb->fcb_cublock; uwCurrentBlock = lpFcb->fcb_cublock;
ucCurrentRecord = lpFcb->fcb_curec; ucCurrentRecord = lpFcb->fcb_curec;
nErrorCode = FcbReadWrite(lpXfcb, 0, mode); nErrorCode = FcbReadWrite(lpXfcb, 1, mode);
lpFcb->fcb_cublock = uwCurrentBlock; lpFcb->fcb_cublock = uwCurrentBlock;
lpFcb->fcb_curec = ucCurrentRecord; lpFcb->fcb_curec = ucCurrentRecord;

View File

@ -111,6 +111,8 @@ FAR * ASM DPBp; /* First drive Parameter Block */
#define XFR_READ 1 #define XFR_READ 1
#define XFR_WRITE 2 #define XFR_WRITE 2
#define XFR_FORCE_WRITE 3 #define XFR_FORCE_WRITE 3
/* flag to update fcb_rndm field */
#define XFR_FCB_RANDOM 4
#define RDONLY 0 #define RDONLY 0
#define WRONLY 1 #define WRONLY 1

View File

@ -556,12 +556,12 @@ dispatch:
case 0x14: case 0x14:
/* FCB read */ /* FCB read */
lr.AL = FcbReadWrite(FP_DS_DX, 0, XFR_READ); lr.AL = FcbReadWrite(FP_DS_DX, 1, XFR_READ);
break; break;
case 0x15: case 0x15:
/* FCB write */ /* FCB write */
lr.AL = FcbReadWrite(FP_DS_DX, 0, XFR_WRITE); lr.AL = FcbReadWrite(FP_DS_DX, 1, XFR_WRITE);
break; break;
case 0x16: case 0x16:
@ -622,7 +622,8 @@ dispatch:
/* Get default DPB */ /* Get default DPB */
/* case 0x1f: see case 0x32 */ /* case 0x1f: see case 0x32 */
/* Random read using FCB */ /* Random read using FCB: fields not updated
(XFR_RANDOM should not be used here) */
case 0x21: case 0x21:
lr.AL = FcbRandomIO(FP_DS_DX, XFR_READ); lr.AL = FcbRandomIO(FP_DS_DX, XFR_READ);
break; break;
@ -658,12 +659,12 @@ dispatch:
/* Read random record(s) using FCB */ /* Read random record(s) using FCB */
case 0x27: case 0x27:
lr.AL = FcbRandomBlockIO(FP_DS_DX, &lr.CX, XFR_READ); lr.AL = FcbRandomBlockIO(FP_DS_DX, &lr.CX, XFR_READ | XFR_FCB_RANDOM);
break; break;
/* Write random record(s) using FCB */ /* Write random record(s) using FCB */
case 0x28: case 0x28:
lr.AL = FcbRandomBlockIO(FP_DS_DX, &lr.CX, XFR_WRITE); lr.AL = FcbRandomBlockIO(FP_DS_DX, &lr.CX, XFR_WRITE | XFR_FCB_RANDOMXS);
break; break;
/* Parse File Name */ /* Parse File Name */