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