📄 fltl.c
字号:
/***********************************************************************************/
/* M-Systems Confidential */
/* Copyright (C) M-Systems Flash Disk Pioneers Ltd. 1995-2003 */
/* All Rights Reserved */
/***********************************************************************************/
/* NOTICE OF M-SYSTEMS OEM */
/* SOFTWARE LICENSE AGREEMENT */
/* */
/* THE USE OF THIS SOFTWARE IS GOVERNED BY A SEPARATE LICENSE */
/* AGREEMENT BETWEEN THE OEM AND M-SYSTEMS. REFER TO THAT AGREEMENT */
/* FOR THE SPECIFIC TERMS AND CONDITIONS OF USE, */
/* OR CONTACT M-SYSTEMS FOR LICENSE ASSISTANCE: */
/* E-MAIL = info@m-sys.com */
/***********************************************************************************/
/*
* $Log: V:/PVCSDB/DiskOnChip/archives/general storage/TrueFFS/src/core/fltl.c-arc $
*
* Rev 1.8 Oct 20 2003 09:01:34 oris
* Added check against exceptions.
*
* Rev 1.7 Sep 01 2003 19:07:10 oris
* - Removed warnings
* - Removed tffsRAMXXX calls.
* - Added default FLTXT macro for converting text to printable text strings.
* - changed TLS definition to FL_TLS
*
* Rev 1.6 Jun 16 2003 01:18:26 oris
* Bug fix - possible cause for an exception in case volForCallBack is initialized.
*
* Rev 1.5 May 11 2003 11:10:16 OriS
* Removed warnings
*
* Rev 1.4 May 11 2003 08:28:08 OriS
* Format routine is now done using verify write.
*
* Rev 1.3 May 08 2003 23:15:18 OriS
* Removed warnings.
*
* Rev 1.2 May 06 2003 11:55:10 OriS
* Added save of structure size for extended disk information routine.
* Changed TFFSSET to tffsRAMset
*
* Rev 1.1 Apr 27 2003 09:03:02 Oris
* Improved argument checks.
*
* Rev 1.0 Apr 09 2003 12:16:04 OriS
* Initial revision.
*
*/
#include "fltl.h"
#include "docbdk.h" /* Only for bdk signature size */
int noOfTLs; /* No. of translation layers actually registered */
TLentry tlTable[FL_TLS];
/*----------------------------------------------------------------------*/
/* f l P r e M o u n t */
/* */
/* Perform TL operation before the TL is mounted */
/* */
/* Notes for FL_COUNT_VOLUMES routine */
/* ---------------------------------- */
/* Note : The number of partitions returned is not neccarily the number */
/* That can be accesses. protected partitions will need a key. */
/* Note : TL that do not support several partitions will return 1 */
/* unless the socket can not be mounted in which case 0 will be */
/* returned. */
/* */
/* Parameters: */
/* callType : The type of the operation (see blockdev.h) */
/* ioreq : Input Output packet */
/* ioreq.irHandle : handle discribing the socket and the partition */
/* flash : Location where the flash media record can be */
/* stored. Note that it is not yet initialized */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flPreMount(FLFunctionNo callType, IOreq FAR2* ioreq , FLFlash * flash)
{
FLStatus layerStatus = flUnknownMedia;
FLStatus callStatus;
#ifdef HW_PROTECTION
FLWord wTempFlags;
#endif /* HW_PROTECTION */
FLSocket *socket = flSocketOf(FL_GET_SOCKET_FROM_HANDLE(ioreq));
int iTL;
/* Identify flash medium and initlize flash record */
callStatus = flIdentifyFlash(socket,flash);
if (callStatus != flOK && callStatus != flUnknownMedia)
return callStatus;
switch(callType)
{
#ifdef HW_PROTECTION
case FL_PROTECTION_CHANGE_TYPE:
/* Only read and or write protected types are available */
wTempFlags = (FLWord)ioreq->irFlags;
if (((wTempFlags & (READ_PROTECTED | WRITE_PROTECTED |
OTW_PROTECTED | PROTECTABLE)) != wTempFlags) ||
((wTempFlags & PROTECTABLE) == 0))
{
DBG_PRINT_ERR(FLZONE_TL,"ERROR - Bad parameters (flags contain unacceptable parameter).\r\n");
return flBadParameter;
}
/* Do not allow both OTW and read protection */
if((wTempFlags & (OTW_PROTECTED | READ_PROTECTED)) ==
(OTW_PROTECTED | READ_PROTECTED))
{
DBG_PRINT_ERR(FLZONE_TL,"ERROR - Bad parameters (can not set OTW protection with read protection).\r\n");
return flBadParameter;
}
break;
#endif /* HW_PROTECTION */
#ifdef FL_EXTENDED_DISK_INFO
case FL_GET_EXTENDED_DISK_INFO :
{
FLExtendedDiskInfo FAR1 * info = (FLExtendedDiskInfo FAR1 *)ioreq->irData;
FLDword dwSavedSize;
if(info->dwStructSize != sizeof(FLExtendedDiskInfo))
{
DBG_PRINT_ERR(FLZONE_TL,"ERROR - Bad parameter (Structure size is wrong).\r\n");
DBG_PRINT_ERR_PRM(FLZONE_TL,(FLTXT(" Given size is %lu while structure size is %lu.\r\n"),info->dwStructSize,(FLDword)sizeof(FLExtendedDiskInfo)));
return flBadParameter;
}
if(info == NULL)
{
DBG_PRINT_ERR(FLZONE_TL,"ERROR - Info record is NULL.\r\n");
return flBadParameter;
}
dwSavedSize = info->dwStructSize;
tffsset(info,0,sizeof(FLExtendedDiskInfo));
info->dwStructSize = dwSavedSize;
break;
}
#endif /* FL_EXTENDED_DISK_INFO */
default:
break;
}
/* Try sending call to the diffrent TLs */
for (iTL = 0; (iTL < noOfTLs) && (layerStatus != flOK); iTL++)
if (tlTable[iTL].preMountRoutine != NULL)
layerStatus = tlTable[iTL].preMountRoutine(callType,ioreq, flash,&callStatus);
if (layerStatus != flOK)
{
switch (callType)
{
case FL_COUNT_VOLUMES:
ioreq->irFlags = 1;
return flOK;
default : /* Protection routines */
return flFeatureNotSupported;
}
}
return callStatus;
}
/*----------------------------------------------------------------------*/
/* f l M o u n t */
/* */
/* Mount a translation layer */
/* */
/* Parameters: */
/* volNo : Volume no. */
/* socketNo : The socket no */
/* tl : Where to store translation layer methods */
/* useFilters : Whether to use filter translation-layers */
/* flash : Location where the flash media record can be */
/* stored. Note that it is not yet initialized */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flMount(unsigned volNo, unsigned socketNo,TL *tl,
FLBoolean useFilters , FLFlash * flash)
{
FLFlash *volForCallback = NULL;
FLSocket *socket = flSocketOf(socketNo);
FLStatus status = flUnknownMedia;
int iTL;
FLStatus flashStatus = flIdentifyFlash(socket,flash);
if (flashStatus != flOK && flashStatus != flUnknownMedia)
return flashStatus;
tl->recommendedClusterInfo = NULL;
tl->writeMultiSector = NULL;
tl->readSectors = NULL;
#ifndef NO_READ_BBT_CODE
tl->readBBT = NULL;
#endif
#if (defined(VERIFY_VOLUME) || defined(VERIFY_WRITE))
tl->checkVolume = NULL;
#endif /* VERIFY_VOLUME || VERIFY_WRITE */
#ifdef DEFRAGMENT_VOLUME
tl->defragment = NULL;
#endif /* DEFRAGMENT */
for (iTL = 0; (iTL < noOfTLs) && (status != flOK) && (status != flHWProtection); iTL++)
if (tlTable[iTL].formatRoutine != NULL) /* not a block-device filter */
status = tlTable[iTL].mountRoutine(volNo,tl,flashStatus == flOK ? flash : NULL,&volForCallback);
if (status == flOK) {
if (volForCallback != NULL)
if (volForCallback->setPowerOnCallback)
volForCallback->setPowerOnCallback(volForCallback);
if (useFilters)
for (iTL = 0; iTL < noOfTLs; iTL++)
if (tlTable[iTL].formatRoutine == NULL) /* block-device filter */
if (tlTable[iTL].mountRoutine(volNo,tl,NULL,NULL) == flOK)
break;
}
return status;
}
#ifdef FORMAT_VOLUME
/*----------------------------------------------------------------------*/
/* f l F o r m a t */
/* */
/* Formats the Flash volume */
/* */
/* Parameters: */
/* volNo : Physical drive no. */
/* formatParams : Address of FormatParams structure to use */
/* flash : Location where the flash media record can be */
/* stored. Note that it is not yet initialized */
/* */
/* Returns: */
/* FLStatus : 0 on success, failed otherwise */
/*----------------------------------------------------------------------*/
FLStatus flFormat(unsigned volNo, TLFormatParams * formatParams,
FLFlash * flash)
{
#ifndef FL_SKIP_ARGS_CHECK
BinaryPartitionFormatParams FAR1* partitionPtr;
#endif /* FL_SKIP_ARGS_CHECK */
FLSocket * socket = flSocketOf(volNo);
FLStatus status = flUnknownMedia;
int iTL,partitionNo;
FLStatus flashStatus = flIdentifyFlash(socket,flash);
if (flashStatus != flOK && flashStatus != flUnknownMedia)
return flashStatus;
/* Validity check for formatParams */
if (!(flash->flags & INFTL_ENABLED) &&
!(flash->flags & SAFTL_ENABLED)) /* Flash does not support INFTL */
{
if ((formatParams->noOfBDTLPartitions > 1) ||
#ifdef HW_PROTECTION
((formatParams->BDTLPartitionInfo != NULL) &&
(formatParams->BDTLPartitionInfo->protectionType & PROTECTABLE)) ||
((formatParams->noOfBinaryPartitions > 0)&&
(formatParams->binaryPartitionInfo->protectionType & PROTECTABLE)) ||
#endif /* HW_PROTECTION */
(formatParams->noOfBinaryPartitions > 1))
{
DBG_PRINT_ERR(FLZONE_TL,"ERROR - Bad format parameters (feature not supported by the TL).\r\n");
return flFeatureNotSupported;
}
}
#ifndef FL_SKIP_ARGS_CHECK
for(partitionNo = 0 , partitionPtr = formatParams->binaryPartitionInfo;
partitionNo < formatParams->noOfBinaryPartitions;
partitionNo++,partitionPtr++)
{
if(*((FLDword FAR1*)(partitionPtr->sign)) == 0xffffffffL)
{
DBG_PRINT_ERR(FLZONE_TL,"ERROR - Can not use 'FFFF' signature for Binary partition.\r\n");
return flBadParameter;
}
}
#endif /* FL_SKIP_ARGS_CHECK */
/* Set default parameters */
if(formatParams->percentUse == TL_DEFAULT_PERCENTAGE)
formatParams->percentUse = 100-flash->maxBadPercentage ;
/* Try each of the registered TL */
#if ((defined(VERIFY_WRITE)) && (defined(ENVIRONMENT_VARS)))
partitionNo = flash->args.verifyWriteMode;
flash->args.verifyWriteMode = FL_ON;
#endif /* ((defined(VERIFY_WRITE)) && (defined(ENVIRONMENT_VARS))) */
for (iTL = 0; iTL < noOfTLs && status == flUnknownMedia; iTL++)
if (tlTable[iTL].formatRoutine != NULL) /* not a block-device filter */
status = tlTable[iTL].formatRoutine(volNo,formatParams,flashStatus == flOK ? flash : NULL);
#if ((defined(VERIFY_WRITE)) && (defined(ENVIRONMENT_VARS)))
flash->args.verifyWriteMode = (FLByte)partitionNo;
#endif /* ((defined(VERIFY_WRITE)) && (defined(ENVIRONMENT_VARS))) */
return status;
}
#endif
FLStatus noFormat (unsigned volNo, TLFormatParams * formatParams, FLFlash *flash)
{
return flOK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -