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