1 /*
2  * The file header definition of a sparse Copy-On-Write Disk (COWD) file
3  *
4  * Copyright (C) 2009-2021, Joachim Metz <joachim.metz@gmail.com>
5  *
6  * Refer to AUTHORS for acknowledgements.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #if !defined( _COWD_SPARSE_FILE_HEADER_H )
23 #define _COWD_SPARSE_FILE_HEADER_H
24 
25 #include <common.h>
26 #include <types.h>
27 
28 #if defined( __cplusplus )
29 extern "C" {
30 #endif
31 
32 typedef struct cowd_sparse_file_header cowd_sparse_file_header_t;
33 
34 struct cowd_sparse_file_header
35 {
36 	/* The signature
37 	 * Consists of 4 bytes
38 	 * Contains: "KDMV"
39 	 */
40 	uint8_t signature[ 4 ];
41 
42 	/* The version
43 	 * Consists of 4 bytes
44 	 */
45 	uint8_t version[ 4 ];
46 
47 	/* The flags
48 	 * Consists of 4 bytes
49 	 */
50 	uint8_t flags[ 4 ];
51 
52 	/* The maximum data number of sectors (capacity)
53 	 * Consists of 4 bytes
54 	 * Contains a value in sectors
55 	 */
56 	uint8_t maximum_data_number_of_sectors[ 4 ];
57 
58 	/* The grain number of sectors
59 	 * Consists of 4 bytes
60 	 * Contains a value in sectors
61 	 */
62 	uint8_t grain_number_of_sectors[ 4 ];
63 
64 	/* The primary grain directory sector number
65 	 * Consists of 4 bytes
66 	 * Contains a value in sectors
67 	 */
68 	uint8_t primary_grain_directory_sector_number[ 4 ];
69 
70 	/* The number of grain directory entries
71 	 * Consists of 4 bytes
72 	 */
73 	uint8_t number_of_grain_directory_entries[ 4 ];
74 
75 	/* The next free grain
76 	 * Consists of 4 bytes
77 	 */
78 	uint8_t next_free_grain[ 4 ];
79 
80 	union
81 	{
82 		struct
83 		{
84 			/* The number of cylinders
85 			 * Consists of 4 bytes
86 			 */
87 			uint8_t number_of_cylinders[ 4 ];
88 
89 			/* The number of heads
90 			 * Consists of 4 bytes
91 			 */
92 			uint8_t number_of_heads[ 4 ];
93 
94 			/* The number of sectors
95 			 * Consists of 4 bytes
96 			 */
97 			uint8_t number_of_sectors[ 4 ];
98 		};
99 		struct
100 		{
101 			/* The parent filename
102 			 * Consists of 1024 bytes
103 			 */
104 			uint8_t parent_filename[ 1024 ];
105 
106 			/* The parent generation
107 			 * Consists of 4 bytes
108 			 */
109 			uint8_t parent_generation[ 4 ];
110 
111 		};
112 	};
113 
114 	/* The generation
115 	 * Consists of 4 bytes
116 	 */
117 	uint8_t generation[ 4 ];
118 
119 	/* The name
120 	 * Consists of 60 bytes
121 	 */
122 	uint8_t name[ 60 ];
123 
124 	/* The description
125 	 * Consists of 512 bytes
126 	 */
127 	uint8_t description[ 512 ];
128 
129 	/* The saved generation
130 	 * Consists of 4 bytes
131 	 */
132 	uint8_t saved_generation[ 4 ];
133 
134 	/* Reserved
135 	 * Consists of 8 bytes
136 	 */
137 	uint8_t reserved[ 8 ];
138 
139 	/* Value to indicate the COWD was cleanly closed
140 	 * Consists of 1 byte
141 	 */
142 	uint8_t is_dirty;
143 
144 	/* Padding
145 	 * Consists of 396 bytes
146 	 */
147 	uint8_t padding[ 396 ];
148 };
149 
150 #if defined( __cplusplus )
151 }
152 #endif
153 
154 #endif /* !defined( _COWD_SPARSE_FILE_HEADER_H ) */
155 
156