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