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