Uses a more recent version of official mbed libraries than that of Neil Thiessen

Dependencies:   FATFileSystem

Dependents:   ThermalWake STM32F407VET6_SDCard STM32F407VET6_SD_HTTP_Server ZZ_SSL_Main_L476 ... more

Fork of SDFileSystem by Neil Thiessen

Committer:
neilt6
Date:
Thu Aug 14 22:27:07 2014 +0000
Revision:
11:67ddc53e3983
Major performance improvements with custom FATFileSystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
neilt6 11:67ddc53e3983 1 /* mbed Microcontroller Library
neilt6 11:67ddc53e3983 2 * Copyright (c) 2006-2012 ARM Limited
neilt6 11:67ddc53e3983 3 *
neilt6 11:67ddc53e3983 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
neilt6 11:67ddc53e3983 5 * of this software and associated documentation files (the "Software"), to deal
neilt6 11:67ddc53e3983 6 * in the Software without restriction, including without limitation the rights
neilt6 11:67ddc53e3983 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
neilt6 11:67ddc53e3983 8 * copies of the Software, and to permit persons to whom the Software is
neilt6 11:67ddc53e3983 9 * furnished to do so, subject to the following conditions:
neilt6 11:67ddc53e3983 10 *
neilt6 11:67ddc53e3983 11 * The above copyright notice and this permission notice shall be included in
neilt6 11:67ddc53e3983 12 * all copies or substantial portions of the Software.
neilt6 11:67ddc53e3983 13 *
neilt6 11:67ddc53e3983 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
neilt6 11:67ddc53e3983 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
neilt6 11:67ddc53e3983 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
neilt6 11:67ddc53e3983 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
neilt6 11:67ddc53e3983 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
neilt6 11:67ddc53e3983 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
neilt6 11:67ddc53e3983 20 * SOFTWARE.
neilt6 11:67ddc53e3983 21 */
neilt6 11:67ddc53e3983 22 #include <string.h>
neilt6 11:67ddc53e3983 23 #include "ff.h"
neilt6 11:67ddc53e3983 24 #include "FATDirHandle.h"
neilt6 11:67ddc53e3983 25
neilt6 11:67ddc53e3983 26 using namespace mbed;
neilt6 11:67ddc53e3983 27
neilt6 11:67ddc53e3983 28 FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) {
neilt6 11:67ddc53e3983 29 dir = the_dir;
neilt6 11:67ddc53e3983 30 }
neilt6 11:67ddc53e3983 31
neilt6 11:67ddc53e3983 32 int FATDirHandle::closedir() {
neilt6 11:67ddc53e3983 33 delete this;
neilt6 11:67ddc53e3983 34 return 0;
neilt6 11:67ddc53e3983 35 }
neilt6 11:67ddc53e3983 36
neilt6 11:67ddc53e3983 37 struct dirent *FATDirHandle::readdir() {
neilt6 11:67ddc53e3983 38 FILINFO finfo;
neilt6 11:67ddc53e3983 39
neilt6 11:67ddc53e3983 40 #if _USE_LFN
neilt6 11:67ddc53e3983 41 finfo.lfname = cur_entry.d_name;
neilt6 11:67ddc53e3983 42 finfo.lfsize = sizeof(cur_entry.d_name);
neilt6 11:67ddc53e3983 43 #endif // _USE_LFN
neilt6 11:67ddc53e3983 44
neilt6 11:67ddc53e3983 45 FRESULT res = f_readdir(&dir, &finfo);
neilt6 11:67ddc53e3983 46
neilt6 11:67ddc53e3983 47 #if _USE_LFN
neilt6 11:67ddc53e3983 48 if(res != 0 || finfo.fname[0]==0) {
neilt6 11:67ddc53e3983 49 return NULL;
neilt6 11:67ddc53e3983 50 } else {
neilt6 11:67ddc53e3983 51 if(cur_entry.d_name[0]==0) {
neilt6 11:67ddc53e3983 52 // No long filename so use short filename.
neilt6 11:67ddc53e3983 53 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
neilt6 11:67ddc53e3983 54 }
neilt6 11:67ddc53e3983 55 return &cur_entry;
neilt6 11:67ddc53e3983 56 }
neilt6 11:67ddc53e3983 57 #else
neilt6 11:67ddc53e3983 58 if(res != 0 || finfo.fname[0]==0) {
neilt6 11:67ddc53e3983 59 return NULL;
neilt6 11:67ddc53e3983 60 } else {
neilt6 11:67ddc53e3983 61 memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname));
neilt6 11:67ddc53e3983 62 return &cur_entry;
neilt6 11:67ddc53e3983 63 }
neilt6 11:67ddc53e3983 64 #endif /* _USE_LFN */
neilt6 11:67ddc53e3983 65 }
neilt6 11:67ddc53e3983 66
neilt6 11:67ddc53e3983 67 void FATDirHandle::rewinddir() {
neilt6 11:67ddc53e3983 68 dir.index = 0;
neilt6 11:67ddc53e3983 69 }
neilt6 11:67ddc53e3983 70
neilt6 11:67ddc53e3983 71 off_t FATDirHandle::telldir() {
neilt6 11:67ddc53e3983 72 return dir.index;
neilt6 11:67ddc53e3983 73 }
neilt6 11:67ddc53e3983 74
neilt6 11:67ddc53e3983 75 void FATDirHandle::seekdir(off_t location) {
neilt6 11:67ddc53e3983 76 dir.index = location;
neilt6 11:67ddc53e3983 77 }
neilt6 11:67ddc53e3983 78