📄 fldrvvxw.c
字号:
socNo = tffsHandle2Soc(pTffsDev->tffsHandle);
diskNo = tffsHandle2Disk(pTffsDev->tffsHandle);
/* check args for sanity */
if ((socNo >= SOCKETS) || (diskNo >= FL_MAX_DISKS_PER_SOCKET))
return (ERROR);
/* stale TFFS handle ? */
if (tffsBlkDevs[socNo][diskNo] != pTffsDev)
return (ERROR);
/* grab socket mutex */
if (tffsSocketMutex[socNo] == NULL)
return (ERROR);
if( semTake(tffsSocketMutex[socNo], WAIT_FOREVER) == ERROR )
return (ERROR);
/* read sectors, handle buffer alignment if needed */
#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT
if( (flBufferAlignment <= ((int) sizeof(char)))
||
((pointerToPhysical(pBuffer) & (flBufferAlignment - 1)) == 0) ) {
#endif
/* check if buffer alignment is disabled, or destination buffer is aligned */
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk;
ioreq.irSectorCount = numBlks;
ioreq.irData = (void FAR1 *) pBuffer;
status = flAbsRead( &ioreq );
if (status == flSectorNotFound) {
/* Read-ahead on non-existing sectors; read sectors one by one */
status = flOK;
for (i = 0, p = pBuffer;
(i < numBlks) && (status == flOK);
i++, p += SECTOR_SIZE ) {
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk + i;
ioreq.irSectorCount = (long) 1;
ioreq.irData = (void FAR1 *) p;
status = flAbsRead( &ioreq );
if (status == flSectorNotFound) {
/* non-existing sector; zero out destination buffer, discard error */
memset (p, 0, SECTOR_SIZE);
status = flOK;
}
}
}
#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT
}
else { /* destination buffer is not aligned */
status = flOK;
/* if internal aligned buffer hasn't been allocated yet, do it */
if( pTffsDev->tffsAlignBuf == NULL ) {
pTffsDev->tffsAlignBuf = memalign( (unsigned) flBufferAlignment,
(unsigned) SECTOR_SIZE );
if( pTffsDev->tffsAlignBuf == NULL )
status = flBufferingError;
}
/* read sectors into internal aligned buffer, then copy to destination */
for (i = 0, p = pBuffer;
(i < numBlks) && (status == flOK);
i++, p += SECTOR_SIZE) {
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk + i;
ioreq.irSectorCount = (long) 1;
ioreq.irData = (void FAR1 *) pTffsDev->tffsAlignBuf;
status = flAbsRead( &ioreq );
if (status == flOK) {
/* copy sector to destination buffer */
memcpy (p, pTffsDev->tffsAlignBuf, SECTOR_SIZE);
}
if (status == flSectorNotFound) {
/*
* Read-ahead on non-existing sector; zero out destination
* buffer, discard error and continue.
*/
memset (p, 0, SECTOR_SIZE);
status = flOK;
}
}
/* update unaligned read statistics */
pTffsDev->tffsUnalignedRead += numBlks;
}
#endif /* FL_DRV_CHK_BUFFER_ALIGNMENT */
/* update read sector counter */
pTffsDev->tffsReadCnt += numBlks;
/* if error, tell dosFs to re-mount this volume */
if (status != flOK)
pTffsDev->tffsBlkdev.bd_readyChanged = TRUE;
/* release socket mutex */
semGive (tffsSocketMutex[socNo]);
return ((status == flOK) ? OK : ERROR);
}
/* ---------------------------------------------------------------------- *
* *
* t f f s B l k W r t *
* *
* Writes sequence of blocks to TrueFFS device. *
* *
* Parameters: *
* *
* pTffsDev : pointer to device desriptor *
* startBlk : starting block number to write *
* numBlks : number of blocks to write *
* pBuffer : pointer to buffer containing data *
* *
* Returns: *
* *
* OK or ERROR *
* *
* ---------------------------------------------------------------------- */
LOCAL STATUS tffsBlkWrt ( FAST TFFS_DEV * pTffsDev,
int startBlk,
int numBlks,
char * pBuffer )
{
int socNo;
int diskNo;
IOreq ioreq;
FLStatus status;
#if defined(FL_DRV_VERIFY_WRITE) || defined(FL_DRV_CHK_BUFFER_ALIGNMENT)
long i;
char FAR1 * p;
#endif
#ifdef FL_DRV_VERIFY_WRITE
char FAR1 * p2;
#ifndef FL_DRV_CHK_BUFFER_ALIGNMENT
char readback [SECTOR_SIZE];
#endif
#endif /* FL_DRV_VERIFY_WRITE */
socNo = tffsHandle2Soc(pTffsDev->tffsHandle);
diskNo = tffsHandle2Disk(pTffsDev->tffsHandle);
/* check args for sanity */
if ((socNo >= SOCKETS) || (diskNo >= FL_MAX_DISKS_PER_SOCKET))
return (ERROR);
/* stale TFFS handle ? */
if (tffsBlkDevs[socNo][diskNo] != pTffsDev)
return (ERROR);
/* grab socket mutex */
if (tffsSocketMutex[socNo] == NULL)
return (ERROR);
if( semTake(tffsSocketMutex[socNo], WAIT_FOREVER) == ERROR )
return (ERROR);
#ifdef FL_DRV_DOSFS2_SUPPORT
/*
* Check for FAT updates. This will also catch and follow to completion
* the disk partitioning operation.
*/
if( (pTffsDev->tffsFlags & (FL_TRUE_BLKDEV | FL_DOSFS_LONGNAMES))
== FL_TRUE_BLKDEV ) {
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk;
ioreq.irSectorCount = numBlks;
ioreq.irData = (char FAR1 *) pBuffer;
(void) ffCheckBeforeWrite (&ioreq);
}
#endif /* FL_DRV_DOSFS2_SUPPORT */
/*
* Write sectors, handle buffer alignment if needed. If write-protect
* error occures, mark volume read-only.
*/
#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT
if( (flBufferAlignment <= ((int) sizeof(char)))
||
((pointerToPhysical(pBuffer) & (flBufferAlignment - 1)) == 0) ) {
#endif
/* check for buffer alignment is disabled, or source buffer is aligned */
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk;
ioreq.irSectorCount = numBlks;
ioreq.irData = (void FAR1 *) pBuffer;
status = flAbsWrite( &ioreq );
#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT
}
else { /* source buffer is not aligned */
status = flOK;
/* if internal aligned buffer hasn't been allocated yet, do it */
if( pTffsDev->tffsAlignBuf == NULL ) {
pTffsDev->tffsAlignBuf = memalign( (unsigned) flBufferAlignment,
(unsigned) SECTOR_SIZE );
if( pTffsDev->tffsAlignBuf == NULL )
status = flBufferingError;
}
/* copy sectors into internal aligned buffer, then write from there */
for (i = 0, p = pBuffer;
(i < numBlks) && (status == flOK);
i++, p += SECTOR_SIZE) {
memcpy (pTffsDev->tffsAlignBuf, p, SECTOR_SIZE);
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk + i;
ioreq.irSectorCount = (long) 1;
ioreq.irData = (void FAR1 *) pTffsDev->tffsAlignBuf;
status = flAbsWrite( &ioreq );
}
/* update unaligned read statistics */
pTffsDev->tffsUnalignedWrite += numBlks;
}
#endif /* FL_DRV_CHK_BUFFER_ALIGNMENT */
if (status == flWriteProtect)
pTffsDev->tffsBlkdev.bd_mode = O_RDONLY;
/* update write sector counter */
pTffsDev->tffsWriteCnt += numBlks;
#ifdef FL_DRV_VERIFY_WRITE
/* if disk has FL_VERIFY_WRITE flag set, read back and verify each sector */
if( (status == flOK) && (ioreq.irSectorCount == numBlks) &&
(pTffsDev->tffsFlags & FL_VERIFY_WRITE) ) {
status = flOK;
#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT
/* if internal aligned buffer hasn't been allocated yet, do it */
if( pTffsDev->tffsAlignBuf == NULL ) {
pTffsDev->tffsAlignBuf = memalign( (unsigned) flBufferAlignment,
(unsigned) SECTOR_SIZE );
}
p2 = pTffsDev->tffsAlignBuf;
if (p2 == NULL)
status = flBufferingError;
#else
p2 = readback;
#endif /* FL_DRV_CHK_BUFFER_ALIGNMENT */
ioreq.irSectorCount = (long) 0;
for( i = 0, p = pBuffer;
(i < numBlks) && (status == flOK);
i++, p += SECTOR_SIZE ) {
ioreq.irHandle = pTffsDev->tffsHandle;
ioreq.irSectorNo = pTffsDev->tffsOffset + startBlk + i;
ioreq.irSectorCount = 1;
ioreq.irData = (void FAR1 *) p2;
status = flAbsRead( &ioreq );
if (status == flOK) {
if( memcmp(p2, p, SECTOR_SIZE) == 0 )
ioreq.irSectorCount++;
else
status = flWriteFault;
}
}
}
#endif /* FL_DRV_VERIFY_WRITE */
/* if error, tell dosFs to re-mount volume */
if (status != flOK)
pTffsDev->tffsBlkdev.bd_readyChanged = TRUE;
/* release socket mutex */
semGive (tffsSocketMutex[socNo]);
return ((status == flOK) ? OK : ERROR);
}
/* ---------------------------------------------------------------------- *
* *
* t f f s I o c t l *
* *
* Handle IOCTL calls to TrueFFS drive
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -