ebh_media.h revision 1.1.6.2 1 1.1.6.2 yamt /* $NetBSD: ebh_media.h,v 1.1.6.2 2012/04/17 00:08:55 yamt Exp $ */
2 1.1.6.2 yamt
3 1.1.6.2 yamt /*-
4 1.1.6.2 yamt * Copyright (c) 2010 Department of Software Engineering,
5 1.1.6.2 yamt * University of Szeged, Hungary
6 1.1.6.2 yamt * Copyright (C) 2009 Ferenc Havasi <havasi (at) inf.u-szeged.hu>
7 1.1.6.2 yamt * Copyright (C) 2009 Zoltan Sogor <weth (at) inf.u-szeged.hu>
8 1.1.6.2 yamt * Copyright (C) 2009 David Tengeri <dtengeri (at) inf.u-szeged.hu>
9 1.1.6.2 yamt * Copyright (C) 2010 Adam Hoka <ahoka (at) NetBSD.org>
10 1.1.6.2 yamt * All rights reserved.
11 1.1.6.2 yamt *
12 1.1.6.2 yamt * This code is derived from software contributed to The NetBSD Foundation
13 1.1.6.2 yamt * by the Department of Software Engineering, University of Szeged, Hungary
14 1.1.6.2 yamt *
15 1.1.6.2 yamt * Redistribution and use in source and binary forms, with or without
16 1.1.6.2 yamt * modification, are permitted provided that the following conditions
17 1.1.6.2 yamt * are met:
18 1.1.6.2 yamt * 1. Redistributions of source code must retain the above copyright
19 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer.
20 1.1.6.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
21 1.1.6.2 yamt * notice, this list of conditions and the following disclaimer in the
22 1.1.6.2 yamt * documentation and/or other materials provided with the distribution.
23 1.1.6.2 yamt *
24 1.1.6.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 1.1.6.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.1.6.2 yamt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.1.6.2 yamt * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.1.6.2 yamt * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 1.1.6.2 yamt * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 1.1.6.2 yamt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
31 1.1.6.2 yamt * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 1.1.6.2 yamt * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1.6.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1.6.2 yamt * SUCH DAMAGE.
35 1.1.6.2 yamt */
36 1.1.6.2 yamt
37 1.1.6.2 yamt #ifndef EBH_MEDIA_H_
38 1.1.6.2 yamt #define EBH_MEDIA_H_
39 1.1.6.2 yamt
40 1.1.6.2 yamt #ifndef _LE_TYPES
41 1.1.6.2 yamt #define _LE_TYPES
42 1.1.6.2 yamt typedef uint16_t le16;
43 1.1.6.2 yamt typedef uint32_t le32;
44 1.1.6.2 yamt typedef uint64_t le64;
45 1.1.6.2 yamt #endif
46 1.1.6.2 yamt
47 1.1.6.2 yamt /*****************************************************************************/
48 1.1.6.2 yamt /* EBH specific structures */
49 1.1.6.2 yamt /*****************************************************************************/
50 1.1.6.2 yamt #define CHFS_MAGIC_BITMASK 0x53454452
51 1.1.6.2 yamt
52 1.1.6.2 yamt #define CHFS_LID_NOT_DIRTY_BIT 0x80000000
53 1.1.6.2 yamt #define CHFS_LID_DIRTY_BIT_MASK 0x7fffffff
54 1.1.6.2 yamt
55 1.1.6.2 yamt /* sizeof(crc) + sizeof(lid) */
56 1.1.6.2 yamt #define CHFS_INVALIDATE_SIZE 8
57 1.1.6.2 yamt
58 1.1.6.2 yamt /* Size of magic + crc_ec + erase_cnt */
59 1.1.6.2 yamt #define CHFS_EB_EC_HDR_SIZE sizeof(struct chfs_eb_ec_hdr)
60 1.1.6.2 yamt /* Size of NOR eraseblock header */
61 1.1.6.2 yamt #define CHFS_EB_HDR_NOR_SIZE sizeof(struct chfs_nor_eb_hdr)
62 1.1.6.2 yamt /* Size of NAND eraseblock header */
63 1.1.6.2 yamt #define CHFS_EB_HDR_NAND_SIZE sizeof(struct chfs_nand_eb_hdr)
64 1.1.6.2 yamt
65 1.1.6.2 yamt /*
66 1.1.6.2 yamt * chfs_eb_ec_hdr - erase counter header of eraseblock
67 1.1.6.2 yamt * @magic: filesystem magic
68 1.1.6.2 yamt * @crc_ec: CRC32 sum of erase counter
69 1.1.6.2 yamt * @erase_cnt: erase counter
70 1.1.6.2 yamt *
71 1.1.6.2 yamt * This structure holds the erasablock description information.
72 1.1.6.2 yamt * This will be written to the beginning of the eraseblock.
73 1.1.6.2 yamt *
74 1.1.6.2 yamt */
75 1.1.6.2 yamt struct chfs_eb_ec_hdr {
76 1.1.6.2 yamt le32 magic;
77 1.1.6.2 yamt le32 crc_ec;
78 1.1.6.2 yamt le32 erase_cnt;
79 1.1.6.2 yamt } __packed;
80 1.1.6.2 yamt
81 1.1.6.2 yamt /**
82 1.1.6.2 yamt * struct chfs_nor_eb_hdr - eraseblock header on NOR flash
83 1.1.6.2 yamt * @crc: CRC32 sum
84 1.1.6.2 yamt * @lid: logical identifier
85 1.1.6.2 yamt *
86 1.1.6.2 yamt * @lid contains the logical block reference but only the first 31 bit (0-30) is
87 1.1.6.2 yamt * used. The 32th bit is for marking a lid dirty (marked for recovery purposes).
88 1.1.6.2 yamt * If a new eraseblock is succesfully assigned with the same lid then the lid of
89 1.1.6.2 yamt * the old one is zeroed. If power failure happened during this operation then
90 1.1.6.2 yamt * the recovery detects that there is two eraseblock with the same lid, but one
91 1.1.6.2 yamt * of them is marked (the old one).
92 1.1.6.2 yamt *
93 1.1.6.2 yamt * Invalidated eraseblock header means that the @crc and @lid is set to 0.
94 1.1.6.2 yamt */
95 1.1.6.2 yamt struct chfs_nor_eb_hdr {
96 1.1.6.2 yamt le32 crc;
97 1.1.6.2 yamt le32 lid;
98 1.1.6.2 yamt } __packed;
99 1.1.6.2 yamt
100 1.1.6.2 yamt /**
101 1.1.6.2 yamt * struct chfs_nand_eb_hdr - eraseblock header on NAND flash
102 1.1.6.2 yamt * @crc: CRC32 sum
103 1.1.6.2 yamt * @lid: logical identifier
104 1.1.6.2 yamt * @serial: layout of the lid
105 1.1.6.2 yamt *
106 1.1.6.2 yamt * @serial is an unique number. Every eraseblock header on NAND flash has its
107 1.1.6.2 yamt * own serial. If there are two eraseblock on the flash referencing to the same
108 1.1.6.2 yamt * logical eraseblock, the one with bigger serial is the newer.
109 1.1.6.2 yamt */
110 1.1.6.2 yamt struct chfs_nand_eb_hdr {
111 1.1.6.2 yamt le32 crc;
112 1.1.6.2 yamt le32 lid;
113 1.1.6.2 yamt le64 serial;
114 1.1.6.2 yamt } __packed;
115 1.1.6.2 yamt
116 1.1.6.2 yamt #endif /* EBH_MEDIA_H_ */
117