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_SHADOWS_FLAG 0x20000000
33 #define EXTRA_SPARE_FLAGS 0x10000000
35 #define ALL_EXTRA_FLAGS 0xF0000000
39 // Also, the top 4 bits of the object Id are set to the object type.
40 #define EXTRA_OBJECT_TYPE_SHIFT (28)
41 #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT)
45 static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 *pt)
47 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));
50 static void yaffs_DumpTags2(const yaffs_ExtendedTags *t)
52 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),
53 t->eccResult, t->blockBad, t->chunkUsed, t->objectId, t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber, t->sequenceNumber));
57 void yaffs_PackTags2(yaffs_PackedTags2 *pt, const yaffs_ExtendedTags *t)
59 pt->t.chunkId = t->chunkId;
60 pt->t.sequenceNumber = t->sequenceNumber;
61 pt->t.byteCount = t->byteCount;
62 pt->t.objectId = t->objectId;
64 if(t->chunkId == 0 && t->extraHeaderInfoAvailable)
66 // Store the extra header info instead
67 pt->t.chunkId = EXTRA_HEADER_INFO_FLAG | t->extraParentObjectId; // We save the parent object in the chunkId
68 if(t->extraIsShrinkHeader)
70 pt->t.chunkId |= EXTRA_SHRINK_FLAG;
74 pt->t.chunkId |= EXTRA_SHADOWS_FLAG;
77 pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK;
78 pt->t.objectId |= (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT);
80 if(t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK)
82 pt->t.byteCount = t->extraEquivalentObjectId;
84 else if(t->extraObjectType == YAFFS_OBJECT_TYPE_FILE)
86 pt->t.byteCount = t->extraFileLength;
94 yaffs_DumpPackedTags2(pt);
97 #ifndef YAFFS_IGNORE_TAGS_ECC
99 yaffs_ECCCalculateOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&pt->ecc);
104 void yaffs_UnpackTags2(yaffs_ExtendedTags *t, yaffs_PackedTags2 *pt)
108 memset(t,0,sizeof(yaffs_ExtendedTags));
110 yaffs_InitialiseTags(t);
112 if(pt->t.sequenceNumber != 0xFFFFFFFF)
115 #ifdef YAFFS_IGNORE_TAGS_ECC
122 yaffs_ECCCalculateOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&ecc);
123 t->eccResult = yaffs_ECCCorrectOther((unsigned char *)&pt->t,sizeof(yaffs_PackedTags2TagsPart),&pt->ecc,&ecc);
128 t->objectId = pt->t.objectId;
129 t->chunkId = pt->t.chunkId;
130 t->byteCount = pt->t.byteCount;
133 t->sequenceNumber = pt->t.sequenceNumber;
135 // Do extra header info stuff
137 if(pt->t.chunkId & EXTRA_HEADER_INFO_FLAG)
142 t->extraHeaderInfoAvailable = 1;
143 t->extraParentObjectId = pt->t.chunkId & (~(ALL_EXTRA_FLAGS));
144 t->extraIsShrinkHeader = (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0;
145 t->extraShadows = (pt->t.chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0;
146 t->extraObjectType = pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT;
147 t->objectId &= ~EXTRA_OBJECT_TYPE_MASK;
149 if(t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK)
151 t->extraEquivalentObjectId = pt->t.byteCount;
155 t->extraFileLength = pt->t.byteCount;
160 yaffs_DumpPackedTags2(pt);