VxWorks Dosfs File System file read/write Test

Source: Internet
Author: User

/**
******************************************************************************
* @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.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.