devextras.h 6.1 KB

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