1 #include <efs-sdcard.h> 9 process_event_t sdcard_inserted_event;
11 process_event_t sdcard_removed_event;
17 static File file_descriptors[MAX_FDS];
23 for (fd = 0; fd < MAX_FDS; fd++) {
24 if (!file_getAttr(&file_descriptors[fd], FILE_STATUS_OPEN)) {
34 if (!sdcard_ready())
return 0;
35 if (fd >= MAX_FDS || fd < 0)
return NULL;
36 if (!file_getAttr(&file_descriptors[fd], FILE_STATUS_OPEN))
return NULL;
37 return &file_descriptors[fd];
43 static int initialized = 0;
49 for (fd = 0; fd < MAX_FDS; fd++) {
50 file_setAttr(&file_descriptors[fd], FILE_STATUS_OPEN,0);
53 if (!sdcard_ready())
return -1;
55 if (fd < 0)
return -1;
61 if (file_fopen(&file_descriptors[fd], efs_sdcard_get_fs(),
62 (
char*)name, mode) < 0) {
71 File *file = get_file(fd);
74 fs_flushFs(efs_sdcard_get_fs());
80 File *file = get_file(fd);
82 return file_read(file, len, (euint8*)buf);
86 cfs_write (
int fd,
const void *buf,
unsigned int len)
88 File *file = get_file(fd);
90 return file_write(file, len, (euint8*)buf);
94 cfs_seek (
int fd, cfs_offset_t offset,
int whence)
100 if (file_setpos(file, offset) != 0)
return -1;
101 return file->FilePtr;
107 #define COMPILE_TIME_CHECK(expr) \ 108 (void) (__builtin_choose_expr ((expr), 0, ((void)0))+3) 110 #define COMPILE_TIME_CHECK(expr) 113 #define MAX_DIR_LISTS 4 114 DirList dir_lists[MAX_DIR_LISTS];
120 for(l = 0; l < MAX_DIR_LISTS; l++) {
121 if (dir_lists[l].fs == NULL) {
122 return &dir_lists[l];
132 COMPILE_TIME_CHECK(
sizeof(DirList*) <=
sizeof(
struct cfs_dir));
133 if (!sdcard_ready())
return -1;
134 dirs = find_free_dir_list();
135 if (!dirs)
return -1;
136 if (ls_openDir(dirs, efs_sdcard_get_fs(), (eint8*)name) != 0) {
140 *(DirList**)dirp = dirs;
149 char *to = dirent->name;
150 DirList *dirs = *(DirList**)dirp;
151 if (!sdcard_ready())
return 1;
152 if (ls_getNext(dirs) != 0)
return 1;
153 start = dirs->currentEntry.FileName;
165 start = dirs->currentEntry.FileName + 8;
170 while(start < end && *start >
' ') {
175 if (dirs->currentEntry.Attribute & ATTR_DIRECTORY) {
178 dirent->size = dirs->currentEntry.FileSize;
186 (*(DirList**)dirp)->fs = NULL;
int cfs_open(const char *name, int flags)
Open a file.
static void start(void)
Start measurement.
cfs_offset_t cfs_seek(int fd, cfs_offset_t offset, int whence)
Seek to a specified position in an open file.
int cfs_write(int fd, const void *buf, unsigned int len)
Write data to an open file.
Header file for the Contiki process interface.
int cfs_opendir(struct cfs_dir *dirp, const char *name)
Open a directory for reading directory entries.
void cfs_close(int fd)
Close an open file.
int cfs_readdir(struct cfs_dir *dirp, struct cfs_dirent *dirent)
Read a directory entry.
int cfs_read(int fd, void *buf, unsigned int len)
Read data from an open file.
#define CFS_READ
Specify that cfs_open() should open a file for reading.
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
void cfs_closedir(struct cfs_dir *dirp)
Close a directory opened with cfs_opendir().