void create_resized_file_of_size(const char *fn,int syze1,int reSyze, int syze2) { int h; int iterations; h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE); iterations = (syze1 + strlen(fn) -1)/ strlen(fn); while (iterations > 0) { yaffs_write(h,fn,strlen(fn)); iterations--; } yaffs_ftruncate(h,reSyze); yaffs_lseek(h,0,SEEK_SET); iterations = (syze2 + strlen(fn) -1)/ strlen(fn); while (iterations > 0) { yaffs_write(h,fn,strlen(fn)); iterations--; } yaffs_close (h); }
int test_yaffs_ftruncate_EROFS(void) { int output = 0; int error_code = 0; handle = yaffs_open(FILE_PATH,O_CREAT | O_RDWR , S_IREAD | S_IWRITE ); if (handle<0){ print_message("failed to open file\n",2); return -1; } EROFS_setup(); output = yaffs_ftruncate(handle,FILE_SIZE_TRUNCATED ); if (output < 0){ error_code=yaffs_get_error(); //printf("EISDIR def %d, Error code %d\n", EISDIR,error_code); if (abs(error_code) == EROFS){ return 1; } else { print_message("different error than expected\n", 2); return -1; } } else { print_message("file truncated with EROFS set.(which is a bad thing)\n", 2); return -1; } }
int test_yaffs_ftruncate_big_file(void) { int output = 0; int error_code = 0; handle = test_yaffs_open(); if (handle >= 0) { output = yaffs_ftruncate(handle,10000000000000000000000000000000); if (output < 0) { error_code = yaffs_get_error(); if (abs(error_code) == EINVAL) { /* yaffs uses the error EINVAL instead of big_file */ return 1; } else { print_message("different error than expected\n", 2); return -1; } } else { print_message("file truncated to a very large size.(which is a bad thing)\n", 2); return -1; } } else { print_message("error opening file\n", 2); return -1; } }
void random_truncate(int h, char * name) { int n; int flen; n = random() & 0xFFFFF; flen = yaffs_lseek(h,0,SEEK_END); if(n > flen) n = flen / 2; yaffs_ftruncate(h,n); yaffs_lseek(h,n,SEEK_SET); }
void small_overwrite_test(const char *mountpt,int nmounts) { char a[30]; int i; int j; int h0; int h1; sprintf(a,"%s/a",mountpt); yaffs_StartUp(); for(i = 0; i < nmounts; i++){ static char xx[8000]; printf("############### Iteration %d Start\n",i); if(1) yaffs_mount(mountpt); dump_directory_tree(mountpt); yaffs_mkdir(a,0); sprintf(xx,"%s/0",a); h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); sprintf(xx,"%s/1",a); h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE); for(j = 0; j < 1000000; j+=1000){ yaffs_ftruncate(h0,j); yaffs_lseek(h0,j,SEEK_SET); yaffs_write(h0,xx,7000); yaffs_write(h1,xx,7000); if(early_exit) exit(0); } yaffs_close(h0); printf("########### %d\n",i); dump_directory_tree(mountpt); if(1) yaffs_unmount(mountpt); } }
int test_yaffs_ftruncate_big_file_clean(void) { /* change file size back to orignal size */ int output = 0; if (handle >= 0) { output = yaffs_ftruncate(handle,FILE_SIZE ); if (output >= 0) { return yaffs_close(handle); } else { print_message("failed to truncate file\n", 2); return -1; } } else { /* the file was not opened so the file could not be truncated */ return 1; } }
int truncate_test(void) { int a; int r; int i; int l; char y[10]; yaffs_StartUp(); yaffs_mount("/boot"); yaffs_unlink("/boot/trunctest"); a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26); yaffs_ftruncate(a,3); l= yaffs_lseek(a,0,SEEK_END); printf("truncated length is %d\n",l); yaffs_lseek(a,5,SEEK_SET); yaffs_write(a,"1",1); yaffs_lseek(a,0,SEEK_SET); r = yaffs_read(a,y,10); printf("read %d bytes:",r); for(i = 0; i < r; i++) printf("[%02X]",y[i]); printf("\n"); return 0; }
int resize_stress_test(const char *path) { int a,b,i,j; int x; int r; char aname[100]; char bname[100]; char abuffer[1000]; char bbuffer[1000]; yaffs_StartUp(); yaffs_mount(path); sprintf(aname,"%s%s",path,"/a"); sprintf(bname,"%s%s",path,"/b"); memset(abuffer,'a',1000); memset(bbuffer,'b',1000); a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); printf(" %s %d %s %d\n",aname,a,bname,b); x = 0; for(j = 0; j < 100; j++) { yaffs_lseek(a,0,SEEK_END); for(i = 0; i <20000; i++) { //r = yaffs_lseek(b,i,SEEK_SET); //r = yaffs_write(b,bbuffer,1000); if(x & 0x16) { // shrink int syz = yaffs_lseek(a,0,SEEK_END); syz -= 500; if(syz < 0) syz = 0; yaffs_ftruncate(a,syz); } else { //expand r = yaffs_lseek(a,i * 500,SEEK_SET); r = yaffs_write(a,abuffer,1000); } x++; } } return 0; }
int resize_stress_test_no_grow(const char *path,int iters) { int a,b,i,j; int x; int r; char aname[100]; char bname[100]; char abuffer[1000]; char bbuffer[1000]; yaffs_StartUp(); yaffs_mount(path); sprintf(aname,"%s%s",path,"/a"); sprintf(bname,"%s%s",path,"/b"); memset(abuffer,'a',1000); memset(bbuffer,'b',1000); a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); printf(" %s %d %s %d\n",aname,a,bname,b); x = 0; for(j = 0; j < iters; j++) { yaffs_lseek(a,0,SEEK_END); for(i = 0; i <20000; i++) { //r = yaffs_lseek(b,i,SEEK_SET); //r = yaffs_write(b,bbuffer,1000); if(!(x%20)) { // shrink int syz = yaffs_lseek(a,0,SEEK_END); while(syz > 4000) { syz -= 2050; if(syz < 0) syz = 0; yaffs_ftruncate(a,syz); syz = yaffs_lseek(a,0,SEEK_END); printf("shrink to %d\n",syz); } } else { //expand r = yaffs_lseek(a,-500,SEEK_END); r = yaffs_write(a,abuffer,1000); } x++; } printf("file size is %lld\n",(long long)yaffs_lseek(a,0,SEEK_END)); } return 0; }
static int __yaffs_ftruncate(mount_point_t *point, file_t *file, off_t len) { return yaffs_ftruncate((int)file->ctx, len);