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