1 #include <efs-sdcard.h> 
    4 #include <debug-uart.h> 
   10 process_event_t sdcard_inserted_event;
 
   12 process_event_t sdcard_removed_event;
 
   18 static File file_descriptors[MAX_FDS];
 
   24   for (fd = 0; fd < MAX_FDS; fd++) {
 
   25     if (!file_getAttr(&file_descriptors[fd], FILE_STATUS_OPEN)) {
 
   35   if (!sdcard_ready()) 
return 0;
 
   36   if (fd >= MAX_FDS || fd < 0) 
return NULL;
 
   37   if (!file_getAttr(&file_descriptors[fd], FILE_STATUS_OPEN)) 
return NULL;
 
   38   return &file_descriptors[fd];
 
   44   static int initialized = 0;
 
   50     for (fd = 0; fd < MAX_FDS; fd++) {
 
   51       file_setAttr(&file_descriptors[fd], FILE_STATUS_OPEN,0);
 
   54   if (!sdcard_ready()) 
return -1;
 
   56   if (fd < 0) 
return -1;
 
   62   if (file_fopen(&file_descriptors[fd], efs_sdcard_get_fs(),
 
   63                  (
char*)name, mode) < 0) {
 
   72   File *file = get_file(fd);
 
   75   fs_flushFs(efs_sdcard_get_fs());
 
   79 cfs_read (
int fd, 
void *buf, 
unsigned int len)
 
   81   File *file = get_file(fd);
 
   83   return file_read(file, len, (euint8*)buf);
 
   87 cfs_write (
int fd, 
const void *buf, 
unsigned int len)
 
   89   File *file = get_file(fd);
 
   91   return file_write(file, len, (euint8*)buf);
 
   95 cfs_seek (
int fd, cfs_offset_t offset, 
int whence)
 
  101   if (file_setpos(file, offset) != 0) 
return -1;
 
  102   return file->FilePtr;
 
  108 #define COMPILE_TIME_CHECK(expr) \ 
  109 (void) (__builtin_choose_expr ((expr), 0, ((void)0))+3) 
  111 #define COMPILE_TIME_CHECK(expr) 
  114 #define MAX_DIR_LISTS 4 
  115 DirList dir_lists[MAX_DIR_LISTS];
 
  121   for(l = 0; l < MAX_DIR_LISTS; l++) {
 
  122     if (dir_lists[l].fs == 
NULL) {
 
  123       return &dir_lists[l];
 
  133   COMPILE_TIME_CHECK(
sizeof(DirList*) <= 
sizeof(
struct cfs_dir));
 
  134   if (!sdcard_ready()) 
return -1;
 
  135   dirs = find_free_dir_list();
 
  136   if (!dirs) 
return -1;
 
  137   if (ls_openDir(dirs, efs_sdcard_get_fs(), (eint8*)name) != 0) {
 
  141   *(DirList**)dirp = dirs;
 
  150   char *to = dirent->name;
 
  151   DirList *dirs = *(DirList**)dirp;
 
  152   if (!sdcard_ready()) 
return 1;
 
  153   if (ls_getNext(dirs) != 0) 
return 1;
 
  154   start = dirs->currentEntry.FileName;
 
  166   start = dirs->currentEntry.FileName + 8;
 
  171     while(start < end && *start > 
' ') {
 
  176   if (dirs->currentEntry.Attribute & ATTR_DIRECTORY) {
 
  179     dirent->size = dirs->currentEntry.FileSize;
 
  187   (*(DirList**)dirp)->fs = 
NULL;
 
int cfs_open(const char *name, int flags)
Open a file. 
 
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file. 
 
#define NULL
The null pointer. 
 
#define CFS_READ
Specify that cfs_open() should open a file for reading. 
 
int cfs_readdir(struct cfs_dir *dir, struct cfs_dirent *record)
Read a directory entry. 
 
void cfs_closedir(struct cfs_dir *dir)
Close a directory opened with cfs_opendir(). 
 
int cfs_opendir(struct cfs_dir *dir, const char *name)
Open a directory for reading directory entries. 
 
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
 
Header file for the Contiki process interface. 
 
void cfs_close(int fd)
Close an open file.