Fixed a bug in the LBA extensions detection code.
[reactos.git] / freeldr / freeldr / inifile / init.c
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <freeldr.h>
21 #include "ini.h"
22 #include <ui.h>
23 #include <fs.h>
24 #include <rtl.h>
25 #include <mm.h>
26 #include <debug.h>
27
28
29 BOOL InitializeIniFile(VOID)
30 {
31 PFILE Freeldr_Ini; // File handle for freeldr.ini
32 PUCHAR FreeLoaderIniFileData;
33 ULONG FreeLoaderIniFileSize;
34
35 // Open the boot drive for file access
36 if (!OpenDiskDrive(BootDrive, 0))
37 {
38 printf("Error opening boot drive for file access.\n");
39 return FALSE;
40 }
41
42 // Try to open freeldr.ini or fail
43 Freeldr_Ini = OpenFile("freeldr.ini");
44 if (Freeldr_Ini == NULL)
45 {
46 printf("FREELDR.INI not found.\nYou need to re-install FreeLoader.\n");
47 return FALSE;
48 }
49
50 // Get the file size & allocate enough memory for it
51 FreeLoaderIniFileSize = GetFileSize(Freeldr_Ini);
52 FreeLoaderIniFileData = AllocateMemory(FreeLoaderIniFileSize);
53
54 // If we are out of memory then return FALSE
55 if (FreeLoaderIniFileData == NULL)
56 {
57 printf("Out of memory while loading FREELDR.INI.\n");
58 CloseFile(Freeldr_Ini);
59 return FALSE;
60 }
61
62 // Read freeldr.ini off the disk
63 if (!ReadFile(Freeldr_Ini, FreeLoaderIniFileSize, NULL, FreeLoaderIniFileData))
64 {
65 CloseFile(Freeldr_Ini);
66 FreeMemory(FreeLoaderIniFileData);
67 return FALSE;
68 }
69
70 CloseFile(Freeldr_Ini);
71 FreeMemory(FreeLoaderIniFileData);
72
73 return TRUE;
74 }