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