RTEMS 6.1-rc6
Loading...
Searching...
No Matches
os-rtems.h
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright © 2002-2003 Free Software Foundation, Inc.
5 * Copyright © 2013 embedded brains GmbH & Co. KG
6 *
7 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
8 *
9 * Port to the RTEMS by embedded brains GmbH & Co. KG
10 *
11 * For licensing information, see the file 'LICENCE' in this directory.
12 *
13 * $Id: os-ecos.h,v 1.24 2005/02/09 09:23:55 pavlov Exp $
14 *
15 */
16
17#ifndef __JFFS2_OS_RTEMS_H__
18#define __JFFS2_OS_RTEMS_H__
19
20#include <asm/atomic.h>
21#include <asm/bug.h>
22#include <linux/compiler.h>
23#include <linux/list.h>
24#include <linux/pagemap.h>
25#include <linux/stat.h>
26#include <linux/types.h>
27#include <sys/uio.h>
28#include <dirent.h>
29#include <errno.h>
30#include <fcntl.h>
31#include <string.h>
32#include <time.h>
33
34#include <rtems/jffs2.h>
35#include <rtems/thread.h>
36
37#define CONFIG_JFFS2_RTIME
38
39#define CONFIG_JFFS2_ZLIB
40
41struct _inode;
42struct super_block;
43
44static inline unsigned int full_name_hash(const void *salt, const unsigned char * name, size_t len) {
45
46 uint32_t hash = 0;
47 (void)salt;
48 while (len--) {
49 hash = (hash << 4) | (hash >> 28);
50 hash ^= *(name++);
51 }
52 return hash;
53}
54
55#define container_of(a, b, c) RTEMS_CONTAINER_OF(a, b, c)
56
57#define JFFS2_INODE_INFO(i) (&(i)->jffs2_i)
58#define OFNI_EDONI_2SFFJ(f) RTEMS_CONTAINER_OF(f, struct _inode, jffs2_i)
59
60#define ITIME(sec) (sec)
61#define I_SEC(tv) (tv)
62
63#define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
64#define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
65#define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
66#define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
67#define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime)
68#define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime)
69#define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime)
70
71#define get_seconds() time(NULL)
72
73struct _inode {
74 cyg_uint32 i_ino;
75
76 int i_count;
77 mode_t i_mode;
78 nlink_t i_nlink; // Could we dispense with this?
79 uid_t i_uid;
80 gid_t i_gid;
81 time_t i_atime;
82 time_t i_mtime;
83 time_t i_ctime;
84// union {
85 unsigned short i_rdev; // For devices only
86 struct _inode * i_parent; // For directories only
87 off_t i_size; // For files only
88// };
89 struct super_block * i_sb;
90 struct jffs2_full_dirent * i_fd;
91
92 struct jffs2_inode_info jffs2_i;
93
94 struct _inode * i_cache_prev; // We need doubly-linked?
95 struct _inode * i_cache_next;
96};
97
98#define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb)
99#define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) )
100
102 struct jffs2_sb_info jffs2_sb;
103 /*
104 * If granular locking is ever enabled for JFFS2, the inode cache
105 * (s_root) needs to be protected due to NAND delayed writes.
106 */
107 struct _inode * s_root;
108 rtems_jffs2_flash_control *s_flash_control;
109 rtems_jffs2_compressor_control *s_compressor_control;
110 bool s_is_readonly;
111 unsigned char s_gc_buffer[PAGE_CACHE_SIZE]; // Avoids malloc when user may be under memory pressure
112 rtems_recursive_mutex s_mutex;
113 char s_name_buf[JFFS2_MAX_NAME_LEN];
114 uint32_t s_flags;
115};
116
117#define sleep_on_spinunlock(wq, sl) spin_unlock(sl)
118#define EBADFD 32767
119
120static inline bool jffs2_is_readonly(struct jffs2_sb_info *c)
121{
122 struct super_block *sb = OFNI_BS_2SFFJ(c);
123
124 return sb->s_is_readonly;
125}
126
127static inline void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
128{
129 const struct super_block *sb = OFNI_BS_2SFFJ(c);
130 rtems_jffs2_flash_control *fc = sb->s_flash_control;
131
132 if (fc->trigger_garbage_collection != NULL) {
134 }
135}
136
137/* fs-rtems.c */
138struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw_inode *ri);
139struct _inode *jffs2_iget(struct super_block *sb, cyg_uint32 ino);
140void jffs2_iput(struct _inode * i);
141void jffs2_gc_release_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f);
142struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, int inum, int nlink);
143
144/* Avoid polluting RTEMS namespace with names not starting in jffs2_ */
145#define os_to_jffs2_mode(x) jffs2_from_os_mode(x)
146static inline uint32_t jffs2_from_os_mode(uint32_t osmode)
147{
148 return osmode & (S_IFMT | S_IRWXU | S_IRWXG | S_IRWXO);
149}
150
151static inline uint32_t jffs2_to_os_mode (uint32_t jmode)
152{
153 return jmode & (S_IFMT | S_IRWXU | S_IRWXG | S_IRWXO);
154}
155
156
157/* flashio.c */
158int jffs2_flash_read(struct jffs2_sb_info *c, loff_t read_buffer_offset,
159 size_t size, size_t * return_size, unsigned char * write_buffer);
160int jffs2_flash_write(struct jffs2_sb_info *c, loff_t write_buffer_offset,
161 size_t size, size_t * return_size, const unsigned char * read_buffer);
162int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
163 unsigned long count, loff_t to, size_t *retlen);
164int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
165int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf);
166int jffs2_flash_direct_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, u_char *buf);
167
168// dir-rtems.c
169struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, size_t namelen);
170int jffs2_create(struct _inode *dir_i, const char *d_name, size_t d_namelen, int mode);
171int jffs2_mknod(struct _inode *dir_i, const unsigned char *d_name, size_t d_namelen, int mode, const unsigned char *data, size_t datalen);
172int jffs2_link (struct _inode *old_d_inode, struct _inode *dir_i, const unsigned char *d_name, size_t d_namelen);
173int jffs2_unlink(struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name, size_t d_namelen);
174int jffs2_rmdir (struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name, size_t d_namelen);
175int jffs2_rename (struct _inode *old_dir_i, struct _inode *d_inode, const unsigned char *old_d_name, size_t old_d_namelen,
176 struct _inode *new_dir_i, const unsigned char *new_d_name, size_t new_d_namelen);
177
178/* erase.c */
179static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c)
180{ }
181
182#define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) )
183#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
184
185#define jffs2_can_mark_obsolete(c) (1)
186#define jffs2_is_writebuffered(c) (0)
187#define jffs2_cleanmarker_oob(c) (0)
188#define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
189
190#define jffs2_flush_wbuf_pad(c) (c=c)
191#define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; })
192#define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0)
193#define jffs2_write_nand_badblock(c,jeb,p) (0)
194#define jffs2_flash_setup(c) (0)
195#define jffs2_nand_flash_cleanup(c) do {} while(0)
196#define jffs2_wbuf_dirty(c) (0)
197#define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
198#define jffs2_wbuf_timeout NULL
199#define jffs2_wbuf_process NULL
200#define jffs2_nor_ecc(c) (0)
201#else /* CONFIG_JFFS2_FS_WRITEBUFFER */
202/* dirty_writeback_interval is in centiseconds, 500cs == 5s */
203#define dirty_writeback_interval 500
204#define MTD_BIT_WRITEABLE 0x800
205#define jffs2_is_writebuffered(c) (c->wbuf != NULL)
206
207#define jffs2_can_mark_obsolete(c) (OFNI_BS_2SFFJ(c)->s_flash_control->block_is_bad == NULL)
208
209#define jffs2_cleanmarker_oob(c) (OFNI_BS_2SFFJ(c)->s_flash_control->block_is_bad != NULL)
210
211#define jffs2_wbuf_dirty(c) (!!(c)->wbuf_len)
212
213/* wbuf.c */
214int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino);
215int jffs2_check_oob_empty(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,int mode);
216int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
217int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
218int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, uint32_t bad_offset);
219void jffs2_wbuf_timeout(unsigned long data);
220void jffs2_wbuf_process(void *data);
221int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino);
222int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
223int jffs2_nand_flash_setup(struct jffs2_sb_info *c);
224void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c);
225int jffs2_flash_block_is_bad(struct jffs2_sb_info * c,
226 cyg_uint32 block_offset,
227 bool *bad);
228int jffs2_flash_block_mark_bad(struct jffs2_sb_info * c,
229 cyg_uint32 block_offset);
230int jffs2_flash_oob_write(struct jffs2_sb_info * c,
231 cyg_uint32 block_offset,
232 uint8_t *oobbuf,
233 uint32_t ooblen);
234int jffs2_flash_oob_read(struct jffs2_sb_info * c,
235 cyg_uint32 block_offset,
236 uint8_t *oobbuf,
237 uint32_t ooblen);
238int jffs2_flash_get_oob_size(struct jffs2_sb_info * c);
239
240int jffs2_dataflash_setup(struct jffs2_sb_info *c);
241void jffs2_dataflash_cleanup(struct jffs2_sb_info *c);
242int jffs2_ubivol_setup(struct jffs2_sb_info *c);
243void jffs2_ubivol_cleanup(struct jffs2_sb_info *c);
244
245int jffs2_nor_wbuf_flash_setup(struct jffs2_sb_info *c);
246void jffs2_nor_wbuf_flash_cleanup(struct jffs2_sb_info *c);
247void jffs2_dirty_trigger(struct jffs2_sb_info *c);
248
249#endif /* CONFIG_JFFS2_FS_WRITEBUFFER */
250
251#ifndef BUG_ON
252#define BUG_ON(x) do { if (unlikely(x)) BUG(); } while(0)
253#endif
254
255#define __init
256
257#endif /* __JFFS2_OS_RTEMS_H__ */
Definition: os-rtems.h:73
Definition: nodelist.h:278
Definition: nodelist.h:252
Definition: jffs2_fs_i.h:20
Definition: jffs2.h:133
Definition: jffs2_fs_sb.h:51
JFFS2 compressor control.
Definition: jffs2.h:506
JFFS2 flash device control.
Definition: jffs2.h:355
rtems_jffs2_trigger_garbage_collection trigger_garbage_collection
Trigger garbage collection operation.
Definition: jffs2.h:439
Definition: os-rtems.h:101
This header file provides the API of Self-Contained Objects.