예제 #1
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;
	
}
예제 #2
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;
}
예제 #3
0
void File_Get_Config_Accumulate(int* f, Accumulate_Config* accumulate_conf)
{
		int n;
		char buf[BUFFERSIZE];

		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d %d %d %d", &accumulate_conf->testpointNo, &accumulate_conf->sensorName, &accumulate_conf->portType, &n );   //测点编号,传感器类型,端口类型,端口地址
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		strcpy( accumulate_conf->location, buf );               //安装地点
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d", &accumulate_conf->measureMaxVal );
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%f", &accumulate_conf->coefficient );
	
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d", &accumulate_conf->shift );

		return;
}
예제 #4
0
int cache_bypass_bug_test(void)
{
	// This test reporoduces a bug whereby YAFFS caching *was* buypassed
	// resulting in erroneous reads after writes.
	// This bug has been fixed.
	
	int a;
	int i;
	char buffer1[1000];
	char buffer2[1000];
	
	memset(buffer1,0,sizeof(buffer1));
	memset(buffer2,0,sizeof(buffer2));
		
	yaffs_StartUp();
	
	yaffs_mount("/boot");
	
	// Create a file of 2000 bytes.
	make_a_file("/boot/a",'X',2000);

	a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
	
	// Write a short sequence to the file.
	// This will go into the cache.
	yaffs_lseek(a,0,SEEK_SET);
	yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20); 

	// Read a short sequence from the file.
	// This will come from the cache.
	yaffs_lseek(a,0,SEEK_SET);
	yaffs_read(a,buffer1,30); 

	// Read a page size sequence from the file.
	yaffs_lseek(a,0,SEEK_SET);
	yaffs_read(a,buffer2,512); 
	
	printf("buffer 1 %s\n",buffer1);
	printf("buffer 2 %s\n",buffer2);
	
	if(strncmp(buffer1,buffer2,20))
	{
		printf("Cache bypass bug detected!!!!!\n");
	}
	
	
	return 1;
}
예제 #5
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);
}
예제 #6
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;
}
예제 #7
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;
}
예제 #8
0
파일: file.c 프로젝트: HackLinux/jz4725
/*
 * Play DSP from WAV file:
 */
