JFFS2: Update Linux compatibility layer

Modify compatbility layer for RTEMS.  Add support for Linux 3.11 based
JFFS2.
This commit is contained in:
Sebastian Huber
2013-09-12 16:53:41 +02:00
parent 672038b174
commit 78b85286f0
25 changed files with 261 additions and 66 deletions

View File

@@ -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__ */

View File

@@ -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__ */

View File

@@ -3,5 +3,6 @@
#define likely(x) (x)
#define unlikely(x) (x)
#define uninitialized_var(x) x = x
#endif /* __LINUX_COMPILER_H__ */

View File

@@ -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

View File

@@ -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__ */

View File

@@ -0,0 +1,30 @@
/*
* Copyright (c) 2013 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
* Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*/
#ifndef __LINUX_RTEMS_IMPL_H__
#define __LINUX_RTEMS_IMPL_H__
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;
}
#endif /* __LINUX_RTEMS_IMPL_H__ */

View File

@@ -1,28 +1,84 @@
#ifndef __LINUX_KERNEL_H__
#define __LINUX_KERNEL_H__
#define jiffies ((unsigned long)cyg_current_time())
#include <rtems.h>
#include <stdlib.h>
#include <string.h>
#include "kernel-rtems.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()
#define KERN_EMERG "<0>" // system is unusable
#define KERN_ALERT "<1>" // action must be taken immediately
#define KERN_CRIT "<2>" // critical conditions
#define KERN_ERR "<3>" // error conditions
#define KERN_WARNING "<4>" // warning conditions
#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_EMERG "<0>"
#define KERN_ALERT "<1>"
#define KERN_CRIT "<2>"
#define KERN_ERR "<3>"
#define KERN_WARNING "<4>"
#define KERN_NOTICE "<5>"
#define KERN_INFO "<6>"
#define KERN_DEBUG "<7>"
#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
#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__ */

View File

@@ -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 )

View File

@@ -0,0 +1,6 @@
#ifndef _LINUX_MAGIC_H
#define _LINUX_MAGIC_H
#define JFFS2_SUPER_MAGIC 0x72b6
#endif /* _LINUX_MAGIC_H */

View File

@@ -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__ */

View File

@@ -0,0 +1,29 @@
#ifndef __LINUX_MUTEX_H
#define __LINUX_MUTEX_H
struct mutex { };
#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

View File

@@ -0,0 +1,3 @@
#ifndef __LINUX_POSIX_ACL_H
#define __LINUX_POSIX_ACL_H
#endif

View File

@@ -1,21 +1,21 @@
#ifndef _LINUX_RBTREE_H
#define _LINUX_RBTREE_H
#include <stddef.h>
struct rb_node {
struct rb_node *rb_left; /* left element */
struct rb_node *rb_right; /* right element */
struct rb_node *rb_parent; /* parent element */
int rb_color; /* node color */
struct rb_node *rb_left;
struct rb_node *rb_right;
struct rb_node *rb_parent;
int rb_color;
};
struct rb_root {
struct rb_node *rb_node; /* root of the tree */
struct rb_node *rb_node;
};
#define NULL ((void *)0)
#define RB_ROOT ((struct rb_root){NULL})
#define RB_ROOT ((struct rb_root){0})
#define rb_entry(p, container, field) \
((container *) ((char *)p - ((char *)&(((container *)0)->field))))
((container *) ((char *)p - offsetof(container, field)))
#define RB_BLACK 0
#define RB_RED 1
@@ -24,12 +24,11 @@ struct rb_root {
extern void rb_insert_color(struct rb_node *, struct rb_root *);
extern void rb_erase(struct rb_node *, struct rb_root *);
/* Find logical next and previous nodes in a tree */
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,
struct rb_root *root);
@@ -43,4 +42,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 */

View File

@@ -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__ */

View File

@@ -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__ */

View File

@@ -3,8 +3,9 @@
#include <stdlib.h>
#include <asm/page.h> /* Don't ask. Linux headers are a mess. */
#include <asm/page.h>
#define kzalloc(x, y) calloc(1, x)
#define kmalloc(x, y) malloc(x)
#define kfree(x) free(x)
#define vmalloc(x) malloc(x)

View File

@@ -1,10 +1,6 @@
#ifndef __LINUX_TIMER_H__
#define __LINUX_TIMER_H__
/* Not yet */
struct timer_list { } ;
#endif /* __LINUX_TIMER_H__ */

View File

@@ -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__ */

View File

@@ -0,0 +1,4 @@
#ifndef _LINUX_UIO_H
#define _LINUX_UIO_H
#endif /* _LINUX_UIO_H */

View File

@@ -9,7 +9,6 @@ typedef struct { } wait_queue_head_t;
#define remove_wait_queue(wait,old_wait) do{} while (0)
#define DECLARE_WAITQUEUE(wait,current) do{} while (0)
static inline void wake_up(wait_queue_head_t *erase_wait)
{ /* Only used for waking up threads blocks on erases. Not used in eCos */ }
static inline void wake_up(wait_queue_head_t *erase_wait) { }
#endif /* __LINUX_WAIT_H__ */

View File

@@ -1,7 +1,6 @@
#ifndef __LINUX_WORKQUEUE_H__
#define __LINUX_WORKQUEUE_H__
/* We don't do this yet */
struct work_struct { } ;
#define INIT_WORK(x,y,z) /* */

View File

@@ -0,0 +1,7 @@
#ifndef _LINUX_XATTR_H
#define _LINUX_XATTR_H
#include <asm/atomic.h>
#include <linux/types.h>
#endif /* _LINUX_XATTR_H */

View File

@@ -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)

View File

@@ -1,6 +1,6 @@
#ifndef __LINUX_ZUTIL_H__
#define __LINUX_ZUTIL_H__
#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
#define PRESET_DICT 0x20
#endif /* __LINUX_ZUTIL_H__ */

View File

@@ -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)
{