ahmed ahmed
/
samir2_alti_logger
dd
FileSystem/FatFileSystem/FATDirHandle.cpp@0:caecb0d1e7d3, 2015-04-08 (annotated)
- Committer:
- pfe
- Date:
- Wed Apr 08 08:27:55 2015 +0000
- Revision:
- 0:caecb0d1e7d3
ddd
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pfe | 0:caecb0d1e7d3 | 1 | /* mbed Microcontroller Library - FATDirHandle |
pfe | 0:caecb0d1e7d3 | 2 | * Copyright (c) 2008, sford |
pfe | 0:caecb0d1e7d3 | 3 | */ |
pfe | 0:caecb0d1e7d3 | 4 | |
pfe | 0:caecb0d1e7d3 | 5 | #include <stdio.h> |
pfe | 0:caecb0d1e7d3 | 6 | #include <stdlib.h> |
pfe | 0:caecb0d1e7d3 | 7 | #include <string.h> |
pfe | 0:caecb0d1e7d3 | 8 | #include "ff.h" |
pfe | 0:caecb0d1e7d3 | 9 | #include "FATDirHandle.h" |
pfe | 0:caecb0d1e7d3 | 10 | #include "FATFileSystem.h" |
pfe | 0:caecb0d1e7d3 | 11 | |
pfe | 0:caecb0d1e7d3 | 12 | namespace mbed { |
pfe | 0:caecb0d1e7d3 | 13 | |
pfe | 0:caecb0d1e7d3 | 14 | FATDirHandle::FATDirHandle(const FATFS_DIR &the_dir) { |
pfe | 0:caecb0d1e7d3 | 15 | dir = the_dir; |
pfe | 0:caecb0d1e7d3 | 16 | } |
pfe | 0:caecb0d1e7d3 | 17 | |
pfe | 0:caecb0d1e7d3 | 18 | int FATDirHandle::closedir() { |
pfe | 0:caecb0d1e7d3 | 19 | delete this; |
pfe | 0:caecb0d1e7d3 | 20 | return 0; |
pfe | 0:caecb0d1e7d3 | 21 | } |
pfe | 0:caecb0d1e7d3 | 22 | |
pfe | 0:caecb0d1e7d3 | 23 | struct dirent *FATDirHandle::readdir() { |
pfe | 0:caecb0d1e7d3 | 24 | FILINFO finfo; |
pfe | 0:caecb0d1e7d3 | 25 | |
pfe | 0:caecb0d1e7d3 | 26 | #if _USE_LFN |
pfe | 0:caecb0d1e7d3 | 27 | finfo.lfname = cur_entry.d_name; |
pfe | 0:caecb0d1e7d3 | 28 | finfo.lfsize = sizeof(cur_entry.d_name); |
pfe | 0:caecb0d1e7d3 | 29 | #endif // _USE_LFN |
pfe | 0:caecb0d1e7d3 | 30 | |
pfe | 0:caecb0d1e7d3 | 31 | FRESULT res = f_readdir(&dir, &finfo); |
pfe | 0:caecb0d1e7d3 | 32 | |
pfe | 0:caecb0d1e7d3 | 33 | #if _USE_LFN |
pfe | 0:caecb0d1e7d3 | 34 | if(res != 0 || finfo.fname[0]==0) { |
pfe | 0:caecb0d1e7d3 | 35 | return NULL; |
pfe | 0:caecb0d1e7d3 | 36 | } else { |
pfe | 0:caecb0d1e7d3 | 37 | if(cur_entry.d_name[0]==0) { |
pfe | 0:caecb0d1e7d3 | 38 | // No long filename so use short filename. |
pfe | 0:caecb0d1e7d3 | 39 | memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); |
pfe | 0:caecb0d1e7d3 | 40 | } |
pfe | 0:caecb0d1e7d3 | 41 | return &cur_entry; |
pfe | 0:caecb0d1e7d3 | 42 | } |
pfe | 0:caecb0d1e7d3 | 43 | #else |
pfe | 0:caecb0d1e7d3 | 44 | if(res != 0 || finfo.fname[0]==0) { |
pfe | 0:caecb0d1e7d3 | 45 | return NULL; |
pfe | 0:caecb0d1e7d3 | 46 | } else { |
pfe | 0:caecb0d1e7d3 | 47 | memcpy(cur_entry.d_name, finfo.fname, sizeof(finfo.fname)); |
pfe | 0:caecb0d1e7d3 | 48 | return &cur_entry; |
pfe | 0:caecb0d1e7d3 | 49 | } |
pfe | 0:caecb0d1e7d3 | 50 | #endif /* _USE_LFN */ |
pfe | 0:caecb0d1e7d3 | 51 | } |
pfe | 0:caecb0d1e7d3 | 52 | |
pfe | 0:caecb0d1e7d3 | 53 | void FATDirHandle::rewinddir() { |
pfe | 0:caecb0d1e7d3 | 54 | dir.index = 0; |
pfe | 0:caecb0d1e7d3 | 55 | } |
pfe | 0:caecb0d1e7d3 | 56 | |
pfe | 0:caecb0d1e7d3 | 57 | off_t FATDirHandle::telldir() { |
pfe | 0:caecb0d1e7d3 | 58 | return dir.index; |
pfe | 0:caecb0d1e7d3 | 59 | } |
pfe | 0:caecb0d1e7d3 | 60 | |
pfe | 0:caecb0d1e7d3 | 61 | void FATDirHandle::seekdir(off_t location) { |
pfe | 0:caecb0d1e7d3 | 62 | dir.index = location; |
pfe | 0:caecb0d1e7d3 | 63 | } |
pfe | 0:caecb0d1e7d3 | 64 | |
pfe | 0:caecb0d1e7d3 | 65 | } |
pfe | 0:caecb0d1e7d3 | 66 |