[PATCH 3/5] JFFS2: Update Linux compatibility layer

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Sep 13 15:09:43 UTC 2013


Modify compatbility layer for RTEMS.  Add support for Linux 3.11 based
JFFS2.
---
 cpukit/libfs/src/jffs2/include/asm/bug.h         |    6 ++-
 cpukit/libfs/src/jffs2/include/asm/page.h        |    7 +--
 cpukit/libfs/src/jffs2/include/linux/compiler.h  |    1 +
 cpukit/libfs/src/jffs2/include/linux/crc32.h     |    2 +
 cpukit/libfs/src/jffs2/include/linux/fs.h        |   25 +++++++-
 cpukit/libfs/src/jffs2/include/linux/kernel.h    |   70 +++++++++++++++++++++-
 cpukit/libfs/src/jffs2/include/linux/list.h      |   14 ++++
 cpukit/libfs/src/jffs2/include/linux/magic.h     |    6 ++
 cpukit/libfs/src/jffs2/include/linux/mtd/mtd.h   |   18 ++++++
 cpukit/libfs/src/jffs2/include/linux/mutex.h     |   31 ++++++++++
 cpukit/libfs/src/jffs2/include/linux/posix_acl.h |    3 +
 cpukit/libfs/src/jffs2/include/linux/rbtree.h    |    6 ++
 cpukit/libfs/src/jffs2/include/linux/rwsem.h     |   16 +-----
 cpukit/libfs/src/jffs2/include/linux/sched.h     |    2 +
 cpukit/libfs/src/jffs2/include/linux/slab.h      |    1 +
 cpukit/libfs/src/jffs2/include/linux/types.h     |   24 +++++---
 cpukit/libfs/src/jffs2/include/linux/uio.h       |    4 +
 cpukit/libfs/src/jffs2/include/linux/xattr.h     |    7 ++
 cpukit/libfs/src/jffs2/include/linux/zlib.h      |    2 +-
 cpukit/libfs/src/jffs2/src/compat-rbtree.c       |   18 +++++-
 20 files changed, 224 insertions(+), 39 deletions(-)
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/magic.h
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/mutex.h
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/posix_acl.h
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/uio.h
 create mode 100644 cpukit/libfs/src/jffs2/include/linux/xattr.h

diff --git a/cpukit/libfs/src/jffs2/include/asm/bug.h b/cpukit/libfs/src/jffs2/include/asm/bug.h
index 060eb27..190e8cf 100644
--- a/cpukit/libfs/src/jffs2/include/asm/bug.h
+++ b/cpukit/libfs/src/jffs2/include/asm/bug.h
@@ -1,6 +1,10 @@
 #ifndef __ASM_BUG_H__
 #define __ASM_BUG_H__
 
-#define BUG() do { diag_printf("BUG() at %s %d\n", __FILE__, __LINE__); *(int *)0=0; } while (0)
+#include <assert.h>
+
+#define BUG() assert(0)
+
+#define WARN_ON(condition) do { } while (0)
 
 #endif /* __ASM_BUG_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/asm/page.h b/cpukit/libfs/src/jffs2/include/asm/page.h
index d77a39a..a1956f7 100644
--- a/cpukit/libfs/src/jffs2/include/asm/page.h
+++ b/cpukit/libfs/src/jffs2/include/asm/page.h
@@ -1,11 +1,6 @@
 #ifndef __ASM_PAGE_H__
 #define __ASM_PAGE_H__
 
-#include <pkgconf/linux_compat.h>
-
-/* These aren't used by much yet. If that changes, you might want
-   to make them actually correct :) */
-#define PAGE_SIZE  (0x1 << PAGE_SHIFT)
-
+#include <sys/param.h>
 
 #endif /* __ASM_PAGE_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/compiler.h b/cpukit/libfs/src/jffs2/include/linux/compiler.h
index fb25365..fb6c7c3 100644
--- a/cpukit/libfs/src/jffs2/include/linux/compiler.h
+++ b/cpukit/libfs/src/jffs2/include/linux/compiler.h
@@ -3,5 +3,6 @@
 
 #define likely(x) (x)
 #define unlikely(x) (x)
+#define uninitialized_var(x) x = x
 
 #endif /* __LINUX_COMPILER_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/crc32.h b/cpukit/libfs/src/jffs2/include/linux/crc32.h
index 8d19a1e..d7fa071 100644
--- a/cpukit/libfs/src/jffs2/include/linux/crc32.h
+++ b/cpukit/libfs/src/jffs2/include/linux/crc32.h
@@ -1,8 +1,10 @@
 #ifndef CRC32_H
 #define CRC32_H
 
