Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor10465531046553 Using Removable Devices Anchor10465541046554µC/FS expects that any call to a function that accesses a removable device may fail, since the device may be removed, powered off or suddenly unresponsive. If µC/FS detects such an event, the device will need to be refreshed or closed and re-opened. FSDev_Refresh() refreshes a device: Anchor10501171050117  

...

rowspan3

...

:

...

...

Anchor10465581046558There are several cases to consider: Anchor10465591046559

...

A device can be refreshed explicitly with FSDev_Refresh(); however, refresh also happens automatically. If a volume access (e.g., FSVol_Fmt(), FSVol_Rd()), entry access (FSEntry_Create(), fs_remove()), file open (fs_fopen() or FSFile_Open()) or directory open (fs_opendir() or FSDir_Open()) is initiated on a device that was not present at the last attempted access, µC/FS attempts to refresh the device information; if that succeeds, it attempts to refresh the volume information.

Anchor10465631046563Files and directories have additional behavior. If a file is opened on a volume, and the underlying device is subsequently removed or changed, all further accesses using the file API (e.g., FSFile_Rd()) will fail with the error code FS_ERR_DEV_CHNGD; all POSIX API functions will return error values. The file should then be closed (to free the file structure). Anchor10465641046564

Similarly, if a directory is opened on a volume, and the underlying device is subsequently removed or changed, all further FSDir_Rd() attempts will fail with the error code FS_ERR_DEV_CHNGD; fs_readdir_r() will return 1. The directory should then be closed (to free the directory structure).