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