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