Mercurial > yaffs-ecoscentric-gpl
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 |
| rev | line source |
|---|---|
| 168 | 1 /* |
| 2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. | |
| 127 | 3 * |
| 168 | 4 * Copyright (C) 2002-2007 Aleph One Ltd. |
| 127 | 5 * for Toby Churchill Ltd and Brightstar Engineering |
| 6 * | |
| 7 * Created by Charles Manning <charles@aleph1.co.uk> | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or modify | |
| 10 * it under the terms of the GNU General Public License version 2 as | |
| 11 * published by the Free Software Foundation. | |
| 12 */ | |
| 13 | |
| 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 | 16 |
| 17 | |
| 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 | 20 |
| 129 | 21 static int yaffs_CheckpointSpaceOk(yaffs_Device *dev) |
| 127 | 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 | 25 T(YAFFS_TRACE_CHECKPOINT, |
| 26 (TSTR("checkpt blocks available = %d" TENDSTR), | |
| 27 blocksAvailable)); | |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
28 |
| 131 | 29 return (blocksAvailable <= 0) ? 0 : 1; |
| 127 | 30 } |
| 31 | |
| 129 | 32 |
| 33 static int yaffs_CheckpointErase(yaffs_Device *dev) | |
| 34 { | |
| 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 | 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 | 50 bi->blockState = YAFFS_BLOCK_STATE_EMPTY; |
| 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 | 55 bi->blockState = YAFFS_BLOCK_STATE_DEAD; |
| 56 } | |
| 57 } | |
| 58 } | |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
59 |
| 129 | 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 | 62 return 1; |
| 63 } | |
| 64 | |
| 65 | |
| 66 static void yaffs_CheckpointFindNextErasedBlock(yaffs_Device *dev) | |
| 67 { | |
| 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 | 70 T(YAFFS_TRACE_CHECKPOINT, |
| 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 | 81 dev->checkpointNextBlock = i + 1; |
| 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 | 84 return; |
| 85 } | |
| 86 } | |
| 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 | 90 dev->checkpointNextBlock = -1; |
| 91 dev->checkpointCurrentBlock = -1; | |
| 92 } | |
| 93 | |
| 94 static void yaffs_CheckpointFindNextCheckpointBlock(yaffs_Device *dev) | |
| 95 { | |
| 96 int i; | |
| 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 | 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 | 105 int realignedChunk = chunk - dev->chunkOffset; |
| 129 | 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 | 113 /* Right kind of block */ |
| 114 dev->checkpointNextBlock = tags.objectId; | |
| 115 dev->checkpointCurrentBlock = i; | |
| 116 dev->checkpointBlockList[dev->blocksInCheckpoint] = i; | |
| 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 | 119 return; |
| 120 } | |
| 121 } | |
| 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 | 124 |
| 125 dev->checkpointNextBlock = -1; | |
| 126 dev->checkpointCurrentBlock = -1; | |
| 127 } | |
| 128 | |
| 129 | |
| 127 | 130 int yaffs_CheckpointOpen(yaffs_Device *dev, int forWriting) |
| 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 | 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 | 141 return 0; |
| 129 | 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 | 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 | 149 return 0; |
| 129 | 150 |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
151 |
| 129 | 152 dev->checkpointPageSequence = 0; |
| 127 | 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 | 156 dev->checkpointCurrentBlock = -1; |
| 157 dev->checkpointCurrentChunk = -1; | |
| 152 | 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 | 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 | 163 dev->checkpointByteOffset = 0; |
| 164 return yaffs_CheckpointErase(dev); | |
| 127 | 165 } else { |
| 129 | 166 int i; |
| 127 | 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 | 169 /* A checkpoint block list of 1 checkpoint block per 16 block is (hopefully) |
| 170 * going to be way more than we need */ | |
| 131 | 171 dev->blocksInCheckpoint = 0; |
| 152 | 172 dev->checkpointMaxBlocks = (dev->internalEndBlock - dev->internalStartBlock)/16 + 2; |
| 129 | 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 | 178 dev->checkpointBlockList[i] = -1; |
| 127 | 179 } |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
180 |
| 127 | 181 return 1; |
| 182 } | |
| 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 | 192 static int yaffs_CheckpointFlushBuffer(yaffs_Device *dev) |
| 193 { | |
| 129 | 194 int chunk; |
| 159 | 195 int realignedChunk; |
| 127 | 196 |
| 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 | 200 yaffs_CheckpointFindNextErasedBlock(dev); |
| 201 dev->checkpointCurrentChunk = 0; | |
| 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 | 205 return 0; |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
206 |
| 127 | 207 tags.chunkDeleted = 0; |
| 129 | 208 tags.objectId = dev->checkpointNextBlock; /* Hint to next place to look */ |
| 209 tags.chunkId = dev->checkpointPageSequence + 1; | |
| 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 | 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 | 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 | 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 | 234 dev->checkpointCurrentChunk++; |
|
356
7ee0cc4ba753
Rationalise context and parameter handling
charles <charles>
parents:
309
diff
changeset
|
235 if (dev->checkpointCurrentChunk >= dev->param.nChunksPerBlock) { |
| 129 | 236 dev->checkpointCurrentChunk = 0; |
| 237 dev->checkpointCurrentBlock = -1; | |
| 127 | 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 | 241 return 1; |
| 242 } | |
| 243 | |
| 129 | 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 | 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 | 248 int ok = 1; |
| 249 | |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
250 |
| 127 | 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 | 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 | 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 | 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 | 266 dev->checkpointByteOffset++; |
| 267 i++; | |
| 268 dataBytes++; | |
| 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 | 274 ok = yaffs_CheckpointFlushBuffer(dev); |
| 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 | 278 } |
| 279 | |
| 280 int yaffs_CheckpointRead(yaffs_Device *dev, void *data, int nBytes) | |
| 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 | 283 int ok = 1; |
| 284 yaffs_ExtendedTags tags; | |
| 129 | 285 |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
286 |
| 129 | 287 int chunk; |
| 159 | 288 int realignedChunk; |
| 127 | 289 |
| 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 | 293 return 0; |
| 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 | 305 yaffs_CheckpointFindNextCheckpointBlock(dev); |
| 306 dev->checkpointCurrentChunk = 0; | |
| 127 | 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 | 310 ok = 0; |
| 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 | 315 |
| 159 | 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 | 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 | 331 |
| 129 | 332 dev->checkpointByteOffset = 0; |
| 333 dev->checkpointPageSequence++; | |
| 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 | 337 dev->checkpointCurrentBlock = -1; |
| 338 } | |
| 127 | 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 | 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 | 345 dev->checkpointByteOffset++; |
| 346 i++; | |
| 347 dataBytes++; | |
| 348 dev->checkpointByteCount++; | |
| 349 } | |
| 350 } | |
|
198
b7f785925166
Cleanup patch - Remove all trailing whitespace and fix a few typos.
wookey <wookey>
parents:
176
diff
changeset
|
351 |
| 127 | 352 return i; |
| 353 } | |
| 354 | |
| 355 int yaffs_CheckpointClose(yaffs_Device *dev) | |
| 356 { | |
| 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 | 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 | 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 | 369 bi->blockState = YAFFS_BLOCK_STATE_CHECKPOINT; |
| 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 | 372 } |
| 373 } | |
| 374 YFREE(dev->checkpointBlockList); | |
| 375 dev->checkpointBlockList = NULL; | |
| 127 | 376 } |
| 377 | |
|
356
7ee0cc4ba753
Rationalise context and parameter handling
charles <charles>
parents:
309
diff
changeset
|
378 dev->nFreeChunks -= dev->blocksInCheckpoint * dev->param.nChunksPerBlock; |
| 129 | 379 dev->nErasedBlocks -= dev->blocksInCheckpoint; |
| 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 | 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 | 387 YFREE(dev->checkpointBuffer); |
| 388 dev->checkpointBuffer = NULL; | |
| 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 | 391 return 0; |
| 392 } | |
| 393 | |
| 394 int yaffs_CheckpointInvalidateStream(yaffs_Device *dev) | |
| 395 { | |
|
305
7bab1896ec86
Fix checkpoint to handle out of space conditions better
charles <charles>
parents:
288
diff
changeset
|
396 /* Erase the checkpoint data */ |
| 127 | 397 |
| 309 | 398 T(YAFFS_TRACE_CHECKPOINT, (TSTR("checkpoint invalidate of %d blocks"TENDSTR), |
| 399 dev->blocksInCheckpoint)); | |
| 127 | 400 |
| 129 | 401 return yaffs_CheckpointErase(dev); |
| 127 | 402 } |
| 403 | |
| 404 | |
| 405 |
