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