static int _umount(vfs_mount_t *mountp) { fatfs_desc_t *fs_desc = mountp->private_data; DEBUG("fatfs_vfs.c: _umount: private_data = %p\n", mountp->private_data); char volume_str[FATFS_MAX_VOL_STR_LEN]; snprintf(volume_str, sizeof(volume_str), "%d:/", fs_desc->vol_idx); DEBUG("unmounting file system of volume '%s'\n", volume_str); FRESULT res = f_unmount(volume_str); if (res == FR_OK) { DEBUG("[OK]"); memset(&fs_desc->fat_fs, 0, sizeof(fs_desc->fat_fs)); } else { DEBUG("[ERROR]"); } return fatfs_err_to_errno(res); }
/********************************************************************************************************************* ** Function name: main ** Descriptions: ** Input parameters: ** Output parameters: ** Returned value: ==OS_OK : 操作成功 ** !=OS_OK : 操作失败(包含出错信息) **-------------------------------------------------------------------------------------------------------------------- ** Created by: Fengliang ** Created Date: 2011-5-16 13:23:42 ** Test recorde: **-------------------------------------------------------------------------------------------------------------------- ** Modified by: ** Modified date: ** Test recorde: *********************************************************************************************************************/ int main(int argc, _TCHAR* argv[]) { char aWriteBuffer[] = "精诚服务,真诚永远!——源于China"; /* 文件内容 */ char aReadBuffer[1024]; FATFS fs[1]; /* Work area for logical drives */ FRESULT Status; /* 操作状态 */ FIL SrcFile, DstFile; /* file objects */ UINT ReadCounter, WriteCounter; /* File read counter */ /* * 1) Register work area for each volume (Always succeeds regardless of disk status) */ f_mount(0, &fs[0]); #if 0 f_mkfs(0, 1, 512); #endif /* * 2) 创建目录. */ f_mkdir("0:ChinaOS"); /* * 3) 打开文件 on the drive 0 */ Status = f_open(&SrcFile, "0:hello.txt", FA_OPEN_EXISTING | FA_READ); if (OS_OK != Status) { printf("Could not find the src file\n"); } Status = f_open(&DstFile, "0:ChinaOS中国操作系统.txt", FA_CREATE_ALWAYS | FA_WRITE); if (OS_OK != Status) { printf("Could not find the dest file\n"); } /* * 4) 复制文件数据. */ while (1) { Status = f_read(&SrcFile, aReadBuffer, sizeof(aReadBuffer), &ReadCounter); if (OS_OK != Status || ReadCounter == 0) { break; /* error or eof */ } /* Copy source to destination */ Status = f_write(&DstFile, aReadBuffer, ReadCounter, &WriteCounter); if (OS_OK != Status || WriteCounter < ReadCounter) { break; /* error or disk full */ } } /* * 5) Close open files */ f_close(&SrcFile); f_close(&DstFile); /* * 6) Unregister work area prior to discard it. */ f_unmount(0); return 0; }