f_mount

The f_mount fucntion gives work area to the FatFs module.

FRESULT f_mount (
  FATFS*       fs,    /* [IN] Filesystem object */
  const TCHAR* path,  /* [IN] Logical drive number */
  BYTE         opt    /* [IN] Initialization option */
);
FRESULT f_unmount (
  const TCHAR* path   /* [IN] Logical drive number */
);

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 requires work area (filesystem object) for each logical drives (FAT volumes). Prior to perform any file/directory operations, a filesystem object needs to be registered with f_mount function for the logical drive. The file/directory API functions get ready to work after this procedure. Some volume management functions, f_mkfs, f_fdisk and f_setcp, do not want a filesystem object.

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 there is any open object of file or directory on the logical drive, the object will be invalidated by this function.

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. The volume mount process will be attempted on subsequent file/directroy function if the filesystem object is not initialized. (delayed mounting) 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 with FR_NOT_READY, 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 on subsequent file/directroy function.

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.

To unregister the work area, specify a NULL to the fs, and then the work area can be discarded. f_unmount function is implemented as a macro.

#define f_unmount(path) f_mount(0, path, 0)

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