yaffs Merge branch 'namechange'
authorCharles Manning <cdhmanning@gmail.com>
Mon, 11 Oct 2010 22:35:05 +0000 (11:35 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Mon, 11 Oct 2010 22:35:05 +0000 (11:35 +1300)
Merge in first set of yaffs name changes

Conflicts:
direct/python/yaffs_python_helper.c
direct/yaffsfs.c

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/dtest.c
direct/python/yaffs_browser.py
direct/python/yaffs_python_helper.c
direct/python/yaffsfs.py
direct/yaffsfs.c

index 779ac15ce564e4ecf2376e44f7eda9b15cc85dd8..db38cb50fce44e39e25369994098e3170874ade4 100644 (file)
@@ -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);
@@ -2683,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;
 
@@ -2747,6 +2775,7 @@ int main(int argc, char *argv[])
         //null_name_test("yaffs2");
 
         test_flash_traffic("yaffs2");
+        link_follow_test("/yaffs2");
 
         return 0;
        
index d0faaffb9a6e803972d736901bd0717864ab85bf..8f88b975b9293c7cf0794c7ef47411cb55defd13 100755 (executable)
@@ -5,12 +5,12 @@ from yaffsfs import *
 import ctypes
 
 yaffs_StartUp()
-yaffs_mount("yaffs2/")
+yaffs_mount("/yaffs2/")
 root_window =tk.Tk()
 root_window.title("YAFFS Browser")
 mount_list_text_variable=tk.StringVar()
 
-mount_list_text_variable.set("yaffs2/")
+mount_list_text_variable.set("/yaffs2/")
 current_directory_dict={}
 open_windows_list=[]
 
@@ -20,24 +20,41 @@ class editor():
     save_button=[]
     file_contents=0
     file_path=0
+    isLink=0
     def save_file(self):
-        #global current_directory_dict
-        print "saving the file"
-        print self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
-        yaffs_lseek(self.yaffs_handle, 0, 0)
-        data_to_be_written=self.file_editor_text.get("1.0", tk.END)
-        print "data to be saved", data_to_be_written
-        length_of_file=len(data_to_be_written)
-        print "length of data to be written",length_of_file 
-        output=yaffs_write(self.yaffs_handle,data_to_be_written , length_of_file)
-        print "output", output
-        yaffs_ftruncate(self.yaffs_handle, length_of_file)
-        yaffs_close(self.yaffs_handle)
-        
-        self.yaffs_handle = yaffs_open(self.file_path,66,0666)
+        if  self.isLink==True:
+            target_path=self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
+            target_path=target_path[0:len(target_path)-1]
+            new_path=self.file_path
+            print "creating a symlink \n target:##", target_path, "##"
+            target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
+            if target_file_exists>=0:
+                ##file exists,create symlink
+                print "target file exist, creating symlink"
+                yaffs_unlink(new_path)
+                output=yaffs_symlink(target_path, new_path)
+                print "yaffs symlink output=", output
+                self.file_editor_root.destroy()
+            else :
+                ##file does not exist
+                print "target file does not exist, cannot create symlink"
+        else :
+            #global current_directory_dict
+            print "saving the file"
+            print self.file_editor_text.get("1.0", tk.END) ##"1.0" is the index of the first line of text
+            yaffs_lseek(self.yaffs_handle, 0, 0)
+            data_to_be_written=self.file_editor_text.get("1.0", tk.END)
+            print "data to be saved", data_to_be_written
+            length_of_file=len(data_to_be_written)
+            print "length of data to be written",length_of_file 
+            output=yaffs_write(self.yaffs_handle,data_to_be_written , length_of_file)
+            print "output", output
+            yaffs_ftruncate(self.yaffs_handle, length_of_file)
+            yaffs_close(self.yaffs_handle)
+            self.yaffs_handle = yaffs_open(self.file_path,66,0666)
         load_dir()
         
-    def __init__(self):
+    def __init__(self, isLink=0):
         global current_directory_dict
         x=name_list_box.curselection()
         self.id=int(x[0])
