2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * yaffs_packedtags2.c: Tags packing for YAFFS2
6 * Copyright (C) 2002 Aleph One Ltd.
8 * Created by Charles Manning <charles@aleph1.co.uk>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * version 2.1 as published by the Free Software Foundation.
16 #include "yaffs_packedtags2.h"
18 #include "yaffs_tagsvalidity.h"
22 // This code packs a set of extended tags into a binary structure for NAND storage
24 // Some of the information is "extra" struff which can be packed in to speed scanning
25 // This is defined by having the EXTRA_HEADER_INFO_FLAG set.
28 // Extra flags applied to chunkId
30 #define EXTRA_HEADER_INFO_FLAG 0x80000000
31 #define EXTRA_SHRINK_FLAG 0x40000000
32 #define EXTRA_SPARE_FLAGS 0x30000000
34 #define ALL_EXTRA_FLAGS 0xF0000000
38 // Also, the top 4 bits of the object Id are set to the object type.
39 #define EXTRA_OBJECT_TYPE_SHIFT (28)
40 #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT)
44 static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 *pt)
46 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));
49 static void yaffs_DumpTags2(const yaffs_ExtendedTags *t)
51 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),
52 t->eccResult, t->blockBad, t->chunkUsed, t->objectId, t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, t->sequenceNumber));
56 void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t)
58 pt->t.chunkId = t->chunkId;
59 pt->t.sequenceNumber = t->sequenceNumber;
60 pt->t.byteCount = t->byteCount;
61 pt->t.objectId = t->objectId;
63 if(t->chunkId == 0 && t->extraHeaderInfoAvailable)
65 // Store the extra header info instead
66 pt->t.chunkId = EXTRA_HEADER_INFO_FLAG | t->extraParentObjectId; // We save the parent object in the chunkId
67 if(t->extraIsShrinkHeader)
69 pt->t.chunkId |= EXTRA_SHRINK_FLAG;
72 pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK;
73 pt->t.objectId |= (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT);
75 if(t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK)
77 pt->t.byteCount = t->extraEquivalentObjectId;
79 else if(t->extraObjectType == YAFFS_OBJECT_TYPE_FILE)
81 pt->t.byteCount = t->extraFileLength;
89 yaffs_DumpPackedTags2(pt);
92 yaffs_ECCCalculateOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&pt->ecc);
96 void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt)
100 memset(t,0,sizeof(yaffs_ExtendedTags));
102 yaffs_InitialiseTags(t);
104 if(pt->t.sequenceNumber != 0xFFFFFFFF)
108 yaffs_ECCCalculateOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&ecc);
109 t->eccResult = yaffs_ECCCorrectOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&pt->ecc,&ecc);
112 t->objectId = pt->t.objectId;
113 t->chunkId = pt->t.chunkId;
114 t->byteCount = pt->t.byteCount;
117 t->sequenceNumber = pt->t.sequenceNumber;
119 // Do extra header info stuff
121 if(pt->t.chunkId & EXTRA_HEADER_INFO_FLAG)
126 t->extraHeaderInfoAvailable = 1;
127 t->extraParentObjectId = pt->t.chunkId & (~(ALL_EXTRA_FLAGS));
128 t->extraIsShrinkHeader = (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0;
129 t->extraObjectType = pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT;
130 t->objectId &= ~EXTRA_OBJECT_TYPE_MASK;
132 if(t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK)
134 t->extraEquivalentObjectId = pt->t.byteCount;
138 t->extraFileLength = pt->t.byteCount;
143 yaffs_DumpPackedTags2(pt);