3e0ddd0b3eb18325ba61ca801d972f8194bde9d5
[yaffs2.git] / direct / yaffsfs.h
1 /*
2  * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2011 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 #ifndef NAME_MAX
30 #define NAME_MAX        256
31 #endif
32
33 #define YAFFS_MAX_FILE_SIZE \
34         ( (sizeof(Y_LOFF_T) < 8) ? YAFFS_MAX_FILE_SIZE_32 : (0x800000000LL - 1) )
35
36
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41
42
43 struct yaffs_dirent {
44         long d_ino;                     /* inode number */
45         off_t d_off;                    /* offset to this dirent */
46         unsigned short d_reclen;        /* length of this dirent */
47         YUCHAR d_type;                  /* type of this record */
48         YCHAR d_name[NAME_MAX+1];       /* file name (null-terminated) */
49         unsigned d_dont_use;            /* debug: not for public consumption */
50 };
51
52 typedef struct opaque_structure yaffs_DIR;
53
54
55
56 struct yaffs_stat {
57         int             st_dev;         /* device */
58         int             st_ino;         /* inode */
59         unsigned        st_mode;        /* protection */
60         int             st_nlink;       /* number of hard links */
61         int             st_uid;         /* user ID of owner */
62         int             st_gid;         /* group ID of owner */
63         unsigned        st_rdev;        /* device type (if inode device) */
64         Y_LOFF_T                st_size;        /* total size, in bytes */
65         unsigned long   st_blksize;     /* blocksize for filesystem I/O */
66         unsigned long   st_blocks;      /* number of blocks allocated */
67 #ifdef CONFIG_YAFFS_WINCE
68         /* Special 64-bit times for WinCE */
69         unsigned long   yst_wince_atime[2];
70         unsigned long   yst_wince_mtime[2];
71         unsigned long   yst_wince_ctime[2];
72 #else
73         unsigned long   yst_atime;      /* time of last access */
74         unsigned long   yst_mtime;      /* time of last modification */
75         unsigned long   yst_ctime;      /* time of last change */
76 #endif
77 };
78
79
80 struct yaffs_utimbuf {
81         unsigned long actime;
82         unsigned long modtime;
83 };
84
85 /* Normal POSIX-style API functions */
86
87 int yaffs_open(const YCHAR *path, int oflag, int mode) ;
88
89 int yaffs_close(int fd) ;
90 int yaffs_fsync(int fd) ;
91 int yaffs_fdatasync(int fd) ;
92 int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
93
94 int yaffs_access(const YCHAR *path, int amode);
95
96 int yaffs_dup(int fd);
97
98 int yaffs_fgetfl(int fd, int *flags);
99
100 int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
101 int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
102
103 int yaffs_pread(int fd, void *buf, unsigned int nbyte, Y_LOFF_T offset);
104 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset);
105
106 Y_LOFF_T yaffs_lseek(int fd, Y_LOFF_T offset, int whence);
107
108 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size);
109 int yaffs_ftruncate(int fd, Y_LOFF_T new_size);
110
111 int yaffs_unlink(const YCHAR *path);
112 int yaffs_funlink(int fd);
113
114 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
115
116 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
117 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
118 int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
119
120 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf);
121 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf);
122
123
124 int yaffs_setxattr(const char *path, const char *name,
125                         const void *data, int size, int flags);
126 int yaffs_lsetxattr(const char *path, const char *name,
127                         const void *data, int size, int flags);
128 int yaffs_fsetxattr(int fd, const char *name,
129                         const void *data, int size, int flags);
130
131 int yaffs_getxattr(const char *path, const char *name,
132                         void *data, int size);
133 int yaffs_lgetxattr(const char *path, const char *name,
134                         void *data, int size);
135 int yaffs_fgetxattr(int fd, const char *name,
136                         void *data, int size);
137
138 int yaffs_removexattr(const char *path, const char *name);
139 int yaffs_lremovexattr(const char *path, const char *name);
140 int yaffs_fremovexattr(int fd, const char *name);
141
142 int yaffs_listxattr(const char *path, char *list, int size);
143 int yaffs_llistxattr(const char *path, char *list, int size);
144 int yaffs_flistxattr(int fd, char *list, int size);
145
146 int yaffs_chmod(const YCHAR *path, mode_t mode);
147 int yaffs_fchmod(int fd, mode_t mode);
148
149 int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
150 int yaffs_rmdir(const YCHAR *path) ;
151
152 yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
153 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
154 void yaffs_rewinddir(yaffs_DIR *dirp) ;
155 int yaffs_closedir(yaffs_DIR *dirp) ;
156
157 int yaffs_mount(const YCHAR *path) ;
158 int yaffs_mount2(const YCHAR *path, int read_only);
159 int yaffs_mount3(const YCHAR *path, int read_only, int skip_checkpt);
160
161 int yaffs_unmount(const YCHAR *path) ;
162 int yaffs_unmount2(const YCHAR *path, int force);
163 int yaffs_remount(const YCHAR *path, int force, int read_only);
164
165 int yaffs_format(const YCHAR *path,
166                 int unmount_flag,
167                 int force_unmount_flag,
168                 int remount_flag);
169
170 /*
171  * yaffs_sync() does a full sync, including checkpoint.
172  * yaffs_sync_files() just flushes the cache and does not write a checkpoint.
173  */
174 int yaffs_sync(const YCHAR *path);
175 int yaffs_sync_files(const YCHAR *path) ;
176
177 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
178 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz);
179
180 int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath);
181 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
182
183 Y_LOFF_T yaffs_freespace(const YCHAR *path);
184 Y_LOFF_T yaffs_totalspace(const YCHAR *path);
185
186 /* Function variants that use a relative directory */
187 struct yaffs_obj;
188 int yaffs_open_sharing_reldir(struct yaffs_obj *reldir, const YCHAR *path, int oflag, int mode, int sharing);
189 int yaffs_open_reldir(struct yaffs_obj *reldir,const YCHAR *path, int oflag, int mode);
190 int yaffs_truncate_reldir(struct yaffs_obj *reldir, const YCHAR *path, Y_LOFF_T new_size);
191 int yaffs_unlink_reldir(struct yaffs_obj *reldir, const YCHAR *path);
192 int yaffs_rename_reldir(struct yaffs_obj *reldir,
193                         const YCHAR *oldPath, const YCHAR *newPath);
194 int yaffs_stat_reldir(struct yaffs_obj *reldir, const YCHAR *path, struct yaffs_stat *buf);
195 int yaffs_lstat_reldir(struct yaffs_obj *reldir, const YCHAR *path, struct yaffs_stat *buf);
196 int yaffs_utime_reldir(struct yaffs_obj *reldir, const YCHAR *path, const struct yaffs_utimbuf *buf);
197 int yaffs_setxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
198                         const char *name, const void *data, int size, int flags);
199 int yaffs_lsetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
200                         const char *name, const void *data, int size, int flags);
201 int yaffs_getxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
202                         const char *name, void *data, int size);
203 int yaffs_lgetxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
204                         const char *name, void *data, int size);
205 int yaffs_listxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
206                         char *data, int size);
207 int yaffs_llistxattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
208                         char *data, int size);
209 int yaffs_removexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
210                         const char *name);
211 int yaffs_lremovexattr_reldir(struct yaffs_obj *reldir, const YCHAR *path,
212                         const char *name);
213 int yaffs_access_reldir(struct yaffs_obj *reldir, const YCHAR *path, int amode);
214 int yaffs_chmod_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode);
215 int yaffs_mkdir_reldir(struct yaffs_obj *reldir, const YCHAR *path, mode_t mode);
216 int yaffs_rmdir_reldir(struct yaffs_obj *reldir, const YCHAR *path);
217 yaffs_DIR *yaffs_opendir_reldir(struct yaffs_obj *reldir, const YCHAR *dirname);
218 int yaffs_symlink_reldir(struct yaffs_obj *reldir,
219                         const YCHAR *oldpath, const YCHAR *newpath);
220 int yaffs_readlink_reldir(struct yaffs_obj *reldir,const YCHAR *path,
221                         YCHAR *buf, int bufsiz);
222 int yaffs_link_reldir(struct yaffs_obj *reldir,
223                         const YCHAR *oldpath, const YCHAR *linkpath);
224 int yaffs_mknod_reldir(struct yaffs_obj *reldir, const YCHAR *pathname,
225                      mode_t mode, dev_t dev);
226
227 /* Function variants that use a relative device */
228 struct yaffs_dev;
229 int yaffs_mount_reldev(struct yaffs_dev *dev);
230 int yaffs_open_sharing_reldev(struct yaffs_dev *dev, const YCHAR *path, int oflag, int mode, int sharing);
231 int yaffs_open_reldev(struct yaffs_dev *dev,const YCHAR *path, int oflag, int mode);
232 int yaffs_truncate_reldev(struct yaffs_dev *dev, const YCHAR *path, Y_LOFF_T new_size);
233 int yaffs_unlink_reldev(struct yaffs_dev *dev, const YCHAR *path);
234 int yaffs_rename_reldev(struct yaffs_dev *dev,
235                         const YCHAR *oldPath, const YCHAR *newPath);
236 int yaffs_stat_reldev(struct yaffs_dev *dev, const YCHAR *path, struct yaffs_stat *buf);
237 int yaffs_lstat_reldev(struct yaffs_dev *dev, const YCHAR *path, struct yaffs_stat *buf);
238 int yaffs_utime_reldev(struct yaffs_dev *dev, const YCHAR *path, const struct yaffs_utimbuf *buf);
239 int yaffs_setxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
240                         const char *name, const void *data, int size, int flags);
241 int yaffs_lsetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
242                         const char *name, const void *data, int size, int flags);
243 int yaffs_getxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
244                         const char *name, void *data, int size);
245 int yaffs_lgetxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
246                         const char *name, void *data, int size);
247 int yaffs_listxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
248                         char *data, int size);
249 int yaffs_llistxattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
250                         char *data, int size);
251 int yaffs_removexattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
252                         const char *name);
253 int yaffs_lremovexattr_reldev(struct yaffs_dev *dev, const YCHAR *path,
254                         const char *name);
255 int yaffs_access_reldev(struct yaffs_dev *dev, const YCHAR *path, int amode);
256 int yaffs_chmod_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode);
257 int yaffs_mkdir_reldev(struct yaffs_dev *dev, const YCHAR *path, mode_t mode);
258 int yaffs_rmdir_reldev(struct yaffs_dev *dev, const YCHAR *path);
259 yaffs_DIR *yaffs_opendir_reldev(struct yaffs_dev *dev, const YCHAR *dirname);
260 int yaffs_symlink_reldev(struct yaffs_dev *dev,
261                         const YCHAR *oldpath, const YCHAR *newpath);
262 int yaffs_readlink_reldev(struct yaffs_dev *dev, const YCHAR *path,
263                         YCHAR *buf, int bufsiz);
264 int yaffs_link_reldev(struct yaffs_dev *dev,
265                         const YCHAR *oldpath, const YCHAR *linkpath);
266 int yaffs_mknod_reldev(struct yaffs_dev *dev, const YCHAR *pathname,
267                      mode_t mode, dev_t dev_val);
268 Y_LOFF_T yaffs_freespace_reldev(struct yaffs_dev *dev);
269 Y_LOFF_T yaffs_totalspace_reldev(struct yaffs_dev *dev);
270
271 /*
272  * yaffs_sync_reldev() does a full sync, including checkpoint.
273  * yaffs_sync_files_reldev() just flushes the cache and does not write a checkpoint.
274  */
275 int yaffs_sync_reldev(struct yaffs_dev *dev);
276 int yaffs_sync_files_reldev(struct yaffs_dev *dev);
277
278 int yaffs_unmount_reldev(struct yaffs_dev *dev);
279 int yaffs_unmount2_reldev(struct yaffs_dev *dev, int force);
280 int yaffs_remount_reldev(struct yaffs_dev *dev, int force, int read_only);
281
282 /*
283  *  Non standard function to get at objects.
284  */
285 struct yaffs_obj * yaffs_get_obj_from_fd(int handle);
286
287 /* Some non-standard functions to use fds to access directories */
288 struct yaffs_dirent *yaffs_readdir_fd(int fd);
289 void yaffs_rewinddir_fd(int fd);
290
291 /* Non-standard functions to pump garbage collection. */
292 int yaffs_do_background_gc(const YCHAR *path, int urgency);
293 int yaffs_do_background_gc_reldev(struct yaffs_dev *dev, int urgency);
294
295 /* Non-standard functions to get usage info */
296 int yaffs_inodecount(const YCHAR *path);
297
298 int yaffs_n_handles(const YCHAR *path);
299
300 int yaffs_n_handles_reldir(struct yaffs_obj *reldir, const YCHAR *path);
301 int yaffs_dump_dev_reldir(struct yaffs_obj *reldir, const YCHAR *path);
302 int yaffs_n_handles_reldev(struct yaffs_dev *dev, const YCHAR *path);
303 int yaffs_dump_dev_reldev(struct yaffs_dev *dev, const YCHAR *path);
304
305 #ifdef CONFIG_YAFFS_WINCE
306 int yaffs_set_wince_times(int fd,
307                         const unsigned *wctime,
308                         const unsigned *watime,
309                         const unsigned *wmtime);
310 int yaffs_get_wince_times(int fd,
311                         unsigned *wctime,
312                         unsigned *watime,
313                         unsigned *wmtime);
314 #endif
315
316
317 #define YAFFS_SHARE_READ  1
318 #define YAFFS_SHARE_WRITE 2
319 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int shareMode);
320
321 struct yaffs_dev;
322 void yaffs_add_device(struct yaffs_dev *dev);
323
324 int yaffs_start_up(void);
325 int yaffsfs_GetLastError(void);
326
327 /* Functions to iterate through devices. NB Use with extreme care! */
328 void yaffs_dev_rewind(void);
329 struct yaffs_dev *yaffs_next_dev(void);
330
331 /* Function to get the last error */
332 int yaffs_get_error(void);
333 const char *yaffs_error_to_str(int err);
334
335 /* Function only for debugging */
336 void *yaffs_getdev(const YCHAR *path);
337 int yaffs_dump_dev(const YCHAR *path);
338 int yaffs_set_error(int error);
339
340 /* Trace control functions */
341 unsigned  yaffs_set_trace(unsigned tm);
342 unsigned  yaffs_get_trace(void);
343
344
345 #ifdef __cplusplus
346 }
347 #endif
348
349
350 #endif