Home | History | Annotate | Download | only in yaffs2
      1 /*
      2  * YAFFS: Yet another FFS. A NAND-flash specific file system.
      3  * devextras.h
      4  *
      5  * Copyright (C) 2002 Aleph One Ltd.
      6  *   for Toby Churchill Ltd and Brightstar Engineering
      7  *
      8  * Created by Charles Manning <charles (at) aleph1.co.uk>
      9  *
     10  * This program is free software; you can redistribute it and/or modify
     11  * it under the terms of the GNU Lesser General Public License version 2.1 as
     12  * published by the Free Software Foundation.
     13  *
     14  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
     15  *
     16  * This file is just holds extra declarations used during development.
     17  * Most of these are from kernel includes placed here so we can use them in
     18  * applications.
     19  *
     20  * $Id: devextras.h,v 1.2 2005/08/11 02:37:49 marty Exp $
     21  *
     22  */
     23 
     24 #ifndef __EXTRAS_H__
     25 #define __EXTRAS_H__
     26 
     27 #if defined WIN32
     28 #define __inline__ __inline
     29 #define new newHack
     30 #endif
     31 
     32 #if !(defined __KERNEL__) || (defined WIN32)
     33 
     34 /* User space defines */
     35 
     36 typedef unsigned char __u8;
     37 typedef unsigned short __u16;
     38 typedef unsigned __u32;
     39 
     40 #if defined(__APPLE__) || defined(__FreeBSD__)
     41 typedef long long loff_t;
     42 #endif
     43 
     44 /*
     45  * Simple doubly linked list implementation.
     46  *
     47  * Some of the internal functions ("__xxx") are useful when
     48  * manipulating whole lists rather than single entries, as
     49  * sometimes we already know the next/prev entries and we can
     50  * generate better code by using them directly rather than
     51  * using the generic single-entry routines.
     52  */
     53 
     54 #define prefetch(x) 1
     55 
     56 struct list_head {
     57 	struct list_head *next, *prev;
     58 };
     59 
     60 #define LIST_HEAD_INIT(name) { &(name), &(name) }
     61 
     62 #define LIST_HEAD(name) \
     63 	struct list_head name = LIST_HEAD_INIT(name)
     64 
     65 #define INIT_LIST_HEAD(ptr) do { \
     66 	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
     67 } while (0)
     68 
     69 /*
     70  * Insert a new entry between two known consecutive entries.
     71  *
     72  * This is only for internal list manipulation where we know
     73  * the prev/next entries already!
     74  */
     75 static __inline__ void __list_add(struct list_head *new,
     76 				  struct list_head *prev,
     77 				  struct list_head *next)
     78 {
     79 	next->prev = new;
     80 	new->next = next;
     81 	new->prev = prev;
     82 	prev->next = new;
     83 }
     84 
     85 /**
     86  * list_add - add a new entry
     87  * @new: new entry to be added
     88  * @head: list head to add it after
     89  *
     90  * Insert a new entry after the specified head.
     91  * This is good for implementing stacks.
     92  */
     93 static __inline__ void list_add(struct list_head *new, struct list_head *head)
     94 {
     95 	__list_add(new, head, head->next);
     96 }
     97 
     98 /**
     99  * list_add_tail - add a new entry
    100  * @new: new entry to be added
    101  * @head: list head to add it before
    102  *
    103  * Insert a new entry before the specified head.
    104  * This is useful for implementing queues.
    105  */
    106 static __inline__ void list_add_tail(struct list_head *new,
    107 				     struct list_head *head)
    108 {
    109 	__list_add(new, head->prev, head);
    110 }
    111 
    112 /*
    113  * Delete a list entry by making the prev/next entries
    114  * point to each other.
    115  *
    116  * This is only for internal list manipulation where we know
    117  * the prev/next entries already!
    118  */
    119 static __inline__ void __list_del(struct list_head *prev,
    120 				  struct list_head *next)
    121 {
    122 	next->prev = prev;
    123 	prev->next = next;
    124 }
    125 
    126 /**
    127  * list_del - deletes entry from list.
    128  * @entry: the element to delete from the list.
    129  * Note: list_empty on entry does not return true after this, the entry is
    130  * in an undefined state.
    131  */
    132 static __inline__ void list_del(struct list_head *entry)
    133 {
    134 	__list_del(entry->prev, entry->next);
    135 }
    136 
    137 /**
    138  * list_del_init - deletes entry from list and reinitialize it.
    139  * @entry: the element to delete from the list.
    140  */
    141 static __inline__ void list_del_init(struct list_head *entry)
    142 {
    143 	__list_del(entry->prev, entry->next);
    144 	INIT_LIST_HEAD(entry);
    145 }
    146 
    147 /**
    148  * list_empty - tests whether a list is empty
    149  * @head: the list to test.
    150  */
    151 static __inline__ int list_empty(struct list_head *head)
    152 {
    153 	return head->next == head;
    154 }
    155 
    156 /**
    157  * list_splice - join two lists
    158  * @list: the new list to add.
    159  * @head: the place to add it in the first list.
    160  */
    161 static __inline__ void list_splice(struct list_head *list,
    162 				   struct list_head *head)
    163 {
    164 	struct list_head *first = list->next;
    165 
    166 	if (first != list) {
    167 		struct list_head *last = list->prev;
    168 		struct list_head *at = head->next;
    169 
    170 		first->prev = head;
    171 		head->next = first;
    172 
    173 		last->next = at;
    174 		at->prev = last;
    175 	}
    176 }
    177 
    178 /**
    179  * list_entry - get the struct for this entry
    180  * @ptr:	the &struct list_head pointer.
    181  * @type:	the type of the struct this is embedded in.
    182  * @member:	the name of the list_struct within the struct.
    183  */
    184 #define list_entry(ptr, type, member) \
    185 	((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
    186 
    187 /**
    188  * list_for_each	-	iterate over a list
    189  * @pos:	the &struct list_head to use as a loop counter.
    190  * @head:	the head for your list.
    191  */
    192 #define list_for_each(pos, head) \
    193 	for (pos = (head)->next, prefetch(pos->next); pos != (head); \
    194         	pos = pos->next, prefetch(pos->next))
    195 
    196 /**
    197  * list_for_each_safe	-	iterate over a list safe against removal
    198  *                              of list entry
    199  * @pos:	the &struct list_head to use as a loop counter.
    200  * @n:		another &struct list_head to use as temporary storage
    201  * @head:	the head for your list.
    202  */
    203 #define list_for_each_safe(pos, n, head) \
    204 	for (pos = (head)->next, n = pos->next; pos != (head); \
    205 		pos = n, n = pos->next)
    206 
    207 /*
    208  * File types
    209  */
    210 #define DT_UNKNOWN	0
    211 #define DT_FIFO		1
    212 #define DT_CHR		2
    213 #define DT_DIR		4
    214 #define DT_BLK		6
    215 #define DT_REG		8
    216 #define DT_LNK		10
    217 #define DT_SOCK		12
    218 #define DT_WHT		14
    219 
    220 #ifndef WIN32
    221 #include <sys/stat.h>
    222 #endif
    223 
    224 /*
    225  * Attribute flags.  These should be or-ed together to figure out what
    226  * has been changed!
    227  */
    228 #define ATTR_MODE	1
    229 #define ATTR_UID	2
    230 #define ATTR_GID	4
    231 #define ATTR_SIZE	8
    232 #define ATTR_ATIME	16
    233 #define ATTR_MTIME	32
    234 #define ATTR_CTIME	64
    235 #define ATTR_ATIME_SET	128
    236 #define ATTR_MTIME_SET	256
    237 #define ATTR_FORCE	512	/* Not a change, but a change it */
    238 #define ATTR_ATTR_FLAG	1024
    239 
    240 struct iattr {
    241 	unsigned int ia_valid;
    242 	unsigned ia_mode;
    243 	unsigned ia_uid;
    244 	unsigned ia_gid;
    245 	unsigned ia_size;
    246 	unsigned ia_atime;
    247 	unsigned ia_mtime;
    248 	unsigned ia_ctime;
    249 	unsigned int ia_attr_flags;
    250 };
    251 
    252 #define KERN_DEBUG
    253 
    254 #else
    255 
    256 #ifndef WIN32
    257 #include <linux/types.h>
    258 #include <linux/list.h>
    259 #include <linux/fs.h>
    260 #include <linux/stat.h>
    261 #endif
    262 
    263 #endif
    264 
    265 #if defined WIN32
    266 #undef new
    267 #endif
    268 
    269 #endif
    270