📄 fldrvvxw.c
字号:
/* create BLK_DEV structure */
pTffsDev = (TFFS_DEV *) malloc (sizeof (TFFS_DEV));
if (pTffsDev == NULL)
return NULL;
pTffsDev->tffsHandle = handle;
/* reset sector read/write counters */
pTffsDev->tffsReadCnt = 0;
pTffsDev->tffsWriteCnt = 0;
#ifdef FL_DRV_CHK_BUFFER_ALIGNMENT
pTffsDev->tffsUnalignedRead = 0;
pTffsDev->tffsUnalignedWrite = 0;
/* there is no alignment buffer attached */
pTffsDev->tffsAlignBuf = NULL;
#endif
/* initialize BLK_DEV struct */
pBlkDev = &pTffsDev->tffsBlkdev;
pBlkDev->bd_removable = FALSE; /* not removable */
pBlkDev->bd_retry = 1; /* retry count */
pBlkDev->bd_mode = O_RDWR; /* initial mode for device */
pBlkDev->bd_readyChanged = TRUE; /* new ready status */
pBlkDev->bd_blkRd = tffsBlkRd; /* read block function */
pBlkDev->bd_blkWrt = tffsBlkWrt; /* write block function */
pBlkDev->bd_ioctl = tffsIoctl; /* ioctl function */
pBlkDev->bd_reset = NULL; /* no reset function */
pBlkDev->bd_statusChk = tffsStatChk; /* check status function */
/* mount */
status = flOK;
if (flags & (FL_DOSFS_LONGNAMES | FL_TRUE_BLKDEV)) {
ioreq.irHandle = handle;
status = flAbsMountVolume( &ioreq );
/* verify TL format if requested; discard status for now */
if (flags & FL_CHK_FORMAT) {
ioreq.irHandle = handle;
ioreq.irData = NULL;
ioreq.irLength = 0;
(void) flVerifyVolume( &ioreq );
}
if (status == flOK) {
/* get total number of sectors on disk */
ioreq.irHandle = handle;
ioreq.irData = &info;
status = flVolumeInfo( &ioreq );
if (status == flOK) {
/* calculate disk's "geometry" */
flBuildGeometry (info.logicalSectors, &cyls, &heads, §s, FALSE);
pBlkDev->bd_nBlocks = heads * sects * cyls;
pBlkDev->bd_blksPerTrack = sects;
pBlkDev->bd_nHeads = heads;
pBlkDev->bd_bytesPerBlk = SECTOR_SIZE;
/* make sector #0 point to MBR */
pTffsDev->tffsOffset = 0;
/*
* If FL_DOSFS_LONGNAMES flag is set, make sector #0 pointing
* to first sector of desired FAT12/16 partition
*/
if (flags & FL_DOSFS_LONGNAMES) {
offset = getPart (handle, (flags & 0xf), &blocksInPart);
if (offset == -1) {
status = flBadFormat;
}
else {
pTffsDev->tffsOffset = offset;
pBlkDev->bd_nBlocks = blocksInPart;
}
}
}
}
}
else { /* !(FL_DOSFS_LONGNAMES | FL_TRUE_BLKDEV) */
ioreq.irHandle = handle;
status = flMountVolume( &ioreq );
/* verify TL format if requested; discard status for now */
if (flags & FL_CHK_FORMAT) {
ioreq.irHandle = handle;
ioreq.irData = NULL;
ioreq.irLength = 0;
(void) flVerifyVolume( &ioreq );
}
if (status == flOK) {
/* get volume info from BPB */
ioreq.irData = &bpb;
status = flGetBPB( &ioreq );
if (status == flOK) {
/* get disk's "geometry" etc. from DOS's BPB */
setFromBPB (pBlkDev, &bpb);
/* offset to 1st FAT12/16 partition is added in BLOCKDEV */
pTffsDev->tffsOffset = 0;
}
}
}
if (status == flOK) {
#ifdef FL_DRV_PHYSICAL_ACCESS
/*
* Needed for physical access to the flash. Find out size of flash
* erase block. Read/write page size is assumed to be 512 bytes.
*/
ioreq.irHandle = handle;
ioreq.irData = (void FAR1 *) &info;
if( flVolumeInfo(&ioreq) == flOK ) {
physReadWriteUnitSize[socNo] = SECTOR_SIZE;
physEraseUnitSize[socNo] = (int) info.physicalUnitSize;
}
#endif /* FL_DRV_PHYSICAL_ACCESS */
/* if requested, turn on 'write' verificaton on TL layer */
switch(flags & (FL_VERIFY_WRITE2 | FL_VERIFY_WRITE3) ) {
case FL_VERIFY_WRITE2:
(void) flSetEnvVolume( FL_VERIFY_WRITE_BDTL, (byte) socNo,
(byte) diskNo,(dword) FL_OFF, &dontcare );
break;
case FL_VERIFY_WRITE3:
case (FL_VERIFY_WRITE2 | FL_VERIFY_WRITE3):
(void) flSetEnvVolume( FL_VERIFY_WRITE_BDTL, (byte) socNo,
(byte) diskNo,(dword) FL_ON, &dontcare );
break;
default:
#if 0 /* andrayk */
(void) flSetEnvVolume( FL_VERIFY_WRITE_BDTL, (byte) socNo,
(byte) diskNo,(dword) FL_UPS, &dontcare );
#endif
break;
}
/* remember device creation flags */
pTffsDev->tffsFlags = flags;
}
if (status != flOK)
free (pTffsDev);
return ((status == flOK) ? pTffsDev : NULL);
}
/* ---------------------------------------------------------------------- *
* *
* t f f s D e v C r e a t e *
* *
* Create TFFS disk device. *
* *
* The bits 3-0 of 'flags' contain the # of the desired partition. If *
* it is zero, then partition table is searched for active FAT12/16 *
* partition; if none exist, the partition table is searched for the *
* first FAT12/16 partition. *
* *
* If partition # is not zero, then the desired partition is picked up *
* from the partition table. *
* *
* Parameters: *
* *
* handle : TFFS handle *
* flags : various flags (see fldrvvxw.h) *
* *
* Returns: *
* *
* NULL on error otherwise TFFS device *
* *
* ---------------------------------------------------------------------- */
BLK_DEV* tffsDevCreate ( int handle,
int flags )
{
TFFS_DEV * pTffsDev;
int socNo;
int diskNo;
socNo = tffsHandle2Soc(handle);
diskNo = tffsHandle2Disk(handle);
/* check args for sanity */
if ((socNo >= SOCKETS) || (diskNo >= FL_MAX_DISKS_PER_SOCKET))
return NULL;
/* check for mutually exclusive flags */
if( (flags & FL_DOSFS_LONGNAMES) && (flags & FL_TRUE_BLKDEV) )
return NULL;
pTffsDev = NULL;
/* grab the socket mutex */
if (tffsSocketMutex[socNo] != NULL) {
if( semTake(tffsSocketMutex[socNo], WAIT_FOREVER) == OK ) {
pTffsDev = devCreate (handle, flags);
if (pTffsDev != NULL)
tffsBlkDevs[socNo][diskNo] = pTffsDev;
}
}
/* release the socket mutex */
semGive( tffsSocketMutex[socNo] );
return ( (pTffsDev == NULL) ? NULL : (&pTffsDev->tffsBlkdev) );
}
/* ---------------------------------------------------------------------- *
* *
* t f f s D e v V e r i f y *
* *
* Verifies underlying low-level flash format on TFFS device. *
* *
* Parameters: *
* *
* handle : TFFS handle *
* flags : various flags (see fldrvvxw.h) *
* *
* Returns: *
* *
* OK or ERROR *
* *
* ---------------------------------------------------------------------- */
STATUS tffsDevVerify ( int handle,
int flags )
{
IOreq ioreq;
int socNo;
int diskNo;
FLStatus status;
STATUS rc;
/* check args for sanity */
socNo = tffsHandle2Soc(handle);
diskNo = tffsHandle2Disk(handle);
if ((socNo >= SOCKETS) || (diskNo >= FL_MAX_DISKS_PER_SOCKET))
return ERROR;
rc = ERROR;
/* grab socket's mutex */
if (tffsSocketMutex[socNo] != NULL) {
if( semTake(tffsSocketMutex[socNo], WAIT_FOREVER) == OK ) {
if( tffsBlkDevs[socNo][diskNo] != NULL ) {
/* verify TL format on that 'disk' */
/* NOTE: argument 'flags' is currently ignored */
ioreq.irHandle = handle;
ioreq.irData = NULL;
ioreq.irLength = 0;
status = flVerifyVolume( &ioreq );
if (status == flOK)
rc = OK;
}
/* release socket's mutex */
semGive( tffsSocketMutex[socNo] );
}
}
return rc;
}
/* ---------------------------------------------------------------------- *
* *
* t f f s B l k R d *
* *
* Reads sequence of blocks from TrueFFS device. *
* *
* Parameters: *
* *
* pTffsDev : pointer to device desriptor *
* startBlk : starting block number to read *
* numBlks : number of blocks to read *
* pBuffer : pointer to buffer to receive data *
* *
* Returns: *
* *
* OK or ERROR *
* *
* ---------------------------------------------------------------------- */
LOCAL STATUS tffsBlkRd ( FAST TFFS_DEV * pTffsDev,
int startBlk,
int numBlks,
char * pBuffer )
{
int socNo;
int diskNo;
IOreq ioreq;
int i;
char * p;
FLStatus status;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -