You are currently viewing the documentation for:
m_fnTrimSectorRange trims a range of sectors on the block device. By trimming sectors, EcFAT signals that these sectors are not used and does not need to be stored.
ECF_ErrorCode m_fnTrimSectorRange(
   struct ECF_BlockDriver *pBlockDriver,
   uint32_t startSector,
   uint32_t endSector
This is a pointer to the struct ECF_BlockDriver that the function is a member of. It can be used by the block driver to access the m_BlockDriverData member or to call the other functions.
This specifies the first sector to trim.
This specifies the last sector to trim.
Return value
Return ECFERR_SUCCESS if the read was successful. If the trim fails, return one of the EcFAT error codes defined in EcFAT.h. You can also define your own error codes, error no 64 to 127 are reserved for custom block driver errors.
The m_fnTrimSectorRange function is part of struct ECF_BlockDriver. You may supply it when writing a block driver. This function is not mandatory in a block driver and can be NULL. EcFAT will call this function to trim sectors. The purpose of trimming is to tell the block device that a sector is no longer in use. Some block drivers benefit from knowing which sectors are in use by e.g. pre-erasing these sectors or by using the unused storage area for something else. The sector range from and including startSector to and including endSector should be trimmed. That is, m_fnTrimSectorRange(&bd, 5, 7) trims sectors 5, 6 and 7. m_fnTrimSectorRange(&bd, 9, 9) trims sector 9. Since most block drivers will pre-erase a sector when m_fnTrimSectorRange is called, EcFAT will try to call m_fnTrimSectorRange with as large ranges as possible so if the underlying hardware supports erases larger than a sector, it is useful to check the range and see if a more efficient operation can be performed. On both single- and multithreaded systems, EcFAT will make certain that it will not call any of the other BlockDriver functions until this call has been completed so you do not need to implement any locking in the block driver unless it is needed for other purposes.
Example Code

// Assume a flash chip with 1024 pages where there is a page-erase, 
// a block-erase (16 pages on this chip) and a chip-erase.
ECF_ErrorCode FlashDriver_TrimSectorRange(struct ECF_BlockDriver *bd, uint32_t startSector, uint32_t endSector)
   uint32_t sector;

   if(startSector == 0 && endSector == 1023) {
   } else if( (startSector & 0xF) == 0 && (endSector & 0xF) == 0xF) {
      for(sector = startSector;sector <= endSector;sector += 16)
   } else {
      for(sector = startSector;sector <= endSector;sector++)