Change from SWIG to ctypes... much easier
[yaffs2.git] / direct / python / README.txt
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.
18 >>> from ctypes import *
19 >>> cdll.LoadLibrary("./libyaffsfs.so")
20 <CDLL './libyaffsfs.so', handle 9ed4178 at b7d418ac>
21 >>> y = CDLL("./libyaffsfs.so")
22 >>> y.yaffs_StartUp()
23 0
24 >>> y.yaffs_mount("/yaffs2")
25 yaffs: Mounting /yaffs2
26 yaffs: yaffs_GutsInitialise()
27 yaffs_ScanBackwards starts  intstartblk 1 intendblk 256...
28 0 blocks to be sorted...
29 ...done
30 yaffs_ScanBackwards ends
31
32 Block summary
33 0 blocks have illegal states
34 Unknown 0 blocks
35 Needs scanning 0 blocks
36 Scanning 0 blocks
37 Empty 256 blocks
38 Allocating 0 blocks
39 Full 0 blocks
40 Dirty 0 blocks
41 Checkpoint 0 blocks
42 Collecting 0 blocks
43 Dead 0 blocks
44
45 yaffs: yaffs_GutsInitialise() done.
46
47 0
48 >>> y.yaffs_open("/yaffs2/xx",66,0666)
49 yaffs: Tnodes added
50 Allocated block 1, seq  4097, 255 left
51 0
52 >>> y.yaffs_write(0,"abc",3)
53 3
54 >>> y.yaffs_lseek(0,0,0)
55 0
56 >>> b = create_string_buffer("",100)
57 >>> y.yaffs_read(0,b,100)
58 3
59 >>> b.value
60 'abc'
61 >>> 
62