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