First working version of a FATFileSystem compatible Chan FAT v0.8 implementation. This is intended to use with long file names and RTOS support. For now long file names work but RTOS support is still untested.

Dependents:   USB_MSC USB_CDC_MSD_Hello TFTPServerTest DMXStation ... more

Committer:
NeoBelerophon
Date:
Fri Feb 04 21:14:33 2011 +0000
Revision:
2:629e4be333f3
Parent:
0:8ea634413549
getdir() did not work -> remove

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NeoBelerophon 0:8ea634413549 1 /*-----------------------------------------------------------------------*/
NeoBelerophon 0:8ea634413549 2 /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2007 */
NeoBelerophon 0:8ea634413549 3 /*-----------------------------------------------------------------------*/
NeoBelerophon 0:8ea634413549 4 /* This is a stub disk I/O module that acts as front end of the existing */
NeoBelerophon 0:8ea634413549 5 /* disk I/O modules and attach it to FatFs module with common interface. */
NeoBelerophon 0:8ea634413549 6 /*-----------------------------------------------------------------------*/
NeoBelerophon 0:8ea634413549 7
NeoBelerophon 0:8ea634413549 8 #include "diskio.h"
NeoBelerophon 0:8ea634413549 9 #include <stdio.h>
NeoBelerophon 0:8ea634413549 10 #include <string.h>
NeoBelerophon 0:8ea634413549 11 #include "FATFileSystem.h"
NeoBelerophon 0:8ea634413549 12
NeoBelerophon 0:8ea634413549 13 #include "mbed.h"
NeoBelerophon 0:8ea634413549 14
NeoBelerophon 0:8ea634413549 15 DSTATUS disk_initialize (
NeoBelerophon 0:8ea634413549 16 BYTE drv /* Physical drive nmuber (0..) */
NeoBelerophon 0:8ea634413549 17 )
NeoBelerophon 0:8ea634413549 18 {
NeoBelerophon 0:8ea634413549 19 FFSDEBUG("disk_initialize on drv [%d]\n", drv);
NeoBelerophon 0:8ea634413549 20 return (DSTATUS)FATFileSystem::_ffs[drv]->disk_initialize();
NeoBelerophon 0:8ea634413549 21 }
NeoBelerophon 0:8ea634413549 22
NeoBelerophon 0:8ea634413549 23 DSTATUS disk_status (
NeoBelerophon 0:8ea634413549 24 BYTE drv /* Physical drive nmuber (0..) */
NeoBelerophon 0:8ea634413549 25 )
NeoBelerophon 0:8ea634413549 26 {
NeoBelerophon 0:8ea634413549 27 FFSDEBUG("disk_status on drv [%d]\n", drv);
NeoBelerophon 0:8ea634413549 28 return (DSTATUS)FATFileSystem::_ffs[drv]->disk_status();
NeoBelerophon 0:8ea634413549 29 }
NeoBelerophon 0:8ea634413549 30
NeoBelerophon 0:8ea634413549 31 DRESULT disk_read (
NeoBelerophon 0:8ea634413549 32 BYTE drv, /* Physical drive nmuber (0..) */
NeoBelerophon 0:8ea634413549 33 BYTE *buff, /* Data buffer to store read data */
NeoBelerophon 0:8ea634413549 34 DWORD sector, /* Sector address (LBA) */
NeoBelerophon 0:8ea634413549 35 BYTE count /* Number of sectors to read (1..255) */
NeoBelerophon 0:8ea634413549 36 )
NeoBelerophon 0:8ea634413549 37 {
NeoBelerophon 0:8ea634413549 38 FFSDEBUG("disk_read(sector %d, count %d) on drv [%d]\n", sector, count, drv);
NeoBelerophon 0:8ea634413549 39 for(int s=sector; s<sector+count; s++) {
NeoBelerophon 0:8ea634413549 40 FFSDEBUG(" disk_read(sector %d)\n", s);
NeoBelerophon 0:8ea634413549 41 int res = FATFileSystem::_ffs[drv]->disk_read((char*)buff, s);
NeoBelerophon 0:8ea634413549 42 if(res) {
NeoBelerophon 0:8ea634413549 43 return RES_PARERR;
NeoBelerophon 0:8ea634413549 44 }
NeoBelerophon 0:8ea634413549 45 buff += 512;
NeoBelerophon 0:8ea634413549 46 }
NeoBelerophon 0:8ea634413549 47 return RES_OK;
NeoBelerophon 0:8ea634413549 48 }
NeoBelerophon 0:8ea634413549 49
NeoBelerophon 0:8ea634413549 50 #if _READONLY == 0
NeoBelerophon 0:8ea634413549 51 DRESULT disk_write (
NeoBelerophon 0:8ea634413549 52 BYTE drv, /* Physical drive nmuber (0..) */
NeoBelerophon 0:8ea634413549 53 const BYTE *buff, /* Data to be written */
NeoBelerophon 0:8ea634413549 54 DWORD sector, /* Sector address (LBA) */
NeoBelerophon 0:8ea634413549 55 BYTE count /* Number of sectors to write (1..255) */
NeoBelerophon 0:8ea634413549 56 )
NeoBelerophon 0:8ea634413549 57 {
NeoBelerophon 0:8ea634413549 58 FFSDEBUG("disk_write(sector %d, count %d) on drv [%d]\n", sector, count, drv);
NeoBelerophon 0:8ea634413549 59 for(int s=sector; s<sector+count; s++) {
NeoBelerophon 0:8ea634413549 60 FFSDEBUG(" disk_write(sector %d)\n", s);
NeoBelerophon 0:8ea634413549 61 int res = FATFileSystem::_ffs[drv]->disk_write((char*)buff, sector);
NeoBelerophon 0:8ea634413549 62 if(res) {
NeoBelerophon 0:8ea634413549 63 return RES_PARERR;
NeoBelerophon 0:8ea634413549 64 }
NeoBelerophon 0:8ea634413549 65 buff += 512;
NeoBelerophon 0:8ea634413549 66 }
NeoBelerophon 0:8ea634413549 67 return RES_OK;
NeoBelerophon 0:8ea634413549 68 }
NeoBelerophon 0:8ea634413549 69 #endif /* _READONLY */
NeoBelerophon 0:8ea634413549 70
NeoBelerophon 0:8ea634413549 71 DRESULT disk_ioctl (
NeoBelerophon 0:8ea634413549 72 BYTE drv, /* Physical drive nmuber (0..) */
NeoBelerophon 0:8ea634413549 73 BYTE ctrl, /* Control code */
NeoBelerophon 0:8ea634413549 74 void *buff /* Buffer to send/receive control data */
NeoBelerophon 0:8ea634413549 75 )
NeoBelerophon 0:8ea634413549 76 {
NeoBelerophon 0:8ea634413549 77 FFSDEBUG("disk_ioctl(%d)\n", ctrl);
NeoBelerophon 0:8ea634413549 78 switch(ctrl) {
NeoBelerophon 0:8ea634413549 79 case CTRL_SYNC:
NeoBelerophon 0:8ea634413549 80 if(FATFileSystem::_ffs[drv] == NULL) {
NeoBelerophon 0:8ea634413549 81 return RES_NOTRDY;
NeoBelerophon 0:8ea634413549 82 } else if(FATFileSystem::_ffs[drv]->disk_sync()) {
NeoBelerophon 0:8ea634413549 83 return RES_ERROR;
NeoBelerophon 0:8ea634413549 84 }
NeoBelerophon 0:8ea634413549 85 return RES_OK;
NeoBelerophon 0:8ea634413549 86 case GET_SECTOR_COUNT:
NeoBelerophon 0:8ea634413549 87 if(FATFileSystem::_ffs[drv] == NULL) {
NeoBelerophon 0:8ea634413549 88 return RES_NOTRDY;
NeoBelerophon 0:8ea634413549 89 } else {
NeoBelerophon 0:8ea634413549 90 int res = FATFileSystem::_ffs[drv]->disk_sectors();
NeoBelerophon 0:8ea634413549 91 if(res > 0) {
NeoBelerophon 0:8ea634413549 92 *((DWORD*)buff) = res; // minimum allowed
NeoBelerophon 0:8ea634413549 93 return RES_OK;
NeoBelerophon 0:8ea634413549 94 } else {
NeoBelerophon 0:8ea634413549 95 return RES_ERROR;
NeoBelerophon 0:8ea634413549 96 }
NeoBelerophon 0:8ea634413549 97 }
NeoBelerophon 0:8ea634413549 98 case GET_BLOCK_SIZE:
NeoBelerophon 0:8ea634413549 99 *((DWORD*)buff) = 1; // default when not known
NeoBelerophon 0:8ea634413549 100 return RES_OK;
NeoBelerophon 0:8ea634413549 101
NeoBelerophon 0:8ea634413549 102 }
NeoBelerophon 0:8ea634413549 103 return RES_PARERR;
NeoBelerophon 0:8ea634413549 104 }
NeoBelerophon 0:8ea634413549 105