annotate yaffs_checkptrw.c @ 391:d0784604eafd

Fix typo (and check git is working)
author Wookey <wookey@wookware.org>
date Thu, 18 Mar 2010 21:44:53 +0000
parents 7ee0cc4ba753
children b5309c9b6d7f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
168
b8f20fdc3a58 normalise licence headers and attributions
wookey <wookey>
parents: 159
diff changeset
1 /*
b8f20fdc3a58 normalise licence headers and attributions
wookey <wookey>
parents: 159
diff changeset
2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
3 *
168
b8f20fdc3a58 normalise licence headers and attributions
wookey <wookey>
parents: 159
diff changeset
4 * Copyright (C) 2002-2007 Aleph One Ltd.
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
5 * for Toby Churchill Ltd and Brightstar Engineering
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
6 *
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
7 * Created by Charles Manning <charles@aleph1.co.uk>
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
8 *
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
9 * This program is free software; you can redistribute it and/or modify
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
10 * it under the terms of the GNU General Public License version 2 as
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
11 * published by the Free Software Foundation.
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
12 */
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
13
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
14 const char *yaffs_checkptrw_c_version =
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
15 "$Id: yaffs_checkptrw.c,v 1.23 2010-02-18 01:18:04 charles Exp $";
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
16
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
17
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
18 #include "yaffs_checkptrw.h"
204
0f70320a2274 Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents: 198
diff changeset
19 #include "yaffs_getblockinfo.h"
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
20
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
21 static int yaffs_CheckpointSpaceOk(yaffs_Device *dev)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
22 {
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
23 int blocksAvailable = dev->nErasedBlocks - dev->param.nReservedBlocks;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
24
131
99e93a234aba Fix some checkpoint stuff, add qsort
charles <charles>
parents: 129
diff changeset
25 T(YAFFS_TRACE_CHECKPOINT,
99e93a234aba Fix some checkpoint stuff, add qsort
charles <charles>
parents: 129
diff changeset
26 (TSTR("checkpt blocks available = %d" TENDSTR),
99e93a234aba Fix some checkpoint stuff, add qsort
charles <charles>
parents: 129
diff changeset
27 blocksAvailable));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
28
131
99e93a234aba Fix some checkpoint stuff, add qsort
charles <charles>
parents: 129
diff changeset
29 return (blocksAvailable <= 0) ? 0 : 1;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
30 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
31
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
32
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
33 static int yaffs_CheckpointErase(yaffs_Device *dev)
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
34 {
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
35 int i;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
36
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
37 if (!dev->param.eraseBlockInNAND)
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
38 return 0;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
39 T(YAFFS_TRACE_CHECKPOINT, (TSTR("checking blocks %d to %d"TENDSTR),
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
40 dev->internalStartBlock, dev->internalEndBlock));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
41
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
42 for (i = dev->internalStartBlock; i <= dev->internalEndBlock; i++) {
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
43 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i);
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
44 if (bi->blockState == YAFFS_BLOCK_STATE_CHECKPOINT) {
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
45 T(YAFFS_TRACE_CHECKPOINT, (TSTR("erasing checkpt block %d"TENDSTR), i));
288
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
46
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
47 dev->nBlockErasures++;
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
48
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
49 if (dev->param.eraseBlockInNAND(dev, i - dev->blockOffset /* realign */)) {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
50 bi->blockState = YAFFS_BLOCK_STATE_EMPTY;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
51 dev->nErasedBlocks++;
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
52 dev->nFreeChunks += dev->param.nChunksPerBlock;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
53 } else {
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
54 dev->param.markNANDBlockBad(dev, i);
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
55 bi->blockState = YAFFS_BLOCK_STATE_DEAD;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
56 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
57 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
58 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
59
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
60 dev->blocksInCheckpoint = 0;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
61
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
62 return 1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
63 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
64
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
65
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
66 static void yaffs_CheckpointFindNextErasedBlock(yaffs_Device *dev)
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
67 {
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
68 int i;
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
69 int blocksAvailable = dev->nErasedBlocks - dev->param.nReservedBlocks;
156
697270be7c20 More checkpoint logging
charles <charles>
parents: 152
diff changeset
70 T(YAFFS_TRACE_CHECKPOINT,
697270be7c20 More checkpoint logging
charles <charles>
parents: 152
diff changeset
71 (TSTR("allocating checkpt block: erased %d reserved %d avail %d next %d "TENDSTR),
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
72 dev->nErasedBlocks, dev->param.nReservedBlocks, blocksAvailable, dev->checkpointNextBlock));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
73
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
74 if (dev->checkpointNextBlock >= 0 &&
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
75 dev->checkpointNextBlock <= dev->internalEndBlock &&
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
76 blocksAvailable > 0) {
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
77
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
78 for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) {
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
79 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, i);
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
80 if (bi->blockState == YAFFS_BLOCK_STATE_EMPTY) {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
81 dev->checkpointNextBlock = i + 1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
82 dev->checkpointCurrentBlock = i;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
83 T(YAFFS_TRACE_CHECKPOINT, (TSTR("allocating checkpt block %d"TENDSTR), i));
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
84 return;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
85 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
86 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
87 }
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
88 T(YAFFS_TRACE_CHECKPOINT, (TSTR("out of checkpt blocks"TENDSTR)));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
89
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
90 dev->checkpointNextBlock = -1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
91 dev->checkpointCurrentBlock = -1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
92 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
93
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
94 static void yaffs_CheckpointFindNextCheckpointBlock(yaffs_Device *dev)
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
95 {
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
96 int i;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
97 yaffs_ExtendedTags tags;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
98
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
99 T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: start: blocks %d next %d" TENDSTR),
158
42d5a9ad06f6 Even more checkpoint tracing
charles <charles>
parents: 157
diff changeset
100 dev->blocksInCheckpoint, dev->checkpointNextBlock));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
101
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
102 if (dev->blocksInCheckpoint < dev->checkpointMaxBlocks)
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
103 for (i = dev->checkpointNextBlock; i <= dev->internalEndBlock; i++) {
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
104 int chunk = i * dev->param.nChunksPerBlock;
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
105 int realignedChunk = chunk - dev->chunkOffset;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
106
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
107 dev->param.readChunkWithTagsFromNAND(dev, realignedChunk,
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
108 NULL, &tags);
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
109 T(YAFFS_TRACE_CHECKPOINT, (TSTR("find next checkpt block: search: block %d oid %d seq %d eccr %d" TENDSTR),
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
110 i, tags.objectId, tags.sequenceNumber, tags.eccResult));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
111
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
112 if (tags.sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA) {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
113 /* Right kind of block */
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
114 dev->checkpointNextBlock = tags.objectId;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
115 dev->checkpointCurrentBlock = i;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
116 dev->checkpointBlockList[dev->blocksInCheckpoint] = i;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
117 dev->blocksInCheckpoint++;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
118 T(YAFFS_TRACE_CHECKPOINT, (TSTR("found checkpt block %d"TENDSTR), i));
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
119 return;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
120 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
121 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
122
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
123 T(YAFFS_TRACE_CHECKPOINT, (TSTR("found no more checkpt blocks"TENDSTR)));
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
124
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
125 dev->checkpointNextBlock = -1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
126 dev->checkpointCurrentBlock = -1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
127 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
128
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
129
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
130 int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting)
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
131 {
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
132
305
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
133
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
134 dev->checkpointOpenForWrite = forWriting;
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
135
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
136 /* Got the functions we need? */
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
137 if (!dev->param.writeChunkWithTagsToNAND ||
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
138 !dev->param.readChunkWithTagsFromNAND ||
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
139 !dev->param.eraseBlockInNAND ||
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
140 !dev->param.markNANDBlockBad)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
141 return 0;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
142
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
143 if (forWriting && !yaffs_CheckpointSpaceOk(dev))
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
144 return 0;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
145
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
146 if (!dev->checkpointBuffer)
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
147 dev->checkpointBuffer = YMALLOC_DMA(dev->param.totalBytesPerChunk);
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
148 if (!dev->checkpointBuffer)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
149 return 0;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
150
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
151
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
152 dev->checkpointPageSequence = 0;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
153 dev->checkpointByteCount = 0;
176
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
154 dev->checkpointSum = 0;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
155 dev->checkpointXor = 0;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
156 dev->checkpointCurrentBlock = -1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
157 dev->checkpointCurrentChunk = -1;
152
043b849c6ea3 Fix block offset with checkpointing
charles <charles>
parents: 150
diff changeset
158 dev->checkpointNextBlock = dev->internalStartBlock;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
159
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
160 /* Erase all the blocks in the checkpoint area */
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
161 if (forWriting) {
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
162 memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk);
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
163 dev->checkpointByteOffset = 0;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
164 return yaffs_CheckpointErase(dev);
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
165 } else {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
166 int i;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
167 /* Set to a value that will kick off a read */
146
1a32267ef1c1 Add large NAND support and improve retirement handling
charles <charles>
parents: 132
diff changeset
168 dev->checkpointByteOffset = dev->nDataBytesPerChunk;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
169 /* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully)
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
170 * going to be way more than we need */
131
99e93a234aba Fix some checkpoint stuff, add qsort
charles <charles>
parents: 129
diff changeset
171 dev->blocksInCheckpoint = 0;
152
043b849c6ea3 Fix block offset with checkpointing
charles <charles>
parents: 150
diff changeset
172 dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
173 dev->checkpointBlockList = YMALLOC(sizeof(int) * dev->checkpointMaxBlocks);
283
3d49e1185b42 Handle malloc failure in checkpoint open.
charles <charles>
parents: 271
diff changeset
174 if(!dev->checkpointBlockList)
3d49e1185b42 Handle malloc failure in checkpoint open.
charles <charles>
parents: 271
diff changeset
175 return 0;
3d49e1185b42 Handle malloc failure in checkpoint open.
charles <charles>
parents: 271
diff changeset
176
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
177 for (i = 0; i < dev->checkpointMaxBlocks; i++)
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
178 dev->checkpointBlockList[i] = -1;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
179 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
180
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
181 return 1;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
182 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
183
176
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
184 int yaffs_GetCheckpointSum(yaffs_Device *dev, __u32 *sum)
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
185 {
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
186 __u32 compositeSum;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
187 compositeSum = (dev->checkpointSum << 8) | (dev->checkpointXor & 0xFF);
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
188 *sum = compositeSum;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
189 return 1;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
190 }
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
191
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
192 static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev)
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
193 {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
194 int chunk;
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
195 int realignedChunk;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
196
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
197 yaffs_ExtendedTags tags;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
198
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
199 if (dev->checkpointCurrentBlock < 0) {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
200 yaffs_CheckpointFindNextErasedBlock(dev);
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
201 dev->checkpointCurrentChunk = 0;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
202 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
203
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
204 if (dev->checkpointCurrentBlock < 0)
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
205 return 0;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
206
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
207 tags.chunkDeleted = 0;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
208 tags.objectId = dev->checkpointNextBlock; /* Hint to next place to look */
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
209 tags.chunkId = dev->checkpointPageSequence + 1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
210 tags.sequenceNumber = YAFFS_SEQUENCE_CHECKPOINT_DATA;
146
1a32267ef1c1 Add large NAND support and improve retirement handling
charles <charles>
parents: 132
diff changeset
211 tags.byteCount = dev->nDataBytesPerChunk;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
212 if (dev->checkpointCurrentChunk == 0) {
132
f0d1a05787e4 Fix problem with checkpoint free space handling
charles <charles>
parents: 131
diff changeset
213 /* First chunk we write for the block? Set block state to
f0d1a05787e4 Fix problem with checkpoint free space handling
charles <charles>
parents: 131
diff changeset
214 checkpoint */
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
215 yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, dev->checkpointCurrentBlock);
132
f0d1a05787e4 Fix problem with checkpoint free space handling
charles <charles>
parents: 131
diff changeset
216 bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT;
f0d1a05787e4 Fix problem with checkpoint free space handling
charles <charles>
parents: 131
diff changeset
217 dev->blocksInCheckpoint++;
f0d1a05787e4 Fix problem with checkpoint free space handling
charles <charles>
parents: 131
diff changeset
218 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
219
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
220 chunk = dev->checkpointCurrentBlock * dev->param.nChunksPerBlock + dev->checkpointCurrentChunk;
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
221
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
222
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
223 T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint wite buffer nand %d(%d:%d) objid %d chId %d" TENDSTR),
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
224 chunk, dev->checkpointCurrentBlock, dev->checkpointCurrentChunk, tags.objectId, tags.chunkId));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
225
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
226 realignedChunk = chunk - dev->chunkOffset;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
227
288
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
228 dev->nPageWrites++;
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
229
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
230 dev->param.writeChunkWithTagsToNAND(dev, realignedChunk,
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
231 dev->checkpointBuffer, &tags);
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
232 dev->checkpointByteOffset = 0;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
233 dev->checkpointPageSequence++;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
234 dev->checkpointCurrentChunk++;
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
235 if (dev->checkpointCurrentChunk >= dev->param.nChunksPerBlock) {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
236 dev->checkpointCurrentChunk = 0;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
237 dev->checkpointCurrentBlock = -1;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
238 }
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
239 memset(dev->checkpointBuffer, 0, dev->nDataBytesPerChunk);
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
240
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
241 return 1;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
242 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
243
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
244
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
245 int yaffs_CheckpointWrite(yaffs_Device *dev, const void *data, int nBytes)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
246 {
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
247 int i = 0;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
248 int ok = 1;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
249
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
250
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
251 __u8 * dataBytes = (__u8 *)data;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
252
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
253
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
254
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
255 if (!dev->checkpointBuffer)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
256 return 0;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
257
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
258 if (!dev->checkpointOpenForWrite)
176
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
259 return -1;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
260
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
261 while (i < nBytes && ok) {
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
262 dev->checkpointBuffer[dev->checkpointByteOffset] = *dataBytes;
176
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
263 dev->checkpointSum += *dataBytes;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
264 dev->checkpointXor ^= *dataBytes;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
265
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
266 dev->checkpointByteOffset++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
267 i++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
268 dataBytes++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
269 dev->checkpointByteCount++;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
270
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
271
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
272 if (dev->checkpointByteOffset < 0 ||
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
273 dev->checkpointByteOffset >= dev->nDataBytesPerChunk)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
274 ok = yaffs_CheckpointFlushBuffer(dev);
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
275 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
276
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
277 return i;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
278 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
279
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
280 int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes)
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
281 {
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
282 int i = 0;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
283 int ok = 1;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
284 yaffs_ExtendedTags tags;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
285
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
286
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
287 int chunk;
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
288 int realignedChunk;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
289
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
290 __u8 *dataBytes = (__u8 *)data;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
291
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
292 if (!dev->checkpointBuffer)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
293 return 0;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
294
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
295 if (dev->checkpointOpenForWrite)
176
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
296 return -1;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
297
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
298 while (i < nBytes && ok) {
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
299
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
300
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
301 if (dev->checkpointByteOffset < 0 ||
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
302 dev->checkpointByteOffset >= dev->nDataBytesPerChunk) {
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
303
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
304 if (dev->checkpointCurrentBlock < 0) {
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
305 yaffs_CheckpointFindNextCheckpointBlock(dev);
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
306 dev->checkpointCurrentChunk = 0;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
307 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
308
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
309 if (dev->checkpointCurrentBlock < 0)
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
310 ok = 0;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
311 else {
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
312 chunk = dev->checkpointCurrentBlock *
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
313 dev->param.nChunksPerBlock +
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
314 dev->checkpointCurrentChunk;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
315
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
316 realignedChunk = chunk - dev->chunkOffset;
288
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
317
b20bce8ec7a2 Rationalise stats gathering for nand access. Does not instrument mounting.
charles <charles>
parents: 283
diff changeset
318 dev->nPageReads++;
159
5f4c756ac1d3 Fix offset problem in checkpt code
charles <charles>
parents: 158
diff changeset
319
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
320 /* read in the next chunk */
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
321 /* printf("read checkpoint page %d\n",dev->checkpointPage); */
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
322 dev->param.readChunkWithTagsFromNAND(dev,
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
323 realignedChunk,
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
324 dev->checkpointBuffer,
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
325 &tags);
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
326
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
327 if (tags.chunkId != (dev->checkpointPageSequence + 1) ||
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
328 tags.eccResult > YAFFS_ECC_RESULT_FIXED ||
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
329 tags.sequenceNumber != YAFFS_SEQUENCE_CHECKPOINT_DATA)
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
330 ok = 0;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
331
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
332 dev->checkpointByteOffset = 0;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
333 dev->checkpointPageSequence++;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
334 dev->checkpointCurrentChunk++;
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
335
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
336 if (dev->checkpointCurrentChunk >= dev->param.nChunksPerBlock)
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
337 dev->checkpointCurrentBlock = -1;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
338 }
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
339 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
340
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
341 if (ok) {
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
342 *dataBytes = dev->checkpointBuffer[dev->checkpointByteOffset];
176
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
343 dev->checkpointSum += *dataBytes;
570d9d4cac30 Adding checkpoint and robustness improvements
charles <charles>
parents: 171
diff changeset
344 dev->checkpointXor ^= *dataBytes;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
345 dev->checkpointByteOffset++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
346 i++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
347 dataBytes++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
348 dev->checkpointByteCount++;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
349 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
350 }
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
351
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
352 return i;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
353 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
354
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
355 int yaffs_CheckpointClose(yaffs_Device *dev)
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
356 {
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
357
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
358 if (dev->checkpointOpenForWrite) {
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
359 if (dev->checkpointByteOffset != 0)
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
360 yaffs_CheckpointFlushBuffer(dev);
305
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
361 } else if(dev->checkpointBlockList){
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
362 int i;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
363 for (i = 0; i < dev->blocksInCheckpoint && dev->checkpointBlockList[i] >= 0; i++) {
305
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
364 int blk = dev->checkpointBlockList[i];
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
365 yaffs_BlockInfo *bi = NULL;
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
366 if( dev->internalStartBlock <= blk && blk <= dev->internalEndBlock)
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
367 bi = yaffs_GetBlockInfo(dev, blk);
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
368 if (bi && bi->blockState == YAFFS_BLOCK_STATE_EMPTY)
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
369 bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
370 else {
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
371 /* Todo this looks odd... */
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
372 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
373 }
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
374 YFREE(dev->checkpointBlockList);
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
375 dev->checkpointBlockList = NULL;
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
376 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
377
356
7ee0cc4ba753 Rationalise context and parameter handling
charles <charles>
parents: 309
diff changeset
378 dev->nFreeChunks -= dev->blocksInCheckpoint * dev->param.nChunksPerBlock;
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
379 dev->nErasedBlocks -= dev->blocksInCheckpoint;
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
380
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
381
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
382 T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint byte count %d" TENDSTR),
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
383 dev->checkpointByteCount));
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
384
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
385 if (dev->checkpointBuffer) {
198
b7f785925166 Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents: 176
diff changeset
386 /* free the buffer */
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
387 YFREE(dev->checkpointBuffer);
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
388 dev->checkpointBuffer = NULL;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
389 return 1;
271
c0dfae9e8073 Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents: 215
diff changeset
390 } else
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
391 return 0;
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
392 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
393
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
394 int yaffs_CheckpointInvalidateStream(yaffs_Device *dev)
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
395 {
305
7bab1896ec86 Fix checkpoint to handle out of space conditions better
charles <charles>
parents: 288
diff changeset
396 /* Erase the checkpoint data */
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
397
309
dee97460ace7 Add extra info to checkpoint trace
charles <charles>
parents: 305
diff changeset
398 T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate of %d blocks"TENDSTR),
dee97460ace7 Add extra info to checkpoint trace
charles <charles>
parents: 305
diff changeset
399 dev->blocksInCheckpoint));
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
400
129
5bc7e85eac5b Add non-partitioned checkpointing
charles <charles>
parents: 127
diff changeset
401 return yaffs_CheckpointErase(dev);
127
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
402 }
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
403
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
404
f8fc631acf25 Checkpointing changes
charles <charles>
parents:
diff changeset
405