Home | History | Annotate | Line # | Download | only in chfs
      1  1.1   ahoka /*-
      2  1.1   ahoka  * Copyright (c) 2010 Department of Software Engineering,
      3  1.1   ahoka  *		      University of Szeged, Hungary
      4  1.1   ahoka  * Copyright (C) 2009 Ferenc Havasi <havasi (at) inf.u-szeged.hu>
      5  1.1   ahoka  * Copyright (C) 2009 Zoltan Sogor <weth (at) inf.u-szeged.hu>
      6  1.1   ahoka  * Copyright (C) 2009 David Tengeri <dtengeri (at) inf.u-szeged.hu>
      7  1.1   ahoka  * Copyright (C) 2010 Adam Hoka <ahoka (at) NetBSD.org>
      8  1.1   ahoka  * All rights reserved.
      9  1.1   ahoka  *
     10  1.1   ahoka  * This code is derived from software contributed to The NetBSD Foundation
     11  1.1   ahoka  * by the Department of Software Engineering, University of Szeged, Hungary
     12  1.1   ahoka  *
     13  1.1   ahoka  * Redistribution and use in source and binary forms, with or without
     14  1.1   ahoka  * modification, are permitted provided that the following conditions
     15  1.1   ahoka  * are met:
     16  1.1   ahoka  * 1. Redistributions of source code must retain the above copyright
     17  1.1   ahoka  *    notice, this list of conditions and the following disclaimer.
     18  1.1   ahoka  * 2. Redistributions in binary form must reproduce the above copyright
     19  1.1   ahoka  *    notice, this list of conditions and the following disclaimer in the
     20  1.1   ahoka  *    documentation and/or other materials provided with the distribution.
     21  1.1   ahoka  *
     22  1.1   ahoka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.1   ahoka  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.1   ahoka  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.1   ahoka  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.1   ahoka  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     27  1.1   ahoka  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     28  1.1   ahoka  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     29  1.1   ahoka  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     30  1.1   ahoka  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1   ahoka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1   ahoka  * SUCH DAMAGE.
     33  1.1   ahoka  */
     34  1.1   ahoka 
     35  1.1   ahoka #ifndef __CHFS_MEDIA_H__
     36  1.1   ahoka #define __CHFS_MEDIA_H__
     37  1.1   ahoka 
     38  1.1   ahoka #ifndef _LE_TYPES
     39  1.1   ahoka #define _LE_TYPES
     40  1.1   ahoka typedef uint16_t le16;
     41  1.1   ahoka typedef uint32_t le32;
     42  1.1   ahoka typedef uint64_t le64;
     43  1.2   ttoth #endif	/* _LE_TYPES */
     44  1.1   ahoka 
     45  1.2   ttoth /* node types */
     46  1.1   ahoka enum {
     47  1.2   ttoth 	CHFS_NODETYPE_VNODE = 1,	/* vnode information */
     48  1.2   ttoth 	CHFS_NODETYPE_DATA,			/* data node */
     49  1.3  andvar 	CHFS_NODETYPE_DIRENT,		/* directory entry */
     50  1.2   ttoth 	CHFS_NODETYPE_PADDING,		/* padding node */
     51  1.1   ahoka };
     52  1.1   ahoka 
     53  1.1   ahoka #define CHFS_NODE_HDR_SIZE sizeof(struct chfs_flash_node_hdr)
     54  1.1   ahoka 
     55  1.2   ttoth /*
     56  1.2   ttoth  * Max size we have to read to get all info.
     57  1.1   ahoka  * It is max size of chfs_flash_dirent_node with max name length.
     58  1.1   ahoka  */
     59  1.1   ahoka #define CHFS_MAX_NODE_SIZE 299
     60  1.1   ahoka 
     61  1.1   ahoka /* This will identify CHfs nodes */
     62  1.1   ahoka #define CHFS_FS_MAGIC_BITMASK 0x4AF1
     63  1.1   ahoka 
     64  1.2   ttoth /*
     65  1.2   ttoth  * struct chfs_flash_node_hdr -
     66  1.2   ttoth  * node header, its members are same for all nodes, used at scan
     67  1.1   ahoka  */
     68  1.1   ahoka struct chfs_flash_node_hdr
     69  1.1   ahoka {
     70  1.2   ttoth 	le16 magic;		/* filesystem magic */
     71  1.2   ttoth 	le16 type;		/* node type */
     72  1.2   ttoth 	le32 length;	/* length of node */
     73  1.2   ttoth 	le32 hdr_crc;	/* crc of the first 3 fields */
     74  1.1   ahoka } __packed;
     75  1.1   ahoka 
     76  1.2   ttoth /* struct chfs_flash_vnode - vnode informations stored on flash */
     77  1.1   ahoka struct chfs_flash_vnode
     78  1.1   ahoka {
     79  1.2   ttoth 	le16 magic;		/* filesystem magic */
     80  1.2   ttoth 	le16 type;		/* node type (should be CHFS_NODETYPE_VNODE) */
     81  1.2   ttoth 	le32 length;	/* length of node */
     82  1.2   ttoth 	le32 hdr_crc;	/* crc of the first 3 fields  */
     83  1.2   ttoth 	le64 vno;		/* vnode number */
     84  1.2   ttoth 	le64 version;	/* version of node */
     85  1.2   ttoth 	le32 uid;		/* owner of file */
     86  1.2   ttoth 	le32 gid;		/* group of file */
     87  1.2   ttoth 	le32 mode;		/* permission of vnode */
     88  1.2   ttoth 	le32 dn_size;	/* size of written data */
     89  1.2   ttoth 	le32 atime;		/* last access time */
     90  1.2   ttoth 	le32 mtime;		/* last modification time */
     91  1.2   ttoth 	le32 ctime;		/* change time */
     92  1.2   ttoth 	le32 dsize;		/* NOT USED, backward compatibility */
     93  1.2   ttoth 	le32 node_crc;	/* crc of all the previous fields */
     94  1.1   ahoka } __packed;
     95  1.1   ahoka 
     96  1.2   ttoth /* struct chfs_flash_data_node - data stored on flash */
     97  1.1   ahoka struct chfs_flash_data_node
     98  1.1   ahoka {
     99  1.2   ttoth 	le16 magic;			/* filesystem magic */
    100  1.2   ttoth 	le16 type;			/* node type (should be CHFS_NODETYPE_DATA) */
    101  1.2   ttoth 	le32 length;		/* length of vnode with data */
    102  1.2   ttoth 	le32 hdr_crc;		/* crc of the first 3 fields */
    103  1.2   ttoth 	le64 vno;			/* vnode number */
    104  1.2   ttoth 	le64 version;		/* version of node */
    105  1.2   ttoth 	le64 offset;		/* offset in the file */
    106  1.2   ttoth 	le32 data_length;	/* length of data */
    107  1.2   ttoth 	le32 data_crc;		/* crc of data*/
    108  1.2   ttoth 	le32 node_crc;		/* crc of full node */
    109  1.2   ttoth 	uint8_t  data[0];	/* data */
    110  1.1   ahoka } __packed;
    111  1.1   ahoka 
    112  1.2   ttoth /*
    113  1.2   ttoth  * struct chfs_flash_dirent_node -
    114  1.2   ttoth  * directory entry information stored on flash
    115  1.1   ahoka  */
    116  1.1   ahoka struct chfs_flash_dirent_node
    117  1.1   ahoka {
    118  1.2   ttoth 	le16 magic;			/* filesystem magic */
    119  1.2   ttoth 	le16 type;			/* node type (should be CHFS_NODETYPE_DIRENT) */
    120  1.2   ttoth 	le32 length;		/* length of node with name */
    121  1.2   ttoth 	le32 hdr_crc;		/* crc of the first 3 fields */
    122  1.2   ttoth 	le64 vno;			/* vnode number */
    123  1.2   ttoth 	le64 pvno;			/* parent's vnode number */
    124  1.2   ttoth 	le64 version;		/* version of node */
    125  1.2   ttoth 	le32 mctime;		/* */
    126  1.2   ttoth 	uint8_t nsize;		/* length of name */
    127  1.2   ttoth 	uint8_t dtype;		/* file type */
    128  1.2   ttoth 	uint8_t unused[2];	/* just for padding */
    129  1.2   ttoth 	le32 name_crc;		/* crc of name */
    130  1.2   ttoth 	le32 node_crc;		/* crc of full node */
    131  1.2   ttoth 	uint8_t  name[0];	/* name of directory entry */
    132  1.1   ahoka } __packed;
    133  1.1   ahoka 
    134  1.2   ttoth /* struct chfs_flash_padding_node - spaceholder node on flash */
    135  1.1   ahoka struct chfs_flash_padding_node
    136  1.1   ahoka {
    137  1.2   ttoth 	le16 magic;		/* filesystem magic */
    138  1.2   ttoth 	le16 type;		/* node type (should be CHFS_NODETYPE_PADDING )*/
    139  1.2   ttoth 	le32 length;	/* length of node */
    140  1.2   ttoth 	le32 hdr_crc;	/* crc of the first 3 fields */
    141  1.1   ahoka } __packed;
    142  1.1   ahoka 
    143  1.1   ahoka #endif /* __CHFS_MEDIA_H__ */
    144