#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#define SDCARDDIR "/media/10-3M/rwfile-test.txt"
#define MAXSIZE 512
//#define MAXRW 1024*1024*10
#define MAXLOOP 15155
int main(int argc, char *argv[])
{
int fd;
if ((fd=open(SDCARDDIR, O_APPEND|O_RDWR|O_CREAT, 777)) < 0)
{
printf("cannot open this file\n");
exit(0);
}
char buf[MAXSIZE] = {0};
memset(buf, 'a', MAXSIZE);
//int count = 0;
//int countw = 0;//write SDcard block
int loop = 0; //loop R-W 500次
ssize_t ret = 0;
//int sumloop = 0; //bad SDcard block
int i;
int ierror = 0;
float per;
while(1)
{
for(i = 0; i < MAXLOOP; i++)
{
ret = write(fd, buf, MAXSIZE);
if(ret < 0)
{
ierror++;
printf("iplace:%d, error:%d\n", i, errno);
break;
}
//sync();
}
sync();
loop += 1;
if(ierror > 0)
{
per = (float)(ierror/MAXLOOP);
printf("loop:%d, ierror:%d, bakblok-per:%f,error:%d\n", loop - 1, ierror, per,errno);
ierror = 0;
}
//sumloop = ierror;
//ierror = 0;
if(loop > 500)
{
//printf("500 rw over loop %d, bad-block %d\n", loop, ierror);
printf("500 rw over loop \n");
break;
}
else
{
close(fd);
remove(SDCARDDIR);
sync();
//fseek(fp, 0L, SEEK_SET);
if ((fd=open(SDCARDDIR, O_APPEND|O_RDWR|O_CREAT, 777)) < 0)
{
printf("cannot open this file\n");
exit(0);
}
}
}
return 0;
}
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#define SDCARDDIR "/media/10-3M/rwfile-test.txt"
#define MAXSIZE 512
//#define MAXRW 1024*1024*10
#define MAXLOOP 15155
int main(int argc, char *argv[])
{
int fd;
if ((fd=open(SDCARDDIR, O_APPEND|O_RDWR|O_CREAT, 777)) < 0)
{
printf("cannot open this file\n");
exit(0);
}
char buf[MAXSIZE] = {0};
memset(buf, 'a', MAXSIZE);
//int count = 0;
//int countw = 0;//write SDcard block
int loop = 0; //loop R-W 500次
ssize_t ret = 0;
//int sumloop = 0; //bad SDcard block
int i;
int ierror = 0;
float per;
while(1)
{
for(i = 0; i < MAXLOOP; i++)
{
ret = write(fd, buf, MAXSIZE);
if(ret < 0)
{
ierror++;
printf("iplace:%d, error:%d\n", i, errno);
break;
}
//sync();
}
sync();
loop += 1;
if(ierror > 0)
{
per = (float)(ierror/MAXLOOP);
printf("loop:%d, ierror:%d, bakblok-per:%f,error:%d\n", loop - 1, ierror, per,errno);
ierror = 0;
}
//sumloop = ierror;
//ierror = 0;
if(loop > 500)
{
//printf("500 rw over loop %d, bad-block %d\n", loop, ierror);
printf("500 rw over loop \n");
break;
}
else
{
close(fd);
remove(SDCARDDIR);
sync();
//fseek(fp, 0L, SEEK_SET);
if ((fd=open(SDCARDDIR, O_APPEND|O_RDWR|O_CREAT, 777)) < 0)
{
printf("cannot open this file\n");
exit(0);
}
}
}
return 0;
}