FINAL VERSION

Dependencies:   mbed

Committer:
jamesheavey
Date:
Thu May 09 14:36:51 2019 +0000
Revision:
140:d8634e76ecce
Parent:
129:b47c28c7eaaf
Final Submission. I have read and agreed with Statement of Academic Integrity.

Who changed what in which revision?

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