#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#define BUFF_SIZE 1024
#define SECTOR_SIZE 1024*170
main(int argc, char *argv[])
{
char buff[BUFF_SIZE];
char readbuff[BUFF_SIZE];
int i;
int fd,ret;
char * filename;
if(argc != 0){
filename = argv[1];
if ((fd = open(filename, O_RDWR )) < 0) {
printf("error file open, will be createdn");
if ((fd = open(filename, O_CREAT|O_RDWR )) < 0) {
printf("file Creat fail.n");
return -1;
}
}
for(i=0;i<BUFF_SIZE;i++){
buff[i]=0xAA;
}
printf("writingn");
for(i=0;i<SECTOR_SIZE;i++){
write(fd,buff,BUFF_SIZE);
}
printf("readingn");
lseek(fd,0, SEEK_SET);
for(i=0;i<SECTOR_SIZE;i++){
read(fd,readbuff,BUFF_SIZE);
if(memcmp(readbuff, buff, BUFF_SIZE)){
printf("error found on %dn", i);
}
}
}
close(fd);
return 0;
}
转载请注明:在路上 » test of bch