Example SDFileSystem in which FATDirHandle exposes the file info struct of the current file/directory.

Committer:
uci1
Date:
Wed Sep 04 00:32:19 2013 +0000
Revision:
0:687056ba3278
Example SDFileSystem with FATDirHandle exposing the file info structure

Who changed what in which revision?

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