36#define FLAG_FILE_CLOSED 0
37#define FLAG_FILE_OPEN 1
46static struct filestate file;
49#define CFS_BUF_SIZE 4000
50char simCFSData[CFS_BUF_SIZE] = { 0 };
52char simCFSChanged = 0;
60 if(file.flag == FLAG_FILE_CLOSED) {
61 file.flag = FLAG_FILE_OPEN;
64 file.endptr = simCFSSize;
67 file.fileptr = file.endptr;
81 file.flag = FLAG_FILE_CLOSED;
87 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_READ) {
88 if(file.fileptr + len >= file.endptr) {
89 len = file.endptr - file.fileptr;
91 memcpy(buf, &simCFSData[file.fileptr], len);
104 if(file.flag == FLAG_FILE_OPEN && file.access &
CFS_WRITE) {
105 if(file.fileptr + len > CFS_BUF_SIZE) {
106 len = CFS_BUF_SIZE - file.fileptr;
107 printf(
"cfs-cooja.c: warning: write truncated\n");
109 memcpy(&simCFSData[file.fileptr], buf, len);
112 simCFSWritten += len;
113 if(file.fileptr > file.endptr) {
114 file.endptr = file.fileptr;
116 if(file.fileptr > simCFSSize) {
117 simCFSSize = file.fileptr;
128 if(file.flag == FLAG_FILE_OPEN) {
134 file.fileptr = file.endptr + o;
136 if(file.fileptr >= 0 && file.fileptr <= CFS_BUF_SIZE) {
137 if(file.fileptr > file.endptr) {
138 file.endptr = file.fileptr;
149 memset(simCFSData, 0,
sizeof(simCFSData));
#define CFS_READ
Specify that cfs_open() should open a file for reading.
int cfs_read(int f, void *buf, unsigned int len)
Read data from an open file.
#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.
int cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e)
Read a directory entry.
int cfs_open(const char *n, int f)
Open a file.
#define CFS_SEEK_SET
Specify that cfs_seek() should compute the offset from the beginning of the file.
#define CFS_WRITE
Specify that cfs_open() should open a file for writing.
#define CFS_SEEK_CUR
Specify that cfs_seek() should compute the offset from the current position of the file pointer.
cfs_offset_t cfs_seek(int f, cfs_offset_t o, int w)
Seek to a specified position in an open file.
#define CFS_SEEK_END
Specify that cfs_seek() should compute the offset from the end of the file.
int cfs_write(int f, const void *buf, unsigned int len)
Write data to an open file.
void cfs_closedir(struct cfs_dir *p)
Close a directory opened with cfs_opendir().
void cfs_close(int f)
Close an open file.
int cfs_offset_t
CFS directory entry name length.
int cfs_opendir(struct cfs_dir *p, const char *n)
Open a directory for reading directory entries.