]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/fs/jffs2/v2_0/src/jffs2port.h
RedBoot TX53 Release 2012-02-15
[karo-tx-redboot.git] / packages / fs / jffs2 / v2_0 / src / jffs2port.h
1 #ifndef __LINUX_JFFS2PORT_H__
2 #define __LINUX_JFFS2PORT_H__
3
4 /* $Id$ */
5
6 #include <pkgconf/system.h>
7 #include <pkgconf/hal.h>
8 //#include <pkgconf/kernel.h>
9 #include <pkgconf/io_fileio.h>
10 //#include <pkgconf/fs_ram.h>
11
12 #include <cyg/infra/cyg_trac.h>        // tracing macros
13 #include <cyg/infra/cyg_ass.h>         // assertion macros
14
15 #include <unistd.h>
16 #include <sys/types.h>
17 #include <fcntl.h>
18 #include <sys/stat.h>
19 #include <errno.h>
20 #include <dirent.h>
21
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <cyg/fileio/fileio.h>
26
27 #include <cyg/hal/drv_api.h>
28 #include <cyg/infra/diag.h>
29
30 #include <cyg/io/flash.h>
31
32 #include <pkgconf/fs_jffs2.h>
33 #include <linux/types.h>
34 #include <linux/list.h>
35 #include <asm/bug.h>
36 // Linux types
37 #define printf diag_printf
38
39 // Structures used by VFS
40
41 typedef unsigned short kdev_t;
42
43 struct qstr {
44         const unsigned char * name;
45         unsigned int len;
46         unsigned int hash;
47 };
48
49 #define DNAME_INLINE_LEN 16
50
51 struct dentry {
52         //      atomic_t d_count;
53         unsigned int d_flags;
54         struct inode  * d_inode;        /* Where the name belongs to - NULL is negative */
55         struct dentry * d_parent;       /* parent directory */
56         struct list_head d_hash;        /* lookup hash list */
57         struct list_head d_child;       /* child of parent list */
58         struct list_head d_subdirs;     /* our children */
59         struct list_head d_alias;       /* inode alias list */
60         struct qstr d_name;
61         struct dentry_operations  *d_op;
62         struct super_block * d_sb;      /* The root of the dentry tree */
63         unsigned char d_iname[DNAME_INLINE_LEN]; /* small names */
64 };
65
66 struct file {
67         struct dentry           *f_dentry;
68         unsigned int            f_flags;
69         mode_t                      f_mode;
70         loff_t                      f_pos;
71         unsigned long           f_reada, f_ramax, f_raend, f_ralen, f_rawin;
72 };
73
74 #define ATTR_MODE       1
75 #define ATTR_UID        2
76 #define ATTR_GID        4
77 #define ATTR_SIZE       8
78 #define ATTR_ATIME      16
79 #define ATTR_MTIME      32
80 #define ATTR_CTIME      64
81 #define ATTR_ATIME_SET  128
82 #define ATTR_MTIME_SET  256
83 #define ATTR_FORCE      512     /* Not a change, but a change it */
84 #define ATTR_ATTR_FLAG  1024
85
86 typedef unsigned short umode_t;
87
88 struct iattr {
89         unsigned int ia_valid;
90         umode_t         ia_mode;
91         uid_t           ia_uid;
92         gid_t           ia_gid;
93         loff_t          ia_size;
94         time_t          ia_atime;
95         time_t          ia_mtime;
96         time_t          ia_ctime;
97 };
98
99 struct page {
100         unsigned long index;
101         void *virtual;
102 };
103
104 struct nameidata {
105         struct dentry *dentry;
106         struct qstr last;
107         unsigned int flags;
108         int last_type;
109 };
110
111 struct file_operations {
112         //struct module *owner;
113         //loff_t (*llseek) (struct file *, loff_t, int);
114         ssize_t (*read) (struct file *, char *, size_t, loff_t *);
115         //ssize_t (*write) (struct file *, const char *, size_t, loff_t *);
116         int (*readdir) (struct file *, char *, int);
117         //unsigned int (*poll) (struct file *, struct poll_table_struct *);
118         int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);
119         //int (*mmap) (struct file *, struct vm_area_struct *);
120         //int (*open) (struct inode *, struct file *);
121         //int (*flush) (struct file *);
122         //int (*release) (struct inode *, struct file *);
123         int (*fsync) (struct file *, struct dentry *, int datasync);
124         //int (*fasync) (int, struct file *, int);
125         //int (*lock) (struct file *, int, struct file_lock *);
126         //ssize_t (*readv) (struct file *, const struct iovec *, unsigned long, loff_t *);
127         //ssize_t (*writev) (struct file *, const struct iovec *, unsigned long, loff_t *);
128 };
129
130 struct inode_operations {
131         int (*create) (struct inode *,struct dentry *,int);
132         struct dentry * (*lookup) (struct inode *,struct dentry *);
133         int (*link) (struct dentry *,struct inode *,struct dentry *);
134         int (*unlink) (struct inode *,struct dentry *);
135         int (*symlink) (struct inode *,struct dentry *,const char *);
136         int (*mkdir) (struct inode *,struct dentry *,int);
137         int (*rmdir) (struct inode *,struct dentry *);
138         int (*mknod) (struct inode *,struct dentry *,int,int);
139         int (*rename) (struct inode *, struct dentry *,
140                         struct inode *, struct dentry *);
141         int (*readlink) (struct dentry *, char *,int);
142         int (*follow_link) (struct dentry *, struct nameidata *);
143         //void (*truncate) (struct inode *);
144         int (*permission) (struct inode *, int);
145         //int (*revalidate) (struct dentry *);
146         int (*setattr) (struct dentry *, struct iattr *);
147         //int (*getattr) (struct dentry *, struct iattr *);
148 };
149
150
151 struct iovec {
152         void *iov_base;
153         ssize_t iov_len; 
154 };
155
156
157 // called by JFFS2
158
159 #define to_kdev_t(rdev) (rdev)
160 #define MAJOR(rdev) (rdev)>>8
161 #define MINOR(rdev) (rdev)
162
163 #define page_address(page)      ((page)->virtual)
164
165 static __inline__ void * kmap(struct page * page) {
166         return page_address(page);
167 }
168
169 #define kunmap(page) do { } while (0)
170
171 //struct page * read_cache_page(cyg_uint32 start, void * f, struct inode * i);
172 struct page *read_cache_page(unsigned long index, int (*filler)(void *,struct page*), void *data);
173 void page_cache_release(struct page * pg);
174
175 struct inode * new_inode(struct super_block *sb);
176 struct inode * iget(struct super_block *sb, cyg_uint32 ino);
177 void iput(struct inode * i);
178 void make_bad_inode(struct inode * inode);
179 int is_bad_inode(struct inode * inode);
180
181 #define insert_inode_hash(inode) do { } while (0)
182
183 #define d_alloc_root(root_inode) root_inode
184
185 #define flush_dcache_page(page) do { } while (0)
186
187 struct jffs2_sb_info;
188 struct jffs2_eraseblock;
189
190 cyg_bool jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset, const size_t size, size_t * return_size, char * write_buffer);
191 cyg_bool jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset, const size_t size, size_t * return_size, char * read_buffer);
192 int jffs2_flash_writev(struct jffs2_sb_info *c, const struct iovec *vecs, unsigned long count, loff_t to, size_t *retlen);
193 cyg_bool jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
194
195
196 // calls to JFFS2
197
198 // dir-ecos.c
199 struct inode *jffs2_lookup(struct inode *dir_i, struct qstr *name);
200 int jffs2_readdir (struct inode *d_inode, unsigned long f_pos, char *nbuf, int nlen);
201 int jffs2_create(struct inode *dir_i, struct qstr *d_name, int mode, struct inode **new_i);
202 int jffs2_mkdir (struct inode *dir_i, struct qstr *d_name, int mode, struct inode **new_i);
203 int jffs2_link (struct inode *old_d_inode, struct inode *dir_i, struct qstr *d_name);
204 int jffs2_unlink(struct inode *dir_i, struct inode *d_inode, struct qstr *d_name);
205 int jffs2_rmdir (struct inode *dir_i, struct inode *d_inode, struct qstr *d_name);
206 int jffs2_rename (struct inode *old_dir_i, struct inode *d_inode, struct qstr *old_d_name,
207                         struct inode *new_dir_i, struct qstr *new_d_name);
208
209 #define init_name_hash()                0
210 static inline unsigned long partial_name_hash(unsigned long c, unsigned long prevhash)
211 {
212         prevhash = (prevhash << 4) | (prevhash >> (8*sizeof(unsigned long)-4));
213         return prevhash ^ c;
214 }
215
216 static inline unsigned long end_name_hash(unsigned long hash)
217 {
218         if (sizeof(hash) > sizeof(unsigned int))
219                 hash += hash >> 4*sizeof(hash);
220         return (unsigned int) hash;
221 }
222
223 static inline unsigned int full_name_hash(const unsigned char * name, unsigned int len) {
224
225         unsigned long hash = init_name_hash();
226         while (len--)
227                 hash = partial_name_hash(*name++, hash);
228         return end_name_hash(hash);
229 }
230
231 #endif /* __LINUX_JFFS2PORT_H__ */
232
233
234
235
236
237
238
239
240
241