augmented CFS compliance for a RAM-based, one-file-only file system in Cooja.

This commit is contained in:
zhitao 2009-09-08 15:08:20 +00:00
parent c6f7ef84fe
commit bdce08d39d
2 changed files with 50 additions and 22 deletions

View file

@ -28,7 +28,7 @@
* *
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* $Id: cfs-cooja.c,v 1.9 2009/03/02 09:34:47 fros4943 Exp $ * $Id: cfs-cooja.c,v 1.10 2009/09/08 15:08:20 zhitao Exp $
*/ */
#include <string.h> #include <string.h>
#include "lib/simEnvChange.h" #include "lib/simEnvChange.h"
@ -39,7 +39,9 @@
struct filestate { struct filestate {
char flag; char flag;
int access;
int fileptr; int fileptr;
int endptr;
}; };
static struct filestate file; static struct filestate file;
@ -47,7 +49,7 @@ static struct filestate file;
const struct simInterface cfs_interface; const struct simInterface cfs_interface;
// COOJA variables // COOJA variables
#define CFS_BUF_SIZE 60*1024 #define CFS_BUF_SIZE 1000000
char simCFSData[CFS_BUF_SIZE] = { 0 }; char simCFSData[CFS_BUF_SIZE] = { 0 };
char simCFSChanged = 0; char simCFSChanged = 0;
int simCFSRead = 0; int simCFSRead = 0;
@ -59,8 +61,13 @@ cfs_open(const char *n, int f)
{ {
if(file.flag == FLAG_FILE_CLOSED) { if(file.flag == FLAG_FILE_CLOSED) {
file.flag = FLAG_FILE_OPEN; file.flag = FLAG_FILE_OPEN;
file.fileptr = 0; file.access = f;
return 1; if(f & CFS_APPEND) {
file.fileptr = file.endptr;
} else {
file.fileptr = 0;
}
return 0;
} else { } else {
return -1; return -1;
} }
@ -75,12 +82,14 @@ cfs_close(int f)
int int
cfs_read(int f, void *buf, unsigned int len) cfs_read(int f, void *buf, unsigned int len)
{ {
if(f == FLAG_FILE_OPEN) { if(file.flag == FLAG_FILE_OPEN && file.access & CFS_READ) {
// TODO Should yield a few times? if(file.fileptr + len >= file.endptr) {
memcpy(buf, &simCFSData[0] + file.fileptr, len); len = file.endptr - file.fileptr;
}
memcpy(buf, &simCFSData[file.fileptr], len);
file.fileptr += len; file.fileptr += len;
simCFSChanged = 1; simCFSChanged = 1;
simCFSRead += len; simCFSRead += len;
return len; return len;
} else { } else {
return -1; return -1;
@ -90,12 +99,17 @@ cfs_read(int f, void *buf, unsigned int len)
int int
cfs_write(int f, const void *buf, unsigned int len) cfs_write(int f, const void *buf, unsigned int len)
{ {
if(f == FLAG_FILE_OPEN) { if(file.flag == FLAG_FILE_OPEN && file.access & CFS_WRITE) {
// TODO Should yield a few times? if(file.fileptr + len > CFS_BUF_SIZE) {
memcpy(&simCFSData[0] + file.fileptr, buf, len); len = CFS_BUF_SIZE - file.fileptr;
file.fileptr += len; }
simCFSChanged = 1; memcpy(&simCFSData[file.fileptr], buf, len);
simCFSWritten += len; file.fileptr += len;
simCFSChanged = 1;
simCFSWritten += len;
if(file.fileptr > file.endptr) {
file.endptr = file.fileptr;
}
return len; return len;
} else { } else {
return -1; return -1;
@ -105,9 +119,20 @@ cfs_write(int f, const void *buf, unsigned int len)
cfs_offset_t cfs_offset_t
cfs_seek(int f, cfs_offset_t o, int w) cfs_seek(int f, cfs_offset_t o, int w)
{ {
if(f == FLAG_FILE_OPEN) { if(file.flag == FLAG_FILE_OPEN) {
file.fileptr = o; if(w == CFS_SEEK_SET) {
return o; file.fileptr = o;
} else if(w == CFS_SEEK_CUR) {
file.fileptr += o;
} else if(w == CFS_SEEK_END) {
file.fileptr = file.endptr + o;
}
if(file.fileptr >= 0 && file.fileptr <= CFS_BUF_SIZE) {
if(file.fileptr > file.endptr) {
file.endptr = file.fileptr;
}
return file.fileptr;
}
} }
return -1; return -1;
} }
@ -115,19 +140,20 @@ cfs_seek(int f, cfs_offset_t o, int w)
int int
cfs_remove(const char *name) cfs_remove(const char *name)
{ {
return -1; memset(simCFSData, 0, sizeof(simCFSData));
return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
cfs_opendir(struct cfs_dir *p, const char *n) cfs_opendir(struct cfs_dir *p, const char *n)
{ {
return 1; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
int int
cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e) cfs_readdir(struct cfs_dir *p, struct cfs_dirent *e)
{ {
return 1; return 0;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
void void

View file

@ -27,7 +27,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: contiki-conf.h,v 1.10 2009/04/01 13:46:56 fros4943 Exp $ * $Id: contiki-conf.h,v 1.11 2009/09/08 15:08:20 zhitao Exp $
* *
*/ */
@ -86,4 +86,6 @@ typedef unsigned long clock_time_t;
#define UIP_CONF_ND6_MAX_DEFROUTERS 2 #define UIP_CONF_ND6_MAX_DEFROUTERS 2
#endif /* UIP_CONF_IPV6 */ #endif /* UIP_CONF_IPV6 */
#define CFS_CONF_OFFSET_TYPE long
#endif /* __CONTIKI_CONF_H__ */ #endif /* __CONTIKI_CONF_H__ */