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)  

fat16.c
Go to the documentation of this file.
1 
18 #include <stdio.h>
19 #include <string.h>
20 
21 #include "file.h"
22 #include "fat16.h"
23 
24 int is_fat_16_fs(FILE *fp)
25 {
26  char *szMagic = "FAT16 ";
27 
28  return contains_data(fp, 0x36, szMagic, strlen(szMagic));
29 } /* is_fat_16_fs */
30 
31 int is_fat_16_br(FILE *fp)
32 {
33  /* A "file" is probably some kind of FAT16 boot record if it contains the
34  magic chars 0x55, 0xAA at positions 0x1FE */
35  unsigned char aucRef[] = {0x55, 0xAA};
36  unsigned char aucMagic[] = {'M','S','W','I','N','4','.','1'};
37 
38  if( ! contains_data(fp, 0x1FE, aucRef, sizeof(aucRef)))
39  return 0;
40  if( ! contains_data(fp, 0x03, aucMagic, sizeof(aucMagic)))
41  return 0;
42  return 1;
43 } /* is_fat_16_br */
44 
46 {
47  #include "br_fat16_0x0.h"
48  #include "br_fat16_0x3e.h"
49 
50  return
51  ( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
52  /* BIOS Parameter Block might differ between systems */
53  contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
54 } /* entire_fat_16_br_matches */
55 
56 int write_fat_16_br(FILE *fp, int bKeepLabel)
57 {
58  #include "label_11_char.h"
59  #include "br_fat16_0x0.h"
60  #include "br_fat16_0x3e.h"
61 
62  if(bKeepLabel)
63  return
64  ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
65  /* BIOS Parameter Block should not be overwritten */
66  write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
67  else
68  return
69  ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
70  /* BIOS Parameter Block should not be overwritten */
71  write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) &&
72  write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
73 } /* write_fat_16_br */
74 
76 {
77  #include "br_fat16_0x0.h"
78  #include "br_fat16fd_0x3e.h"
79 
80  return
81  ( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
82  /* BIOS Parameter Block might differ between systems */
83  contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
84 } /* entire_fat_16_fd_br_matches */
85 
86 int write_fat_16_fd_br(FILE *fp, int bKeepLabel)
87 {
88  #include "label_11_char.h"
89  #include "br_fat16_0x0.h"
90  #include "br_fat16fd_0x3e.h"
91 
92  if(bKeepLabel)
93  return
94  ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
95  /* BIOS Parameter Block should not be overwritten */
96  write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
97  else
98  return
99  ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
100  /* BIOS Parameter Block should not be overwritten */
101  write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) &&
102  write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
103 } /* write_fat_16_fd_br */
104 
106 {
107  #include "br_fat16ros_0x0.h"
108  #include "br_fat16ros_0x3e.h"
109 
110  return
111  ( contains_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
112  /* BIOS Parameter Block might differ between systems */
113  contains_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
114 } /* entire_fat_16_ros_br_matches */
115 
116 int write_fat_16_ros_br(FILE *fp, int bKeepLabel)
117 {
118  #include "label_11_char.h"
119  #include "br_fat16ros_0x0.h"
120  #include "br_fat16ros_0x3e.h"
121 
122  if(bKeepLabel)
123  return
124  ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
125  /* BIOS Parameter Block should not be overwritten */
126  write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
127  else
128  return
129  ( write_data(fp, 0x0, br_fat16_0x0, sizeof(br_fat16_0x0)) &&
130  /* BIOS Parameter Block should not be overwritten */
131  write_data(fp, 0x2b, label_11_char, sizeof(label_11_char)) &&
132  write_data(fp, 0x3e, br_fat16_0x3e, sizeof(br_fat16_0x3e)) );
133 } /* write_fat_16_ros_br */
write_data
int write_data(FILE *fp, unsigned long ulPosition, const void *pData, unsigned int uiLen)
Definition: file.c:78
br_fat16_0x0
unsigned char br_fat16_0x0[]
Definition: br_fat16_0x0.h:1
label_11_char.h
entire_fat_16_fd_br_matches
int entire_fat_16_fd_br_matches(FILE *fp)
Definition: fat16.c:75
br_fat16_0x3e.h
contains_data
int contains_data(FILE *fp, unsigned long ulPosition, const void *pData, unsigned int uiLen)
Definition: file.c:29
is_fat_16_fs
int is_fat_16_fs(FILE *fp)
Definition: fat16.c:24
is_fat_16_br
int is_fat_16_br(FILE *fp)
Definition: fat16.c:31
write_fat_16_ros_br
int write_fat_16_ros_br(FILE *fp, int bKeepLabel)
Definition: fat16.c:116
br_fat16ros_0x0.h
fat16.h
br_fat16_0x0.h
write_fat_16_br
int write_fat_16_br(FILE *fp, int bKeepLabel)
Definition: fat16.c:56
br_fat16_0x3e
unsigned char br_fat16_0x3e[]
Definition: br_fat16_0x3e.h:1
br_fat16ros_0x3e.h
br_fat16fd_0x3e.h
write_fat_16_fd_br
int write_fat_16_fd_br(FILE *fp, int bKeepLabel)
Definition: fat16.c:86
file.h
entire_fat_16_br_matches
int entire_fat_16_br_matches(FILE *fp)
Definition: fat16.c:45
entire_fat_16_ros_br_matches
int entire_fat_16_ros_br_matches(FILE *fp)
Definition: fat16.c:105
label_11_char
unsigned char label_11_char[]
Definition: label_11_char.h:1