1 #include <efs-sdcard.h>
5 #include <debug-uart.h>
12 process_event_t sdcard_inserted_event;
14 process_event_t sdcard_removed_event;
16 static struct process *event_process =
NULL;
21 static File file_descriptors[MAX_FDS];
27 for (fd = 0; fd < MAX_FDS; fd++) {
28 if (!file_getAttr(&file_descriptors[fd], FILE_STATUS_OPEN)) {
38 if (!sdcard_ready())
return 0;
39 if (fd >= MAX_FDS || fd < 0)
return NULL;
40 if (!file_getAttr(&file_descriptors[fd], FILE_STATUS_OPEN))
return NULL;
41 return &file_descriptors[fd];
49 if (!sdcard_ready())
return -1;
51 if (fd < 0)
return -1;
57 if (file_fopen(&file_descriptors[fd], &sdcard_efs.myFs,
58 (
char*)name, mode) < 0) {
67 File *file = get_file(fd);
70 fs_flushFs(efs_sdcard_get_fs());
74 cfs_read (
int fd,
void *buf,
unsigned int len)
76 File *file = get_file(fd);
78 return file_read(file, len, (euint8*)buf);
82 cfs_write (
int fd,
const void *buf,
unsigned int len)
84 File *file = get_file(fd);
86 return file_write(file, len, (euint8*)buf);
90 cfs_seek (
int fd, cfs_offset_t offset,
int whence)
96 if (file_setpos(file, offset) != 0)
return -1;
103 #define COMPILE_TIME_CHECK(expr) \
104 (void) (__builtin_choose_expr ((expr), 0, ((void)0))+3)
106 #define COMPILE_TIME_CHECK(expr)
109 #define MAX_DIR_LISTS 4
110 DirList dir_lists[MAX_DIR_LISTS];
116 for(l = 0; l < MAX_DIR_LISTS; l++) {
117 if (dir_lists[l].fs ==
NULL) {
118 return &dir_lists[l];
128 COMPILE_TIME_CHECK(
sizeof(DirList*) <=
sizeof(
struct cfs_dir));
129 if (!sdcard_ready())
return -1;
130 dirs = find_free_dir_list();
131 if (!dirs)
return -1;
132 if (ls_openDir(dirs, efs_sdcard_get_fs(), (eint8*)name) != 0) {
136 *(DirList**)dirp = dirs;
145 char *to = dirent->name;
146 DirList *dirs = *(DirList**)dirp;
147 if (!sdcard_ready())
return 1;
148 if (ls_getNext(dirs) != 0)
return 1;
149 start = dirs->currentEntry.FileName;
161 start = dirs->currentEntry.FileName + 8;
166 while(start < end && *start >
' ') {
171 if (dirs->currentEntry.Attribute & ATTR_DIRECTORY) {
174 dirent->size = dirs->currentEntry.FileSize;
182 (*(DirList**)dirp)->fs =
NULL;