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