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