The f_mount fucntion registers/unregisters filesystem object to the FatFs module.
FRESULT f_mount ( FATFS* fs, /* [IN] Filesystem object */ const TCHAR* path, /* [IN] Logical drive number */ BYTE opt /* [IN] Initialization option */ );
FR_OK, FR_INVALID_DRIVE, FR_DISK_ERR, FR_NOT_READY, FR_NOT_ENABLED, FR_NO_FILESYSTEM
FatFs needs work area (filesystem object) for each logical drives (FAT volumes). Prior to perform file/directory operations, a filesystem object needs to be registered with f_mount function to the logical drive. The file/directory API functions get ready to work after this procedure. If there is any open object of file or directory on the logical drive, the object will be invalidated by this function.
The f_mount function registers/unregisters a filesystem object to the FatFs module as follows:
If forced mounting is not specified (opt = 0), this function always succeeds regardless of the physical drive status. It only clears (de-initializes) the given work area and registers its address to the internal table and no activity of the physical drive in this function. To unregister the work area, specify a NULL to the fs, and then the work area can be discarded. The volume mount processes, initialize the corresponding physical drive, find the FAT volume in it and then initialize the work area, is performed in the subsequent file/directory functions when either of following conditions is true.
If the function with forced mounting (opt = 1) failed, it means that the filesystem object has been registered successfully but the volume is currently not ready to work. The volume mount process will be attempted at subsequent file/directroy functions if the filesystem object is not initialized. (delayed mounting)
If implementation of the disk I/O layer lacks asynchronous media change detection, application program needs to perform f_mount function after each media change to force cleared the filesystem object.
Always available.
int main (void) { FATFS *fs; /* Ponter to the filesystem object */ fs = malloc(sizeof (FATFS)); /* Get work area for the volume */ f_mount(fs, "", 0); /* Mount the default drive */ f_open(... /* Here any file API can be used */ ... f_mount(fs, "", 0); /* Re-mount the default drive to reinitialize the filesystem */ ... f_mount(0, "", 0); /* Unmount the default drive */ free(fs); /* Here the work area can be discarded */ ... }