2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
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.
14 #include "yaffs_packedtags2.h"
16 #include "yaffs_trace.h"
17 #include "yaffs_tagsvalidity.h"
19 /* This code packs a set of extended tags into a binary structure for
23 /* Some of the information is "extra" struff which can be packed in to
25 * This is defined by having the EXTRA_HEADER_INFO_FLAG set.
28 /* Extra flags applied to chunk_id */
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
37 /* Also, the top 4 bits of the object Id are set to the object type. */
38 #define EXTRA_OBJECT_TYPE_SHIFT (28)
39 #define EXTRA_OBJECT_TYPE_MASK ((0x0F) << EXTRA_OBJECT_TYPE_SHIFT)
41 static void yaffs_dump_packed_tags2_tags_only(const struct
42 yaffs_packed_tags2_tags_only *ptt)
45 (TSTR("packed tags obj %d chunk %d byte %d seq %d" TENDSTR),
46 ptt->obj_id, ptt->chunk_id, ptt->n_bytes, ptt->seq_number));
49 static void yaffs_dump_packed_tags2(const struct yaffs_packed_tags2 *pt)
51 yaffs_dump_packed_tags2_tags_only(&pt->t);
54 static void yaffs_dump_tags2(const struct yaffs_ext_tags *t)
58 ("ext.tags eccres %d blkbad %d chused %d obj %d chunk%d byte %d del %d ser %d seq %d"
59 TENDSTR), t->ecc_result, t->block_bad, t->chunk_used, t->obj_id,
60 t->chunk_id, t->n_bytes, t->is_deleted, t->serial_number,
65 void yaffs_pack_tags2_tags_only(struct yaffs_packed_tags2_tags_only *ptt,
66 const struct yaffs_ext_tags *t)
68 ptt->chunk_id = t->chunk_id;
69 ptt->seq_number = t->seq_number;
70 ptt->n_bytes = t->n_bytes;
71 ptt->obj_id = t->obj_id;
73 if (t->chunk_id == 0 && t->extra_available) {
74 /* Store the extra header info instead */
75 /* We save the parent object in the chunk_id */
76 ptt->chunk_id = EXTRA_HEADER_INFO_FLAG | t->extra_parent_id;
77 if (t->extra_is_shrink)
78 ptt->chunk_id |= EXTRA_SHRINK_FLAG;
80 ptt->chunk_id |= EXTRA_SHADOWS_FLAG;
82 ptt->obj_id &= ~EXTRA_OBJECT_TYPE_MASK;
83 ptt->obj_id |= (t->extra_obj_type << EXTRA_OBJECT_TYPE_SHIFT);
85 if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
86 ptt->n_bytes = t->extra_equiv_id;
87 else if (t->extra_obj_type == YAFFS_OBJECT_TYPE_FILE)
88 ptt->n_bytes = t->extra_length;
93 yaffs_dump_packed_tags2_tags_only(ptt);
97 void yaffs_pack_tags2(struct yaffs_packed_tags2 *pt,
98 const struct yaffs_ext_tags *t, int tags_ecc)
100 yaffs_pack_tags2_tags_only(&pt->t, t);
103 yaffs_ecc_calc_other((unsigned char *)&pt->t,
105 yaffs_packed_tags2_tags_only),
109 void yaffs_unpack_tags2_tags_only(struct yaffs_ext_tags *t,
110 struct yaffs_packed_tags2_tags_only *ptt)
113 memset(t, 0, sizeof(struct yaffs_ext_tags));
117 if (ptt->seq_number != 0xFFFFFFFF) {
120 t->obj_id = ptt->obj_id;
121 t->chunk_id = ptt->chunk_id;
122 t->n_bytes = ptt->n_bytes;
124 t->serial_number = 0;
125 t->seq_number = ptt->seq_number;
127 /* Do extra header info stuff */
129 if (ptt->chunk_id & EXTRA_HEADER_INFO_FLAG) {
133 t->extra_available = 1;
135 ptt->chunk_id & (~(ALL_EXTRA_FLAGS));
137 (ptt->chunk_id & EXTRA_SHRINK_FLAG) ? 1 : 0;
139 (ptt->chunk_id & EXTRA_SHADOWS_FLAG) ? 1 : 0;
141 ptt->obj_id >> EXTRA_OBJECT_TYPE_SHIFT;
142 t->obj_id &= ~EXTRA_OBJECT_TYPE_MASK;
144 if (t->extra_obj_type == YAFFS_OBJECT_TYPE_HARDLINK)
145 t->extra_equiv_id = ptt->n_bytes;
147 t->extra_length = ptt->n_bytes;
151 yaffs_dump_packed_tags2_tags_only(ptt);
156 void yaffs_unpack_tags2(struct yaffs_ext_tags *t, struct yaffs_packed_tags2 *pt,
160 enum yaffs_ecc_result ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
162 if (pt->t.seq_number != 0xFFFFFFFF && tags_ecc) {
163 /* Chunk is in use and we need to do ECC */
165 struct yaffs_ecc_other ecc;
167 yaffs_ecc_calc_other((unsigned char *)&pt->t,
169 yaffs_packed_tags2_tags_only),
172 yaffs_ecc_correct_other((unsigned char *)&pt->t,
174 yaffs_packed_tags2_tags_only),
178 ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
181 ecc_result = YAFFS_ECC_RESULT_FIXED;
184 ecc_result = YAFFS_ECC_RESULT_UNFIXED;
187 ecc_result = YAFFS_ECC_RESULT_UNKNOWN;
191 yaffs_unpack_tags2_tags_only(t, &pt->t);
193 t->ecc_result = ecc_result;
195 yaffs_dump_packed_tags2(pt);