+#include <zlib.h>
 #include <cyg/crc/crc.h>
 
+#undef crc32
 #define crc32(val, s, len) cyg_crc32_accumulate(val, (unsigned char *)s, len)
 
 #endif
diff --git a/cpukit/libfs/src/jffs2/include/linux/fs.h b/cpukit/libfs/src/jffs2/include/linux/fs.h
index c2f173a..8da9880 100644
--- a/cpukit/libfs/src/jffs2/include/linux/fs.h
+++ b/cpukit/libfs/src/jffs2/include/linux/fs.h
@@ -2,12 +2,31 @@
 #define __LINUX_FS_H__
 
 #include <linux/stat.h>
-/*
- * File types
- */
+#include <sys/types.h>
+#include <sys/time.h>
+
 #define DT_UNKNOWN	0
 #define DT_DIR		4
 #define DT_REG		8
+#define DT_LNK		10
+
+#define ATTR_MODE	(1U << 0)
+#define ATTR_UID	(1U << 1)
+#define ATTR_GID	(1U << 2)
+#define ATTR_SIZE	(1U << 3)
+#define ATTR_ATIME	(1U << 4)
+#define ATTR_MTIME	(1U << 5)
+#define ATTR_CTIME	(1U << 6)
 
+struct iattr {
+	unsigned int	ia_valid;
+	mode_t		ia_mode;
+	uid_t		ia_uid;
+	gid_t		ia_gid;
+	off_t		ia_size;
+	time_t		ia_atime;
+	time_t		ia_mtime;
+	time_t		ia_ctime;
+};
 
 #endif /* __LINUX_FS_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/kernel.h b/cpukit/libfs/src/jffs2/include/linux/kernel.h
index e5d8d90..3679351 100644
--- a/cpukit/libfs/src/jffs2/include/linux/kernel.h
+++ b/cpukit/libfs/src/jffs2/include/linux/kernel.h
@@ -1,11 +1,19 @@
 #ifndef __LINUX_KERNEL_H__
 #define __LINUX_KERNEL_H__
 
-#define jiffies ((unsigned long)cyg_current_time())
+#include <rtems.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define jiffies ((unsigned long)rtems_clock_get_ticks_since_boot())
 
 #define ERR_PTR(err) ((void*)(err))
 #define PTR_ERR(err) ((unsigned long)(err))
 #define IS_ERR(err) ((unsigned long)err > (unsigned long)-1000L)
+static inline void *ERR_CAST(const void *ptr)
+{
+	return (void *) (uintptr_t) ptr;
+}
 
 #define CURRENT_TIME cyg_timestamp()
 
@@ -17,12 +25,70 @@
 #define	KERN_NOTICE             "<5>" // normal but significant condition
 #define	KERN_INFO               "<6>" // informational
 #define	KERN_DEBUG              "<7>" // debug-level messages
-#define printk diag_printf
+#define KERN_CONT		""
+
+#ifndef pr_fmt
+#define pr_fmt(fmt) fmt
+#endif
+
+#define pr_emerg(fmt, ...) \
+	printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_alert(fmt, ...) \
+	printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_crit(fmt, ...) \
+	printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_err(fmt, ...) \
+	printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warning(fmt, ...) \
+	printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_warn pr_warning
+#define pr_notice(fmt, ...) \
+	printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_info(fmt, ...) \
+	printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
+#define pr_cont(fmt, ...) \
+	printk(KERN_CONT fmt, ##__VA_ARGS__)
+
+#ifdef DEBUG
+#define pr_debug(fmt, ...) \
+	printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#else
+static inline int no_printk(const char *fmt, ...)
+{
+	(void) fmt;
+	return 0;
+}
+#define pr_debug(fmt, ...) \
+	no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
+#endif
 
 #define min(x,y) (x<y?x:y)
 #define max(x,y) (x<y?y:x)
 #define min_t(t, x,y) ((t)x<(t)y?(t)x:(t)y)
 
+#define capable(x) 0
+
+static inline char *do_kmemdup(const char *s, size_t n)
+{
+	char *dup = malloc(n + 1);
+
+	if (dup != 0) {
+		dup[n] = '\0';
+		dup = memcpy(dup, s, n);
+	}
+
+	return dup;
+}
+
+#define kmemdup(x, y, z) do_kmemdup(x, y)
+
+#define from_kuid(x, y) (y)
+#define from_kgid(x, y) (y)
+#define i_uid_read(x) ((x)->i_uid)
+#define i_gid_read(x) ((x)->i_gid)
+#define i_uid_write(x, y) do { (x)->i_uid = (y); } while (0)
+#define i_gid_write(x, y) do { (x)->i_gid = (y); } while (0)
+#define truncate_setsize(x, y) do { (x)->i_size = (y); } while (0)
 
 #endif /* __LINUX_KERNEL_H__ */
 
diff --git a/cpukit/libfs/src/jffs2/include/linux/list.h b/cpukit/libfs/src/jffs2/include/linux/list.h
index e9ebab1..4dc8a5a 100644
--- a/cpukit/libfs/src/jffs2/include/linux/list.h
+++ b/cpukit/libfs/src/jffs2/include/linux/list.h
@@ -103,6 +103,20 @@ list_del( struct list_head *ent )
     ent->next->prev = ent->prev;
 } /* list_del() */
 
