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