41 #define FLAG_FILE_CLOSED 0
42 #define FLAG_FILE_OPEN 1
44 unsigned int filesize;
47 #ifdef CFS_XMEM_CONF_OFFSET
48 #define CFS_XMEM_OFFSET CFS_XMEM_CONF_OFFSET
50 #define CFS_XMEM_OFFSET 0
54 #ifdef CFS_XMEM_CONF_SIZE
55 #define CFS_XMEM_SIZE CFS_XMEM_CONF_SIZE
57 #define CFS_XMEM_SIZE XMEM_ERASE_UNIT_SIZE
60 static struct filestate file;
66 if(file.flag == FLAG_FILE_CLOSED) {
67 file.flag = FLAG_FILE_OPEN;
73 file.fileptr = file.filesize;
77 xmem_erase(CFS_XMEM_SIZE, CFS_XMEM_OFFSET);
89 file.flag = FLAG_FILE_CLOSED;
93 cfs_read(
int f,
void *buf,
unsigned int len)
95 if(file.fileptr + len > CFS_XMEM_SIZE) {
96 len = CFS_XMEM_SIZE - file.fileptr;
99 if(file.fileptr + len > file.filesize) {
100 len = file.filesize - file.fileptr;
104 xmem_pread(buf, len, CFS_XMEM_OFFSET + file.fileptr);
113 cfs_write(
int f,
const void *buf,
unsigned int len)
115 if(file.fileptr >= CFS_XMEM_SIZE) {
118 if(file.fileptr + len > CFS_XMEM_SIZE) {
119 len = CFS_XMEM_SIZE - file.fileptr;
122 if(file.fileptr + len > file.filesize) {
124 file.filesize = file.fileptr + len;
128 xmem_pwrite(buf, len, CFS_XMEM_OFFSET + file.fileptr);
140 if(o > file.filesize) {
152 file.flag = FLAG_FILE_CLOSED;
155 xmem_erase(CFS_XMEM_SIZE, CFS_XMEM_OFFSET);