1. 程式人生 > >fatfs 學習筆記--f_mount用法

fatfs 學習筆記--f_mount用法

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.

  • Filesystem object has not been initialized. It is de-initialized by f_mount function.
  • Physical drive is not initialized. It is de-initialized by system reset or media removal.

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.