+static __inline__ void
+list_move( struct list_head *list, struct list_head *head )
+{
+    list_del( list );
+    list_add( list, head );
+}
+
+static __inline__ void
+list_move_tail( struct list_head *list, struct list_head *head )
+{
+    list_del( list );
+    list_add_tail( list, head );
+}
+
 /* Is this list empty? */
 static __inline__ int
 list_empty( struct list_head *list )
diff --git a/cpukit/libfs/src/jffs2/include/linux/magic.h b/cpukit/libfs/src/jffs2/include/linux/magic.h
new file mode 100644
index 0000000..07ba6b6
--- /dev/null
+++ b/cpukit/libfs/src/jffs2/include/linux/magic.h
@@ -0,0 +1,6 @@
+#ifndef _LINUX_MAGIC_H
+#define _LINUX_MAGIC_H
+
+#define JFFS2_SUPER_MAGIC 0x72b6
+
+#endif /* _LINUX_MAGIC_H */
diff --git a/cpukit/libfs/src/jffs2/include/linux/mtd/mtd.h b/cpukit/libfs/src/jffs2/include/linux/mtd/mtd.h
index 817d31c..bcf0a9a 100644
--- a/cpukit/libfs/src/jffs2/include/linux/mtd/mtd.h
+++ b/cpukit/libfs/src/jffs2/include/linux/mtd/mtd.h
@@ -1,5 +1,23 @@
 #ifndef __LINUX_MTD_MTD_H__
 #define __LINUX_MTD_MTD_H__
 
+#include <linux/slab.h>
+#include <errno.h>
+
+#define MTD_FAIL_ADDR_UNKNOWN -1LL
+
+static inline int do_mtd_point(size_t *retlen, void **ebuf)
+{
+	*retlen = 0;
+	*ebuf = NULL;
+
+	return -EOPNOTSUPP;
+}
+
+#define mtd_point(a, b, c, d, e, f) do_mtd_point(d, e)
+
+#define mtd_unpoint(a, b, c) do { } while (0)
+
+#define mtd_kmalloc_up_to(a, b) kmalloc(*(b), GFP_KERNEL)
 
 #endif /* __LINUX_MTD_MTD_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/mutex.h b/cpukit/libfs/src/jffs2/include/linux/mutex.h
new file mode 100644
index 0000000..dc94d66
--- /dev/null
+++ b/cpukit/libfs/src/jffs2/include/linux/mutex.h
@@ -0,0 +1,31 @@
+#ifndef __LINUX_MUTEX_H
+#define __LINUX_MUTEX_H
+
+struct mutex {
+	/* Empty */
+};
+
+#define DEFINE_MUTEX(m) struct mutex m
+
+static inline void mutex_init(struct mutex *m)
+{
+	(void) m;
+}
+
+static inline void mutex_lock(struct mutex *m)
+{
+	(void) m;
+}
+
+static inline int mutex_lock_interruptible(struct mutex *m)
+{
+	(void) m;
+	return 0;
+}
+
+static inline void mutex_unlock(struct mutex *m)
+{
+	(void) m;
+}
+
+#endif
diff --git a/cpukit/libfs/src/jffs2/include/linux/posix_acl.h b/cpukit/libfs/src/jffs2/include/linux/posix_acl.h
new file mode 100644
index 0000000..49504bc
--- /dev/null
+++ b/cpukit/libfs/src/jffs2/include/linux/posix_acl.h
@@ -0,0 +1,3 @@
+#ifndef __LINUX_POSIX_ACL_H
+#define __LINUX_POSIX_ACL_H
+#endif
diff --git a/cpukit/libfs/src/jffs2/include/linux/rbtree.h b/cpukit/libfs/src/jffs2/include/linux/rbtree.h
index fef5f71..3c2c811 100644
--- a/cpukit/libfs/src/jffs2/include/linux/rbtree.h
+++ b/cpukit/libfs/src/jffs2/include/linux/rbtree.h
@@ -28,6 +28,7 @@ extern void rb_erase(struct rb_node *, struct rb_root *);
 extern struct rb_node *rb_next(struct rb_node *);
 extern struct rb_node *rb_prev(struct rb_node *);
 extern struct rb_node *rb_first(struct rb_root *);
