yaffs: Merge branch 'python_play'
authorTimothy Manning <tfhmanning@gmail.com>
Wed, 20 Oct 2010 00:42:58 +0000 (13:42 +1300)
committerTimothy Manning <tfhmanning@gmail.com>
Wed, 20 Oct 2010 00:42:58 +0000 (13:42 +1300)
Fix conflict

direct/python/README_yaffs_import_py.txt [new file with mode: 0644]
direct/python/yaffs_browser.py
direct/python/yaffs_importer.py [new file with mode: 0644]
direct/python/yaffsfs.py
direct/timothy_tests/Makefile [new file with mode: 0644]
direct/timothy_tests/yaffs_tester.c [new file with mode: 0644]
direct/timothy_tests/yaffs_tester.h [new file with mode: 0644]
direct/yaffsfs.c
direct/yaffsfs.h

diff --git a/direct/python/README_yaffs_import_py.txt b/direct/python/README_yaffs_import_py.txt
new file mode 100644 (file)
index 0000000..d497819
--- /dev/null
@@ -0,0 +1,36 @@
+Readme for the yaffs_import.py file
+
+python yaffs_import [scanning_path] [optional flags]
+
+the scanning path needs to be the absolute path to the directory where you
+wish to start scanning from. this function will scan all of the the
+directories above this path and copy the all files in these directories.
+
+example:
+       $  yaffs_importer.py /home/timothy/work/yaffs/
+
+
+flags:
+       -d [number] 
+               set the debugging message level.
+               that debug level 0 will always be printed unless debug_level is set to -1
+               level 0 error messages
+               level 1 basic tasks are shown(creating, deleating,ect)(this is set as the
+               default and is recommended)
+               level 2 all process are shown
+               level 3 shows minor tasks such as join_paths, ect
+               level 4 is used for bug hunting and shows each step and in detail 
+       -ignore_hidden_directories
+               will not copy hidden (./) directories if used.
+
+Deleating files and folders
+       to deleate files and folders in yaffs use the yaffs_browser (the documentation still needs to be written).
+       to run the browser use this: "python yaffs_browser"
+       to deleate a file or a folder select the file or folder then go
+       Edit->Delete selected.
+
+Clear Yaffs
+       the easiest way to clear yaffs of all files and folders is to remove
+       the emfile-2k-0 file. this file is stored in the
+       yaffs2/direct/python/ folder. 
+       the command is: rm emfile-2k-0  
\ No newline at end of file
index 8f88b97..28fb49f 100755 (executable)
@@ -60,7 +60,7 @@ class editor():
         self.id=int(x[0])
         self.file_editor_root =tk.Toplevel()
         self.save_button=tk.Button(self.file_editor_root, text="save", command=self.save_file)
-        self.save_button.pack()
+        self.save_button.pack(fill=tk.BOTH)
 
         self.file_path=current_directory_dict[self.id]["path"]
         print "file path", self.file_path
@@ -70,7 +70,7 @@ class editor():
         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
         print "length of file to be opened:", length_of_file
-        if isLink==True:
+        if isLink==True and False ==True : ##this alows the symlink to be edited and is no longer used. to renable it delete "and False ==True"
             print "opening symlink"
             self.file_contents=ctypes.create_string_buffer(1000)
             yaffs_readlink(self.file_path,self.file_contents,1000)
@@ -81,28 +81,37 @@ class editor():
             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.pack(fill=tk.BOTH)
         ##self.file_editor_text.bind("<Control-s>", self.save_file)
         ##doesn't work because it can't pass "self"
 
 def load_dir():
     global current_directory_dict
     print "loading a new directory*******************************************************************"
+    ##deleate current items in text box
     name_list_box.delete(0, tk.END)
     current_directory_dict=yaffs_ls(mount_list_text_variable.get())
     print "new directory", current_directory_dict
     ##copy directory into file box
     for x in range(0,len(current_directory_dict)):
-        name_list_box.insert(x,(current_directory_dict[x]["inodes"]+"  "+ current_directory_dict[x]["type"]+"  "+ current_directory_dict[x]["size"]+"  "+ current_directory_dict[x]["path"]))
+        name_list_box.insert(x,(current_directory_dict[x]["inodes"]+"  "+ current_directory_dict[x]["type"]+"  "+ current_directory_dict[x]["size"]+"  "+ current_directory_dict[x]["path"]+"  "+current_directory_dict[x]["extra_data"]))
     name_list_box.grid(column=0, row=1)
     return current_directory_dict
-
+    
+def remount_yaffs():
+    ##this isn't working. somethihg need to be changed in the config of the simulator to release the handle of the emfile
+    print "remounting yaffs"
+    print"unmounting yaffs:", yaffs_unmount("yaffs2/")
+    print "mounting yaffs", yaffs_mount("/yaffs2/")
+    load_dir()
+    
 def load_file(link=0):
     global open_windows_list
     open_windows_list.append(editor(link))
 
 def load_command(self=0):
