ms-sys  2.7.0
About: ms-sys writes Microsoft compatible boot records. Development version.
  Fossies Dox: ms-sys-2.7.0.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

fat32.c
Go to the documentation of this file.
1 
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "file.h"
22 #include "fat32.h"
23 
24 int is_fat_32_fs(FILE *fp)
25 {
26  char *szMagic = "FAT32 ";
27 
28  return contains_data(fp, 0x52, szMagic, strlen(szMagic));
29 } /* is_fat_32_fs */
30 
31 int is_fat_32_br(FILE *fp)
32 {
33  /* A "file" is probably some kind of FAT32 boot record if it contains the
34  magic chars 0x55, 0xAA at positions 0x1FE, 0x3FE and 0x5FE */
35  unsigned char aucRef[] = {0x55, 0xAA};
36  unsigned char aucMagic9x[] = {'M','S','W','I','N','4','.','1'};
37  unsigned char aucMagicNT[] = {'M','S','D','O','S','5','.','0'};
38  int i;
39 
40  for(i=0 ; i<3 ; i++)
41  if( ! contains_data(fp, 0x1FE + i*0x200, aucRef, sizeof(aucRef)))
42  return 0;
43  if(( ! contains_data(fp, 0x03, aucMagic9x, sizeof(aucMagic9x))) &&
44  ( ! contains_data(fp, 0x03, aucMagicNT, sizeof(aucMagicNT))))
45  return 0;
46  return 1;
47 } /* is_fat_32_br */
48 
50 {
51  #include "br_fat32_0x0.h"
52  #include "br_fat32_0x52.h"
53  #include "br_fat32_0x3f0.h"
54 
55  return
56  ( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
57  /* BIOS Parameter Block might differ between systems */
58  contains_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
59  /* Cluster information might differ between systems */
60  contains_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
61 } /* entire_fat_32_br_matches */
62 
63 int write_fat_32_br(FILE *fp, int bKeepLabel)
64 {
65  #include "label_11_char.h"
66  #include "br_fat32_0x0.h"
67  #include "br_fat32_0x52.h"
68  #include "br_fat32_0x3f0.h"
69 
70  if(bKeepLabel)
71  return
72  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
73  /* BIOS Parameter Block should not be overwritten */
74  write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
75  /* Cluster information is not overwritten, however, it would be OK
76  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
77  write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
78  else
79  return
80  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
81  /* BIOS Parameter Block should not be overwritten */
82  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
83  write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
84  /* Cluster information is not overwritten, however, it would be OK
85  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
86  write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
87 } /* write_fat_32_br */
88 
90 {
91  #include "br_fat32_0x0.h"
92  #include "br_fat32fd_0x52.h"
93  #include "br_fat32fd_0x3f0.h"
94 
95  return
96  ( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
97  /* BIOS Parameter Block might differ between systems */
98  contains_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
99  /* Cluster information might differ between systems */
100  contains_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
101 } /* entire_fat_32_fd_br_matches */
102 
103 int write_fat_32_fd_br(FILE *fp, int bKeepLabel)
104 {
105  #include "label_11_char.h"
106  #include "br_fat32_0x0.h"
107  #include "br_fat32fd_0x52.h"
108  #include "br_fat32fd_0x3f0.h"
109 
110  if(bKeepLabel)
111  return
112  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
113  /* BIOS Parameter Block should not be overwritten */
114  write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
115  /* Cluster information is not overwritten, however, it would be OK
116  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
117  write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
118  else
119  return
120  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
121  /* BIOS Parameter Block should not be overwritten */
122  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
123  write_data(fp, 0x52, br_fat32_0x52, sizeof(br_fat32_0x52)) &&
124  /* Cluster information is not overwritten, however, it would be OK
125  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
126  write_data(fp, 0x3f0, br_fat32_0x3f0, sizeof(br_fat32_0x3f0)) );
127 } /* write_fat_32_fd_br */
128 
130 {
131  #include "br_fat32_0x0.h"
132  #include "br_fat32nt5_0x52.h"
133  #include "br_fat32nt5_0x3f0.h"
134  #include "br_fat32nt5_0x1800.h"
135 
136  return
137  ( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
138  /* BIOS Parameter Block might differ between systems */
139  contains_data(fp, 0x52, br_fat32nt5_0x52, sizeof(br_fat32nt5_0x52)) &&
140  /* Cluster information might differ between systems */
141  contains_data(fp, 0x3f0, br_fat32nt5_0x3f0, sizeof(br_fat32nt5_0x3f0)) &&
143  );
144 } /* entire_fat_32_nt5_br_matches */
145 
146 int write_fat_32_nt5_br(FILE *fp, int bKeepLabel)
147 {
148  #include "label_11_char.h"
149  #include "br_fat32_0x0.h"
150  #include "br_fat32nt5_0x52.h"
151  #include "br_fat32nt5_0x3f0.h"
152  #include "br_fat32nt5_0x1800.h"
153 
154  if(bKeepLabel)
155  return
156  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
157  /* BIOS Parameter Block should not be overwritten */
158  write_data(fp, 0x52, br_fat32nt5_0x52, sizeof(br_fat32nt5_0x52)) &&
159  /* Cluster information is not overwritten, however, it would be OK
160  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
161  write_data(fp, 0x3f0, br_fat32nt5_0x3f0, sizeof(br_fat32nt5_0x3f0)) &&
162  write_data(fp, 0x1800, br_fat32nt5_0x1800, sizeof(br_fat32nt5_0x1800))
163  );
164  else
165  return
166  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
167  /* BIOS Parameter Block should not be overwritten */
168  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
169  write_data(fp, 0x52, br_fat32nt5_0x52, sizeof(br_fat32nt5_0x52)) &&
170  /* Cluster information is not overwritten, however, it would be OK
171  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
172  write_data(fp, 0x3f0, br_fat32nt5_0x3f0, sizeof(br_fat32nt5_0x3f0)) &&
173  write_data(fp, 0x1800, br_fat32nt5_0x1800, sizeof(br_fat32nt5_0x1800))
174  );
175 } /* write_fat_32_nt5_br */
176 
178 {
179  #include "br_fat32nt6_0x0.h"
180  #include "br_fat32nt6_0x52.h"
181  #include "br_fat32nt6_0x5fe.h"
182  #include "br_fat32nt6_0x1800.h"
183 
184  return
185  ( contains_data(fp, 0x0, br_fat32nt6_0x0, sizeof(br_fat32nt6_0x0)) &&
186  /* BIOS Parameter Block might differ between systems */
187  contains_data(fp, 0x52, br_fat32nt6_0x52, sizeof(br_fat32nt6_0x52)) &&
188  /* Cluster information might differ between systems */
189  contains_data(fp, 0x5fe, br_fat32nt6_0x5fe, sizeof(br_fat32nt6_0x5fe)) &&
191  );
192 } /* entire_fat_32_nt6_br_matches */
193 
194 int write_fat_32_nt6_br(FILE *fp, int bKeepLabel)
195 {
196  #include "label_11_char.h"
197  #include "br_fat32nt6_0x0.h"
198  #include "br_fat32nt6_0x52.h"
199  #include "br_fat32nt6_0x5fe.h"
200  #include "br_fat32nt6_0x1800.h"
201 
202  if(bKeepLabel)
203  return
204  ( write_data(fp, 0x0, br_fat32nt6_0x0, sizeof(br_fat32nt6_0x0)) &&
205  /* BIOS Parameter Block should not be overwritten */
206  write_data(fp, 0x52, br_fat32nt6_0x52, sizeof(br_fat32nt6_0x52)) &&
207  /* Cluster information is not overwritten, however, it would be OK
208  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
209  write_data(fp, 0x5fe, br_fat32nt6_0x5fe, sizeof(br_fat32nt6_0x5fe)) &&
210  write_data(fp, 0x1800, br_fat32nt6_0x1800, sizeof(br_fat32nt6_0x1800))
211  );
212  else
213  return
214  ( write_data(fp, 0x0, br_fat32nt6_0x0, sizeof(br_fat32nt6_0x0)) &&
215  /* BIOS Parameter Block should not be overwritten */
216  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
217  write_data(fp, 0x52, br_fat32nt6_0x52, sizeof(br_fat32nt6_0x52)) &&
218  /* Cluster information is not overwritten, however, it would be OK
219  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
220  write_data(fp, 0x5fe, br_fat32nt6_0x5fe, sizeof(br_fat32nt6_0x5fe)) &&
221  write_data(fp, 0x1800, br_fat32nt6_0x1800, sizeof(br_fat32nt6_0x1800))
222  );
223 } /* write_fat_32_nt6_br */
224 
226 {
227  #include "br_fat32_0x0.h"
228  #include "br_fat32pe_0x52.h"
229  #include "br_fat32pe_0x3f0.h"
230  #include "br_fat32pe_0x1800.h"
231 
232  return
233  ( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
234  /* BIOS Parameter Block might differ between systems */
235  contains_data(fp, 0x52, br_fat32pe_0x52, sizeof(br_fat32pe_0x52)) &&
236  /* Cluster information might differ between systems */
237  contains_data(fp, 0x3f0, br_fat32pe_0x3f0, sizeof(br_fat32pe_0x3f0)) &&
239  );
240 } /* entire_fat_32_nt_br_matches */
241 
242 int write_fat_32_pe_br(FILE *fp, int bKeepLabel)
243 {
244  #include "label_11_char.h"
245  #include "br_fat32_0x0.h"
246  #include "br_fat32pe_0x52.h"
247  #include "br_fat32pe_0x3f0.h"
248  #include "br_fat32pe_0x1800.h"
249 
250  if(bKeepLabel)
251  return
252  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
253  /* BIOS Parameter Block should not be overwritten */
254  write_data(fp, 0x52, br_fat32pe_0x52, sizeof(br_fat32pe_0x52)) &&
255  /* Cluster information is not overwritten, however, it would bo OK
256  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
257  write_data(fp, 0x3f0, br_fat32pe_0x3f0, sizeof(br_fat32pe_0x3f0)) &&
258  write_data(fp, 0x1800, br_fat32pe_0x1800, sizeof(br_fat32pe_0x1800))
259  );
260  else
261  return
262  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
263  /* BIOS Parameter Block should not be overwritten */
264  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
265  write_data(fp, 0x52, br_fat32pe_0x52, sizeof(br_fat32pe_0x52)) &&
266  /* Cluster information is not overwritten, however, it would bo OK
267  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
268  write_data(fp, 0x3f0, br_fat32pe_0x3f0, sizeof(br_fat32pe_0x3f0)) &&
269  write_data(fp, 0x1800, br_fat32pe_0x1800, sizeof(br_fat32pe_0x1800))
270  );
271 } /* write_fat_32_pe_br */
272 
274 {
275  #include "br_fat32_0x0.h"
276  #include "br_fat32ros_0x52.h"
277  #include "br_fat32ros_0x3f0.h"
278  #include "br_fat32ros_0x1c00.h"
279 
280  return
281  ( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
282  /* BIOS Parameter Block might differ between systems */
283  contains_data(fp, 0x52, br_fat32ros_0x52, sizeof(br_fat32ros_0x52)) &&
284  /* Cluster information might differ between systems */
285  contains_data(fp, 0x3f0, br_fat32ros_0x3f0, sizeof(br_fat32ros_0x3f0)) &&
287  );
288 } /* entire_fat_32_ros_br_matches */
289 
290 /* See http://doxygen.reactos.org/dc/d83/bootsup_8c_source.html#l01596 */
291 int write_fat_32_ros_br(FILE *fp, int bKeepLabel)
292 {
293  #include "label_11_char.h"
294  #include "br_fat32_0x0.h"
295  #include "br_fat32ros_0x52.h"
296  #include "br_fat32ros_0x3f0.h"
297  #include "br_fat32ros_0x1c00.h"
298 
299  if(bKeepLabel)
300  return
301  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
302  /* BIOS Parameter Block should not be overwritten */
303  write_data(fp, 0x52, br_fat32ros_0x52, sizeof(br_fat32ros_0x52)) &&
304  /* Cluster information is not overwritten, however, it would be OK
305  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
306  write_data(fp, 0x3f0, br_fat32ros_0x3f0, sizeof(br_fat32ros_0x3f0)) &&
307  write_data(fp, 0x1c00, br_fat32ros_0x1c00, sizeof(br_fat32ros_0x1c00))
308  );
309  else
310  return
311  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
312  /* BIOS Parameter Block should not be overwritten */
313  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
314  write_data(fp, 0x52, br_fat32ros_0x52, sizeof(br_fat32ros_0x52)) &&
315  /* Cluster information is not overwritten, however, it would be OK
316  to write 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff here. */
317  write_data(fp, 0x3f0, br_fat32ros_0x3f0, sizeof(br_fat32ros_0x3f0)) &&
318  write_data(fp, 0x1c00, br_fat32ros_0x1c00, sizeof(br_fat32ros_0x1c00))
319  );
320 } /* write_fat_32_ros_br */
321 
323 {
324  #include "br_fat32_0x0.h"
325  #include "br_fat32kos_0x52.h"
326 
327  return
328  ( contains_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
329  contains_data(fp, 0x52, br_fat32kos_0x52, sizeof(br_fat32kos_0x52)) );
330 } /* entire_fat_32_kos_br_matches */
331 
332 int write_fat_32_kos_br(FILE *fp, int bKeepLabel)
333 {
334  #include "label_11_char.h"
335  #include "br_fat32_0x0.h"
336  #include "br_fat32kos_0x52.h"
337 
338  if(bKeepLabel)
339  return
340  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
341  write_data(fp, 0x52, br_fat32kos_0x52, sizeof(br_fat32kos_0x52)) );
342  else
343  return
344  ( write_data(fp, 0x0, br_fat32_0x0, sizeof(br_fat32_0x0)) &&
345  write_data(fp, 0x47, label_11_char, sizeof(label_11_char)) &&
346  write_data(fp, 0x52, br_fat32kos_0x52, sizeof(br_fat32kos_0x52)) );
347 } /* write_fat_32_kos_br */
write_data
int write_data(FILE *fp, unsigned long ulPosition, const void *pData, unsigned int uiLen)
Definition: file.c:78
is_fat_32_fs
int is_fat_32_fs(FILE *fp)
Definition: fat32.c:24
br_fat32nt5_0x52.h
br_fat32_0x3f0
unsigned char br_fat32_0x3f0[]
Definition: br_fat32_0x3f0.h:1
br_fat32nt5_0x3f0.h
entire_fat_32_br_matches
int entire_fat_32_br_matches(FILE *fp)
Definition: fat32.c:49
br_fat32nt6_0x52.h
entire_fat_32_kos_br_matches
int entire_fat_32_kos_br_matches(FILE *fp)
Definition: fat32.c:322
br_fat32_0x52.h
write_fat_32_nt5_br
int write_fat_32_nt5_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:146
br_fat32pe_0x52.h
entire_fat_32_ros_br_matches
int entire_fat_32_ros_br_matches(FILE *fp)
Definition: fat32.c:273
br_fat32nt6_0x52
unsigned char br_fat32nt6_0x52[]
Definition: br_fat32nt6_0x52.h:1
write_fat_32_nt6_br
int write_fat_32_nt6_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:194
label_11_char.h
br_fat32nt6_0x1800
unsigned char br_fat32nt6_0x1800[]
Definition: br_fat32nt6_0x1800.h:1
entire_fat_32_pe_br_matches
int entire_fat_32_pe_br_matches(FILE *fp)
Definition: fat32.c:225
br_fat32ros_0x3f0
unsigned char br_fat32ros_0x3f0[]
Definition: br_fat32ros_0x3f0.h:1
br_fat32_0x52
unsigned char br_fat32_0x52[]
Definition: br_fat32_0x52.h:1
entire_fat_32_fd_br_matches
int entire_fat_32_fd_br_matches(FILE *fp)
Definition: fat32.c:89
write_fat_32_pe_br
int write_fat_32_pe_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:242
br_fat32nt5_0x3f0
unsigned char br_fat32nt5_0x3f0[]
Definition: br_fat32nt5_0x3f0.h:1
contains_data
int contains_data(FILE *fp, unsigned long ulPosition, const void *pData, unsigned int uiLen)
Definition: file.c:29
is_fat_32_br
int is_fat_32_br(FILE *fp)
Definition: fat32.c:31
br_fat32kos_0x52.h
br_fat32ros_0x1c00.h
br_fat32ros_0x52
unsigned char br_fat32ros_0x52[]
Definition: br_fat32ros_0x52.h:1
br_fat32nt5_0x52
unsigned char br_fat32nt5_0x52[]
Definition: br_fat32nt5_0x52.h:1
br_fat32_0x3f0.h
br_fat32nt6_0x1800.h
br_fat32pe_0x3f0.h
br_fat32pe_0x1800
unsigned char br_fat32pe_0x1800[]
Definition: br_fat32pe_0x1800.h:1
br_fat32nt5_0x1800
unsigned char br_fat32nt5_0x1800[]
Definition: br_fat32nt5_0x1800.h:1
br_fat32pe_0x3f0
unsigned char br_fat32pe_0x3f0[]
Definition: br_fat32pe_0x3f0.h:1
br_fat32nt6_0x0.h
entire_fat_32_nt5_br_matches
int entire_fat_32_nt5_br_matches(FILE *fp)
Definition: fat32.c:129
br_fat32nt6_0x5fe.h
write_fat_32_br
int write_fat_32_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:63
br_fat32_0x0.h
br_fat32nt6_0x0
unsigned char br_fat32nt6_0x0[]
Definition: br_fat32nt6_0x0.h:1
br_fat32ros_0x3f0.h
br_fat32nt6_0x5fe
unsigned char br_fat32nt6_0x5fe[]
Definition: br_fat32nt6_0x5fe.h:1
write_fat_32_ros_br
int write_fat_32_ros_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:291
br_fat32_0x0
unsigned char br_fat32_0x0[]
Definition: br_fat32_0x0.h:1
br_fat32fd_0x52.h
write_fat_32_fd_br
int write_fat_32_fd_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:103
fat32.h
br_fat32pe_0x1800.h
file.h
br_fat32fd_0x3f0.h
write_fat_32_kos_br
int write_fat_32_kos_br(FILE *fp, int bKeepLabel)
Definition: fat32.c:332
entire_fat_32_nt6_br_matches
int entire_fat_32_nt6_br_matches(FILE *fp)
Definition: fat32.c:177
br_fat32nt5_0x1800.h
br_fat32ros_0x1c00
unsigned char br_fat32ros_0x1c00[]
Definition: br_fat32ros_0x1c00.h:1
br_fat32pe_0x52
unsigned char br_fat32pe_0x52[]
Definition: br_fat32pe_0x52.h:1
br_fat32ros_0x52.h
br_fat32kos_0x52
unsigned char br_fat32kos_0x52[]
Definition: br_fat32kos_0x52.h:1
label_11_char
unsigned char label_11_char[]
Definition: label_11_char.h:1