First working version of a FATFileSystem compatible Chan FAT v0.8 implementation. This is intended to use with long file names and RTOS support. For now long file names work but RTOS support is still untested.

Dependents:   USB_MSC USB_CDC_MSD_Hello TFTPServerTest DMXStation ... more

Committer:
NeoBelerophon
Date:
Fri Feb 04 21:14:33 2011 +0000
Revision:
2:629e4be333f3
Parent:
0:8ea634413549
getdir() did not work -> remove

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NeoBelerophon 0:8ea634413549 1 /* mbed Microcontroller Library - FATDirHandle
NeoBelerophon 0:8ea634413549 2 * Copyright (c) 2008, sford
NeoBelerophon 0:8ea634413549 3 */
NeoBelerophon 0:8ea634413549 4
NeoBelerophon 0:8ea634413549 5 #include <stdio.h>
NeoBelerophon 0:8ea634413549 6 #include <stdlib.h>
NeoBelerophon 0:8ea634413549 7 #include <string.h>
NeoBelerophon 0:8ea634413549 8 #include "ff.h"
NeoBelerophon 0:8ea634413549 9 #include "FATDirHandle.h"
NeoBelerophon 0:8ea634413549 10 #include "FATFileSystem.h"
NeoBelerophon 0:8ea634413549 11
NeoBelerophon 0:8ea634413549 12 namespace mbed {
NeoBelerophon 0:8ea634413549 13
NeoBelerophon 0:8ea634413549 14 FATDirHandle::FATDirHandle(const DIR_t &the_dir) {
NeoBelerophon 0:8ea634413549 15 dir = the_dir;
NeoBelerophon 0:8ea634413549 16 }
NeoBelerophon 0:8ea634413549 17
NeoBelerophon 0:8ea634413549 18 int FATDirHandle::closedir() {
NeoBelerophon 0:8ea634413549 19 delete this;
NeoBelerophon 0:8ea634413549 20 return 0;
NeoBelerophon 0:8ea634413549 21 }
NeoBelerophon 0:8ea634413549 22
NeoBelerophon 0:8ea634413549 23 struct dirent *FATDirHandle::readdir() {
NeoBelerophon 0:8ea634413549 24 FILINFO finfo;
NeoBelerophon 0:8ea634413549 25 #if _USE_LFN
NeoBelerophon 0:8ea634413549 26 static char lfn[_MAX_LFN * (_LFN_UNICODE ? 2 : 1) + 1];
NeoBelerophon 0:8ea634413549 27 finfo.lfname = lfn;
NeoBelerophon 0:8ea634413549 28 finfo.lfsize = sizeof(lfn);
NeoBelerophon 0:8ea634413549 29 #endif
NeoBelerophon 0:8ea634413549 30 FRESULT res = f_readdir(&dir, &finfo);
NeoBelerophon 0:8ea634413549 31 if(res != 0 || finfo.fname[0]==0) {
NeoBelerophon 0:8ea634413549 32 return NULL;
NeoBelerophon 0:8ea634413549 33 } else {
NeoBelerophon 0:8ea634413549 34 char* fn;
NeoBelerophon 0:8ea634413549 35 int stringSize = 0;
NeoBelerophon 0:8ea634413549 36 #if _USE_LFN
NeoBelerophon 0:8ea634413549 37 fn = *finfo.lfname ? finfo.lfname : finfo.fname;
NeoBelerophon 0:8ea634413549 38 stringSize = finfo.lfsize;
NeoBelerophon 0:8ea634413549 39 #else
NeoBelerophon 0:8ea634413549 40 fn = fno.fname;
NeoBelerophon 0:8ea634413549 41 stringSize = sizeof(finfo.fname);
NeoBelerophon 0:8ea634413549 42 #endif
NeoBelerophon 0:8ea634413549 43 memcpy(cur_entry.d_name, fn, stringSize);
NeoBelerophon 0:8ea634413549 44 return &cur_entry;
NeoBelerophon 0:8ea634413549 45 }
NeoBelerophon 0:8ea634413549 46 }
NeoBelerophon 0:8ea634413549 47
NeoBelerophon 0:8ea634413549 48 void FATDirHandle::rewinddir() {
NeoBelerophon 0:8ea634413549 49 dir.index = 0;
NeoBelerophon 0:8ea634413549 50 }
NeoBelerophon 0:8ea634413549 51
NeoBelerophon 0:8ea634413549 52 off_t FATDirHandle::telldir() {
NeoBelerophon 0:8ea634413549 53 return dir.index;
NeoBelerophon 0:8ea634413549 54 }
NeoBelerophon 0:8ea634413549 55
NeoBelerophon 0:8ea634413549 56 void FATDirHandle::seekdir(off_t location) {
NeoBelerophon 0:8ea634413549 57 dir.index = location;
NeoBelerophon 0:8ea634413549 58 }
NeoBelerophon 0:8ea634413549 59
NeoBelerophon 0:8ea634413549 60 }
NeoBelerophon 0:8ea634413549 61