+##
+## YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
+##
+## Copyright (C) 2002-2010 Aleph One Ltd.
+## for Toby Churchill Ltd and Brightstar Engineering
+##
+## Created by Timothy Manning <timothy@yaffs.net>
+##
+## 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.
+##
+
import os
from yaffsfs import *
import sys
error=yaffs_get_error()
debug_message("error######################################",0)
debug_message(("error code", error), 0)
+ error_message=ctypes.c_char_p()
+ error_message.value=yaffs_error_to_str(error);
+ print "error message", error_message.value
+
def debug_message(message, debug_level):
"""note: that debug level 0 will always be printed unless debug_level is set to -1"""
return new_path
def create_file(file):
+# freespace=ctypes.c_longlong
+# freespace.value=yaffs_freespace(yaffs_root_dir_path)
+# print "yaffs free space:", freespace.value
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("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 there is already a file in yaffs then remove the file . this is to prevent yaffs from opening and 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)
data_file=open(file["path"], "r")
output=yaffs_lseek(current_handle, 0, 0)
if output==-1:
+ ##if there is no more space in the emfile then this is where it will show up.
+ freespace=ctypes.c_longlong
+ freespace.value=yaffs_freespace(yaffs_root_dir_path)
+ print "yaffs free space:", freespace.value
+
+ if freespace.value==0:
+ #print "yaffs free space:", yaffs_freespace(yaffs_root_dir_path)
+ print "yaffs is out of space exiting program"
+ #sys.exit()
debug_message("error with yaffs lseeking", 2)
check_for_yaffs_errors(output)
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 ):
+def import_into_yaffs(file_path, yaffs_path="/yaffs2/", debug_level=1, copy_hidden_dir=True ,new_yaffs_trace_val=-1 ):
# global current_debug_level
# global search_hidden_directories
# global yaffs_root_dir_path
# yaffs_root_dir_path=yaffs_path
# path=file_path
old_yaffs_trace_val=yaffs_get_trace()
- yaffs_set_trace(new_yaffs_trace_val)
+ if new_yaffs_trace_val!=-1:
+ 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)
if __name__=="__main__":
- yaffs_StartUp()
+ yaffs_start_up()
yaffs_mount("/yaffs2/")
- yaffs_set_trace(0)
+ #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/"
+ yaffs_root_dir_path="/yaffs2/"
+ yaffs_trace=-1
#print sys.argv
path=sys.argv[1]
for i in range(2, len(sys.argv)):
current_debug_level=int( sys.argv[i+1])
if sys.argv[i]=="-ignore_hidden_directories":
search_hidden_directories=False
+ if sys.argv[i]=="-o":
+ yaffs_root_dir_path=sys.argv[i+1]
+ if sys.argv[i]=="-yaffs_trace":
+ yaffs_trace=int(sys.argv[i+1])
#
#
# 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 )
+ import_into_yaffs(path, yaffs_root_dir_path, current_debug_level, search_hidden_directories, yaffs_trace )
# scan_dir(path)
# copy_scanned_files_into_yaffs()
#print_scanned_dir_list()