[FREELDR] Verbose error output for FS errors
[reactos.git] / boot / freeldr / freeldr / lib / inifile / ini_init.c
1 /*
2 * FreeLoader
3 * Copyright (C) 2009 Hervé Poussineau <hpoussin@reactos.org>
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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include <freeldr.h>
21 #include <debug.h>
22 DBG_DEFAULT_CHANNEL(INIFILE);
23
24 static ARC_STATUS IniOpenIniFile(ULONG* FileId)
25 {
26 CHAR FreeldrPath[MAX_PATH];
27
28 //
29 // Create full freeldr.ini path
30 //
31 MachDiskGetBootPath(FreeldrPath, sizeof(FreeldrPath));
32 strcat(FreeldrPath, "\\freeldr.ini");
33
34 // Try to open freeldr.ini
35 return ArcOpen(FreeldrPath, OpenReadOnly, FileId);
36 }
37
38 BOOLEAN IniFileInitialize(VOID)
39 {
40 FILEINFORMATION FileInformation;
41 ULONG FileId; // File handle for freeldr.ini
42 PCHAR FreeLoaderIniFileData;
43 ULONG FreeLoaderIniFileSize, Count;
44 ARC_STATUS Status;
45 BOOLEAN Success;
46 TRACE("IniFileInitialize()\n");
47
48 //
49 // Open freeldr.ini
50 //
51 Status = IniOpenIniFile(&FileId);
52 if (Status != ESUCCESS)
53 {
54 ERR("Error while opening freeldr.ini, Status: %d\n", Status);
55 UiMessageBoxCritical("Error opening freeldr.ini or file not found.\nYou need to re-install FreeLoader.");
56 return FALSE;
57 }
58
59 //
60 // Get the file size
61 //
62 Status = ArcGetFileInformation(FileId, &FileInformation);
63 if (Status != ESUCCESS || FileInformation.EndingAddress.HighPart != 0)
64 {
65 UiMessageBoxCritical("Error while getting informations about freeldr.ini.\nYou need to re-install FreeLoader.");
66 return FALSE;
67 }
68 FreeLoaderIniFileSize = FileInformation.EndingAddress.LowPart;
69
70 //
71 // Allocate memory to cache the whole freeldr.ini
72 //
73 FreeLoaderIniFileData = FrLdrTempAlloc(FreeLoaderIniFileSize, TAG_INI_FILE);
74 if (!FreeLoaderIniFileData)
75 {
76 UiMessageBoxCritical("Out of memory while loading freeldr.ini.");
77 ArcClose(FileId);
78 return FALSE;
79 }
80
81 //
82 // Read freeldr.ini off the disk
83 //
84 Status = ArcRead(FileId, FreeLoaderIniFileData, FreeLoaderIniFileSize, &Count);
85 if (Status != ESUCCESS || Count != FreeLoaderIniFileSize)
86 {
87 ERR("Error while reading freeldr.ini, Status: %d\n", Status);
88 UiMessageBoxCritical("Error while reading freeldr.ini.");
89 ArcClose(FileId);
90 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
91 return FALSE;
92 }
93
94 //
95 // Parse the .ini file data
96 //
97 Success = IniParseFile(FreeLoaderIniFileData, FreeLoaderIniFileSize);
98
99 //
100 // Do some cleanup, and return
101 //
102 ArcClose(FileId);
103 FrLdrTempFree(FreeLoaderIniFileData, TAG_INI_FILE);
104
105 return Success;
106 }