ac2c48c3a911d95c29a9cd6d963f4b1a8177b2e1
[yaffs2.git] / direct / python / examples.py
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         yaffs_closedir(dc)
26         return 0
27     else:
28         print "Could not open directory"
29         return -1
30
31 def yaffs_mkfile(fname,fsize):
32     fd = yaffs_open(fname,66, 0666)
33     if fd >= 0:
34         b = create_string_buffer("",1024)
35         totalwrite=0
36         while fsize > 0:
37             thiswrite = 1024 if fsize > 1024 else fsize
38             result = yaffs_write(fd,b,thiswrite)
39             totalwrite += result
40             fsize -= result
41             if result != thiswrite:
42                 fsize= 0
43
44         return totalwrite
45     else :
46         return -1
47
48 root = "/yaffs2"
49
50 yaffs_StartUp()
51 yaffs_mount(root)
52
53 yaffs_mkdir(root+"/dd",0666)
54
55 yaffs_open(root+"/dd/111",66,0666)
56
57 yaffs_ls(root)