@@ -52,9 +69,17 @@ class editor():
         self.yaffs_handle = yaffs_open(current_directory_dict[self.id]["path"],66,0666)
         length_of_file=yaffs_lseek(self.yaffs_handle, 0, 2) ##seeks to the end of the file
         yaffs_lseek(self.yaffs_handle, 0, 0)## returns the handle to the front of th file
-        self.file_contents=ctypes.create_string_buffer(length_of_file)
-        yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
-        print "file contents", self.file_contents.raw
+        print "length of file to be opened:", length_of_file
+        if isLink==True:
+            print "opening symlink"
+            self.file_contents=ctypes.create_string_buffer(1000)
+            yaffs_readlink(self.file_path,self.file_contents,1000)
+            self.isLink=True
+        else:
+            print"opening file"
+            self.file_contents=ctypes.create_string_buffer(length_of_file)
+            yaffs_read(self.yaffs_handle,self.file_contents,length_of_file)
+            print "file contents", self.file_contents.raw
         self.file_editor_text.insert(tk.END, self.file_contents.raw)
         self.file_editor_text.pack()
         ##self.file_editor_text.bind("<Control-s>", self.save_file)
@@ -72,13 +97,13 @@ def load_dir():
     name_list_box.grid(column=0, row=1)
     return current_directory_dict
 
-def load_file():
+def load_file(link=0):
     global open_windows_list
-    open_windows_list.append(editor())
+    open_windows_list.append(editor(link))
 
 def load_command(self=0):
     global current_directory_dict
-    print "you loaded a file/dir"
+    print "you loaded a file/dir/link"
     x=name_list_box.curselection()
     x=int(x[0])
     print "cursor selection", x
@@ -103,8 +128,9 @@ def load_command(self=0):
         ##open file
         print "open file"
         load_file()
-    
-
+    elif current_directory_dict[x]["type"]=="link": 
+        print "loading a symlink"
+        load_file(1)
     ##mount_list_text_variable.set(mount_list_text_variable.get()+str(list[0][0]))
     
 def back_a_directory(self=0):
@@ -131,7 +157,7 @@ def back_a_directory(self=0):
     
     
     
-        
 def yaffs_ls(dname):
     ls_dict=[]
 
@@ -144,18 +170,29 @@ def yaffs_ls(dname):
             se = sep.contents
             fullname = dname + se.d_name
             st = yaffs_stat_struct()
-            result = yaffs_stat(fullname,byref(st))
+            result = yaffs_lstat(fullname,byref(st))
             perms = st.st_mode & 0777
-            isFile = True if st.st_mode & 0x8000 else False
-            isDir  = True if st.st_mode & 0x4000 else False
+            ftype = st.st_mode & yaffs_S_IFMT
+            isFile = True if ftype == yaffs_S_IFREG else False
+            isDir  = True if ftype == yaffs_S_IFDIR else False
+            isSymlink= True if ftype == yaffs_S_IFLNK else False
 
             if isFile :
                 ls_dict.append ({"type" :"file",  "inodes" :  str(se.d_ino),   "permissions" : str(hex(perms)),  "size": str(st.st_size), "path":  fullname})
+                print "file st.st_mode:", st.st_mode
+
             elif isDir :
+                print "dir st.st_mode:", st.st_mode
+
                 ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0",   "path": fullname+"/"})
+            elif isSymlink:
+                print "symlink st.st_mode:", st.st_mode
 
-#            else :
-#              ls_dict.append( "Other ("+hex(st.st_mode)+") "+se.d_ino, hex(perms)+ fullname)
+                ls_dict.append ({"type" :"link",  "inodes" :  str(se.d_ino),   "permissions" : str(hex(perms)),  "size": str(st.st_size), "path":  fullname})
+
+            else :
+                print "unknown st.st_mode:", st.st_mode
+                ls_dict.append({ "type":"Other", "inodes":str(se.d_ino),  "permissions":str( hex(perms)), "size":"0",   "path": fullname})
             sep = yaffs_readdir(dc)
         yaffs_closedir(dc)
         return ls_dict
@@ -172,6 +209,65 @@ button_back=tk.Button(toolbar_frame, command=back_a_directory, text="back")
 button_back.grid(column=1, row=0)
 toolbar_frame.grid(row=0, column=0,  columnspan=3)
 
