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