/**
******************************************************************************
* @file dosfstest.c
* @author Daniel_lee
* @version V1.0
* @date 2013.7.15
* @brief This is a test of using DOSFS.
******************************************************************************
**/
/* Includes------------------------------------------------------------------*/
#include "VxWorks.h"
#include "iv.h" #include "intLib.h"
#include "SysLib.h"
#include "LogLib.h"
#include "DosfsLib.h"
#include "IoLib.h"
#include "stdio.h"
STATUS Dosfstest () {
int fd,bytes = 0, length = 0;
unsigned char buf[64] = "Hello,i ' m testing the file system";
unsigned char revbuf[64] = {0};
/*FD = creat ("/d/my.txt", O_RDWR);
if (fd = =-1) {
Logmsg ("Error:creat file failed\r\n", 0,0,0,0,0,0);
return ERROR;
}*/
FD = open ("/d/my.txt", o_rdwr,0);
if (fd = =-1) {
Logmsg ("Error:open file failed\r\n", 0,0,0,0,0,0);
return ERROR;
}
bytes = Write (fd,buf,sizeof ("Hello,i ' m testing the File system"));
Logmsg ("Write%d bytes data\r\n", bytes,0,0,0,0,0);
if (bytes! = sizeof ("Hello,i ' m testing the File system")) {
Logmsg ("Error:write%d bytes data\r\n", bytes,0,0,0,0,0);
Close (FD);
return ERROR;
}
Close (FD);
FD = open ("/d/my.txt", o_rdwr,0);
if (fd = =-1) {
Logmsg ("Error:open file failed\r\n", 0,0,0,0,0,0);
return ERROR;
}
bytes = Read (fd,revbuf,sizeof (REVBUF));
Logmsg ("read%d bytes data\r\n", bytes,0,0,0,0,0);
REVBUF[9] = ' + ';
Logmsg ("read%d bytes data, and read date is%s\r\n", bytes,revbuf,0,0,0,0);
Close (FD);
return OK;
}
Experimental summary: The array must indicate the size of the allocated space at initialization and cannot be initialized with a variable.
Can not write immediately after reading the data, because when writing data, the file pointer has pointed to the end of the file, immediately read what can not read, you need to use Lseek set offset pointer to read correctly.