int PlayDSP(DSPFILE *dfile, WAVFILE *wfile)
{
	UInt32 byte_count = (UInt32) wfile->wavinfo.Samples;
	int bytes;
	int n;
	int byte_modulo;
        int total_bytes;

	//First determine how many bytes are required for each channel's sample:
	switch ( wfile->wavinfo.DataBits ) 
	{
	case 8 :
		byte_count = 1;
		break;
	case 16 :
		byte_count = 2;
		break;
	default :
		printf("Cannot process %u bit samples\n", (unsigned)wfile->wavinfo.DataBits);
		return -1;
	}

	byte_modulo = byte_count;				/* This many bytes per sample */
	byte_count  = wfile->wavinfo.Samples * byte_modulo;	/* Total bytes to process */
        total_bytes = byte_count;

        /* Seek to requested start sample */
        yaffs_lseek(wfile->fd,wfile->StartSample*byte_modulo,SEEK_CUR);
 
	for (; byte_count > 0 && wfile->wavinfo.DataBytes > 0; byte_count -= (UInt32) n ) 
	{
		bytes = (int) ( byte_count > dfile->dspblksiz ? dfile->dspblksiz : byte_count );
		if ( bytes > wfile->wavinfo.DataBytes )	/* Size bigger than data chunk? */
			bytes = wfile->wavinfo.DataBytes;	/* Data chunk only has this much left */

	//	printf("play databytes:%d bytes:%d n:%d\n",wfile->wavinfo.DataBytes,bytes,n);

		if ( (n = yaffs_read(wfile->fd,dfile->dspbuf,bytes)) != bytes ) 
		{
			if ( n >= 0 )
				printf("Unexpected EOF reading samples from WAV file\n");
			else	
				printf("Reading samples from WAV file\n");
			goto errxit;
		}
	//	printf("pcm writeing data\n");//treckle
		if (pcm_write(dfile->dspbuf,n) <= 0)
		{
			printf("Writing samples data failed\n");
			goto errxit;
		}
	//	printf("end pcm writeing data\n");//treckle
		wfile->wavinfo.DataBytes -= (UInt32) bytes;	/* We have fewer bytes left to read */
		//printf("dspblksize=%d bytes=%d DataBytes=%d\n", dfile->dspblksiz, bytes, wfile->wavinfo.DataBytes);

        }
	return 0;	/* All samples played successfully */

	errxit:	return -1;	/* Indicate error return */
}
예제 #9
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);
}
예제 #10
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);	   
	
}
예제 #11
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;
    }
}
예제 #12
0
void File_Get_Config_Analogue(int* f, Analogue_Config* analogue_conf)
{
		int n;
		char buf[BUFFERSIZE];
	
		printf("In Analogue Config Function:\n");
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %d %d %d", &analogue_conf->testpointNo, &analogue_conf->sensorName, &analogue_conf->portType, &n );   //测点编号,传感器类型,端口类型,端口地址
				
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		strcpy( analogue_conf->location, buf );               //安装地点
				
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %d", &analogue_conf->alarm.minval, &analogue_conf->alarm.maxval );
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %d", &analogue_conf->liftAlarm.minval, &analogue_conf->liftAlarm.maxval );
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %d", &analogue_conf->measureRange.minval, &analogue_conf->measureRange.maxval );
				
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %d", &analogue_conf->outage.minval, &analogue_conf->outage.maxval );
				
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %d", &analogue_conf->recover.minval, &analogue_conf->recover.maxval );
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read((*f), buf, BUFFERSIZE );
		printf( "buf=[%s]\n", buf );
		sscanf( buf, "%d %f", &analogue_conf->outputControl, &analogue_conf->coefficient );
		
		printf("Quit Analogue Config Function\n");
	
		return;
}
예제 #13
0
void File_Get_Config_Switch(int* f, Switch_Config* switch_conf)
{
		int n;
		char buf[BUFFERSIZE];
	
		printf("In Switch Config Function:\n");
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d %d %d %d", &switch_conf->testpointNo, &switch_conf->sensorName, &switch_conf->portType, &n );   //测点编号,传感器类型,端口类型,端口地址
				
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		strcpy( switch_conf->location, buf );               //安装地点
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d", &switch_conf->outputControl );	
		
		printf("Quit Switch Config Function\n");

		return;
}
예제 #14
0
void File_Get_Config_Tristate(int* f, Tristate_Config* tristate_conf)
{
		int n;
		char buf[BUFFERSIZE];
	
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d %d %d %d", &tristate_conf->testpointNo, &tristate_conf->sensorName, &tristate_conf->portType, &n );   //测点编号,传感器类型,端口类型,端口地址
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		strcpy( tristate_conf->location, buf );               //安装地点
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d %d %d", &tristate_conf->current[0], &tristate_conf->current[1], &tristate_conf->current[2] );
		
		memset(buf, '\0', sizeof(buf));
		n = yaffs_read( (*f), buf, BUFFERSIZE );
		sscanf( buf, "%d", &tristate_conf->outputControl );
	
		return;
}
예제 #15
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]);
}
예제 #16
0
void simple_rw_test(const char *mountpt)
{
	int i;
	int h;
	char a[100];
	
	int x;
	int result;

	sprintf(a,"%s/aaa",mountpt);
	
	yaffs_StartUp();
	
	yaffs_mount(mountpt);
	
	yaffs_unlink(a);
	
	h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
	
	for(i = 100000;i < 200000; i++){
		result = yaffs_write(h,&i,sizeof(i));
		
		if(result != 4)
		{
			printf("write error\n");
			exit(1);
		}
	}
	
	//yaffs_close(h);
	
	// h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
	
	
	yaffs_lseek(h,0,SEEK_SET);
	
	for(i = 100000; i < 200000; i++){
		result = yaffs_read(h,&x,sizeof(x));
		
		if(result != 4 || x != i){
			printf("read error %d %x %x\n",i,result,x);
		}
	}
	
	printf("Simple rw test passed\n");
	
	
	
}
예제 #17
0
int LoadImageFile(char *str, char *buf, int size)
{
	int h;
	int len;
	
	h = yaffs_open(str, O_RDONLY, S_IREAD | S_IWRITE);
	if(h == -1)
		return 0;
	len = (int)yaffs_lseek(h, 0, SEEK_END);
	if(len > size)
		len = size;
	yaffs_lseek(h, 0, SEEK_SET);
	yaffs_read(h, buf, len);
	yaffs_close(h);

	return len;
}
예제 #18
0
void cmd_yaffs_mread_file(char *fn, char *addr)
{
	int h;
	struct yaffs_stat s;

	yaffs_stat(fn, &s);

	printf("Copy %s to 0x%p... ", fn, addr);
	h = yaffs_open(fn, O_RDWR, 0);
	if (h < 0) {
		printf("File not found\n");
		return;
	}

	yaffs_read(h, addr, (int)s.st_size);
	printf("\t[DONE]\n");

	yaffs_close(h);
}
예제 #19
0
파일: ebook.c 프로젝트: WangDongfang/DfewOS
/*==============================================================================
 * - _open_file()
 *
 * - open a text file, and read it's all context to memory
 */
