|
319
|
1 Using python with yaffsfs
|
|
|
2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
3
|
|
|
4 Herewith a brief session showing yaffs direct being accessed from python.
|
|
|
5
|
|
|
6 I tried SWIG first, but ctypes turned out to be way, way easier...
|
|
|
7
|
|
|
8 Thanks to the people on NZPUG mailing list that helped with the exercise.
|
|
|
9
|
|
|
10 Build libyaffsfs.so with the accompanying Makefile.
|
|
|
11
|
|
|
12 $ make libyaffsfs.so
|
|
|
13
|
|
|
14 $ python
|
|
|
15 Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
|
|
|
16 [GCC 4.3.3] on linux2
|
|
|
17 Type "help", "copyright", "credits" or "license" for more information.
|
|
320
|
18 >>> from yaffsfs import *
|
|
|
19 >>> yaffs_StartUp()
|
|
319
|
20 0
|
|
320
|
21 >>> yaffs_mount("/yaffs2")
|
|
319
|
22 yaffs: Mounting /yaffs2
|
|
|
23 yaffs: yaffs_GutsInitialise()
|
|
|
24 yaffs_ScanBackwards starts intstartblk 1 intendblk 256...
|
|
|
25 0 blocks to be sorted...
|
|
|
26 ...done
|
|
|
27 yaffs_ScanBackwards ends
|
|
|
28
|
|
|
29 Block summary
|
|
|
30 0 blocks have illegal states
|
|
|
31 Unknown 0 blocks
|
|
|
32 Needs scanning 0 blocks
|
|
|
33 Scanning 0 blocks
|
|
|
34 Empty 256 blocks
|
|
|
35 Allocating 0 blocks
|
|
|
36 Full 0 blocks
|
|
|
37 Dirty 0 blocks
|
|
|
38 Checkpoint 0 blocks
|
|
|
39 Collecting 0 blocks
|
|
|
40 Dead 0 blocks
|
|
|
41
|
|
|
42 yaffs: yaffs_GutsInitialise() done.
|
|
|
43
|
|
|
44 0
|
|
320
|
45 >>> yaffs_open("/yaffs2/xx",66,0666)
|
|
319
|
46 yaffs: Tnodes added
|
|
|
47 Allocated block 1, seq 4097, 255 left
|
|
|
48 0
|
|
320
|
49 >>> yaffs_write(0,"abcdefg",5)
|
|
|
50 5
|
|
319
|
51 >>> b = create_string_buffer("",100)
|
|
320
|
52 >>> yaffs_lseek(0,0,0)
|
|
|
53 0
|
|
|
54 >>> yaffs_read(0,b,100)
|
|
|
55 5
|
|
|
56 >>> print b.value
|
|
|
57 abcde
|