You are currently viewing the documentation for:
ECF_Mount
The ECF_Mount function mounts a file system.
ECF_ErrorCode ECF_Mount(
   char driveLetter,
   struct ECF_BlockDriver *pBlockDriver,
   uint16_t flags
);
Parameters
driveLetter
This is the drive letter you want to use to refer to this file system. E.g. 'A'
pBlockDriver
This is a pointer to the ECF_BlockDriver struct that allows the file system to access your block device.
flags
These are flags specifying which partition to mount.
ECF_MOUNT_PARTITION_AUTO:
Attempts to mount partition 1 if a partition table exists but will mount partitionless if not. This is the default and recommended for most applications.
ECF_MOUNT_PARTITION1:
Mounts partition 1 on the block device. This is usually the case for mounting an SD Card.
ECF_MOUNT_PARTITION2:
Mounts partition 2 on the block device.
ECF_MOUNT_PARTITION3:
Mounts partition 3 on the block device.
ECF_MOUNT_PARTITION4:
Mounts partition 4 on the block device.
ECF_MOUNT_PARTITIONLESS:
Mounts a block device that does not contain a partition table. This is usually the case when mounting a block device that resides on an embedded flash.
ECF_MOUNT_JOURNAL:
Activates journaling for the mounted partition. Activating journaling will auto-create the necessary JOURNAL.ECF file in the root folder automatically.
Return value
Returns one of the EcFAT error codes (ECFERR_SUCCESS on success)
Remarks
This must be called before accessing files on the disk.
Example Code
#include <stdio.h>
#include <EcFAT/EcFAT.h>

// Use this buffer as a 32kb RAM Disk
uint8_t abRamDisk[64][512];

ECF_ErrorCode RamDriver_ReadSector(
   struct ECF_BlockDriver *, 
   uint32_t dwSector, 
   uint8_t *pbData)
{
   memcpy(pbData, abRamDisk[dwSector], 512);
   return ECFERR_SUCCESS;
}

ECF_ErrorCode RamDriver_WriteSector(
   struct ECF_BlockDriver *,
   uint32_t dwSector, 
   uint8_t *pbData)
{
   memcpy(abRamDisk[dwSector], pbData, 512);
   return ECFERR_SUCCESS;
}

ECF_ErrorCode RamDriver_GetVolumeInformation(
   struct ECF_BlockDriver *,
   uint16_t*  pwSectorSize,
   uint32_t* pdwNumberOfSectors)
{
   *pwSectorSize = 512;
   *pdwNumberOfSectors = 64;
   return ECFERR_SUCCESS;
}

int main(int argc, char **argv)
{
   struct ECF_BlockDriver bd;
   ECF_ErrorCode err;

   ECF_Init();

   memset(&bd, 0, sizeof(bd));
   bd.m_fnReadSector = RamDriver_ReadSector;
   bd.m_fnWriteSector = RamDriver_WriteSector;
   bd.m_fnGetVolumeInformation = RamDriver_GetVolumeInformation;

   err = ECF_Format(&bd, ECF_CLUSTERSIZE_AUTO, ECF_FORMAT_QUICK);
   if(err != ECFERR_SUCCESS) {
      printf("Block device could not be formatted. Error: %s\r\n",
        ECF_GetErrorMessage(err));
      return 1;
   }

   err = ECF_Mount('A', &bd, ECF_MOUNT_PARTITION_AUTO); 
   if(err != ECFERR_SUCCESS) {
      printf("Block device could not be mounted. Error: %s\r\n",
   ECF_GetErrorMessage(err));
      return 1;
   }


   // ... Read or write some files to the disk ...
   err = ECF_Unmount('A');
   if(err != ECFERR_SUCCESS) {
      printf("Block device could not be unmounted. Error: %s\r\n",
   ECF_GetErrorMessage(err));
      return 1;
   }
}
         
See also