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