X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=direct%2Fpython%2Fexamples.py;h=68fc95c8306252902ccb0b65a616756fb264c7ab;hb=00ebf30805d631cd9bb3155aa249705b3a5777f5;hp=6b40080432ea237122d392da1f2216c4a1b6d580;hpb=22e75ceb6885637cc22f864270d04ea83354548d;p=yaffs2.git diff --git a/direct/python/examples.py b/direct/python/examples.py index 6b40080..68fc95c 100644 --- a/direct/python/examples.py +++ b/direct/python/examples.py @@ -1,3 +1,17 @@ +## +## 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 Charles Manning +## +## 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. +## + + from yaffsfs import * def yaffs_ls(dname): @@ -16,24 +30,69 @@ def yaffs_ls(dname): isDir = True if st.st_mode & 0x4000 else False if isFile : - print "File ",se.d_ino, hex(perms), st.st_size, fullname - if isDir : - print "Dir ",se.d_ino, hex(perms), fullname + print "File ",se.d_ino, hex(perms), st.st_size, fullname, " times ", st.yst_atime, st.yst_ctime, st.yst_mtime + elif isDir : + print "Dir ",se.d_ino, hex(perms), fullname, " times ", st.yst_atime, st.yst_ctime, st.yst_mtime yaffs_ls(fullname) - + else : + print "Other (",hex(st.st_mode),") ",se.d_ino, hex(perms), fullname, " times ", st.yst_atime, st.yst_ctime, st.yst_mtime + sep = yaffs_readdir(dc) + yaffs_closedir(dc) + return 0 else: print "Could not open directory" return -1 +def yaffs_mkfile(fname,fsize): + fd = yaffs_open(fname,66, 0666) + if fd >= 0: + b = create_string_buffer("",1024) + totalwrite=0 + while fsize > 0: + thiswrite = 1024 if fsize > 1024 else fsize + result = yaffs_write(fd,b,thiswrite) + totalwrite += result + fsize -= result + if result != thiswrite: + fsize= 0 + + return totalwrite + else : + return -1 + +def yaffs_link_test(dir): + fnamea = dir + '/aaa' + fnameb = dir + '/bbb' + yaffs_unlink(fnamea) + fd = yaffs_open(fnamea,66,0666) + yaffs_link(fnamea,fnameb) + yaffs_ls(dir) + yaffs_unlink(fnamea) + yaffs_ls(dir) + yaffs_unlink(fnameb) + +def yaffs_o_excl_test(dir): + fname = dir + '/aaa' + yaffs_unlink(fname) + fd = yaffs_open(fname, 66, 0666) + yaffs_close(fd) + print "Created ", fname, " result ", fd + fdx = yaffs_open(fname, 0301, 0666) + print "Attempt to create with O_EXCL existing file returned ", fdx + yaffs_unlink(fname) + fdx = yaffs_open(fname, 0301, 0666) + print "Attempt to create with O_EXCL non-existing file returned ", fdx + root = "/yaffs2" -yaffs_StartUp() +yaffs_start_up() yaffs_mount(root) yaffs_mkdir(root+"/dd",0666) -yaffs_open(root+"/dd/111",66,0666) +h = yaffs_open(root+"/dd/111",66,0666) +yaffs_close(h) yaffs_ls(root)