blob: f2c7666625cfbf91b2a7c3934967975a2094f52d [file] [log] [blame]
William Juulc051bbe2007-11-15 11:13:05 +01001/*
Wolfgang Denk74e0dde2008-08-14 14:41:06 +02002 * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
William Juulc051bbe2007-11-15 11:13:05 +01003 *
Charles Manning3796e1f2012-05-09 16:55:17 +00004 * Copyright (C) 2002-2011 Aleph One Ltd.
William Juulc051bbe2007-11-15 11:13:05 +01005 * 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
William Juulc051bbe2007-11-15 11:13:05 +010029#ifndef NAME_MAX
30#define NAME_MAX 256
31#endif
32
Charles Manning3796e1f2012-05-09 16:55:17 +000033#define YAFFS_MAX_FILE_SIZE (0x800000000LL - 1)
William Juulc051bbe2007-11-15 11:13:05 +010034
William Juulc051bbe2007-11-15 11:13:05 +010035
Charles Manning3796e1f2012-05-09 16:55:17 +000036struct yaffs_dirent {
37 long d_ino; /* inode number */
38 off_t d_off; /* offset to this dirent */
39 unsigned short d_reclen; /* length of this dirent */
40 YUCHAR d_type; /* type of this record */
41 YCHAR d_name[NAME_MAX+1]; /* file name (null-terminated) */
42 unsigned d_dont_use; /* debug: not for public consumption */
43};
William Juulc051bbe2007-11-15 11:13:05 +010044
Charles Manning3796e1f2012-05-09 16:55:17 +000045typedef struct opaque_structure yaffs_DIR;
William Juulc051bbe2007-11-15 11:13:05 +010046
William Juulc051bbe2007-11-15 11:13:05 +010047
William Juulc051bbe2007-11-15 11:13:05 +010048
Charles Manning3796e1f2012-05-09 16:55:17 +000049struct yaffs_stat {
50 int st_dev; /* device */
51 int st_ino; /* inode */
52 unsigned st_mode; /* protection */
53 int st_nlink; /* number of hard links */
54 int st_uid; /* user ID of owner */
55 int st_gid; /* group ID of owner */
56 unsigned st_rdev; /* device type (if inode device) */
57 loff_t st_size; /* total size, in bytes */
58 unsigned long st_blksize; /* blocksize for filesystem I/O */
59 unsigned long st_blocks; /* number of blocks allocated */
60#ifdef CONFIG_YAFFS_WINCE
61 /* Special 64-bit times for WinCE */
62 unsigned long yst_wince_atime[2];
63 unsigned long yst_wince_mtime[2];
64 unsigned long yst_wince_ctime[2];
65#else
66 unsigned long yst_atime; /* time of last access */
67 unsigned long yst_mtime; /* time of last modification */
68 unsigned long yst_ctime; /* time of last change */
William Juulc051bbe2007-11-15 11:13:05 +010069#endif
Charles Manning3796e1f2012-05-09 16:55:17 +000070};
William Juulc051bbe2007-11-15 11:13:05 +010071
William Juulc051bbe2007-11-15 11:13:05 +010072
Charles Manning3796e1f2012-05-09 16:55:17 +000073struct yaffs_utimbuf {
74 unsigned long actime;
75 unsigned long modtime;
76};
William Juulc051bbe2007-11-15 11:13:05 +010077
William Juulc051bbe2007-11-15 11:13:05 +010078
Charles Manning3796e1f2012-05-09 16:55:17 +000079int yaffs_open(const YCHAR *path, int oflag, int mode) ;
William Juulc051bbe2007-11-15 11:13:05 +010080
Charles Manning3796e1f2012-05-09 16:55:17 +000081int yaffs_close(int fd) ;
82int yaffs_fsync(int fd) ;
83int yaffs_fdatasync(int fd) ;
84int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
William Juulc051bbe2007-11-15 11:13:05 +010085
Charles Manning3796e1f2012-05-09 16:55:17 +000086int yaffs_access(const YCHAR *path, int amode);
William Juulc051bbe2007-11-15 11:13:05 +010087
Charles Manning3796e1f2012-05-09 16:55:17 +000088int yaffs_dup(int fd);
William Juulc051bbe2007-11-15 11:13:05 +010089
Charles Manning3796e1f2012-05-09 16:55:17 +000090int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
91int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
William Juulc051bbe2007-11-15 11:13:05 +010092
Charles Manning3796e1f2012-05-09 16:55:17 +000093int yaffs_pread(int fd, void *buf, unsigned int nbyte, loff_t offset);
94int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, loff_t offset);
William Juulc051bbe2007-11-15 11:13:05 +010095
Charles Manning3796e1f2012-05-09 16:55:17 +000096loff_t yaffs_lseek(int fd, loff_t offset, int whence) ;
William Juulc051bbe2007-11-15 11:13:05 +010097
Charles Manning3796e1f2012-05-09 16:55:17 +000098int yaffs_truncate(const YCHAR *path, loff_t new_size);
99int yaffs_ftruncate(int fd, loff_t new_size);
William Juulc051bbe2007-11-15 11:13:05 +0100100
Charles Manning3796e1f2012-05-09 16:55:17 +0000101int yaffs_unlink(const YCHAR *path) ;
102int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
William Juulc051bbe2007-11-15 11:13:05 +0100103
Charles Manning3796e1f2012-05-09 16:55:17 +0000104int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
105int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
106int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
William Juulc051bbe2007-11-15 11:13:05 +0100107
Charles Manning3796e1f2012-05-09 16:55:17 +0000108int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf);
109int yaffs_futime(int fd, const struct yaffs_utimbuf *buf);
William Juulc051bbe2007-11-15 11:13:05 +0100110
William Juulc051bbe2007-11-15 11:13:05 +0100111
Charles Manning3796e1f2012-05-09 16:55:17 +0000112int yaffs_setxattr(const char *path, const char *name,
113 const void *data, int size, int flags);
114int yaffs_lsetxattr(const char *path, const char *name,
115 const void *data, int size, int flags);
116int yaffs_fsetxattr(int fd, const char *name,
117 const void *data, int size, int flags);
William Juulc051bbe2007-11-15 11:13:05 +0100118
Charles Manning3796e1f2012-05-09 16:55:17 +0000119int yaffs_getxattr(const char *path, const char *name,
120 void *data, int size);
121int yaffs_lgetxattr(const char *path, const char *name,
122 void *data, int size);
123int yaffs_fgetxattr(int fd, const char *name,
124 void *data, int size);
William Juulc051bbe2007-11-15 11:13:05 +0100125
Charles Manning3796e1f2012-05-09 16:55:17 +0000126int yaffs_removexattr(const char *path, const char *name);
127int yaffs_lremovexattr(const char *path, const char *name);
128int yaffs_fremovexattr(int fd, const char *name);
William Juulc051bbe2007-11-15 11:13:05 +0100129
Charles Manning3796e1f2012-05-09 16:55:17 +0000130int yaffs_listxattr(const char *path, char *list, int size);
131int yaffs_llistxattr(const char *path, char *list, int size);
132int yaffs_flistxattr(int fd, char *list, int size);
William Juulc051bbe2007-11-15 11:13:05 +0100133
William Juulc051bbe2007-11-15 11:13:05 +0100134
Charles Manning3796e1f2012-05-09 16:55:17 +0000135#ifdef CONFIG_YAFFS_WINCE
William Juulc051bbe2007-11-15 11:13:05 +0100136
Charles Manning3796e1f2012-05-09 16:55:17 +0000137int yaffs_set_wince_times(int fd,
138 const unsigned *wctime,
139 const unsigned *watime,
140 const unsigned *wmtime);
141int yaffs_get_wince_times(int fd,
142 unsigned *wctime,
143 unsigned *watime,
144 unsigned *wmtime);
William Juulc051bbe2007-11-15 11:13:05 +0100145
William Juulc051bbe2007-11-15 11:13:05 +0100146#endif
147
Charles Manning3796e1f2012-05-09 16:55:17 +0000148int yaffs_chmod(const YCHAR *path, mode_t mode);
149int yaffs_fchmod(int fd, mode_t mode);
William Juulc051bbe2007-11-15 11:13:05 +0100150
Charles Manning3796e1f2012-05-09 16:55:17 +0000151int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
152int yaffs_rmdir(const YCHAR *path) ;
William Juulc051bbe2007-11-15 11:13:05 +0100153
Charles Manning3796e1f2012-05-09 16:55:17 +0000154yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
155struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
156void yaffs_rewinddir(yaffs_DIR *dirp) ;
157int yaffs_closedir(yaffs_DIR *dirp) ;
William Juulc051bbe2007-11-15 11:13:05 +0100158
Charles Manning3796e1f2012-05-09 16:55:17 +0000159int yaffs_mount(const YCHAR *path) ;
160int yaffs_mount2(const YCHAR *path, int read_only);
161int yaffs_mount_common(const YCHAR *path, int read_only, int skip_checkpt);
William Juulc051bbe2007-11-15 11:13:05 +0100162
Charles Manning3796e1f2012-05-09 16:55:17 +0000163int yaffs_unmount(const YCHAR *path) ;
164int yaffs_unmount2(const YCHAR *path, int force);
165int yaffs_remount(const YCHAR *path, int force, int read_only);
William Juulc051bbe2007-11-15 11:13:05 +0100166
William Juulc051bbe2007-11-15 11:13:05 +0100167
Charles Manning3796e1f2012-05-09 16:55:17 +0000168int yaffs_sync(const YCHAR *path) ;
William Juulc051bbe2007-11-15 11:13:05 +0100169
Charles Manning3796e1f2012-05-09 16:55:17 +0000170int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
171int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz);
William Juulc051bbe2007-11-15 11:13:05 +0100172
Charles Manning3796e1f2012-05-09 16:55:17 +0000173int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath);
174int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
William Juulc051bbe2007-11-15 11:13:05 +0100175
Charles Manning3796e1f2012-05-09 16:55:17 +0000176loff_t yaffs_freespace(const YCHAR *path);
177loff_t yaffs_totalspace(const YCHAR *path);
William Juulc051bbe2007-11-15 11:13:05 +0100178
Charles Manning3796e1f2012-05-09 16:55:17 +0000179int yaffs_inodecount(const YCHAR *path);
William Juulc051bbe2007-11-15 11:13:05 +0100180
Charles Manning3796e1f2012-05-09 16:55:17 +0000181int yaffs_n_handles(const YCHAR *path);
William Juulc051bbe2007-11-15 11:13:05 +0100182
Charles Manning3796e1f2012-05-09 16:55:17 +0000183#define YAFFS_SHARE_READ 1
184#define YAFFS_SHARE_WRITE 2
185int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int shareMode);
William Juulc051bbe2007-11-15 11:13:05 +0100186
Charles Manning3796e1f2012-05-09 16:55:17 +0000187struct yaffs_dev;
188void yaffs_add_device(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100189
Charles Manning3796e1f2012-05-09 16:55:17 +0000190int yaffs_start_up(void);
191int yaffsfs_GetLastError(void);
William Juulc051bbe2007-11-15 11:13:05 +0100192
Charles Manning3796e1f2012-05-09 16:55:17 +0000193/* Functions to iterate through devices. NB Use with extreme care! */
194void yaffs_dev_rewind(void);
195struct yaffs_dev *yaffs_next_dev(void);
William Juulc051bbe2007-11-15 11:13:05 +0100196
Charles Manning3796e1f2012-05-09 16:55:17 +0000197/* Function to get the last error */
198int yaffs_get_error(void);
199const char *yaffs_error_to_str(int err);
William Juulc051bbe2007-11-15 11:13:05 +0100200
Charles Manning3796e1f2012-05-09 16:55:17 +0000201/* Function only for debugging */
202void *yaffs_getdev(const YCHAR *path);
203int yaffs_dump_dev(const YCHAR *path);
204int yaffs_set_error(int error);
William Juulc051bbe2007-11-15 11:13:05 +0100205
Charles Manning3796e1f2012-05-09 16:55:17 +0000206/* Trace control functions */
207unsigned yaffs_set_trace(unsigned tm);
208unsigned yaffs_get_trace(void);
William Juulc051bbe2007-11-15 11:13:05 +0100209#endif