-    global current_directory_dict
+    global current_directory_dictls
+    
     print "you loaded a file/dir/link"
     x=name_list_box.curselection()
     x=int(x[0])
@@ -178,21 +187,28 @@ def yaffs_ls(dname):
             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})
+                ls_dict.append ({"type" :"file",  "inodes" :  str(se.d_ino),   "permissions" : str(hex(perms)),  "size": str(st.st_size), "path":  fullname,"extra_data":""})
                 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+"/"})
+                ls_dict.append({"type":"dir", "inodes" :str(se.d_ino), "permissions":str( hex(perms)),"size":"0",   "path": fullname+"/", "extra_data":""})
             elif isSymlink:
                 print "symlink st.st_mode:", st.st_mode
+                file_contents=ctypes.create_string_buffer(30)
+                yaffs_readlink(fullname,file_contents,30)
+                string=repr(file_contents.value)
+                print "len of str", len(string)
+#                string.lstrip()
+
+                print "string", string, "###"
 
-                ls_dict.append ({"type" :"link",  "inodes" :  str(se.d_ino),   "permissions" : str(hex(perms)),  "size": str(st.st_size), "path":  fullname})
+                ls_dict.append ({"type" :"link",  "inodes" :  str(se.d_ino),   "permissions" : str(hex(perms)),  "size": str(st.st_size), "path":  fullname, "extra_data":"> "+string})
 
             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})
+                ls_dict.append({ "type":"Other", "inodes":str(se.d_ino),  "permissions":str( hex(perms)), "size":"0",   "path": fullname,"extra_data":""})
             sep = yaffs_readdir(dc)
         yaffs_closedir(dc)
         return ls_dict
@@ -264,8 +280,6 @@ def delete_selected(selected_dir=0):
             output=yaffs_rmdir(path)
             print "rmdir output:", output
             
-    
-    
     load_dir()
 
 
@@ -461,9 +475,9 @@ mount_list_frame.grid(row=1, column=0, columnspan=2)
 
 
 list_frame=tk.Frame(root_window)
-name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=50)
+name_list_box=tk.Listbox(list_frame,exportselection=0, height=30, width=80)
 load_dir()
-list_frame.grid()
+list_frame.grid(sticky=tk.W+tk.E+tk.N+tk.S)
 
 name_list_box.bind("<Double-Button-1>", load_command)
 
@@ -471,6 +485,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="Remount yaffs", command=remount_yaffs)
+
 #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)