+def delete_selected(selected_dir=0):
+    if selected_dir==0:
+        print"using current_directory_dict"
+        global current_directory_dict
+        x=name_list_box.curselection()
+        x=int(x[0])
+        print current_directory_dict[x]["type"]
+        if current_directory_dict[x]["type"]=="file":
+            path=current_directory_dict[x]["path"]
+            path =path
+            output=yaffs_unlink(path)
+            print "unlinking output:", output
+        elif current_directory_dict[x]["type"]=="dir":
+            path=current_directory_dict[x]["path"]
+            inside_dir=yaffs_ls(path)
+            print "files and folder inside dir", inside_dir
+            print "len of dir", len(inside_dir)
+            if inside_dir!=[]: ##if the dir is not empty
+                ## remove stuff in dir
+                for i in range(0,len(inside_dir)):
+                    print "calling self*****"
+                    delete_selected(inside_dir[i])
+                
+            path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file 
+            print "removing:", path
+            output=yaffs_rmdir(path)
+            print "rmdir output:", output
+    else :
+        print "using passed dir"
+        print "dir passed", selected_dir
+        current_directory_dict =selected_dir
+
+        print "after copying", current_directory_dict
+        print current_directory_dict["type"]
+        if current_directory_dict["type"]=="file":
+            path=current_directory_dict["path"]
+            path =path
+            output=yaffs_unlink(path)
+            print "unlinking output:", output
+        elif current_directory_dict["type"]=="dir":
+            path=current_directory_dict["path"]
+            inside_dir=yaffs_ls(path)
+            print "files and folder inside dir", inside_dir
+            print "len of dir", len(inside_dir)
+            if inside_dir!=[]: ##if the dir is not empty
+                ## remove stuff in dir
+                for i in range(0,len(inside_dir)):
+                    print "calling self*****"
+                    delete_selected(inside_dir[i])
+                
+            path =path[0:len(path)-1] ##this is to remove the "/" off the end of the of the file 
+            print "removing:", path
+            output=yaffs_rmdir(path)
+            print "rmdir output:", output
+            
+    
+    
+    load_dir()
+
 
 
 class new_file():
@@ -241,6 +337,117 @@ class new_folder():
         button_frame.pack()
 
 