static OS_STATUS _open_file (const char *file_name)
{
    struct yaffs_stat statFile;
    int fd;
    int read_cnt;

    /* alloc memory to store file text */
    if (yaffs_stat (file_name, &statFile) < 0) { /* not exist */
        return OS_STATUS_ERROR;
    }
	_G_text = calloc (1, statFile.st_size + 1);

    /* open file */
    fd = yaffs_open (file_name, O_RDONLY, 0666);
	if (fd < 0) {
        free (_G_text);
        return OS_STATUS_ERROR;
	}

    /* read text */
	read_cnt = yaffs_read (fd, _G_text, statFile.st_size);
	if (read_cnt < 0) {
        free (_G_text);
        yaffs_close (fd);
        return OS_STATUS_ERROR;
	}

    /* close file */
	yaffs_close (fd);

    /* make book name */
    {
        char *ext = NULL;

        strcpy (_G_book_name, strrchr (file_name, '/') + 1);
        if ((ext = strrchr (_G_book_name, '.')) != NULL) {
            *ext = '\0';
        }
    }

    return OS_STATUS_OK;
}
예제 #20
0
char *V5M_LoadImageFile(char *str, UINT32 *size)
{
	int h;
	char *buf = NULL;
	
	h = yaffs_open(str, O_RDONLY, S_IREAD | S_IWRITE);
	if(h == -1)
		return NULL;

	*size = (int)yaffs_lseek(h, 0, SEEK_END);
	yaffs_lseek(h, 0, SEEK_SET);

	if (*size == 0)
		return NULL;
	buf = (char *) gHapiContext.pmalloc(*size);
	yaffs_read(h, buf, (unsigned int)(*size));
	yaffs_close(h);

	return buf;
}
예제 #21
0
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;

}
예제 #22
0
int test_yaffs_read_EINVAL(void)
{
	int error_code = 0;
	handle=yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE);
	char text[2000000];
	int output=0;	
	
	if (handle<0){
		print_message("could not open file\n",2);
		return -1;
	}	

	/*there needs a large amout of test in the file in order to trigger EINVAL */
	output=test_yaffs_read_EINVAL_init();
	if (output<0){
		print_message("could not write text to the file\n",2);
		return -1; 
	}

	if (handle>=0){
		output=yaffs_read(handle, text, -1);
		if (output<0){ 
			error_code=yaffs_get_error();
			if (abs(error_code)== EINVAL){
				return 1;
			} else {
				print_message("different error than expected\n",2);
				return -1;
			}
		} else{
			print_message("read a negative number of bytes (which is a bad thing)\n",2);
			return -1;
		}
	} else {
		print_message("error opening file\n",2);
		return -1;
	}
}
예제 #23
0
/*==============================================================================
 * - T_web_server_start()
 *
 * - http server task
 */