diff --git a/direct/python/yaffs_importer.py b/direct/python/yaffs_importer.py
new file mode 100644 (file)
index 0000000..1a6937b
--- /dev/null
@@ -0,0 +1,402 @@
+import os
+from yaffsfs import *
+import sys
+import ctypes
+
+
+dir_in_snapshot=[]
+files_in_snapshot=[]
+symlinks_in_snapshot=[]
+unknown_in_snapshot=[]
+is_mount_in_snapshot=[]
+def check_for_yaffs_errors(output):
+    if output<0:
+        ##error has happened
+        error=ctypes.c_int()
+        error=yaffs_get_error()
+        debug_message("error######################################",0)
+        debug_message(("error code", error),  0)
+
+def debug_message(message, debug_level):
+    """note: that debug level 0 will always be printed unless debug_level is set to -1"""
+    """level 0 error messages"""
+    """level 1 basic tasks are shown(creating, deleating,ect)"""
+    """level 2 all process are shown"""
+    """level 3 shows minor tasks such as join_paths, ect"""
+    """level 4 is used for bug hunting and shows each step in detail"""
+    if current_debug_level>=debug_level:
+#        for i in range(0, len(message)):
+#            print message, 
+#        print"\n \n \n"
+        print message
+def join_paths(path1, path2):
+    new_path=path1
+    if path1[len(path1)-1]=="/"and path2[0]=="/":
+        new_path+=path2[1:]
+    elif path1[len(path1)-1]!="/"and path2[0]!="/":
+        new_path+="/"
+        new_path+=path2
+    else:
+        new_path+=path2
+    
+    debug_message(("adding path ", path1, " to ",  path2, " resulting path: ", new_path), 3)
+    return new_path
+    
+def subtract_paths(path1, path2):
+    if len(path1)>len(path2):
+        if path1[len(path1)-1]!="/":
+            path1 +="/"
+        if path2[len(path2)-1]!="/":
+            path2 += "/"
+        debug_message("the two path1 is longer than path2 and can therefore be subtracted.", 4)
+        ##if the two paths are diretly subtractable
+        if path1[0:len (path2)-1]==path2:
+            debug_message("the two paths are direcly subtractable", 4)
+            new_path=path1[len(path2):]
+        elif path1[1:len (path2)-1]==path2:
+            debug_message("the path1 has one more charecter at the begining. assuming that the first chareter is a slash", 4)##fix this assumption.
+            new_path=path1[len(path2)+1:]
+        elif path1[1:len (path2)]==path2[1:]:
+            debug_message("the path2 has one more charecter at the begining. assuming that the first chareter is a slash", 4)##fix this assumption.
+
+            new_path=path1[len(path2)-1:]
+        else :
+            debug_message("error:could not subtract paths", 0)
+            debug_message( ("paths do not match:"+ path1+ "  "+path2), 0)
+            return 0
+    else :
+        debug_message( ("cannot subtract path2(:", path2, ") from path1(", path1, ")because path 2 is too long"), 0)
+        
+        return 0
+    debug_message(("subtracting paths ", path2, " from ",  path1, " resulting path: ", new_path), 3)
+    return new_path
+    
+def create_file(file):
+    debug_message( "\n \n \n", 2)
+    file_path= join_paths(yaffs_root_dir_path, file["path"][len(path):])
+    debug_message( ("creating file:", file_path), 2)
+    debug_message (("mode", file["mode"]), 2)
+    debug_message("opening file",2)
+#    yaffs_ls(file["path"])
+
+    ##if there is already a file in yaffs then remove the file . this is to prevent yaffs from opening a nd writing to a read only file
+    if yaffs_access(file_path, 0)==0:##the 0 means does it exist. 
+        debug_message ("file already exists in yaffs", 2)
+        output=yaffs_unlink(file_path)
+        debug_message(("unlinking", file_path, output), 2)
+        check_for_yaffs_errors(output)
+    
+    current_handle=yaffs_open(file_path, yaffs_O_CREAT | yaffs_O_TRUNC| yaffs_O_RDWR, yaffs_S_IREAD | yaffs_S_IWRITE)  ##opens a file with mode set to write
+    debug_message(("current_handle", current_handle), 2)
+    data_file=open(file["path"], "r")
+    output=yaffs_lseek(current_handle, 0, 0)
+    if output==-1:
+        debug_message("error with yaffs lseeking", 2)
+        
+        check_for_yaffs_errors(output)
+    data_to_be_written= data_file.read()
+    
+    
+    length_of_file=len(data_to_be_written)
+    debug_message (("length of data to be written",length_of_file), 3) 
+    output=yaffs_write(current_handle,data_to_be_written , length_of_file)
+    if output>=0:
+        debug_message(( "writing to ", file_path," ",  output), 1)
+    else :
+        debug_message(( "error writing file:", output), 0)
+        check_for_yaffs_errors(output)
+    output=yaffs_ftruncate(current_handle, length_of_file)
+    if output>=0:
+        debug_message(( "truncating file:", output), 2)
+    else :
+        debug_message(( "error truncating file:", output), 0)
+        check_for_yaffs_errors(output)
+    output=yaffs_close(current_handle)
+    if output>=0:
+        debug_message(( "closing file:", output), 2)
+    else :
+        debug_message(( "error closing file:", output), 0)
+        check_for_yaffs_errors(output)
+    ##changes the mode of the yaffs file to be the same as the scanned file
+    yaffs_chmod(file_path, file["mode"]);
+    if output>=0:
+        debug_message(( "chmoding file:", output), 2)
+    else :
+        debug_message(( "error chmoding file:", output), 0)
+        check_for_yaffs_errors(output)
+
+
+
+def create_dir(dir, scanned_path, yaffs_path):
+    debug_message( "\n \n \n", 2)
+    absolute_dir_path=join_paths(yaffs_path, subtract_paths(dir["path"],scanned_path)) 
+    debug_message( ("creating dir:", absolute_dir_path), 2)
+    debug_message (("mode(in octal", oct(dir["mode"])), 2)
+
+       ##this is a bug in yaffs which will not make a dir if there is a slash on the end
+    if absolute_dir_path[len(absolute_dir_path)-1]=="/":
+        absolute_dir_path=absolute_dir_path[0:len(absolute_dir_path)-1]
+        debug_message (("path has slash on the end. removing slash new path is:",absolute_dir_path) , 4)
+        
+        
+    ##if there is already a dir in yaffs then remove the dir . this is to clean the yaffs folder if it already exists.
+    ##in yaffs all of the files in the dir to be removed must be empty.
+    ##need to create a reverse ls to delete all of the files first.
+#    if yaffs_access(absolute_dir_path, 0)==0:##the 0 means does it exist. 
+#        debug_message ("folder already exists in yaffs", 2)
+#        output=yaffs_rmdir(absolute_dir_path)
+#        debug_message(("unlinking", absolute_dir_path, output), 2)
+#        check_for_yaffs_errors(output)
+        
+        
+    output=yaffs_mkdir(absolute_dir_path, dir["mode"] )
+    if output>=0:
+        debug_message(( "created dir:", absolute_dir_path," ", output), 1)
+    else :
+        debug_message(( "error creating dir ", absolute_dir_path, " ", output), 0)
+        check_for_yaffs_errors(output)
+        if output==17:
+            printf("the directory already exists")
+    
+    
+
+
+def remove_file_from_path(path):
+    slash_id=[]
+    for i in range(0, len(path)):
+        if path[i]=="/":
+            slash_id.append(i)
+    new_path=path[:slash_id[len(slash_id)-1]]
+    debug_message( ("removed file from path", new_path), 2)
+    return new_path
+    
+def is_dir_hidden(dir):
+    """this code tests if a directory is hidden (has a ./<name> format) and returns true if it is hidden"""
+    slash_id=[]
+    for i in range(0, len(dir)):
+        if dir[i]=="/":
+            slash_id.append(i)
+
+    if dir[slash_id[len(slash_id)-1]+1]==".":
+        return True
+    else :
+        return False
+    
+def scan_dir(path, search_hidden_directories=True, ):
+    """this function scans all of the files and directories in a directory. The function then calls its self on any of the directories that it found. this causes it to build up a tree of all the files and directories """
+    global files_in_snapshot
+    global symlinks_in_snapshot
+    global dir_in_snapshot
+    dir_in_current_dir=[]
+    global unknown_in_snapshot
+#    files_in_snapshot=[]
+#    symlinks_in_snapshot=[]
+#    dir_in_snapshot=[]
+#    dir_in_current_dir=[]
+#    unknown_in_snapshot=[]
+    if os.path.exists(path)==False:
+        debug_message ("error#############################",0)
+        debug_message (("path:", path, "  doesnot exist"), 0)
+        return 0
+    dir_snapshot=os.listdir(path)
+    for i in range(0, len(dir_snapshot)):
+
+        current_snapshot=os.path.join(path, dir_snapshot[i])
+        ##debug_message (("current snapshot:", current_snapshot), 2)
+        isDir=os.path.isdir(current_snapshot)
+        isFile=os.path.isfile(current_snapshot)
+        isLink=os.path.islink(current_snapshot)
+        isMount=os.path.ismount(current_snapshot)
+
+        stat=os.lstat(current_snapshot)
+        
+        ##note the order of these if and elif statemens is importaint since a file can be symbloic link and a file
+        if isDir:
+            if search_hidden_directories==True or (is_dir_hidden(current_snapshot) ==False or search_hidden_directories==True ) :
+#                st_mode ##mode of the folder read/write ect
+                dir_in_snapshot.append({"path":current_snapshot, "mode":stat.st_mode})
+                dir_in_current_dir.append(current_snapshot)
+            else :
+                debug_message( ("file is hidden so it is ingored", current_snapshot,), 1)
+        elif  isLink:
+
+            ##for some reason the os.readlink only gives the target link realative to the directory which the symbloic link is in. change this into a absolute path
+            x=current_snapshot
+            x=remove_file_from_path(x)
+            target=join_paths(x,os.readlink(current_snapshot) )
+            symlinks_in_snapshot.append({"path":current_snapshot, "target":target})
+        elif isFile:
+
+#            stat.st_ino ##inode number
+#            st_nlink ##number of hard links to this file
+#            st_size ##size of file
+            files_in_snapshot.append({"path":current_snapshot, "inode": stat.st_ino, "size":stat.st_size, "num_of_hardlinks":stat.st_nlink, "mode":stat.st_mode})
+
+#        elif isMount:
+#            is_mount_in_snapshot.append(current_snapshot)
+        else:
+            unknown_in_snapshot.append(current_snapshot)
+            
+    for i in range(0, len(dir_in_current_dir)):
+        debug_message(("scanning dir", dir_in_current_dir[i]) , 2)
+        scan_dir(dir_in_current_dir[i], search_hidden_directories)
+        
+#        #debug_message(("data 0", data[0][0]), 2)
+#        if len(files)
+#        files_in_snapshot.append(data[0][0])
+#        dir_in_snapshot.append(data[1][0])
+#        symlinks_in_snapshot.append(data[2][0])
+#        unknown_in_snapshot.append(data[3][0])
+    return (files_in_snapshot, dir_in_snapshot, symlinks_in_snapshot, unknown_in_snapshot)
+##
+##def print_scanned_dir_list():
+##    global files_in_snapshot
+##    global symlinks_in_snapshot
+##    print( "scanning dir", 2)
+##
+##
+##    for i in range(0, len(files_in_snapshot)):
+##        if files_in_snapshot[i]["num_of_hardlinks"]>1:
+##            print "inode",files_in_snapshot[i]["inode"],"size",files_in_snapshot[i]["size"],"path:", files_in_snapshot[i]["path"], "    num of hard links",  files_in_snapshot[i]["num_of_hardlinks"] 
+##
+##        else :
+##            print "inode",files_in_snapshot[i]["inode"],"size",files_in_snapshot[i]["size"],"path:", files_in_snapshot[i]["path"]
+###        current_open_file=open(files_in_snapshot[i], "r")
+###        #current_open_file.f.read(3)
+###        lines_in_file=current_open_file.readlines()
+###        #use for loop to write code into yaffs file
+###        print "number of line of code:", len(lines_in_file)
+###    print current_open_file
+##    for i in range(0, len(symlinks_in_snapshot)):
+##        print "symlinks in snapshot:", symlinks_in_snapshot[i]
+##    for i in range(0, len(dir_in_snapshot)):
+##        print "directories in snapshot:", dir_in_snapshot[i]
+##    for i in range(0, len(unknown_in_snapshot)):
+##        print "unknown objects in snapshot:", unknown_in_snapshot[i]
+##
+
+
+def copy_scanned_files_into_yaffs(files_in_snapshot, dir_in_snapshot,  symlinks_in_snapshot, unknown_in_snapshot,   path, yaffs_root_dir_path="/yaffs2/", yaffs_mount_point_path="/yaffs2/" ):
+#files_in_snapshot, dir_in_snapshot, symlinks_in_snapshot, unknown_in_snapshot
+#########################################copy directories into yaffs so the files can be created in these directories
+    debug_message("making directories in yaffs", 1)
+    if yaffs_root_dir_path!=yaffs_mount_point_path:
+        slash_id=[]
+        debug_message("making directories to the place in yaffs where the directories will copied to", 2)
+        root_branch_path=subtract_paths(yaffs_root_dir_path, yaffs_mount_point_path)
+        for i in range(0, len(root_branch_path)):
+
+            if root_branch_path[i]=="/" and i != 0:
+               slash_id.append(i)
+        debug_message(("slash_id", slash_id),4) 
+        for i in range(0, len(slash_id)):
+            create_dir({"path":root_branch_path[:slash_id[i]], "mode": yaffs_S_IREAD | yaffs_S_IWRITE}, "/", yaffs_mount_point_path) 
+    
+    for i in range(0, len(dir_in_snapshot)):
+        create_dir(dir_in_snapshot[i], path, yaffs_root_dir_path)
+  
+    
+    
+#########################################copy file into yaffs
+    debug_message("copying scanned files into yaffs", 1)
+    list=[]
+    inode_blacklist=[]
+
+    debug_message("files to be copyied into yaffs", 2)
+    for a in range(0, len(files_in_snapshot)):
+        debug_message(files_in_snapshot[a], 2)
+    debug_message("\n\n\n", 2)
+    for i in range(0, len(files_in_snapshot)):
+        list=[]
+        if files_in_snapshot[i]["num_of_hardlinks"]>1 and files_in_snapshot[i]["inode"] not in inode_blacklist :
+            debug_message("found a hard link", 2)
+            debug_message(("inode",files_in_snapshot[i]["inode"],"size",files_in_snapshot[i]["size"],"path:", files_in_snapshot[i]["path"], "    num of hard links",  files_in_snapshot[i]["num_of_hardlinks"] ), 2)
+            for a in range(0, len(files_in_snapshot) ) :
+                if files_in_snapshot[a]["inode"] ==files_in_snapshot[i]["inode"]  :
+                    ##and os.path.isfile(files_in_snapshot[i])
+                    debug_message(("found this file which matches inode",files_in_snapshot[a]), 2) 
+                    list.append(files_in_snapshot[a])
+                    debug_message(("length of list", len(list)), 2)
+                if len(list)==files_in_snapshot[i]["num_of_hardlinks"]:
+                    break
+            for a in range(0, len(list)):
+                debug_message(list[a], 2)
+            ##add inode to blacklist. all of the indoes in the list should be the same.
+            inode_blacklist.append(list[0]["inode"])
+            ##create a file from the first hardlink.
+            create_file(list[0])
+            target_path=yaffs_root_dir_path+list[0]["path"][len(path):]
+            for i in range(1, len(list)):
+                debug_message("creating_symlink", 2)
+                debug_message(("target path", target_path), 2)
+                hardlink_path=yaffs_root_dir_path+list[i]["path"][len(path):]
+                debug_message(("hardlink path", hardlink_path), 2)
+                output=yaffs_link(target_path,hardlink_path)
+                debug_message(("creating hardlink:", list[i]["path"], "output:", output), 1)
+        elif files_in_snapshot[i]["inode"] not in inode_blacklist :
+            create_file(files_in_snapshot[i])
+
+
+############################copy symlinks into yaffs
+
+    for i in range(0, len(symlinks_in_snapshot)):
+        debug_message(("symlinks in snapshot:", symlinks_in_snapshot[i]), 2)
+        target_path=join_paths(yaffs_root_dir_path, subtract_paths(symlinks_in_snapshot[i]["target"],  path))
+        new_path=join_paths(yaffs_root_dir_path, subtract_paths(symlinks_in_snapshot[i]["path"], path))
+        output=yaffs_symlink(target_path, new_path)
+        debug_message(("created symlink",new_path , " > ", target_path, "  output:", output), 1)
+        ##yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
+   
+    
+    for i in range(0, len(unknown_in_snapshot)):
+        debug_message( ("unknown object in snapshot:", unknown_in_snapshot[i]), 0)
+    
+    
+def import_into_yaffs(file_path, yaffs_path="/yaffs2/", debug_level=1,  copy_hidden_dir=True ,new_yaffs_trace_val=0 ):
+#    global current_debug_level
+#    global search_hidden_directories
+#    global yaffs_root_dir_path
+#    global path
+    
+#    current_debug_level=debug_level
+#    search_hidden_directories=copy_hidden_dir
+#    yaffs_root_dir_path=yaffs_path
+#    path=file_path
+    old_yaffs_trace_val=yaffs_get_trace()
+    yaffs_set_trace(new_yaffs_trace_val)
+    
+    data=scan_dir(file_path, copy_hidden_dir)
+    copy_scanned_files_into_yaffs(data[0], data[1], data[2], data[3],file_path,  yaffs_path)
+    
+    yaffs_set_trace(old_yaffs_trace_val)
+    
+    
+if __name__=="__main__":
+    yaffs_StartUp()
+    yaffs_mount("/yaffs2/")
+    yaffs_set_trace(0)
+#    absolute_path = os.path.abspath(os.path.curdir)
+    #print "absolute path:", absolute_path
+    current_debug_level=1
+    search_hidden_directories=True
+    yaffs_root_dir_path="/yaffs2/scanning/"
+    #print sys.argv
+    path=sys.argv[1]
+    for i in range(2, len(sys.argv)):
+        if sys.argv[i]=="-d":
+            current_debug_level=int( sys.argv[i+1])
+        if sys.argv[i]=="-ignore_hidden_directories":
+            search_hidden_directories=False
+#
+#
+#    path="/home/timothy/work/yaffs/git/yaffs2"
+#    path="/home/timothy/my_stuff/old_laptop/timothy/programming_lejos/"
+
+
+    import_into_yaffs(path, yaffs_root_dir_path, current_debug_level,  search_hidden_directories, 0 )
+#    scan_dir(path)
+#    copy_scanned_files_into_yaffs()
+    #print_scanned_dir_list()
+
+    print"unmounting yaffs:", yaffs_unmount("/yaffs2/")
index 1d0c8ff..03583fd 100644 (file)
@@ -245,6 +245,21 @@ yaffs_start_up = ylib.yaffs_start_up
 yaffs_start_up.argtypes = []
 yaffs_start_up.restype = c_int
 
