Mark Schwarzer / SDFileSystem

Dependents:   Schwarzer_A7_1

Committer:
markschwarzer
Date:
Mon Nov 09 14:25:13 2020 +0000
Revision:
0:964d386ab059
logged data in SD card

Who changed what in which revision?

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