+class new_symlink():
+    path_entry_box=0
+    target_text=0
+    new_text=0
+    new_file_window=0
+    def create_the_symlink(self):
+        global mount_list_text_variable
+        ##check the symlink's target is a file.
+        target_path=self.target_text.get()
+        new_path=self.new_text.get()
+        print "creating a symlink \n target:", target_path
+        target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
+        if target_file_exists>=0:
+            ##file exists,create symlink
+            print "target file exist, creating symlink"
+            yaffs_symlink(target_path, new_path)
+            self.new_file_window.destroy()
+        else :
+            ##file does not exist
+            print "target file does not exist, cannot create symlink"
+        load_dir()
+
+    def cancel(self):
+        ##del self
+        self.new_file_window.destroy()
+    def __init__(self):
+        global mount_list_text_variable
+        self.new_file_window =tk.Toplevel(takefocus=True)
+        target_frame=tk.Frame(self.new_file_window)
+        target_label=tk.Label(target_frame, text="target")
+        target_label.pack(side=tk.LEFT)
+        self.target_text=tk.StringVar()
+        self.target_text.set(mount_list_text_variable.get())
+        #print "############################",mount_list_text_variable.get()
+        self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
+        self.target_entry_box.pack(side=tk.RIGHT)
+        target_frame.pack()
+        
+        new_frame=tk.Frame(self.new_file_window)
+        new_label=tk.Label(new_frame, text="file path")
+        new_label.pack(side=tk.LEFT)
+        self.new_text=tk.StringVar()
+        self.new_text.set(mount_list_text_variable.get())
+        #print "############################",mount_list_text_variable.get()
+        self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
+        self.new_entry_box.pack(side=tk.RIGHT)
+        new_frame.pack()
+        
+        button_frame=tk.Frame(self.new_file_window)
+        create_button=tk.Button(button_frame, text="Create", command=self.create_the_symlink)
+        create_button.pack(side=tk.LEFT)
+        cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
+        cancel_button.pack(side=tk.RIGHT)
+        button_frame.pack()
+
+
+
+class new_hardlink():
+    path_entry_box=0
+    target_text=0
+    new_text=0
+    new_file_window=0
+    def create_the_hardlink(self):
+        global mount_list_text_variable
+        ##check the symlink's target is a file.
+        target_path=self.target_text.get()
+        new_path=self.new_text.get()
+        print "creating a hardlink \n target:", target_path
+        target_file_exists=yaffs_access(target_path, 0) ##yaffs_access will return 0 on success and -1 on failure.
+        if target_file_exists>=0:
+            ##file exists,create symlink
+            print "target file exist, creating hardlink"
+            yaffs_link(target_path, new_path)
+            self.new_file_window.destroy()
+        else :
+            ##file does not exist
+            print "target file does not exist, cannot create hardlink"
+        load_dir()
+
+    def cancel(self):
+        ##del self
+        self.new_file_window.destroy()
+    def __init__(self):
+        global mount_list_text_variable
+        self.new_file_window =tk.Toplevel(takefocus=True)
+        target_frame=tk.Frame(self.new_file_window)
+        target_label=tk.Label(target_frame, text="target")
+        target_label.pack(side=tk.LEFT)
+        self.target_text=tk.StringVar()
+        self.target_text.set(mount_list_text_variable.get())
+        #print "############################",mount_list_text_variable.get()
+        self.target_entry_box= tk.Entry(target_frame, textvariable=self.target_text)
+        self.target_entry_box.pack(side=tk.RIGHT)
+        target_frame.pack()
+        
+        new_frame=tk.Frame(self.new_file_window)
+        new_label=tk.Label(new_frame, text="file path")
+        new_label.pack(side=tk.LEFT)
+        self.new_text=tk.StringVar()
+        self.new_text.set(mount_list_text_variable.get())
+        #print "############################",mount_list_text_variable.get()
+        self.new_entry_box= tk.Entry(new_frame, textvariable=self.new_text)
+        self.new_entry_box.pack(side=tk.RIGHT)
+        new_frame.pack()
+        
+        button_frame=tk.Frame(self.new_file_window)
+        create_button=tk.Button(button_frame, text="Create", command=self.create_the_hardlink)
+        create_button.pack(side=tk.LEFT)
+        cancel_button=tk.Button(button_frame, text="Cancel", command=self.cancel)
+        cancel_button.pack(side=tk.RIGHT)
+        button_frame.pack()
 
 
 ##mount list entry box init
@@ -264,8 +471,8 @@ browser_menu_bar=tk.Menu(root_window)
 browser_file_menu=tk.Menu(browser_menu_bar)
 
 browser_file_menu.add_command(label="Reload", command=load_dir)
-browser_file_menu.add_command(label="Open")
-browser_file_menu.add_command(label="Save")
+#browser_file_menu.add_command(label="Open")
+#browser_file_menu.add_command(label="Save")
 browser_menu_bar.add_cascade(label="File", menu=browser_file_menu)
 root_window.config(menu=browser_menu_bar)
 
@@ -274,7 +481,11 @@ browser_edit_menu=tk.Menu(browser_menu_bar)
 
 browser_edit_menu.add_command(label="New File", command=new_file)
 browser_edit_menu.add_command(label="New Folder", command=new_folder)
-browser_edit_menu.add_command(label="Rename File")
+browser_edit_menu.add_command(label="New Symlink", command=new_symlink)
+browser_edit_menu.add_command(label="New Hardlink", command=new_hardlink)
+
+
+browser_edit_menu.add_command(label="delete selected", command=delete_selected)
 browser_menu_bar.add_cascade(label="Edit", menu=browser_edit_menu)
 
 
index 01eb3575069cdcdcb4dd385264b7887739a30cd5..b7c6047d4281959c115c284916dfbbb13ccf56cf 100644 (file)
@@ -47,3 +47,13 @@ int yaffs_O_TRUNC(void) { return O_TRUNC;}
 
 int yaffs_set_trace(unsigned int tm) { return yaffs_trace_mask=tm; }
 int yaffs_get_trace(void) { return yaffs_trace_mask; }
