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