33 #include "lib/simEnvChange.h"
36 #define FLAG_FILE_CLOSED 0
37 #define FLAG_FILE_OPEN 1
46 static struct filestate file;
48 const struct simInterface cfs_interface;
51 #define CFS_BUF_SIZE 4000
52 char simCFSData[CFS_BUF_SIZE] = { 0 };
53 char simCFSChanged = 0;
55 int simCFSWritten = 0;
61 if(file.flag == FLAG_FILE_CLOSED) {
62 file.flag = FLAG_FILE_OPEN;
65 file.fileptr = file.endptr;
78 file.flag = FLAG_FILE_CLOSED;
82 cfs_read(
int f,
void *buf,
unsigned int len)
84 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_READ) {
85 if(file.fileptr + len >= file.endptr) {
86 len = file.endptr - file.fileptr;
88 memcpy(buf, &simCFSData[file.fileptr], len);
99 cfs_write(
int f,
const void *buf,
unsigned int len)
101 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_WRITE) {
102 if(file.fileptr + len > CFS_BUF_SIZE) {
103 len = CFS_BUF_SIZE - file.fileptr;
104 printf(
"cfs-cooja.c: warning: write truncated\n");
106 memcpy(&simCFSData[file.fileptr], buf, len);
109 simCFSWritten += len;
110 if(file.fileptr > file.endptr) {
111 file.endptr = file.fileptr;
122 if(file.flag == FLAG_FILE_OPEN) {
128 file.fileptr = file.endptr + o;
130 if(file.fileptr >= 0 && file.fileptr <= CFS_BUF_SIZE) {
131 if(file.fileptr > file.endptr) {
132 file.endptr = file.fileptr;
143 memset(simCFSData, 0,
sizeof(simCFSData));
165 doInterfaceActionsBeforeTick(
void)
170 doInterfaceActionsAfterTick(
void)
174 SIM_INTERFACE(cfs_interface,
175 doInterfaceActionsBeforeTick,
176 doInterfaceActionsAfterTick);
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 CFS_SEEK_CUR
Specify that cfs_seek() should compute the offset from the current position of the file pointer...
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
#define CFS_SEEK_END
Specify that cfs_seek() should compute the offset from the end of the file.
#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.
#define CFS_APPEND
Specify that cfs_open() should append written data to the file rather than overwriting it...
int cfs_remove(const char *name)
Remove a file.
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. ...
void cfs_close(int fd)
Close an open file.