34 #include "lib/simEnvChange.h" 37 #define FLAG_FILE_CLOSED 0 38 #define FLAG_FILE_OPEN 1 47 static struct filestate file;
49 const struct simInterface cfs_interface;
52 #define CFS_BUF_SIZE 4000 53 char simCFSData[CFS_BUF_SIZE] = { 0 };
55 char simCFSChanged = 0;
57 int simCFSWritten = 0;
63 if(file.flag == FLAG_FILE_CLOSED) {
64 file.flag = FLAG_FILE_OPEN;
67 file.endptr = simCFSSize;
70 file.fileptr = file.endptr;
84 file.flag = FLAG_FILE_CLOSED;
90 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_READ) {
91 if(file.fileptr + len >= file.endptr) {
92 len = file.endptr - file.fileptr;
94 memcpy(buf, &simCFSData[file.fileptr], len);
107 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_WRITE) {
108 if(file.fileptr + len > CFS_BUF_SIZE) {
109 len = CFS_BUF_SIZE - file.fileptr;
110 printf(
"cfs-cooja.c: warning: write truncated\n");
112 memcpy(&simCFSData[file.fileptr], buf, len);
115 simCFSWritten += len;
116 if(file.fileptr > file.endptr) {
117 file.endptr = file.fileptr;
119 if(file.fileptr > simCFSSize) {
120 simCFSSize = file.fileptr;
131 if(file.flag == FLAG_FILE_OPEN) {
137 file.fileptr = file.endptr + o;
139 if(file.fileptr >= 0 && file.fileptr <= CFS_BUF_SIZE) {
140 if(file.fileptr > file.endptr) {
141 file.endptr = file.fileptr;
152 memset(simCFSData, 0,
sizeof(simCFSData));
174 doInterfaceActionsBeforeTick(
void)
179 doInterfaceActionsAfterTick(
void)
183 SIM_INTERFACE(cfs_interface,
184 doInterfaceActionsBeforeTick,
185 doInterfaceActionsAfterTick);
int cfs_open(const char *n, int f)
Open a file.
int cfs_remove(const char *name)
Remove a file.
cfs_offset_t cfs_seek(int f, cfs_offset_t o, int w)
Seek to a specified position in an open file.
#define CFS_APPEND
Specify that cfs_open() should append written data to the file rather than overwriting it...
int cfs_write(int f, const void *buf, unsigned int len)
Write data to an open file.
int cfs_opendir(struct cfs_dir *p, const char *n)
Open a directory for reading directory entries.
void cfs_close(int f)
Close an open file.
int cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e)
Read a directory entry.
#define CFS_SEEK_END
Specify that cfs_seek() should compute the offset from the end of the file.
int cfs_read(int f, 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_CUR
Specify that cfs_seek() should compute the offset from the current position of the file pointer...
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file. ...
void cfs_closedir(struct cfs_dir *p)
Close a directory opened with cfs_opendir().
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.