Mercurial > yaffs-ecoscentric-gpl
annotate yaffs_packedtags2.c @ 424:d21d6fd33e63
yaffs Fix incorrect handling of deletion flag
Move the reading of the deleted flag so that it picks up any changes.
Notw we need a value on the stack because the object might get
freed and we don't want to access a hanging pointer.
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
| author | Charles Manning <cdhmanning@gmail.com> |
|---|---|
| date | Thu, 13 May 2010 14:29:16 +1200 |
| parents | b5309c9b6d7f |
| children |
| rev | line source |
|---|---|
| 14 | 1 /* |
| 168 | 2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. |
| 14 | 3 * |
|
409
b5309c9b6d7f
yaffs Some cleanups.
Charles Manning <cdhmanning@gmail.com>
parents:
343
diff
changeset
|
4 * Copyright (C) 2002-2010 Aleph One Ltd. |
| 168 | 5 * for Toby Churchill Ltd and Brightstar Engineering |
| 14 | 6 * |
| 7 * Created by Charles Manning <charles@aleph1.co.uk> | |
| 8 * | |
| 168 | 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. | |
| 14 | 12 */ |
| 77 | 13 |
| 6 | 14 #include "yaffs_packedtags2.h" |
| 15 #include "yportenv.h" | |
| 342 | 16 #include "yaffs_trace.h" |
| 14 | 17 #include "yaffs_tagsvalidity.h" |
| 18 | |
| 77 | 19 /* This code packs a set of extended tags into a binary structure for |
| 20 * NAND storage | |
| 21 */ | |
| 14 | 22 |
| 77 | 23 /* Some of the information is "extra" struff which can be packed in to |
| 24 * speed scanning | |
| 25 * This is defined by having the EXTRA_HEADER_INFO_FLAG set. | |
| 26 */ | |
| 14 | 27 |
| 77 | 28 /* Extra flags applied to chunkId */ |
| 14 | 29 |
| 30 #define EXTRA_HEADER_INFO_FLAG 0x80000000 | |
| 31 #define EXTRA_SHRINK_FLAG 0x40000000 | |
| 48 | 32 #define EXTRA_SHADOWS_FLAG 0x20000000 |
| 33 #define EXTRA_SPARE_FLAGS 0x10000000 | |
| 14 | 34 |
| 35 #define ALL_EXTRA_FLAGS 0xF0000000 | |
| 36 | |
| 77 | 37 /* Also, the top 4 bits of the object Id are set to the object type. */ |
| 14 | 38 #define EXTRA_OBJECT_TYPE_SHIFT (28) |
| 39 #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT) | |
| 40 | |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
41 |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
42 static void yaffs_DumpPackedTags2TagsPart(const yaffs_PackedTags2TagsPart *ptt) |
| 7 | 43 { |
| 77 | 44 T(YAFFS_TRACE_MTD, |
| 45 (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR), | |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
46 ptt->objectId, ptt->chunkId, ptt->byteCount, |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
47 ptt->sequenceNumber)); |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
48 } |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
49 static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 *pt) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
50 { |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
51 yaffs_DumpPackedTags2TagsPart(&pt->t); |
| 7 | 52 } |
| 6 | 53 |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
54 static void yaffs_DumpTags2(const yaffs_ExtendedTags *t) |
| 7 | 55 { |
| 77 | 56 T(YAFFS_TRACE_MTD, |
| 57 (TSTR | |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
58 ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d" |
| 77 | 59 TENDSTR), t->eccResult, t->blockBad, t->chunkUsed, t->objectId, |
| 60 t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, | |
| 61 t->sequenceNumber)); | |
| 62 | |
| 7 | 63 } |
| 64 | |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
65 void yaffs_PackTags2TagsPart(yaffs_PackedTags2TagsPart *ptt, |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
66 const yaffs_ExtendedTags *t) |
| 6 | 67 { |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
68 ptt->chunkId = t->chunkId; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
69 ptt->sequenceNumber = t->sequenceNumber; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
70 ptt->byteCount = t->byteCount; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
71 ptt->objectId = t->objectId; |
| 77 | 72 |
| 73 if (t->chunkId == 0 && t->extraHeaderInfoAvailable) { | |
| 74 /* Store the extra header info instead */ | |
| 75 /* We save the parent object in the chunkId */ | |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
76 ptt->chunkId = EXTRA_HEADER_INFO_FLAG |
| 77 | 77 | t->extraParentObjectId; |
| 274 | 78 if (t->extraIsShrinkHeader) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
79 ptt->chunkId |= EXTRA_SHRINK_FLAG; |
| 274 | 80 if (t->extraShadows) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
81 ptt->chunkId |= EXTRA_SHADOWS_FLAG; |
| 77 | 82 |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
83 ptt->objectId &= ~EXTRA_OBJECT_TYPE_MASK; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
84 ptt->objectId |= |
| 77 | 85 (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT); |
| 86 | |
| 274 | 87 if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
88 ptt->byteCount = t->extraEquivalentObjectId; |
| 274 | 89 else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
90 ptt->byteCount = t->extraFileLength; |
| 274 | 91 else |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
92 ptt->byteCount = 0; |
| 14 | 93 } |
| 77 | 94 |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
95 yaffs_DumpPackedTags2TagsPart(ptt); |
| 7 | 96 yaffs_DumpTags2(t); |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
97 } |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
98 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
99 |
|
343
1d1b453d8b57
Change parameters to packing/unpacking to fix mkyaffs2image compilation issue
charles <charles>
parents:
342
diff
changeset
|
100 void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t, int tagsECC) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
101 { |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
102 yaffs_PackTags2TagsPart(&pt->t, t); |
| 77 | 103 |
|
343
1d1b453d8b57
Change parameters to packing/unpacking to fix mkyaffs2image compilation issue
charles <charles>
parents:
342
diff
changeset
|
104 if(tagsECC) |
| 77 | 105 yaffs_ECCCalculateOther((unsigned char *)&pt->t, |
| 106 sizeof(yaffs_PackedTags2TagsPart), | |
| 107 &pt->ecc); | |
| 6 | 108 } |
| 109 | |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
110 |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
111 void yaffs_UnpackTags2TagsPart(yaffs_ExtendedTags *t, |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
112 yaffs_PackedTags2TagsPart *ptt) |
| 6 | 113 { |
| 114 | |
| 77 | 115 memset(t, 0, sizeof(yaffs_ExtendedTags)); |
| 116 | |
| 14 | 117 yaffs_InitialiseTags(t); |
| 77 | 118 |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
119 if (ptt->sequenceNumber != 0xFFFFFFFF) { |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
120 t->blockBad = 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
121 t->chunkUsed = 1; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
122 t->objectId = ptt->objectId; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
123 t->chunkId = ptt->chunkId; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
124 t->byteCount = ptt->byteCount; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
125 t->chunkDeleted = 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
126 t->serialNumber = 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
127 t->sequenceNumber = ptt->sequenceNumber; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
128 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
129 /* Do extra header info stuff */ |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
130 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
131 if (ptt->chunkId & EXTRA_HEADER_INFO_FLAG) { |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
132 t->chunkId = 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
133 t->byteCount = 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
134 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
135 t->extraHeaderInfoAvailable = 1; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
136 t->extraParentObjectId = |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
137 ptt->chunkId & (~(ALL_EXTRA_FLAGS)); |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
138 t->extraIsShrinkHeader = |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
139 (ptt->chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
140 t->extraShadows = |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
141 (ptt->chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
142 t->extraObjectType = |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
143 ptt->objectId >> EXTRA_OBJECT_TYPE_SHIFT; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
144 t->objectId &= ~EXTRA_OBJECT_TYPE_MASK; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
145 |
| 274 | 146 if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
147 t->extraEquivalentObjectId = ptt->byteCount; |
| 274 | 148 else |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
149 t->extraFileLength = ptt->byteCount; |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
150 } |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
151 } |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
152 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
153 yaffs_DumpPackedTags2TagsPart(ptt); |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
154 yaffs_DumpTags2(t); |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
155 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
156 } |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
157 |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
158 |
|
343
1d1b453d8b57
Change parameters to packing/unpacking to fix mkyaffs2image compilation issue
charles <charles>
parents:
342
diff
changeset
|
159 void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt, int tagsECC) |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
160 { |
|
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
161 |
| 244 | 162 yaffs_ECCResult eccResult = YAFFS_ECC_RESULT_NO_ERROR; |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
163 |
| 300 | 164 if (pt->t.sequenceNumber != 0xFFFFFFFF && |
|
343
1d1b453d8b57
Change parameters to packing/unpacking to fix mkyaffs2image compilation issue
charles <charles>
parents:
342
diff
changeset
|
165 tagsECC){ |
| 300 | 166 /* Chunk is in use and we need to do ECC */ |
| 167 | |
| 168 yaffs_ECCOther ecc; | |
| 169 int result; | |
| 170 yaffs_ECCCalculateOther((unsigned char *)&pt->t, | |
| 171 sizeof(yaffs_PackedTags2TagsPart), | |
| 172 &ecc); | |
| 173 result = yaffs_ECCCorrectOther((unsigned char *)&pt->t, | |
| 174 sizeof(yaffs_PackedTags2TagsPart), | |
| 175 &pt->ecc, &ecc); | |
| 176 switch (result) { | |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
177 case 0: |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
178 eccResult = YAFFS_ECC_RESULT_NO_ERROR; |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
179 break; |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
180 case 1: |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
181 eccResult = YAFFS_ECC_RESULT_FIXED; |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
182 break; |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
183 case -1: |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
184 eccResult = YAFFS_ECC_RESULT_UNFIXED; |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
185 break; |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
186 default: |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
187 eccResult = YAFFS_ECC_RESULT_UNKNOWN; |
|
22
0b57027b96fe
Some improvements to garbage collection and st_xxx to yst_xxx changes
charles <charles>
parents:
14
diff
changeset
|
188 } |
| 6 | 189 } |
| 7 | 190 |
|
271
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
191 yaffs_UnpackTags2TagsPart(t, &pt->t); |
|
c0dfae9e8073
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey <wookey>
parents:
244
diff
changeset
|
192 |
| 244 | 193 t->eccResult = eccResult; |
| 194 | |
| 7 | 195 yaffs_DumpPackedTags2(pt); |
| 196 yaffs_DumpTags2(t); | |
| 6 | 197 } |
|
204
0f70320a2274
Check in inband tags, some extra yaffs direct functions and some other changes
charles <charles>
parents:
198
diff
changeset
|
198 |
