f_mount

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 */
);

Parameters

fs
Pointer to the filesystem object to be registered and cleared. Null pointer unregisters the registered filesystem object.
path
Pointer to the null-terminated string that specifies the logical drive. The string without drive number means the default drive.
opt
Mounting option. 0: Do not mount now (to be mounted on the first access to the volume), 1: Force mounted the volume to check if it is ready to work.

Return Values

FR_OK, FR_INVALID_DRIVE, FR_DISK_ERR, FR_NOT_READY, FR_NOT_ENABLED, FR_NO_FILESYSTEM

Description

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:

  1. Determines the logical drive which specified by path.
  2. Clears and unregisters the regsitered work area of the volume if exist.
  3. Clears and registers the new work area to the volume if fs is not NULL.
  4. Performs volume mount process to the volume if forced mounting is specified.

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.

QuickInfo

Always available.

Example

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 */

    ...
}

See Also

f_open, FATFS

Return