source: rtems/cpukit/libfs/src/jffs2/src/os-rtems.h @ 3c96bee

4.11
Last change on this file since 3c96bee was 3c96bee, checked in by Sebastian Huber <sebastian.huber@…>, on Sep 12, 2013 at 1:32:07 PM

JFFS2: Add RTEMS support

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright © 2002-2003 Free Software Foundation, Inc.
5 * Copyright © 2013 embedded brains GmbH <rtems@embedded-brains.de>
6 *
7 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
8 *
9 * Port to the RTEMS by embedded brains GmbH.
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 <dirent.h>
28#include <errno.h>
29#include <fcntl.h>
30#include <string.h>
31#include <time.h>
32
33#include <rtems/jffs2.h>
34
35#define CONFIG_JFFS2_RTIME
36
37#define CONFIG_JFFS2_ZLIB
38
39struct _inode;
40struct super_block;
41
42struct iovec {
43        void *iov_base;
44        ssize_t iov_len; 
45};
46
47static inline unsigned int full_name_hash(const unsigned char * name, size_t len) {
48
49        unsigned hash = 0;
50        while (len--) {
51                hash = (hash << 4) | (hash >> 28);
52                hash ^= *(name++);
53        }
54        return hash;
55}
56
57/* NAND flash not currently supported on RTEMS */
58#define jffs2_can_mark_obsolete(c) (1)
59
60#define JFFS2_INODE_INFO(i) (&(i)->jffs2_i)
61#define OFNI_EDONI_2SFFJ(f)  ((struct _inode *) ( ((char *)f) - ((char *)(&((struct _inode *)NULL)->jffs2_i)) ) )
62
63#define ITIME(sec) (sec)
64#define I_SEC(tv) (tv)
65 
66#define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size)
67#define JFFS2_F_I_MODE(f) (OFNI_EDONI_2SFFJ(f)->i_mode)
68#define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid)
69#define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid)
70#define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime)
71#define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime)
72#define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime)
73
74#define get_seconds() time(NULL)
75
76struct _inode {
77        cyg_uint32              i_ino;
78
79        int                     i_count;
80        mode_t                  i_mode;
81        nlink_t                 i_nlink; // Could we dispense with this?
82        uid_t                   i_uid;
83        gid_t                   i_gid;
84        time_t                  i_atime;
85        time_t                  i_mtime;
86        time_t                  i_ctime;
87//      union {
88                unsigned short  i_rdev; // For devices only
89                struct _inode * i_parent; // For directories only
90                off_t           i_size; // For files only
91//      };
92        struct super_block *    i_sb;
93        struct jffs2_full_dirent * i_fd;
94
95        struct jffs2_inode_info jffs2_i;
96
97        struct _inode *         i_cache_prev; // We need doubly-linked?
98        struct _inode *         i_cache_next;
99};
100
101#define JFFS2_SB_INFO(sb) (&(sb)->jffs2_sb)
102#define OFNI_BS_2SFFJ(c)  ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->jffs2_sb)) ) )
103
104struct super_block {
105        struct jffs2_sb_info    jffs2_sb;
106        struct _inode *         s_root;
107        rtems_jffs2_flash_control       *s_flash_control;
108        rtems_jffs2_compressor_control  *s_compressor_control;
109        bool                    s_is_readonly;
110        unsigned char           s_gc_buffer[PAGE_CACHE_SIZE]; // Avoids malloc when user may be under memory pressure
111        rtems_id                s_mutex;
112        char                    s_name_buf[JFFS2_MAX_NAME_LEN];
113};
114
115#define sleep_on_spinunlock(wq, sl) spin_unlock(sl)
116#define EBADFD 32767
117
118static inline bool jffs2_is_readonly(struct jffs2_sb_info *c)
119{
120        struct super_block *sb = OFNI_BS_2SFFJ(c);
121
122        return sb->s_is_readonly;
123}
124
125static inline void jffs2_garbage_collect_trigger(struct jffs2_sb_info *c)
126{
127       /* We don't have a GC thread in RTEMS (yet) */
128}
129
130/* fs-rtems.c */
131struct _inode *jffs2_new_inode (struct _inode *dir_i, int mode, struct jffs2_raw_inode *ri);
132struct _inode *jffs2_iget(struct super_block *sb, cyg_uint32 ino);
133void jffs2_iput(struct _inode * i);
134void jffs2_gc_release_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f);
135struct jffs2_inode_info *jffs2_gc_fetch_inode(struct jffs2_sb_info *c, int inum, int nlink);
136unsigned char *jffs2_gc_fetch_page(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 
137                                   unsigned long offset, unsigned long *priv);
138void jffs2_gc_release_page(struct jffs2_sb_info *c, unsigned char *pg, unsigned long *priv);
139
140/* Avoid polluting RTEMS namespace with names not starting in jffs2_ */
141#define os_to_jffs2_mode(x) jffs2_from_os_mode(x)
142static inline uint32_t jffs2_from_os_mode(uint32_t osmode)
143{
144  return osmode & (S_IFMT | S_IRWXU | S_IRWXG | S_IRWXO);
145}
146
147static inline uint32_t jffs2_to_os_mode (uint32_t jmode)
148{
149  return jmode & (S_IFMT | S_IRWXU | S_IRWXG | S_IRWXO);
150}
151
152
153/* flashio.c */
154int jffs2_flash_read(struct jffs2_sb_info *c, cyg_uint32 read_buffer_offset,
155                          const size_t size, size_t * return_size, unsigned char * write_buffer);
156int jffs2_flash_write(struct jffs2_sb_info *c, cyg_uint32 write_buffer_offset,
157                           const size_t size, size_t * return_size, unsigned char * read_buffer);
158int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct iovec *vecs,
159                              unsigned long count, loff_t to, size_t *retlen);
160int jffs2_flash_erase(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb);
161
162// dir-rtems.c
163struct _inode *jffs2_lookup(struct _inode *dir_i, const unsigned char *name, size_t namelen);
164int jffs2_create(struct _inode *dir_i, const char *d_name, size_t d_namelen, int mode);
165int jffs2_mknod(struct _inode *dir_i, const unsigned char *d_name, size_t d_namelen, int mode, const unsigned char *data, size_t datalen);
166int jffs2_link (struct _inode *old_d_inode, struct _inode *dir_i, const unsigned char *d_name, size_t d_namelen);
167int jffs2_unlink(struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name, size_t d_namelen);
168int jffs2_rmdir (struct _inode *dir_i, struct _inode *d_inode, const unsigned char *d_name, size_t d_namelen);
169int jffs2_rename (struct _inode *old_dir_i, struct _inode *d_inode, const unsigned char *old_d_name, size_t old_d_namelen,
170                  struct _inode *new_dir_i, const unsigned char *new_d_name, size_t new_d_namelen);
171
172/* erase.c */
173static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c)
174{ }
175
176#ifndef CONFIG_JFFS2_FS_WRITEBUFFER
177#define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) )
178#define jffs2_can_mark_obsolete(c) (1)
179#define jffs2_is_writebuffered(c) (0)
180#define jffs2_cleanmarker_oob(c) (0)
181#define jffs2_write_nand_cleanmarker(c,jeb) (-EIO)
182
183#define jffs2_flush_wbuf_pad(c) (c=c)
184#define jffs2_flush_wbuf_gc(c, i) ({ (void)(c), (void) i, 0; })
185#define jffs2_nand_read_failcnt(c,jeb) do { ; } while(0)
186#define jffs2_write_nand_badblock(c,jeb,p) (0)
187#define jffs2_flash_setup(c) (0)
188#define jffs2_nand_flash_cleanup(c) do {} while(0)
189#define jffs2_wbuf_dirty(c) (0)
190#define jffs2_flash_writev(a,b,c,d,e,f) jffs2_flash_direct_writev(a,b,c,d,e)
191#define jffs2_wbuf_timeout NULL
192#define jffs2_wbuf_process NULL
193#define jffs2_nor_ecc(c) (0)
194#else
195#error no nand yet
196#endif
197
198#ifndef BUG_ON
199#define BUG_ON(x) do { if (unlikely(x)) BUG(); } while(0)
200#endif
201
202#define __init
203
204#endif /* __JFFS2_OS_RTEMS_H__ */
Note: See TracBrowser for help on using the repository browser.