/*
* YAFFS: Yet another FFS. A NAND-flash specific file system.
*
- * Copyright (C) 2002-2011 Aleph One Ltd.
- * for Toby Churchill Ltd and Brightstar Engineering
+ * Copyright (C) 2002-2018 Aleph One Ltd.
*
* Created by Charles Manning <charles@aleph1.co.uk>
*
#include "yaffs_fsx.h"
#include <stdio.h>
+#include <unistd.h>
extern int fuzz_test;
static int interleave_fsx;
static int no_verification;
-
+
char fullPathName[100];
char fullPowerUpName[100];
char fullStartName[100];
if(ext_fatal)
ext_fatal();
-
+
while(1){
sleep(1);
}
unsigned x[2];
int nread = 0;
int nwritten = 0;
-
+
x[0] = x[1] = 0;
-
+
if(initialise){
- x[0] = 0;
+ x[0] = 0;
x[1] = 1;
} else {
inh = yaffs_open(name,O_RDONLY, S_IREAD | S_IWRITE);
printf("Error reading counter %s handle %d, x[0] %u x[1] %u last error %d\n",
name, inh, x[0], x[1],yaffsfs_GetLastError());
FatalError(__LINE__);
-
+
}
x[0]++;
x[1]++;
}
-
+
FSX();
outh = yaffs_open(fullTempCounterName, O_RDWR | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
-
+
if(outh >= 0){
struct yaffs_stat tmpstat, oldstat, tmpfstat;
- FSX();
+ FSX();
yaffs_fstat(outh,&tmpfstat);
printf("\n\n\n*** Writing file %s inode %d\n",fullTempCounterName,tmpfstat.st_ino);
nwritten = yaffs_write(outh,x,sizeof(x));
yaffs_rename(fullTempCounterName,name);
FSX();
}
-
+
if(nwritten != sizeof(x)){
printf("Error writing counter %s handle %d, x[0] %u x[1] %u\n",
name, inh, x[0], x[1]);
FatalError(__LINE__);
}
-
+
*val = x[0];
-
+
printf("##\n"
"## Set counter %s to %u\n"
"##\n", name,x[0]);
char str[1000];
int error_line = 0;
int nentries;
-
+
d = yaffs_opendir(dname);
-
+
if(!d)
{
printf("opendir failed\n");
strcat(str,"/");
strcat(str,de->d_name);
nentries++;
-
+
yaffs_lstat(str,&s);
-
+
printf("%s inode %ld %d obj %x length %d mode %X ",str, de->d_ino, s.st_ino,de->d_dont_use,(int)s.st_size,s.st_mode);\
if(de->d_ino != s.st_ino){
printf(" \n\n!!!! HEY inode mismatch\n\n");
if(yaffs_readlink(str,str,100) < 0)
printf("no alias");
else
- printf("\"%s\"",str);
+ printf("\"%s\"",str);
break;
default: printf("unknown"); break;
}
-
+
printf("\n");
if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
dump_directory_tree_worker(str,1);
-
+
if(s.st_ino > 10000)
error_line = __LINE__;
-
+
}
-
+
if(strstr(dname,"lost+found") && nentries >0){
printf("\n\n!!! HEY lost+found not empty, had %d entries\n\n\n",nentries);
error_line = __LINE__;
if(error_line && !no_verification)
FatalError(error_line);
-
+
yaffs_closedir(d);
}
int i;
struct yaffs_stat st;
unsigned checksum = 0;
-
+
FSX();
h = yaffs_open(fname,O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
yaffs_fstat(h,&st);
printf("\n\n\n**** Open writing file %s inode %d\n",fname, st.st_ino);
-
+
FSX();
if(h < 0){
xx[i] = sz32 + i;
checksum ^= xx[i];
}
-
+
FSX();
if((r = yaffs_write(h,xx,sizeof(xx))) != sizeof(xx)){
goto WRITE_ERROR;
if((r = yaffs_write(h,xx,sizeof(unsigned))) != sizeof(unsigned)){
goto WRITE_ERROR;
}
-
+
FSX();
yaffs_close(h);
printf("File closed\n");
printf("ywrite error at position %d\n",(int)yaffs_lseek(h,0,SEEK_END));
yaffs_close(h);
return -1;
-
+
}
static int y_verify_file(const char *fName)
return 0;
printf("Verifying file %s\n",fName);
-
+
h = yaffs_open(fName, O_RDONLY,S_IREAD | S_IWRITE);
if(h < 0){
yaffs_close(h);
return -1;
}
-
+
recordedSize = sz32 * sizeof(xx) + 8;
printf("verify %s: file size is %d, recorded size is %d\n", fName, totalSize, recordedSize);
yaffs_close(h);
return -1;
}
-
+
checksum ^= xx[0];
if(checksum != 0){
int result;
int sz32;
sz32 = (myrand() % 1000) + 20;
-
+
result = y_wr_file(fullTempMainName,sz32);
FSX();
if(!no_verification && result)
FatalError(__LINE__);
- printf("Raname file %s to %s\n",fullTempMainName,fullMainName);
+ printf("Rename file %s to %s\n",fullTempMainName,fullMainName);
yaffs_rename(fullTempMainName,fullMainName);
FSX();
}
void NorStressTestInitialise(const char *prefix)
{
MakeFullNames(prefix);
-
+
UpdateCounter(fullPowerUpName,&powerUps,1);
UpdateCounter(fullStartName,&cycleStarts,1);
UpdateCounter(fullEndName,&cycleEnds,1);
interleave_fsx = do_fsx;
no_verification = skip_verification;
-
+
MakeFullNames(prefix);
dump_directory_tree(fullPathName);
FSX_INIT(prefix);
-
+
dump_directory_tree(fullPathName);
-
+
UpdateCounter(fullPowerUpName,&powerUps,0);
dump_directory_tree(fullPathName);
-
+
while(n_cycles < 0 || n_cycles > 0){
if(n_cycles > 0)
n_cycles--;
DoVerifyMainFile();
DoUpdateMainFile();
dump_directory_tree(fullPathName);
-
+
UpdateCounter(fullEndName,&cycleEnds,0);
dump_directory_tree(fullPathName);
}