int  test_yaffs_rename_ENOTEMPTY(void)
{

	int output=0;
	int error_code =0;

	if (yaffs_mkdir(DIR_PATH,O_CREAT | O_RDWR)==-1){
		print_message("failed to create dir\n",1);
		return -1;
	}
	if (yaffs_mkdir(DIR_PATH2,O_CREAT | O_RDWR)==-1){
		print_message("failed to create dir2\n",1);
		return -1;
	}
	if (yaffs_close(yaffs_open(DIR_PATH2_FILE,O_CREAT | O_RDWR, FILE_MODE))==-1){
		print_message("failed to create file\n",1);
		return -1;
	}
	output = yaffs_rename( DIR_PATH,DIR_PATH2 );
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==ENOTEMPTY){
			return 1;
		} else {
			print_message("different error than expected\n",2);
			return -1;
		}
		print_message("could not rename a directory over a nonempty directory (which is a bad thing)\n",2);
		return -1;
	} 
		
	return 1;

}
예제 #2
0
int directory_rename_test(void)
{
	int r;
	yaffs_StartUp();
	
	yaffs_mount("/ram");
	yaffs_mkdir("/ram/a",0);
	yaffs_mkdir("/ram/a/b",0);
	yaffs_mkdir("/ram/c",0);
	
	printf("\nDirectory look-up of /ram\n");
	dumpDir("/ram");
	dumpDir("/ram/a");
	dumpDir("/ram/a/b");

	printf("Do rename (should fail)\n");
		
	r = yaffs_rename("/ram/a","/ram/a/b/d");
	printf("\nDirectory look-up of /ram\n");
	dumpDir("/ram");
	dumpDir("/ram/a");
	dumpDir("/ram/a/b");

	printf("Do rename (should not fail)\n");
		
	r = yaffs_rename("/ram/c","/ram/a/b/d");
	printf("\nDirectory look-up of /ram\n");
	dumpDir("/ram");
	dumpDir("/ram/a");
	dumpDir("/ram/a/b");
	
	
	return 1;
	
}
int  test_yaffs_rename_full_dir_over_dir(void)
{

	int output=0;
	int error_code =0;

	if (yaffs_mkdir(DIR_PATH,O_CREAT | O_RDWR)==-1){
		print_message("failed to create dir\n",1);
		return -1;
	}
	if (yaffs_mkdir(DIR_PATH2,O_CREAT | O_RDWR)==-1){
		print_message("failed to create dir2\n",1);
		return -1;
	}
	if (yaffs_close(yaffs_open(DIR_PATH2_FILE,O_CREAT | O_RDWR, FILE_MODE))==-1){
		print_message("failed to create file\n",1);
		return -1;
	}
	output = yaffs_rename( DIR_PATH2,DIR_PATH );
	if (output<0){ 
		print_message("could not rename a directory over a empty directory (which is a bad thing)\n",2);
		return -1;
	} 
		
	return 1;

}
예제 #4
0
void scan_deleted_files_test(const char *mountpt)
{
	char fn[100];
	char sub[100];
	
	const char *p;
	
	int i;
	int j;
	int k;
	int h;
	
	sprintf(sub,"%s/sdir",mountpt);
	yaffs_StartUp();
	
	for(j = 0; j < 10; j++)
	{
		printf("\n\n>>>>>>> Run %d <<<<<<<<<<<<<\n\n",j);
		yaffs_mount(mountpt);
		yaffs_mkdir(sub,0);
		
		
		p = (j & 0) ? mountpt: sub;
	
		for(i = 0; i < 100; i++)
		{
		  sprintf(fn,"%s/%d",p,i);  
		  
		  if(i & 1)
		  {
			  h = yaffs_open(fn,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
			  for(k = 0; k < 1000; k++)
				  yaffs_write(h,fn,100);
			  yaffs_close(h);
		  }
		  else
		    	yaffs_mkdir(fn,0);
		}
		
		for(i = 0; i < 10; i++)
		{
		  sprintf(fn,"%s/%d",p,i);  
		  if(i & 1) 
		  	yaffs_unlink(fn);
		  else
		  	yaffs_rmdir(fn);
		  
		}
				
		yaffs_unmount(mountpt);
	}
	
	
	

}
예제 #5
0
void File_Init(void)
{
		int f1, f2;
	
		yaffs_mount("/nand");											//挂载
    
		f1 = yaffs_open("nand/first_start", O_RDONLY, 0 );
	  if ( f1 >= 0 )    //不是第一次启动文件系统 
		{
				printf("first_start open success!\n");
				File_TpConfig_Exist();
				//File_SubstationConfig_Exist();
				//File_Data_Exist();
		}
		else              //第一次启动文件系统
 	  {
			  yaffs_unmount("/nand");
				yaffs_format("/nand", 0, 0, 0);           //格式化
				yaffs_mount("/nand");											//挂载
				yaffs_mkdir("/nand/config", 0666);				//创建配置文件目录
				yaffs_mkdir("/nand/data", 0666);					//创建上传数据目录
				
				f1 = yaffs_open( "/nand/first_start",  O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE  );
				if ( f1 >= 0 )
				{
						printf("first_start create success!\n");
				}
/*			
				f2 = yaffs_open( "/nand/config/TestpointConfig",  O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE  );			
				if ( f2 >= 0 )
				{
						printf("Testpoint Config Create Success!\n");
						yaffs_close(f2);
				}
				
				f2 = yaffs_open( "/nand/config/SubstationConfig",  O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE  );			
				if ( f2 >= 0 )
				{
						printf("Substation Config Create Success!\n");
						yaffs_close(f2);
				}
				
				f2 = yaffs_open( "/nand/data/SensorData",  O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE  );			
				if ( f2 >= 0 )
				{
						printf("SensorData Create Success!\n");
						yaffs_close(f2);
				}
				*/
		}
		
		yaffs_close(f1);
				
		return;
}
예제 #6
0
int test_yaffs_rmdir_ENOTDIR(void)
{
	int output=0;
	int error_code =0;
	if (yaffs_close(yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE))==-1){
		print_message("failed to create file\n",1);
		return -1;
	}
	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			print_message("failed to create directory\n",2);
			return -1;
		}
	}
	output = yaffs_rmdir("/yaffs2/test_dir/foo/dir/");
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==ENOTDIR){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else{
		print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
		return -1;
	}	
}
예제 #7
0
int test_yaffs_rmdir_EINVAL(void)
{
	int output=0;
	int error_code =0;

	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			print_message("failed to create directory\n",2);
			return -1;
		}
	}
	output = yaffs_rmdir("/yaffs2/.");
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==EINVAL){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else{
		print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
		return -1;
	}	
}
예제 #8
0
void fill_empty_files_test(const char *mountpt)
{
	int i;
	yaffs_StartUp();
	char name[100];
	int result = 0;
	
	int d,f;

	for(i = 0; i < 5; i++)
	{
		yaffs_mount(mountpt);
		for(d = 0; result >= 0 && d < 1000; d++){
			sprintf(name,"%s/%d",mountpt,d);
			result= yaffs_mkdir(name,0);
			printf("creating directory %s result %d\n",name,result);
			
			for(f = 0; result >= 0 && f < 100; f++){
				sprintf(name,"%s/%d/%d",mountpt,d,f);
				result= yaffs_open(name,O_CREAT, 0);
				yaffs_close(result);
				printf("creating file %s result %d\n",name,result);
			}
		}
		yaffs_unmount(mountpt);
	}
	
}
예제 #9
0
void checkpoint_upgrade_test(const char *mountpt,int nmounts)
{

	char a[50];
	char b[50];
	char c[50];
	char d[50];
	
	int i;
	int j;
	int h;
	
	sprintf(a,"%s/a",mountpt);
	

	
	
	printf("Create start condition\n");
	yaffs_StartUp();
	SetCheckpointReservedBlocks(0);
	yaffs_mount(mountpt);
	yaffs_mkdir(a,0);
	sprintf(b,"%s/zz",a);
	sprintf(c,"%s/xx",a);
	make_file2(b,c,2000000);
	sprintf(d,"%s/aa",a);
	make_file2(d,NULL,500000000);
	dump_directory_tree(mountpt);
	
	printf("Umount/mount attempt full\n");
	yaffs_unmount(mountpt);
	
	SetCheckpointReservedBlocks(10);
	yaffs_mount(mountpt);
	
	printf("unlink small file\n");
	yaffs_unlink(c);
	dump_directory_tree(mountpt);
		
	printf("Umount/mount attempt\n");
	yaffs_unmount(mountpt);
	yaffs_mount(mountpt);
	
	for(j = 0; j < 500; j++){
		printf("***** touch %d\n",j);
		dump_directory_tree(mountpt);
		yaffs_touch(b);
		yaffs_unmount(mountpt);
		yaffs_mount(mountpt);
	}

	for(j = 0; j < 500; j++){
		printf("***** touch %d\n",j);
		dump_directory_tree(mountpt);
		yaffs_touch(b);
		yaffs_unmount(mountpt);
		yaffs_mount(mountpt);
	}
}
예제 #10
0
void cmd_yaffs_mkdir(const char *dir)
{
	int retval = yaffs_mkdir(dir, 0);

	if (retval < 0)
		printf("yaffs_mkdir returning error: %d, %s\n",
			retval, yaffs_error_str());
}
예제 #11
0
void cmd_yaffs_mkdir(const char *dir)
{
	checkMount();

	int retval = yaffs_mkdir(dir, 0);

	if ( retval < 0)
		printf("yaffs_mkdir returning error: %d\n", retval);
}
예제 #12
0
int do_mkdir(int argc,char **argv)
{
	//todo:more
	
	if(argc >= 2) {
		printk("mkdir %s\n",argv[1]);
		yaffs_mkdir(argv[1],0);	
	}
	return 0;	
}
예제 #13
0
void run_test(int x)
{
	int output=0;
	int y= 0;
	char message[200];
	message[0]='\0';

	yaffs_mkdir(TEST_DIR,S_IWRITE | S_IREAD);
	yaffs_set_error(0);	/*reset the last error to 0 */
	//printf("foo exists %d\n",test_yaffs_open());
	sprintf(message,"\nrunning test: %s \n",test_list[x].name_of_test);
	print_message(message,3);
	output=test_list[x].p_function();	/*run test*/
	if (output>=0){
		/*test has passed*/
		sprintf(message,"\ttest %s passed\n",test_list[x].name_of_test);
		print_message(message,3); 
		num_of_tests_pass++;
	} else {
		/*test is assumed to have failed*/
		printf("test failed\n");
		sprintf(message,"test: %s failed\n",test_list[x].name_of_test);
		print_message(message,1);		
		num_of_tests_failed ++;	
	
		get_error();
		print_message("\n\n",1);
		if (get_exit_on_error()){	
			quit_quick_tests(1);
		}
	}
	output=0;
	output=test_list[x].p_function_clean();	/*clean the test*/
	if (output <0){
		/* if the test failed to clean it's self then */
		sprintf(message,"test: %s failed to clean\n",test_list[x].name_of_test);
		print_message(message,1);		
		num_of_tests_failed ++;	
		num_of_tests_pass--;
		get_error();
		printf("\n\n");
		if (get_exit_on_error()){
			quit_quick_tests(1);
		}
		
	} else {
		sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
		print_message(message,3);
	}
	/* close all open handles */
	for (y=0; y<100;y++){
		yaffs_close(y);
	}
	delete_dir(TEST_DIR);
}
예제 #14
0
int test_yaffs_rename_EEXISTS(void)
{
	int output=0;
	int error_code =0;

	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			print_message("failed to create directory\n",2);
			return -1;
		}
	}
	if (0 !=  yaffs_access(RENAME_DIR_PATH,0)) {
		output = yaffs_mkdir(RENAME_DIR_PATH,S_IWRITE | S_IREAD);
		if (output < 0) {
			error_code=yaffs_get_error();
			if (abs(error_code)!=EEXIST){
				print_message("failed to create second directory\n",2);
				return -1;
			}
		}
	}
	output= yaffs_open("/yaffs2/dir2/file",O_CREAT | O_RDWR, FILE_MODE);
	if (output<0){
		print_message("failed to open file in the second directory\n",2);
		return -1;
	}
	output = yaffs_rename(DIR_PATH , RENAME_DIR_PATH);
	if (output<0){ 
		error_code=yaffs_get_error();
		if (abs(error_code)==ENOTEMPTY){
			return 1;
		} else {
			print_message("returned error does not match the the expected error\n",2);
			return -1;
		}
	} else{
		print_message("removed /yaffs2/ directory (which is a bad thing)\n",2);
		return -1;
	}	
}
예제 #15
0
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);
	}
}
예제 #16
0
파일: lfs.c 프로젝트: brandonhamilton/misp
/*
** Creates a directory.
** @param #1 Directory path.
*/
static int make_dir (lua_State *L) {
	const char *path = luaL_checkstring (L, 1);
	int fail;
	fail =  yaffs_mkdir (path, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |
	                     S_IWGRP | S_IXGRP | S_IROTH | S_IXOTH );
	if (fail) {
		lua_pushnil (L);
        lua_pushfstring (L, "%s", strerror(errno));
		return 2;
	}
	lua_pushboolean (L, 1);
	return 1;
}
예제 #17
0
void rmdir_test(const char *mountpt)
{
	char name[100];
	yaffs_StartUp();
	
	yaffs_mount(mountpt);
	
	strcpy(name,mountpt);
	strcat(name,"/");
	strcat(name,"hello");
	yaffs_mkdir(name,0666);
	yaffs_rmdir(name);
	yaffs_unmount(mountpt);
}
예제 #18
0
int test_yaffs_rename_dir(void)
{
	int output=0;


	if (0 !=  yaffs_access(DIR_PATH,0)) {
		output = yaffs_mkdir(DIR_PATH,S_IREAD|S_IWRITE);
		if (output < 0) {
			print_message("failed to create file\n",2);
			return -1;
		}
	}
	output = yaffs_rename( DIR_PATH , RENAME_DIR_PATH);
	return output;	
}
예제 #19
0
/*==============================================================================
 * - y_mkdir()
 *
 * - make a new directory
 */
