-- CHANGED -- To stop compilation errors I changed all *.c files to *.cpp. I have not tested this to see if it actually works. --- Updated FAT File System driver. Features include: * Updated to R0.09 - Sep 06, 2011 [[http://elm-chan.org/fsw/ff/00index_e.html]] * Bug fixes from Stéphane Bausseron ** [[http://mbed.org/forum/mbed/topic/2273/?page=1#comment-11521]] ** [[http://mbed.org/forum/mbed/topic/2307]] * Long filename support enabled and exposed through mbed SDK.

Dependents:   WAVEplayer_fix

Fork of FatFileSystem by Adam Green

Committer:
bridadan
Date:
Mon Feb 09 16:02:31 2015 +0000
Revision:
1:8263aa1f626a
Parent:
0:6ceefe1c53e4
Attempting to fix program for K64F platform.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AdamGreen 0:6ceefe1c53e4 1 /* mbed Microcontroller Library - FATDirHandle
AdamGreen 0:6ceefe1c53e4 2 * Copyright (c) 2008, sford
AdamGreen 0:6ceefe1c53e4 3 */
AdamGreen 0:6ceefe1c53e4 4
AdamGreen 0:6ceefe1c53e4 5 #include <stdio.h>
AdamGreen 0:6ceefe1c53e4 6 #include <stdlib.h>
AdamGreen 0:6ceefe1c53e4 7 #include <string.h>
AdamGreen 0:6ceefe1c53e4 8 #include "ff.h"
AdamGreen 0:6ceefe1c53e4 9 #include "FATDirHandle.h"
AdamGreen 0:6ceefe1c53e4 10 #include "FATFileSystem.h"
AdamGreen 0:6ceefe1c53e4 11
AdamGreen 0:6ceefe1c53e4 12 namespace mbed {
AdamGreen 0:6ceefe1c53e4 13
AdamGreen 0:6ceefe1c53e4 14 FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) {
AdamGreen 0:6ceefe1c53e4 15 dir = the_dir;
AdamGreen 0:6ceefe1c53e4 16 }
AdamGreen 0:6ceefe1c53e4 17
AdamGreen 0:6ceefe1c53e4 18 int FATDirHandle::closedir() {
AdamGreen 0:6ceefe1c53e4 19 delete this;
AdamGreen 0:6ceefe1c53e4 20 return 0;
AdamGreen 0:6ceefe1c53e4 21 }
AdamGreen 0:6ceefe1c53e4 22
AdamGreen 0:6ceefe1c53e4 23 struct dirent *FATDirHandle::readdir() {
AdamGreen 0:6ceefe1c53e4 24 FILINFO finfo;
AdamGreen 0:6ceefe1c53e4 25
AdamGreen 0:6ceefe1c53e4 26 #if _USE_LFN
AdamGreen 0:6ceefe1c53e4 27 finfo.lfname = cur_entry.d_name;
AdamGreen 0:6ceefe1c53e4 28 finfo.lfsize = sizeof(cur_entry.d_name);
AdamGreen 0:6ceefe1c53e4 29 #endif // _USE_LFN
AdamGreen 0:6ceefe1c53e4 30
AdamGreen 0:6ceefe1c53e4 31 FRESULT res = f_readdir(&dir, &finfo);
AdamGreen 0:6ceefe1c53e4 32
AdamGreen 0:6ceefe1c53e4 33 #if _USE_LFN
AdamGreen 0:6ceefe1c53e4 34 if(res != 0 || finfo.fname[0]==0) {
AdamGreen 0:6ceefe1c53e4 35 return NULL;
AdamGreen 0:6ceefe1c53e4 36 } else {
AdamGreen 0:6ceefe1c53e4 37 if(cur_entry.d_name[0]==0) {
AdamGreen 0:6ceefe1c53e4 38 // No long filename so use short filename.
AdamGreen 0:6ceefe1c53e4 39 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
AdamGreen 0:6ceefe1c53e4 40 }
AdamGreen 0:6ceefe1c53e4 41 return &cur_entry;
AdamGreen 0:6ceefe1c53e4 42 }
AdamGreen 0:6ceefe1c53e4 43 #else
AdamGreen 0:6ceefe1c53e4 44 if(res != 0 || finfo.fname[0]==0) {
AdamGreen 0:6ceefe1c53e4 45 return NULL;
AdamGreen 0:6ceefe1c53e4 46 } else {
AdamGreen 0:6ceefe1c53e4 47 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
AdamGreen 0:6ceefe1c53e4 48 return &cur_entry;
AdamGreen 0:6ceefe1c53e4 49 }
AdamGreen 0:6ceefe1c53e4 50 #endif /* _USE_LFN */
AdamGreen 0:6ceefe1c53e4 51 }
AdamGreen 0:6ceefe1c53e4 52
AdamGreen 0:6ceefe1c53e4 53 void FATDirHandle::rewinddir() {
AdamGreen 0:6ceefe1c53e4 54 dir.index = 0;
AdamGreen 0:6ceefe1c53e4 55 }
AdamGreen 0:6ceefe1c53e4 56
AdamGreen 0:6ceefe1c53e4 57 off_t FATDirHandle::telldir() {
AdamGreen 0:6ceefe1c53e4 58 return dir.index;
AdamGreen 0:6ceefe1c53e4 59 }
AdamGreen 0:6ceefe1c53e4 60
AdamGreen 0:6ceefe1c53e4 61 void FATDirHandle::seekdir(off_t location) {
AdamGreen 0:6ceefe1c53e4 62 dir.index = location;
AdamGreen 0:6ceefe1c53e4 63 }
AdamGreen 0:6ceefe1c53e4 64
AdamGreen 0:6ceefe1c53e4 65 }
AdamGreen 0:6ceefe1c53e4 66