vxworks dosfs文件系统文件读写测试
2013-07-17 23:49
726 查看
/**
******************************************************************************
* @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] = '\0';
logMsg("read %d bytes data, and read date is %s\r\n",bytes,revBuf,0,0,0,0);
close(fd);
return OK;
}
实验总结:数组在初始化时必须指明分配的空间大小,不能用变量初始化。
不能write后立马去读数据,因为在写数据的时候文件指针已经指向了文件尾部,马上读的话什么也读不出来,需要使用lseek设置偏移指针才可正确读出。
******************************************************************************
* @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] = '\0';
logMsg("read %d bytes data, and read date is %s\r\n",bytes,revBuf,0,0,0,0);
close(fd);
return OK;
}
实验总结:数组在初始化时必须指明分配的空间大小,不能用变量初始化。
不能write后立马去读数据,因为在写数据的时候文件指针已经指向了文件尾部,马上读的话什么也读不出来,需要使用lseek设置偏移指针才可正确读出。
相关文章推荐
- vxWorks下dosFs文件系统的创建 分类: vxWorks 2014-08-05 15:59 706人阅读 评论(1) 收藏
- vxWorks下dosFs文件系统的创建
- vxWorks下dosFs文件系统的创建
- vxWorks下dosFs文件系统的创建
- vxWorks下dosFs文件系统的创建
- vdbench多节点测试文件系统读写
- Linux下各种主要文件系统的读写性能测试
- OpenWrt中对USB文件系统的操作, 以及读写性能测试
- 【nodejs】 文件系统(fs) 之读写文件
- 简单的nodejs 文件系统(fs)读写
- node.js基于fs模块对系统文件及目录进行读写操作的方法详解
- 测试磁盘和文件系统的读写性能vdbench
- Linux下各种主要文件系统的读写性能测试 ------------实际系统中的Nand Flash速度测试结果
- Iozone 文件系统的读写性能测试工具的使用
- node.js 使用fs模块对系统文件及目录进行读写操作
- (ext2,ext3,reiserfs,xfs,jfs)文件系统的性能测试
- ZYNQ系统中实现FAT32文件系统的SD卡读写之三 SDK编程调试
- 学生成绩管理系统(dos+文件)
- linux IO子系统和文件系统读写流程分析
- 文件系统读写性能