void T_web_server_start ()
{   
    int sockfd;                        // Socket file descriptor
    int nsockfd;                       // New Socket file descriptor
    int num;
    socklen_t       sin_size;                      // to store struct size
    char revbuf[LENGTH]; 
    struct sockaddr_in addr_local;     
    struct sockaddr_in addr_remote;    
               
    /* Get the Socket file descriptor */  
    if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1 )  {   
        serial_printf ("ERROR: Cannot obtain Socket Despcritor.\n");
        return ;
    } else {
        WEB_LOG ("OK: Obtain Socket Despcritor sucessfully.\n");
    }
    
    /* Fill the local socket address struct */
    addr_local.sin_family = AF_INET;           // Protocol Family
    addr_local.sin_port = htons(PORT);         // Port number
    addr_local.sin_addr.s_addr  = INADDR_ANY;  // AutoFill local address
    memset(&(addr_local.sin_zero), 0, 8);          // Flush the rest of struct

    /*  Blind a special Port */
    if( bind(sockfd, (struct sockaddr*)&addr_local, sizeof(struct sockaddr)) == -1 ) {  
        serial_printf ("ERROR: Cannot bind Port %d\n.",PORT);
        return ;
    } else {
        WEB_LOG ("OK: Bind the Port %d sucessfully.\n",PORT);
    }
   
    /*  Listen remote connect/calling */
    if(listen(sockfd,BACKLOG) == -1)    {  
        serial_printf ("ERROR: Cannot listen Port %d\n.", PORT);
        return ;
    } else {
        WEB_LOG ("OK: Listening the Port %d sucessfully.\n", PORT);
    }
   
    while(1) {  
        sin_size = sizeof(struct sockaddr_in);  
        
        /*  Wait a connection, and obtain a new socket file despriptor for single connection */
        if ((nsockfd = accept(sockfd, (struct sockaddr *)&addr_remote, &sin_size)) == -1) {  
            serial_printf ("ERROR: Obtain new Socket Despcritor error\n");
            continue;
        } else {
            WEB_LOG ("OK: Server has got connect from %s\n", inet_ntoa(addr_remote.sin_addr)); 
        }
        
        num = recv(nsockfd, revbuf, LENGTH, 0);
        revbuf[num] = '\0';
        WEB_LOG (revbuf);
        
        /* Child process */
//        if(!fork())                    
        {  
            WEB_LOG ("OK: Http web is servering.\n");

            if(revbuf[5]==' ') {

                send(nsockfd, reply, sizeof(reply), 0); 
                send(nsockfd, html, sizeof(html), 0); 
            } else if(revbuf[5]=='1') {

                send(nsockfd, httpgif, sizeof(httpgif), 0);
                send(nsockfd, bmp, sizeof(bmp), 0);
            } else {
                char file_name[PATH_LEN_MAX] = {WEB_PATH};
                char file_context[1024];
                char send_context[2048];
                int  i = 5;
                int  fd;
                int  read_byte;
                int  send_byte;
#if 0
                int  f_len, h_len = strlen(HOME_HTML);
#endif
                while (!isspace(revbuf[i++]))
                    ;
                revbuf[--i] = '\0';
                strncat (file_name, revbuf + 5, PATH_LEN_MAX - strlen(file_name) - 1);
                file_name[PATH_LEN_MAX - 1] = '\0';
                
#if 0
                f_len = strlen (file_name);
                if ((f_len > h_len) &&
                    (strcmp (file_name + f_len - h_len, HOME_HTML) == 0)) {
                    strcpy (file_name, WEB_PATH HOME_HTML);
                }
#endif

                fd = yaffs_open(file_name, O_RDONLY, 0);
                if ( fd ==  -1) {
                    serial_printf("ERROR: Cannot open file %s", file_name);
                }

                if ( (strcmp (strchr (file_name, '.'), ".html") == 0) || /* *.html */
                     (strcmp (strchr (file_name, '.'), ".jpg") == 0)) { /* *.jpg */
                    read_byte = yaffs_read(fd, file_context, 1024);
                    while (read_byte > 0) {
                        send(nsockfd, file_context, read_byte, 0);
                        read_byte = yaffs_read(fd, file_context, 1024);
                    }
                } else { /* !.html */

                send(nsockfd, html_start, sizeof(html_start), 0); 
                read_byte = yaffs_read(fd, file_context+1, 1023);
                file_context[0] = '|';
                read_byte++;
                while (read_byte > 1) {
                    send_byte = 0;
                    for (i = 0; i < read_byte; i++) {
                        if (file_context[i] == '\n') {
                            send_context[send_byte++] = '<';
                            send_context[send_byte++] = 'B';
                            send_context[send_byte++] = 'R';
                            send_context[send_byte++] = '>';
                            send_context[send_byte++] = '|';
                        } else if (file_context[i] == '<'){
                            send_context[send_byte++] = '&';
                            send_context[send_byte++] = 'l';
                            send_context[send_byte++] = 't';
                        } else if (file_context[i] == '&'){
                            send_context[send_byte++] = '&';
                            send_context[send_byte++] = 'a';
                            send_context[send_byte++] = 'm';
                            send_context[send_byte++] = 'p';
                        } else if (file_context[i] == '"'){
                            send_context[send_byte++] = '&';
                            send_context[send_byte++] = 'q';
                            send_context[send_byte++] = 'u';
                            send_context[send_byte++] = 'o';
                            send_context[send_byte++] = 't';
                        }else {
                            send_context[send_byte++] = file_context[i];
                        }
                    }

                    send(nsockfd, send_context, send_byte, 0); 

                    read_byte = yaffs_read(fd, file_context, 1024);
                }
                send(nsockfd, html_end, sizeof(html_end), 0); 

                } /* !*.html */

                yaffs_close(fd);
            }
        }      
        close(nsockfd);  
//        while(waitpid(-1, NULL, WNOHANG) > 0);
    }    
}
예제 #24
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;

}
예제 #25
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);
	}
}
예제 #26
0
static int yVerifyFile(const char *fName)
{
	unsigned checksum = 0;
	unsigned totalSize;
	unsigned sz32;
	unsigned recordedSize = 0;
	int r;
	int h;
	int i;
	int retval = 0;


        printf("Verifying file %s\n",fName);
        	
	h = yaffs_open(fName, O_RDONLY,S_IREAD | S_IWRITE);

	if(h < 0){
		printf("could not open file %s\n",fName);
		return -1;
	}

	totalSize = yaffs_lseek(h,0,SEEK_END);
	yaffs_lseek(h,0,SEEK_SET);

	r = yaffs_read(h,&sz32,sizeof(sz32));

	if(r != sizeof(sz32)){
		printf("reading size failed ... returned %d\n",r);
		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);
	if(totalSize != recordedSize){
		printf("!!!!!!!!!!!!!!!!!!!!!!!!file size is wrong, should be %d, is %d\n", recordedSize,totalSize);
		yaffs_close(h);
		return -1;
	}

	checksum ^= sz32;


	while(sz32 > 0){
		r = yaffs_read(h,xx,sizeof(xx));
		if(r != sizeof(xx)){
			printf("!!!!!!!!!!!!!!!!!!!!!!!!!!reading data failed ... returned %d\n",r);
			yaffs_close(h);
			return -1;
		}
		for(i = 0; i < XX_SIZE; i++)
		  checksum ^= xx[i];
		sz32--;
	}
	r = yaffs_read(h,xx,sizeof(xx[0]));
	if(r != sizeof(xx[0])){
		printf("!!!!!!!!!!!!!!!!!!!!!!!!!!reading data failed ... returned %d\n",r);
		yaffs_close(h);
		return -1;
	}
	
	checksum ^= xx[0];

	if(checksum != 0){
		printf("!!!!!!!!!!!!!!!!!!!!! checksum failed\n");
		retval = -1;
        } else
		printf("verified ok\n");
	yaffs_close(h);

	return retval;
}
예제 #27
0
파일: file.c 프로젝트: HackLinux/jz4725
/*
 * Open a WAV file for reading: returns (WAVFILE *)
 *
 * The opened file is positioned at the first byte of WAV file data, or
 * NULL is returned if the open is unsuccessful.
 */
