Fix race yaffs_flush_inodes against iput
[yaffs2.git] / yaffs_packedtags1.c
1 /*
2  * YAFFS: Yet Another Flash File System. A NAND-flash specific file system.
3  *
4  * Copyright (C) 2002-2018 Aleph One Ltd.
5  *
6  * Created by Charles Manning <charles@aleph1.co.uk>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 #include "yaffs_packedtags1.h"
14 #include "yportenv.h"
15
16 static const u8 all_ff[20] = {
17         0xff, 0xff, 0xff, 0xff,
18         0xff, 0xff, 0xff, 0xff,
19         0xff, 0xff, 0xff, 0xff,
20         0xff, 0xff, 0xff, 0xff,
21         0xff, 0xff, 0xff, 0xff
22 };
23
24 void yaffs_pack_tags1(struct yaffs_packed_tags1 *pt,
25                       const struct yaffs_ext_tags *t)
26 {
27         pt->chunk_id = t->chunk_id;
28         pt->serial_number = t->serial_number;
29         pt->n_bytes = t->n_bytes;
30         pt->obj_id = t->obj_id;
31         pt->ecc = 0;
32         pt->deleted = (t->is_deleted) ? 0 : 1;
33         pt->unused_stuff = 0;
34         pt->should_be_ff = 0xffffffff;
35 }
36
37 void yaffs_unpack_tags1(struct yaffs_ext_tags *t,
38                         const struct yaffs_packed_tags1 *pt)
39 {
40         if (memcmp(all_ff, pt, sizeof(struct yaffs_packed_tags1))) {
41                 t->block_bad = 0;
42                 if (pt->should_be_ff != 0xffffffff)
43                         t->block_bad = 1;
44                 t->chunk_used = 1;
45                 t->obj_id = pt->obj_id;
46                 t->chunk_id = pt->chunk_id;
47                 t->n_bytes = pt->n_bytes;
48                 t->ecc_result = YAFFS_ECC_RESULT_NO_ERROR;
49                 t->is_deleted = (pt->deleted) ? 0 : 1;
50                 t->serial_number = pt->serial_number;
51         } else {
52                 memset(t, 0, sizeof(struct yaffs_ext_tags));
53         }
54 }