yaffs Yet more tests for quick tests.
[yaffs2.git] / direct / python / yaffsfs.py
1 ##
2 ## YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3 ##
4 ## Copyright (C) 2002-2010 Aleph One Ltd.
5 ##   for Toby Churchill Ltd and Brightstar Engineering
6 ##
7 ## Created by Charles Manning <charles@aleph1.co.uk>
8 ##
9 ## This program is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License version 2 as
11 ## published by the Free Software Foundation.
12 ##
13
14 from ctypes import *
15 cdll.LoadLibrary("./libyaffsfs.so")
16 ylib = CDLL("./libyaffsfs.so")
17
18 #const char * yaffs_error_to_str(int err);
19 yaffs_error_to_str = ylib.yaffs_error_to_str
20 yaffs_error_to_str.argtypes=[c_int]
21 yaffs_error_to_str.restype=c_char_p
22
23
24 #int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharingmode) ;
25 yaffs_open_sharing = ylib.yaffs_open_sharing
26 yaffs_open_sharing.argtypes = [ c_char_p, c_int, c_int, c_int]
27 yaffs_open_sharing.restype = c_int
28
29 #int yaffs_open(const YCHAR *path, int oflag, int mode) ;
30 yaffs_open = ylib.yaffs_open
31 yaffs_open.argtypes = [ c_char_p, c_int, c_int]
32 yaffs_open.restype = c_int
33
34 #int yaffs_close(int fd) ;
35 yaffs_close = ylib.yaffs_close
36 yaffs_close.argtypes = [ c_int]
37 yaffs_close.restype = c_int
38
39 #int yaffs_fsync(int fd) ;
40 yaffs_fsync = ylib.yaffs_fsync
41 yaffs_fsync.argtypes = [c_int]
42 yaffs_fsync.restype = c_int
43
44 #int yaffs_fdatasync(int fd) ;
45 yaffs_fdatasync = ylib.yaffs_fdatasync
46 yaffs_fdatasync.argtypes = [c_int]
47 yaffs_fdatasync.restype = c_int
48
49 #int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
50 yaffs_flush = ylib.yaffs_flush
51 yaffs_flush.argtypes = [c_int]
52 yaffs_flush.restype = c_int
53
54 #int yaffs_access(const YCHAR *path, int amode);
55 yaffs_access=ylib.yaffs_access
56 yaffs_access.argtypes= [c_char_p,c_int]
57 yaffs_access.restype = c_int
58
59 #int yaffs_dup(int fd);
60 yaffs_dup = ylib.yaffs_dup
61 yaffs_dup.argtypes = [c_int]
62 yaffs_dup.restype = c_int
63
64 #int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
65 yaffs_read=ylib.yaffs_read
66 yaffs_read.argtypes=[c_int,c_char_p,c_int]
67 yaffs_read.restype = c_int
68
69 #int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
70 yaffs_write=ylib.yaffs_write
71 yaffs_write.argtypes=[c_int,c_char_p,c_int]
72 yaffs_write.restype = c_int
73
74 #int yaffs_pread(int fd, void *buf, unsigned int nbyte, unsigned int offset);
75 yaffs_pread=ylib.yaffs_pread
76 yaffs_pread.argtypes=[c_int,c_char_p,c_int,c_int]
77 yaffs_pread.restype = c_int
78
79 #int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, unsigned int offset);
80 yaffs_pwrite=ylib.yaffs_pwrite
81 yaffs_pwrite.argtypes=[c_int,c_char_p,c_int,c_int]
82 yaffs_pwrite.restype = c_int
83
84 # off_t = 4 byte int
85 #off_t yaffs_lseek(int fd, off_t offset, int whence) ;
86 yaffs_lseek=ylib.yaffs_lseek
87 yaffs_lseek.argtypes= [c_int, c_int, c_int]
88 yaffs_lseek.restype= c_int
89
90 #int yaffs_truncate(const YCHAR *path, off_t newSize);
91 yaffs_truncate=ylib.yaffs_truncate
92 yaffs_truncate.argtypes = [c_char_p,c_int]
93 yaffs_truncate.restype = c_int
94
95 #int yaffs_ftruncate(int fd, off_t newSize);
96 yaffs_ftruncate = ylib.yaffs_ftruncate
97 yaffs_truncate.argtypes = [c_int,c_int]
98 yaffs_truncate.restype = c_int
99
100 #int yaffs_unlink(const YCHAR *path) ;
101 yaffs_unlink=ylib.yaffs_unlink
102 yaffs_unlink.argtypes = [c_char_p]
103 yaffs_unlink.restype = c_int
104
105 #int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
106 yaffs_rename= ylib.yaffs_rename
107 yaffs_rename.argtypes=[c_char_p, c_char_p]
108 yaffs_rename.restype = c_int
109
110 class yaffs_stat_struct(Structure):
111     _fields_ = [
112         ("st_dev", c_int),
113         ("st_ino", c_int),
114         ("st_mode", c_int),
115         ("st_nlink", c_int),
116         ("st_uid", c_int),
117         ("st_gid", c_int),
118         ("st_rdev", c_int),
119         ("st_size", c_int),
120         ("st_blksize", c_int),
121         ("st_blocks", c_int),
122         ("yst_atime", c_int),
123         ("yst_mtime", c_int),
124         ("yst_ctime", c_int)]
125
126 #int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
127 yaffs_stat = ylib.yaffs_stat
128 yaffs_stat.argtypes=[c_char_p,POINTER(yaffs_stat_struct)]
129 yaffs_stat.restype=c_int
130
131 #int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
132 yaffs_lstat = ylib.yaffs_lstat
133 yaffs_lstat.argtypes=[c_char_p,POINTER(yaffs_stat_struct)]
134 yaffs_lstat.restype=c_int
135
136 #int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
137 yaffs_fstat = ylib.yaffs_fstat
138 yaffs_fstat.argtypes=[c_int,POINTER(yaffs_stat_struct)]
139 yaffs_fstat.restype=c_int
140
141
142 #int yaffs_chmod(const YCHAR *path, mode_t mode);
143 yaffs_chmod = ylib.yaffs_chmod
144 yaffs_chmod.argtypes = [c_char_p, c_int]
145 yaffs_chmod.restype = c_int
146
147 #int yaffs_fchmod(int fd, mode_t mode); 
148 yaffs_fchmod = ylib.yaffs_fchmod
149 yaffs_fchmod.argtypes = [c_int, c_int]
150 yaffs_fchmod.restype = c_int
151
152 #int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
153 yaffs_mkdir = ylib.yaffs_mkdir
154 yaffs_mkdir.argtypes = [c_char_p, c_int]
155 yaffs_mkdir.restype = c_int
156
157 #int yaffs_rmdir(const YCHAR *path) ;
158 yaffs_rmdir = ylib.yaffs_rmdir
159 yaffs_rmdir.argtypes = [c_char_p]
160 yaffs_rmdir.restype = c_int
161
162 class yaffs_dirent_struct(Structure):
163     _fields_ = [
164         ("d_ino", c_int),
165         ("d_off", c_int),
166         ("d_reclen", c_short),
167         ("d_type", c_char),
168         ("d_name", c_char * 257),
169         ("d_dont_use", c_int)]
170
171 #yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
172 yaffs_opendir = ylib.yaffs_opendir
173 yaffs_opendir.argtypes = [c_char_p]
174 yaffs_opendir.restype = c_int
175
176 #struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
177 yaffs_readdir= ylib.yaffs_readdir
178 yaffs_readdir.argtypes=[c_int]
179 yaffs_readdir.restype=POINTER(yaffs_dirent_struct)
180
181 #void yaffs_rewinddir(yaffs_DIR *dirp) ;
182 yaffs_rewinddir = ylib.yaffs_rewinddir
183 yaffs_rewinddir.argtypes = [c_int]
184 yaffs_rewinddir.restype = c_int ###### Should be void
185
186 #int yaffs_closedir(yaffs_DIR *dirp) ;
187 yaffs_closedir = ylib.yaffs_closedir
188 yaffs_closedir.argtypes = [c_int]
189 yaffs_closedir.restype = c_int
190
191
192 #int yaffs_mount(const YCHAR *path) ;
193 yaffs_mount = ylib.yaffs_mount
194 yaffs_mount.argtypes = [c_char_p]
195 yaffs_mount.restype = c_int
196
197 #int yaffs_mount2(const YCHAR *path,int readOnly) ;
198 yaffs_mount2 = ylib.yaffs_mount2
199 yaffs_mount2.argtypes = [c_char_p, c_int]
200 yaffs_mount2.restype = c_int
201
202 #int yaffs_unmount(const YCHAR *path) ;
203 yaffs_unmount = ylib.yaffs_unmount
204 yaffs_unmount.argtypes = [c_char_p]
205 yaffs_unmount.restype = c_int
206
207 #int yaffs_unmount(const YCHAR *path, int force) ;
208 yaffs_unmount2 = ylib.yaffs_unmount2
209 yaffs_unmount2.argtypes = [c_char_p, c_int]
210 yaffs_unmount2.restype = c_int
211
212 #int yaffs_remount(const YCHAR *path, int force, int readOnly) ;
213 yaffs_remount = ylib.yaffs_remount
214 yaffs_remount.argtypes = [c_char_p, c_int, c_int]
215 yaffs_remount.restype = c_int
216
217 #int yaffs_sync(const YCHAR *path) ;
218 yaffs_sync = ylib.yaffs_sync
219 yaffs_sync.argtypes = [c_char_p]
220 yaffs_sync.restype = c_int
221
222 #int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
223 yaffs_symlink= ylib.yaffs_symlink
224 yaffs_symlink.argtypes= [c_char_p, c_char_p]
225 yaffs_symlink.restype = c_int
226
227 #int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz); 
228 yaffs_readlink = ylib.yaffs_readlink
229 yaffs_readlink.argtypes = [c_char_p, c_char_p, c_int]
230 yaffs_readlink.restype = c_int
231
232 #int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath); 
233 yaffs_link = ylib.yaffs_link
234 yaffs_link.argtypes = [c_char_p, c_char_p]
235 yaffs_link.restype = c_int
236
237 #int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
238 yaffs_mknod = ylib.yaffs_mknod
239 yaffs_mknod.argtypes = [c_char_p, c_int, c_int]
240 yaffs_mknod.restype = c_int
241
242 #loff_t yaffs_freespace(const YCHAR *path);
243 yaffs_freespace = ylib.yaffs_freespace
244 yaffs_freespace.argtypes = [c_char_p]
245 yaffs_freespace.restype = c_longlong
246
247 #loff_t yaffs_totalspace(const YCHAR *path);
248 yaffs_totalspace = ylib.yaffs_totalspace
249 yaffs_totalspace.argtypes = [c_char_p]
250 yaffs_totalspace.restype = c_longlong
251
252 #int yaffs_inodecount(const YCHAR *path);
253 yaffs_inodecount = ylib.yaffs_inodecount
254 yaffs_inodecount.argtypes = [c_char_p]
255 yaffs_inodecount.restype = c_int
256
257 #int yaffs_n_handles(const YCHAR *path)
258 yaffs_n_handles = ylib.yaffs_n_handles
259 yaffs_n_handles.argtypes = [c_char_p]
260 yaffs_n_handles.restype = c_int
261
262 #int yaffs_start_up(void)
263 yaffs_start_up = ylib.yaffs_start_up
264 yaffs_start_up.argtypes = []
265 yaffs_start_up.restype = c_int
266
267 #int yaffs_set_trace(unsigned int tm) { return yaffs_traceMask=tm; }
268 yaffs_set_trace=ylib.yaffs_set_trace
269 yaffs_set_trace.argtypes=[c_uint]
270 yaffs_set_trace.restype=c_uint
271
272 #int yaffs_get_trace(void) { return yaffs_traceMask; }
273 yaffs_get_trace=ylib.yaffs_get_trace
274 yaffs_get_trace.argtypes=[]
275 yaffs_get_trace.restypes=c_uint
276
277 #int yaffs_get_error(void)
278 yaffs_get_error=ylib.yaffs_get_error
279 yaffs_get_error.argtypes=[]
280 yaffs_get_error.restypes=c_int
281
282 yaffs_O_CREAT=ylib.yaffs_O_CREAT()
283 yaffs_O_RDONLY=ylib.yaffs_O_RDONLY()
284 yaffs_O_WRONLY=ylib.yaffs_O_WRONLY()
285 yaffs_O_RDWR=ylib.yaffs_O_RDWR()
286 yaffs_O_TRUNC=ylib.yaffs_O_TRUNC()
287
288
289 yaffs_S_IFMT=ylib.yaffs_S_IFMT()
290 yaffs_S_IFLNK= ylib.yaffs_S_IFLNK()
291 yaffs_S_IFDIR =ylib.yaffs_S_IFDIR()
292 yaffs_S_IFREG=ylib.yaffs_S_IFREG()
293 yaffs_S_IREAD=ylib.yaffs_S_IREAD()
294 yaffs_S_IWRITE=ylib.yaffs_S_IWRITE()
295 yaffs_S_IEXEC=ylib.yaffs_S_IEXEC()  
296 yaffs_XATTR_CREATE=ylib.yaffs_XATTR_CREATE()
297 yaffs_XATTR_REPLACE=ylib.yaffs_XATTR_REPLACE()
298 yaffs_S_IEXEC=ylib.yaffs_S_IEXEC()