int y_mkdir(int argc, char *argv[])
{
    int yaffs_retval;
    char path[PATH_LEN_MAX];

    CHECK_ARG_NUM(2, "please type directory name");

    _make_abs_path(path, argv[1]);

    yaffs_retval = yaffs_mkdir(path, 0);

    CHECK_YAFFS_RETVAL(yaffs_retval, "can't make directory '%s'%s\n", path, ""); 

    return CMD_OK;
}
예제 #20
0
void init(char *yaffs_test_dir,char *yaffs_mount_dir,int argc, char *argv[]){
	char output=0;
	int x=0;
	int seed=-1;
	FILE *log_handle;
	/*these variables are already set to zero, but it is better not to take chances*/
	message_buffer.head=0;				 
	message_buffer.tail=0;


	log_handle=fopen(LOG_FILE,"w");
	if (log_handle!=NULL){
		fputs("log file for yaffs tester\n",log_handle);
		fclose(log_handle);
	}
	add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/	
	yaffs_start_up();
    	yaffs_mount(yaffs_mount_dir);
	for (x=0;x<argc;x++){
//		add_to_buffer(&message_buffer,"argv ",MESSAGE_LEVEL_BASIC_TASKS,PRINT);
//		add_to_buffer(&message_buffer,argv[x],MESSAGE_LEVEL_BASIC_TASKS,PRINT);
		if (strcmp("-seed",argv[x])==0){			/*warning only compares the length of the strings, quick fix*/
			seed= atoi(argv[x+1]);
			/*add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
			append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);			
			append_to_buffer(&message_buffer,"\n",MESSAGE_LEVEL_BASIC_TASKS,PRINT);*/
		}
	}
	if (seed==-1){
		seed=time(NULL);
		srand(seed); 
	}
	else {
	srand(seed);
	}
	add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
	append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/	

	if (yaffs_access(yaffs_test_dir,0))	/* if the test folder does not exist then create it */
	{
		add_to_buffer(&message_buffer,"creating dir: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
		append_to_buffer(&message_buffer,yaffs_test_dir,MESSAGE_LEVEL_BASIC_TASKS,PRINT);	
		output=yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
		yaffs_check_for_errors(output, &message_buffer,"could not create dir","created dir\n\n");
	}
	
}
예제 #21
0
void checkpoint_fill_test(const char *mountpt,int nmounts)
{

	char a[50];
	char b[50];
	char c[50];
	
	int i;
	int j;
	int h;
	
	sprintf(a,"%s/a",mountpt);
	

	
	
	yaffs_StartUp();
	
	for(i = 0; i < nmounts; i++){
		printf("############### Iteration %d   Start\n",i);
		yaffs_mount(mountpt);
		dump_directory_tree(mountpt);
		yaffs_mkdir(a,0);
		
		sprintf(b,"%s/zz",a);
		
		h = yaffs_open(b,O_CREAT | O_RDWR,S_IREAD |S_IWRITE);
		
		
		while(yaffs_write(h,c,50) == 50){}
		
		yaffs_close(h);
		
		for(j = 0; j < 2; j++){
			printf("touch %d\n",j);
			yaffs_touch(b);
			yaffs_unmount(mountpt);
			yaffs_mount(mountpt);
		}

		dump_directory_tree(mountpt);		
		yaffs_unmount(mountpt);
	}
}
예제 #22
0
void yaffs_backward_scan_test(const char *path)
{
	char fn[100];
	
	yaffs_StartUp();	
	
	yaffs_mount(path);
	
	do_some_file_stuff(path);
	
	sprintf(fn,"%s/ddd",path);
	
	yaffs_mkdir(fn,0);
	
	do_some_file_stuff(fn);
	
	yaffs_unmount(path);
	
	yaffs_mount(path);
}
예제 #23
0
int test_yaffs_mkdir_EROFS(void)
{
	int error_code = 0;

	EROFS_setup();

	output = yaffs_mkdir(DIR_PATH,O_CREAT | O_RDWR);
	if (output < 0){
		error_code = yaffs_get_error();
		if (abs(error_code) == EROFS){
			return 1;
		} else {
			print_message("different error than expected\n", 2);
			return -1;
		}
	} else {
		print_message("created a new directory with EROFS set (which is a bad thing)\n", 2);
		return -1;
	}
}
예제 #24
0
int test_yaffs_mkdir_ELOOP_dir(void)
{
	int error_code = 0;

	if (set_up_ELOOP()<0){
		print_message("failed to setup symlinks\n",2);
		return -1;
	}

	output = yaffs_mkdir(ELOOP_PATH "/file",O_CREAT | O_RDWR);
	if (output < 0){
		error_code = yaffs_get_error();
		if (abs(error_code) == ELOOP){
			return 1;
		} else {
			print_message("different error than expected\n", 2);
			return -1;
		}
	} else {
		print_message("created a new directory on top of an non-existing directory (which is a bad thing)\n", 2);
		return -1;
	}
}
예제 #25
0
void multi_mount_test(const char *mountpt,int nmounts)
{

	char a[30];
	char b[30];
	char c[30];
	
	int i;
	int j;
	
	sprintf(a,"%s/a",mountpt);
	

	
	
	yaffs_StartUp();
	
	for(i = 0; i < nmounts; i++){
		printf("############### Iteration %d   Start\n",i);
		yaffs_mount(mountpt);
		dump_directory_tree(mountpt);
		yaffs_mkdir(a,0);
		for(j = 0; j < i; j++){
			sprintf(b,"%s/%d",a,j);
			verify_200k_file(b);
		}
		sprintf(b,"%s/%d",a,i);

		write_200k_file(b,"","");
		
		printf("######## Iteration %d   End\n",i);
		dump_directory_tree(mountpt);
		
		yaffs_unmount(mountpt);
	}
}
예제 #26
0
int do_mount(int argc,char **argv)
{
	yaffs_mount("/boot");
	yaffs_mkdir("/boot/mydoc", 0);
	cmd_yaffs_ls("/boot",0);
}
예제 #27
0
void yaffs_bash_around(const char *mountpt, int n_cycles)
{
	char name[200];
	char name1[200];
	int  h[BASH_HANDLES];
	int i;
	int op;
	int pos;
	int n;
	int n1;
	int start_op;
	int op_max = 99;
	
	int cycle = 0;
	
	sprintf(name,"%s/bashdir",mountpt);
	
	yaffs_mkdir(name,0666);

	for(i = 0; i < BASH_HANDLES; i++)
		h[i] = -1;
		
	while(n_cycles){
		if(cycle % 100 == 0){
			printf("CYCLE %8d mo %2d inodes %d space %d ",cycle,op_max,
				yaffs_inodecount(mountpt),(int)yaffs_freespace(mountpt));
			for(i = 0; i < BASH_HANDLES; i++)
				printf("%2d ",h[i]);
			printf("\n");
		}
		cycle++;

		if(n_cycles > 0)
			n_cycles--;
		i = rand() % BASH_HANDLES;
		op = rand() % op_max;
		pos = rand() & 20000000;
		n = rand() % 100;
		n1 = rand() % 100;
		
		sprintf(name,"%s/bashdir/xx%d",mountpt,n);
		sprintf(name1,"%s/bashdir/xx%d",mountpt,n1);

		start_op = op;
		
		op-=1;
		if(op < 0){
			if(h[i]>= 0){
				yaffs_close(h[i]);
				h[i] = -1;
			}
			continue;
		}
		op-=1;
		if(op < 0){
			if(h[i] < 0)
				h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666);
			continue;
		}

		op-=5;
		if(op< 0){
			yaffs_lseek(h[i],pos,SEEK_SET);
			yaffs_write(h[i],name,n);
			continue;
		}
		op-=1;
		if(op < 0){
			yaffs_unlink(name);
			continue;
		}
		op-=1;
		if(op < 0){
			yaffs_rename(name,name1);
			continue;
		}
		op-=1;
		if(op < 0){
			yaffs_mkdir(name,0666);
			continue;
		}
		op-=1;
		if(op < 0){
			yaffs_rmdir(name);
			continue;
		}
		
		op_max = start_op-op;
	}
		
	
}
예제 #28
0
void small_mount_test(const char *mountpt,int nmounts)
{

	char a[30];
	
	int i;
	int j;

	int h0;
	int h1;
	int len0;
	int len1;
	int nread;
	
	sprintf(a,"%s/a",mountpt);

	yaffs_StartUp();
	
	
	
	for(i = 0; i < nmounts; i++){
		
		static char xx[1000];
		
		printf("############### Iteration %d   Start\n",i);
		if(1 || i == 0 || i == 5) 
			yaffs_mount(mountpt);

		dump_directory_tree(mountpt);
		
		yaffs_mkdir(a,0);
		
		sprintf(xx,"%s/0",a);
		if(i ==0){
		
			h0 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
			for(j = 0; j < 130; j++)
				yaffs_write(h0,xx,1000);
			yaffs_close(h0);
		}
		
		h0 = yaffs_open(xx,O_RDONLY,0);
		
		sprintf(xx,"%s/1",a);
		h1 = yaffs_open(xx, O_RDWR | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE);
		
		while((nread = yaffs_read(h0,xx,1000)) > 0)
			yaffs_write(h1,xx,nread);
		
		
		len0 = yaffs_lseek(h0,0,SEEK_END);
		len1 = yaffs_lseek(h1,0,SEEK_END);
		
		yaffs_lseek(h0,0,SEEK_SET);
		yaffs_lseek(h1,0,SEEK_SET);

		for(j = 0; j < 200; j++){
		   yaffs_read(h0,xx,1000);
		   yaffs_read(h1,xx,1000);
		}
		
		yaffs_close(h0);
		yaffs_close(h1);
		
		printf("########### %d\n",i);
		dump_directory_tree(mountpt);

		if(1 || i == 4 || i == nmounts -1)
			yaffs_unmount(mountpt);
	}
}
예제 #29
0
파일: exp.c 프로젝트: HackLinux/jz4725
//void main(void)
void yaffstest(void)
{
	int i = 0,j;
	int f = -1,f1=-1;
	int fd[Nfile];
#if 1
	char file[20];
	char buf[2048];
	char buffer[2048];
#endif
	struct yaffs_stat s;
	int ret;
	unsigned int block;
	unsigned int page;
	int size;

#if 0
	unsigned char buffer0[16];
	unsigned char buffer1[2048];
	unsigned char buffer2[64];
	unsigned char buffer3[2048];
	

	jz_nand_init ();
	
#if mkyaffs
	/* we want to write the oob to spare here */
	memset(buffer1,0xff,2048);
	memset(buffer0,0xff,16);
#else
	memset(buffer0,0x2,16);
	buffer0[0]=0xff;
	memset(buffer1,0xb,2048);
#endif

	for(i=16;i<80;i++)
		nand_flash_erase_block(i);

for(i=16;i<80;i++)
{
	block=i;
	printf("block=%d ok\n",block);
	for(j=0;j<128;j++){
	memset(buffer2,0,16);
	memset(buffer3,0,2048);
	
	page=block*128+j;

	nand_flash_program_buf(page, buffer1,buffer0);//writeing data
//	nand_flash_program_buf(page, NULL, buffer0);//writeing spare
	if(nand_flash_read_buf(page, buffer3,buffer2)!=0)
		printf("*********read nand failed\n");
	if(nand_flash_read_buf(page, NULL,buffer2)!=0)
		printf("*********read nand oob failed\n");

//	ret=memcmp(buffer1+512+256+128,buffer3+512+256+128,64);
	ret=memcmp(buffer1,buffer3,512);
	if(ret!=0)
		printf("ret=%d\n",ret);
	ret=memcmp(buffer2,buffer0,16);
	if(ret!=0)
		printf("ret=%d\n \r\n",ret); 
	}
}
/*
	for(i=0;i<16;i++)
		printf("***data[%d]=%x,spare[%d]=%x\n",i,buffer3[i],i,buffer2[i]);
	for(i=896+64;i>896;i--)
		printf("*** buffer3[%d]=%x,buffer1[%d]=%x\n",i,buffer3[i],i,buffer1[i]); 
*/
#else
#if 1
	yaffs_StartUp();
	yaffs_mount("/mnt");
//	yaffs_mount("/d");
//	return;
//	ListDir("/mnt");
	yaffs_mkdir("/mnt/mtdblock", 0);
	yaffs_mkdir("/mnt/mtdblock/font", 0);
//	yaffs_mkdir("/c/data1", 0);
//	ListDir("/mnt/mtdblock");
//	ListDir("/mnt/mtdblock/font");
#endif
#if 0
	printf("testing serial\n\n");
	Updatefile();
	ReadOptions("/mnt/mtdblock/test1");
	ReadOptions("/mnt/mtdblock/options.cfg");
//	ReadOptions("/mnt/mtdblock/font/LANGUAGE.E");
	ListDir("/mnt/mtdblock");
	ListDir("/mnt/mtdblock/font");

	return;
#else
	/* testing memory */
	return;
#endif


#if 1
//	f = yaffs_open("/mnt/mtdblock/bigfile", O_CREAT | O_RDWR , S_IREAD | S_IWRITE);
	f = yaffs_open("/mnt/mtdblock/options.cfg", O_CREAT | O_RDWR , S_IREAD | S_IWRITE);
	if(f<0)
		printf("Yaffs Open File Failed\n");
	#if 1
//	for(i=0;i<12000;i++)
	for(i=0;i<1200;i++)
	{
		
		yaffs_lseek(f,0,SEEK_SET);
		yaffs_read(f,buffer,50);
		memset(buffer,i%255,2048);
		size=yaffs_lseek(f,0,SEEK_END);
//		ret=yaffs_write(f,buffer,2048);
		ret=yaffs_write(f,buffer,100);
//		printf("the result write  = %d,No.%d\n",ret,i);
		yaffs_lseek(f,0,SEEK_SET);
		yaffs_read(f,buffer,50);
	}
	#endif
	yaffs_lseek(f,0,SEEK_SET);
	size=yaffs_lseek(f,0,SEEK_END);

	yaffs_close(f);

	printf("the length of file =%d,it should be %d\n",size,i*2048);
	ListDir("/mnt/mtdblock");
//	yaffs_unlink("/c/data1/bigfile");
//	ListDir("/c/data1");
	
#else
	for(i=0;i<Nfile;i++)
	{
		sprintf(file,"/c/data0/file%d",i);
		printf("will open file %s\n",file);		
	//	fd[i] = yaffs_open(file, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
		fd[i] = yaffs_open(file, O_CREAT | O_RDWR , S_IREAD | S_IWRITE);
	//	printf("**************fd[%d]=%d\n",i,fd[i]);

		memset(buffer,0x5b+i,2048);
#if 1

		size=yaffs_lseek(fd[i],0,SEEK_END);
		ret=yaffs_write(fd[i],buffer,2048);
		printf("the result of yaffs write file %s = %d\n",file,ret);

/*		for(j=0;j<2;j++)
		{
			printf("buffer[%i]=%x\n",j,buffer[j]);
		}*/

		yaffs_lseek(fd[i],0,SEEK_SET);
#endif
		size=yaffs_lseek(fd[i],0,SEEK_END);
		printf("the length of file %s=%d\n",file,size);
		yaffs_lseek(fd[i],-2048,SEEK_END);
#if 1
		memset(buf,0,2048);
		ret=yaffs_read(fd[i],buf,2048);
		printf("the result of yaffs read file %s ==%d\n",file,ret);
/*
		for(j=0;j<2;j++)
		{
			printf("buf[%i]=%x\n",j,buf[j]);
		} */

		ret=memcmp(buffer,buf,2048);
		printf("the result of compare read*write file %s = %d\n",file,ret);
#endif
	

	//	yaffs_close(fd[i]);
	}
#endif

#endif
#if 0
	yaffs_mkdir("/c/mydoc", 0);
	yaffs_mkdir("/d/data0", 0);
	yaffs_mkdir("/d/data1", 0);
	
	f = yaffs_open("/d/data0/file1.gsk", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	yaffs_close(f);
	
	f = yaffs_open("/d/data0/file2.gsk", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	yaffs_close(f);
#endif 
//	yaffs_unlink("/d/data0/file1");
//	ListDir("/d/data0");
}
예제 #30
0
int long_test(int argc, char *argv[])
{

	int f;
	int r;
	char buffer[20];
	
	char str[100];
	
	int h;
	mode_t temp_mode;
	struct yaffs_stat ystat;
	
	yaffs_StartUp();
	
	yaffs_mount("/boot");
	yaffs_mount("/data");
	yaffs_mount("/flash");
	yaffs_mount("/ram");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /data\n");
	dumpDir("/data");
	printf("\nDirectory look-up of /flash\n");
	dumpDir("/flash");

	//leave_unlinked_file("/flash",20000,0);
	//leave_unlinked_file("/data",20000,0);
	
	leave_unlinked_file("/ram",20,0);
	

	f = yaffs_open("/boot/b1", O_RDONLY,0);
	
	printf("open /boot/b1 readonly, f=%d\n",f);
	
	f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
	
	printf("open /boot/b1 O_CREAT, f=%d\n",f);
	
	
	r = yaffs_write(f,"hello",1);
	printf("write %d attempted to write to a read-only file\n",r);
	
	r = yaffs_close(f);
	
	printf("close %d\n",r);

	f = yaffs_open("/boot/b1", O_RDWR,0);
	
	printf("open /boot/b1 O_RDWR,f=%d\n",f);
	
	
	r = yaffs_write(f,"hello",2);
	printf("write %d attempted to write to a writeable file\n",r);
	r = yaffs_write(f,"world",3);
	printf("write %d attempted to write to a writeable file\n",r);
	
	r= yaffs_lseek(f,0,SEEK_END);
	printf("seek end %d\n",r);
	memset(buffer,0,20);
	r = yaffs_read(f,buffer,10);
	printf("read %d \"%s\"\n",r,buffer);
	r= yaffs_lseek(f,0,SEEK_SET);
	printf("seek set %d\n",r);
	memset(buffer,0,20);
	r = yaffs_read(f,buffer,10);
	printf("read %d \"%s\"\n",r,buffer);
	memset(buffer,0,20);
	r = yaffs_read(f,buffer,10);
	printf("read %d \"%s\"\n",r,buffer);

	// Check values reading at end.
	// A read past end of file should return 0 for 0 bytes read.
		
	r= yaffs_lseek(f,0,SEEK_END);
	r = yaffs_read(f,buffer,10);
	printf("read at end returned  %d\n",r); 
	r= yaffs_lseek(f,500,SEEK_END);
	r = yaffs_read(f,buffer,10);
	printf("read past end returned  %d\n",r);       
	
	r = yaffs_close(f);
	
	printf("close %d\n",r);
	
	copy_in_a_file("/boot/yyfile","xxx");
	
	// Create a file with a long name
	
	copy_in_a_file("/boot/file with a long name","xxx");
	
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");

	// Check stat
	r = yaffs_stat("/boot/file with a long name",&ystat);
	
	// Check rename
	
	r = yaffs_rename("/boot/file with a long name","/boot/r1");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	// Check unlink
	r = yaffs_unlink("/boot/r1");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");

	// Check mkdir
	
	r = yaffs_mkdir("/boot/directory1",0);
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");

	// add a file to the directory                  
	copy_in_a_file("/boot/directory1/file with a long name","xxx");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");
	
	//  Attempt to delete directory (should fail)
	
	r = yaffs_rmdir("/boot/directory1");
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");
	
	// Delete file first, then rmdir should work
	r = yaffs_unlink("/boot/directory1/file with a long name");
	r = yaffs_rmdir("/boot/directory1");
	
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");

#if 0
	fill_disk_and_delete("/boot",20,20);
			
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
#endif

	yaffs_symlink("yyfile","/boot/slink");
	
	yaffs_readlink("/boot/slink",str,100);
	printf("symlink alias is %s\n",str);
	
	
	
	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
	dumpDirFollow("/boot");
	printf("\nDirectory look-up of /boot/directory1\n");
	dumpDir("/boot/directory1");

	h = yaffs_open("/boot/slink",O_RDWR,0);
	
	printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
	
	yaffs_close(h);
	
	yaffs_unlink("/boot/slink");

	
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	// Check chmod
	
	yaffs_stat("/boot/yyfile",&ystat);
	temp_mode = ystat.st_mode;
	
	yaffs_chmod("/boot/yyfile",0x55555);
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	yaffs_chmod("/boot/yyfile",temp_mode);
	printf("\nDirectory look-up of /boot\n");
	dumpDir("/boot");
	
	// Permission checks...
	PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
	PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
	PermissionsCheck("/boot/yyfile",0, O_RDWR,0);

	PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
	PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
	PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);

	PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
	PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
	PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
	
	PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
	PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
	PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);

	yaffs_chmod("/boot/yyfile",temp_mode);
	
	//create a zero-length file and unlink it (test for scan bug)
	
	h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
	yaffs_close(h);
	
	yaffs_unlink("/boot/zlf");
	
	
	yaffs_DumpDevStruct("/boot");
	
	fill_disk_and_delete("/boot",20,20);
	
	yaffs_DumpDevStruct("/boot");
	
	fill_files("/boot",1,10000,0);
	fill_files("/boot",1,10000,5000);
	fill_files("/boot",2,10000,0);
	fill_files("/boot",2,10000,5000);
	
	leave_unlinked_file("/data",20000,0);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	leave_unlinked_file("/data",20000,5000);
	
	yaffs_DumpDevStruct("/boot");
	yaffs_DumpDevStruct("/data");
	
		
		
	return 0;

}