You are currently viewing the documentation for:
ECF_WearLevelFormat
The ECF_WearLevelFormat function formats a block device to prepare it to hold wear leveled data. It will erase all existing data on the block device.
ECF_ErrorCode ECF_WearLevelFormat(
   struct ECF_BlockDriver *pBlockDriver,
   uint16_t maximumNumberOfBadBlocks,
   uint16_t flags
);
Parameters
pBlockDriver
This is a pointer to the ECF_BlockDriver struct for the block device you want to prepare for wear leveling.
maximumNumberOfBadBlocks
Specifies the maximum number of bad blocks/sectors the device can handle. Set to 0 if you don't want to support bad block handling. Must be 0 if ECF_OPT_SUPPORT_BAD_BLOCK_MANAGEMENT is not defined. ECF_OPT_WEARLEVEL_MAX_BAD_BLOCK_COUNT (default 256) specifices the maximum number of bad blocks EcFAT can handle. maximumNumberOfBadBlocks specifies the maximum number of bad blocks the disc can store.
flags
Options to ECF_WearLevelFormat().
ECF_WEARLEVELFORMAT_BAD_BLOCK_SCAN:
Will scan the device for bad blocks by attempting to write each block. The block driver must report ECFERR_BADBLOCK for blocks that can not be written and that should be marked as bad. Only available if ECF_OPT_SUPPORT_BAD_BLOCKS is defined.
Return value
Returns one of the EcFAT error codes (ECFERR_SUCCESS on success)
Remarks
Wear-leveling is used to even out writes to flash memories. It is useful if you are storing data on a device which only supports a limited write count on each sector and that doesn't have internal wear leveling. This is typical for flash memories. Because of the extra data structures necessary needed to keep track of the block relocation, a wear leveled block device will use around 4-5% of the disk space for internal structures. The low level format will not be FAT compatible although the upper layer will be. This means that you cannot directly read the data from say a PC but converting it from the wear-leveled FAT form to the regular FAT form is fairly easy. ECF_WearLevelFormat will erase all the data on the block device. It needs to be called for an unformatted block device before any of the other block device functions can be called. In a typical case you will call ECF_WearLevelFormat() first followed by optionally ECF_CreatePartitionTable/ECF_CreatePartition and finally ECF_Format for all your partitions. You need to specify ECF_OPT_SUPPORT_WEARLEVEL and ECF_OPT_SUPPORT_FORMAT in your Project.h for EcFAT to compile with support for this function.
See also