add MemFileSystem::dump and MemFileSystem::load

Dependents:   SDFileSystem

Fork of FATFileSystem by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers diskio.cpp Source File

diskio.cpp

00001 /*-----------------------------------------------------------------------*/
00002 /* Low level disk I/O module skeleton for FatFs     (C)ChaN, 2007        */
00003 /*-----------------------------------------------------------------------*/
00004 /* This is a stub disk I/O module that acts as front end of the existing */
00005 /* disk I/O modules and attach it to FatFs module with common interface. */
00006 /*-----------------------------------------------------------------------*/
00007 #include "ffconf.h"
00008 #include "diskio.h"
00009 
00010 #include "mbed_debug.h"
00011 #include "FATFileSystem.h"
00012 
00013 using namespace mbed;
00014 
00015 DSTATUS disk_initialize (
00016     BYTE drv                /* Physical drive nmuber (0..) */
00017 )
00018 {
00019     debug_if(FFS_DBG, "disk_initialize on drv [%d]\n", drv);
00020     return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize();
00021 }
00022 
00023 DSTATUS disk_status (
00024     BYTE drv        /* Physical drive nmuber (0..) */
00025 )
00026 {
00027     debug_if(FFS_DBG, "disk_status on drv [%d]\n", drv);
00028     return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status();
00029 }
00030 
00031 DRESULT disk_read (
00032     BYTE drv,        /* Physical drive nmuber (0..) */
00033     BYTE *buff,        /* Data buffer to store read data */
00034     DWORD sector,    /* Sector address (LBA) */
00035     BYTE count        /* Number of sectors to read (1..255) */
00036 )
00037 {
00038     debug_if(FFS_DBG, "disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv);
00039     if (FATFileSystem::_ffs[drv]->disk_read((uint8_t*)buff, sector, count))
00040         return RES_PARERR;
00041     else
00042         return RES_OK;
00043 }
00044 
00045 #if _READONLY == 0
00046 DRESULT disk_write (
00047     BYTE drv,            /* Physical drive nmuber (0..) */
00048     const BYTE *buff,    /* Data to be written */
00049     DWORD sector,        /* Sector address (LBA) */
00050     BYTE count            /* Number of sectors to write (1..255) */
00051 )
00052 {
00053     debug_if(FFS_DBG, "disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
00054     if (FATFileSystem::_ffs[drv]->disk_write((uint8_t*)buff, sector, count))
00055         return RES_PARERR;
00056     else
00057         return RES_OK;
00058 }
00059 #endif /* _READONLY */
00060 
00061 DRESULT disk_ioctl (
00062     BYTE drv,        /* Physical drive nmuber (0..) */
00063     BYTE ctrl,        /* Control code */
00064     void *buff        /* Buffer to send/receive control data */
00065 )
00066 {
00067     debug_if(FFS_DBG, "disk_ioctl(%d)\n", ctrl);
00068     switch(ctrl) {
00069         case CTRL_SYNC:
00070             if(FATFileSystem::_ffs[drv] == NULL) {
00071                 return RES_NOTRDY;
00072             } else if(FATFileSystem::_ffs[drv]->disk_sync()) {
00073                 return RES_ERROR;
00074             }
00075             return RES_OK;
00076         case GET_SECTOR_COUNT:
00077             if(FATFileSystem::_ffs[drv] == NULL) {
00078                 return RES_NOTRDY;
00079             } else {
00080                 DWORD res = FATFileSystem::_ffs[drv]->disk_sectors();
00081                 if(res > 0) {
00082                     *((DWORD*)buff) = res; // minimum allowed
00083                     return RES_OK;
00084                 } else {
00085                     return RES_ERROR;
00086                 }
00087             }
00088         case GET_BLOCK_SIZE:
00089             *((DWORD*)buff) = 1; // default when not known
00090             return RES_OK;
00091 
00092     }
00093     return RES_PARERR;
00094 }