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