/*
* 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 <unistd.h>
#include <fcntl.h>
#include <time.h>
+#include <ctype.h>
+
#include "yaffsfs.h"
#include "yaffs_guts.h" /* Only for dumping device innards */
+#include "yaffs_endian.h" /*For testing the swap_u64 macro */
extern int yaffs_trace_mask;
}
-
-
-
int dump_file_data(char *fn)
{
int h;
l = strlen(xx);
result = yaffs_read(h,yy,l);
+ if (result)
+ printf("result in line %d is %d", __LINE__, result);
yy[l] = 0;
if(strcmp(xx,yy)){
make_pattern_file(fn[j],fsize);
result = dump_file_data(fn[j]);
result = check_pattern_file(fn[j]);
+ if (result)
+ printf("result in line %d is %d", __LINE__, result);
}
yaffs_unmount(path);
}
int h;
int n;
int result;
- int f;
+ int f =0;
static char xx[600];
char str[50];
{
f = yaffs_freespace(path);
}
+ printf("last freespace was %d\n", f);
result = yaffs_close(h);
- printf(" close %d\n",result);
+ printf(" close %d\n", result);
}
}
{
sprintf(str,"%s/%d",path,j);
result = yaffs_unlink(str);
- printf("unlinking file %s, result %d\n",str,result);
+ printf("unlinking file %s, result %d\n", str, result);
}
}
}
yaffs_DIR *d;
struct yaffs_dirent *de;
struct yaffs_stat s;
- char str[100];
+ char str[300];
d = yaffs_opendir(dname);
yaffs_lstat(str,&s);
- printf("%s ino %lld length %d mode %X ",de->d_name,(int)s.st_ino,s.st_size,s.st_mode);
+ printf("%s ino %d length %d mode %X ",
+ de->d_name, (int)s.st_ino, (int)s.st_size, s.st_mode);
switch(s.st_mode & S_IFMT)
{
case S_IFREG: printf("data file"); break;
yaffs_lstat(str,&s);
- printf("%s inode %d obj %x length %lld mode %X ",
- str,s.st_ino,de->d_dont_use, s.st_size,s.st_mode);
+ printf("%s inode %d length %d mode %X ",
+ str, s.st_ino, (int)s.st_size, s.st_mode);
switch(s.st_mode & S_IFMT)
{
case S_IFREG: printf("data file"); break;
printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
}
+void dump_directory_tree_worker_fd(const char *dname,int recursive)
+{
+ int h;
+ struct yaffs_dirent *de;
+ struct yaffs_stat s;
+ char str[1000];
+
+ h = yaffs_open(dname, O_RDONLY, 0);
+
+ if(h < 0)
+ {
+ printf("open of dir failed\n");
+ }
+ else
+ {
+ printf("using fd %d\n", h);
+
+ while((de = yaffs_readdir_fd(h)) != NULL)
+ {
+ sprintf(str,"%s/%s",dname,de->d_name);
+
+ yaffs_lstat(str,&s);
+
+ printf("%s inode %d length %d mode %X ",
+ str,s.st_ino, (int)s.st_size, s.st_mode);
+ switch(s.st_mode & S_IFMT)
+ {
+ case S_IFREG: printf("data file"); break;
+ case S_IFDIR: printf("directory"); break;
+ case S_IFLNK: printf("symlink -->");
+ if(yaffs_readlink(str,str,100) < 0)
+ printf("no alias");
+ else
+ printf("\"%s\"",str);
+ break;
+ default: printf("unknown"); break;
+ }
+
+ printf("\n");
+
+ if((s.st_mode & S_IFMT) == S_IFDIR && recursive)
+ dump_directory_tree_worker_fd(str,1);
+
+ }
+
+ yaffs_close(h);
+ }
+
+}
+
+static void dump_directory_tree_fd(const char *dname)
+{
+ dump_directory_tree_worker_fd(dname,1);
+ printf("\n");
+ printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
+}
+
void dumpDir(const char *dname)
{ dump_directory_tree_worker(dname,0);
printf("\n");
mode_t temp_mode;
struct yaffs_stat ystat;
+ (void) argc;
+ (void) argv;
+
yaffs_start_up();
yaffs_mount("/boot");
int total = 0;
int lastTotal = 0;
- char str[100];
+ char str[300];
yaffs_start_up();
int yaffs_scan_test(const char *path)
{
+ (void) path;
+
return 0;
}
{
//expand
r = yaffs_lseek(a,i * 500,SEEK_SET);
+ if (r < 0)
+ printf("At line %d, r is %d\n", __LINE__, r);
r = yaffs_write(a,abuffer,1000);
+ if (r < 0)
+ printf("At line %d, r is %d\n", __LINE__, r);
}
x++;
//expand
r = yaffs_lseek(a,500,SEEK_END);
r = yaffs_write(a,abuffer,1000);
+ if (r < 0)
+ printf("At line %d, r is %d\n", __LINE__, r);
}
x++;
//expand
r = yaffs_lseek(a,-500,SEEK_END);
r = yaffs_write(a,abuffer,1000);
+ if (r < 0)
+ printf("At line %d, r is %d\n", __LINE__, r);
}
x++;
printf("Do rename (should fail)\n");
r = yaffs_rename("/ram/a","/ram/a/b/d");
+ if (r < 0)
+ printf("At line %d, r is %d\n", __LINE__, r);
+
printf("\nDirectory look-up of /ram\n");
dumpDir("/ram");
dumpDir("/ram/a");
{
int f;
- yaffs_start_up();
- yaffs_mount("/boot");
- fill_disk("/boot/",2);
- f = yaffs_freespace("/boot");
+ yaffs_start_up();
+ yaffs_mount("/boot");
+ fill_disk("/boot/",2);
+ f = yaffs_freespace("/boot");
- printf("%d free when disk full\n",f);
- return 1;
+ printf("%d free when disk full\n",f);
+ return 1;
}
int truncate_test(void)
r = yaffs_read(a,y,10);
- printf("read %d bytes:",r);
+ printf("read %d bytes:", r);
for(i = 0; i < r; i++) printf("[%02X]",y[i]);
}
+void fill_n_file_test(const char *mountpt, int n, int syz)
+{
+ int i;
+ int l;
+
+ yaffs_start_up();
+
+ yaffs_format(mountpt, 0, 0, 0);
+ yaffs_mount(mountpt);
+
+
+ for(i = 0; i < n; i++)
+ {
+ int h;
+ char fname[200];
+
+ sprintf(fname, "%s/%d", mountpt, i);
+
+ h = yaffs_open(fname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
+
+ l = syz;
+
+ while(l > 0) {
+ yaffs_write(h, fname, sizeof(fname));
+ l -= sizeof(fname);
+ }
+
+ yaffs_close(h);
+
+ }
+
+}
+
+
void fill_files_test(const char *mountpt)
{
int i;
for(i = 0; i < nmounts; i++){
int h0;
int h1;
- int len0;
- int len1;
-
- static char xx[1000];
+ char xx[1000];
printf("############### Iteration %d Start\n",i);
if(1 || i == 0 || i == 5)
yaffs_write(h1,xx,1000);
}
#endif
- len0 = yaffs_lseek(h0,0,SEEK_END);
- len1 = yaffs_lseek(h1,0,SEEK_END);
+ yaffs_lseek(h0,0,SEEK_END);
+ yaffs_lseek(h1,0,SEEK_END);
yaffs_lseek(h0,0,SEEK_SET);
yaffs_lseek(h1,0,SEEK_SET);
int h0;
int h1;
- int len0;
- int len1;
int nread;
sprintf(a,"%s/a",mountpt);
for(i = 0; i < nmounts; i++){
- static char xx[1000];
+ char xx[1000];
printf("############### Iteration %d Start\n",i);
if(1 || i == 0 || i == 5)
yaffs_write(h1,xx,nread);
- len0 = yaffs_lseek(h0,0,SEEK_END);
- len1 = yaffs_lseek(h1,0,SEEK_END);
+ yaffs_lseek(h0,0,SEEK_END);
+ yaffs_lseek(h1,0,SEEK_END);
yaffs_lseek(h0,0,SEEK_SET);
yaffs_lseek(h1,0,SEEK_SET);
extern void SetCheckpointReservedBlocks(int n);
-void checkpoint_upgrade_test(const char *mountpt,int nmounts)
+void checkpoint_upgrade_test(const char *mountpt, int nmounts)
{
char a[50];
int j;
- sprintf(a,"%s/a",mountpt);
-
-
+ (void) nmounts;
+ sprintf(a,"%s/a",mountpt);
printf("Create start condition\n");
yaffs_start_up();
yaffs_lseek(h,n,SEEK_SET);
}
-void random_truncate(int h, char * name)
+void random_truncate(int h, char *name)
{
int n;
int flen;
+
+ (void) name;
+
n = random() & 0xFFFFF;
flen = yaffs_lseek(h,0,SEEK_END);
if(n > flen)
char name[100];
int h;
int result;
- int val1;
struct yaffs_utimbuf utb;
struct yaffs_stat st;
+ //setup
+ yaffs_start_up();
+
+ yaffs_mount(mountpt);
+
+ strcpy(name,mountpt);
+ strcat(name,"/");
+ strcat(name,"xfile");
+
+ yaffs_unlink(name);
+
+ printf("created\n");
+ h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
+
+ yaffs_fstat(h,&st);
+ printf(" times before %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
+
+ //here are the last access and modification times.
+ utb.actime = 1000;
+ utb.modtime = 2000;
+
+ //futime sets the last modification and access time of the file
+ result = yaffs_futime(h,&utb);
+ printf("setting times using the futime function to a 1000 m 2000 result %d\n",result);
+
+ //read the times from the file header
+ yaffs_fstat(h,&st);
+ printf(" times %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
+
+
+ utb.actime = 5000;
+ utb.modtime = 8000;
+ result = yaffs_utime(name, &utb);
+ printf("utime to a 5000 m 8000 result %d\n",result);
+ yaffs_fstat(h,&st);
+ printf(" times %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
+
+ result = yaffs_utime(name, NULL);
+ printf("utime to NULL result %d\n",result);
+ yaffs_fstat(h,&st);
+ printf(" times %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
+
+
+}
+
+void print_binary(u64 val){
+ int count = 0;
+ for (int i= 63; i>=0; i --) {
+ if (count == 0){
+ printf(" ");
+ }
+ if ((((u64)1) << i) & val) {
+ printf("1");
+ } else {
+ printf("0");
+ }
+ count = (count +1) % 8;
+ }
+}
+
+void testing_swap_u64() {
+ int numberOfFailedTests = 0;
+ for (int i =0; i < 8; i ++) {
+ u64 startingNumber = (0xffLLu << (i*8));
+ u64 expected = (0xffLLu << (64 - (i*8) -8));
+ u64 converted = swap_u64(startingNumber);
+ if (converted != expected) {
+ numberOfFailedTests ++;
+ printf("numbers do not match.\n");
+ printf("0xff\t\t\t");
+ print_binary(0xff);
+ printf("\nStarting Number \t");
+ print_binary(startingNumber);
+ printf("\nExpecting \t\t");
+ print_binary(expected);
+ printf("\nConverted \t\t");
+ print_binary(converted);
+
+ printf("\n");
+ }
+ }
+ if (numberOfFailedTests){
+ printf("testing_swap failed %d tests\n", numberOfFailedTests);
+ } else {
+ printf("testing_swap_u64 passed all tests\n");
+ }
+}
+
+
+void size_utime_test(const char *mountpt)
+{
+ char name[100];
+ int h;
+ int result;
+ struct yaffs_utimbuf utb;
+ struct yaffs_stat st;
+
+ //setup
yaffs_start_up();
yaffs_mount(mountpt);
printf("created\n");
h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
- yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime);
+ yaffs_fstat(h,&st);
+ printf(" times before %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
+
+ //first lets get the yaffs_object.
+
+ //then check that yaffs_stat also works.
+ //yaffs_stat already uses 64 bits for both wince and unix times.
+ //To see if we are using 32 or 64 bit time, save a large number into the time and
+ //see if it overflows.
+ long bitsInTime = 8*sizeof(st.yst_ctime);
+ printf("the times are %ld bits long\n", bitsInTime);
+
+ //two testcases
+ if (bitsInTime == 64) {
+ //no need to test the overflow. Just check that it can be retrieved intact.
+ //use u64 variables in case utb truncates the values to 32 bit time by accident.
+ u64 start = 0xfffff;
+ u64 end = 0xffffff;
+
+ utb.actime = start;
+ utb.modtime = end;
+
+ result = yaffs_futime(h,&utb);
+ yaffs_fstat(h,&st);
+ if (st.yst_atime == start && st.yst_mtime == end) {
+ printf("successfully stored and retrevied a 64 bit number for atime and modtime\n");
+ } else {
+ printf("failed to store and retrieve a 64 bit number for atime and modtime\n");
+
+ }
+ } else {
+ //it is a 32 bit number. Check to see that it overflowed.
+
+ }
+
+
+ //here are the last access and modification times.
utb.actime = 1000;
utb.modtime = 2000;
+
+ //futime sets the last modification and access time of the file
result = yaffs_futime(h,&utb);
- printf("futime to a 1000 m 2000 result %d\n",result);
- yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime);
+ printf("setting times using the futime function to a 1000 m 2000 result %d\n",result);
+
+ //read the times from the file header
+ yaffs_fstat(h,&st);
+ printf(" times %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
utb.actime = 5000;
utb.modtime = 8000;
result = yaffs_utime(name, &utb);
printf("utime to a 5000 m 8000 result %d\n",result);
- yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime);
+ yaffs_fstat(h,&st);
+ printf(" times %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
result = yaffs_utime(name, NULL);
printf("utime to NULL result %d\n",result);
- yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime);
+ yaffs_fstat(h,&st);
+ printf(" times %llu %llu %llu\n",
+ ( u64) st.yst_atime, ( u64) st.yst_ctime, ( u64) st.yst_mtime);
}
+
void basic_xattr_test(const char *mountpt)
{
char name[100];
result = yaffs_symlink(fn,sn);
result = yaffs_link(sn,hn);
+ if (result < 0)
+ printf("At line %d result is %d\n", __LINE__, result);
+
h =yaffs_open(hn,O_RDWR,0);
}
void max_files_test(const char *mountpt)
{
char fn[100];
- char sn[100];
- char hn[100];
+
int result;
int h;
int i;
result = yaffs_close(h);
}
- yaffs_unmount(mountpt);
-
- //h =yaffs_open(hn,O_RDWR,0);
+ if (result < 0)
+ printf("At line %d result is %d\n", __LINE__, result);
+ yaffs_unmount(mountpt);
}
+
void case_insensitive_test(const char *mountpt)
{
char fn[100];
h = yaffs_open(fn2, O_RDONLY, 0);
ret = yaffs_read(h, buffer, 100);
- if (ret != strlen(fn) + 1 || memcmp(buffer, fn, ret)){
+ if (ret != (int)(strlen(fn) + 1) || memcmp(buffer, fn, ret)){
printf("wrong file read\n");
} else {
printf("File %s is the same as file %s\n", fn, fn2);
#define BUFFER_N 1100
unsigned xxbuffer[BUFFER_N];
-
void set_buffer(int n)
{
int i;
int wrote;
for(i = 0; i < N_WRITES; i++) {
- printf("writing at %lld\n", offset);
+ printf("writing at %d\n", (int)offset);
set_buffer(i);
pos = yaffs_lseek(h, offset, SEEK_SET);
if(pos != offset) {
- printf("mismatched seek pos %lld offset %lld\n",
- pos, offset);
+ printf("mismatched seek pos %d offset %d\n",
+ (int)pos, (int)offset);
perror("lseek64");
exit(1);
}
}
-
-
-
void verify_big_sparse_file(int h)
{
unsigned check_buffer[BUFFER_N];
loff_t pos;
int n = sizeof(check_buffer);
int result;
- const char * check_type;
int checks_failed = 0;
int checks_passed = 0;
for(i = 0; i < N_WRITES * STRIDE; i++) {
if(i % STRIDE) {
- check_type = "zero";
memset(xxbuffer,0, n);
} else {
- check_type = "buffer";
set_buffer(i/STRIDE);
}
- //printf("%s checking %lld\n", check_type, offset);
pos = yaffs_lseek(h, offset, SEEK_SET);
if(pos != offset) {
- printf("mismatched seek pos %lld offset %lld\n",
- pos, offset);
+ printf("mismatched seek pos %d offset %d\n",
+ (int)pos, (int)offset);
perror("lseek64");
exit(1);
}
exit(1);
}
-
-
-
if(memcmp(xxbuffer, check_buffer, n)) {
int j;
- printf("buffer at %lld mismatches\n", pos);
+ printf("buffer at %d mismatches\n", (int)pos);
printf("xxbuffer ");
for(j = 0; j < 20; j++)
printf(" %d",xxbuffer[j]);
yaffs_unmount(mountpt);
- yaffs_mount_common(mountpt, 0, 1);
+ yaffs_mount3(mountpt, 0, 1);
printf("mounted with no checkpt\n");
dumpDir(mountpt);
handle = yaffs_open(fullname, O_RDONLY, 0);
yaffs_unmount(mountpt);
/* Check resize by adding to the end, resizing back and verifying. */
- yaffs_mount_common(mountpt, 0, 1);
+ yaffs_mount3(mountpt, 0, 1);
printf("checking resize\n");
dumpDir(mountpt);
handle = yaffs_open(fullname, O_RDWR, 0);
file_end = yaffs_lseek(handle, 0, SEEK_END);
- printf("file_end %lld\n", file_end);
+ printf("file_end %d\n", (int)file_end);
for(i = 0; i < 10000; i++)
yaffs_write(handle, xx_buffer, sizeof(xx_buffer));
yaffs_ftruncate(handle, file_end);
}
+int mk_dir(const char *mp, const char *name)
+{
+ char full_name[100];
+
+ sprintf(full_name, "%s/%s", mp, name);
+
+ return yaffs_mkdir(full_name, S_IREAD| S_IWRITE);
+}
+
+int mk_file(const char *mp, const char *name)
+{
+ char full_name[100];
+ int h;
+
+ sprintf(full_name, "%s/%s", mp, name);
+
+ h = yaffs_open(full_name, O_RDWR | O_CREAT | O_TRUNC, S_IREAD| S_IWRITE);
+
+ yaffs_write(h, name, strlen(name));
+
+ yaffs_close(h);
+ return 0;
+}
+
+void xx_test(const char *mountpt)
+{
+ yaffs_start_up();
+
+ yaffs_format(mountpt,0,0,0);
+
+ yaffs_mount(mountpt);
+ printf("mounted\n");
+ dumpDir(mountpt);
+
+ printf("create files\n");
+
+ mk_dir(mountpt, "foo");
+ mk_file(mountpt, "foo/f1");
+ mk_file(mountpt, "foo/f2");
+ mk_file(mountpt, "foo/f3");
+ mk_file(mountpt, "foo/f4");
+ dump_directory_tree(mountpt);
+
+ printf("unmount and remount\n");
+
+ /* Unmount/remount */
+ yaffs_unmount(mountpt);
+ yaffs_mount(mountpt);
+ dump_directory_tree(mountpt);
+}
+
+void yy_test(const char *mountpt)
+{
+ yaffs_start_up();
+
+ yaffs_mount(mountpt);
+ dump_directory_tree(mountpt);
+}
+
+
void readdir_test(const char *mountpt)
{
- char xx_buffer[1000];
int i;
- int handle;
- char fullname[100];
-
yaffs_DIR *dirs[100];
-
yaffs_trace_mask = 0;
yaffs_start_up();
yaffs_unmount(mountpt);
+}
+
+void format_test(const char *mountpt)
+{
+ int ret;
+
+ yaffs_start_up();
+
+ ret = yaffs_format(mountpt, 0, 0, 0);
+ printf("yaffs_format(...,0, 0, 0) of unmounted returned %d."
+ " Should return 0\n\n\n", ret);
+
+ yaffs_mount(mountpt);
+
+ ret = yaffs_format(mountpt, 0, 0, 0);
+ printf("yaffs_format(...,0, 0, 0) of mounted returned %d."
+ " Should return -1 (busy)\n\n\n", ret);
+
+ ret = yaffs_format(mountpt, 1, 0, 0);
+ printf("yaffs_format(...,1, 0, 0) of mounted returned %d."
+ " Should return 0.\n\n\n", ret);
+
+ ret = yaffs_mount(mountpt);
+ printf("mount should return 0 returned %d\n\n\n", ret);
+
+ ret = yaffs_format(mountpt, 1, 0, 1);
+ printf("yaffs_format(...,1, 0, 1) of mounted returned %d."
+ " Should return 0.\n\n\n", ret);
+
+ ret = yaffs_mount(mountpt);
+ printf("mount should return -1 returned %d\n", ret);
+}
+
+void dir_rename_test(const char *mountpt)
+{
+ char fname[100];
+ char dname[100];
+ int h;
+ int ret;
+
+ yaffs_start_up();
+ yaffs_mount(mountpt);
+
+ sprintf(fname,"%s/file",mountpt);
+ sprintf(dname,"%s/directory",mountpt);
+
+ h = yaffs_open(fname,O_CREAT | O_RDWR | O_TRUNC, 0666);
+ yaffs_close(h);
+
+ yaffs_mkdir(dname, 0666);
+
+ dump_directory_tree(mountpt);
+
+ printf("Try to rename %s to %s\n", fname, dname);
+ ret = yaffs_rename(fname, dname);
+ printf("result %d, %d\n", ret, yaffs_get_error());
+
+ printf("Try to rename %s to %s\n", dname, fname);
+ ret = yaffs_rename(dname, fname);
+ printf("result %d, %d\n", ret, yaffs_get_error());
+
+
+}
+
+
+void dir_fd_test(const char *mountpt)
+{
+ char name[100];
+ int h;
+ int i;
+
+ yaffs_start_up();
+ yaffs_mount(mountpt);
+
+ sprintf(name,"%s/directory",mountpt);
+ yaffs_mkdir(name, 0666);
+ for(i=0; i < 20; i++) {
+ sprintf(name,"%s/directory/file%d",mountpt, i);
+
+ h = yaffs_open(name, O_CREAT | O_TRUNC | O_RDWR, 0666);
+ yaffs_write(h, name, strlen(name));
+ yaffs_close(h);
+ }
+ sprintf(name,"%s/dddd",mountpt);
+ yaffs_mkdir(name, 0666);
+ for(i=0; i < 20; i++) {
+ sprintf(name,"%s/dddd/filezzz%d",mountpt, i);
+
+ h = yaffs_open(name, O_CREAT | O_TRUNC | O_RDWR, 0666);
+ yaffs_write(h, name, strlen(name));
+ yaffs_close(h);
+ }
+
+
+ dump_directory_tree(mountpt);
+ dump_directory_tree_fd(mountpt);
+ dump_directory_tree_fd(mountpt);
+
+}
+
+void create_delete_many_files_test(const char *mountpt)
+{
+
+ char fn[100];
+ int i;
+ int fsize;
+ char buffer[1000];
+ int h;
+ int wrote;
+
+
+ yaffs_start_up();
+ yaffs_mount(mountpt);
+
+ for(i = 1; i < 2000; i++) {
+ sprintf(fn,"%s/f%d",mountpt, i);
+ fsize = (i%10) * 10000 + 20000;
+ h = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, 0666);
+ while (fsize > 0) {
+ wrote = yaffs_write(h, buffer, sizeof(buffer));
+ if (wrote != sizeof(buffer)) {
+ printf("Writing file %s, only wrote %d bytes\n", fn, wrote);
+ break;
+ }
+ fsize -= wrote;
+ }
+ yaffs_unlink(fn);
+ yaffs_close(h);
+ }
+
+}
+
+void find_device_check(void)
+{
+ yaffs_start_up();
+ yaffs_mount("/nand");
+ yaffs_mount("/");
+ yaffs_mkdir("/nandxxx", 0666);
+ yaffs_mkdir("/nand/xxx", 0666);
+}
+
+
+void try_opendir(const char *str)
+{
+ yaffs_DIR *d;
+
+ d = yaffs_opendir(str);
+
+ printf("%s --> %p\n", str, d);
+
+ if (d)
+ yaffs_closedir(d);
+}
+
+void opendir_test(void)
+{
+ yaffs_start_up();
+ yaffs_mount("/nand/");
+ yaffs_symlink("x", "/nand/sym");
+ yaffs_mkdir("/nand/x",0666);
+ yaffs_mkdir("/nand/y",0666);
+ yaffs_mkdir("/nand/x/r",0666);
+ yaffs_mkdir("/nand/x/s",0666);
+ yaffs_mkdir("/nand/x/t",0666);
+
+ try_opendir("nand/x/.");
+ try_opendir("nand/x/r/..");
+ try_opendir("nand/x/./");
+ try_opendir("nand/x/r/../");
+ try_opendir("/nand/x");
+ try_opendir("/nand/x/");
+ try_opendir("nand/x");
+ try_opendir("nand/sym");
+ try_opendir("nand/sym/");
+
+}
+
+void try_rmdir(const char *str)
+{
+ int ret;
+
+ ret= yaffs_rmdir(str);
+
+ printf("rmdir(\"%s\") --> %d, errno %d\n", str, ret, yaffs_get_error());
+
+}
+
+void rmdir_test2(void)
+{
+ yaffs_start_up();
+
+ yaffs_mount("/nand/");
+ yaffs_mkdir("/nand/z",0666);
+ try_rmdir("/nand/z");
+ yaffs_mkdir("/nand/z",0666);
+ try_rmdir("/nand/z/");
+}
+
+
+void dump_yaffs_malloc_usage(void)
+{
+ unsigned current;
+ unsigned high_water;
+
+ yaffsfs_get_malloc_values(¤t, &high_water);
+
+ printf("\n"
+ "***************************************\n"
+ "Dump of yaffs malloc usage during run\n"
+ "Currently allocated : %u bytes\n"
+ "High water allocated : %u bytes\n"
+ "Note, this is not accurate on all platforms\n",
+ current, high_water);
}
int main(int argc, char *argv[])
{
+
+ //unlink("emfile-nand");
+
+
+ atexit(dump_yaffs_malloc_usage);
+
+ (void) argc;
+ (void) argv;
+
random_seed = time(NULL);
//return long_test(argc,argv);
//rename_over_test("//////////////////flash///////////////////yaffs1///////////");
- //fill_empty_files_test("/yaffs2/");
- //resize_stress_test("/yaffs2");
- //overwrite_test("/yaffs2");
+ //fill_empty_files_test("/nand/");
+ //resize_stress_test("/nand");
+ //overwrite_test("/nand");
- //long_name_test("/yaffs2");
- //link_test0("/yaffs2");
+ //long_name_test("/nand");
+ //link_test0("/nand");
//link_test1("yaffs2");
//scan_pattern_test("/flash",10000,10);
- //short_scan_test("/flash/flash",40000,200);
+ //short_scan_test("/yflash2",40000,200);
+ //short_scan_test("/nand128MB",40000,200);
//small_mount_test("/flash/flash",1000);
//small_overwrite_test("/flash/flash",1000);
//seek_overwrite_test("/flash/flash",1000);
//long_test_on_path("/ram2k");
// long_test_on_path("/flash");
//simple_rw_test("/flash/flash");
- //fill_disk_test("/flash/flash");
+ //fill_n_file_test("/nand128MB", 50, 128000000/50);
// rename_over_test("/flash");
//lookup_test("/flash");
//freespace_test("/flash/flash");
//check_resize_gc_bug("/flash");
- //basic_xattr_test("/yaffs2");
- //big_xattr_test("/yaffs2");
+ //basic_xattr_test("/nand");
+ //big_xattr_test("/nand");
//null_name_test("yaffs2");
//test_flash_traffic("yaffs2");
- // link_follow_test("/yaffs2");
- //basic_utime_test("/yaffs2");
+ // link_follow_test("/nand");
+ //basic_utime_test("/nand");
+
+
+ //format_test("/nand");
+
+ //max_files_test("/nand");
+
+ //start_twice("/nand");
+
+ //large_file_test("/nand");
+ //readdir_test("/nand");
+
+ basic_utime_test("/nand");
+ testing_swap_u64();
+ size_utime_test("/nand");
+ //case_insensitive_test("/nand");
- max_files_test("/yaffs2");
+ //yy_test("/nand");
+ //dir_rename_test("/nand");
- //start_twice("/yaffs2");
+ //dir_fd_test("/nand");
- //large_file_test("/yaffs2");
- //readdir_test("/yaffs2");
+ //format_test("/nand");
- //basic_utime_test("/yaffs2");
- //case_insensitive_test("/yaffs2");
+ //opendir_test();
+ //rmdir_test2();
+ //create_delete_many_files_test("/nand");
return 0;
}