diff options
author | juhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2008-06-06 12:52:39 +0000 |
---|---|---|
committer | juhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73> | 2008-06-06 12:52:39 +0000 |
commit | da7797b2ca558347d2f6862ede2ca96a1fee20ce (patch) | |
tree | 4de5c4b7528ff05a6f76ba33d18ea2fa8edf543a /target/linux | |
parent | 70cc333f243e759bd07a83d22a42757dfec6dabc (diff) |
[kernel] generic-2.6: sync yaffs code with the official CVS tree
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@11378 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux')
66 files changed, 1986 insertions, 2967 deletions
diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Kconfig b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Kconfig index 7b6f836cd..de1516390 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Kconfig +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Kconfig @@ -43,7 +43,8 @@ config YAFFS_9BYTE_TAGS format that you need to continue to support. New data written also uses the older-style format. Note: Use of this option generally requires that MTD's oob layout be adjusted to use the - older-style format. See notes on tags formats and MTD versions. + older-style format. See notes on tags formats and MTD versions + in yaffs_mtdif1.c. If unsure, say N. @@ -109,26 +110,6 @@ config YAFFS_DISABLE_LAZY_LOAD If unsure, say N. -config YAFFS_CHECKPOINT_RESERVED_BLOCKS - int "Reserved blocks for checkpointing" - depends on YAFFS_YAFFS2 - default 10 - help - Give the number of Blocks to reserve for checkpointing. - Checkpointing saves the state at unmount so that mounting is - much faster as a scan of all the flash to regenerate this state - is not needed. These Blocks are reserved per partition, so if - you have very small partitions the default (10) may be a mess - for you. You can set this value to 0, but that does not mean - checkpointing is disabled at all. There only won't be any - specially reserved blocks for checkpointing, so if there is - enough free space on the filesystem, it will be used for - checkpointing. - - If unsure, leave at default (10), but don't wonder if there are - always 2MB used on your large page device partition (10 x 2k - pagesize). When using small partitions or when being very small - on space, you probably want to set this to zero. config YAFFS_DISABLE_WIDE_TNODES bool "Turn off wide tnodes" diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Makefile b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Makefile index 73f46583f..382ee6142 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Makefile +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/Makefile @@ -5,7 +5,6 @@ obj-$(CONFIG_YAFFS_FS) += yaffs.o yaffs-y := yaffs_ecc.o yaffs_fs.o yaffs_guts.o yaffs_checkptrw.o -yaffs-y += yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o +yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o yaffs-y += yaffs_tagscompat.o yaffs_tagsvalidity.o -yaffs-y += yaffs_mtdif1.o yaffs_packedtags1.o -yaffs-y += yaffs_mtdif.o yaffs_mtdif2.o +yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/devextras.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/devextras.h index fcf2690a5..55c31219d 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/devextras.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/devextras.h @@ -14,194 +14,117 @@ */ /* - * This file is just holds extra declarations used during development. - * Most of these are from kernel includes placed here so we can use them in - * applications. + * This file is just holds extra declarations of macros that would normally + * be providesd in the Linux kernel. These macros have been written from + * scratch but are functionally equivalent to the Linux ones. * */ #ifndef __EXTRAS_H__ #define __EXTRAS_H__ -#if defined WIN32 -#define __inline__ __inline -#define new newHack -#endif - -#if !(defined __KERNEL__) || (defined WIN32) -/* User space defines */ +#if !(defined __KERNEL__) +/* Definition of types */ typedef unsigned char __u8; typedef unsigned short __u16; typedef unsigned __u32; +#endif + /* - * Simple doubly linked list implementation. - * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. + * This is a simple doubly linked list implementation that matches the + * way the Linux kernel doubly linked list implementation works. */ -#define prefetch(x) 1 - -struct list_head { - struct list_head *next, *prev; +struct ylist_head { + struct ylist_head *next; /* next in chain */ + struct ylist_head *prev; /* previous in chain */ }; -#define LIST_HEAD_INIT(name) { &(name), &(name) } -#define LIST_HEAD(name) \ - struct list_head name = LIST_HEAD_INIT(name) +/* Initialise a list head to an empty list */ +#define YINIT_LIST_HEAD(p) \ +do { \ + (p)->next = (p);\ + (p)->prev = (p); \ +} while(0) -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) -/* - * Insert a new entry between two known consecutive entries. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_add(struct list_head *new, - struct list_head *prev, - struct list_head *next) +/* Add an element to a list */ +static __inline__ void ylist_add(struct ylist_head *newEntry, + struct ylist_head *list) { - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; + struct ylist_head *listNext = list->next; + + list->next = newEntry; + newEntry->prev = list; + newEntry->next = listNext; + listNext->prev = newEntry; + } -/** - * list_add - add a new entry - * @new: new entry to be added - * @head: list head to add it after - * - * Insert a new entry after the specified head. - * This is good for implementing stacks. - */ -static __inline__ void list_add(struct list_head *new, struct list_head *head) -{ - __list_add(new, head, head->next); -} -/** - * list_add_tail - add a new entry - * @new: new entry to be added - * @head: list head to add it before - * - * Insert a new entry before the specified head. - * This is useful for implementing queues. - */ -static __inline__ void list_add_tail(struct list_head *new, - struct list_head *head) +/* Take an element out of its current list, with or without + * reinitialising the links.of the entry*/ +static __inline__ void ylist_del(struct ylist_head *entry) { - __list_add(new, head->prev, head); + struct ylist_head *listNext = entry->next; + struct ylist_head *listPrev = entry->prev; + + listNext->prev = listPrev; + listPrev->next = listNext; + } -/* - * Delete a list entry by making the prev/next entries - * point to each other. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_del(struct list_head *prev, - struct list_head *next) +static __inline__ void ylist_del_init(struct ylist_head *entry) { - next->prev = prev; - prev->next = next; + ylist_del(entry); + entry->next = entry->prev = entry; } -/** - * list_del - deletes entry from list. - * @entry: the element to delete from the list. - * Note: list_empty on entry does not return true after this, the entry is - * in an undefined state. - */ -static __inline__ void list_del(struct list_head *entry) -{ - __list_del(entry->prev, entry->next); -} -/** - * list_del_init - deletes entry from list and reinitialize it. - * @entry: the element to delete from the list. - */ -static __inline__ void list_del_init(struct list_head *entry) +/* Test if the list is empty */ +static __inline__ int ylist_empty(struct ylist_head *entry) { - __list_del(entry->prev, entry->next); - INIT_LIST_HEAD(entry); + return (entry->next == entry); } -/** - * list_empty - tests whether a list is empty - * @head: the list to test. + +/* ylist_entry takes a pointer to a list entry and offsets it to that + * we can find a pointer to the object it is embedded in. */ -static __inline__ int list_empty(struct list_head *head) -{ - return head->next == head; -} + + +#define ylist_entry(entry, type, member) \ + ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member))) + -/** - * list_splice - join two lists - * @list: the new list to add. - * @head: the place to add it in the first list. +/* ylist_for_each and list_for_each_safe iterate over lists. + * ylist_for_each_safe uses temporary storage to make the list delete safe */ -static __inline__ void list_splice(struct list_head *list, - struct list_head *head) -{ - struct list_head *first = list->next; - if (first != list) { - struct list_head *last = list->prev; - struct list_head *at = head->next; +#define ylist_for_each(itervar, list) \ + for (itervar = (list)->next; itervar != (list); itervar = itervar->next ) - first->prev = head; - head->next = first; +#define ylist_for_each_safe(itervar,saveVar, list) \ + for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \ + itervar = saveVar, saveVar = saveVar->next) - last->next = at; - at->prev = last; - } -} -/** - * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_struct within the struct. - */ -#define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) +#if !(defined __KERNEL__) + + +#ifndef WIN32 +#include <sys/stat.h> +#endif + + +#ifdef CONFIG_YAFFS_PROVIDE_DEFS +/* File types */ -/** - * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. - * @head: the head for your list. - */ -#define list_for_each(pos, head) \ - for (pos = (head)->next, prefetch(pos->next); pos != (head); \ - pos = pos->next, prefetch(pos->next)) - -/** - * list_for_each_safe - iterate over a list safe against removal - * of list entry - * @pos: the &struct list_head to use as a loop counter. - * @n: another &struct list_head to use as temporary storage - * @head: the head for your list. - */ -#define list_for_each_safe(pos, n, head) \ - for (pos = (head)->next, n = pos->next; pos != (head); \ - pos = n, n = pos->next) -/* - * File types - */ #define DT_UNKNOWN 0 #define DT_FIFO 1 #define DT_CHR 2 @@ -212,13 +135,13 @@ static __inline__ void list_splice(struct list_head *list, #define DT_SOCK 12 #define DT_WHT 14 + #ifndef WIN32 #include <sys/stat.h> #endif /* - * Attribute flags. These should be or-ed together to figure out what - * has been changed! + * Attribute flags. */ #define ATTR_MODE 1 #define ATTR_UID 2 @@ -227,10 +150,7 @@ static __inline__ void list_splice(struct list_head *list, #define ATTR_ATIME 16 #define ATTR_MTIME 32 #define ATTR_CTIME 64 -#define ATTR_ATIME_SET 128 -#define ATTR_MTIME_SET 256 -#define ATTR_FORCE 512 /* Not a change, but a change it */ -#define ATTR_ATTR_FLAG 1024 + struct iattr { unsigned int ia_valid; @@ -244,21 +164,18 @@ struct iattr { unsigned int ia_attr_flags; }; +#endif + + #define KERN_DEBUG #else -#ifndef WIN32 #include <linux/types.h> -#include <linux/list.h> #include <linux/fs.h> #include <linux/stat.h> -#endif #endif -#if defined WIN32 -#undef new -#endif #endif diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/moduleconfig.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/moduleconfig.h index 016391ca5..ac5af6f35 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/moduleconfig.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/moduleconfig.h @@ -54,11 +54,11 @@ that you need to continue to support. New data written also uses the older-style format. Note: Use of this option generally requires that MTD's oob layout be adjusted to use the older-style format. See notes on tags formats and -MTD versions. +MTD versions in yaffs_mtdif1.c. */ /* Default: Not selected */ /* Meaning: Use older-style on-NAND data format with pageStatus byte */ -#define CONFIG_YAFFS_9BYTE_TAGS +//#define CONFIG_YAFFS_9BYTE_TAGS #endif /* YAFFS_OUT_OF_TREE */ diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_checkptrw.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_checkptrw.c index 933a33fb8..68e6d0ce5 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_checkptrw.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_checkptrw.c @@ -12,11 +12,11 @@ */ const char *yaffs_checkptrw_c_version = - "$Id: yaffs_checkptrw.c,v 1.14 2007-05-15 20:07:40 charles Exp $"; + "$Id: yaffs_checkptrw.c,v 1.16 2008-05-05 07:58:58 charles Exp $"; #include "yaffs_checkptrw.h" - +#include "yaffs_getblockinfo.h" static int yaffs_CheckpointSpaceOk(yaffs_Device *dev) { @@ -142,7 +142,7 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) return 0; if(!dev->checkpointBuffer) - dev->checkpointBuffer = YMALLOC_DMA(dev->nDataBytesPerChunk); + dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk); if(!dev->checkpointBuffer) return 0; diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_ecc.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_ecc.c index e2860393d..9f5973a5b 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_ecc.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_ecc.c @@ -29,7 +29,7 @@ */ const char *yaffs_ecc_c_version = - "$Id: yaffs_ecc.c,v 1.9 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_ecc.c,v 1.10 2007-12-13 15:35:17 wookey Exp $"; #include "yportenv.h" diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_fs.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_fs.c index 67001b10e..ab6a3a7e0 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_fs.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_fs.c @@ -32,7 +32,7 @@ */ const char *yaffs_fs_c_version = - "$Id: yaffs_fs.c,v 1.63 2007-09-19 20:35:40 imcd Exp $"; + "$Id: yaffs_fs.c,v 1.66 2008-05-05 07:58:58 charles Exp $"; extern const char *yaffs_guts_c_version; #include <linux/version.h> @@ -53,6 +53,8 @@ extern const char *yaffs_guts_c_version; #include <linux/string.h> #include <linux/ctype.h> +#include "asm/div64.h" + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) #include <linux/statfs.h> /* Added NCB 15-8-2003 */ @@ -753,6 +755,8 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj) break; } + inode->i_flags |= S_NOATIME; + inode->i_ino = obj->objectId; inode->i_mode = obj->yst_mode; inode->i_uid = obj->yst_uid; @@ -1350,25 +1354,47 @@ static int yaffs_statfs(struct super_block *sb, struct statfs *buf) buf->f_type = YAFFS_MAGIC; buf->f_bsize = sb->s_blocksize; buf->f_namelen = 255; - if (sb->s_blocksize > dev->nDataBytesPerChunk) { - + + if(dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)){ + /* Do this if chunk size is not a power of 2 */ + + uint64_t bytesInDev; + uint64_t bytesFree; + + bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock +1))) * + ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk)); + + do_div(bytesInDev,sb->s_blocksize); /* bytesInDev becomes the number of blocks */ + buf->f_blocks = bytesInDev; + + bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) * + ((uint64_t)(dev->nDataBytesPerChunk)); + + do_div(bytesFree,sb->s_blocksize); + + buf->f_bfree = bytesFree; + + } else if (sb->s_blocksize > dev->nDataBytesPerChunk) { + buf->f_blocks = - (dev->endBlock - dev->startBlock + - 1) * dev->nChunksPerBlock / (sb->s_blocksize / - dev->nDataBytesPerChunk); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize / - dev->nDataBytesPerChunk); + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock / + (sb->s_blocksize / dev->nDataBytesPerChunk); + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) / + (sb->s_blocksize / dev->nDataBytesPerChunk); } else { - - buf->f_blocks = - (dev->endBlock - dev->startBlock + - 1) * dev->nChunksPerBlock * (dev->nDataBytesPerChunk / - sb->s_blocksize); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) * (dev->nDataBytesPerChunk / - sb->s_blocksize); + buf->f_blocks = + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock * + (dev->nDataBytesPerChunk / sb->s_blocksize); + + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) * + (dev->nDataBytesPerChunk / sb->s_blocksize); } + + buf->f_files = 0; buf->f_ffree = 0; buf->f_bavail = buf->f_bfree; @@ -1602,6 +1628,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, sb->s_magic = YAFFS_MAGIC; sb->s_op = &yaffs_super_ops; + sb->s_flags |= MS_NOATIME; if (!sb) printk(KERN_INFO "yaffs: sb is NULL\n"); @@ -1678,22 +1705,15 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, #ifdef CONFIG_YAFFS_AUTO_YAFFS2 if (yaffsVersion == 1 && -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - mtd->writesize >= 2048) { -#else - mtd->oobblock >= 2048) { -#endif + WRITE_SIZE(mtd) >= 2048) { T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n")); yaffsVersion = 2; } /* Added NCB 26/5/2006 for completeness */ - if (yaffsVersion == 2 && -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - mtd->writesize == 512) { -#else - mtd->oobblock == 512) { -#endif + if (yaffsVersion == 2 && + !options.inband_tags && + WRITE_SIZE(mtd) == 512){ T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs1\n")); yaffsVersion = 1; } @@ -1719,12 +1739,9 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, return NULL; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (mtd->writesize < YAFFS_MIN_YAFFS2_CHUNK_SIZE || -#else - if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE || -#endif - mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) { + if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE || + mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) && + !options.inband_tags) { T(YAFFS_TRACE_ALWAYS, ("yaffs: MTD device does not have the " "right page sizes\n")); @@ -1784,9 +1801,10 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->startBlock = 0; dev->endBlock = nBlocks - 1; dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK; - dev->nDataBytesPerChunk = YAFFS_BYTES_PER_CHUNK; + dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK; dev->nReservedBlocks = 5; dev->nShortOpCaches = (options.no_cache) ? 0 : 10; + dev->inbandTags = options.inband_tags; /* ... and the functions. */ if (yaffsVersion == 2) { @@ -1799,15 +1817,14 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->spareBuffer = YMALLOC(mtd->oobsize); dev->isYaffs2 = 1; #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - dev->nDataBytesPerChunk = mtd->writesize; + dev->totalBytesPerChunk = mtd->writesize; dev->nChunksPerBlock = mtd->erasesize / mtd->writesize; #else - dev->nDataBytesPerChunk = mtd->oobblock; + dev->totalBytesPerChunk = mtd->oobblock; dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock; #endif nBlocks = mtd->size / mtd->erasesize; - dev->nCheckpointReservedBlocks = CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS; dev->startBlock = 0; dev->endBlock = nBlocks - 1; } else { @@ -1990,12 +2007,12 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) { buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock); buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock); + buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk); buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk); buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits); buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize); buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks); buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks); - buf += sprintf(buf, "nCheckptResBlocks.. %d\n", dev->nCheckpointReservedBlocks); buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint); buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated); buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes); @@ -2006,10 +2023,8 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads); buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures); buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies); - buf += - sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections); - buf += - sprintf(buf, "passiveGCs......... %d\n", + buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections); + buf += sprintf(buf, "passiveGCs......... %d\n", dev->passiveGarbageCollections); buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites); buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches); @@ -2025,6 +2040,7 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions); buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC); buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2); + buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags); return buf; } diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_getblockinfo.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_getblockinfo.h new file mode 100644 index 000000000..b9742ac0a --- /dev/null +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_getblockinfo.h @@ -0,0 +1,34 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2007 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning <charles@aleph1.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __YAFFS_GETBLOCKINFO_H__ +#define __YAFFS_GETBLOCKINFO_H__ + +#include "yaffs_guts.h" + +/* Function to manipulate block info */ +static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk) +{ + if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { + T(YAFFS_TRACE_ERROR, + (TSTR + ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR), + blk)); + YBUG(); + } + return &dev->blockInfo[blk - dev->internalStartBlock]; +} + +#endif diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.c index 2ab814691..223f2c130 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.c @@ -12,13 +12,14 @@ */ const char *yaffs_guts_c_version = - "$Id: yaffs_guts.c,v 1.49 2007-05-15 20:07:40 charles Exp $"; + "$Id: yaffs_guts.c,v 1.56 2008-05-08 23:23:26 charles Exp $"; #include "yportenv.h" #include "yaffsinterface.h" #include "yaffs_guts.h" #include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" #include "yaffs_tagscompat.h" #ifndef CONFIG_YAFFS_USE_OWN_SORT @@ -78,9 +79,6 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in); static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blockNo); -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, - int lineNo); static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, int chunkInNAND); @@ -121,23 +119,32 @@ static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, /* Function to calculate chunk and offset */ -static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, __u32 *chunk, __u32 *offset) +static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut, __u32 *offsetOut) { - if(dev->chunkShift){ - /* Easy-peasy power of 2 case */ - *chunk = (__u32)(addr >> dev->chunkShift); - *offset = (__u32)(addr & dev->chunkMask); - } - else if(dev->crumbsPerChunk) + int chunk; + __u32 offset; + + chunk = (__u32)(addr >> dev->chunkShift); + + if(dev->chunkDiv == 1) { - /* Case where we're using "crumbs" */ - *offset = (__u32)(addr & dev->crumbMask); - addr >>= dev->crumbShift; - *chunk = ((__u32)addr)/dev->crumbsPerChunk; - *offset += ((addr - (*chunk * dev->crumbsPerChunk)) << dev->crumbShift); + /* easy power of 2 case */ + offset = (__u32)(addr & dev->chunkMask); } else - YBUG(); + { + /* Non power-of-2 case */ + + loff_t chunkBase; + + chunk /= dev->chunkDiv; + + chunkBase = ((loff_t)chunk) * dev->nDataBytesPerChunk; + offset = (__u32)(addr - chunkBase); + } + + *chunkOut = chunk; + *offsetOut = offset; } /* Function to return the number of shifts for a power of 2 greater than or equal @@ -168,7 +175,7 @@ static __u32 ShiftsGE(__u32 x) /* Function to return the number of shifts to get a 1 in bit 0 */ -static __u32 ShiftDiv(__u32 x) +static __u32 Shifts(__u32 x) { int nShifts; @@ -200,16 +207,21 @@ static int yaffs_InitialiseTempBuffers(yaffs_Device *dev) for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) { dev->tempBuffer[i].line = 0; /* not in use */ dev->tempBuffer[i].buffer = buf = - YMALLOC_DMA(dev->nDataBytesPerChunk); + YMALLOC_DMA(dev->totalBytesPerChunk); } return buf ? YAFFS_OK : YAFFS_FAIL; } -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) +__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) { int i, j; + + dev->tempInUse++; + if(dev->tempInUse > dev->maxTemp) + dev->maxTemp = dev->tempInUse; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].line == 0) { dev->tempBuffer[i].line = lineNo; @@ -242,10 +254,13 @@ static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) } -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, +void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo) { int i; + + dev->tempInUse--; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].buffer == buffer) { dev->tempBuffer[i].line = 0; @@ -390,11 +405,14 @@ static int yaffs_SkipVerification(yaffs_Device *dev) return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL)); } +#if 0 static int yaffs_SkipFullVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_FULL)); } +#endif + static int yaffs_SkipNANDVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND)); @@ -597,7 +615,6 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn, int i; yaffs_Device *dev = obj->myDev; int ok = 1; - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; if (tn) { if (level > 0) { @@ -646,7 +663,6 @@ static void yaffs_VerifyFile(yaffs_Object *obj) __u32 lastChunk; __u32 x; __u32 i; - int ok; yaffs_Device *dev; yaffs_ExtendedTags tags; yaffs_Tnode *tn; @@ -829,7 +845,7 @@ static void yaffs_VerifyObjects(yaffs_Device *dev) { yaffs_Object *obj; int i; - struct list_head *lh; + struct ylist_head *lh; if(yaffs_SkipVerification(dev)) return; @@ -837,9 +853,9 @@ static void yaffs_VerifyObjects(yaffs_Device *dev) /* Iterate through the objects in each hash entry */ for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){ - list_for_each(lh, &dev->objectBucket[i].list) { + ylist_for_each(lh, &dev->objectBucket[i].list) { if (lh) { - obj = list_entry(lh, yaffs_Object, hashLink); + obj = ylist_entry(lh, yaffs_Object, hashLink); yaffs_VerifyObject(obj); } } @@ -915,7 +931,6 @@ static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, } - static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, const __u8 * data, yaffs_ExtendedTags * tags, @@ -992,7 +1007,11 @@ static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, /* Copy the data into the robustification buffer */ yaffs_HandleWriteChunkOk(dev, chunk, data, tags); - } while (writeOk != YAFFS_OK && attempts < yaffs_wr_attempts); + } while (writeOk != YAFFS_OK && + (yaffs_wr_attempts <= 0 || attempts <= yaffs_wr_attempts)); + + if(!writeOk) + chunk = -1; if (attempts > 1) { T(YAFFS_TRACE_ERROR, @@ -1143,6 +1162,10 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) * Must be a multiple of 32-bits */ tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + + /* make these things */ newTnodes = YMALLOC(nTnodes * tnodeSize); @@ -1233,15 +1256,21 @@ static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device * dev) dev->nFreeTnodes--; } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + return tn; } static yaffs_Tnode *yaffs_GetTnode(yaffs_Device * dev) { yaffs_Tnode *tn = yaffs_GetTnodeRaw(dev); + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); if(tn) - memset(tn, 0, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + memset(tn, 0, tnodeSize); return tn; } @@ -1262,6 +1291,8 @@ static void yaffs_FreeTnode(yaffs_Device * dev, yaffs_Tnode * tn) dev->freeTnodes = tn; dev->nFreeTnodes++; } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + } static void yaffs_DeinitialiseTnodes(yaffs_Device * dev) @@ -1854,7 +1885,7 @@ static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects) /* Hook them into the free list */ for (i = 0; i < nObjects - 1; i++) { newObjects[i].siblings.next = - (struct list_head *)(&newObjects[i + 1]); + (struct ylist_head *)(&newObjects[i + 1]); } newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects; @@ -1894,9 +1925,9 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) tn->myDev = dev; tn->chunkId = -1; tn->variantType = YAFFS_OBJECT_TYPE_UNKNOWN; - INIT_LIST_HEAD(&(tn->hardLinks)); - INIT_LIST_HEAD(&(tn->hashLink)); - INIT_LIST_HEAD(&tn->siblings); + YINIT_LIST_HEAD(&(tn->hardLinks)); + YINIT_LIST_HEAD(&(tn->hashLink)); + YINIT_LIST_HEAD(&tn->siblings); /* Add it to the lost and found directory. * NB Can't put root or lostNFound in lostNFound so @@ -1907,6 +1938,8 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) } } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + return tn; } @@ -1937,8 +1970,8 @@ static void yaffs_UnhashObject(yaffs_Object * tn) yaffs_Device *dev = tn->myDev; /* If it is still linked into the bucket list, free from the list */ - if (!list_empty(&tn->hashLink)) { - list_del_init(&tn->hashLink); + if (!ylist_empty(&tn->hashLink)) { + ylist_del_init(&tn->hashLink); bucket = yaffs_HashFunction(tn->objectId); dev->objectBucket[bucket].count--; } @@ -1964,9 +1997,12 @@ static void yaffs_FreeObject(yaffs_Object * tn) yaffs_UnhashObject(tn); /* Link into the free list. */ - tn->siblings.next = (struct list_head *)(dev->freeObjects); + tn->siblings.next = (struct ylist_head *)(dev->freeObjects); dev->freeObjects = tn; dev->nFreeObjects++; + + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + } #ifdef __KERNEL__ @@ -2007,7 +2043,7 @@ static void yaffs_InitialiseObjects(yaffs_Device * dev) dev->nFreeObjects = 0; for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) { - INIT_LIST_HEAD(&dev->objectBucket[i].list); + YINIT_LIST_HEAD(&dev->objectBucket[i].list); dev->objectBucket[i].count = 0; } @@ -2058,7 +2094,7 @@ static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) */ int found = 0; - struct list_head *i; + struct ylist_head *i; __u32 n = (__u32) bucket; @@ -2068,10 +2104,10 @@ static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) found = 1; n += YAFFS_NOBJECT_BUCKETS; if (1 || dev->objectBucket[bucket].count > 0) { - list_for_each(i, &dev->objectBucket[bucket].list) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { /* If there is already one in the list */ if (i - && list_entry(i, yaffs_Object, + && ylist_entry(i, yaffs_Object, hashLink)->objectId == n) { found = 0; } @@ -2088,7 +2124,7 @@ static void yaffs_HashObject(yaffs_Object * in) int bucket = yaffs_HashFunction(in->objectId); yaffs_Device *dev = in->myDev; - list_add(&in->hashLink, &dev->objectBucket[bucket].list); + ylist_add(&in->hashLink, &dev->objectBucket[bucket].list); dev->objectBucket[bucket].count++; } @@ -2096,13 +2132,13 @@ static void yaffs_HashObject(yaffs_Object * in) yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number) { int bucket = yaffs_HashFunction(number); - struct list_head *i; + struct ylist_head *i; yaffs_Object *in; - list_for_each(i, &dev->objectBucket[bucket].list) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { /* Look if it is in the list */ if (i) { - in = list_entry(i, yaffs_Object, hashLink); + in = ylist_entry(i, yaffs_Object, hashLink); if (in->objectId == number) { #ifdef __KERNEL__ /* Don't tell the VFS about this one if it is defered free */ @@ -2123,7 +2159,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, { yaffs_Object *theObject; - yaffs_Tnode *tn; + yaffs_Tnode *tn = NULL; if (number < 0) { number = yaffs_CreateNewObjectNumber(dev); @@ -2171,7 +2207,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, theObject->variant.fileVariant.top = tn; break; case YAFFS_OBJECT_TYPE_DIRECTORY: - INIT_LIST_HEAD(&theObject->variant.directoryVariant. + YINIT_LIST_HEAD(&theObject->variant.directoryVariant. children); break; case YAFFS_OBJECT_TYPE_SYMLINK: @@ -2238,7 +2274,7 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, const YCHAR * aliasString, __u32 rdev) { yaffs_Object *in; - YCHAR *str; + YCHAR *str = NULL; yaffs_Device *dev = parent->myDev; @@ -2296,7 +2332,7 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, equivalentObject; in->variant.hardLinkVariant.equivalentObjectId = equivalentObject->objectId; - list_add(&in->hardLinks, &equivalentObject->hardLinks); + ylist_add(&in->hardLinks, &equivalentObject->hardLinks); break; case YAFFS_OBJECT_TYPE_FILE: case YAFFS_OBJECT_TYPE_DIRECTORY: @@ -2457,7 +2493,7 @@ int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, existingTarget = yaffs_FindObjectByName(newDir, newName); if (existingTarget && existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && - !list_empty(&existingTarget->variant.directoryVariant.children)) { + !ylist_empty(&existingTarget->variant.directoryVariant.children)) { /* There is a target that is a non-empty directory, so we fail */ return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */ } else if (existingTarget && existingTarget != obj) { @@ -2801,6 +2837,40 @@ static int yaffs_FindBlockForAllocation(yaffs_Device * dev) } + +static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev) +{ + if(!dev->nCheckpointBlocksRequired){ + /* Not a valid value so recalculate */ + int nBytes = 0; + int nBlocks; + int devBlocks = (dev->endBlock - dev->startBlock + 1); + int tnodeSize; + + tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + + nBytes += sizeof(yaffs_CheckpointValidity); + nBytes += sizeof(yaffs_CheckpointDevice); + nBytes += devBlocks * sizeof(yaffs_BlockInfo); + nBytes += devBlocks * dev->chunkBitmapStride; + nBytes += (sizeof(yaffs_CheckpointObject) + sizeof(__u32)) * (dev->nObjectsCreated - dev->nFreeObjects); + nBytes += (tnodeSize + sizeof(__u32)) * (dev->nTnodesCreated - dev->nFreeTnodes); + nBytes += sizeof(yaffs_CheckpointValidity); + nBytes += sizeof(__u32); /* checksum*/ + + /* Round up and add 2 blocks to allow for some bad blocks, so add 3 */ + + nBlocks = (nBytes/(dev->nDataBytesPerChunk * dev->nChunksPerBlock)) + 3; + + dev->nCheckpointBlocksRequired = nBlocks; + } + + return dev->nCheckpointBlocksRequired; +} + // Check if there's space to allocate... // Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()? static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) @@ -2809,7 +2879,7 @@ static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) int reservedBlocks = dev->nReservedBlocks; int checkpointBlocks; - checkpointBlocks = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint; + checkpointBlocks = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(checkpointBlocks < 0) checkpointBlocks = 0; @@ -3037,7 +3107,7 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block) yaffs_ObjectHeader *oh; oh = (yaffs_ObjectHeader *)buffer; oh->isShrink = 0; - oh->shadowsObject = -1; + oh->shadowsObject = oh->inbandShadowsObject = -1; tags.extraShadows = 0; tags.extraIsShrinkHeader = 0; @@ -3142,7 +3212,7 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) do { maxTries++; - checkpointBlockAdjust = (dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint); + checkpointBlockAdjust = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(checkpointBlockAdjust < 0) checkpointBlockAdjust = 0; @@ -3628,7 +3698,7 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, oh->type = in->variantType; oh->yst_mode = in->yst_mode; - oh->shadowsObject = shadows; + oh->shadowsObject = oh->inbandShadowsObject = shadows; #ifdef CONFIG_YAFFS_WINCE oh->win_atime[0] = in->win_atime[0]; @@ -4220,7 +4290,11 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, int i; yaffs_Device *dev = in->myDev; int ok = 1; - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + if (tn) { if (level > 0) { @@ -4238,7 +4312,7 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, /* printf("write tnode at %d\n",baseOffset); */ ok = (yaffs_CheckpointWrite(dev,&baseOffset,sizeof(baseOffset)) == sizeof(baseOffset)); if(ok) - ok = (yaffs_CheckpointWrite(dev,tn,nTnodeBytes) == nTnodeBytes); + ok = (yaffs_CheckpointWrite(dev,tn,tnodeSize) == tnodeSize); } } @@ -4272,6 +4346,10 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) yaffs_FileStructure *fileStructPtr = &obj->variant.fileVariant; yaffs_Tnode *tn; int nread = 0; + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk)); @@ -4283,8 +4361,7 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) /* printf("read tnode at %d\n",baseChunk); */ tn = yaffs_GetTnodeRaw(dev); if(tn) - ok = (yaffs_CheckpointRead(dev,tn,(dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8) == - (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + ok = (yaffs_CheckpointRead(dev,tn,tnodeSize) == tnodeSize); else ok = 0; @@ -4315,7 +4392,7 @@ static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) yaffs_CheckpointObject cp; int i; int ok = 1; - struct list_head *lh; + struct ylist_head *lh; /* Iterate through the objects in each hash entry, @@ -4323,9 +4400,9 @@ static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) */ for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){ - list_for_each(lh, &dev->objectBucket[i].list) { + ylist_for_each(lh, &dev->objectBucket[i].list) { if (lh) { - obj = list_entry(lh, yaffs_Object, hashLink); + obj = ylist_entry(lh, yaffs_Object, hashLink); if (!obj->deferedFree) { yaffs_ObjectToCheckpointObject(&cp,obj); cp.structType = sizeof(cp); @@ -4383,7 +4460,7 @@ static int yaffs_ReadCheckpointObjects(yaffs_Device *dev) ok = yaffs_ReadCheckpointTnodes(obj); } else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { obj->hardLinks.next = - (struct list_head *) + (struct ylist_head *) hardList; hardList = obj; } @@ -4589,7 +4666,7 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, { int chunk; - int start; + __u32 start; int nToCopy; int n = nBytes; int nDone = 0; @@ -4617,10 +4694,10 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, cache = yaffs_FindChunkCache(in, chunk); /* If the chunk is already in the cache or it is less than a whole chunk - * then use the cache (if there is caching) + * or we're using inband tags then use the cache (if there is caching) * else bypass the cache. */ - if (cache || nToCopy != dev->nDataBytesPerChunk) { + if (cache || nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { if (dev->nShortOpCaches > 0) { /* If we can't find the data in the cache, then load it up. */ @@ -4709,7 +4786,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, { int chunk; - int start; + __u32 start; int nToCopy; int n = nBytes; int nDone = 0; @@ -4757,8 +4834,10 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, nToWriteBack = dev->nDataBytesPerChunk; } - if (nToCopy != dev->nDataBytesPerChunk) { - /* An incomplete start or end chunk (or maybe both start and end chunk) */ + if (nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { + /* An incomplete start or end chunk (or maybe both start and end chunk), + * or we're using inband tags, so we want to use the cache buffers. + */ if (dev->nShortOpCaches > 0) { yaffs_ChunkCache *cache; /* If we can't find the data in the cache, then load the cache */ @@ -4846,7 +4925,8 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, } } else { - + /* A full chunk. Write directly from the supplied buffer. */ + #ifdef CONFIG_YAFFS_WINCE /* Under WinCE can't do direct transfer. Need to use a local buffer. * This is because we otherwise screw up WinCE's memory mapper @@ -4865,7 +4945,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, 0); yaffs_ReleaseTempBuffer(dev, localBuffer, __LINE__); #else - /* A full chunk. Write directly from the supplied buffer. */ + chunkWritten = yaffs_WriteChunkDataToObject(in, chunk, buffer, dev->nDataBytesPerChunk, @@ -4943,7 +5023,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) { int oldFileSize = in->variant.fileVariant.fileSize; - int newSizeOfPartialChunk; + __u32 newSizeOfPartialChunk; int newFullChunks; yaffs_Device *dev = in->myDev; @@ -4956,11 +5036,11 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) yaffs_CheckGarbageCollection(dev); if (in->variantType != YAFFS_OBJECT_TYPE_FILE) { - return yaffs_GetFileSize(in); + return YAFFS_FAIL; } if (newSize == oldFileSize) { - return oldFileSize; + return YAFFS_OK; } if (newSize < oldFileSize) { @@ -5005,7 +5085,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) (newSize < oldFileSize) ? 1 : 0, 0); } - return newSize; + return YAFFS_OK; } loff_t yaffs_GetFileSize(yaffs_Object * obj) @@ -5058,7 +5138,7 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in) if (in->myDev->isYaffs2 && (in->parent != in->myDev->deletedDir)) { /* Move to the unlinked directory so we have a record that it was deleted. */ - yaffs_ChangeObjectName(in, in->myDev->deletedDir,"deleted", 0, 0); + yaffs_ChangeObjectName(in, in->myDev->deletedDir,_Y("deleted"), 0, 0); } @@ -5096,7 +5176,7 @@ static int yaffs_UnlinkFile(yaffs_Object * in) if (immediateDeletion) { retVal = yaffs_ChangeObjectName(in, in->myDev->deletedDir, - "deleted", 0, 0); + _Y("deleted"), 0, 0); T(YAFFS_TRACE_TRACING, (TSTR("yaffs: immediate deletion of file %d" TENDSTR), in->objectId)); @@ -5109,7 +5189,7 @@ static int yaffs_UnlinkFile(yaffs_Object * in) } else { retVal = yaffs_ChangeObjectName(in, in->myDev->unlinkedDir, - "unlinked", 0, 0); + _Y("unlinked"), 0, 0); } } @@ -5144,7 +5224,7 @@ int yaffs_DeleteFile(yaffs_Object * in) static int yaffs_DeleteDirectory(yaffs_Object * in) { /* First check that the directory is empty. */ - if (list_empty(&in->variant.directoryVariant.children)) { + if (ylist_empty(&in->variant.directoryVariant.children)) { return yaffs_DoGenericObjectDeletion(in); } @@ -5164,7 +5244,7 @@ static int yaffs_DeleteHardLink(yaffs_Object * in) /* remove this hardlink from the list assocaited with the equivalent * object */ - list_del(&in->hardLinks); + ylist_del(&in->hardLinks); return yaffs_DoGenericObjectDeletion(in); } @@ -5196,7 +5276,7 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { return yaffs_DeleteHardLink(obj); - } else if (!list_empty(&obj->hardLinks)) { + } else if (!ylist_empty(&obj->hardLinks)) { /* Curve ball: We're unlinking an object that has a hardlink. * * This problem arises because we are not strictly following @@ -5215,10 +5295,10 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) int retVal; YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - hl = list_entry(obj->hardLinks.next, yaffs_Object, hardLinks); + hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks); - list_del_init(&hl->hardLinks); - list_del_init(&hl->siblings); + ylist_del_init(&hl->hardLinks); + ylist_del_init(&hl->siblings); yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1); @@ -5325,13 +5405,13 @@ static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList) if (in) { /* Add the hardlink pointers */ hl->variant.hardLinkVariant.equivalentObject = in; - list_add(&hl->hardLinks, &in->hardLinks); + ylist_add(&hl->hardLinks, &in->hardLinks); } else { /* Todo Need to report/handle this better. * Got a problem... hardlink to a non-existant object */ hl->variant.hardLinkVariant.equivalentObject = NULL; - INIT_LIST_HEAD(&hl->hardLinks); + YINIT_LIST_HEAD(&hl->hardLinks); } @@ -5371,7 +5451,7 @@ static int yaffs_Scan(yaffs_Device * dev) yaffs_BlockState state; yaffs_Object *hardList = NULL; yaffs_BlockInfo *bi; - int sequenceNumber; + __u32 sequenceNumber; yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; @@ -5488,6 +5568,8 @@ static int yaffs_Scan(yaffs_Device * dev) for (blockIterator = startIterator; !alloc_failed && blockIterator <= endIterator; blockIterator++) { + YYIELD(); + if (dev->isYaffs2) { /* get the block to scan in the correct order */ blk = blockIndex[blockIterator].block; @@ -5548,8 +5630,7 @@ static int yaffs_Scan(yaffs_Device * dev) bi->sequenceNumber)) { T(YAFFS_TRACE_ALWAYS, (TSTR - ("yaffs: Allocation block %d was not highest sequence id:" - " block seq = %d, dev seq = %d" + ("yaffs: Allocation block %d was not highest sequence id: block seq = %d, dev seq = %d" TENDSTR), blk,bi->sequenceNumber,dev->sequenceNumber)); } } @@ -5723,7 +5804,7 @@ static int yaffs_Scan(yaffs_Device * dev) /* Set up as a directory */ parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; - INIT_LIST_HEAD(&parent->variant. + YINIT_LIST_HEAD(&parent->variant. directoryVariant. children); } else if (parent->variantType != @@ -5735,8 +5816,7 @@ static int yaffs_Scan(yaffs_Device * dev) T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: attempting to use non-directory as" - " a directory in scan. Put in lost+found." + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found." TENDSTR))); parent = dev->lostNFoundDir; } @@ -5781,7 +5861,7 @@ static int yaffs_Scan(yaffs_Device * dev) equivalentObjectId = oh->equivalentObjectId; in->hardLinks.next = - (struct list_head *) + (struct ylist_head *) hardList; hardList = in; break; @@ -5840,16 +5920,16 @@ static int yaffs_Scan(yaffs_Device * dev) * just delete them. */ { - struct list_head *i; - struct list_head *n; + struct ylist_head *i; + struct ylist_head *n; yaffs_Object *l; /* Soft delete all the unlinked files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->unlinkedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } } @@ -5938,7 +6018,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) yaffs_BlockState state; yaffs_Object *hardList = NULL; yaffs_BlockInfo *bi; - int sequenceNumber; + __u32 sequenceNumber; yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; @@ -6053,8 +6133,10 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Sort the blocks */ #ifndef CONFIG_YAFFS_USE_OWN_SORT - yaffs_qsort(blockIndex, nBlocksToScan, - sizeof(yaffs_BlockIndex), ybicmp); + { + /* Use qsort now. */ + yaffs_qsort(blockIndex, nBlocksToScan, sizeof(yaffs_BlockIndex), ybicmp); + } #else { /* Dungy old bubble sort... */ @@ -6265,6 +6347,12 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) NULL); oh = (yaffs_ObjectHeader *) chunkData; + + if(dev->inbandTags){ + /* Fix up the header if they got corrupted by inband tags */ + oh->shadowsObject = oh->inbandShadowsObject; + oh->isShrink = oh->inbandIsShrink; + } if (!in) in = yaffs_FindOrCreateObjectByNumber(dev, tags.objectId, oh->type); @@ -6275,8 +6363,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* TODO Hoosterman we have a problem! */ T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: Could not make object for object %d " - "at chunk %d during scan" + ("yaffs tragedy: Could not make object for object %d at chunk %d during scan" TENDSTR), tags.objectId, chunk)); } @@ -6434,7 +6521,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Set up as a directory */ parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; - INIT_LIST_HEAD(&parent->variant. + YINIT_LIST_HEAD(&parent->variant. directoryVariant. children); } else if (parent->variantType != @@ -6446,8 +6533,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: attempting to use non-directory as" - " a directory in scan. Put in lost+found." + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found." TENDSTR))); parent = dev->lostNFoundDir; } @@ -6498,7 +6584,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) in->variant.hardLinkVariant.equivalentObjectId = equivalentObjectId; in->hardLinks.next = - (struct list_head *) hardList; + (struct ylist_head *) hardList; hardList = in; } break; @@ -6558,27 +6644,27 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) * Sort out state of unlinked and deleted objects. */ { - struct list_head *i; - struct list_head *n; + struct ylist_head *i; + struct ylist_head *n; yaffs_Object *l; /* Soft delete all the unlinked files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->unlinkedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } } /* Soft delete all the deletedDir files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->deletedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } @@ -6605,7 +6691,7 @@ static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj) if(dev && dev->removeObjectCallback) dev->removeObjectCallback(obj); - list_del_init(&obj->siblings); + ylist_del_init(&obj->siblings); obj->parent = NULL; } @@ -6631,14 +6717,14 @@ static void yaffs_AddObjectToDirectory(yaffs_Object * directory, if (obj->siblings.prev == NULL) { /* Not initialised */ - INIT_LIST_HEAD(&obj->siblings); + YINIT_LIST_HEAD(&obj->siblings); - } else if (!list_empty(&obj->siblings)) { + } else if (!ylist_empty(&obj->siblings)) { /* If it is holed up somewhere else, un hook it */ yaffs_RemoveObjectFromDirectory(obj); } /* Now add it */ - list_add(&obj->siblings, &directory->variant.directoryVariant.children); + ylist_add(&obj->siblings, &directory->variant.directoryVariant.children); obj->parent = directory; if (directory == obj->myDev->unlinkedDir @@ -6654,7 +6740,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, { int sum; - struct list_head *i; + struct ylist_head *i; YCHAR buffer[YAFFS_MAX_NAME_LENGTH + 1]; yaffs_Object *l; @@ -6679,9 +6765,9 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, sum = yaffs_CalcNameSum(name); - list_for_each(i, &directory->variant.directoryVariant.children) { + ylist_for_each(i, &directory->variant.directoryVariant.children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_CheckObjectDetailsLoaded(l); @@ -6713,7 +6799,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, int (*fn) (yaffs_Object *)) { - struct list_head *i; + struct ylist_head *i; yaffs_Object *l; if (!theDir) { @@ -6730,9 +6816,9 @@ int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, YBUG(); } - list_for_each(i, &theDir->variant.directoryVariant.children) { + ylist_for_each(i, &theDir->variant.directoryVariant.children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); if (l && !fn(l)) { return YAFFS_FAIL; } @@ -6821,12 +6907,12 @@ int yaffs_GetObjectFileLength(yaffs_Object * obj) int yaffs_GetObjectLinkCount(yaffs_Object * obj) { int count = 0; - struct list_head *i; + struct ylist_head *i; if (!obj->unlinked) { count++; /* the object itself */ } - list_for_each(i, &obj->hardLinks) { + ylist_for_each(i, &obj->hardLinks) { count++; /* add the hard links; */ } return count; @@ -7049,8 +7135,9 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* Check geometry parameters. */ - if ((dev->isYaffs2 && dev->nDataBytesPerChunk < 1024) || - (!dev->isYaffs2 && dev->nDataBytesPerChunk != 512) || + if ((!dev->inbandTags && dev->isYaffs2 && dev->totalBytesPerChunk < 1024) || + (!dev->isYaffs2 && dev->totalBytesPerChunk != 512) || + (dev->inbandTags && !dev->isYaffs2 ) || dev->nChunksPerBlock < 2 || dev->nReservedBlocks < 2 || dev->internalStartBlock <= 0 || @@ -7059,8 +7146,8 @@ int yaffs_GutsInitialise(yaffs_Device * dev) ) { T(YAFFS_TRACE_ALWAYS, (TSTR - ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s " - TENDSTR), dev->nDataBytesPerChunk, dev->isYaffs2 ? "2" : "")); + ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s, inbandTags %d " + TENDSTR), dev->totalBytesPerChunk, dev->isYaffs2 ? "2" : "", dev->inbandTags)); return YAFFS_FAIL; } @@ -7069,6 +7156,12 @@ int yaffs_GutsInitialise(yaffs_Device * dev) (TSTR("yaffs: InitialiseNAND failed" TENDSTR))); return YAFFS_FAIL; } + + /* Sort out space for inband tags, if required */ + if(dev->inbandTags) + dev->nDataBytesPerChunk = dev->totalBytesPerChunk - sizeof(yaffs_PackedTags2TagsPart); + else + dev->nDataBytesPerChunk = dev->totalBytesPerChunk; /* Got the right mix of functions? */ if (!yaffs_CheckDevFunctions(dev)) { @@ -7104,22 +7197,14 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* * Calculate all the chunk size manipulation numbers: */ - /* Start off assuming it is a power of 2 */ - dev->chunkShift = ShiftDiv(dev->nDataBytesPerChunk); - dev->chunkMask = (1<<dev->chunkShift) - 1; - - if(dev->nDataBytesPerChunk == (dev->chunkMask + 1)){ - /* Yes it is a power of 2, disable crumbs */ - dev->crumbMask = 0; - dev->crumbShift = 0; - dev->crumbsPerChunk = 0; - } else { - /* Not a power of 2, use crumbs instead */ - dev->crumbShift = ShiftDiv(sizeof(yaffs_PackedTags2TagsPart)); - dev->crumbMask = (1<<dev->crumbShift)-1; - dev->crumbsPerChunk = dev->nDataBytesPerChunk/(1 << dev->crumbShift); - dev->chunkShift = 0; - dev->chunkMask = 0; + { + __u32 x = dev->nDataBytesPerChunk; + /* We always use dev->chunkShift and dev->chunkDiv */ + dev->chunkShift = Shifts(x); + x >>= dev->chunkShift; + dev->chunkDiv = x; + /* We only use chunk mask if chunkDiv is 1 */ + dev->chunkMask = (1<<dev->chunkShift) - 1; } @@ -7203,7 +7288,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) if (!init_failed && dev->nShortOpCaches > 0) { int i; - __u8 *buf; + void *buf; int srCacheBytes = dev->nShortOpCaches * sizeof(yaffs_ChunkCache); if (dev->nShortOpCaches > YAFFS_MAX_SHORT_OP_CACHES) { @@ -7219,7 +7304,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->srCache[i].object = NULL; dev->srCache[i].lastUse = 0; dev->srCache[i].dirty = 0; - dev->srCache[i].data = buf = YMALLOC_DMA(dev->nDataBytesPerChunk); + dev->srCache[i].data = buf = YMALLOC_DMA(dev->totalBytesPerChunk); } if(!buf) init_failed = 1; @@ -7345,6 +7430,7 @@ void yaffs_Deinitialise(yaffs_Device * dev) YFREE(dev->tempBuffer[i].buffer); } + dev->isMounted = 0; } @@ -7410,7 +7496,7 @@ int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) nFree -= ((dev->nReservedBlocks + 1) * dev->nChunksPerBlock); /* Now we figure out how much to reserve for the checkpoint and report that... */ - blocksForCheckpoint = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint; + blocksForCheckpoint = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(blocksForCheckpoint < 0) blocksForCheckpoint = 0; @@ -7448,22 +7534,25 @@ static void yaffs_VerifyFreeChunks(yaffs_Device * dev) /*---------------------------------------- YAFFS test code ----------------------*/ #define yaffs_CheckStruct(structure,syze, name) \ + do { \ if(sizeof(structure) != syze) \ { \ T(YAFFS_TRACE_ALWAYS,(TSTR("%s should be %d but is %d\n" TENDSTR),\ name,syze,sizeof(structure))); \ return YAFFS_FAIL; \ - } + } \ + } while(0) static int yaffs_CheckStructures(void) { -/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags") */ -/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion") */ -/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare") */ +/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags"); */ +/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion"); */ +/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare"); */ #ifndef CONFIG_YAFFS_TNODE_LIST_DEBUG - yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode") + yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode"); +#endif +#ifndef CONFIG_YAFFS_WINCE + yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader"); #endif - yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader") - return YAFFS_OK; } diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.h index ea06c1a38..b9b2ea194 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_guts.h @@ -90,7 +90,7 @@ #define YAFFS_MAX_SHORT_OP_CACHES 20 -#define YAFFS_N_TEMP_BUFFERS 4 +#define YAFFS_N_TEMP_BUFFERS 6 /* We limit the number attempts at sucessfully saving a chunk of data. * Small-page devices have 32 pages per block; large-page devices have 64. @@ -277,7 +277,7 @@ typedef struct { int softDeletions:10; /* number of soft deleted pages */ int pagesInUse:10; /* number of pages in use */ - yaffs_BlockState blockState:4; /* One of the above block states */ + unsigned blockState:4; /* One of the above block states. NB use unsigned because enum is sometimes an int */ __u32 needsRetiring:1; /* Data has failed on this block, need to get valid data off */ /* and retire the block. */ __u32 skipErasedCheck: 1; /* If this is set we can skip the erased check on this block */ @@ -303,7 +303,7 @@ typedef struct { __u16 sum__NoLongerUsed; /* checksum of name. No longer used */ YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - /* Thes following apply to directories, files, symlinks - not hard links */ + /* The following apply to directories, files, symlinks - not hard links */ __u32 yst_mode; /* protection */ #ifdef CONFIG_YAFFS_WINCE @@ -331,11 +331,14 @@ typedef struct { __u32 win_ctime[2]; __u32 win_atime[2]; __u32 win_mtime[2]; - __u32 roomToGrow[4]; #else - __u32 roomToGrow[10]; + __u32 roomToGrow[6]; + #endif + __u32 inbandShadowsObject; + __u32 inbandIsShrink; + __u32 reservedSpace[2]; int shadowsObject; /* This object header shadows the specified object if > 0 */ /* isShrink applies to object headers written when we shrink the file (ie resize) */ @@ -381,7 +384,7 @@ typedef struct { } yaffs_FileStructure; typedef struct { - struct list_head children; /* list of child links */ + struct ylist_head children; /* list of child links */ } yaffs_DirectoryStructure; typedef struct { @@ -424,14 +427,14 @@ struct yaffs_ObjectStruct { struct yaffs_DeviceStruct *myDev; /* The device I'm on */ - struct list_head hashLink; /* list of objects in this hash bucket */ + struct ylist_head hashLink; /* list of objects in this hash bucket */ - struct list_head hardLinks; /* all the equivalent hard linked objects */ + struct ylist_head hardLinks; /* all the equivalent hard linked objects */ /* directory structure stuff */ /* also used for linking up the free list */ struct yaffs_ObjectStruct *parent; - struct list_head siblings; + struct ylist_head siblings; /* Where's my object header in NAND? */ int chunkId; @@ -485,7 +488,7 @@ struct yaffs_ObjectList_struct { typedef struct yaffs_ObjectList_struct yaffs_ObjectList; typedef struct { - struct list_head list; + struct ylist_head list; int count; } yaffs_ObjectBucket; @@ -528,7 +531,7 @@ typedef struct { /*----------------- Device ---------------------------------*/ struct yaffs_DeviceStruct { - struct list_head devList; + struct ylist_head devList; const char *name; /* Entry parameters set up way early. Yaffs sets up the rest.*/ @@ -544,7 +547,7 @@ struct yaffs_DeviceStruct { /* Stuff used by the shared space checkpointing mechanism */ /* If this value is zero, then this mechanism is disabled */ - int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ +// int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ @@ -583,7 +586,7 @@ struct yaffs_DeviceStruct { yaffs_ExtendedTags * tags); int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo); int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo, - yaffs_BlockState * state, int *sequenceNumber); + yaffs_BlockState * state, __u32 *sequenceNumber); #endif int isYaffs2; @@ -598,7 +601,8 @@ struct yaffs_DeviceStruct { void (*markSuperBlockDirty)(void * superblock); int wideTnodesDisabled; /* Set to disable wide tnodes */ - + + YCHAR *pathDividers; /* String of legal path dividers */ /* End of stuff that must be set before initialisation. */ @@ -615,16 +619,14 @@ struct yaffs_DeviceStruct { __u32 tnodeWidth; __u32 tnodeMask; - /* Stuff to support various file offses to chunk/offset translations */ - /* "Crumbs" for nDataBytesPerChunk not being a power of 2 */ - __u32 crumbMask; - __u32 crumbShift; - __u32 crumbsPerChunk; - - /* Straight shifting for nDataBytesPerChunk being a power of 2 */ - __u32 chunkShift; - __u32 chunkMask; + /* Stuff for figuring out file offset to chunk conversions */ + __u32 chunkShift; /* Shift value */ + __u32 chunkDiv; /* Divisor after shifting: 1 for power-of-2 sizes */ + __u32 chunkMask; /* Mask to use for power-of-2 case */ + /* Stuff to handle inband tags */ + int inbandTags; + __u32 totalBytesPerChunk; #ifdef __KERNEL__ @@ -663,6 +665,8 @@ struct yaffs_DeviceStruct { __u32 checkpointSum; __u32 checkpointXor; + int nCheckpointBlocksRequired; /* Number of blocks needed to store current checkpoint set */ + /* Block Info */ yaffs_BlockInfo *blockInfo; __u8 *chunkBits; /* bitmap of chunks in use */ @@ -744,9 +748,11 @@ struct yaffs_DeviceStruct { int nUnlinkedFiles; /* Count of unlinked files. */ int nBackgroundDeletions; /* Count of background deletions. */ - + + /* Temporary buffer management */ yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS]; int maxTemp; + int tempInUse; int unmanagedTempAllocations; int unmanagedTempDeallocations; @@ -758,7 +764,7 @@ struct yaffs_DeviceStruct { typedef struct yaffs_DeviceStruct yaffs_Device; -/* The static layout of bllock usage etc is stored in the super block header */ +/* The static layout of block usage etc is stored in the super block header */ typedef struct { int StructType; int version; @@ -797,18 +803,6 @@ typedef struct { __u32 head; } yaffs_CheckpointValidity; -/* Function to manipulate block info */ -static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk) -{ - if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { - T(YAFFS_TRACE_ERROR, - (TSTR - ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR), - blk)); - YBUG(); - } - return &dev->blockInfo[blk - dev->internalStartBlock]; -} /*----------------------- YAFFS Functions -----------------------*/ @@ -899,4 +893,7 @@ void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn); int yaffs_CheckFF(__u8 * buffer, int nBytes); void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi); +__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); +void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo); + #endif diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.c index 466e5a44c..4888b96f6 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.c @@ -12,7 +12,7 @@ */ const char *yaffs_mtdif_c_version = - "$Id: yaffs_mtdif.c,v 1.19 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_mtdif.c,v 1.21 2007-12-13 15:35:18 wookey Exp $"; #include "yportenv.h" @@ -24,7 +24,7 @@ const char *yaffs_mtdif_c_version = #include "linux/time.h" #include "linux/mtd/nand.h" -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) static struct nand_oobinfo yaffs_oobinfo = { .useecc = 1, .eccbytes = 6, @@ -36,7 +36,7 @@ static struct nand_oobinfo yaffs_noeccinfo = { }; #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) static inline void translate_spare2oob(const yaffs_Spare *spare, __u8 *oob) { oob[0] = spare->tagByte0; @@ -75,14 +75,14 @@ int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) @@ -139,14 +139,14 @@ int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.h index 317600cac..511b0176a 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif.h @@ -18,6 +18,11 @@ #include "yaffs_guts.h" +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) +extern struct nand_oobinfo yaffs_oobinfo; +extern struct nand_oobinfo yaffs_noeccinfo; +#endif + int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare); int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1-compat.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1-compat.c deleted file mode 100644 index 6ea675611..000000000 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1-compat.c +++ /dev/null @@ -1,434 +0,0 @@ -From ian@brightstareng.com Fri May 18 15:06:49 2007 -From ian@brightstareng.com Fri May 18 15:08:21 2007 -Received: from 206.173.66.57.ptr.us.xo.net ([206.173.66.57] helo=zebra.brightstareng.com) - by apollo.linkchoose.co.uk with esmtp (Exim 4.60) - (envelope-from <ian@brightstareng.com>) - id 1Hp380-00011e-T6 - for david.goodenough@linkchoose.co.uk; Fri, 18 May 2007 15:08:21 +0100 -Received: from localhost (localhost.localdomain [127.0.0.1]) - by zebra.brightstareng.com (Postfix) with ESMTP - id 4819F28C004; Fri, 18 May 2007 10:07:49 -0400 (EDT) -Received: from zebra.brightstareng.com ([127.0.0.1]) - by localhost (zebra [127.0.0.1]) (amavisd-new, port 10024) with ESMTP - id 05328-06; Fri, 18 May 2007 10:07:16 -0400 (EDT) -Received: from pippin (unknown [192.168.1.25]) - by zebra.brightstareng.com (Postfix) with ESMTP - id 8BEF528C1BC; Fri, 18 May 2007 10:06:53 -0400 (EDT) -From: Ian McDonnell <ian@brightstareng.com> -To: David Goodenough <david.goodenough@linkchoose.co.uk> -Subject: Re: something tested this time -- yaffs_mtdif1-compat.c -Date: Fri, 18 May 2007 10:06:49 -0400 -User-Agent: KMail/1.9.1 -References: <200705142207.06909.ian@brightstareng.com> <200705171131.53536.ian@brightstareng.com> <200705181334.32166.david.goodenough@linkchoose.co.uk> -In-Reply-To: <200705181334.32166.david.goodenough@linkchoose.co.uk> -Cc: Andrea Conti <alyf@alyf.net>, - Charles Manning <manningc2@actrix.gen.nz> -MIME-Version: 1.0 -Content-Type: Multipart/Mixed; - boundary="Boundary-00=_5LbTGmt62YoutxM" -Message-Id: <200705181006.49860.ian@brightstareng.com> -X-Virus-Scanned: by amavisd-new at brightstareng.com -Status: R -X-Status: NT -X-KMail-EncryptionState: -X-KMail-SignatureState: -X-KMail-MDN-Sent: - ---Boundary-00=_5LbTGmt62YoutxM -Content-Type: text/plain; - charset="iso-8859-15" -Content-Transfer-Encoding: 7bit -Content-Disposition: inline - -David, Andrea, - -On Friday 18 May 2007 08:34, you wrote: -> Yea team. With this fix in place (I put it in the wrong place -> at first) I can now mount and ls the Yaffs partition without -> an error messages! - -Good news! - -Attached is a newer yaffs_mtdif1.c with a bandaid to help the -2.6.18 and 2.6.19 versions of MTD not trip on the oob read. -See the LINUX_VERSION_CODE conditional in -nandmtd1_ReadChunkWithTagsFromNAND. - --imcd - ---Boundary-00=_5LbTGmt62YoutxM -Content-Type: text/x-csrc; - charset="iso-8859-15"; - name="yaffs_mtdif1.c" -Content-Transfer-Encoding: 7bit -Content-Disposition: attachment; - filename="yaffs_mtdif1.c" - -/* - * YAFFS: Yet another FFS. A NAND-flash specific file system. - * yaffs_mtdif1.c NAND mtd interface functions for small-page NAND. - * - * Copyright (C) 2002 Aleph One Ltd. - * for Toby Churchill Ltd and Brightstar Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -/* - * This module provides the interface between yaffs_nand.c and the - * MTD API. This version is used when the MTD interface supports the - * 'mtd_oob_ops' style calls to read_oob and write_oob, circa 2.6.17, - * and we have small-page NAND device. - * - * These functions are invoked via function pointers in yaffs_nand.c. - * This replaces functionality provided by functions in yaffs_mtdif.c - * and the yaffs_TagsCompatability functions in yaffs_tagscompat.c that are - * called in yaffs_mtdif.c when the function pointers are NULL. - * We assume the MTD layer is performing ECC (useNANDECC is true). - */ - -#include "yportenv.h" -#include "yaffs_guts.h" -#include "yaffs_packedtags1.h" -#include "yaffs_tagscompat.h" // for yaffs_CalcTagsECC - -#include "linux/kernel.h" -#include "linux/version.h" -#include "linux/types.h" -#include "linux/mtd/mtd.h" - -/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $"; - -#ifndef CONFIG_YAFFS_9BYTE_TAGS -# define YTAG1_SIZE 8 -#else -# define YTAG1_SIZE 9 -#endif - -#if 0 -/* Use the following nand_ecclayout with MTD when using - * CONFIG_YAFFS_9BYTE_TAGS and the older on-NAND tags layout. - * If you have existing Yaffs images and the byte order differs from this, - * adjust 'oobfree' to match your existing Yaffs data. - * - * This nand_ecclayout scatters/gathers to/from the old-yaffs layout with the - * pageStatus byte (at NAND spare offset 4) scattered/gathered from/to - * the 9th byte. - * - * Old-style on-NAND format: T0,T1,T2,T3,P,B,T4,T5,E0,E1,E2,T6,T7,E3,E4,E5 - * We have/need PackedTags1 plus pageStatus: T0,T1,T2,T3,T4,T5,T6,T7,P - * where Tn are the tag bytes, En are MTD's ECC bytes, P is the pageStatus - * byte and B is the small-page bad-block indicator byte. - */ -static struct nand_ecclayout nand_oob_16 = { - .eccbytes = 6, - .eccpos = { 8, 9, 10, 13, 14, 15 }, - .oobavail = 9, - .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } } -}; -#endif - -/* Write a chunk (page) of data to NAND. - * - * Caller always provides ExtendedTags data which are converted to a more - * compact (packed) form for storage in NAND. A mini-ECC runs over the - * contents of the tags meta-data; used to valid the tags when read. - * - * - Pack ExtendedTags to PackedTags1 form - * - Compute mini-ECC for PackedTags1 - * - Write data and packed tags to NAND. - * - * Note: Due to the use of the PackedTags1 meta-data which does not include - * a full sequence number (as found in the larger PackedTags2 form) it is - * necessary for Yaffs to re-write a chunk/page (just once) to mark it as - * discarded and dirty. This is not ideal: newer NAND parts are supposed - * to be written just once. When Yaffs performs this operation, this - * function is called with a NULL data pointer -- calling MTD write_oob - * without data is valid usage (2.6.17). - * - * Any underlying MTD error results in YAFFS_FAIL. - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, - int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkBytes = dev->nDataBytesPerChunk; - loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; - struct mtd_oob_ops ops; - yaffs_PackedTags1 pt1; - int retval; - - /* we assume that PackedTags1 and yaffs_Tags are compatible */ - compile_time_assertion(sizeof(yaffs_PackedTags1) == 12); - compile_time_assertion(sizeof(yaffs_Tags) == 8); - - yaffs_PackTags1(&pt1, etags); - yaffs_CalcTagsECC((yaffs_Tags *)&pt1); - - /* When deleting a chunk, the upper layer provides only skeletal - * etags, one with chunkDeleted set. However, we need to update the - * tags, not erase them completely. So we use the NAND write property - * that only zeroed-bits stick and set tag bytes to all-ones and - * zero just the (not) deleted bit. - */ -#ifndef CONFIG_YAFFS_9BYTE_TAGS - if (etags->chunkDeleted) { - memset(&pt1, 0xff, 8); - /* clear delete status bit to indicate deleted */ - pt1.deleted = 0; - } -#else - ((__u8 *)&pt1)[8] = 0xff; - if (etags->chunkDeleted) { - memset(&pt1, 0xff, 8); - /* zero pageStatus byte to indicate deleted */ - ((__u8 *)&pt1)[8] = 0; - } -#endif - - memset(&ops, 0, sizeof(ops)); - ops.mode = MTD_OOB_AUTO; - ops.len = (data) ? chunkBytes : 0; - ops.ooblen = YTAG1_SIZE; - ops.datbuf = (__u8 *)data; - ops.oobbuf = (__u8 *)&pt1; - - retval = mtd->write_oob(mtd, addr, &ops); - if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "write_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); - } - return retval ? YAFFS_FAIL : YAFFS_OK; -} - -/* Return with empty ExtendedTags but add eccResult. - */ -static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval) -{ - if (etags) { - memset(etags, 0, sizeof(*etags)); - etags->eccResult = eccResult; - } - return retval; -} - -/* Read a chunk (page) from NAND. - * - * Caller expects ExtendedTags data to be usable even on error; that is, - * all members except eccResult and blockBad are zeroed. - * - * - Check ECC results for data (if applicable) - * - Check for blank/erased block (return empty ExtendedTags if blank) - * - Check the PackedTags1 mini-ECC (correct if necessary/possible) - * - Convert PackedTags1 to ExtendedTags - * - Update eccResult and blockBad members to refect state. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, - int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkBytes = dev->nDataBytesPerChunk; - loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; - int eccres = YAFFS_ECC_RESULT_NO_ERROR; - struct mtd_oob_ops ops; - yaffs_PackedTags1 pt1; - int retval; - int deleted; - - memset(&ops, 0, sizeof(ops)); - ops.mode = MTD_OOB_AUTO; - ops.len = (data) ? chunkBytes : 0; - ops.ooblen = YTAG1_SIZE; - ops.datbuf = data; - ops.oobbuf = (__u8 *)&pt1; - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) - /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; - * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. - */ - ops.len = (ops.datbuf) ? ops.len : ops.ooblen; -#endif - /* Read page and oob using MTD. - * Check status and determine ECC result. - */ - retval = mtd->read_oob(mtd, addr, &ops); - if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "read_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); - } - - switch (retval) { - case 0: - /* no error */ - break; - - case -EUCLEAN: - /* MTD's ECC fixed the data */ - eccres = YAFFS_ECC_RESULT_FIXED; - dev->eccFixed++; - break; - - case -EBADMSG: - /* MTD's ECC could not fix the data */ - dev->eccUnfixed++; - /* fall into... */ - default: - rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); - etags->blockBad = (mtd->block_isbad)(mtd, addr); - return YAFFS_FAIL; - } - - /* Check for a blank/erased chunk. - */ - if (yaffs_CheckFF((__u8 *)&pt1, 8)) { - /* when blank, upper layers want eccResult to be <= NO_ERROR */ - return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); - } - -#ifndef CONFIG_YAFFS_9BYTE_TAGS - /* Read deleted status (bit) then return it to it's non-deleted - * state before performing tags mini-ECC check. pt1.deleted is - * inverted. - */ - deleted = !pt1.deleted; - pt1.deleted = 1; -#else - (void) deleted; /* not used */ -#endif - - /* Check the packed tags mini-ECC and correct if necessary/possible. - */ - retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); - switch (retval) { - case 0: - /* no tags error, use MTD result */ - break; - case 1: - /* recovered tags-ECC error */ - dev->tagsEccFixed++; - eccres = YAFFS_ECC_RESULT_FIXED; - break; - default: - /* unrecovered tags-ECC error */ - dev->tagsEccUnfixed++; - return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); - } - - /* Unpack the tags to extended form and set ECC result. - * [set shouldBeFF just to keep yaffs_UnpackTags1 happy] - */ - pt1.shouldBeFF = 0xFFFFFFFF; - yaffs_UnpackTags1(etags, &pt1); - etags->eccResult = eccres; - - /* Set deleted state. - */ -#ifndef CONFIG_YAFFS_9BYTE_TAGS - etags->chunkDeleted = deleted; -#else - etags->chunkDeleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); -#endif - return YAFFS_OK; -} - -/* Mark a block bad. - * - * This is a persistant state. - * Use of this function should be rare. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) -{ - struct mtd_info * mtd = dev->genericDevice; - int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; - int retval; - - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); - - retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); - return (retval) ? YAFFS_FAIL : YAFFS_OK; -} - -/* Check any MTD prerequists. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -static int nandmtd1_TestPrerequists(struct mtd_info * mtd) -{ - /* 2.6.18 has mtd->ecclayout->oobavail */ - /* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */ - int oobavail = mtd->ecclayout->oobavail; - - if (oobavail < YTAG1_SIZE) { - yaffs_trace(YAFFS_TRACE_ERROR, - "mtd device has only %d bytes for tags, need %d", - oobavail, YTAG1_SIZE); - return YAFFS_FAIL; - } - return YAFFS_OK; -} - -/* Query for the current state of a specific block. - * - * Examine the tags of the first chunk of the block and return the state: - * - YAFFS_BLOCK_STATE_DEAD, the block is marked bad - * - YAFFS_BLOCK_STATE_NEEDS_SCANNING, the block is in use - * - YAFFS_BLOCK_STATE_EMPTY, the block is clean - * - * Always returns YAFFS_OK. - */ -int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * pState, int *pSequenceNumber) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkNo = blockNo * dev->nChunksPerBlock; - yaffs_ExtendedTags etags; - int state = YAFFS_BLOCK_STATE_DEAD; - int seqnum = 0; - int retval; - - /* We don't yet have a good place to test for MTD config prerequists. - * Do it here as we are called during the initial scan. - */ - if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) { - return YAFFS_FAIL; - } - - retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); - if (etags.blockBad) { - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad", blockNo); - state = YAFFS_BLOCK_STATE_DEAD; - } - else if (etags.chunkUsed) { - state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; - seqnum = etags.sequenceNumber; - } - else { - state = YAFFS_BLOCK_STATE_EMPTY; - } - - *pState = state; - *pSequenceNumber = seqnum; - - /* query always succeeds */ - return YAFFS_OK; -} - -#endif /*KERNEL_VERSION*/ - ---Boundary-00=_5LbTGmt62YoutxM-- - - - diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1.c index 36d5adec5..2b33c2cfe 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif1.c @@ -34,9 +34,9 @@ #include "linux/mtd/mtd.h" /* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $"; +const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.7 2007-12-13 15:35:18 wookey Exp $"; #ifndef CONFIG_YAFFS_9BYTE_TAGS # define YTAG1_SIZE 8 @@ -189,7 +189,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,20)) /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. */ @@ -288,7 +288,7 @@ int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; int retval; - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); + yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo); retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); return (retval) ? YAFFS_FAIL : YAFFS_OK; @@ -327,6 +327,7 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, { struct mtd_info * mtd = dev->genericDevice; int chunkNo = blockNo * dev->nChunksPerBlock; + loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk; yaffs_ExtendedTags etags; int state = YAFFS_BLOCK_STATE_DEAD; int seqnum = 0; @@ -340,11 +341,16 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, } retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); + etags.blockBad = (mtd->block_isbad)(mtd, addr); if (etags.blockBad) { yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad", blockNo); + "block %d is marked bad\n", blockNo); state = YAFFS_BLOCK_STATE_DEAD; } + else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) { + /* bad tags, need to look more closely */ + state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; + } else if (etags.chunkUsed) { state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; seqnum = etags.sequenceNumber; @@ -360,4 +366,4 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, return YAFFS_OK; } -#endif /*KERNEL_VERSION*/ +#endif /*MTD_VERSION*/ diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif2.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif2.c index cdad0734b..3768b9b07 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif2.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_mtdif2.c @@ -14,7 +14,7 @@ /* mtd interface for YAFFS2 */ const char *yaffs_mtdif2_c_version = - "$Id: yaffs_mtdif2.c,v 1.17 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_mtdif2.c,v 1.20 2008-05-05 07:58:58 charles Exp $"; #include "yportenv.h" @@ -27,19 +27,23 @@ const char *yaffs_mtdif2_c_version = #include "yaffs_packedtags2.h" +/* NB For use with inband tags.... + * We assume that the data buffer is of size totalBytersPerChunk so that we can also + * use it to load the tags. + */ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #else size_t dummy; #endif int retval = 0; - loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; + loff_t addr; yaffs_PackedTags2 pt; @@ -47,47 +51,42 @@ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); - -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (tags) - yaffs_PackTags2(&pt, tags); + + + addr = ((loff_t) chunkInNAND) * dev->totalBytesPerChunk; + + /* For yaffs2 writing there must be both data and tags. + * If we're using inband tags, then the tags are stuffed into + * the end of the data buffer. + */ + if(!data || !tags) + BUG(); + else if(dev->inbandTags){ + yaffs_PackedTags2TagsPart *pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->nDataBytesPerChunk); + yaffs_PackTags2TagsPart(pt2tp,tags); + } else - BUG(); /* both tags and data should always be present */ - - if (data) { - ops.mode = MTD_OOB_AUTO; - ops.ooblen = sizeof(pt); - ops.len = dev->nDataBytesPerChunk; - ops.ooboffs = 0; - ops.datbuf = (__u8 *)data; - ops.oobbuf = (void *)&pt; - retval = mtd->write_oob(mtd, addr, &ops); - } else - BUG(); /* both tags and data should always be present */ -#else - if (tags) { yaffs_PackTags2(&pt, tags); - } + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) + ops.mode = MTD_OOB_AUTO; + ops.ooblen = (dev->inbandTags) ? 0 : sizeof(pt); + ops.len = dev->totalBytesPerChunk; + ops.ooboffs = 0; + ops.datbuf = (__u8 *)data; + ops.oobbuf = (dev->inbandTags) ? NULL : (void *)&pt; + retval = mtd->write_oob(mtd, addr, &ops); - if (data && tags) { - if (dev->useNANDECC) - retval = - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); - else - retval = - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); +#else + if (!dev->inbandTags) { + retval = + mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, + &dummy, data, (__u8 *) & pt, NULL); } else { - if (data) - retval = - mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy, - data); - if (tags) - retval = - mtd->write_oob(mtd, addr, mtd->oobsize, &dummy, - (__u8 *) & pt); - + retval = + mtd->write(mtd, addr, dev->totalBytesPerChunk, &dummy, + data); } #endif @@ -101,11 +100,12 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; + int localData = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; @@ -115,10 +115,21 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); + + if(dev->inbandTags){ + + if(!data) { + localData = 1; + data = yaffs_GetTempBuffer(dev,__LINE__); + } + + + } + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (data && !tags) - retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk, + if (dev->inbandTags || (data && !tags)) + retval = mtd->read(mtd, addr, dev->totalBytesPerChunk, &dummy, data); else if (tags) { ops.mode = MTD_OOB_AUTO; @@ -130,38 +141,43 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, retval = mtd->read_oob(mtd, addr, &ops); } #else - if (data && tags) { - if (dev->useNANDECC) { - retval = - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, dev->spareBuffer, - NULL); - } else { - retval = - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, + if (!dev->inbandTags && data && tags) { + + retval = mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, &dummy, data, dev->spareBuffer, NULL); - } } else { if (data) retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk, &dummy, data); - if (tags) + if (!dev->inbandTags && tags) retval = mtd->read_oob(mtd, addr, mtd->oobsize, &dummy, dev->spareBuffer); } #endif - memcpy(&pt, dev->spareBuffer, sizeof(pt)); - if (tags) - yaffs_UnpackTags2(tags, &pt); + if(dev->inbandTags){ + if(tags){ + yaffs_PackedTags2TagsPart * pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; + yaffs_UnpackTags2TagsPart(tags,pt2tp); + } + } + else { + if (tags){ + memcpy(&pt, dev->spareBuffer, sizeof(pt)); + yaffs_UnpackTags2(tags, &pt); + } + } + if(localData) + yaffs_ReleaseTempBuffer(dev,data,__LINE__); + if(tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR) - tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; - + tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; if (retval == 0) return YAFFS_OK; else diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nand.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nand.c index 4e250338d..af4215772 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nand.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nand.c @@ -12,12 +12,13 @@ */ const char *yaffs_nand_c_version = - "$Id: yaffs_nand.c,v 1.7 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_nand.c,v 1.9 2008-05-05 07:58:58 charles Exp $"; #include "yaffs_nand.h" #include "yaffs_tagscompat.h" #include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * buffer, @@ -98,7 +99,7 @@ int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo) int yaffs_QueryInitialBlockState(yaffs_Device * dev, int blockNo, yaffs_BlockState * state, - unsigned *sequenceNumber) + __u32 *sequenceNumber) { blockNo -= dev->blockOffset; diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nandemul2k.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nandemul2k.h index cd2e96f7a..c8576b307 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nandemul2k.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_nandemul2k.h @@ -22,13 +22,13 @@ int nandemul2k_WriteChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, const __u8 * data, - yaffs_ExtendedTags * tags); + const yaffs_ExtendedTags * tags); int nandemul2k_ReadChunkWithTagsFromNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * tags); int nandemul2k_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int nandemul2k_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, int *sequenceNumber); + yaffs_BlockState * state, __u32 *sequenceNumber); int nandemul2k_EraseBlockInNAND(struct yaffs_DeviceStruct *dev, int blockInNAND); int nandemul2k_InitialiseNAND(struct yaffs_DeviceStruct *dev); diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.c index e420f95da..957ed8bf0 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.c @@ -37,60 +37,70 @@ #define EXTRA_OBJECT_TYPE_SHIFT (28) #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT) -static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) + +static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart * ptt) { T(YAFFS_TRACE_MTD, (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR), - pt->t.objectId, pt->t.chunkId, pt->t.byteCount, - pt->t.sequenceNumber)); + ptt->objectId, ptt->chunkId, ptt->byteCount, + ptt->sequenceNumber)); +} +static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) +{ + yaffs_DumpPackedTags2TagsPart(&pt->t); } static void yaffs_DumpTags2(const yaffs_ExtendedTags * t) { T(YAFFS_TRACE_MTD, (TSTR - ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte " - "%d del %d ser %d seq %d" + ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d" TENDSTR), t->eccResult, t->blockBad, t->chunkUsed, t->objectId, t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, t->sequenceNumber)); } -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * ptt, const yaffs_ExtendedTags * t) { - pt->t.chunkId = t->chunkId; - pt->t.sequenceNumber = t->sequenceNumber; - pt->t.byteCount = t->byteCount; - pt->t.objectId = t->objectId; + ptt->chunkId = t->chunkId; + ptt->sequenceNumber = t->sequenceNumber; + ptt->byteCount = t->byteCount; + ptt->objectId = t->objectId; if (t->chunkId == 0 && t->extraHeaderInfoAvailable) { /* Store the extra header info instead */ /* We save the parent object in the chunkId */ - pt->t.chunkId = EXTRA_HEADER_INFO_FLAG + ptt->chunkId = EXTRA_HEADER_INFO_FLAG | t->extraParentObjectId; if (t->extraIsShrinkHeader) { - pt->t.chunkId |= EXTRA_SHRINK_FLAG; + ptt->chunkId |= EXTRA_SHRINK_FLAG; } if (t->extraShadows) { - pt->t.chunkId |= EXTRA_SHADOWS_FLAG; + ptt->chunkId |= EXTRA_SHADOWS_FLAG; } - pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK; - pt->t.objectId |= + ptt->objectId &= ~EXTRA_OBJECT_TYPE_MASK; + ptt->objectId |= (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT); if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { - pt->t.byteCount = t->extraEquivalentObjectId; + ptt->byteCount = t->extraEquivalentObjectId; } else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE) { - pt->t.byteCount = t->extraFileLength; + ptt->byteCount = t->extraFileLength; } else { - pt->t.byteCount = 0; + ptt->byteCount = 0; } } - yaffs_DumpPackedTags2(pt); + yaffs_DumpPackedTags2TagsPart(ptt); yaffs_DumpTags2(t); +} + + +void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +{ + yaffs_PackTags2TagsPart(&pt->t,t); #ifndef YAFFS_IGNORE_TAGS_ECC { @@ -101,13 +111,60 @@ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) #endif } -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) + +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * ptt) { memset(t, 0, sizeof(yaffs_ExtendedTags)); yaffs_InitialiseTags(t); + if (ptt->sequenceNumber != 0xFFFFFFFF) { + t->blockBad = 0; + t->chunkUsed = 1; + t->objectId = ptt->objectId; + t->chunkId = ptt->chunkId; + t->byteCount = ptt->byteCount; + t->chunkDeleted = 0; + t->serialNumber = 0; + t->sequenceNumber = ptt->sequenceNumber; + + /* Do extra header info stuff */ + + if (ptt->chunkId & EXTRA_HEADER_INFO_FLAG) { + t->chunkId = 0; + t->byteCount = 0; + + t->extraHeaderInfoAvailable = 1; + t->extraParentObjectId = + ptt->chunkId & (~(ALL_EXTRA_FLAGS)); + t->extraIsShrinkHeader = + (ptt->chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; + t->extraShadows = + (ptt->chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; + t->extraObjectType = + ptt->objectId >> EXTRA_OBJECT_TYPE_SHIFT; + t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; + + if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { + t->extraEquivalentObjectId = ptt->byteCount; + } else { + t->extraFileLength = ptt->byteCount; + } + } + } + + yaffs_DumpPackedTags2TagsPart(ptt); + yaffs_DumpTags2(t); + +} + + +void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) +{ + + yaffs_UnpackTags2TagsPart(t,&pt->t); + if (pt->t.sequenceNumber != 0xFFFFFFFF) { /* Page is in use */ #ifdef YAFFS_IGNORE_TAGS_ECC @@ -142,41 +199,10 @@ void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) } } #endif - t->blockBad = 0; - t->chunkUsed = 1; - t->objectId = pt->t.objectId; - t->chunkId = pt->t.chunkId; - t->byteCount = pt->t.byteCount; - t->chunkDeleted = 0; - t->serialNumber = 0; - t->sequenceNumber = pt->t.sequenceNumber; - - /* Do extra header info stuff */ - - if (pt->t.chunkId & EXTRA_HEADER_INFO_FLAG) { - t->chunkId = 0; - t->byteCount = 0; - - t->extraHeaderInfoAvailable = 1; - t->extraParentObjectId = - pt->t.chunkId & (~(ALL_EXTRA_FLAGS)); - t->extraIsShrinkHeader = - (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; - t->extraShadows = - (pt->t.chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; - t->extraObjectType = - pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT; - t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; - - if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { - t->extraEquivalentObjectId = pt->t.byteCount; - } else { - t->extraFileLength = pt->t.byteCount; - } - } } yaffs_DumpPackedTags2(pt); yaffs_DumpTags2(t); } + diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.h index c2242ffe7..75761d333 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_packedtags2.h @@ -33,6 +33,11 @@ typedef struct { yaffs_ECCOther ecc; } yaffs_PackedTags2; +/* Full packed tags with ECC, used for oob tags */ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t); void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt); + +/* Only the tags part (no ECC for use with inband tags */ +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * pt, const yaffs_ExtendedTags * t); +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * pt); #endif diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.c b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.c index 7622b1af7..ab756d06d 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.c +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.c @@ -14,6 +14,7 @@ #include "yaffs_guts.h" #include "yaffs_tagscompat.h" #include "yaffs_ecc.h" +#include "yaffs_getblockinfo.h" static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND); #ifdef NOTYET @@ -438,7 +439,7 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, yaffs_ECCResult eccResult; static yaffs_Spare spareFF; - static int init; + static int init = 0; if (!init) { memset(&spareFF, 0xFF, sizeof(spareFF)); @@ -497,9 +498,9 @@ int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, } int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, yaffs_BlockState * - state, - int *sequenceNumber) + int blockNo, + yaffs_BlockState *state, + __u32 *sequenceNumber) { yaffs_Spare spare0, spare1; diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.h index a61e3ba14..6549398ee 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yaffs_tagscompat.h @@ -30,8 +30,9 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, yaffs_BlockState * - state, int *sequenceNumber); + int blockNo, + yaffs_BlockState *state, + __u32 *sequenceNumber); void yaffs_CalcTagsECC(yaffs_Tags * tags); int yaffs_CheckECCOnTags(yaffs_Tags * tags); diff --git a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yportenv.h b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yportenv.h index 15ac28121..097b2a675 100644 --- a/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yportenv.h +++ b/target/linux/generic-2.6/files-2.6.25/fs/yaffs2/yportenv.h @@ -17,6 +17,14 @@ #ifndef __YPORTENV_H__ #define __YPORTENV_H__ +/* + * Define the MTD version in terms of Linux Kernel versions + * This allows yaffs to be used independantly of the kernel + * as well as with it. + */ + +#define MTD_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) + #if defined CONFIG_YAFFS_WINCE #include "ywinceenv.h" @@ -26,7 +34,10 @@ #include "moduleconfig.h" /* Linux kernel */ + #include <linux/version.h> +#define MTD_VERSION_CODE LINUX_VERSION_CODE + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) #include <linux/config.h> #endif @@ -90,6 +101,8 @@ #elif defined CONFIG_YAFFS_DIRECT +#define MTD_VERSION_CODE MTD_VERSION(2,6,22) + /* Direct interface */ #include "ydirectenv.h" @@ -180,8 +193,8 @@ extern unsigned int yaffs_wr_attempts; #define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p);} while(0) -#ifndef CONFIG_YAFFS_WINCE -#define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__)) +#ifndef YBUG +#define YBUG() do {T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__));} while(0) #endif #endif diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Kconfig b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Kconfig index 7b6f836cd..de1516390 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Kconfig +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Kconfig @@ -43,7 +43,8 @@ config YAFFS_9BYTE_TAGS format that you need to continue to support. New data written also uses the older-style format. Note: Use of this option generally requires that MTD's oob layout be adjusted to use the - older-style format. See notes on tags formats and MTD versions. + older-style format. See notes on tags formats and MTD versions + in yaffs_mtdif1.c. If unsure, say N. @@ -109,26 +110,6 @@ config YAFFS_DISABLE_LAZY_LOAD If unsure, say N. -config YAFFS_CHECKPOINT_RESERVED_BLOCKS - int "Reserved blocks for checkpointing" - depends on YAFFS_YAFFS2 - default 10 - help - Give the number of Blocks to reserve for checkpointing. - Checkpointing saves the state at unmount so that mounting is - much faster as a scan of all the flash to regenerate this state - is not needed. These Blocks are reserved per partition, so if - you have very small partitions the default (10) may be a mess - for you. You can set this value to 0, but that does not mean - checkpointing is disabled at all. There only won't be any - specially reserved blocks for checkpointing, so if there is - enough free space on the filesystem, it will be used for - checkpointing. - - If unsure, leave at default (10), but don't wonder if there are - always 2MB used on your large page device partition (10 x 2k - pagesize). When using small partitions or when being very small - on space, you probably want to set this to zero. config YAFFS_DISABLE_WIDE_TNODES bool "Turn off wide tnodes" diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Makefile b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Makefile index 73f46583f..382ee6142 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Makefile +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/Makefile @@ -5,7 +5,6 @@ obj-$(CONFIG_YAFFS_FS) += yaffs.o yaffs-y := yaffs_ecc.o yaffs_fs.o yaffs_guts.o yaffs_checkptrw.o -yaffs-y += yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o +yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o yaffs-y += yaffs_tagscompat.o yaffs_tagsvalidity.o -yaffs-y += yaffs_mtdif1.o yaffs_packedtags1.o -yaffs-y += yaffs_mtdif.o yaffs_mtdif2.o +yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/devextras.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/devextras.h index fcf2690a5..55c31219d 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/devextras.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/devextras.h @@ -14,194 +14,117 @@ */ /* - * This file is just holds extra declarations used during development. - * Most of these are from kernel includes placed here so we can use them in - * applications. + * This file is just holds extra declarations of macros that would normally + * be providesd in the Linux kernel. These macros have been written from + * scratch but are functionally equivalent to the Linux ones. * */ #ifndef __EXTRAS_H__ #define __EXTRAS_H__ -#if defined WIN32 -#define __inline__ __inline -#define new newHack -#endif - -#if !(defined __KERNEL__) || (defined WIN32) -/* User space defines */ +#if !(defined __KERNEL__) +/* Definition of types */ typedef unsigned char __u8; typedef unsigned short __u16; typedef unsigned __u32; +#endif + /* - * Simple doubly linked list implementation. - * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. + * This is a simple doubly linked list implementation that matches the + * way the Linux kernel doubly linked list implementation works. */ -#define prefetch(x) 1 - -struct list_head { - struct list_head *next, *prev; +struct ylist_head { + struct ylist_head *next; /* next in chain */ + struct ylist_head *prev; /* previous in chain */ }; -#define LIST_HEAD_INIT(name) { &(name), &(name) } -#define LIST_HEAD(name) \ - struct list_head name = LIST_HEAD_INIT(name) +/* Initialise a list head to an empty list */ +#define YINIT_LIST_HEAD(p) \ +do { \ + (p)->next = (p);\ + (p)->prev = (p); \ +} while(0) -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) -/* - * Insert a new entry between two known consecutive entries. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_add(struct list_head *new, - struct list_head *prev, - struct list_head *next) +/* Add an element to a list */ +static __inline__ void ylist_add(struct ylist_head *newEntry, + struct ylist_head *list) { - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; + struct ylist_head *listNext = list->next; + + list->next = newEntry; + newEntry->prev = list; + newEntry->next = listNext; + listNext->prev = newEntry; + } -/** - * list_add - add a new entry - * @new: new entry to be added - * @head: list head to add it after - * - * Insert a new entry after the specified head. - * This is good for implementing stacks. - */ -static __inline__ void list_add(struct list_head *new, struct list_head *head) -{ - __list_add(new, head, head->next); -} -/** - * list_add_tail - add a new entry - * @new: new entry to be added - * @head: list head to add it before - * - * Insert a new entry before the specified head. - * This is useful for implementing queues. - */ -static __inline__ void list_add_tail(struct list_head *new, - struct list_head *head) +/* Take an element out of its current list, with or without + * reinitialising the links.of the entry*/ +static __inline__ void ylist_del(struct ylist_head *entry) { - __list_add(new, head->prev, head); + struct ylist_head *listNext = entry->next; + struct ylist_head *listPrev = entry->prev; + + listNext->prev = listPrev; + listPrev->next = listNext; + } -/* - * Delete a list entry by making the prev/next entries - * point to each other. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_del(struct list_head *prev, - struct list_head *next) +static __inline__ void ylist_del_init(struct ylist_head *entry) { - next->prev = prev; - prev->next = next; + ylist_del(entry); + entry->next = entry->prev = entry; } -/** - * list_del - deletes entry from list. - * @entry: the element to delete from the list. - * Note: list_empty on entry does not return true after this, the entry is - * in an undefined state. - */ -static __inline__ void list_del(struct list_head *entry) -{ - __list_del(entry->prev, entry->next); -} -/** - * list_del_init - deletes entry from list and reinitialize it. - * @entry: the element to delete from the list. - */ -static __inline__ void list_del_init(struct list_head *entry) +/* Test if the list is empty */ +static __inline__ int ylist_empty(struct ylist_head *entry) { - __list_del(entry->prev, entry->next); - INIT_LIST_HEAD(entry); + return (entry->next == entry); } -/** - * list_empty - tests whether a list is empty - * @head: the list to test. + +/* ylist_entry takes a pointer to a list entry and offsets it to that + * we can find a pointer to the object it is embedded in. */ -static __inline__ int list_empty(struct list_head *head) -{ - return head->next == head; -} + + +#define ylist_entry(entry, type, member) \ + ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member))) + -/** - * list_splice - join two lists - * @list: the new list to add. - * @head: the place to add it in the first list. +/* ylist_for_each and list_for_each_safe iterate over lists. + * ylist_for_each_safe uses temporary storage to make the list delete safe */ -static __inline__ void list_splice(struct list_head *list, - struct list_head *head) -{ - struct list_head *first = list->next; - if (first != list) { - struct list_head *last = list->prev; - struct list_head *at = head->next; +#define ylist_for_each(itervar, list) \ + for (itervar = (list)->next; itervar != (list); itervar = itervar->next ) - first->prev = head; - head->next = first; +#define ylist_for_each_safe(itervar,saveVar, list) \ + for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \ + itervar = saveVar, saveVar = saveVar->next) - last->next = at; - at->prev = last; - } -} -/** - * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_struct within the struct. - */ -#define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) +#if !(defined __KERNEL__) + + +#ifndef WIN32 +#include <sys/stat.h> +#endif + + +#ifdef CONFIG_YAFFS_PROVIDE_DEFS +/* File types */ -/** - * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. - * @head: the head for your list. - */ -#define list_for_each(pos, head) \ - for (pos = (head)->next, prefetch(pos->next); pos != (head); \ - pos = pos->next, prefetch(pos->next)) - -/** - * list_for_each_safe - iterate over a list safe against removal - * of list entry - * @pos: the &struct list_head to use as a loop counter. - * @n: another &struct list_head to use as temporary storage - * @head: the head for your list. - */ -#define list_for_each_safe(pos, n, head) \ - for (pos = (head)->next, n = pos->next; pos != (head); \ - pos = n, n = pos->next) -/* - * File types - */ #define DT_UNKNOWN 0 #define DT_FIFO 1 #define DT_CHR 2 @@ -212,13 +135,13 @@ static __inline__ void list_splice(struct list_head *list, #define DT_SOCK 12 #define DT_WHT 14 + #ifndef WIN32 #include <sys/stat.h> #endif /* - * Attribute flags. These should be or-ed together to figure out what - * has been changed! + * Attribute flags. */ #define ATTR_MODE 1 #define ATTR_UID 2 @@ -227,10 +150,7 @@ static __inline__ void list_splice(struct list_head *list, #define ATTR_ATIME 16 #define ATTR_MTIME 32 #define ATTR_CTIME 64 -#define ATTR_ATIME_SET 128 -#define ATTR_MTIME_SET 256 -#define ATTR_FORCE 512 /* Not a change, but a change it */ -#define ATTR_ATTR_FLAG 1024 + struct iattr { unsigned int ia_valid; @@ -244,21 +164,18 @@ struct iattr { unsigned int ia_attr_flags; }; +#endif + + #define KERN_DEBUG #else -#ifndef WIN32 #include <linux/types.h> -#include <linux/list.h> #include <linux/fs.h> #include <linux/stat.h> -#endif #endif -#if defined WIN32 -#undef new -#endif #endif diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/moduleconfig.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/moduleconfig.h index 016391ca5..ac5af6f35 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/moduleconfig.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/moduleconfig.h @@ -54,11 +54,11 @@ that you need to continue to support. New data written also uses the older-style format. Note: Use of this option generally requires that MTD's oob layout be adjusted to use the older-style format. See notes on tags formats and -MTD versions. +MTD versions in yaffs_mtdif1.c. */ /* Default: Not selected */ /* Meaning: Use older-style on-NAND data format with pageStatus byte */ -#define CONFIG_YAFFS_9BYTE_TAGS +//#define CONFIG_YAFFS_9BYTE_TAGS #endif /* YAFFS_OUT_OF_TREE */ diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_checkptrw.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_checkptrw.c index 933a33fb8..68e6d0ce5 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_checkptrw.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_checkptrw.c @@ -12,11 +12,11 @@ */ const char *yaffs_checkptrw_c_version = - "$Id: yaffs_checkptrw.c,v 1.14 2007-05-15 20:07:40 charles Exp $"; + "$Id: yaffs_checkptrw.c,v 1.16 2008-05-05 07:58:58 charles Exp $"; #include "yaffs_checkptrw.h" - +#include "yaffs_getblockinfo.h" static int yaffs_CheckpointSpaceOk(yaffs_Device *dev) { @@ -142,7 +142,7 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) return 0; if(!dev->checkpointBuffer) - dev->checkpointBuffer = YMALLOC_DMA(dev->nDataBytesPerChunk); + dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk); if(!dev->checkpointBuffer) return 0; diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_ecc.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_ecc.c index e2860393d..9f5973a5b 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_ecc.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_ecc.c @@ -29,7 +29,7 @@ */ const char *yaffs_ecc_c_version = - "$Id: yaffs_ecc.c,v 1.9 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_ecc.c,v 1.10 2007-12-13 15:35:17 wookey Exp $"; #include "yportenv.h" diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_fs.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_fs.c index 67001b10e..ab6a3a7e0 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_fs.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_fs.c @@ -32,7 +32,7 @@ */ const char *yaffs_fs_c_version = - "$Id: yaffs_fs.c,v 1.63 2007-09-19 20:35:40 imcd Exp $"; + "$Id: yaffs_fs.c,v 1.66 2008-05-05 07:58:58 charles Exp $"; extern const char *yaffs_guts_c_version; #include <linux/version.h> @@ -53,6 +53,8 @@ extern const char *yaffs_guts_c_version; #include <linux/string.h> #include <linux/ctype.h> +#include "asm/div64.h" + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) #include <linux/statfs.h> /* Added NCB 15-8-2003 */ @@ -753,6 +755,8 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj) break; } + inode->i_flags |= S_NOATIME; + inode->i_ino = obj->objectId; inode->i_mode = obj->yst_mode; inode->i_uid = obj->yst_uid; @@ -1350,25 +1354,47 @@ static int yaffs_statfs(struct super_block *sb, struct statfs *buf) buf->f_type = YAFFS_MAGIC; buf->f_bsize = sb->s_blocksize; buf->f_namelen = 255; - if (sb->s_blocksize > dev->nDataBytesPerChunk) { - + + if(dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)){ + /* Do this if chunk size is not a power of 2 */ + + uint64_t bytesInDev; + uint64_t bytesFree; + + bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock +1))) * + ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk)); + + do_div(bytesInDev,sb->s_blocksize); /* bytesInDev becomes the number of blocks */ + buf->f_blocks = bytesInDev; + + bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) * + ((uint64_t)(dev->nDataBytesPerChunk)); + + do_div(bytesFree,sb->s_blocksize); + + buf->f_bfree = bytesFree; + + } else if (sb->s_blocksize > dev->nDataBytesPerChunk) { + buf->f_blocks = - (dev->endBlock - dev->startBlock + - 1) * dev->nChunksPerBlock / (sb->s_blocksize / - dev->nDataBytesPerChunk); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize / - dev->nDataBytesPerChunk); + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock / + (sb->s_blocksize / dev->nDataBytesPerChunk); + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) / + (sb->s_blocksize / dev->nDataBytesPerChunk); } else { - - buf->f_blocks = - (dev->endBlock - dev->startBlock + - 1) * dev->nChunksPerBlock * (dev->nDataBytesPerChunk / - sb->s_blocksize); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) * (dev->nDataBytesPerChunk / - sb->s_blocksize); + buf->f_blocks = + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock * + (dev->nDataBytesPerChunk / sb->s_blocksize); + + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) * + (dev->nDataBytesPerChunk / sb->s_blocksize); } + + buf->f_files = 0; buf->f_ffree = 0; buf->f_bavail = buf->f_bfree; @@ -1602,6 +1628,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, sb->s_magic = YAFFS_MAGIC; sb->s_op = &yaffs_super_ops; + sb->s_flags |= MS_NOATIME; if (!sb) printk(KERN_INFO "yaffs: sb is NULL\n"); @@ -1678,22 +1705,15 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, #ifdef CONFIG_YAFFS_AUTO_YAFFS2 if (yaffsVersion == 1 && -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - mtd->writesize >= 2048) { -#else - mtd->oobblock >= 2048) { -#endif + WRITE_SIZE(mtd) >= 2048) { T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n")); yaffsVersion = 2; } /* Added NCB 26/5/2006 for completeness */ - if (yaffsVersion == 2 && -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - mtd->writesize == 512) { -#else - mtd->oobblock == 512) { -#endif + if (yaffsVersion == 2 && + !options.inband_tags && + WRITE_SIZE(mtd) == 512){ T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs1\n")); yaffsVersion = 1; } @@ -1719,12 +1739,9 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, return NULL; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (mtd->writesize < YAFFS_MIN_YAFFS2_CHUNK_SIZE || -#else - if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE || -#endif - mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) { + if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE || + mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) && + !options.inband_tags) { T(YAFFS_TRACE_ALWAYS, ("yaffs: MTD device does not have the " "right page sizes\n")); @@ -1784,9 +1801,10 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->startBlock = 0; dev->endBlock = nBlocks - 1; dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK; - dev->nDataBytesPerChunk = YAFFS_BYTES_PER_CHUNK; + dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK; dev->nReservedBlocks = 5; dev->nShortOpCaches = (options.no_cache) ? 0 : 10; + dev->inbandTags = options.inband_tags; /* ... and the functions. */ if (yaffsVersion == 2) { @@ -1799,15 +1817,14 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->spareBuffer = YMALLOC(mtd->oobsize); dev->isYaffs2 = 1; #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - dev->nDataBytesPerChunk = mtd->writesize; + dev->totalBytesPerChunk = mtd->writesize; dev->nChunksPerBlock = mtd->erasesize / mtd->writesize; #else - dev->nDataBytesPerChunk = mtd->oobblock; + dev->totalBytesPerChunk = mtd->oobblock; dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock; #endif nBlocks = mtd->size / mtd->erasesize; - dev->nCheckpointReservedBlocks = CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS; dev->startBlock = 0; dev->endBlock = nBlocks - 1; } else { @@ -1990,12 +2007,12 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) { buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock); buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock); + buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk); buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk); buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits); buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize); buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks); buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks); - buf += sprintf(buf, "nCheckptResBlocks.. %d\n", dev->nCheckpointReservedBlocks); buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint); buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated); buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes); @@ -2006,10 +2023,8 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads); buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures); buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies); - buf += - sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections); - buf += - sprintf(buf, "passiveGCs......... %d\n", + buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections); + buf += sprintf(buf, "passiveGCs......... %d\n", dev->passiveGarbageCollections); buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites); buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches); @@ -2025,6 +2040,7 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions); buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC); buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2); + buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags); return buf; } diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_getblockinfo.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_getblockinfo.h new file mode 100644 index 000000000..b9742ac0a --- /dev/null +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_getblockinfo.h @@ -0,0 +1,34 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2007 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning <charles@aleph1.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __YAFFS_GETBLOCKINFO_H__ +#define __YAFFS_GETBLOCKINFO_H__ + +#include "yaffs_guts.h" + +/* Function to manipulate block info */ +static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk) +{ + if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { + T(YAFFS_TRACE_ERROR, + (TSTR + ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR), + blk)); + YBUG(); + } + return &dev->blockInfo[blk - dev->internalStartBlock]; +} + +#endif diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.c index 2ab814691..223f2c130 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.c @@ -12,13 +12,14 @@ */ const char *yaffs_guts_c_version = - "$Id: yaffs_guts.c,v 1.49 2007-05-15 20:07:40 charles Exp $"; + "$Id: yaffs_guts.c,v 1.56 2008-05-08 23:23:26 charles Exp $"; #include "yportenv.h" #include "yaffsinterface.h" #include "yaffs_guts.h" #include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" #include "yaffs_tagscompat.h" #ifndef CONFIG_YAFFS_USE_OWN_SORT @@ -78,9 +79,6 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in); static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blockNo); -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, - int lineNo); static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, int chunkInNAND); @@ -121,23 +119,32 @@ static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, /* Function to calculate chunk and offset */ -static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, __u32 *chunk, __u32 *offset) +static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut, __u32 *offsetOut) { - if(dev->chunkShift){ - /* Easy-peasy power of 2 case */ - *chunk = (__u32)(addr >> dev->chunkShift); - *offset = (__u32)(addr & dev->chunkMask); - } - else if(dev->crumbsPerChunk) + int chunk; + __u32 offset; + + chunk = (__u32)(addr >> dev->chunkShift); + + if(dev->chunkDiv == 1) { - /* Case where we're using "crumbs" */ - *offset = (__u32)(addr & dev->crumbMask); - addr >>= dev->crumbShift; - *chunk = ((__u32)addr)/dev->crumbsPerChunk; - *offset += ((addr - (*chunk * dev->crumbsPerChunk)) << dev->crumbShift); + /* easy power of 2 case */ + offset = (__u32)(addr & dev->chunkMask); } else - YBUG(); + { + /* Non power-of-2 case */ + + loff_t chunkBase; + + chunk /= dev->chunkDiv; + + chunkBase = ((loff_t)chunk) * dev->nDataBytesPerChunk; + offset = (__u32)(addr - chunkBase); + } + + *chunkOut = chunk; + *offsetOut = offset; } /* Function to return the number of shifts for a power of 2 greater than or equal @@ -168,7 +175,7 @@ static __u32 ShiftsGE(__u32 x) /* Function to return the number of shifts to get a 1 in bit 0 */ -static __u32 ShiftDiv(__u32 x) +static __u32 Shifts(__u32 x) { int nShifts; @@ -200,16 +207,21 @@ static int yaffs_InitialiseTempBuffers(yaffs_Device *dev) for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) { dev->tempBuffer[i].line = 0; /* not in use */ dev->tempBuffer[i].buffer = buf = - YMALLOC_DMA(dev->nDataBytesPerChunk); + YMALLOC_DMA(dev->totalBytesPerChunk); } return buf ? YAFFS_OK : YAFFS_FAIL; } -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) +__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) { int i, j; + + dev->tempInUse++; + if(dev->tempInUse > dev->maxTemp) + dev->maxTemp = dev->tempInUse; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].line == 0) { dev->tempBuffer[i].line = lineNo; @@ -242,10 +254,13 @@ static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) } -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, +void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo) { int i; + + dev->tempInUse--; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].buffer == buffer) { dev->tempBuffer[i].line = 0; @@ -390,11 +405,14 @@ static int yaffs_SkipVerification(yaffs_Device *dev) return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL)); } +#if 0 static int yaffs_SkipFullVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_FULL)); } +#endif + static int yaffs_SkipNANDVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND)); @@ -597,7 +615,6 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn, int i; yaffs_Device *dev = obj->myDev; int ok = 1; - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; if (tn) { if (level > 0) { @@ -646,7 +663,6 @@ static void yaffs_VerifyFile(yaffs_Object *obj) __u32 lastChunk; __u32 x; __u32 i; - int ok; yaffs_Device *dev; yaffs_ExtendedTags tags; yaffs_Tnode *tn; @@ -829,7 +845,7 @@ static void yaffs_VerifyObjects(yaffs_Device *dev) { yaffs_Object *obj; int i; - struct list_head *lh; + struct ylist_head *lh; if(yaffs_SkipVerification(dev)) return; @@ -837,9 +853,9 @@ static void yaffs_VerifyObjects(yaffs_Device *dev) /* Iterate through the objects in each hash entry */ for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){ - list_for_each(lh, &dev->objectBucket[i].list) { + ylist_for_each(lh, &dev->objectBucket[i].list) { if (lh) { - obj = list_entry(lh, yaffs_Object, hashLink); + obj = ylist_entry(lh, yaffs_Object, hashLink); yaffs_VerifyObject(obj); } } @@ -915,7 +931,6 @@ static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, } - static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, const __u8 * data, yaffs_ExtendedTags * tags, @@ -992,7 +1007,11 @@ static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, /* Copy the data into the robustification buffer */ yaffs_HandleWriteChunkOk(dev, chunk, data, tags); - } while (writeOk != YAFFS_OK && attempts < yaffs_wr_attempts); + } while (writeOk != YAFFS_OK && + (yaffs_wr_attempts <= 0 || attempts <= yaffs_wr_attempts)); + + if(!writeOk) + chunk = -1; if (attempts > 1) { T(YAFFS_TRACE_ERROR, @@ -1143,6 +1162,10 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) * Must be a multiple of 32-bits */ tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + + /* make these things */ newTnodes = YMALLOC(nTnodes * tnodeSize); @@ -1233,15 +1256,21 @@ static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device * dev) dev->nFreeTnodes--; } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + return tn; } static yaffs_Tnode *yaffs_GetTnode(yaffs_Device * dev) { yaffs_Tnode *tn = yaffs_GetTnodeRaw(dev); + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); if(tn) - memset(tn, 0, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + memset(tn, 0, tnodeSize); return tn; } @@ -1262,6 +1291,8 @@ static void yaffs_FreeTnode(yaffs_Device * dev, yaffs_Tnode * tn) dev->freeTnodes = tn; dev->nFreeTnodes++; } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + } static void yaffs_DeinitialiseTnodes(yaffs_Device * dev) @@ -1854,7 +1885,7 @@ static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects) /* Hook them into the free list */ for (i = 0; i < nObjects - 1; i++) { newObjects[i].siblings.next = - (struct list_head *)(&newObjects[i + 1]); + (struct ylist_head *)(&newObjects[i + 1]); } newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects; @@ -1894,9 +1925,9 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) tn->myDev = dev; tn->chunkId = -1; tn->variantType = YAFFS_OBJECT_TYPE_UNKNOWN; - INIT_LIST_HEAD(&(tn->hardLinks)); - INIT_LIST_HEAD(&(tn->hashLink)); - INIT_LIST_HEAD(&tn->siblings); + YINIT_LIST_HEAD(&(tn->hardLinks)); + YINIT_LIST_HEAD(&(tn->hashLink)); + YINIT_LIST_HEAD(&tn->siblings); /* Add it to the lost and found directory. * NB Can't put root or lostNFound in lostNFound so @@ -1907,6 +1938,8 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) } } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + return tn; } @@ -1937,8 +1970,8 @@ static void yaffs_UnhashObject(yaffs_Object * tn) yaffs_Device *dev = tn->myDev; /* If it is still linked into the bucket list, free from the list */ - if (!list_empty(&tn->hashLink)) { - list_del_init(&tn->hashLink); + if (!ylist_empty(&tn->hashLink)) { + ylist_del_init(&tn->hashLink); bucket = yaffs_HashFunction(tn->objectId); dev->objectBucket[bucket].count--; } @@ -1964,9 +1997,12 @@ static void yaffs_FreeObject(yaffs_Object * tn) yaffs_UnhashObject(tn); /* Link into the free list. */ - tn->siblings.next = (struct list_head *)(dev->freeObjects); + tn->siblings.next = (struct ylist_head *)(dev->freeObjects); dev->freeObjects = tn; dev->nFreeObjects++; + + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + } #ifdef __KERNEL__ @@ -2007,7 +2043,7 @@ static void yaffs_InitialiseObjects(yaffs_Device * dev) dev->nFreeObjects = 0; for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) { - INIT_LIST_HEAD(&dev->objectBucket[i].list); + YINIT_LIST_HEAD(&dev->objectBucket[i].list); dev->objectBucket[i].count = 0; } @@ -2058,7 +2094,7 @@ static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) */ int found = 0; - struct list_head *i; + struct ylist_head *i; __u32 n = (__u32) bucket; @@ -2068,10 +2104,10 @@ static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) found = 1; n += YAFFS_NOBJECT_BUCKETS; if (1 || dev->objectBucket[bucket].count > 0) { - list_for_each(i, &dev->objectBucket[bucket].list) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { /* If there is already one in the list */ if (i - && list_entry(i, yaffs_Object, + && ylist_entry(i, yaffs_Object, hashLink)->objectId == n) { found = 0; } @@ -2088,7 +2124,7 @@ static void yaffs_HashObject(yaffs_Object * in) int bucket = yaffs_HashFunction(in->objectId); yaffs_Device *dev = in->myDev; - list_add(&in->hashLink, &dev->objectBucket[bucket].list); + ylist_add(&in->hashLink, &dev->objectBucket[bucket].list); dev->objectBucket[bucket].count++; } @@ -2096,13 +2132,13 @@ static void yaffs_HashObject(yaffs_Object * in) yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number) { int bucket = yaffs_HashFunction(number); - struct list_head *i; + struct ylist_head *i; yaffs_Object *in; - list_for_each(i, &dev->objectBucket[bucket].list) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { /* Look if it is in the list */ if (i) { - in = list_entry(i, yaffs_Object, hashLink); + in = ylist_entry(i, yaffs_Object, hashLink); if (in->objectId == number) { #ifdef __KERNEL__ /* Don't tell the VFS about this one if it is defered free */ @@ -2123,7 +2159,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, { yaffs_Object *theObject; - yaffs_Tnode *tn; + yaffs_Tnode *tn = NULL; if (number < 0) { number = yaffs_CreateNewObjectNumber(dev); @@ -2171,7 +2207,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, theObject->variant.fileVariant.top = tn; break; case YAFFS_OBJECT_TYPE_DIRECTORY: - INIT_LIST_HEAD(&theObject->variant.directoryVariant. + YINIT_LIST_HEAD(&theObject->variant.directoryVariant. children); break; case YAFFS_OBJECT_TYPE_SYMLINK: @@ -2238,7 +2274,7 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, const YCHAR * aliasString, __u32 rdev) { yaffs_Object *in; - YCHAR *str; + YCHAR *str = NULL; yaffs_Device *dev = parent->myDev; @@ -2296,7 +2332,7 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, equivalentObject; in->variant.hardLinkVariant.equivalentObjectId = equivalentObject->objectId; - list_add(&in->hardLinks, &equivalentObject->hardLinks); + ylist_add(&in->hardLinks, &equivalentObject->hardLinks); break; case YAFFS_OBJECT_TYPE_FILE: case YAFFS_OBJECT_TYPE_DIRECTORY: @@ -2457,7 +2493,7 @@ int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, existingTarget = yaffs_FindObjectByName(newDir, newName); if (existingTarget && existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && - !list_empty(&existingTarget->variant.directoryVariant.children)) { + !ylist_empty(&existingTarget->variant.directoryVariant.children)) { /* There is a target that is a non-empty directory, so we fail */ return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */ } else if (existingTarget && existingTarget != obj) { @@ -2801,6 +2837,40 @@ static int yaffs_FindBlockForAllocation(yaffs_Device * dev) } + +static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev) +{ + if(!dev->nCheckpointBlocksRequired){ + /* Not a valid value so recalculate */ + int nBytes = 0; + int nBlocks; + int devBlocks = (dev->endBlock - dev->startBlock + 1); + int tnodeSize; + + tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + + nBytes += sizeof(yaffs_CheckpointValidity); + nBytes += sizeof(yaffs_CheckpointDevice); + nBytes += devBlocks * sizeof(yaffs_BlockInfo); + nBytes += devBlocks * dev->chunkBitmapStride; + nBytes += (sizeof(yaffs_CheckpointObject) + sizeof(__u32)) * (dev->nObjectsCreated - dev->nFreeObjects); + nBytes += (tnodeSize + sizeof(__u32)) * (dev->nTnodesCreated - dev->nFreeTnodes); + nBytes += sizeof(yaffs_CheckpointValidity); + nBytes += sizeof(__u32); /* checksum*/ + + /* Round up and add 2 blocks to allow for some bad blocks, so add 3 */ + + nBlocks = (nBytes/(dev->nDataBytesPerChunk * dev->nChunksPerBlock)) + 3; + + dev->nCheckpointBlocksRequired = nBlocks; + } + + return dev->nCheckpointBlocksRequired; +} + // Check if there's space to allocate... // Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()? static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) @@ -2809,7 +2879,7 @@ static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) int reservedBlocks = dev->nReservedBlocks; int checkpointBlocks; - checkpointBlocks = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint; + checkpointBlocks = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(checkpointBlocks < 0) checkpointBlocks = 0; @@ -3037,7 +3107,7 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block) yaffs_ObjectHeader *oh; oh = (yaffs_ObjectHeader *)buffer; oh->isShrink = 0; - oh->shadowsObject = -1; + oh->shadowsObject = oh->inbandShadowsObject = -1; tags.extraShadows = 0; tags.extraIsShrinkHeader = 0; @@ -3142,7 +3212,7 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) do { maxTries++; - checkpointBlockAdjust = (dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint); + checkpointBlockAdjust = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(checkpointBlockAdjust < 0) checkpointBlockAdjust = 0; @@ -3628,7 +3698,7 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, oh->type = in->variantType; oh->yst_mode = in->yst_mode; - oh->shadowsObject = shadows; + oh->shadowsObject = oh->inbandShadowsObject = shadows; #ifdef CONFIG_YAFFS_WINCE oh->win_atime[0] = in->win_atime[0]; @@ -4220,7 +4290,11 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, int i; yaffs_Device *dev = in->myDev; int ok = 1; - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + if (tn) { if (level > 0) { @@ -4238,7 +4312,7 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, /* printf("write tnode at %d\n",baseOffset); */ ok = (yaffs_CheckpointWrite(dev,&baseOffset,sizeof(baseOffset)) == sizeof(baseOffset)); if(ok) - ok = (yaffs_CheckpointWrite(dev,tn,nTnodeBytes) == nTnodeBytes); + ok = (yaffs_CheckpointWrite(dev,tn,tnodeSize) == tnodeSize); } } @@ -4272,6 +4346,10 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) yaffs_FileStructure *fileStructPtr = &obj->variant.fileVariant; yaffs_Tnode *tn; int nread = 0; + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk)); @@ -4283,8 +4361,7 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) /* printf("read tnode at %d\n",baseChunk); */ tn = yaffs_GetTnodeRaw(dev); if(tn) - ok = (yaffs_CheckpointRead(dev,tn,(dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8) == - (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + ok = (yaffs_CheckpointRead(dev,tn,tnodeSize) == tnodeSize); else ok = 0; @@ -4315,7 +4392,7 @@ static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) yaffs_CheckpointObject cp; int i; int ok = 1; - struct list_head *lh; + struct ylist_head *lh; /* Iterate through the objects in each hash entry, @@ -4323,9 +4400,9 @@ static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) */ for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){ - list_for_each(lh, &dev->objectBucket[i].list) { + ylist_for_each(lh, &dev->objectBucket[i].list) { if (lh) { - obj = list_entry(lh, yaffs_Object, hashLink); + obj = ylist_entry(lh, yaffs_Object, hashLink); if (!obj->deferedFree) { yaffs_ObjectToCheckpointObject(&cp,obj); cp.structType = sizeof(cp); @@ -4383,7 +4460,7 @@ static int yaffs_ReadCheckpointObjects(yaffs_Device *dev) ok = yaffs_ReadCheckpointTnodes(obj); } else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { obj->hardLinks.next = - (struct list_head *) + (struct ylist_head *) hardList; hardList = obj; } @@ -4589,7 +4666,7 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, { int chunk; - int start; + __u32 start; int nToCopy; int n = nBytes; int nDone = 0; @@ -4617,10 +4694,10 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, cache = yaffs_FindChunkCache(in, chunk); /* If the chunk is already in the cache or it is less than a whole chunk - * then use the cache (if there is caching) + * or we're using inband tags then use the cache (if there is caching) * else bypass the cache. */ - if (cache || nToCopy != dev->nDataBytesPerChunk) { + if (cache || nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { if (dev->nShortOpCaches > 0) { /* If we can't find the data in the cache, then load it up. */ @@ -4709,7 +4786,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, { int chunk; - int start; + __u32 start; int nToCopy; int n = nBytes; int nDone = 0; @@ -4757,8 +4834,10 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, nToWriteBack = dev->nDataBytesPerChunk; } - if (nToCopy != dev->nDataBytesPerChunk) { - /* An incomplete start or end chunk (or maybe both start and end chunk) */ + if (nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { + /* An incomplete start or end chunk (or maybe both start and end chunk), + * or we're using inband tags, so we want to use the cache buffers. + */ if (dev->nShortOpCaches > 0) { yaffs_ChunkCache *cache; /* If we can't find the data in the cache, then load the cache */ @@ -4846,7 +4925,8 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, } } else { - + /* A full chunk. Write directly from the supplied buffer. */ + #ifdef CONFIG_YAFFS_WINCE /* Under WinCE can't do direct transfer. Need to use a local buffer. * This is because we otherwise screw up WinCE's memory mapper @@ -4865,7 +4945,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, 0); yaffs_ReleaseTempBuffer(dev, localBuffer, __LINE__); #else - /* A full chunk. Write directly from the supplied buffer. */ + chunkWritten = yaffs_WriteChunkDataToObject(in, chunk, buffer, dev->nDataBytesPerChunk, @@ -4943,7 +5023,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) { int oldFileSize = in->variant.fileVariant.fileSize; - int newSizeOfPartialChunk; + __u32 newSizeOfPartialChunk; int newFullChunks; yaffs_Device *dev = in->myDev; @@ -4956,11 +5036,11 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) yaffs_CheckGarbageCollection(dev); if (in->variantType != YAFFS_OBJECT_TYPE_FILE) { - return yaffs_GetFileSize(in); + return YAFFS_FAIL; } if (newSize == oldFileSize) { - return oldFileSize; + return YAFFS_OK; } if (newSize < oldFileSize) { @@ -5005,7 +5085,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) (newSize < oldFileSize) ? 1 : 0, 0); } - return newSize; + return YAFFS_OK; } loff_t yaffs_GetFileSize(yaffs_Object * obj) @@ -5058,7 +5138,7 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in) if (in->myDev->isYaffs2 && (in->parent != in->myDev->deletedDir)) { /* Move to the unlinked directory so we have a record that it was deleted. */ - yaffs_ChangeObjectName(in, in->myDev->deletedDir,"deleted", 0, 0); + yaffs_ChangeObjectName(in, in->myDev->deletedDir,_Y("deleted"), 0, 0); } @@ -5096,7 +5176,7 @@ static int yaffs_UnlinkFile(yaffs_Object * in) if (immediateDeletion) { retVal = yaffs_ChangeObjectName(in, in->myDev->deletedDir, - "deleted", 0, 0); + _Y("deleted"), 0, 0); T(YAFFS_TRACE_TRACING, (TSTR("yaffs: immediate deletion of file %d" TENDSTR), in->objectId)); @@ -5109,7 +5189,7 @@ static int yaffs_UnlinkFile(yaffs_Object * in) } else { retVal = yaffs_ChangeObjectName(in, in->myDev->unlinkedDir, - "unlinked", 0, 0); + _Y("unlinked"), 0, 0); } } @@ -5144,7 +5224,7 @@ int yaffs_DeleteFile(yaffs_Object * in) static int yaffs_DeleteDirectory(yaffs_Object * in) { /* First check that the directory is empty. */ - if (list_empty(&in->variant.directoryVariant.children)) { + if (ylist_empty(&in->variant.directoryVariant.children)) { return yaffs_DoGenericObjectDeletion(in); } @@ -5164,7 +5244,7 @@ static int yaffs_DeleteHardLink(yaffs_Object * in) /* remove this hardlink from the list assocaited with the equivalent * object */ - list_del(&in->hardLinks); + ylist_del(&in->hardLinks); return yaffs_DoGenericObjectDeletion(in); } @@ -5196,7 +5276,7 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { return yaffs_DeleteHardLink(obj); - } else if (!list_empty(&obj->hardLinks)) { + } else if (!ylist_empty(&obj->hardLinks)) { /* Curve ball: We're unlinking an object that has a hardlink. * * This problem arises because we are not strictly following @@ -5215,10 +5295,10 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) int retVal; YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - hl = list_entry(obj->hardLinks.next, yaffs_Object, hardLinks); + hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks); - list_del_init(&hl->hardLinks); - list_del_init(&hl->siblings); + ylist_del_init(&hl->hardLinks); + ylist_del_init(&hl->siblings); yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1); @@ -5325,13 +5405,13 @@ static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList) if (in) { /* Add the hardlink pointers */ hl->variant.hardLinkVariant.equivalentObject = in; - list_add(&hl->hardLinks, &in->hardLinks); + ylist_add(&hl->hardLinks, &in->hardLinks); } else { /* Todo Need to report/handle this better. * Got a problem... hardlink to a non-existant object */ hl->variant.hardLinkVariant.equivalentObject = NULL; - INIT_LIST_HEAD(&hl->hardLinks); + YINIT_LIST_HEAD(&hl->hardLinks); } @@ -5371,7 +5451,7 @@ static int yaffs_Scan(yaffs_Device * dev) yaffs_BlockState state; yaffs_Object *hardList = NULL; yaffs_BlockInfo *bi; - int sequenceNumber; + __u32 sequenceNumber; yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; @@ -5488,6 +5568,8 @@ static int yaffs_Scan(yaffs_Device * dev) for (blockIterator = startIterator; !alloc_failed && blockIterator <= endIterator; blockIterator++) { + YYIELD(); + if (dev->isYaffs2) { /* get the block to scan in the correct order */ blk = blockIndex[blockIterator].block; @@ -5548,8 +5630,7 @@ static int yaffs_Scan(yaffs_Device * dev) bi->sequenceNumber)) { T(YAFFS_TRACE_ALWAYS, (TSTR - ("yaffs: Allocation block %d was not highest sequence id:" - " block seq = %d, dev seq = %d" + ("yaffs: Allocation block %d was not highest sequence id: block seq = %d, dev seq = %d" TENDSTR), blk,bi->sequenceNumber,dev->sequenceNumber)); } } @@ -5723,7 +5804,7 @@ static int yaffs_Scan(yaffs_Device * dev) /* Set up as a directory */ parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; - INIT_LIST_HEAD(&parent->variant. + YINIT_LIST_HEAD(&parent->variant. directoryVariant. children); } else if (parent->variantType != @@ -5735,8 +5816,7 @@ static int yaffs_Scan(yaffs_Device * dev) T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: attempting to use non-directory as" - " a directory in scan. Put in lost+found." + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found." TENDSTR))); parent = dev->lostNFoundDir; } @@ -5781,7 +5861,7 @@ static int yaffs_Scan(yaffs_Device * dev) equivalentObjectId = oh->equivalentObjectId; in->hardLinks.next = - (struct list_head *) + (struct ylist_head *) hardList; hardList = in; break; @@ -5840,16 +5920,16 @@ static int yaffs_Scan(yaffs_Device * dev) * just delete them. */ { - struct list_head *i; - struct list_head *n; + struct ylist_head *i; + struct ylist_head *n; yaffs_Object *l; /* Soft delete all the unlinked files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->unlinkedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } } @@ -5938,7 +6018,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) yaffs_BlockState state; yaffs_Object *hardList = NULL; yaffs_BlockInfo *bi; - int sequenceNumber; + __u32 sequenceNumber; yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; @@ -6053,8 +6133,10 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Sort the blocks */ #ifndef CONFIG_YAFFS_USE_OWN_SORT - yaffs_qsort(blockIndex, nBlocksToScan, - sizeof(yaffs_BlockIndex), ybicmp); + { + /* Use qsort now. */ + yaffs_qsort(blockIndex, nBlocksToScan, sizeof(yaffs_BlockIndex), ybicmp); + } #else { /* Dungy old bubble sort... */ @@ -6265,6 +6347,12 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) NULL); oh = (yaffs_ObjectHeader *) chunkData; + + if(dev->inbandTags){ + /* Fix up the header if they got corrupted by inband tags */ + oh->shadowsObject = oh->inbandShadowsObject; + oh->isShrink = oh->inbandIsShrink; + } if (!in) in = yaffs_FindOrCreateObjectByNumber(dev, tags.objectId, oh->type); @@ -6275,8 +6363,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* TODO Hoosterman we have a problem! */ T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: Could not make object for object %d " - "at chunk %d during scan" + ("yaffs tragedy: Could not make object for object %d at chunk %d during scan" TENDSTR), tags.objectId, chunk)); } @@ -6434,7 +6521,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Set up as a directory */ parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; - INIT_LIST_HEAD(&parent->variant. + YINIT_LIST_HEAD(&parent->variant. directoryVariant. children); } else if (parent->variantType != @@ -6446,8 +6533,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: attempting to use non-directory as" - " a directory in scan. Put in lost+found." + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found." TENDSTR))); parent = dev->lostNFoundDir; } @@ -6498,7 +6584,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) in->variant.hardLinkVariant.equivalentObjectId = equivalentObjectId; in->hardLinks.next = - (struct list_head *) hardList; + (struct ylist_head *) hardList; hardList = in; } break; @@ -6558,27 +6644,27 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) * Sort out state of unlinked and deleted objects. */ { - struct list_head *i; - struct list_head *n; + struct ylist_head *i; + struct ylist_head *n; yaffs_Object *l; /* Soft delete all the unlinked files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->unlinkedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } } /* Soft delete all the deletedDir files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->deletedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } @@ -6605,7 +6691,7 @@ static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj) if(dev && dev->removeObjectCallback) dev->removeObjectCallback(obj); - list_del_init(&obj->siblings); + ylist_del_init(&obj->siblings); obj->parent = NULL; } @@ -6631,14 +6717,14 @@ static void yaffs_AddObjectToDirectory(yaffs_Object * directory, if (obj->siblings.prev == NULL) { /* Not initialised */ - INIT_LIST_HEAD(&obj->siblings); + YINIT_LIST_HEAD(&obj->siblings); - } else if (!list_empty(&obj->siblings)) { + } else if (!ylist_empty(&obj->siblings)) { /* If it is holed up somewhere else, un hook it */ yaffs_RemoveObjectFromDirectory(obj); } /* Now add it */ - list_add(&obj->siblings, &directory->variant.directoryVariant.children); + ylist_add(&obj->siblings, &directory->variant.directoryVariant.children); obj->parent = directory; if (directory == obj->myDev->unlinkedDir @@ -6654,7 +6740,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, { int sum; - struct list_head *i; + struct ylist_head *i; YCHAR buffer[YAFFS_MAX_NAME_LENGTH + 1]; yaffs_Object *l; @@ -6679,9 +6765,9 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, sum = yaffs_CalcNameSum(name); - list_for_each(i, &directory->variant.directoryVariant.children) { + ylist_for_each(i, &directory->variant.directoryVariant.children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_CheckObjectDetailsLoaded(l); @@ -6713,7 +6799,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, int (*fn) (yaffs_Object *)) { - struct list_head *i; + struct ylist_head *i; yaffs_Object *l; if (!theDir) { @@ -6730,9 +6816,9 @@ int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, YBUG(); } - list_for_each(i, &theDir->variant.directoryVariant.children) { + ylist_for_each(i, &theDir->variant.directoryVariant.children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); if (l && !fn(l)) { return YAFFS_FAIL; } @@ -6821,12 +6907,12 @@ int yaffs_GetObjectFileLength(yaffs_Object * obj) int yaffs_GetObjectLinkCount(yaffs_Object * obj) { int count = 0; - struct list_head *i; + struct ylist_head *i; if (!obj->unlinked) { count++; /* the object itself */ } - list_for_each(i, &obj->hardLinks) { + ylist_for_each(i, &obj->hardLinks) { count++; /* add the hard links; */ } return count; @@ -7049,8 +7135,9 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* Check geometry parameters. */ - if ((dev->isYaffs2 && dev->nDataBytesPerChunk < 1024) || - (!dev->isYaffs2 && dev->nDataBytesPerChunk != 512) || + if ((!dev->inbandTags && dev->isYaffs2 && dev->totalBytesPerChunk < 1024) || + (!dev->isYaffs2 && dev->totalBytesPerChunk != 512) || + (dev->inbandTags && !dev->isYaffs2 ) || dev->nChunksPerBlock < 2 || dev->nReservedBlocks < 2 || dev->internalStartBlock <= 0 || @@ -7059,8 +7146,8 @@ int yaffs_GutsInitialise(yaffs_Device * dev) ) { T(YAFFS_TRACE_ALWAYS, (TSTR - ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s " - TENDSTR), dev->nDataBytesPerChunk, dev->isYaffs2 ? "2" : "")); + ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s, inbandTags %d " + TENDSTR), dev->totalBytesPerChunk, dev->isYaffs2 ? "2" : "", dev->inbandTags)); return YAFFS_FAIL; } @@ -7069,6 +7156,12 @@ int yaffs_GutsInitialise(yaffs_Device * dev) (TSTR("yaffs: InitialiseNAND failed" TENDSTR))); return YAFFS_FAIL; } + + /* Sort out space for inband tags, if required */ + if(dev->inbandTags) + dev->nDataBytesPerChunk = dev->totalBytesPerChunk - sizeof(yaffs_PackedTags2TagsPart); + else + dev->nDataBytesPerChunk = dev->totalBytesPerChunk; /* Got the right mix of functions? */ if (!yaffs_CheckDevFunctions(dev)) { @@ -7104,22 +7197,14 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* * Calculate all the chunk size manipulation numbers: */ - /* Start off assuming it is a power of 2 */ - dev->chunkShift = ShiftDiv(dev->nDataBytesPerChunk); - dev->chunkMask = (1<<dev->chunkShift) - 1; - - if(dev->nDataBytesPerChunk == (dev->chunkMask + 1)){ - /* Yes it is a power of 2, disable crumbs */ - dev->crumbMask = 0; - dev->crumbShift = 0; - dev->crumbsPerChunk = 0; - } else { - /* Not a power of 2, use crumbs instead */ - dev->crumbShift = ShiftDiv(sizeof(yaffs_PackedTags2TagsPart)); - dev->crumbMask = (1<<dev->crumbShift)-1; - dev->crumbsPerChunk = dev->nDataBytesPerChunk/(1 << dev->crumbShift); - dev->chunkShift = 0; - dev->chunkMask = 0; + { + __u32 x = dev->nDataBytesPerChunk; + /* We always use dev->chunkShift and dev->chunkDiv */ + dev->chunkShift = Shifts(x); + x >>= dev->chunkShift; + dev->chunkDiv = x; + /* We only use chunk mask if chunkDiv is 1 */ + dev->chunkMask = (1<<dev->chunkShift) - 1; } @@ -7203,7 +7288,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) if (!init_failed && dev->nShortOpCaches > 0) { int i; - __u8 *buf; + void *buf; int srCacheBytes = dev->nShortOpCaches * sizeof(yaffs_ChunkCache); if (dev->nShortOpCaches > YAFFS_MAX_SHORT_OP_CACHES) { @@ -7219,7 +7304,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->srCache[i].object = NULL; dev->srCache[i].lastUse = 0; dev->srCache[i].dirty = 0; - dev->srCache[i].data = buf = YMALLOC_DMA(dev->nDataBytesPerChunk); + dev->srCache[i].data = buf = YMALLOC_DMA(dev->totalBytesPerChunk); } if(!buf) init_failed = 1; @@ -7345,6 +7430,7 @@ void yaffs_Deinitialise(yaffs_Device * dev) YFREE(dev->tempBuffer[i].buffer); } + dev->isMounted = 0; } @@ -7410,7 +7496,7 @@ int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) nFree -= ((dev->nReservedBlocks + 1) * dev->nChunksPerBlock); /* Now we figure out how much to reserve for the checkpoint and report that... */ - blocksForCheckpoint = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint; + blocksForCheckpoint = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(blocksForCheckpoint < 0) blocksForCheckpoint = 0; @@ -7448,22 +7534,25 @@ static void yaffs_VerifyFreeChunks(yaffs_Device * dev) /*---------------------------------------- YAFFS test code ----------------------*/ #define yaffs_CheckStruct(structure,syze, name) \ + do { \ if(sizeof(structure) != syze) \ { \ T(YAFFS_TRACE_ALWAYS,(TSTR("%s should be %d but is %d\n" TENDSTR),\ name,syze,sizeof(structure))); \ return YAFFS_FAIL; \ - } + } \ + } while(0) static int yaffs_CheckStructures(void) { -/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags") */ -/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion") */ -/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare") */ +/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags"); */ +/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion"); */ +/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare"); */ #ifndef CONFIG_YAFFS_TNODE_LIST_DEBUG - yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode") + yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode"); +#endif +#ifndef CONFIG_YAFFS_WINCE + yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader"); #endif - yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader") - return YAFFS_OK; } diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.h index ea06c1a38..b9b2ea194 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_guts.h @@ -90,7 +90,7 @@ #define YAFFS_MAX_SHORT_OP_CACHES 20 -#define YAFFS_N_TEMP_BUFFERS 4 +#define YAFFS_N_TEMP_BUFFERS 6 /* We limit the number attempts at sucessfully saving a chunk of data. * Small-page devices have 32 pages per block; large-page devices have 64. @@ -277,7 +277,7 @@ typedef struct { int softDeletions:10; /* number of soft deleted pages */ int pagesInUse:10; /* number of pages in use */ - yaffs_BlockState blockState:4; /* One of the above block states */ + unsigned blockState:4; /* One of the above block states. NB use unsigned because enum is sometimes an int */ __u32 needsRetiring:1; /* Data has failed on this block, need to get valid data off */ /* and retire the block. */ __u32 skipErasedCheck: 1; /* If this is set we can skip the erased check on this block */ @@ -303,7 +303,7 @@ typedef struct { __u16 sum__NoLongerUsed; /* checksum of name. No longer used */ YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - /* Thes following apply to directories, files, symlinks - not hard links */ + /* The following apply to directories, files, symlinks - not hard links */ __u32 yst_mode; /* protection */ #ifdef CONFIG_YAFFS_WINCE @@ -331,11 +331,14 @@ typedef struct { __u32 win_ctime[2]; __u32 win_atime[2]; __u32 win_mtime[2]; - __u32 roomToGrow[4]; #else - __u32 roomToGrow[10]; + __u32 roomToGrow[6]; + #endif + __u32 inbandShadowsObject; + __u32 inbandIsShrink; + __u32 reservedSpace[2]; int shadowsObject; /* This object header shadows the specified object if > 0 */ /* isShrink applies to object headers written when we shrink the file (ie resize) */ @@ -381,7 +384,7 @@ typedef struct { } yaffs_FileStructure; typedef struct { - struct list_head children; /* list of child links */ + struct ylist_head children; /* list of child links */ } yaffs_DirectoryStructure; typedef struct { @@ -424,14 +427,14 @@ struct yaffs_ObjectStruct { struct yaffs_DeviceStruct *myDev; /* The device I'm on */ - struct list_head hashLink; /* list of objects in this hash bucket */ + struct ylist_head hashLink; /* list of objects in this hash bucket */ - struct list_head hardLinks; /* all the equivalent hard linked objects */ + struct ylist_head hardLinks; /* all the equivalent hard linked objects */ /* directory structure stuff */ /* also used for linking up the free list */ struct yaffs_ObjectStruct *parent; - struct list_head siblings; + struct ylist_head siblings; /* Where's my object header in NAND? */ int chunkId; @@ -485,7 +488,7 @@ struct yaffs_ObjectList_struct { typedef struct yaffs_ObjectList_struct yaffs_ObjectList; typedef struct { - struct list_head list; + struct ylist_head list; int count; } yaffs_ObjectBucket; @@ -528,7 +531,7 @@ typedef struct { /*----------------- Device ---------------------------------*/ struct yaffs_DeviceStruct { - struct list_head devList; + struct ylist_head devList; const char *name; /* Entry parameters set up way early. Yaffs sets up the rest.*/ @@ -544,7 +547,7 @@ struct yaffs_DeviceStruct { /* Stuff used by the shared space checkpointing mechanism */ /* If this value is zero, then this mechanism is disabled */ - int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ +// int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ @@ -583,7 +586,7 @@ struct yaffs_DeviceStruct { yaffs_ExtendedTags * tags); int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo); int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo, - yaffs_BlockState * state, int *sequenceNumber); + yaffs_BlockState * state, __u32 *sequenceNumber); #endif int isYaffs2; @@ -598,7 +601,8 @@ struct yaffs_DeviceStruct { void (*markSuperBlockDirty)(void * superblock); int wideTnodesDisabled; /* Set to disable wide tnodes */ - + + YCHAR *pathDividers; /* String of legal path dividers */ /* End of stuff that must be set before initialisation. */ @@ -615,16 +619,14 @@ struct yaffs_DeviceStruct { __u32 tnodeWidth; __u32 tnodeMask; - /* Stuff to support various file offses to chunk/offset translations */ - /* "Crumbs" for nDataBytesPerChunk not being a power of 2 */ - __u32 crumbMask; - __u32 crumbShift; - __u32 crumbsPerChunk; - - /* Straight shifting for nDataBytesPerChunk being a power of 2 */ - __u32 chunkShift; - __u32 chunkMask; + /* Stuff for figuring out file offset to chunk conversions */ + __u32 chunkShift; /* Shift value */ + __u32 chunkDiv; /* Divisor after shifting: 1 for power-of-2 sizes */ + __u32 chunkMask; /* Mask to use for power-of-2 case */ + /* Stuff to handle inband tags */ + int inbandTags; + __u32 totalBytesPerChunk; #ifdef __KERNEL__ @@ -663,6 +665,8 @@ struct yaffs_DeviceStruct { __u32 checkpointSum; __u32 checkpointXor; + int nCheckpointBlocksRequired; /* Number of blocks needed to store current checkpoint set */ + /* Block Info */ yaffs_BlockInfo *blockInfo; __u8 *chunkBits; /* bitmap of chunks in use */ @@ -744,9 +748,11 @@ struct yaffs_DeviceStruct { int nUnlinkedFiles; /* Count of unlinked files. */ int nBackgroundDeletions; /* Count of background deletions. */ - + + /* Temporary buffer management */ yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS]; int maxTemp; + int tempInUse; int unmanagedTempAllocations; int unmanagedTempDeallocations; @@ -758,7 +764,7 @@ struct yaffs_DeviceStruct { typedef struct yaffs_DeviceStruct yaffs_Device; -/* The static layout of bllock usage etc is stored in the super block header */ +/* The static layout of block usage etc is stored in the super block header */ typedef struct { int StructType; int version; @@ -797,18 +803,6 @@ typedef struct { __u32 head; } yaffs_CheckpointValidity; -/* Function to manipulate block info */ -static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk) -{ - if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { - T(YAFFS_TRACE_ERROR, - (TSTR - ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR), - blk)); - YBUG(); - } - return &dev->blockInfo[blk - dev->internalStartBlock]; -} /*----------------------- YAFFS Functions -----------------------*/ @@ -899,4 +893,7 @@ void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn); int yaffs_CheckFF(__u8 * buffer, int nBytes); void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi); +__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); +void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo); + #endif diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.c index 466e5a44c..4888b96f6 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.c @@ -12,7 +12,7 @@ */ const char *yaffs_mtdif_c_version = - "$Id: yaffs_mtdif.c,v 1.19 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_mtdif.c,v 1.21 2007-12-13 15:35:18 wookey Exp $"; #include "yportenv.h" @@ -24,7 +24,7 @@ const char *yaffs_mtdif_c_version = #include "linux/time.h" #include "linux/mtd/nand.h" -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) static struct nand_oobinfo yaffs_oobinfo = { .useecc = 1, .eccbytes = 6, @@ -36,7 +36,7 @@ static struct nand_oobinfo yaffs_noeccinfo = { }; #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) static inline void translate_spare2oob(const yaffs_Spare *spare, __u8 *oob) { oob[0] = spare->tagByte0; @@ -75,14 +75,14 @@ int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) @@ -139,14 +139,14 @@ int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.h index 317600cac..511b0176a 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif.h @@ -18,6 +18,11 @@ #include "yaffs_guts.h" +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) +extern struct nand_oobinfo yaffs_oobinfo; +extern struct nand_oobinfo yaffs_noeccinfo; +#endif + int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare); int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1-compat.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1-compat.c deleted file mode 100644 index 6ea675611..000000000 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1-compat.c +++ /dev/null @@ -1,434 +0,0 @@ -From ian@brightstareng.com Fri May 18 15:06:49 2007 -From ian@brightstareng.com Fri May 18 15:08:21 2007 -Received: from 206.173.66.57.ptr.us.xo.net ([206.173.66.57] helo=zebra.brightstareng.com) - by apollo.linkchoose.co.uk with esmtp (Exim 4.60) - (envelope-from <ian@brightstareng.com>) - id 1Hp380-00011e-T6 - for david.goodenough@linkchoose.co.uk; Fri, 18 May 2007 15:08:21 +0100 -Received: from localhost (localhost.localdomain [127.0.0.1]) - by zebra.brightstareng.com (Postfix) with ESMTP - id 4819F28C004; Fri, 18 May 2007 10:07:49 -0400 (EDT) -Received: from zebra.brightstareng.com ([127.0.0.1]) - by localhost (zebra [127.0.0.1]) (amavisd-new, port 10024) with ESMTP - id 05328-06; Fri, 18 May 2007 10:07:16 -0400 (EDT) -Received: from pippin (unknown [192.168.1.25]) - by zebra.brightstareng.com (Postfix) with ESMTP - id 8BEF528C1BC; Fri, 18 May 2007 10:06:53 -0400 (EDT) -From: Ian McDonnell <ian@brightstareng.com> -To: David Goodenough <david.goodenough@linkchoose.co.uk> -Subject: Re: something tested this time -- yaffs_mtdif1-compat.c -Date: Fri, 18 May 2007 10:06:49 -0400 -User-Agent: KMail/1.9.1 -References: <200705142207.06909.ian@brightstareng.com> <200705171131.53536.ian@brightstareng.com> <200705181334.32166.david.goodenough@linkchoose.co.uk> -In-Reply-To: <200705181334.32166.david.goodenough@linkchoose.co.uk> -Cc: Andrea Conti <alyf@alyf.net>, - Charles Manning <manningc2@actrix.gen.nz> -MIME-Version: 1.0 -Content-Type: Multipart/Mixed; - boundary="Boundary-00=_5LbTGmt62YoutxM" -Message-Id: <200705181006.49860.ian@brightstareng.com> -X-Virus-Scanned: by amavisd-new at brightstareng.com -Status: R -X-Status: NT -X-KMail-EncryptionState: -X-KMail-SignatureState: -X-KMail-MDN-Sent: - ---Boundary-00=_5LbTGmt62YoutxM -Content-Type: text/plain; - charset="iso-8859-15" -Content-Transfer-Encoding: 7bit -Content-Disposition: inline - -David, Andrea, - -On Friday 18 May 2007 08:34, you wrote: -> Yea team. With this fix in place (I put it in the wrong place -> at first) I can now mount and ls the Yaffs partition without -> an error messages! - -Good news! - -Attached is a newer yaffs_mtdif1.c with a bandaid to help the -2.6.18 and 2.6.19 versions of MTD not trip on the oob read. -See the LINUX_VERSION_CODE conditional in -nandmtd1_ReadChunkWithTagsFromNAND. - --imcd - ---Boundary-00=_5LbTGmt62YoutxM -Content-Type: text/x-csrc; - charset="iso-8859-15"; - name="yaffs_mtdif1.c" -Content-Transfer-Encoding: 7bit -Content-Disposition: attachment; - filename="yaffs_mtdif1.c" - -/* - * YAFFS: Yet another FFS. A NAND-flash specific file system. - * yaffs_mtdif1.c NAND mtd interface functions for small-page NAND. - * - * Copyright (C) 2002 Aleph One Ltd. - * for Toby Churchill Ltd and Brightstar Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -/* - * This module provides the interface between yaffs_nand.c and the - * MTD API. This version is used when the MTD interface supports the - * 'mtd_oob_ops' style calls to read_oob and write_oob, circa 2.6.17, - * and we have small-page NAND device. - * - * These functions are invoked via function pointers in yaffs_nand.c. - * This replaces functionality provided by functions in yaffs_mtdif.c - * and the yaffs_TagsCompatability functions in yaffs_tagscompat.c that are - * called in yaffs_mtdif.c when the function pointers are NULL. - * We assume the MTD layer is performing ECC (useNANDECC is true). - */ - -#include "yportenv.h" -#include "yaffs_guts.h" -#include "yaffs_packedtags1.h" -#include "yaffs_tagscompat.h" // for yaffs_CalcTagsECC - -#include "linux/kernel.h" -#include "linux/version.h" -#include "linux/types.h" -#include "linux/mtd/mtd.h" - -/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $"; - -#ifndef CONFIG_YAFFS_9BYTE_TAGS -# define YTAG1_SIZE 8 -#else -# define YTAG1_SIZE 9 -#endif - -#if 0 -/* Use the following nand_ecclayout with MTD when using - * CONFIG_YAFFS_9BYTE_TAGS and the older on-NAND tags layout. - * If you have existing Yaffs images and the byte order differs from this, - * adjust 'oobfree' to match your existing Yaffs data. - * - * This nand_ecclayout scatters/gathers to/from the old-yaffs layout with the - * pageStatus byte (at NAND spare offset 4) scattered/gathered from/to - * the 9th byte. - * - * Old-style on-NAND format: T0,T1,T2,T3,P,B,T4,T5,E0,E1,E2,T6,T7,E3,E4,E5 - * We have/need PackedTags1 plus pageStatus: T0,T1,T2,T3,T4,T5,T6,T7,P - * where Tn are the tag bytes, En are MTD's ECC bytes, P is the pageStatus - * byte and B is the small-page bad-block indicator byte. - */ -static struct nand_ecclayout nand_oob_16 = { - .eccbytes = 6, - .eccpos = { 8, 9, 10, 13, 14, 15 }, - .oobavail = 9, - .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } } -}; -#endif - -/* Write a chunk (page) of data to NAND. - * - * Caller always provides ExtendedTags data which are converted to a more - * compact (packed) form for storage in NAND. A mini-ECC runs over the - * contents of the tags meta-data; used to valid the tags when read. - * - * - Pack ExtendedTags to PackedTags1 form - * - Compute mini-ECC for PackedTags1 - * - Write data and packed tags to NAND. - * - * Note: Due to the use of the PackedTags1 meta-data which does not include - * a full sequence number (as found in the larger PackedTags2 form) it is - * necessary for Yaffs to re-write a chunk/page (just once) to mark it as - * discarded and dirty. This is not ideal: newer NAND parts are supposed - * to be written just once. When Yaffs performs this operation, this - * function is called with a NULL data pointer -- calling MTD write_oob - * without data is valid usage (2.6.17). - * - * Any underlying MTD error results in YAFFS_FAIL. - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, - int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkBytes = dev->nDataBytesPerChunk; - loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; - struct mtd_oob_ops ops; - yaffs_PackedTags1 pt1; - int retval; - - /* we assume that PackedTags1 and yaffs_Tags are compatible */ - compile_time_assertion(sizeof(yaffs_PackedTags1) == 12); - compile_time_assertion(sizeof(yaffs_Tags) == 8); - - yaffs_PackTags1(&pt1, etags); - yaffs_CalcTagsECC((yaffs_Tags *)&pt1); - - /* When deleting a chunk, the upper layer provides only skeletal - * etags, one with chunkDeleted set. However, we need to update the - * tags, not erase them completely. So we use the NAND write property - * that only zeroed-bits stick and set tag bytes to all-ones and - * zero just the (not) deleted bit. - */ -#ifndef CONFIG_YAFFS_9BYTE_TAGS - if (etags->chunkDeleted) { - memset(&pt1, 0xff, 8); - /* clear delete status bit to indicate deleted */ - pt1.deleted = 0; - } -#else - ((__u8 *)&pt1)[8] = 0xff; - if (etags->chunkDeleted) { - memset(&pt1, 0xff, 8); - /* zero pageStatus byte to indicate deleted */ - ((__u8 *)&pt1)[8] = 0; - } -#endif - - memset(&ops, 0, sizeof(ops)); - ops.mode = MTD_OOB_AUTO; - ops.len = (data) ? chunkBytes : 0; - ops.ooblen = YTAG1_SIZE; - ops.datbuf = (__u8 *)data; - ops.oobbuf = (__u8 *)&pt1; - - retval = mtd->write_oob(mtd, addr, &ops); - if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "write_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); - } - return retval ? YAFFS_FAIL : YAFFS_OK; -} - -/* Return with empty ExtendedTags but add eccResult. - */ -static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval) -{ - if (etags) { - memset(etags, 0, sizeof(*etags)); - etags->eccResult = eccResult; - } - return retval; -} - -/* Read a chunk (page) from NAND. - * - * Caller expects ExtendedTags data to be usable even on error; that is, - * all members except eccResult and blockBad are zeroed. - * - * - Check ECC results for data (if applicable) - * - Check for blank/erased block (return empty ExtendedTags if blank) - * - Check the PackedTags1 mini-ECC (correct if necessary/possible) - * - Convert PackedTags1 to ExtendedTags - * - Update eccResult and blockBad members to refect state. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, - int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkBytes = dev->nDataBytesPerChunk; - loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; - int eccres = YAFFS_ECC_RESULT_NO_ERROR; - struct mtd_oob_ops ops; - yaffs_PackedTags1 pt1; - int retval; - int deleted; - - memset(&ops, 0, sizeof(ops)); - ops.mode = MTD_OOB_AUTO; - ops.len = (data) ? chunkBytes : 0; - ops.ooblen = YTAG1_SIZE; - ops.datbuf = data; - ops.oobbuf = (__u8 *)&pt1; - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) - /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; - * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. - */ - ops.len = (ops.datbuf) ? ops.len : ops.ooblen; -#endif - /* Read page and oob using MTD. - * Check status and determine ECC result. - */ - retval = mtd->read_oob(mtd, addr, &ops); - if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "read_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); - } - - switch (retval) { - case 0: - /* no error */ - break; - - case -EUCLEAN: - /* MTD's ECC fixed the data */ - eccres = YAFFS_ECC_RESULT_FIXED; - dev->eccFixed++; - break; - - case -EBADMSG: - /* MTD's ECC could not fix the data */ - dev->eccUnfixed++; - /* fall into... */ - default: - rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); - etags->blockBad = (mtd->block_isbad)(mtd, addr); - return YAFFS_FAIL; - } - - /* Check for a blank/erased chunk. - */ - if (yaffs_CheckFF((__u8 *)&pt1, 8)) { - /* when blank, upper layers want eccResult to be <= NO_ERROR */ - return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); - } - -#ifndef CONFIG_YAFFS_9BYTE_TAGS - /* Read deleted status (bit) then return it to it's non-deleted - * state before performing tags mini-ECC check. pt1.deleted is - * inverted. - */ - deleted = !pt1.deleted; - pt1.deleted = 1; -#else - (void) deleted; /* not used */ -#endif - - /* Check the packed tags mini-ECC and correct if necessary/possible. - */ - retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); - switch (retval) { - case 0: - /* no tags error, use MTD result */ - break; - case 1: - /* recovered tags-ECC error */ - dev->tagsEccFixed++; - eccres = YAFFS_ECC_RESULT_FIXED; - break; - default: - /* unrecovered tags-ECC error */ - dev->tagsEccUnfixed++; - return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); - } - - /* Unpack the tags to extended form and set ECC result. - * [set shouldBeFF just to keep yaffs_UnpackTags1 happy] - */ - pt1.shouldBeFF = 0xFFFFFFFF; - yaffs_UnpackTags1(etags, &pt1); - etags->eccResult = eccres; - - /* Set deleted state. - */ -#ifndef CONFIG_YAFFS_9BYTE_TAGS - etags->chunkDeleted = deleted; -#else - etags->chunkDeleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); -#endif - return YAFFS_OK; -} - -/* Mark a block bad. - * - * This is a persistant state. - * Use of this function should be rare. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) -{ - struct mtd_info * mtd = dev->genericDevice; - int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; - int retval; - - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); - - retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); - return (retval) ? YAFFS_FAIL : YAFFS_OK; -} - -/* Check any MTD prerequists. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -static int nandmtd1_TestPrerequists(struct mtd_info * mtd) -{ - /* 2.6.18 has mtd->ecclayout->oobavail */ - /* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */ - int oobavail = mtd->ecclayout->oobavail; - - if (oobavail < YTAG1_SIZE) { - yaffs_trace(YAFFS_TRACE_ERROR, - "mtd device has only %d bytes for tags, need %d", - oobavail, YTAG1_SIZE); - return YAFFS_FAIL; - } - return YAFFS_OK; -} - -/* Query for the current state of a specific block. - * - * Examine the tags of the first chunk of the block and return the state: - * - YAFFS_BLOCK_STATE_DEAD, the block is marked bad - * - YAFFS_BLOCK_STATE_NEEDS_SCANNING, the block is in use - * - YAFFS_BLOCK_STATE_EMPTY, the block is clean - * - * Always returns YAFFS_OK. - */ -int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * pState, int *pSequenceNumber) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkNo = blockNo * dev->nChunksPerBlock; - yaffs_ExtendedTags etags; - int state = YAFFS_BLOCK_STATE_DEAD; - int seqnum = 0; - int retval; - - /* We don't yet have a good place to test for MTD config prerequists. - * Do it here as we are called during the initial scan. - */ - if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) { - return YAFFS_FAIL; - } - - retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); - if (etags.blockBad) { - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad", blockNo); - state = YAFFS_BLOCK_STATE_DEAD; - } - else if (etags.chunkUsed) { - state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; - seqnum = etags.sequenceNumber; - } - else { - state = YAFFS_BLOCK_STATE_EMPTY; - } - - *pState = state; - *pSequenceNumber = seqnum; - - /* query always succeeds */ - return YAFFS_OK; -} - -#endif /*KERNEL_VERSION*/ - ---Boundary-00=_5LbTGmt62YoutxM-- - - - diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1.c index 36d5adec5..2b33c2cfe 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif1.c @@ -34,9 +34,9 @@ #include "linux/mtd/mtd.h" /* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $"; +const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.7 2007-12-13 15:35:18 wookey Exp $"; #ifndef CONFIG_YAFFS_9BYTE_TAGS # define YTAG1_SIZE 8 @@ -189,7 +189,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,20)) /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. */ @@ -288,7 +288,7 @@ int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; int retval; - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); + yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo); retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); return (retval) ? YAFFS_FAIL : YAFFS_OK; @@ -327,6 +327,7 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, { struct mtd_info * mtd = dev->genericDevice; int chunkNo = blockNo * dev->nChunksPerBlock; + loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk; yaffs_ExtendedTags etags; int state = YAFFS_BLOCK_STATE_DEAD; int seqnum = 0; @@ -340,11 +341,16 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, } retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); + etags.blockBad = (mtd->block_isbad)(mtd, addr); if (etags.blockBad) { yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad", blockNo); + "block %d is marked bad\n", blockNo); state = YAFFS_BLOCK_STATE_DEAD; } + else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) { + /* bad tags, need to look more closely */ + state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; + } else if (etags.chunkUsed) { state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; seqnum = etags.sequenceNumber; @@ -360,4 +366,4 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, return YAFFS_OK; } -#endif /*KERNEL_VERSION*/ +#endif /*MTD_VERSION*/ diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif2.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif2.c index cdad0734b..3768b9b07 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif2.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_mtdif2.c @@ -14,7 +14,7 @@ /* mtd interface for YAFFS2 */ const char *yaffs_mtdif2_c_version = - "$Id: yaffs_mtdif2.c,v 1.17 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_mtdif2.c,v 1.20 2008-05-05 07:58:58 charles Exp $"; #include "yportenv.h" @@ -27,19 +27,23 @@ const char *yaffs_mtdif2_c_version = #include "yaffs_packedtags2.h" +/* NB For use with inband tags.... + * We assume that the data buffer is of size totalBytersPerChunk so that we can also + * use it to load the tags. + */ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #else size_t dummy; #endif int retval = 0; - loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; + loff_t addr; yaffs_PackedTags2 pt; @@ -47,47 +51,42 @@ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); - -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (tags) - yaffs_PackTags2(&pt, tags); + + + addr = ((loff_t) chunkInNAND) * dev->totalBytesPerChunk; + + /* For yaffs2 writing there must be both data and tags. + * If we're using inband tags, then the tags are stuffed into + * the end of the data buffer. + */ + if(!data || !tags) + BUG(); + else if(dev->inbandTags){ + yaffs_PackedTags2TagsPart *pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->nDataBytesPerChunk); + yaffs_PackTags2TagsPart(pt2tp,tags); + } else - BUG(); /* both tags and data should always be present */ - - if (data) { - ops.mode = MTD_OOB_AUTO; - ops.ooblen = sizeof(pt); - ops.len = dev->nDataBytesPerChunk; - ops.ooboffs = 0; - ops.datbuf = (__u8 *)data; - ops.oobbuf = (void *)&pt; - retval = mtd->write_oob(mtd, addr, &ops); - } else - BUG(); /* both tags and data should always be present */ -#else - if (tags) { yaffs_PackTags2(&pt, tags); - } + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) + ops.mode = MTD_OOB_AUTO; + ops.ooblen = (dev->inbandTags) ? 0 : sizeof(pt); + ops.len = dev->totalBytesPerChunk; + ops.ooboffs = 0; + ops.datbuf = (__u8 *)data; + ops.oobbuf = (dev->inbandTags) ? NULL : (void *)&pt; + retval = mtd->write_oob(mtd, addr, &ops); - if (data && tags) { - if (dev->useNANDECC) - retval = - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); - else - retval = - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); +#else + if (!dev->inbandTags) { + retval = + mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, + &dummy, data, (__u8 *) & pt, NULL); } else { - if (data) - retval = - mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy, - data); - if (tags) - retval = - mtd->write_oob(mtd, addr, mtd->oobsize, &dummy, - (__u8 *) & pt); - + retval = + mtd->write(mtd, addr, dev->totalBytesPerChunk, &dummy, + data); } #endif @@ -101,11 +100,12 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; + int localData = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; @@ -115,10 +115,21 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); + + if(dev->inbandTags){ + + if(!data) { + localData = 1; + data = yaffs_GetTempBuffer(dev,__LINE__); + } + + + } + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (data && !tags) - retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk, + if (dev->inbandTags || (data && !tags)) + retval = mtd->read(mtd, addr, dev->totalBytesPerChunk, &dummy, data); else if (tags) { ops.mode = MTD_OOB_AUTO; @@ -130,38 +141,43 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, retval = mtd->read_oob(mtd, addr, &ops); } #else - if (data && tags) { - if (dev->useNANDECC) { - retval = - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, dev->spareBuffer, - NULL); - } else { - retval = - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, + if (!dev->inbandTags && data && tags) { + + retval = mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, &dummy, data, dev->spareBuffer, NULL); - } } else { if (data) retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk, &dummy, data); - if (tags) + if (!dev->inbandTags && tags) retval = mtd->read_oob(mtd, addr, mtd->oobsize, &dummy, dev->spareBuffer); } #endif - memcpy(&pt, dev->spareBuffer, sizeof(pt)); - if (tags) - yaffs_UnpackTags2(tags, &pt); + if(dev->inbandTags){ + if(tags){ + yaffs_PackedTags2TagsPart * pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; + yaffs_UnpackTags2TagsPart(tags,pt2tp); + } + } + else { + if (tags){ + memcpy(&pt, dev->spareBuffer, sizeof(pt)); + yaffs_UnpackTags2(tags, &pt); + } + } + if(localData) + yaffs_ReleaseTempBuffer(dev,data,__LINE__); + if(tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR) - tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; - + tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; if (retval == 0) return YAFFS_OK; else diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nand.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nand.c index 4e250338d..af4215772 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nand.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nand.c @@ -12,12 +12,13 @@ */ const char *yaffs_nand_c_version = - "$Id: yaffs_nand.c,v 1.7 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_nand.c,v 1.9 2008-05-05 07:58:58 charles Exp $"; #include "yaffs_nand.h" #include "yaffs_tagscompat.h" #include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * buffer, @@ -98,7 +99,7 @@ int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo) int yaffs_QueryInitialBlockState(yaffs_Device * dev, int blockNo, yaffs_BlockState * state, - unsigned *sequenceNumber) + __u32 *sequenceNumber) { blockNo -= dev->blockOffset; diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nandemul2k.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nandemul2k.h index cd2e96f7a..c8576b307 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nandemul2k.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_nandemul2k.h @@ -22,13 +22,13 @@ int nandemul2k_WriteChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, const __u8 * data, - yaffs_ExtendedTags * tags); + const yaffs_ExtendedTags * tags); int nandemul2k_ReadChunkWithTagsFromNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * tags); int nandemul2k_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int nandemul2k_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, int *sequenceNumber); + yaffs_BlockState * state, __u32 *sequenceNumber); int nandemul2k_EraseBlockInNAND(struct yaffs_DeviceStruct *dev, int blockInNAND); int nandemul2k_InitialiseNAND(struct yaffs_DeviceStruct *dev); diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.c index e420f95da..957ed8bf0 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.c @@ -37,60 +37,70 @@ #define EXTRA_OBJECT_TYPE_SHIFT (28) #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT) -static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) + +static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart * ptt) { T(YAFFS_TRACE_MTD, (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR), - pt->t.objectId, pt->t.chunkId, pt->t.byteCount, - pt->t.sequenceNumber)); + ptt->objectId, ptt->chunkId, ptt->byteCount, + ptt->sequenceNumber)); +} +static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) +{ + yaffs_DumpPackedTags2TagsPart(&pt->t); } static void yaffs_DumpTags2(const yaffs_ExtendedTags * t) { T(YAFFS_TRACE_MTD, (TSTR - ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte " - "%d del %d ser %d seq %d" + ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d" TENDSTR), t->eccResult, t->blockBad, t->chunkUsed, t->objectId, t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, t->sequenceNumber)); } -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * ptt, const yaffs_ExtendedTags * t) { - pt->t.chunkId = t->chunkId; - pt->t.sequenceNumber = t->sequenceNumber; - pt->t.byteCount = t->byteCount; - pt->t.objectId = t->objectId; + ptt->chunkId = t->chunkId; + ptt->sequenceNumber = t->sequenceNumber; + ptt->byteCount = t->byteCount; + ptt->objectId = t->objectId; if (t->chunkId == 0 && t->extraHeaderInfoAvailable) { /* Store the extra header info instead */ /* We save the parent object in the chunkId */ - pt->t.chunkId = EXTRA_HEADER_INFO_FLAG + ptt->chunkId = EXTRA_HEADER_INFO_FLAG | t->extraParentObjectId; if (t->extraIsShrinkHeader) { - pt->t.chunkId |= EXTRA_SHRINK_FLAG; + ptt->chunkId |= EXTRA_SHRINK_FLAG; } if (t->extraShadows) { - pt->t.chunkId |= EXTRA_SHADOWS_FLAG; + ptt->chunkId |= EXTRA_SHADOWS_FLAG; } - pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK; - pt->t.objectId |= + ptt->objectId &= ~EXTRA_OBJECT_TYPE_MASK; + ptt->objectId |= (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT); if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { - pt->t.byteCount = t->extraEquivalentObjectId; + ptt->byteCount = t->extraEquivalentObjectId; } else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE) { - pt->t.byteCount = t->extraFileLength; + ptt->byteCount = t->extraFileLength; } else { - pt->t.byteCount = 0; + ptt->byteCount = 0; } } - yaffs_DumpPackedTags2(pt); + yaffs_DumpPackedTags2TagsPart(ptt); yaffs_DumpTags2(t); +} + + +void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +{ + yaffs_PackTags2TagsPart(&pt->t,t); #ifndef YAFFS_IGNORE_TAGS_ECC { @@ -101,13 +111,60 @@ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) #endif } -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) + +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * ptt) { memset(t, 0, sizeof(yaffs_ExtendedTags)); yaffs_InitialiseTags(t); + if (ptt->sequenceNumber != 0xFFFFFFFF) { + t->blockBad = 0; + t->chunkUsed = 1; + t->objectId = ptt->objectId; + t->chunkId = ptt->chunkId; + t->byteCount = ptt->byteCount; + t->chunkDeleted = 0; + t->serialNumber = 0; + t->sequenceNumber = ptt->sequenceNumber; + + /* Do extra header info stuff */ + + if (ptt->chunkId & EXTRA_HEADER_INFO_FLAG) { + t->chunkId = 0; + t->byteCount = 0; + + t->extraHeaderInfoAvailable = 1; + t->extraParentObjectId = + ptt->chunkId & (~(ALL_EXTRA_FLAGS)); + t->extraIsShrinkHeader = + (ptt->chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; + t->extraShadows = + (ptt->chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; + t->extraObjectType = + ptt->objectId >> EXTRA_OBJECT_TYPE_SHIFT; + t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; + + if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { + t->extraEquivalentObjectId = ptt->byteCount; + } else { + t->extraFileLength = ptt->byteCount; + } + } + } + + yaffs_DumpPackedTags2TagsPart(ptt); + yaffs_DumpTags2(t); + +} + + +void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) +{ + + yaffs_UnpackTags2TagsPart(t,&pt->t); + if (pt->t.sequenceNumber != 0xFFFFFFFF) { /* Page is in use */ #ifdef YAFFS_IGNORE_TAGS_ECC @@ -142,41 +199,10 @@ void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) } } #endif - t->blockBad = 0; - t->chunkUsed = 1; - t->objectId = pt->t.objectId; - t->chunkId = pt->t.chunkId; - t->byteCount = pt->t.byteCount; - t->chunkDeleted = 0; - t->serialNumber = 0; - t->sequenceNumber = pt->t.sequenceNumber; - - /* Do extra header info stuff */ - - if (pt->t.chunkId & EXTRA_HEADER_INFO_FLAG) { - t->chunkId = 0; - t->byteCount = 0; - - t->extraHeaderInfoAvailable = 1; - t->extraParentObjectId = - pt->t.chunkId & (~(ALL_EXTRA_FLAGS)); - t->extraIsShrinkHeader = - (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; - t->extraShadows = - (pt->t.chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; - t->extraObjectType = - pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT; - t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; - - if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { - t->extraEquivalentObjectId = pt->t.byteCount; - } else { - t->extraFileLength = pt->t.byteCount; - } - } } yaffs_DumpPackedTags2(pt); yaffs_DumpTags2(t); } + diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.h index c2242ffe7..75761d333 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_packedtags2.h @@ -33,6 +33,11 @@ typedef struct { yaffs_ECCOther ecc; } yaffs_PackedTags2; +/* Full packed tags with ECC, used for oob tags */ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t); void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt); + +/* Only the tags part (no ECC for use with inband tags */ +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * pt, const yaffs_ExtendedTags * t); +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * pt); #endif diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.c b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.c index 7622b1af7..ab756d06d 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.c +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.c @@ -14,6 +14,7 @@ #include "yaffs_guts.h" #include "yaffs_tagscompat.h" #include "yaffs_ecc.h" +#include "yaffs_getblockinfo.h" static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND); #ifdef NOTYET @@ -438,7 +439,7 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, yaffs_ECCResult eccResult; static yaffs_Spare spareFF; - static int init; + static int init = 0; if (!init) { memset(&spareFF, 0xFF, sizeof(spareFF)); @@ -497,9 +498,9 @@ int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, } int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, yaffs_BlockState * - state, - int *sequenceNumber) + int blockNo, + yaffs_BlockState *state, + __u32 *sequenceNumber) { yaffs_Spare spare0, spare1; diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.h index a61e3ba14..6549398ee 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yaffs_tagscompat.h @@ -30,8 +30,9 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, yaffs_BlockState * - state, int *sequenceNumber); + int blockNo, + yaffs_BlockState *state, + __u32 *sequenceNumber); void yaffs_CalcTagsECC(yaffs_Tags * tags); int yaffs_CheckECCOnTags(yaffs_Tags * tags); diff --git a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yportenv.h b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yportenv.h index 15ac28121..097b2a675 100644 --- a/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yportenv.h +++ b/target/linux/generic-2.6/files-2.6.26/fs/yaffs2/yportenv.h @@ -17,6 +17,14 @@ #ifndef __YPORTENV_H__ #define __YPORTENV_H__ +/* + * Define the MTD version in terms of Linux Kernel versions + * This allows yaffs to be used independantly of the kernel + * as well as with it. + */ + +#define MTD_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) + #if defined CONFIG_YAFFS_WINCE #include "ywinceenv.h" @@ -26,7 +34,10 @@ #include "moduleconfig.h" /* Linux kernel */ + #include <linux/version.h> +#define MTD_VERSION_CODE LINUX_VERSION_CODE + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) #include <linux/config.h> #endif @@ -90,6 +101,8 @@ #elif defined CONFIG_YAFFS_DIRECT +#define MTD_VERSION_CODE MTD_VERSION(2,6,22) + /* Direct interface */ #include "ydirectenv.h" @@ -180,8 +193,8 @@ extern unsigned int yaffs_wr_attempts; #define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p);} while(0) -#ifndef CONFIG_YAFFS_WINCE -#define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__)) +#ifndef YBUG +#define YBUG() do {T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__));} while(0) #endif #endif diff --git a/target/linux/generic-2.6/files/fs/yaffs2/Kconfig b/target/linux/generic-2.6/files/fs/yaffs2/Kconfig index 7b6f836cd..de1516390 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/Kconfig +++ b/target/linux/generic-2.6/files/fs/yaffs2/Kconfig @@ -43,7 +43,8 @@ config YAFFS_9BYTE_TAGS format that you need to continue to support. New data written also uses the older-style format. Note: Use of this option generally requires that MTD's oob layout be adjusted to use the - older-style format. See notes on tags formats and MTD versions. + older-style format. See notes on tags formats and MTD versions + in yaffs_mtdif1.c. If unsure, say N. @@ -109,26 +110,6 @@ config YAFFS_DISABLE_LAZY_LOAD If unsure, say N. -config YAFFS_CHECKPOINT_RESERVED_BLOCKS - int "Reserved blocks for checkpointing" - depends on YAFFS_YAFFS2 - default 10 - help - Give the number of Blocks to reserve for checkpointing. - Checkpointing saves the state at unmount so that mounting is - much faster as a scan of all the flash to regenerate this state - is not needed. These Blocks are reserved per partition, so if - you have very small partitions the default (10) may be a mess - for you. You can set this value to 0, but that does not mean - checkpointing is disabled at all. There only won't be any - specially reserved blocks for checkpointing, so if there is - enough free space on the filesystem, it will be used for - checkpointing. - - If unsure, leave at default (10), but don't wonder if there are - always 2MB used on your large page device partition (10 x 2k - pagesize). When using small partitions or when being very small - on space, you probably want to set this to zero. config YAFFS_DISABLE_WIDE_TNODES bool "Turn off wide tnodes" diff --git a/target/linux/generic-2.6/files/fs/yaffs2/Makefile b/target/linux/generic-2.6/files/fs/yaffs2/Makefile index 73f46583f..382ee6142 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/Makefile +++ b/target/linux/generic-2.6/files/fs/yaffs2/Makefile @@ -5,7 +5,6 @@ obj-$(CONFIG_YAFFS_FS) += yaffs.o yaffs-y := yaffs_ecc.o yaffs_fs.o yaffs_guts.o yaffs_checkptrw.o -yaffs-y += yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o +yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o yaffs-y += yaffs_tagscompat.o yaffs_tagsvalidity.o -yaffs-y += yaffs_mtdif1.o yaffs_packedtags1.o -yaffs-y += yaffs_mtdif.o yaffs_mtdif2.o +yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o diff --git a/target/linux/generic-2.6/files/fs/yaffs2/devextras.h b/target/linux/generic-2.6/files/fs/yaffs2/devextras.h index fcf2690a5..55c31219d 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/devextras.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/devextras.h @@ -14,194 +14,117 @@ */ /* - * This file is just holds extra declarations used during development. - * Most of these are from kernel includes placed here so we can use them in - * applications. + * This file is just holds extra declarations of macros that would normally + * be providesd in the Linux kernel. These macros have been written from + * scratch but are functionally equivalent to the Linux ones. * */ #ifndef __EXTRAS_H__ #define __EXTRAS_H__ -#if defined WIN32 -#define __inline__ __inline -#define new newHack -#endif - -#if !(defined __KERNEL__) || (defined WIN32) -/* User space defines */ +#if !(defined __KERNEL__) +/* Definition of types */ typedef unsigned char __u8; typedef unsigned short __u16; typedef unsigned __u32; +#endif + /* - * Simple doubly linked list implementation. - * - * Some of the internal functions ("__xxx") are useful when - * manipulating whole lists rather than single entries, as - * sometimes we already know the next/prev entries and we can - * generate better code by using them directly rather than - * using the generic single-entry routines. + * This is a simple doubly linked list implementation that matches the + * way the Linux kernel doubly linked list implementation works. */ -#define prefetch(x) 1 - -struct list_head { - struct list_head *next, *prev; +struct ylist_head { + struct ylist_head *next; /* next in chain */ + struct ylist_head *prev; /* previous in chain */ }; -#define LIST_HEAD_INIT(name) { &(name), &(name) } -#define LIST_HEAD(name) \ - struct list_head name = LIST_HEAD_INIT(name) +/* Initialise a list head to an empty list */ +#define YINIT_LIST_HEAD(p) \ +do { \ + (p)->next = (p);\ + (p)->prev = (p); \ +} while(0) -#define INIT_LIST_HEAD(ptr) do { \ - (ptr)->next = (ptr); (ptr)->prev = (ptr); \ -} while (0) -/* - * Insert a new entry between two known consecutive entries. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_add(struct list_head *new, - struct list_head *prev, - struct list_head *next) +/* Add an element to a list */ +static __inline__ void ylist_add(struct ylist_head *newEntry, + struct ylist_head *list) { - next->prev = new; - new->next = next; - new->prev = prev; - prev->next = new; + struct ylist_head *listNext = list->next; + + list->next = newEntry; + newEntry->prev = list; + newEntry->next = listNext; + listNext->prev = newEntry; + } -/** - * list_add - add a new entry - * @new: new entry to be added - * @head: list head to add it after - * - * Insert a new entry after the specified head. - * This is good for implementing stacks. - */ -static __inline__ void list_add(struct list_head *new, struct list_head *head) -{ - __list_add(new, head, head->next); -} -/** - * list_add_tail - add a new entry - * @new: new entry to be added - * @head: list head to add it before - * - * Insert a new entry before the specified head. - * This is useful for implementing queues. - */ -static __inline__ void list_add_tail(struct list_head *new, - struct list_head *head) +/* Take an element out of its current list, with or without + * reinitialising the links.of the entry*/ +static __inline__ void ylist_del(struct ylist_head *entry) { - __list_add(new, head->prev, head); + struct ylist_head *listNext = entry->next; + struct ylist_head *listPrev = entry->prev; + + listNext->prev = listPrev; + listPrev->next = listNext; + } -/* - * Delete a list entry by making the prev/next entries - * point to each other. - * - * This is only for internal list manipulation where we know - * the prev/next entries already! - */ -static __inline__ void __list_del(struct list_head *prev, - struct list_head *next) +static __inline__ void ylist_del_init(struct ylist_head *entry) { - next->prev = prev; - prev->next = next; + ylist_del(entry); + entry->next = entry->prev = entry; } -/** - * list_del - deletes entry from list. - * @entry: the element to delete from the list. - * Note: list_empty on entry does not return true after this, the entry is - * in an undefined state. - */ -static __inline__ void list_del(struct list_head *entry) -{ - __list_del(entry->prev, entry->next); -} -/** - * list_del_init - deletes entry from list and reinitialize it. - * @entry: the element to delete from the list. - */ -static __inline__ void list_del_init(struct list_head *entry) +/* Test if the list is empty */ +static __inline__ int ylist_empty(struct ylist_head *entry) { - __list_del(entry->prev, entry->next); - INIT_LIST_HEAD(entry); + return (entry->next == entry); } -/** - * list_empty - tests whether a list is empty - * @head: the list to test. + +/* ylist_entry takes a pointer to a list entry and offsets it to that + * we can find a pointer to the object it is embedded in. */ -static __inline__ int list_empty(struct list_head *head) -{ - return head->next == head; -} + + +#define ylist_entry(entry, type, member) \ + ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member))) + -/** - * list_splice - join two lists - * @list: the new list to add. - * @head: the place to add it in the first list. +/* ylist_for_each and list_for_each_safe iterate over lists. + * ylist_for_each_safe uses temporary storage to make the list delete safe */ -static __inline__ void list_splice(struct list_head *list, - struct list_head *head) -{ - struct list_head *first = list->next; - if (first != list) { - struct list_head *last = list->prev; - struct list_head *at = head->next; +#define ylist_for_each(itervar, list) \ + for (itervar = (list)->next; itervar != (list); itervar = itervar->next ) - first->prev = head; - head->next = first; +#define ylist_for_each_safe(itervar,saveVar, list) \ + for (itervar = (list)->next, saveVar = (list)->next->next; itervar != (list); \ + itervar = saveVar, saveVar = saveVar->next) - last->next = at; - at->prev = last; - } -} -/** - * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_struct within the struct. - */ -#define list_entry(ptr, type, member) \ - ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) +#if !(defined __KERNEL__) + + +#ifndef WIN32 +#include <sys/stat.h> +#endif + + +#ifdef CONFIG_YAFFS_PROVIDE_DEFS +/* File types */ -/** - * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. - * @head: the head for your list. - */ -#define list_for_each(pos, head) \ - for (pos = (head)->next, prefetch(pos->next); pos != (head); \ - pos = pos->next, prefetch(pos->next)) - -/** - * list_for_each_safe - iterate over a list safe against removal - * of list entry - * @pos: the &struct list_head to use as a loop counter. - * @n: another &struct list_head to use as temporary storage - * @head: the head for your list. - */ -#define list_for_each_safe(pos, n, head) \ - for (pos = (head)->next, n = pos->next; pos != (head); \ - pos = n, n = pos->next) -/* - * File types - */ #define DT_UNKNOWN 0 #define DT_FIFO 1 #define DT_CHR 2 @@ -212,13 +135,13 @@ static __inline__ void list_splice(struct list_head *list, #define DT_SOCK 12 #define DT_WHT 14 + #ifndef WIN32 #include <sys/stat.h> #endif /* - * Attribute flags. These should be or-ed together to figure out what - * has been changed! + * Attribute flags. */ #define ATTR_MODE 1 #define ATTR_UID 2 @@ -227,10 +150,7 @@ static __inline__ void list_splice(struct list_head *list, #define ATTR_ATIME 16 #define ATTR_MTIME 32 #define ATTR_CTIME 64 -#define ATTR_ATIME_SET 128 -#define ATTR_MTIME_SET 256 -#define ATTR_FORCE 512 /* Not a change, but a change it */ -#define ATTR_ATTR_FLAG 1024 + struct iattr { unsigned int ia_valid; @@ -244,21 +164,18 @@ struct iattr { unsigned int ia_attr_flags; }; +#endif + + #define KERN_DEBUG #else -#ifndef WIN32 #include <linux/types.h> -#include <linux/list.h> #include <linux/fs.h> #include <linux/stat.h> -#endif #endif -#if defined WIN32 -#undef new -#endif #endif diff --git a/target/linux/generic-2.6/files/fs/yaffs2/moduleconfig.h b/target/linux/generic-2.6/files/fs/yaffs2/moduleconfig.h index 016391ca5..ac5af6f35 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/moduleconfig.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/moduleconfig.h @@ -54,11 +54,11 @@ that you need to continue to support. New data written also uses the older-style format. Note: Use of this option generally requires that MTD's oob layout be adjusted to use the older-style format. See notes on tags formats and -MTD versions. +MTD versions in yaffs_mtdif1.c. */ /* Default: Not selected */ /* Meaning: Use older-style on-NAND data format with pageStatus byte */ -#define CONFIG_YAFFS_9BYTE_TAGS +//#define CONFIG_YAFFS_9BYTE_TAGS #endif /* YAFFS_OUT_OF_TREE */ diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_checkptrw.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_checkptrw.c index 933a33fb8..68e6d0ce5 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_checkptrw.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_checkptrw.c @@ -12,11 +12,11 @@ */ const char *yaffs_checkptrw_c_version = - "$Id: yaffs_checkptrw.c,v 1.14 2007-05-15 20:07:40 charles Exp $"; + "$Id: yaffs_checkptrw.c,v 1.16 2008-05-05 07:58:58 charles Exp $"; #include "yaffs_checkptrw.h" - +#include "yaffs_getblockinfo.h" static int yaffs_CheckpointSpaceOk(yaffs_Device *dev) { @@ -142,7 +142,7 @@ int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) return 0; if(!dev->checkpointBuffer) - dev->checkpointBuffer = YMALLOC_DMA(dev->nDataBytesPerChunk); + dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk); if(!dev->checkpointBuffer) return 0; diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_ecc.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_ecc.c index e2860393d..9f5973a5b 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_ecc.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_ecc.c @@ -29,7 +29,7 @@ */ const char *yaffs_ecc_c_version = - "$Id: yaffs_ecc.c,v 1.9 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_ecc.c,v 1.10 2007-12-13 15:35:17 wookey Exp $"; #include "yportenv.h" diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_fs.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_fs.c index 67001b10e..ab6a3a7e0 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_fs.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_fs.c @@ -32,7 +32,7 @@ */ const char *yaffs_fs_c_version = - "$Id: yaffs_fs.c,v 1.63 2007-09-19 20:35:40 imcd Exp $"; + "$Id: yaffs_fs.c,v 1.66 2008-05-05 07:58:58 charles Exp $"; extern const char *yaffs_guts_c_version; #include <linux/version.h> @@ -53,6 +53,8 @@ extern const char *yaffs_guts_c_version; #include <linux/string.h> #include <linux/ctype.h> +#include "asm/div64.h" + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)) #include <linux/statfs.h> /* Added NCB 15-8-2003 */ @@ -753,6 +755,8 @@ static void yaffs_FillInodeFromObject(struct inode *inode, yaffs_Object * obj) break; } + inode->i_flags |= S_NOATIME; + inode->i_ino = obj->objectId; inode->i_mode = obj->yst_mode; inode->i_uid = obj->yst_uid; @@ -1350,25 +1354,47 @@ static int yaffs_statfs(struct super_block *sb, struct statfs *buf) buf->f_type = YAFFS_MAGIC; buf->f_bsize = sb->s_blocksize; buf->f_namelen = 255; - if (sb->s_blocksize > dev->nDataBytesPerChunk) { - + + if(dev->nDataBytesPerChunk & (dev->nDataBytesPerChunk - 1)){ + /* Do this if chunk size is not a power of 2 */ + + uint64_t bytesInDev; + uint64_t bytesFree; + + bytesInDev = ((uint64_t)((dev->endBlock - dev->startBlock +1))) * + ((uint64_t)(dev->nChunksPerBlock * dev->nDataBytesPerChunk)); + + do_div(bytesInDev,sb->s_blocksize); /* bytesInDev becomes the number of blocks */ + buf->f_blocks = bytesInDev; + + bytesFree = ((uint64_t)(yaffs_GetNumberOfFreeChunks(dev))) * + ((uint64_t)(dev->nDataBytesPerChunk)); + + do_div(bytesFree,sb->s_blocksize); + + buf->f_bfree = bytesFree; + + } else if (sb->s_blocksize > dev->nDataBytesPerChunk) { + buf->f_blocks = - (dev->endBlock - dev->startBlock + - 1) * dev->nChunksPerBlock / (sb->s_blocksize / - dev->nDataBytesPerChunk); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) / (sb->s_blocksize / - dev->nDataBytesPerChunk); + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock / + (sb->s_blocksize / dev->nDataBytesPerChunk); + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) / + (sb->s_blocksize / dev->nDataBytesPerChunk); } else { - - buf->f_blocks = - (dev->endBlock - dev->startBlock + - 1) * dev->nChunksPerBlock * (dev->nDataBytesPerChunk / - sb->s_blocksize); - buf->f_bfree = - yaffs_GetNumberOfFreeChunks(dev) * (dev->nDataBytesPerChunk / - sb->s_blocksize); + buf->f_blocks = + (dev->endBlock - dev->startBlock + 1) * + dev->nChunksPerBlock * + (dev->nDataBytesPerChunk / sb->s_blocksize); + + buf->f_bfree = + yaffs_GetNumberOfFreeChunks(dev) * + (dev->nDataBytesPerChunk / sb->s_blocksize); } + + buf->f_files = 0; buf->f_ffree = 0; buf->f_bavail = buf->f_bfree; @@ -1602,6 +1628,7 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, sb->s_magic = YAFFS_MAGIC; sb->s_op = &yaffs_super_ops; + sb->s_flags |= MS_NOATIME; if (!sb) printk(KERN_INFO "yaffs: sb is NULL\n"); @@ -1678,22 +1705,15 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, #ifdef CONFIG_YAFFS_AUTO_YAFFS2 if (yaffsVersion == 1 && -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - mtd->writesize >= 2048) { -#else - mtd->oobblock >= 2048) { -#endif + WRITE_SIZE(mtd) >= 2048) { T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs2\n")); yaffsVersion = 2; } /* Added NCB 26/5/2006 for completeness */ - if (yaffsVersion == 2 && -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - mtd->writesize == 512) { -#else - mtd->oobblock == 512) { -#endif + if (yaffsVersion == 2 && + !options.inband_tags && + WRITE_SIZE(mtd) == 512){ T(YAFFS_TRACE_ALWAYS,("yaffs: auto selecting yaffs1\n")); yaffsVersion = 1; } @@ -1719,12 +1739,9 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, return NULL; } -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (mtd->writesize < YAFFS_MIN_YAFFS2_CHUNK_SIZE || -#else - if (mtd->oobblock < YAFFS_MIN_YAFFS2_CHUNK_SIZE || -#endif - mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) { + if ((WRITE_SIZE(mtd) < YAFFS_MIN_YAFFS2_CHUNK_SIZE || + mtd->oobsize < YAFFS_MIN_YAFFS2_SPARE_SIZE) && + !options.inband_tags) { T(YAFFS_TRACE_ALWAYS, ("yaffs: MTD device does not have the " "right page sizes\n")); @@ -1784,9 +1801,10 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->startBlock = 0; dev->endBlock = nBlocks - 1; dev->nChunksPerBlock = YAFFS_CHUNKS_PER_BLOCK; - dev->nDataBytesPerChunk = YAFFS_BYTES_PER_CHUNK; + dev->totalBytesPerChunk = YAFFS_BYTES_PER_CHUNK; dev->nReservedBlocks = 5; dev->nShortOpCaches = (options.no_cache) ? 0 : 10; + dev->inbandTags = options.inband_tags; /* ... and the functions. */ if (yaffsVersion == 2) { @@ -1799,15 +1817,14 @@ static struct super_block *yaffs_internal_read_super(int yaffsVersion, dev->spareBuffer = YMALLOC(mtd->oobsize); dev->isYaffs2 = 1; #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - dev->nDataBytesPerChunk = mtd->writesize; + dev->totalBytesPerChunk = mtd->writesize; dev->nChunksPerBlock = mtd->erasesize / mtd->writesize; #else - dev->nDataBytesPerChunk = mtd->oobblock; + dev->totalBytesPerChunk = mtd->oobblock; dev->nChunksPerBlock = mtd->erasesize / mtd->oobblock; #endif nBlocks = mtd->size / mtd->erasesize; - dev->nCheckpointReservedBlocks = CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS; dev->startBlock = 0; dev->endBlock = nBlocks - 1; } else { @@ -1990,12 +2007,12 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) { buf += sprintf(buf, "startBlock......... %d\n", dev->startBlock); buf += sprintf(buf, "endBlock........... %d\n", dev->endBlock); + buf += sprintf(buf, "totalBytesPerChunk. %d\n", dev->totalBytesPerChunk); buf += sprintf(buf, "nDataBytesPerChunk. %d\n", dev->nDataBytesPerChunk); buf += sprintf(buf, "chunkGroupBits..... %d\n", dev->chunkGroupBits); buf += sprintf(buf, "chunkGroupSize..... %d\n", dev->chunkGroupSize); buf += sprintf(buf, "nErasedBlocks...... %d\n", dev->nErasedBlocks); buf += sprintf(buf, "nReservedBlocks.... %d\n", dev->nReservedBlocks); - buf += sprintf(buf, "nCheckptResBlocks.. %d\n", dev->nCheckpointReservedBlocks); buf += sprintf(buf, "blocksInCheckpoint. %d\n", dev->blocksInCheckpoint); buf += sprintf(buf, "nTnodesCreated..... %d\n", dev->nTnodesCreated); buf += sprintf(buf, "nFreeTnodes........ %d\n", dev->nFreeTnodes); @@ -2006,10 +2023,8 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) buf += sprintf(buf, "nPageReads......... %d\n", dev->nPageReads); buf += sprintf(buf, "nBlockErasures..... %d\n", dev->nBlockErasures); buf += sprintf(buf, "nGCCopies.......... %d\n", dev->nGCCopies); - buf += - sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections); - buf += - sprintf(buf, "passiveGCs......... %d\n", + buf += sprintf(buf, "garbageCollections. %d\n", dev->garbageCollections); + buf += sprintf(buf, "passiveGCs......... %d\n", dev->passiveGarbageCollections); buf += sprintf(buf, "nRetriedWrites..... %d\n", dev->nRetriedWrites); buf += sprintf(buf, "nShortOpCaches..... %d\n", dev->nShortOpCaches); @@ -2025,6 +2040,7 @@ static char *yaffs_dump_dev(char *buf, yaffs_Device * dev) sprintf(buf, "nBackgroudDeletions %d\n", dev->nBackgroundDeletions); buf += sprintf(buf, "useNANDECC......... %d\n", dev->useNANDECC); buf += sprintf(buf, "isYaffs2........... %d\n", dev->isYaffs2); + buf += sprintf(buf, "inbandTags......... %d\n", dev->inbandTags); return buf; } diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_getblockinfo.h b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_getblockinfo.h new file mode 100644 index 000000000..b9742ac0a --- /dev/null +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_getblockinfo.h @@ -0,0 +1,34 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * + * Copyright (C) 2002-2007 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning <charles@aleph1.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 2.1 as + * published by the Free Software Foundation. + * + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + +#ifndef __YAFFS_GETBLOCKINFO_H__ +#define __YAFFS_GETBLOCKINFO_H__ + +#include "yaffs_guts.h" + +/* Function to manipulate block info */ +static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk) +{ + if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { + T(YAFFS_TRACE_ERROR, + (TSTR + ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR), + blk)); + YBUG(); + } + return &dev->blockInfo[blk - dev->internalStartBlock]; +} + +#endif diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.c index 2ab814691..223f2c130 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.c @@ -12,13 +12,14 @@ */ const char *yaffs_guts_c_version = - "$Id: yaffs_guts.c,v 1.49 2007-05-15 20:07:40 charles Exp $"; + "$Id: yaffs_guts.c,v 1.56 2008-05-08 23:23:26 charles Exp $"; #include "yportenv.h" #include "yaffsinterface.h" #include "yaffs_guts.h" #include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" #include "yaffs_tagscompat.h" #ifndef CONFIG_YAFFS_USE_OWN_SORT @@ -78,9 +79,6 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in); static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blockNo); -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, - int lineNo); static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, int chunkInNAND); @@ -121,23 +119,32 @@ static yaffs_Tnode *yaffs_FindLevel0Tnode(yaffs_Device * dev, /* Function to calculate chunk and offset */ -static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, __u32 *chunk, __u32 *offset) +static void yaffs_AddrToChunk(yaffs_Device *dev, loff_t addr, int *chunkOut, __u32 *offsetOut) { - if(dev->chunkShift){ - /* Easy-peasy power of 2 case */ - *chunk = (__u32)(addr >> dev->chunkShift); - *offset = (__u32)(addr & dev->chunkMask); - } - else if(dev->crumbsPerChunk) + int chunk; + __u32 offset; + + chunk = (__u32)(addr >> dev->chunkShift); + + if(dev->chunkDiv == 1) { - /* Case where we're using "crumbs" */ - *offset = (__u32)(addr & dev->crumbMask); - addr >>= dev->crumbShift; - *chunk = ((__u32)addr)/dev->crumbsPerChunk; - *offset += ((addr - (*chunk * dev->crumbsPerChunk)) << dev->crumbShift); + /* easy power of 2 case */ + offset = (__u32)(addr & dev->chunkMask); } else - YBUG(); + { + /* Non power-of-2 case */ + + loff_t chunkBase; + + chunk /= dev->chunkDiv; + + chunkBase = ((loff_t)chunk) * dev->nDataBytesPerChunk; + offset = (__u32)(addr - chunkBase); + } + + *chunkOut = chunk; + *offsetOut = offset; } /* Function to return the number of shifts for a power of 2 greater than or equal @@ -168,7 +175,7 @@ static __u32 ShiftsGE(__u32 x) /* Function to return the number of shifts to get a 1 in bit 0 */ -static __u32 ShiftDiv(__u32 x) +static __u32 Shifts(__u32 x) { int nShifts; @@ -200,16 +207,21 @@ static int yaffs_InitialiseTempBuffers(yaffs_Device *dev) for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) { dev->tempBuffer[i].line = 0; /* not in use */ dev->tempBuffer[i].buffer = buf = - YMALLOC_DMA(dev->nDataBytesPerChunk); + YMALLOC_DMA(dev->totalBytesPerChunk); } return buf ? YAFFS_OK : YAFFS_FAIL; } -static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) +__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) { int i, j; + + dev->tempInUse++; + if(dev->tempInUse > dev->maxTemp) + dev->maxTemp = dev->tempInUse; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].line == 0) { dev->tempBuffer[i].line = lineNo; @@ -242,10 +254,13 @@ static __u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo) } -static void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, +void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo) { int i; + + dev->tempInUse--; + for (i = 0; i < YAFFS_N_TEMP_BUFFERS; i++) { if (dev->tempBuffer[i].buffer == buffer) { dev->tempBuffer[i].line = 0; @@ -390,11 +405,14 @@ static int yaffs_SkipVerification(yaffs_Device *dev) return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL)); } +#if 0 static int yaffs_SkipFullVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_FULL)); } +#endif + static int yaffs_SkipNANDVerification(yaffs_Device *dev) { return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY_NAND)); @@ -597,7 +615,6 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object * obj, yaffs_Tnode * tn, int i; yaffs_Device *dev = obj->myDev; int ok = 1; - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; if (tn) { if (level > 0) { @@ -646,7 +663,6 @@ static void yaffs_VerifyFile(yaffs_Object *obj) __u32 lastChunk; __u32 x; __u32 i; - int ok; yaffs_Device *dev; yaffs_ExtendedTags tags; yaffs_Tnode *tn; @@ -829,7 +845,7 @@ static void yaffs_VerifyObjects(yaffs_Device *dev) { yaffs_Object *obj; int i; - struct list_head *lh; + struct ylist_head *lh; if(yaffs_SkipVerification(dev)) return; @@ -837,9 +853,9 @@ static void yaffs_VerifyObjects(yaffs_Device *dev) /* Iterate through the objects in each hash entry */ for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){ - list_for_each(lh, &dev->objectBucket[i].list) { + ylist_for_each(lh, &dev->objectBucket[i].list) { if (lh) { - obj = list_entry(lh, yaffs_Object, hashLink); + obj = ylist_entry(lh, yaffs_Object, hashLink); yaffs_VerifyObject(obj); } } @@ -915,7 +931,6 @@ static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, } - static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, const __u8 * data, yaffs_ExtendedTags * tags, @@ -992,7 +1007,11 @@ static int yaffs_WriteNewChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, /* Copy the data into the robustification buffer */ yaffs_HandleWriteChunkOk(dev, chunk, data, tags); - } while (writeOk != YAFFS_OK && attempts < yaffs_wr_attempts); + } while (writeOk != YAFFS_OK && + (yaffs_wr_attempts <= 0 || attempts <= yaffs_wr_attempts)); + + if(!writeOk) + chunk = -1; if (attempts > 1) { T(YAFFS_TRACE_ERROR, @@ -1143,6 +1162,10 @@ static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes) * Must be a multiple of 32-bits */ tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + + /* make these things */ newTnodes = YMALLOC(nTnodes * tnodeSize); @@ -1233,15 +1256,21 @@ static yaffs_Tnode *yaffs_GetTnodeRaw(yaffs_Device * dev) dev->nFreeTnodes--; } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + return tn; } static yaffs_Tnode *yaffs_GetTnode(yaffs_Device * dev) { yaffs_Tnode *tn = yaffs_GetTnodeRaw(dev); + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); if(tn) - memset(tn, 0, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + memset(tn, 0, tnodeSize); return tn; } @@ -1262,6 +1291,8 @@ static void yaffs_FreeTnode(yaffs_Device * dev, yaffs_Tnode * tn) dev->freeTnodes = tn; dev->nFreeTnodes++; } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + } static void yaffs_DeinitialiseTnodes(yaffs_Device * dev) @@ -1854,7 +1885,7 @@ static int yaffs_CreateFreeObjects(yaffs_Device * dev, int nObjects) /* Hook them into the free list */ for (i = 0; i < nObjects - 1; i++) { newObjects[i].siblings.next = - (struct list_head *)(&newObjects[i + 1]); + (struct ylist_head *)(&newObjects[i + 1]); } newObjects[nObjects - 1].siblings.next = (void *)dev->freeObjects; @@ -1894,9 +1925,9 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) tn->myDev = dev; tn->chunkId = -1; tn->variantType = YAFFS_OBJECT_TYPE_UNKNOWN; - INIT_LIST_HEAD(&(tn->hardLinks)); - INIT_LIST_HEAD(&(tn->hashLink)); - INIT_LIST_HEAD(&tn->siblings); + YINIT_LIST_HEAD(&(tn->hardLinks)); + YINIT_LIST_HEAD(&(tn->hashLink)); + YINIT_LIST_HEAD(&tn->siblings); /* Add it to the lost and found directory. * NB Can't put root or lostNFound in lostNFound so @@ -1907,6 +1938,8 @@ static yaffs_Object *yaffs_AllocateEmptyObject(yaffs_Device * dev) } } + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + return tn; } @@ -1937,8 +1970,8 @@ static void yaffs_UnhashObject(yaffs_Object * tn) yaffs_Device *dev = tn->myDev; /* If it is still linked into the bucket list, free from the list */ - if (!list_empty(&tn->hashLink)) { - list_del_init(&tn->hashLink); + if (!ylist_empty(&tn->hashLink)) { + ylist_del_init(&tn->hashLink); bucket = yaffs_HashFunction(tn->objectId); dev->objectBucket[bucket].count--; } @@ -1964,9 +1997,12 @@ static void yaffs_FreeObject(yaffs_Object * tn) yaffs_UnhashObject(tn); /* Link into the free list. */ - tn->siblings.next = (struct list_head *)(dev->freeObjects); + tn->siblings.next = (struct ylist_head *)(dev->freeObjects); dev->freeObjects = tn; dev->nFreeObjects++; + + dev->nCheckpointBlocksRequired = 0; /* force recalculation*/ + } #ifdef __KERNEL__ @@ -2007,7 +2043,7 @@ static void yaffs_InitialiseObjects(yaffs_Device * dev) dev->nFreeObjects = 0; for (i = 0; i < YAFFS_NOBJECT_BUCKETS; i++) { - INIT_LIST_HEAD(&dev->objectBucket[i].list); + YINIT_LIST_HEAD(&dev->objectBucket[i].list); dev->objectBucket[i].count = 0; } @@ -2058,7 +2094,7 @@ static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) */ int found = 0; - struct list_head *i; + struct ylist_head *i; __u32 n = (__u32) bucket; @@ -2068,10 +2104,10 @@ static int yaffs_CreateNewObjectNumber(yaffs_Device * dev) found = 1; n += YAFFS_NOBJECT_BUCKETS; if (1 || dev->objectBucket[bucket].count > 0) { - list_for_each(i, &dev->objectBucket[bucket].list) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { /* If there is already one in the list */ if (i - && list_entry(i, yaffs_Object, + && ylist_entry(i, yaffs_Object, hashLink)->objectId == n) { found = 0; } @@ -2088,7 +2124,7 @@ static void yaffs_HashObject(yaffs_Object * in) int bucket = yaffs_HashFunction(in->objectId); yaffs_Device *dev = in->myDev; - list_add(&in->hashLink, &dev->objectBucket[bucket].list); + ylist_add(&in->hashLink, &dev->objectBucket[bucket].list); dev->objectBucket[bucket].count++; } @@ -2096,13 +2132,13 @@ static void yaffs_HashObject(yaffs_Object * in) yaffs_Object *yaffs_FindObjectByNumber(yaffs_Device * dev, __u32 number) { int bucket = yaffs_HashFunction(number); - struct list_head *i; + struct ylist_head *i; yaffs_Object *in; - list_for_each(i, &dev->objectBucket[bucket].list) { + ylist_for_each(i, &dev->objectBucket[bucket].list) { /* Look if it is in the list */ if (i) { - in = list_entry(i, yaffs_Object, hashLink); + in = ylist_entry(i, yaffs_Object, hashLink); if (in->objectId == number) { #ifdef __KERNEL__ /* Don't tell the VFS about this one if it is defered free */ @@ -2123,7 +2159,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, { yaffs_Object *theObject; - yaffs_Tnode *tn; + yaffs_Tnode *tn = NULL; if (number < 0) { number = yaffs_CreateNewObjectNumber(dev); @@ -2171,7 +2207,7 @@ yaffs_Object *yaffs_CreateNewObject(yaffs_Device * dev, int number, theObject->variant.fileVariant.top = tn; break; case YAFFS_OBJECT_TYPE_DIRECTORY: - INIT_LIST_HEAD(&theObject->variant.directoryVariant. + YINIT_LIST_HEAD(&theObject->variant.directoryVariant. children); break; case YAFFS_OBJECT_TYPE_SYMLINK: @@ -2238,7 +2274,7 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, const YCHAR * aliasString, __u32 rdev) { yaffs_Object *in; - YCHAR *str; + YCHAR *str = NULL; yaffs_Device *dev = parent->myDev; @@ -2296,7 +2332,7 @@ static yaffs_Object *yaffs_MknodObject(yaffs_ObjectType type, equivalentObject; in->variant.hardLinkVariant.equivalentObjectId = equivalentObject->objectId; - list_add(&in->hardLinks, &equivalentObject->hardLinks); + ylist_add(&in->hardLinks, &equivalentObject->hardLinks); break; case YAFFS_OBJECT_TYPE_FILE: case YAFFS_OBJECT_TYPE_DIRECTORY: @@ -2457,7 +2493,7 @@ int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName, existingTarget = yaffs_FindObjectByName(newDir, newName); if (existingTarget && existingTarget->variantType == YAFFS_OBJECT_TYPE_DIRECTORY && - !list_empty(&existingTarget->variant.directoryVariant.children)) { + !ylist_empty(&existingTarget->variant.directoryVariant.children)) { /* There is a target that is a non-empty directory, so we fail */ return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */ } else if (existingTarget && existingTarget != obj) { @@ -2801,6 +2837,40 @@ static int yaffs_FindBlockForAllocation(yaffs_Device * dev) } + +static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev) +{ + if(!dev->nCheckpointBlocksRequired){ + /* Not a valid value so recalculate */ + int nBytes = 0; + int nBlocks; + int devBlocks = (dev->endBlock - dev->startBlock + 1); + int tnodeSize; + + tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + + nBytes += sizeof(yaffs_CheckpointValidity); + nBytes += sizeof(yaffs_CheckpointDevice); + nBytes += devBlocks * sizeof(yaffs_BlockInfo); + nBytes += devBlocks * dev->chunkBitmapStride; + nBytes += (sizeof(yaffs_CheckpointObject) + sizeof(__u32)) * (dev->nObjectsCreated - dev->nFreeObjects); + nBytes += (tnodeSize + sizeof(__u32)) * (dev->nTnodesCreated - dev->nFreeTnodes); + nBytes += sizeof(yaffs_CheckpointValidity); + nBytes += sizeof(__u32); /* checksum*/ + + /* Round up and add 2 blocks to allow for some bad blocks, so add 3 */ + + nBlocks = (nBytes/(dev->nDataBytesPerChunk * dev->nChunksPerBlock)) + 3; + + dev->nCheckpointBlocksRequired = nBlocks; + } + + return dev->nCheckpointBlocksRequired; +} + // Check if there's space to allocate... // Thinks.... do we need top make this ths same as yaffs_GetFreeChunks()? static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) @@ -2809,7 +2879,7 @@ static int yaffs_CheckSpaceForAllocation(yaffs_Device * dev) int reservedBlocks = dev->nReservedBlocks; int checkpointBlocks; - checkpointBlocks = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint; + checkpointBlocks = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(checkpointBlocks < 0) checkpointBlocks = 0; @@ -3037,7 +3107,7 @@ static int yaffs_GarbageCollectBlock(yaffs_Device * dev, int block) yaffs_ObjectHeader *oh; oh = (yaffs_ObjectHeader *)buffer; oh->isShrink = 0; - oh->shadowsObject = -1; + oh->shadowsObject = oh->inbandShadowsObject = -1; tags.extraShadows = 0; tags.extraIsShrinkHeader = 0; @@ -3142,7 +3212,7 @@ static int yaffs_CheckGarbageCollection(yaffs_Device * dev) do { maxTries++; - checkpointBlockAdjust = (dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint); + checkpointBlockAdjust = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(checkpointBlockAdjust < 0) checkpointBlockAdjust = 0; @@ -3628,7 +3698,7 @@ int yaffs_UpdateObjectHeader(yaffs_Object * in, const YCHAR * name, int force, oh->type = in->variantType; oh->yst_mode = in->yst_mode; - oh->shadowsObject = shadows; + oh->shadowsObject = oh->inbandShadowsObject = shadows; #ifdef CONFIG_YAFFS_WINCE oh->win_atime[0] = in->win_atime[0]; @@ -4220,7 +4290,11 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, int i; yaffs_Device *dev = in->myDev; int ok = 1; - int nTnodeBytes = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); + if (tn) { if (level > 0) { @@ -4238,7 +4312,7 @@ static int yaffs_CheckpointTnodeWorker(yaffs_Object * in, yaffs_Tnode * tn, /* printf("write tnode at %d\n",baseOffset); */ ok = (yaffs_CheckpointWrite(dev,&baseOffset,sizeof(baseOffset)) == sizeof(baseOffset)); if(ok) - ok = (yaffs_CheckpointWrite(dev,tn,nTnodeBytes) == nTnodeBytes); + ok = (yaffs_CheckpointWrite(dev,tn,tnodeSize) == tnodeSize); } } @@ -4272,6 +4346,10 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) yaffs_FileStructure *fileStructPtr = &obj->variant.fileVariant; yaffs_Tnode *tn; int nread = 0; + int tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8; + + if(tnodeSize < sizeof(yaffs_Tnode)) + tnodeSize = sizeof(yaffs_Tnode); ok = (yaffs_CheckpointRead(dev,&baseChunk,sizeof(baseChunk)) == sizeof(baseChunk)); @@ -4283,8 +4361,7 @@ static int yaffs_ReadCheckpointTnodes(yaffs_Object *obj) /* printf("read tnode at %d\n",baseChunk); */ tn = yaffs_GetTnodeRaw(dev); if(tn) - ok = (yaffs_CheckpointRead(dev,tn,(dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8) == - (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8); + ok = (yaffs_CheckpointRead(dev,tn,tnodeSize) == tnodeSize); else ok = 0; @@ -4315,7 +4392,7 @@ static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) yaffs_CheckpointObject cp; int i; int ok = 1; - struct list_head *lh; + struct ylist_head *lh; /* Iterate through the objects in each hash entry, @@ -4323,9 +4400,9 @@ static int yaffs_WriteCheckpointObjects(yaffs_Device *dev) */ for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){ - list_for_each(lh, &dev->objectBucket[i].list) { + ylist_for_each(lh, &dev->objectBucket[i].list) { if (lh) { - obj = list_entry(lh, yaffs_Object, hashLink); + obj = ylist_entry(lh, yaffs_Object, hashLink); if (!obj->deferedFree) { yaffs_ObjectToCheckpointObject(&cp,obj); cp.structType = sizeof(cp); @@ -4383,7 +4460,7 @@ static int yaffs_ReadCheckpointObjects(yaffs_Device *dev) ok = yaffs_ReadCheckpointTnodes(obj); } else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { obj->hardLinks.next = - (struct list_head *) + (struct ylist_head *) hardList; hardList = obj; } @@ -4589,7 +4666,7 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, { int chunk; - int start; + __u32 start; int nToCopy; int n = nBytes; int nDone = 0; @@ -4617,10 +4694,10 @@ int yaffs_ReadDataFromFile(yaffs_Object * in, __u8 * buffer, loff_t offset, cache = yaffs_FindChunkCache(in, chunk); /* If the chunk is already in the cache or it is less than a whole chunk - * then use the cache (if there is caching) + * or we're using inband tags then use the cache (if there is caching) * else bypass the cache. */ - if (cache || nToCopy != dev->nDataBytesPerChunk) { + if (cache || nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { if (dev->nShortOpCaches > 0) { /* If we can't find the data in the cache, then load it up. */ @@ -4709,7 +4786,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, { int chunk; - int start; + __u32 start; int nToCopy; int n = nBytes; int nDone = 0; @@ -4757,8 +4834,10 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, nToWriteBack = dev->nDataBytesPerChunk; } - if (nToCopy != dev->nDataBytesPerChunk) { - /* An incomplete start or end chunk (or maybe both start and end chunk) */ + if (nToCopy != dev->nDataBytesPerChunk || dev->inbandTags) { + /* An incomplete start or end chunk (or maybe both start and end chunk), + * or we're using inband tags, so we want to use the cache buffers. + */ if (dev->nShortOpCaches > 0) { yaffs_ChunkCache *cache; /* If we can't find the data in the cache, then load the cache */ @@ -4846,7 +4925,8 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, } } else { - + /* A full chunk. Write directly from the supplied buffer. */ + #ifdef CONFIG_YAFFS_WINCE /* Under WinCE can't do direct transfer. Need to use a local buffer. * This is because we otherwise screw up WinCE's memory mapper @@ -4865,7 +4945,7 @@ int yaffs_WriteDataToFile(yaffs_Object * in, const __u8 * buffer, loff_t offset, 0); yaffs_ReleaseTempBuffer(dev, localBuffer, __LINE__); #else - /* A full chunk. Write directly from the supplied buffer. */ + chunkWritten = yaffs_WriteChunkDataToObject(in, chunk, buffer, dev->nDataBytesPerChunk, @@ -4943,7 +5023,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) { int oldFileSize = in->variant.fileVariant.fileSize; - int newSizeOfPartialChunk; + __u32 newSizeOfPartialChunk; int newFullChunks; yaffs_Device *dev = in->myDev; @@ -4956,11 +5036,11 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) yaffs_CheckGarbageCollection(dev); if (in->variantType != YAFFS_OBJECT_TYPE_FILE) { - return yaffs_GetFileSize(in); + return YAFFS_FAIL; } if (newSize == oldFileSize) { - return oldFileSize; + return YAFFS_OK; } if (newSize < oldFileSize) { @@ -5005,7 +5085,7 @@ int yaffs_ResizeFile(yaffs_Object * in, loff_t newSize) (newSize < oldFileSize) ? 1 : 0, 0); } - return newSize; + return YAFFS_OK; } loff_t yaffs_GetFileSize(yaffs_Object * obj) @@ -5058,7 +5138,7 @@ static int yaffs_DoGenericObjectDeletion(yaffs_Object * in) if (in->myDev->isYaffs2 && (in->parent != in->myDev->deletedDir)) { /* Move to the unlinked directory so we have a record that it was deleted. */ - yaffs_ChangeObjectName(in, in->myDev->deletedDir,"deleted", 0, 0); + yaffs_ChangeObjectName(in, in->myDev->deletedDir,_Y("deleted"), 0, 0); } @@ -5096,7 +5176,7 @@ static int yaffs_UnlinkFile(yaffs_Object * in) if (immediateDeletion) { retVal = yaffs_ChangeObjectName(in, in->myDev->deletedDir, - "deleted", 0, 0); + _Y("deleted"), 0, 0); T(YAFFS_TRACE_TRACING, (TSTR("yaffs: immediate deletion of file %d" TENDSTR), in->objectId)); @@ -5109,7 +5189,7 @@ static int yaffs_UnlinkFile(yaffs_Object * in) } else { retVal = yaffs_ChangeObjectName(in, in->myDev->unlinkedDir, - "unlinked", 0, 0); + _Y("unlinked"), 0, 0); } } @@ -5144,7 +5224,7 @@ int yaffs_DeleteFile(yaffs_Object * in) static int yaffs_DeleteDirectory(yaffs_Object * in) { /* First check that the directory is empty. */ - if (list_empty(&in->variant.directoryVariant.children)) { + if (ylist_empty(&in->variant.directoryVariant.children)) { return yaffs_DoGenericObjectDeletion(in); } @@ -5164,7 +5244,7 @@ static int yaffs_DeleteHardLink(yaffs_Object * in) /* remove this hardlink from the list assocaited with the equivalent * object */ - list_del(&in->hardLinks); + ylist_del(&in->hardLinks); return yaffs_DoGenericObjectDeletion(in); } @@ -5196,7 +5276,7 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) if (obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK) { return yaffs_DeleteHardLink(obj); - } else if (!list_empty(&obj->hardLinks)) { + } else if (!ylist_empty(&obj->hardLinks)) { /* Curve ball: We're unlinking an object that has a hardlink. * * This problem arises because we are not strictly following @@ -5215,10 +5295,10 @@ static int yaffs_UnlinkWorker(yaffs_Object * obj) int retVal; YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - hl = list_entry(obj->hardLinks.next, yaffs_Object, hardLinks); + hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks); - list_del_init(&hl->hardLinks); - list_del_init(&hl->siblings); + ylist_del_init(&hl->hardLinks); + ylist_del_init(&hl->siblings); yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1); @@ -5325,13 +5405,13 @@ static void yaffs_HardlinkFixup(yaffs_Device *dev, yaffs_Object *hardList) if (in) { /* Add the hardlink pointers */ hl->variant.hardLinkVariant.equivalentObject = in; - list_add(&hl->hardLinks, &in->hardLinks); + ylist_add(&hl->hardLinks, &in->hardLinks); } else { /* Todo Need to report/handle this better. * Got a problem... hardlink to a non-existant object */ hl->variant.hardLinkVariant.equivalentObject = NULL; - INIT_LIST_HEAD(&hl->hardLinks); + YINIT_LIST_HEAD(&hl->hardLinks); } @@ -5371,7 +5451,7 @@ static int yaffs_Scan(yaffs_Device * dev) yaffs_BlockState state; yaffs_Object *hardList = NULL; yaffs_BlockInfo *bi; - int sequenceNumber; + __u32 sequenceNumber; yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; @@ -5488,6 +5568,8 @@ static int yaffs_Scan(yaffs_Device * dev) for (blockIterator = startIterator; !alloc_failed && blockIterator <= endIterator; blockIterator++) { + YYIELD(); + if (dev->isYaffs2) { /* get the block to scan in the correct order */ blk = blockIndex[blockIterator].block; @@ -5548,8 +5630,7 @@ static int yaffs_Scan(yaffs_Device * dev) bi->sequenceNumber)) { T(YAFFS_TRACE_ALWAYS, (TSTR - ("yaffs: Allocation block %d was not highest sequence id:" - " block seq = %d, dev seq = %d" + ("yaffs: Allocation block %d was not highest sequence id: block seq = %d, dev seq = %d" TENDSTR), blk,bi->sequenceNumber,dev->sequenceNumber)); } } @@ -5723,7 +5804,7 @@ static int yaffs_Scan(yaffs_Device * dev) /* Set up as a directory */ parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; - INIT_LIST_HEAD(&parent->variant. + YINIT_LIST_HEAD(&parent->variant. directoryVariant. children); } else if (parent->variantType != @@ -5735,8 +5816,7 @@ static int yaffs_Scan(yaffs_Device * dev) T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: attempting to use non-directory as" - " a directory in scan. Put in lost+found." + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found." TENDSTR))); parent = dev->lostNFoundDir; } @@ -5781,7 +5861,7 @@ static int yaffs_Scan(yaffs_Device * dev) equivalentObjectId = oh->equivalentObjectId; in->hardLinks.next = - (struct list_head *) + (struct ylist_head *) hardList; hardList = in; break; @@ -5840,16 +5920,16 @@ static int yaffs_Scan(yaffs_Device * dev) * just delete them. */ { - struct list_head *i; - struct list_head *n; + struct ylist_head *i; + struct ylist_head *n; yaffs_Object *l; /* Soft delete all the unlinked files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->unlinkedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } } @@ -5938,7 +6018,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) yaffs_BlockState state; yaffs_Object *hardList = NULL; yaffs_BlockInfo *bi; - int sequenceNumber; + __u32 sequenceNumber; yaffs_ObjectHeader *oh; yaffs_Object *in; yaffs_Object *parent; @@ -6053,8 +6133,10 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Sort the blocks */ #ifndef CONFIG_YAFFS_USE_OWN_SORT - yaffs_qsort(blockIndex, nBlocksToScan, - sizeof(yaffs_BlockIndex), ybicmp); + { + /* Use qsort now. */ + yaffs_qsort(blockIndex, nBlocksToScan, sizeof(yaffs_BlockIndex), ybicmp); + } #else { /* Dungy old bubble sort... */ @@ -6265,6 +6347,12 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) NULL); oh = (yaffs_ObjectHeader *) chunkData; + + if(dev->inbandTags){ + /* Fix up the header if they got corrupted by inband tags */ + oh->shadowsObject = oh->inbandShadowsObject; + oh->isShrink = oh->inbandIsShrink; + } if (!in) in = yaffs_FindOrCreateObjectByNumber(dev, tags.objectId, oh->type); @@ -6275,8 +6363,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* TODO Hoosterman we have a problem! */ T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: Could not make object for object %d " - "at chunk %d during scan" + ("yaffs tragedy: Could not make object for object %d at chunk %d during scan" TENDSTR), tags.objectId, chunk)); } @@ -6434,7 +6521,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) /* Set up as a directory */ parent->variantType = YAFFS_OBJECT_TYPE_DIRECTORY; - INIT_LIST_HEAD(&parent->variant. + YINIT_LIST_HEAD(&parent->variant. directoryVariant. children); } else if (parent->variantType != @@ -6446,8 +6533,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) T(YAFFS_TRACE_ERROR, (TSTR - ("yaffs tragedy: attempting to use non-directory as" - " a directory in scan. Put in lost+found." + ("yaffs tragedy: attempting to use non-directory as a directory in scan. Put in lost+found." TENDSTR))); parent = dev->lostNFoundDir; } @@ -6498,7 +6584,7 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) in->variant.hardLinkVariant.equivalentObjectId = equivalentObjectId; in->hardLinks.next = - (struct list_head *) hardList; + (struct ylist_head *) hardList; hardList = in; } break; @@ -6558,27 +6644,27 @@ static int yaffs_ScanBackwards(yaffs_Device * dev) * Sort out state of unlinked and deleted objects. */ { - struct list_head *i; - struct list_head *n; + struct ylist_head *i; + struct ylist_head *n; yaffs_Object *l; /* Soft delete all the unlinked files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->unlinkedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } } /* Soft delete all the deletedDir files */ - list_for_each_safe(i, n, + ylist_for_each_safe(i, n, &dev->deletedDir->variant.directoryVariant. children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_DestroyObject(l); } @@ -6605,7 +6691,7 @@ static void yaffs_RemoveObjectFromDirectory(yaffs_Object * obj) if(dev && dev->removeObjectCallback) dev->removeObjectCallback(obj); - list_del_init(&obj->siblings); + ylist_del_init(&obj->siblings); obj->parent = NULL; } @@ -6631,14 +6717,14 @@ static void yaffs_AddObjectToDirectory(yaffs_Object * directory, if (obj->siblings.prev == NULL) { /* Not initialised */ - INIT_LIST_HEAD(&obj->siblings); + YINIT_LIST_HEAD(&obj->siblings); - } else if (!list_empty(&obj->siblings)) { + } else if (!ylist_empty(&obj->siblings)) { /* If it is holed up somewhere else, un hook it */ yaffs_RemoveObjectFromDirectory(obj); } /* Now add it */ - list_add(&obj->siblings, &directory->variant.directoryVariant.children); + ylist_add(&obj->siblings, &directory->variant.directoryVariant.children); obj->parent = directory; if (directory == obj->myDev->unlinkedDir @@ -6654,7 +6740,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, { int sum; - struct list_head *i; + struct ylist_head *i; YCHAR buffer[YAFFS_MAX_NAME_LENGTH + 1]; yaffs_Object *l; @@ -6679,9 +6765,9 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, sum = yaffs_CalcNameSum(name); - list_for_each(i, &directory->variant.directoryVariant.children) { + ylist_for_each(i, &directory->variant.directoryVariant.children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); yaffs_CheckObjectDetailsLoaded(l); @@ -6713,7 +6799,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object * directory, int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, int (*fn) (yaffs_Object *)) { - struct list_head *i; + struct ylist_head *i; yaffs_Object *l; if (!theDir) { @@ -6730,9 +6816,9 @@ int yaffs_ApplyToDirectoryChildren(yaffs_Object * theDir, YBUG(); } - list_for_each(i, &theDir->variant.directoryVariant.children) { + ylist_for_each(i, &theDir->variant.directoryVariant.children) { if (i) { - l = list_entry(i, yaffs_Object, siblings); + l = ylist_entry(i, yaffs_Object, siblings); if (l && !fn(l)) { return YAFFS_FAIL; } @@ -6821,12 +6907,12 @@ int yaffs_GetObjectFileLength(yaffs_Object * obj) int yaffs_GetObjectLinkCount(yaffs_Object * obj) { int count = 0; - struct list_head *i; + struct ylist_head *i; if (!obj->unlinked) { count++; /* the object itself */ } - list_for_each(i, &obj->hardLinks) { + ylist_for_each(i, &obj->hardLinks) { count++; /* add the hard links; */ } return count; @@ -7049,8 +7135,9 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* Check geometry parameters. */ - if ((dev->isYaffs2 && dev->nDataBytesPerChunk < 1024) || - (!dev->isYaffs2 && dev->nDataBytesPerChunk != 512) || + if ((!dev->inbandTags && dev->isYaffs2 && dev->totalBytesPerChunk < 1024) || + (!dev->isYaffs2 && dev->totalBytesPerChunk != 512) || + (dev->inbandTags && !dev->isYaffs2 ) || dev->nChunksPerBlock < 2 || dev->nReservedBlocks < 2 || dev->internalStartBlock <= 0 || @@ -7059,8 +7146,8 @@ int yaffs_GutsInitialise(yaffs_Device * dev) ) { T(YAFFS_TRACE_ALWAYS, (TSTR - ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s " - TENDSTR), dev->nDataBytesPerChunk, dev->isYaffs2 ? "2" : "")); + ("yaffs: NAND geometry problems: chunk size %d, type is yaffs%s, inbandTags %d " + TENDSTR), dev->totalBytesPerChunk, dev->isYaffs2 ? "2" : "", dev->inbandTags)); return YAFFS_FAIL; } @@ -7069,6 +7156,12 @@ int yaffs_GutsInitialise(yaffs_Device * dev) (TSTR("yaffs: InitialiseNAND failed" TENDSTR))); return YAFFS_FAIL; } + + /* Sort out space for inband tags, if required */ + if(dev->inbandTags) + dev->nDataBytesPerChunk = dev->totalBytesPerChunk - sizeof(yaffs_PackedTags2TagsPart); + else + dev->nDataBytesPerChunk = dev->totalBytesPerChunk; /* Got the right mix of functions? */ if (!yaffs_CheckDevFunctions(dev)) { @@ -7104,22 +7197,14 @@ int yaffs_GutsInitialise(yaffs_Device * dev) /* * Calculate all the chunk size manipulation numbers: */ - /* Start off assuming it is a power of 2 */ - dev->chunkShift = ShiftDiv(dev->nDataBytesPerChunk); - dev->chunkMask = (1<<dev->chunkShift) - 1; - - if(dev->nDataBytesPerChunk == (dev->chunkMask + 1)){ - /* Yes it is a power of 2, disable crumbs */ - dev->crumbMask = 0; - dev->crumbShift = 0; - dev->crumbsPerChunk = 0; - } else { - /* Not a power of 2, use crumbs instead */ - dev->crumbShift = ShiftDiv(sizeof(yaffs_PackedTags2TagsPart)); - dev->crumbMask = (1<<dev->crumbShift)-1; - dev->crumbsPerChunk = dev->nDataBytesPerChunk/(1 << dev->crumbShift); - dev->chunkShift = 0; - dev->chunkMask = 0; + { + __u32 x = dev->nDataBytesPerChunk; + /* We always use dev->chunkShift and dev->chunkDiv */ + dev->chunkShift = Shifts(x); + x >>= dev->chunkShift; + dev->chunkDiv = x; + /* We only use chunk mask if chunkDiv is 1 */ + dev->chunkMask = (1<<dev->chunkShift) - 1; } @@ -7203,7 +7288,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) if (!init_failed && dev->nShortOpCaches > 0) { int i; - __u8 *buf; + void *buf; int srCacheBytes = dev->nShortOpCaches * sizeof(yaffs_ChunkCache); if (dev->nShortOpCaches > YAFFS_MAX_SHORT_OP_CACHES) { @@ -7219,7 +7304,7 @@ int yaffs_GutsInitialise(yaffs_Device * dev) dev->srCache[i].object = NULL; dev->srCache[i].lastUse = 0; dev->srCache[i].dirty = 0; - dev->srCache[i].data = buf = YMALLOC_DMA(dev->nDataBytesPerChunk); + dev->srCache[i].data = buf = YMALLOC_DMA(dev->totalBytesPerChunk); } if(!buf) init_failed = 1; @@ -7345,6 +7430,7 @@ void yaffs_Deinitialise(yaffs_Device * dev) YFREE(dev->tempBuffer[i].buffer); } + dev->isMounted = 0; } @@ -7410,7 +7496,7 @@ int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev) nFree -= ((dev->nReservedBlocks + 1) * dev->nChunksPerBlock); /* Now we figure out how much to reserve for the checkpoint and report that... */ - blocksForCheckpoint = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint; + blocksForCheckpoint = yaffs_CalcCheckpointBlocksRequired(dev) - dev->blocksInCheckpoint; if(blocksForCheckpoint < 0) blocksForCheckpoint = 0; @@ -7448,22 +7534,25 @@ static void yaffs_VerifyFreeChunks(yaffs_Device * dev) /*---------------------------------------- YAFFS test code ----------------------*/ #define yaffs_CheckStruct(structure,syze, name) \ + do { \ if(sizeof(structure) != syze) \ { \ T(YAFFS_TRACE_ALWAYS,(TSTR("%s should be %d but is %d\n" TENDSTR),\ name,syze,sizeof(structure))); \ return YAFFS_FAIL; \ - } + } \ + } while(0) static int yaffs_CheckStructures(void) { -/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags") */ -/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion") */ -/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare") */ +/* yaffs_CheckStruct(yaffs_Tags,8,"yaffs_Tags"); */ +/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion"); */ +/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare"); */ #ifndef CONFIG_YAFFS_TNODE_LIST_DEBUG - yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode") + yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode"); +#endif +#ifndef CONFIG_YAFFS_WINCE + yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader"); #endif - yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader") - return YAFFS_OK; } diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.h b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.h index ea06c1a38..b9b2ea194 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_guts.h @@ -90,7 +90,7 @@ #define YAFFS_MAX_SHORT_OP_CACHES 20 -#define YAFFS_N_TEMP_BUFFERS 4 +#define YAFFS_N_TEMP_BUFFERS 6 /* We limit the number attempts at sucessfully saving a chunk of data. * Small-page devices have 32 pages per block; large-page devices have 64. @@ -277,7 +277,7 @@ typedef struct { int softDeletions:10; /* number of soft deleted pages */ int pagesInUse:10; /* number of pages in use */ - yaffs_BlockState blockState:4; /* One of the above block states */ + unsigned blockState:4; /* One of the above block states. NB use unsigned because enum is sometimes an int */ __u32 needsRetiring:1; /* Data has failed on this block, need to get valid data off */ /* and retire the block. */ __u32 skipErasedCheck: 1; /* If this is set we can skip the erased check on this block */ @@ -303,7 +303,7 @@ typedef struct { __u16 sum__NoLongerUsed; /* checksum of name. No longer used */ YCHAR name[YAFFS_MAX_NAME_LENGTH + 1]; - /* Thes following apply to directories, files, symlinks - not hard links */ + /* The following apply to directories, files, symlinks - not hard links */ __u32 yst_mode; /* protection */ #ifdef CONFIG_YAFFS_WINCE @@ -331,11 +331,14 @@ typedef struct { __u32 win_ctime[2]; __u32 win_atime[2]; __u32 win_mtime[2]; - __u32 roomToGrow[4]; #else - __u32 roomToGrow[10]; + __u32 roomToGrow[6]; + #endif + __u32 inbandShadowsObject; + __u32 inbandIsShrink; + __u32 reservedSpace[2]; int shadowsObject; /* This object header shadows the specified object if > 0 */ /* isShrink applies to object headers written when we shrink the file (ie resize) */ @@ -381,7 +384,7 @@ typedef struct { } yaffs_FileStructure; typedef struct { - struct list_head children; /* list of child links */ + struct ylist_head children; /* list of child links */ } yaffs_DirectoryStructure; typedef struct { @@ -424,14 +427,14 @@ struct yaffs_ObjectStruct { struct yaffs_DeviceStruct *myDev; /* The device I'm on */ - struct list_head hashLink; /* list of objects in this hash bucket */ + struct ylist_head hashLink; /* list of objects in this hash bucket */ - struct list_head hardLinks; /* all the equivalent hard linked objects */ + struct ylist_head hardLinks; /* all the equivalent hard linked objects */ /* directory structure stuff */ /* also used for linking up the free list */ struct yaffs_ObjectStruct *parent; - struct list_head siblings; + struct ylist_head siblings; /* Where's my object header in NAND? */ int chunkId; @@ -485,7 +488,7 @@ struct yaffs_ObjectList_struct { typedef struct yaffs_ObjectList_struct yaffs_ObjectList; typedef struct { - struct list_head list; + struct ylist_head list; int count; } yaffs_ObjectBucket; @@ -528,7 +531,7 @@ typedef struct { /*----------------- Device ---------------------------------*/ struct yaffs_DeviceStruct { - struct list_head devList; + struct ylist_head devList; const char *name; /* Entry parameters set up way early. Yaffs sets up the rest.*/ @@ -544,7 +547,7 @@ struct yaffs_DeviceStruct { /* Stuff used by the shared space checkpointing mechanism */ /* If this value is zero, then this mechanism is disabled */ - int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ +// int nCheckpointReservedBlocks; /* Blocks to reserve for checkpoint data */ @@ -583,7 +586,7 @@ struct yaffs_DeviceStruct { yaffs_ExtendedTags * tags); int (*markNANDBlockBad) (struct yaffs_DeviceStruct * dev, int blockNo); int (*queryNANDBlock) (struct yaffs_DeviceStruct * dev, int blockNo, - yaffs_BlockState * state, int *sequenceNumber); + yaffs_BlockState * state, __u32 *sequenceNumber); #endif int isYaffs2; @@ -598,7 +601,8 @@ struct yaffs_DeviceStruct { void (*markSuperBlockDirty)(void * superblock); int wideTnodesDisabled; /* Set to disable wide tnodes */ - + + YCHAR *pathDividers; /* String of legal path dividers */ /* End of stuff that must be set before initialisation. */ @@ -615,16 +619,14 @@ struct yaffs_DeviceStruct { __u32 tnodeWidth; __u32 tnodeMask; - /* Stuff to support various file offses to chunk/offset translations */ - /* "Crumbs" for nDataBytesPerChunk not being a power of 2 */ - __u32 crumbMask; - __u32 crumbShift; - __u32 crumbsPerChunk; - - /* Straight shifting for nDataBytesPerChunk being a power of 2 */ - __u32 chunkShift; - __u32 chunkMask; + /* Stuff for figuring out file offset to chunk conversions */ + __u32 chunkShift; /* Shift value */ + __u32 chunkDiv; /* Divisor after shifting: 1 for power-of-2 sizes */ + __u32 chunkMask; /* Mask to use for power-of-2 case */ + /* Stuff to handle inband tags */ + int inbandTags; + __u32 totalBytesPerChunk; #ifdef __KERNEL__ @@ -663,6 +665,8 @@ struct yaffs_DeviceStruct { __u32 checkpointSum; __u32 checkpointXor; + int nCheckpointBlocksRequired; /* Number of blocks needed to store current checkpoint set */ + /* Block Info */ yaffs_BlockInfo *blockInfo; __u8 *chunkBits; /* bitmap of chunks in use */ @@ -744,9 +748,11 @@ struct yaffs_DeviceStruct { int nUnlinkedFiles; /* Count of unlinked files. */ int nBackgroundDeletions; /* Count of background deletions. */ - + + /* Temporary buffer management */ yaffs_TempBuffer tempBuffer[YAFFS_N_TEMP_BUFFERS]; int maxTemp; + int tempInUse; int unmanagedTempAllocations; int unmanagedTempDeallocations; @@ -758,7 +764,7 @@ struct yaffs_DeviceStruct { typedef struct yaffs_DeviceStruct yaffs_Device; -/* The static layout of bllock usage etc is stored in the super block header */ +/* The static layout of block usage etc is stored in the super block header */ typedef struct { int StructType; int version; @@ -797,18 +803,6 @@ typedef struct { __u32 head; } yaffs_CheckpointValidity; -/* Function to manipulate block info */ -static Y_INLINE yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device * dev, int blk) -{ - if (blk < dev->internalStartBlock || blk > dev->internalEndBlock) { - T(YAFFS_TRACE_ERROR, - (TSTR - ("**>> yaffs: getBlockInfo block %d is not valid" TENDSTR), - blk)); - YBUG(); - } - return &dev->blockInfo[blk - dev->internalStartBlock]; -} /*----------------------- YAFFS Functions -----------------------*/ @@ -899,4 +893,7 @@ void yaffs_DeleteChunk(yaffs_Device * dev, int chunkId, int markNAND, int lyn); int yaffs_CheckFF(__u8 * buffer, int nBytes); void yaffs_HandleChunkError(yaffs_Device *dev, yaffs_BlockInfo *bi); +__u8 *yaffs_GetTempBuffer(yaffs_Device * dev, int lineNo); +void yaffs_ReleaseTempBuffer(yaffs_Device * dev, __u8 * buffer, int lineNo); + #endif diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.c index 466e5a44c..4888b96f6 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.c @@ -12,7 +12,7 @@ */ const char *yaffs_mtdif_c_version = - "$Id: yaffs_mtdif.c,v 1.19 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_mtdif.c,v 1.21 2007-12-13 15:35:18 wookey Exp $"; #include "yportenv.h" @@ -24,7 +24,7 @@ const char *yaffs_mtdif_c_version = #include "linux/time.h" #include "linux/mtd/nand.h" -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)) +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) static struct nand_oobinfo yaffs_oobinfo = { .useecc = 1, .eccbytes = 6, @@ -36,7 +36,7 @@ static struct nand_oobinfo yaffs_noeccinfo = { }; #endif -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) static inline void translate_spare2oob(const yaffs_Spare *spare, __u8 *oob) { oob[0] = spare->tagByte0; @@ -75,14 +75,14 @@ int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) @@ -139,14 +139,14 @@ int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_Spare * spare) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) __u8 spareAsBytes[8]; /* OOB */ if (data && !spare) diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.h b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.h index 317600cac..511b0176a 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif.h @@ -18,6 +18,11 @@ #include "yaffs_guts.h" +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,18)) +extern struct nand_oobinfo yaffs_oobinfo; +extern struct nand_oobinfo yaffs_noeccinfo; +#endif + int nandmtd_WriteChunkToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_Spare * spare); int nandmtd_ReadChunkFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1-compat.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1-compat.c deleted file mode 100644 index 6ea675611..000000000 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1-compat.c +++ /dev/null @@ -1,434 +0,0 @@ -From ian@brightstareng.com Fri May 18 15:06:49 2007 -From ian@brightstareng.com Fri May 18 15:08:21 2007 -Received: from 206.173.66.57.ptr.us.xo.net ([206.173.66.57] helo=zebra.brightstareng.com) - by apollo.linkchoose.co.uk with esmtp (Exim 4.60) - (envelope-from <ian@brightstareng.com>) - id 1Hp380-00011e-T6 - for david.goodenough@linkchoose.co.uk; Fri, 18 May 2007 15:08:21 +0100 -Received: from localhost (localhost.localdomain [127.0.0.1]) - by zebra.brightstareng.com (Postfix) with ESMTP - id 4819F28C004; Fri, 18 May 2007 10:07:49 -0400 (EDT) -Received: from zebra.brightstareng.com ([127.0.0.1]) - by localhost (zebra [127.0.0.1]) (amavisd-new, port 10024) with ESMTP - id 05328-06; Fri, 18 May 2007 10:07:16 -0400 (EDT) -Received: from pippin (unknown [192.168.1.25]) - by zebra.brightstareng.com (Postfix) with ESMTP - id 8BEF528C1BC; Fri, 18 May 2007 10:06:53 -0400 (EDT) -From: Ian McDonnell <ian@brightstareng.com> -To: David Goodenough <david.goodenough@linkchoose.co.uk> -Subject: Re: something tested this time -- yaffs_mtdif1-compat.c -Date: Fri, 18 May 2007 10:06:49 -0400 -User-Agent: KMail/1.9.1 -References: <200705142207.06909.ian@brightstareng.com> <200705171131.53536.ian@brightstareng.com> <200705181334.32166.david.goodenough@linkchoose.co.uk> -In-Reply-To: <200705181334.32166.david.goodenough@linkchoose.co.uk> -Cc: Andrea Conti <alyf@alyf.net>, - Charles Manning <manningc2@actrix.gen.nz> -MIME-Version: 1.0 -Content-Type: Multipart/Mixed; - boundary="Boundary-00=_5LbTGmt62YoutxM" -Message-Id: <200705181006.49860.ian@brightstareng.com> -X-Virus-Scanned: by amavisd-new at brightstareng.com -Status: R -X-Status: NT -X-KMail-EncryptionState: -X-KMail-SignatureState: -X-KMail-MDN-Sent: - ---Boundary-00=_5LbTGmt62YoutxM -Content-Type: text/plain; - charset="iso-8859-15" -Content-Transfer-Encoding: 7bit -Content-Disposition: inline - -David, Andrea, - -On Friday 18 May 2007 08:34, you wrote: -> Yea team. With this fix in place (I put it in the wrong place -> at first) I can now mount and ls the Yaffs partition without -> an error messages! - -Good news! - -Attached is a newer yaffs_mtdif1.c with a bandaid to help the -2.6.18 and 2.6.19 versions of MTD not trip on the oob read. -See the LINUX_VERSION_CODE conditional in -nandmtd1_ReadChunkWithTagsFromNAND. - --imcd - ---Boundary-00=_5LbTGmt62YoutxM -Content-Type: text/x-csrc; - charset="iso-8859-15"; - name="yaffs_mtdif1.c" -Content-Transfer-Encoding: 7bit -Content-Disposition: attachment; - filename="yaffs_mtdif1.c" - -/* - * YAFFS: Yet another FFS. A NAND-flash specific file system. - * yaffs_mtdif1.c NAND mtd interface functions for small-page NAND. - * - * Copyright (C) 2002 Aleph One Ltd. - * for Toby Churchill Ltd and Brightstar Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ - -/* - * This module provides the interface between yaffs_nand.c and the - * MTD API. This version is used when the MTD interface supports the - * 'mtd_oob_ops' style calls to read_oob and write_oob, circa 2.6.17, - * and we have small-page NAND device. - * - * These functions are invoked via function pointers in yaffs_nand.c. - * This replaces functionality provided by functions in yaffs_mtdif.c - * and the yaffs_TagsCompatability functions in yaffs_tagscompat.c that are - * called in yaffs_mtdif.c when the function pointers are NULL. - * We assume the MTD layer is performing ECC (useNANDECC is true). - */ - -#include "yportenv.h" -#include "yaffs_guts.h" -#include "yaffs_packedtags1.h" -#include "yaffs_tagscompat.h" // for yaffs_CalcTagsECC - -#include "linux/kernel.h" -#include "linux/version.h" -#include "linux/types.h" -#include "linux/mtd/mtd.h" - -/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $"; - -#ifndef CONFIG_YAFFS_9BYTE_TAGS -# define YTAG1_SIZE 8 -#else -# define YTAG1_SIZE 9 -#endif - -#if 0 -/* Use the following nand_ecclayout with MTD when using - * CONFIG_YAFFS_9BYTE_TAGS and the older on-NAND tags layout. - * If you have existing Yaffs images and the byte order differs from this, - * adjust 'oobfree' to match your existing Yaffs data. - * - * This nand_ecclayout scatters/gathers to/from the old-yaffs layout with the - * pageStatus byte (at NAND spare offset 4) scattered/gathered from/to - * the 9th byte. - * - * Old-style on-NAND format: T0,T1,T2,T3,P,B,T4,T5,E0,E1,E2,T6,T7,E3,E4,E5 - * We have/need PackedTags1 plus pageStatus: T0,T1,T2,T3,T4,T5,T6,T7,P - * where Tn are the tag bytes, En are MTD's ECC bytes, P is the pageStatus - * byte and B is the small-page bad-block indicator byte. - */ -static struct nand_ecclayout nand_oob_16 = { - .eccbytes = 6, - .eccpos = { 8, 9, 10, 13, 14, 15 }, - .oobavail = 9, - .oobfree = { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1 } } -}; -#endif - -/* Write a chunk (page) of data to NAND. - * - * Caller always provides ExtendedTags data which are converted to a more - * compact (packed) form for storage in NAND. A mini-ECC runs over the - * contents of the tags meta-data; used to valid the tags when read. - * - * - Pack ExtendedTags to PackedTags1 form - * - Compute mini-ECC for PackedTags1 - * - Write data and packed tags to NAND. - * - * Note: Due to the use of the PackedTags1 meta-data which does not include - * a full sequence number (as found in the larger PackedTags2 form) it is - * necessary for Yaffs to re-write a chunk/page (just once) to mark it as - * discarded and dirty. This is not ideal: newer NAND parts are supposed - * to be written just once. When Yaffs performs this operation, this - * function is called with a NULL data pointer -- calling MTD write_oob - * without data is valid usage (2.6.17). - * - * Any underlying MTD error results in YAFFS_FAIL. - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev, - int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * etags) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkBytes = dev->nDataBytesPerChunk; - loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; - struct mtd_oob_ops ops; - yaffs_PackedTags1 pt1; - int retval; - - /* we assume that PackedTags1 and yaffs_Tags are compatible */ - compile_time_assertion(sizeof(yaffs_PackedTags1) == 12); - compile_time_assertion(sizeof(yaffs_Tags) == 8); - - yaffs_PackTags1(&pt1, etags); - yaffs_CalcTagsECC((yaffs_Tags *)&pt1); - - /* When deleting a chunk, the upper layer provides only skeletal - * etags, one with chunkDeleted set. However, we need to update the - * tags, not erase them completely. So we use the NAND write property - * that only zeroed-bits stick and set tag bytes to all-ones and - * zero just the (not) deleted bit. - */ -#ifndef CONFIG_YAFFS_9BYTE_TAGS - if (etags->chunkDeleted) { - memset(&pt1, 0xff, 8); - /* clear delete status bit to indicate deleted */ - pt1.deleted = 0; - } -#else - ((__u8 *)&pt1)[8] = 0xff; - if (etags->chunkDeleted) { - memset(&pt1, 0xff, 8); - /* zero pageStatus byte to indicate deleted */ - ((__u8 *)&pt1)[8] = 0; - } -#endif - - memset(&ops, 0, sizeof(ops)); - ops.mode = MTD_OOB_AUTO; - ops.len = (data) ? chunkBytes : 0; - ops.ooblen = YTAG1_SIZE; - ops.datbuf = (__u8 *)data; - ops.oobbuf = (__u8 *)&pt1; - - retval = mtd->write_oob(mtd, addr, &ops); - if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "write_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); - } - return retval ? YAFFS_FAIL : YAFFS_OK; -} - -/* Return with empty ExtendedTags but add eccResult. - */ -static int rettags(yaffs_ExtendedTags * etags, int eccResult, int retval) -{ - if (etags) { - memset(etags, 0, sizeof(*etags)); - etags->eccResult = eccResult; - } - return retval; -} - -/* Read a chunk (page) from NAND. - * - * Caller expects ExtendedTags data to be usable even on error; that is, - * all members except eccResult and blockBad are zeroed. - * - * - Check ECC results for data (if applicable) - * - Check for blank/erased block (return empty ExtendedTags if blank) - * - Check the PackedTags1 mini-ECC (correct if necessary/possible) - * - Convert PackedTags1 to ExtendedTags - * - Update eccResult and blockBad members to refect state. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, - int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkBytes = dev->nDataBytesPerChunk; - loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; - int eccres = YAFFS_ECC_RESULT_NO_ERROR; - struct mtd_oob_ops ops; - yaffs_PackedTags1 pt1; - int retval; - int deleted; - - memset(&ops, 0, sizeof(ops)); - ops.mode = MTD_OOB_AUTO; - ops.len = (data) ? chunkBytes : 0; - ops.ooblen = YTAG1_SIZE; - ops.datbuf = data; - ops.oobbuf = (__u8 *)&pt1; - -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) - /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; - * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. - */ - ops.len = (ops.datbuf) ? ops.len : ops.ooblen; -#endif - /* Read page and oob using MTD. - * Check status and determine ECC result. - */ - retval = mtd->read_oob(mtd, addr, &ops); - if (retval) { - yaffs_trace(YAFFS_TRACE_MTD, - "read_oob failed, chunk %d, mtd error %d\n", - chunkInNAND, retval); - } - - switch (retval) { - case 0: - /* no error */ - break; - - case -EUCLEAN: - /* MTD's ECC fixed the data */ - eccres = YAFFS_ECC_RESULT_FIXED; - dev->eccFixed++; - break; - - case -EBADMSG: - /* MTD's ECC could not fix the data */ - dev->eccUnfixed++; - /* fall into... */ - default: - rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); - etags->blockBad = (mtd->block_isbad)(mtd, addr); - return YAFFS_FAIL; - } - - /* Check for a blank/erased chunk. - */ - if (yaffs_CheckFF((__u8 *)&pt1, 8)) { - /* when blank, upper layers want eccResult to be <= NO_ERROR */ - return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); - } - -#ifndef CONFIG_YAFFS_9BYTE_TAGS - /* Read deleted status (bit) then return it to it's non-deleted - * state before performing tags mini-ECC check. pt1.deleted is - * inverted. - */ - deleted = !pt1.deleted; - pt1.deleted = 1; -#else - (void) deleted; /* not used */ -#endif - - /* Check the packed tags mini-ECC and correct if necessary/possible. - */ - retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); - switch (retval) { - case 0: - /* no tags error, use MTD result */ - break; - case 1: - /* recovered tags-ECC error */ - dev->tagsEccFixed++; - eccres = YAFFS_ECC_RESULT_FIXED; - break; - default: - /* unrecovered tags-ECC error */ - dev->tagsEccUnfixed++; - return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); - } - - /* Unpack the tags to extended form and set ECC result. - * [set shouldBeFF just to keep yaffs_UnpackTags1 happy] - */ - pt1.shouldBeFF = 0xFFFFFFFF; - yaffs_UnpackTags1(etags, &pt1); - etags->eccResult = eccres; - - /* Set deleted state. - */ -#ifndef CONFIG_YAFFS_9BYTE_TAGS - etags->chunkDeleted = deleted; -#else - etags->chunkDeleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); -#endif - return YAFFS_OK; -} - -/* Mark a block bad. - * - * This is a persistant state. - * Use of this function should be rare. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) -{ - struct mtd_info * mtd = dev->genericDevice; - int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; - int retval; - - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); - - retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); - return (retval) ? YAFFS_FAIL : YAFFS_OK; -} - -/* Check any MTD prerequists. - * - * Returns YAFFS_OK or YAFFS_FAIL. - */ -static int nandmtd1_TestPrerequists(struct mtd_info * mtd) -{ - /* 2.6.18 has mtd->ecclayout->oobavail */ - /* 2.6.21 has mtd->ecclayout->oobavail and mtd->oobavail */ - int oobavail = mtd->ecclayout->oobavail; - - if (oobavail < YTAG1_SIZE) { - yaffs_trace(YAFFS_TRACE_ERROR, - "mtd device has only %d bytes for tags, need %d", - oobavail, YTAG1_SIZE); - return YAFFS_FAIL; - } - return YAFFS_OK; -} - -/* Query for the current state of a specific block. - * - * Examine the tags of the first chunk of the block and return the state: - * - YAFFS_BLOCK_STATE_DEAD, the block is marked bad - * - YAFFS_BLOCK_STATE_NEEDS_SCANNING, the block is in use - * - YAFFS_BLOCK_STATE_EMPTY, the block is clean - * - * Always returns YAFFS_OK. - */ -int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * pState, int *pSequenceNumber) -{ - struct mtd_info * mtd = dev->genericDevice; - int chunkNo = blockNo * dev->nChunksPerBlock; - yaffs_ExtendedTags etags; - int state = YAFFS_BLOCK_STATE_DEAD; - int seqnum = 0; - int retval; - - /* We don't yet have a good place to test for MTD config prerequists. - * Do it here as we are called during the initial scan. - */ - if (nandmtd1_TestPrerequists(mtd) != YAFFS_OK) { - return YAFFS_FAIL; - } - - retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); - if (etags.blockBad) { - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad", blockNo); - state = YAFFS_BLOCK_STATE_DEAD; - } - else if (etags.chunkUsed) { - state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; - seqnum = etags.sequenceNumber; - } - else { - state = YAFFS_BLOCK_STATE_EMPTY; - } - - *pState = state; - *pSequenceNumber = seqnum; - - /* query always succeeds */ - return YAFFS_OK; -} - -#endif /*KERNEL_VERSION*/ - ---Boundary-00=_5LbTGmt62YoutxM-- - - - diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1.c index 36d5adec5..2b33c2cfe 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif1.c @@ -34,9 +34,9 @@ #include "linux/mtd/mtd.h" /* Don't compile this module if we don't have MTD's mtd_oob_ops interface */ -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) -const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.3 2007/05/15 20:16:11 ian Exp $"; +const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.7 2007-12-13 15:35:18 wookey Exp $"; #ifndef CONFIG_YAFFS_9BYTE_TAGS # define YTAG1_SIZE 8 @@ -189,7 +189,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) +#if (MTD_VERSION_CODE < MTD_VERSION(2,6,20)) /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. */ @@ -288,7 +288,7 @@ int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo) int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk; int retval; - yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad", blockNo); + yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo); retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo); return (retval) ? YAFFS_FAIL : YAFFS_OK; @@ -327,6 +327,7 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, { struct mtd_info * mtd = dev->genericDevice; int chunkNo = blockNo * dev->nChunksPerBlock; + loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk; yaffs_ExtendedTags etags; int state = YAFFS_BLOCK_STATE_DEAD; int seqnum = 0; @@ -340,11 +341,16 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, } retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags); + etags.blockBad = (mtd->block_isbad)(mtd, addr); if (etags.blockBad) { yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, - "block %d is marked bad", blockNo); + "block %d is marked bad\n", blockNo); state = YAFFS_BLOCK_STATE_DEAD; } + else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) { + /* bad tags, need to look more closely */ + state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; + } else if (etags.chunkUsed) { state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; seqnum = etags.sequenceNumber; @@ -360,4 +366,4 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, return YAFFS_OK; } -#endif /*KERNEL_VERSION*/ +#endif /*MTD_VERSION*/ diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif2.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif2.c index cdad0734b..3768b9b07 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif2.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_mtdif2.c @@ -14,7 +14,7 @@ /* mtd interface for YAFFS2 */ const char *yaffs_mtdif2_c_version = - "$Id: yaffs_mtdif2.c,v 1.17 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_mtdif2.c,v 1.20 2008-05-05 07:58:58 charles Exp $"; #include "yportenv.h" @@ -27,19 +27,23 @@ const char *yaffs_mtdif2_c_version = #include "yaffs_packedtags2.h" +/* NB For use with inband tags.... + * We assume that the data buffer is of size totalBytersPerChunk so that we can also + * use it to load the tags. + */ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, const __u8 * data, const yaffs_ExtendedTags * tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #else size_t dummy; #endif int retval = 0; - loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; + loff_t addr; yaffs_PackedTags2 pt; @@ -47,47 +51,42 @@ int nandmtd2_WriteChunkWithTagsToNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_WriteChunkWithTagsToNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); - -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (tags) - yaffs_PackTags2(&pt, tags); + + + addr = ((loff_t) chunkInNAND) * dev->totalBytesPerChunk; + + /* For yaffs2 writing there must be both data and tags. + * If we're using inband tags, then the tags are stuffed into + * the end of the data buffer. + */ + if(!data || !tags) + BUG(); + else if(dev->inbandTags){ + yaffs_PackedTags2TagsPart *pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)(data + dev->nDataBytesPerChunk); + yaffs_PackTags2TagsPart(pt2tp,tags); + } else - BUG(); /* both tags and data should always be present */ - - if (data) { - ops.mode = MTD_OOB_AUTO; - ops.ooblen = sizeof(pt); - ops.len = dev->nDataBytesPerChunk; - ops.ooboffs = 0; - ops.datbuf = (__u8 *)data; - ops.oobbuf = (void *)&pt; - retval = mtd->write_oob(mtd, addr, &ops); - } else - BUG(); /* both tags and data should always be present */ -#else - if (tags) { yaffs_PackTags2(&pt, tags); - } + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) + ops.mode = MTD_OOB_AUTO; + ops.ooblen = (dev->inbandTags) ? 0 : sizeof(pt); + ops.len = dev->totalBytesPerChunk; + ops.ooboffs = 0; + ops.datbuf = (__u8 *)data; + ops.oobbuf = (dev->inbandTags) ? NULL : (void *)&pt; + retval = mtd->write_oob(mtd, addr, &ops); - if (data && tags) { - if (dev->useNANDECC) - retval = - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); - else - retval = - mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, (__u8 *) & pt, NULL); +#else + if (!dev->inbandTags) { + retval = + mtd->write_ecc(mtd, addr, dev->nDataBytesPerChunk, + &dummy, data, (__u8 *) & pt, NULL); } else { - if (data) - retval = - mtd->write(mtd, addr, dev->nDataBytesPerChunk, &dummy, - data); - if (tags) - retval = - mtd->write_oob(mtd, addr, mtd->oobsize, &dummy, - (__u8 *) & pt); - + retval = + mtd->write(mtd, addr, dev->totalBytesPerChunk, &dummy, + data); } #endif @@ -101,11 +100,12 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * tags) { struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice); -#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) +#if (MTD_VERSION_CODE > MTD_VERSION(2,6,17)) struct mtd_oob_ops ops; #endif size_t dummy; int retval = 0; + int localData = 0; loff_t addr = ((loff_t) chunkInNAND) * dev->nDataBytesPerChunk; @@ -115,10 +115,21 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, (TSTR ("nandmtd2_ReadChunkWithTagsFromNAND chunk %d data %p tags %p" TENDSTR), chunkInNAND, data, tags)); + + if(dev->inbandTags){ + + if(!data) { + localData = 1; + data = yaffs_GetTempBuffer(dev,__LINE__); + } + + + } + #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17)) - if (data && !tags) - retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk, + if (dev->inbandTags || (data && !tags)) + retval = mtd->read(mtd, addr, dev->totalBytesPerChunk, &dummy, data); else if (tags) { ops.mode = MTD_OOB_AUTO; @@ -130,38 +141,43 @@ int nandmtd2_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, retval = mtd->read_oob(mtd, addr, &ops); } #else - if (data && tags) { - if (dev->useNANDECC) { - retval = - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, - &dummy, data, dev->spareBuffer, - NULL); - } else { - retval = - mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, + if (!dev->inbandTags && data && tags) { + + retval = mtd->read_ecc(mtd, addr, dev->nDataBytesPerChunk, &dummy, data, dev->spareBuffer, NULL); - } } else { if (data) retval = mtd->read(mtd, addr, dev->nDataBytesPerChunk, &dummy, data); - if (tags) + if (!dev->inbandTags && tags) retval = mtd->read_oob(mtd, addr, mtd->oobsize, &dummy, dev->spareBuffer); } #endif - memcpy(&pt, dev->spareBuffer, sizeof(pt)); - if (tags) - yaffs_UnpackTags2(tags, &pt); + if(dev->inbandTags){ + if(tags){ + yaffs_PackedTags2TagsPart * pt2tp; + pt2tp = (yaffs_PackedTags2TagsPart *)&data[dev->nDataBytesPerChunk]; + yaffs_UnpackTags2TagsPart(tags,pt2tp); + } + } + else { + if (tags){ + memcpy(&pt, dev->spareBuffer, sizeof(pt)); + yaffs_UnpackTags2(tags, &pt); + } + } + if(localData) + yaffs_ReleaseTempBuffer(dev,data,__LINE__); + if(tags && retval == -EBADMSG && tags->eccResult == YAFFS_ECC_RESULT_NO_ERROR) - tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; - + tags->eccResult = YAFFS_ECC_RESULT_UNFIXED; if (retval == 0) return YAFFS_OK; else diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nand.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nand.c index 4e250338d..af4215772 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nand.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nand.c @@ -12,12 +12,13 @@ */ const char *yaffs_nand_c_version = - "$Id: yaffs_nand.c,v 1.7 2007-02-14 01:09:06 wookey Exp $"; + "$Id: yaffs_nand.c,v 1.9 2008-05-05 07:58:58 charles Exp $"; #include "yaffs_nand.h" #include "yaffs_tagscompat.h" #include "yaffs_tagsvalidity.h" +#include "yaffs_getblockinfo.h" int yaffs_ReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * buffer, @@ -98,7 +99,7 @@ int yaffs_MarkBlockBad(yaffs_Device * dev, int blockNo) int yaffs_QueryInitialBlockState(yaffs_Device * dev, int blockNo, yaffs_BlockState * state, - unsigned *sequenceNumber) + __u32 *sequenceNumber) { blockNo -= dev->blockOffset; diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nandemul2k.h b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nandemul2k.h index cd2e96f7a..c8576b307 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nandemul2k.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_nandemul2k.h @@ -22,13 +22,13 @@ int nandemul2k_WriteChunkWithTagsToNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, const __u8 * data, - yaffs_ExtendedTags * tags); + const yaffs_ExtendedTags * tags); int nandemul2k_ReadChunkWithTagsFromNAND(struct yaffs_DeviceStruct *dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * tags); int nandemul2k_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int nandemul2k_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, - yaffs_BlockState * state, int *sequenceNumber); + yaffs_BlockState * state, __u32 *sequenceNumber); int nandemul2k_EraseBlockInNAND(struct yaffs_DeviceStruct *dev, int blockInNAND); int nandemul2k_InitialiseNAND(struct yaffs_DeviceStruct *dev); diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.c index e420f95da..957ed8bf0 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.c @@ -37,60 +37,70 @@ #define EXTRA_OBJECT_TYPE_SHIFT (28) #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT) -static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) + +static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart * ptt) { T(YAFFS_TRACE_MTD, (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR), - pt->t.objectId, pt->t.chunkId, pt->t.byteCount, - pt->t.sequenceNumber)); + ptt->objectId, ptt->chunkId, ptt->byteCount, + ptt->sequenceNumber)); +} +static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt) +{ + yaffs_DumpPackedTags2TagsPart(&pt->t); } static void yaffs_DumpTags2(const yaffs_ExtendedTags * t) { T(YAFFS_TRACE_MTD, (TSTR - ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte " - "%d del %d ser %d seq %d" + ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d" TENDSTR), t->eccResult, t->blockBad, t->chunkUsed, t->objectId, t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, t->sequenceNumber)); } -void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * ptt, const yaffs_ExtendedTags * t) { - pt->t.chunkId = t->chunkId; - pt->t.sequenceNumber = t->sequenceNumber; - pt->t.byteCount = t->byteCount; - pt->t.objectId = t->objectId; + ptt->chunkId = t->chunkId; + ptt->sequenceNumber = t->sequenceNumber; + ptt->byteCount = t->byteCount; + ptt->objectId = t->objectId; if (t->chunkId == 0 && t->extraHeaderInfoAvailable) { /* Store the extra header info instead */ /* We save the parent object in the chunkId */ - pt->t.chunkId = EXTRA_HEADER_INFO_FLAG + ptt->chunkId = EXTRA_HEADER_INFO_FLAG | t->extraParentObjectId; if (t->extraIsShrinkHeader) { - pt->t.chunkId |= EXTRA_SHRINK_FLAG; + ptt->chunkId |= EXTRA_SHRINK_FLAG; } if (t->extraShadows) { - pt->t.chunkId |= EXTRA_SHADOWS_FLAG; + ptt->chunkId |= EXTRA_SHADOWS_FLAG; } - pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK; - pt->t.objectId |= + ptt->objectId &= ~EXTRA_OBJECT_TYPE_MASK; + ptt->objectId |= (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT); if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { - pt->t.byteCount = t->extraEquivalentObjectId; + ptt->byteCount = t->extraEquivalentObjectId; } else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE) { - pt->t.byteCount = t->extraFileLength; + ptt->byteCount = t->extraFileLength; } else { - pt->t.byteCount = 0; + ptt->byteCount = 0; } } - yaffs_DumpPackedTags2(pt); + yaffs_DumpPackedTags2TagsPart(ptt); yaffs_DumpTags2(t); +} + + +void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) +{ + yaffs_PackTags2TagsPart(&pt->t,t); #ifndef YAFFS_IGNORE_TAGS_ECC { @@ -101,13 +111,60 @@ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t) #endif } -void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) + +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * ptt) { memset(t, 0, sizeof(yaffs_ExtendedTags)); yaffs_InitialiseTags(t); + if (ptt->sequenceNumber != 0xFFFFFFFF) { + t->blockBad = 0; + t->chunkUsed = 1; + t->objectId = ptt->objectId; + t->chunkId = ptt->chunkId; + t->byteCount = ptt->byteCount; + t->chunkDeleted = 0; + t->serialNumber = 0; + t->sequenceNumber = ptt->sequenceNumber; + + /* Do extra header info stuff */ + + if (ptt->chunkId & EXTRA_HEADER_INFO_FLAG) { + t->chunkId = 0; + t->byteCount = 0; + + t->extraHeaderInfoAvailable = 1; + t->extraParentObjectId = + ptt->chunkId & (~(ALL_EXTRA_FLAGS)); + t->extraIsShrinkHeader = + (ptt->chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; + t->extraShadows = + (ptt->chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; + t->extraObjectType = + ptt->objectId >> EXTRA_OBJECT_TYPE_SHIFT; + t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; + + if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { + t->extraEquivalentObjectId = ptt->byteCount; + } else { + t->extraFileLength = ptt->byteCount; + } + } + } + + yaffs_DumpPackedTags2TagsPart(ptt); + yaffs_DumpTags2(t); + +} + + +void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) +{ + + yaffs_UnpackTags2TagsPart(t,&pt->t); + if (pt->t.sequenceNumber != 0xFFFFFFFF) { /* Page is in use */ #ifdef YAFFS_IGNORE_TAGS_ECC @@ -142,41 +199,10 @@ void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt) } } #endif - t->blockBad = 0; - t->chunkUsed = 1; - t->objectId = pt->t.objectId; - t->chunkId = pt->t.chunkId; - t->byteCount = pt->t.byteCount; - t->chunkDeleted = 0; - t->serialNumber = 0; - t->sequenceNumber = pt->t.sequenceNumber; - - /* Do extra header info stuff */ - - if (pt->t.chunkId & EXTRA_HEADER_INFO_FLAG) { - t->chunkId = 0; - t->byteCount = 0; - - t->extraHeaderInfoAvailable = 1; - t->extraParentObjectId = - pt->t.chunkId & (~(ALL_EXTRA_FLAGS)); - t->extraIsShrinkHeader = - (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; - t->extraShadows = - (pt->t.chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; - t->extraObjectType = - pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT; - t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; - - if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) { - t->extraEquivalentObjectId = pt->t.byteCount; - } else { - t->extraFileLength = pt->t.byteCount; - } - } } yaffs_DumpPackedTags2(pt); yaffs_DumpTags2(t); } + diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.h b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.h index c2242ffe7..75761d333 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_packedtags2.h @@ -33,6 +33,11 @@ typedef struct { yaffs_ECCOther ecc; } yaffs_PackedTags2; +/* Full packed tags with ECC, used for oob tags */ void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t); void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt); + +/* Only the tags part (no ECC for use with inband tags */ +void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart * pt, const yaffs_ExtendedTags * t); +void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags * t, yaffs_PackedTags2TagsPart * pt); #endif diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.c b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.c index 7622b1af7..ab756d06d 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.c +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.c @@ -14,6 +14,7 @@ #include "yaffs_guts.h" #include "yaffs_tagscompat.h" #include "yaffs_ecc.h" +#include "yaffs_getblockinfo.h" static void yaffs_HandleReadDataError(yaffs_Device * dev, int chunkInNAND); #ifdef NOTYET @@ -438,7 +439,7 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, yaffs_ECCResult eccResult; static yaffs_Spare spareFF; - static int init; + static int init = 0; if (!init) { memset(&spareFF, 0xFF, sizeof(spareFF)); @@ -497,9 +498,9 @@ int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, } int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, yaffs_BlockState * - state, - int *sequenceNumber) + int blockNo, + yaffs_BlockState *state, + __u32 *sequenceNumber) { yaffs_Spare spare0, spare1; diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.h b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.h index a61e3ba14..6549398ee 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/yaffs_tagscompat.h @@ -30,8 +30,9 @@ int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo); int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, - int blockNo, yaffs_BlockState * - state, int *sequenceNumber); + int blockNo, + yaffs_BlockState *state, + __u32 *sequenceNumber); void yaffs_CalcTagsECC(yaffs_Tags * tags); int yaffs_CheckECCOnTags(yaffs_Tags * tags); diff --git a/target/linux/generic-2.6/files/fs/yaffs2/yportenv.h b/target/linux/generic-2.6/files/fs/yaffs2/yportenv.h index 15ac28121..097b2a675 100644 --- a/target/linux/generic-2.6/files/fs/yaffs2/yportenv.h +++ b/target/linux/generic-2.6/files/fs/yaffs2/yportenv.h @@ -17,6 +17,14 @@ #ifndef __YPORTENV_H__ #define __YPORTENV_H__ +/* + * Define the MTD version in terms of Linux Kernel versions + * This allows yaffs to be used independantly of the kernel + * as well as with it. + */ + +#define MTD_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c)) + #if defined CONFIG_YAFFS_WINCE #include "ywinceenv.h" @@ -26,7 +34,10 @@ #include "moduleconfig.h" /* Linux kernel */ + #include <linux/version.h> +#define MTD_VERSION_CODE LINUX_VERSION_CODE + #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)) #include <linux/config.h> #endif @@ -90,6 +101,8 @@ #elif defined CONFIG_YAFFS_DIRECT +#define MTD_VERSION_CODE MTD_VERSION(2,6,22) + /* Direct interface */ #include "ydirectenv.h" @@ -180,8 +193,8 @@ extern unsigned int yaffs_wr_attempts; #define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ALWAYS)) TOUT(p);} while(0) -#ifndef CONFIG_YAFFS_WINCE -#define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__)) +#ifndef YBUG +#define YBUG() do {T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__));} while(0) #endif #endif |