-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall.c
More file actions
113 lines (93 loc) · 2.09 KB
/
install.c
File metadata and controls
113 lines (93 loc) · 2.09 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
/*
* PROJECT: ReactOS FreeLoader installer for Linux
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Installation functions
* COPYRIGHT: Copyright 2001 Brian Palmer (brianp@sginet.com)
* Copyright 2019 Arnav Bhatt (arnavbhatt2004@gmail.com)
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdbool.h>
#include "install.h"
#include "volume.h"
/*
* These includes are required to define
* the fat_data and fat32_data arrays.
*/
#include "fat.h"
#include "fat32.h"
bool InstallBootSector(char* lpszVolumeType);
int main(int argc, char *argv[])
{
if (argc < 3)
{
printf("syntax: install /dev/sdx\nwhere [x] is the letter of drive\n[fs_type]\nwhere fs_type is fat or fat32\n");
return -1;
}
if (!OpenVolume(argv[1]))
{
printf("Exiting program...\n");
return -1;
}
if (!InstallBootSector(argv[2]))
{
printf("Exiting program...\n");
return -1;
}
CloseVolume();
printf("You must now copy freeldr.sys & freeldr.ini to %s.\n", argv[1]);
return 0;
}
bool InstallBootSector(char* lpszVolumeType)
{
unsigned char BootSectorBuffer[512];
if (!ReadVolumeSector(0, BootSectorBuffer))
{
return false;
}
if (strcasecmp(lpszVolumeType, "fat32") == 0)
{
//
// Update the BPB in the new boot sector
//
memcpy((fat32_data+3), (BootSectorBuffer+3), 87 /*fat32 BPB length*/);
//
// Write out new boot sector
//
if (!WriteVolumeSector(0, fat32_data))
{
return false;
}
//
// Write out new extra sector
//
if (!WriteVolumeSector(14, (fat32_data+512)))
{
return false;
}
}
else if (strcasecmp(lpszVolumeType, "fat") == 0)
{
//
// Update the BPB in the new boot sector
//
memcpy((fat_data+3), (BootSectorBuffer+3), 59 /*fat BPB length*/);
//
// Write out new boot sector
//
if (!WriteVolumeSector(0, fat_data))
{
return false;
}
}
else
{
printf("%s:%d: ", __FILE__, __LINE__);
printf("File system type %s unknown.\n", lpszVolumeType);
return false;
}
printf("%s boot sector installed.\n", lpszVolumeType);
return true;
}