40 #define FLAG_FILE_CLOSED 0
41 #define FLAG_FILE_OPEN 1
43 unsigned int filesize;
46 #ifdef CFS_XMEM_CONF_OFFSET
47 #define CFS_XMEM_OFFSET CFS_XMEM_CONF_OFFSET
49 #define CFS_XMEM_OFFSET 0
53 #ifdef CFS_XMEM_CONF_SIZE
54 #define CFS_XMEM_SIZE CFS_XMEM_CONF_SIZE
56 #define CFS_XMEM_SIZE XMEM_ERASE_UNIT_SIZE
59 static struct filestate file;
65 if(file.flag == FLAG_FILE_CLOSED) {
66 file.flag = FLAG_FILE_OPEN;
72 file.fileptr = file.filesize;
76 xmem_erase(CFS_XMEM_SIZE, CFS_XMEM_OFFSET);
88 file.flag = FLAG_FILE_CLOSED;
92 cfs_read(
int f,
void *buf,
unsigned int len)
94 if(file.fileptr + len > CFS_XMEM_SIZE) {
95 len = CFS_XMEM_SIZE - file.fileptr;
98 if(file.fileptr + len > file.filesize) {
99 len = file.filesize - file.fileptr;
103 xmem_pread(buf, len, CFS_XMEM_OFFSET + file.fileptr);
112 cfs_write(
int f,
const void *buf,
unsigned int len)
114 if(file.fileptr >= CFS_XMEM_SIZE) {
117 if(file.fileptr + len > CFS_XMEM_SIZE) {
118 len = CFS_XMEM_SIZE - file.fileptr;
121 if(file.fileptr + len > file.filesize) {
123 file.filesize = file.fileptr + len;
127 xmem_pwrite(buf, len, CFS_XMEM_OFFSET + file.fileptr);
139 if(o > file.filesize) {
151 file.flag = FLAG_FILE_CLOSED;
154 xmem_erase(CFS_XMEM_SIZE, CFS_XMEM_OFFSET);
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_WRITE
Specify that cfs_open() should open a file for writing.
#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.