-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfatsys.c
executable file
·101 lines (70 loc) · 1.84 KB
/
fatsys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/******************************************************************************
* FATFORMAT *
******************************************************************************/
//#include <fs.h>
#include <stdio.h>
#include <stdlib.h>
void print_usage ()
{
printf("USAGE: fatsys <image file> <boot_sector>\n");
}
int
main (int argc, char* argv[])
{
// TOS_FAT_Device device;
// unsigned int file_size, i;
// unsigned char size[10] = "";
FILE *image_file;
//Variable to be used as the boot sector
FILE *boot_sector;
unsigned int i;
unsigned char* buffer;
// char temp;
// BPB_FAT bpb_fat;
// BPB_FAT16 bpb_fat16;
// BPB_FAT32 bpb_fat32;
if (!(argc == 3))
{
print_usage();
return -1;
}
i=0;
// printf("%s\n\n", argv[2]);
//printf("%c\n", argv[1][0]);
//Variable to be used as the image file
boot_sector = fopen(argv[2], "rb");
image_file = fopen(argv[1], "rb");
buffer = (char*) malloc((unsigned int) 1474560);
for (i = 0; i < 1474560; i++) buffer[i] = '\0';
i = 0;
while (i < 3){
buffer[i] = getc(boot_sector);
i++;
}
//can't fseek since it would zero of the bytes needed
fseek(image_file, 3, SEEK_SET);
while(i < 62){
buffer[i] = getc(image_file);
i++;
}
//seek past place holding zeros in boot loader
fseek(boot_sector, 62, SEEK_SET);
fseek(image_file, 62, SEEK_SET);
//finish off boot sector
while(i< 512){
buffer[i] = getc(boot_sector);
i++;
}
fseek(image_file, 512, SEEK_SET);
while( i < 1474560){
buffer[i] = getc(image_file);
i++;
}
fclose(image_file);
fclose(boot_sector);
image_file=fopen(argv[1],"wb");
fwrite(buffer, 1474560, 1, image_file);
fclose(image_file);
free(buffer);
return 0;
}