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