media.h revision 1.1.6.3 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.3 yamt #endif /* _LE_TYPES */
44 1.1.6.2 yamt
45 1.1.6.3 yamt /* node types */
46 1.1.6.2 yamt enum {
47 1.1.6.3 yamt CHFS_NODETYPE_VNODE = 1, /* vnode information */
48 1.1.6.3 yamt CHFS_NODETYPE_DATA, /* data node */
49 1.1.6.3 yamt CHFS_NODETYPE_DIRENT, /* directory enrty */
50 1.1.6.3 yamt CHFS_NODETYPE_PADDING, /* padding node */
51 1.1.6.2 yamt };
52 1.1.6.2 yamt
53 1.1.6.2 yamt #define CHFS_NODE_HDR_SIZE sizeof(struct chfs_flash_node_hdr)
54 1.1.6.2 yamt
55 1.1.6.3 yamt /*
56 1.1.6.3 yamt * Max size we have to read to get all info.
57 1.1.6.2 yamt * It is max size of chfs_flash_dirent_node with max name length.
58 1.1.6.2 yamt */
59 1.1.6.2 yamt #define CHFS_MAX_NODE_SIZE 299
60 1.1.6.2 yamt
61 1.1.6.2 yamt /* This will identify CHfs nodes */
62 1.1.6.2 yamt #define CHFS_FS_MAGIC_BITMASK 0x4AF1
63 1.1.6.2 yamt
64 1.1.6.3 yamt /*
65 1.1.6.3 yamt * struct chfs_flash_node_hdr -
66 1.1.6.3 yamt * node header, its members are same for all nodes, used at scan
67 1.1.6.2 yamt */
68 1.1.6.2 yamt struct chfs_flash_node_hdr
69 1.1.6.2 yamt {
70 1.1.6.3 yamt le16 magic; /* filesystem magic */
71 1.1.6.3 yamt le16 type; /* node type */
72 1.1.6.3 yamt le32 length; /* length of node */
73 1.1.6.3 yamt le32 hdr_crc; /* crc of the first 3 fields */
74 1.1.6.2 yamt } __packed;
75 1.1.6.2 yamt
76 1.1.6.3 yamt /* struct chfs_flash_vnode - vnode informations stored on flash */
77 1.1.6.2 yamt struct chfs_flash_vnode
78 1.1.6.2 yamt {
79 1.1.6.3 yamt le16 magic; /* filesystem magic */
80 1.1.6.3 yamt le16 type; /* node type (should be CHFS_NODETYPE_VNODE) */
81 1.1.6.3 yamt le32 length; /* length of node */
82 1.1.6.3 yamt le32 hdr_crc; /* crc of the first 3 fields */
83 1.1.6.3 yamt le64 vno; /* vnode number */
84 1.1.6.3 yamt le64 version; /* version of node */
85 1.1.6.3 yamt le32 uid; /* owner of file */
86 1.1.6.3 yamt le32 gid; /* group of file */
87 1.1.6.3 yamt le32 mode; /* permission of vnode */
88 1.1.6.3 yamt le32 dn_size; /* size of written data */
89 1.1.6.3 yamt le32 atime; /* last access time */
90 1.1.6.3 yamt le32 mtime; /* last modification time */
91 1.1.6.3 yamt le32 ctime; /* change time */
92 1.1.6.3 yamt le32 dsize; /* NOT USED, backward compatibility */
93 1.1.6.3 yamt le32 node_crc; /* crc of all the previous fields */
94 1.1.6.2 yamt } __packed;
95 1.1.6.2 yamt
96 1.1.6.3 yamt /* struct chfs_flash_data_node - data stored on flash */
97 1.1.6.2 yamt struct chfs_flash_data_node
98 1.1.6.2 yamt {
99 1.1.6.3 yamt le16 magic; /* filesystem magic */
100 1.1.6.3 yamt le16 type; /* node type (should be CHFS_NODETYPE_DATA) */
101 1.1.6.3 yamt le32 length; /* length of vnode with data */
102 1.1.6.3 yamt le32 hdr_crc; /* crc of the first 3 fields */
103 1.1.6.3 yamt le64 vno; /* vnode number */
104 1.1.6.3 yamt le64 version; /* version of node */
105 1.1.6.3 yamt le64 offset; /* offset in the file */
106 1.1.6.3 yamt le32 data_length; /* length of data */
107 1.1.6.3 yamt le32 data_crc; /* crc of data*/
108 1.1.6.3 yamt le32 node_crc; /* crc of full node */
109 1.1.6.3 yamt uint8_t data[0]; /* data */
110 1.1.6.2 yamt } __packed;
111 1.1.6.2 yamt
112 1.1.6.3 yamt /*
113 1.1.6.3 yamt * struct chfs_flash_dirent_node -
114 1.1.6.3 yamt * directory entry information stored on flash
115 1.1.6.2 yamt */
116 1.1.6.2 yamt struct chfs_flash_dirent_node
117 1.1.6.2 yamt {
118 1.1.6.3 yamt le16 magic; /* filesystem magic */
119 1.1.6.3 yamt le16 type; /* node type (should be CHFS_NODETYPE_DIRENT) */
120 1.1.6.3 yamt le32 length; /* length of node with name */
121 1.1.6.3 yamt le32 hdr_crc; /* crc of the first 3 fields */
122 1.1.6.3 yamt le64 vno; /* vnode number */
123 1.1.6.3 yamt le64 pvno; /* parent's vnode number */
124 1.1.6.3 yamt le64 version; /* version of node */
125 1.1.6.3 yamt le32 mctime; /* */
126 1.1.6.3 yamt uint8_t nsize; /* length of name */
127 1.1.6.3 yamt uint8_t dtype; /* file type */
128 1.1.6.3 yamt uint8_t unused[2]; /* just for padding */
129 1.1.6.3 yamt le32 name_crc; /* crc of name */
130 1.1.6.3 yamt le32 node_crc; /* crc of full node */
131 1.1.6.3 yamt uint8_t name[0]; /* name of directory entry */
132 1.1.6.2 yamt } __packed;
133 1.1.6.2 yamt
134 1.1.6.3 yamt /* struct chfs_flash_padding_node - spaceholder node on flash */
135 1.1.6.2 yamt struct chfs_flash_padding_node
136 1.1.6.2 yamt {
137 1.1.6.3 yamt le16 magic; /* filesystem magic */
138 1.1.6.3 yamt le16 type; /* node type (should be CHFS_NODETYPE_PADDING )*/
139 1.1.6.3 yamt le32 length; /* length of node */
140 1.1.6.3 yamt le32 hdr_crc; /* crc of the first 3 fields */
141 1.1.6.2 yamt } __packed;
142 1.1.6.2 yamt
143 1.1.6.2 yamt #endif /* __CHFS_MEDIA_H__ */
144