97668dc7dc4be19b6a3d8d8e897993585aac249a
[yaffs2.git] / yaffs_packedtags2.c
1 #include "yaffs_packedtags2.h"
2 #include "yportenv.h"
3
4
5 static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 *pt)
6 {
7         T(YAFFS_TRACE_MTD,(TSTR("packed tags obj %d chunk %d byte %d seq %d"TENDSTR),pt->t.objectId,pt->t.chunkId,pt->t.byteCount,pt->t.sequenceNumber));
8 }
9
10 static void yaffs_DumpTags2(const yaffs_ExtendedTags *t)
11 {
12         T(YAFFS_TRACE_MTD,(TSTR("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d"TENDSTR),
13              t->eccResult, t->blockBad, t->chunkUsed, t->objectId, t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, t->sequenceNumber));
14           
15 }
16
17 void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t)
18 {
19         pt->t.chunkId = t->chunkId;
20         pt->t.sequenceNumber = t->sequenceNumber;
21         pt->t.byteCount = t->byteCount;
22         pt->t.objectId = t->objectId;
23         
24         yaffs_DumpPackedTags2(pt);
25         yaffs_DumpTags2(t);
26         
27         yaffs_ECCCalculateOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&pt->ecc);
28         
29 }
30
31 void yaffs_UnpackTags2(yaffs_ExtendedTags *t, const yaffs_PackedTags2 *pt)
32 {
33
34         
35         if(pt->t.sequenceNumber == 0xFFFFFFFF)
36         {
37                 memset(t,0,sizeof(yaffs_ExtendedTags));
38                 
39         }
40         else
41         {
42                 // Page is in use
43                 yaffs_ECCOther ecc;
44                 yaffs_ECCCalculateOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&ecc);
45                 t->eccResult = yaffs_ECCCorrectOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&pt->ecc,&ecc);
46                 t->blockBad = 0;
47                 t->chunkUsed = 1;
48                 t->objectId = pt->t.objectId;
49                 t->chunkId =  pt->t.chunkId;
50                 t->byteCount = pt->t.byteCount;
51                 t->chunkDeleted = 0;
52                 t->serialNumber = 0;
53                 t->sequenceNumber = pt->t.sequenceNumber;
54         }
55
56         yaffs_DumpPackedTags2(pt);
57         yaffs_DumpTags2(t);
58
59 }
60