+
+int yaffs_S_IFMT(void){return S_IFMT;}
+int yaffs_S_IFLNK(void){return S_IFLNK;}
+int yaffs_S_IFDIR(void){return S_IFDIR;}
+int yaffs_S_IFREG(void){return S_IFREG;}
+int yaffs_S_IREAD(void){return S_IREAD;}
+int yaffs_S_IWRITE(void){return S_IWRITE;}
+int yaffs_S_IEXEC(void){return S_IEXEC;}
+int yaffs_XATTR_CREATE(void){return XATTR_CREATE;}
+int yaffs_XATTR_REPLACE(void){return XATTR_REPLACE;}
index 48d412993f62933a90bdfd2833a7a8545c5da710..1d0c8ffde8c4845b20f4fa6341509c0cae8db118 100644 (file)
@@ -245,3 +245,20 @@ yaffs_start_up = ylib.yaffs_start_up
 yaffs_start_up.argtypes = []
 yaffs_start_up.restype = c_int
 
+yaffs_O_CREAT=ylib.yaffs_O_CREAT()
+yaffs_O_RDONLY=ylib.yaffs_O_RDONLY()
+yaffs_O_WRONLY=ylib.yaffs_O_WRONLY()
+yaffs_O_RDWR=ylib.yaffs_O_RDWR()
+yaffs_O_TRUNC=ylib.yaffs_O_TRUNC()
+
+
+yaffs_S_IFMT=ylib.yaffs_S_IFMT()
+yaffs_S_IFLNK= ylib.yaffs_S_IFLNK()
+yaffs_S_IFDIR =ylib.yaffs_S_IFDIR()
+yaffs_S_IFREG=ylib.yaffs_S_IFREG()
+yaffs_S_IREAD=ylib.yaffs_S_IREAD()
+yaffs_S_IWRITE=ylib.yaffs_S_IWRITE()
+yaffs_S_IEXEC=ylib.yaffs_S_IEXEC()  
+yaffs_XATTR_CREATE=ylib.yaffs_XATTR_CREATE()
+yaffs_XATTR_REPLACE=ylib.yaffs_XATTR_REPLACE()
+yaffs_S_IEXEC=ylib.yaffs_S_IEXEC()
index 191ac8d520d0cf39d7897634d81be5bfa8462d03..f95c19906ac7f6cde771177700eacab25e7d01e9 100644 (file)
@@ -31,7 +31,7 @@
 #define YAFFSFS_RW_SIZE  (1<<YAFFSFS_RW_SHIFT)
 
 /* Some forward references */
-static yaffs_obj_t *yaffsfs_FindObject(yaffs_obj_t *relativeDirectory, const YCHAR *path, int symDepth);
+static yaffs_obj_t *yaffsfs_FindObject(yaffs_obj_t *relativeDirectory, const YCHAR *path, int symDepth, int getEquiv);
 static void yaffsfs_RemoveObjectCallback(yaffs_obj_t *obj);
 
 unsigned int yaffs_wr_attempts;
@@ -428,15 +428,18 @@ static yaffs_obj_t *yaffsfs_FindRoot(const YCHAR *path, YCHAR **restOfPath)
 static yaffs_obj_t *yaffsfs_FollowLink(yaffs_obj_t *obj,int symDepth)
 {
 
+       if(obj)
+               obj = yaffs_get_equivalent_obj(obj);
+
        while(obj && obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK){
                YCHAR *alias = obj->variant.symlink_variant.alias;
 
                if(yaffsfs_IsPathDivider(*alias))
                        /* Starts with a /, need to scan from root up */
-                       obj = yaffsfs_FindObject(NULL,alias,symDepth++);
+                       obj = yaffsfs_FindObject(NULL,alias,symDepth++,1);
                else
                        /* Relative to here, so use the parent of the symlink as a start */
-                       obj = yaffsfs_FindObject(obj->parent,alias,symDepth++);
+                       obj = yaffsfs_FindObject(obj->parent,alias,symDepth++,1);
        }
        return obj;
 }
