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"
20 /* This code packs a set of extended tags into a binary structure for
24 /* Some of the information is "extra" struff which can be packed in to
26 * This is defined by having the EXTRA_HEADER_INFO_FLAG set.
29 /* Extra flags applied to chunkId */
31 #define EXTRA_HEADER_INFO_FLAG 0x80000000
32 #define EXTRA_SHRINK_FLAG 0x40000000
33 #define EXTRA_SHADOWS_FLAG 0x20000000
34 #define EXTRA_SPARE_FLAGS 0x10000000
36 #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)
42 static void yaffs_DumpPackedTags2(const yaffs_PackedTags2 * pt)
45 (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR),
46 pt->t.objectId, pt->t.chunkId, pt->t.byteCount,
47 pt->t.sequenceNumber));
50 static void yaffs_DumpTags2(const yaffs_ExtendedTags * t)
54 ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte "
55 "%d del %d ser %d seq %d"
56 TENDSTR), t->eccResult, t->blockBad, t->chunkUsed, t->objectId,
57 t->chunkId, t->byteCount, t->chunkDeleted, t->serialNumber,
62 void yaffs_PackTags2(yaffs_PackedTags2 * pt, const yaffs_ExtendedTags * t)
64 pt->t.chunkId = t->chunkId;
65 pt->t.sequenceNumber = t->sequenceNumber;
66 pt->t.byteCount = t->byteCount;
67 pt->t.objectId = t->objectId;
69 if (t->chunkId == 0 && t->extraHeaderInfoAvailable) {
70 /* Store the extra header info instead */
71 /* We save the parent object in the chunkId */
72 pt->t.chunkId = EXTRA_HEADER_INFO_FLAG
73 | t->extraParentObjectId;
74 if (t->extraIsShrinkHeader) {
75 pt->t.chunkId |= EXTRA_SHRINK_FLAG;
77 if (t->extraShadows) {
78 pt->t.chunkId |= EXTRA_SHADOWS_FLAG;
81 pt->t.objectId &= ~EXTRA_OBJECT_TYPE_MASK;
83 (t->extraObjectType << EXTRA_OBJECT_TYPE_SHIFT);
85 if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) {
86 pt->t.byteCount = t->extraEquivalentObjectId;
87 } else if (t->extraObjectType == YAFFS_OBJECT_TYPE_FILE) {
88 pt->t.byteCount = t->extraFileLength;
94 yaffs_DumpPackedTags2(pt);
97 #ifndef YAFFS_IGNORE_TAGS_ECC
99 yaffs_ECCCalculateOther((unsigned char *)&pt->t,
100 sizeof(yaffs_PackedTags2TagsPart),
106 void yaffs_UnpackTags2(yaffs_ExtendedTags * t, yaffs_PackedTags2 * pt)
109 memset(t, 0, sizeof(yaffs_ExtendedTags));
111 yaffs_InitialiseTags(t);
113 if (pt->t.sequenceNumber != 0xFFFFFFFF) {
115 #ifdef YAFFS_IGNORE_TAGS_ECC
122 yaffs_ECCCalculateOther((unsigned char *)&pt->t,
124 (yaffs_PackedTags2TagsPart),
127 yaffs_ECCCorrectOther((unsigned char *)&pt->t,
129 (yaffs_PackedTags2TagsPart),
135 t->objectId = pt->t.objectId;
136 t->chunkId = pt->t.chunkId;
137 t->byteCount = pt->t.byteCount;
140 t->sequenceNumber = pt->t.sequenceNumber;
142 /* Do extra header info stuff */
144 if (pt->t.chunkId & EXTRA_HEADER_INFO_FLAG) {
148 t->extraHeaderInfoAvailable = 1;
149 t->extraParentObjectId =
150 pt->t.chunkId & (~(ALL_EXTRA_FLAGS));
151 t->extraIsShrinkHeader =
152 (pt->t.chunkId & EXTRA_SHRINK_FLAG) ? 1 : 0;
154 (pt->t.chunkId & EXTRA_SHADOWS_FLAG) ? 1 : 0;
156 pt->t.objectId >> EXTRA_OBJECT_TYPE_SHIFT;
157 t->objectId &= ~EXTRA_OBJECT_TYPE_MASK;
159 if (t->extraObjectType == YAFFS_OBJECT_TYPE_HARDLINK) {
160 t->extraEquivalentObjectId = pt->t.byteCount;
162 t->extraFileLength = pt->t.byteCount;
167 yaffs_DumpPackedTags2(pt);