Add hardlinks to yaffs direct
authorcharles <charles>
Wed, 8 Feb 2006 22:38:24 +0000 (22:38 +0000)
committercharles <charles>
Wed, 8 Feb 2006 22:38:24 +0000 (22:38 +0000)
direct/dtest.c
direct/yaffsfs.c

index a48c618..8edd85f 100644 (file)
@@ -1347,6 +1347,49 @@ void lookup_test(const char *mountpt)
        
 }
 
+void link_test(const char *mountpt)
+{
+       int i;
+       int h;
+       char a[100];
+       char b[100];
+       char c[100];
+       
+       int  f0;
+       int f1;
+       int f2;
+       int f3;
+       sprintf(a,"%s/aaa",mountpt);
+       sprintf(b,"%s/bbb",mountpt);
+       sprintf(c,"%s/ccc",mountpt);
+       
+       yaffs_StartUp();
+       
+       yaffs_mount(mountpt);
+       
+       
+       h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
+       for(i = 0; i < 100; i++)
+               yaffs_write(h,a,100);
+       
+       yaffs_close(h);
+       
+       yaffs_unlink(b);
+       yaffs_unlink(c);
+       yaffs_link(a,b);
+       yaffs_link(a,c);
+       yaffs_unlink(b);
+       yaffs_unlink(c);
+       yaffs_unlink(a);
+       
+       
+       yaffs_unmount(mountpt);
+       yaffs_mount(mountpt);
+       
+       printf("link test done\n");     
+       
+}
+
 void freespace_test(const char *mountpt)
 {
        int i;
@@ -1623,11 +1666,14 @@ int main(int argc, char *argv[])
        
        //long_test_on_path("/ram2k");
        // long_test_on_path("/flash");
-       simple_rw_test("/flash/flash");
-       fill_disk_test("/flash/flash");
+       //simple_rw_test("/flash/flash");
+       //fill_disk_test("/flash/flash");
        // rename_over_test("/flash");
        //lookup_test("/flash");
-       freespace_test("/flash/flash");
+       //freespace_test("/flash/flash");
+       
+       link_test("/flash/flash");
+       
        
        
        
index 4f06f9c..914e714 100644 (file)
@@ -25,7 +25,7 @@
 #endif
 
 
-const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.7 2005-10-07 03:48:50 charles Exp $";
+const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.8 2006-02-08 22:38:24 charles Exp $";
 
 // configurationList is the list of devices that are supported
 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
@@ -1402,7 +1402,66 @@ int yaffs_readlink(const char *path, char *buf, int bufsiz)
        return retVal;
 }
 
-int yaffs_link(const char *oldpath, const char *newpath); 
+int yaffs_link(const char *oldpath, const char *newpath)
+{
+       // Creates a link called newpath to existing oldpath
+       yaffs_Object *obj = NULL;
+       yaffs_Object *target = NULL;
+       int retVal;
+
+               
+       yaffsfs_Lock();
+       
+       obj = yaffsfs_FindObject(NULL,oldpath,0);
+       target = yaffsfs_FindObject(NULL,newpath,0);
+       
+       if(!obj)
+       {
+               yaffsfs_SetError(-ENOENT);
+               retVal = -1;
+       }
+       else if(target)
+       {
+               yaffsfs_SetError(-EEXIST);
+               retVal = -1;
+       }
+       else    
+       {
+               yaffs_Object *newdir = NULL;
+               yaffs_Object *link = NULL;
+               
+               char *newname;
+               
+               newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0);
+               
+               if(!newdir)
+               {
+                       yaffsfs_SetError(-ENOTDIR);
+                       retVal = -1;
+               }
+               else if(newdir->myDev != obj->myDev)
+               {
+                       yaffsfs_SetError(-EXDEV);
+                       retVal = -1;
+               }
+               if(newdir && strlen(newname) > 0)
+               {
+                       link = yaffs_Link(newdir,newname,obj);
+                       if(link)
+                               retVal = 0;
+                       else
+                       {
+                               yaffsfs_SetError(-ENOSPC);
+                               retVal = -1;
+                       }
+
+               }
+       }
+       yaffsfs_Unlock();
+       
+       return retVal;
+}
+
 int yaffs_mknod(const char *pathname, mode_t mode, dev_t dev);
 
 int yaffs_DumpDevStruct(const char *path)