devextras.h 6.0 KB

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