comparison direct/python/examples.py @ 321:fd8194c28cac

Add some python examples
author charles
date Tue, 13 Oct 2009 02:28:21 +0100
parents
children 1206ae06f03d
comparison
equal deleted inserted replaced
320:e239e0b8c57d 321:fd8194c28cac
1 from yaffsfs import *
2
3 def yaffs_ls(dname):
4 if dname[-1] != "/": dname = dname + "/"
5 dc = yaffs_opendir(dname)
6 if dc != 0 :
7 sep = yaffs_readdir(dc)
8 while bool(sep):
9 se = sep.contents
10 fullname = dname + se.d_name
11 #print fullname, " ", se.d_ino," ",ord(se.d_type)
12 st = yaffs_stat_struct()
13 result = yaffs_stat(fullname,byref(st))
14 perms = st.st_mode & 0777
15 isFile = True if st.st_mode & 0x8000 else False
16 isDir = True if st.st_mode & 0x4000 else False
17
18 if isFile :
19 print "File ",se.d_ino, hex(perms), st.st_size, fullname
20 if isDir :
21 print "Dir ",se.d_ino, hex(perms), fullname
22 yaffs_ls(fullname)
23
24 sep = yaffs_readdir(dc)
25 else:
26 print "Could not open directory"
27 return -1
28
29
30 root = "/yaffs2"
31
32 yaffs_StartUp()
33 yaffs_mount(root)
34
35 yaffs_mkdir(root+"/dd",0666)
36
37 yaffs_open(root+"/dd/111",66,0666)
38
39 yaffs_ls(root)