media.h revision 1.1 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.1 ahoka #endif
44 1.1 ahoka
45 1.1 ahoka /*****************************************************************************/
46 1.1 ahoka /* File system specific structures */
47 1.1 ahoka /*****************************************************************************/
48 1.1 ahoka
49 1.1 ahoka enum {
50 1.1 ahoka CHFS_NODETYPE_VNODE = 1,
51 1.1 ahoka CHFS_NODETYPE_DATA,
52 1.1 ahoka CHFS_NODETYPE_DIRENT,
53 1.1 ahoka CHFS_NODETYPE_PADDING,
54 1.1 ahoka };
55 1.1 ahoka
56 1.1 ahoka //#define CHFS_NODE_HDR_SIZE 12 /* magic + type + length + hdr_crc */
57 1.1 ahoka #define CHFS_NODE_HDR_SIZE sizeof(struct chfs_flash_node_hdr)
58 1.1 ahoka
59 1.1 ahoka /* Max size we have to read to get all info.
60 1.1 ahoka * It is max size of chfs_flash_dirent_node with max name length.
61 1.1 ahoka */
62 1.1 ahoka #define CHFS_MAX_NODE_SIZE 299
63 1.1 ahoka
64 1.1 ahoka /* This will identify CHfs nodes */
65 1.1 ahoka #define CHFS_FS_MAGIC_BITMASK 0x4AF1
66 1.1 ahoka
67 1.1 ahoka /**
68 1.1 ahoka * struct chfs_flash_node_hdr - node header, its members are same for
69 1.1 ahoka * all nodes, used at scan
70 1.1 ahoka * @magic: filesystem magic
71 1.1 ahoka * @type: node type
72 1.1 ahoka * @length: length of node
73 1.1 ahoka * @hdr_crc: crc of the first 3 members
74 1.1 ahoka */
75 1.1 ahoka struct chfs_flash_node_hdr
76 1.1 ahoka {
77 1.1 ahoka le16 magic;
78 1.1 ahoka le16 type;
79 1.1 ahoka le32 length;
80 1.1 ahoka le32 hdr_crc;
81 1.1 ahoka } __packed;
82 1.1 ahoka
83 1.1 ahoka /**
84 1.1 ahoka * struct chfs_flash_vnode - vnode informations stored on flash
85 1.1 ahoka * @magic: filesystem magic
86 1.1 ahoka * @type: node type (CHFS_NODETYPE_VNODE)
87 1.1 ahoka * @length: length of node
88 1.1 ahoka * @hdr_crc: crc of the first 3 members
89 1.1 ahoka * @vno: vnode identifier id
90 1.1 ahoka * @version: vnode's version number
91 1.1 ahoka * @uid: owner of the file
92 1.1 ahoka * @gid: group of file
93 1.1 ahoka * @mode: permissions for vnode
94 1.1 ahoka * @dn_size: size of written out data nodes
95 1.1 ahoka * @atime: last access times
96 1.1 ahoka * @mtime: last modification time
97 1.1 ahoka * @ctime: change time
98 1.1 ahoka * @dsize: size of the node's data
99 1.1 ahoka * @node_crc: crc of full node
100 1.1 ahoka */
101 1.1 ahoka struct chfs_flash_vnode
102 1.1 ahoka {
103 1.1 ahoka le16 magic; /*0 */
104 1.1 ahoka le16 type; /*2 */
105 1.1 ahoka le32 length; /*4 */
106 1.1 ahoka le32 hdr_crc; /*8 */
107 1.1 ahoka le64 vno; /*12*/
108 1.1 ahoka le64 version; /*20*/
109 1.1 ahoka le32 uid; /*28*/
110 1.1 ahoka le32 gid; /*32*/
111 1.1 ahoka le32 mode; /*36*/
112 1.1 ahoka le32 dn_size; /*40*/
113 1.1 ahoka le32 atime; /*44*/
114 1.1 ahoka le32 mtime; /*48*/
115 1.1 ahoka le32 ctime; /*52*/
116 1.1 ahoka le32 dsize; /*56*/
117 1.1 ahoka le32 node_crc; /*60*/
118 1.1 ahoka } __packed;
119 1.1 ahoka
120 1.1 ahoka /**
121 1.1 ahoka * struct chfs_flash_data_node - node informations of data stored on flash
122 1.1 ahoka * @magic: filesystem magic
123 1.1 ahoka * @type: node type (CHFS_NODETYPE_DATA)
124 1.1 ahoka * @length: length of node with data
125 1.1 ahoka * @hdr_crc: crc of the first 3 members
126 1.1 ahoka * @vno: vnode identifier id
127 1.1 ahoka * @version: vnode's version number
128 1.1 ahoka * @offset: offset in the file where write begins
129 1.1 ahoka * @data_length: length of data
130 1.1 ahoka * @data_crc: crc of data
131 1.1 ahoka * @node_crc: crc of full node
132 1.1 ahoka * @data: array of data
133 1.1 ahoka */
134 1.1 ahoka struct chfs_flash_data_node
135 1.1 ahoka {
136 1.1 ahoka le16 magic;
137 1.1 ahoka le16 type;
138 1.1 ahoka le32 length;
139 1.1 ahoka le32 hdr_crc;
140 1.1 ahoka le64 vno;
141 1.1 ahoka le64 version;
142 1.1 ahoka le64 offset;
143 1.1 ahoka le32 data_length;
144 1.1 ahoka le32 data_crc;
145 1.1 ahoka le32 node_crc;
146 1.1 ahoka uint8_t data[0];
147 1.1 ahoka } __packed;
148 1.1 ahoka
149 1.1 ahoka /**
150 1.1 ahoka * struct chfs_flash_dirent_node - vnode informations stored on flash
151 1.1 ahoka * @magic: filesystem magic
152 1.1 ahoka * @type: node type (CHFS_NODETYPE_DIRENT)
153 1.1 ahoka * @length: length of node
154 1.1 ahoka * @hdr_crc: crc of the first 3 members
155 1.1 ahoka * @vno: vnode identifier id
156 1.1 ahoka * @pvno: vnode identifier id of parent vnode
157 1.1 ahoka * @version: vnode's version number
158 1.1 ahoka * @mctime:
159 1.1 ahoka * @nsize: length of name
160 1.1 ahoka * @dtype: file type
161 1.1 ahoka * @unused: just for padding
162 1.1 ahoka * @name_crc: crc of name
163 1.1 ahoka * @node_crc: crc of full node
164 1.1 ahoka * @name: name of the directory entry
165 1.1 ahoka */
166 1.1 ahoka struct chfs_flash_dirent_node
167 1.1 ahoka {
168 1.1 ahoka le16 magic;
169 1.1 ahoka le16 type;
170 1.1 ahoka le32 length;
171 1.1 ahoka le32 hdr_crc;
172 1.1 ahoka le64 vno;
173 1.1 ahoka le64 pvno;
174 1.1 ahoka le64 version;
175 1.1 ahoka le32 mctime;
176 1.1 ahoka uint8_t nsize;
177 1.1 ahoka uint8_t dtype;
178 1.1 ahoka uint8_t unused[2];
179 1.1 ahoka le32 name_crc;
180 1.1 ahoka le32 node_crc;
181 1.1 ahoka uint8_t name[0];
182 1.1 ahoka } __packed;
183 1.1 ahoka
184 1.1 ahoka /**
185 1.1 ahoka * struct chfs_flash_padding_node - node informations of data stored on
186 1.1 ahoka * flash
187 1.1 ahoka * @magic: filesystem magic
188 1.1 ahoka * @type: node type (CHFS_NODETYPE_PADDING)
189 1.1 ahoka * @length: length of node
190 1.1 ahoka * @hdr_crc: crc of the first 3 members
191 1.1 ahoka */
192 1.1 ahoka struct chfs_flash_padding_node
193 1.1 ahoka {
194 1.1 ahoka le16 magic;
195 1.1 ahoka le16 type;
196 1.1 ahoka le32 length;
197 1.1 ahoka le32 hdr_crc;
198 1.1 ahoka } __packed;
199 1.1 ahoka
200 1.1 ahoka #endif /* __CHFS_MEDIA_H__ */
201