yaffs Improve yaffs direct link following
[yaffs2.git] / direct / basic-test / dtest.c
index 3ac5604284dbd3c3a577aabc19c48d47f9685861..fe485e2bc9d85854469d956f431b7a849dee363c 100644 (file)
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <time.h>
 
 #include "yaffsfs.h"
 
@@ -28,9 +29,7 @@ extern int yaffs_traceMask;
 
 void dumpDir(const char *dname);
 
-char xx[600];
-
-void copy_in_a_file(char *yaffsName,char *inName)
+void copy_in_a_file(const char *yaffsName,const char *inName)
 {
        int inh,outh;
        unsigned char buffer[100];
@@ -52,7 +51,7 @@ void copy_in_a_file(char *yaffsName,char *inName)
        close(inh);
 }
 
-void make_a_file(char *yaffsName,char bval,int sizeOfFile)
+void make_a_file(const char *yaffsName,char bval,int sizeOfFile)
 {
        int outh;
        int i;
@@ -401,7 +400,8 @@ void fill_disk(const char *path,int nfiles)
        int n;
        int result;
        int f;
-       
+
+        static char xx[600];   
        char str[50];
        
        for(n = 0; n < nfiles; n++)
@@ -481,7 +481,7 @@ void fill_files(const char *path,int flags, int maxIterations,int siz)
        }
 }
 
-void leave_unlinked_file(char *path,int maxIterations,int siz)
+void leave_unlinked_file(const char *path,int maxIterations,int siz)
 {
        int i;
        char str[50];
@@ -531,7 +531,7 @@ void dumpDirFollow(const char *dname)
                {
                        sprintf(str,"%s/%s",dname,de->d_name);
                        
-                       yaffs_stat(str,&s);
+                       yaffs_lstat(str,&s);
                        
                        printf("%s ino %d length %d mode %X ",de->d_name,(int)s.st_ino,(int)s.st_size,s.st_mode);
                        switch(s.st_mode & S_IFMT)
@@ -741,7 +741,7 @@ int long_test(int argc, char *argv[])
        dumpDir("/boot");
 
        // Check stat
-       r = yaffs_stat("/boot/file with a long name",&ystat);
+       r = yaffs_lstat("/boot/file with a long name",&ystat);
        
        // Check rename
        
@@ -828,7 +828,7 @@ int long_test(int argc, char *argv[])
        
        // Check chmod
        
-       yaffs_stat("/boot/yyfile",&ystat);
+       yaffs_lstat("/boot/yyfile",&ystat);
        temp_mode = ystat.st_mode;
        
        yaffs_chmod("/boot/yyfile",0x55555);
@@ -1094,12 +1094,12 @@ int root_perm_remount(const char *path)
    
    yaffs_mount(path);
    
-   yaffs_stat(path,&s);
+   yaffs_lstat(path,&s);
    printf("root perms after mount %x\n",s.st_mode);
    
    yaffs_chmod(path, 0777);
 
-   yaffs_stat(path,&s);
+   yaffs_lstat(path,&s);
    printf("root perms after setting to 0777 is  %x\n",s.st_mode);
    
    yaffs_unmount(path);
@@ -1498,7 +1498,7 @@ void long_name_test(const char *mountpt)
        char name[300];
        int result = 0;
        
-       int d,f;
+       int f;
        
        // Make a 256 byte name
        memset(name,0,sizeof(name));
@@ -1602,7 +1602,6 @@ void lookup_test(const char *mountpt)
 
 void link_test0(const char *mountpt)
 {
-       int i;
        char namea[300];
        char nameb[300];
        int result = 0;
@@ -2176,7 +2175,7 @@ void small_overwrite_test(const char *mountpt,int nmounts)
 
 void seek_overwrite_test(const char *mountpt,int nmounts)
 {
-
+        static char xx[5000];
        char a[30];
        
        int i;
@@ -2556,7 +2555,6 @@ void basic_xattr_test(const char *mountpt)
        int h;
        int result;
        int val1;
-       int valread;
 
        yaffs_StartUp();
 
@@ -2607,7 +2605,6 @@ void big_xattr_test(const char *mountpt)
        int h;
        int result;
        char val[1000];
-       char valread[1000];
 
        yaffs_StartUp();
 
@@ -2686,6 +2683,34 @@ void test_flash_traffic(const char *mountpt)
 
 }
 
+void link_follow_test(const char *mountpt)
+{
+       char fn[100];
+       char sn[100];
+       char hn[100];
+       int result;
+       int h;
+       
+       yaffs_traceMask = 0;
+
+       yaffs_StartUp();
+
+       yaffs_mount(mountpt);
+
+       sprintf(fn,"%s/file",mountpt);
+       sprintf(sn,"%s/sym",mountpt);
+       sprintf(hn,"%s/hl-sym",mountpt);
+       
+       h = yaffs_open(fn,O_CREAT| O_RDWR, S_IREAD | S_IWRITE);
+       result = yaffs_close(h);
+
+       result = yaffs_symlink(fn,sn);
+       result = yaffs_link(sn,hn);
+
+       h =yaffs_open(hn,O_RDWR,0);
+
+}
+
 int random_seed;
 int simulate_power_failure;
 
@@ -2750,6 +2775,7 @@ int main(int argc, char *argv[])
         //null_name_test("yaffs2");
 
         test_flash_traffic("yaffs2");
+        link_follow_test("/yaffs2");
 
         return 0;