changeset 122:5dbd6682bfb2

Add hardlinks to yaffs direct
author charles
date Wed, 08 Feb 2006 22:38:24 +0000
parents d02f0fbee6ee
children 2292eab33128
files direct/dtest.c direct/yaffsfs.c
diffstat 2 files changed, 109 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/direct/dtest.c
+++ b/direct/dtest.c
@@ -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");
+	
 	
 	
 	
--- a/direct/yaffsfs.c
+++ b/direct/yaffsfs.c
@@ -1402,7 +1402,66 @@ int yaffs_readlink(const char *path, cha
 	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)