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