+extern struct rb_node *rb_last(struct rb_root *);
 
 /* Fast replacement of a single node without remove/rebalance/add/rebalance */
 extern void rb_replace_node(struct rb_node *victim, struct rb_node *new, 
@@ -43,4 +44,9 @@ static inline void rb_link_node(struct rb_node * node, struct rb_node * parent,
 	*rb_link = node;
 }
 
+static inline struct rb_node *rb_parent(struct rb_node * node)
+{
+	return node->rb_parent;
+}
+
 #endif	/* _LINUX_RBTREE_H */
diff --git a/cpukit/libfs/src/jffs2/include/linux/rwsem.h b/cpukit/libfs/src/jffs2/include/linux/rwsem.h
index d648a15..57bfdf1 100644
--- a/cpukit/libfs/src/jffs2/include/linux/rwsem.h
+++ b/cpukit/libfs/src/jffs2/include/linux/rwsem.h
@@ -1,20 +1,6 @@
 #ifndef __LINUX_RWSEM_H__
 #define __LINUX_RWSEM_H__
 
-// eCos does not have the concept of a read/write semaphore. So just
-// map them onto normal semaphores and hope we don't deadlock
-// somewhere.
-
-#include <asm/semaphore.h>
-
 struct rw_semaphore;
 
-#define down_read(sem) cyg_drv_mutex_lock((cyg_drv_mutex_t *)sem)
-#define down_read_trylock(sem) cyg_drv_mutex_trylock((cyg_drv_mutex_t *)sem)
-#define down_write(sem) cyg_drv_mutex_lock((cyg_drv_mutex_t *)sem)
-#define down_write_trylock(sem) cyg_drv_mutex_trylock((cyg_drv_mutex_t *)sem)
-#define up_read(sem) cyg_drv_mutex_unlock((cyg_drv_mutex_t *)sem)
-#define up_write(sem) cyg_drv_mutex_unlock((cyg_drv_mutex_t *)sem)
-#define downgrade_write(sem) 
-
-#endif // __LINUX_RWSEM_H__ 
+#endif /* __LINUX_RWSEM_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/sched.h b/cpukit/libfs/src/jffs2/include/linux/sched.h
index 14a7359..1f4e7da 100644
--- a/cpukit/libfs/src/jffs2/include/linux/sched.h
+++ b/cpukit/libfs/src/jffs2/include/linux/sched.h
@@ -1,7 +1,9 @@
 #ifndef __LINUX_SCHED_H__
 #define __LINUX_SCHED_H__
 
+#define schedule() do { } while(0)
 #define cond_resched() do { } while(0)
 #define signal_pending(x) (0)
+#define set_current_state(x) do { } while (0)
 
 #endif /* __LINUX_SCHED_H__ */
diff --git a/cpukit/libfs/src/jffs2/include/linux/slab.h b/cpukit/libfs/src/jffs2/include/linux/slab.h
index fff3949..070bcf3 100644
--- a/cpukit/libfs/src/jffs2/include/linux/slab.h
+++ b/cpukit/libfs/src/jffs2/include/linux/slab.h
@@ -5,6 +5,7 @@
 
 #include <asm/page.h> /* Don't ask. Linux headers are a mess. */
 
+#define kzalloc(x, y) calloc(1, x)
 #define kmalloc(x, y) malloc(x)
 #define kfree(x) free(x)
 #define vmalloc(x) malloc(x)
diff --git a/cpukit/libfs/src/jffs2/include/linux/types.h b/cpukit/libfs/src/jffs2/include/linux/types.h
index 56665b7..a85b856 100644
--- a/cpukit/libfs/src/jffs2/include/linux/types.h
+++ b/cpukit/libfs/src/jffs2/include/linux/types.h
@@ -1,19 +1,25 @@
 #ifndef __LINUX_TYPES_H__
 #define __LINUX_TYPES_H__
 
-#include "cyg/infra/cyg_type.h"
-
-#define uint8_t cyg_uint8
-#define uint16_t cyg_uint16
-#define uint32_t cyg_uint32
-
-#define int8_t cyg_int8
-#define int16_t cyg_int16
-#define int32_t cyg_int32
+#include <sys/types.h>
+#include <stdint.h>
 
 #define loff_t off_t
 
+typedef uint8_t u8;
+typedef uint16_t u16;
+typedef uint32_t u32;
+
+typedef uint8_t __u8;
+typedef uint16_t __u16;
+typedef uint32_t __u32;
 
 #define kvec iovec
+
+struct qstr {
+	const char *name;
+	size_t len;
+};
+
 #endif /* __LINUX_TYPES_H__ */
 
diff --git a/cpukit/libfs/src/jffs2/include/linux/uio.h b/cpukit/libfs/src/jffs2/include/linux/uio.h
new file mode 100644
index 0000000..f58e0ad
--- /dev/null
+++ b/cpukit/libfs/src/jffs2/include/linux/uio.h
@@ -0,0 +1,4 @@
+#ifndef _LINUX_UIO_H
+#define _LINUX_UIO_H
+
+#endif /* _LINUX_UIO_H */
diff --git a/cpukit/libfs/src/jffs2/include/linux/xattr.h b/cpukit/libfs/src/jffs2/include/linux/xattr.h
new file mode 100644
index 0000000..9b17d44
--- /dev/null
+++ b/cpukit/libfs/src/jffs2/include/linux/xattr.h
@@ -0,0 +1,7 @@
+#ifndef _LINUX_XATTR_H
+#define _LINUX_XATTR_H
+
+#include <asm/atomic.h>
+#include <linux/types.h>
+
+#endif /* _LINUX_XATTR_H */
diff --git a/cpukit/libfs/src/jffs2/include/linux/zlib.h b/cpukit/libfs/src/jffs2/include/linux/zlib.h
index 9de691e..783aea1 100644
--- a/cpukit/libfs/src/jffs2/include/linux/zlib.h
+++ b/cpukit/libfs/src/jffs2/include/linux/zlib.h
@@ -1,7 +1,7 @@
 #ifndef __LINUX_ZLIB_H__
 #define __LINUX_ZLIB_H__
 
-#include <cyg/compress/zlib.h>
+#include <zlib.h>
 
 #define zlib_deflateInit(x,y) deflateInit(x,y)
 #define zlib_deflate(x,y) deflate(x,y)
diff --git a/cpukit/libfs/src/jffs2/src/compat-rbtree.c b/cpukit/libfs/src/jffs2/src/compat-rbtree.c
index 5bc1cc5..a73cdc2 100644
--- a/cpukit/libfs/src/jffs2/src/compat-rbtree.c
+++ b/cpukit/libfs/src/jffs2/src/compat-rbtree.c
@@ -119,8 +119,9 @@
 	RB_LEFT(tmp) = (elm);					\
 	RB_PARENT(elm) = (tmp);					\
 	RB_AUGMENT(tmp);					\
-	if ((RB_PARENT(tmp)))					\
+	if ((RB_PARENT(tmp))) {					\
 		RB_AUGMENT(RB_PARENT(tmp));			\
+	}							\
 } while (0)
 
 #define RB_ROTATE_RIGHT(head, elm, tmp) do {			\
@@ -139,8 +140,9 @@
 	RB_RIGHT(tmp) = (elm);					\
 	RB_PARENT(elm) = (tmp);					\
 	RB_AUGMENT(tmp);					\
-	if ((RB_PARENT(tmp)))					\
+	if ((RB_PARENT(tmp))) {					\
 		RB_AUGMENT(RB_PARENT(tmp));			\
+	}							\
 } while(0)
 
 /* Note args swapped to match Linux */
@@ -384,6 +386,18 @@ struct rb_node *rb_first(struct rb_root *root)
         return n;
 }
 
+struct rb_node *rb_last(struct rb_root *root)
+{
+	struct rb_node	*n;
+
+	n = root->rb_node;
+	if (!n)
+		return 0;
+	while (n->rb_right)
+		n = n->rb_right;
+	return n;
+}
+
 void rb_replace_node(struct rb_node *victim, struct rb_node *new,
                      struct rb_root *root)
 {
-- 
1.7.7




More information about the devel mailing list