|
298
|
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 |
|
322
|
20 elif isDir : |
|
298
|
21 print "Dir ",se.d_ino, hex(perms), fullname |
|
|
22 yaffs_ls(fullname) |
|
322
|
23 else : |
|
|
24 print "Other (",hex(st.st_mode),") ",se.d_ino, hex(perms), fullname |
|
|
25 |
|
298
|
26 sep = yaffs_readdir(dc) |
|
299
|
27 yaffs_closedir(dc) |
|
|
28 return 0 |
|
298
|
29 else: |
|
|
30 print "Could not open directory" |
|
|
31 return -1 |
|
|
32 |
|
299
|
33 def yaffs_mkfile(fname,fsize): |
|
|
34 fd = yaffs_open(fname,66, 0666) |
|
|
35 if fd >= 0: |
|
|
36 b = create_string_buffer("",1024) |
|
|
37 totalwrite=0 |
|
|
38 while fsize > 0: |
|
|
39 thiswrite = 1024 if fsize > 1024 else fsize |
|
|
40 result = yaffs_write(fd,b,thiswrite) |
|
|
41 totalwrite += result |
|
|
42 fsize -= result |
|
|
43 if result != thiswrite: |
|
|
44 fsize= 0 |
|
|
45 |
|
|
46 return totalwrite |
|
|
47 else : |
|
|
48 return -1 |
|
298
|
49 |
|
|
50 root = "/yaffs2" |
|
|
51 |
|
|
52 yaffs_StartUp() |
|
|
53 yaffs_mount(root) |
|
|
54 |
|
|
55 yaffs_mkdir(root+"/dd",0666) |
|
|
56 |
|
|
57 yaffs_open(root+"/dd/111",66,0666) |
|
|
58 |
|
|
59 yaffs_ls(root) |