yaffs Normalized headers for release branch.
[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 #int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharingmode) ;
19 yaffs_open_sharing = ylib.yaffs_open_sharing
20 yaffs_open_sharing.argtypes = [ c_char_p, c_int, c_int, c_int]
21 yaffs_open_sharing.restype = c_int
22
23 #int yaffs_open(const YCHAR *path, int oflag, int mode) ;
24 yaffs_open = ylib.yaffs_open
25 yaffs_open.argtypes = [ c_char_p, c_int, c_int]
26 yaffs_open.restype = c_int
27
28 #int yaffs_close(int fd) ;
29 yaffs_close = ylib.yaffs_close
30 yaffs_close.argtypes = [ c_int]
31 yaffs_close.restype = c_int
32
33 #int yaffs_fsync(int fd) ;
34 yaffs_fsync = ylib.yaffs_fsync
35 yaffs_fsync.argtypes = [c_int]
36 yaffs_fsync.restype = c_int
37
38 #int yaffs_fdatasync(int fd) ;
39 yaffs_fdatasync = ylib.yaffs_fdatasync
40 yaffs_fdatasync.argtypes = [c_int]
41 yaffs_fdatasync.restype = c_int
42
43 #int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
44 yaffs_flush = ylib.yaffs_flush
45 yaffs_flush.argtypes = [c_int]
46 yaffs_flush.restype = c_int
47
48 #int yaffs_access(const YCHAR *path, int amode);
49 yaffs_access=ylib.yaffs_access
50 yaffs_access.argtypes= [c_char_p,c_int]
51 yaffs_access.restype = c_int
52
53 #int yaffs_dup(int fd);
54 yaffs_dup = ylib.yaffs_dup
55 yaffs_dup.argtypes = [c_int]
56 yaffs_dup.restype = c_int
57
58 #int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
59 yaffs_read=ylib.yaffs_read
60 yaffs_read.argtypes=[c_int,c_char_p,c_int]
61 yaffs_read.restype = c_int
62
63 #int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
64 yaffs_write=ylib.yaffs_write
65 yaffs_write.argtypes=[c_int,c_char_p,c_int]
66 yaffs_write.restype = c_int
67
68 #int yaffs_pread(int fd, void *buf, unsigned int nbyte, unsigned int offset);
69 yaffs_pread=ylib.yaffs_pread
70 yaffs_pread.argtypes=[c_int,c_char_p,c_int,c_int]
71 yaffs_pread.restype = c_int
72
73 #int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, unsigned int offset);
74 yaffs_pwrite=ylib.yaffs_pwrite
75 yaffs_pwrite.argtypes=[c_int,c_char_p,c_int,c_int]
76 yaffs_pwrite.restype = c_int
77
78 # off_t = 4 byte int
79 #off_t yaffs_lseek(int fd, off_t offset, int whence) ;
80 yaffs_lseek=ylib.yaffs_lseek
81 yaffs_lseek.argtypes= [c_int, c_int, c_int]
82 yaffs_lseek.restype= c_int
83
84 #int yaffs_truncate(const YCHAR *path, off_t newSize);
85 yaffs_truncate=ylib.yaffs_truncate
86 yaffs_truncate.argtypes = [c_char_p,c_int]
87 yaffs_truncate.restype = c_int
88
89 #int yaffs_ftruncate(int fd, off_t newSize);
90 yaffs_ftruncate = ylib.yaffs_ftruncate
91 yaffs_truncate.argtypes = [c_int,c_int]
92 yaffs_truncate.restype = c_int
93
94 #int yaffs_unlink(const YCHAR *path) ;
95 yaffs_unlink=ylib.yaffs_unlink
96 yaffs_unlink.argtypes = [c_char_p]
97 yaffs_unlink.restype = c_int
98
99 #int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
100 yaffs_rename= ylib.yaffs_rename
101 yaffs_rename.argtypes=[c_char_p, c_char_p]
102 yaffs_rename.restype = c_int
103
104 class yaffs_stat_struct(Structure):
105     _fields_ = [
106         ("st_dev", c_int),
107         ("st_ino", c_int),
108         ("st_mode", c_int),
109         ("st_nlink", c_int),
110         ("st_uid", c_int),
111         ("st_gid", c_int),
112         ("st_rdev", c_int),
113         ("st_size", c_int),
114         ("st_blksize", c_int),
115         ("st_blocks", c_int),
116         ("yst_atime", c_int),
117         ("yst_mtime", c_int),
118         ("yst_ctime", c_int)]
119
120 #int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
121 yaffs_stat = ylib.yaffs_stat
122 yaffs_stat.argtypes=[c_char_p,POINTER(yaffs_stat_struct)]
123 yaffs_stat.restype=c_int
124
125 #int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
126 yaffs_lstat = ylib.yaffs_lstat
127 yaffs_lstat.argtypes=[c_char_p,POINTER(yaffs_stat_struct)]
128 yaffs_lstat.restype=c_int
129
130 #int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
131 yaffs_fstat = ylib.yaffs_fstat
132 yaffs_fstat.argtypes=[c_int,POINTER(yaffs_stat_struct)]
133 yaffs_fstat.restype=c_int
134
135
136 #int yaffs_chmod(const YCHAR *path, mode_t mode);
137 yaffs_chmod = ylib.yaffs_chmod
138 yaffs_chmod.argtypes = [c_char_p, c_int]
139 yaffs_chmod.restype = c_int
140
141 #int yaffs_fchmod(int fd, mode_t mode); 
142 yaffs_fchmod = ylib.yaffs_fchmod
143 yaffs_fchmod.argtypes = [c_int, c_int]
144 yaffs_fchmod.restype = c_int
145
146 #int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
147 yaffs_mkdir = ylib.yaffs_mkdir
148 yaffs_mkdir.argtypes = [c_char_p, c_int]
149 yaffs_mkdir.restype = c_int
150
151 #int yaffs_rmdir(const YCHAR *path) ;
152 yaffs_rmdir = ylib.yaffs_rmdir
153 yaffs_rmdir.argtypes = [c_char_p]
154 yaffs_rmdir.restype = c_int
155
156 class yaffs_dirent_struct(Structure):
157     _fields_ = [
158         ("d_ino", c_int),
159         ("d_off", c_int),
160         ("d_reclen", c_short),
161         ("d_type", c_char),
162         ("d_name", c_char * 257),
163         ("d_dont_use", c_int)]
164
165 #yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
166 yaffs_opendir = ylib.yaffs_opendir
167 yaffs_opendir.argtypes = [c_char_p]
168 yaffs_opendir.restype = c_int
169
170 #struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
171 yaffs_readdir= ylib.yaffs_readdir
172 yaffs_readdir.argtypes=[c_int]
173 yaffs_readdir.restype=POINTER(yaffs_dirent_struct)
174
175 #void yaffs_rewinddir(yaffs_DIR *dirp) ;
176 yaffs_rewinddir = ylib.yaffs_rewinddir
177 yaffs_rewinddir.argtypes = [c_int]
178 yaffs_rewinddir.restype = c_int ###### Should be void
179
180 #int yaffs_closedir(yaffs_DIR *dirp) ;
181 yaffs_closedir = ylib.yaffs_closedir
182 yaffs_closedir.argtypes = [c_int]
183 yaffs_closedir.restype = c_int
184
185
186 #int yaffs_mount(const YCHAR *path) ;
187 yaffs_mount = ylib.yaffs_mount
188 yaffs_mount.argtypes = [c_char_p]
189 yaffs_mount.restype = c_int
190
191 #int yaffs_mount2(const YCHAR *path,int readOnly) ;
192 yaffs_mount2 = ylib.yaffs_mount2
193 yaffs_mount2.argtypes = [c_char_p, c_int]
194 yaffs_mount2.restype = c_int
195
196 #int yaffs_unmount(const YCHAR *path) ;
197 yaffs_unmount = ylib.yaffs_unmount
198 yaffs_unmount.argtypes = [c_char_p]
199 yaffs_unmount.restype = c_int
200
201 #int yaffs_unmount(const YCHAR *path, int force) ;
202 yaffs_unmount2 = ylib.yaffs_unmount2
203 yaffs_unmount2.argtypes = [c_char_p, c_int]
204 yaffs_unmount2.restype = c_int
205
206 #int yaffs_remount(const YCHAR *path, int force, int readOnly) ;
207 yaffs_remount = ylib.yaffs_remount
208 yaffs_remount.argtypes = [c_char_p, c_int, c_int]
209 yaffs_remount.restype = c_int
210
211 #int yaffs_sync(const YCHAR *path) ;
212 yaffs_sync = ylib.yaffs_sync
213 yaffs_sync.argtypes = [c_char_p]
214 yaffs_sync.restype = c_int
215
216 #int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
217 yaffs_symlink= ylib.yaffs_symlink
218 yaffs_symlink.argtypes= [c_char_p, c_char_p]
219 yaffs_symlink.restype = c_int
220
221 #int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz); 
222 yaffs_readlink = ylib.yaffs_readlink
223 yaffs_readlink.argtypes = [c_char_p, c_char_p, c_int]
224 yaffs_readlink.restype = c_int
225
226 #int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath); 
227 yaffs_link = ylib.yaffs_link
228 yaffs_link.argtypes = [c_char_p, c_char_p]
229 yaffs_link.restype = c_int
230
231 #int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
232 yaffs_mknod = ylib.yaffs_mknod
233 yaffs_mknod.argtypes = [c_char_p, c_int, c_int]
234 yaffs_mknod.restype = c_int
235
236 #loff_t yaffs_freespace(const YCHAR *path);
237 yaffs_freespace = ylib.yaffs_freespace
238 yaffs_freespace.argtypes = [c_char_p]
239 yaffs_freespace.restype = c_longlong
240
241 #loff_t yaffs_totalspace(const YCHAR *path);
242 yaffs_totalspace = ylib.yaffs_totalspace
243 yaffs_totalspace.argtypes = [c_char_p]
244 yaffs_totalspace.restype = c_longlong
245
246 #int yaffs_inodecount(const YCHAR *path);
247 yaffs_inodecount = ylib.yaffs_inodecount
248 yaffs_inodecount.argtypes = [c_char_p]
249 yaffs_inodecount.restype = c_int
250
251 #int yaffs_n_handles(const YCHAR *path)
252 yaffs_n_handles = ylib.yaffs_n_handles
253 yaffs_n_handles.argtypes = [c_char_p]
254 yaffs_n_handles.restype = c_int
255
256 #int yaffs_StartUp(void)
257 yaffs_StartUp = ylib.yaffs_StartUp
258 yaffs_StartUp.argtypes = []
259 yaffs_StartUp.restype = c_int
260