Fork of FATFileSystem that exposes FILINFO in the FATDirHandle. This allows obtaining true file sizes and testing whether a dir pointer is a directory or a file.

Dependents:   SDFileSystemNoStall

Fork of FATFileSystem by mbed official

Committer:
uci1
Date:
Thu Oct 30 07:01:15 2014 +0000
Revision:
6:7a3c53d25d96
Parent:
5:f40c1ca31913
Revert the fat file system back to that from 17 Mar 2014 so that it works with the SD card library, and add again the exposing of FILINFO to FATDirHandle

Who changed what in which revision?

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