3196f0c6a691b3b17f2d652e075971329ac1d977
[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 struct yaffs_dirent {
38         long d_ino;                     /* inode number */
39         off_t d_off;                    /* offset to this dirent */
40         unsigned short d_reclen;        /* length of this dirent */
41         YUCHAR d_type;                  /* type of this record */
42         YCHAR d_name[NAME_MAX+1];       /* file name (null-terminated) */
43         unsigned d_dont_use;            /* debug: not for public consumption */
44 };
45
46 typedef struct opaque_structure yaffs_DIR;
47
48
49
50 struct yaffs_stat {
51         int             st_dev;         /* device */
52         int             st_ino;         /* inode */
53         unsigned        st_mode;        /* protection */
54         int             st_nlink;       /* number of hard links */
55         int             st_uid;         /* user ID of owner */
56         int             st_gid;         /* group ID of owner */
57         unsigned        st_rdev;        /* device type (if inode device) */
58         Y_LOFF_T                st_size;        /* total size, in bytes */
59         unsigned long   st_blksize;     /* blocksize for filesystem I/O */
60         unsigned long   st_blocks;      /* number of blocks allocated */
61 #ifdef CONFIG_YAFFS_WINCE
62         /* Special 64-bit times for WinCE */
63         unsigned long   yst_wince_atime[2];
64         unsigned long   yst_wince_mtime[2];
65         unsigned long   yst_wince_ctime[2];
66 #else
67         unsigned long   yst_atime;      /* time of last access */
68         unsigned long   yst_mtime;      /* time of last modification */
69         unsigned long   yst_ctime;      /* time of last change */
70 #endif
71 };
72
73
74 struct yaffs_utimbuf {
75         unsigned long actime;
76         unsigned long modtime;
77 };
78
79
80 int yaffs_open(const YCHAR *path, int oflag, int mode) ;
81
82 int yaffs_close(int fd) ;
83 int yaffs_fsync(int fd) ;
84 int yaffs_fdatasync(int fd) ;
85 int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
86
87 int yaffs_access(const YCHAR *path, int amode);
88
89 int yaffs_dup(int fd);
90
91 int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
92 int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
93
94 int yaffs_pread(int fd, void *buf, unsigned int nbyte, Y_LOFF_T offset);
95 int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, Y_LOFF_T offset);
96
97 Y_LOFF_T yaffs_lseek(int fd, Y_LOFF_T offset, int whence) ;
98
99 int yaffs_truncate(const YCHAR *path, Y_LOFF_T new_size);
100 int yaffs_ftruncate(int fd, Y_LOFF_T new_size);
101
102 int yaffs_unlink(const YCHAR *path) ;
103 int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
104
105 int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
106 int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
107 int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
108
109 int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf);
110 int yaffs_futime(int fd, const struct yaffs_utimbuf *buf);
111
112
113 int yaffs_setxattr(const char *path, const char *name,
114                         const void *data, int size, int flags);
115 int yaffs_lsetxattr(const char *path, const char *name,
116                         const void *data, int size, int flags);
117 int yaffs_fsetxattr(int fd, const char *name,
118                         const void *data, int size, int flags);
119
120 int yaffs_getxattr(const char *path, const char *name,
121                         void *data, int size);
122 int yaffs_lgetxattr(const char *path, const char *name,
123                         void *data, int size);
124 int yaffs_fgetxattr(int fd, const char *name,
125                         void *data, int size);
126
127 int yaffs_removexattr(const char *path, const char *name);
128 int yaffs_lremovexattr(const char *path, const char *name);
129 int yaffs_fremovexattr(int fd, const char *name);
130
131 int yaffs_listxattr(const char *path, char *list, int size);
132 int yaffs_llistxattr(const char *path, char *list, int size);
133 int yaffs_flistxattr(int fd, char *list, int size);
134
135
136 #ifdef CONFIG_YAFFS_WINCE
137
138 int yaffs_set_wince_times(int fd,
139                         const unsigned *wctime,
140                         const unsigned *watime,
141                         const unsigned *wmtime);
142 int yaffs_get_wince_times(int fd,
143                         unsigned *wctime,
144                         unsigned *watime,
145                         unsigned *wmtime);
146
147 #endif
148
149 int yaffs_chmod(const YCHAR *path, mode_t mode);
150 int yaffs_fchmod(int fd, mode_t mode);
151
152 int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
153 int yaffs_rmdir(const YCHAR *path) ;
154
155 yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
156 struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
157 void yaffs_rewinddir(yaffs_DIR *dirp) ;
158 int yaffs_closedir(yaffs_DIR *dirp) ;
159
160 int yaffs_mount(const YCHAR *path) ;
161 int yaffs_mount2(const YCHAR *path, int read_only);
162 int yaffs_mount_common(const YCHAR *path, int read_only, int skip_checkpt);
163
164 int yaffs_unmount(const YCHAR *path) ;
165 int yaffs_unmount2(const YCHAR *path, int force);
166 int yaffs_remount(const YCHAR *path, int force, int read_only);
167
168
169 int yaffs_sync(const YCHAR *path) ;
170
171 int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
172 int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz);
173
174 int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath);
175 int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
176
177 Y_LOFF_T yaffs_freespace(const YCHAR *path);
178 Y_LOFF_T yaffs_totalspace(const YCHAR *path);
179
180 int yaffs_inodecount(const YCHAR *path);
181
182 int yaffs_n_handles(const YCHAR *path);
183
184 #define YAFFS_SHARE_READ  1
185 #define YAFFS_SHARE_WRITE 2
186 int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int shareMode);
187
188 struct yaffs_dev;
189 void yaffs_add_device(struct yaffs_dev *dev);
190
191 int yaffs_start_up(void);
192 int yaffsfs_GetLastError(void);
193
194 /* Functions to iterate through devices. NB Use with extreme care! */
195 void yaffs_dev_rewind(void);
196 struct yaffs_dev *yaffs_next_dev(void);
197
198 /* Function to get the last error */
199 int yaffs_get_error(void);
200 const char *yaffs_error_to_str(int err);
201
202 /* Function only for debugging */
203 void *yaffs_getdev(const YCHAR *path);
204 int yaffs_dump_dev(const YCHAR *path);
205 int yaffs_set_error(int error);
206
207 /* Trace control functions */
208 unsigned  yaffs_set_trace(unsigned tm);
209 unsigned  yaffs_get_trace(void);
210 #endif