[Yaffs-archive] maybe I found a bug?

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: guo@unication.com.cn
Date:  
To: yaffs
Subject: [Yaffs-archive] maybe I found a bug?
Dear All,
    I use yaffs in a PDA. Some error was occured, and we debug it. At last, it seems yaffs bug. I writed a very simple program to test it in yaffsram and mtd IF. the result are same.

before run this program, please mount -t yaffsram none /mnt/yaffs. yaffs.o need be inserted, as you known. the Makefile  USE_RAM_FOR_TEST must be unmarked.

follwing the program:
-------------------------------
// very Simple program to test YAFFS
// by Russell Greece, 
// 2003-12-04

// bind a unix domain socket, delete PATH it without closed
// loop for  make a normal file, rename it
// and then, error occured
// I found the inode numbers of socket and new file are identical

// Why I do this test:
// I choosed YAFFS in my new system, qt/Embedded and Qtopia cannot
//   run successful often.
// So my friend Timmy Lee() and I debug it,
//   at last, we found this point 
// I need help. pleeeeeeease...

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <sys/un.h>
#include <netdb.h>
#include <errno.h>
#include <stdlib.h>
 

// Get inode of specified PATH
static long long FileINode(const char *FileName)
{
 struct stat Stat;
 if (stat(FileName, &Stat) < 0) {
  return -1;
 }
 return Stat.st_ino;
}

#define UNLINK_FILE_NAME "/mnt/yaffs/russell_unlinked"

// create a socket PATH(unix domain), rm the PATH, keep fd openning
static void BindSocket(void)
{
 int error;
 int s = socket( PF_LOCAL, SOCK_STREAM, 0 );
 struct sockaddr_un a;

 memset( &a, 0, sizeof(a) );
 a.sun_family = PF_LOCAL;
 strncpy( a.sun_path, UNLINK_FILE_NAME, sizeof(a.sun_path) - 1 );
 error = bind( s, (struct sockaddr*)&a, SUN_LEN(&a) );
 if (error < 0) {
  perror("bind:");
 }
 printf ("inode of %s is %lld\n", UNLINK_FILE_NAME, FileINode(UNLINK_FILE_NAME));
 unlink (UNLINK_FILE_NAME);
}


// create a file FileName."new", write it, and rename it to FileName
static int TestCount = 0;
static void TestFile(const char *FileName)
{
 int fd;
 int i;
 char TmpFileName[strlen(FileName) + 1 + 4];

 TestCount ++;
 sprintf(TmpFileName, "%s.new", FileName);
 fd = open(TmpFileName, O_CREAT|O_WRONLY, 0666);
 if (fd < 0) {
  perror("open new");
  printf("Test count is %d\n", TestCount);
  printf ("inode of %s is %lld\n", TmpFileName, FileINode(TmpFileName));
  exit(1);
 }
 for (i = 0; i < 10; i++) {
  char Buffer[100];
  sprintf(Buffer, "this is line %d\n", i + 1);
  write(fd, Buffer, strlen(Buffer));
 }
 close (fd);
 rename(TmpFileName, FileName);
}

// you know that
int main(void)
{
 BindSocket();
 
 for (;;) {
  TestFile("/mnt/yaffs/russell_normal");
 }
 return 0;

}