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=[]
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])
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)
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
##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):
-
+
def yaffs_ls(dname):
ls_dict=[]
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
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():
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
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)
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)
#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;
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;
}
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;
/*
* 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;
}
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;
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 &&
/* 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;
}
}
*/
}
- 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);
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);
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);
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 */
{
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;
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);
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);
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);
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);
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);
int retval = 0;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
+
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(obj) {
int access_ok = 1;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
+
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(!obj)
yaffsfs_SetError(-ENOENT);
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,dirname,0);
+ obj = yaffsfs_FindObject(NULL,dirname,0,1);
if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY){
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(!obj) {
yaffsfs_SetError(-ENOENT);
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);
{
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);
}