+#int yaffs_set_trace(unsigned int tm) { return yaffs_traceMask=tm; }
+yaffs_set_trace=ylib.yaffs_set_trace
+yaffs_set_trace.argtypes=[c_uint]
+yaffs_set_trace.restype=c_uint
+
+#int yaffs_get_trace(void) { return yaffs_traceMask; }
+yaffs_get_trace=ylib.yaffs_get_trace
+yaffs_get_trace.argtypes=[]
+yaffs_get_trace.restypes=c_uint
+
+#int yaffs_get_error(void)
+yaffs_get_error=ylib.yaffs_get_error
+yaffs_get_error.argtypes=[]
+yaffs_get_error.restypes=c_int
+
 yaffs_O_CREAT=ylib.yaffs_O_CREAT()
 yaffs_O_RDONLY=ylib.yaffs_O_RDONLY()
 yaffs_O_WRONLY=ylib.yaffs_O_WRONLY()
diff --git a/direct/timothy_tests/Makefile b/direct/timothy_tests/Makefile
new file mode 100644 (file)
index 0000000..13371b2
--- /dev/null
@@ -0,0 +1,103 @@
+# Makefile for YAFFS direct stress tests
+#
+#
+# YAFFS: Yet another Flash File System. A NAND-flash specific file system.
+#
+# Copyright (C) 2003-2010 Aleph One Ltd.
+#
+#
+# Created by Charles Manning <charles@aleph1.co.uk>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# NB Warning this Makefile does not include header dependencies.
+#
+# $Id: Makefile,v 1.7 2010-02-25 22:34:47 charles Exp $
+
+#EXTRA_COMPILE_FLAGS = -DYAFFS_IGNORE_TAGS_ECC
+
+CFLAGS =      -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DCONFIG_YAFFS_YAFFS2  
+CFLAGS +=     -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
+CFLAGS +=    -Wall -g $(EXTRA_COMPILE_FLAGS) -Wstrict-aliasing 
+#CFLAGS +=    -fno-strict-aliasing
+CFLAGS +=    -O0
+CFLAGS +=    -Wextra -Wpointer-arith
+#CFLAGS +=    -DCONFIG_YAFFS_VALGRIND_TEST
+
+#CFLAGS+=   -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations
+#CFLAGS+=   -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline
+
+
+COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsfs.o yaffs_guts.o \
+                yaffs_packedtags1.o yaffs_ramdisk.o yaffs_ramem2k.o \
+                yaffs_tagscompat.o yaffs_packedtags2.o yaffs_tagsvalidity.o yaffs_nand.o \
+                yaffs_checkptrw.o  yaffs_qsort.o\
+                yaffs_nameval.o \
+                yaffs_norif1.o  ynorsim.o   \
+                yaffs_allocator.o \
+                yaffs_bitmap.o \
+                yaffs_yaffs1.o \
+                yaffs_yaffs2.o \
+                yaffs_verify.o
+
+#               yaffs_checkptrwtest.o\
+
+YAFFSTESTOBJS  = $(COMMONTESTOBJS) yaffs_tester.o
+
+
+ALLOBJS = $(sort $(YAFFSTESTOBJS))
+
+YAFFSSYMLINKS = devextras.h yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffsinterface.h yportenv.h yaffs_tagscompat.c yaffs_tagscompat.h \
+          yaffs_packedtags1.c yaffs_packedtags1.h yaffs_packedtags2.c yaffs_packedtags2.h  yaffs_nandemul2k.h \
+          yaffs_nand.c yaffs_nand.h yaffs_getblockinfo.h yaffs_list.h \
+          yaffs_tagsvalidity.c yaffs_tagsvalidity.h yaffs_checkptrw.h yaffs_checkptrw.c \
+          yaffs_nameval.c yaffs_nameval.h \
+          yaffs_qsort.c yaffs_qsort.h yaffs_trace.h \
+          yaffs_allocator.c yaffs_allocator.h \
+          yaffs_yaffs1.c yaffs_yaffs1.h \
+          yaffs_yaffs2.c yaffs_yaffs2.h \
+          yaffs_bitmap.c yaffs_bitmap.h \
+          yaffs_verify.c yaffs_verify.h
+
+YAFFSDIRECTSYMLINKS =  yaffsfs.c yaffs_flashif.h yaffs_flashif2.h\
+                      yaffsfs.h yaffs_malloc.h ydirectenv.h \
+                      yaffs_flashif.c yaffscfg.h \
+                      yaffs_nandif.c yaffs_nandif.h
+
+
+DIRECTEXTRASYMLINKS =  yaffscfg2k.c yaffs_fileem2k.c yaffs_fileem2k.h\
+                       yaffs_fileem.c yaffs_norif1.c yaffs_norif1.h \
+                       yaffs_ramdisk.c yaffs_ramdisk.h yaffs_ramem2k.c \
+                       ynorsim.h ynorsim.c
+
+SYMLINKS = $(YAFFSSYMLINKS) $(YAFFSDIRECTSYMLINKS) $(DIRECTEXTRASYMLINKS)
+#all: directtest2k boottest
+
+all: yaffs_tester 
+
+$(ALLOBJS): %.o: %.c
+       gcc -c $(CFLAGS) -o $@ $<
+
+
+$(YAFFSSYMLINKS):
+       ln -s ../../$@ $@
+
+$(YAFFSDIRECTSYMLINKS):
+       ln -s ../$@ $@
+
+$(DIRECTEXTRASYMLINKS):
+       ln -s ../basic-test/$@ $@
+
+
+yaffs_tester: $(SYMLINKS) $(YAFFSTESTOBJS)
+       gcc $(CFLLAG) -o $@ $(YAFFSTESTOBJS)
+
+
+
+
+
+
+clean:
+       rm -f yaffs_tester  $(ALLOBJS) core $(SYMLINKS)
diff --git a/direct/timothy_tests/yaffs_tester.c b/direct/timothy_tests/yaffs_tester.c
new file mode 100644 (file)
index 0000000..3c7c8ef
--- /dev/null
@@ -0,0 +1,115 @@
+/*yaffs_tester.c*/
+#include "yaffs_tester.h"
+
+
+int random_seed;
+int simulate_power_failure = 0;
+
+
+buffer message_buffer; /*create  message_buffer */
+
+
+
+int main()
+{      
+       char yaffs_test_dir[]="/yaffs2/test_dir";
+       char yaffs_mount_dir[]="/yaffs2/";
+       printf("welcome to the yaffs tester\n");
+       init(yaffs_test_dir,yaffs_mount_dir);
+       //test(yaffs_test_dir);
+       add_to_buffer(&message_buffer,"message1\0");
+       add_to_buffer(&message_buffer,"message2\0");
+       add_to_buffer(&message_buffer,"message3\0");
+       add_to_buffer(&message_buffer,"message4\0");
+       add_to_buffer(&message_buffer,"message5\0");
+       print_buffer(&message_buffer);
+       yaffs_unmount(yaffs_mount_dir);
+       return 0;
+}
+
+void add_to_buffer(buffer *p_Buffer, char message[])
+{
+       //add a thing to add \0 on the end of the message
+       if (p_Buffer->head+1==p_Buffer->tail)
+       {
+               p_Buffer->tail++;
+               if (p_Buffer->tail >BUFFER_SIZE-1) p_Buffer->tail -= BUFFER_SIZE-1;
+               
+       }
+       /*move the head up one. the head always points at the last witten data*/
+       p_Buffer->head++;
+       if (p_Buffer->head >BUFFER_SIZE) p_Buffer->head -= BUFFER_SIZE;
+
+       strcpy(p_Buffer->message[p_Buffer->head],message);
+
+}
+void print_buffer(buffer *p_Buffer)
+{
+       printf("print buffer\n");
+       printf("buffer head:%d\n",p_Buffer->head);
+       printf("buffer tail:%d\n",p_Buffer->tail);
+       int x;
+       for (x=p_Buffer->head; x>=p_Buffer->tail; x--)
+       {
+               printf("x:%d\n",x);
+               if (x<0) x = BUFFER_SIZE;
+               printf("%s",p_Buffer->message[x]);
+               
+       }
+
+}
+
+
+void init(char yaffs_test_dir[],char yaffs_mount_dir[])
+{
+       yaffs_StartUp();
+       yaffs_mount(yaffs_mount_dir);
+       if (yaffs_access(yaffs_test_dir,0))
+       {
+               yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
+       }
+}
+
+void yaffs_check_for_errors(char output)
+{
+       if (output==-1)
+       {
+               printf("error####");
+               print_buffer(&message_buffer);
+       }
+}
+
+void test(char yaffs_test_dir[])
+{
+       char name[MAX_FILE_NAME_SIZE +3];
+       unsigned int x;
+       while(1)
+       {
+
+               generate_random_string(name);
+               printf("the length of the string is %d \n",strlen(name)); 
+               printf("generated string is:");
+               for (x=0; x <= (strlen(name)-1)&&x<=MAX_FILE_NAME_SIZE ; x++)
+               {
+//                     printf("x=%d\n",x);
+                       printf("%c ",name[x]);
+               }
+               printf("\n");
+       }
+}
+void  generate_random_string(char *ptr)
+{
+       unsigned int x;
+       unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1);   /*creates a int with the number of charecters been between 1 and 51*/           
+       printf("generating string\n");
+       printf("string length is %d\n",length);
+       for (x=0; x <= (length-2) &&length>2 ; x++)
+       {
+//             printf("x=%d\n",x);     
+               ptr[x]=(rand() % 126-32)+32;    /*generate a number between 32 and 126 and uses it as a charecter (letter) */
+//             printf("charecter generated is %c\n",ptr[x]);
+       }
+       ptr[x+1]=0;     /*adds NULL charecter to turn it into a string*/
+       
+}
+
diff --git a/direct/timothy_tests/yaffs_tester.h b/direct/timothy_tests/yaffs_tester.h
new file mode 100644 (file)
index 0000000..1f96591
--- /dev/null
@@ -0,0 +1,25 @@
+/*yaffs_tester.h */
+#ifndef __YAFFS_TESTER_H__
+       #define __YAFFS_TESTER_H__
+
+       #include <stdio.h>
+       
+       #include "yaffsfs.h"    /* it is in "yaffs2/direct/" link it in the Makefile */
+       
+
+       #define MAX_FILE_NAME_SIZE 51
+       #define BUFFER_MESSAGE_LENGTH 50                /*number of char in message*/
+       #define BUFFER_SIZE 50                  /*number of messages in buffer*/
+       typedef struct buffer_template
+       {
+               char message[BUFFER_SIZE][BUFFER_MESSAGE_LENGTH];
+               char head;
+               char tail;
+       }buffer; 
+
+       void init(char yaffs_test_dir[],char yaffs_mount_dir[]);        /*sets up yaffs and mounts yaffs */
+       void test(char yaffs_test_dir[]);                               /*contains the test code*/
+       void generate_random_string(char *ptr);                         /*generates a random string of letters to be used for a name*/
+       void add_to_buffer(buffer *p_Buffer, char message[]);           /*code for buffer*/
+       void print_buffer(buffer *p_Buffer);                            /*print all of the messages in the buffer*/ 
+#endif
index 0b236ff..ea33223 100644 (file)
@@ -2330,6 +2330,11 @@ int yaffs_n_handles(const YCHAR *path)
        return yaffsfs_CountHandles(obj);
 }
 
+int yaffs_get_error(void)
+{
+       return yaffsfs_GetLastError();
+}
+
 int yaffs_dump_dev(const YCHAR *path)
 {
 #if 0
index 5f47a2d..e094959 100644 (file)
@@ -171,11 +171,14 @@ void yaffs_add_device(struct yaffs_dev_s *dev);
 
 int yaffs_start_up(void);
 
+/* Function to get the last error */
+int yaffs_get_error(void);
 
 /* Function only for debugging */
 void * yaffs_getdev(const YCHAR *path);
 int yaffs_dump_dev(const YCHAR *path);
 
+
 #endif