@@ -500,9 +503,7 @@ static yaffs_obj_t *yaffsfs_DoFindDirectory(yaffs_obj_t *startDir,
                        else{
                                dir = yaffs_find_by_name(dir,str);
 
-                               while(dir && dir->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
-                                       dir = yaffsfs_FollowLink(dir,symDepth);
-
+                               dir = yaffsfs_FollowLink(dir,symDepth);
 
                                if(dir && dir->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY)
                                        dir = NULL;
@@ -522,17 +523,23 @@ static yaffs_obj_t *yaffsfs_FindDirectory(yaffs_obj_t *relativeDirectory,
 /*
  * yaffsfs_FindObject turns a path for an existing object into the object
  */
-static yaffs_obj_t *yaffsfs_FindObject(yaffs_obj_t *relativeDirectory, const YCHAR *path,int symDepth)
+static yaffs_obj_t *yaffsfs_FindObject(yaffs_obj_t *relativeDirectory, const YCHAR *path,int symDepth, int getEquiv)
 {
        yaffs_obj_t *dir;
+       yaffs_obj_t *obj;
        YCHAR *name;
 
        dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
 
        if(dir && *name)
-               return yaffs_find_by_name(dir,name);
+               obj = yaffs_find_by_name(dir,name);
+       else
+               obj = dir;
 
-       return dir;
+       if(getEquiv)
+               obj = yaffs_get_equivalent_obj(obj);
+
+       return obj;
 }
 
 
@@ -570,7 +577,7 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
        yaffs_obj_t *dir = NULL;
        YCHAR *name;
        int handle = -1;
-       yaffsfs_Handle *h = NULL;
+       yaffsfs_Handle *yh = NULL;
        int openDenied = 0;
        int symDepth = 0;
        int errorReported = 0;
@@ -600,16 +607,12 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
 
        if(handle >= 0){
 
-               h = yaffsfs_GetHandlePointer(handle);
+               yh = yaffsfs_GetHandlePointer(handle);
 
                /* try to find the exisiting object */
-               obj = yaffsfs_FindObject(NULL,path,0);
-
-               if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK)
-                       obj = yaffsfs_FollowLink(obj,symDepth++);
+               obj = yaffsfs_FindObject(NULL,path,0,1);
 
-               if(obj)
-                       obj = yaffs_get_equivalent_obj(obj);
+               obj = yaffsfs_FollowLink(obj,symDepth++);
 
                if(obj &&
                        obj->variant_type != YAFFS_OBJECT_TYPE_FILE &&
@@ -651,24 +654,24 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
 
                        /* Check sharing of an existing object. */
                        {
-                               yaffsfs_Handle *h;
+                               yaffsfs_Handle *hx;
                                int i;
                                sharedReadAllowed = 1;
                                sharedWriteAllowed = 1;
                                alreadyReading = 0;
                                alreadyWriting = 0;
                                for( i = 0; i < YAFFSFS_N_HANDLES; i++){
-                                       h = &yaffsfs_handle[i];
-                                       if(h->useCount > 0 &&
-                                               h->inodeId >= 0 &&
-                                               yaffsfs_inode[h->inodeId].iObj == obj){
-                                               if(!h->shareRead)
+                                       hx = &yaffsfs_handle[i];
+                                       if(hx->useCount > 0 &&
+                                               hx->inodeId >= 0 &&
+                                               yaffsfs_inode[hx->inodeId].iObj == obj){
+                                               if(!hx->shareRead)
                                                        sharedReadAllowed = 0;
-                                               if(!h->shareWrite)
+                                               if(!hx->shareWrite)
                                                        sharedWriteAllowed = 0;
-                                               if(h->reading)
+                                               if(hx->reading)
                                                        alreadyReading = 1;
-                                               if(h->writing)
+                                               if(hx->writing)
                                                        alreadyWriting = 0;
                                        }
                                }
@@ -710,18 +713,18 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing)
                                 */
                        }
                        
-                       h->inodeId = inodeId;
-                       h->reading = (oflag & (O_RDONLY | O_RDWR)) ? 1 : 0;
-                       h->writing = (oflag & (O_WRONLY | O_RDWR)) ? 1 : 0;
-                       h->append =  (oflag & O_APPEND) ? 1 : 0;
-                       h->position = 0;
-                       h->shareRead = shareRead;
-                       h->shareWrite = shareWrite;
+                       yh->inodeId = inodeId;
+                       yh->reading = (oflag & (O_RDONLY | O_RDWR)) ? 1 : 0;
+                       yh->writing = (oflag & (O_WRONLY | O_RDWR)) ? 1 : 0;
+                       yh->append =  (oflag & O_APPEND) ? 1 : 0;
+                       yh->position = 0;
+                       yh->shareRead = shareRead;
+                       yh->shareWrite = shareWrite;
 
                        /* Hook inode to object */
                         obj->my_inode = (void*) &yaffsfs_inode[inodeId];
 
-                        if((oflag & O_TRUNC) && h->writing)
+                        if((oflag & O_TRUNC) && yh->writing)
                                 yaffs_resize_file(obj,0);
                } else {
                        yaffsfs_PutHandle(handle);
@@ -995,9 +998,7 @@ int yaffs_truncate(const YCHAR *path,off_t new_size)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,path,0);
-       if(obj)
-               obj = yaffs_get_equivalent_obj(obj);
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!obj)
                yaffsfs_SetError(-ENOENT);
@@ -1089,7 +1090,7 @@ int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,path,0);
+       obj = yaffsfs_FindObject(NULL,path,0,0);
        dir = yaffsfs_FindDirectory(NULL,path,&name,0);
        if(!dir)
                yaffsfs_SetError(-ENOTDIR);
@@ -1140,7 +1141,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
 
        olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
        newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
-       obj = yaffsfs_FindObject(NULL,oldPath,0);
+       obj = yaffsfs_FindObject(NULL,oldPath,0,0);
 
        if(!olddir || !newdir || !obj) {
                /* bad file */
@@ -1185,8 +1186,7 @@ static int yaffsfs_DoStat(yaffs_obj_t *obj,struct yaffs_stat *buf)
 {
        int retVal = -1;
 
-       if(obj)
-               obj = yaffs_get_equivalent_obj(obj);
+       obj = yaffs_get_equivalent_obj(obj);
 
        if(obj && buf){
                buf->st_dev = (int)obj->my_dev->os_context;
@@ -1231,7 +1231,8 @@ static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int d
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!doLStat && obj)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1289,7 +1290,8 @@ static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *da
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1353,7 +1355,8 @@ static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, in
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1416,7 +1419,8 @@ static int yaffs_do_listxattr(const YCHAR *path, char *data, int size, int follo
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1478,7 +1482,8 @@ static int yaffs_do_removexattr(const YCHAR *path, const char *name, int follow)
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(follow)
                obj = yaffsfs_FollowLink(obj,0);
@@ -1637,7 +1642,8 @@ int yaffs_access(const YCHAR *path, int amode)
        int retval = 0;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(obj) {
                int access_ok = 1;
@@ -1673,7 +1679,8 @@ int yaffs_chmod(const YCHAR *path, mode_t mode)
        int retVal = -1;
 
        yaffsfs_Lock();
-       obj = yaffsfs_FindObject(NULL,path,0);
+
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!obj)
                yaffsfs_SetError(-ENOENT);
@@ -2088,7 +2095,7 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,dirname,0);
+       obj = yaffsfs_FindObject(NULL,dirname,0,1);
 
        if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY){
 
@@ -2216,7 +2223,7 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,path,0);
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        if(!obj) {
                yaffsfs_SetError(-ENOENT);
@@ -2245,8 +2252,8 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath)
 
        yaffsfs_Lock();
 
-       obj = yaffsfs_FindObject(NULL,oldpath,0);
-       target = yaffsfs_FindObject(NULL,newpath,0);
+       obj = yaffsfs_FindObject(NULL,oldpath,0,1);
+       target = yaffsfs_FindObject(NULL,newpath,0,0);
 
        if(!obj) {
                yaffsfs_SetError(-ENOENT);
@@ -2314,9 +2321,7 @@ int yaffs_n_handles(const YCHAR *path)
 {
        yaffs_obj_t *obj;
 
-       obj = yaffsfs_FindObject(NULL,path,0);
-       if(obj)
-               obj = yaffs_get_equivalent_obj(obj);
+       obj = yaffsfs_FindObject(NULL,path,0,1);
 
        return yaffsfs_CountHandles(obj);
 }