1 | /*
|
---|
2 | * Copyright (c) 2011 Maurizio Lombardi
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup fs
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 |
|
---|
33 | #ifndef _MINIX_FS_H_
|
---|
34 | #define _MINIX_FS_H_
|
---|
35 |
|
---|
36 | #include <sys/types.h>
|
---|
37 |
|
---|
38 | #define MFS_MAX_BLOCK_SIZE 4096
|
---|
39 | #define MFS_MIN_BLOCK_SIZE 1024
|
---|
40 |
|
---|
41 | #define MFS_ROOT_INO 1
|
---|
42 | #define MFS_SUPER_BLOCK 0
|
---|
43 | #define MFS_SUPER_BLOCK_SIZE 1024
|
---|
44 |
|
---|
45 | #define V2_NR_DIRECT_ZONES 7
|
---|
46 | #define V2_NR_INDIRECT_ZONES 3
|
---|
47 |
|
---|
48 | #define V1_NR_DIRECT_ZONES 7
|
---|
49 | #define V1_NR_INDIRECT_ZONES 2
|
---|
50 |
|
---|
51 | #define MFS_MAX_NAME_LEN 14
|
---|
52 | #define MFS_L_MAX_NAME_LEN 30
|
---|
53 | #define MFS3_MAX_NAME_LEN 60
|
---|
54 |
|
---|
55 | #define MFS_MAGIC_V1 0x137F
|
---|
56 | #define MFS_MAGIC_V1R 0x7F13
|
---|
57 |
|
---|
58 | #define MFS_MAGIC_V1L 0x138F
|
---|
59 | #define MFS_MAGIC_V1LR 0x8F13
|
---|
60 |
|
---|
61 | #define MFS_MAGIC_V2 0x2468
|
---|
62 | #define MFS_MAGIC_V2R 0x6824
|
---|
63 |
|
---|
64 | #define MFS_MAGIC_V2L 0x2478
|
---|
65 | #define MFS_MAGIC_V2LR 0x7824
|
---|
66 |
|
---|
67 | #define MFS_MAGIC_V3 0x4D5A
|
---|
68 | #define MFS_MAGIC_V3R 0x5A4D
|
---|
69 |
|
---|
70 | /*MFS V1/V2 superblock data on disk*/
|
---|
71 | struct mfs_superblock {
|
---|
72 | /*Total number of inodes on the device*/
|
---|
73 | uint16_t s_ninodes;
|
---|
74 | /*Total number of zones on the device*/
|
---|
75 | uint16_t s_nzones;
|
---|
76 | /*Number of inode bitmap blocks*/
|
---|
77 | uint16_t s_ibmap_blocks;
|
---|
78 | /*Number of zone bitmap blocks*/
|
---|
79 | uint16_t s_zbmap_blocks;
|
---|
80 | /*First data zone on device*/
|
---|
81 | uint16_t s_first_data_zone;
|
---|
82 | /*Base 2 logarithm of the zone to block ratio*/
|
---|
83 | uint16_t s_log2_zone_size;
|
---|
84 | /*Maximum file size expressed in bytes*/
|
---|
85 | uint32_t s_max_file_size;
|
---|
86 | /*
|
---|
87 | *Magic number used to recognize MinixFS
|
---|
88 | *and to detect on-disk endianness
|
---|
89 | */
|
---|
90 | uint16_t s_magic;
|
---|
91 | /*Flag used to detect FS errors*/
|
---|
92 | uint16_t s_state;
|
---|
93 | /*Total number of zones on the device (V2 only)*/
|
---|
94 | uint32_t s_nzones2;
|
---|
95 | } __attribute__ ((packed));
|
---|
96 |
|
---|
97 |
|
---|
98 | /*MFS V3 superblock data on disk*/
|
---|
99 | struct mfs3_superblock {
|
---|
100 | /*Total number of inodes on the device*/
|
---|
101 | uint32_t s_ninodes;
|
---|
102 | /*Number of inode bitmap blocks*/
|
---|
103 | int16_t s_ibmap_blocks;
|
---|
104 | /*Number of zone bitmap blocks*/
|
---|
105 | int16_t s_zbmap_blocks;
|
---|
106 | /*First data zone on device*/
|
---|
107 | uint16_t s_first_data_zone;
|
---|
108 | /*Base 2 logarithm of the zone to block ratio*/
|
---|
109 | int16_t s_log2_zone_size;
|
---|
110 | int16_t s_pad;
|
---|
111 | /*Maximum file size expressed in bytes*/
|
---|
112 | int32_t s_max_file_size;
|
---|
113 | /*Total number of zones on the device*/
|
---|
114 | uint32_t s_total_zones;
|
---|
115 | /*
|
---|
116 | *Magic number used to recognize MinixFS
|
---|
117 | *and to detect on-disk endianness
|
---|
118 | */
|
---|
119 | int16_t s_magic;
|
---|
120 | int16_t s_pad2;
|
---|
121 | /*Filesystem block size expressed in bytes*/
|
---|
122 | uint16_t s_block_size;
|
---|
123 | /*Filesystem disk format version*/
|
---|
124 | int8_t s_disk_version;
|
---|
125 | } __attribute__ ((packed));
|
---|
126 |
|
---|
127 | /*MinixFS V1 inode structure as it is on disk*/
|
---|
128 | struct mfs_v1_inode {
|
---|
129 | uint16_t i_mode;
|
---|
130 | int16_t i_uid;
|
---|
131 | int32_t i_size;
|
---|
132 | int32_t i_mtime;
|
---|
133 | uint8_t i_gid;
|
---|
134 | uint8_t i_nlinks;
|
---|
135 | /*Block numbers for direct zones*/
|
---|
136 | uint16_t i_dzone[V1_NR_DIRECT_ZONES];
|
---|
137 | /*Block numbers for indirect zones*/
|
---|
138 | uint16_t i_izone[V1_NR_INDIRECT_ZONES];
|
---|
139 | } __attribute__ ((packed));
|
---|
140 |
|
---|
141 | /*MinixFS V2 inode structure as it is on disk.*/
|
---|
142 | struct mfs_v2_inode {
|
---|
143 | uint16_t i_mode;
|
---|
144 | uint16_t i_nlinks;
|
---|
145 | int16_t i_uid;
|
---|
146 | uint16_t i_gid;
|
---|
147 | int32_t i_size;
|
---|
148 | int32_t i_atime;
|
---|
149 | int32_t i_mtime;
|
---|
150 | int32_t i_ctime;
|
---|
151 | /*Block numbers for direct zones*/
|
---|
152 | uint32_t i_dzone[V2_NR_DIRECT_ZONES];
|
---|
153 | /*Block numbers for indirect zones*/
|
---|
154 | uint32_t i_izone[V2_NR_INDIRECT_ZONES];
|
---|
155 | } __attribute__ ((packed));
|
---|
156 |
|
---|
157 | /*MinixFS V1/V2 directory entry on-disk structure*/
|
---|
158 | struct mfs_dentry {
|
---|
159 | uint16_t d_inum;
|
---|
160 | char d_name[MFS_MAX_NAME_LEN];
|
---|
161 | } __attribute__ ((packed));
|
---|
162 |
|
---|
163 | /*MinixFS V1/V2 with 30-char filenames (Linux variant)*/
|
---|
164 | struct mfs_l_dentry {
|
---|
165 | uint16_t d_inum;
|
---|
166 | char d_name[MFS_L_MAX_NAME_LEN];
|
---|
167 | } __attribute__ ((packed));
|
---|
168 |
|
---|
169 | /*MinixFS V3 directory entry on-disk structure*/
|
---|
170 | struct mfs3_dentry {
|
---|
171 | uint32_t d_inum;
|
---|
172 | char d_name[MFS3_MAX_NAME_LEN];
|
---|
173 | } __attribute__ ((packed));
|
---|
174 |
|
---|
175 |
|
---|
176 | #endif
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * @}
|
---|
180 | */
|
---|
181 |
|
---|