1 --- a/fs/yaffs2/devextras.h
2 +++ b/fs/yaffs2/devextras.h
7 - * This file is just holds extra declarations used during development.
8 - * Most of these are from kernel includes placed here so we can use them in
10 + * This file is just holds extra declarations of macros that would normally
11 + * be providesd in the Linux kernel. These macros have been written from
12 + * scratch but are functionally equivalent to the Linux ones.
20 -#define __inline__ __inline
24 -#if !(defined __KERNEL__) || (defined WIN32)
26 -/* User space defines */
27 +#if !(defined __KERNEL__)
29 +/* Definition of types */
30 typedef unsigned char __u8;
31 typedef unsigned short __u16;
32 typedef unsigned __u32;
37 - * Simple doubly linked list implementation.
39 - * Some of the internal functions ("__xxx") are useful when
40 - * manipulating whole lists rather than single entries, as
41 - * sometimes we already know the next/prev entries and we can
42 - * generate better code by using them directly rather than
43 - * using the generic single-entry routines.
44 + * This is a simple doubly linked list implementation that matches the
45 + * way the Linux kernel doubly linked list implementation works.
48 -#define prefetch(x) 1
51 - struct list_head *next, *prev;
53 + struct ylist_head *next; /* next in chain */
54 + struct ylist_head *prev; /* previous in chain */
57 -#define LIST_HEAD_INIT(name) { &(name), &(name) }
59 -#define LIST_HEAD(name) \
60 - struct list_head name = LIST_HEAD_INIT(name)
61 +/* Initialise a static list */
62 +#define YLIST_HEAD(name) \
63 +struct ylist_head name = { &(name), &(name)}
66 -#define INIT_LIST_HEAD(ptr) do { \
67 - (ptr)->next = (ptr); (ptr)->prev = (ptr); \
69 +/* Initialise a list head to an empty list */
70 +#define YINIT_LIST_HEAD(p) \
77 - * Insert a new entry between two known consecutive entries.
79 - * This is only for internal list manipulation where we know
80 - * the prev/next entries already!
82 -static __inline__ void __list_add(struct list_head *new,
83 - struct list_head *prev,
84 - struct list_head *next)
93 - * list_add - add a new entry
94 - * @new: new entry to be added
95 - * @head: list head to add it after
97 - * Insert a new entry after the specified head.
98 - * This is good for implementing stacks.
100 -static __inline__ void list_add(struct list_head *new, struct list_head *head)
101 +/* Add an element to a list */
102 +static __inline__ void ylist_add(struct ylist_head *newEntry,
103 + struct ylist_head *list)
105 - __list_add(new, head, head->next);
107 + struct ylist_head *listNext = list->next;
109 + list->next = newEntry;
110 + newEntry->prev = list;
111 + newEntry->next = listNext;
112 + listNext->prev = newEntry;
115 - * list_add_tail - add a new entry
116 - * @new: new entry to be added
117 - * @head: list head to add it before
119 - * Insert a new entry before the specified head.
120 - * This is useful for implementing queues.
122 -static __inline__ void list_add_tail(struct list_head *new,
123 - struct list_head *head)
125 - __list_add(new, head->prev, head);
129 - * Delete a list entry by making the prev/next entries
130 - * point to each other.
132 - * This is only for internal list manipulation where we know
133 - * the prev/next entries already!
135 -static __inline__ void __list_del(struct list_head *prev,
136 - struct list_head *next)
137 +static __inline__ void ylist_add_tail(struct ylist_head *newEntry,
138 + struct ylist_head *list)
142 + struct ylist_head *listPrev = list->prev;
144 + list->prev = newEntry;
145 + newEntry->next = list;
146 + newEntry->prev = listPrev;
147 + listPrev->next = newEntry;
152 - * list_del - deletes entry from list.
153 - * @entry: the element to delete from the list.
154 - * Note: list_empty on entry does not return true after this, the entry is
155 - * in an undefined state.
157 -static __inline__ void list_del(struct list_head *entry)
159 +/* Take an element out of its current list, with or without
160 + * reinitialising the links.of the entry*/
161 +static __inline__ void ylist_del(struct ylist_head *entry)
163 - __list_del(entry->prev, entry->next);
164 + struct ylist_head *listNext = entry->next;
165 + struct ylist_head *listPrev = entry->prev;
167 + listNext->prev = listPrev;
168 + listPrev->next = listNext;
173 - * list_del_init - deletes entry from list and reinitialize it.
174 - * @entry: the element to delete from the list.
176 -static __inline__ void list_del_init(struct list_head *entry)
177 +static __inline__ void ylist_del_init(struct ylist_head *entry)
179 - __list_del(entry->prev, entry->next);
180 - INIT_LIST_HEAD(entry);
182 + entry->next = entry->prev = entry;
186 - * list_empty - tests whether a list is empty
187 - * @head: the list to test.
189 -static __inline__ int list_empty(struct list_head *head)
191 +/* Test if the list is empty */
192 +static __inline__ int ylist_empty(struct ylist_head *entry)
194 - return head->next == head;
195 + return (entry->next == entry);
199 - * list_splice - join two lists
200 - * @list: the new list to add.
201 - * @head: the place to add it in the first list.
203 +/* ylist_entry takes a pointer to a list entry and offsets it to that
204 + * we can find a pointer to the object it is embedded in.
206 -static __inline__ void list_splice(struct list_head *list,
207 - struct list_head *head)
209 - struct list_head *first = list->next;
211 - if (first != list) {
212 - struct list_head *last = list->prev;
213 - struct list_head *at = head->next;
215 - first->prev = head;
216 - head->next = first;
224 - * list_entry - get the struct for this entry
225 - * @ptr: the &struct list_head pointer.
226 - * @type: the type of the struct this is embedded in.
227 - * @member: the name of the list_struct within the struct.
229 -#define list_entry(ptr, type, member) \
230 - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
233 - * list_for_each - iterate over a list
234 - * @pos: the &struct list_head to use as a loop counter.
235 - * @head: the head for your list.
237 -#define list_for_each(pos, head) \
238 - for (pos = (head)->next, prefetch(pos->next); pos != (head); \
239 - pos = pos->next, prefetch(pos->next))
242 - * list_for_each_safe - iterate over a list safe against removal
244 - * @pos: the &struct list_head to use as a loop counter.
245 - * @n: another &struct list_head to use as temporary storage
246 - * @head: the head for your list.
248 -#define list_for_each_safe(pos, n, head) \
249 - for (pos = (head)->next, n = pos->next; pos != (head); \
250 - pos = n, n = pos->next)
251 +#define ylist_entry(entry, type, member) \
252 + ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member)))
257 +/* ylist_for_each and list_for_each_safe iterate over lists.
258 + * ylist_for_each_safe uses temporary storage to make the list delete safe
261 +#define ylist_for_each(itervar, list) \
262 + for (itervar = (list)->next; itervar != (list); itervar = itervar->next)
264 +#define ylist_for_each_safe(itervar, saveVar, list) \
265 + for (itervar = (list)->next, saveVar = (list)->next->next; \
266 + itervar != (list); itervar = saveVar, saveVar = saveVar->next)
269 +#if !(defined __KERNEL__)
273 +#include <sys/stat.h>
277 +#ifdef CONFIG_YAFFS_PROVIDE_DEFS
284 @@ -212,6 +153,7 @@ static __inline__ void list_splice(struc
290 #include <sys/stat.h>
292 @@ -227,10 +169,6 @@ static __inline__ void list_splice(struc
293 #define ATTR_ATIME 16
294 #define ATTR_MTIME 32
295 #define ATTR_CTIME 64
296 -#define ATTR_ATIME_SET 128
297 -#define ATTR_MTIME_SET 256
298 -#define ATTR_FORCE 512 /* Not a change, but a change it */
299 -#define ATTR_ATTR_FLAG 1024
302 unsigned int ia_valid;
303 @@ -244,21 +182,15 @@ struct iattr {
304 unsigned int ia_attr_flags;
313 #include <linux/types.h>
314 -#include <linux/list.h>
315 #include <linux/fs.h>
316 #include <linux/stat.h>
326 --- a/fs/yaffs2/Kconfig
327 +++ b/fs/yaffs2/Kconfig
330 tristate "YAFFS2 file system support"
333 + depends on MTD_BLOCK
337 @@ -43,7 +43,8 @@ config YAFFS_9BYTE_TAGS
338 format that you need to continue to support. New data written
339 also uses the older-style format. Note: Use of this option
340 generally requires that MTD's oob layout be adjusted to use the
341 - older-style format. See notes on tags formats and MTD versions.
342 + older-style format. See notes on tags formats and MTD versions
347 @@ -109,26 +110,6 @@ config YAFFS_DISABLE_LAZY_LOAD
351 -config YAFFS_CHECKPOINT_RESERVED_BLOCKS
352 - int "Reserved blocks for checkpointing"
353 - depends on YAFFS_YAFFS2
356 - Give the number of Blocks to reserve for checkpointing.
357 - Checkpointing saves the state at unmount so that mounting is
358 - much faster as a scan of all the flash to regenerate this state
359 - is not needed. These Blocks are reserved per partition, so if
360 - you have very small partitions the default (10) may be a mess
361 - for you. You can set this value to 0, but that does not mean
362 - checkpointing is disabled at all. There only won't be any
363 - specially reserved blocks for checkpointing, so if there is
364 - enough free space on the filesystem, it will be used for
367 - If unsure, leave at default (10), but don't wonder if there are
368 - always 2MB used on your large page device partition (10 x 2k
369 - pagesize). When using small partitions or when being very small
370 - on space, you probably want to set this to zero.
372 config YAFFS_DISABLE_WIDE_TNODES
373 bool "Turn off wide tnodes"
374 --- a/fs/yaffs2/Makefile
375 +++ b/fs/yaffs2/Makefile
377 obj-$(CONFIG_YAFFS_FS) += yaffs.o
379 yaffs-y := yaffs_ecc.o yaffs_fs.o yaffs_guts.o yaffs_checkptrw.o
380 -yaffs-y += yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o
381 +yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o
382 yaffs-y += yaffs_tagscompat.o yaffs_tagsvalidity.o
383 -yaffs-y += yaffs_mtdif1.o yaffs_packedtags1.o
384 -yaffs-y += yaffs_mtdif.o yaffs_mtdif2.o
385 +yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o
386 --- a/fs/yaffs2/moduleconfig.h
387 +++ b/fs/yaffs2/moduleconfig.h
390 /* Default: Not selected */
391 /* Meaning: Yaffs does its own ECC, rather than using MTD ECC */
392 -//#define CONFIG_YAFFS_DOES_ECC
393 +/* #define CONFIG_YAFFS_DOES_ECC */
395 /* Default: Not selected */
396 /* Meaning: ECC byte order is 'wrong'. Only meaningful if */
397 /* CONFIG_YAFFS_DOES_ECC is set */
398 -//#define CONFIG_YAFFS_ECC_WRONG_ORDER
399 +/* #define CONFIG_YAFFS_ECC_WRONG_ORDER */
401 /* Default: Selected */
402 /* Meaning: Disables testing whether chunks are erased before writing to them*/
403 @@ -54,11 +54,11 @@ that you need to continue to support. N
405 Note: Use of this option generally requires that MTD's oob layout be
406 adjusted to use the older-style format. See notes on tags formats and
408 +MTD versions in yaffs_mtdif1.c.
410 /* Default: Not selected */
411 /* Meaning: Use older-style on-NAND data format with pageStatus byte */
412 -#define CONFIG_YAFFS_9BYTE_TAGS
413 +/* #define CONFIG_YAFFS_9BYTE_TAGS */
415 #endif /* YAFFS_OUT_OF_TREE */
417 --- a/fs/yaffs2/yaffs_checkptrw.c
418 +++ b/fs/yaffs2/yaffs_checkptrw.c
422 const char *yaffs_checkptrw_c_version =
423 - "$Id: yaffs_checkptrw.c,v 1.14 2007-05-15 20:07:40 charles Exp $";
424 + "$Id: yaffs_checkptrw.c,v 1.18 2009-03-06 17:20:49 wookey Exp $";
427 #include "yaffs_checkptrw.h"
429 +#include "yaffs_getblockinfo.h"
431 static int yaffs_CheckpointSpaceOk(yaffs_Device *dev)
434 int blocksAvailable = dev->nErasedBlocks - dev->nReservedBlocks;
436 T(YAFFS_TRACE_CHECKPOINT,
437 (TSTR("checkpt blocks available = %d" TENDSTR),
441 return (blocksAvailable <= 0) ? 0 : 1;
445 static int yaffs_CheckpointErase(yaffs_Device *dev)
451 - if(!dev->eraseBlockInNAND)
452 + if (!dev->eraseBlockInNAND)
454 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checking blocks %d to %d"TENDSTR),
455 - dev->internalStartBlock,dev->internalEndBlock));
456 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checking blocks %d to %d"TENDSTR),
457 + dev->internalStartBlock, dev->internalEndBlock));
459 - for(i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) {
460 - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i);
461 - if(bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT){
462 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("erasing checkpt block %d"TENDSTR),i));
463 - if(dev->eraseBlockInNAND(dev,i- dev->blockOffset /* realign */)){
464 + for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) {
465 + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i);
466 + if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) {
467 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("erasing checkpt block %d"TENDSTR), i));
468 + if (dev->eraseBlockInNAND(dev, i - dev->blockOffset /* realign */)) {
469 bi->blockState = YAFFS_BLOCK_STATE_EMPTY;
470 dev->nErasedBlocks++;
471 dev->nFreeChunks += dev->nChunksPerBlock;
474 - dev->markNANDBlockBad(dev,i);
476 + dev->markNANDBlockBad(dev, i);
477 bi->blockState = YAFFS_BLOCK_STATE_DEAD;
480 @@ -71,23 +66,23 @@ static void yaffs_CheckpointFindNextEras
481 int blocksAvailable = dev->nErasedBlocks - dev->nReservedBlocks;
482 T(YAFFS_TRACE_CHECKPOINT,
483 (TSTR("allocating checkpt block: erased %d reserved %d avail %d next %d "TENDSTR),
484 - dev->nErasedBlocks,dev->nReservedBlocks,blocksAvailable,dev->checkpointNextBlock));
485 + dev->nErasedBlocks, dev->nReservedBlocks, blocksAvailable, dev->checkpointNextBlock));
487 - if(dev->checkpointNextBlock >= 0 &&
488 - dev->checkpointNextBlock <= dev->internalEndBlock &&
489 - blocksAvailable > 0){
491 - for(i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++){
492 - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i);
493 - if(bi->blockState == YAFFS_BLOCK_STATE_EMPTY){
494 + if (dev->checkpointNextBlock >= 0 &&
495 + dev->checkpointNextBlock <= dev->internalEndBlock &&
496 + blocksAvailable > 0) {
498 + for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) {
499 + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i);
500 + if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) {
501 dev->checkpointNextBlock = i + 1;
502 dev->checkpointCurrentBlock = i;
503 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("allocating checkpt block %d"TENDSTR),i));
504 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("allocating checkpt block %d"TENDSTR), i));
509 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("out of checkpt blocks"TENDSTR)));
510 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("out of checkpt blocks"TENDSTR)));
512 dev->checkpointNextBlock = -1;
513 dev->checkpointCurrentBlock = -1;
514 @@ -98,30 +93,31 @@ static void yaffs_CheckpointFindNextChec
516 yaffs_ExtendedTags tags;
518 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR),
519 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR),
520 dev->blocksInCheckpoint, dev->checkpointNextBlock));
522 - if(dev->blocksInCheckpoint < dev->checkpointMaxBlocks)
523 - for(i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++){
524 + if (dev->blocksInCheckpoint < dev->checkpointMaxBlocks)
525 + for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) {
526 int chunk = i * dev->nChunksPerBlock;
527 int realignedChunk = chunk - dev->chunkOffset;
529 - dev->readChunkWithTagsFromNAND(dev,realignedChunk,NULL,&tags);
530 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR),
531 - i, tags.objectId,tags.sequenceNumber,tags.eccResult));
532 + dev->readChunkWithTagsFromNAND(dev, realignedChunk,
534 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR),
535 + i, tags.objectId, tags.sequenceNumber, tags.eccResult));
537 - if(tags.sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA){
538 + if (tags.sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA) {
539 /* Right kind of block */
540 dev->checkpointNextBlock = tags.objectId;
541 dev->checkpointCurrentBlock = i;
542 dev->checkpointBlockList[dev->blocksInCheckpoint] = i;
543 dev->blocksInCheckpoint++;
544 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("found checkpt block %d"TENDSTR),i));
545 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("found checkpt block %d"TENDSTR), i));
550 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("found no more checkpt blocks"TENDSTR)));
551 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("found no more checkpt blocks"TENDSTR)));
553 dev->checkpointNextBlock = -1;
554 dev->checkpointCurrentBlock = -1;
555 @@ -133,17 +129,17 @@ int yaffs_CheckpointOpen(yaffs_Device *d
557 /* Got the functions we need? */
558 if (!dev->writeChunkWithTagsToNAND ||
559 - !dev->readChunkWithTagsFromNAND ||
560 - !dev->eraseBlockInNAND ||
561 - !dev->markNANDBlockBad)
562 + !dev->readChunkWithTagsFromNAND ||
563 + !dev->eraseBlockInNAND ||
564 + !dev->markNANDBlockBad)
567 - if(forWriting && !yaffs_CheckpointSpaceOk(dev))
568 + if (forWriting && !yaffs_CheckpointSpaceOk(dev))
571 - if(!dev->checkpointBuffer)
572 - dev->checkpointBuffer = YMALLOC_DMA(dev->nDataBytesPerChunk);
573 - if(!dev->checkpointBuffer)
574 + if (!dev->checkpointBuffer)
575 + dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk);
576 + if (!dev->checkpointBuffer)
580 @@ -159,12 +155,10 @@ int yaffs_CheckpointOpen(yaffs_Device *d
581 dev->checkpointNextBlock = dev->internalStartBlock;
583 /* Erase all the blocks in the checkpoint area */
585 - memset(dev->checkpointBuffer,0,dev->nDataBytesPerChunk);
587 + memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk);
588 dev->checkpointByteOffset = 0;
589 return yaffs_CheckpointErase(dev);
594 /* Set to a value that will kick off a read */
595 @@ -174,7 +168,7 @@ int yaffs_CheckpointOpen(yaffs_Device *d
596 dev->blocksInCheckpoint = 0;
597 dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2;
598 dev->checkpointBlockList = YMALLOC(sizeof(int) * dev->checkpointMaxBlocks);
599 - for(i = 0; i < dev->checkpointMaxBlocks; i++)
600 + for (i = 0; i < dev->checkpointMaxBlocks; i++)
601 dev->checkpointBlockList[i] = -1;
604 @@ -191,18 +185,17 @@ int yaffs_GetCheckpointSum(yaffs_Device
606 static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev)
612 yaffs_ExtendedTags tags;
614 - if(dev->checkpointCurrentBlock < 0){
615 + if (dev->checkpointCurrentBlock < 0) {
616 yaffs_CheckpointFindNextErasedBlock(dev);
617 dev->checkpointCurrentChunk = 0;
620 - if(dev->checkpointCurrentBlock < 0)
621 + if (dev->checkpointCurrentBlock < 0)
624 tags.chunkDeleted = 0;
625 @@ -210,10 +203,10 @@ static int yaffs_CheckpointFlushBuffer(y
626 tags.chunkId = dev->checkpointPageSequence + 1;
627 tags.sequenceNumber = YAFFS_SEQUENCE_CHECKPOINT_DATA;
628 tags.byteCount = dev->nDataBytesPerChunk;
629 - if(dev->checkpointCurrentChunk == 0){
630 + if (dev->checkpointCurrentChunk == 0) {
631 /* First chunk we write for the block? Set block state to
633 - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,dev->checkpointCurrentBlock);
634 + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointCurrentBlock);
635 bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT;
636 dev->blocksInCheckpoint++;
638 @@ -221,28 +214,29 @@ static int yaffs_CheckpointFlushBuffer(y
639 chunk = dev->checkpointCurrentBlock * dev->nChunksPerBlock + dev->checkpointCurrentChunk;
642 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR),
643 - chunk, dev->checkpointCurrentBlock, dev->checkpointCurrentChunk,tags.objectId,tags.chunkId));
644 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR),
645 + chunk, dev->checkpointCurrentBlock, dev->checkpointCurrentChunk, tags.objectId, tags.chunkId));
647 realignedChunk = chunk - dev->chunkOffset;
649 - dev->writeChunkWithTagsToNAND(dev,realignedChunk,dev->checkpointBuffer,&tags);
650 + dev->writeChunkWithTagsToNAND(dev, realignedChunk,
651 + dev->checkpointBuffer, &tags);
652 dev->checkpointByteOffset = 0;
653 dev->checkpointPageSequence++;
654 dev->checkpointCurrentChunk++;
655 - if(dev->checkpointCurrentChunk >= dev->nChunksPerBlock){
656 + if (dev->checkpointCurrentChunk >= dev->nChunksPerBlock) {
657 dev->checkpointCurrentChunk = 0;
658 dev->checkpointCurrentBlock = -1;
660 - memset(dev->checkpointBuffer,0,dev->nDataBytesPerChunk);
661 + memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk);
667 -int yaffs_CheckpointWrite(yaffs_Device *dev,const void *data, int nBytes)
668 +int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes)
675 @@ -250,17 +244,14 @@ int yaffs_CheckpointWrite(yaffs_Device *
679 - if(!dev->checkpointBuffer)
680 + if (!dev->checkpointBuffer)
683 - if(!dev->checkpointOpenForWrite)
684 + if (!dev->checkpointOpenForWrite)
687 - while(i < nBytes && ok) {
691 - dev->checkpointBuffer[dev->checkpointByteOffset] = *dataBytes ;
692 + while (i < nBytes && ok) {
693 + dev->checkpointBuffer[dev->checkpointByteOffset] = *dataBytes;
694 dev->checkpointSum += *dataBytes;
695 dev->checkpointXor ^= *dataBytes;
697 @@ -270,18 +261,17 @@ int yaffs_CheckpointWrite(yaffs_Device *
698 dev->checkpointByteCount++;
701 - if(dev->checkpointByteOffset < 0 ||
702 + if (dev->checkpointByteOffset < 0 ||
703 dev->checkpointByteOffset >= dev->nDataBytesPerChunk)
704 ok = yaffs_CheckpointFlushBuffer(dev);
712 int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes)
717 yaffs_ExtendedTags tags;
719 @@ -291,52 +281,54 @@ int yaffs_CheckpointRead(yaffs_Device *d
721 __u8 *dataBytes = (__u8 *)data;
723 - if(!dev->checkpointBuffer)
724 + if (!dev->checkpointBuffer)
727 - if(dev->checkpointOpenForWrite)
728 + if (dev->checkpointOpenForWrite)
731 - while(i < nBytes && ok) {
732 + while (i < nBytes && ok) {
735 - if(dev->checkpointByteOffset < 0 ||
736 - dev->checkpointByteOffset >= dev->nDataBytesPerChunk) {
737 + if (dev->checkpointByteOffset < 0 ||
738 + dev->checkpointByteOffset >= dev->nDataBytesPerChunk) {
740 - if(dev->checkpointCurrentBlock < 0){
741 + if (dev->checkpointCurrentBlock < 0) {
742 yaffs_CheckpointFindNextCheckpointBlock(dev);
743 dev->checkpointCurrentChunk = 0;
746 - if(dev->checkpointCurrentBlock < 0)
747 + if (dev->checkpointCurrentBlock < 0)
751 - chunk = dev->checkpointCurrentBlock * dev->nChunksPerBlock +
752 - dev->checkpointCurrentChunk;
753 + chunk = dev->checkpointCurrentBlock *
754 + dev->nChunksPerBlock +
755 + dev->checkpointCurrentChunk;
757 realignedChunk = chunk - dev->chunkOffset;
759 - /* read in the next chunk */
760 - /* printf("read checkpoint page %d\n",dev->checkpointPage); */
761 - dev->readChunkWithTagsFromNAND(dev, realignedChunk,
762 - dev->checkpointBuffer,
765 - if(tags.chunkId != (dev->checkpointPageSequence + 1) ||
766 - tags.sequenceNumber != YAFFS_SEQUENCE_CHECKPOINT_DATA)
768 + /* read in the next chunk */
769 + /* printf("read checkpoint page %d\n",dev->checkpointPage); */
770 + dev->readChunkWithTagsFromNAND(dev,
772 + dev->checkpointBuffer,
775 + if (tags.chunkId != (dev->checkpointPageSequence + 1) ||
776 + tags.eccResult > YAFFS_ECC_RESULT_FIXED ||
777 + tags.sequenceNumber != YAFFS_SEQUENCE_CHECKPOINT_DATA)
780 dev->checkpointByteOffset = 0;
781 dev->checkpointPageSequence++;
782 dev->checkpointCurrentChunk++;
784 - if(dev->checkpointCurrentChunk >= dev->nChunksPerBlock)
785 + if (dev->checkpointCurrentChunk >= dev->nChunksPerBlock)
786 dev->checkpointCurrentBlock = -1;
792 *dataBytes = dev->checkpointBuffer[dev->checkpointByteOffset];
793 dev->checkpointSum += *dataBytes;
794 dev->checkpointXor ^= *dataBytes;
795 @@ -353,17 +345,17 @@ int yaffs_CheckpointRead(yaffs_Device *d
796 int yaffs_CheckpointClose(yaffs_Device *dev)
799 - if(dev->checkpointOpenForWrite){
800 - if(dev->checkpointByteOffset != 0)
801 + if (dev->checkpointOpenForWrite) {
802 + if (dev->checkpointByteOffset != 0)
803 yaffs_CheckpointFlushBuffer(dev);
806 - for(i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++){
807 - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,dev->checkpointBlockList[i]);
808 - if(bi->blockState == YAFFS_BLOCK_STATE_EMPTY)
809 + for (i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++) {
810 + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointBlockList[i]);
811 + if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY)
812 bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT;
814 - // Todo this looks odd...
815 + /* Todo this looks odd... */
818 YFREE(dev->checkpointBlockList);
819 @@ -374,27 +366,25 @@ int yaffs_CheckpointClose(yaffs_Device *
820 dev->nErasedBlocks -= dev->blocksInCheckpoint;
823 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checkpoint byte count %d" TENDSTR),
824 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint byte count %d" TENDSTR),
825 dev->checkpointByteCount));
827 - if(dev->checkpointBuffer){
828 + if (dev->checkpointBuffer) {
829 /* free the buffer */
830 YFREE(dev->checkpointBuffer);
831 dev->checkpointBuffer = NULL;
840 int yaffs_CheckpointInvalidateStream(yaffs_Device *dev)
842 /* Erase the first checksum block */
844 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("checkpoint invalidate"TENDSTR)));
845 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate"TENDSTR)));
847 - if(!yaffs_CheckpointSpaceOk(dev))
848 + if (!yaffs_CheckpointSpaceOk(dev))
851 return yaffs_CheckpointErase(dev);
852 --- a/fs/yaffs2/yaffs_checkptrw.h
853 +++ b/fs/yaffs2/yaffs_checkptrw.h
856 int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting);
858 -int yaffs_CheckpointWrite(yaffs_Device *dev,const void *data, int nBytes);
859 +int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes);
861 -int yaffs_CheckpointRead(yaffs_Device *dev,void *data, int nBytes);
862 +int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes);
864 int yaffs_GetCheckpointSum(yaffs_Device *dev, __u32 *sum);
866 --- a/fs/yaffs2/yaffs_ecc.c
867 +++ b/fs/yaffs2/yaffs_ecc.c
871 const char *yaffs_ecc_c_version =
872 - "$Id: yaffs_ecc.c,v 1.9 2007-02-14 01:09:06 wookey Exp $";
873 + "$Id: yaffs_ecc.c,v 1.11 2009-03-06 17:20:50 wookey Exp $";
875 #include "yportenv.h"
877 @@ -109,12 +109,10 @@ void yaffs_ECCCalculate(const unsigned c
878 b = column_parity_table[*data++];
881 - if (b & 0x01) // odd number of bits in the byte
883 + if (b & 0x01) { /* odd number of bits in the byte */
885 line_parity_prime ^= ~i;
890 ecc[2] = (~col_parity) | 0x03;
891 @@ -158,7 +156,7 @@ void yaffs_ECCCalculate(const unsigned c
894 #ifdef CONFIG_YAFFS_ECC_WRONG_ORDER
895 - // Swap the bytes into the wrong order
896 + /* Swap the bytes into the wrong order */
900 @@ -189,7 +187,7 @@ int yaffs_ECCCorrect(unsigned char *data
903 #ifdef CONFIG_YAFFS_ECC_WRONG_ORDER
904 - // swap the bytes to correct for the wrong order
905 + /* swap the bytes to correct for the wrong order */
909 @@ -251,7 +249,7 @@ int yaffs_ECCCorrect(unsigned char *data
910 * ECCxxxOther does ECC calcs on arbitrary n bytes of data
912 void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes,
913 - yaffs_ECCOther * eccOther)
914 + yaffs_ECCOther *eccOther)
918 @@ -278,8 +276,8 @@ void yaffs_ECCCalculateOther(const unsig
921 int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes,
922 - yaffs_ECCOther * read_ecc,
923 - const yaffs_ECCOther * test_ecc)
924 + yaffs_ECCOther *read_ecc,
925 + const yaffs_ECCOther *test_ecc)
927 unsigned char cDelta; /* column parity delta */
928 unsigned lDelta; /* line parity delta */
929 @@ -294,8 +292,7 @@ int yaffs_ECCCorrectOther(unsigned char
930 return 0; /* no error */
932 if (lDelta == ~lDeltaPrime &&
933 - (((cDelta ^ (cDelta >> 1)) & 0x15) == 0x15))
935 + (((cDelta ^ (cDelta >> 1)) & 0x15) == 0x15)) {
936 /* Single bit (recoverable) error in data */
939 @@ -307,7 +304,7 @@ int yaffs_ECCCorrectOther(unsigned char
943 - if(lDelta >= nBytes)
944 + if (lDelta >= nBytes)
947 data[lDelta] ^= (1 << bit);
948 @@ -316,7 +313,7 @@ int yaffs_ECCCorrectOther(unsigned char
951 if ((yaffs_CountBits32(lDelta) + yaffs_CountBits32(lDeltaPrime) +
952 - yaffs_CountBits(cDelta)) == 1) {
953 + yaffs_CountBits(cDelta)) == 1) {
954 /* Reccoverable error in ecc */
956 *read_ecc = *test_ecc;
957 @@ -326,6 +323,4 @@ int yaffs_ECCCorrectOther(unsigned char
958 /* Unrecoverable error */
964 --- a/fs/yaffs2/yaffs_ecc.h
965 +++ b/fs/yaffs2/yaffs_ecc.h
967 * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
971 - * This code implements the ECC algorithm used in SmartMedia.
973 - * The ECC comprises 22 bits of parity information and is stuffed into 3 bytes.
974 - * The two unused bit are set to 1.
975 - * The ECC can correct single bit errors in a 256-byte page of data. Thus, two such ECC
976 - * blocks are used on a 512-byte NAND page.
980 + * This code implements the ECC algorithm used in SmartMedia.
982 + * The ECC comprises 22 bits of parity information and is stuffed into 3 bytes.
983 + * The two unused bit are set to 1.
984 + * The ECC can correct single bit errors in a 256-byte page of data. Thus, two such ECC
985 + * blocks are used on a 512-byte NAND page.
989 #ifndef __YAFFS_ECC_H__
990 #define __YAFFS_ECC_H__
991 @@ -34,11 +34,11 @@ typedef struct {
993 void yaffs_ECCCalculate(const unsigned char *data, unsigned char *ecc);
994 int yaffs_ECCCorrect(unsigned char *data, unsigned char *read_ecc,
995 - const unsigned char *test_ecc);
996 + const unsigned char *test_ecc);
998 void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes,
999 - yaffs_ECCOther * ecc);
1000 + yaffs_ECCOther *ecc);
1001 int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes,
1002 - yaffs_ECCOther * read_ecc,
1003 - const yaffs_ECCOther * test_ecc);
1004 + yaffs_ECCOther *read_ecc,
1005 + const yaffs_ECCOther *test_ecc);
1007 --- a/fs/yaffs2/yaffs_fs.c
1008 +++ b/fs/yaffs2/yaffs_fs.c
1011 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
1013 - * Copyright (C) 2002-2007 Aleph One Ltd.
1014 + * Copyright (C) 2002-2009 Aleph One Ltd.
1015 * for Toby Churchill Ltd and Brightstar Engineering
1017 * Created by Charles Manning <charles@aleph1.co.uk>
1021 const char *yaffs_fs_c_version =
1022 - "$Id: yaffs_fs.c,v 1.63 2007-09-19 20:35:40 imcd Exp $";
1023 + "$Id: yaffs_fs.c,v 1.79 2009-03-17 01:12:00 wookey Exp $";
1024 extern const char *yaffs_guts_c_version;
1026 #include <linux/version.h>
1027 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
1028 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
1029 #include <linux/config.h>
1031 #include <linux/kernel.h>
1032 #include <linux/module.h>
1033 #include <linux/slab.h>
1034 #include <linux/init.h>
1035 -#include <linux/list.h>
1036 #include <linux/fs.h>
1037 #include <linux/proc_fs.h>
1038 #include <linux/smp_lock.h>
1039 @@ -53,10 +52,12 @@ extern const char *yaffs_guts_c_version;
1040 #include <linux/string.h>
1041 #include <linux/ctype.h>
1043 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1044 +#include "asm/div64.h"
1046 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1048 #include <linux/statfs.h> /* Added NCB 15-8-2003 */
1049 -#include <asm/statfs.h>
1050 +#include <linux/statfs.h>
1051 #define UnlockPage(p) unlock_page(p)
1052 #define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags)
1054 @@ -69,22 +70,45 @@ extern const char *yaffs_guts_c_version;
1055 #define BDEVNAME_SIZE 0
1056 #define yaffs_devname(sb, buf) kdevname(sb->s_dev)
1058 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1059 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0))
1060 /* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */
1066 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1067 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26))
1068 +#define YPROC_ROOT (&proc_root)
1070 +#define YPROC_ROOT NULL
1073 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1074 #define WRITE_SIZE_STR "writesize"
1075 -#define WRITE_SIZE(mtd) (mtd)->writesize
1076 +#define WRITE_SIZE(mtd) ((mtd)->writesize)
1078 #define WRITE_SIZE_STR "oobblock"
1079 -#define WRITE_SIZE(mtd) (mtd)->oobblock
1080 +#define WRITE_SIZE(mtd) ((mtd)->oobblock)
1083 -#include <asm/uaccess.h>
1084 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 27))
1085 +#define YAFFS_USE_WRITE_BEGIN_END 1
1087 +#define YAFFS_USE_WRITE_BEGIN_END 0
1090 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28))
1091 +static uint32_t YCALCBLOCKS(uint64_t partition_size, uint32_t block_size)
1093 + uint64_t result = partition_size;
1094 + do_div(result, block_size);
1095 + return (uint32_t)result;
1098 +#define YCALCBLOCKS(s, b) ((s)/(b))
1101 +#include <linux/uaccess.h>
1103 #include "yportenv.h"
1104 #include "yaffs_guts.h"
1105 @@ -96,28 +120,44 @@ extern const char *yaffs_guts_c_version;
1107 unsigned int yaffs_traceMask = YAFFS_TRACE_BAD_BLOCKS;
1108 unsigned int yaffs_wr_attempts = YAFFS_WR_ATTEMPTS;
1109 +unsigned int yaffs_auto_checkpoint = 1;
1111 /* Module Parameters */
1112 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1113 -module_param(yaffs_traceMask,uint,0644);
1114 -module_param(yaffs_wr_attempts,uint,0644);
1115 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1116 +module_param(yaffs_traceMask, uint, 0644);
1117 +module_param(yaffs_wr_attempts, uint, 0644);
1118 +module_param(yaffs_auto_checkpoint, uint, 0644);
1120 +MODULE_PARM(yaffs_traceMask, "i");
1121 +MODULE_PARM(yaffs_wr_attempts, "i");
1122 +MODULE_PARM(yaffs_auto_checkpoint, "i");
1125 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25))
1126 +/* use iget and read_inode */
1127 +#define Y_IGET(sb, inum) iget((sb), (inum))
1128 +static void yaffs_read_inode(struct inode *inode);
1131 -MODULE_PARM(yaffs_traceMask,"i");
1132 -MODULE_PARM(yaffs_wr_attempts,"i");
1133 +/* Call local equivalent */
1134 +#define YAFFS_USE_OWN_IGET
1135 +#define Y_IGET(sb, inum) yaffs_iget((sb), (inum))
1137 +static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino);
1140 /*#define T(x) printk x */
1142 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
1143 -#define yaffs_InodeToObjectLV(iptr) (iptr)->i_private
1144 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
1145 +#define yaffs_InodeToObjectLV(iptr) ((iptr)->i_private)
1147 -#define yaffs_InodeToObjectLV(iptr) (iptr)->u.generic_ip
1148 +#define yaffs_InodeToObjectLV(iptr) ((iptr)->u.generic_ip)
1151 #define yaffs_InodeToObject(iptr) ((yaffs_Object *)(yaffs_InodeToObjectLV(iptr)))
1152 #define yaffs_DentryToObject(dptr) yaffs_InodeToObject((dptr)->d_inode)
1154 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1155 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1156 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->s_fs_info)
1158 #define yaffs_SuperToDevice(sb) ((yaffs_Device *)sb->u.generic_sbp)
1159 @@ -126,47 +166,49 @@ MODULE_PARM(yaffs_wr_attempts,"i");
1160 static void yaffs_put_super(struct super_block *sb);
1162 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
1165 +static ssize_t yaffs_hold_space(struct file *f);
1166 +static void yaffs_release_space(struct file *f);
1168 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1169 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1170 static int yaffs_file_flush(struct file *file, fl_owner_t id);
1172 static int yaffs_file_flush(struct file *file);
1175 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
1179 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir);
1181 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1182 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1183 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
1184 struct nameidata *n);
1185 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
1186 - struct nameidata *n);
1187 + struct nameidata *n);
1189 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode);
1190 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry);
1192 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
1193 - struct dentry *dentry);
1194 + struct dentry *dentry);
1195 static int yaffs_unlink(struct inode *dir, struct dentry *dentry);
1196 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
1197 - const char *symname);
1198 + const char *symname);
1199 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode);
1201 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1202 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1203 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1207 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
1211 static int yaffs_rename(struct inode *old_dir, struct dentry *old_dentry,
1212 struct inode *new_dir, struct dentry *new_dentry);
1213 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr);
1215 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1216 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1217 static int yaffs_sync_fs(struct super_block *sb, int wait);
1218 static void yaffs_write_super(struct super_block *sb);
1220 @@ -174,33 +216,47 @@ static int yaffs_sync_fs(struct super_bl
1221 static int yaffs_write_super(struct super_block *sb);
1224 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1225 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1226 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf);
1227 -#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1228 +#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1229 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf);
1231 static int yaffs_statfs(struct super_block *sb, struct statfs *buf);
1233 -static void yaffs_read_inode(struct inode *inode);
1235 +#ifdef YAFFS_HAS_PUT_INODE
1236 static void yaffs_put_inode(struct inode *inode);
1239 static void yaffs_delete_inode(struct inode *);
1240 static void yaffs_clear_inode(struct inode *);
1242 static int yaffs_readpage(struct file *file, struct page *page);
1243 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1244 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1245 static int yaffs_writepage(struct page *page, struct writeback_control *wbc);
1247 static int yaffs_writepage(struct page *page);
1251 +#if (YAFFS_USE_WRITE_BEGIN_END != 0)
1252 +static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
1253 + loff_t pos, unsigned len, unsigned flags,
1254 + struct page **pagep, void **fsdata);
1255 +static int yaffs_write_end(struct file *filp, struct address_space *mapping,
1256 + loff_t pos, unsigned len, unsigned copied,
1257 + struct page *pg, void *fsdadata);
1259 static int yaffs_prepare_write(struct file *f, struct page *pg,
1260 - unsigned offset, unsigned to);
1261 + unsigned offset, unsigned to);
1262 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
1266 -static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
1268 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
1271 +static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
1273 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
1274 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
1276 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd);
1277 @@ -209,12 +265,17 @@ static int yaffs_follow_link(struct dent
1278 static struct address_space_operations yaffs_file_address_operations = {
1279 .readpage = yaffs_readpage,
1280 .writepage = yaffs_writepage,
1281 +#if (YAFFS_USE_WRITE_BEGIN_END > 0)
1282 + .write_begin = yaffs_write_begin,
1283 + .write_end = yaffs_write_end,
1285 .prepare_write = yaffs_prepare_write,
1286 .commit_write = yaffs_commit_write,
1290 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,22))
1291 -static struct file_operations yaffs_file_operations = {
1292 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
1293 +static const struct file_operations yaffs_file_operations = {
1294 .read = do_sync_read,
1295 .write = do_sync_write,
1296 .aio_read = generic_file_aio_read,
1297 @@ -224,11 +285,12 @@ static struct file_operations yaffs_file
1298 .fsync = yaffs_sync_object,
1299 .splice_read = generic_file_splice_read,
1300 .splice_write = generic_file_splice_write,
1301 + .llseek = generic_file_llseek,
1304 -#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
1305 +#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
1307 -static struct file_operations yaffs_file_operations = {
1308 +static const struct file_operations yaffs_file_operations = {
1309 .read = do_sync_read,
1310 .write = do_sync_write,
1311 .aio_read = generic_file_aio_read,
1312 @@ -241,29 +303,29 @@ static struct file_operations yaffs_file
1316 -static struct file_operations yaffs_file_operations = {
1317 +static const struct file_operations yaffs_file_operations = {
1318 .read = generic_file_read,
1319 .write = generic_file_write,
1320 .mmap = generic_file_mmap,
1321 .flush = yaffs_file_flush,
1322 .fsync = yaffs_sync_object,
1323 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1324 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1325 .sendfile = generic_file_sendfile,
1330 -static struct inode_operations yaffs_file_inode_operations = {
1331 +static const struct inode_operations yaffs_file_inode_operations = {
1332 .setattr = yaffs_setattr,
1335 -static struct inode_operations yaffs_symlink_inode_operations = {
1336 +static const struct inode_operations yaffs_symlink_inode_operations = {
1337 .readlink = yaffs_readlink,
1338 .follow_link = yaffs_follow_link,
1339 .setattr = yaffs_setattr,
1342 -static struct inode_operations yaffs_dir_inode_operations = {
1343 +static const struct inode_operations yaffs_dir_inode_operations = {
1344 .create = yaffs_create,
1345 .lookup = yaffs_lookup,
1347 @@ -276,16 +338,21 @@ static struct inode_operations yaffs_dir
1348 .setattr = yaffs_setattr,
1351 -static struct file_operations yaffs_dir_operations = {
1352 +static const struct file_operations yaffs_dir_operations = {
1353 .read = generic_read_dir,
1354 .readdir = yaffs_readdir,
1355 .fsync = yaffs_sync_object,
1358 -static struct super_operations yaffs_super_ops = {
1359 +static const struct super_operations yaffs_super_ops = {
1360 .statfs = yaffs_statfs,
1362 +#ifndef YAFFS_USE_OWN_IGET
1363 .read_inode = yaffs_read_inode,
1365 +#ifdef YAFFS_HAS_PUT_INODE
1366 .put_inode = yaffs_put_inode,
1368 .put_super = yaffs_put_super,
1369 .delete_inode = yaffs_delete_inode,
1370 .clear_inode = yaffs_clear_inode,
1371 @@ -293,22 +360,21 @@ static struct super_operations yaffs_sup
1372 .write_super = yaffs_write_super,
1375 -static void yaffs_GrossLock(yaffs_Device * dev)
1376 +static void yaffs_GrossLock(yaffs_Device *dev)
1378 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs locking\n"));
1380 + T(YAFFS_TRACE_OS, ("yaffs locking %p\n", current));
1381 down(&dev->grossLock);
1382 + T(YAFFS_TRACE_OS, ("yaffs locked %p\n", current));
1385 -static void yaffs_GrossUnlock(yaffs_Device * dev)
1386 +static void yaffs_GrossUnlock(yaffs_Device *dev)
1388 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs unlocking\n"));
1389 + T(YAFFS_TRACE_OS, ("yaffs unlocking %p\n", current));
1390 up(&dev->grossLock);
1394 -static int yaffs_readlink(struct dentry *dentry, char __user * buffer,
1396 +static int yaffs_readlink(struct dentry *dentry, char __user *buffer,
1399 unsigned char *alias;
1401 @@ -329,7 +395,7 @@ static int yaffs_readlink(struct dentry
1405 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
1406 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
1407 static void *yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
1409 static int yaffs_follow_link(struct dentry *dentry, struct nameidata *nd)
1410 @@ -345,32 +411,31 @@ static int yaffs_follow_link(struct dent
1412 yaffs_GrossUnlock(dev);
1422 ret = vfs_follow_link(nd, alias);
1425 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
1426 - return ERR_PTR (ret);
1427 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
1428 + return ERR_PTR(ret);
1434 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1435 - yaffs_Object * obj);
1436 + yaffs_Object *obj);
1439 * Lookup is used to find objects in the fs
1441 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1442 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1444 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry,
1445 - struct nameidata *n)
1446 + struct nameidata *n)
1448 static struct dentry *yaffs_lookup(struct inode *dir, struct dentry *dentry)
1450 @@ -383,12 +448,11 @@ static struct dentry *yaffs_lookup(struc
1451 yaffs_GrossLock(dev);
1454 - (KERN_DEBUG "yaffs_lookup for %d:%s\n",
1455 - yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
1456 + ("yaffs_lookup for %d:%s\n",
1457 + yaffs_InodeToObject(dir)->objectId, dentry->d_name.name));
1460 - yaffs_FindObjectByName(yaffs_InodeToObject(dir),
1461 - dentry->d_name.name);
1462 + obj = yaffs_FindObjectByName(yaffs_InodeToObject(dir),
1463 + dentry->d_name.name);
1465 obj = yaffs_GetEquivalentObject(obj); /* in case it was a hardlink */
1467 @@ -397,13 +461,13 @@ static struct dentry *yaffs_lookup(struc
1471 - (KERN_DEBUG "yaffs_lookup found %d\n", obj->objectId));
1472 + ("yaffs_lookup found %d\n", obj->objectId));
1474 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
1478 - (KERN_DEBUG "yaffs_loookup dentry \n"));
1479 + ("yaffs_loookup dentry \n"));
1480 /* #if 0 asserted by NCB for 2.5/6 compatability - falls through to
1481 * d_add even if NULL inode */
1483 @@ -416,7 +480,7 @@ static struct dentry *yaffs_lookup(struc
1487 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_lookup not found\n"));
1488 + T(YAFFS_TRACE_OS, ("yaffs_lookup not found\n"));
1492 @@ -425,20 +489,22 @@ static struct dentry *yaffs_lookup(struc
1493 d_add(dentry, inode);
1496 - /* return (ERR_PTR(-EIO)); */
1501 +#ifdef YAFFS_HAS_PUT_INODE
1503 /* For now put inode is just for debugging
1504 * Put inode is called when the inode **structure** is put.
1506 static void yaffs_put_inode(struct inode *inode)
1509 - ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
1510 - atomic_read(&inode->i_count)));
1511 + ("yaffs_put_inode: ino %d, count %d\n", (int)inode->i_ino,
1512 + atomic_read(&inode->i_count)));
1517 /* clear is called to tell the fs to release any per-inode data it holds */
1518 static void yaffs_clear_inode(struct inode *inode)
1519 @@ -449,9 +515,9 @@ static void yaffs_clear_inode(struct ino
1520 obj = yaffs_InodeToObject(inode);
1523 - ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
1524 - atomic_read(&inode->i_count),
1525 - obj ? "object exists" : "null object"));
1526 + ("yaffs_clear_inode: ino %d, count %d %s\n", (int)inode->i_ino,
1527 + atomic_read(&inode->i_count),
1528 + obj ? "object exists" : "null object"));
1532 @@ -486,23 +552,23 @@ static void yaffs_delete_inode(struct in
1536 - ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
1537 - atomic_read(&inode->i_count),
1538 - obj ? "object exists" : "null object"));
1539 + ("yaffs_delete_inode: ino %d, count %d %s\n", (int)inode->i_ino,
1540 + atomic_read(&inode->i_count),
1541 + obj ? "object exists" : "null object"));
1545 yaffs_GrossLock(dev);
1546 - yaffs_DeleteFile(obj);
1547 + yaffs_DeleteObject(obj);
1548 yaffs_GrossUnlock(dev);
1550 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,13))
1551 - truncate_inode_pages (&inode->i_data, 0);
1552 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 13))
1553 + truncate_inode_pages(&inode->i_data, 0);
1558 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
1559 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
1560 static int yaffs_file_flush(struct file *file, fl_owner_t id)
1562 static int yaffs_file_flush(struct file *file)
1563 @@ -513,8 +579,8 @@ static int yaffs_file_flush(struct file
1564 yaffs_Device *dev = obj->myDev;
1567 - (KERN_DEBUG "yaffs_file_flush object %d (%s)\n", obj->objectId,
1568 - obj->dirty ? "dirty" : "clean"));
1569 + ("yaffs_file_flush object %d (%s)\n", obj->objectId,
1570 + obj->dirty ? "dirty" : "clean"));
1572 yaffs_GrossLock(dev);
1574 @@ -535,15 +601,15 @@ static int yaffs_readpage_nolock(struct
1578 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage at %08x, size %08x\n",
1579 - (unsigned)(pg->index << PAGE_CACHE_SHIFT),
1580 - (unsigned)PAGE_CACHE_SIZE));
1581 + T(YAFFS_TRACE_OS, ("yaffs_readpage at %08x, size %08x\n",
1582 + (unsigned)(pg->index << PAGE_CACHE_SHIFT),
1583 + (unsigned)PAGE_CACHE_SIZE));
1585 obj = yaffs_DentryToObject(f->f_dentry);
1589 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1590 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1591 BUG_ON(!PageLocked(pg));
1593 if (!PageLocked(pg))
1594 @@ -555,9 +621,9 @@ static int yaffs_readpage_nolock(struct
1596 yaffs_GrossLock(dev);
1599 - yaffs_ReadDataFromFile(obj, pg_buf, pg->index << PAGE_CACHE_SHIFT,
1601 + ret = yaffs_ReadDataFromFile(obj, pg_buf,
1602 + pg->index << PAGE_CACHE_SHIFT,
1605 yaffs_GrossUnlock(dev);
1607 @@ -575,7 +641,7 @@ static int yaffs_readpage_nolock(struct
1608 flush_dcache_page(pg);
1611 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_readpage done\n"));
1612 + T(YAFFS_TRACE_OS, ("yaffs_readpage done\n"));
1616 @@ -593,7 +659,7 @@ static int yaffs_readpage(struct file *f
1618 /* writepage inspired by/stolen from smbfs */
1620 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1621 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1622 static int yaffs_writepage(struct page *page, struct writeback_control *wbc)
1624 static int yaffs_writepage(struct page *page)
1625 @@ -616,12 +682,11 @@ static int yaffs_writepage(struct page *
1627 if (offset > inode->i_size) {
1630 - "yaffs_writepage at %08x, inode size = %08x!!!\n",
1631 - (unsigned)(page->index << PAGE_CACHE_SHIFT),
1632 - (unsigned)inode->i_size));
1633 + ("yaffs_writepage at %08x, inode size = %08x!!!\n",
1634 + (unsigned)(page->index << PAGE_CACHE_SHIFT),
1635 + (unsigned)inode->i_size));
1637 - (KERN_DEBUG " -> don't care!!\n"));
1638 + (" -> don't care!!\n"));
1642 @@ -629,11 +694,10 @@ static int yaffs_writepage(struct page *
1643 end_index = inode->i_size >> PAGE_CACHE_SHIFT;
1646 - if (page->index < end_index) {
1647 + if (page->index < end_index)
1648 nBytes = PAGE_CACHE_SIZE;
1651 nBytes = inode->i_size & (PAGE_CACHE_SIZE - 1);
1656 @@ -643,19 +707,18 @@ static int yaffs_writepage(struct page *
1657 yaffs_GrossLock(obj->myDev);
1660 - (KERN_DEBUG "yaffs_writepage at %08x, size %08x\n",
1661 - (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
1662 + ("yaffs_writepage at %08x, size %08x\n",
1663 + (unsigned)(page->index << PAGE_CACHE_SHIFT), nBytes));
1665 - (KERN_DEBUG "writepag0: obj = %05x, ino = %05x\n",
1666 - (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
1667 + ("writepag0: obj = %05x, ino = %05x\n",
1668 + (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
1671 - yaffs_WriteDataToFile(obj, buffer, page->index << PAGE_CACHE_SHIFT,
1673 + nWritten = yaffs_WriteDataToFile(obj, buffer,
1674 + page->index << PAGE_CACHE_SHIFT, nBytes, 0);
1677 - (KERN_DEBUG "writepag1: obj = %05x, ino = %05x\n",
1678 - (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
1679 + ("writepag1: obj = %05x, ino = %05x\n",
1680 + (int)obj->variant.fileVariant.fileSize, (int)inode->i_size));
1682 yaffs_GrossUnlock(obj->myDev);
1684 @@ -667,100 +730,207 @@ static int yaffs_writepage(struct page *
1685 return (nWritten == nBytes) ? 0 : -ENOSPC;
1689 +#if (YAFFS_USE_WRITE_BEGIN_END > 0)
1690 +static int yaffs_write_begin(struct file *filp, struct address_space *mapping,
1691 + loff_t pos, unsigned len, unsigned flags,
1692 + struct page **pagep, void **fsdata)
1694 + struct page *pg = NULL;
1695 + pgoff_t index = pos >> PAGE_CACHE_SHIFT;
1696 + uint32_t offset = pos & (PAGE_CACHE_SIZE - 1);
1697 + uint32_t to = offset + len;
1700 + int space_held = 0;
1702 + T(YAFFS_TRACE_OS, ("start yaffs_write_begin\n"));
1704 +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 28)
1705 + pg = grab_cache_page_write_begin(mapping, index, flags);
1707 + pg = __grab_cache_page(mapping, index);
1715 + /* Get fs space */
1716 + space_held = yaffs_hold_space(filp);
1718 + if (!space_held) {
1723 + /* Update page if required */
1725 + if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
1726 + ret = yaffs_readpage_nolock(filp, pg);
1731 + /* Happy path return */
1732 + T(YAFFS_TRACE_OS, ("end yaffs_write_begin - ok\n"));
1737 + T(YAFFS_TRACE_OS, ("end yaffs_write_begin fail returning %d\n", ret));
1739 + yaffs_release_space(filp);
1742 + page_cache_release(pg);
1749 static int yaffs_prepare_write(struct file *f, struct page *pg,
1750 - unsigned offset, unsigned to)
1751 + unsigned offset, unsigned to)
1753 + T(YAFFS_TRACE_OS, ("yaffs_prepair_write\n"));
1755 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_prepair_write\n"));
1756 if (!Page_Uptodate(pg) && (offset || to < PAGE_CACHE_SIZE))
1757 return yaffs_readpage_nolock(f, pg);
1763 +#if (YAFFS_USE_WRITE_BEGIN_END > 0)
1764 +static int yaffs_write_end(struct file *filp, struct address_space *mapping,
1765 + loff_t pos, unsigned len, unsigned copied,
1766 + struct page *pg, void *fsdadata)
1770 + uint32_t offset_into_page = pos & (PAGE_CACHE_SIZE - 1);
1773 + addr = kva + offset_into_page;
1776 + ("yaffs_write_end addr %x pos %x nBytes %d\n",
1778 + (int)pos, copied));
1780 + ret = yaffs_file_write(filp, addr, copied, &pos);
1782 + if (ret != copied) {
1784 + ("yaffs_write_end not same size ret %d copied %d\n",
1787 + ClearPageUptodate(pg);
1789 + SetPageUptodate(pg);
1794 + yaffs_release_space(filp);
1796 + page_cache_release(pg);
1801 static int yaffs_commit_write(struct file *f, struct page *pg, unsigned offset,
1807 - void *addr = page_address(pg) + offset;
1808 loff_t pos = (((loff_t) pg->index) << PAGE_CACHE_SHIFT) + offset;
1809 int nBytes = to - offset;
1812 unsigned spos = pos;
1813 - unsigned saddr = (unsigned)addr;
1817 + addr = kva + offset;
1819 + saddr = (unsigned) addr;
1822 - (KERN_DEBUG "yaffs_commit_write addr %x pos %x nBytes %d\n", saddr,
1824 + ("yaffs_commit_write addr %x pos %x nBytes %d\n",
1825 + saddr, spos, nBytes));
1827 nWritten = yaffs_file_write(f, addr, nBytes, &pos);
1829 if (nWritten != nBytes) {
1832 - "yaffs_commit_write not same size nWritten %d nBytes %d\n",
1833 - nWritten, nBytes));
1834 + ("yaffs_commit_write not same size nWritten %d nBytes %d\n",
1835 + nWritten, nBytes));
1837 ClearPageUptodate(pg);
1839 SetPageUptodate(pg);
1845 - (KERN_DEBUG "yaffs_commit_write returning %d\n",
1846 - nWritten == nBytes ? 0 : nWritten));
1847 + ("yaffs_commit_write returning %d\n",
1848 + nWritten == nBytes ? 0 : nWritten));
1850 return nWritten == nBytes ? 0 : nWritten;
1856 -static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj)
1857 +static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object *obj)
1862 /* Check mode against the variant type and attempt to repair if broken. */
1863 - __u32 mode = obj->yst_mode;
1864 - switch( obj->variantType ){
1865 - case YAFFS_OBJECT_TYPE_FILE :
1866 - if( ! S_ISREG(mode) ){
1867 - obj->yst_mode &= ~S_IFMT;
1868 - obj->yst_mode |= S_IFREG;
1872 - case YAFFS_OBJECT_TYPE_SYMLINK :
1873 - if( ! S_ISLNK(mode) ){
1874 - obj->yst_mode &= ~S_IFMT;
1875 - obj->yst_mode |= S_IFLNK;
1879 - case YAFFS_OBJECT_TYPE_DIRECTORY :
1880 - if( ! S_ISDIR(mode) ){
1881 - obj->yst_mode &= ~S_IFMT;
1882 - obj->yst_mode |= S_IFDIR;
1886 - case YAFFS_OBJECT_TYPE_UNKNOWN :
1887 - case YAFFS_OBJECT_TYPE_HARDLINK :
1888 - case YAFFS_OBJECT_TYPE_SPECIAL :
1893 + __u32 mode = obj->yst_mode;
1894 + switch (obj->variantType) {
1895 + case YAFFS_OBJECT_TYPE_FILE:
1896 + if (!S_ISREG(mode)) {
1897 + obj->yst_mode &= ~S_IFMT;
1898 + obj->yst_mode |= S_IFREG;
1902 + case YAFFS_OBJECT_TYPE_SYMLINK:
1903 + if (!S_ISLNK(mode)) {
1904 + obj->yst_mode &= ~S_IFMT;
1905 + obj->yst_mode |= S_IFLNK;
1909 + case YAFFS_OBJECT_TYPE_DIRECTORY:
1910 + if (!S_ISDIR(mode)) {
1911 + obj->yst_mode &= ~S_IFMT;
1912 + obj->yst_mode |= S_IFDIR;
1916 + case YAFFS_OBJECT_TYPE_UNKNOWN:
1917 + case YAFFS_OBJECT_TYPE_HARDLINK:
1918 + case YAFFS_OBJECT_TYPE_SPECIAL:
1924 + inode->i_flags |= S_NOATIME;
1926 inode->i_ino = obj->objectId;
1927 inode->i_mode = obj->yst_mode;
1928 inode->i_uid = obj->yst_uid;
1929 inode->i_gid = obj->yst_gid;
1930 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
1931 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
1932 inode->i_blksize = inode->i_sb->s_blocksize;
1934 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1935 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1937 inode->i_rdev = old_decode_dev(obj->yst_rdev);
1938 inode->i_atime.tv_sec = (time_t) (obj->yst_atime);
1939 @@ -781,26 +951,25 @@ static void yaffs_FillInodeFromObject(st
1940 inode->i_nlink = yaffs_GetObjectLinkCount(obj);
1944 - "yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
1945 - inode->i_mode, inode->i_uid, inode->i_gid,
1946 - (int)inode->i_size, atomic_read(&inode->i_count)));
1947 + ("yaffs_FillInode mode %x uid %d gid %d size %d count %d\n",
1948 + inode->i_mode, inode->i_uid, inode->i_gid,
1949 + (int)inode->i_size, atomic_read(&inode->i_count)));
1951 switch (obj->yst_mode & S_IFMT) {
1952 default: /* fifo, device or socket */
1953 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1954 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
1955 init_special_inode(inode, obj->yst_mode,
1956 - old_decode_dev(obj->yst_rdev));
1957 + old_decode_dev(obj->yst_rdev));
1959 init_special_inode(inode, obj->yst_mode,
1960 - (dev_t) (obj->yst_rdev));
1961 + (dev_t) (obj->yst_rdev));
1964 case S_IFREG: /* file */
1965 inode->i_op = &yaffs_file_inode_operations;
1966 inode->i_fop = &yaffs_file_operations;
1967 inode->i_mapping->a_ops =
1968 - &yaffs_file_address_operations;
1969 + &yaffs_file_address_operations;
1971 case S_IFDIR: /* directory */
1972 inode->i_op = &yaffs_dir_inode_operations;
1973 @@ -817,34 +986,36 @@ static void yaffs_FillInodeFromObject(st
1977 - (KERN_DEBUG "yaffs_FileInode invalid parameters\n"));
1978 + ("yaffs_FileInode invalid parameters\n"));
1983 struct inode *yaffs_get_inode(struct super_block *sb, int mode, int dev,
1984 - yaffs_Object * obj)
1985 + yaffs_Object *obj)
1987 struct inode *inode;
1991 - (KERN_DEBUG "yaffs_get_inode for NULL super_block!!\n"));
1992 + ("yaffs_get_inode for NULL super_block!!\n"));
1999 - (KERN_DEBUG "yaffs_get_inode for NULL object!!\n"));
2000 + ("yaffs_get_inode for NULL object!!\n"));
2006 - (KERN_DEBUG "yaffs_get_inode for object %d\n", obj->objectId));
2007 + ("yaffs_get_inode for object %d\n", obj->objectId));
2009 - inode = iget(sb, obj->objectId);
2010 + inode = Y_IGET(sb, obj->objectId);
2011 + if (IS_ERR(inode))
2014 /* NB Side effect: iget calls back to yaffs_read_inode(). */
2015 /* iget also increments the inode's i_count */
2016 @@ -854,7 +1025,7 @@ struct inode *yaffs_get_inode(struct sup
2019 static ssize_t yaffs_file_write(struct file *f, const char *buf, size_t n,
2025 @@ -869,28 +1040,26 @@ static ssize_t yaffs_file_write(struct f
2027 inode = f->f_dentry->d_inode;
2029 - if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND) {
2030 + if (!S_ISBLK(inode->i_mode) && f->f_flags & O_APPEND)
2031 ipos = inode->i_size;
2040 - (KERN_DEBUG "yaffs_file_write: hey obj is null!\n"));
2042 + ("yaffs_file_write: hey obj is null!\n"));
2046 - "yaffs_file_write about to write writing %d bytes"
2047 - "to object %d at %d\n",
2048 - n, obj->objectId, ipos));
2050 + ("yaffs_file_write about to write writing %zu bytes"
2051 + "to object %d at %d\n",
2052 + n, obj->objectId, ipos));
2054 nWritten = yaffs_WriteDataToFile(obj, buf, ipos, n, 0);
2057 - (KERN_DEBUG "yaffs_file_write writing %d bytes, %d written at %d\n",
2058 - n, nWritten, ipos));
2059 + ("yaffs_file_write writing %zu bytes, %d written at %d\n",
2060 + n, nWritten, ipos));
2065 @@ -899,10 +1068,9 @@ static ssize_t yaffs_file_write(struct f
2066 inode->i_blocks = (ipos + 511) >> 9;
2070 - "yaffs_file_write size updated to %d bytes, "
2072 - ipos, (int)(inode->i_blocks)));
2073 + ("yaffs_file_write size updated to %d bytes, "
2075 + ipos, (int)(inode->i_blocks)));
2079 @@ -910,13 +1078,54 @@ static ssize_t yaffs_file_write(struct f
2080 return nWritten == 0 ? -ENOSPC : nWritten;
2083 +/* Space holding and freeing is done to ensure we have space available for write_begin/end */
2084 +/* For now we just assume few parallel writes and check against a small number. */
2085 +/* Todo: need to do this with a counter to handle parallel reads better */
2087 +static ssize_t yaffs_hold_space(struct file *f)
2089 + yaffs_Object *obj;
2090 + yaffs_Device *dev;
2095 + obj = yaffs_DentryToObject(f->f_dentry);
2099 + yaffs_GrossLock(dev);
2101 + nFreeChunks = yaffs_GetNumberOfFreeChunks(dev);
2103 + yaffs_GrossUnlock(dev);
2105 + return (nFreeChunks > 20) ? 1 : 0;
2108 +static void yaffs_release_space(struct file *f)
2110 + yaffs_Object *obj;
2111 + yaffs_Device *dev;
2114 + obj = yaffs_DentryToObject(f->f_dentry);
2118 + yaffs_GrossLock(dev);
2121 + yaffs_GrossUnlock(dev);
2124 static int yaffs_readdir(struct file *f, void *dirent, filldir_t filldir)
2128 struct inode *inode = f->f_dentry->d_inode;
2129 unsigned long offset, curoffs;
2130 - struct list_head *i;
2131 + struct ylist_head *i;
2134 char name[YAFFS_MAX_NAME_LENGTH + 1];
2135 @@ -932,24 +1141,20 @@ static int yaffs_readdir(struct file *f,
2139 - (KERN_DEBUG "yaffs_readdir: entry . ino %d \n",
2140 - (int)inode->i_ino));
2141 - if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR)
2143 + ("yaffs_readdir: entry . ino %d \n",
2144 + (int)inode->i_ino));
2145 + if (filldir(dirent, ".", 1, offset, inode->i_ino, DT_DIR) < 0)
2153 - (KERN_DEBUG "yaffs_readdir: entry .. ino %d \n",
2154 - (int)f->f_dentry->d_parent->d_inode->i_ino));
2156 - (dirent, "..", 2, offset,
2157 - f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0) {
2158 + ("yaffs_readdir: entry .. ino %d \n",
2159 + (int)f->f_dentry->d_parent->d_inode->i_ino));
2160 + if (filldir(dirent, "..", 2, offset,
2161 + f->f_dentry->d_parent->d_inode->i_ino, DT_DIR) < 0)
2167 @@ -965,35 +1170,32 @@ static int yaffs_readdir(struct file *f,
2168 f->f_version = inode->i_version;
2171 - list_for_each(i, &obj->variant.directoryVariant.children) {
2172 + ylist_for_each(i, &obj->variant.directoryVariant.children) {
2174 if (curoffs >= offset) {
2175 - l = list_entry(i, yaffs_Object, siblings);
2176 + l = ylist_entry(i, yaffs_Object, siblings);
2178 yaffs_GetObjectName(l, name,
2179 YAFFS_MAX_NAME_LENGTH + 1);
2181 - (KERN_DEBUG "yaffs_readdir: %s inode %d\n", name,
2182 + ("yaffs_readdir: %s inode %d\n", name,
2183 yaffs_GetObjectInode(l)));
2189 - yaffs_GetObjectInode(l),
2190 - yaffs_GetObjectType(l))
2195 + yaffs_GetObjectInode(l),
2196 + yaffs_GetObjectType(l)) < 0)
2210 yaffs_GrossUnlock(dev);
2213 @@ -1002,12 +1204,19 @@ static int yaffs_readdir(struct file *f,
2215 * File creation. Allocate an inode, and we're done..
2217 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2219 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2222 +#define YCRED(x) (x->cred)
2225 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2226 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
2230 static int yaffs_mknod(struct inode *dir, struct dentry *dentry, int mode,
2235 struct inode *inode;
2236 @@ -1018,25 +1227,25 @@ static int yaffs_mknod(struct inode *dir
2237 yaffs_Object *parent = yaffs_InodeToObject(dir);
2239 int error = -ENOSPC;
2240 - uid_t uid = current->fsuid;
2241 - gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
2242 + uid_t uid = YCRED(current)->fsuid;
2243 + gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
2245 - if((dir->i_mode & S_ISGID) && S_ISDIR(mode))
2246 + if ((dir->i_mode & S_ISGID) && S_ISDIR(mode))
2251 - (KERN_DEBUG "yaffs_mknod: parent object %d type %d\n",
2252 - parent->objectId, parent->variantType));
2253 + ("yaffs_mknod: parent object %d type %d\n",
2254 + parent->objectId, parent->variantType));
2257 - (KERN_DEBUG "yaffs_mknod: could not get parent object\n"));
2258 + ("yaffs_mknod: could not get parent object\n"));
2262 T(YAFFS_TRACE_OS, ("yaffs_mknod: making oject for %s, "
2263 - "mode %x dev %x\n",
2264 - dentry->d_name.name, mode, rdev));
2265 + "mode %x dev %x\n",
2266 + dentry->d_name.name, mode, rdev));
2268 dev = parent->myDev;
2270 @@ -1045,33 +1254,28 @@ static int yaffs_mknod(struct inode *dir
2271 switch (mode & S_IFMT) {
2273 /* Special (socket, fifo, device...) */
2274 - T(YAFFS_TRACE_OS, (KERN_DEBUG
2275 - "yaffs_mknod: making special\n"));
2276 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2278 - yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
2279 - gid, old_encode_dev(rdev));
2282 - yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
2284 + T(YAFFS_TRACE_OS, ("yaffs_mknod: making special\n"));
2285 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2286 + obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
2287 + gid, old_encode_dev(rdev));
2289 + obj = yaffs_MknodSpecial(parent, dentry->d_name.name, mode, uid,
2293 case S_IFREG: /* file */
2294 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
2296 - yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
2298 + T(YAFFS_TRACE_OS, ("yaffs_mknod: making file\n"));
2299 + obj = yaffs_MknodFile(parent, dentry->d_name.name, mode, uid,
2302 case S_IFDIR: /* directory */
2304 - (KERN_DEBUG "yaffs_mknod: making directory\n"));
2306 - yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
2308 + ("yaffs_mknod: making directory\n"));
2309 + obj = yaffs_MknodDirectory(parent, dentry->d_name.name, mode,
2312 case S_IFLNK: /* symlink */
2313 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mknod: making file\n"));
2314 + T(YAFFS_TRACE_OS, ("yaffs_mknod: making symlink\n"));
2315 obj = NULL; /* Do we ever get here? */
2318 @@ -1083,12 +1287,12 @@ static int yaffs_mknod(struct inode *dir
2319 inode = yaffs_get_inode(dir->i_sb, mode, rdev, obj);
2320 d_instantiate(dentry, inode);
2322 - (KERN_DEBUG "yaffs_mknod created object %d count = %d\n",
2323 - obj->objectId, atomic_read(&inode->i_count)));
2324 + ("yaffs_mknod created object %d count = %d\n",
2325 + obj->objectId, atomic_read(&inode->i_count)));
2329 - (KERN_DEBUG "yaffs_mknod failed making object\n"));
2330 + ("yaffs_mknod failed making object\n"));
2334 @@ -1098,25 +1302,19 @@ static int yaffs_mknod(struct inode *dir
2335 static int yaffs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
2338 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_mkdir\n"));
2339 + T(YAFFS_TRACE_OS, ("yaffs_mkdir\n"));
2340 retVal = yaffs_mknod(dir, dentry, mode | S_IFDIR, 0);
2342 - /* attempt to fix dir bug - didn't work */
2350 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2351 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2352 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode,
2353 struct nameidata *n)
2355 static int yaffs_create(struct inode *dir, struct dentry *dentry, int mode)
2358 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_create\n"));
2359 + T(YAFFS_TRACE_OS, ("yaffs_create\n"));
2360 return yaffs_mknod(dir, dentry, mode | S_IFREG, 0);
2363 @@ -1127,8 +1325,8 @@ static int yaffs_unlink(struct inode *di
2367 - (KERN_DEBUG "yaffs_unlink %d:%s\n", (int)(dir->i_ino),
2368 - dentry->d_name.name));
2369 + ("yaffs_unlink %d:%s\n", (int)(dir->i_ino),
2370 + dentry->d_name.name));
2372 dev = yaffs_InodeToObject(dir)->myDev;
2374 @@ -1151,82 +1349,74 @@ static int yaffs_unlink(struct inode *di
2377 static int yaffs_link(struct dentry *old_dentry, struct inode *dir,
2378 - struct dentry *dentry)
2379 + struct dentry *dentry)
2381 struct inode *inode = old_dentry->d_inode;
2382 yaffs_Object *obj = NULL;
2383 yaffs_Object *link = NULL;
2386 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_link\n"));
2387 + T(YAFFS_TRACE_OS, ("yaffs_link\n"));
2389 obj = yaffs_InodeToObject(inode);
2392 yaffs_GrossLock(dev);
2394 - if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
2397 - yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
2400 + if (!S_ISDIR(inode->i_mode)) /* Don't link directories */
2401 + link = yaffs_Link(yaffs_InodeToObject(dir), dentry->d_name.name,
2405 old_dentry->d_inode->i_nlink = yaffs_GetObjectLinkCount(obj);
2406 d_instantiate(dentry, old_dentry->d_inode);
2407 atomic_inc(&old_dentry->d_inode->i_count);
2409 - (KERN_DEBUG "yaffs_link link count %d i_count %d\n",
2410 - old_dentry->d_inode->i_nlink,
2411 - atomic_read(&old_dentry->d_inode->i_count)));
2413 + ("yaffs_link link count %d i_count %d\n",
2414 + old_dentry->d_inode->i_nlink,
2415 + atomic_read(&old_dentry->d_inode->i_count)));
2418 yaffs_GrossUnlock(dev);
2429 static int yaffs_symlink(struct inode *dir, struct dentry *dentry,
2430 - const char *symname)
2431 + const char *symname)
2435 - uid_t uid = current->fsuid;
2436 - gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : current->fsgid;
2437 + uid_t uid = YCRED(current)->fsuid;
2438 + gid_t gid = (dir->i_mode & S_ISGID) ? dir->i_gid : YCRED(current)->fsgid;
2440 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_symlink\n"));
2441 + T(YAFFS_TRACE_OS, ("yaffs_symlink\n"));
2443 dev = yaffs_InodeToObject(dir)->myDev;
2444 yaffs_GrossLock(dev);
2445 obj = yaffs_MknodSymLink(yaffs_InodeToObject(dir), dentry->d_name.name,
2446 - S_IFLNK | S_IRWXUGO, uid, gid, symname);
2447 + S_IFLNK | S_IRWXUGO, uid, gid, symname);
2448 yaffs_GrossUnlock(dev);
2452 struct inode *inode;
2454 inode = yaffs_get_inode(dir->i_sb, obj->yst_mode, 0, obj);
2455 d_instantiate(dentry, inode);
2456 - T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink created OK\n"));
2457 + T(YAFFS_TRACE_OS, ("symlink created OK\n"));
2460 - T(YAFFS_TRACE_OS, (KERN_DEBUG "symlink not created\n"));
2462 + T(YAFFS_TRACE_OS, ("symlink not created\n"));
2468 static int yaffs_sync_object(struct file *file, struct dentry *dentry,
2474 @@ -1236,7 +1426,7 @@ static int yaffs_sync_object(struct file
2478 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_object\n"));
2479 + T(YAFFS_TRACE_OS, ("yaffs_sync_object\n"));
2480 yaffs_GrossLock(dev);
2481 yaffs_FlushFile(obj, 1);
2482 yaffs_GrossUnlock(dev);
2483 @@ -1255,41 +1445,36 @@ static int yaffs_rename(struct inode *ol
2484 int retVal = YAFFS_FAIL;
2485 yaffs_Object *target;
2487 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_rename\n"));
2488 + T(YAFFS_TRACE_OS, ("yaffs_rename\n"));
2489 dev = yaffs_InodeToObject(old_dir)->myDev;
2491 yaffs_GrossLock(dev);
2493 /* Check if the target is an existing directory that is not empty. */
2495 - yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
2496 - new_dentry->d_name.name);
2497 + target = yaffs_FindObjectByName(yaffs_InodeToObject(new_dir),
2498 + new_dentry->d_name.name);
2503 - target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
2504 - !list_empty(&target->variant.directoryVariant.children)) {
2505 + if (target && target->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
2506 + !ylist_empty(&target->variant.directoryVariant.children)) {
2508 - T(YAFFS_TRACE_OS, (KERN_DEBUG "target is non-empty dir\n"));
2509 + T(YAFFS_TRACE_OS, ("target is non-empty dir\n"));
2511 retVal = YAFFS_FAIL;
2514 /* Now does unlinking internally using shadowing mechanism */
2515 - T(YAFFS_TRACE_OS, (KERN_DEBUG "calling yaffs_RenameObject\n"));
2518 - yaffs_RenameObject(yaffs_InodeToObject(old_dir),
2519 - old_dentry->d_name.name,
2520 - yaffs_InodeToObject(new_dir),
2521 - new_dentry->d_name.name);
2522 + T(YAFFS_TRACE_OS, ("calling yaffs_RenameObject\n"));
2524 + retVal = yaffs_RenameObject(yaffs_InodeToObject(old_dir),
2525 + old_dentry->d_name.name,
2526 + yaffs_InodeToObject(new_dir),
2527 + new_dentry->d_name.name);
2529 yaffs_GrossUnlock(dev);
2531 if (retVal == YAFFS_OK) {
2534 new_dentry->d_inode->i_nlink--;
2535 mark_inode_dirty(new_dentry->d_inode);
2537 @@ -1298,7 +1483,6 @@ static int yaffs_rename(struct inode *ol
2544 static int yaffs_setattr(struct dentry *dentry, struct iattr *attr)
2545 @@ -1308,15 +1492,15 @@ static int yaffs_setattr(struct dentry *
2549 - (KERN_DEBUG "yaffs_setattr of object %d\n",
2550 - yaffs_InodeToObject(inode)->objectId));
2552 - if ((error = inode_change_ok(inode, attr)) == 0) {
2553 + ("yaffs_setattr of object %d\n",
2554 + yaffs_InodeToObject(inode)->objectId));
2556 + error = inode_change_ok(inode, attr);
2558 dev = yaffs_InodeToObject(inode)->myDev;
2559 yaffs_GrossLock(dev);
2560 if (yaffs_SetAttributes(yaffs_InodeToObject(inode), attr) ==
2566 @@ -1328,12 +1512,12 @@ static int yaffs_setattr(struct dentry *
2570 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2571 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2572 static int yaffs_statfs(struct dentry *dentry, struct kstatfs *buf)
2574 yaffs_Device *dev = yaffs_DentryToObject(dentry)->myDev;
2575 struct super_block *sb = dentry->d_sb;
2576 -#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2577 +#elif (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
2578 static int yaffs_statfs(struct super_block *sb, struct kstatfs *buf)
2580 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2581 @@ -1343,32 +1527,53 @@ static int yaffs_statfs(struct super_blo
2582 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2585 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_statfs\n"));
2586 + T(YAFFS_TRACE_OS, ("yaffs_statfs\n"));
2588 yaffs_GrossLock(dev);
2590 buf->f_type = YAFFS_MAGIC;
2591 buf->f_bsize = sb->s_blocksize;
2592 buf->f_namelen = 255;
2593 - if (sb->s_blocksize > dev->nDataBytesPerChunk) {
2595 + if (dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)) {
2596 + /* Do this if chunk size is not a power of 2 */
2598 + uint64_t bytesInDev;
2599 + uint64_t bytesFree;
2601 + bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock + 1))) *
2602 + ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk));
2604 + do_div(bytesInDev, sb->s_blocksize); /* bytesInDev becomes the number of blocks */
2605 + buf->f_blocks = bytesInDev;
2607 + bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) *
2608 + ((uint64_t)(dev->nDataBytesPerChunk));
2610 + do_div(bytesFree, sb->s_blocksize);
2612 + buf->f_bfree = bytesFree;
2614 + } else if (sb->s_blocksize > dev->nDataBytesPerChunk) {
2617 - (dev->endBlock - dev->startBlock +
2618 - 1) * dev->nChunksPerBlock / (sb->s_blocksize /
2619 - dev->nDataBytesPerChunk);
2620 + (dev->endBlock - dev->startBlock + 1) *
2621 + dev->nChunksPerBlock /
2622 + (sb->s_blocksize / dev->nDataBytesPerChunk);
2624 - yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize /
2625 - dev->nDataBytesPerChunk);
2626 + yaffs_GetNumberOfFreeChunks(dev) /
2627 + (sb->s_blocksize / dev->nDataBytesPerChunk);
2631 - (dev->endBlock - dev->startBlock +
2632 - 1) * dev->nChunksPerBlock * (dev->nDataBytesPerChunk /
2634 + (dev->endBlock - dev->startBlock + 1) *
2635 + dev->nChunksPerBlock *
2636 + (dev->nDataBytesPerChunk / sb->s_blocksize);
2639 - yaffs_GetNumberOfFreeChunks(dev) * (dev->nDataBytesPerChunk /
2641 + yaffs_GetNumberOfFreeChunks(dev) *
2642 + (dev->nDataBytesPerChunk / sb->s_blocksize);
2647 buf->f_bavail = buf->f_bfree;
2648 @@ -1378,18 +1583,19 @@ static int yaffs_statfs(struct super_blo
2653 static int yaffs_do_sync_fs(struct super_block *sb)
2656 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2657 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_do_sync_fs\n"));
2658 + T(YAFFS_TRACE_OS, ("yaffs_do_sync_fs\n"));
2662 yaffs_GrossLock(dev);
2666 + yaffs_FlushEntireDeviceCache(dev);
2667 yaffs_CheckpointSave(dev);
2670 yaffs_GrossUnlock(dev);
2672 @@ -1397,35 +1603,73 @@ static int yaffs_do_sync_fs(struct super
2678 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2680 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2681 static void yaffs_write_super(struct super_block *sb)
2683 static int yaffs_write_super(struct super_block *sb)
2687 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_write_super\n"));
2688 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
2689 - return 0; /* yaffs_do_sync_fs(sb);*/
2690 + T(YAFFS_TRACE_OS, ("yaffs_write_super\n"));
2691 + if (yaffs_auto_checkpoint >= 2)
2692 + yaffs_do_sync_fs(sb);
2693 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18))
2699 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2700 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
2701 static int yaffs_sync_fs(struct super_block *sb, int wait)
2703 static int yaffs_sync_fs(struct super_block *sb)
2706 + T(YAFFS_TRACE_OS, ("yaffs_sync_fs\n"));
2708 + if (yaffs_auto_checkpoint >= 1)
2709 + yaffs_do_sync_fs(sb);
2714 +#ifdef YAFFS_USE_OWN_IGET
2716 +static struct inode *yaffs_iget(struct super_block *sb, unsigned long ino)
2718 + struct inode *inode;
2719 + yaffs_Object *obj;
2720 + yaffs_Device *dev = yaffs_SuperToDevice(sb);
2723 + ("yaffs_iget for %lu\n", ino));
2725 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_sync_fs\n"));
2726 + inode = iget_locked(sb, ino);
2728 + return ERR_PTR(-ENOMEM);
2729 + if (!(inode->i_state & I_NEW))
2732 + /* NB This is called as a side effect of other functions, but
2733 + * we had to release the lock to prevent deadlocks, so
2734 + * need to lock again.
2737 - return 0; /* yaffs_do_sync_fs(sb);*/
2738 + yaffs_GrossLock(dev);
2740 + obj = yaffs_FindObjectByNumber(dev, inode->i_ino);
2742 + yaffs_FillInodeFromObject(inode, obj);
2744 + yaffs_GrossUnlock(dev);
2746 + unlock_new_inode(inode);
2752 static void yaffs_read_inode(struct inode *inode)
2754 @@ -1438,7 +1682,7 @@ static void yaffs_read_inode(struct inod
2755 yaffs_Device *dev = yaffs_SuperToDevice(inode->i_sb);
2758 - (KERN_DEBUG "yaffs_read_inode for %d\n", (int)inode->i_ino));
2759 + ("yaffs_read_inode for %d\n", (int)inode->i_ino));
2761 yaffs_GrossLock(dev);
2763 @@ -1449,18 +1693,20 @@ static void yaffs_read_inode(struct inod
2764 yaffs_GrossUnlock(dev);
2767 -static LIST_HEAD(yaffs_dev_list);
2770 +static YLIST_HEAD(yaffs_dev_list);
2773 +#if 0 /* not used */
2774 static int yaffs_remount_fs(struct super_block *sb, int *flags, char *data)
2776 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2778 - if( *flags & MS_RDONLY ) {
2779 + if (*flags & MS_RDONLY) {
2780 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2783 - (KERN_DEBUG "yaffs_remount_fs: %s: RO\n", dev->name ));
2784 + ("yaffs_remount_fs: %s: RO\n", dev->name));
2786 yaffs_GrossLock(dev);
2788 @@ -1472,10 +1718,9 @@ static int yaffs_remount_fs(struct super
2791 yaffs_GrossUnlock(dev);
2796 - (KERN_DEBUG "yaffs_remount_fs: %s: RW\n", dev->name ));
2797 + ("yaffs_remount_fs: %s: RW\n", dev->name));
2801 @@ -1486,7 +1731,7 @@ static void yaffs_put_super(struct super
2803 yaffs_Device *dev = yaffs_SuperToDevice(sb);
2805 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_put_super\n"));
2806 + T(YAFFS_TRACE_OS, ("yaffs_put_super\n"));
2808 yaffs_GrossLock(dev);
2810 @@ -1494,18 +1739,17 @@ static void yaffs_put_super(struct super
2812 yaffs_CheckpointSave(dev);
2814 - if (dev->putSuperFunc) {
2815 + if (dev->putSuperFunc)
2816 dev->putSuperFunc(sb);
2819 yaffs_Deinitialise(dev);
2821 yaffs_GrossUnlock(dev);
2823 /* we assume this is protected by lock_kernel() in mount/umount */
2824 - list_del(&dev->devList);
2825 + ylist_del(&dev->devList);
2827 - if(dev->spareBuffer){
2828 + if (dev->spareBuffer) {
2829 YFREE(dev->spareBuffer);
2830 dev->spareBuffer = NULL;
2832 @@ -1516,12 +1760,10 @@ static void yaffs_put_super(struct super
2834 static void yaffs_MTDPutSuper(struct super_block *sb)
2837 struct mtd_info *mtd = yaffs_SuperToDevice(sb)->genericDevice;
2844 put_mtd_device(mtd);
2846 @@ -1531,9 +1773,9 @@ static void yaffs_MarkSuperBlockDirty(vo
2848 struct super_block *sb = (struct super_block *)vsb;
2850 - T(YAFFS_TRACE_OS, (KERN_DEBUG "yaffs_MarkSuperBlockDirty() sb = %p\n",sb));
2853 + T(YAFFS_TRACE_OS, ("yaffs_MarkSuperBlockDirty() sb = %p\n", sb));
2859 @@ -1546,48 +1788,48 @@ typedef struct {
2860 #define MAX_OPT_LEN 20
2861 static int yaffs_parse_options(yaffs_options *options, const char *options_str)
2863 - char cur_opt[MAX_OPT_LEN+1];
2864 + char cur_opt[MAX_OPT_LEN + 1];
2868 /* Parse through the options which is a comma seperated list */
2870 - while(options_str && *options_str && !error){
2871 - memset(cur_opt,0,MAX_OPT_LEN+1);
2872 + while (options_str && *options_str && !error) {
2873 + memset(cur_opt, 0, MAX_OPT_LEN + 1);
2876 - while(*options_str && *options_str != ','){
2877 - if(p < MAX_OPT_LEN){
2878 + while (*options_str && *options_str != ',') {
2879 + if (p < MAX_OPT_LEN) {
2880 cur_opt[p] = *options_str;
2886 - if(!strcmp(cur_opt,"inband-tags"))
2887 + if (!strcmp(cur_opt, "inband-tags"))
2888 options->inband_tags = 1;
2889 - else if(!strcmp(cur_opt,"no-cache"))
2890 + else if (!strcmp(cur_opt, "no-cache"))
2891 options->no_cache = 1;
2892 - else if(!strcmp(cur_opt,"no-checkpoint-read"))
2893 + else if (!strcmp(cur_opt, "no-checkpoint-read"))
2894 options->skip_checkpoint_read = 1;
2895 - else if(!strcmp(cur_opt,"no-checkpoint-write"))
2896 + else if (!strcmp(cur_opt, "no-checkpoint-write"))
2897 options->skip_checkpoint_write = 1;
2898 - else if(!strcmp(cur_opt,"no-checkpoint")){
2899 + else if (!strcmp(cur_opt, "no-checkpoint")) {
2900 options->skip_checkpoint_read = 1;
2901 options->skip_checkpoint_write = 1;
2903 - printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",cur_opt);
2904 + printk(KERN_INFO "yaffs: Bad mount option \"%s\"\n",
2914 static struct super_block *yaffs_internal_read_super(int yaffsVersion,
2915 - struct super_block *sb,
2916 - void *data, int silent)
2917 + struct super_block *sb,
2918 + void *data, int silent)
2921 struct inode *inode = NULL;
2922 @@ -1602,6 +1844,7 @@ static struct super_block *yaffs_interna
2924 sb->s_magic = YAFFS_MAGIC;
2925 sb->s_op = &yaffs_super_ops;
2926 + sb->s_flags |= MS_NOATIME;
2929 printk(KERN_INFO "yaffs: sb is NULL\n");
2930 @@ -1614,14 +1857,14 @@ static struct super_block *yaffs_interna
2932 yaffs_devname(sb, devname_buf));
2938 - printk(KERN_INFO "yaffs: passed flags \"%s\"\n",data_str);
2939 + printk(KERN_INFO "yaffs: passed flags \"%s\"\n", data_str);
2941 - memset(&options,0,sizeof(options));
2942 + memset(&options, 0, sizeof(options));
2944 - if(yaffs_parse_options(&options,data_str)){
2945 + if (yaffs_parse_options(&options, data_str)) {
2946 /* Option parsing failed */
2949 @@ -1645,9 +1888,9 @@ static struct super_block *yaffs_interna
2950 yaffs_devname(sb, devname_buf)));
2952 /* Check it's an mtd device..... */
2953 - if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR) {
2954 + if (MAJOR(sb->s_dev) != MTD_BLOCK_MAJOR)
2955 return NULL; /* This isn't an mtd device */
2958 /* Get the device */
2959 mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
2961 @@ -1673,29 +1916,23 @@ static struct super_block *yaffs_interna
2962 T(YAFFS_TRACE_OS, (" %s %d\n", WRITE_SIZE_STR, WRITE_SIZE(mtd)));
2963 T(YAFFS_TRACE_OS, (" oobsize %d\n", mtd->oobsize));
2964 T(YAFFS_TRACE_OS, (" erasesize %d\n", mtd->erasesize));
2965 - T(YAFFS_TRACE_OS, (" size %d\n", mtd->size));
2966 +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
2967 + T(YAFFS_TRACE_OS, (" size %u\n", mtd->size));
2969 + T(YAFFS_TRACE_OS, (" size %lld\n", mtd->size));
2972 #ifdef CONFIG_YAFFS_AUTO_YAFFS2
2974 - if (yaffsVersion == 1 &&
2975 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2976 - mtd->writesize >= 2048) {
2978 - mtd->oobblock >= 2048) {
2980 - T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n"));
2982 + if (yaffsVersion == 1 && WRITE_SIZE(mtd) >= 2048) {
2983 + T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs2\n"));
2987 /* Added NCB 26/5/2006 for completeness */
2988 - if (yaffsVersion == 2 &&
2989 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
2990 - mtd->writesize == 512) {
2992 - mtd->oobblock == 512) {
2994 - T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs1\n"));
2996 + if (yaffsVersion == 2 && !options.inband_tags && WRITE_SIZE(mtd) == 512) {
2997 + T(YAFFS_TRACE_ALWAYS, ("yaffs: auto selecting yaffs1\n"));
3002 @@ -1707,7 +1944,7 @@ static struct super_block *yaffs_interna
3003 !mtd->block_markbad ||
3006 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3007 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3008 !mtd->read_oob || !mtd->write_oob) {
3011 @@ -1719,12 +1956,9 @@ static struct super_block *yaffs_interna
3015 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3016 - if (mtd->writesize < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
3018 - if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
3020 - mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) {
3021 + if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE ||
3022 + mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) &&
3023 + !options.inband_tags) {
3024 T(YAFFS_TRACE_ALWAYS,
3025 ("yaffs: MTD device does not have the "
3026 "right page sizes\n"));
3027 @@ -1735,7 +1969,7 @@ static struct super_block *yaffs_interna
3031 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3032 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3033 !mtd->read_oob || !mtd->write_oob) {
3036 @@ -1761,7 +1995,7 @@ static struct super_block *yaffs_interna
3037 * Set the yaffs_Device up for mtd
3040 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
3041 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
3042 sb->s_fs_info = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
3044 sb->u.generic_sbp = dev = kmalloc(sizeof(yaffs_Device), GFP_KERNEL);
3045 @@ -1780,13 +2014,15 @@ static struct super_block *yaffs_interna
3047 /* Set up the memory size parameters.... */
3049 - nBlocks = mtd->size / (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK);
3050 + nBlocks = YCALCBLOCKS(mtd->size, (YAFFS_CHUNKS_PER_BLOCK * YAFFS_BYTES_PER_CHUNK));
3052 dev->startBlock = 0;
3053 dev->endBlock = nBlocks - 1;
3054 dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK;
3055 - dev->nDataBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
3056 + dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK;
3057 dev->nReservedBlocks = 5;
3058 dev->nShortOpCaches = (options.no_cache) ? 0 : 10;
3059 + dev->inbandTags = options.inband_tags;
3061 /* ... and the functions. */
3062 if (yaffsVersion == 2) {
3063 @@ -1798,20 +2034,19 @@ static struct super_block *yaffs_interna
3064 dev->queryNANDBlock = nandmtd2_QueryNANDBlock;
3065 dev->spareBuffer = YMALLOC(mtd->oobsize);
3067 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3068 - dev->nDataBytesPerChunk = mtd->writesize;
3069 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3070 + dev->totalBytesPerChunk = mtd->writesize;
3071 dev->nChunksPerBlock = mtd->erasesize / mtd->writesize;
3073 - dev->nDataBytesPerChunk = mtd->oobblock;
3074 + dev->totalBytesPerChunk = mtd->oobblock;
3075 dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock;
3077 - nBlocks = mtd->size / mtd->erasesize;
3078 + nBlocks = YCALCBLOCKS(mtd->size, mtd->erasesize);
3080 - dev->nCheckpointReservedBlocks = CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS;
3081 dev->startBlock = 0;
3082 dev->endBlock = nBlocks - 1;
3084 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3085 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3086 /* use the MTD interface in yaffs_mtdif1.c */
3087 dev->writeChunkWithTagsToNAND =
3088 nandmtd1_WriteChunkWithTagsToNAND;
3089 @@ -1847,7 +2082,7 @@ static struct super_block *yaffs_interna
3090 dev->skipCheckpointWrite = options.skip_checkpoint_write;
3092 /* we assume this is protected by lock_kernel() in mount/umount */
3093 - list_add_tail(&dev->devList, &yaffs_dev_list);
3094 + ylist_add_tail(&dev->devList, &yaffs_dev_list);
3096 init_MUTEX(&dev->grossLock);
3098 @@ -1884,20 +2119,23 @@ static struct super_block *yaffs_interna
3102 + sb->s_dirt = !dev->isCheckpointed;
3103 + T(YAFFS_TRACE_ALWAYS,
3104 + ("yaffs_read_super: isCheckpointed %d\n", dev->isCheckpointed));
3106 T(YAFFS_TRACE_OS, ("yaffs_read_super: done\n"));
3111 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
3112 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
3113 static int yaffs_internal_read_super_mtd(struct super_block *sb, void *data,
3116 return yaffs_internal_read_super(1, sb, data, silent) ? 0 : -EINVAL;
3119 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3120 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3121 static int yaffs_read_super(struct file_system_type *fs,
3122 int flags, const char *dev_name,
3123 void *data, struct vfsmount *mnt)
3124 @@ -1938,14 +2176,14 @@ static DECLARE_FSTYPE(yaffs_fs_type, "ya
3126 #ifdef CONFIG_YAFFS_YAFFS2
3128 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
3129 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
3130 static int yaffs2_internal_read_super_mtd(struct super_block *sb, void *data,
3133 return yaffs_internal_read_super(2, sb, data, silent) ? 0 : -EINVAL;
3136 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
3137 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
3138 static int yaffs2_read_super(struct file_system_type *fs,
3139 int flags, const char *dev_name, void *data,
3140 struct vfsmount *mnt)
3141 @@ -1990,12 +2228,12 @@ static char *yaffs_dump_dev(char *buf, y
3143 buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock);
3144 buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock);
3145 + buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk);
3146 buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk);
3147 buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits);
3148 buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize);
3149 buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks);
3150 buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks);
3151 - buf += sprintf(buf, "nCheckptResBlocks.. %d\n", dev->nCheckpointReservedBlocks);
3152 buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint);
3153 buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated);
3154 buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes);
3155 @@ -2006,10 +2244,8 @@ static char *yaffs_dump_dev(char *buf, y
3156 buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads);
3157 buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures);
3158 buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies);
3160 - sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
3162 - sprintf(buf, "passiveGCs......... %d\n",
3163 + buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections);
3164 + buf += sprintf(buf, "passiveGCs......... %d\n",
3165 dev->passiveGarbageCollections);
3166 buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites);
3167 buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches);
3168 @@ -2025,6 +2261,7 @@ static char *yaffs_dump_dev(char *buf, y
3169 sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions);
3170 buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC);
3171 buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2);
3172 + buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags);
3176 @@ -2033,7 +2270,7 @@ static int yaffs_proc_read(char *page,
3178 off_t offset, int count, int *eof, void *data)
3180 - struct list_head *item;
3181 + struct ylist_head *item;
3185 @@ -2057,8 +2294,8 @@ static int yaffs_proc_read(char *page,
3188 /* Locate and print the Nth entry. Order N-squared but N is small. */
3189 - list_for_each(item, &yaffs_dev_list) {
3190 - yaffs_Device *dev = list_entry(item, yaffs_Device, devList);
3191 + ylist_for_each(item, &yaffs_dev_list) {
3192 + yaffs_Device *dev = ylist_entry(item, yaffs_Device, devList);
3196 @@ -2119,7 +2356,7 @@ static int yaffs_proc_write(struct file
3200 - char substring[MAX_MASK_NAME_LENGTH+1];
3201 + char substring[MAX_MASK_NAME_LENGTH + 1];
3205 @@ -2129,9 +2366,8 @@ static int yaffs_proc_write(struct file
3207 while (!done && (pos < count)) {
3209 - while ((pos < count) && isspace(buf[pos])) {
3210 + while ((pos < count) && isspace(buf[pos]))
3216 @@ -2148,20 +2384,21 @@ static int yaffs_proc_write(struct file
3219 mask_bitfield = simple_strtoul(buf + pos, &end, 0);
3221 if (end > buf + pos) {
3222 mask_name = "numeral";
3223 len = end - (buf + pos);
3227 - for(x = buf + pos, i = 0;
3228 - (*x == '_' || (*x >='a' && *x <= 'z')) &&
3229 - i <MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3230 - substring[i] = *x;
3231 + for (x = buf + pos, i = 0;
3232 + (*x == '_' || (*x >= 'a' && *x <= 'z')) &&
3233 + i < MAX_MASK_NAME_LENGTH; x++, i++, pos++)
3234 + substring[i] = *x;
3235 substring[i] = '\0';
3237 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3238 - if(strcmp(substring,mask_flags[i].mask_name) == 0){
3239 + if (strcmp(substring, mask_flags[i].mask_name) == 0) {
3240 mask_name = mask_flags[i].mask_name;
3241 mask_bitfield = mask_flags[i].mask_bitfield;
3243 @@ -2172,7 +2409,7 @@ static int yaffs_proc_write(struct file
3245 if (mask_name != NULL) {
3250 rg &= ~mask_bitfield;
3252 @@ -2191,13 +2428,13 @@ static int yaffs_proc_write(struct file
3254 yaffs_traceMask = rg | YAFFS_TRACE_ALWAYS;
3256 - printk("new trace = 0x%08X\n",yaffs_traceMask);
3257 + printk(KERN_DEBUG "new trace = 0x%08X\n", yaffs_traceMask);
3259 if (rg & YAFFS_TRACE_ALWAYS) {
3260 for (i = 0; mask_flags[i].mask_name != NULL; i++) {
3262 flag = ((rg & mask_flags[i].mask_bitfield) == mask_flags[i].mask_bitfield) ? '+' : '-';
3263 - printk("%c%s\n", flag, mask_flags[i].mask_name);
3264 + printk(KERN_DEBUG "%c%s\n", flag, mask_flags[i].mask_name);
3268 @@ -2211,12 +2448,8 @@ struct file_system_to_install {
3271 static struct file_system_to_install fs_to_install[] = {
3272 -//#ifdef CONFIG_YAFFS_YAFFS1
3273 {&yaffs_fs_type, 0},
3275 -//#ifdef CONFIG_YAFFS_YAFFS2
3276 {&yaffs2_fs_type, 0},
3281 @@ -2231,15 +2464,14 @@ static int __init init_yaffs_fs(void)
3282 /* Install the proc_fs entry */
3283 my_proc_entry = create_proc_entry("yaffs",
3288 if (my_proc_entry) {
3289 my_proc_entry->write_proc = yaffs_proc_write;
3290 my_proc_entry->read_proc = yaffs_proc_read;
3291 my_proc_entry->data = NULL;
3297 /* Now add the file system entries */
3299 @@ -2247,9 +2479,8 @@ static int __init init_yaffs_fs(void)
3301 while (fsinst->fst && !error) {
3302 error = register_filesystem(fsinst->fst);
3305 fsinst->installed = 1;
3310 @@ -2277,7 +2508,7 @@ static void __exit exit_yaffs_fs(void)
3311 T(YAFFS_TRACE_ALWAYS, ("yaffs " __DATE__ " " __TIME__
3314 - remove_proc_entry("yaffs", &proc_root);
3315 + remove_proc_entry("yaffs", YPROC_ROOT);
3317 fsinst = fs_to_install;
3319 @@ -2288,7 +2519,6 @@ static void __exit exit_yaffs_fs(void)
3326 module_init(init_yaffs_fs)
3328 +++ b/fs/yaffs2/yaffs_getblockinfo.h
3331 + * YAFFS: Yet another Flash File System . A NAND-flash specific file system.
3333 + * Copyright (C) 2002-2007 Aleph One Ltd.
3334 + * for Toby Churchill Ltd and Brightstar Engineering
3336 + * Created by Charles Manning <charles@aleph1.co.uk>
3338 + * This program is free software; you can redistribute it and/or modify
3339 + * it under the terms of the GNU Lesser General Public License version 2.1 as
3340 + * published by the Free Software Foundation.
3342 + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
3345 +#ifndef __YAFFS_GETBLOCKINFO_H__
3346 +#define __YAFFS_GETBLOCKINFO_H__
3348 +#include "yaffs_guts.h"
3350 +/* Function to manipulate block info */
3351 +static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk)
3353 + if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) {
3354 + T(YAFFS_TRACE_ERROR,
3356 + ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR),
3360 + return &dev->blockInfo[blk - dev->internalStartBlock];
3364 --- a/fs/yaffs2/yaffs_guts.c
3365 +++ b/fs/yaffs2/yaffs_guts.c
3369 const char *yaffs_guts_c_version =
3370 - "$Id: yaffs_guts.c,v 1.49 2007-05-15 20:07:40 charles Exp $";
3371 + "$Id: yaffs_guts.c,v 1.82 2009-03-09 04:24:17 charles Exp $";
3373 #include "yportenv.h"
3375 #include "yaffsinterface.h"
3376 #include "yaffs_guts.h"
3377 #include "yaffs_tagsvalidity.h"
3378 +#include "yaffs_getblockinfo.h"
3380 #include "yaffs_tagscompat.h"
3381 -#ifndef CONFIG_YAFFS_USE_OWN_SORT
3382 +#ifndef CONFIG_YAFFS_USE_OWN_SORT
3383 #include "yaffs_qsort.h"
3385 #include "yaffs_nand.h"
3386 @@ -32,116 +33,116 @@ const char *yaffs_guts_c_version =
3387 #include "yaffs_packedtags2.h"
3390 -#ifdef CONFIG_YAFFS_WINCE
3391 -void yfsd_LockYAFFS(BOOL fsLockOnly);
3392 -void yfsd_UnlockYAFFS(BOOL fsLockOnly);
3395 #define YAFFS_PASSIVE_GC_CHUNKS 2
3397 #include "yaffs_ecc.h"
3400 /* Robustification (if it ever comes about...) */
3401 -static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND);
3402 -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND, int erasedOk);
3403 -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND,
3404 - const __u8 * data,
3405 - const yaffs_ExtendedTags * tags);
3406 -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND,
3407 - const yaffs_ExtendedTags * tags);
3408 +static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND);
3409 +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND,
3411 +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND,
3413 + const yaffs_ExtendedTags *tags);
3414 +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND,
3415 + const yaffs_ExtendedTags *tags);
3417 /* Other local prototypes */
3418 -static int yaffs_UnlinkObject( yaffs_Object *obj);
3419 +static int yaffs_UnlinkObject(yaffs_Object *obj);
3420 static int yaffs_ObjectHasCachedWriteData(yaffs_Object *obj);
3422 static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList);
3424 -static int yaffs_WriteNewChunkWithTagsToNAND(yaffs_Device * dev,
3425 - const __u8 * buffer,
3426 - yaffs_ExtendedTags * tags,
3428 -static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode,
3429 - int chunkInNAND, int inScan);
3431 -static yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number,
3432 - yaffs_ObjectType type);
3433 -static void yaffs_AddObjectToDirectory(yaffs_Object * directory,
3434 - yaffs_Object * obj);
3435 -static int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name,
3436 - int force, int isShrink, int shadows);
3437 -static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj);
3438 +static int yaffs_WriteNewChunkWithTagsToNAND(yaffs_Device *dev,
3439 + const __u8 *buffer,
3440 + yaffs_ExtendedTags *tags,
3442 +static int yaffs_PutChunkIntoFile(yaffs_Object *in, int chunkInInode,
3443 + int chunkInNAND, int inScan);
3445 +static yaffs_Object *yaffs_CreateNewObject(yaffs_Device *dev, int number,
3446 + yaffs_ObjectType type);
3447 +static void yaffs_AddObjectToDirectory(yaffs_Object *directory,
3448 + yaffs_Object *obj);
3449 +static int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name,
3450 + int force, int isShrink, int shadows);
3451 +static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj);
3452 static int yaffs_CheckStructures(void);
3453 -static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level,
3454 - int chunkOffset, int *limit);
3455 -static int yaffs_DoGenericObjectDeletion(yaffs_Object * in);
3457 -static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blockNo);
3459 -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo);
3460 -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer,
3462 +static int yaffs_DeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level,
3463 + int chunkOffset, int *limit);
3464 +static int yaffs_DoGenericObjectDeletion(yaffs_Object *in);
3466 +static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device *dev, int blockNo);
3468 -static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev,
3471 -static int yaffs_UnlinkWorker(yaffs_Object * obj);
3472 -static void yaffs_DestroyObject(yaffs_Object * obj);
3473 +static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev,
3476 -static int yaffs_TagsMatch(const yaffs_ExtendedTags * tags, int objectId,
3477 - int chunkInObject);
3478 +static int yaffs_UnlinkWorker(yaffs_Object *obj);
3480 -loff_t yaffs_GetFileSize(yaffs_Object * obj);
3481 +static int yaffs_TagsMatch(const yaffs_ExtendedTags *tags, int objectId,
3482 + int chunkInObject);
3484 -static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockInfo **blockUsedPtr);
3485 +static int yaffs_AllocateChunk(yaffs_Device *dev, int useReserve,
3486 + yaffs_BlockInfo **blockUsedPtr);
3488 -static void yaffs_VerifyFreeChunks(yaffs_Device * dev);
3489 +static void yaffs_VerifyFreeChunks(yaffs_Device *dev);
3491 static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in);
3493 +static void yaffs_VerifyDirectory(yaffs_Object *directory);
3494 #ifdef YAFFS_PARANOID
3495 -static int yaffs_CheckFileSanity(yaffs_Object * in);
3496 +static int yaffs_CheckFileSanity(yaffs_Object *in);
3498 #define yaffs_CheckFileSanity(in)
3501 -static void yaffs_InvalidateWholeChunkCache(yaffs_Object * in);
3502 -static void yaffs_InvalidateChunkCache(yaffs_Object * object, int chunkId);
3503 +static void yaffs_InvalidateWholeChunkCache(yaffs_Object *in);
3504 +static void yaffs_InvalidateChunkCache(yaffs_Object *object, int chunkId);
3506 static void yaffs_InvalidateCheckpoint(yaffs_Device *dev);
3508 -static int yaffs_FindChunkInFile(yaffs_Object * in, int chunkInInode,
3509 - yaffs_ExtendedTags * tags);
3510 +static int yaffs_FindChunkInFile(yaffs_Object *in, int chunkInInode,
3511 + yaffs_ExtendedTags *tags);
3513 -static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos);
3514 -static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev,
3515 - yaffs_FileStructure * fStruct,
3517 +static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn,
3519 +static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device *dev,
3520 + yaffs_FileStructure *fStruct,
3524 /* Function to calculate chunk and offset */
3526 -static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, __u32 *chunk, __u32 *offset)
3527 +static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut,
3530 - if(dev->chunkShift){
3531 - /* Easy-peasy power of 2 case */
3532 - *chunk = (__u32)(addr >> dev->chunkShift);
3533 - *offset = (__u32)(addr & dev->chunkMask);
3535 - else if(dev->crumbsPerChunk)
3537 - /* Case where we're using "crumbs" */
3538 - *offset = (__u32)(addr & dev->crumbMask);
3539 - addr >>= dev->crumbShift;
3540 - *chunk = ((__u32)addr)/dev->crumbsPerChunk;
3541 - *offset += ((addr - (*chunk * dev->crumbsPerChunk)) << dev->crumbShift);
3545 + chunk = (__u32)(addr >> dev->chunkShift);
3547 + if (dev->chunkDiv == 1) {
3548 + /* easy power of 2 case */
3549 + offset = (__u32)(addr & dev->chunkMask);
3551 + /* Non power-of-2 case */
3555 + chunk /= dev->chunkDiv;
3557 + chunkBase = ((loff_t)chunk) * dev->nDataBytesPerChunk;
3558 + offset = (__u32)(addr - chunkBase);
3563 + *chunkOut = chunk;
3564 + *offsetOut = offset;
3567 -/* Function to return the number of shifts for a power of 2 greater than or equal
3568 - * to the given number
3569 +/* Function to return the number of shifts for a power of 2 greater than or
3570 + * equal to the given number
3571 * Note we don't try to cater for all possible numbers and this does not have to
3572 * be hellishly efficient.
3574 @@ -153,13 +154,14 @@ static __u32 ShiftsGE(__u32 x)
3576 nShifts = extraBits = 0;
3579 - if(x & 1) extraBits++;
3593 @@ -168,16 +170,17 @@ static __u32 ShiftsGE(__u32 x)
3594 /* Function to return the number of shifts to get a 1 in bit 0
3597 -static __u32 ShiftDiv(__u32 x)
3598 +static __u32 Shifts(__u32 x)
3615 @@ -195,21 +198,25 @@ static int yaffs_InitialiseTempBuffers(y
3617 __u8 *buf = (__u8 *)1;
3619 - memset(dev->tempBuffer,0,sizeof(dev->tempBuffer));
3620 + memset(dev->tempBuffer, 0, sizeof(dev->tempBuffer));
3622 for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) {
3623 dev->tempBuffer[i].line = 0; /* not in use */
3624 dev->tempBuffer[i].buffer = buf =
3625 - YMALLOC_DMA(dev->nDataBytesPerChunk);
3626 + YMALLOC_DMA(dev->totalBytesPerChunk);
3629 return buf ? YAFFS_OK : YAFFS_FAIL;
3633 -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo)
3634 +__u8 *yaffs_GetTempBuffer(yaffs_Device *dev, int lineNo)
3639 + if (dev->tempInUse > dev->maxTemp)
3640 + dev->maxTemp = dev->tempInUse;
3642 for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
3643 if (dev->tempBuffer[i].line == 0) {
3644 dev->tempBuffer[i].line = lineNo;
3645 @@ -227,9 +234,9 @@ static __u8 *yaffs_GetTempBuffer(yaffs_D
3646 T(YAFFS_TRACE_BUFFERS,
3647 (TSTR("Out of temp buffers at line %d, other held by lines:"),
3649 - for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
3650 + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++)
3651 T(YAFFS_TRACE_BUFFERS, (TSTR(" %d "), dev->tempBuffer[i].line));
3654 T(YAFFS_TRACE_BUFFERS, (TSTR(" " TENDSTR)));
3657 @@ -242,10 +249,13 @@ static __u8 *yaffs_GetTempBuffer(yaffs_D
3661 -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer,
3662 +void yaffs_ReleaseTempBuffer(yaffs_Device *dev, __u8 *buffer,
3669 for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
3670 if (dev->tempBuffer[i].buffer == buffer) {
3671 dev->tempBuffer[i].line = 0;
3672 @@ -267,27 +277,26 @@ static void yaffs_ReleaseTempBuffer(yaff
3674 * Determine if we have a managed buffer.
3676 -int yaffs_IsManagedTempBuffer(yaffs_Device * dev, const __u8 * buffer)
3677 +int yaffs_IsManagedTempBuffer(yaffs_Device *dev, const __u8 *buffer)
3681 for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
3682 if (dev->tempBuffer[i].buffer == buffer)
3686 + for (i = 0; i < dev->nShortOpCaches; i++) {
3687 + if (dev->srCache[i].data == buffer)
3691 - for (i = 0; i < dev->nShortOpCaches; i++) {
3692 - if( dev->srCache[i].data == buffer )
3697 - if (buffer == dev->checkpointBuffer)
3700 - T(YAFFS_TRACE_ALWAYS,
3701 - (TSTR("yaffs: unmaged buffer detected.\n" TENDSTR)));
3703 + if (buffer == dev->checkpointBuffer)
3706 + T(YAFFS_TRACE_ALWAYS,
3707 + (TSTR("yaffs: unmaged buffer detected.\n" TENDSTR)));
3712 @@ -296,62 +305,63 @@ int yaffs_IsManagedTempBuffer(yaffs_Devi
3713 * Chunk bitmap manipulations
3716 -static Y_INLINE __u8 *yaffs_BlockBits(yaffs_Device * dev, int blk)
3717 +static Y_INLINE __u8 *yaffs_BlockBits(yaffs_Device *dev, int blk)
3719 if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) {
3720 T(YAFFS_TRACE_ERROR,
3721 - (TSTR("**>> yaffs: BlockBits block %d is not valid" TENDSTR),
3723 + (TSTR("**>> yaffs: BlockBits block %d is not valid" TENDSTR),
3727 return dev->chunkBits +
3728 - (dev->chunkBitmapStride * (blk - dev->internalStartBlock));
3729 + (dev->chunkBitmapStride * (blk - dev->internalStartBlock));
3732 static Y_INLINE void yaffs_VerifyChunkBitId(yaffs_Device *dev, int blk, int chunk)
3734 - if(blk < dev->internalStartBlock || blk > dev->internalEndBlock ||
3735 - chunk < 0 || chunk >= dev->nChunksPerBlock) {
3736 - T(YAFFS_TRACE_ERROR,
3737 - (TSTR("**>> yaffs: Chunk Id (%d:%d) invalid"TENDSTR),blk,chunk));
3739 + if (blk < dev->internalStartBlock || blk > dev->internalEndBlock ||
3740 + chunk < 0 || chunk >= dev->nChunksPerBlock) {
3741 + T(YAFFS_TRACE_ERROR,
3742 + (TSTR("**>> yaffs: Chunk Id (%d:%d) invalid"TENDSTR),
3748 -static Y_INLINE void yaffs_ClearChunkBits(yaffs_Device * dev, int blk)
3749 +static Y_INLINE void yaffs_ClearChunkBits(yaffs_Device *dev, int blk)
3751 __u8 *blkBits = yaffs_BlockBits(dev, blk);
3753 memset(blkBits, 0, dev->chunkBitmapStride);
3756 -static Y_INLINE void yaffs_ClearChunkBit(yaffs_Device * dev, int blk, int chunk)
3757 +static Y_INLINE void yaffs_ClearChunkBit(yaffs_Device *dev, int blk, int chunk)
3759 __u8 *blkBits = yaffs_BlockBits(dev, blk);
3761 - yaffs_VerifyChunkBitId(dev,blk,chunk);
3762 + yaffs_VerifyChunkBitId(dev, blk, chunk);
3764 blkBits[chunk / 8] &= ~(1 << (chunk & 7));
3767 -static Y_INLINE void yaffs_SetChunkBit(yaffs_Device * dev, int blk, int chunk)
3768 +static Y_INLINE void yaffs_SetChunkBit(yaffs_Device *dev, int blk, int chunk)
3770 __u8 *blkBits = yaffs_BlockBits(dev, blk);
3772 - yaffs_VerifyChunkBitId(dev,blk,chunk);
3773 + yaffs_VerifyChunkBitId(dev, blk, chunk);
3775 blkBits[chunk / 8] |= (1 << (chunk & 7));
3778 -static Y_INLINE int yaffs_CheckChunkBit(yaffs_Device * dev, int blk, int chunk)
3779 +static Y_INLINE int yaffs_CheckChunkBit(yaffs_Device *dev, int blk, int chunk)
3781 __u8 *blkBits = yaffs_BlockBits(dev, blk);
3782 - yaffs_VerifyChunkBitId(dev,blk,chunk);
3783 + yaffs_VerifyChunkBitId(dev, blk, chunk);
3785 return (blkBits[chunk / 8] & (1 << (chunk & 7))) ? 1 : 0;
3788 -static Y_INLINE int yaffs_StillSomeChunkBits(yaffs_Device * dev, int blk)
3789 +static Y_INLINE int yaffs_StillSomeChunkBits(yaffs_Device *dev, int blk)
3791 __u8 *blkBits = yaffs_BlockBits(dev, blk);
3793 @@ -363,17 +373,17 @@ static Y_INLINE int yaffs_StillSomeChunk
3797 -static int yaffs_CountChunkBits(yaffs_Device * dev, int blk)
3798 +static int yaffs_CountChunkBits(yaffs_Device *dev, int blk)
3800 __u8 *blkBits = yaffs_BlockBits(dev, blk);
3803 for (i = 0; i < dev->chunkBitmapStride; i++) {
3815 @@ -400,7 +410,7 @@ static int yaffs_SkipNANDVerification(ya
3816 return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND));
3819 -static const char * blockStateName[] = {
3820 +static const char *blockStateName[] = {
3824 @@ -413,64 +423,65 @@ static const char * blockStateName[] = {
3828 -static void yaffs_VerifyBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int n)
3829 +static void yaffs_VerifyBlock(yaffs_Device *dev, yaffs_BlockInfo *bi, int n)
3834 - if(yaffs_SkipVerification(dev))
3835 + if (yaffs_SkipVerification(dev))
3838 /* Report illegal runtime states */
3839 - if(bi->blockState <0 || bi->blockState >= YAFFS_NUMBER_OF_BLOCK_STATES)
3840 - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has undefined state %d"TENDSTR),n,bi->blockState));
3841 + if (bi->blockState >= YAFFS_NUMBER_OF_BLOCK_STATES)
3842 + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has undefined state %d"TENDSTR), n, bi->blockState));
3844 - switch(bi->blockState){
3845 - case YAFFS_BLOCK_STATE_UNKNOWN:
3846 - case YAFFS_BLOCK_STATE_SCANNING:
3847 - case YAFFS_BLOCK_STATE_NEEDS_SCANNING:
3848 - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has bad run-state %s"TENDSTR),
3849 - n,blockStateName[bi->blockState]));
3850 + switch (bi->blockState) {
3851 + case YAFFS_BLOCK_STATE_UNKNOWN:
3852 + case YAFFS_BLOCK_STATE_SCANNING:
3853 + case YAFFS_BLOCK_STATE_NEEDS_SCANNING:
3854 + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has bad run-state %s"TENDSTR),
3855 + n, blockStateName[bi->blockState]));
3858 /* Check pages in use and soft deletions are legal */
3860 actuallyUsed = bi->pagesInUse - bi->softDeletions;
3862 - if(bi->pagesInUse < 0 || bi->pagesInUse > dev->nChunksPerBlock ||
3863 + if (bi->pagesInUse < 0 || bi->pagesInUse > dev->nChunksPerBlock ||
3864 bi->softDeletions < 0 || bi->softDeletions > dev->nChunksPerBlock ||
3865 actuallyUsed < 0 || actuallyUsed > dev->nChunksPerBlock)
3866 - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has illegal values pagesInUsed %d softDeletions %d"TENDSTR),
3867 - n,bi->pagesInUse,bi->softDeletions));
3868 + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has illegal values pagesInUsed %d softDeletions %d"TENDSTR),
3869 + n, bi->pagesInUse, bi->softDeletions));
3872 /* Check chunk bitmap legal */
3873 - inUse = yaffs_CountChunkBits(dev,n);
3874 - if(inUse != bi->pagesInUse)
3875 - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has inconsistent values pagesInUse %d counted chunk bits %d"TENDSTR),
3876 - n,bi->pagesInUse,inUse));
3877 + inUse = yaffs_CountChunkBits(dev, n);
3878 + if (inUse != bi->pagesInUse)
3879 + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has inconsistent values pagesInUse %d counted chunk bits %d"TENDSTR),
3880 + n, bi->pagesInUse, inUse));
3882 /* Check that the sequence number is valid.
3883 * Ten million is legal, but is very unlikely
3885 - if(dev->isYaffs2 &&
3886 + if (dev->isYaffs2 &&
3887 (bi->blockState == YAFFS_BLOCK_STATE_ALLOCATING || bi->blockState == YAFFS_BLOCK_STATE_FULL) &&
3888 - (bi->sequenceNumber < YAFFS_LOWEST_SEQUENCE_NUMBER || bi->sequenceNumber > 10000000 ))
3889 - T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has suspect sequence number of %d"TENDSTR),
3890 - n,bi->sequenceNumber));
3892 + (bi->sequenceNumber < YAFFS_LOWEST_SEQUENCE_NUMBER || bi->sequenceNumber > 10000000))
3893 + T(YAFFS_TRACE_VERIFY, (TSTR("Block %d has suspect sequence number of %d"TENDSTR),
3894 + n, bi->sequenceNumber));
3897 -static void yaffs_VerifyCollectedBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int n)
3898 +static void yaffs_VerifyCollectedBlock(yaffs_Device *dev, yaffs_BlockInfo *bi,
3901 - yaffs_VerifyBlock(dev,bi,n);
3902 + yaffs_VerifyBlock(dev, bi, n);
3904 /* After collection the block should be in the erased state */
3905 - /* TODO: This will need to change if we do partial gc */
3906 + /* This will need to change if we do partial gc */
3908 - if(bi->blockState != YAFFS_BLOCK_STATE_EMPTY){
3909 - T(YAFFS_TRACE_ERROR,(TSTR("Block %d is in state %d after gc, should be erased"TENDSTR),
3910 - n,bi->blockState));
3911 + if (bi->blockState != YAFFS_BLOCK_STATE_COLLECTING &&
3912 + bi->blockState != YAFFS_BLOCK_STATE_EMPTY) {
3913 + T(YAFFS_TRACE_ERROR, (TSTR("Block %d is in state %d after gc, should be erased"TENDSTR),
3914 + n, bi->blockState));
3918 @@ -480,52 +491,49 @@ static void yaffs_VerifyBlocks(yaffs_Dev
3919 int nBlocksPerState[YAFFS_NUMBER_OF_BLOCK_STATES];
3920 int nIllegalBlockStates = 0;
3923 - if(yaffs_SkipVerification(dev))
3924 + if (yaffs_SkipVerification(dev))
3927 - memset(nBlocksPerState,0,sizeof(nBlocksPerState));
3929 + memset(nBlocksPerState, 0, sizeof(nBlocksPerState));
3931 - for(i = dev->internalStartBlock; i <= dev->internalEndBlock; i++){
3932 - yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i);
3933 - yaffs_VerifyBlock(dev,bi,i);
3934 + for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) {
3935 + yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i);
3936 + yaffs_VerifyBlock(dev, bi, i);
3938 - if(bi->blockState >=0 && bi->blockState < YAFFS_NUMBER_OF_BLOCK_STATES)
3939 + if (bi->blockState < YAFFS_NUMBER_OF_BLOCK_STATES)
3940 nBlocksPerState[bi->blockState]++;
3942 nIllegalBlockStates++;
3946 - T(YAFFS_TRACE_VERIFY,(TSTR(""TENDSTR)));
3947 - T(YAFFS_TRACE_VERIFY,(TSTR("Block summary"TENDSTR)));
3948 + T(YAFFS_TRACE_VERIFY, (TSTR(""TENDSTR)));
3949 + T(YAFFS_TRACE_VERIFY, (TSTR("Block summary"TENDSTR)));
3951 - T(YAFFS_TRACE_VERIFY,(TSTR("%d blocks have illegal states"TENDSTR),nIllegalBlockStates));
3952 - if(nBlocksPerState[YAFFS_BLOCK_STATE_ALLOCATING] > 1)
3953 - T(YAFFS_TRACE_VERIFY,(TSTR("Too many allocating blocks"TENDSTR)));
3954 + T(YAFFS_TRACE_VERIFY, (TSTR("%d blocks have illegal states"TENDSTR), nIllegalBlockStates));
3955 + if (nBlocksPerState[YAFFS_BLOCK_STATE_ALLOCATING] > 1)
3956 + T(YAFFS_TRACE_VERIFY, (TSTR("Too many allocating blocks"TENDSTR)));
3958 - for(i = 0; i < YAFFS_NUMBER_OF_BLOCK_STATES; i++)
3959 + for (i = 0; i < YAFFS_NUMBER_OF_BLOCK_STATES; i++)
3960 T(YAFFS_TRACE_VERIFY,
3961 (TSTR("%s %d blocks"TENDSTR),
3962 - blockStateName[i],nBlocksPerState[i]));
3963 + blockStateName[i], nBlocksPerState[i]));
3965 - if(dev->blocksInCheckpoint != nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT])
3966 + if (dev->blocksInCheckpoint != nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT])
3967 T(YAFFS_TRACE_VERIFY,
3968 (TSTR("Checkpoint block count wrong dev %d count %d"TENDSTR),
3969 dev->blocksInCheckpoint, nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT]));
3971 - if(dev->nErasedBlocks != nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY])
3972 + if (dev->nErasedBlocks != nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY])
3973 T(YAFFS_TRACE_VERIFY,
3974 (TSTR("Erased block count wrong dev %d count %d"TENDSTR),
3975 dev->nErasedBlocks, nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY]));
3977 - if(nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING] > 1)
3978 + if (nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING] > 1)
3979 T(YAFFS_TRACE_VERIFY,
3980 (TSTR("Too many collecting blocks %d (max is 1)"TENDSTR),
3981 nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING]));
3983 - T(YAFFS_TRACE_VERIFY,(TSTR(""TENDSTR)));
3984 + T(YAFFS_TRACE_VERIFY, (TSTR(""TENDSTR)));
3988 @@ -535,26 +543,26 @@ static void yaffs_VerifyBlocks(yaffs_Dev
3990 static void yaffs_VerifyObjectHeader(yaffs_Object *obj, yaffs_ObjectHeader *oh, yaffs_ExtendedTags *tags, int parentCheck)
3992 - if(yaffs_SkipVerification(obj->myDev))
3993 + if (obj && yaffs_SkipVerification(obj->myDev))
3996 - if(!(tags && obj && oh)){
3997 - T(YAFFS_TRACE_VERIFY,
3998 - (TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR),
3999 - (__u32)tags,(__u32)obj,(__u32)oh));
4000 + if (!(tags && obj && oh)) {
4001 + T(YAFFS_TRACE_VERIFY,
4002 + (TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR),
4003 + (__u32)tags, (__u32)obj, (__u32)oh));
4007 - if(oh->type <= YAFFS_OBJECT_TYPE_UNKNOWN ||
4008 - oh->type > YAFFS_OBJECT_TYPE_MAX)
4009 - T(YAFFS_TRACE_VERIFY,
4010 - (TSTR("Obj %d header type is illegal value 0x%x"TENDSTR),
4011 - tags->objectId, oh->type));
4013 - if(tags->objectId != obj->objectId)
4014 - T(YAFFS_TRACE_VERIFY,
4015 - (TSTR("Obj %d header mismatch objectId %d"TENDSTR),
4016 - tags->objectId, obj->objectId));
4017 + if (oh->type <= YAFFS_OBJECT_TYPE_UNKNOWN ||
4018 + oh->type > YAFFS_OBJECT_TYPE_MAX)
4019 + T(YAFFS_TRACE_VERIFY,
4020 + (TSTR("Obj %d header type is illegal value 0x%x"TENDSTR),
4021 + tags->objectId, oh->type));
4023 + if (tags->objectId != obj->objectId)
4024 + T(YAFFS_TRACE_VERIFY,
4025 + (TSTR("Obj %d header mismatch objectId %d"TENDSTR),
4026 + tags->objectId, obj->objectId));
4030 @@ -563,46 +571,43 @@ static void yaffs_VerifyObjectHeader(yaf
4031 * Tests do not apply to the root object.
4034 - if(parentCheck && tags->objectId > 1 && !obj->parent)
4035 - T(YAFFS_TRACE_VERIFY,
4036 - (TSTR("Obj %d header mismatch parentId %d obj->parent is NULL"TENDSTR),
4037 - tags->objectId, oh->parentObjectId));
4040 - if(parentCheck && obj->parent &&
4041 - oh->parentObjectId != obj->parent->objectId &&
4042 - (oh->parentObjectId != YAFFS_OBJECTID_UNLINKED ||
4043 - obj->parent->objectId != YAFFS_OBJECTID_DELETED))
4044 - T(YAFFS_TRACE_VERIFY,
4045 - (TSTR("Obj %d header mismatch parentId %d parentObjectId %d"TENDSTR),
4046 - tags->objectId, oh->parentObjectId, obj->parent->objectId));
4047 + if (parentCheck && tags->objectId > 1 && !obj->parent)
4048 + T(YAFFS_TRACE_VERIFY,
4049 + (TSTR("Obj %d header mismatch parentId %d obj->parent is NULL"TENDSTR),
4050 + tags->objectId, oh->parentObjectId));
4052 + if (parentCheck && obj->parent &&
4053 + oh->parentObjectId != obj->parent->objectId &&
4054 + (oh->parentObjectId != YAFFS_OBJECTID_UNLINKED ||
4055 + obj->parent->objectId != YAFFS_OBJECTID_DELETED))
4056 + T(YAFFS_TRACE_VERIFY,
4057 + (TSTR("Obj %d header mismatch parentId %d parentObjectId %d"TENDSTR),
4058 + tags->objectId, oh->parentObjectId, obj->parent->objectId));
4060 - if(tags->objectId > 1 && oh->name[0] == 0) /* Null name */
4061 + if (tags->objectId > 1 && oh->name[0] == 0) /* Null name */
4062 T(YAFFS_TRACE_VERIFY,
4063 - (TSTR("Obj %d header name is NULL"TENDSTR),
4065 + (TSTR("Obj %d header name is NULL"TENDSTR),
4068 - if(tags->objectId > 1 && ((__u8)(oh->name[0])) == 0xff) /* Trashed name */
4069 + if (tags->objectId > 1 && ((__u8)(oh->name[0])) == 0xff) /* Trashed name */
4070 T(YAFFS_TRACE_VERIFY,
4071 - (TSTR("Obj %d header name is 0xFF"TENDSTR),
4073 + (TSTR("Obj %d header name is 0xFF"TENDSTR),
4079 -static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn,
4080 - __u32 level, int chunkOffset)
4081 +static int yaffs_VerifyTnodeWorker(yaffs_Object *obj, yaffs_Tnode *tn,
4082 + __u32 level, int chunkOffset)
4085 yaffs_Device *dev = obj->myDev;
4087 - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
4092 - for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++){
4093 + for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++) {
4094 if (tn->internal[i]) {
4095 ok = yaffs_VerifyTnodeWorker(obj,
4097 @@ -611,20 +616,19 @@ static int yaffs_VerifyTnodeWorker(yaffs
4100 } else if (level == 0) {
4102 yaffs_ExtendedTags tags;
4103 __u32 objectId = obj->objectId;
4105 chunkOffset <<= YAFFS_TNODES_LEVEL0_BITS;
4107 - for(i = 0; i < YAFFS_NTNODES_LEVEL0; i++){
4108 - __u32 theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
4109 + for (i = 0; i < YAFFS_NTNODES_LEVEL0; i++) {
4110 + __u32 theChunk = yaffs_GetChunkGroupBase(dev, tn, i);
4113 + if (theChunk > 0) {
4114 /* T(~0,(TSTR("verifying (%d:%d) %d"TENDSTR),tags.objectId,tags.chunkId,theChunk)); */
4115 - yaffs_ReadChunkWithTagsFromNAND(dev,theChunk,NULL, &tags);
4116 - if(tags.objectId != objectId || tags.chunkId != chunkOffset){
4117 - T(~0,(TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR),
4118 + yaffs_ReadChunkWithTagsFromNAND(dev, theChunk, NULL, &tags);
4119 + if (tags.objectId != objectId || tags.chunkId != chunkOffset) {
4120 + T(~0, (TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR),
4121 objectId, chunkOffset, theChunk,
4122 tags.objectId, tags.chunkId));
4124 @@ -646,13 +650,15 @@ static void yaffs_VerifyFile(yaffs_Objec
4130 yaffs_ExtendedTags tags;
4134 - if(obj && yaffs_SkipVerification(obj->myDev))
4138 + if (yaffs_SkipVerification(obj->myDev))
4142 @@ -662,17 +668,17 @@ static void yaffs_VerifyFile(yaffs_Objec
4143 lastChunk = obj->variant.fileVariant.fileSize / dev->nDataBytesPerChunk + 1;
4144 x = lastChunk >> YAFFS_TNODES_LEVEL0_BITS;
4145 requiredTallness = 0;
4148 x >>= YAFFS_TNODES_INTERNAL_BITS;
4152 actualTallness = obj->variant.fileVariant.topLevel;
4154 - if(requiredTallness > actualTallness )
4155 + if (requiredTallness > actualTallness)
4156 T(YAFFS_TRACE_VERIFY,
4157 (TSTR("Obj %d had tnode tallness %d, needs to be %d"TENDSTR),
4158 - obj->objectId,actualTallness, requiredTallness));
4159 + obj->objectId, actualTallness, requiredTallness));
4162 /* Check that the chunks in the tnode tree are all correct.
4163 @@ -680,39 +686,31 @@ static void yaffs_VerifyFile(yaffs_Objec
4164 * checking the tags for every chunk match.
4167 - if(yaffs_SkipNANDVerification(dev))
4168 + if (yaffs_SkipNANDVerification(dev))
4171 - for(i = 1; i <= lastChunk; i++){
4172 - tn = yaffs_FindLevel0Tnode(dev, &obj->variant.fileVariant,i);
4173 + for (i = 1; i <= lastChunk; i++) {
4174 + tn = yaffs_FindLevel0Tnode(dev, &obj->variant.fileVariant, i);
4177 - __u32 theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
4179 + __u32 theChunk = yaffs_GetChunkGroupBase(dev, tn, i);
4180 + if (theChunk > 0) {
4181 /* T(~0,(TSTR("verifying (%d:%d) %d"TENDSTR),objectId,i,theChunk)); */
4182 - yaffs_ReadChunkWithTagsFromNAND(dev,theChunk,NULL, &tags);
4183 - if(tags.objectId != objectId || tags.chunkId != i){
4184 - T(~0,(TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR),
4185 + yaffs_ReadChunkWithTagsFromNAND(dev, theChunk, NULL, &tags);
4186 + if (tags.objectId != objectId || tags.chunkId != i) {
4187 + T(~0, (TSTR("Object %d chunkId %d NAND mismatch chunk %d tags (%d:%d)"TENDSTR),
4188 objectId, i, theChunk,
4189 tags.objectId, tags.chunkId));
4198 -static void yaffs_VerifyDirectory(yaffs_Object *obj)
4200 - if(obj && yaffs_SkipVerification(obj->myDev))
4205 static void yaffs_VerifyHardLink(yaffs_Object *obj)
4207 - if(obj && yaffs_SkipVerification(obj->myDev))
4208 + if (obj && yaffs_SkipVerification(obj->myDev))
4211 /* Verify sane equivalent object */
4212 @@ -720,7 +718,7 @@ static void yaffs_VerifyHardLink(yaffs_O
4214 static void yaffs_VerifySymlink(yaffs_Object *obj)
4216 - if(obj && yaffs_SkipVerification(obj->myDev))
4217 + if (obj && yaffs_SkipVerification(obj->myDev))
4220 /* Verify symlink string */
4221 @@ -728,7 +726,7 @@ static void yaffs_VerifySymlink(yaffs_Ob
4223 static void yaffs_VerifySpecial(yaffs_Object *obj)
4225 - if(obj && yaffs_SkipVerification(obj->myDev))
4226 + if (obj && yaffs_SkipVerification(obj->myDev))
4230 @@ -740,14 +738,19 @@ static void yaffs_VerifyObject(yaffs_Obj
4234 - __u32 chunkIsLive;
4235 + __u32 chunkInRange;
4236 + __u32 chunkShouldNotBeDeleted;
4243 + if (obj->beingCreated)
4248 - if(yaffs_SkipVerification(dev))
4249 + if (yaffs_SkipVerification(dev))
4252 /* Check sane object header chunk */
4253 @@ -755,50 +758,54 @@ static void yaffs_VerifyObject(yaffs_Obj
4254 chunkMin = dev->internalStartBlock * dev->nChunksPerBlock;
4255 chunkMax = (dev->internalEndBlock+1) * dev->nChunksPerBlock - 1;
4257 - chunkIdOk = (obj->chunkId >= chunkMin && obj->chunkId <= chunkMax);
4258 - chunkIsLive = chunkIdOk &&
4259 + chunkInRange = (((unsigned)(obj->hdrChunk)) >= chunkMin && ((unsigned)(obj->hdrChunk)) <= chunkMax);
4260 + chunkIdOk = chunkInRange || obj->hdrChunk == 0;
4261 + chunkValid = chunkInRange &&
4262 yaffs_CheckChunkBit(dev,
4263 - obj->chunkId / dev->nChunksPerBlock,
4264 - obj->chunkId % dev->nChunksPerBlock);
4266 - (!chunkIdOk || !chunkIsLive)) {
4267 - T(YAFFS_TRACE_VERIFY,
4268 - (TSTR("Obj %d has chunkId %d %s %s"TENDSTR),
4269 - obj->objectId,obj->chunkId,
4270 - chunkIdOk ? "" : ",out of range",
4271 - chunkIsLive || !chunkIdOk ? "" : ",marked as deleted"));
4272 + obj->hdrChunk / dev->nChunksPerBlock,
4273 + obj->hdrChunk % dev->nChunksPerBlock);
4274 + chunkShouldNotBeDeleted = chunkInRange && !chunkValid;
4277 + (!chunkIdOk || chunkShouldNotBeDeleted)) {
4278 + T(YAFFS_TRACE_VERIFY,
4279 + (TSTR("Obj %d has chunkId %d %s %s"TENDSTR),
4280 + obj->objectId, obj->hdrChunk,
4281 + chunkIdOk ? "" : ",out of range",
4282 + chunkShouldNotBeDeleted ? ",marked as deleted" : ""));
4285 - if(chunkIdOk && chunkIsLive &&!yaffs_SkipNANDVerification(dev)) {
4286 + if (chunkValid && !yaffs_SkipNANDVerification(dev)) {
4287 yaffs_ExtendedTags tags;
4288 yaffs_ObjectHeader *oh;
4289 - __u8 *buffer = yaffs_GetTempBuffer(dev,__LINE__);
4290 + __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__);
4292 oh = (yaffs_ObjectHeader *)buffer;
4294 - yaffs_ReadChunkWithTagsFromNAND(dev, obj->chunkId,buffer, &tags);
4295 + yaffs_ReadChunkWithTagsFromNAND(dev, obj->hdrChunk, buffer,
4298 - yaffs_VerifyObjectHeader(obj,oh,&tags,1);
4299 + yaffs_VerifyObjectHeader(obj, oh, &tags, 1);
4301 - yaffs_ReleaseTempBuffer(dev,buffer,__LINE__);
4302 + yaffs_ReleaseTempBuffer(dev, buffer, __LINE__);
4305 /* Verify it has a parent */
4306 - if(obj && !obj->fake &&
4307 - (!obj->parent || obj->parent->myDev != dev)){
4308 - T(YAFFS_TRACE_VERIFY,
4309 - (TSTR("Obj %d has parent pointer %p which does not look like an object"TENDSTR),
4310 - obj->objectId,obj->parent));
4311 + if (obj && !obj->fake &&
4312 + (!obj->parent || obj->parent->myDev != dev)) {
4313 + T(YAFFS_TRACE_VERIFY,
4314 + (TSTR("Obj %d has parent pointer %p which does not look like an object"TENDSTR),
4315 + obj->objectId, obj->parent));
4318 /* Verify parent is a directory */
4319 - if(obj->parent && obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){
4320 - T(YAFFS_TRACE_VERIFY,
4321 - (TSTR("Obj %d's parent is not a directory (type %d)"TENDSTR),
4322 - obj->objectId,obj->parent->variantType));
4323 + if (obj->parent && obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
4324 + T(YAFFS_TRACE_VERIFY,
4325 + (TSTR("Obj %d's parent is not a directory (type %d)"TENDSTR),
4326 + obj->objectId, obj->parent->variantType));
4329 - switch(obj->variantType){
4330 + switch (obj->variantType) {
4331 case YAFFS_OBJECT_TYPE_FILE:
4332 yaffs_VerifyFile(obj);
4334 @@ -818,33 +825,30 @@ static void yaffs_VerifyObject(yaffs_Obj
4336 T(YAFFS_TRACE_VERIFY,
4337 (TSTR("Obj %d has illegaltype %d"TENDSTR),
4338 - obj->objectId,obj->variantType));
4339 + obj->objectId, obj->variantType));
4346 static void yaffs_VerifyObjects(yaffs_Device *dev)
4350 - struct list_head *lh;
4351 + struct ylist_head *lh;
4353 - if(yaffs_SkipVerification(dev))
4354 + if (yaffs_SkipVerification(dev))
4357 /* Iterate through the objects in each hash entry */
4359 - for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){
4360 - list_for_each(lh, &dev->objectBucket[i].list) {
4361 + for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) {
4362 + ylist_for_each(lh, &dev->objectBucket[i].list) {
4364 - obj = list_entry(lh, yaffs_Object, hashLink);
4365 + obj = ylist_entry(lh, yaffs_Object, hashLink);
4366 yaffs_VerifyObject(obj);
4375 @@ -855,19 +859,20 @@ static void yaffs_VerifyObjects(yaffs_De
4376 static Y_INLINE int yaffs_HashFunction(int n)
4379 - return (n % YAFFS_NOBJECT_BUCKETS);
4380 + return n % YAFFS_NOBJECT_BUCKETS;
4384 - * Access functions to useful fake objects
4385 + * Access functions to useful fake objects.
4386 + * Note that root might have a presence in NAND if permissions are set.
4389 -yaffs_Object *yaffs_Root(yaffs_Device * dev)
4390 +yaffs_Object *yaffs_Root(yaffs_Device *dev)
4392 return dev->rootDir;
4395 -yaffs_Object *yaffs_LostNFound(yaffs_Device * dev)
4396 +yaffs_Object *yaffs_LostNFound(yaffs_Device *dev)
4398 return dev->lostNFoundDir;
4400 @@ -877,7 +882,7 @@ yaffs_Object *yaffs_LostNFound(yaffs_Dev
4401 * Erased NAND checking functions
4404 -int yaffs_CheckFF(__u8 * buffer, int nBytes)
4405 +int yaffs_CheckFF(__u8 *buffer, int nBytes)
4407 /* Horrible, slow implementation */
4409 @@ -889,9 +894,8 @@ int yaffs_CheckFF(__u8 * buffer, int nBy
4412 static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev,
4417 int retval = YAFFS_OK;
4418 __u8 *data = yaffs_GetTempBuffer(dev, __LINE__);
4419 yaffs_ExtendedTags tags;
4420 @@ -899,10 +903,9 @@ static int yaffs_CheckChunkErased(struct
4422 result = yaffs_ReadChunkWithTagsFromNAND(dev, chunkInNAND, data, &tags);
4424 - if(tags.eccResult > YAFFS_ECC_RESULT_NO_ERROR)
4425 + if (tags.eccResult > YAFFS_ECC_RESULT_NO_ERROR)
4426 retval = YAFFS_FAIL;
4429 if (!yaffs_CheckFF(data, dev->nDataBytesPerChunk) || tags.chunkUsed) {
4430 T(YAFFS_TRACE_NANDACCESS,
4431 (TSTR("Chunk %d not erased" TENDSTR), chunkInNAND));
4432 @@ -915,11 +918,10 @@ static int yaffs_CheckChunkErased(struct
4437 static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev,
4438 - const __u8 * data,
4439 - yaffs_ExtendedTags * tags,
4442 + yaffs_ExtendedTags *tags,
4447 @@ -972,7 +974,7 @@ static int yaffs_WriteNewChunkWithTagsTo
4448 erasedOk = yaffs_CheckChunkErased(dev, chunk);
4449 if (erasedOk != YAFFS_OK) {
4450 T(YAFFS_TRACE_ERROR,
4451 - (TSTR ("**>> yaffs chunk %d was not erased"
4452 + (TSTR("**>> yaffs chunk %d was not erased"
4455 /* try another chunk */
4456 @@ -992,7 +994,11 @@ static int yaffs_WriteNewChunkWithTagsTo
4457 /* Copy the data into the robustification buffer */
4458 yaffs_HandleWriteChunkOk(dev, chunk, data, tags);
4460 - } while (writeOk != YAFFS_OK && attempts < yaffs_wr_attempts);
4461 + } while (writeOk != YAFFS_OK &&
4462 + (yaffs_wr_attempts <= 0 || attempts <= yaffs_wr_attempts));
4468 T(YAFFS_TRACE_ERROR,
4469 @@ -1009,13 +1015,35 @@ static int yaffs_WriteNewChunkWithTagsTo
4470 * Block retiring for handling a broken block.
4473 -static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND)
4474 +static void yaffs_RetireBlock(yaffs_Device *dev, int blockInNAND)
4476 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND);
4478 yaffs_InvalidateCheckpoint(dev);
4480 - yaffs_MarkBlockBad(dev, blockInNAND);
4481 + if (yaffs_MarkBlockBad(dev, blockInNAND) != YAFFS_OK) {
4482 + if (yaffs_EraseBlockInNAND(dev, blockInNAND) != YAFFS_OK) {
4483 + T(YAFFS_TRACE_ALWAYS, (TSTR(
4484 + "yaffs: Failed to mark bad and erase block %d"
4485 + TENDSTR), blockInNAND));
4487 + yaffs_ExtendedTags tags;
4488 + int chunkId = blockInNAND * dev->nChunksPerBlock;
4490 + __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__);
4492 + memset(buffer, 0xff, dev->nDataBytesPerChunk);
4493 + yaffs_InitialiseTags(&tags);
4494 + tags.sequenceNumber = YAFFS_SEQUENCE_BAD_BLOCK;
4495 + if (dev->writeChunkWithTagsToNAND(dev, chunkId -
4496 + dev->chunkOffset, buffer, &tags) != YAFFS_OK)
4497 + T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: Failed to "
4498 + TCONT("write bad block marker to block %d")
4499 + TENDSTR), blockInNAND));
4501 + yaffs_ReleaseTempBuffer(dev, buffer, __LINE__);
4505 bi->blockState = YAFFS_BLOCK_STATE_DEAD;
4506 bi->gcPrioritise = 0;
4507 @@ -1029,49 +1057,45 @@ static void yaffs_RetireBlock(yaffs_Devi
4511 -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND,
4512 - const __u8 * data,
4513 - const yaffs_ExtendedTags * tags)
4514 +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND,
4516 + const yaffs_ExtendedTags *tags)
4520 -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND,
4521 - const yaffs_ExtendedTags * tags)
4522 +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND,
4523 + const yaffs_ExtendedTags *tags)
4527 void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi)
4529 - if(!bi->gcPrioritise){
4530 + if (!bi->gcPrioritise) {
4531 bi->gcPrioritise = 1;
4532 dev->hasPendingPrioritisedGCs = 1;
4533 - bi->chunkErrorStrikes ++;
4534 + bi->chunkErrorStrikes++;
4536 - if(bi->chunkErrorStrikes > 3){
4537 + if (bi->chunkErrorStrikes > 3) {
4538 bi->needsRetiring = 1; /* Too many stikes, so retire this */
4539 T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: Block struck out" TENDSTR)));
4546 -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND, int erasedOk)
4547 +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND,
4551 int blockInNAND = chunkInNAND / dev->nChunksPerBlock;
4552 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND);
4554 - yaffs_HandleChunkError(dev,bi);
4555 + yaffs_HandleChunkError(dev, bi);
4560 /* Was an actual write failure, so mark the block for retirement */
4561 bi->needsRetiring = 1;
4562 T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
4563 (TSTR("**>> Block %d needs retiring" TENDSTR), blockInNAND));
4568 /* Delete the chunk */
4569 @@ -1081,12 +1105,12 @@ static void yaffs_HandleWriteChunkError(
4571 /*---------------- Name handling functions ------------*/
4573 -static __u16 yaffs_CalcNameSum(const YCHAR * name)
4574 +static __u16 yaffs_CalcNameSum(const YCHAR *name)
4579 - YUCHAR *bname = (YUCHAR *) name;
4580 + const YUCHAR *bname = (const YUCHAR *) name;
4582 while ((*bname) && (i < (YAFFS_MAX_NAME_LENGTH/2))) {
4584 @@ -1102,14 +1126,14 @@ static __u16 yaffs_CalcNameSum(const YCH
4588 -static void yaffs_SetObjectName(yaffs_Object * obj, const YCHAR * name)
4589 +static void yaffs_SetObjectName(yaffs_Object *obj, const YCHAR *name)
4591 #ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
4592 - if (name && yaffs_strlen(name) <= YAFFS_SHORT_NAME_LENGTH) {
4593 + memset(obj->shortName, 0, sizeof(YCHAR) * (YAFFS_SHORT_NAME_LENGTH+1));
4594 + if (name && yaffs_strlen(name) <= YAFFS_SHORT_NAME_LENGTH)
4595 yaffs_strcpy(obj->shortName, name);
4598 obj->shortName[0] = _Y('\0');
4601 obj->sum = yaffs_CalcNameSum(name);
4603 @@ -1126,7 +1150,7 @@ static void yaffs_SetObjectName(yaffs_Ob
4604 * Don't use this function directly
4607 -static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes)
4608 +static int yaffs_CreateTnodes(yaffs_Device *dev, int nTnodes)
4612 @@ -1143,6 +1167,9 @@ static int yaffs_CreateTnodes(yaffs_Devi
4613 * Must be a multiple of 32-bits */
4614 tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
4616 + if (tnodeSize < sizeof(yaffs_Tnode))
4617 + tnodeSize = sizeof(yaffs_Tnode);
4619 /* make these things */
4621 newTnodes = YMALLOC(nTnodes * tnodeSize);
4622 @@ -1150,7 +1177,7 @@ static int yaffs_CreateTnodes(yaffs_Devi
4625 T(YAFFS_TRACE_ERROR,
4626 - (TSTR("yaffs: Could not allocate Tnodes" TENDSTR)));
4627 + (TSTR("yaffs: Could not allocate Tnodes" TENDSTR)));
4631 @@ -1170,7 +1197,7 @@ static int yaffs_CreateTnodes(yaffs_Devi
4632 dev->freeTnodes = newTnodes;
4634 /* New hookup for wide tnodes */
4635 - for(i = 0; i < nTnodes -1; i++) {
4636 + for (i = 0; i < nTnodes - 1; i++) {
4637 curr = (yaffs_Tnode *) &mem[i * tnodeSize];
4638 next = (yaffs_Tnode *) &mem[(i+1) * tnodeSize];
4639 curr->internal[0] = next;
4640 @@ -1197,7 +1224,6 @@ static int yaffs_CreateTnodes(yaffs_Devi
4642 ("yaffs: Could not add tnodes to management list" TENDSTR)));
4646 tnl->tnodes = newTnodes;
4647 tnl->next = dev->allocatedTnodeList;
4648 @@ -1211,14 +1237,13 @@ static int yaffs_CreateTnodes(yaffs_Devi
4650 /* GetTnode gets us a clean tnode. Tries to make allocate more if we run out */
4652 -static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device * dev)
4653 +static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device *dev)
4655 yaffs_Tnode *tn = NULL;
4657 /* If there are none left make more */
4658 - if (!dev->freeTnodes) {
4659 + if (!dev->freeTnodes)
4660 yaffs_CreateTnodes(dev, YAFFS_ALLOCATION_NTNODES);
4663 if (dev->freeTnodes) {
4664 tn = dev->freeTnodes;
4665 @@ -1233,21 +1258,27 @@ static yaffs_Tnode *yaffs_GetTnodeRaw(ya
4669 + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/
4674 -static yaffs_Tnode *yaffs_GetTnode(yaffs_Device * dev)
4675 +static yaffs_Tnode *yaffs_GetTnode(yaffs_Device *dev)
4677 yaffs_Tnode *tn = yaffs_GetTnodeRaw(dev);
4678 + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
4681 - memset(tn, 0, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8);
4682 + if (tnodeSize < sizeof(yaffs_Tnode))
4683 + tnodeSize = sizeof(yaffs_Tnode);
4686 + memset(tn, 0, tnodeSize);
4691 /* FreeTnode frees up a tnode and puts it back on the free list */
4692 -static void yaffs_FreeTnode(yaffs_Device * dev, yaffs_Tnode * tn)
4693 +static void yaffs_FreeTnode(yaffs_Device *dev, yaffs_Tnode *tn)
4696 #ifdef CONFIG_YAFFS_TNODE_LIST_DEBUG
4697 @@ -1262,9 +1293,10 @@ static void yaffs_FreeTnode(yaffs_Device
4698 dev->freeTnodes = tn;
4701 + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/
4704 -static void yaffs_DeinitialiseTnodes(yaffs_Device * dev)
4705 +static void yaffs_DeinitialiseTnodes(yaffs_Device *dev)
4707 /* Free the list of allocated tnodes */
4708 yaffs_TnodeList *tmp;
4709 @@ -1282,71 +1314,72 @@ static void yaffs_DeinitialiseTnodes(yaf
4710 dev->nFreeTnodes = 0;
4713 -static void yaffs_InitialiseTnodes(yaffs_Device * dev)
4714 +static void yaffs_InitialiseTnodes(yaffs_Device *dev)
4716 dev->allocatedTnodeList = NULL;
4717 dev->freeTnodes = NULL;
4718 dev->nFreeTnodes = 0;
4719 dev->nTnodesCreated = 0;
4724 -void yaffs_PutLevel0Tnode(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos, unsigned val)
4725 +void yaffs_PutLevel0Tnode(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos,
4728 - __u32 *map = (__u32 *)tn;
4733 + __u32 *map = (__u32 *)tn;
4739 - pos &= YAFFS_TNODES_LEVEL0_MASK;
4740 - val >>= dev->chunkGroupBits;
4741 + pos &= YAFFS_TNODES_LEVEL0_MASK;
4742 + val >>= dev->chunkGroupBits;
4744 - bitInMap = pos * dev->tnodeWidth;
4745 - wordInMap = bitInMap /32;
4746 - bitInWord = bitInMap & (32 -1);
4747 + bitInMap = pos * dev->tnodeWidth;
4748 + wordInMap = bitInMap / 32;
4749 + bitInWord = bitInMap & (32 - 1);
4751 - mask = dev->tnodeMask << bitInWord;
4752 + mask = dev->tnodeMask << bitInWord;
4754 - map[wordInMap] &= ~mask;
4755 - map[wordInMap] |= (mask & (val << bitInWord));
4756 + map[wordInMap] &= ~mask;
4757 + map[wordInMap] |= (mask & (val << bitInWord));
4759 - if(dev->tnodeWidth > (32-bitInWord)) {
4760 - bitInWord = (32 - bitInWord);
4762 - mask = dev->tnodeMask >> (/*dev->tnodeWidth -*/ bitInWord);
4763 - map[wordInMap] &= ~mask;
4764 - map[wordInMap] |= (mask & (val >> bitInWord));
4766 + if (dev->tnodeWidth > (32 - bitInWord)) {
4767 + bitInWord = (32 - bitInWord);
4769 + mask = dev->tnodeMask >> (/*dev->tnodeWidth -*/ bitInWord);
4770 + map[wordInMap] &= ~mask;
4771 + map[wordInMap] |= (mask & (val >> bitInWord));
4775 -static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos)
4776 +static __u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn,
4779 - __u32 *map = (__u32 *)tn;
4784 + __u32 *map = (__u32 *)tn;
4790 - pos &= YAFFS_TNODES_LEVEL0_MASK;
4791 + pos &= YAFFS_TNODES_LEVEL0_MASK;
4793 - bitInMap = pos * dev->tnodeWidth;
4794 - wordInMap = bitInMap /32;
4795 - bitInWord = bitInMap & (32 -1);
4796 + bitInMap = pos * dev->tnodeWidth;
4797 + wordInMap = bitInMap / 32;
4798 + bitInWord = bitInMap & (32 - 1);
4800 - val = map[wordInMap] >> bitInWord;
4801 + val = map[wordInMap] >> bitInWord;
4803 - if(dev->tnodeWidth > (32-bitInWord)) {
4804 - bitInWord = (32 - bitInWord);
4806 - val |= (map[wordInMap] << bitInWord);
4808 + if (dev->tnodeWidth > (32 - bitInWord)) {
4809 + bitInWord = (32 - bitInWord);
4811 + val |= (map[wordInMap] << bitInWord);
4814 - val &= dev->tnodeMask;
4815 - val <<= dev->chunkGroupBits;
4816 + val &= dev->tnodeMask;
4817 + val <<= dev->chunkGroupBits;
4823 /* ------------------- End of individual tnode manipulation -----------------*/
4824 @@ -1357,24 +1390,21 @@ static __u32 yaffs_GetChunkGroupBase(yaf
4827 /* FindLevel0Tnode finds the level 0 tnode, if one exists. */
4828 -static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev,
4829 - yaffs_FileStructure * fStruct,
4831 +static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device *dev,
4832 + yaffs_FileStructure *fStruct,
4836 yaffs_Tnode *tn = fStruct->top;
4838 int requiredTallness;
4839 int level = fStruct->topLevel;
4841 /* Check sane level and chunk Id */
4842 - if (level < 0 || level > YAFFS_TNODES_MAX_LEVEL) {
4843 + if (level < 0 || level > YAFFS_TNODES_MAX_LEVEL)
4847 - if (chunkId > YAFFS_MAX_CHUNK_ID) {
4848 + if (chunkId > YAFFS_MAX_CHUNK_ID)
4852 /* First check we're tall enough (ie enough topLevel) */
4854 @@ -1385,22 +1415,17 @@ static yaffs_Tnode *yaffs_FindLevel0Tnod
4858 - if (requiredTallness > fStruct->topLevel) {
4859 - /* Not tall enough, so we can't find it, return NULL. */
4862 + if (requiredTallness > fStruct->topLevel)
4863 + return NULL; /* Not tall enough, so we can't find it */
4865 /* Traverse down to level 0 */
4866 while (level > 0 && tn) {
4868 - internal[(chunkId >>
4869 - ( YAFFS_TNODES_LEVEL0_BITS +
4871 - YAFFS_TNODES_INTERNAL_BITS)
4873 - YAFFS_TNODES_INTERNAL_MASK];
4874 + tn = tn->internal[(chunkId >>
4875 + (YAFFS_TNODES_LEVEL0_BITS +
4877 + YAFFS_TNODES_INTERNAL_BITS)) &
4878 + YAFFS_TNODES_INTERNAL_MASK];
4884 @@ -1417,12 +1442,11 @@ static yaffs_Tnode *yaffs_FindLevel0Tnod
4885 * be plugged into the ttree.
4888 -static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device * dev,
4889 - yaffs_FileStructure * fStruct,
4891 - yaffs_Tnode *passedTn)
4892 +static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device *dev,
4893 + yaffs_FileStructure *fStruct,
4895 + yaffs_Tnode *passedTn)
4898 int requiredTallness;
4901 @@ -1432,13 +1456,11 @@ static yaffs_Tnode *yaffs_AddOrFindLevel
4904 /* Check sane level and page Id */
4905 - if (fStruct->topLevel < 0 || fStruct->topLevel > YAFFS_TNODES_MAX_LEVEL) {
4906 + if (fStruct->topLevel < 0 || fStruct->topLevel > YAFFS_TNODES_MAX_LEVEL)
4910 - if (chunkId > YAFFS_MAX_CHUNK_ID) {
4911 + if (chunkId > YAFFS_MAX_CHUNK_ID)
4915 /* First check we're tall enough (ie enough topLevel) */
4917 @@ -1451,7 +1473,7 @@ static yaffs_Tnode *yaffs_AddOrFindLevel
4920 if (requiredTallness > fStruct->topLevel) {
4921 - /* Not tall enough,gotta make the tree taller */
4922 + /* Not tall enough, gotta make the tree taller */
4923 for (i = fStruct->topLevel; i < requiredTallness; i++) {
4925 tn = yaffs_GetTnode(dev);
4926 @@ -1473,27 +1495,27 @@ static yaffs_Tnode *yaffs_AddOrFindLevel
4927 l = fStruct->topLevel;
4932 while (l > 0 && tn) {
4934 - ( YAFFS_TNODES_LEVEL0_BITS +
4935 + (YAFFS_TNODES_LEVEL0_BITS +
4936 (l - 1) * YAFFS_TNODES_INTERNAL_BITS)) &
4937 YAFFS_TNODES_INTERNAL_MASK;
4940 - if((l>1) && !tn->internal[x]){
4941 + if ((l > 1) && !tn->internal[x]) {
4942 /* Add missing non-level-zero tnode */
4943 tn->internal[x] = yaffs_GetTnode(dev);
4945 - } else if(l == 1) {
4946 + } else if (l == 1) {
4947 /* Looking from level 1 at level 0 */
4950 /* If we already have one, then release it.*/
4951 - if(tn->internal[x])
4952 - yaffs_FreeTnode(dev,tn->internal[x]);
4953 + if (tn->internal[x])
4954 + yaffs_FreeTnode(dev, tn->internal[x]);
4955 tn->internal[x] = passedTn;
4957 - } else if(!tn->internal[x]) {
4958 + } else if (!tn->internal[x]) {
4959 /* Don't have one, none passed in */
4960 tn->internal[x] = yaffs_GetTnode(dev);
4962 @@ -1504,31 +1526,29 @@ static yaffs_Tnode *yaffs_AddOrFindLevel
4965 /* top is level 0 */
4967 - memcpy(tn,passedTn,(dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8);
4968 - yaffs_FreeTnode(dev,passedTn);
4970 + memcpy(tn, passedTn, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8);
4971 + yaffs_FreeTnode(dev, passedTn);
4978 -static int yaffs_FindChunkInGroup(yaffs_Device * dev, int theChunk,
4979 - yaffs_ExtendedTags * tags, int objectId,
4981 +static int yaffs_FindChunkInGroup(yaffs_Device *dev, int theChunk,
4982 + yaffs_ExtendedTags *tags, int objectId,
4987 for (j = 0; theChunk && j < dev->chunkGroupSize; j++) {
4988 - if (yaffs_CheckChunkBit
4989 - (dev, theChunk / dev->nChunksPerBlock,
4990 - theChunk % dev->nChunksPerBlock)) {
4991 + if (yaffs_CheckChunkBit(dev, theChunk / dev->nChunksPerBlock,
4992 + theChunk % dev->nChunksPerBlock)) {
4993 yaffs_ReadChunkWithTagsFromNAND(dev, theChunk, NULL,
4995 if (yaffs_TagsMatch(tags, objectId, chunkInInode)) {
5002 @@ -1543,7 +1563,7 @@ static int yaffs_FindChunkInGroup(yaffs_
5003 * Returns 0 if it stopped early due to hitting the limit and the delete is incomplete.
5006 -static int yaffs_DeleteWorker(yaffs_Object * in, yaffs_Tnode * tn, __u32 level,
5007 +static int yaffs_DeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level,
5008 int chunkOffset, int *limit)
5011 @@ -1557,7 +1577,6 @@ static int yaffs_DeleteWorker(yaffs_Obje
5016 for (i = YAFFS_NTNODES_INTERNAL - 1; allDone && i >= 0;
5018 if (tn->internal[i]) {
5019 @@ -1565,17 +1584,17 @@ static int yaffs_DeleteWorker(yaffs_Obje
5023 - yaffs_DeleteWorker(in,
5030 + yaffs_DeleteWorker(in,
5038 YAFFS_TNODES_INTERNAL_BITS)
5045 yaffs_FreeTnode(dev,
5046 @@ -1584,27 +1603,25 @@ static int yaffs_DeleteWorker(yaffs_Obje
5047 tn->internal[i] = NULL;
5052 return (allDone) ? 1 : 0;
5053 } else if (level == 0) {
5056 for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0 && !hitLimit;
5058 - theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
5060 + theChunk = yaffs_GetChunkGroupBase(dev, tn, i);
5065 - YAFFS_TNODES_LEVEL0_BITS) + i;
5066 + chunkInInode = (chunkOffset <<
5067 + YAFFS_TNODES_LEVEL0_BITS) + i;
5070 - yaffs_FindChunkInGroup(dev,
5075 + yaffs_FindChunkInGroup(dev,
5081 if (foundChunk > 0) {
5082 yaffs_DeleteChunk(dev,
5083 @@ -1613,14 +1630,13 @@ static int yaffs_DeleteWorker(yaffs_Obje
5086 *limit = *limit - 1;
5087 - if (*limit <= 0) {
5095 - yaffs_PutLevel0Tnode(dev,tn,i,0);
5096 + yaffs_PutLevel0Tnode(dev, tn, i, 0);
5100 @@ -1634,9 +1650,8 @@ static int yaffs_DeleteWorker(yaffs_Obje
5104 -static void yaffs_SoftDeleteChunk(yaffs_Device * dev, int chunk)
5105 +static void yaffs_SoftDeleteChunk(yaffs_Device *dev, int chunk)
5108 yaffs_BlockInfo *theBlock;
5110 T(YAFFS_TRACE_DELETION, (TSTR("soft delete chunk %d" TENDSTR), chunk));
5111 @@ -1654,7 +1669,7 @@ static void yaffs_SoftDeleteChunk(yaffs_
5112 * Thus, essentially this is the same as DeleteWorker except that the chunks are soft deleted.
5115 -static int yaffs_SoftDeleteWorker(yaffs_Object * in, yaffs_Tnode * tn,
5116 +static int yaffs_SoftDeleteWorker(yaffs_Object *in, yaffs_Tnode *tn,
5117 __u32 level, int chunkOffset)
5120 @@ -1691,14 +1706,14 @@ static int yaffs_SoftDeleteWorker(yaffs_
5121 } else if (level == 0) {
5123 for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0; i--) {
5124 - theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
5125 + theChunk = yaffs_GetChunkGroupBase(dev, tn, i);
5127 /* Note this does not find the real chunk, only the chunk group.
5128 * We make an assumption that a chunk group is not larger than
5131 yaffs_SoftDeleteChunk(dev, theChunk);
5132 - yaffs_PutLevel0Tnode(dev,tn,i,0);
5133 + yaffs_PutLevel0Tnode(dev, tn, i, 0);
5137 @@ -1712,7 +1727,7 @@ static int yaffs_SoftDeleteWorker(yaffs_
5141 -static void yaffs_SoftDeleteFile(yaffs_Object * obj)
5142 +static void yaffs_SoftDeleteFile(yaffs_Object *obj)
5145 obj->variantType == YAFFS_OBJECT_TYPE_FILE && !obj->softDeleted) {
5146 @@ -1746,8 +1761,8 @@ static void yaffs_SoftDeleteFile(yaffs_O
5147 * by a special case.
5150 -static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device * dev, yaffs_Tnode * tn,
5151 - __u32 level, int del0)
5152 +static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device *dev, yaffs_Tnode *tn,
5153 + __u32 level, int del0)
5157 @@ -1763,9 +1778,8 @@ static yaffs_Tnode *yaffs_PruneWorker(ya
5158 (i == 0) ? del0 : 1);
5161 - if (tn->internal[i]) {
5162 + if (tn->internal[i])
5167 if (hasData == 0 && del0) {
5168 @@ -1781,8 +1795,8 @@ static yaffs_Tnode *yaffs_PruneWorker(ya
5172 -static int yaffs_PruneFileStructure(yaffs_Device * dev,
5173 - yaffs_FileStructure * fStruct)
5174 +static int yaffs_PruneFileStructure(yaffs_Device *dev,
5175 + yaffs_FileStructure *fStruct)
5179 @@ -1805,9 +1819,8 @@ static int yaffs_PruneFileStructure(yaff
5182 for (i = 1; i < YAFFS_NTNODES_INTERNAL; i++) {
5183 - if (tn->internal[i]) {
5184 + if (tn->internal[i])
5190 @@ -1828,7 +1841,7 @@ static int yaffs_PruneFileStructure(yaff
5191 /* yaffs_CreateFreeObjects creates a bunch more objects and
5192 * adds them to the object free list.
5194 -static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects)
5195 +static int yaffs_CreateFreeObjects(yaffs_Device *dev, int nObjects)
5198 yaffs_Object *newObjects;
5199 @@ -1842,9 +1855,9 @@ static int yaffs_CreateFreeObjects(yaffs
5200 list = YMALLOC(sizeof(yaffs_ObjectList));
5202 if (!newObjects || !list) {
5209 T(YAFFS_TRACE_ALLOCATE,
5210 (TSTR("yaffs: Could not allocate more objects" TENDSTR)));
5211 @@ -1854,7 +1867,7 @@ static int yaffs_CreateFreeObjects(yaffs
5212 /* Hook them into the free list */
5213 for (i = 0; i < nObjects - 1; i++) {
5214 newObjects[i].siblings.next =
5215 - (struct list_head *)(&newObjects[i + 1]);
5216 + (struct ylist_head *)(&newObjects[i + 1]);
5219 newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects;
5220 @@ -1873,85 +1886,109 @@ static int yaffs_CreateFreeObjects(yaffs
5223 /* AllocateEmptyObject gets us a clean Object. Tries to make allocate more if we run out */
5224 -static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev)
5225 +static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device *dev)
5227 yaffs_Object *tn = NULL;
5229 +#ifdef VALGRIND_TEST
5230 + tn = YMALLOC(sizeof(yaffs_Object));
5232 /* If there are none left make more */
5233 - if (!dev->freeObjects) {
5234 + if (!dev->freeObjects)
5235 yaffs_CreateFreeObjects(dev, YAFFS_ALLOCATION_NOBJECTS);
5238 if (dev->freeObjects) {
5239 tn = dev->freeObjects;
5241 - (yaffs_Object *) (dev->freeObjects->siblings.next);
5242 + (yaffs_Object *) (dev->freeObjects->siblings.next);
5243 dev->nFreeObjects--;
5248 /* Now sweeten it up... */
5250 memset(tn, 0, sizeof(yaffs_Object));
5251 + tn->beingCreated = 1;
5256 tn->variantType = YAFFS_OBJECT_TYPE_UNKNOWN;
5257 - INIT_LIST_HEAD(&(tn->hardLinks));
5258 - INIT_LIST_HEAD(&(tn->hashLink));
5259 - INIT_LIST_HEAD(&tn->siblings);
5260 + YINIT_LIST_HEAD(&(tn->hardLinks));
5261 + YINIT_LIST_HEAD(&(tn->hashLink));
5262 + YINIT_LIST_HEAD(&tn->siblings);
5265 + /* Now make the directory sane */
5266 + if (dev->rootDir) {
5267 + tn->parent = dev->rootDir;
5268 + ylist_add(&(tn->siblings), &dev->rootDir->variant.directoryVariant.children);
5271 /* Add it to the lost and found directory.
5272 * NB Can't put root or lostNFound in lostNFound so
5273 * check if lostNFound exists first
5275 - if (dev->lostNFoundDir) {
5276 + if (dev->lostNFoundDir)
5277 yaffs_AddObjectToDirectory(dev->lostNFoundDir, tn);
5280 + tn->beingCreated = 0;
5283 + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/
5288 -static yaffs_Object *yaffs_CreateFakeDirectory(yaffs_Device * dev, int number,
5289 +static yaffs_Object *yaffs_CreateFakeDirectory(yaffs_Device *dev, int number,
5294 yaffs_CreateNewObject(dev, number, YAFFS_OBJECT_TYPE_DIRECTORY);
5296 - obj->fake = 1; /* it is fake so it has no NAND presence... */
5297 + obj->fake = 1; /* it is fake so it might have no NAND presence... */
5298 obj->renameAllowed = 0; /* ... and we're not allowed to rename it... */
5299 obj->unlinkAllowed = 0; /* ... or unlink it */
5302 obj->yst_mode = mode;
5304 - obj->chunkId = 0; /* Not a valid chunk. */
5305 + obj->hdrChunk = 0; /* Not a valid chunk. */
5312 -static void yaffs_UnhashObject(yaffs_Object * tn)
5313 +static void yaffs_UnhashObject(yaffs_Object *tn)
5316 yaffs_Device *dev = tn->myDev;
5318 /* If it is still linked into the bucket list, free from the list */
5319 - if (!list_empty(&tn->hashLink)) {
5320 - list_del_init(&tn->hashLink);
5321 + if (!ylist_empty(&tn->hashLink)) {
5322 + ylist_del_init(&tn->hashLink);
5323 bucket = yaffs_HashFunction(tn->objectId);
5324 dev->objectBucket[bucket].count--;
5329 /* FreeObject frees up a Object and puts it back on the free list */
5330 -static void yaffs_FreeObject(yaffs_Object * tn)
5331 +static void yaffs_FreeObject(yaffs_Object *tn)
5334 yaffs_Device *dev = tn->myDev;
5338 + T(YAFFS_TRACE_OS, (TSTR("FreeObject %p inode %p"TENDSTR), tn, tn->myInode));
5343 + if (!ylist_empty(&tn->siblings))
5349 /* We're still hooked up to a cached inode.
5350 * Don't delete now, but mark for later deletion
5351 @@ -1963,24 +2000,28 @@ static void yaffs_FreeObject(yaffs_Objec
5353 yaffs_UnhashObject(tn);
5355 +#ifdef VALGRIND_TEST
5358 /* Link into the free list. */
5359 - tn->siblings.next = (struct list_head *)(dev->freeObjects);
5360 + tn->siblings.next = (struct ylist_head *)(dev->freeObjects);
5361 dev->freeObjects = tn;
5362 dev->nFreeObjects++;
5364 + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/
5369 -void yaffs_HandleDeferedFree(yaffs_Object * obj)
5370 +void yaffs_HandleDeferedFree(yaffs_Object *obj)
5372 - if (obj->deferedFree) {
5373 + if (obj->deferedFree)
5374 yaffs_FreeObject(obj);
5380 -static void yaffs_DeinitialiseObjects(yaffs_Device * dev)
5381 +static void yaffs_DeinitialiseObjects(yaffs_Device *dev)
5383 /* Free the list of allocated Objects */
5385 @@ -1998,7 +2039,7 @@ static void yaffs_DeinitialiseObjects(ya
5386 dev->nFreeObjects = 0;
5389 -static void yaffs_InitialiseObjects(yaffs_Device * dev)
5390 +static void yaffs_InitialiseObjects(yaffs_Device *dev)
5394 @@ -2007,15 +2048,14 @@ static void yaffs_InitialiseObjects(yaff
5395 dev->nFreeObjects = 0;
5397 for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) {
5398 - INIT_LIST_HEAD(&dev->objectBucket[i].list);
5399 + YINIT_LIST_HEAD(&dev->objectBucket[i].list);
5400 dev->objectBucket[i].count = 0;
5405 -static int yaffs_FindNiceObjectBucket(yaffs_Device * dev)
5406 +static int yaffs_FindNiceObjectBucket(yaffs_Device *dev)
5412 int lowest = 999999;
5413 @@ -2049,7 +2089,7 @@ static int yaffs_FindNiceObjectBucket(ya
5417 -static int yaffs_CreateNewObjectNumber(yaffs_Device * dev)
5418 +static int yaffs_CreateNewObjectNumber(yaffs_Device *dev)
5420 int bucket = yaffs_FindNiceObjectBucket(dev);
5422 @@ -2058,7 +2098,7 @@ static int yaffs_CreateNewObjectNumber(y
5426 - struct list_head *i;
5427 + struct ylist_head *i;
5429 __u32 n = (__u32) bucket;
5431 @@ -2068,41 +2108,38 @@ static int yaffs_CreateNewObjectNumber(y
5433 n += YAFFS_NOBJECT_BUCKETS;
5434 if (1 || dev->objectBucket[bucket].count > 0) {
5435 - list_for_each(i, &dev->objectBucket[bucket].list) {
5436 + ylist_for_each(i, &dev->objectBucket[bucket].list) {
5437 /* If there is already one in the list */
5439 - && list_entry(i, yaffs_Object,
5440 - hashLink)->objectId == n) {
5441 + if (i && ylist_entry(i, yaffs_Object,
5442 + hashLink)->objectId == n) {
5453 -static void yaffs_HashObject(yaffs_Object * in)
5454 +static void yaffs_HashObject(yaffs_Object *in)
5456 int bucket = yaffs_HashFunction(in->objectId);
5457 yaffs_Device *dev = in->myDev;
5459 - list_add(&in->hashLink, &dev->objectBucket[bucket].list);
5460 + ylist_add(&in->hashLink, &dev->objectBucket[bucket].list);
5461 dev->objectBucket[bucket].count++;
5465 -yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number)
5466 +yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device *dev, __u32 number)
5468 int bucket = yaffs_HashFunction(number);
5469 - struct list_head *i;
5470 + struct ylist_head *i;
5473 - list_for_each(i, &dev->objectBucket[bucket].list) {
5474 + ylist_for_each(i, &dev->objectBucket[bucket].list) {
5475 /* Look if it is in the list */
5477 - in = list_entry(i, yaffs_Object, hashLink);
5478 + in = ylist_entry(i, yaffs_Object, hashLink);
5479 if (in->objectId == number) {
5481 /* Don't tell the VFS about this one if it is defered free */
5482 @@ -2118,31 +2155,27 @@ yaffs_Object *yaffs_FindObjectByNumber(y
5486 -yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number,
5487 +yaffs_Object *yaffs_CreateNewObject(yaffs_Device *dev, int number,
5488 yaffs_ObjectType type)
5491 yaffs_Object *theObject;
5493 + yaffs_Tnode *tn = NULL;
5497 number = yaffs_CreateNewObjectNumber(dev);
5500 theObject = yaffs_AllocateEmptyObject(dev);
5505 - if(type == YAFFS_OBJECT_TYPE_FILE){
5506 + if (type == YAFFS_OBJECT_TYPE_FILE) {
5507 tn = yaffs_GetTnode(dev);
5510 yaffs_FreeObject(theObject);
5518 theObject->fake = 0;
5519 theObject->renameAllowed = 1;
5520 @@ -2171,8 +2204,8 @@ yaffs_Object *yaffs_CreateNewObject(yaff
5521 theObject->variant.fileVariant.top = tn;
5523 case YAFFS_OBJECT_TYPE_DIRECTORY:
5524 - INIT_LIST_HEAD(&theObject->variant.directoryVariant.
5526 + YINIT_LIST_HEAD(&theObject->variant.directoryVariant.
5529 case YAFFS_OBJECT_TYPE_SYMLINK:
5530 case YAFFS_OBJECT_TYPE_HARDLINK:
5531 @@ -2188,32 +2221,30 @@ yaffs_Object *yaffs_CreateNewObject(yaff
5535 -static yaffs_Object *yaffs_FindOrCreateObjectByNumber(yaffs_Device * dev,
5536 +static yaffs_Object *yaffs_FindOrCreateObjectByNumber(yaffs_Device *dev,
5538 yaffs_ObjectType type)
5540 yaffs_Object *theObject = NULL;
5544 theObject = yaffs_FindObjectByNumber(dev, number);
5549 theObject = yaffs_CreateNewObject(dev, number, type);
5557 -static YCHAR *yaffs_CloneString(const YCHAR * str)
5558 +static YCHAR *yaffs_CloneString(const YCHAR *str)
5560 YCHAR *newStr = NULL;
5563 newStr = YMALLOC((yaffs_strlen(str) + 1) * sizeof(YCHAR));
5566 yaffs_strcpy(newStr, str);
5569 @@ -2229,29 +2260,31 @@ static YCHAR *yaffs_CloneString(const YC
5572 static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type,
5573 - yaffs_Object * parent,
5574 - const YCHAR * name,
5575 + yaffs_Object *parent,
5576 + const YCHAR *name,
5580 - yaffs_Object * equivalentObject,
5581 - const YCHAR * aliasString, __u32 rdev)
5582 + yaffs_Object *equivalentObject,
5583 + const YCHAR *aliasString, __u32 rdev)
5587 + YCHAR *str = NULL;
5589 yaffs_Device *dev = parent->myDev;
5591 /* Check if the entry exists. If it does then fail the call since we don't want a dup.*/
5592 - if (yaffs_FindObjectByName(parent, name)) {
5593 + if (yaffs_FindObjectByName(parent, name))
5597 in = yaffs_CreateNewObject(dev, -1, type);
5599 - if(type == YAFFS_OBJECT_TYPE_SYMLINK){
5601 + return YAFFS_FAIL;
5603 + if (type == YAFFS_OBJECT_TYPE_SYMLINK) {
5604 str = yaffs_CloneString(aliasString);
5607 yaffs_FreeObject(in);
5610 @@ -2260,7 +2293,7 @@ static yaffs_Object *yaffs_MknodObject(y
5617 in->variantType = type;
5619 @@ -2293,10 +2326,10 @@ static yaffs_Object *yaffs_MknodObject(y
5621 case YAFFS_OBJECT_TYPE_HARDLINK:
5622 in->variant.hardLinkVariant.equivalentObject =
5625 in->variant.hardLinkVariant.equivalentObjectId =
5626 - equivalentObject->objectId;
5627 - list_add(&in->hardLinks, &equivalentObject->hardLinks);
5628 + equivalentObject->objectId;
5629 + ylist_add(&in->hardLinks, &equivalentObject->hardLinks);
5631 case YAFFS_OBJECT_TYPE_FILE:
5632 case YAFFS_OBJECT_TYPE_DIRECTORY:
5633 @@ -2308,7 +2341,7 @@ static yaffs_Object *yaffs_MknodObject(y
5635 if (yaffs_UpdateObjectHeader(in, name, 0, 0, 0) < 0) {
5636 /* Could not create the object header, fail the creation */
5637 - yaffs_DestroyObject(in);
5638 + yaffs_DeleteObject(in);
5642 @@ -2317,38 +2350,38 @@ static yaffs_Object *yaffs_MknodObject(y
5646 -yaffs_Object *yaffs_MknodFile(yaffs_Object * parent, const YCHAR * name,
5647 - __u32 mode, __u32 uid, __u32 gid)
5648 +yaffs_Object *yaffs_MknodFile(yaffs_Object *parent, const YCHAR *name,
5649 + __u32 mode, __u32 uid, __u32 gid)
5651 return yaffs_MknodObject(YAFFS_OBJECT_TYPE_FILE, parent, name, mode,
5652 - uid, gid, NULL, NULL, 0);
5653 + uid, gid, NULL, NULL, 0);
5656 -yaffs_Object *yaffs_MknodDirectory(yaffs_Object * parent, const YCHAR * name,
5657 - __u32 mode, __u32 uid, __u32 gid)
5658 +yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent, const YCHAR *name,
5659 + __u32 mode, __u32 uid, __u32 gid)
5661 return yaffs_MknodObject(YAFFS_OBJECT_TYPE_DIRECTORY, parent, name,
5662 mode, uid, gid, NULL, NULL, 0);
5665 -yaffs_Object *yaffs_MknodSpecial(yaffs_Object * parent, const YCHAR * name,
5666 - __u32 mode, __u32 uid, __u32 gid, __u32 rdev)
5667 +yaffs_Object *yaffs_MknodSpecial(yaffs_Object *parent, const YCHAR *name,
5668 + __u32 mode, __u32 uid, __u32 gid, __u32 rdev)
5670 return yaffs_MknodObject(YAFFS_OBJECT_TYPE_SPECIAL, parent, name, mode,
5671 uid, gid, NULL, NULL, rdev);
5674 -yaffs_Object *yaffs_MknodSymLink(yaffs_Object * parent, const YCHAR * name,
5675 - __u32 mode, __u32 uid, __u32 gid,
5676 - const YCHAR * alias)
5677 +yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent, const YCHAR *name,
5678 + __u32 mode, __u32 uid, __u32 gid,
5679 + const YCHAR *alias)
5681 return yaffs_MknodObject(YAFFS_OBJECT_TYPE_SYMLINK, parent, name, mode,
5682 - uid, gid, NULL, alias, 0);
5683 + uid, gid, NULL, alias, 0);
5686 /* yaffs_Link returns the object id of the equivalent object.*/
5687 -yaffs_Object *yaffs_Link(yaffs_Object * parent, const YCHAR * name,
5688 - yaffs_Object * equivalentObject)
5689 +yaffs_Object *yaffs_Link(yaffs_Object *parent, const YCHAR *name,
5690 + yaffs_Object *equivalentObject)
5692 /* Get the real object in case we were fed a hard link as an equivalent object */
5693 equivalentObject = yaffs_GetEquivalentObject(equivalentObject);
5694 @@ -2363,33 +2396,31 @@ yaffs_Object *yaffs_Link(yaffs_Object *
5698 -static int yaffs_ChangeObjectName(yaffs_Object * obj, yaffs_Object * newDir,
5699 - const YCHAR * newName, int force, int shadows)
5700 +static int yaffs_ChangeObjectName(yaffs_Object *obj, yaffs_Object *newDir,
5701 + const YCHAR *newName, int force, int shadows)
5706 yaffs_Object *existingTarget;
5708 - if (newDir == NULL) {
5709 + if (newDir == NULL)
5710 newDir = obj->parent; /* use the old directory */
5713 if (newDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
5714 T(YAFFS_TRACE_ALWAYS,
5716 - ("tragendy: yaffs_ChangeObjectName: newDir is not a directory"
5717 + ("tragedy: yaffs_ChangeObjectName: newDir is not a directory"
5722 /* TODO: Do we need this different handling for YAFFS2 and YAFFS1?? */
5723 - if (obj->myDev->isYaffs2) {
5724 + if (obj->myDev->isYaffs2)
5725 unlinkOp = (newDir == obj->myDev->unlinkedDir);
5728 unlinkOp = (newDir == obj->myDev->unlinkedDir
5729 && obj->variantType == YAFFS_OBJECT_TYPE_FILE);
5732 deleteOp = (newDir == obj->myDev->deletedDir);
5734 @@ -2415,40 +2446,40 @@ static int yaffs_ChangeObjectName(yaffs_
5737 /* If it is a deletion then we mark it as a shrink for gc purposes. */
5738 - if (yaffs_UpdateObjectHeader(obj, newName, 0, deleteOp, shadows)>= 0)
5739 + if (yaffs_UpdateObjectHeader(obj, newName, 0, deleteOp, shadows) >= 0)
5746 -int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName,
5747 - yaffs_Object * newDir, const YCHAR * newName)
5748 +int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName,
5749 + yaffs_Object *newDir, const YCHAR *newName)
5751 - yaffs_Object *obj;
5752 - yaffs_Object *existingTarget;
5753 + yaffs_Object *obj = NULL;
5754 + yaffs_Object *existingTarget = NULL;
5758 + if (!oldDir || oldDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
5760 + if (!newDir || newDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
5763 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
5764 /* Special case for case insemsitive systems (eg. WinCE).
5765 * While look-up is case insensitive, the name isn't.
5766 * Therefore we might want to change x.txt to X.txt
5768 - if (oldDir == newDir && yaffs_strcmp(oldName, newName) == 0) {
5769 + if (oldDir == newDir && yaffs_strcmp(oldName, newName) == 0)
5774 + else if (yaffs_strlen(newName) > YAFFS_MAX_NAME_LENGTH)
5775 + /* ENAMETOOLONG */
5776 + return YAFFS_FAIL;
5778 obj = yaffs_FindObjectByName(oldDir, oldName);
5779 - /* Check new name to long. */
5780 - if (obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK &&
5781 - yaffs_strlen(newName) > YAFFS_MAX_ALIAS_LENGTH)
5782 - /* ENAMETOOLONG */
5783 - return YAFFS_FAIL;
5784 - else if (obj->variantType != YAFFS_OBJECT_TYPE_SYMLINK &&
5785 - yaffs_strlen(newName) > YAFFS_MAX_NAME_LENGTH)
5786 - /* ENAMETOOLONG */
5787 - return YAFFS_FAIL;
5789 if (obj && obj->renameAllowed) {
5791 @@ -2456,8 +2487,8 @@ int yaffs_RenameObject(yaffs_Object * ol
5793 existingTarget = yaffs_FindObjectByName(newDir, newName);
5794 if (existingTarget &&
5795 - existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
5796 - !list_empty(&existingTarget->variant.directoryVariant.children)) {
5797 + existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY &&
5798 + !ylist_empty(&existingTarget->variant.directoryVariant.children)) {
5799 /* There is a target that is a non-empty directory, so we fail */
5800 return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */
5801 } else if (existingTarget && existingTarget != obj) {
5802 @@ -2465,7 +2496,7 @@ int yaffs_RenameObject(yaffs_Object * ol
5803 * but only if it isn't the same object
5805 yaffs_ChangeObjectName(obj, newDir, newName, force,
5806 - existingTarget->objectId);
5807 + existingTarget->objectId);
5808 yaffs_UnlinkObject(existingTarget);
5811 @@ -2476,7 +2507,7 @@ int yaffs_RenameObject(yaffs_Object * ol
5813 /*------------------------- Block Management and Page Allocation ----------------*/
5815 -static int yaffs_InitialiseBlocks(yaffs_Device * dev)
5816 +static int yaffs_InitialiseBlocks(yaffs_Device *dev)
5818 int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1;
5820 @@ -2487,23 +2518,20 @@ static int yaffs_InitialiseBlocks(yaffs_
5822 /* If the first allocation strategy fails, thry the alternate one */
5823 dev->blockInfo = YMALLOC(nBlocks * sizeof(yaffs_BlockInfo));
5824 - if(!dev->blockInfo){
5825 + if (!dev->blockInfo) {
5826 dev->blockInfo = YMALLOC_ALT(nBlocks * sizeof(yaffs_BlockInfo));
5827 dev->blockInfoAlt = 1;
5831 dev->blockInfoAlt = 0;
5833 - if(dev->blockInfo){
5835 + if (dev->blockInfo) {
5836 /* Set up dynamic blockinfo stuff. */
5837 dev->chunkBitmapStride = (dev->nChunksPerBlock + 7) / 8; /* round up bytes */
5838 dev->chunkBits = YMALLOC(dev->chunkBitmapStride * nBlocks);
5839 - if(!dev->chunkBits){
5840 + if (!dev->chunkBits) {
5841 dev->chunkBits = YMALLOC_ALT(dev->chunkBitmapStride * nBlocks);
5842 dev->chunkBitsAlt = 1;
5846 dev->chunkBitsAlt = 0;
5849 @@ -2514,30 +2542,29 @@ static int yaffs_InitialiseBlocks(yaffs_
5856 -static void yaffs_DeinitialiseBlocks(yaffs_Device * dev)
5857 +static void yaffs_DeinitialiseBlocks(yaffs_Device *dev)
5859 - if(dev->blockInfoAlt && dev->blockInfo)
5860 + if (dev->blockInfoAlt && dev->blockInfo)
5861 YFREE_ALT(dev->blockInfo);
5862 - else if(dev->blockInfo)
5863 + else if (dev->blockInfo)
5864 YFREE(dev->blockInfo);
5866 dev->blockInfoAlt = 0;
5868 dev->blockInfo = NULL;
5870 - if(dev->chunkBitsAlt && dev->chunkBits)
5871 + if (dev->chunkBitsAlt && dev->chunkBits)
5872 YFREE_ALT(dev->chunkBits);
5873 - else if(dev->chunkBits)
5874 + else if (dev->chunkBits)
5875 YFREE(dev->chunkBits);
5876 dev->chunkBitsAlt = 0;
5877 dev->chunkBits = NULL;
5880 -static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device * dev,
5881 - yaffs_BlockInfo * bi)
5882 +static int yaffs_BlockNotDisqualifiedFromGC(yaffs_Device *dev,
5883 + yaffs_BlockInfo *bi)
5887 @@ -2556,7 +2583,7 @@ static int yaffs_BlockNotDisqualifiedFro
5888 seq = dev->sequenceNumber;
5890 for (i = dev->internalStartBlock; i <= dev->internalEndBlock;
5893 b = yaffs_GetBlockInfo(dev, i);
5894 if (b->blockState == YAFFS_BLOCK_STATE_FULL &&
5895 (b->pagesInUse - b->softDeletions) <
5896 @@ -2571,38 +2598,36 @@ static int yaffs_BlockNotDisqualifiedFro
5899 return (bi->sequenceNumber <= dev->oldestDirtySequence);
5903 /* FindDiretiestBlock is used to select the dirtiest block (or close enough)
5904 * for garbage collection.
5907 -static int yaffs_FindBlockForGarbageCollection(yaffs_Device * dev,
5909 +static int yaffs_FindBlockForGarbageCollection(yaffs_Device *dev,
5913 int b = dev->currentDirtyChecker;
5919 - int prioritised=0;
5920 + int prioritised = 0;
5921 yaffs_BlockInfo *bi;
5922 int pendingPrioritisedExist = 0;
5924 /* First let's see if we need to grab a prioritised block */
5925 - if(dev->hasPendingPrioritisedGCs){
5926 - for(i = dev->internalStartBlock; i < dev->internalEndBlock && !prioritised; i++){
5927 + if (dev->hasPendingPrioritisedGCs) {
5928 + for (i = dev->internalStartBlock; i < dev->internalEndBlock && !prioritised; i++) {
5930 bi = yaffs_GetBlockInfo(dev, i);
5931 - //yaffs_VerifyBlock(dev,bi,i);
5932 + /* yaffs_VerifyBlock(dev,bi,i); */
5934 - if(bi->gcPrioritise) {
5935 + if (bi->gcPrioritise) {
5936 pendingPrioritisedExist = 1;
5937 - if(bi->blockState == YAFFS_BLOCK_STATE_FULL &&
5938 - yaffs_BlockNotDisqualifiedFromGC(dev, bi)){
5939 + if (bi->blockState == YAFFS_BLOCK_STATE_FULL &&
5940 + yaffs_BlockNotDisqualifiedFromGC(dev, bi)) {
5941 pagesInUse = (bi->pagesInUse - bi->softDeletions);
5944 @@ -2611,7 +2636,7 @@ static int yaffs_FindBlockForGarbageColl
5948 - if(!pendingPrioritisedExist) /* None found, so we can clear this */
5949 + if (!pendingPrioritisedExist) /* None found, so we can clear this */
5950 dev->hasPendingPrioritisedGCs = 0;
5953 @@ -2623,31 +2648,28 @@ static int yaffs_FindBlockForGarbageColl
5955 dev->nonAggressiveSkip--;
5957 - if (!aggressive && (dev->nonAggressiveSkip > 0)) {
5958 + if (!aggressive && (dev->nonAggressiveSkip > 0))
5965 - (aggressive) ? dev->nChunksPerBlock : YAFFS_PASSIVE_GC_CHUNKS + 1;
5966 + (aggressive) ? dev->nChunksPerBlock : YAFFS_PASSIVE_GC_CHUNKS + 1;
5971 dev->internalEndBlock - dev->internalStartBlock + 1;
5975 dev->internalEndBlock - dev->internalStartBlock + 1;
5976 iterations = iterations / 16;
5977 - if (iterations > 200) {
5978 + if (iterations > 200)
5983 for (i = 0; i <= iterations && pagesInUse > 0 && !prioritised; i++) {
5985 - if (b < dev->internalStartBlock || b > dev->internalEndBlock) {
5986 + if (b < dev->internalStartBlock || b > dev->internalEndBlock)
5987 b = dev->internalStartBlock;
5990 if (b < dev->internalStartBlock || b > dev->internalEndBlock) {
5991 T(YAFFS_TRACE_ERROR,
5992 @@ -2657,17 +2679,9 @@ static int yaffs_FindBlockForGarbageColl
5994 bi = yaffs_GetBlockInfo(dev, b);
5997 - if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) {
6004 if (bi->blockState == YAFFS_BLOCK_STATE_FULL &&
6005 - (bi->pagesInUse - bi->softDeletions) < pagesInUse &&
6006 - yaffs_BlockNotDisqualifiedFromGC(dev, bi)) {
6007 + (bi->pagesInUse - bi->softDeletions) < pagesInUse &&
6008 + yaffs_BlockNotDisqualifiedFromGC(dev, bi)) {
6010 pagesInUse = (bi->pagesInUse - bi->softDeletions);
6012 @@ -2678,19 +2692,18 @@ static int yaffs_FindBlockForGarbageColl
6015 (TSTR("GC Selected block %d with %d free, prioritised:%d" TENDSTR), dirtiest,
6016 - dev->nChunksPerBlock - pagesInUse,prioritised));
6017 + dev->nChunksPerBlock - pagesInUse, prioritised));
6020 dev->oldestDirtySequence = 0;
6022 - if (dirtiest > 0) {
6024 dev->nonAggressiveSkip = 4;
6030 -static void yaffs_BlockBecameDirty(yaffs_Device * dev, int blockNo)
6031 +static void yaffs_BlockBecameDirty(yaffs_Device *dev, int blockNo)
6033 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockNo);
6035 @@ -2752,7 +2765,7 @@ static void yaffs_BlockBecameDirty(yaffs
6039 -static int yaffs_FindBlockForAllocation(yaffs_Device * dev)
6040 +static int yaffs_FindBlockForAllocation(yaffs_Device *dev)
6044 @@ -2763,7 +2776,7 @@ static int yaffs_FindBlockForAllocation(
6045 * Can't get space to gc
6047 T(YAFFS_TRACE_ERROR,
6048 - (TSTR("yaffs tragedy: no more eraased blocks" TENDSTR)));
6049 + (TSTR("yaffs tragedy: no more erased blocks" TENDSTR)));
6053 @@ -2794,31 +2807,74 @@ static int yaffs_FindBlockForAllocation(
6055 T(YAFFS_TRACE_ALWAYS,
6057 - ("yaffs tragedy: no more eraased blocks, but there should have been %d"
6058 + ("yaffs tragedy: no more erased blocks, but there should have been %d"
6059 TENDSTR), dev->nErasedBlocks));
6065 -// Check if there's space to allocate...
6066 -// Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()?
6067 -static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev)
6069 +static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev)
6071 + if (!dev->nCheckpointBlocksRequired &&
6073 + /* Not a valid value so recalculate */
6076 + int devBlocks = (dev->endBlock - dev->startBlock + 1);
6079 + tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
6081 + if (tnodeSize < sizeof(yaffs_Tnode))
6082 + tnodeSize = sizeof(yaffs_Tnode);
6084 + nBytes += sizeof(yaffs_CheckpointValidity);
6085 + nBytes += sizeof(yaffs_CheckpointDevice);
6086 + nBytes += devBlocks * sizeof(yaffs_BlockInfo);
6087 + nBytes += devBlocks * dev->chunkBitmapStride;
6088 + nBytes += (sizeof(yaffs_CheckpointObject) + sizeof(__u32)) * (dev->nObjectsCreated - dev->nFreeObjects);
6089 + nBytes += (tnodeSize + sizeof(__u32)) * (dev->nTnodesCreated - dev->nFreeTnodes);
6090 + nBytes += sizeof(yaffs_CheckpointValidity);
6091 + nBytes += sizeof(__u32); /* checksum*/
6093 + /* Round up and add 2 blocks to allow for some bad blocks, so add 3 */
6095 + nBlocks = (nBytes/(dev->nDataBytesPerChunk * dev->nChunksPerBlock)) + 3;
6097 + dev->nCheckpointBlocksRequired = nBlocks;
6100 + return dev->nCheckpointBlocksRequired;
6104 + * Check if there's space to allocate...
6105 + * Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()?
6107 +static int yaffs_CheckSpaceForAllocation(yaffs_Device *dev)
6110 int reservedBlocks = dev->nReservedBlocks;
6111 int checkpointBlocks;
6113 - checkpointBlocks = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint;
6114 - if(checkpointBlocks < 0)
6115 + if (dev->isYaffs2) {
6116 + checkpointBlocks = yaffs_CalcCheckpointBlocksRequired(dev) -
6117 + dev->blocksInCheckpoint;
6118 + if (checkpointBlocks < 0)
6119 + checkpointBlocks = 0;
6121 checkpointBlocks = 0;
6124 reservedChunks = ((reservedBlocks + checkpointBlocks) * dev->nChunksPerBlock);
6126 return (dev->nFreeChunks > reservedChunks);
6129 -static int yaffs_AllocateChunk(yaffs_Device * dev, int useReserve, yaffs_BlockInfo **blockUsedPtr)
6130 +static int yaffs_AllocateChunk(yaffs_Device *dev, int useReserve,
6131 + yaffs_BlockInfo **blockUsedPtr)
6134 yaffs_BlockInfo *bi;
6135 @@ -2835,7 +2891,7 @@ static int yaffs_AllocateChunk(yaffs_Dev
6138 if (dev->nErasedBlocks < dev->nReservedBlocks
6139 - && dev->allocationPage == 0) {
6140 + && dev->allocationPage == 0) {
6141 T(YAFFS_TRACE_ALLOCATE, (TSTR("Allocating reserve" TENDSTR)));
6144 @@ -2844,10 +2900,10 @@ static int yaffs_AllocateChunk(yaffs_Dev
6145 bi = yaffs_GetBlockInfo(dev, dev->allocationBlock);
6147 retVal = (dev->allocationBlock * dev->nChunksPerBlock) +
6148 - dev->allocationPage;
6149 + dev->allocationPage;
6151 yaffs_SetChunkBit(dev, dev->allocationBlock,
6152 - dev->allocationPage);
6153 + dev->allocationPage);
6155 dev->allocationPage++;
6157 @@ -2859,43 +2915,43 @@ static int yaffs_AllocateChunk(yaffs_Dev
6158 dev->allocationBlock = -1;
6168 T(YAFFS_TRACE_ERROR,
6169 - (TSTR("!!!!!!!!! Allocator out !!!!!!!!!!!!!!!!!" TENDSTR)));
6170 + (TSTR("!!!!!!!!! Allocator out !!!!!!!!!!!!!!!!!" TENDSTR)));
6175 -static int yaffs_GetErasedChunks(yaffs_Device * dev)
6176 +static int yaffs_GetErasedChunks(yaffs_Device *dev)
6180 n = dev->nErasedBlocks * dev->nChunksPerBlock;
6182 - if (dev->allocationBlock > 0) {
6183 + if (dev->allocationBlock > 0)
6184 n += (dev->nChunksPerBlock - dev->allocationPage);
6191 -static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block)
6192 +static int yaffs_GarbageCollectBlock(yaffs_Device *dev, int block,
6199 int retVal = YAFFS_OK;
6202 int isCheckpointBlock;
6206 int chunksBefore = yaffs_GetErasedChunks(dev);
6208 @@ -2911,8 +2967,11 @@ static int yaffs_GarbageCollectBlock(yaf
6209 bi->blockState = YAFFS_BLOCK_STATE_COLLECTING;
6211 T(YAFFS_TRACE_TRACING,
6212 - (TSTR("Collecting block %d, in use %d, shrink %d, " TENDSTR), block,
6213 - bi->pagesInUse, bi->hasShrinkHeader));
6214 + (TSTR("Collecting block %d, in use %d, shrink %d, wholeBlock %d" TENDSTR),
6217 + bi->hasShrinkHeader,
6220 /*yaffs_VerifyFreeChunks(dev); */
6222 @@ -2926,26 +2985,33 @@ static int yaffs_GarbageCollectBlock(yaf
6225 if (isCheckpointBlock ||
6226 - !yaffs_StillSomeChunkBits(dev, block)) {
6227 + !yaffs_StillSomeChunkBits(dev, block)) {
6228 T(YAFFS_TRACE_TRACING,
6230 - ("Collecting block %d that has no chunks in use" TENDSTR),
6233 + ("Collecting block %d that has no chunks in use" TENDSTR),
6235 yaffs_BlockBecameDirty(dev, block);
6238 __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__);
6240 - yaffs_VerifyBlock(dev,bi,block);
6241 + yaffs_VerifyBlock(dev, bi, block);
6243 - for (chunkInBlock = 0, oldChunk = block * dev->nChunksPerBlock;
6244 - chunkInBlock < dev->nChunksPerBlock
6245 - && yaffs_StillSomeChunkBits(dev, block);
6246 - chunkInBlock++, oldChunk++) {
6247 - if (yaffs_CheckChunkBit(dev, block, chunkInBlock)) {
6248 + maxCopies = (wholeBlock) ? dev->nChunksPerBlock : 10;
6249 + oldChunk = block * dev->nChunksPerBlock + dev->gcChunk;
6251 + for (/* init already done */;
6252 + retVal == YAFFS_OK &&
6253 + dev->gcChunk < dev->nChunksPerBlock &&
6254 + (bi->blockState == YAFFS_BLOCK_STATE_COLLECTING) &&
6256 + dev->gcChunk++, oldChunk++) {
6257 + if (yaffs_CheckChunkBit(dev, block, dev->gcChunk)) {
6259 /* This page is in use and might need to be copied off */
6265 yaffs_InitialiseTags(&tags);
6266 @@ -2959,22 +3025,22 @@ static int yaffs_GarbageCollectBlock(yaf
6268 T(YAFFS_TRACE_GC_DETAIL,
6270 - ("Collecting page %d, %d %d %d " TENDSTR),
6271 - chunkInBlock, tags.objectId, tags.chunkId,
6272 + ("Collecting chunk in block %d, %d %d %d " TENDSTR),
6273 + dev->gcChunk, tags.objectId, tags.chunkId,
6276 - if(object && !yaffs_SkipVerification(dev)){
6277 - if(tags.chunkId == 0)
6278 - matchingChunk = object->chunkId;
6279 - else if(object->softDeleted)
6280 + if (object && !yaffs_SkipVerification(dev)) {
6281 + if (tags.chunkId == 0)
6282 + matchingChunk = object->hdrChunk;
6283 + else if (object->softDeleted)
6284 matchingChunk = oldChunk; /* Defeat the test */
6286 - matchingChunk = yaffs_FindChunkInFile(object,tags.chunkId,NULL);
6287 + matchingChunk = yaffs_FindChunkInFile(object, tags.chunkId, NULL);
6289 - if(oldChunk != matchingChunk)
6290 + if (oldChunk != matchingChunk)
6291 T(YAFFS_TRACE_ERROR,
6292 (TSTR("gc: page in gc mismatch: %d %d %d %d"TENDSTR),
6293 - oldChunk,matchingChunk,tags.objectId, tags.chunkId));
6294 + oldChunk, matchingChunk, tags.objectId, tags.chunkId));
6298 @@ -2986,9 +3052,11 @@ static int yaffs_GarbageCollectBlock(yaf
6299 tags.objectId, tags.chunkId, tags.byteCount));
6302 - if (object && object->deleted
6303 - && tags.chunkId != 0) {
6304 - /* Data chunk in a deleted file, throw it away
6306 + object->deleted &&
6307 + object->softDeleted &&
6308 + tags.chunkId != 0) {
6309 + /* Data chunk in a soft deleted file, throw it away
6310 * It's a soft deleted data chunk,
6311 * No need to copy this, just forget about it and
6312 * fix up the object.
6313 @@ -3003,13 +3071,12 @@ static int yaffs_GarbageCollectBlock(yaf
6318 - /* Todo object && object->deleted && object->nDataChunks == 0 */
6321 + /* Todo object && object->deleted && object->nDataChunks == 0 */
6322 /* Deleted object header with no data chunks.
6323 * Can be discarded and the file deleted.
6325 - object->chunkId = 0;
6326 + object->hdrChunk = 0;
6327 yaffs_FreeTnode(object->myDev,
6330 @@ -3031,17 +3098,14 @@ static int yaffs_GarbageCollectBlock(yaf
6331 * We need to nuke the shrinkheader flags first
6332 * We no longer want the shrinkHeader flag since its work is done
6333 * and if it is left in place it will mess up scanning.
6334 - * Also, clear out any shadowing stuff
6337 yaffs_ObjectHeader *oh;
6338 oh = (yaffs_ObjectHeader *)buffer;
6340 - oh->shadowsObject = -1;
6341 - tags.extraShadows = 0;
6342 tags.extraIsShrinkHeader = 0;
6344 - yaffs_VerifyObjectHeader(object,oh,&tags,1);
6345 + yaffs_VerifyObjectHeader(object, oh, &tags, 1);
6349 @@ -3055,7 +3119,7 @@ static int yaffs_GarbageCollectBlock(yaf
6351 if (tags.chunkId == 0) {
6353 - object->chunkId = newChunk;
6354 + object->hdrChunk = newChunk;
6355 object->serial = tags.serialNumber;
6357 /* It's a data chunk */
6358 @@ -3067,7 +3131,8 @@ static int yaffs_GarbageCollectBlock(yaf
6362 - yaffs_DeleteChunk(dev, oldChunk, markNAND, __LINE__);
6363 + if (retVal == YAFFS_OK)
6364 + yaffs_DeleteChunk(dev, oldChunk, markNAND, __LINE__);
6368 @@ -3098,18 +3163,25 @@ static int yaffs_GarbageCollectBlock(yaf
6372 - yaffs_VerifyCollectedBlock(dev,bi,block);
6373 + yaffs_VerifyCollectedBlock(dev, bi, block);
6375 - if (chunksBefore >= (chunksAfter = yaffs_GetErasedChunks(dev))) {
6376 + chunksAfter = yaffs_GetErasedChunks(dev);
6377 + if (chunksBefore >= chunksAfter) {
6380 ("gc did not increase free chunks before %d after %d"
6381 TENDSTR), chunksBefore, chunksAfter));
6384 + /* If the gc completed then clear the current gcBlock so that we find another. */
6385 + if (bi->blockState != YAFFS_BLOCK_STATE_COLLECTING) {
6386 + dev->gcBlock = -1;
6396 /* New garbage collector
6397 @@ -3121,7 +3193,7 @@ static int yaffs_GarbageCollectBlock(yaf
6398 * The idea is to help clear out space in a more spread-out manner.
6399 * Dunno if it really does anything useful.
6401 -static int yaffs_CheckGarbageCollection(yaffs_Device * dev)
6402 +static int yaffs_CheckGarbageCollection(yaffs_Device *dev)
6406 @@ -3142,8 +3214,8 @@ static int yaffs_CheckGarbageCollection(
6410 - checkpointBlockAdjust = (dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint);
6411 - if(checkpointBlockAdjust < 0)
6412 + checkpointBlockAdjust = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint;
6413 + if (checkpointBlockAdjust < 0)
6414 checkpointBlockAdjust = 0;
6416 if (dev->nErasedBlocks < (dev->nReservedBlocks + checkpointBlockAdjust + 2)) {
6417 @@ -3154,20 +3226,24 @@ static int yaffs_CheckGarbageCollection(
6421 - block = yaffs_FindBlockForGarbageCollection(dev, aggressive);
6422 + if (dev->gcBlock <= 0) {
6423 + dev->gcBlock = yaffs_FindBlockForGarbageCollection(dev, aggressive);
6427 + block = dev->gcBlock;
6430 dev->garbageCollections++;
6431 - if (!aggressive) {
6433 dev->passiveGarbageCollections++;
6438 ("yaffs: GC erasedBlocks %d aggressive %d" TENDSTR),
6439 dev->nErasedBlocks, aggressive));
6441 - gcOk = yaffs_GarbageCollectBlock(dev, block);
6442 + gcOk = yaffs_GarbageCollectBlock(dev, block, aggressive);
6445 if (dev->nErasedBlocks < (dev->nReservedBlocks) && block > 0) {
6446 @@ -3176,15 +3252,16 @@ static int yaffs_CheckGarbageCollection(
6447 ("yaffs: GC !!!no reclaim!!! erasedBlocks %d after try %d block %d"
6448 TENDSTR), dev->nErasedBlocks, maxTries, block));
6450 - } while ((dev->nErasedBlocks < dev->nReservedBlocks) && (block > 0)
6451 - && (maxTries < 2));
6452 + } while ((dev->nErasedBlocks < dev->nReservedBlocks) &&
6456 return aggressive ? gcOk : YAFFS_OK;
6459 /*------------------------- TAGS --------------------------------*/
6461 -static int yaffs_TagsMatch(const yaffs_ExtendedTags * tags, int objectId,
6462 +static int yaffs_TagsMatch(const yaffs_ExtendedTags *tags, int objectId,
6465 return (tags->chunkId == chunkInObject &&
6466 @@ -3195,8 +3272,8 @@ static int yaffs_TagsMatch(const yaffs_E
6468 /*-------------------- Data file manipulation -----------------*/
6470 -static int yaffs_FindChunkInFile(yaffs_Object * in, int chunkInInode,
6471 - yaffs_ExtendedTags * tags)
6472 +static int yaffs_FindChunkInFile(yaffs_Object *in, int chunkInInode,
6473 + yaffs_ExtendedTags *tags)
6475 /*Get the Tnode, then get the level 0 offset chunk offset */
6477 @@ -3214,7 +3291,7 @@ static int yaffs_FindChunkInFile(yaffs_O
6478 tn = yaffs_FindLevel0Tnode(dev, &in->variant.fileVariant, chunkInInode);
6481 - theChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode);
6482 + theChunk = yaffs_GetChunkGroupBase(dev, tn, chunkInInode);
6485 yaffs_FindChunkInGroup(dev, theChunk, tags, in->objectId,
6486 @@ -3223,8 +3300,8 @@ static int yaffs_FindChunkInFile(yaffs_O
6490 -static int yaffs_FindAndDeleteChunkInFile(yaffs_Object * in, int chunkInInode,
6491 - yaffs_ExtendedTags * tags)
6492 +static int yaffs_FindAndDeleteChunkInFile(yaffs_Object *in, int chunkInInode,
6493 + yaffs_ExtendedTags *tags)
6495 /* Get the Tnode, then get the level 0 offset chunk offset */
6497 @@ -3243,29 +3320,23 @@ static int yaffs_FindAndDeleteChunkInFil
6501 - theChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode);
6502 + theChunk = yaffs_GetChunkGroupBase(dev, tn, chunkInInode);
6505 yaffs_FindChunkInGroup(dev, theChunk, tags, in->objectId,
6508 /* Delete the entry in the filestructure (if found) */
6509 - if (retVal != -1) {
6510 - yaffs_PutLevel0Tnode(dev,tn,chunkInInode,0);
6513 - /*T(("No level 0 found for %d\n", chunkInInode)); */
6515 + yaffs_PutLevel0Tnode(dev, tn, chunkInInode, 0);
6518 - if (retVal == -1) {
6519 - /* T(("Could not find %d to delete\n",chunkInInode)); */
6524 #ifdef YAFFS_PARANOID
6526 -static int yaffs_CheckFileSanity(yaffs_Object * in)
6527 +static int yaffs_CheckFileSanity(yaffs_Object *in)
6531 @@ -3278,10 +3349,8 @@ static int yaffs_CheckFileSanity(yaffs_O
6535 - if (in->variantType != YAFFS_OBJECT_TYPE_FILE) {
6536 - /* T(("Object not a file\n")); */
6537 + if (in->variantType != YAFFS_OBJECT_TYPE_FILE)
6541 objId = in->objectId;
6542 fSize = in->variant.fileVariant.fileSize;
6543 @@ -3294,7 +3363,7 @@ static int yaffs_CheckFileSanity(yaffs_O
6547 - theChunk = yaffs_GetChunkGroupBase(dev,tn,chunk);
6548 + theChunk = yaffs_GetChunkGroupBase(dev, tn, chunk);
6550 if (yaffs_CheckChunkBits
6551 (dev, theChunk / dev->nChunksPerBlock,
6552 @@ -3323,7 +3392,7 @@ static int yaffs_CheckFileSanity(yaffs_O
6556 -static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode,
6557 +static int yaffs_PutChunkIntoFile(yaffs_Object *in, int chunkInInode,
6558 int chunkInNAND, int inScan)
6560 /* NB inScan is zero unless scanning.
6561 @@ -3358,11 +3427,10 @@ static int yaffs_PutChunkIntoFile(yaffs_
6562 &in->variant.fileVariant,
6570 - existingChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode);
6571 + existingChunk = yaffs_GetChunkGroupBase(dev, tn, chunkInInode);
6574 /* If we're scanning then we need to test for duplicates
6575 @@ -3374,7 +3442,7 @@ static int yaffs_PutChunkIntoFile(yaffs_
6576 * Update: For backward scanning we don't need to re-read tags so this is quite cheap.
6579 - if (existingChunk != 0) {
6580 + if (existingChunk > 0) {
6581 /* NB Right now existing chunk will not be real chunkId if the device >= 32MB
6582 * thus we have to do a FindChunkInFile to get the real chunk id.
6584 @@ -3411,8 +3479,10 @@ static int yaffs_PutChunkIntoFile(yaffs_
6585 * not be loaded during a scan
6588 - newSerial = newTags.serialNumber;
6589 - existingSerial = existingTags.serialNumber;
6591 + newSerial = newTags.serialNumber;
6592 + existingSerial = existingTags.serialNumber;
6596 (in->myDev->isYaffs2 ||
6597 @@ -3437,24 +3507,23 @@ static int yaffs_PutChunkIntoFile(yaffs_
6601 - if (existingChunk == 0) {
6602 + if (existingChunk == 0)
6606 - yaffs_PutLevel0Tnode(dev,tn,chunkInInode,chunkInNAND);
6607 + yaffs_PutLevel0Tnode(dev, tn, chunkInInode, chunkInNAND);
6612 -static int yaffs_ReadChunkDataFromObject(yaffs_Object * in, int chunkInInode,
6614 +static int yaffs_ReadChunkDataFromObject(yaffs_Object *in, int chunkInInode,
6617 int chunkInNAND = yaffs_FindChunkInFile(in, chunkInInode, NULL);
6619 - if (chunkInNAND >= 0) {
6620 + if (chunkInNAND >= 0)
6621 return yaffs_ReadChunkWithTagsFromNAND(in->myDev, chunkInNAND,
6626 T(YAFFS_TRACE_NANDACCESS,
6627 (TSTR("Chunk %d not found zero instead" TENDSTR),
6629 @@ -3465,7 +3534,7 @@ static int yaffs_ReadChunkDataFromObject
6633 -void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn)
6634 +void yaffs_DeleteChunk(yaffs_Device *dev, int chunkId, int markNAND, int lyn)
6638 @@ -3475,16 +3544,15 @@ void yaffs_DeleteChunk(yaffs_Device * de
6644 block = chunkId / dev->nChunksPerBlock;
6645 page = chunkId % dev->nChunksPerBlock;
6648 - if(!yaffs_CheckChunkBit(dev,block,page))
6649 + if (!yaffs_CheckChunkBit(dev, block, page))
6650 T(YAFFS_TRACE_VERIFY,
6651 - (TSTR("Deleting invalid chunk %d"TENDSTR),
6653 + (TSTR("Deleting invalid chunk %d"TENDSTR),
6656 bi = yaffs_GetBlockInfo(dev, block);
6658 @@ -3524,14 +3592,12 @@ void yaffs_DeleteChunk(yaffs_Device * de
6659 yaffs_BlockBecameDirty(dev, block);
6663 - /* T(("Bad news deleting chunk %d\n",chunkId)); */
6668 -static int yaffs_WriteChunkDataToObject(yaffs_Object * in, int chunkInInode,
6669 - const __u8 * buffer, int nBytes,
6670 +static int yaffs_WriteChunkDataToObject(yaffs_Object *in, int chunkInInode,
6671 + const __u8 *buffer, int nBytes,
6674 /* Find old chunk Need to do this to get serial number
6675 @@ -3561,6 +3627,12 @@ static int yaffs_WriteChunkDataToObject(
6676 (prevChunkId >= 0) ? prevTags.serialNumber + 1 : 1;
6677 newTags.byteCount = nBytes;
6679 + if (nBytes < 1 || nBytes > dev->totalBytesPerChunk) {
6680 + T(YAFFS_TRACE_ERROR,
6681 + (TSTR("Writing %d bytes to chunk!!!!!!!!!" TENDSTR), nBytes));
6686 yaffs_WriteNewChunkWithTagsToNAND(dev, buffer, &newTags,
6688 @@ -3568,11 +3640,9 @@ static int yaffs_WriteChunkDataToObject(
6689 if (newChunkId >= 0) {
6690 yaffs_PutChunkIntoFile(in, chunkInInode, newChunkId, 0);
6692 - if (prevChunkId >= 0) {
6693 + if (prevChunkId >= 0)
6694 yaffs_DeleteChunk(dev, prevChunkId, 1, __LINE__);
6698 yaffs_CheckFileSanity(in);
6701 @@ -3582,7 +3652,7 @@ static int yaffs_WriteChunkDataToObject(
6702 /* UpdateObjectHeader updates the header on NAND for an object.
6703 * If name is not NULL, then that new name is used.
6705 -int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force,
6706 +int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name, int force,
6707 int isShrink, int shadows)
6710 @@ -3603,9 +3673,12 @@ int yaffs_UpdateObjectHeader(yaffs_Objec
6712 yaffs_ObjectHeader *oh = NULL;
6714 - yaffs_strcpy(oldName,"silly old name");
6715 + yaffs_strcpy(oldName, _Y("silly old name"));
6717 - if (!in->fake || force) {
6720 + in == dev->rootDir || /* The rootDir should also be saved */
6723 yaffs_CheckGarbageCollection(dev);
6724 yaffs_CheckObjectDetailsLoaded(in);
6725 @@ -3613,13 +3686,13 @@ int yaffs_UpdateObjectHeader(yaffs_Objec
6726 buffer = yaffs_GetTempBuffer(in->myDev, __LINE__);
6727 oh = (yaffs_ObjectHeader *) buffer;
6729 - prevChunkId = in->chunkId;
6730 + prevChunkId = in->hdrChunk;
6732 - if (prevChunkId >= 0) {
6733 + if (prevChunkId > 0) {
6734 result = yaffs_ReadChunkWithTagsFromNAND(dev, prevChunkId,
6737 - yaffs_VerifyObjectHeader(in,oh,&oldTags,0);
6738 + yaffs_VerifyObjectHeader(in, oh, &oldTags, 0);
6740 memcpy(oldName, oh->name, sizeof(oh->name));
6742 @@ -3628,7 +3701,7 @@ int yaffs_UpdateObjectHeader(yaffs_Objec
6744 oh->type = in->variantType;
6745 oh->yst_mode = in->yst_mode;
6746 - oh->shadowsObject = shadows;
6747 + oh->shadowsObject = oh->inbandShadowsObject = shadows;
6749 #ifdef CONFIG_YAFFS_WINCE
6750 oh->win_atime[0] = in->win_atime[0];
6751 @@ -3645,20 +3718,18 @@ int yaffs_UpdateObjectHeader(yaffs_Objec
6752 oh->yst_ctime = in->yst_ctime;
6753 oh->yst_rdev = in->yst_rdev;
6757 oh->parentObjectId = in->parent->objectId;
6760 oh->parentObjectId = 0;
6763 if (name && *name) {
6764 memset(oh->name, 0, sizeof(oh->name));
6765 yaffs_strncpy(oh->name, name, YAFFS_MAX_NAME_LENGTH);
6766 - } else if (prevChunkId>=0) {
6767 + } else if (prevChunkId >= 0)
6768 memcpy(oh->name, oldName, sizeof(oh->name));
6771 memset(oh->name, 0, sizeof(oh->name));
6774 oh->isShrink = isShrink;
6776 @@ -3708,7 +3779,7 @@ int yaffs_UpdateObjectHeader(yaffs_Objec
6777 newTags.extraShadows = (oh->shadowsObject > 0) ? 1 : 0;
6778 newTags.extraObjectType = in->variantType;
6780 - yaffs_VerifyObjectHeader(in,oh,&newTags,1);
6781 + yaffs_VerifyObjectHeader(in, oh, &newTags, 1);
6783 /* Create new chunk in NAND */
6785 @@ -3717,20 +3788,20 @@ int yaffs_UpdateObjectHeader(yaffs_Objec
6787 if (newChunkId >= 0) {
6789 - in->chunkId = newChunkId;
6790 + in->hdrChunk = newChunkId;
6792 if (prevChunkId >= 0) {
6793 yaffs_DeleteChunk(dev, prevChunkId, 1,
6797 - if(!yaffs_ObjectHasCachedWriteData(in))
6798 + if (!yaffs_ObjectHasCachedWriteData(in))
6801 /* If this was a shrink, then mark the block that the chunk lives on */
6803 bi = yaffs_GetBlockInfo(in->myDev,
6804 - newChunkId /in->myDev-> nChunksPerBlock);
6805 + newChunkId / in->myDev->nChunksPerBlock);
6806 bi->hasShrinkHeader = 1;
6809 @@ -3766,7 +3837,7 @@ static int yaffs_ObjectHasCachedWriteDat
6810 yaffs_ChunkCache *cache;
6811 int nCaches = obj->myDev->nShortOpCaches;
6813 - for(i = 0; i < nCaches; i++){
6814 + for (i = 0; i < nCaches; i++) {
6815 cache = &dev->srCache[i];
6816 if (cache->object == obj &&
6818 @@ -3777,7 +3848,7 @@ static int yaffs_ObjectHasCachedWriteDat
6822 -static void yaffs_FlushFilesChunkCache(yaffs_Object * obj)
6823 +static void yaffs_FlushFilesChunkCache(yaffs_Object *obj)
6825 yaffs_Device *dev = obj->myDev;
6826 int lowest = -99; /* Stop compiler whining. */
6827 @@ -3844,16 +3915,16 @@ void yaffs_FlushEntireDeviceCache(yaffs_
6831 - for( i = 0; i < nCaches && !obj; i++) {
6832 + for (i = 0; i < nCaches && !obj; i++) {
6833 if (dev->srCache[i].object &&
6834 dev->srCache[i].dirty)
6835 obj = dev->srCache[i].object;
6840 yaffs_FlushFilesChunkCache(obj);
6847 @@ -3863,41 +3934,21 @@ void yaffs_FlushEntireDeviceCache(yaffs_
6848 * Then look for the least recently used non-dirty one.
6849 * Then look for the least recently used dirty one...., flush and look again.
6851 -static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device * dev)
6852 +static yaffs_ChunkCache *yaffs_GrabChunkCacheWorker(yaffs_Device *dev)
6858 if (dev->nShortOpCaches > 0) {
6859 for (i = 0; i < dev->nShortOpCaches; i++) {
6860 if (!dev->srCache[i].object)
6861 return &dev->srCache[i];
6870 - usage = 0; /* just to stop the compiler grizzling */
6872 - for (i = 0; i < dev->nShortOpCaches; i++) {
6873 - if (!dev->srCache[i].dirty &&
6874 - ((dev->srCache[i].lastUse < usage && theOne >= 0) ||
6876 - usage = dev->srCache[i].lastUse;
6882 - return theOne >= 0 ? &dev->srCache[theOne] : NULL;
6889 -static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device * dev)
6890 +static yaffs_ChunkCache *yaffs_GrabChunkCache(yaffs_Device *dev)
6892 yaffs_ChunkCache *cache;
6893 yaffs_Object *theObj;
6894 @@ -3927,8 +3978,7 @@ static yaffs_ChunkCache *yaffs_GrabChunk
6895 for (i = 0; i < dev->nShortOpCaches; i++) {
6896 if (dev->srCache[i].object &&
6897 !dev->srCache[i].locked &&
6898 - (dev->srCache[i].lastUse < usage || !cache))
6900 + (dev->srCache[i].lastUse < usage || !cache)) {
6901 usage = dev->srCache[i].lastUse;
6902 theObj = dev->srCache[i].object;
6903 cache = &dev->srCache[i];
6904 @@ -3950,7 +4000,7 @@ static yaffs_ChunkCache *yaffs_GrabChunk
6907 /* Find a cached chunk */
6908 -static yaffs_ChunkCache *yaffs_FindChunkCache(const yaffs_Object * obj,
6909 +static yaffs_ChunkCache *yaffs_FindChunkCache(const yaffs_Object *obj,
6912 yaffs_Device *dev = obj->myDev;
6913 @@ -3969,7 +4019,7 @@ static yaffs_ChunkCache *yaffs_FindChunk
6916 /* Mark the chunk for the least recently used algorithym */
6917 -static void yaffs_UseChunkCache(yaffs_Device * dev, yaffs_ChunkCache * cache,
6918 +static void yaffs_UseChunkCache(yaffs_Device *dev, yaffs_ChunkCache *cache,
6922 @@ -3977,9 +4027,9 @@ static void yaffs_UseChunkCache(yaffs_De
6923 if (dev->srLastUse < 0 || dev->srLastUse > 100000000) {
6924 /* Reset the cache usages */
6926 - for (i = 1; i < dev->nShortOpCaches; i++) {
6927 + for (i = 1; i < dev->nShortOpCaches; i++)
6928 dev->srCache[i].lastUse = 0;
6934 @@ -3987,9 +4037,8 @@ static void yaffs_UseChunkCache(yaffs_De
6936 cache->lastUse = dev->srLastUse;
6945 @@ -3997,21 +4046,20 @@ static void yaffs_UseChunkCache(yaffs_De
6946 * Do this when a whole page gets written,
6947 * ie the short cache for this page is no longer valid.
6949 -static void yaffs_InvalidateChunkCache(yaffs_Object * object, int chunkId)
6950 +static void yaffs_InvalidateChunkCache(yaffs_Object *object, int chunkId)
6952 if (object->myDev->nShortOpCaches > 0) {
6953 yaffs_ChunkCache *cache = yaffs_FindChunkCache(object, chunkId);
6957 cache->object = NULL;
6962 /* Invalidate all the cache pages associated with this object
6963 * Do this whenever ther file is deleted or resized.
6965 -static void yaffs_InvalidateWholeChunkCache(yaffs_Object * in)
6966 +static void yaffs_InvalidateWholeChunkCache(yaffs_Object *in)
6969 yaffs_Device *dev = in->myDev;
6970 @@ -4019,9 +4067,8 @@ static void yaffs_InvalidateWholeChunkCa
6971 if (dev->nShortOpCaches > 0) {
6972 /* Invalidate it. */
6973 for (i = 0; i < dev->nShortOpCaches; i++) {
6974 - if (dev->srCache[i].object == in) {
6975 + if (dev->srCache[i].object == in)
6976 dev->srCache[i].object = NULL;
6981 @@ -4029,18 +4076,18 @@ static void yaffs_InvalidateWholeChunkCa
6982 /*--------------------- Checkpointing --------------------*/
6985 -static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev,int head)
6986 +static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev, int head)
6988 yaffs_CheckpointValidity cp;
6990 - memset(&cp,0,sizeof(cp));
6991 + memset(&cp, 0, sizeof(cp));
6993 cp.structType = sizeof(cp);
6994 cp.magic = YAFFS_MAGIC;
6995 cp.version = YAFFS_CHECKPOINT_VERSION;
6996 cp.head = (head) ? 1 : 0;
6998 - return (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp))?
6999 + return (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp)) ?
7003 @@ -4049,9 +4096,9 @@ static int yaffs_ReadCheckpointValidityM
7004 yaffs_CheckpointValidity cp;
7007 - ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp));
7008 + ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp));
7012 ok = (cp.structType == sizeof(cp)) &&
7013 (cp.magic == YAFFS_MAGIC) &&
7014 (cp.version == YAFFS_CHECKPOINT_VERSION) &&
7015 @@ -4100,21 +4147,21 @@ static int yaffs_WriteCheckpointDevice(y
7018 /* Write device runtime values*/
7019 - yaffs_DeviceToCheckpointDevice(&cp,dev);
7020 + yaffs_DeviceToCheckpointDevice(&cp, dev);
7021 cp.structType = sizeof(cp);
7023 - ok = (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp));
7024 + ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp));
7026 /* Write block info */
7029 nBytes = nBlocks * sizeof(yaffs_BlockInfo);
7030 - ok = (yaffs_CheckpointWrite(dev,dev->blockInfo,nBytes) == nBytes);
7031 + ok = (yaffs_CheckpointWrite(dev, dev->blockInfo, nBytes) == nBytes);
7034 /* Write chunk bits */
7037 nBytes = nBlocks * dev->chunkBitmapStride;
7038 - ok = (yaffs_CheckpointWrite(dev,dev->chunkBits,nBytes) == nBytes);
7039 + ok = (yaffs_CheckpointWrite(dev, dev->chunkBits, nBytes) == nBytes);
7043 @@ -4128,25 +4175,25 @@ static int yaffs_ReadCheckpointDevice(ya
7047 - ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp));
7049 + ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp));
7053 - if(cp.structType != sizeof(cp))
7054 + if (cp.structType != sizeof(cp))
7058 - yaffs_CheckpointDeviceToDevice(dev,&cp);
7059 + yaffs_CheckpointDeviceToDevice(dev, &cp);
7061 nBytes = nBlocks * sizeof(yaffs_BlockInfo);
7063 - ok = (yaffs_CheckpointRead(dev,dev->blockInfo,nBytes) == nBytes);
7064 + ok = (yaffs_CheckpointRead(dev, dev->blockInfo, nBytes) == nBytes);
7069 nBytes = nBlocks * dev->chunkBitmapStride;
7071 - ok = (yaffs_CheckpointRead(dev,dev->chunkBits,nBytes) == nBytes);
7072 + ok = (yaffs_CheckpointRead(dev, dev->chunkBits, nBytes) == nBytes);
7076 @@ -4157,7 +4204,7 @@ static void yaffs_ObjectToCheckpointObje
7078 cp->objectId = obj->objectId;
7079 cp->parentId = (obj->parent) ? obj->parent->objectId : 0;
7080 - cp->chunkId = obj->chunkId;
7081 + cp->hdrChunk = obj->hdrChunk;
7082 cp->variantType = obj->variantType;
7083 cp->deleted = obj->deleted;
7084 cp->softDeleted = obj->softDeleted;
7085 @@ -4168,20 +4215,28 @@ static void yaffs_ObjectToCheckpointObje
7086 cp->serial = obj->serial;
7087 cp->nDataChunks = obj->nDataChunks;
7089 - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
7090 + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE)
7091 cp->fileSizeOrEquivalentObjectId = obj->variant.fileVariant.fileSize;
7092 - else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
7093 + else if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
7094 cp->fileSizeOrEquivalentObjectId = obj->variant.hardLinkVariant.equivalentObjectId;
7097 -static void yaffs_CheckpointObjectToObject( yaffs_Object *obj,yaffs_CheckpointObject *cp)
7098 +static int yaffs_CheckpointObjectToObject(yaffs_Object *obj, yaffs_CheckpointObject *cp)
7101 yaffs_Object *parent;
7103 + if (obj->variantType != cp->variantType) {
7104 + T(YAFFS_TRACE_ERROR, (TSTR("Checkpoint read object %d type %d "
7105 + TCONT("chunk %d does not match existing object type %d")
7106 + TENDSTR), cp->objectId, cp->variantType, cp->hdrChunk,
7107 + obj->variantType));
7111 obj->objectId = cp->objectId;
7115 parent = yaffs_FindOrCreateObjectByNumber(
7118 @@ -4189,10 +4244,19 @@ static void yaffs_CheckpointObjectToObje
7124 + if (parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
7125 + T(YAFFS_TRACE_ALWAYS, (TSTR("Checkpoint read object %d parent %d type %d"
7126 + TCONT(" chunk %d Parent type, %d, not directory")
7128 + cp->objectId, cp->parentId, cp->variantType,
7129 + cp->hdrChunk, parent->variantType));
7132 yaffs_AddObjectToDirectory(parent, obj);
7135 - obj->chunkId = cp->chunkId;
7136 + obj->hdrChunk = cp->hdrChunk;
7137 obj->variantType = cp->variantType;
7138 obj->deleted = cp->deleted;
7139 obj->softDeleted = cp->softDeleted;
7140 @@ -4203,29 +4267,34 @@ static void yaffs_CheckpointObjectToObje
7141 obj->serial = cp->serial;
7142 obj->nDataChunks = cp->nDataChunks;
7144 - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
7145 + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE)
7146 obj->variant.fileVariant.fileSize = cp->fileSizeOrEquivalentObjectId;
7147 - else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
7148 + else if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
7149 obj->variant.hardLinkVariant.equivalentObjectId = cp->fileSizeOrEquivalentObjectId;
7151 - if(obj->objectId >= YAFFS_NOBJECT_BUCKETS)
7152 + if (obj->hdrChunk > 0)
7153 obj->lazyLoaded = 1;
7159 -static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn,
7160 - __u32 level, int chunkOffset)
7161 +static int yaffs_CheckpointTnodeWorker(yaffs_Object *in, yaffs_Tnode *tn,
7162 + __u32 level, int chunkOffset)
7165 yaffs_Device *dev = in->myDev;
7167 - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
7168 + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
7170 + if (tnodeSize < sizeof(yaffs_Tnode))
7171 + tnodeSize = sizeof(yaffs_Tnode);
7177 - for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++){
7178 + for (i = 0; i < YAFFS_NTNODES_INTERNAL && ok; i++) {
7179 if (tn->internal[i]) {
7180 ok = yaffs_CheckpointTnodeWorker(in,
7182 @@ -4235,10 +4304,9 @@ static int yaffs_CheckpointTnodeWorker(y
7184 } else if (level == 0) {
7185 __u32 baseOffset = chunkOffset << YAFFS_TNODES_LEVEL0_BITS;
7186 - /* printf("write tnode at %d\n",baseOffset); */
7187 - ok = (yaffs_CheckpointWrite(dev,&baseOffset,sizeof(baseOffset)) == sizeof(baseOffset));
7189 - ok = (yaffs_CheckpointWrite(dev,tn,nTnodeBytes) == nTnodeBytes);
7190 + ok = (yaffs_CheckpointWrite(dev, &baseOffset, sizeof(baseOffset)) == sizeof(baseOffset));
7192 + ok = (yaffs_CheckpointWrite(dev, tn, tnodeSize) == tnodeSize);
7196 @@ -4251,13 +4319,13 @@ static int yaffs_WriteCheckpointTnodes(y
7197 __u32 endMarker = ~0;
7200 - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE){
7201 + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) {
7202 ok = yaffs_CheckpointTnodeWorker(obj,
7203 obj->variant.fileVariant.top,
7204 obj->variant.fileVariant.topLevel,
7207 - ok = (yaffs_CheckpointWrite(obj->myDev,&endMarker,sizeof(endMarker)) ==
7209 + ok = (yaffs_CheckpointWrite(obj->myDev, &endMarker, sizeof(endMarker)) ==
7213 @@ -4272,38 +4340,38 @@ static int yaffs_ReadCheckpointTnodes(ya
7214 yaffs_FileStructure *fileStructPtr = &obj->variant.fileVariant;
7217 + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
7219 - ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk));
7220 + if (tnodeSize < sizeof(yaffs_Tnode))
7221 + tnodeSize = sizeof(yaffs_Tnode);
7223 - while(ok && (~baseChunk)){
7224 + ok = (yaffs_CheckpointRead(dev, &baseChunk, sizeof(baseChunk)) == sizeof(baseChunk));
7226 + while (ok && (~baseChunk)) {
7228 /* Read level 0 tnode */
7231 - /* printf("read tnode at %d\n",baseChunk); */
7232 tn = yaffs_GetTnodeRaw(dev);
7234 - ok = (yaffs_CheckpointRead(dev,tn,(dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8) ==
7235 - (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8);
7237 + ok = (yaffs_CheckpointRead(dev, tn, tnodeSize) == tnodeSize);
7243 ok = yaffs_AddOrFindLevel0Tnode(dev,
7254 - ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk));
7256 + ok = (yaffs_CheckpointRead(dev, &baseChunk, sizeof(baseChunk)) == sizeof(baseChunk));
7260 - T(YAFFS_TRACE_CHECKPOINT,(
7261 + T(YAFFS_TRACE_CHECKPOINT, (
7262 TSTR("Checkpoint read tnodes %d records, last %d. ok %d" TENDSTR),
7263 - nread,baseChunk,ok));
7264 + nread, baseChunk, ok));
7268 @@ -4315,41 +4383,40 @@ static int yaffs_WriteCheckpointObjects(
7269 yaffs_CheckpointObject cp;
7272 - struct list_head *lh;
7273 + struct ylist_head *lh;
7276 /* Iterate through the objects in each hash entry,
7277 * dumping them to the checkpointing stream.
7280 - for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){
7281 - list_for_each(lh, &dev->objectBucket[i].list) {
7282 + for (i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++) {
7283 + ylist_for_each(lh, &dev->objectBucket[i].list) {
7285 - obj = list_entry(lh, yaffs_Object, hashLink);
7286 + obj = ylist_entry(lh, yaffs_Object, hashLink);
7287 if (!obj->deferedFree) {
7288 - yaffs_ObjectToCheckpointObject(&cp,obj);
7289 + yaffs_ObjectToCheckpointObject(&cp, obj);
7290 cp.structType = sizeof(cp);
7292 - T(YAFFS_TRACE_CHECKPOINT,(
7293 + T(YAFFS_TRACE_CHECKPOINT, (
7294 TSTR("Checkpoint write object %d parent %d type %d chunk %d obj addr %x" TENDSTR),
7295 - cp.objectId,cp.parentId,cp.variantType,cp.chunkId,(unsigned) obj));
7296 + cp.objectId, cp.parentId, cp.variantType, cp.hdrChunk, (unsigned) obj));
7298 - ok = (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp));
7299 + ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp));
7301 - if(ok && obj->variantType == YAFFS_OBJECT_TYPE_FILE){
7302 + if (ok && obj->variantType == YAFFS_OBJECT_TYPE_FILE)
7303 ok = yaffs_WriteCheckpointTnodes(obj);
7311 - /* Dump end of list */
7312 - memset(&cp,0xFF,sizeof(yaffs_CheckpointObject));
7313 + /* Dump end of list */
7314 + memset(&cp, 0xFF, sizeof(yaffs_CheckpointObject));
7315 cp.structType = sizeof(cp);
7318 - ok = (yaffs_CheckpointWrite(dev,&cp,sizeof(cp)) == sizeof(cp));
7320 + ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp));
7324 @@ -4362,38 +4429,39 @@ static int yaffs_ReadCheckpointObjects(y
7326 yaffs_Object *hardList = NULL;
7328 - while(ok && !done) {
7329 - ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp));
7330 - if(cp.structType != sizeof(cp)) {
7331 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("struct size %d instead of %d ok %d"TENDSTR),
7332 - cp.structType,sizeof(cp),ok));
7333 + while (ok && !done) {
7334 + ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp));
7335 + if (cp.structType != sizeof(cp)) {
7336 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("struct size %d instead of %d ok %d"TENDSTR),
7337 + cp.structType, sizeof(cp), ok));
7341 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("Checkpoint read object %d parent %d type %d chunk %d " TENDSTR),
7342 - cp.objectId,cp.parentId,cp.variantType,cp.chunkId));
7343 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("Checkpoint read object %d parent %d type %d chunk %d " TENDSTR),
7344 + cp.objectId, cp.parentId, cp.variantType, cp.hdrChunk));
7346 - if(ok && cp.objectId == ~0)
7347 + if (ok && cp.objectId == ~0)
7350 - obj = yaffs_FindOrCreateObjectByNumber(dev,cp.objectId, cp.variantType);
7352 - yaffs_CheckpointObjectToObject(obj,&cp);
7353 - if(obj->variantType == YAFFS_OBJECT_TYPE_FILE) {
7355 + obj = yaffs_FindOrCreateObjectByNumber(dev, cp.objectId, cp.variantType);
7357 + ok = yaffs_CheckpointObjectToObject(obj, &cp);
7360 + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) {
7361 ok = yaffs_ReadCheckpointTnodes(obj);
7362 - } else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) {
7363 + } else if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) {
7364 obj->hardLinks.next =
7365 - (struct list_head *)
7367 + (struct ylist_head *) hardList;
7378 - yaffs_HardlinkFixup(dev,hardList);
7380 + yaffs_HardlinkFixup(dev, hardList);
7384 @@ -4403,11 +4471,11 @@ static int yaffs_WriteCheckpointSum(yaff
7385 __u32 checkpointSum;
7388 - yaffs_GetCheckpointSum(dev,&checkpointSum);
7389 + yaffs_GetCheckpointSum(dev, &checkpointSum);
7391 - ok = (yaffs_CheckpointWrite(dev,&checkpointSum,sizeof(checkpointSum)) == sizeof(checkpointSum));
7392 + ok = (yaffs_CheckpointWrite(dev, &checkpointSum, sizeof(checkpointSum)) == sizeof(checkpointSum));
7399 @@ -4419,14 +4487,14 @@ static int yaffs_ReadCheckpointSum(yaffs
7400 __u32 checkpointSum1;
7403 - yaffs_GetCheckpointSum(dev,&checkpointSum0);
7404 + yaffs_GetCheckpointSum(dev, &checkpointSum0);
7406 - ok = (yaffs_CheckpointRead(dev,&checkpointSum1,sizeof(checkpointSum1)) == sizeof(checkpointSum1));
7407 + ok = (yaffs_CheckpointRead(dev, &checkpointSum1, sizeof(checkpointSum1)) == sizeof(checkpointSum1));
7413 - if(checkpointSum0 != checkpointSum1)
7414 + if (checkpointSum0 != checkpointSum1)
7418 @@ -4435,46 +4503,43 @@ static int yaffs_ReadCheckpointSum(yaffs
7420 static int yaffs_WriteCheckpointData(yaffs_Device *dev)
7425 - if(dev->skipCheckpointWrite || !dev->isYaffs2){
7426 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint write" TENDSTR)));
7427 + if (dev->skipCheckpointWrite || !dev->isYaffs2) {
7428 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint write" TENDSTR)));
7433 - ok = yaffs_CheckpointOpen(dev,1);
7435 + ok = yaffs_CheckpointOpen(dev, 1);
7438 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR)));
7439 - ok = yaffs_WriteCheckpointValidityMarker(dev,1);
7441 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint validity" TENDSTR)));
7442 + ok = yaffs_WriteCheckpointValidityMarker(dev, 1);
7445 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint device" TENDSTR)));
7447 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint device" TENDSTR)));
7448 ok = yaffs_WriteCheckpointDevice(dev);
7451 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint objects" TENDSTR)));
7453 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint objects" TENDSTR)));
7454 ok = yaffs_WriteCheckpointObjects(dev);
7457 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR)));
7458 - ok = yaffs_WriteCheckpointValidityMarker(dev,0);
7460 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("write checkpoint validity" TENDSTR)));
7461 + ok = yaffs_WriteCheckpointValidityMarker(dev, 0);
7466 ok = yaffs_WriteCheckpointSum(dev);
7470 - if(!yaffs_CheckpointClose(dev))
7472 + if (!yaffs_CheckpointClose(dev))
7476 - dev->isCheckpointed = 1;
7478 - dev->isCheckpointed = 0;
7480 + dev->isCheckpointed = 1;
7482 + dev->isCheckpointed = 0;
7484 return dev->isCheckpointed;
7486 @@ -4483,43 +4548,43 @@ static int yaffs_ReadCheckpointData(yaff
7490 - if(dev->skipCheckpointRead || !dev->isYaffs2){
7491 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint read" TENDSTR)));
7492 + if (dev->skipCheckpointRead || !dev->isYaffs2) {
7493 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint read" TENDSTR)));
7498 - ok = yaffs_CheckpointOpen(dev,0); /* open for read */
7500 + ok = yaffs_CheckpointOpen(dev, 0); /* open for read */
7503 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint validity" TENDSTR)));
7504 - ok = yaffs_ReadCheckpointValidityMarker(dev,1);
7506 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint validity" TENDSTR)));
7507 + ok = yaffs_ReadCheckpointValidityMarker(dev, 1);
7510 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint device" TENDSTR)));
7512 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint device" TENDSTR)));
7513 ok = yaffs_ReadCheckpointDevice(dev);
7516 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint objects" TENDSTR)));
7518 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint objects" TENDSTR)));
7519 ok = yaffs_ReadCheckpointObjects(dev);
7522 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint validity" TENDSTR)));
7523 - ok = yaffs_ReadCheckpointValidityMarker(dev,0);
7525 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint validity" TENDSTR)));
7526 + ok = yaffs_ReadCheckpointValidityMarker(dev, 0);
7531 ok = yaffs_ReadCheckpointSum(dev);
7532 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint checksum %d" TENDSTR),ok));
7533 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("read checkpoint checksum %d" TENDSTR), ok));
7536 - if(!yaffs_CheckpointClose(dev))
7537 + if (!yaffs_CheckpointClose(dev))
7541 - dev->isCheckpointed = 1;
7543 - dev->isCheckpointed = 0;
7545 + dev->isCheckpointed = 1;
7547 + dev->isCheckpointed = 0;
7551 @@ -4527,11 +4592,11 @@ static int yaffs_ReadCheckpointData(yaff
7553 static void yaffs_InvalidateCheckpoint(yaffs_Device *dev)
7555 - if(dev->isCheckpointed ||
7556 - dev->blocksInCheckpoint > 0){
7557 + if (dev->isCheckpointed ||
7558 + dev->blocksInCheckpoint > 0) {
7559 dev->isCheckpointed = 0;
7560 yaffs_CheckpointInvalidateStream(dev);
7561 - if(dev->superBlock && dev->markSuperBlockDirty)
7562 + if (dev->superBlock && dev->markSuperBlockDirty)
7563 dev->markSuperBlockDirty(dev->superBlock);
7566 @@ -4540,18 +4605,18 @@ static void yaffs_InvalidateCheckpoint(y
7567 int yaffs_CheckpointSave(yaffs_Device *dev)
7570 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("save entry: isCheckpointed %d"TENDSTR),dev->isCheckpointed));
7571 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("save entry: isCheckpointed %d"TENDSTR), dev->isCheckpointed));
7573 yaffs_VerifyObjects(dev);
7574 yaffs_VerifyBlocks(dev);
7575 yaffs_VerifyFreeChunks(dev);
7577 - if(!dev->isCheckpointed) {
7578 + if (!dev->isCheckpointed) {
7579 yaffs_InvalidateCheckpoint(dev);
7580 yaffs_WriteCheckpointData(dev);
7583 - T(YAFFS_TRACE_ALWAYS,(TSTR("save exit: isCheckpointed %d"TENDSTR),dev->isCheckpointed));
7584 + T(YAFFS_TRACE_ALWAYS, (TSTR("save exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed));
7586 return dev->isCheckpointed;
7588 @@ -4559,17 +4624,17 @@ int yaffs_CheckpointSave(yaffs_Device *d
7589 int yaffs_CheckpointRestore(yaffs_Device *dev)
7592 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("restore entry: isCheckpointed %d"TENDSTR),dev->isCheckpointed));
7593 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore entry: isCheckpointed %d"TENDSTR), dev->isCheckpointed));
7595 retval = yaffs_ReadCheckpointData(dev);
7597 - if(dev->isCheckpointed){
7598 + if (dev->isCheckpointed) {
7599 yaffs_VerifyObjects(dev);
7600 yaffs_VerifyBlocks(dev);
7601 yaffs_VerifyFreeChunks(dev);
7604 - T(YAFFS_TRACE_CHECKPOINT,(TSTR("restore exit: isCheckpointed %d"TENDSTR),dev->isCheckpointed));
7605 + T(YAFFS_TRACE_CHECKPOINT, (TSTR("restore exit: isCheckpointed %d"TENDSTR), dev->isCheckpointed));
7609 @@ -4584,12 +4649,12 @@ int yaffs_CheckpointRestore(yaffs_Device
7610 * Curve-balls: the first chunk might also be the last chunk.
7613 -int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset,
7615 +int yaffs_ReadDataFromFile(yaffs_Object *in, __u8 *buffer, loff_t offset,
7625 @@ -4600,27 +4665,26 @@ int yaffs_ReadDataFromFile(yaffs_Object
7629 - //chunk = offset / dev->nDataBytesPerChunk + 1;
7630 - //start = offset % dev->nDataBytesPerChunk;
7631 - yaffs_AddrToChunk(dev,offset,&chunk,&start);
7632 + /* chunk = offset / dev->nDataBytesPerChunk + 1; */
7633 + /* start = offset % dev->nDataBytesPerChunk; */
7634 + yaffs_AddrToChunk(dev, offset, &chunk, &start);
7637 /* OK now check for the curveball where the start and end are in
7640 - if ((start + n) < dev->nDataBytesPerChunk) {
7641 + if ((start + n) < dev->nDataBytesPerChunk)
7645 nToCopy = dev->nDataBytesPerChunk - start;
7648 cache = yaffs_FindChunkCache(in, chunk);
7650 /* If the chunk is already in the cache or it is less than a whole chunk
7651 - * then use the cache (if there is caching)
7652 + * or we're using inband tags then use the cache (if there is caching)
7653 * else bypass the cache.
7655 - if (cache || nToCopy != dev->nDataBytesPerChunk) {
7656 + if (cache || nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) {
7657 if (dev->nShortOpCaches > 0) {
7659 /* If we can't find the data in the cache, then load it up. */
7660 @@ -4641,14 +4705,9 @@ int yaffs_ReadDataFromFile(yaffs_Object
7664 -#ifdef CONFIG_YAFFS_WINCE
7665 - yfsd_UnlockYAFFS(TRUE);
7668 memcpy(buffer, &cache->data[start], nToCopy);
7670 -#ifdef CONFIG_YAFFS_WINCE
7671 - yfsd_LockYAFFS(TRUE);
7675 /* Read into the local buffer then copy..*/
7676 @@ -4657,41 +4716,19 @@ int yaffs_ReadDataFromFile(yaffs_Object
7677 yaffs_GetTempBuffer(dev, __LINE__);
7678 yaffs_ReadChunkDataFromObject(in, chunk,
7680 -#ifdef CONFIG_YAFFS_WINCE
7681 - yfsd_UnlockYAFFS(TRUE);
7684 memcpy(buffer, &localBuffer[start], nToCopy);
7686 -#ifdef CONFIG_YAFFS_WINCE
7687 - yfsd_LockYAFFS(TRUE);
7690 yaffs_ReleaseTempBuffer(dev, localBuffer,
7695 -#ifdef CONFIG_YAFFS_WINCE
7696 - __u8 *localBuffer = yaffs_GetTempBuffer(dev, __LINE__);
7698 - /* Under WinCE can't do direct transfer. Need to use a local buffer.
7699 - * This is because we otherwise screw up WinCE's memory mapper
7701 - yaffs_ReadChunkDataFromObject(in, chunk, localBuffer);
7703 -#ifdef CONFIG_YAFFS_WINCE
7704 - yfsd_UnlockYAFFS(TRUE);
7706 - memcpy(buffer, localBuffer, dev->nDataBytesPerChunk);
7708 -#ifdef CONFIG_YAFFS_WINCE
7709 - yfsd_LockYAFFS(TRUE);
7710 - yaffs_ReleaseTempBuffer(dev, localBuffer, __LINE__);
7714 /* A full chunk. Read directly into the supplied buffer. */
7715 yaffs_ReadChunkDataFromObject(in, chunk, buffer);
7721 @@ -4704,28 +4741,37 @@ int yaffs_ReadDataFromFile(yaffs_Object
7725 -int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset,
7726 - int nBytes, int writeThrough)
7727 +int yaffs_WriteDataToFile(yaffs_Object *in, const __u8 *buffer, loff_t offset,
7728 + int nBytes, int writeThrough)
7738 int startOfWrite = offset;
7739 int chunkWritten = 0;
7748 while (n > 0 && chunkWritten >= 0) {
7749 - //chunk = offset / dev->nDataBytesPerChunk + 1;
7750 - //start = offset % dev->nDataBytesPerChunk;
7751 - yaffs_AddrToChunk(dev,offset,&chunk,&start);
7752 + /* chunk = offset / dev->nDataBytesPerChunk + 1; */
7753 + /* start = offset % dev->nDataBytesPerChunk; */
7754 + yaffs_AddrToChunk(dev, offset, &chunk, &start);
7756 + if (chunk * dev->nDataBytesPerChunk + start != offset ||
7757 + start >= dev->nDataBytesPerChunk) {
7758 + T(YAFFS_TRACE_ERROR, (
7759 + TSTR("AddrToChunk of offset %d gives chunk %d start %d"
7761 + (int)offset, chunk, start));
7765 /* OK now check for the curveball where the start and end are in
7766 @@ -4740,25 +4786,32 @@ int yaffs_WriteDataToFile(yaffs_Object *
7767 * we need to write back as much as was there before.
7771 - in->variant.fileVariant.fileSize -
7772 - ((chunk - 1) * dev->nDataBytesPerChunk);
7773 + chunkStart = ((chunk - 1) * dev->nDataBytesPerChunk);
7775 + if (chunkStart > in->variant.fileVariant.fileSize)
7776 + nBytesRead = 0; /* Past end of file */
7778 + nBytesRead = in->variant.fileVariant.fileSize - chunkStart;
7780 - if (nBytesRead > dev->nDataBytesPerChunk) {
7781 + if (nBytesRead > dev->nDataBytesPerChunk)
7782 nBytesRead = dev->nDataBytesPerChunk;
7787 (start + n)) ? nBytesRead : (start + n);
7789 + if (nToWriteBack < 0 || nToWriteBack > dev->nDataBytesPerChunk)
7793 nToCopy = dev->nDataBytesPerChunk - start;
7794 nToWriteBack = dev->nDataBytesPerChunk;
7797 - if (nToCopy != dev->nDataBytesPerChunk) {
7798 - /* An incomplete start or end chunk (or maybe both start and end chunk) */
7799 + if (nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) {
7800 + /* An incomplete start or end chunk (or maybe both start and end chunk),
7801 + * or we're using inband tags, so we want to use the cache buffers.
7803 if (dev->nShortOpCaches > 0) {
7804 yaffs_ChunkCache *cache;
7805 /* If we can't find the data in the cache, then load the cache */
7806 @@ -4775,10 +4828,9 @@ int yaffs_WriteDataToFile(yaffs_Object *
7807 yaffs_ReadChunkDataFromObject(in, chunk,
7813 - !yaffs_CheckSpaceForAllocation(in->myDev)){
7814 + } else if (cache &&
7816 + !yaffs_CheckSpaceForAllocation(in->myDev)) {
7817 /* Drop the cache if it was a read cache item and
7818 * no space check has been made for it.
7820 @@ -4788,16 +4840,12 @@ int yaffs_WriteDataToFile(yaffs_Object *
7822 yaffs_UseChunkCache(dev, cache, 1);
7824 -#ifdef CONFIG_YAFFS_WINCE
7825 - yfsd_UnlockYAFFS(TRUE);
7829 memcpy(&cache->data[start], buffer,
7832 -#ifdef CONFIG_YAFFS_WINCE
7833 - yfsd_LockYAFFS(TRUE);
7837 cache->nBytes = nToWriteBack;
7839 @@ -4825,15 +4873,10 @@ int yaffs_WriteDataToFile(yaffs_Object *
7840 yaffs_ReadChunkDataFromObject(in, chunk,
7843 -#ifdef CONFIG_YAFFS_WINCE
7844 - yfsd_UnlockYAFFS(TRUE);
7848 memcpy(&localBuffer[start], buffer, nToCopy);
7850 -#ifdef CONFIG_YAFFS_WINCE
7851 - yfsd_LockYAFFS(TRUE);
7854 yaffs_WriteChunkDataToObject(in, chunk,
7856 @@ -4846,31 +4889,15 @@ int yaffs_WriteDataToFile(yaffs_Object *
7861 -#ifdef CONFIG_YAFFS_WINCE
7862 - /* Under WinCE can't do direct transfer. Need to use a local buffer.
7863 - * This is because we otherwise screw up WinCE's memory mapper
7865 - __u8 *localBuffer = yaffs_GetTempBuffer(dev, __LINE__);
7866 -#ifdef CONFIG_YAFFS_WINCE
7867 - yfsd_UnlockYAFFS(TRUE);
7869 - memcpy(localBuffer, buffer, dev->nDataBytesPerChunk);
7870 -#ifdef CONFIG_YAFFS_WINCE
7871 - yfsd_LockYAFFS(TRUE);
7874 - yaffs_WriteChunkDataToObject(in, chunk, localBuffer,
7875 - dev->nDataBytesPerChunk,
7877 - yaffs_ReleaseTempBuffer(dev, localBuffer, __LINE__);
7879 /* A full chunk. Write directly from the supplied buffer. */
7884 yaffs_WriteChunkDataToObject(in, chunk, buffer,
7885 dev->nDataBytesPerChunk,
7889 /* Since we've overwritten the cached data, we better invalidate it. */
7890 yaffs_InvalidateChunkCache(in, chunk);
7892 @@ -4886,9 +4913,8 @@ int yaffs_WriteDataToFile(yaffs_Object *
7894 /* Update file object */
7896 - if ((startOfWrite + nDone) > in->variant.fileVariant.fileSize) {
7897 + if ((startOfWrite + nDone) > in->variant.fileVariant.fileSize)
7898 in->variant.fileVariant.fileSize = (startOfWrite + nDone);
7903 @@ -4898,7 +4924,7 @@ int yaffs_WriteDataToFile(yaffs_Object *
7905 /* ---------------------- File resizing stuff ------------------ */
7907 -static void yaffs_PruneResizedChunks(yaffs_Object * in, int newSize)
7908 +static void yaffs_PruneResizedChunks(yaffs_Object *in, int newSize)
7911 yaffs_Device *dev = in->myDev;
7912 @@ -4939,11 +4965,11 @@ static void yaffs_PruneResizedChunks(yaf
7916 -int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize)
7917 +int yaffs_ResizeFile(yaffs_Object *in, loff_t newSize)
7920 int oldFileSize = in->variant.fileVariant.fileSize;
7921 - int newSizeOfPartialChunk;
7922 + __u32 newSizeOfPartialChunk;
7925 yaffs_Device *dev = in->myDev;
7926 @@ -4955,13 +4981,11 @@ int yaffs_ResizeFile(yaffs_Object * in,
7928 yaffs_CheckGarbageCollection(dev);
7930 - if (in->variantType != YAFFS_OBJECT_TYPE_FILE) {
7931 - return yaffs_GetFileSize(in);
7933 + if (in->variantType != YAFFS_OBJECT_TYPE_FILE)
7934 + return YAFFS_FAIL;
7936 - if (newSize == oldFileSize) {
7937 - return oldFileSize;
7939 + if (newSize == oldFileSize)
7942 if (newSize < oldFileSize) {
7944 @@ -4994,21 +5018,20 @@ int yaffs_ResizeFile(yaffs_Object * in,
7949 /* Write a new object header.
7950 * show we've shrunk the file, if need be
7951 * Do this only if the file is not in the deleted directories.
7953 - if (in->parent->objectId != YAFFS_OBJECTID_UNLINKED &&
7954 - in->parent->objectId != YAFFS_OBJECTID_DELETED) {
7956 + in->parent->objectId != YAFFS_OBJECTID_UNLINKED &&
7957 + in->parent->objectId != YAFFS_OBJECTID_DELETED)
7958 yaffs_UpdateObjectHeader(in, NULL, 0,
7959 (newSize < oldFileSize) ? 1 : 0, 0);
7966 -loff_t yaffs_GetFileSize(yaffs_Object * obj)
7967 +loff_t yaffs_GetFileSize(yaffs_Object *obj)
7969 obj = yaffs_GetEquivalentObject(obj);
7971 @@ -5024,7 +5047,7 @@ loff_t yaffs_GetFileSize(yaffs_Object *
7975 -int yaffs_FlushFile(yaffs_Object * in, int updateTime)
7976 +int yaffs_FlushFile(yaffs_Object *in, int updateTime)
7980 @@ -5039,9 +5062,8 @@ int yaffs_FlushFile(yaffs_Object * in, i
7985 - (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >=
7986 - 0) ? YAFFS_OK : YAFFS_FAIL;
7987 + retVal = (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >=
7988 + 0) ? YAFFS_OK : YAFFS_FAIL;
7992 @@ -5050,7 +5072,7 @@ int yaffs_FlushFile(yaffs_Object * in, i
7996 -static int yaffs_DoGenericObjectDeletion(yaffs_Object * in)
7997 +static int yaffs_DoGenericObjectDeletion(yaffs_Object *in)
8000 /* First off, invalidate the file's data in the cache, without flushing. */
8001 @@ -5058,13 +5080,13 @@ static int yaffs_DoGenericObjectDeletion
8003 if (in->myDev->isYaffs2 && (in->parent != in->myDev->deletedDir)) {
8004 /* Move to the unlinked directory so we have a record that it was deleted. */
8005 - yaffs_ChangeObjectName(in, in->myDev->deletedDir,"deleted", 0, 0);
8006 + yaffs_ChangeObjectName(in, in->myDev->deletedDir, _Y("deleted"), 0, 0);
8010 yaffs_RemoveObjectFromDirectory(in);
8011 - yaffs_DeleteChunk(in->myDev, in->chunkId, 1, __LINE__);
8013 + yaffs_DeleteChunk(in->myDev, in->hdrChunk, 1, __LINE__);
8016 yaffs_FreeObject(in);
8018 @@ -5075,62 +5097,63 @@ static int yaffs_DoGenericObjectDeletion
8019 * and the inode associated with the file.
8020 * It does not delete the links associated with the file.
8022 -static int yaffs_UnlinkFile(yaffs_Object * in)
8023 +static int yaffs_UnlinkFileIfNeeded(yaffs_Object *in)
8027 int immediateDeletion = 0;
8031 - if (!in->myInode) {
8032 - immediateDeletion = 1;
8036 + immediateDeletion = 1;
8038 - if (in->inUse <= 0) {
8039 - immediateDeletion = 1;
8042 + if (in->inUse <= 0)
8043 + immediateDeletion = 1;
8045 - if (immediateDeletion) {
8047 - yaffs_ChangeObjectName(in, in->myDev->deletedDir,
8049 - T(YAFFS_TRACE_TRACING,
8050 - (TSTR("yaffs: immediate deletion of file %d" TENDSTR),
8053 - in->myDev->nDeletedFiles++;
8054 - if (0 && in->myDev->isYaffs2) {
8055 - yaffs_ResizeFile(in, 0);
8057 - yaffs_SoftDeleteFile(in);
8060 - yaffs_ChangeObjectName(in, in->myDev->unlinkedDir,
8061 - "unlinked", 0, 0);
8064 + if (immediateDeletion) {
8066 + yaffs_ChangeObjectName(in, in->myDev->deletedDir,
8067 + _Y("deleted"), 0, 0);
8068 + T(YAFFS_TRACE_TRACING,
8069 + (TSTR("yaffs: immediate deletion of file %d" TENDSTR),
8072 + in->myDev->nDeletedFiles++;
8073 + if (1 || in->myDev->isYaffs2)
8074 + yaffs_ResizeFile(in, 0);
8075 + yaffs_SoftDeleteFile(in);
8078 + yaffs_ChangeObjectName(in, in->myDev->unlinkedDir,
8079 + _Y("unlinked"), 0, 0);
8086 -int yaffs_DeleteFile(yaffs_Object * in)
8087 +int yaffs_DeleteFile(yaffs_Object *in)
8089 int retVal = YAFFS_OK;
8090 + int deleted = in->deleted;
8092 + yaffs_ResizeFile(in, 0);
8094 if (in->nDataChunks > 0) {
8095 - /* Use soft deletion if there is data in the file */
8096 - if (!in->unlinked) {
8097 - retVal = yaffs_UnlinkFile(in);
8099 + /* Use soft deletion if there is data in the file.
8100 + * That won't be the case if it has been resized to zero.
8102 + if (!in->unlinked)
8103 + retVal = yaffs_UnlinkFileIfNeeded(in);
8105 if (retVal == YAFFS_OK && in->unlinked && !in->deleted) {
8108 in->myDev->nDeletedFiles++;
8109 yaffs_SoftDeleteFile(in);
8111 - return in->deleted ? YAFFS_OK : YAFFS_FAIL;
8112 + return deleted ? YAFFS_OK : YAFFS_FAIL;
8114 /* The file has no data chunks so we toss it immediately */
8115 yaffs_FreeTnode(in->myDev, in->variant.fileVariant.top);
8116 @@ -5141,62 +5164,75 @@ int yaffs_DeleteFile(yaffs_Object * in)
8120 -static int yaffs_DeleteDirectory(yaffs_Object * in)
8121 +static int yaffs_DeleteDirectory(yaffs_Object *in)
8123 /* First check that the directory is empty. */
8124 - if (list_empty(&in->variant.directoryVariant.children)) {
8125 + if (ylist_empty(&in->variant.directoryVariant.children))
8126 return yaffs_DoGenericObjectDeletion(in);
8133 -static int yaffs_DeleteSymLink(yaffs_Object * in)
8134 +static int yaffs_DeleteSymLink(yaffs_Object *in)
8136 YFREE(in->variant.symLinkVariant.alias);
8138 return yaffs_DoGenericObjectDeletion(in);
8141 -static int yaffs_DeleteHardLink(yaffs_Object * in)
8142 +static int yaffs_DeleteHardLink(yaffs_Object *in)
8144 /* remove this hardlink from the list assocaited with the equivalent
8147 - list_del(&in->hardLinks);
8148 + ylist_del_init(&in->hardLinks);
8149 return yaffs_DoGenericObjectDeletion(in);
8152 -static void yaffs_DestroyObject(yaffs_Object * obj)
8153 +int yaffs_DeleteObject(yaffs_Object *obj)
8156 switch (obj->variantType) {
8157 case YAFFS_OBJECT_TYPE_FILE:
8158 - yaffs_DeleteFile(obj);
8159 + retVal = yaffs_DeleteFile(obj);
8161 case YAFFS_OBJECT_TYPE_DIRECTORY:
8162 - yaffs_DeleteDirectory(obj);
8163 + return yaffs_DeleteDirectory(obj);
8165 case YAFFS_OBJECT_TYPE_SYMLINK:
8166 - yaffs_DeleteSymLink(obj);
8167 + retVal = yaffs_DeleteSymLink(obj);
8169 case YAFFS_OBJECT_TYPE_HARDLINK:
8170 - yaffs_DeleteHardLink(obj);
8171 + retVal = yaffs_DeleteHardLink(obj);
8173 case YAFFS_OBJECT_TYPE_SPECIAL:
8174 - yaffs_DoGenericObjectDeletion(obj);
8175 + retVal = yaffs_DoGenericObjectDeletion(obj);
8177 case YAFFS_OBJECT_TYPE_UNKNOWN:
8179 break; /* should not happen. */
8185 -static int yaffs_UnlinkWorker(yaffs_Object * obj)
8186 +static int yaffs_UnlinkWorker(yaffs_Object *obj)
8189 + int immediateDeletion = 0;
8192 + if (!obj->myInode)
8193 + immediateDeletion = 1;
8195 + if (obj->inUse <= 0)
8196 + immediateDeletion = 1;
8199 if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) {
8200 return yaffs_DeleteHardLink(obj);
8201 - } else if (!list_empty(&obj->hardLinks)) {
8202 + } else if (!ylist_empty(&obj->hardLinks)) {
8203 /* Curve ball: We're unlinking an object that has a hardlink.
8205 * This problem arises because we are not strictly following
8206 @@ -5215,24 +5251,24 @@ static int yaffs_UnlinkWorker(yaffs_Obje
8208 YCHAR name[YAFFS_MAX_NAME_LENGTH + 1];
8210 - hl = list_entry(obj->hardLinks.next, yaffs_Object, hardLinks);
8211 + hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks);
8213 - list_del_init(&hl->hardLinks);
8214 - list_del_init(&hl->siblings);
8215 + ylist_del_init(&hl->hardLinks);
8216 + ylist_del_init(&hl->siblings);
8218 yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1);
8220 retVal = yaffs_ChangeObjectName(obj, hl->parent, name, 0, 0);
8222 - if (retVal == YAFFS_OK) {
8223 + if (retVal == YAFFS_OK)
8224 retVal = yaffs_DoGenericObjectDeletion(hl);
8230 + } else if (immediateDeletion) {
8231 switch (obj->variantType) {
8232 case YAFFS_OBJECT_TYPE_FILE:
8233 - return yaffs_UnlinkFile(obj);
8234 + return yaffs_DeleteFile(obj);
8236 case YAFFS_OBJECT_TYPE_DIRECTORY:
8237 return yaffs_DeleteDirectory(obj);
8238 @@ -5248,21 +5284,22 @@ static int yaffs_UnlinkWorker(yaffs_Obje
8244 + return yaffs_ChangeObjectName(obj, obj->myDev->unlinkedDir,
8245 + _Y("unlinked"), 0, 0);
8249 -static int yaffs_UnlinkObject( yaffs_Object *obj)
8250 +static int yaffs_UnlinkObject(yaffs_Object *obj)
8253 - if (obj && obj->unlinkAllowed) {
8254 + if (obj && obj->unlinkAllowed)
8255 return yaffs_UnlinkWorker(obj);
8261 -int yaffs_Unlink(yaffs_Object * dir, const YCHAR * name)
8262 +int yaffs_Unlink(yaffs_Object *dir, const YCHAR *name)
8266 @@ -5272,8 +5309,8 @@ int yaffs_Unlink(yaffs_Object * dir, con
8268 /*----------------------- Initialisation Scanning ---------------------- */
8270 -static void yaffs_HandleShadowedObject(yaffs_Device * dev, int objId,
8271 - int backwardScanning)
8272 +static void yaffs_HandleShadowedObject(yaffs_Device *dev, int objId,
8273 + int backwardScanning)
8277 @@ -5286,9 +5323,8 @@ static void yaffs_HandleShadowedObject(y
8278 /* Handle YAFFS2 case (backward scanning)
8279 * If the shadowed object exists then ignore.
8281 - if (yaffs_FindObjectByNumber(dev, objId)) {
8282 + if (yaffs_FindObjectByNumber(dev, objId))
8287 /* Let's create it (if it does not exist) assuming it is a file so that it can do shrinking etc.
8288 @@ -5297,6 +5333,8 @@ static void yaffs_HandleShadowedObject(y
8290 yaffs_FindOrCreateObjectByNumber(dev, objId,
8291 YAFFS_OBJECT_TYPE_FILE);
8294 yaffs_AddObjectToDirectory(dev->unlinkedDir, obj);
8295 obj->variant.fileVariant.shrinkSize = 0;
8296 obj->valid = 1; /* So that we don't read any other info for this file */
8297 @@ -5325,44 +5363,77 @@ static void yaffs_HardlinkFixup(yaffs_De
8299 /* Add the hardlink pointers */
8300 hl->variant.hardLinkVariant.equivalentObject = in;
8301 - list_add(&hl->hardLinks, &in->hardLinks);
8302 + ylist_add(&hl->hardLinks, &in->hardLinks);
8304 /* Todo Need to report/handle this better.
8305 * Got a problem... hardlink to a non-existant object
8307 hl->variant.hardLinkVariant.equivalentObject = NULL;
8308 - INIT_LIST_HEAD(&hl->hardLinks);
8309 + YINIT_LIST_HEAD(&hl->hardLinks);
8320 +static int ybicmp(const void *a, const void *b)
8322 + register int aseq = ((yaffs_BlockIndex *)a)->seq;
8323 + register int bseq = ((yaffs_BlockIndex *)b)->seq;
8324 + register int ablock = ((yaffs_BlockIndex *)a)->block;
8325 + register int bblock = ((yaffs_BlockIndex *)b)->block;
8327 + return ablock - bblock;
8329 + return aseq - bseq;
8333 +struct yaffs_ShadowFixerStruct {
8336 + struct yaffs_ShadowFixerStruct *next;
8340 +static void yaffs_StripDeletedObjects(yaffs_Device *dev)
8343 + * Sort out state of unlinked and deleted objects after scanning.
8345 + struct ylist_head *i;
8346 + struct ylist_head *n;
8349 + /* Soft delete all the unlinked files */
8350 + ylist_for_each_safe(i, n,
8351 + &dev->unlinkedDir->variant.directoryVariant.children) {
8353 + l = ylist_entry(i, yaffs_Object, siblings);
8354 + yaffs_DeleteObject(l);
8358 -static int ybicmp(const void *a, const void *b){
8359 - register int aseq = ((yaffs_BlockIndex *)a)->seq;
8360 - register int bseq = ((yaffs_BlockIndex *)b)->seq;
8361 - register int ablock = ((yaffs_BlockIndex *)a)->block;
8362 - register int bblock = ((yaffs_BlockIndex *)b)->block;
8363 - if( aseq == bseq )
8364 - return ablock - bblock;
8366 - return aseq - bseq;
8367 + ylist_for_each_safe(i, n,
8368 + &dev->deletedDir->variant.directoryVariant.children) {
8370 + l = ylist_entry(i, yaffs_Object, siblings);
8371 + yaffs_DeleteObject(l);
8377 -static int yaffs_Scan(yaffs_Device * dev)
8378 +static int yaffs_Scan(yaffs_Device *dev)
8380 yaffs_ExtendedTags tags;
8385 - int nBlocksToScan = 0;
8389 @@ -5371,26 +5442,19 @@ static int yaffs_Scan(yaffs_Device * dev
8390 yaffs_BlockState state;
8391 yaffs_Object *hardList = NULL;
8392 yaffs_BlockInfo *bi;
8393 - int sequenceNumber;
8394 + __u32 sequenceNumber;
8395 yaffs_ObjectHeader *oh;
8397 yaffs_Object *parent;
8398 - int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1;
8400 int alloc_failed = 0;
8402 + struct yaffs_ShadowFixerStruct *shadowFixerList = NULL;
8407 - yaffs_BlockIndex *blockIndex = NULL;
8409 - if (dev->isYaffs2) {
8410 - T(YAFFS_TRACE_SCAN,
8411 - (TSTR("yaffs_Scan is not for YAFFS2!" TENDSTR)));
8412 - return YAFFS_FAIL;
8415 - //TODO Throw all the yaffs2 stuuf out of yaffs_Scan since it is only for yaffs1 format.
8418 (TSTR("yaffs_Scan starts intstartblk %d intendblk %d..." TENDSTR),
8419 @@ -5400,12 +5464,6 @@ static int yaffs_Scan(yaffs_Device * dev
8421 dev->sequenceNumber = YAFFS_LOWEST_SEQUENCE_NUMBER;
8423 - if (dev->isYaffs2) {
8424 - blockIndex = YMALLOC(nBlocks * sizeof(yaffs_BlockIndex));
8426 - return YAFFS_FAIL;
8429 /* Scan all the blocks to determine their state */
8430 for (blk = dev->internalStartBlock; blk <= dev->internalEndBlock; blk++) {
8431 bi = yaffs_GetBlockInfo(dev, blk);
8432 @@ -5418,6 +5476,9 @@ static int yaffs_Scan(yaffs_Device * dev
8433 bi->blockState = state;
8434 bi->sequenceNumber = sequenceNumber;
8436 + if (bi->sequenceNumber == YAFFS_SEQUENCE_BAD_BLOCK)
8437 + bi->blockState = state = YAFFS_BLOCK_STATE_DEAD;
8439 T(YAFFS_TRACE_SCAN_DEBUG,
8440 (TSTR("Block scanning block %d state %d seq %d" TENDSTR), blk,
8441 state, sequenceNumber));
8442 @@ -5430,70 +5491,21 @@ static int yaffs_Scan(yaffs_Device * dev
8443 (TSTR("Block empty " TENDSTR)));
8444 dev->nErasedBlocks++;
8445 dev->nFreeChunks += dev->nChunksPerBlock;
8446 - } else if (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING) {
8448 - /* Determine the highest sequence number */
8449 - if (dev->isYaffs2 &&
8450 - sequenceNumber >= YAFFS_LOWEST_SEQUENCE_NUMBER &&
8451 - sequenceNumber < YAFFS_HIGHEST_SEQUENCE_NUMBER) {
8453 - blockIndex[nBlocksToScan].seq = sequenceNumber;
8454 - blockIndex[nBlocksToScan].block = blk;
8458 - if (sequenceNumber >= dev->sequenceNumber) {
8459 - dev->sequenceNumber = sequenceNumber;
8461 - } else if (dev->isYaffs2) {
8462 - /* TODO: Nasty sequence number! */
8463 - T(YAFFS_TRACE_SCAN,
8465 - ("Block scanning block %d has bad sequence number %d"
8466 - TENDSTR), blk, sequenceNumber));
8472 - /* Sort the blocks
8473 - * Dungy old bubble sort for now...
8475 - if (dev->isYaffs2) {
8476 - yaffs_BlockIndex temp;
8480 - for (i = 0; i < nBlocksToScan; i++)
8481 - for (j = i + 1; j < nBlocksToScan; j++)
8482 - if (blockIndex[i].seq > blockIndex[j].seq) {
8483 - temp = blockIndex[j];
8484 - blockIndex[j] = blockIndex[i];
8485 - blockIndex[i] = temp;
8489 - /* Now scan the blocks looking at the data. */
8490 - if (dev->isYaffs2) {
8491 - startIterator = 0;
8492 - endIterator = nBlocksToScan - 1;
8493 - T(YAFFS_TRACE_SCAN_DEBUG,
8494 - (TSTR("%d blocks to be scanned" TENDSTR), nBlocksToScan));
8496 - startIterator = dev->internalStartBlock;
8497 - endIterator = dev->internalEndBlock;
8499 + startIterator = dev->internalStartBlock;
8500 + endIterator = dev->internalEndBlock;
8502 /* For each block.... */
8503 for (blockIterator = startIterator; !alloc_failed && blockIterator <= endIterator;
8506 - if (dev->isYaffs2) {
8507 - /* get the block to scan in the correct order */
8508 - blk = blockIndex[blockIterator].block;
8510 - blk = blockIterator;
8516 + blk = blockIterator;
8518 bi = yaffs_GetBlockInfo(dev, blk);
8519 state = bi->blockState;
8520 @@ -5511,7 +5523,7 @@ static int yaffs_Scan(yaffs_Device * dev
8522 /* Let's have a good look at this chunk... */
8524 - if (!dev->isYaffs2 && tags.chunkDeleted) {
8525 + if (tags.eccResult == YAFFS_ECC_RESULT_UNFIXED || tags.chunkDeleted) {
8529 @@ -5540,18 +5552,6 @@ static int yaffs_Scan(yaffs_Device * dev
8530 dev->allocationBlockFinder = blk;
8531 /* Set it to here to encourage the allocator to go forth from here. */
8533 - /* Yaffs2 sanity check:
8534 - * This should be the one with the highest sequence number
8537 - && (dev->sequenceNumber !=
8538 - bi->sequenceNumber)) {
8539 - T(YAFFS_TRACE_ALWAYS,
8541 - ("yaffs: Allocation block %d was not highest sequence id:"
8542 - " block seq = %d, dev seq = %d"
8543 - TENDSTR), blk,bi->sequenceNumber,dev->sequenceNumber));
8547 dev->nFreeChunks += (dev->nChunksPerBlock - c);
8548 @@ -5570,11 +5570,11 @@ static int yaffs_Scan(yaffs_Device * dev
8549 * the same chunkId).
8557 - if(!yaffs_PutChunkIntoFile(in, tags.chunkId, chunk,1))
8559 + if (!yaffs_PutChunkIntoFile(in, tags.chunkId, chunk, 1))
8563 @@ -5617,7 +5617,7 @@ static int yaffs_Scan(yaffs_Device * dev
8564 * deleted, and worse still it has changed type. Delete the old object.
8567 - yaffs_DestroyObject(in);
8568 + yaffs_DeleteObject(in);
8572 @@ -5627,14 +5627,20 @@ static int yaffs_Scan(yaffs_Device * dev
8580 if (in && oh->shadowsObject > 0) {
8581 - yaffs_HandleShadowedObject(dev,
8586 + struct yaffs_ShadowFixerStruct *fixer;
8587 + fixer = YMALLOC(sizeof(struct yaffs_ShadowFixerStruct));
8589 + fixer->next = shadowFixerList;
8590 + shadowFixerList = fixer;
8591 + fixer->objectId = tags.objectId;
8592 + fixer->shadowedId = oh->shadowsObject;
8597 if (in && in->valid) {
8598 @@ -5643,12 +5649,10 @@ static int yaffs_Scan(yaffs_Device * dev
8599 unsigned existingSerial = in->serial;
8600 unsigned newSerial = tags.serialNumber;
8602 - if (dev->isYaffs2 ||
8603 - ((existingSerial + 1) & 3) ==
8605 + if (((existingSerial + 1) & 3) == newSerial) {
8606 /* Use new one - destroy the exisiting one */
8607 yaffs_DeleteChunk(dev,
8613 @@ -5681,7 +5685,8 @@ static int yaffs_Scan(yaffs_Device * dev
8614 in->yst_ctime = oh->yst_ctime;
8615 in->yst_rdev = oh->yst_rdev;
8617 - in->chunkId = chunk;
8618 + in->hdrChunk = chunk;
8619 + in->serial = tags.serialNumber;
8621 } else if (in && !in->valid) {
8622 /* we need to load this info */
8623 @@ -5705,7 +5710,8 @@ static int yaffs_Scan(yaffs_Device * dev
8624 in->yst_ctime = oh->yst_ctime;
8625 in->yst_rdev = oh->yst_rdev;
8627 - in->chunkId = chunk;
8628 + in->hdrChunk = chunk;
8629 + in->serial = tags.serialNumber;
8631 yaffs_SetObjectName(in, oh->name);
8633 @@ -5718,25 +5724,25 @@ static int yaffs_Scan(yaffs_Device * dev
8634 yaffs_FindOrCreateObjectByNumber
8635 (dev, oh->parentObjectId,
8636 YAFFS_OBJECT_TYPE_DIRECTORY);
8637 - if (parent->variantType ==
8640 + if (parent && parent->variantType ==
8641 YAFFS_OBJECT_TYPE_UNKNOWN) {
8642 /* Set up as a directory */
8643 parent->variantType =
8644 - YAFFS_OBJECT_TYPE_DIRECTORY;
8645 - INIT_LIST_HEAD(&parent->variant.
8648 - } else if (parent->variantType !=
8649 - YAFFS_OBJECT_TYPE_DIRECTORY)
8651 + YAFFS_OBJECT_TYPE_DIRECTORY;
8652 + YINIT_LIST_HEAD(&parent->variant.
8655 + } else if (!parent || parent->variantType !=
8656 + YAFFS_OBJECT_TYPE_DIRECTORY) {
8657 /* Hoosterman, another problem....
8658 * We're trying to use a non-directory as a directory
8661 T(YAFFS_TRACE_ERROR,
8663 - ("yaffs tragedy: attempting to use non-directory as"
8664 - " a directory in scan. Put in lost+found."
8665 + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found."
8667 parent = dev->lostNFoundDir;
8669 @@ -5760,15 +5766,6 @@ static int yaffs_Scan(yaffs_Device * dev
8670 /* Todo got a problem */
8672 case YAFFS_OBJECT_TYPE_FILE:
8674 - && oh->isShrink) {
8675 - /* Prune back the shrunken chunks */
8676 - yaffs_PruneResizedChunks
8677 - (in, oh->fileSize);
8678 - /* Mark the block as having a shrinkHeader */
8679 - bi->hasShrinkHeader = 1;
8682 if (dev->useHeaderFileSize)
8684 in->variant.fileVariant.
8685 @@ -5778,11 +5775,11 @@ static int yaffs_Scan(yaffs_Device * dev
8687 case YAFFS_OBJECT_TYPE_HARDLINK:
8688 in->variant.hardLinkVariant.
8689 - equivalentObjectId =
8690 - oh->equivalentObjectId;
8691 + equivalentObjectId =
8692 + oh->equivalentObjectId;
8693 in->hardLinks.next =
8694 - (struct list_head *)
8696 + (struct ylist_head *)
8700 case YAFFS_OBJECT_TYPE_DIRECTORY:
8701 @@ -5794,15 +5791,17 @@ static int yaffs_Scan(yaffs_Device * dev
8702 case YAFFS_OBJECT_TYPE_SYMLINK:
8703 in->variant.symLinkVariant.alias =
8704 yaffs_CloneString(oh->alias);
8705 - if(!in->variant.symLinkVariant.alias)
8706 + if (!in->variant.symLinkVariant.alias)
8712 if (parent == dev->deletedDir) {
8713 yaffs_DestroyObject(in);
8714 bi->hasShrinkHeader = 1;
8720 @@ -5823,10 +5822,6 @@ static int yaffs_Scan(yaffs_Device * dev
8725 - YFREE(blockIndex);
8729 /* Ok, we've done all the scanning.
8730 * Fix up the hard link chains.
8731 @@ -5834,32 +5829,36 @@ static int yaffs_Scan(yaffs_Device * dev
8735 - yaffs_HardlinkFixup(dev,hardList);
8736 + yaffs_HardlinkFixup(dev, hardList);
8738 - /* Handle the unlinked files. Since they were left in an unlinked state we should
8739 - * just delete them.
8741 + /* Fix up any shadowed objects */
8743 - struct list_head *i;
8744 - struct list_head *n;
8745 + struct yaffs_ShadowFixerStruct *fixer;
8746 + yaffs_Object *obj;
8749 - /* Soft delete all the unlinked files */
8750 - list_for_each_safe(i, n,
8751 - &dev->unlinkedDir->variant.directoryVariant.
8754 - l = list_entry(i, yaffs_Object, siblings);
8755 - yaffs_DestroyObject(l);
8757 + while (shadowFixerList) {
8758 + fixer = shadowFixerList;
8759 + shadowFixerList = fixer->next;
8760 + /* Complete the rename transaction by deleting the shadowed object
8761 + * then setting the object header to unshadowed.
8763 + obj = yaffs_FindObjectByNumber(dev, fixer->shadowedId);
8765 + yaffs_DeleteObject(obj);
8767 + obj = yaffs_FindObjectByNumber(dev, fixer->objectId);
8770 + yaffs_UpdateObjectHeader(obj, NULL, 1, 0, 0);
8776 yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__);
8783 T(YAFFS_TRACE_SCAN, (TSTR("yaffs_Scan ends" TENDSTR)));
8785 @@ -5871,25 +5870,27 @@ static void yaffs_CheckObjectDetailsLoad
8788 yaffs_ObjectHeader *oh;
8789 - yaffs_Device *dev = in->myDev;
8790 + yaffs_Device *dev;
8791 yaffs_ExtendedTags tags;
8793 int alloc_failed = 0;
8802 - T(YAFFS_TRACE_SCAN,(TSTR("details for object %d %s loaded" TENDSTR),
8803 + T(YAFFS_TRACE_SCAN, (TSTR("details for object %d %s loaded" TENDSTR),
8805 in->lazyLoaded ? "not yet" : "already"));
8808 - if(in->lazyLoaded){
8809 + if (in->lazyLoaded && in->hdrChunk > 0) {
8811 chunkData = yaffs_GetTempBuffer(dev, __LINE__);
8813 - result = yaffs_ReadChunkWithTagsFromNAND(dev,in->chunkId,chunkData,&tags);
8814 + result = yaffs_ReadChunkWithTagsFromNAND(dev, in->hdrChunk, chunkData, &tags);
8815 oh = (yaffs_ObjectHeader *) chunkData;
8817 in->yst_mode = oh->yst_mode;
8818 @@ -5911,18 +5912,18 @@ static void yaffs_CheckObjectDetailsLoad
8820 yaffs_SetObjectName(in, oh->name);
8822 - if(in->variantType == YAFFS_OBJECT_TYPE_SYMLINK){
8823 - in->variant.symLinkVariant.alias =
8824 + if (in->variantType == YAFFS_OBJECT_TYPE_SYMLINK) {
8825 + in->variant.symLinkVariant.alias =
8826 yaffs_CloneString(oh->alias);
8827 - if(!in->variant.symLinkVariant.alias)
8828 + if (!in->variant.symLinkVariant.alias)
8829 alloc_failed = 1; /* Not returned to caller */
8832 - yaffs_ReleaseTempBuffer(dev,chunkData, __LINE__);
8833 + yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__);
8837 -static int yaffs_ScanBackwards(yaffs_Device * dev)
8838 +static int yaffs_ScanBackwards(yaffs_Device *dev)
8840 yaffs_ExtendedTags tags;
8842 @@ -5938,7 +5939,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
8843 yaffs_BlockState state;
8844 yaffs_Object *hardList = NULL;
8845 yaffs_BlockInfo *bi;
8846 - int sequenceNumber;
8847 + __u32 sequenceNumber;
8848 yaffs_ObjectHeader *oh;
8850 yaffs_Object *parent;
8851 @@ -5972,12 +5973,12 @@ static int yaffs_ScanBackwards(yaffs_Dev
8853 blockIndex = YMALLOC(nBlocks * sizeof(yaffs_BlockIndex));
8856 + if (!blockIndex) {
8857 blockIndex = YMALLOC_ALT(nBlocks * sizeof(yaffs_BlockIndex));
8862 + if (!blockIndex) {
8864 (TSTR("yaffs_Scan() could not allocate block index!" TENDSTR)));
8866 @@ -5999,15 +6000,17 @@ static int yaffs_ScanBackwards(yaffs_Dev
8867 bi->blockState = state;
8868 bi->sequenceNumber = sequenceNumber;
8870 - if(bi->sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA)
8871 + if (bi->sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA)
8872 bi->blockState = state = YAFFS_BLOCK_STATE_CHECKPOINT;
8873 + if (bi->sequenceNumber == YAFFS_SEQUENCE_BAD_BLOCK)
8874 + bi->blockState = state = YAFFS_BLOCK_STATE_DEAD;
8876 T(YAFFS_TRACE_SCAN_DEBUG,
8877 (TSTR("Block scanning block %d state %d seq %d" TENDSTR), blk,
8878 state, sequenceNumber));
8881 - if(state == YAFFS_BLOCK_STATE_CHECKPOINT){
8882 + if (state == YAFFS_BLOCK_STATE_CHECKPOINT) {
8883 dev->blocksInCheckpoint++;
8885 } else if (state == YAFFS_BLOCK_STATE_DEAD) {
8886 @@ -6021,8 +6024,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
8887 } else if (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING) {
8889 /* Determine the highest sequence number */
8890 - if (dev->isYaffs2 &&
8891 - sequenceNumber >= YAFFS_LOWEST_SEQUENCE_NUMBER &&
8892 + if (sequenceNumber >= YAFFS_LOWEST_SEQUENCE_NUMBER &&
8893 sequenceNumber < YAFFS_HIGHEST_SEQUENCE_NUMBER) {
8895 blockIndex[nBlocksToScan].seq = sequenceNumber;
8896 @@ -6030,10 +6032,9 @@ static int yaffs_ScanBackwards(yaffs_Dev
8900 - if (sequenceNumber >= dev->sequenceNumber) {
8901 + if (sequenceNumber >= dev->sequenceNumber)
8902 dev->sequenceNumber = sequenceNumber;
8904 - } else if (dev->isYaffs2) {
8906 /* TODO: Nasty sequence number! */
8909 @@ -6053,11 +6054,13 @@ static int yaffs_ScanBackwards(yaffs_Dev
8911 /* Sort the blocks */
8912 #ifndef CONFIG_YAFFS_USE_OWN_SORT
8913 - yaffs_qsort(blockIndex, nBlocksToScan,
8914 - sizeof(yaffs_BlockIndex), ybicmp);
8916 + /* Use qsort now. */
8917 + yaffs_qsort(blockIndex, nBlocksToScan, sizeof(yaffs_BlockIndex), ybicmp);
8921 - /* Dungy old bubble sort... */
8922 + /* Dungy old bubble sort... */
8924 yaffs_BlockIndex temp;
8926 @@ -6075,7 +6078,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
8930 - T(YAFFS_TRACE_SCAN, (TSTR("...done" TENDSTR)));
8931 + T(YAFFS_TRACE_SCAN, (TSTR("...done" TENDSTR)));
8933 /* Now scan the blocks looking at the data. */
8935 @@ -6085,10 +6088,10 @@ static int yaffs_ScanBackwards(yaffs_Dev
8937 /* For each block.... backwards */
8938 for (blockIterator = endIterator; !alloc_failed && blockIterator >= startIterator;
8939 - blockIterator--) {
8940 - /* Cooperative multitasking! This loop can run for so
8941 + blockIterator--) {
8942 + /* Cooperative multitasking! This loop can run for so
8943 long that watchdog timers expire. */
8947 /* get the block to scan in the correct order */
8948 blk = blockIndex[blockIterator].block;
8949 @@ -6127,10 +6130,8 @@ static int yaffs_ScanBackwards(yaffs_Dev
8950 * this is the one being allocated from
8953 - if(foundChunksInBlock)
8955 + if (foundChunksInBlock) {
8956 /* This is a chunk that was skipped due to failing the erased check */
8958 } else if (c == 0) {
8959 /* We're looking at the first chunk in the block so the block is unused */
8960 state = YAFFS_BLOCK_STATE_EMPTY;
8961 @@ -6138,7 +6139,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
8963 if (state == YAFFS_BLOCK_STATE_NEEDS_SCANNING ||
8964 state == YAFFS_BLOCK_STATE_ALLOCATING) {
8965 - if(dev->sequenceNumber == bi->sequenceNumber) {
8966 + if (dev->sequenceNumber == bi->sequenceNumber) {
8967 /* this is the block being allocated from */
8970 @@ -6150,27 +6151,31 @@ static int yaffs_ScanBackwards(yaffs_Dev
8971 dev->allocationBlock = blk;
8972 dev->allocationPage = c;
8973 dev->allocationBlockFinder = blk;
8977 /* This is a partially written block that is not
8978 * the current allocation block. This block must have
8979 * had a write failure, so set up for retirement.
8982 - bi->needsRetiring = 1;
8983 + /* bi->needsRetiring = 1; ??? TODO */
8984 bi->gcPrioritise = 1;
8986 T(YAFFS_TRACE_ALWAYS,
8987 - (TSTR("Partially written block %d being set for retirement" TENDSTR),
8988 + (TSTR("Partially written block %d detected" TENDSTR),
8998 + } else if (tags.eccResult == YAFFS_ECC_RESULT_UNFIXED) {
8999 + T(YAFFS_TRACE_SCAN,
9000 + (TSTR(" Unfixed ECC in chunk(%d:%d), chunk ignored"TENDSTR),
9003 + dev->nFreeChunks++;
9005 } else if (tags.chunkId > 0) {
9006 /* chunkId > 0 so it is a data chunk... */
9007 unsigned int endpos;
9008 @@ -6187,7 +6192,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
9011 YAFFS_OBJECT_TYPE_FILE);
9017 @@ -6197,8 +6202,8 @@ static int yaffs_ScanBackwards(yaffs_Dev
9019 in->variant.fileVariant.shrinkSize) {
9020 /* This has not been invalidated by a resize */
9021 - if(!yaffs_PutChunkIntoFile(in, tags.chunkId,
9023 + if (!yaffs_PutChunkIntoFile(in, tags.chunkId,
9028 @@ -6221,7 +6226,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
9034 /* This chunk has been invalidated by a resize, so delete */
9035 yaffs_DeleteChunk(dev, chunk, 1, __LINE__);
9037 @@ -6242,6 +6247,8 @@ static int yaffs_ScanBackwards(yaffs_Dev
9038 in = yaffs_FindOrCreateObjectByNumber
9039 (dev, tags.objectId,
9040 tags.extraObjectType);
9046 @@ -6251,8 +6258,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
9047 tags.extraShadows ||
9049 (tags.objectId == YAFFS_OBJECTID_ROOT ||
9050 - tags.objectId == YAFFS_OBJECTID_LOSTNFOUND))
9052 + tags.objectId == YAFFS_OBJECTID_LOSTNFOUND))) {
9054 /* If we don't have valid info then we need to read the chunk
9055 * TODO In future we can probably defer reading the chunk and
9056 @@ -6266,8 +6272,17 @@ static int yaffs_ScanBackwards(yaffs_Dev
9058 oh = (yaffs_ObjectHeader *) chunkData;
9061 + if (dev->inbandTags) {
9062 + /* Fix up the header if they got corrupted by inband tags */
9063 + oh->shadowsObject = oh->inbandShadowsObject;
9064 + oh->isShrink = oh->inbandIsShrink;
9068 in = yaffs_FindOrCreateObjectByNumber(dev, tags.objectId, oh->type);
9075 @@ -6275,10 +6290,9 @@ static int yaffs_ScanBackwards(yaffs_Dev
9076 /* TODO Hoosterman we have a problem! */
9077 T(YAFFS_TRACE_ERROR,
9079 - ("yaffs tragedy: Could not make object for object %d "
9080 - "at chunk %d during scan"
9081 + ("yaffs tragedy: Could not make object for object %d at chunk %d during scan"
9082 TENDSTR), tags.objectId, chunk));
9088 @@ -6289,10 +6303,9 @@ static int yaffs_ScanBackwards(yaffs_Dev
9090 if ((in->variantType == YAFFS_OBJECT_TYPE_FILE) &&
9092 - oh-> type == YAFFS_OBJECT_TYPE_FILE)||
9093 + oh->type == YAFFS_OBJECT_TYPE_FILE) ||
9094 (tags.extraHeaderInfoAvailable &&
9095 - tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE))
9097 + tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE))) {
9099 (oh) ? oh->fileSize : tags.
9101 @@ -6300,7 +6313,9 @@ static int yaffs_ScanBackwards(yaffs_Dev
9103 parentObjectId : tags.
9104 extraParentObjectId;
9105 - unsigned isShrink =
9109 (oh) ? oh->isShrink : tags.
9110 extraIsShrinkHeader;
9112 @@ -6323,9 +6338,8 @@ static int yaffs_ScanBackwards(yaffs_Dev
9118 bi->hasShrinkHeader = 1;
9122 /* Use existing - destroy this one. */
9123 @@ -6333,6 +6347,17 @@ static int yaffs_ScanBackwards(yaffs_Dev
9127 + if (!in->valid && in->variantType !=
9128 + (oh ? oh->type : tags.extraObjectType))
9129 + T(YAFFS_TRACE_ERROR, (
9130 + TSTR("yaffs tragedy: Bad object type, "
9131 + TCONT("%d != %d, for object %d at chunk ")
9132 + TCONT("%d during scan")
9134 + oh->type : tags.extraObjectType,
9135 + in->variantType, tags.objectId,
9139 (tags.objectId == YAFFS_OBJECTID_ROOT ||
9141 @@ -6340,7 +6365,7 @@ static int yaffs_ScanBackwards(yaffs_Dev
9142 /* We only load some info, don't fiddle with directory structure */
9147 in->variantType = oh->type;
9149 in->yst_mode = oh->yst_mode;
9150 @@ -6365,15 +6390,15 @@ static int yaffs_ScanBackwards(yaffs_Dev
9154 - in->chunkId = chunk;
9155 + in->hdrChunk = chunk;
9157 } else if (!in->valid) {
9158 /* we need to load this info */
9161 - in->chunkId = chunk;
9162 + in->hdrChunk = chunk;
9166 in->variantType = oh->type;
9168 in->yst_mode = oh->yst_mode;
9169 @@ -6403,20 +6428,19 @@ static int yaffs_ScanBackwards(yaffs_Dev
9170 yaffs_SetObjectName(in, oh->name);
9172 yaffs_FindOrCreateObjectByNumber
9173 - (dev, oh->parentObjectId,
9174 - YAFFS_OBJECT_TYPE_DIRECTORY);
9175 + (dev, oh->parentObjectId,
9176 + YAFFS_OBJECT_TYPE_DIRECTORY);
9178 fileSize = oh->fileSize;
9179 - isShrink = oh->isShrink;
9180 + isShrink = oh->isShrink;
9181 equivalentObjectId = oh->equivalentObjectId;
9186 in->variantType = tags.extraObjectType;
9188 yaffs_FindOrCreateObjectByNumber
9189 - (dev, tags.extraParentObjectId,
9190 - YAFFS_OBJECT_TYPE_DIRECTORY);
9191 + (dev, tags.extraParentObjectId,
9192 + YAFFS_OBJECT_TYPE_DIRECTORY);
9193 fileSize = tags.extraFileLength;
9194 isShrink = tags.extraIsShrinkHeader;
9195 equivalentObjectId = tags.extraEquivalentObjectId;
9196 @@ -6425,29 +6449,30 @@ static int yaffs_ScanBackwards(yaffs_Dev
9203 /* directory stuff...
9207 - if (parent->variantType ==
9208 + if (parent && parent->variantType ==
9209 YAFFS_OBJECT_TYPE_UNKNOWN) {
9210 /* Set up as a directory */
9211 parent->variantType =
9212 - YAFFS_OBJECT_TYPE_DIRECTORY;
9213 - INIT_LIST_HEAD(&parent->variant.
9216 - } else if (parent->variantType !=
9217 - YAFFS_OBJECT_TYPE_DIRECTORY)
9219 + YAFFS_OBJECT_TYPE_DIRECTORY;
9220 + YINIT_LIST_HEAD(&parent->variant.
9223 + } else if (!parent || parent->variantType !=
9224 + YAFFS_OBJECT_TYPE_DIRECTORY) {
9225 /* Hoosterman, another problem....
9226 * We're trying to use a non-directory as a directory
9229 T(YAFFS_TRACE_ERROR,
9231 - ("yaffs tragedy: attempting to use non-directory as"
9232 - " a directory in scan. Put in lost+found."
9233 + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found."
9235 parent = dev->lostNFoundDir;
9237 @@ -6494,12 +6519,12 @@ static int yaffs_ScanBackwards(yaffs_Dev
9240 case YAFFS_OBJECT_TYPE_HARDLINK:
9241 - if(!itsUnlinked) {
9242 - in->variant.hardLinkVariant.equivalentObjectId =
9243 - equivalentObjectId;
9244 - in->hardLinks.next =
9245 - (struct list_head *) hardList;
9247 + if (!itsUnlinked) {
9248 + in->variant.hardLinkVariant.equivalentObjectId =
9249 + equivalentObjectId;
9250 + in->hardLinks.next =
9251 + (struct ylist_head *) hardList;
9255 case YAFFS_OBJECT_TYPE_DIRECTORY:
9256 @@ -6509,12 +6534,11 @@ static int yaffs_ScanBackwards(yaffs_Dev
9259 case YAFFS_OBJECT_TYPE_SYMLINK:
9261 - in->variant.symLinkVariant.alias =
9262 - yaffs_CloneString(oh->
9264 - if(!in->variant.symLinkVariant.alias)
9267 + in->variant.symLinkVariant.alias =
9268 + yaffs_CloneString(oh->alias);
9269 + if (!in->variant.symLinkVariant.alias)
9274 @@ -6551,75 +6575,129 @@ static int yaffs_ScanBackwards(yaffs_Dev
9275 * We should now have scanned all the objects, now it's time to add these
9278 - yaffs_HardlinkFixup(dev,hardList);
9279 + yaffs_HardlinkFixup(dev, hardList);
9283 - * Sort out state of unlinked and deleted objects.
9286 - struct list_head *i;
9287 - struct list_head *n;
9288 + yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__);
9292 + return YAFFS_FAIL;
9294 - /* Soft delete all the unlinked files */
9295 - list_for_each_safe(i, n,
9296 - &dev->unlinkedDir->variant.directoryVariant.
9299 - l = list_entry(i, yaffs_Object, siblings);
9300 - yaffs_DestroyObject(l);
9303 + T(YAFFS_TRACE_SCAN, (TSTR("yaffs_ScanBackwards ends" TENDSTR)));
9305 - /* Soft delete all the deletedDir files */
9306 - list_for_each_safe(i, n,
9307 - &dev->deletedDir->variant.directoryVariant.
9310 - l = list_entry(i, yaffs_Object, siblings);
9311 - yaffs_DestroyObject(l);
9316 +/*------------------------------ Directory Functions ----------------------------- */
9318 +static void yaffs_VerifyObjectInDirectory(yaffs_Object *obj)
9320 + struct ylist_head *lh;
9321 + yaffs_Object *listObj;
9326 + T(YAFFS_TRACE_ALWAYS, (TSTR("No object to verify" TENDSTR)));
9331 + if (yaffs_SkipVerification(obj->myDev))
9334 + if (!obj->parent) {
9335 + T(YAFFS_TRACE_ALWAYS, (TSTR("Object does not have parent" TENDSTR)));
9340 + if (obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
9341 + T(YAFFS_TRACE_ALWAYS, (TSTR("Parent is not directory" TENDSTR)));
9345 + /* Iterate through the objects in each hash entry */
9347 + ylist_for_each(lh, &obj->parent->variant.directoryVariant.children) {
9349 + listObj = ylist_entry(lh, yaffs_Object, siblings);
9350 + yaffs_VerifyObject(listObj);
9351 + if (obj == listObj)
9357 + T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory %d times" TENDSTR), count));
9362 - yaffs_ReleaseTempBuffer(dev, chunkData, __LINE__);
9363 +static void yaffs_VerifyDirectory(yaffs_Object *directory)
9365 + struct ylist_head *lh;
9366 + yaffs_Object *listObj;
9369 - return YAFFS_FAIL;
9375 - T(YAFFS_TRACE_SCAN, (TSTR("yaffs_ScanBackwards ends" TENDSTR)));
9376 + if (yaffs_SkipFullVerification(directory->myDev))
9380 + if (directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
9381 + T(YAFFS_TRACE_ALWAYS, (TSTR("Directory has wrong type: %d" TENDSTR), directory->variantType));
9385 + /* Iterate through the objects in each hash entry */
9387 + ylist_for_each(lh, &directory->variant.directoryVariant.children) {
9389 + listObj = ylist_entry(lh, yaffs_Object, siblings);
9390 + if (listObj->parent != directory) {
9391 + T(YAFFS_TRACE_ALWAYS, (TSTR("Object in directory list has wrong parent %p" TENDSTR), listObj->parent));
9394 + yaffs_VerifyObjectInDirectory(listObj);
9399 -/*------------------------------ Directory Functions ----------------------------- */
9401 -static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj)
9402 +static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj)
9404 yaffs_Device *dev = obj->myDev;
9405 + yaffs_Object *parent;
9407 + yaffs_VerifyObjectInDirectory(obj);
9408 + parent = obj->parent;
9410 + yaffs_VerifyDirectory(parent);
9412 - if(dev && dev->removeObjectCallback)
9413 + if (dev && dev->removeObjectCallback)
9414 dev->removeObjectCallback(obj);
9416 - list_del_init(&obj->siblings);
9418 + ylist_del_init(&obj->siblings);
9421 + yaffs_VerifyDirectory(parent);
9425 -static void yaffs_AddObjectToDirectory(yaffs_Object * directory,
9426 - yaffs_Object * obj)
9427 +static void yaffs_AddObjectToDirectory(yaffs_Object *directory,
9428 + yaffs_Object *obj)
9432 T(YAFFS_TRACE_ALWAYS,
9434 ("tragedy: Trying to add an object to a null pointer directory"
9439 if (directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
9440 T(YAFFS_TRACE_ALWAYS,
9441 @@ -6631,37 +6709,42 @@ static void yaffs_AddObjectToDirectory(y
9443 if (obj->siblings.prev == NULL) {
9444 /* Not initialised */
9445 - INIT_LIST_HEAD(&obj->siblings);
9447 - } else if (!list_empty(&obj->siblings)) {
9448 - /* If it is holed up somewhere else, un hook it */
9449 - yaffs_RemoveObjectFromDirectory(obj);
9454 + yaffs_VerifyDirectory(directory);
9456 + yaffs_RemoveObjectFromDirectory(obj);
9460 - list_add(&obj->siblings, &directory->variant.directoryVariant.children);
9461 + ylist_add(&obj->siblings, &directory->variant.directoryVariant.children);
9462 obj->parent = directory;
9464 if (directory == obj->myDev->unlinkedDir
9465 - || directory == obj->myDev->deletedDir) {
9466 + || directory == obj->myDev->deletedDir) {
9468 obj->myDev->nUnlinkedFiles++;
9469 obj->renameAllowed = 0;
9472 + yaffs_VerifyDirectory(directory);
9473 + yaffs_VerifyObjectInDirectory(obj);
9476 -yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory,
9477 - const YCHAR * name)
9478 +yaffs_Object *yaffs_FindObjectByName(yaffs_Object *directory,
9479 + const YCHAR *name)
9483 - struct list_head *i;
9484 + struct ylist_head *i;
9485 YCHAR buffer[YAFFS_MAX_NAME_LENGTH + 1];
9495 T(YAFFS_TRACE_ALWAYS,
9496 @@ -6669,6 +6752,7 @@ yaffs_Object *yaffs_FindObjectByName(yaf
9497 ("tragedy: yaffs_FindObjectByName: null pointer directory"
9502 if (directory->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
9503 T(YAFFS_TRACE_ALWAYS,
9504 @@ -6679,28 +6763,27 @@ yaffs_Object *yaffs_FindObjectByName(yaf
9506 sum = yaffs_CalcNameSum(name);
9508 - list_for_each(i, &directory->variant.directoryVariant.children) {
9509 + ylist_for_each(i, &directory->variant.directoryVariant.children) {
9511 - l = list_entry(i, yaffs_Object, siblings);
9512 + l = ylist_entry(i, yaffs_Object, siblings);
9514 + if (l->parent != directory)
9517 yaffs_CheckObjectDetailsLoaded(l);
9519 /* Special case for lost-n-found */
9520 if (l->objectId == YAFFS_OBJECTID_LOSTNFOUND) {
9521 - if (yaffs_strcmp(name, YAFFS_LOSTNFOUND_NAME) == 0) {
9522 + if (yaffs_strcmp(name, YAFFS_LOSTNFOUND_NAME) == 0)
9525 - } else if (yaffs_SumCompare(l->sum, sum) || l->chunkId <= 0)
9527 - /* LostnFound cunk called Objxxx
9528 + } else if (yaffs_SumCompare(l->sum, sum) || l->hdrChunk <= 0) {
9529 + /* LostnFound chunk called Objxxx
9532 yaffs_GetObjectName(l, buffer,
9533 YAFFS_MAX_NAME_LENGTH);
9534 - if (yaffs_strncmp(name, buffer,YAFFS_MAX_NAME_LENGTH) == 0) {
9535 + if (yaffs_strncmp(name, buffer, YAFFS_MAX_NAME_LENGTH) == 0)
9542 @@ -6710,10 +6793,10 @@ yaffs_Object *yaffs_FindObjectByName(yaf
9546 -int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir,
9547 - int (*fn) (yaffs_Object *))
9548 +int yaffs_ApplyToDirectoryChildren(yaffs_Object *theDir,
9549 + int (*fn) (yaffs_Object *))
9551 - struct list_head *i;
9552 + struct ylist_head *i;
9556 @@ -6722,20 +6805,21 @@ int yaffs_ApplyToDirectoryChildren(yaffs
9557 ("tragedy: yaffs_FindObjectByName: null pointer directory"
9560 + return YAFFS_FAIL;
9562 if (theDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) {
9563 T(YAFFS_TRACE_ALWAYS,
9565 ("tragedy: yaffs_FindObjectByName: non-directory" TENDSTR)));
9567 + return YAFFS_FAIL;
9570 - list_for_each(i, &theDir->variant.directoryVariant.children) {
9571 + ylist_for_each(i, &theDir->variant.directoryVariant.children) {
9573 - l = list_entry(i, yaffs_Object, siblings);
9574 - if (l && !fn(l)) {
9575 + l = ylist_entry(i, yaffs_Object, siblings);
9582 @@ -6748,7 +6832,7 @@ int yaffs_ApplyToDirectoryChildren(yaffs
9586 -yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object * obj)
9587 +yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj)
9589 if (obj && obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) {
9590 /* We want the object id of the equivalent object, not this one */
9591 @@ -6756,10 +6840,9 @@ yaffs_Object *yaffs_GetEquivalentObject(
9592 yaffs_CheckObjectDetailsLoaded(obj);
9598 -int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize)
9599 +int yaffs_GetObjectName(yaffs_Object *obj, YCHAR *name, int buffSize)
9601 memset(name, 0, buffSize * sizeof(YCHAR));
9603 @@ -6767,18 +6850,26 @@ int yaffs_GetObjectName(yaffs_Object * o
9605 if (obj->objectId == YAFFS_OBJECTID_LOSTNFOUND) {
9606 yaffs_strncpy(name, YAFFS_LOSTNFOUND_NAME, buffSize - 1);
9607 - } else if (obj->chunkId <= 0) {
9608 + } else if (obj->hdrChunk <= 0) {
9610 + YCHAR numString[20];
9611 + YCHAR *x = &numString[19];
9612 + unsigned v = obj->objectId;
9613 + numString[19] = 0;
9616 + *x = '0' + (v % 10);
9619 /* make up a name */
9620 - yaffs_sprintf(locName, _Y("%s%d"), YAFFS_LOSTNFOUND_PREFIX,
9622 + yaffs_strcpy(locName, YAFFS_LOSTNFOUND_PREFIX);
9623 + yaffs_strcat(locName, x);
9624 yaffs_strncpy(name, locName, buffSize - 1);
9627 #ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
9628 - else if (obj->shortName[0]) {
9629 + else if (obj->shortName[0])
9630 yaffs_strcpy(name, obj->shortName);
9635 @@ -6788,9 +6879,9 @@ int yaffs_GetObjectName(yaffs_Object * o
9637 memset(buffer, 0, obj->myDev->nDataBytesPerChunk);
9639 - if (obj->chunkId >= 0) {
9640 + if (obj->hdrChunk > 0) {
9641 result = yaffs_ReadChunkWithTagsFromNAND(obj->myDev,
9642 - obj->chunkId, buffer,
9643 + obj->hdrChunk, buffer,
9646 yaffs_strncpy(name, oh->name, buffSize - 1);
9647 @@ -6801,46 +6892,43 @@ int yaffs_GetObjectName(yaffs_Object * o
9648 return yaffs_strlen(name);
9651 -int yaffs_GetObjectFileLength(yaffs_Object * obj)
9652 +int yaffs_GetObjectFileLength(yaffs_Object *obj)
9655 /* Dereference any hard linking */
9656 obj = yaffs_GetEquivalentObject(obj);
9658 - if (obj->variantType == YAFFS_OBJECT_TYPE_FILE) {
9659 + if (obj->variantType == YAFFS_OBJECT_TYPE_FILE)
9660 return obj->variant.fileVariant.fileSize;
9662 - if (obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) {
9663 + if (obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
9664 return yaffs_strlen(obj->variant.symLinkVariant.alias);
9667 /* Only a directory should drop through to here */
9668 return obj->myDev->nDataBytesPerChunk;
9672 -int yaffs_GetObjectLinkCount(yaffs_Object * obj)
9673 +int yaffs_GetObjectLinkCount(yaffs_Object *obj)
9676 - struct list_head *i;
9677 + struct ylist_head *i;
9679 - if (!obj->unlinked) {
9680 - count++; /* the object itself */
9682 - list_for_each(i, &obj->hardLinks) {
9683 - count++; /* add the hard links; */
9686 + if (!obj->unlinked)
9687 + count++; /* the object itself */
9689 + ylist_for_each(i, &obj->hardLinks)
9690 + count++; /* add the hard links; */
9695 -int yaffs_GetObjectInode(yaffs_Object * obj)
9696 +int yaffs_GetObjectInode(yaffs_Object *obj)
9698 obj = yaffs_GetEquivalentObject(obj);
9700 return obj->objectId;
9703 -unsigned yaffs_GetObjectType(yaffs_Object * obj)
9704 +unsigned yaffs_GetObjectType(yaffs_Object *obj)
9706 obj = yaffs_GetEquivalentObject(obj);
9708 @@ -6872,19 +6960,18 @@ unsigned yaffs_GetObjectType(yaffs_Objec
9712 -YCHAR *yaffs_GetSymlinkAlias(yaffs_Object * obj)
9713 +YCHAR *yaffs_GetSymlinkAlias(yaffs_Object *obj)
9715 obj = yaffs_GetEquivalentObject(obj);
9716 - if (obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK) {
9717 + if (obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
9718 return yaffs_CloneString(obj->variant.symLinkVariant.alias);
9721 return yaffs_CloneString(_Y(""));
9725 #ifndef CONFIG_YAFFS_WINCE
9727 -int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr)
9728 +int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr)
9730 unsigned int valid = attr->ia_valid;
9732 @@ -6910,7 +6997,7 @@ int yaffs_SetAttributes(yaffs_Object * o
9736 -int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr)
9737 +int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr)
9739 unsigned int valid = 0;
9741 @@ -6934,13 +7021,12 @@ int yaffs_GetAttributes(yaffs_Object * o
9742 attr->ia_valid = valid;
9751 -int yaffs_DumpObject(yaffs_Object * obj)
9752 +int yaffs_DumpObject(yaffs_Object *obj)
9756 @@ -6951,7 +7037,7 @@ int yaffs_DumpObject(yaffs_Object * obj)
9757 ("Object %d, inode %d \"%s\"\n dirty %d valid %d serial %d sum %d"
9758 " chunk %d type %d size %d\n"
9759 TENDSTR), obj->objectId, yaffs_GetObjectInode(obj), name,
9760 - obj->dirty, obj->valid, obj->serial, obj->sum, obj->chunkId,
9761 + obj->dirty, obj->valid, obj->serial, obj->sum, obj->hdrChunk,
9762 yaffs_GetObjectType(obj), yaffs_GetObjectFileLength(obj)));
9765 @@ -6960,7 +7046,7 @@ int yaffs_DumpObject(yaffs_Object * obj)
9767 /*---------------------------- Initialisation code -------------------------------------- */
9769 -static int yaffs_CheckDevFunctions(const yaffs_Device * dev)
9770 +static int yaffs_CheckDevFunctions(const yaffs_Device *dev)
9773 /* Common functions, gotta have */
9774 @@ -7011,7 +7097,7 @@ static int yaffs_CreateInitialDirectorie
9775 yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_LOSTNFOUND,
9776 YAFFS_LOSTNFOUND_MODE | S_IFDIR);
9778 - if(dev->lostNFoundDir && dev->rootDir && dev->unlinkedDir && dev->deletedDir){
9779 + if (dev->lostNFoundDir && dev->rootDir && dev->unlinkedDir && dev->deletedDir) {
9780 yaffs_AddObjectToDirectory(dev->rootDir, dev->lostNFoundDir);
9783 @@ -7019,7 +7105,7 @@ static int yaffs_CreateInitialDirectorie
9787 -int yaffs_GutsInitialise(yaffs_Device * dev)
9788 +int yaffs_GutsInitialise(yaffs_Device *dev)
9790 int init_failed = 0;
9792 @@ -7040,6 +7126,8 @@ int yaffs_GutsInitialise(yaffs_Device *
9793 dev->chunkOffset = 0;
9794 dev->nFreeChunks = 0;
9796 + dev->gcBlock = -1;
9798 if (dev->startBlock == 0) {
9799 dev->internalStartBlock = dev->startBlock + 1;
9800 dev->internalEndBlock = dev->endBlock + 1;
9801 @@ -7049,18 +7137,18 @@ int yaffs_GutsInitialise(yaffs_Device *
9803 /* Check geometry parameters. */
9805 - if ((dev->isYaffs2 && dev->nDataBytesPerChunk < 1024) ||
9806 - (!dev->isYaffs2 && dev->nDataBytesPerChunk != 512) ||
9807 + if ((!dev->inbandTags && dev->isYaffs2 && dev->totalBytesPerChunk < 1024) ||
9808 + (!dev->isYaffs2 && dev->totalBytesPerChunk < 512) ||
9809 + (dev->inbandTags && !dev->isYaffs2) ||
9810 dev->nChunksPerBlock < 2 ||
9811 dev->nReservedBlocks < 2 ||
9812 dev->internalStartBlock <= 0 ||
9813 dev->internalEndBlock <= 0 ||
9814 - dev->internalEndBlock <= (dev->internalStartBlock + dev->nReservedBlocks + 2) // otherwise it is too small
9816 + dev->internalEndBlock <= (dev->internalStartBlock + dev->nReservedBlocks + 2)) { /* otherwise it is too small */
9817 T(YAFFS_TRACE_ALWAYS,
9819 - ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s "
9820 - TENDSTR), dev->nDataBytesPerChunk, dev->isYaffs2 ? "2" : ""));
9821 + ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s, inbandTags %d "
9822 + TENDSTR), dev->totalBytesPerChunk, dev->isYaffs2 ? "2" : "", dev->inbandTags));
9826 @@ -7070,6 +7158,12 @@ int yaffs_GutsInitialise(yaffs_Device *
9830 + /* Sort out space for inband tags, if required */
9831 + if (dev->inbandTags)
9832 + dev->nDataBytesPerChunk = dev->totalBytesPerChunk - sizeof(yaffs_PackedTags2TagsPart);
9834 + dev->nDataBytesPerChunk = dev->totalBytesPerChunk;
9836 /* Got the right mix of functions? */
9837 if (!yaffs_CheckDevFunctions(dev)) {
9838 /* Function missing */
9839 @@ -7097,31 +7191,18 @@ int yaffs_GutsInitialise(yaffs_Device *
9845 /* OK now calculate a few things for the device */
9848 * Calculate all the chunk size manipulation numbers:
9850 - /* Start off assuming it is a power of 2 */
9851 - dev->chunkShift = ShiftDiv(dev->nDataBytesPerChunk);
9852 - dev->chunkMask = (1<<dev->chunkShift) - 1;
9854 - if(dev->nDataBytesPerChunk == (dev->chunkMask + 1)){
9855 - /* Yes it is a power of 2, disable crumbs */
9856 - dev->crumbMask = 0;
9857 - dev->crumbShift = 0;
9858 - dev->crumbsPerChunk = 0;
9860 - /* Not a power of 2, use crumbs instead */
9861 - dev->crumbShift = ShiftDiv(sizeof(yaffs_PackedTags2TagsPart));
9862 - dev->crumbMask = (1<<dev->crumbShift)-1;
9863 - dev->crumbsPerChunk = dev->nDataBytesPerChunk/(1 << dev->crumbShift);
9864 - dev->chunkShift = 0;
9865 - dev->chunkMask = 0;
9868 + x = dev->nDataBytesPerChunk;
9869 + /* We always use dev->chunkShift and dev->chunkDiv */
9870 + dev->chunkShift = Shifts(x);
9871 + x >>= dev->chunkShift;
9872 + dev->chunkDiv = x;
9873 + /* We only use chunk mask if chunkDiv is 1 */
9874 + dev->chunkMask = (1<<dev->chunkShift) - 1;
9877 * Calculate chunkGroupBits.
9878 @@ -7133,16 +7214,15 @@ int yaffs_GutsInitialise(yaffs_Device *
9881 /* Set up tnode width if wide tnodes are enabled. */
9882 - if(!dev->wideTnodesDisabled){
9883 + if (!dev->wideTnodesDisabled) {
9884 /* bits must be even so that we end up with 32-bit words */
9890 dev->tnodeWidth = 16;
9892 dev->tnodeWidth = bits;
9896 dev->tnodeWidth = 16;
9898 dev->tnodeMask = (1<<dev->tnodeWidth)-1;
9899 @@ -7193,7 +7273,7 @@ int yaffs_GutsInitialise(yaffs_Device *
9900 dev->hasPendingPrioritisedGCs = 1; /* Assume the worst for now, will get fixed on first GC */
9902 /* Initialise temporary buffers and caches. */
9903 - if(!yaffs_InitialiseTempBuffers(dev))
9904 + if (!yaffs_InitialiseTempBuffers(dev))
9907 dev->srCache = NULL;
9908 @@ -7203,25 +7283,26 @@ int yaffs_GutsInitialise(yaffs_Device *
9910 dev->nShortOpCaches > 0) {
9914 int srCacheBytes = dev->nShortOpCaches * sizeof(yaffs_ChunkCache);
9916 - if (dev->nShortOpCaches > YAFFS_MAX_SHORT_OP_CACHES) {
9917 + if (dev->nShortOpCaches > YAFFS_MAX_SHORT_OP_CACHES)
9918 dev->nShortOpCaches = YAFFS_MAX_SHORT_OP_CACHES;
9921 - buf = dev->srCache = YMALLOC(srCacheBytes);
9922 + dev->srCache = YMALLOC(srCacheBytes);
9925 - memset(dev->srCache,0,srCacheBytes);
9926 + buf = (__u8 *) dev->srCache;
9929 + memset(dev->srCache, 0, srCacheBytes);
9931 for (i = 0; i < dev->nShortOpCaches && buf; i++) {
9932 dev->srCache[i].object = NULL;
9933 dev->srCache[i].lastUse = 0;
9934 dev->srCache[i].dirty = 0;
9935 - dev->srCache[i].data = buf = YMALLOC_DMA(dev->nDataBytesPerChunk);
9936 + dev->srCache[i].data = buf = YMALLOC_DMA(dev->totalBytesPerChunk);
9943 @@ -7229,29 +7310,30 @@ int yaffs_GutsInitialise(yaffs_Device *
9948 + if (!init_failed) {
9949 dev->gcCleanupList = YMALLOC(dev->nChunksPerBlock * sizeof(__u32));
9950 - if(!dev->gcCleanupList)
9951 + if (!dev->gcCleanupList)
9955 - if (dev->isYaffs2) {
9956 + if (dev->isYaffs2)
9957 dev->useHeaderFileSize = 1;
9959 - if(!init_failed && !yaffs_InitialiseBlocks(dev))
9961 + if (!init_failed && !yaffs_InitialiseBlocks(dev))
9964 yaffs_InitialiseTnodes(dev);
9965 yaffs_InitialiseObjects(dev);
9967 - if(!init_failed && !yaffs_CreateInitialDirectories(dev))
9968 + if (!init_failed && !yaffs_CreateInitialDirectories(dev))
9973 + if (!init_failed) {
9974 /* Now scan the flash. */
9975 if (dev->isYaffs2) {
9976 - if(yaffs_CheckpointRestore(dev)) {
9977 + if (yaffs_CheckpointRestore(dev)) {
9978 + yaffs_CheckObjectDetailsLoaded(dev->rootDir);
9979 T(YAFFS_TRACE_ALWAYS,
9980 (TSTR("yaffs: restored from checkpoint" TENDSTR)));
9982 @@ -7273,24 +7355,25 @@ int yaffs_GutsInitialise(yaffs_Device *
9983 dev->nBackgroundDeletions = 0;
9984 dev->oldestDirtySequence = 0;
9986 - if(!init_failed && !yaffs_InitialiseBlocks(dev))
9987 + if (!init_failed && !yaffs_InitialiseBlocks(dev))
9990 yaffs_InitialiseTnodes(dev);
9991 yaffs_InitialiseObjects(dev);
9993 - if(!init_failed && !yaffs_CreateInitialDirectories(dev))
9994 + if (!init_failed && !yaffs_CreateInitialDirectories(dev))
9997 - if(!init_failed && !yaffs_ScanBackwards(dev))
9998 + if (!init_failed && !yaffs_ScanBackwards(dev))
10002 - if(!yaffs_Scan(dev))
10003 + } else if (!yaffs_Scan(dev))
10006 + yaffs_StripDeletedObjects(dev);
10010 + if (init_failed) {
10011 /* Clean up the mess */
10012 T(YAFFS_TRACE_TRACING,
10013 (TSTR("yaffs: yaffs_GutsInitialise() aborted.\n" TENDSTR)));
10014 @@ -7318,7 +7401,7 @@ int yaffs_GutsInitialise(yaffs_Device *
10018 -void yaffs_Deinitialise(yaffs_Device * dev)
10019 +void yaffs_Deinitialise(yaffs_Device *dev)
10021 if (dev->isMounted) {
10023 @@ -7330,7 +7413,7 @@ void yaffs_Deinitialise(yaffs_Device * d
10026 for (i = 0; i < dev->nShortOpCaches; i++) {
10027 - if(dev->srCache[i].data)
10028 + if (dev->srCache[i].data)
10029 YFREE(dev->srCache[i].data);
10030 dev->srCache[i].data = NULL;
10032 @@ -7341,16 +7424,17 @@ void yaffs_Deinitialise(yaffs_Device * d
10034 YFREE(dev->gcCleanupList);
10036 - for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) {
10037 + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++)
10038 YFREE(dev->tempBuffer[i].buffer);
10041 dev->isMounted = 0;
10044 + if (dev->deinitialiseNAND)
10045 + dev->deinitialiseNAND(dev);
10049 -static int yaffs_CountFreeChunks(yaffs_Device * dev)
10050 +static int yaffs_CountFreeChunks(yaffs_Device *dev)
10054 @@ -7358,7 +7442,7 @@ static int yaffs_CountFreeChunks(yaffs_D
10055 yaffs_BlockInfo *blk;
10057 for (nFree = 0, b = dev->internalStartBlock; b <= dev->internalEndBlock;
10060 blk = yaffs_GetBlockInfo(dev, b);
10062 switch (blk->blockState) {
10063 @@ -7373,19 +7457,19 @@ static int yaffs_CountFreeChunks(yaffs_D
10073 -int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev)
10074 +int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev)
10076 /* This is what we report to the outside world */
10079 int nDirtyCacheChunks;
10080 int blocksForCheckpoint;
10084 nFree = dev->nFreeChunks;
10085 @@ -7397,12 +7481,9 @@ int yaffs_GetNumberOfFreeChunks(yaffs_De
10087 /* Now count the number of dirty chunks in the cache and subtract those */
10091 - for (nDirtyCacheChunks = 0, i = 0; i < dev->nShortOpCaches; i++) {
10092 - if (dev->srCache[i].dirty)
10093 - nDirtyCacheChunks++;
10095 + for (nDirtyCacheChunks = 0, i = 0; i < dev->nShortOpCaches; i++) {
10096 + if (dev->srCache[i].dirty)
10097 + nDirtyCacheChunks++;
10100 nFree -= nDirtyCacheChunks;
10101 @@ -7410,8 +7491,8 @@ int yaffs_GetNumberOfFreeChunks(yaffs_De
10102 nFree -= ((dev->nReservedBlocks + 1) * dev->nChunksPerBlock);
10104 /* Now we figure out how much to reserve for the checkpoint and report that... */
10105 - blocksForCheckpoint = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint;
10106 - if(blocksForCheckpoint < 0)
10107 + blocksForCheckpoint = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint;
10108 + if (blocksForCheckpoint < 0)
10109 blocksForCheckpoint = 0;
10111 nFree -= (blocksForCheckpoint * dev->nChunksPerBlock);
10112 @@ -7425,12 +7506,12 @@ int yaffs_GetNumberOfFreeChunks(yaffs_De
10114 static int yaffs_freeVerificationFailures;
10116 -static void yaffs_VerifyFreeChunks(yaffs_Device * dev)
10117 +static void yaffs_VerifyFreeChunks(yaffs_Device *dev)
10122 - if(yaffs_SkipVerification(dev))
10123 + if (yaffs_SkipVerification(dev))
10126 counted = yaffs_CountFreeChunks(dev);
10127 @@ -7447,23 +7528,25 @@ static void yaffs_VerifyFreeChunks(yaffs
10129 /*---------------------------------------- YAFFS test code ----------------------*/
10131 -#define yaffs_CheckStruct(structure,syze, name) \
10132 - if(sizeof(structure) != syze) \
10134 - T(YAFFS_TRACE_ALWAYS,(TSTR("%s should be %d but is %d\n" TENDSTR),\
10135 - name,syze,sizeof(structure))); \
10136 - return YAFFS_FAIL; \
10138 +#define yaffs_CheckStruct(structure, syze, name) \
10140 + if (sizeof(structure) != syze) { \
10141 + T(YAFFS_TRACE_ALWAYS, (TSTR("%s should be %d but is %d\n" TENDSTR),\
10142 + name, syze, sizeof(structure))); \
10143 + return YAFFS_FAIL; \
10147 static int yaffs_CheckStructures(void)
10149 -/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags") */
10150 -/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion") */
10151 -/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare") */
10152 +/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags"); */
10153 +/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion"); */
10154 +/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare"); */
10155 #ifndef CONFIG_YAFFS_TNODE_LIST_DEBUG
10156 - yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode")
10157 + yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode");
10159 - yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader")
10162 +#ifndef CONFIG_YAFFS_WINCE
10163 + yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader");
10167 --- a/fs/yaffs2/yaffs_guts.h
10168 +++ b/fs/yaffs2/yaffs_guts.h
10171 #define YAFFS_MAX_SHORT_OP_CACHES 20
10173 -#define YAFFS_N_TEMP_BUFFERS 4
10174 +#define YAFFS_N_TEMP_BUFFERS 6
10176 /* We limit the number attempts at sucessfully saving a chunk of data.
10177 * Small-page devices have 32 pages per block; large-page devices have 64.
10178 @@ -108,6 +108,9 @@
10179 #define YAFFS_LOWEST_SEQUENCE_NUMBER 0x00001000
10180 #define YAFFS_HIGHEST_SEQUENCE_NUMBER 0xEFFFFF00
10182 +/* Special sequence number for bad block that failed to be marked bad */
10183 +#define YAFFS_SEQUENCE_BAD_BLOCK 0xFFFF0000
10185 /* ChunkCache is used for short read/write operations.*/
10187 struct yaffs_ObjectStruct *object;
10188 @@ -134,11 +137,10 @@ typedef struct {
10190 unsigned chunkId:20;
10191 unsigned serialNumber:2;
10192 - unsigned byteCount:10;
10193 + unsigned byteCountLSB:10;
10194 unsigned objectId:18;
10196 - unsigned unusedStuff:2;
10198 + unsigned byteCountMSB:2;
10202 @@ -277,13 +279,13 @@ typedef struct {
10204 int softDeletions:10; /* number of soft deleted pages */
10205 int pagesInUse:10; /* number of pages in use */
10206 - yaffs_BlockState blockState:4; /* One of the above block states */
10207 + unsigned blockState:4; /* One of the above block states. NB use unsigned because enum is sometimes an int */
10208 __u32 needsRetiring:1; /* Data has failed on this block, need to get valid data off */
10209 - /* and retire the block. */
10210 - __u32 skipErasedCheck: 1; /* If this is set we can skip the erased check on this block */
10211 - __u32 gcPrioritise: 1; /* An ECC check or blank check has failed on this block.
10212 + /* and retire the block. */
10213 + __u32 skipErasedCheck:1; /* If this is set we can skip the erased check on this block */
10214 + __u32 gcPrioritise:1; /* An ECC check or blank check has failed on this block.
10215 It should be prioritised for GC */
10216 - __u32 chunkErrorStrikes:3; /* How many times we've had ecc etc failures on this block and tried to reuse it */
10217 + __u32 chunkErrorStrikes:3; /* How many times we've had ecc etc failures on this block and tried to reuse it */
10219 #ifdef CONFIG_YAFFS_YAFFS2
10220 __u32 hasShrinkHeader:1; /* This block has at least one shrink object header */
10221 @@ -300,11 +302,11 @@ typedef struct {
10223 /* Apply to everything */
10224 int parentObjectId;
10225 - __u16 sum__NoLongerUsed; /* checksum of name. No longer used */
10226 + __u16 sum__NoLongerUsed; /* checksum of name. No longer used */
10227 YCHAR name[YAFFS_MAX_NAME_LENGTH + 1];
10229 - /* Thes following apply to directories, files, symlinks - not hard links */
10230 - __u32 yst_mode; /* protection */
10231 + /* The following apply to directories, files, symlinks - not hard links */
10232 + __u32 yst_mode; /* protection */
10234 #ifdef CONFIG_YAFFS_WINCE
10235 __u32 notForWinCE[5];
10236 @@ -331,11 +333,14 @@ typedef struct {
10237 __u32 win_ctime[2];
10238 __u32 win_atime[2];
10239 __u32 win_mtime[2];
10240 - __u32 roomToGrow[4];
10242 - __u32 roomToGrow[10];
10243 + __u32 roomToGrow[6];
10246 + __u32 inbandShadowsObject;
10247 + __u32 inbandIsShrink;
10249 + __u32 reservedSpace[2];
10250 int shadowsObject; /* This object header shadows the specified object if > 0 */
10252 /* isShrink applies to object headers written when we shrink the file (ie resize) */
10253 @@ -381,7 +386,7 @@ typedef struct {
10254 } yaffs_FileStructure;
10257 - struct list_head children; /* list of child links */
10258 + struct ylist_head children; /* list of child links */
10259 } yaffs_DirectoryStructure;
10262 @@ -418,23 +423,24 @@ struct yaffs_ObjectStruct {
10263 * still in the inode cache. Free of object is defered.
10264 * until the inode is released.
10266 + __u8 beingCreated:1; /* This object is still being created so skip some checks. */
10268 __u8 serial; /* serial number of chunk in NAND. Cached here */
10269 __u16 sum; /* sum of the name to speed searching */
10271 - struct yaffs_DeviceStruct *myDev; /* The device I'm on */
10272 + struct yaffs_DeviceStruct *myDev; /* The device I'm on */
10274 - struct list_head hashLink; /* list of objects in this hash bucket */
10275 + struct ylist_head hashLink; /* list of objects in this hash bucket */
10277 - struct list_head hardLinks; /* all the equivalent hard linked objects */
10278 + struct ylist_head hardLinks; /* all the equivalent hard linked objects */
10280 /* directory structure stuff */
10281 /* also used for linking up the free list */
10282 struct yaffs_ObjectStruct *parent;
10283 - struct list_head siblings;
10284 + struct ylist_head siblings;
10286 /* Where's my object header in NAND? */
10290 int nDataChunks; /* Number of data chunks attached to the file. */
10292 @@ -485,7 +491,7 @@ struct yaffs_ObjectList_struct {
10293 typedef struct yaffs_ObjectList_struct yaffs_ObjectList;
10296 - struct list_head list;
10297 + struct ylist_head list;
10299 } yaffs_ObjectBucket;
10301 @@ -495,11 +501,10 @@ typedef struct {
10312 yaffs_ObjectType variantType:3;
10314 __u8 softDeleted:1;
10315 @@ -511,8 +516,7 @@ typedef struct {
10318 __u32 fileSizeOrEquivalentObjectId;
10320 -}yaffs_CheckpointObject;
10321 +} yaffs_CheckpointObject;
10323 /*--------------------- Temporary buffers ----------------
10325 @@ -528,13 +532,13 @@ typedef struct {
10326 /*----------------- Device ---------------------------------*/
10328 struct yaffs_DeviceStruct {
10329 - struct list_head devList;
10330 + struct ylist_head devList;
10333 /* Entry parameters set up way early. Yaffs sets up the rest.*/
10334 int nDataBytesPerChunk; /* Should be a power of 2 >= 512 */
10335 int nChunksPerBlock; /* does not need to be a power of 2 */
10336 - int nBytesPerSpare; /* spare area size */
10337 + int spareBytesPerChunk; /* spare area size */
10338 int startBlock; /* Start block we're allowed to use */
10339 int endBlock; /* End block we're allowed to use */
10340 int nReservedBlocks; /* We want this tuneable so that we can reduce */
10341 @@ -544,9 +548,7 @@ struct yaffs_DeviceStruct {
10342 /* Stuff used by the shared space checkpointing mechanism */
10343 /* If this value is zero, then this mechanism is disabled */
10345 - int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */
10348 +/* int nCheckpointReservedBlocks; */ /* Blocks to reserve for checkpoint data */
10351 int nShortOpCaches; /* If <= 0, then short op caching is disabled, else
10352 @@ -560,30 +562,31 @@ struct yaffs_DeviceStruct {
10353 void *genericDevice; /* Pointer to device context
10354 * On an mtd this holds the mtd pointer.
10356 - void *superBlock;
10357 + void *superBlock;
10359 /* NAND access functions (Must be set before calling YAFFS)*/
10361 - int (*writeChunkToNAND) (struct yaffs_DeviceStruct * dev,
10362 - int chunkInNAND, const __u8 * data,
10363 - const yaffs_Spare * spare);
10364 - int (*readChunkFromNAND) (struct yaffs_DeviceStruct * dev,
10365 - int chunkInNAND, __u8 * data,
10366 - yaffs_Spare * spare);
10367 - int (*eraseBlockInNAND) (struct yaffs_DeviceStruct * dev,
10368 - int blockInNAND);
10369 - int (*initialiseNAND) (struct yaffs_DeviceStruct * dev);
10370 + int (*writeChunkToNAND) (struct yaffs_DeviceStruct *dev,
10371 + int chunkInNAND, const __u8 *data,
10372 + const yaffs_Spare *spare);
10373 + int (*readChunkFromNAND) (struct yaffs_DeviceStruct *dev,
10374 + int chunkInNAND, __u8 *data,
10375 + yaffs_Spare *spare);
10376 + int (*eraseBlockInNAND) (struct yaffs_DeviceStruct *dev,
10377 + int blockInNAND);
10378 + int (*initialiseNAND) (struct yaffs_DeviceStruct *dev);
10379 + int (*deinitialiseNAND) (struct yaffs_DeviceStruct *dev);
10381 #ifdef CONFIG_YAFFS_YAFFS2
10382 - int (*writeChunkWithTagsToNAND) (struct yaffs_DeviceStruct * dev,
10383 - int chunkInNAND, const __u8 * data,
10384 - const yaffs_ExtendedTags * tags);
10385 - int (*readChunkWithTagsFromNAND) (struct yaffs_DeviceStruct * dev,
10386 - int chunkInNAND, __u8 * data,
10387 - yaffs_ExtendedTags * tags);
10388 - int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo);
10389 - int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo,
10390 - yaffs_BlockState * state, int *sequenceNumber);
10391 + int (*writeChunkWithTagsToNAND) (struct yaffs_DeviceStruct *dev,
10392 + int chunkInNAND, const __u8 *data,
10393 + const yaffs_ExtendedTags *tags);
10394 + int (*readChunkWithTagsFromNAND) (struct yaffs_DeviceStruct *dev,
10395 + int chunkInNAND, __u8 *data,
10396 + yaffs_ExtendedTags *tags);
10397 + int (*markNANDBlockBad) (struct yaffs_DeviceStruct *dev, int blockNo);
10398 + int (*queryNANDBlock) (struct yaffs_DeviceStruct *dev, int blockNo,
10399 + yaffs_BlockState *state, __u32 *sequenceNumber);
10403 @@ -595,10 +598,12 @@ struct yaffs_DeviceStruct {
10404 void (*removeObjectCallback)(struct yaffs_ObjectStruct *obj);
10406 /* Callback to mark the superblock dirsty */
10407 - void (*markSuperBlockDirty)(void * superblock);
10408 + void (*markSuperBlockDirty)(void *superblock);
10410 int wideTnodesDisabled; /* Set to disable wide tnodes */
10412 + YCHAR *pathDividers; /* String of legal path dividers */
10415 /* End of stuff that must be set before initialisation. */
10417 @@ -615,16 +620,14 @@ struct yaffs_DeviceStruct {
10421 - /* Stuff to support various file offses to chunk/offset translations */
10422 - /* "Crumbs" for nDataBytesPerChunk not being a power of 2 */
10424 - __u32 crumbShift;
10425 - __u32 crumbsPerChunk;
10427 - /* Straight shifting for nDataBytesPerChunk being a power of 2 */
10428 - __u32 chunkShift;
10431 + /* Stuff for figuring out file offset to chunk conversions */
10432 + __u32 chunkShift; /* Shift value */
10433 + __u32 chunkDiv; /* Divisor after shifting: 1 for power-of-2 sizes */
10434 + __u32 chunkMask; /* Mask to use for power-of-2 case */
10436 + /* Stuff to handle inband tags */
10438 + __u32 totalBytesPerChunk;
10442 @@ -633,7 +636,7 @@ struct yaffs_DeviceStruct {
10443 __u8 *spareBuffer; /* For mtdif2 use. Don't know the size of the buffer
10444 * at compile time so we have to allocate it.
10446 - void (*putSuperFunc) (struct super_block * sb);
10447 + void (*putSuperFunc) (struct super_block *sb);
10451 @@ -663,6 +666,8 @@ struct yaffs_DeviceStruct {
10452 __u32 checkpointSum;
10453 __u32 checkpointXor;
10455 + int nCheckpointBlocksRequired; /* Number of blocks needed to store current checkpoint set */
10458 yaffs_BlockInfo *blockInfo;
10459 __u8 *chunkBits; /* bitmap of chunks in use */
10460 @@ -684,11 +689,15 @@ struct yaffs_DeviceStruct {
10461 yaffs_TnodeList *allocatedTnodeList;
10467 int nObjectsCreated;
10468 yaffs_Object *freeObjects;
10473 yaffs_ObjectList *allocatedObjectList;
10475 yaffs_ObjectBucket objectBucket[YAFFS_NOBJECT_BUCKETS];
10476 @@ -745,8 +754,10 @@ struct yaffs_DeviceStruct {
10477 int nBackgroundDeletions; /* Count of background deletions. */
10480 + /* Temporary buffer management */
10481 yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS];
10484 int unmanagedTempAllocations;
10485 int unmanagedTempDeallocations;
10487 @@ -758,9 +769,9 @@ struct yaffs_DeviceStruct {
10489 typedef struct yaffs_DeviceStruct yaffs_Device;
10491 -/* The static layout of bllock usage etc is stored in the super block header */
10492 +/* The static layout of block usage etc is stored in the super block header */
10497 int checkpointStartBlock;
10498 int checkpointEndBlock;
10499 @@ -773,7 +784,7 @@ typedef struct {
10500 * must be preserved over unmount/mount cycles.
10506 int allocationBlock; /* Current block being allocated off */
10507 __u32 allocationPage;
10508 @@ -791,57 +802,45 @@ typedef struct {
10520 } yaffs_CheckpointValidity;
10522 -/* Function to manipulate block info */
10523 -static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk)
10525 - if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) {
10526 - T(YAFFS_TRACE_ERROR,
10528 - ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR),
10532 - return &dev->blockInfo[blk - dev->internalStartBlock];
10535 /*----------------------- YAFFS Functions -----------------------*/
10537 -int yaffs_GutsInitialise(yaffs_Device * dev);
10538 -void yaffs_Deinitialise(yaffs_Device * dev);
10539 +int yaffs_GutsInitialise(yaffs_Device *dev);
10540 +void yaffs_Deinitialise(yaffs_Device *dev);
10542 -int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev);
10543 +int yaffs_GetNumberOfFreeChunks(yaffs_Device *dev);
10545 -int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName,
10546 - yaffs_Object * newDir, const YCHAR * newName);
10547 +int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName,
10548 + yaffs_Object *newDir, const YCHAR *newName);
10550 -int yaffs_Unlink(yaffs_Object * dir, const YCHAR * name);
10551 -int yaffs_DeleteFile(yaffs_Object * obj);
10552 +int yaffs_Unlink(yaffs_Object *dir, const YCHAR *name);
10553 +int yaffs_DeleteObject(yaffs_Object *obj);
10555 -int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize);
10556 -int yaffs_GetObjectFileLength(yaffs_Object * obj);
10557 -int yaffs_GetObjectInode(yaffs_Object * obj);
10558 -unsigned yaffs_GetObjectType(yaffs_Object * obj);
10559 -int yaffs_GetObjectLinkCount(yaffs_Object * obj);
10560 +int yaffs_GetObjectName(yaffs_Object *obj, YCHAR *name, int buffSize);
10561 +int yaffs_GetObjectFileLength(yaffs_Object *obj);
10562 +int yaffs_GetObjectInode(yaffs_Object *obj);
10563 +unsigned yaffs_GetObjectType(yaffs_Object *obj);
10564 +int yaffs_GetObjectLinkCount(yaffs_Object *obj);
10566 -int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr);
10567 -int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr);
10568 +int yaffs_SetAttributes(yaffs_Object *obj, struct iattr *attr);
10569 +int yaffs_GetAttributes(yaffs_Object *obj, struct iattr *attr);
10571 /* File operations */
10572 -int yaffs_ReadDataFromFile(yaffs_Object * obj, __u8 * buffer, loff_t offset,
10574 -int yaffs_WriteDataToFile(yaffs_Object * obj, const __u8 * buffer, loff_t offset,
10575 - int nBytes, int writeThrough);
10576 -int yaffs_ResizeFile(yaffs_Object * obj, loff_t newSize);
10578 -yaffs_Object *yaffs_MknodFile(yaffs_Object * parent, const YCHAR * name,
10579 - __u32 mode, __u32 uid, __u32 gid);
10580 -int yaffs_FlushFile(yaffs_Object * obj, int updateTime);
10581 +int yaffs_ReadDataFromFile(yaffs_Object *obj, __u8 *buffer, loff_t offset,
10583 +int yaffs_WriteDataToFile(yaffs_Object *obj, const __u8 *buffer, loff_t offset,
10584 + int nBytes, int writeThrough);
10585 +int yaffs_ResizeFile(yaffs_Object *obj, loff_t newSize);
10587 +yaffs_Object *yaffs_MknodFile(yaffs_Object *parent, const YCHAR *name,
10588 + __u32 mode, __u32 uid, __u32 gid);
10589 +int yaffs_FlushFile(yaffs_Object *obj, int updateTime);
10591 /* Flushing and checkpointing */
10592 void yaffs_FlushEntireDeviceCache(yaffs_Device *dev);
10593 @@ -850,33 +849,33 @@ int yaffs_CheckpointSave(yaffs_Device *d
10594 int yaffs_CheckpointRestore(yaffs_Device *dev);
10596 /* Directory operations */
10597 -yaffs_Object *yaffs_MknodDirectory(yaffs_Object * parent, const YCHAR * name,
10598 - __u32 mode, __u32 uid, __u32 gid);
10599 -yaffs_Object *yaffs_FindObjectByName(yaffs_Object * theDir, const YCHAR * name);
10600 -int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir,
10601 +yaffs_Object *yaffs_MknodDirectory(yaffs_Object *parent, const YCHAR *name,
10602 + __u32 mode, __u32 uid, __u32 gid);
10603 +yaffs_Object *yaffs_FindObjectByName(yaffs_Object *theDir, const YCHAR *name);
10604 +int yaffs_ApplyToDirectoryChildren(yaffs_Object *theDir,
10605 int (*fn) (yaffs_Object *));
10607 -yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number);
10608 +yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device *dev, __u32 number);
10610 /* Link operations */
10611 -yaffs_Object *yaffs_Link(yaffs_Object * parent, const YCHAR * name,
10612 - yaffs_Object * equivalentObject);
10613 +yaffs_Object *yaffs_Link(yaffs_Object *parent, const YCHAR *name,
10614 + yaffs_Object *equivalentObject);
10616 -yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object * obj);
10617 +yaffs_Object *yaffs_GetEquivalentObject(yaffs_Object *obj);
10619 /* Symlink operations */
10620 -yaffs_Object *yaffs_MknodSymLink(yaffs_Object * parent, const YCHAR * name,
10621 +yaffs_Object *yaffs_MknodSymLink(yaffs_Object *parent, const YCHAR *name,
10622 __u32 mode, __u32 uid, __u32 gid,
10623 - const YCHAR * alias);
10624 -YCHAR *yaffs_GetSymlinkAlias(yaffs_Object * obj);
10625 + const YCHAR *alias);
10626 +YCHAR *yaffs_GetSymlinkAlias(yaffs_Object *obj);
10628 /* Special inodes (fifos, sockets and devices) */
10629 -yaffs_Object *yaffs_MknodSpecial(yaffs_Object * parent, const YCHAR * name,
10630 +yaffs_Object *yaffs_MknodSpecial(yaffs_Object *parent, const YCHAR *name,
10631 __u32 mode, __u32 uid, __u32 gid, __u32 rdev);
10633 /* Special directories */
10634 -yaffs_Object *yaffs_Root(yaffs_Device * dev);
10635 -yaffs_Object *yaffs_LostNFound(yaffs_Device * dev);
10636 +yaffs_Object *yaffs_Root(yaffs_Device *dev);
10637 +yaffs_Object *yaffs_LostNFound(yaffs_Device *dev);
10639 #ifdef CONFIG_YAFFS_WINCE
10640 /* CONFIG_YAFFS_WINCE special stuff */
10641 @@ -885,18 +884,21 @@ void yfsd_WinFileTimeNow(__u32 target[2]
10645 -void yaffs_HandleDeferedFree(yaffs_Object * obj);
10646 +void yaffs_HandleDeferedFree(yaffs_Object *obj);
10650 -int yaffs_DumpObject(yaffs_Object * obj);
10651 +int yaffs_DumpObject(yaffs_Object *obj);
10653 -void yaffs_GutsTest(yaffs_Device * dev);
10654 +void yaffs_GutsTest(yaffs_Device *dev);
10656 /* A few useful functions */
10657 -void yaffs_InitialiseTags(yaffs_ExtendedTags * tags);
10658 -void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn);
10659 -int yaffs_CheckFF(__u8 * buffer, int nBytes);
10660 +void yaffs_InitialiseTags(yaffs_ExtendedTags *tags);
10661 +void yaffs_DeleteChunk(yaffs_Device *dev, int chunkId, int markNAND, int lyn);
10662 +int yaffs_CheckFF(__u8 *buffer, int nBytes);
10663 void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi);
10665 +__u8 *yaffs_GetTempBuffer(yaffs_Device *dev, int lineNo);
10666 +void yaffs_ReleaseTempBuffer(yaffs_Device *dev, __u8 *buffer, int lineNo);
10669 --- a/fs/yaffs2/yaffs_mtdif1.c
10670 +++ b/fs/yaffs2/yaffs_mtdif1.c
10672 #include "yportenv.h"
10673 #include "yaffs_guts.h"
10674 #include "yaffs_packedtags1.h"
10675 -#include "yaffs_tagscompat.h" // for yaffs_CalcTagsECC
10676 +#include "yaffs_tagscompat.h" /* for yaffs_CalcTagsECC */
10678 #include "linux/kernel.h"
10679 #include "linux/version.h"
10681 #include "linux/mtd/mtd.h"
10683 /* Don't compile this module if we don't have MTD's mtd_oob_ops interface */
10684 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
10685 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
10687 -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $";
10688 +const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.10 2009-03-09 07:41:10 charles Exp $";
10690 #ifndef CONFIG_YAFFS_9BYTE_TAGS
10691 # define YTAG1_SIZE 8
10692 @@ -89,9 +89,9 @@ static struct nand_ecclayout nand_oob_16
10693 * Returns YAFFS_OK or YAFFS_FAIL.
10695 int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
10696 - int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags)
10697 + int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *etags)
10699 - struct mtd_info * mtd = dev->genericDevice;
10700 + struct mtd_info *mtd = dev->genericDevice;
10701 int chunkBytes = dev->nDataBytesPerChunk;
10702 loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
10703 struct mtd_oob_ops ops;
10704 @@ -146,7 +146,7 @@ int nandmtd1_WriteChunkWithTagsToNAND(ya
10706 /* Return with empty ExtendedTags but add eccResult.
10708 -static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval)
10709 +static int rettags(yaffs_ExtendedTags *etags, int eccResult, int retval)
10712 memset(etags, 0, sizeof(*etags));
10713 @@ -169,9 +169,9 @@ static int rettags(yaffs_ExtendedTags *
10714 * Returns YAFFS_OK or YAFFS_FAIL.
10716 int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
10717 - int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags)
10718 + int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags)
10720 - struct mtd_info * mtd = dev->genericDevice;
10721 + struct mtd_info *mtd = dev->genericDevice;
10722 int chunkBytes = dev->nDataBytesPerChunk;
10723 loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
10724 int eccres = YAFFS_ECC_RESULT_NO_ERROR;
10725 @@ -189,7 +189,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(y
10727 ops.oobbuf = (__u8 *)&pt1;
10729 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20))
10730 +#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 20))
10731 /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug;
10732 * help it out with ops.len = ops.ooblen when ops.datbuf == NULL.
10734 @@ -284,11 +284,11 @@ int nandmtd1_ReadChunkWithTagsFromNAND(y
10736 int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
10738 - struct mtd_info * mtd = dev->genericDevice;
10739 + struct mtd_info *mtd = dev->genericDevice;
10740 int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk;
10743 - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo);
10744 + yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo);
10746 retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo);
10747 return (retval) ? YAFFS_FAIL : YAFFS_OK;
10748 @@ -298,7 +298,7 @@ int nandmtd1_MarkNANDBlockBad(struct yaf
10750 * Returns YAFFS_OK or YAFFS_FAIL.
10752 -static int nandmtd1_TestPrerequists(struct mtd_info * mtd)
10753 +static int nandmtd1_TestPrerequists(struct mtd_info *mtd)
10755 /* 2.6.18 has mtd->ecclayout->oobavail */
10756 /* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */
10757 @@ -323,10 +323,11 @@ static int nandmtd1_TestPrerequists(stru
10758 * Always returns YAFFS_OK.
10760 int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
10761 - yaffs_BlockState * pState, int *pSequenceNumber)
10762 + yaffs_BlockState *pState, __u32 *pSequenceNumber)
10764 - struct mtd_info * mtd = dev->genericDevice;
10765 + struct mtd_info *mtd = dev->genericDevice;
10766 int chunkNo = blockNo * dev->nChunksPerBlock;
10767 + loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk;
10768 yaffs_ExtendedTags etags;
10769 int state = YAFFS_BLOCK_STATE_DEAD;
10771 @@ -335,21 +336,22 @@ int nandmtd1_QueryNANDBlock(struct yaffs
10772 /* We don't yet have a good place to test for MTD config prerequists.
10773 * Do it here as we are called during the initial scan.
10775 - if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) {
10776 + if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK)
10780 retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags);
10781 + etags.blockBad = (mtd->block_isbad)(mtd, addr);
10782 if (etags.blockBad) {
10783 yaffs_trace(YAFFS_TRACE_BAD_BLOCKS,
10784 - "block %d is marked bad", blockNo);
10785 + "block %d is marked bad\n", blockNo);
10786 state = YAFFS_BLOCK_STATE_DEAD;
10788 - else if (etags.chunkUsed) {
10789 + } else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) {
10790 + /* bad tags, need to look more closely */
10791 + state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
10792 + } else if (etags.chunkUsed) {
10793 state = YAFFS_BLOCK_STATE_NEEDS_SCANNING;
10794 seqnum = etags.sequenceNumber;
10798 state = YAFFS_BLOCK_STATE_EMPTY;
10801 @@ -360,4 +362,4 @@ int nandmtd1_QueryNANDBlock(struct yaffs
10805 -#endif /*KERNEL_VERSION*/
10806 +#endif /*MTD_VERSION*/
10807 --- a/fs/yaffs2/yaffs_mtdif1.h
10808 +++ b/fs/yaffs2/yaffs_mtdif1.h
10809 @@ -14,15 +14,15 @@
10810 #ifndef __YAFFS_MTDIF1_H__
10811 #define __YAFFS_MTDIF1_H__
10813 -int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
10814 - const __u8 * data, const yaffs_ExtendedTags * tags);
10815 +int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND,
10816 + const __u8 *data, const yaffs_ExtendedTags *tags);
10818 -int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
10819 - __u8 * data, yaffs_ExtendedTags * tags);
10820 +int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND,
10821 + __u8 *data, yaffs_ExtendedTags *tags);
10823 int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo);
10825 int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
10826 - yaffs_BlockState * state, int *sequenceNumber);
10827 + yaffs_BlockState *state, __u32 *sequenceNumber);
10830 --- a/fs/yaffs2/yaffs_mtdif2.c
10831 +++ b/fs/yaffs2/yaffs_mtdif2.c
10833 /* mtd interface for YAFFS2 */
10835 const char *yaffs_mtdif2_c_version =
10836 - "$Id: yaffs_mtdif2.c,v 1.17 2007-02-14 01:09:06 wookey Exp $";
10837 + "$Id: yaffs_mtdif2.c,v 1.23 2009-03-06 17:20:53 wookey Exp $";
10839 #include "yportenv.h"
10841 @@ -27,19 +27,23 @@ const char *yaffs_mtdif2_c_version =
10843 #include "yaffs_packedtags2.h"
10845 -int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
10846 - const __u8 * data,
10847 - const yaffs_ExtendedTags * tags)
10848 +/* NB For use with inband tags....
10849 + * We assume that the data buffer is of size totalBytersPerChunk so that we can also
10850 + * use it to load the tags.
10852 +int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND,
10853 + const __u8 *data,
10854 + const yaffs_ExtendedTags *tags)
10856 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
10857 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
10858 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
10859 struct mtd_oob_ops ops;
10865 - loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk;
10868 yaffs_PackedTags2 pt;
10870 @@ -48,46 +52,40 @@ int nandmtd2_WriteChunkWithTagsToNAND(ya
10871 ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p"
10872 TENDSTR), chunkInNAND, data, tags));
10874 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
10876 - yaffs_PackTags2(&pt, tags);
10878 - BUG(); /* both tags and data should always be present */
10881 - ops.mode = MTD_OOB_AUTO;
10882 - ops.ooblen = sizeof(pt);
10883 - ops.len = dev->nDataBytesPerChunk;
10885 - ops.datbuf = (__u8 *)data;
10886 - ops.oobbuf = (void *)&pt;
10887 - retval = mtd->write_oob(mtd, addr, &ops);
10888 + addr = ((loff_t) chunkInNAND) * dev->totalBytesPerChunk;
10890 + /* For yaffs2 writing there must be both data and tags.
10891 + * If we're using inband tags, then the tags are stuffed into
10892 + * the end of the data buffer.
10894 + if (!data || !tags)
10896 + else if (dev->inbandTags) {
10897 + yaffs_PackedTags2TagsPart *pt2tp;
10898 + pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->nDataBytesPerChunk);
10899 + yaffs_PackTags2TagsPart(pt2tp, tags);
10901 - BUG(); /* both tags and data should always be present */
10904 yaffs_PackTags2(&pt, tags);
10907 - if (data && tags) {
10908 - if (dev->useNANDECC)
10910 - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk,
10911 - &dummy, data, (__u8 *) & pt, NULL);
10914 - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk,
10915 - &dummy, data, (__u8 *) & pt, NULL);
10919 - mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy,
10923 - mtd->write_oob(mtd, addr, mtd->oobsize, &dummy,
10925 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
10926 + ops.mode = MTD_OOB_AUTO;
10927 + ops.ooblen = (dev->inbandTags) ? 0 : sizeof(pt);
10928 + ops.len = dev->totalBytesPerChunk;
10930 + ops.datbuf = (__u8 *)data;
10931 + ops.oobbuf = (dev->inbandTags) ? NULL : (void *)&pt;
10932 + retval = mtd->write_oob(mtd, addr, &ops);
10935 + if (!dev->inbandTags) {
10937 + mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk,
10938 + &dummy, data, (__u8 *) &pt, NULL);
10941 + mtd->write(mtd, addr, dev->totalBytesPerChunk, &dummy,
10946 @@ -97,17 +95,18 @@ int nandmtd2_WriteChunkWithTagsToNAND(ya
10950 -int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
10951 - __u8 * data, yaffs_ExtendedTags * tags)
10952 +int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND,
10953 + __u8 *data, yaffs_ExtendedTags *tags)
10955 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
10956 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
10957 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
10958 struct mtd_oob_ops ops;
10962 + int localData = 0;
10964 - loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk;
10965 + loff_t addr = ((loff_t) chunkInNAND) * dev->totalBytesPerChunk;
10967 yaffs_PackedTags2 pt;
10969 @@ -116,9 +115,20 @@ int nandmtd2_ReadChunkWithTagsFromNAND(y
10970 ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p"
10971 TENDSTR), chunkInNAND, data, tags));
10973 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
10974 - if (data && !tags)
10975 - retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk,
10976 + if (dev->inbandTags) {
10980 + data = yaffs_GetTempBuffer(dev, __LINE__);
10987 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 17))
10988 + if (dev->inbandTags || (data && !tags))
10989 + retval = mtd->read(mtd, addr, dev->totalBytesPerChunk,
10992 ops.mode = MTD_OOB_AUTO;
10993 @@ -130,38 +140,42 @@ int nandmtd2_ReadChunkWithTagsFromNAND(y
10994 retval = mtd->read_oob(mtd, addr, &ops);
10997 - if (data && tags) {
10998 - if (dev->useNANDECC) {
11000 - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk,
11001 - &dummy, data, dev->spareBuffer,
11005 - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk,
11006 + if (!dev->inbandTags && data && tags) {
11008 + retval = mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk,
11009 &dummy, data, dev->spareBuffer,
11015 mtd->read(mtd, addr, dev->nDataBytesPerChunk, &dummy,
11018 + if (!dev->inbandTags && tags)
11020 mtd->read_oob(mtd, addr, mtd->oobsize, &dummy,
11025 - memcpy(&pt, dev->spareBuffer, sizeof(pt));
11028 - yaffs_UnpackTags2(tags, &pt);
11029 + if (dev->inbandTags) {
11031 + yaffs_PackedTags2TagsPart *pt2tp;
11032 + pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk];
11033 + yaffs_UnpackTags2TagsPart(tags, pt2tp);
11037 + memcpy(&pt, dev->spareBuffer, sizeof(pt));
11038 + yaffs_UnpackTags2(tags, &pt);
11043 + yaffs_ReleaseTempBuffer(dev, data, __LINE__);
11045 - if(tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR)
11046 + if (tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR)
11047 tags->eccResult = YAFFS_ECC_RESULT_UNFIXED;
11052 @@ -178,7 +192,7 @@ int nandmtd2_MarkNANDBlockBad(struct yaf
11054 mtd->block_markbad(mtd,
11055 blockNo * dev->nChunksPerBlock *
11056 - dev->nDataBytesPerChunk);
11057 + dev->totalBytesPerChunk);
11061 @@ -188,7 +202,7 @@ int nandmtd2_MarkNANDBlockBad(struct yaf
11064 int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
11065 - yaffs_BlockState * state, int *sequenceNumber)
11066 + yaffs_BlockState *state, __u32 *sequenceNumber)
11068 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
11070 @@ -198,7 +212,7 @@ int nandmtd2_QueryNANDBlock(struct yaffs
11072 mtd->block_isbad(mtd,
11073 blockNo * dev->nChunksPerBlock *
11074 - dev->nDataBytesPerChunk);
11075 + dev->totalBytesPerChunk);
11078 T(YAFFS_TRACE_MTD, (TSTR("block is bad" TENDSTR)));
11079 --- a/fs/yaffs2/yaffs_mtdif2.h
11080 +++ b/fs/yaffs2/yaffs_mtdif2.h
11081 @@ -17,13 +17,13 @@
11082 #define __YAFFS_MTDIF2_H__
11084 #include "yaffs_guts.h"
11085 -int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND,
11086 - const __u8 * data,
11087 - const yaffs_ExtendedTags * tags);
11088 -int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
11089 - __u8 * data, yaffs_ExtendedTags * tags);
11090 +int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device *dev, int chunkInNAND,
11091 + const __u8 *data,
11092 + const yaffs_ExtendedTags *tags);
11093 +int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND,
11094 + __u8 *data, yaffs_ExtendedTags *tags);
11095 int nandmtd2_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo);
11096 int nandmtd2_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
11097 - yaffs_BlockState * state, int *sequenceNumber);
11098 + yaffs_BlockState *state, __u32 *sequenceNumber);
11101 --- a/fs/yaffs2/yaffs_mtdif.c
11102 +++ b/fs/yaffs2/yaffs_mtdif.c
11106 const char *yaffs_mtdif_c_version =
11107 - "$Id: yaffs_mtdif.c,v 1.19 2007-02-14 01:09:06 wookey Exp $";
11108 + "$Id: yaffs_mtdif.c,v 1.22 2009-03-06 17:20:51 wookey Exp $";
11110 #include "yportenv.h"
11112 @@ -24,7 +24,7 @@ const char *yaffs_mtdif_c_version =
11113 #include "linux/time.h"
11114 #include "linux/mtd/nand.h"
11116 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18))
11117 +#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 18))
11118 static struct nand_oobinfo yaffs_oobinfo = {
11121 @@ -36,7 +36,7 @@ static struct nand_oobinfo yaffs_noeccin
11125 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
11126 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
11127 static inline void translate_spare2oob(const yaffs_Spare *spare, __u8 *oob)
11129 oob[0] = spare->tagByte0;
11130 @@ -45,8 +45,8 @@ static inline void translate_spare2oob(c
11131 oob[3] = spare->tagByte3;
11132 oob[4] = spare->tagByte4;
11133 oob[5] = spare->tagByte5 & 0x3f;
11134 - oob[5] |= spare->blockStatus == 'Y' ? 0: 0x80;
11135 - oob[5] |= spare->pageStatus == 0 ? 0: 0x40;
11136 + oob[5] |= spare->blockStatus == 'Y' ? 0 : 0x80;
11137 + oob[5] |= spare->pageStatus == 0 ? 0 : 0x40;
11138 oob[6] = spare->tagByte6;
11139 oob[7] = spare->tagByte7;
11141 @@ -71,18 +71,18 @@ static inline void translate_oob2spare(y
11145 -int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND,
11146 - const __u8 * data, const yaffs_Spare * spare)
11147 +int nandmtd_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND,
11148 + const __u8 *data, const yaffs_Spare *spare)
11150 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
11151 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
11152 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
11153 struct mtd_oob_ops ops;
11158 loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk;
11159 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
11160 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
11161 __u8 spareAsBytes[8]; /* OOB */
11163 if (data && !spare)
11164 @@ -135,18 +135,18 @@ int nandmtd_WriteChunkToNAND(yaffs_Devic
11168 -int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data,
11169 - yaffs_Spare * spare)
11170 +int nandmtd_ReadChunkFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data,
11171 + yaffs_Spare *spare)
11173 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
11174 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
11175 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
11176 struct mtd_oob_ops ops;
11181 loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk;
11182 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17))
11183 +#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
11184 __u8 spareAsBytes[8]; /* OOB */
11186 if (data && !spare)
11187 @@ -205,7 +205,7 @@ int nandmtd_ReadChunkFromNAND(yaffs_Devi
11191 -int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber)
11192 +int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
11194 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
11196 @@ -234,7 +234,7 @@ int nandmtd_EraseBlockInNAND(yaffs_Devic
11200 -int nandmtd_InitialiseNAND(yaffs_Device * dev)
11201 +int nandmtd_InitialiseNAND(yaffs_Device *dev)
11205 --- a/fs/yaffs2/yaffs_mtdif.h
11206 +++ b/fs/yaffs2/yaffs_mtdif.h
11207 @@ -18,10 +18,15 @@
11209 #include "yaffs_guts.h"
11211 -int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND,
11212 - const __u8 * data, const yaffs_Spare * spare);
11213 -int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data,
11214 - yaffs_Spare * spare);
11215 -int nandmtd_EraseBlockInNAND(yaffs_Device * dev, int blockNumber);
11216 -int nandmtd_InitialiseNAND(yaffs_Device * dev);
11217 +#if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 18))
11218 +extern struct nand_oobinfo yaffs_oobinfo;
11219 +extern struct nand_oobinfo yaffs_noeccinfo;
11222 +int nandmtd_WriteChunkToNAND(yaffs_Device *dev, int chunkInNAND,
11223 + const __u8 *data, const yaffs_Spare *spare);
11224 +int nandmtd_ReadChunkFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data,
11225 + yaffs_Spare *spare);
11226 +int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber);
11227 +int nandmtd_InitialiseNAND(yaffs_Device *dev);
11229 --- a/fs/yaffs2/yaffs_nand.c
11230 +++ b/fs/yaffs2/yaffs_nand.c
11231 @@ -12,16 +12,17 @@
11234 const char *yaffs_nand_c_version =
11235 - "$Id: yaffs_nand.c,v 1.7 2007-02-14 01:09:06 wookey Exp $";
11236 + "$Id: yaffs_nand.c,v 1.10 2009-03-06 17:20:54 wookey Exp $";
11238 #include "yaffs_nand.h"
11239 #include "yaffs_tagscompat.h"
11240 #include "yaffs_tagsvalidity.h"
11242 +#include "yaffs_getblockinfo.h"
11244 -int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
11246 - yaffs_ExtendedTags * tags)
11247 +int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND,
11249 + yaffs_ExtendedTags *tags)
11252 yaffs_ExtendedTags localTags;
11253 @@ -29,7 +30,7 @@ int yaffs_ReadChunkWithTagsFromNAND(yaff
11254 int realignedChunkInNAND = chunkInNAND - dev->chunkOffset;
11256 /* If there are no tags provided, use local tags to get prioritised gc working */
11261 if (dev->readChunkWithTagsFromNAND)
11262 @@ -40,20 +41,20 @@ int yaffs_ReadChunkWithTagsFromNAND(yaff
11263 realignedChunkInNAND,
11267 - tags->eccResult > YAFFS_ECC_RESULT_NO_ERROR){
11269 + tags->eccResult > YAFFS_ECC_RESULT_NO_ERROR) {
11271 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, chunkInNAND/dev->nChunksPerBlock);
11272 - yaffs_HandleChunkError(dev,bi);
11273 + yaffs_HandleChunkError(dev, bi);
11279 -int yaffs_WriteChunkWithTagsToNAND(yaffs_Device * dev,
11280 +int yaffs_WriteChunkWithTagsToNAND(yaffs_Device *dev,
11282 - const __u8 * buffer,
11283 - yaffs_ExtendedTags * tags)
11284 + const __u8 *buffer,
11285 + yaffs_ExtendedTags *tags)
11287 chunkInNAND -= dev->chunkOffset;
11289 @@ -84,7 +85,7 @@ int yaffs_WriteChunkWithTagsToNAND(yaffs
11293 -int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo)
11294 +int yaffs_MarkBlockBad(yaffs_Device *dev, int blockNo)
11296 blockNo -= dev->blockOffset;
11298 @@ -95,10 +96,10 @@ int yaffs_MarkBlockBad(yaffs_Device * de
11299 return yaffs_TagsCompatabilityMarkNANDBlockBad(dev, blockNo);
11302 -int yaffs_QueryInitialBlockState(yaffs_Device * dev,
11303 +int yaffs_QueryInitialBlockState(yaffs_Device *dev,
11305 - yaffs_BlockState * state,
11306 - unsigned *sequenceNumber)
11307 + yaffs_BlockState *state,
11308 + __u32 *sequenceNumber)
11310 blockNo -= dev->blockOffset;
11312 --- a/fs/yaffs2/yaffs_nandemul2k.h
11313 +++ b/fs/yaffs2/yaffs_nandemul2k.h
11314 @@ -21,14 +21,14 @@
11315 #include "yaffs_guts.h"
11317 int nandemul2k_WriteChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev,
11318 - int chunkInNAND, const __u8 * data,
11319 - yaffs_ExtendedTags * tags);
11320 + int chunkInNAND, const __u8 *data,
11321 + const yaffs_ExtendedTags *tags);
11322 int nandemul2k_ReadChunkWithTagsFromNAND(struct yaffs_DeviceStruct *dev,
11323 - int chunkInNAND, __u8 * data,
11324 - yaffs_ExtendedTags * tags);
11325 + int chunkInNAND, __u8 *data,
11326 + yaffs_ExtendedTags *tags);
11327 int nandemul2k_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo);
11328 int nandemul2k_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
11329 - yaffs_BlockState * state, int *sequenceNumber);
11330 + yaffs_BlockState *state, __u32 *sequenceNumber);
11331 int nandemul2k_EraseBlockInNAND(struct yaffs_DeviceStruct *dev,
11333 int nandemul2k_InitialiseNAND(struct yaffs_DeviceStruct *dev);
11334 --- a/fs/yaffs2/yaffs_nand.h
11335 +++ b/fs/yaffs2/yaffs_nand.h
11336 @@ -19,21 +19,21 @@
11340 -int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND,
11342 - yaffs_ExtendedTags * tags);
11344 -int yaffs_WriteChunkWithTagsToNAND(yaffs_Device * dev,
11346 - const __u8 * buffer,
11347 - yaffs_ExtendedTags * tags);
11349 -int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo);
11351 -int yaffs_QueryInitialBlockState(yaffs_Device * dev,
11353 - yaffs_BlockState * state,
11354 - unsigned *sequenceNumber);
11355 +int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND,
11357 + yaffs_ExtendedTags *tags);
11359 +int yaffs_WriteChunkWithTagsToNAND(yaffs_Device *dev,
11361 + const __u8 *buffer,
11362 + yaffs_ExtendedTags *tags);
11364 +int yaffs_MarkBlockBad(yaffs_Device *dev, int blockNo);
11366 +int yaffs_QueryInitialBlockState(yaffs_Device *dev,
11368 + yaffs_BlockState *state,
11369 + unsigned *sequenceNumber);
11371 int yaffs_EraseBlockInNAND(struct yaffs_DeviceStruct *dev,
11373 --- a/fs/yaffs2/yaffs_packedtags1.c
11374 +++ b/fs/yaffs2/yaffs_packedtags1.c
11376 #include "yaffs_packedtags1.h"
11377 #include "yportenv.h"
11379 -void yaffs_PackTags1(yaffs_PackedTags1 * pt, const yaffs_ExtendedTags * t)
11380 +void yaffs_PackTags1(yaffs_PackedTags1 *pt, const yaffs_ExtendedTags *t)
11382 pt->chunkId = t->chunkId;
11383 pt->serialNumber = t->serialNumber;
11384 @@ -27,7 +27,7 @@ void yaffs_PackTags1(yaffs_PackedTags1 *
11388 -void yaffs_UnpackTags1(yaffs_ExtendedTags * t, const yaffs_PackedTags1 * pt)
11389 +void yaffs_UnpackTags1(yaffs_ExtendedTags *t, const yaffs_PackedTags1 *pt)
11391 static const __u8 allFF[] =
11392 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
11393 @@ -35,9 +35,8 @@ void yaffs_UnpackTags1(yaffs_ExtendedTag
11395 if (memcmp(allFF, pt, sizeof(yaffs_PackedTags1))) {
11397 - if (pt->shouldBeFF != 0xFFFFFFFF) {
11398 + if (pt->shouldBeFF != 0xFFFFFFFF)
11402 t->objectId = pt->objectId;
11403 t->chunkId = pt->chunkId;
11404 @@ -47,6 +46,5 @@ void yaffs_UnpackTags1(yaffs_ExtendedTag
11405 t->serialNumber = pt->serialNumber;
11407 memset(t, 0, sizeof(yaffs_ExtendedTags));
11411 --- a/fs/yaffs2/yaffs_packedtags1.h
11412 +++ b/fs/yaffs2/yaffs_packedtags1.h
11413 @@ -32,6 +32,6 @@ typedef struct {
11415 } yaffs_PackedTags1;
11417 -void yaffs_PackTags1(yaffs_PackedTags1 * pt, const yaffs_ExtendedTags * t);
11418 -void yaffs_UnpackTags1(yaffs_ExtendedTags * t, const yaffs_PackedTags1 * pt);
11419 +void yaffs_PackTags1(yaffs_PackedTags1 *pt, const yaffs_ExtendedTags *t);
11420 +void yaffs_UnpackTags1(yaffs_ExtendedTags *t, const yaffs_PackedTags1 *pt);
11422 --- a/fs/yaffs2/yaffs_packedtags2.c
11423 +++ b/fs/yaffs2/yaffs_packedtags2.c
11424 @@ -37,60 +37,68 @@
11425 #define EXTRA_OBJECT_TYPE_SHIFT (28)
11426 #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT)
11428 -static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt)
11430 +static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart *ptt)
11433 (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR),
11434 - pt->t.objectId, pt->t.chunkId, pt->t.byteCount,
11435 - pt->t.sequenceNumber));
11436 + ptt->objectId, ptt->chunkId, ptt->byteCount,
11437 + ptt->sequenceNumber));
11439 +static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 *pt)
11441 + yaffs_DumpPackedTags2TagsPart(&pt->t);
11444 -static void yaffs_DumpTags2(const yaffs_ExtendedTags * t)
11445 +static void yaffs_DumpTags2(const yaffs_ExtendedTags *t)
11449 - ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte "
11450 - "%d del %d ser %d seq %d"
11451 + ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d"
11452 TENDSTR), t->eccResult, t->blockBad, t->chunkUsed, t->objectId,
11453 t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber,
11454 t->sequenceNumber));
11458 -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t)
11459 +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart *ptt,
11460 + const yaffs_ExtendedTags *t)
11462 - pt->t.chunkId = t->chunkId;
11463 - pt->t.sequenceNumber = t->sequenceNumber;
11464 - pt->t.byteCount = t->byteCount;
11465 - pt->t.objectId = t->objectId;
11466 + ptt->chunkId = t->chunkId;
11467 + ptt->sequenceNumber = t->sequenceNumber;
11468 + ptt->byteCount = t->byteCount;
11469 + ptt->objectId = t->objectId;
11471 if (t->chunkId == 0 && t->extraHeaderInfoAvailable) {
11472 /* Store the extra header info instead */
11473 /* We save the parent object in the chunkId */
11474 - pt->t.chunkId = EXTRA_HEADER_INFO_FLAG
11475 + ptt->chunkId = EXTRA_HEADER_INFO_FLAG
11476 | t->extraParentObjectId;
11477 - if (t->extraIsShrinkHeader) {
11478 - pt->t.chunkId |= EXTRA_SHRINK_FLAG;
11480 - if (t->extraShadows) {
11481 - pt->t.chunkId |= EXTRA_SHADOWS_FLAG;
11483 + if (t->extraIsShrinkHeader)
11484 + ptt->chunkId |= EXTRA_SHRINK_FLAG;
11485 + if (t->extraShadows)
11486 + ptt->chunkId |= EXTRA_SHADOWS_FLAG;
11488 - pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK;
11489 - pt->t.objectId |=
11490 + ptt->objectId &= ~EXTRA_OBJECT_TYPE_MASK;
11492 (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT);
11494 - if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) {
11495 - pt->t.byteCount = t->extraEquivalentObjectId;
11496 - } else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE) {
11497 - pt->t.byteCount = t->extraFileLength;
11499 - pt->t.byteCount = 0;
11501 + if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK)
11502 + ptt->byteCount = t->extraEquivalentObjectId;
11503 + else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE)
11504 + ptt->byteCount = t->extraFileLength;
11506 + ptt->byteCount = 0;
11509 - yaffs_DumpPackedTags2(pt);
11510 + yaffs_DumpPackedTags2TagsPart(ptt);
11511 yaffs_DumpTags2(t);
11515 +void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t)
11517 + yaffs_PackTags2TagsPart(&pt->t, t);
11519 #ifndef YAFFS_IGNORE_TAGS_ECC
11521 @@ -101,82 +109,98 @@ void yaffs_PackTags2(yaffs_PackedTags2 *
11525 -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt)
11527 +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags *t,
11528 + yaffs_PackedTags2TagsPart *ptt)
11531 memset(t, 0, sizeof(yaffs_ExtendedTags));
11533 yaffs_InitialiseTags(t);
11535 - if (pt->t.sequenceNumber != 0xFFFFFFFF) {
11536 - /* Page is in use */
11537 -#ifdef YAFFS_IGNORE_TAGS_ECC
11539 - t->eccResult = YAFFS_ECC_RESULT_NO_ERROR;
11543 - yaffs_ECCOther ecc;
11545 - yaffs_ECCCalculateOther((unsigned char *)&pt->t,
11547 - (yaffs_PackedTags2TagsPart),
11550 - yaffs_ECCCorrectOther((unsigned char *)&pt->t,
11552 - (yaffs_PackedTags2TagsPart),
11556 - t->eccResult = YAFFS_ECC_RESULT_NO_ERROR;
11559 - t->eccResult = YAFFS_ECC_RESULT_FIXED;
11562 - t->eccResult = YAFFS_ECC_RESULT_UNFIXED;
11565 - t->eccResult = YAFFS_ECC_RESULT_UNKNOWN;
11569 + if (ptt->sequenceNumber != 0xFFFFFFFF) {
11572 - t->objectId = pt->t.objectId;
11573 - t->chunkId = pt->t.chunkId;
11574 - t->byteCount = pt->t.byteCount;
11575 + t->objectId = ptt->objectId;
11576 + t->chunkId = ptt->chunkId;
11577 + t->byteCount = ptt->byteCount;
11578 t->chunkDeleted = 0;
11579 t->serialNumber = 0;
11580 - t->sequenceNumber = pt->t.sequenceNumber;
11581 + t->sequenceNumber = ptt->sequenceNumber;
11583 /* Do extra header info stuff */
11585 - if (pt->t.chunkId & EXTRA_HEADER_INFO_FLAG) {
11586 + if (ptt->chunkId & EXTRA_HEADER_INFO_FLAG) {
11590 t->extraHeaderInfoAvailable = 1;
11591 t->extraParentObjectId =
11592 - pt->t.chunkId & (~(ALL_EXTRA_FLAGS));
11593 + ptt->chunkId & (~(ALL_EXTRA_FLAGS));
11594 t->extraIsShrinkHeader =
11595 - (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0;
11596 + (ptt->chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0;
11598 - (pt->t.chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0;
11599 + (ptt->chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0;
11600 t->extraObjectType =
11601 - pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT;
11602 + ptt->objectId >> EXTRA_OBJECT_TYPE_SHIFT;
11603 t->objectId &= ~EXTRA_OBJECT_TYPE_MASK;
11605 - if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) {
11606 - t->extraEquivalentObjectId = pt->t.byteCount;
11608 - t->extraFileLength = pt->t.byteCount;
11609 + if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK)
11610 + t->extraEquivalentObjectId = ptt->byteCount;
11612 + t->extraFileLength = ptt->byteCount;
11616 + yaffs_DumpPackedTags2TagsPart(ptt);
11617 + yaffs_DumpTags2(t);
11622 +void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt)
11625 + yaffs_ECCResult eccResult = YAFFS_ECC_RESULT_NO_ERROR;
11627 + if (pt->t.sequenceNumber != 0xFFFFFFFF) {
11628 + /* Page is in use */
11629 +#ifndef YAFFS_IGNORE_TAGS_ECC
11631 + yaffs_ECCOther ecc;
11633 + yaffs_ECCCalculateOther((unsigned char *)&pt->t,
11635 + (yaffs_PackedTags2TagsPart),
11638 + yaffs_ECCCorrectOther((unsigned char *)&pt->t,
11640 + (yaffs_PackedTags2TagsPart),
11642 + switch (result) {
11644 + eccResult = YAFFS_ECC_RESULT_NO_ERROR;
11647 + eccResult = YAFFS_ECC_RESULT_FIXED;
11650 + eccResult = YAFFS_ECC_RESULT_UNFIXED;
11653 + eccResult = YAFFS_ECC_RESULT_UNKNOWN;
11659 + yaffs_UnpackTags2TagsPart(t, &pt->t);
11661 + t->eccResult = eccResult;
11663 yaffs_DumpPackedTags2(pt);
11664 yaffs_DumpTags2(t);
11668 --- a/fs/yaffs2/yaffs_packedtags2.h
11669 +++ b/fs/yaffs2/yaffs_packedtags2.h
11670 @@ -33,6 +33,11 @@ typedef struct {
11671 yaffs_ECCOther ecc;
11672 } yaffs_PackedTags2;
11674 -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t);
11675 -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt);
11676 +/* Full packed tags with ECC, used for oob tags */
11677 +void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t);
11678 +void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt);
11680 +/* Only the tags part (no ECC for use with inband tags */
11681 +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart *pt, const yaffs_ExtendedTags *t);
11682 +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags *t, yaffs_PackedTags2TagsPart *pt);
11684 --- a/fs/yaffs2/yaffs_qsort.c
11685 +++ b/fs/yaffs2/yaffs_qsort.c
11686 @@ -28,12 +28,12 @@
11689 #include "yportenv.h"
11690 -//#include <linux/string.h>
11691 +/* #include <linux/string.h> */
11694 * Qsort routine from Bentley & McIlroy's "Engineering a Sort Function".
11696 -#define swapcode(TYPE, parmi, parmj, n) { \
11697 +#define swapcode(TYPE, parmi, parmj, n) do { \
11698 long i = (n) / sizeof (TYPE); \
11699 register TYPE *pi = (TYPE *) (parmi); \
11700 register TYPE *pj = (TYPE *) (parmj); \
11701 @@ -41,28 +41,29 @@
11702 register TYPE t = *pi; \
11705 - } while (--i > 0); \
11707 + } while (--i > 0); \
11710 #define SWAPINIT(a, es) swaptype = ((char *)a - (char *)0) % sizeof(long) || \
11711 - es % sizeof(long) ? 2 : es == sizeof(long)? 0 : 1;
11712 + es % sizeof(long) ? 2 : es == sizeof(long) ? 0 : 1;
11714 static __inline void
11715 swapfunc(char *a, char *b, int n, int swaptype)
11718 - swapcode(long, a, b, n)
11719 + swapcode(long, a, b, n);
11721 - swapcode(char, a, b, n)
11722 + swapcode(char, a, b, n);
11725 -#define swap(a, b) \
11726 +#define yswap(a, b) do { \
11727 if (swaptype == 0) { \
11728 long t = *(long *)(a); \
11729 *(long *)(a) = *(long *)(b); \
11730 *(long *)(b) = t; \
11732 - swapfunc(a, b, es, swaptype)
11733 + swapfunc(a, b, es, swaptype); \
11736 #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
11738 @@ -70,12 +71,12 @@ static __inline char *
11739 med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *))
11741 return cmp(a, b) < 0 ?
11742 - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a ))
11743 - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c ));
11744 + (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a))
11745 + : (cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c));
11749 -#define min(a,b) (((a) < (b)) ? (a) : (b))
11750 +#define min(a, b) (((a) < (b)) ? (a) : (b))
11754 @@ -92,7 +93,7 @@ loop: SWAPINIT(a, es);
11755 for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es)
11756 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
11758 - swap(pl, pl - es);
11759 + yswap(pl, pl - es);
11762 pm = (char *)a + (n / 2) * es;
11763 @@ -107,7 +108,7 @@ loop: SWAPINIT(a, es);
11765 pm = med3(pl, pm, pn, cmp);
11769 pa = pb = (char *)a + es;
11771 pc = pd = (char *)a + (n - 1) * es;
11772 @@ -115,7 +116,7 @@ loop: SWAPINIT(a, es);
11773 while (pb <= pc && (r = cmp(pb, a)) <= 0) {
11781 @@ -123,14 +124,14 @@ loop: SWAPINIT(a, es);
11782 while (pb <= pc && (r = cmp(pc, a)) >= 0) {
11798 @@ -139,7 +140,7 @@ loop: SWAPINIT(a, es);
11799 for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es)
11800 for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0;
11802 - swap(pl, pl - es);
11803 + yswap(pl, pl - es);
11807 @@ -148,9 +149,11 @@ loop: SWAPINIT(a, es);
11808 vecswap(a, pb - r, r);
11809 r = min((long)(pd - pc), (long)(pn - pd - es));
11810 vecswap(pb, pn - r, r);
11811 - if ((r = pb - pa) > es)
11814 yaffs_qsort(a, r / es, es, cmp);
11815 - if ((r = pd - pc) > es) {
11818 /* Iterate rather than recurse to save stack space */
11821 --- a/fs/yaffs2/yaffs_qsort.h
11822 +++ b/fs/yaffs2/yaffs_qsort.h
11824 #ifndef __YAFFS_QSORT_H__
11825 #define __YAFFS_QSORT_H__
11827 -extern void yaffs_qsort (void *const base, size_t total_elems, size_t size,
11828 - int (*cmp)(const void *, const void *));
11829 +extern void yaffs_qsort(void *const base, size_t total_elems, size_t size,
11830 + int (*cmp)(const void *, const void *));
11833 --- a/fs/yaffs2/yaffs_tagscompat.c
11834 +++ b/fs/yaffs2/yaffs_tagscompat.c
11835 @@ -14,16 +14,17 @@
11836 #include "yaffs_guts.h"
11837 #include "yaffs_tagscompat.h"
11838 #include "yaffs_ecc.h"
11839 +#include "yaffs_getblockinfo.h"
11841 -static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND);
11842 +static void yaffs_HandleReadDataError(yaffs_Device *dev, int chunkInNAND);
11844 -static void yaffs_CheckWrittenBlock(yaffs_Device * dev, int chunkInNAND);
11845 -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND,
11846 - const __u8 * data,
11847 - const yaffs_Spare * spare);
11848 -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND,
11849 - const yaffs_Spare * spare);
11850 -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND);
11851 +static void yaffs_CheckWrittenBlock(yaffs_Device *dev, int chunkInNAND);
11852 +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND,
11853 + const __u8 *data,
11854 + const yaffs_Spare *spare);
11855 +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND,
11856 + const yaffs_Spare *spare);
11857 +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND);
11860 static const char yaffs_countBitsTable[256] = {
11861 @@ -54,13 +55,13 @@ int yaffs_CountBits(__u8 x)
11863 /********** Tags ECC calculations *********/
11865 -void yaffs_CalcECC(const __u8 * data, yaffs_Spare * spare)
11866 +void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare)
11868 yaffs_ECCCalculate(data, spare->ecc1);
11869 yaffs_ECCCalculate(&data[256], spare->ecc2);
11872 -void yaffs_CalcTagsECC(yaffs_Tags * tags)
11873 +void yaffs_CalcTagsECC(yaffs_Tags *tags)
11875 /* Calculate an ecc */
11877 @@ -74,9 +75,8 @@ void yaffs_CalcTagsECC(yaffs_Tags * tags
11878 for (i = 0; i < 8; i++) {
11879 for (j = 1; j & 0xff; j <<= 1) {
11888 @@ -84,7 +84,7 @@ void yaffs_CalcTagsECC(yaffs_Tags * tags
11892 -int yaffs_CheckECCOnTags(yaffs_Tags * tags)
11893 +int yaffs_CheckECCOnTags(yaffs_Tags *tags)
11895 unsigned ecc = tags->ecc;
11897 @@ -115,8 +115,8 @@ int yaffs_CheckECCOnTags(yaffs_Tags * ta
11899 /********** Tags **********/
11901 -static void yaffs_LoadTagsIntoSpare(yaffs_Spare * sparePtr,
11902 - yaffs_Tags * tagsPtr)
11903 +static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr,
11904 + yaffs_Tags *tagsPtr)
11906 yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr;
11908 @@ -132,8 +132,8 @@ static void yaffs_LoadTagsIntoSpare(yaff
11909 sparePtr->tagByte7 = tu->asBytes[7];
11912 -static void yaffs_GetTagsFromSpare(yaffs_Device * dev, yaffs_Spare * sparePtr,
11913 - yaffs_Tags * tagsPtr)
11914 +static void yaffs_GetTagsFromSpare(yaffs_Device *dev, yaffs_Spare *sparePtr,
11915 + yaffs_Tags *tagsPtr)
11917 yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr;
11919 @@ -148,21 +148,20 @@ static void yaffs_GetTagsFromSpare(yaffs
11920 tu->asBytes[7] = sparePtr->tagByte7;
11922 result = yaffs_CheckECCOnTags(tagsPtr);
11923 - if (result > 0) {
11925 dev->tagsEccFixed++;
11926 - } else if (result < 0) {
11927 + else if (result < 0)
11928 dev->tagsEccUnfixed++;
11932 -static void yaffs_SpareInitialise(yaffs_Spare * spare)
11933 +static void yaffs_SpareInitialise(yaffs_Spare *spare)
11935 memset(spare, 0xFF, sizeof(yaffs_Spare));
11938 static int yaffs_WriteChunkToNAND(struct yaffs_DeviceStruct *dev,
11939 - int chunkInNAND, const __u8 * data,
11940 - yaffs_Spare * spare)
11941 + int chunkInNAND, const __u8 *data,
11942 + yaffs_Spare *spare)
11944 if (chunkInNAND < dev->startBlock * dev->nChunksPerBlock) {
11945 T(YAFFS_TRACE_ERROR,
11946 @@ -177,9 +176,9 @@ static int yaffs_WriteChunkToNAND(struct
11948 static int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev,
11951 - yaffs_Spare * spare,
11952 - yaffs_ECCResult * eccResult,
11954 + yaffs_Spare *spare,
11955 + yaffs_ECCResult *eccResult,
11956 int doErrorCorrection)
11959 @@ -252,9 +251,11 @@ static int yaffs_ReadChunkFromNAND(struc
11960 /* Must allocate enough memory for spare+2*sizeof(int) */
11961 /* for ecc results from device. */
11962 struct yaffs_NANDSpare nspare;
11964 - dev->readChunkFromNAND(dev, chunkInNAND, data,
11965 - (yaffs_Spare *) & nspare);
11967 + memset(&nspare, 0, sizeof(nspare));
11969 + retVal = dev->readChunkFromNAND(dev, chunkInNAND, data,
11970 + (yaffs_Spare *) &nspare);
11971 memcpy(spare, &nspare, sizeof(yaffs_Spare));
11972 if (data && doErrorCorrection) {
11973 if (nspare.eccres1 > 0) {
11974 @@ -302,8 +303,7 @@ static int yaffs_ReadChunkFromNAND(struc
11975 static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev,
11979 - static int init = 0;
11981 static __u8 cmpbuf[YAFFS_BYTES_PER_CHUNK];
11982 static __u8 data[YAFFS_BYTES_PER_CHUNK];
11983 /* Might as well always allocate the larger size for */
11984 @@ -331,12 +331,12 @@ static int yaffs_CheckChunkErased(struct
11985 * Functions for robustisizing
11988 -static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND)
11989 +static void yaffs_HandleReadDataError(yaffs_Device *dev, int chunkInNAND)
11991 int blockInNAND = chunkInNAND / dev->nChunksPerBlock;
11993 /* Mark the block for retirement */
11994 - yaffs_GetBlockInfo(dev, blockInNAND)->needsRetiring = 1;
11995 + yaffs_GetBlockInfo(dev, blockInNAND + dev->blockOffset)->needsRetiring = 1;
11996 T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
11997 (TSTR("**>>Block %d marked for retirement" TENDSTR), blockInNAND));
11999 @@ -348,22 +348,22 @@ static void yaffs_HandleReadDataError(ya
12003 -static void yaffs_CheckWrittenBlock(yaffs_Device * dev, int chunkInNAND)
12004 +static void yaffs_CheckWrittenBlock(yaffs_Device *dev, int chunkInNAND)
12008 -static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND,
12009 - const __u8 * data,
12010 - const yaffs_Spare * spare)
12011 +static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND,
12012 + const __u8 *data,
12013 + const yaffs_Spare *spare)
12017 -static void yaffs_HandleUpdateChunk(yaffs_Device * dev, int chunkInNAND,
12018 - const yaffs_Spare * spare)
12019 +static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND,
12020 + const yaffs_Spare *spare)
12024 -static void yaffs_HandleWriteChunkError(yaffs_Device * dev, int chunkInNAND)
12025 +static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND)
12027 int blockInNAND = chunkInNAND / dev->nChunksPerBlock;
12029 @@ -373,8 +373,8 @@ static void yaffs_HandleWriteChunkError(
12030 yaffs_DeleteChunk(dev, chunkInNAND, 1, __LINE__);
12033 -static int yaffs_VerifyCompare(const __u8 * d0, const __u8 * d1,
12034 - const yaffs_Spare * s0, const yaffs_Spare * s1)
12035 +static int yaffs_VerifyCompare(const __u8 *d0, const __u8 *d1,
12036 + const yaffs_Spare *s0, const yaffs_Spare *s1)
12039 if (memcmp(d0, d1, YAFFS_BYTES_PER_CHUNK) != 0 ||
12040 @@ -398,28 +398,35 @@ static int yaffs_VerifyCompare(const __u
12042 #endif /* NOTYET */
12044 -int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device * dev,
12046 - const __u8 * data,
12047 - const yaffs_ExtendedTags *
12049 +int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device *dev,
12051 + const __u8 *data,
12052 + const yaffs_ExtendedTags *eTags)
12057 yaffs_SpareInitialise(&spare);
12059 - if (eTags->chunkDeleted) {
12060 + if (eTags->chunkDeleted)
12061 spare.pageStatus = 0;
12064 tags.objectId = eTags->objectId;
12065 tags.chunkId = eTags->chunkId;
12066 - tags.byteCount = eTags->byteCount;
12068 + tags.byteCountLSB = eTags->byteCount & 0x3ff;
12070 + if (dev->nDataBytesPerChunk >= 1024)
12071 + tags.byteCountMSB = (eTags->byteCount >> 10) & 3;
12073 + tags.byteCountMSB = 3;
12076 tags.serialNumber = eTags->serialNumber;
12078 - if (!dev->useNANDECC && data) {
12079 + if (!dev->useNANDECC && data)
12080 yaffs_CalcECC(data, &spare);
12083 yaffs_LoadTagsIntoSpare(&spare, &tags);
12086 @@ -427,15 +434,15 @@ int yaffs_TagsCompatabilityWriteChunkWit
12087 return yaffs_WriteChunkToNAND(dev, chunkInNAND, data, &spare);
12090 -int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev,
12091 +int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device *dev,
12094 - yaffs_ExtendedTags * eTags)
12096 + yaffs_ExtendedTags *eTags)
12101 - yaffs_ECCResult eccResult;
12102 + yaffs_ECCResult eccResult = YAFFS_ECC_RESULT_UNKNOWN;
12104 static yaffs_Spare spareFF;
12106 @@ -466,7 +473,11 @@ int yaffs_TagsCompatabilityReadChunkWith
12108 eTags->objectId = tags.objectId;
12109 eTags->chunkId = tags.chunkId;
12110 - eTags->byteCount = tags.byteCount;
12111 + eTags->byteCount = tags.byteCountLSB;
12113 + if (dev->nDataBytesPerChunk >= 1024)
12114 + eTags->byteCount |= (((unsigned) tags.byteCountMSB) << 10);
12116 eTags->serialNumber = tags.serialNumber;
12119 @@ -497,9 +508,9 @@ int yaffs_TagsCompatabilityMarkNANDBlock
12122 int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev,
12123 - int blockNo, yaffs_BlockState *
12125 - int *sequenceNumber)
12127 + yaffs_BlockState *state,
12128 + __u32 *sequenceNumber)
12131 yaffs_Spare spare0, spare1;
12132 --- a/fs/yaffs2/yaffs_tagscompat.h
12133 +++ b/fs/yaffs2/yaffs_tagscompat.h
12134 @@ -17,24 +17,23 @@
12135 #define __YAFFS_TAGSCOMPAT_H__
12137 #include "yaffs_guts.h"
12138 -int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device * dev,
12140 - const __u8 * data,
12141 - const yaffs_ExtendedTags *
12143 -int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev,
12146 - yaffs_ExtendedTags *
12148 +int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device *dev,
12150 + const __u8 *data,
12151 + const yaffs_ExtendedTags *tags);
12152 +int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device *dev,
12155 + yaffs_ExtendedTags *tags);
12156 int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev,
12158 int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev,
12159 - int blockNo, yaffs_BlockState *
12160 - state, int *sequenceNumber);
12162 + yaffs_BlockState *state,
12163 + __u32 *sequenceNumber);
12165 -void yaffs_CalcTagsECC(yaffs_Tags * tags);
12166 -int yaffs_CheckECCOnTags(yaffs_Tags * tags);
12167 +void yaffs_CalcTagsECC(yaffs_Tags *tags);
12168 +int yaffs_CheckECCOnTags(yaffs_Tags *tags);
12169 int yaffs_CountBits(__u8 byte);
12172 --- a/fs/yaffs2/yaffs_tagsvalidity.c
12173 +++ b/fs/yaffs2/yaffs_tagsvalidity.c
12174 @@ -13,14 +13,14 @@
12176 #include "yaffs_tagsvalidity.h"
12178 -void yaffs_InitialiseTags(yaffs_ExtendedTags * tags)
12179 +void yaffs_InitialiseTags(yaffs_ExtendedTags *tags)
12181 memset(tags, 0, sizeof(yaffs_ExtendedTags));
12182 tags->validMarker0 = 0xAAAAAAAA;
12183 tags->validMarker1 = 0x55555555;
12186 -int yaffs_ValidateTags(yaffs_ExtendedTags * tags)
12187 +int yaffs_ValidateTags(yaffs_ExtendedTags *tags)
12189 return (tags->validMarker0 == 0xAAAAAAAA &&
12190 tags->validMarker1 == 0x55555555);
12191 --- a/fs/yaffs2/yaffs_tagsvalidity.h
12192 +++ b/fs/yaffs2/yaffs_tagsvalidity.h
12195 #include "yaffs_guts.h"
12197 -void yaffs_InitialiseTags(yaffs_ExtendedTags * tags);
12198 -int yaffs_ValidateTags(yaffs_ExtendedTags * tags);
12199 +void yaffs_InitialiseTags(yaffs_ExtendedTags *tags);
12200 +int yaffs_ValidateTags(yaffs_ExtendedTags *tags);
12202 --- a/fs/yaffs2/yportenv.h
12203 +++ b/fs/yaffs2/yportenv.h
12204 @@ -17,17 +17,28 @@
12205 #ifndef __YPORTENV_H__
12206 #define __YPORTENV_H__
12209 + * Define the MTD version in terms of Linux Kernel versions
12210 + * This allows yaffs to be used independantly of the kernel
12211 + * as well as with it.
12214 +#define MTD_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c))
12216 #if defined CONFIG_YAFFS_WINCE
12218 #include "ywinceenv.h"
12220 -#elif defined __KERNEL__
12221 +#elif defined __KERNEL__
12223 #include "moduleconfig.h"
12227 #include <linux/version.h>
12228 -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19))
12229 +#define MTD_VERSION_CODE LINUX_VERSION_CODE
12231 +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19))
12232 #include <linux/config.h>
12234 #include <linux/kernel.h>
12235 @@ -40,12 +51,13 @@
12237 #define YUCHAR unsigned char
12239 -#define yaffs_strcpy(a,b) strcpy(a,b)
12240 -#define yaffs_strncpy(a,b,c) strncpy(a,b,c)
12241 -#define yaffs_strncmp(a,b,c) strncmp(a,b,c)
12242 -#define yaffs_strlen(s) strlen(s)
12243 -#define yaffs_sprintf sprintf
12244 -#define yaffs_toupper(a) toupper(a)
12245 +#define yaffs_strcat(a, b) strcat(a, b)
12246 +#define yaffs_strcpy(a, b) strcpy(a, b)
12247 +#define yaffs_strncpy(a, b, c) strncpy(a, b, c)
12248 +#define yaffs_strncmp(a, b, c) strncmp(a, b, c)
12249 +#define yaffs_strlen(s) strlen(s)
12250 +#define yaffs_sprintf sprintf
12251 +#define yaffs_toupper(a) toupper(a)
12253 #define Y_INLINE inline
12255 @@ -53,19 +65,19 @@
12256 #define YAFFS_LOSTNFOUND_PREFIX "obj"
12258 /* #define YPRINTF(x) printk x */
12259 -#define YMALLOC(x) kmalloc(x,GFP_KERNEL)
12260 +#define YMALLOC(x) kmalloc(x, GFP_NOFS)
12261 #define YFREE(x) kfree(x)
12262 #define YMALLOC_ALT(x) vmalloc(x)
12263 #define YFREE_ALT(x) vfree(x)
12264 #define YMALLOC_DMA(x) YMALLOC(x)
12266 -// KR - added for use in scan so processes aren't blocked indefinitely.
12267 +/* KR - added for use in scan so processes aren't blocked indefinitely. */
12268 #define YYIELD() schedule()
12270 #define YAFFS_ROOT_MODE 0666
12271 #define YAFFS_LOSTNFOUND_MODE 0666
12273 -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
12274 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0))
12275 #define Y_CURRENT_TIME CURRENT_TIME.tv_sec
12276 #define Y_TIME_CONVERT(x) (x).tv_sec
12278 @@ -73,11 +85,12 @@
12279 #define Y_TIME_CONVERT(x) (x)
12282 -#define yaffs_SumCompare(x,y) ((x) == (y))
12283 -#define yaffs_strcmp(a,b) strcmp(a,b)
12284 +#define yaffs_SumCompare(x, y) ((x) == (y))
12285 +#define yaffs_strcmp(a, b) strcmp(a, b)
12287 #define TENDSTR "\n"
12288 #define TSTR(x) KERN_WARNING x
12289 +#define TCONT(x) x
12290 #define TOUT(p) printk p
12292 #define yaffs_trace(mask, fmt, args...) \
12295 #elif defined CONFIG_YAFFS_DIRECT
12297 +#define MTD_VERSION_CODE MTD_VERSION(2, 6, 22)
12299 /* Direct interface */
12300 #include "ydirectenv.h"
12302 @@ -111,11 +126,12 @@
12304 #define YUCHAR unsigned char
12306 -#define yaffs_strcpy(a,b) strcpy(a,b)
12307 -#define yaffs_strncpy(a,b,c) strncpy(a,b,c)
12308 -#define yaffs_strlen(s) strlen(s)
12309 -#define yaffs_sprintf sprintf
12310 -#define yaffs_toupper(a) toupper(a)
12311 +#define yaffs_strcat(a, b) strcat(a, b)
12312 +#define yaffs_strcpy(a, b) strcpy(a, b)
12313 +#define yaffs_strncpy(a, b, c) strncpy(a, b, c)
12314 +#define yaffs_strlen(s) strlen(s)
12315 +#define yaffs_sprintf sprintf
12316 +#define yaffs_toupper(a) toupper(a)
12318 #define Y_INLINE inline
12320 @@ -133,8 +149,8 @@
12321 #define YAFFS_ROOT_MODE 0666
12322 #define YAFFS_LOSTNFOUND_MODE 0666
12324 -#define yaffs_SumCompare(x,y) ((x) == (y))
12325 -#define yaffs_strcmp(a,b) strcmp(a,b)
12326 +#define yaffs_SumCompare(x, y) ((x) == (y))
12327 +#define yaffs_strcmp(a, b) strcmp(a, b)
12330 /* Should have specified a configuration type */
12331 @@ -178,10 +194,10 @@ extern unsigned int yaffs_wr_attempts;
12332 #define YAFFS_TRACE_ALWAYS 0xF0000000
12335 -#define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p);} while(0)
12336 +#define T(mask, p) do { if ((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p); } while (0)
12338 -#ifndef CONFIG_YAFFS_WINCE
12339 -#define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__))
12341 +#define YBUG() do {T(YAFFS_TRACE_BUG, (TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR), __LINE__)); } while (0)