WAVFILE *WavOpenForRead(const char *Pathname) 
{
	WAVFILE *wfile;
	UInt32 offset;				/* File offset */
	Byte ubuf[4];				/* 4 byte buffer */
	UInt32 dbytes;				/* Data byte count */
						/* wavfile.c values : */
	int channels;				/* Channels recorded in this wav file */
	u_long samplerate;			/* Sampling rate */
	int sample_bits;			/* data bit size (8/12/16) */
	u_long samples;				/* The number of samples in this file */
	u_long datastart;			/* The offset to the wav data */

	if(g_wfile) WavClose(g_wfile); 

	wfile = wavfile_alloc(Pathname);

	if ( wfile == NULL )
		return NULL;			/* Insufficient memory (class B msg) */

	/*
	 * Open the file for reading:
	 */
	printf("Opening WAV file %s\n", wfile->Pathname);
	if ( (wfile->fd = yaffs_open(wfile->Pathname,O_RDONLY)) < 0 ) 
	{
		printf("Opening WAV file %s failed\n", wfile->Pathname);
		goto errxit;
	}

	if ( yaffs_lseek(wfile->fd,0,SEEK_SET) != 0 ) 
	{
		printf("Rewinding WAV file %s\n",wfile->Pathname);
		goto errxit;		/* Wav file must be seekable device */
	}

	if ( WaveReadHeader(wfile->fd,&channels,&samplerate,&sample_bits,&samples,&datastart) != 0 ) 
	{
		printf("Reading WAV header from %s", wfile->Pathname);
		goto errxit;
	}

	/*
	 * Copy WAV data over to WAVFILE struct:
	 */
	if ( channels == 2 )
		wfile->wavinfo.Channels = Stereo;
	else	wfile->wavinfo.Channels = Mono;

	wfile->wavinfo.SamplingRate = (UInt32) samplerate;
	wfile->wavinfo.Samples = (UInt32) samples;
	wfile->wavinfo.DataBits = (UInt16) sample_bits;
	wfile->wavinfo.DataStart = (UInt32) datastart;
        wfile->num_samples = wfile->wavinfo.Samples;

	offset = wfile->wavinfo.DataStart - 4;

	/*
	 * Seek to byte count and read dbytes:
	 */
	if ( yaffs_lseek(wfile->fd,offset,SEEK_SET) != offset ) 
	{
		printf("Seeking to WAV data in %s",wfile->Pathname);
		goto errxit;			/* Seek failure */
	}

	if ( yaffs_read(wfile->fd,ubuf,4) != 4 ) 
	{
		printf("Reading dbytes from %s",wfile->Pathname);
		goto errxit;
	}

	/*
	 * Put little endian value into 32 bit value:
	 */
	dbytes = ubuf[3];
	dbytes = (dbytes << 8) | ubuf[2];
	dbytes = (dbytes << 8) | ubuf[1];
	dbytes = (dbytes << 8) | ubuf[0];

	wfile->wavinfo.DataBytes = dbytes;

	/*
	 * Open succeeded:
	 */
	return wfile;				/* Return open descriptor */

	/*
	 * Return error after failed open:
	  WavClose*/
errxit:	
	mem_free(wfile);				/* Dispose of WAVFILE struct */
	return NULL;				/* Return error indication */
}
예제 #28
0
UINT32 V5M_fread(UINT8 *buf, UINT32 length, V5MF_HANDLE file)
{
	return (UINT32) yaffs_read(file, (void *)buf, (unsigned int) length );
}
예제 #29
0
파일: yaffs.c 프로젝트: charlestac/smileos
static ssize_t __yaffs_read(mount_point_t *point, file_t *file, void *buf, size_t len)
{
    return yaffs_read((int)file->ctx, buf, len);
}
예제 #30
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");
}