From d5915a8104264250beafbbaa1412aa1fb0e97b75 Mon Sep 17 00:00:00 2001 From: Waldemar Brodkorb Date: Thu, 18 Nov 2010 19:06:20 +0100 Subject: sync with upstream git --- target/linux/patches/2.6.36/yaffs2.patch | 25047 ++++++++++++++++------------- 1 file changed, 13444 insertions(+), 11603 deletions(-) diff --git a/target/linux/patches/2.6.36/yaffs2.patch b/target/linux/patches/2.6.36/yaffs2.patch index 5d0d7ba6f..ab8924e0f 100644 --- a/target/linux/patches/2.6.36/yaffs2.patch +++ b/target/linux/patches/2.6.36/yaffs2.patch @@ -1,361 +1,26 @@ -diff -Nur linux-2.6.34.orig/fs/Kconfig linux-2.6.34/fs/Kconfig ---- linux-2.6.34.orig/fs/Kconfig 2010-05-16 23:17:36.000000000 +0200 -+++ linux-2.6.34/fs/Kconfig 2010-05-20 20:16:22.261614078 +0200 -@@ -174,6 +174,10 @@ +diff -Nur linux-2.6.36.orig/fs/Kconfig linux-2.6.36/fs/Kconfig +--- linux-2.6.36.orig/fs/Kconfig 2010-10-20 22:30:22.000000000 +0200 ++++ linux-2.6.36/fs/Kconfig 2010-11-18 18:15:51.000000000 +0100 +@@ -174,6 +174,7 @@ source "fs/befs/Kconfig" source "fs/bfs/Kconfig" source "fs/efs/Kconfig" -+ -+# Patched by YAFFS +source "fs/yaffs2/Kconfig" -+ source "fs/jffs2/Kconfig" # UBIFS File system configuration source "fs/ubifs/Kconfig" -diff -Nur linux-2.6.34.orig/fs/Makefile linux-2.6.34/fs/Makefile ---- linux-2.6.34.orig/fs/Makefile 2010-05-16 23:17:36.000000000 +0200 -+++ linux-2.6.34/fs/Makefile 2010-05-20 20:16:56.351613526 +0200 -@@ -124,5 +124,6 @@ - obj-$(CONFIG_OCFS2_FS) += ocfs2/ - obj-$(CONFIG_BTRFS_FS) += btrfs/ +diff -Nur linux-2.6.36.orig/fs/Makefile linux-2.6.36/fs/Makefile +--- linux-2.6.36.orig/fs/Makefile 2010-10-20 22:30:22.000000000 +0200 ++++ linux-2.6.36/fs/Makefile 2010-11-18 18:15:51.000000000 +0100 +@@ -126,3 +126,4 @@ obj-$(CONFIG_GFS2_FS) += gfs2/ -+obj-$(CONFIG_YAFFS_FS) += yaffs2/ obj-$(CONFIG_EXOFS_FS) += exofs/ obj-$(CONFIG_CEPH_FS) += ceph/ -diff -Nur linux-2.6.34.orig/fs/Makefile.pre.yaffs linux-2.6.34/fs/Makefile.pre.yaffs ---- linux-2.6.34.orig/fs/Makefile.pre.yaffs 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/Makefile.pre.yaffs 2010-05-20 20:16:22.271612558 +0200 -@@ -0,0 +1,126 @@ -+# -+# Makefile for the Linux filesystems. -+# -+# 14 Sep 2000, Christoph Hellwig -+# Rewritten to use lists instead of if-statements. -+# -+ -+obj-y := open.o read_write.o file_table.o super.o \ -+ char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \ -+ ioctl.o readdir.o select.o fifo.o dcache.o inode.o \ -+ attr.o bad_inode.o file.o filesystems.o namespace.o \ -+ seq_file.o xattr.o libfs.o fs-writeback.o \ -+ pnode.o drop_caches.o splice.o sync.o utimes.o \ -+ stack.o -+ -+ifeq ($(CONFIG_BLOCK),y) -+obj-y += buffer.o bio.o block_dev.o direct-io.o mpage.o ioprio.o -+else -+obj-y += no-block.o -+endif -+ -+obj-$(CONFIG_BLK_DEV_INTEGRITY) += bio-integrity.o -+obj-y += notify/ -+obj-$(CONFIG_EPOLL) += eventpoll.o -+obj-$(CONFIG_ANON_INODES) += anon_inodes.o -+obj-$(CONFIG_SIGNALFD) += signalfd.o -+obj-$(CONFIG_TIMERFD) += timerfd.o -+obj-$(CONFIG_EVENTFD) += eventfd.o -+obj-$(CONFIG_AIO) += aio.o -+obj-$(CONFIG_FILE_LOCKING) += locks.o -+obj-$(CONFIG_COMPAT) += compat.o compat_ioctl.o -+ -+nfsd-$(CONFIG_NFSD) := nfsctl.o -+obj-y += $(nfsd-y) $(nfsd-m) -+ -+obj-$(CONFIG_BINFMT_AOUT) += binfmt_aout.o -+obj-$(CONFIG_BINFMT_EM86) += binfmt_em86.o -+obj-$(CONFIG_BINFMT_MISC) += binfmt_misc.o -+ -+# binfmt_script is always there -+obj-y += binfmt_script.o -+ -+obj-$(CONFIG_BINFMT_ELF) += binfmt_elf.o -+obj-$(CONFIG_COMPAT_BINFMT_ELF) += compat_binfmt_elf.o -+obj-$(CONFIG_BINFMT_ELF_FDPIC) += binfmt_elf_fdpic.o -+obj-$(CONFIG_BINFMT_SOM) += binfmt_som.o -+obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o -+ -+obj-$(CONFIG_FS_MBCACHE) += mbcache.o -+obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o xattr_acl.o -+obj-$(CONFIG_NFS_COMMON) += nfs_common/ -+obj-$(CONFIG_GENERIC_ACL) += generic_acl.o -+ -+obj-$(CONFIG_QUOTA) += dquot.o -+obj-$(CONFIG_QFMT_V1) += quota_v1.o -+obj-$(CONFIG_QFMT_V2) += quota_v2.o -+obj-$(CONFIG_QUOTA_TREE) += quota_tree.o -+obj-$(CONFIG_QUOTACTL) += quota.o -+ -+obj-$(CONFIG_PROC_FS) += proc/ -+obj-y += partitions/ -+obj-$(CONFIG_SYSFS) += sysfs/ -+obj-$(CONFIG_CONFIGFS_FS) += configfs/ -+obj-y += devpts/ -+ -+obj-$(CONFIG_PROFILING) += dcookies.o -+obj-$(CONFIG_DLM) += dlm/ -+ -+# Do not add any filesystems before this line -+obj-$(CONFIG_REISERFS_FS) += reiserfs/ -+obj-$(CONFIG_EXT3_FS) += ext3/ # Before ext2 so root fs can be ext3 -+obj-$(CONFIG_EXT2_FS) += ext2/ -+# We place ext4 after ext2 so plain ext2 root fs's are mounted using ext2 -+# unless explicitly requested by rootfstype -+obj-$(CONFIG_EXT4_FS) += ext4/ -+obj-$(CONFIG_JBD) += jbd/ -+obj-$(CONFIG_JBD2) += jbd2/ -+obj-$(CONFIG_CRAMFS) += cramfs/ -+obj-$(CONFIG_SQUASHFS) += squashfs/ -+obj-y += ramfs/ -+obj-$(CONFIG_HUGETLBFS) += hugetlbfs/ -+obj-$(CONFIG_CODA_FS) += coda/ -+obj-$(CONFIG_MINIX_FS) += minix/ -+obj-$(CONFIG_FAT_FS) += fat/ -+obj-$(CONFIG_BFS_FS) += bfs/ -+obj-$(CONFIG_ISO9660_FS) += isofs/ -+obj-$(CONFIG_HFSPLUS_FS) += hfsplus/ # Before hfs to find wrapped HFS+ -+obj-$(CONFIG_HFS_FS) += hfs/ -+obj-$(CONFIG_ECRYPT_FS) += ecryptfs/ -+obj-$(CONFIG_VXFS_FS) += freevxfs/ -+obj-$(CONFIG_NFS_FS) += nfs/ -+obj-$(CONFIG_EXPORTFS) += exportfs/ -+obj-$(CONFIG_NFSD) += nfsd/ -+obj-$(CONFIG_LOCKD) += lockd/ -+obj-$(CONFIG_NLS) += nls/ -+obj-$(CONFIG_SYSV_FS) += sysv/ -+obj-$(CONFIG_SMB_FS) += smbfs/ -+obj-$(CONFIG_CIFS) += cifs/ -+obj-$(CONFIG_NCP_FS) += ncpfs/ -+obj-$(CONFIG_HPFS_FS) += hpfs/ -+obj-$(CONFIG_NTFS_FS) += ntfs/ -+obj-$(CONFIG_UFS_FS) += ufs/ -+obj-$(CONFIG_EFS_FS) += efs/ -+obj-$(CONFIG_JFFS2_FS) += jffs2/ -+obj-$(CONFIG_UBIFS_FS) += ubifs/ -+obj-$(CONFIG_AFFS_FS) += affs/ -+obj-$(CONFIG_ROMFS_FS) += romfs/ -+obj-$(CONFIG_QNX4FS_FS) += qnx4/ -+obj-$(CONFIG_AUTOFS_FS) += autofs/ -+obj-$(CONFIG_AUTOFS4_FS) += autofs4/ -+obj-$(CONFIG_ADFS_FS) += adfs/ -+obj-$(CONFIG_FUSE_FS) += fuse/ -+obj-$(CONFIG_UDF_FS) += udf/ -+obj-$(CONFIG_SUN_OPENPROMFS) += openpromfs/ -+obj-$(CONFIG_OMFS_FS) += omfs/ -+obj-$(CONFIG_JFS_FS) += jfs/ -+obj-$(CONFIG_XFS_FS) += xfs/ -+obj-$(CONFIG_9P_FS) += 9p/ -+obj-$(CONFIG_AFS_FS) += afs/ -+obj-$(CONFIG_BEFS_FS) += befs/ -+obj-$(CONFIG_HOSTFS) += hostfs/ -+obj-$(CONFIG_HPPFS) += hppfs/ -+obj-$(CONFIG_DEBUG_FS) += debugfs/ -+obj-$(CONFIG_OCFS2_FS) += ocfs2/ -+obj-$(CONFIG_BTRFS_FS) += btrfs/ -+obj-$(CONFIG_GFS2_FS) += gfs2/ -diff -Nur linux-2.6.34.orig/fs/yaffs2/devextras.h linux-2.6.34/fs/yaffs2/devextras.h ---- linux-2.6.34.orig/fs/yaffs2/devextras.h 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/devextras.h 2010-05-20 20:16:22.271612558 +0200 -@@ -0,0 +1,196 @@ -+/* -+ * 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 -+ * -+ * 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. -+ */ -+ -+/* -+ * 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 __KERNEL__) -+ -+/* Definition of types */ -+typedef unsigned char __u8; -+typedef unsigned short __u16; -+typedef unsigned __u32; -+ -+#endif -+ -+/* -+ * This is a simple doubly linked list implementation that matches the -+ * way the Linux kernel doubly linked list implementation works. -+ */ -+ -+struct ylist_head { -+ struct ylist_head *next; /* next in chain */ -+ struct ylist_head *prev; /* previous in chain */ -+}; -+ -+ -+/* Initialise a static list */ -+#define YLIST_HEAD(name) \ -+struct ylist_head name = { &(name), &(name)} -+ -+ -+ -+/* Initialise a list head to an empty list */ -+#define YINIT_LIST_HEAD(p) \ -+do { \ -+ (p)->next = (p);\ -+ (p)->prev = (p); \ -+} while (0) -+ -+ -+/* Add an element to a list */ -+static __inline__ void ylist_add(struct ylist_head *newEntry, -+ struct ylist_head *list) -+{ -+ struct ylist_head *listNext = list->next; -+ -+ list->next = newEntry; -+ newEntry->prev = list; -+ newEntry->next = listNext; -+ listNext->prev = newEntry; -+ -+} -+ -+static __inline__ void ylist_add_tail(struct ylist_head *newEntry, -+ struct ylist_head *list) -+{ -+ struct ylist_head *listPrev = list->prev; -+ -+ list->prev = newEntry; -+ newEntry->next = list; -+ newEntry->prev = listPrev; -+ listPrev->next = newEntry; -+ -+} -+ -+ -+/* 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) -+{ -+ struct ylist_head *listNext = entry->next; -+ struct ylist_head *listPrev = entry->prev; -+ -+ listNext->prev = listPrev; -+ listPrev->next = listNext; -+ -+} -+ -+static __inline__ void ylist_del_init(struct ylist_head *entry) -+{ -+ ylist_del(entry); -+ entry->next = entry->prev = entry; -+} -+ -+ -+/* Test if the list is empty */ -+static __inline__ int ylist_empty(struct ylist_head *entry) -+{ -+ return (entry->next == entry); -+} -+ -+ -+/* 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. -+ */ -+ -+ -+#define ylist_entry(entry, type, member) \ -+ ((type *)((char *)(entry)-(unsigned long)(&((type *)NULL)->member))) -+ -+ -+/* ylist_for_each and list_for_each_safe iterate over lists. -+ * ylist_for_each_safe uses temporary storage to make the list delete safe -+ */ -+ -+#define ylist_for_each(itervar, list) \ -+ for (itervar = (list)->next; itervar != (list); itervar = itervar->next) -+ -+#define ylist_for_each_safe(itervar, saveVar, list) \ -+ for (itervar = (list)->next, saveVar = (list)->next->next; \ -+ itervar != (list); itervar = saveVar, saveVar = saveVar->next) -+ -+ -+#if !(defined __KERNEL__) -+ -+ -+#ifndef WIN32 -+#include -+#endif -+ -+ -+#ifdef CONFIG_YAFFS_PROVIDE_DEFS -+/* File types */ -+ -+ -+#define DT_UNKNOWN 0 -+#define DT_FIFO 1 -+#define DT_CHR 2 -+#define DT_DIR 4 -+#define DT_BLK 6 -+#define DT_REG 8 -+#define DT_LNK 10 -+#define DT_SOCK 12 -+#define DT_WHT 14 -+ -+ -+#ifndef WIN32 -+#include -+#endif -+ -+/* -+ * Attribute flags. These should be or-ed together to figure out what -+ * has been changed! -+ */ -+#define ATTR_MODE 1 -+#define ATTR_UID 2 -+#define ATTR_GID 4 -+#define ATTR_SIZE 8 -+#define ATTR_ATIME 16 -+#define ATTR_MTIME 32 -+#define ATTR_CTIME 64 -+ -+struct iattr { -+ unsigned int ia_valid; -+ unsigned ia_mode; -+ unsigned ia_uid; -+ unsigned ia_gid; -+ unsigned ia_size; -+ unsigned ia_atime; -+ unsigned ia_mtime; -+ unsigned ia_ctime; -+ unsigned int ia_attr_flags; -+}; -+ -+#endif -+ -+#else -+ -+#include -+#include -+#include -+ -+#endif -+ -+ -+#endif -diff -Nur linux-2.6.34.orig/fs/yaffs2/Kconfig linux-2.6.34/fs/yaffs2/Kconfig ---- linux-2.6.34.orig/fs/yaffs2/Kconfig 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/Kconfig 2010-05-20 20:16:22.271612558 +0200 -@@ -0,0 +1,156 @@ ++obj-$(CONFIG_YAFFS_FS) += yaffs2/ +diff -Nur linux-2.6.36.orig/fs/yaffs2/Kconfig linux-2.6.36/fs/yaffs2/Kconfig +--- linux-2.6.36.orig/fs/yaffs2/Kconfig 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/Kconfig 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,161 @@ +# +# YAFFS file system configurations +# @@ -448,39 +113,15 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/Kconfig linux-2.6.34/fs/yaffs2/Kconfig + + If unsure, say Y. + -+config YAFFS_DISABLE_LAZY_LOAD -+ bool "Disable lazy loading" -+ depends on YAFFS_YAFFS2 -+ default n -+ help -+ "Lazy loading" defers loading file details until they are -+ required. This saves mount time, but makes the first look-up -+ a bit longer. -+ -+ Lazy loading will only happen if enabled by this option being 'n' -+ and if the appropriate tags are available, else yaffs2 will -+ automatically fall back to immediate loading and do the right -+ thing. -+ -+ Lazy laoding will be required by checkpointing. -+ -+ Setting this to 'y' will disable lazy loading. -+ -+ If unsure, say N. -+ -+ -+config YAFFS_DISABLE_WIDE_TNODES -+ bool "Turn off wide tnodes" -+ depends on YAFFS_FS ++config YAFFS_DISABLE_TAGS_ECC ++ bool "Disable YAFFS from doing ECC on tags by default" ++ depends on YAFFS_FS && YAFFS_YAFFS2 + default n + help -+ Wide tnodes are only used for NAND arrays >=32MB for 512-byte -+ page devices and >=128MB for 2k page devices. They use slightly -+ more RAM but are faster since they eliminate chunk group -+ searching. -+ -+ Setting this to 'y' will force tnode width to 16 bits and save -+ memory but make large arrays slower. ++ This defaults Yaffs to using its own ECC calculations on tags instead of ++ just relying on the MTD. ++ This behavior can also be overridden with tags_ecc_on and ++ tags_ecc_off mount options. + + If unsure, say N. + @@ -502,38 +143,74 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/Kconfig linux-2.6.34/fs/yaffs2/Kconfig + + If unsure, say Y. + -+config YAFFS_SHORT_NAMES_IN_RAM -+ bool "Cache short names in RAM" ++config YAFFS_EMPTY_LOST_AND_FOUND ++ bool "Empty lost and found on boot" + depends on YAFFS_FS -+ default y ++ default n + help -+ If this config is set, then short names are stored with the -+ yaffs_Object. This costs an extra 16 bytes of RAM per object, -+ but makes look-ups faster. ++ If this is enabled then the contents of lost and found is ++ automatically dumped at mount. + -+ If unsure, say Y. -diff -Nur linux-2.6.34.orig/fs/yaffs2/Makefile linux-2.6.34/fs/yaffs2/Makefile ---- linux-2.6.34.orig/fs/yaffs2/Makefile 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/Makefile 2010-05-20 20:16:22.271612558 +0200 -@@ -0,0 +1,10 @@ ++ If unsure, say N. ++ ++config YAFFS_DISABLE_BLOCK_REFRESHING ++ bool "Disable yaffs2 block refreshing" ++ depends on YAFFS_FS ++ default n ++ help ++ If this is set, then block refreshing is disabled. ++ Block refreshing infrequently refreshes the oldest block in ++ a yaffs2 file system. This mechanism helps to refresh flash to ++ mitigate against data loss. This is particularly useful for MLC. ++ ++ If unsure, say N. ++ ++config YAFFS_DISABLE_BACKGROUND ++ bool "Disable yaffs2 background processing" ++ depends on YAFFS_FS ++ default n ++ help ++ If this is set, then background processing is disabled. ++ Background processing makes many foreground activities faster. ++ ++ If unsure, say N. ++ ++config YAFFS_XATTR ++ bool "Enable yaffs2 xattr support" ++ depends on YAFFS_FS ++ default y ++ help ++ If this is set then yaffs2 will provide xattr support. ++ If unsure, say Y. +diff -Nur linux-2.6.36.orig/fs/yaffs2/Makefile linux-2.6.36/fs/yaffs2/Makefile +--- linux-2.6.36.orig/fs/yaffs2/Makefile 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/Makefile 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,17 @@ +# +# Makefile for the linux YAFFS filesystem routines. +# + +obj-$(CONFIG_YAFFS_FS) += yaffs.o + -+yaffs-y := yaffs_ecc.o yaffs_fs.o yaffs_guts.o yaffs_checkptrw.o -+yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o yaffs_qsort.o ++yaffs-y := yaffs_ecc.o yaffs_vfs.o yaffs_guts.o yaffs_checkptrw.o ++yaffs-y += yaffs_packedtags1.o yaffs_packedtags2.o yaffs_nand.o +yaffs-y += yaffs_tagscompat.o yaffs_tagsvalidity.o +yaffs-y += yaffs_mtdif.o yaffs_mtdif1.o yaffs_mtdif2.o -diff -Nur linux-2.6.34.orig/fs/yaffs2/moduleconfig.h linux-2.6.34/fs/yaffs2/moduleconfig.h ---- linux-2.6.34.orig/fs/yaffs2/moduleconfig.h 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/moduleconfig.h 2010-05-20 20:16:22.281614392 +0200 -@@ -0,0 +1,65 @@ ++yaffs-y += yaffs_nameval.o yaffs_attribs.o ++yaffs-y += yaffs_allocator.o ++yaffs-y += yaffs_yaffs1.o ++yaffs-y += yaffs_yaffs2.o ++yaffs-y += yaffs_bitmap.o ++yaffs-y += yaffs_verify.o ++ +diff -Nur linux-2.6.36.orig/fs/yaffs2/moduleconfig.h linux-2.6.36/fs/yaffs2/moduleconfig.h +--- linux-2.6.36.orig/fs/yaffs2/moduleconfig.h 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/moduleconfig.h 2010-11-18 18:49:02.000000000 +0100 +@@ -0,0 +1,81 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * -+ * Copyright (C) 2002-2007 Aleph One Ltd. ++ * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Martin Fouts @@ -561,25 +238,41 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/moduleconfig.h linux-2.6.34/fs/yaffs2/modu +/* Meaning: Yaffs does its own ECC, rather than using MTD ECC */ +/* #define CONFIG_YAFFS_DOES_ECC */ + ++/* Default: Selected */ ++/* Meaning: Yaffs does its own ECC on tags for packed tags rather than use mtd */ ++#define CONFIG_YAFFS_DOES_TAGS_ECC ++ +/* Default: Not selected */ +/* Meaning: ECC byte order is 'wrong'. Only meaningful if */ +/* CONFIG_YAFFS_DOES_ECC is set */ +/* #define CONFIG_YAFFS_ECC_WRONG_ORDER */ + -+/* Default: Selected */ -+/* Meaning: Disables testing whether chunks are erased before writing to them*/ -+#define CONFIG_YAFFS_DISABLE_CHUNK_ERASED_CHECK ++/* Default: Not selected */ ++/* Meaning: Always test whether chunks are erased before writing to them. ++ Use during mtd debugging and init. */ ++/* #define CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED */ + -+/* Default: Selected */ -+/* Meaning: Cache short names, taking more RAM, but faster look-ups */ -+#define CONFIG_YAFFS_SHORT_NAMES_IN_RAM ++/* Default: Not Selected */ ++/* Meaning: At mount automatically empty all files from lost and found. */ ++/* This is done to fix an old problem where rmdir was not checking for an */ ++/* empty directory. This can also be achieved with a mount option. */ ++#define CONFIG_YAFFS_EMPTY_LOST_AND_FOUND + -+/* Default: 10 */ -+/* Meaning: set the count of blocks to reserve for checkpointing */ -+#define CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS 10 ++/* Default: Unselected */ ++/* Meaning: Select to disable block refreshing. */ ++/* Block Refreshing periodically rewrites the oldest block. */ ++/* #define CONFIG_DISABLE_BLOCK_REFRESHING */ ++ ++/* Default: Unselected */ ++/* Meaning: Select to disable background processing */ ++/* #define CONFIG_DISABLE_BACKGROUND */ ++ ++/* Default: Selected */ ++/* Meaning: Enable XATTR support */ ++#define CONFIG_YAFFS_XATTR + +/* -+Older-style on-NAND data format has a "pageStatus" byte to record ++Older-style on-NAND data format has a "page_status" byte to record +chunk/page state. This byte is zeroed when the page is discarded. +Choose this option if you have existing on-NAND data in this format +that you need to continue to support. New data written also uses the @@ -589,20 +282,20 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/moduleconfig.h linux-2.6.34/fs/yaffs2/modu +MTD versions in yaffs_mtdif1.c. +*/ +/* Default: Not selected */ -+/* Meaning: Use older-style on-NAND data format with pageStatus byte */ ++/* Meaning: Use older-style on-NAND data format with page_status byte */ +/* #define CONFIG_YAFFS_9BYTE_TAGS */ + +#endif /* YAFFS_OUT_OF_TREE */ + +#endif /* __YAFFS_CONFIG_H__ */ -diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_checkptrw.c linux-2.6.34/fs/yaffs2/yaffs_checkptrw.c ---- linux-2.6.34.orig/fs/yaffs2/yaffs_checkptrw.c 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/yaffs_checkptrw.c 2010-05-20 20:16:22.281614392 +0200 -@@ -0,0 +1,394 @@ +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_allocator.c linux-2.6.36/fs/yaffs2/yaffs_allocator.c +--- linux-2.6.36.orig/fs/yaffs2/yaffs_allocator.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_allocator.c 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,397 @@ +/* + * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. + * -+ * Copyright (C) 2002-2007 Aleph One Ltd. ++ * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning @@ -612,395 +305,398 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_checkptrw.c linux-2.6.34/fs/yaffs2/y + * published by the Free Software Foundation. + */ + -+const char *yaffs_checkptrw_c_version = -+ "$Id: yaffs_checkptrw.c,v 1.18 2009-03-06 17:20:49 wookey Exp $"; -+ ++#include "yaffs_allocator.h" ++#include "yaffs_guts.h" ++#include "yaffs_trace.h" ++#include "yportenv.h" + -+#include "yaffs_checkptrw.h" -+#include "yaffs_getblockinfo.h" ++#ifdef CONFIG_YAFFS_YMALLOC_ALLOCATOR + -+static int yaffs_CheckpointSpaceOk(yaffs_Device *dev) ++void yaffs_deinit_raw_tnodes_and_objs(struct yaffs_dev *dev) +{ -+ int blocksAvailable = dev->nErasedBlocks - dev->nReservedBlocks; -+ -+ T(YAFFS_TRACE_CHECKPOINT, -+ (TSTR("checkpt blocks available = %d" TENDSTR), -+ blocksAvailable)); -+ -+ return (blocksAvailable <= 0) ? 0 : 1; ++ dev = dev; +} + -+ -+static int yaffs_CheckpointErase(yaffs_Device *dev) ++void yaffs_init_raw_tnodes_and_objs(struct yaffs_dev *dev) +{ -+ int i; -+ -+ if (!dev->eraseBlockInNAND) -+ return 0; -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("checking blocks %d to %d"TENDSTR), -+ dev->internalStartBlock, dev->internalEndBlock)); -+ -+ for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) { -+ yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i); -+ if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) { -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("erasing checkpt block %d"TENDSTR), i)); -+ if (dev->eraseBlockInNAND(dev, i - dev->blockOffset /* realign */)) { -+ bi->blockState = YAFFS_BLOCK_STATE_EMPTY; -+ dev->nErasedBlocks++; -+ dev->nFreeChunks += dev->nChunksPerBlock; -+ } else { -+ dev->markNANDBlockBad(dev, i); -+ bi->blockState = YAFFS_BLOCK_STATE_DEAD; -+ } -+ } -+ } ++ dev = dev; ++} + -+ dev->blocksInCheckpoint = 0; ++struct yaffs_tnode *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) ++{ ++ return (struct yaffs_tnode *)YMALLOC(dev->tnode_size); ++} + -+ return 1; ++void yaffs_free_raw_tnode(struct yaffs_dev *dev, struct yaffs_tnode *tn) ++{ ++ dev = dev; ++ YFREE(tn); +} + ++void yaffs_init_raw_objs(struct yaffs_dev *dev) ++{ ++ dev = dev; ++} + -+static void yaffs_CheckpointFindNextErasedBlock(yaffs_Device *dev) ++void yaffs_deinit_raw_objs(struct yaffs_dev *dev) +{ -+ int i; -+ int blocksAvailable = dev->nErasedBlocks - dev->nReservedBlocks; -+ T(YAFFS_TRACE_CHECKPOINT, -+ (TSTR("allocating checkpt block: erased %d reserved %d avail %d next %d "TENDSTR), -+ dev->nErasedBlocks, dev->nReservedBlocks, blocksAvailable, dev->checkpointNextBlock)); -+ -+ if (dev->checkpointNextBlock >= 0 && -+ dev->checkpointNextBlock <= dev->internalEndBlock && -+ blocksAvailable > 0) { -+ -+ for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) { -+ yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i); -+ if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) { -+ dev->checkpointNextBlock = i + 1; -+ dev->checkpointCurrentBlock = i; -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("allocating checkpt block %d"TENDSTR), i)); -+ return; -+ } -+ } -+ } -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("out of checkpt blocks"TENDSTR))); ++ dev = dev; ++} + -+ dev->checkpointNextBlock = -1; -+ dev->checkpointCurrentBlock = -1; ++struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev) ++{ ++ dev = dev; ++ return (struct yaffs_obj *)YMALLOC(sizeof(struct yaffs_obj)); +} + -+static void yaffs_CheckpointFindNextCheckpointBlock(yaffs_Device *dev) ++void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj) +{ -+ int i; -+ yaffs_ExtendedTags tags; + -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR), -+ dev->blocksInCheckpoint, dev->checkpointNextBlock)); ++ dev = dev; ++ YFREE(obj); ++} + -+ if (dev->blocksInCheckpoint < dev->checkpointMaxBlocks) -+ for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) { -+ int chunk = i * dev->nChunksPerBlock; -+ int realignedChunk = chunk - dev->chunkOffset; ++#else + -+ dev->readChunkWithTagsFromNAND(dev, realignedChunk, -+ NULL, &tags); -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR), -+ i, tags.objectId, tags.sequenceNumber, tags.eccResult)); ++struct yaffs_tnode_list { ++ struct yaffs_tnode_list *next; ++ struct yaffs_tnode *tnodes; ++}; + -+ if (tags.sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA) { -+ /* Right kind of block */ -+ dev->checkpointNextBlock = tags.objectId; -+ dev->checkpointCurrentBlock = i; -+ dev->checkpointBlockList[dev->blocksInCheckpoint] = i; -+ dev->blocksInCheckpoint++; -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("found checkpt block %d"TENDSTR), i)); -+ return; -+ } -+ } ++struct yaffs_obj_list { ++ struct yaffs_obj_list *next; ++ struct yaffs_obj *objects; ++}; + -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("found no more checkpt blocks"TENDSTR))); ++struct yaffs_allocator { ++ int n_tnodes_created; ++ struct yaffs_tnode *free_tnodes; ++ int n_free_tnodes; ++ struct yaffs_tnode_list *alloc_tnode_list; + -+ dev->checkpointNextBlock = -1; -+ dev->checkpointCurrentBlock = -1; -+} ++ int n_obj_created; ++ struct yaffs_obj *free_objs; ++ int n_free_objects; + ++ struct yaffs_obj_list *allocated_obj_list; ++}; + -+int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) ++static void yaffs_deinit_raw_tnodes(struct yaffs_dev *dev) +{ + -+ /* Got the functions we need? */ -+ if (!dev->writeChunkWithTagsToNAND || -+ !dev->readChunkWithTagsFromNAND || -+ !dev->eraseBlockInNAND || -+ !dev->markNANDBlockBad) -+ return 0; -+ -+ if (forWriting && !yaffs_CheckpointSpaceOk(dev)) -+ return 0; -+ -+ if (!dev->checkpointBuffer) -+ dev->checkpointBuffer = YMALLOC_DMA(dev->totalBytesPerChunk); -+ if (!dev->checkpointBuffer) -+ return 0; ++ struct yaffs_allocator *allocator = ++ (struct yaffs_allocator *)dev->allocator; + ++ struct yaffs_tnode_list *tmp; + -+ dev->checkpointPageSequence = 0; ++ if (!allocator) { ++ YBUG(); ++ return; ++ } + -+ dev->checkpointOpenForWrite = forWriting; ++ while (allocator->alloc_tnode_list) { ++ tmp = allocator->alloc_tnode_list->next; + -+ dev->checkpointByteCount = 0; -+ dev->checkpointSum = 0; -+ dev->checkpointXor = 0; -+ dev->checkpointCurrentBlock = -1; -+ dev->checkpointCurrentChunk = -1; -+ dev->checkpointNextBlock = dev->internalStartBlock; ++ YFREE(allocator->alloc_tnode_list->tnodes); ++ YFREE(allocator->alloc_tnode_list); ++ allocator->alloc_tnode_list = tmp; + -+ /* Erase all the blocks in the checkpoint area */ -+ if (forWriting) { -+ memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk); -+ dev->checkpointByteOffset = 0; -+ return yaffs_CheckpointErase(dev); -+ } else { -+ int i; -+ /* Set to a value that will kick off a read */ -+ dev->checkpointByteOffset = dev->nDataBytesPerChunk; -+ /* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully) -+ * going to be way more than we need */ -+ dev->blocksInCheckpoint = 0; -+ dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2; -+ dev->checkpointBlockList = YMALLOC(sizeof(int) * dev->checkpointMaxBlocks); -+ for (i = 0; i < dev->checkpointMaxBlocks; i++) -+ dev->checkpointBlockList[i] = -1; + } + -+ return 1; -+} -+ -+int yaffs_GetCheckpointSum(yaffs_Device *dev, __u32 *sum) -+{ -+ __u32 compositeSum; -+ compositeSum = (dev->checkpointSum << 8) | (dev->checkpointXor & 0xFF); -+ *sum = compositeSum; -+ return 1; ++ allocator->free_tnodes = NULL; ++ allocator->n_free_tnodes = 0; ++ allocator->n_tnodes_created = 0; +} + -+static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev) ++static void yaffs_init_raw_tnodes(struct yaffs_dev *dev) +{ -+ int chunk; -+ int realignedChunk; -+ -+ yaffs_ExtendedTags tags; ++ struct yaffs_allocator *allocator = dev->allocator; + -+ if (dev->checkpointCurrentBlock < 0) { -+ yaffs_CheckpointFindNextErasedBlock(dev); -+ dev->checkpointCurrentChunk = 0; ++ if (allocator) { ++ allocator->alloc_tnode_list = NULL; ++ allocator->free_tnodes = NULL; ++ allocator->n_free_tnodes = 0; ++ allocator->n_tnodes_created = 0; ++ } else { ++ YBUG(); + } ++} + -+ if (dev->checkpointCurrentBlock < 0) -+ return 0; ++static int yaffs_create_tnodes(struct yaffs_dev *dev, int n_tnodes) ++{ ++ struct yaffs_allocator *allocator = ++ (struct yaffs_allocator *)dev->allocator; ++ int i; ++ struct yaffs_tnode *new_tnodes; ++ u8 *mem; ++ struct yaffs_tnode *curr; ++ struct yaffs_tnode *next; ++ struct yaffs_tnode_list *tnl; + -+ tags.chunkDeleted = 0; -+ tags.objectId = dev->checkpointNextBlock; /* Hint to next place to look */ -+ tags.chunkId = dev->checkpointPageSequence + 1; -+ tags.sequenceNumber = YAFFS_SEQUENCE_CHECKPOINT_DATA; -+ tags.byteCount = dev->nDataBytesPerChunk; -+ if (dev->checkpointCurrentChunk == 0) { -+ /* First chunk we write for the block? Set block state to -+ checkpoint */ -+ yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointCurrentBlock); -+ bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT; -+ dev->blocksInCheckpoint++; ++ if (!allocator) { ++ YBUG(); ++ return YAFFS_FAIL; + } + -+ chunk = dev->checkpointCurrentBlock * dev->nChunksPerBlock + dev->checkpointCurrentChunk; -+ ++ if (n_tnodes < 1) ++ return YAFFS_OK; + -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR), -+ chunk, dev->checkpointCurrentBlock, dev->checkpointCurrentChunk, tags.objectId, tags.chunkId)); ++ /* make these things */ + -+ realignedChunk = chunk - dev->chunkOffset; ++ new_tnodes = YMALLOC(n_tnodes * dev->tnode_size); ++ mem = (u8 *) new_tnodes; + -+ dev->writeChunkWithTagsToNAND(dev, realignedChunk, -+ dev->checkpointBuffer, &tags); -+ dev->checkpointByteOffset = 0; -+ dev->checkpointPageSequence++; -+ dev->checkpointCurrentChunk++; -+ if (dev->checkpointCurrentChunk >= dev->nChunksPerBlock) { -+ dev->checkpointCurrentChunk = 0; -+ dev->checkpointCurrentBlock = -1; ++ if (!new_tnodes) { ++ T(YAFFS_TRACE_ERROR, ++ (TSTR("yaffs: Could not allocate Tnodes" TENDSTR))); ++ return YAFFS_FAIL; + } -+ memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk); -+ -+ return 1; -+} + ++ /* New hookup for wide tnodes */ ++ for (i = 0; i < n_tnodes - 1; i++) { ++ curr = (struct yaffs_tnode *)&mem[i * dev->tnode_size]; ++ next = (struct yaffs_tnode *)&mem[(i + 1) * dev->tnode_size]; ++ curr->internal[0] = next; ++ } + -+int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes) -+{ -+ int i = 0; -+ int ok = 1; -+ ++ curr = (struct yaffs_tnode *)&mem[(n_tnodes - 1) * dev->tnode_size]; ++ curr->internal[0] = allocator->free_tnodes; ++ allocator->free_tnodes = (struct yaffs_tnode *)mem; + -+ __u8 * dataBytes = (__u8 *)data; ++ allocator->n_free_tnodes += n_tnodes; ++ allocator->n_tnodes_created += n_tnodes; + ++ /* Now add this bunch of tnodes to a list for freeing up. ++ * NB If we can't add this to the management list it isn't fatal ++ * but it just means we can't free this bunch of tnodes later. ++ */ + ++ tnl = YMALLOC(sizeof(struct yaffs_tnode_list)); ++ if (!tnl) { ++ T(YAFFS_TRACE_ERROR, ++ (TSTR ++ ("yaffs: Could not add tnodes to management list" TENDSTR))); ++ return YAFFS_FAIL; ++ } else { ++ tnl->tnodes = new_tnodes; ++ tnl->next = allocator->alloc_tnode_list; ++ allocator->alloc_tnode_list = tnl; ++ } + -+ if (!dev->checkpointBuffer) -+ return 0; ++ T(YAFFS_TRACE_ALLOCATE, (TSTR("yaffs: Tnodes added" TENDSTR))); + -+ if (!dev->checkpointOpenForWrite) -+ return -1; ++ return YAFFS_OK; ++} + -+ while (i < nBytes && ok) { -+ dev->checkpointBuffer[dev->checkpointByteOffset] = *dataBytes; -+ dev->checkpointSum += *dataBytes; -+ dev->checkpointXor ^= *dataBytes; ++struct yaffs_tnode *yaffs_alloc_raw_tnode(struct yaffs_dev *dev) ++{ ++ struct yaffs_allocator *allocator = ++ (struct yaffs_allocator *)dev->allocator; ++ struct yaffs_tnode *tn = NULL; + -+ dev->checkpointByteOffset++; -+ i++; -+ dataBytes++; -+ dev->checkpointByteCount++; ++ if (!allocator) { ++ YBUG(); ++ return NULL; ++ } + ++ /* If there are none left make more */ ++ if (!allocator->free_tnodes) ++ yaffs_create_tnodes(dev, YAFFS_ALLOCATION_NTNODES); + -+ if (dev->checkpointByteOffset < 0 || -+ dev->checkpointByteOffset >= dev->nDataBytesPerChunk) -+ ok = yaffs_CheckpointFlushBuffer(dev); ++ if (allocator->free_tnodes) { ++ tn = allocator->free_tnodes; ++ allocator->free_tnodes = allocator->free_tnodes->internal[0]; ++ allocator->n_free_tnodes--; + } + -+ return i; ++ return tn; +} + -+int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes) ++/* FreeTnode frees up a tnode and puts it back on the free list */ ++void yaffs_free_raw_tnode(struct yaffs_dev *dev, struct yaffs_tnode *tn) +{ -+ int i = 0; -+ int ok = 1; -+ yaffs_ExtendedTags tags; ++ struct yaffs_allocator *allocator = dev->allocator; + ++ if (!allocator) { ++ YBUG(); ++ return; ++ } + -+ int chunk; -+ int realignedChunk; ++ if (tn) { ++ tn->internal[0] = allocator->free_tnodes; ++ allocator->free_tnodes = tn; ++ allocator->n_free_tnodes++; ++ } ++ dev->checkpoint_blocks_required = 0; /* force recalculation */ ++} + -+ __u8 *dataBytes = (__u8 *)data; ++static void yaffs_init_raw_objs(struct yaffs_dev *dev) ++{ ++ struct yaffs_allocator *allocator = dev->allocator; + -+ if (!dev->checkpointBuffer) -+ return 0; ++ if (allocator) { ++ allocator->allocated_obj_list = NULL; ++ allocator->free_objs = NULL; ++ allocator->n_free_objects = 0; ++ } else { ++ YBUG(); ++ } ++} + -+ if (dev->checkpointOpenForWrite) -+ return -1; ++static void yaffs_deinit_raw_objs(struct yaffs_dev *dev) ++{ ++ struct yaffs_allocator *allocator = dev->allocator; ++ struct yaffs_obj_list *tmp; + -+ while (i < nBytes && ok) { ++ if (!allocator) { ++ YBUG(); ++ return; ++ } + ++ while (allocator->allocated_obj_list) { ++ tmp = allocator->allocated_obj_list->next; ++ YFREE(allocator->allocated_obj_list->objects); ++ YFREE(allocator->allocated_obj_list); + -+ if (dev->checkpointByteOffset < 0 || -+ dev->checkpointByteOffset >= dev->nDataBytesPerChunk) { ++ allocator->allocated_obj_list = tmp; ++ } + -+ if (dev->checkpointCurrentBlock < 0) { -+ yaffs_CheckpointFindNextCheckpointBlock(dev); -+ dev->checkpointCurrentChunk = 0; -+ } ++ allocator->free_objs = NULL; ++ allocator->n_free_objects = 0; ++ allocator->n_obj_created = 0; ++} + -+ if (dev->checkpointCurrentBlock < 0) -+ ok = 0; -+ else { -+ chunk = dev->checkpointCurrentBlock * -+ dev->nChunksPerBlock + -+ dev->checkpointCurrentChunk; ++static int yaffs_create_free_objs(struct yaffs_dev *dev, int n_obj) ++{ ++ struct yaffs_allocator *allocator = dev->allocator; + -+ realignedChunk = chunk - dev->chunkOffset; ++ int i; ++ struct yaffs_obj *new_objs; ++ struct yaffs_obj_list *list; + -+ /* read in the next chunk */ -+ /* printf("read checkpoint page %d\n",dev->checkpointPage); */ -+ dev->readChunkWithTagsFromNAND(dev, -+ realignedChunk, -+ dev->checkpointBuffer, -+ &tags); -+ -+ if (tags.chunkId != (dev->checkpointPageSequence + 1) || -+ tags.eccResult > YAFFS_ECC_RESULT_FIXED || -+ tags.sequenceNumber != YAFFS_SEQUENCE_CHECKPOINT_DATA) -+ ok = 0; ++ if (!allocator) { ++ YBUG(); ++ return YAFFS_FAIL; ++ } + -+ dev->checkpointByteOffset = 0; -+ dev->checkpointPageSequence++; -+ dev->checkpointCurrentChunk++; ++ if (n_obj < 1) ++ return YAFFS_OK; + -+ if (dev->checkpointCurrentChunk >= dev->nChunksPerBlock) -+ dev->checkpointCurrentBlock = -1; -+ } -+ } ++ /* make these things */ ++ new_objs = YMALLOC(n_obj * sizeof(struct yaffs_obj)); ++ list = YMALLOC(sizeof(struct yaffs_obj_list)); + -+ if (ok) { -+ *dataBytes = dev->checkpointBuffer[dev->checkpointByteOffset]; -+ dev->checkpointSum += *dataBytes; -+ dev->checkpointXor ^= *dataBytes; -+ dev->checkpointByteOffset++; -+ i++; -+ dataBytes++; -+ dev->checkpointByteCount++; ++ if (!new_objs || !list) { ++ if (new_objs) { ++ YFREE(new_objs); ++ new_objs = NULL; ++ } ++ if (list) { ++ YFREE(list); ++ list = NULL; + } ++ T(YAFFS_TRACE_ALLOCATE, ++ (TSTR("yaffs: Could not allocate more objects" TENDSTR))); ++ return YAFFS_FAIL; ++ } ++ ++ /* Hook them into the free list */ ++ for (i = 0; i < n_obj - 1; i++) { ++ new_objs[i].siblings.next = ++ (struct list_head *)(&new_objs[i + 1]); + } + -+ return i; ++ new_objs[n_obj - 1].siblings.next = (void *)allocator->free_objs; ++ allocator->free_objs = new_objs; ++ allocator->n_free_objects += n_obj; ++ allocator->n_obj_created += n_obj; ++ ++ /* Now add this bunch of Objects to a list for freeing up. */ ++ ++ list->objects = new_objs; ++ list->next = allocator->allocated_obj_list; ++ allocator->allocated_obj_list = list; ++ ++ return YAFFS_OK; +} + -+int yaffs_CheckpointClose(yaffs_Device *dev) ++struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev) +{ ++ struct yaffs_obj *obj = NULL; ++ struct yaffs_allocator *allocator = dev->allocator; + -+ if (dev->checkpointOpenForWrite) { -+ if (dev->checkpointByteOffset != 0) -+ yaffs_CheckpointFlushBuffer(dev); -+ } else { -+ int i; -+ for (i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++) { -+ yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointBlockList[i]); -+ if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) -+ bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT; -+ else { -+ /* Todo this looks odd... */ -+ } -+ } -+ YFREE(dev->checkpointBlockList); -+ dev->checkpointBlockList = NULL; ++ if (!allocator) { ++ YBUG(); ++ return obj; + } + -+ dev->nFreeChunks -= dev->blocksInCheckpoint * dev->nChunksPerBlock; -+ dev->nErasedBlocks -= dev->blocksInCheckpoint; -+ ++ /* If there are none left make more */ ++ if (!allocator->free_objs) ++ yaffs_create_free_objs(dev, YAFFS_ALLOCATION_NOBJECTS); + -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint byte count %d" TENDSTR), -+ dev->checkpointByteCount)); ++ if (allocator->free_objs) { ++ obj = allocator->free_objs; ++ allocator->free_objs = ++ (struct yaffs_obj *)(allocator->free_objs->siblings.next); ++ allocator->n_free_objects--; ++ } + -+ if (dev->checkpointBuffer) { -+ /* free the buffer */ -+ YFREE(dev->checkpointBuffer); -+ dev->checkpointBuffer = NULL; -+ return 1; -+ } else -+ return 0; ++ return obj; +} + -+int yaffs_CheckpointInvalidateStream(yaffs_Device *dev) ++void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj) +{ -+ /* Erase the first checksum block */ + -+ T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate"TENDSTR))); ++ struct yaffs_allocator *allocator = dev->allocator; + -+ if (!yaffs_CheckpointSpaceOk(dev)) -+ return 0; ++ if (!allocator) ++ YBUG(); ++ else { ++ /* Link into the free list. */ ++ obj->siblings.next = (struct list_head *)(allocator->free_objs); ++ allocator->free_objs = obj; ++ allocator->n_free_objects++; ++ } ++} ++ ++void yaffs_deinit_raw_tnodes_and_objs(struct yaffs_dev *dev) ++{ ++ if (dev->allocator) { ++ yaffs_deinit_raw_tnodes(dev); ++ yaffs_deinit_raw_objs(dev); + -+ return yaffs_CheckpointErase(dev); ++ YFREE(dev->allocator); ++ dev->allocator = NULL; ++ } else { ++ YBUG(); ++ } +} + ++void yaffs_init_raw_tnodes_and_objs(struct yaffs_dev *dev) ++{ ++ struct yaffs_allocator *allocator; + ++ if (!dev->allocator) { ++ allocator = YMALLOC(sizeof(struct yaffs_allocator)); ++ if (allocator) { ++ dev->allocator = allocator; ++ yaffs_init_raw_tnodes(dev); ++ yaffs_init_raw_objs(dev); ++ } ++ } else { ++ YBUG(); ++ } ++} + -diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_checkptrw.h linux-2.6.34/fs/yaffs2/yaffs_checkptrw.h ---- linux-2.6.34.orig/fs/yaffs2/yaffs_checkptrw.h 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/yaffs_checkptrw.h 2010-05-20 20:16:22.281614392 +0200 -@@ -0,0 +1,35 @@ ++#endif +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_allocator.h linux-2.6.36/fs/yaffs2/yaffs_allocator.h +--- linux-2.6.36.orig/fs/yaffs2/yaffs_allocator.h 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_allocator.h 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,30 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * -+ * Copyright (C) 2002-2007 Aleph One Ltd. ++ * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning @@ -1012,34 +708,29 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_checkptrw.h linux-2.6.34/fs/yaffs2/y + * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL. + */ + -+#ifndef __YAFFS_CHECKPTRW_H__ -+#define __YAFFS_CHECKPTRW_H__ ++#ifndef __YAFFS_ALLOCATOR_H__ ++#define __YAFFS_ALLOCATOR_H__ + +#include "yaffs_guts.h" + -+int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting); -+ -+int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes); -+ -+int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes); -+ -+int yaffs_GetCheckpointSum(yaffs_Device *dev, __u32 *sum); ++void yaffs_init_raw_tnodes_and_objs(struct yaffs_dev *dev); ++void yaffs_deinit_raw_tnodes_and_objs(struct yaffs_dev *dev); + -+int yaffs_CheckpointClose(yaffs_Device *dev); -+ -+int yaffs_CheckpointInvalidateStream(yaffs_Device *dev); ++struct yaffs_tnode *yaffs_alloc_raw_tnode(struct yaffs_dev *dev); ++void yaffs_free_raw_tnode(struct yaffs_dev *dev, struct yaffs_tnode *tn); + ++struct yaffs_obj *yaffs_alloc_raw_obj(struct yaffs_dev *dev); ++void yaffs_free_raw_obj(struct yaffs_dev *dev, struct yaffs_obj *obj); + +#endif -+ -diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_ecc.c linux-2.6.34/fs/yaffs2/yaffs_ecc.c ---- linux-2.6.34.orig/fs/yaffs2/yaffs_ecc.c 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/yaffs_ecc.c 2010-05-20 20:16:22.281614392 +0200 -@@ -0,0 +1,326 @@ +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_attribs.c linux-2.6.36/fs/yaffs2/yaffs_attribs.c +--- linux-2.6.36.orig/fs/yaffs2/yaffs_attribs.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_attribs.c 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,124 @@ +/* + * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. + * -+ * Copyright (C) 2002-2007 Aleph One Ltd. ++ * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning @@ -1049,327 +740,265 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_ecc.c linux-2.6.34/fs/yaffs2/yaffs_e + * published by the Free Software Foundation. + */ + -+/* -+ * This code implements the ECC algorithm used in SmartMedia. -+ * -+ * The ECC comprises 22 bits of parity information and is stuffed into 3 bytes. -+ * The two unused bit are set to 1. -+ * The ECC can correct single bit errors in a 256-byte page of data. Thus, two such ECC -+ * blocks are used on a 512-byte NAND page. -+ * -+ */ -+ -+/* Table generated by gen-ecc.c -+ * Using a table means we do not have to calculate p1..p4 and p1'..p4' -+ * for each byte of data. These are instead provided in a table in bits7..2. -+ * Bit 0 of each entry indicates whether the entry has an odd or even parity, and therefore -+ * this bytes influence on the line parity. -+ */ -+ -+const char *yaffs_ecc_c_version = -+ "$Id: yaffs_ecc.c,v 1.11 2009-03-06 17:20:50 wookey Exp $"; ++#include "yaffs_guts.h" ++#include "yaffs_attribs.h" + -+#include "yportenv.h" ++void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh) ++{ ++ obj->yst_uid = oh->yst_uid; ++ obj->yst_gid = oh->yst_gid; ++ obj->yst_atime = oh->yst_atime; ++ obj->yst_mtime = oh->yst_mtime; ++ obj->yst_ctime = oh->yst_ctime; ++ obj->yst_rdev = oh->yst_rdev; ++} + -+#include "yaffs_ecc.h" ++void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj) ++{ ++ oh->yst_uid = obj->yst_uid; ++ oh->yst_gid = obj->yst_gid; ++ oh->yst_atime = obj->yst_atime; ++ oh->yst_mtime = obj->yst_mtime; ++ oh->yst_ctime = obj->yst_ctime; ++ oh->yst_rdev = obj->yst_rdev; + -+static const unsigned char column_parity_table[] = { -+ 0x00, 0x55, 0x59, 0x0c, 0x65, 0x30, 0x3c, 0x69, -+ 0x69, 0x3c, 0x30, 0x65, 0x0c, 0x59, 0x55, 0x00, -+ 0x95, 0xc0, 0xcc, 0x99, 0xf0, 0xa5, 0xa9, 0xfc, -+ 0xfc, 0xa9, 0xa5, 0xf0, 0x99, 0xcc, 0xc0, 0x95, -+ 0x99, 0xcc, 0xc0, 0x95, 0xfc, 0xa9, 0xa5, 0xf0, -+ 0xf0, 0xa5, 0xa9, 0xfc, 0x95, 0xc0, 0xcc, 0x99, -+ 0x0c, 0x59, 0x55, 0x00, 0x69, 0x3c, 0x30, 0x65, -+ 0x65, 0x30, 0x3c, 0x69, 0x00, 0x55, 0x59, 0x0c, -+ 0xa5, 0xf0, 0xfc, 0xa9, 0xc0, 0x95, 0x99, 0xcc, -+ 0xcc, 0x99, 0x95, 0xc0, 0xa9, 0xfc, 0xf0, 0xa5, -+ 0x30, 0x65, 0x69, 0x3c, 0x55, 0x00, 0x0c, 0x59, -+ 0x59, 0x0c, 0x00, 0x55, 0x3c, 0x69, 0x65, 0x30, -+ 0x3c, 0x69, 0x65, 0x30, 0x59, 0x0c, 0x00, 0x55, -+ 0x55, 0x00, 0x0c, 0x59, 0x30, 0x65, 0x69, 0x3c, -+ 0xa9, 0xfc, 0xf0, 0xa5, 0xcc, 0x99, 0x95, 0xc0, -+ 0xc0, 0x95, 0x99, 0xcc, 0xa5, 0xf0, 0xfc, 0xa9, -+ 0xa9, 0xfc, 0xf0, 0xa5, 0xcc, 0x99, 0x95, 0xc0, -+ 0xc0, 0x95, 0x99, 0xcc, 0xa5, 0xf0, 0xfc, 0xa9, -+ 0x3c, 0x69, 0x65, 0x30, 0x59, 0x0c, 0x00, 0x55, -+ 0x55, 0x00, 0x0c, 0x59, 0x30, 0x65, 0x69, 0x3c, -+ 0x30, 0x65, 0x69, 0x3c, 0x55, 0x00, 0x0c, 0x59, -+ 0x59, 0x0c, 0x00, 0x55, 0x3c, 0x69, 0x65, 0x30, -+ 0xa5, 0xf0, 0xfc, 0xa9, 0xc0, 0x95, 0x99, 0xcc, -+ 0xcc, 0x99, 0x95, 0xc0, 0xa9, 0xfc, 0xf0, 0xa5, -+ 0x0c, 0x59, 0x55, 0x00, 0x69, 0x3c, 0x30, 0x65, -+ 0x65, 0x30, 0x3c, 0x69, 0x00, 0x55, 0x59, 0x0c, -+ 0x99, 0xcc, 0xc0, 0x95, 0xfc, 0xa9, 0xa5, 0xf0, -+ 0xf0, 0xa5, 0xa9, 0xfc, 0x95, 0xc0, 0xcc, 0x99, -+ 0x95, 0xc0, 0xcc, 0x99, 0xf0, 0xa5, 0xa9, 0xfc, -+ 0xfc, 0xa9, 0xa5, 0xf0, 0x99, 0xcc, 0xc0, 0x95, -+ 0x00, 0x55, 0x59, 0x0c, 0x65, 0x30, 0x3c, 0x69, -+ 0x69, 0x3c, 0x30, 0x65, 0x0c, 0x59, 0x55, 0x00, -+}; ++} + -+/* Count the bits in an unsigned char or a U32 */ ++void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c) ++{ ++ obj->yst_mtime = Y_CURRENT_TIME; ++ if (do_a) ++ obj->yst_atime = obj->yst_atime; ++ if (do_c) ++ obj->yst_ctime = obj->yst_atime; ++} + -+static int yaffs_CountBits(unsigned char x) ++void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev) +{ -+ int r = 0; -+ while (x) { -+ if (x & 1) -+ r++; -+ x >>= 1; -+ } -+ return r; ++ yaffs_load_current_time(obj, 1, 1); ++ obj->yst_rdev = rdev; ++ obj->yst_uid = uid; ++ obj->yst_gid = gid; +} + -+static int yaffs_CountBits32(unsigned x) ++loff_t yaffs_get_file_size(struct yaffs_obj *obj) +{ -+ int r = 0; -+ while (x) { -+ if (x & 1) -+ r++; -+ x >>= 1; ++ YCHAR *alias = NULL; ++ obj = yaffs_get_equivalent_obj(obj); ++ ++ switch (obj->variant_type) { ++ case YAFFS_OBJECT_TYPE_FILE: ++ return obj->variant.file_variant.file_size; ++ case YAFFS_OBJECT_TYPE_SYMLINK: ++ alias = obj->variant.symlink_variant.alias; ++ if (!alias) ++ return 0; ++ return yaffs_strnlen(alias, YAFFS_MAX_ALIAS_LENGTH); ++ default: ++ return 0; + } -+ return r; +} + -+/* Calculate the ECC for a 256-byte block of data */ -+void yaffs_ECCCalculate(const unsigned char *data, unsigned char *ecc) ++int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr) +{ -+ unsigned int i; -+ -+ unsigned char col_parity = 0; -+ unsigned char line_parity = 0; -+ unsigned char line_parity_prime = 0; -+ unsigned char t; -+ unsigned char b; ++ unsigned int valid = attr->ia_valid; + -+ for (i = 0; i < 256; i++) { -+ b = column_parity_table[*data++]; -+ col_parity ^= b; ++ if (valid & ATTR_MODE) ++ obj->yst_mode = attr->ia_mode; ++ if (valid & ATTR_UID) ++ obj->yst_uid = attr->ia_uid; ++ if (valid & ATTR_GID) ++ obj->yst_gid = attr->ia_gid; + -+ if (b & 0x01) { /* odd number of bits in the byte */ -+ line_parity ^= i; -+ line_parity_prime ^= ~i; -+ } -+ } ++ if (valid & ATTR_ATIME) ++ obj->yst_atime = Y_TIME_CONVERT(attr->ia_atime); ++ if (valid & ATTR_CTIME) ++ obj->yst_ctime = Y_TIME_CONVERT(attr->ia_ctime); ++ if (valid & ATTR_MTIME) ++ obj->yst_mtime = Y_TIME_CONVERT(attr->ia_mtime); + -+ ecc[2] = (~col_parity) | 0x03; ++ if (valid & ATTR_SIZE) ++ yaffs_resize_file(obj, attr->ia_size); + -+ t = 0; -+ if (line_parity & 0x80) -+ t |= 0x80; -+ if (line_parity_prime & 0x80) -+ t |= 0x40; -+ if (line_parity & 0x40) -+ t |= 0x20; -+ if (line_parity_prime & 0x40) -+ t |= 0x10; -+ if (line_parity & 0x20) -+ t |= 0x08; -+ if (line_parity_prime & 0x20) -+ t |= 0x04; -+ if (line_parity & 0x10) -+ t |= 0x02; -+ if (line_parity_prime & 0x10) -+ t |= 0x01; -+ ecc[1] = ~t; ++ yaffs_update_oh(obj, NULL, 1, 0, 0, NULL); + -+ t = 0; -+ if (line_parity & 0x08) -+ t |= 0x80; -+ if (line_parity_prime & 0x08) -+ t |= 0x40; -+ if (line_parity & 0x04) -+ t |= 0x20; -+ if (line_parity_prime & 0x04) -+ t |= 0x10; -+ if (line_parity & 0x02) -+ t |= 0x08; -+ if (line_parity_prime & 0x02) -+ t |= 0x04; -+ if (line_parity & 0x01) -+ t |= 0x02; -+ if (line_parity_prime & 0x01) -+ t |= 0x01; -+ ecc[0] = ~t; ++ return YAFFS_OK; + -+#ifdef CONFIG_YAFFS_ECC_WRONG_ORDER -+ /* Swap the bytes into the wrong order */ -+ t = ecc[0]; -+ ecc[0] = ecc[1]; -+ ecc[1] = t; -+#endif +} + -+ -+/* Correct the ECC on a 256 byte block of data */ -+ -+int yaffs_ECCCorrect(unsigned char *data, unsigned char *read_ecc, -+ const unsigned char *test_ecc) ++int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr) +{ -+ unsigned char d0, d1, d2; /* deltas */ -+ -+ d0 = read_ecc[0] ^ test_ecc[0]; -+ d1 = read_ecc[1] ^ test_ecc[1]; -+ d2 = read_ecc[2] ^ test_ecc[2]; -+ -+ if ((d0 | d1 | d2) == 0) -+ return 0; /* no error */ ++ unsigned int valid = 0; + -+ if (((d0 ^ (d0 >> 1)) & 0x55) == 0x55 && -+ ((d1 ^ (d1 >> 1)) & 0x55) == 0x55 && -+ ((d2 ^ (d2 >> 1)) & 0x54) == 0x54) { -+ /* Single bit (recoverable) error in data */ -+ -+ unsigned byte; -+ unsigned bit; ++ attr->ia_mode = obj->yst_mode; ++ valid |= ATTR_MODE; ++ attr->ia_uid = obj->yst_uid; ++ valid |= ATTR_UID; ++ attr->ia_gid = obj->yst_gid; ++ valid |= ATTR_GID; + -+#ifdef CONFIG_YAFFS_ECC_WRONG_ORDER -+ /* swap the bytes to correct for the wrong order */ -+ unsigned char t; ++ Y_TIME_CONVERT(attr->ia_atime) = obj->yst_atime; ++ valid |= ATTR_ATIME; ++ Y_TIME_CONVERT(attr->ia_ctime) = obj->yst_ctime; ++ valid |= ATTR_CTIME; ++ Y_TIME_CONVERT(attr->ia_mtime) = obj->yst_mtime; ++ valid |= ATTR_MTIME; + -+ t = d0; -+ d0 = d1; -+ d1 = t; -+#endif ++ attr->ia_size = yaffs_get_file_size(obj); ++ valid |= ATTR_SIZE; + -+ bit = byte = 0; ++ attr->ia_valid = valid; + -+ if (d1 & 0x80) -+ byte |= 0x80; -+ if (d1 & 0x20) -+ byte |= 0x40; -+ if (d1 & 0x08) -+ byte |= 0x20; -+ if (d1 & 0x02) -+ byte |= 0x10; -+ if (d0 & 0x80) -+ byte |= 0x08; -+ if (d0 & 0x20) -+ byte |= 0x04; -+ if (d0 & 0x08) -+ byte |= 0x02; -+ if (d0 & 0x02) -+ byte |= 0x01; ++ return YAFFS_OK; ++} +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_attribs.h linux-2.6.36/fs/yaffs2/yaffs_attribs.h +--- linux-2.6.36.orig/fs/yaffs2/yaffs_attribs.h 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_attribs.h 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,28 @@ ++/* ++ * YAFFS: Yet another Flash File System . A NAND-flash specific file system. ++ * ++ * Copyright (C) 2002-2010 Aleph One Ltd. ++ * for Toby Churchill Ltd and Brightstar Engineering ++ * ++ * Created by Charles Manning ++ * ++ * 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. ++ */ + -+ if (d2 & 0x80) -+ bit |= 0x04; -+ if (d2 & 0x20) -+ bit |= 0x02; -+ if (d2 & 0x08) -+ bit |= 0x01; ++#ifndef __YAFFS_ATTRIBS_H__ ++#define __YAFFS_ATTRIBS_H__ + -+ data[byte] ^= (1 << bit); ++#include "yaffs_guts.h" + -+ return 1; /* Corrected the error */ -+ } ++void yaffs_load_attribs(struct yaffs_obj *obj, struct yaffs_obj_hdr *oh); ++void yaffs_load_attribs_oh(struct yaffs_obj_hdr *oh, struct yaffs_obj *obj); ++void yaffs_attribs_init(struct yaffs_obj *obj, u32 gid, u32 uid, u32 rdev); ++void yaffs_load_current_time(struct yaffs_obj *obj, int do_a, int do_c); ++int yaffs_set_attribs(struct yaffs_obj *obj, struct iattr *attr); ++int yaffs_get_attribs(struct yaffs_obj *obj, struct iattr *attr); + -+ if ((yaffs_CountBits(d0) + -+ yaffs_CountBits(d1) + -+ yaffs_CountBits(d2)) == 1) { -+ /* Reccoverable error in ecc */ ++#endif +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_bitmap.c linux-2.6.36/fs/yaffs2/yaffs_bitmap.c +--- linux-2.6.36.orig/fs/yaffs2/yaffs_bitmap.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_bitmap.c 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,104 @@ ++/* ++ * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. ++ * ++ * Copyright (C) 2002-2010 Aleph One Ltd. ++ * for Toby Churchill Ltd and Brightstar Engineering ++ * ++ * Created by Charles Manning ++ * ++ * 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. ++ */ + -+ read_ecc[0] = test_ecc[0]; -+ read_ecc[1] = test_ecc[1]; -+ read_ecc[2] = test_ecc[2]; ++#include "yaffs_bitmap.h" ++#include "yaffs_trace.h" ++/* ++ * Chunk bitmap manipulations ++ */ + -+ return 1; /* Corrected the error */ ++static Y_INLINE u8 *yaffs_block_bits(struct yaffs_dev *dev, int blk) ++{ ++ if (blk < dev->internal_start_block || blk > dev->internal_end_block) { ++ T(YAFFS_TRACE_ERROR, ++ (TSTR("**>> yaffs: BlockBits block %d is not valid" TENDSTR), ++ blk)); ++ YBUG(); + } -+ -+ /* Unrecoverable error */ -+ -+ return -1; -+ ++ return dev->chunk_bits + ++ (dev->chunk_bit_stride * (blk - dev->internal_start_block)); +} + -+ -+/* -+ * ECCxxxOther does ECC calcs on arbitrary n bytes of data -+ */ -+void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes, -+ yaffs_ECCOther *eccOther) ++void yaffs_verify_chunk_bit_id(struct yaffs_dev *dev, int blk, int chunk) +{ -+ unsigned int i; -+ -+ unsigned char col_parity = 0; -+ unsigned line_parity = 0; -+ unsigned line_parity_prime = 0; -+ unsigned char b; -+ -+ for (i = 0; i < nBytes; i++) { -+ b = column_parity_table[*data++]; -+ col_parity ^= b; -+ -+ if (b & 0x01) { -+ /* odd number of bits in the byte */ -+ line_parity ^= i; -+ line_parity_prime ^= ~i; -+ } -+ ++ if (blk < dev->internal_start_block || blk > dev->internal_end_block || ++ chunk < 0 || chunk >= dev->param.chunks_per_block) { ++ T(YAFFS_TRACE_ERROR, ++ (TSTR("**>> yaffs: Chunk Id (%d:%d) invalid" TENDSTR), ++ blk, chunk)); ++ YBUG(); + } -+ -+ eccOther->colParity = (col_parity >> 2) & 0x3f; -+ eccOther->lineParity = line_parity; -+ eccOther->lineParityPrime = line_parity_prime; +} + -+int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, -+ yaffs_ECCOther *read_ecc, -+ const yaffs_ECCOther *test_ecc) ++void yaffs_clear_chunk_bits(struct yaffs_dev *dev, int blk) +{ -+ unsigned char cDelta; /* column parity delta */ -+ unsigned lDelta; /* line parity delta */ -+ unsigned lDeltaPrime; /* line parity delta */ -+ unsigned bit; ++ u8 *blk_bits = yaffs_block_bits(dev, blk); + -+ cDelta = read_ecc->colParity ^ test_ecc->colParity; -+ lDelta = read_ecc->lineParity ^ test_ecc->lineParity; -+ lDeltaPrime = read_ecc->lineParityPrime ^ test_ecc->lineParityPrime; ++ memset(blk_bits, 0, dev->chunk_bit_stride); ++} + -+ if ((cDelta | lDelta | lDeltaPrime) == 0) -+ return 0; /* no error */ ++void yaffs_clear_chunk_bit(struct yaffs_dev *dev, int blk, int chunk) ++{ ++ u8 *blk_bits = yaffs_block_bits(dev, blk); + -+ if (lDelta == ~lDeltaPrime && -+ (((cDelta ^ (cDelta >> 1)) & 0x15) == 0x15)) { -+ /* Single bit (recoverable) error in data */ ++ yaffs_verify_chunk_bit_id(dev, blk, chunk); + -+ bit = 0; ++ blk_bits[chunk / 8] &= ~(1 << (chunk & 7)); ++} + -+ if (cDelta & 0x20) -+ bit |= 0x04; -+ if (cDelta & 0x08) -+ bit |= 0x02; -+ if (cDelta & 0x02) -+ bit |= 0x01; ++void yaffs_set_chunk_bit(struct yaffs_dev *dev, int blk, int chunk) ++{ ++ u8 *blk_bits = yaffs_block_bits(dev, blk); + -+ if (lDelta >= nBytes) -+ return -1; ++ yaffs_verify_chunk_bit_id(dev, blk, chunk); + -+ data[lDelta] ^= (1 << bit); ++ blk_bits[chunk / 8] |= (1 << (chunk & 7)); ++} + -+ return 1; /* corrected */ -+ } ++int yaffs_check_chunk_bit(struct yaffs_dev *dev, int blk, int chunk) ++{ ++ u8 *blk_bits = yaffs_block_bits(dev, blk); ++ yaffs_verify_chunk_bit_id(dev, blk, chunk); + -+ if ((yaffs_CountBits32(lDelta) + yaffs_CountBits32(lDeltaPrime) + -+ yaffs_CountBits(cDelta)) == 1) { -+ /* Reccoverable error in ecc */ ++ return (blk_bits[chunk / 8] & (1 << (chunk & 7))) ? 1 : 0; ++} + -+ *read_ecc = *test_ecc; -+ return 1; /* corrected */ ++int yaffs_still_some_chunks(struct yaffs_dev *dev, int blk) ++{ ++ u8 *blk_bits = yaffs_block_bits(dev, blk); ++ int i; ++ for (i = 0; i < dev->chunk_bit_stride; i++) { ++ if (*blk_bits) ++ return 1; ++ blk_bits++; + } ++ return 0; ++} + -+ /* Unrecoverable error */ ++int yaffs_count_chunk_bits(struct yaffs_dev *dev, int blk) ++{ ++ u8 *blk_bits = yaffs_block_bits(dev, blk); ++ int i; ++ int n = 0; ++ for (i = 0; i < dev->chunk_bit_stride; i++) { ++ u8 x = *blk_bits; ++ while (x) { ++ if (x & 1) ++ n++; ++ x >>= 1; ++ } + -+ return -1; ++ blk_bits++; ++ } ++ return n; +} -diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_ecc.h linux-2.6.34/fs/yaffs2/yaffs_ecc.h ---- linux-2.6.34.orig/fs/yaffs2/yaffs_ecc.h 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/yaffs_ecc.h 2010-05-20 20:16:22.281614392 +0200 -@@ -0,0 +1,44 @@ +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_bitmap.h linux-2.6.36/fs/yaffs2/yaffs_bitmap.h +--- linux-2.6.36.orig/fs/yaffs2/yaffs_bitmap.h 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_bitmap.h 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,33 @@ +/* + * YAFFS: Yet another Flash File System . A NAND-flash specific file system. + * -+ * Copyright (C) 2002-2007 Aleph One Ltd. ++ * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning @@ -1382,9205 +1011,9702 @@ diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_ecc.h linux-2.6.34/fs/yaffs2/yaffs_e + */ + +/* -+ * This code implements the ECC algorithm used in SmartMedia. -+ * -+ * The ECC comprises 22 bits of parity information and is stuffed into 3 bytes. -+ * The two unused bit are set to 1. -+ * The ECC can correct single bit errors in a 256-byte page of data. Thus, two such ECC -+ * blocks are used on a 512-byte NAND page. -+ * ++ * Chunk bitmap manipulations + */ + -+#ifndef __YAFFS_ECC_H__ -+#define __YAFFS_ECC_H__ ++#ifndef __YAFFS_BITMAP_H__ ++#define __YAFFS_BITMAP_H__ ++ ++#include "yaffs_guts.h" ++ ++void yaffs_verify_chunk_bit_id(struct yaffs_dev *dev, int blk, int chunk); ++void yaffs_clear_chunk_bits(struct yaffs_dev *dev, int blk); ++void yaffs_clear_chunk_bit(struct yaffs_dev *dev, int blk, int chunk); ++void yaffs_set_chunk_bit(struct yaffs_dev *dev, int blk, int chunk); ++int yaffs_check_chunk_bit(struct yaffs_dev *dev, int blk, int chunk); ++int yaffs_still_some_chunks(struct yaffs_dev *dev, int blk); ++int yaffs_count_chunk_bits(struct yaffs_dev *dev, int blk); + -+typedef struct { -+ unsigned char colParity; -+ unsigned lineParity; -+ unsigned lineParityPrime; -+} yaffs_ECCOther; -+ -+void yaffs_ECCCalculate(const unsigned char *data, unsigned char *ecc); -+int yaffs_ECCCorrect(unsigned char *data, unsigned char *read_ecc, -+ const unsigned char *test_ecc); -+ -+void yaffs_ECCCalculateOther(const unsigned char *data, unsigned nBytes, -+ yaffs_ECCOther *ecc); -+int yaffs_ECCCorrectOther(unsigned char *data, unsigned nBytes, -+ yaffs_ECCOther *read_ecc, -+ const yaffs_ECCOther *test_ecc); -+#endif -diff -Nur linux-2.6.34.orig/fs/yaffs2/yaffs_fs.c linux-2.6.34/fs/yaffs2/yaffs_fs.c ---- linux-2.6.34.orig/fs/yaffs2/yaffs_fs.c 1970-01-01 01:00:00.000000000 +0100 -+++ linux-2.6.34/fs/yaffs2/yaffs_fs.c 2010-05-20 20:16:22.281614392 +0200 -@@ -0,0 +1,2529 @@ ++#endif +diff -Nur linux-2.6.36.orig/fs/yaffs2/yaffs_checkptrw.c linux-2.6.36/fs/yaffs2/yaffs_checkptrw.c +--- linux-2.6.36.orig/fs/yaffs2/yaffs_checkptrw.c 1970-01-01 01:00:00.000000000 +0100 ++++ linux-2.6.36/fs/yaffs2/yaffs_checkptrw.c 2010-11-18 18:15:51.000000000 +0100 +@@ -0,0 +1,420 @@ +/* + * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. + * -+ * Copyright (C) 2002-2009 Aleph One Ltd. ++ * Copyright (C) 2002-2010 Aleph One Ltd. + * for Toby Churchill Ltd and Brightstar Engineering + * + * Created by Charles Manning -+ * Acknowledgements: -+ * Luc van OostenRyck for numerous patches. -+ * Nick Bane for numerous patches. -+ * Nick Bane for 2.5/2.6 integration. -+ * Andras Toth for mknod rdev issue. -+ * Michael Fischer for finding the problem with inode inconsistency. -+ * Some code bodily lifted from JFFS + * + * 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 is the file system front-end to YAFFS that hooks it up to -+ * the VFS. -+ * -+ * Special notes: -+ * >> 2.4: sb->u.generic_sbp points to the yaffs_Device associated with -+ * this superblock -+ * >> 2.6: sb->s_fs_info points to the yaffs_Device associated with this -+ * superblock -+ * >> inode->u.generic_ip points to the associated yaffs_Object. -+ */ -+ -+const char *yaffs_fs_c_version = -+ "$Id: yaffs_fs.c,v 1.79 2009-03-17 01:12:00 wookey Exp $"; -+extern const char *yaffs_guts_c_version; ++#include "yaffs_checkptrw.h" ++#include "yaffs_getblockinfo.h" + -+#include -+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)) -+#include -+#endif -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include -+#include ++static int yaffs2_checkpt_space_ok(struct yaffs_dev *dev) ++{ ++ int blocks_avail = dev->n_erased_blocks - dev->param.n_reserved_blocks; + -+#include "asm/div64.h" ++ T(YAFFS_TRACE_CHECKPOINT, ++ (TSTR("checkpt blocks available = %d" TENDSTR), blocks_avail)); + -+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)) ++ return (blocks_avail <= 0) ? 0 : 1; ++} + -+#include /* Added NCB 15-8-2003 */ -+#include -+#define UnlockPage(p) unlock_page(p) -+#define Page_Uptodate(page) test_bit(PG_uptodate, &(page)->flags) ++static int yaffs_checkpt_erase(struct yaffs_dev *dev) ++{ ++ int i; + -+/* FIXME: use sb->s_id instead ? */ -+#define yaffs_devname(sb, buf) bdevname(sb->s_bdev, buf) ++ if (!dev->param.erase_fn) ++ return 0; ++ T(YAFFS_TRACE_CHECKPOINT, (TSTR("checking blocks %d to %d" TENDSTR), ++ dev->internal_start_block, ++ dev->internal_end_block)); ++ ++ for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) { ++ struct yaffs_block_info *bi = yaffs_get_block_info(dev, i); ++ if (bi->block_state == YAFFS_BLOCK_STATE_CHECKPOINT) { ++ T(YAFFS_TRACE_CHECKPOINT, ++ (TSTR("erasing checkpt block %d" TENDSTR), i)); ++ ++ dev->n_erasures++; ++ ++ if (dev->param. ++ erase_fn(dev, ++ i - dev->block_offset /* realign */ )) { ++ bi->block_state = YAFFS_BLOCK_STATE_EMPTY; ++ dev->n_erased_blocks++; ++ dev->n_free_chunks += ++ dev->param.chunks_per_block; ++ } else { ++ dev->param.bad_block_fn(dev, i); ++ bi->block_state = YAFFS_BLOCK_STATE_DEAD; ++ } ++ } ++ } + -+#else ++ dev->blocks_in_checkpt = 0; + -+#include -+#define BDEVNAME_SIZE 0 -+#define yaffs_devname(sb, buf) kdevname(sb->s_dev) ++ return 1; ++} + -+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 5, 0)) -+/* added NCB 26/5/2006 for 2.4.25-vrs2-tcl1 kernel */ -+#define __user -+#endif ++static void yaffs2_checkpt_find_erased_block(struct yaffs_dev *dev) ++{ ++ int i; ++ int blocks_avail = dev->n_erased_blocks - dev->param.n_reserved_blocks; ++ T(YAFFS_TRACE_CHECKPOINT, ++ (TSTR ++ ("allocating checkpt block: erased %d reserved %d avail %d next %d " ++ TENDSTR), dev->n_erased_blocks,