aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/inc_chibiosfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gfile/inc_chibiosfs.c')
-rw-r--r--src/gfile/inc_chibiosfs.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/gfile/inc_chibiosfs.c b/src/gfile/inc_chibiosfs.c
index 8d321b33..13ae6cac 100644
--- a/src/gfile/inc_chibiosfs.c
+++ b/src/gfile/inc_chibiosfs.c
@@ -27,22 +27,39 @@ static const GFILEVMT FsCHIBIOSVMT = {
0, 0, 0, 0,
0, ChibiOSBFSClose, ChibiOSBFSRead, ChibiOSBFSWrite,
ChibiOSBFSSetpos, ChibiOSBFSGetsize, ChibiOSBFSEof,
- 0, 0,
- 0
+ 0, 0, 0,
+ #if GFILE_NEED_FILELISTS
+ 0, 0, 0,
+ #endif
};
static void ChibiOSBFSClose(GFILE *f) {
- chFileStreamClose(((BaseFileStream *)f->fd));
+ chFileStreamClose(((BaseFileStream *)f->obj));
}
static int ChibiOSBFSRead(GFILE *f, void *buf, int size) {
- return chSequentialStreamRead(((BaseFileStream *)f->fd), (uint8_t *)buf, size);
+ return chSequentialStreamRead(((BaseFileStream *)f->obj), (uint8_t *)buf, size);
}
static int ChibiOSBFSWrite(GFILE *f, const void *buf, int size) {
- return chSequentialStreamWrite(((BaseFileStream *)f->fd), (uint8_t *)buf, size);
+ return chSequentialStreamWrite(((BaseFileStream *)f->obj), (uint8_t *)buf, size);
}
static bool_t ChibiOSBFSSetpos(GFILE *f, long int pos) {
- chFileStreamSeek(((BaseFileStream *)f->fd), pos);
+ chFileStreamSeek(((BaseFileStream *)f->obj), pos);
return TRUE;
}
-static long int ChibiOSBFSGetsize(GFILE *f) { return chFileStreamGetSize(((BaseFileStream *)f->fd)); }
-static bool_t ChibiOSBFSEof(GFILE *f) { return f->pos >= chFileStreamGetSize(((BaseFileStream *)f->fd)); }
+static long int ChibiOSBFSGetsize(GFILE *f) { return chFileStreamGetSize(((BaseFileStream *)f->obj)); }
+static bool_t ChibiOSBFSEof(GFILE *f) { return f->pos >= chFileStreamGetSize(((BaseFileStream *)f->obj)); }
+
+GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode) {
+ GFILE * f;
+
+ // Get an empty file and set the flags
+ if (!(f = findemptyfile(mode)))
+ return 0;
+
+ // File is open - fill in all the details
+ f->vmt = &FsCHIBIOSVMT;
+ f->obj = BaseFileStreamPtr;
+ f->pos = 0;
+ f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK;
+ return f;
+}