blob: e14f41c63ee5b529c7f76aa467202f23f925b3cf [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
William Juulc051bbe2007-11-15 11:13:05 +010021#ifndef __YAFFSFS_H__
22#define __YAFFSFS_H__
23
24#include "yaffscfg.h"
25#include "yportenv.h"
26
William Juulc051bbe2007-11-15 11:13:05 +010027#ifndef NAME_MAX
28#define NAME_MAX 256
29#endif
30
Charles Manning3796e1f2012-05-09 16:55:17 +000031#define YAFFS_MAX_FILE_SIZE (0x800000000LL - 1)
William Juulc051bbe2007-11-15 11:13:05 +010032
Charles Manning3796e1f2012-05-09 16:55:17 +000033struct 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 Juulc051bbe2007-11-15 11:13:05 +010041
Charles Manning3796e1f2012-05-09 16:55:17 +000042typedef struct opaque_structure yaffs_DIR;
William Juulc051bbe2007-11-15 11:13:05 +010043
Charles Manning3796e1f2012-05-09 16:55:17 +000044struct 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 Juulc051bbe2007-11-15 11:13:05 +010064#endif
Charles Manning3796e1f2012-05-09 16:55:17 +000065};
William Juulc051bbe2007-11-15 11:13:05 +010066
Charles Manning3796e1f2012-05-09 16:55:17 +000067struct yaffs_utimbuf {
68 unsigned long actime;
69 unsigned long modtime;
70};
William Juulc051bbe2007-11-15 11:13:05 +010071
Charles Manning3796e1f2012-05-09 16:55:17 +000072int yaffs_open(const YCHAR *path, int oflag, int mode) ;
William Juulc051bbe2007-11-15 11:13:05 +010073
Charles Manning3796e1f2012-05-09 16:55:17 +000074int yaffs_close(int fd) ;
75int yaffs_fsync(int fd) ;
76int yaffs_fdatasync(int fd) ;
77int yaffs_flush(int fd) ; /* same as yaffs_fsync() */
William Juulc051bbe2007-11-15 11:13:05 +010078
Charles Manning3796e1f2012-05-09 16:55:17 +000079int yaffs_access(const YCHAR *path, int amode);
William Juulc051bbe2007-11-15 11:13:05 +010080
Charles Manning3796e1f2012-05-09 16:55:17 +000081int yaffs_dup(int fd);
William Juulc051bbe2007-11-15 11:13:05 +010082
Charles Manning3796e1f2012-05-09 16:55:17 +000083int yaffs_read(int fd, void *buf, unsigned int nbyte) ;
84int yaffs_write(int fd, const void *buf, unsigned int nbyte) ;
William Juulc051bbe2007-11-15 11:13:05 +010085
Charles Manning3796e1f2012-05-09 16:55:17 +000086int yaffs_pread(int fd, void *buf, unsigned int nbyte, loff_t offset);
87int yaffs_pwrite(int fd, const void *buf, unsigned int nbyte, loff_t offset);
William Juulc051bbe2007-11-15 11:13:05 +010088
Charles Manning3796e1f2012-05-09 16:55:17 +000089loff_t yaffs_lseek(int fd, loff_t offset, int whence) ;
William Juulc051bbe2007-11-15 11:13:05 +010090
Charles Manning3796e1f2012-05-09 16:55:17 +000091int yaffs_truncate(const YCHAR *path, loff_t new_size);
92int yaffs_ftruncate(int fd, loff_t new_size);
William Juulc051bbe2007-11-15 11:13:05 +010093
Charles Manning3796e1f2012-05-09 16:55:17 +000094int yaffs_unlink(const YCHAR *path) ;
95int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) ;
William Juulc051bbe2007-11-15 11:13:05 +010096
Charles Manning3796e1f2012-05-09 16:55:17 +000097int yaffs_stat(const YCHAR *path, struct yaffs_stat *buf) ;
98int yaffs_lstat(const YCHAR *path, struct yaffs_stat *buf) ;
99int yaffs_fstat(int fd, struct yaffs_stat *buf) ;
William Juulc051bbe2007-11-15 11:13:05 +0100100
Charles Manning3796e1f2012-05-09 16:55:17 +0000101int yaffs_utime(const YCHAR *path, const struct yaffs_utimbuf *buf);
102int yaffs_futime(int fd, const struct yaffs_utimbuf *buf);
William Juulc051bbe2007-11-15 11:13:05 +0100103
Charles Manning3796e1f2012-05-09 16:55:17 +0000104int yaffs_setxattr(const char *path, const char *name,
105 const void *data, int size, int flags);
106int yaffs_lsetxattr(const char *path, const char *name,
107 const void *data, int size, int flags);
108int yaffs_fsetxattr(int fd, const char *name,
109 const void *data, int size, int flags);
William Juulc051bbe2007-11-15 11:13:05 +0100110
Charles Manning3796e1f2012-05-09 16:55:17 +0000111int yaffs_getxattr(const char *path, const char *name,
112 void *data, int size);
113int yaffs_lgetxattr(const char *path, const char *name,
114 void *data, int size);
115int yaffs_fgetxattr(int fd, const char *name,
116 void *data, int size);
William Juulc051bbe2007-11-15 11:13:05 +0100117
Charles Manning3796e1f2012-05-09 16:55:17 +0000118int yaffs_removexattr(const char *path, const char *name);
119int yaffs_lremovexattr(const char *path, const char *name);
120int yaffs_fremovexattr(int fd, const char *name);
William Juulc051bbe2007-11-15 11:13:05 +0100121
Charles Manning3796e1f2012-05-09 16:55:17 +0000122int yaffs_listxattr(const char *path, char *list, int size);
123int yaffs_llistxattr(const char *path, char *list, int size);
124int yaffs_flistxattr(int fd, char *list, int size);
William Juulc051bbe2007-11-15 11:13:05 +0100125
Charles Manning3796e1f2012-05-09 16:55:17 +0000126#ifdef CONFIG_YAFFS_WINCE
William Juulc051bbe2007-11-15 11:13:05 +0100127
Charles Manning3796e1f2012-05-09 16:55:17 +0000128int yaffs_set_wince_times(int fd,
129 const unsigned *wctime,
130 const unsigned *watime,
131 const unsigned *wmtime);
132int yaffs_get_wince_times(int fd,
133 unsigned *wctime,
134 unsigned *watime,
135 unsigned *wmtime);
William Juulc051bbe2007-11-15 11:13:05 +0100136
William Juulc051bbe2007-11-15 11:13:05 +0100137#endif
138
Charles Manning3796e1f2012-05-09 16:55:17 +0000139int yaffs_chmod(const YCHAR *path, mode_t mode);
140int yaffs_fchmod(int fd, mode_t mode);
William Juulc051bbe2007-11-15 11:13:05 +0100141
Charles Manning3796e1f2012-05-09 16:55:17 +0000142int yaffs_mkdir(const YCHAR *path, mode_t mode) ;
143int yaffs_rmdir(const YCHAR *path) ;
William Juulc051bbe2007-11-15 11:13:05 +0100144
Charles Manning3796e1f2012-05-09 16:55:17 +0000145yaffs_DIR *yaffs_opendir(const YCHAR *dirname) ;
146struct yaffs_dirent *yaffs_readdir(yaffs_DIR *dirp) ;
147void yaffs_rewinddir(yaffs_DIR *dirp) ;
148int yaffs_closedir(yaffs_DIR *dirp) ;
William Juulc051bbe2007-11-15 11:13:05 +0100149
Charles Manning3796e1f2012-05-09 16:55:17 +0000150int yaffs_mount(const YCHAR *path) ;
151int yaffs_mount2(const YCHAR *path, int read_only);
152int yaffs_mount_common(const YCHAR *path, int read_only, int skip_checkpt);
William Juulc051bbe2007-11-15 11:13:05 +0100153
Charles Manning3796e1f2012-05-09 16:55:17 +0000154int yaffs_unmount(const YCHAR *path) ;
155int yaffs_unmount2(const YCHAR *path, int force);
156int yaffs_remount(const YCHAR *path, int force, int read_only);
William Juulc051bbe2007-11-15 11:13:05 +0100157
Charles Manning3796e1f2012-05-09 16:55:17 +0000158int yaffs_sync(const YCHAR *path) ;
William Juulc051bbe2007-11-15 11:13:05 +0100159
Charles Manning3796e1f2012-05-09 16:55:17 +0000160int yaffs_symlink(const YCHAR *oldpath, const YCHAR *newpath);
161int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz);
William Juulc051bbe2007-11-15 11:13:05 +0100162
Charles Manning3796e1f2012-05-09 16:55:17 +0000163int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath);
164int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev);
William Juulc051bbe2007-11-15 11:13:05 +0100165
Charles Manning3796e1f2012-05-09 16:55:17 +0000166loff_t yaffs_freespace(const YCHAR *path);
167loff_t yaffs_totalspace(const YCHAR *path);
William Juulc051bbe2007-11-15 11:13:05 +0100168
Charles Manning3796e1f2012-05-09 16:55:17 +0000169int yaffs_inodecount(const YCHAR *path);
William Juulc051bbe2007-11-15 11:13:05 +0100170
Charles Manning3796e1f2012-05-09 16:55:17 +0000171int yaffs_n_handles(const YCHAR *path);
William Juulc051bbe2007-11-15 11:13:05 +0100172
Charles Manning3796e1f2012-05-09 16:55:17 +0000173#define YAFFS_SHARE_READ 1
174#define YAFFS_SHARE_WRITE 2
175int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int shareMode);
William Juulc051bbe2007-11-15 11:13:05 +0100176
Charles Manning3796e1f2012-05-09 16:55:17 +0000177struct yaffs_dev;
178void yaffs_add_device(struct yaffs_dev *dev);
William Juulc051bbe2007-11-15 11:13:05 +0100179
Charles Manning3796e1f2012-05-09 16:55:17 +0000180int yaffs_start_up(void);
181int yaffsfs_GetLastError(void);
William Juulc051bbe2007-11-15 11:13:05 +0100182
Charles Manning3796e1f2012-05-09 16:55:17 +0000183/* Functions to iterate through devices. NB Use with extreme care! */
184void yaffs_dev_rewind(void);
185struct yaffs_dev *yaffs_next_dev(void);
William Juulc051bbe2007-11-15 11:13:05 +0100186
Charles Manning3796e1f2012-05-09 16:55:17 +0000187/* Function to get the last error */
188int yaffs_get_error(void);
189const char *yaffs_error_to_str(int err);
William Juulc051bbe2007-11-15 11:13:05 +0100190
Charles Manning3796e1f2012-05-09 16:55:17 +0000191/* Function only for debugging */
192void *yaffs_getdev(const YCHAR *path);
193int yaffs_dump_dev(const YCHAR *path);
194int yaffs_set_error(int error);
William Juulc051bbe2007-11-15 11:13:05 +0100195
Charles Manning3796e1f2012-05-09 16:55:17 +0000196/* Trace control functions */
197unsigned yaffs_set_trace(unsigned tm);
198unsigned yaffs_get_trace(void);
William Juulc051bbe2007-11-15 11:13:05 +0100199#endif