📄 fatfilt.c
字号:
/* Find if any clusters were logically deleted, and if so, delete them */
for (offset = 0; offset < SECTOR_SIZE; offset += 2, iSec += pv->clusterSize) {
oldFATentry = LE2( *(LEushort FAR0 *)(oldFAT + offset) );
newFATentry = LE2( *(LEushort FAR1 *)(newFAT + offset) );
#endif /* FAT_12BIT */
if ((oldFATentry != FAT_FREE) && (newFATentry == FAT_FREE)) {
ioreq.irHandle = pv->handle;
ioreq.irSectorNo = iSec;
ioreq.irSectorCount = pv->clusterSize;
checkStatus( flAbsDelete(&ioreq) );
}
}
return flOK;
}
#endif /* FL_INCLUDE_FAT_MONITOR */
/* --------------------------------------------------------------------------- *
* *
* f f C h e c k B e f o r e W r i t e *
* *
* Catch all the FAT updates. Detect disk partitioning operation, track it *
* to completion, re-read partition tables, and re-install FAT filters on *
* all FAT12/16 partitions. *
* *
* Parameters: *
* ioreq : standard I/O request to be checked *
* *
* Returns: *
* flOK on success, otherwise error code *
* *
* --------------------------------------------------------------------------- */
FLStatus ffCheckBeforeWrite ( IOreq FAR2 * ioreq )
{
int socNo, diskNo;
FLffDisk * pd;
FLffVol * pv;
long iSec;
int iPart;
IOreq ioreq2;
char FAR1 * usrBuf;
/* if module hasn't been reset yet, do it now */
if (resetDone == FALSE)
(void) reset();
/* break TFFS handle into socket# and disk#, and do sanity check */
socNo = H2S(ioreq->irHandle);
diskNo = H2D(ioreq->irHandle);
if ((socNo >= ((int) noOfSockets)) || (diskNo >= MAX_TL_PARTITIONS))
return flBadDriveHandle;
/* if disk structure hasn't been allocated yet, do it now */
if (ffDisk[socNo][diskNo] == NULL)
checkStatus( newDisk((int)ioreq->irHandle) );
pd = ffDisk[socNo][diskNo];
/* read partition table(s) and install FAT filters is needed */
if (pd->ffstate == flStateNotInitialized)
checkStatus( parseDisk((int)ioreq->irHandle) );
/* catch writes to MBR, and track the whole disk partitioning operations */
while( isPartTableWrite(pd, ioreq) == TRUE ) {
/* disk re-partitioning is in progress */
if( pd->secToWatch == (SectorNo)0 ) {
/* it's write to MBR, so trash BPBs in all disk's partitions */
if (pd->parts > 0) {
for (iPart = 0; iPart < pd->parts; iPart++) {
ioreq2.irHandle = ioreq->irHandle;
ioreq2.irSectorNo = (pd->part[iPart])->startSecNo;
ioreq2.irSectorCount = (SectorNo) 1;
ioreq2.irData = (void FAR1 *) zeroes;
(void) flAbsWrite(&ioreq2);
}
}
}
/* keep FAT filters disabled while disk partitioning is in progress */
pd->ffstate = flStateInitInProgress;
/* partition table which is about to be written to disk */
usrBuf = FLBUF( ioreq, (pd->secToWatch - ioreq->irSectorNo) );
switch( isExtPartPresent(usrBuf, &(pd->secToWatch)) ) {
case flOK:
/*
* Found valid partition table with extended partition.
* The pd->secToWatch has been updated to point to the
* sector where next partition table will be written to.
*/
continue;
case flFileNotFound:
/*
* Valid partition table, but no extended partition in it.
* Partitioning has been completed. Set pd->ffstate to
* 'flStateNotInitialized' to initiate parsing of partition
* table(s) and FAT filter installation next time this routine
* is called.
*/
pd->ffstate = flStateNotInitialized;
break;
case flBadFormat:
default:
/* No valid partition table. */
break;
}
return flOK;
}
#ifdef FL_INCLUDE_FAT_MONITOR
/* check for FAT update */
if (pd->ffstate == flStateInitialized) {
/* NOTE: We can handle 'write' request that spans disk partition boundaries */
for (iSec = ioreq->irSectorNo;
iSec < (ioreq->irSectorNo + ioreq->irSectorCount); iSec++) {
for (iPart = 0; iPart < pd->parts; iPart++) {
pv = pd->part[iPart];
/* we monitor only FAT12/16 partitions */
if ((pv->type != FAT12_PARTIT) && (pv->type != FAT16_PARTIT) &&
(pv->type != DOS4_PARTIT))
continue;
/* FAT filters can be disabled on individual partitions */
if (pv->ffEnabled != TRUE)
continue;
if (iSec == (long)pv->startSecNo) {
/* partition's boot sector is being updated */
usrBuf = FLBUF( ioreq, (iSec - ioreq->irSectorNo) );
if( isBPBchanged(pv, usrBuf) == TRUE ) {
/*
* Critical fields in partition's boot sector have been changed.
* Turn off FAT monitor on this partition.
*/
pv->ffEnabled = FALSE;
DEBUG_PRINT(("Debug: BPB update detected.\r\n"));
continue;
}
}
if ((iSec >= (long)pv->firstFATsecNo) && (iSec <= (long)pv->lastFATsecNo)) {
/* compare new and old contents of FAT sectors(s) */
usrBuf = FLBUF( ioreq, (iSec - ioreq->irSectorNo) );
checkStatus( partFreeDelClusters(pv, iSec, usrBuf) );
}
}
}
}
#endif /* FL_INCLUDE_FAT_MONITOR */
return flOK;
}
/* --------------------------------------------------------------------------- *
* *
* f l f f C o n t r o l *
* *
* Enable/disable/install FAT filters. See comments inside the routine for *
* the list of supported operations. *
* *
* Parameters: *
* handle : TFFS handle *
* partNo : partition # (0 .. FL_MAX_PARTS_PER_DISK) *
* state : see list of supported operations below *
* *
* Returns: *
* flOK on success, otherwise error code *
* *
* --------------------------------------------------------------------------- *
* *
* The following FAT monitor control requests are supported: *
* *
* state : flStateNotInitialized *
* partNo : [0 ... pd->parts-1] *
* action : turn off FAT monitor on specified partition *
* *
* state : flStateNotInitialized *
* partNo : < 0 *
* action : turn off FAT monitor on all partitions *
* *
* state : flStateInitialized *
* partNo : [0 ... pd->parts-1] *
* action : if FAT monitor has been installed on specified partition, *
* turn it on *
* *
* state : flStateInitInProgress *
* partNo : ignored *
* action : re-read partition table(s), and install FAT filters on all *
* partitions *
* *
* --------------------------------------------------------------------------- */
FLStatus flffControl ( int handle,
int partNo,
FLState state )
{
int socNo, diskNo;
FLffDisk * pd;
int i;
FLStatus status;
/* if module hasn't been reset yet, do it now */
if (resetDone == FALSE)
(void) reset();
/* break TFFS handle into socket# and disk#, and do sanity check */
socNo = H2S(handle);
diskNo = H2D(handle);
if ((socNo >= ((int) noOfSockets)) || (diskNo >= MAX_TL_PARTITIONS))
return flBadDriveHandle;
/* if disk structure hasn't been allocated yet, do it now */
if (ffDisk[socNo][diskNo] == NULL)
checkStatus( newDisk(handle) );
pd = ffDisk[socNo][diskNo];
/* abort if disk re-partitioning is in progress */
if (pd->ffstate == flStateInitInProgress)
return flDriveNotReady;
/* read partition table(s) and install FAT filters is needed */
if (pd->ffstate == flStateNotInitialized) {
if (state == flStateNotInitialized)
return flOK;
checkStatus( parseDisk(handle) );
}
/* check 'partNo' arguement for sanity */
if ((partNo >= pd->parts) || (partNo >= FL_MAX_PARTS_PER_DISK))
return flBadDriveHandle;
/* do requested operation */
status = flBadParameter;
switch (state) {
case flStateInitInProgress:
/* read partition table(s), install FAT filters on all partitions */
pd->ffstate = flStateNotInitialized;
status = parseDisk(handle);
break;
case flStateNotInitialized:
/* turn off FAT monitor */
if (partNo < 0) { /* all partitions */
for (i = 0; i < FL_MAX_PARTS_PER_DISK; i++) {
if (pd->part[i] != NULL)
(pd->part[i])->ffEnabled = FALSE;
}
}
else { /* specified partition */
if (pd->part[partNo] != NULL)
(pd->part[partNo])->ffEnabled = FALSE;
}
status = flOK;
break;
#ifdef FL_INCLUDE_FAT_MONITOR
case flStateInitialized:
/* turn on FAT monitor */
if ((pd->ffstate == flStateInitialized) && (partNo >= 0)) {
if (pd->part[partNo] != NULL) {
switch( (pd->part[partNo])->type ) {
case FAT12_PARTIT:
case FAT16_PARTIT:
case DOS4_PARTIT:
(pd->part[partNo])->ffEnabled = TRUE;
status = flOK;
break;
case FL_RAW_PART:
DEBUG_PRINT(("Debug: can't ctrl non-existent partition.\r\n"));
break;
default:
DEBUG_PRINT(("Debug: can't ctrl non-FAT12/16 partition.\r\n"));
break;
}
}
}
break;
#endif /* FL_INCLUDE_FAT_MONITOR */
} /* switch(state) */
return status;
}
/* --------------------------------------------------------------------------- *
* *
* f l f f I n f o *
* *
* Obtain complete partition info for specified disk. *
* *
* Parameters: *
* handle : TFFS handle *
* *
* Returns: *
* NULL if error, otherwise pointer to partitioning info *
* *
* --------------------------------------------------------------------------- */
FLffDisk * flffInfo ( int handle )
{
int socNo, diskNo;
FLffDisk * pd;
/* if module hasn't been reset yet, do it now */
if (resetDone == FALSE)
(void) reset();
/* break TFFS handle into socket# and disk#, and do sanity check */
socNo = H2S(handle);
diskNo = H2D(handle);
if ((socNo >= ((int) noOfSockets)) || (diskNo >= MAX_TL_PARTITIONS))
return NULL;
/* if disk structure hasn't been allocated yet, do it now */
if (ffDisk[socNo][diskNo] == NULL) {
if( newDisk(handle) != flOK )
return NULL;
}
pd = ffDisk[socNo][diskNo];
/* read partition table(s) and install FAT filters is needed */
if (pd->ffstate == flStateNotInitialized) {
if( parseDisk(handle) != flOK )
return NULL;
}
return pd;
}
#endif /* ABS_READ_WRITE && FL_READ_ONLY */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -