예제 #1
0
void rename_over_test(const char *mountpt)
{
	int i;
	char a[100];
	char b[100];
	char c[100];
	
	sprintf(a,"%s/a",mountpt);
	sprintf(b,"%s/b",mountpt);
	sprintf(c,"%s/c",mountpt);
	
	yaffs_StartUp();
	
	yaffs_mount(mountpt);
	
	printf("Existing files\n");
	dumpDirFollow(mountpt);
	
	
	
	i = yaffs_open(c,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
	printf("File c handle is %d\n",i);
	yaffs_close(i);
	i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE); 
	yaffs_close(i);
	i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR,  S_IREAD | S_IWRITE);
	yaffs_close(i);
	yaffs_rename(a,b); // rename over
	yaffs_rename(b,a); // rename back again (not renaimng over)
	yaffs_rename(a,b); // rename back again (not renaimng over)
	
	
	yaffs_unmount(mountpt);
	
}
예제 #2
0
int overwrite_test(const char *path)
{
   char aname[100];
   char bname[100];
   int i;
   int j;   
   int a;
   int b;
   yaffs_StartUp();
   
   yaffs_mount(path);
   
   sprintf(aname,"%s%s",path,"/a");
   sprintf(bname,"%s%s",path,"/b");
   
   b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   for(j= 0; j < 500; j++){
   	yaffs_write(b,bname,100);
	a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   	for(i = 0; i < rand() % 20000; i++)
   		yaffs_write(a,&a,sizeof(a));
	yaffs_close(a);
   }
   
   return 0;
   
}
예제 #3
0
int test_yaffs_fsync_EROFS(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;
	}
	EROFS_setup();
	handle = yaffs_open(FILE_PATH,O_CREAT  ,S_IREAD  );
	if (handle<0){
		print_message("failed to open file\n",2);
		return -1;
	}
	output = yaffs_fsync(handle);
	if (output==-1){
		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("file synced with EROFS set.(which is a bad thing)\n",2);
		return -1;
	}
}
예제 #4
0
int cache_read_test(void)
{
	int a,b,c;
	int i;
	int sizeOfFiles = 500000;
	char buffer[100];
	
	yaffs_StartUp();
	
	yaffs_mount("/boot");
	
	make_a_file("/boot/a",'a',sizeOfFiles);
	make_a_file("/boot/b",'b',sizeOfFiles);

	a = yaffs_open("/boot/a",O_RDONLY,0);
	b = yaffs_open("/boot/b",O_RDONLY,0);
	c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);

	do{
		i = sizeOfFiles;
		if (i > 100) i = 100;
		sizeOfFiles  -= i;
		yaffs_read(a,buffer,i);
		yaffs_read(b,buffer,i);
		yaffs_write(c,buffer,i);
	} while(sizeOfFiles > 0);
	
	
	
	return 1;
	
}
예제 #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
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);
	}
}
예제 #7
0
static void UpdateCounter(const char *name, unsigned *val,  int initialise)
{
  int inh=-1;
  int outh=-1;
  unsigned x[2];
  int nread = 0;
  int nwritten = 0;
  
  x[0] = x[1] = 0;
  
  if(initialise){
    x[0] = 0; 
    x[1] = 1;
  } else {
    inh = yaffs_open(name,O_RDONLY, S_IREAD | S_IWRITE);
    if(inh >= 0){
      nread = yaffs_read(inh,x,sizeof(x));
      yaffs_close(inh);
    }

    if(nread != sizeof(x) ||
       x[0] + 1 != x[1]){
      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();
              
    }
    x[0]++;
    x[1]++;
  }
  
  outh = yaffs_open(fullTempCounterName, O_RDWR | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);
  if(outh >= 0){
    nwritten = yaffs_write(outh,x,sizeof(x));
    yaffs_close(outh);
    yaffs_rename(fullTempCounterName,name);
  }
  
  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();
  }
  
  *val = x[0];
  
  printf("##\n"
         "## Set counter %s to %u\n"
         "##\n", name,x[0]);
}
예제 #8
0
void leave_unlinked_file(const char *path,int maxIterations,int siz)
{
	int i;
	char str[50];
	int h;
	
	i = 0;
	
	do{
		sprintf(str,"%s/%d",path,i);
		printf("create %s\n",str);
		h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
		if(h >= 0)
		{
			yaffs_unlink(str);
		}
		i++;
	} while(h < 0 && i < maxIterations);
	
	if(h >= 0)
	{
		for(i = 0; i < siz; i++)
		{
			yaffs_write(h,str,1);
		}
	}
	
	printf("Leaving file %s open\n",str);

}
예제 #9
0
void fill_disk(const char *path,int nfiles)
{
	int h;
	int n;
	int result;
	int f;

        static char xx[600];	
	char str[50];
	
	for(n = 0; n < nfiles; n++)
	{
		sprintf(str,"%s/%d",path,n);
		
		h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
		
		printf("writing file %s handle %d ",str, h);
		
		while ((result = yaffs_write(h,xx,600)) == 600)
		{
			f = yaffs_freespace(path);
		}
		result = yaffs_close(h);
		printf(" close %d\n",result);
	}
}
예제 #10
0
void yaffs_device_flush_test(const char *path)
{
	char fn[100];
	int h;
	int i;
	
	yaffs_StartUp();	
	
	yaffs_mount(path);
	
	do_some_file_stuff(path);
	
	// Open and add some data to a few files
	for(i = 0; i < 10; i++) {
	
		sprintf(fn,"%s/ff%d",path,i);

		h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IWRITE | S_IREAD);
		yaffs_write(h,xxzz,2000);
		yaffs_write(h,xxzz,2000);
	}
	yaffs_unmount(path);
	
	yaffs_mount(path);
}
예제 #11
0
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);
}
예제 #12
0
int test_yaffs_open_EACCES(void)
{
	int error_code=0;
	int output =-1;
	if (yaffs_access(FILE_PATH,0)!=0){
		output=yaffs_close(test_yaffs_open());
		if (output<0){
			print_message("failed to open file\n",2);
			return -1;
		}
	}

	output=yaffs_chmod(FILE_PATH,S_IREAD);
	if (output<0){
		print_message("failed to chmod file\n",2);
		return -1;
	}
	handle=yaffs_open(FILE_PATH, O_TRUNC| O_RDWR,FILE_MODE );
	if (handle <0){
		error_code=yaffs_get_error();
		if (abs(error_code)==EACCES){
			return 1;
		}
		else {
			print_message("different error than expected\n",2);
			return -1;
		}
	}
	else {
		print_message("file opened with read and write permissions, chmoded to read only.(which is a bad thing)\n",2);
		return -1;
	}
}
예제 #13
0
void verify_200k_file(const char *fn)
{
   int h1;
   int i;
   char x[11];
   const char *s="0123456789";
   int errCount = 0;
   
   h1 = yaffs_open(fn, O_RDONLY, 0);
   
   for(i = 0; i < 200000 && errCount < 10; i+= 10)
   {
   	yaffs_read(h1,x,10);
	if(strncmp(x,s,10) != 0)
	{
		printf("File %s verification failed at %d\n",fn,i);
		errCount++;
	}
   }
   if(errCount >= 10)
   	printf("Too many errors... aborted\n");
      
   yaffs_close(h1);	   
	
}
예제 #14
0
void write_200k_file(const char *fn, const char *fdel, const char *fdel1)
{
   int h1;
   int i;
   int offs;
   
   h1 = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
   
   for(i = 0; i < 100000; i+= 10000)
   {
   	write_10k(h1);
   }
   
   offs = yaffs_lseek(h1,0,SEEK_CUR);
   if( offs != 100000)
   {
   	printf("Could not write file\n");
   }
   
   yaffs_unlink(fdel);
   for(i = 0; i < 100000; i+= 10000)
   {
   	write_10k(h1);
   }
   
   offs = yaffs_lseek(h1,0,SEEK_CUR);
   if( offs != 200000)
   {
   	printf("Could not write file\n");
   }
   
   yaffs_close(h1);
   yaffs_unlink(fdel1);
   
}
예제 #15
0
/*==============================================================================
 * - cat()
 *
 * - print a file context
 */
int cat(int argc, char *argv[])
{
    int fd;
    int read_byte;
    char file_context[1024];
    char path_name[PATH_LEN_MAX];

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

    _make_abs_path(path_name, argv[1]);

    /*
     * open file
     */
    fd = yaffs_open(path_name, O_RDONLY, 0);
    if ( fd ==  -1) {
        serial_printf("cannot open file '%s'", path_name);
        return CMD_ERROR;
    }

    /*
     * read and print file context
     */
    read_byte = yaffs_read(fd, file_context, 1023);
    while (read_byte > 0) {
        file_context[read_byte] = '\0';
        serial_printf(file_context);

        read_byte = yaffs_read(fd, file_context, 1023);
    }

    yaffs_close(fd);
    return CMD_OK;
}
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;

}
예제 #17
0
int dump_file_data(char *fn)
{
	int h;
	int i = 0;
	int ok = 1;
	unsigned char b;
	
	h = yaffs_open(fn, O_RDWR,0);

				
	printf("%s\n",fn);
	while(yaffs_read(h,&b,1)> 0)
	{
		printf("%02x",b);
		i++;
		if(i > 32) 
		{
		   printf("\n");
		   i = 0;;
		 }
	}
	printf("\n");
	yaffs_close(h);
	return ok;
}
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;

}
예제 #19
0
void read_a_file(char *fn)
{
	int h;
	int i = 0;
	unsigned char b;

	h = yaffs_open(fn, O_RDWR,0);
	if(h<0)
	{
		printf("File not found\n");
		return;
	}

	while(yaffs_read(h,&b,1)> 0)
	{
		printf("%02x ",b);
		i++;
		if(i > 32)
		{
		   printf("\n");
		   i = 0;;
		 }
	}
	printf("\n");
	yaffs_close(h);
}
예제 #20
0
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;
	}
}
예제 #21
0
int test_yaffs_chmod_EROFS(void)
{
	int error=0;
	int output;
	if (yaffs_close(yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE))==-1){
		print_message("failed to create file\n",1);
		return -1;
	}
	EROFS_setup();

	output = yaffs_chmod(FILE_PATH,S_IREAD|S_IWRITE);

	if (output<0){
		error=yaffs_get_error();
		if (abs(error)==EROFS){
			return 1;
		} else {
			print_message("different error than expected\n",2);
			return -1;
		}
	} else {
		print_message("chmoded with EROFS setup (which is a bad thing)\n",2);
		return -1;
	}

}
예제 #22
0
int check_pattern_file(char *fn)
{
	int h;
	int marker;
	int i;
	int size;
	int ok = 1;
	
	h = yaffs_open(fn, O_RDWR,0);
	size = yaffs_lseek(h,0,SEEK_END);
		
	for(i = 0; i < size; i+=256)
	{
		yaffs_lseek(h,i,SEEK_SET);
		yaffs_read(h,&marker,sizeof(marker));
		ok = (marker == ~i);
		if(!ok)
		{
		   printf("pattern check failed on file %s, size %d at position %d. Got %x instead of %x\n",
					fn,size,i,marker,~i);
		}
	}
	yaffs_close(h);
	return ok;
}
예제 #23
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);
	}
	
}
예제 #24
0
void handle_test(const char *mountpt)
{
	int i;
	int h;
	int cycle;
	char a[100];

	sprintf(a,"%s/aaa",mountpt);
	
	yaffs_StartUp();
	
	yaffs_mount(mountpt);

        for(cycle = 0; cycle < 5; cycle++){
        printf("Start cycle %d\n",cycle);
 	i = 0;
	do {
        h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
	printf("%d  handle %d\n",i,h);
	i++;
	} while(h >= 0);
	
	while(i >= -1) {
	 yaffs_close(i);
	 i--;
        }
        }
	
	yaffs_unmount(mountpt);
}
예제 #25
0
void verify_file_of_size(const char *fn,int syze)
{
	int h;
	int result;
	
	char xx[200];
	char yy[200];
	int l;
	
	int iterations = (syze + strlen(fn) -1)/ strlen(fn);
	
	h = yaffs_open(fn, O_RDONLY, S_IREAD | S_IWRITE);
		
	while (iterations > 0)
	{
		sprintf(xx,"%s %8d",fn,iterations);
		l = strlen(xx);
		
		result = yaffs_read(h,yy,l);
		yy[l] = 0;
		
		if(strcmp(xx,yy)){
			printf("=====>>>>> verification of file %s failed near position %lld\n",fn,(long long)yaffs_lseek(h,0,SEEK_CUR));
		}
		iterations--;
	}
	yaffs_close (h);
}
예제 #26
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;
	}	
}
int test_yaffs_open_ENAMETOOLONG(void)
{
	int output = 0;
	int x = 0;
	int error_code = 0;
	int file_name_length = 1000000;
	char file_name[file_name_length];

	strcat(file_name,YAFFS_MOUNT_POINT);
	for (x = strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
		file_name[x] = 'a';
	}
	file_name[file_name_length-2]='\0';
	handle = yaffs_open(file_name, O_CREAT | O_TRUNC| O_RDWR ,FILE_MODE );

	if (handle == -1){
		error_code = yaffs_get_error();

		if (abs(error_code) == ENAMETOOLONG){
			return 1;
		} else {
			print_message("different error than expected\n",2);
			return -1;
		}
	} else {
		//printf("handle %d \n",handle);
		print_message("non existant file opened.(which is a bad thing)\n", 2);
		return -1;
	}
}
예제 #28
0
void make_a_file(char *yaffsName, char bval, int sizeOfFile)
{
	int outh;
	int i;
	unsigned char buffer[100];

	outh = yaffs_open(yaffsName,
				O_CREAT | O_RDWR | O_TRUNC,
				S_IREAD | S_IWRITE);
	if (outh < 0) {
		printf("Error opening file: %d. %s\n", outh, yaffs_error_str());
		return;
	}

	memset(buffer, bval, 100);

	do {
		i = sizeOfFile;
		if (i > 100)
			i = 100;
		sizeOfFile -= i;

		yaffs_write(outh, buffer, i);

	} while (sizeOfFile > 0);


	yaffs_close(outh);
}
예제 #29
0
/*==============================================================================
 * - cp()
 *
 * - copy a file form here to there
 */
int cp(int argc, char *argv[])
{
    int fd_in, fd_out;
    int read_byte, write_byte;
    char file_context[1024];

    char old_path_name[PATH_LEN_MAX];
    char new_path_name[PATH_LEN_MAX];

    CHECK_ARG_NUM(3, "too few argument");

    _make_abs_path(old_path_name, argv[1]);
    fd_in = yaffs_open(old_path_name, O_RDONLY, 0);
    CHECK_YAFFS_RETVAL(fd_in, "can't open file '%s'%s\n", old_path_name, "");

    _make_abs_path(new_path_name, argv[2]);
    fd_out = yaffs_open(new_path_name, O_CREAT|O_RDWR|O_TRUNC, S_IREAD|S_IWRITE);
    if (fd_out == -1) {
        yaffs_close(fd_in);
        serial_printf("can't create file '%s'", new_path_name);
        return CMD_ERROR;
    }

    /*
     * read from fd_in and write to fd_out
     */
    read_byte = yaffs_read(fd_in, file_context, 1024);
    while (read_byte > 0) {
        write_byte = yaffs_write(fd_out, file_context, read_byte);
        if (write_byte != read_byte) {
            serial_printf("copy file failed!");
            break;
        }

        read_byte = yaffs_read(fd_in, file_context, 1024);
    }

    yaffs_close(fd_in);
    yaffs_close(fd_out);

    if (read_byte > 0) {
        return CMD_ERROR;
    } else {
        return CMD_OK;
    }
}
예제 #30
0
void V5M_SaveImageFile(char *str, char *buf, UINT32 len)
{
	int h;

	yaffs_unlink(str);
	h = yaffs_open(str,  O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
	yaffs_write(h, buf, (unsigned int)len);
	yaffs_close(h);
}