Add more test code.
[yaffs2.git] / direct / yaffsfs.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system. 
3  *
4  * Copyright (C) 2002-2007 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 Lesser General Public License version 2.1 as
11  * published by the Free Software Foundation.
12  *
13  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
14  */
15
16 /*
17  * Header file for using yaffs in an application via
18  * a direct interface.
19  */
20
21
22 #ifndef __YAFFSFS_H__
23 #define __YAFFSFS_H__
24
25 #include "yaffscfg.h"
26 #include "yportenv.h"
27
28
29 //typedef long off_t;
30 //typedef long dev_t;
31 //typedef unsigned long mode_t;
32
33
34 #ifndef NAME_MAX
35 #define NAME_MAX        256
36 #endif
37
38
39 #ifdef CONFIG_YAFFSFS_PROVIDE_VALUES
40
41 #ifndef O_RDONLY
42 #define O_RDONLY        00
43 #endif
44
45 #ifndef O_WRONLY
46 #define O_WRONLY        01
47 #endif
48
49 #ifndef O_RDWR
50 #define O_RDWR          02
51 #endif
52
53 #ifndef O_CREAT         
54 #define O_CREAT         0100
55 #endif
56
57 #ifndef O_EXCL
58 #define O_EXCL          0200
59 #endif
60
61 #ifndef O_TRUNC
62 #define O_TRUNC         01000
63 #endif
64
65 #ifndef O_APPEND
66 #define O_APPEND        02000
67 #endif
68
69 #ifndef SEEK_SET
70 #define SEEK_SET        0
71 #endif
72
73 #ifndef SEEK_CUR
74 #define SEEK_CUR        1
75 #endif
76
77 #ifndef SEEK_END
78 #define SEEK_END        2
79 #endif
80
81 #ifndef EBUSY
82 #define EBUSY   16
83 #endif
84
85 #ifndef ENODEV
86 #define ENODEV  19
87 #endif
88
89 #ifndef EINVAL
90 #define EINVAL  22
91 #endif
92
93 #ifndef EBADF
94 #define EBADF   9
95 #endif
96
97 #ifndef EACCES
98 #define EACCES  13
99 #endif
100
101 #ifndef EXDEV   
102 #define EXDEV   18
103 #endif
104
105 #ifndef ENOENT
106 #define ENOENT  2
107 #endif
108
109 #ifndef ENOSPC
110 #define ENOSPC  28
111 #endif
112
113 #ifndef ENOTEMPTY
114 #define ENOTEMPTY 39
115 #endif
116
117 #ifndef ENAMETOOLONG
118 #define ENAMETOOLONG 36
119 #endif
120
121 #ifndef ENOMEM
122 #define ENOMEM 12
123 #endif
124
125 #ifndef EEXIST
126 #define EEXIST 17
127 #endif
128
129 #ifndef ENOTDIR
130 #define ENOTDIR 20
131 #endif
132
133 #ifndef EISDIR
134 #define EISDIR 21
135 #endif
136
137
138 // Mode flags
139
140 #ifndef S_IFMT
141 #define S_IFMT          0170000
142 #endif
143
144 #ifndef S_IFLNK
145 #define S_IFLNK         0120000
146 #endif
147
148 #ifndef S_IFDIR
149 #define S_IFDIR         0040000
150 #endif
151
152 #ifndef S_IFREG
153 #define S_IFREG         0100000
154 #endif
155
156 #ifndef S_IREAD 
157 #define S_IREAD         0000400
158 #endif
159
160 #ifndef S_IWRITE
161 #define S_IWRITE        0000200
162 #endif
163
164 #ifndef S_IEXEC
165 #define S_IEXEC 0000100
166 #endif
167
168 #ifndef R_OK
169 #define R_OK    4
170 #define W_OK    2
171 #define X_OK    1
172 #define F_OK    0
173 #endif
174
175 #else
176 #include <errno.h>
177 #include <sys/stat.h>
178 #include <fcntl.h>
179 #endif
180
181
182 struct yaffs_dirent{
183     long d_ino;                 /* inode number */
184     off_t d_off;                /* offset to this dirent */
185     unsigned short d_reclen;    /* length of this d_name */
186     YUCHAR  d_type;     /* type of this record */
187     YCHAR d_name [NAME_MAX+1];   /* file name (null-terminated) */
188     unsigned d_dont_use;        /* debug pointer, not for public consumption */
189 };
190
191 typedef struct yaffs_dirent yaffs_dirent;
192
193
194 typedef struct __opaque yaffs_DIR;
195
196
197
198 struct yaffs_stat{
199     int               st_dev;      /* device */
200     int           st_ino;      /* inode */
201     unsigned      st_mode;     /* protection */
202     int           st_nlink;    /* number of hard links */
203     int           st_uid;      /* user ID of owner */
204     int           st_gid;      /* group ID of owner */
205     unsigned      st_rdev;     /* device type (if inode device) */
206     off_t         st_size;     /* total size, in bytes */
207     unsigned long st_blksize;  /* blocksize for filesystem I/O */
208     unsigned long st_blocks;   /* number of blocks allocated */
209 #ifdef CONFIG_YAFFS_WINCE
210         /* Special 64-bit times for WinCE */
211         unsigned long yst_wince_atime[2];
212         unsigned long yst_wince_mtime[2];
213         unsigned long yst_wince_ctime[2];
214 #else
215         unsigned long yst_atime;    /* time of last access */
216     unsigned long yst_mtime;    /* time of last modification */
217     unsigned long yst_ctime;    /* time of last change */
218 #endif
219 };
220
221 int yaffs_open(const YCHAR *path, int oflag, int mode) ;
222 int yaffs_close(int fd) ;
223 int yaffs_fsync(int fd) ;
224 int yaffs_fdatasync(int fd) ;
225 int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
226
227 int yaffs_access(const YCHAR *path, int amode);
228
229 int yaffs_dup(int fd);
230
231 int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
232 int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
233
234 int yaffs_pread(int fd, void *buf, unsigned int nbyte, unsigned int offset);
235 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, unsigned int offset);
236
237 off_t yaffs_lseek(int fd, off_t offset, int whence) ;
238
239 int yaffs_truncate(const YCHAR *path, off_t newSize);
240 int yaffs_ftruncate(int fd, off_t newSize);
241
242 int yaffs_unlink(const YCHAR *path) ;
243 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
244
245 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
246 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
247 int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
248
249 #ifdef CONFIG_YAFFS_WINCE
250
251 int yaffs_set_wince_times(int fd, const unsigned *wctime, const unsigned *watime, const unsigned *wmtime);
252 int yaffs_get_wince_times(int fd, unsigned *wctime, unsigned *watime, unsigned *wmtime);
253
254 #endif
255
256 int yaffs_chmod(const YCHAR *path, mode_t mode); 
257 int yaffs_fchmod(int fd, mode_t mode); 
258
259 int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
260 int yaffs_rmdir(const YCHAR *path) ;
261
262 yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
263 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
264 void yaffs_rewinddir(yaffs_DIR *dirp) ;
265 int yaffs_closedir(yaffs_DIR *dirp) ;
266
267 int yaffs_mount(const YCHAR *path) ;
268 int yaffs_mount2(const YCHAR *path, int readOnly);
269 int yaffs_unmount(const YCHAR *path) ;
270 int yaffs_unmount2(const YCHAR *path, int force);
271 int yaffs_remount(const YCHAR *path, int force, int readOnly);
272
273
274 int yaffs_sync(const YCHAR *path) ;
275
276 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath); 
277 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz); 
278
279 int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath); 
280 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
281
282 loff_t yaffs_freespace(const YCHAR *path);
283 loff_t yaffs_totalspace(const YCHAR *path);
284
285 int yaffs_inodecount(const YCHAR *path);
286
287
288 void yaffs_initialise(yaffsfs_DeviceConfiguration *configList);
289
290 int yaffs_StartUp(void);
291
292 #endif
293
294