3 * Configuration file functions
5 * Copyright (c) 2006 Christoph Pfisterer
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * * Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the
20 * * Neither the name of Christoph Pfisterer nor the names of the
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Modifications copyright (c) 2012-2015 Roderick W. Smith
40 * Modifications distributed under the terms of the GNU General Public
41 * License (GPL) version 3 (GPLv3) or (at your option) any later version.
45 * This program is free software: you can redistribute it and/or modify
46 * it under the terms of the GNU General Public License as published by
47 * the Free Software Foundation, either version 3 of the License, or
48 * (at your option) any later version.
50 * This program is distributed in the hope that it will be useful,
51 * but WITHOUT ANY WARRANTY; without even the implied warranty of
52 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 * GNU General Public License for more details.
55 * You should have received a copy of the GNU General Public License
56 * along with this program. If not, see <http://www.gnu.org/licenses/>.
65 #include "../include/refit_call_wrapper.h"
66 #include "../mok/mok.h"
70 #define LINUX_OPTIONS_FILENAMES L"refind_linux.conf,refind-linux.conf"
71 #define MAXCONFIGFILESIZE (128*1024)
73 #define ENCODING_ISO8859_1 (0)
74 #define ENCODING_UTF8 (1)
75 #define ENCODING_UTF16_LE (2)
77 #define GetTime ST->RuntimeServices->GetTime
78 #define LAST_MINUTE 1439 /* Last minute of a day */
80 extern REFIT_MENU_ENTRY MenuEntryReturn
;
81 //static REFIT_MENU_ENTRY MenuEntryReturn = { L"Return to Main Menu", TAG_RETURN, 0, 0, 0, NULL, NULL, NULL };
84 // read a file into a buffer
87 EFI_STATUS
ReadFile(IN EFI_FILE_HANDLE BaseDir
, IN CHAR16
*FileName
, IN OUT REFIT_FILE
*File
, OUT UINTN
*size
)
90 EFI_FILE_HANDLE FileHandle
;
91 EFI_FILE_INFO
*FileInfo
;
98 // read the file, allocating a buffer on the way
99 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
, EFI_FILE_MODE_READ
, 0);
100 SPrint(Message
, 255, L
"while loading the file '%s'", FileName
);
101 if (CheckError(Status
, Message
))
104 FileInfo
= LibFileInfo(FileHandle
);
105 if (FileInfo
== NULL
) {
106 // TODO: print and register the error
107 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
108 return EFI_LOAD_ERROR
;
110 ReadSize
= FileInfo
->FileSize
;
113 File
->BufferSize
= (UINTN
)ReadSize
;
114 File
->Buffer
= AllocatePool(File
->BufferSize
);
115 if (File
->Buffer
== NULL
) {
117 return EFI_OUT_OF_RESOURCES
;
119 *size
= File
->BufferSize
;
121 Status
= refit_call3_wrapper(FileHandle
->Read
, FileHandle
, &File
->BufferSize
, File
->Buffer
);
122 if (CheckError(Status
, Message
)) {
123 MyFreePool(File
->Buffer
);
125 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
128 Status
= refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
131 File
->Current8Ptr
= (CHAR8
*)File
->Buffer
;
132 File
->End8Ptr
= File
->Current8Ptr
+ File
->BufferSize
;
133 File
->Current16Ptr
= (CHAR16
*)File
->Buffer
;
134 File
->End16Ptr
= File
->Current16Ptr
+ (File
->BufferSize
>> 1);
137 File
->Encoding
= ENCODING_ISO8859_1
; // default: 1:1 translation of CHAR8 to CHAR16
138 if (File
->BufferSize
>= 4) {
139 if (File
->Buffer
[0] == 0xFF && File
->Buffer
[1] == 0xFE) {
140 // BOM in UTF-16 little endian (or UTF-32 little endian)
141 File
->Encoding
= ENCODING_UTF16_LE
; // use CHAR16 as is
142 File
->Current16Ptr
++;
143 } else if (File
->Buffer
[0] == 0xEF && File
->Buffer
[1] == 0xBB && File
->Buffer
[2] == 0xBF) {
145 File
->Encoding
= ENCODING_UTF8
; // translate from UTF-8 to UTF-16
146 File
->Current8Ptr
+= 3;
147 } else if (File
->Buffer
[1] == 0 && File
->Buffer
[3] == 0) {
148 File
->Encoding
= ENCODING_UTF16_LE
; // use CHAR16 as is
150 // TODO: detect other encodings as they are implemented
157 // get a single line of text from a file
160 static CHAR16
*ReadLine(REFIT_FILE
*File
)
165 if (File
->Buffer
== NULL
)
168 if (File
->Encoding
== ENCODING_ISO8859_1
|| File
->Encoding
== ENCODING_UTF8
) {
170 CHAR8
*p
, *LineStart
, *LineEnd
;
172 p
= File
->Current8Ptr
;
173 if (p
>= File
->End8Ptr
)
177 for (; p
< File
->End8Ptr
; p
++)
178 if (*p
== 13 || *p
== 10)
181 for (; p
< File
->End8Ptr
; p
++)
182 if (*p
!= 13 && *p
!= 10)
184 File
->Current8Ptr
= p
;
186 LineLength
= (UINTN
)(LineEnd
- LineStart
) + 1;
187 Line
= AllocatePool(LineLength
* sizeof(CHAR16
));
192 if (File
->Encoding
== ENCODING_ISO8859_1
) {
193 for (p
= LineStart
; p
< LineEnd
; )
195 } else if (File
->Encoding
== ENCODING_UTF8
) {
196 // TODO: actually handle UTF-8
197 for (p
= LineStart
; p
< LineEnd
; )
202 } else if (File
->Encoding
== ENCODING_UTF16_LE
) {
204 CHAR16
*p
, *LineStart
, *LineEnd
;
206 p
= File
->Current16Ptr
;
207 if (p
>= File
->End16Ptr
)
211 for (; p
< File
->End16Ptr
; p
++)
212 if (*p
== 13 || *p
== 10)
215 for (; p
< File
->End16Ptr
; p
++)
216 if (*p
!= 13 && *p
!= 10)
218 File
->Current16Ptr
= p
;
220 LineLength
= (UINTN
)(LineEnd
- LineStart
) + 1;
221 Line
= AllocatePool(LineLength
* sizeof(CHAR16
));
225 for (p
= LineStart
, q
= Line
; p
< LineEnd
; )
230 return NULL
; // unsupported encoding
235 // Returns FALSE if *p points to the end of a token, TRUE otherwise.
236 // Also modifies *p **IF** the first and second characters are both
237 // quotes ('"'); it deletes one of them.
238 static BOOLEAN
KeepReading(IN OUT CHAR16
*p
, IN OUT BOOLEAN
*IsQuoted
) {
239 BOOLEAN MoreToRead
= FALSE
;
242 if ((p
== NULL
) || (IsQuoted
== NULL
))
248 if ((*p
!= ' ' && *p
!= '\t' && *p
!= '=' && *p
!= '#' && *p
!= ',') || *IsQuoted
) {
253 Temp
= StrDuplicate(&p
[1]);
260 *IsQuoted
= !(*IsQuoted
);
262 } // if/else second character is a quote
263 } // if first character is a quote
266 } // BOOLEAN KeepReading()
269 // get a line of tokens from a file
271 UINTN
ReadTokenLine(IN REFIT_FILE
*File
, OUT CHAR16
***TokenList
)
273 BOOLEAN LineFinished
, IsQuoted
= FALSE
;
274 CHAR16
*Line
, *Token
, *p
;
275 UINTN TokenCount
= 0;
279 while (TokenCount
== 0) {
280 Line
= ReadLine(File
);
283 if (Line
[0] == L
'\0') {
289 LineFinished
= FALSE
;
290 while (!LineFinished
) {
291 // skip whitespace & find start of token
292 while ((*p
== ' ' || *p
== '\t' || *p
== '=' || *p
== ',') && !IsQuoted
)
294 if (*p
== 0 || *p
== '#')
298 IsQuoted
= !IsQuoted
;
304 while (KeepReading(p
, &IsQuoted
)) {
305 if ((*p
== L
'/') && !IsQuoted
) // Switch Unix-style to DOS-style directory separators
309 if (*p
== L
'\0' || *p
== L
'#')
313 AddListElement((VOID
***)TokenList
, &TokenCount
, (VOID
*)StrDuplicate(Token
));
319 } /* ReadTokenLine() */
321 VOID
FreeTokenLine(IN OUT CHAR16
***TokenList
, IN OUT UINTN
*TokenCount
)
323 // TODO: also free the items
324 FreeList((VOID
***)TokenList
, TokenCount
);
327 // handle a parameter with a single integer argument
328 static VOID
HandleInt(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT UINTN
*Value
)
330 if (TokenCount
== 2) {
331 if (StrCmp(TokenList
[1], L
"-1") == 0)
334 *Value
= Atoi(TokenList
[1]);
338 // handle a parameter with a single string argument
339 static VOID
HandleString(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT CHAR16
**Target
) {
340 if ((TokenCount
== 2) && Target
) {
341 if ((StrLen(TokenList
[1]) > 1) && (TokenList
[1][0] == L
'+') &&
342 ((TokenList
[1][1] == L
',') || (TokenList
[1][1] == L
' '))) {
344 MergeStrings(Target
, TokenList
[1] + 2, L
',');
346 *Target
= StrDuplicate(TokenList
[1] + 2);
350 *Target
= StrDuplicate(TokenList
[1]);
353 } // static VOID HandleString()
355 // Handle a parameter with a series of string arguments, to replace or be added to a
356 // comma-delimited list. Passes each token through the CleanUpPathNameSlashes() function
357 // to ensure consistency in subsequent comparisons of filenames. If the first
358 // non-keyword token is "+", the list is added to the existing target string; otherwise,
359 // the tokens replace the current string.
360 static VOID
HandleStrings(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT CHAR16
**Target
) {
362 BOOLEAN AddMode
= FALSE
;
364 if ((TokenCount
> 2) && (StrCmp(TokenList
[1], L
"+") == 0)) {
368 if ((*Target
!= NULL
) && !AddMode
) {
372 for (i
= 1; i
< TokenCount
; i
++) {
373 if ((i
!= 1) || !AddMode
) {
374 CleanUpPathNameSlashes(TokenList
[i
]);
375 MergeStrings(Target
, TokenList
[i
], L
',');
378 } // static VOID HandleStrings()
380 // Convert TimeString (in "HH:MM" format) to a pure-minute format. Values should be
381 // in the range from 0 (for 00:00, or midnight) to 1439 (for 23:59; aka LAST_MINUTE).
382 // Any value outside that range denotes an error in the specification. Note that if
383 // the input is a number that includes no colon, this function will return the original
384 // number in UINTN form.
385 static UINTN
HandleTime(IN CHAR16
*TimeString
) {
386 UINTN Hour
= 0, Minute
= 0, TimeLength
, i
= 0;
388 TimeLength
= StrLen(TimeString
);
389 while (i
< TimeLength
) {
390 if (TimeString
[i
] == L
':') {
394 if ((TimeString
[i
] >= L
'0') && (TimeString
[i
] <= '9')) {
396 Minute
+= (TimeString
[i
] - L
'0');
400 return (Hour
* 60 + Minute
);
401 } // BOOLEAN HandleTime()
403 static BOOLEAN
HandleBoolean(IN CHAR16
**TokenList
, IN UINTN TokenCount
) {
404 BOOLEAN TruthValue
= TRUE
;
406 if ((TokenCount
>= 2) && ((StrCmp(TokenList
[1], L
"0") == 0) ||
407 MyStriCmp(TokenList
[1], L
"false") ||
408 MyStriCmp(TokenList
[1], L
"off"))) {
413 } // BOOLEAN HandleBoolean
415 // Sets the default boot loader IF the current time is within the bounds
416 // defined by the third and fourth tokens in the TokenList.
417 static VOID
SetDefaultByTime(IN CHAR16
**TokenList
, OUT CHAR16
**Default
) {
419 EFI_TIME CurrentTime
;
420 UINTN StartTime
, EndTime
, Now
;
421 BOOLEAN SetIt
= FALSE
;
423 StartTime
= HandleTime(TokenList
[2]);
424 EndTime
= HandleTime(TokenList
[3]);
426 if ((StartTime
<= LAST_MINUTE
) && (EndTime
<= LAST_MINUTE
)) {
427 Status
= refit_call2_wrapper(GetTime
, &CurrentTime
, NULL
);
428 if (Status
!= EFI_SUCCESS
)
430 Now
= CurrentTime
.Hour
* 60 + CurrentTime
.Minute
;
432 if (Now
> LAST_MINUTE
) { // Shouldn't happen; just being paranoid
433 Print(L
"Warning: Impossible system time: %d:%d\n", CurrentTime
.Hour
, CurrentTime
.Minute
);
435 } // if impossible time
437 if (StartTime
< EndTime
) { // Time range does NOT cross midnight
438 if ((Now
>= StartTime
) && (Now
<= EndTime
))
440 } else { // Time range DOES cross midnight
441 if ((Now
>= StartTime
) && (Now
<= EndTime
))
443 } // if/else time range crosses midnight
446 MyFreePool(*Default
);
447 *Default
= StrDuplicate(TokenList
[1]);
449 } // if ((StartTime <= LAST_MINUTE) && (EndTime <= LAST_MINUTE))
450 } // VOID SetDefaultByTime()
453 VOID
ReadConfig(CHAR16
*FileName
)
459 CHAR16
*TempStr
= NULL
;
461 EFI_GUID RefindGuid
= REFIND_GUID_VALUE
;
463 // Set a few defaults only if we're loading the default file.
464 if (MyStriCmp(FileName
, GlobalConfig
.ConfigFilename
)) {
465 MyFreePool(GlobalConfig
.AlsoScan
);
466 GlobalConfig
.AlsoScan
= StrDuplicate(ALSO_SCAN_DIRS
);
467 MyFreePool(GlobalConfig
.DontScanDirs
);
469 if (SelfVolume
->VolName
) {
470 TempStr
= SelfVolume
->VolName
? StrDuplicate(SelfVolume
->VolName
) : NULL
;
472 TempStr
= AllocateZeroPool(256 * sizeof(CHAR16
));
474 SPrint(TempStr
, 255, L
"fs%d", SelfVolume
->VolNumber
);
477 MergeStrings(&TempStr
, SelfDirPath
, L
':');
478 MergeStrings(&TempStr
, MEMTEST_LOCATIONS
, L
',');
479 GlobalConfig
.DontScanDirs
= TempStr
;
480 MyFreePool(GlobalConfig
.DontScanFiles
);
481 GlobalConfig
.DontScanFiles
= StrDuplicate(DONT_SCAN_FILES
);
482 MergeStrings(&(GlobalConfig
.DontScanFiles
), MOK_NAMES
, L
',');
483 MyFreePool(GlobalConfig
.DontScanVolumes
);
484 GlobalConfig
.DontScanVolumes
= StrDuplicate(DONT_SCAN_VOLUMES
);
485 GlobalConfig
.WindowsRecoveryFiles
= StrDuplicate(WINDOWS_RECOVERY_FILES
);
486 if (GlobalConfig
.DefaultSelection
!= NULL
) {
487 MyFreePool(GlobalConfig
.DefaultSelection
);
488 GlobalConfig
.DefaultSelection
= NULL
;
490 Status
= EfivarGetRaw(&RefindGuid
, L
"PreviousBoot", (CHAR8
**) &(GlobalConfig
.DefaultSelection
), &i
);
491 if (Status
!= EFI_SUCCESS
)
492 GlobalConfig
.DefaultSelection
= NULL
;
495 if (!FileExists(SelfDir
, FileName
)) {
496 Print(L
"Configuration file '%s' missing!\n", FileName
);
497 if (!FileExists(SelfDir
, L
"icons")) {
498 Print(L
"Icons directory doesn't exist; setting textonly = TRUE!\n");
499 GlobalConfig
.TextOnly
= TRUE
;
504 Status
= ReadFile(SelfDir
, FileName
, &File
, &i
);
505 if (EFI_ERROR(Status
))
509 TokenCount
= ReadTokenLine(&File
, &TokenList
);
513 if (MyStriCmp(TokenList
[0], L
"timeout")) {
514 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.Timeout
));
516 } else if (MyStriCmp(TokenList
[0], L
"hideui")) {
517 for (i
= 1; i
< TokenCount
; i
++) {
518 FlagName
= TokenList
[i
];
519 if (MyStriCmp(FlagName
, L
"banner")) {
520 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BANNER
;
521 } else if (MyStriCmp(FlagName
, L
"label")) {
522 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_LABEL
;
523 } else if (MyStriCmp(FlagName
, L
"singleuser")) {
524 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SINGLEUSER
;
525 } else if (MyStriCmp(FlagName
, L
"hwtest")) {
526 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HWTEST
;
527 } else if (MyStriCmp(FlagName
, L
"arrows")) {
528 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_ARROWS
;
529 } else if (MyStriCmp(FlagName
, L
"hints")) {
530 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HINTS
;
531 } else if (MyStriCmp(FlagName
, L
"editor")) {
532 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_EDITOR
;
533 } else if (MyStriCmp(FlagName
, L
"safemode")) {
534 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SAFEMODE
;
535 } else if (MyStriCmp(FlagName
, L
"badges")) {
536 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BADGES
;
537 } else if (MyStriCmp(FlagName
, L
"all")) {
538 GlobalConfig
.HideUIFlags
= HIDEUI_FLAG_ALL
;
540 Print(L
" unknown hideui flag: '%s'\n", FlagName
);
544 } else if (MyStriCmp(TokenList
[0], L
"icons_dir")) {
545 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.IconsDir
));
547 } else if (MyStriCmp(TokenList
[0], L
"scanfor")) {
548 for (i
= 0; i
< NUM_SCAN_OPTIONS
; i
++) {
550 GlobalConfig
.ScanFor
[i
] = TokenList
[i
][0];
552 GlobalConfig
.ScanFor
[i
] = ' ';
555 } else if (MyStriCmp(TokenList
[0], L
"uefi_deep_legacy_scan")) {
556 GlobalConfig
.DeepLegacyScan
= HandleBoolean(TokenList
, TokenCount
);
558 } else if (MyStriCmp(TokenList
[0], L
"scan_delay") && (TokenCount
== 2)) {
559 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.ScanDelay
));
561 } else if (MyStriCmp(TokenList
[0], L
"also_scan_dirs")) {
562 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.AlsoScan
));
564 } else if (MyStriCmp(TokenList
[0], L
"don't_scan_volumes") || MyStriCmp(TokenList
[0], L
"dont_scan_volumes")) {
565 // Note: Don't use HandleStrings() because it modifies slashes, which might be present in volume name
566 MyFreePool(GlobalConfig
.DontScanVolumes
);
567 GlobalConfig
.DontScanVolumes
= NULL
;
568 for (i
= 1; i
< TokenCount
; i
++) {
569 MergeStrings(&GlobalConfig
.DontScanVolumes
, TokenList
[i
], L
',');
572 } else if (MyStriCmp(TokenList
[0], L
"don't_scan_dirs") || MyStriCmp(TokenList
[0], L
"dont_scan_dirs")) {
573 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DontScanDirs
));
575 } else if (MyStriCmp(TokenList
[0], L
"don't_scan_files") || MyStriCmp(TokenList
[0], L
"dont_scan_files")) {
576 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DontScanFiles
));
578 } else if (MyStriCmp(TokenList
[0], L
"windows_recovery_files")) {
579 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.WindowsRecoveryFiles
));
581 } else if (MyStriCmp(TokenList
[0], L
"scan_driver_dirs")) {
582 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DriverDirs
));
584 } else if (MyStriCmp(TokenList
[0], L
"showtools")) {
585 SetMem(GlobalConfig
.ShowTools
, NUM_TOOLS
* sizeof(UINTN
), 0);
586 for (i
= 1; (i
< TokenCount
) && (i
< NUM_TOOLS
); i
++) {
587 FlagName
= TokenList
[i
];
588 if (MyStriCmp(FlagName
, L
"shell")) {
589 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHELL
;
590 } else if (MyStriCmp(FlagName
, L
"gptsync")) {
591 GlobalConfig
.ShowTools
[i
- 1] = TAG_GPTSYNC
;
592 } else if (MyStriCmp(FlagName
, L
"gdisk")) {
593 GlobalConfig
.ShowTools
[i
- 1] = TAG_GDISK
;
594 } else if (MyStriCmp(FlagName
, L
"about")) {
595 GlobalConfig
.ShowTools
[i
- 1] = TAG_ABOUT
;
596 } else if (MyStriCmp(FlagName
, L
"exit")) {
597 GlobalConfig
.ShowTools
[i
- 1] = TAG_EXIT
;
598 } else if (MyStriCmp(FlagName
, L
"reboot")) {
599 GlobalConfig
.ShowTools
[i
- 1] = TAG_REBOOT
;
600 } else if (MyStriCmp(FlagName
, L
"shutdown")) {
601 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHUTDOWN
;
602 } else if (MyStriCmp(FlagName
, L
"apple_recovery")) {
603 GlobalConfig
.ShowTools
[i
- 1] = TAG_APPLE_RECOVERY
;
604 } else if (MyStriCmp(FlagName
, L
"windows_recovery")) {
605 GlobalConfig
.ShowTools
[i
- 1] = TAG_WINDOWS_RECOVERY
;
606 } else if (MyStriCmp(FlagName
, L
"mok_tool")) {
607 GlobalConfig
.ShowTools
[i
- 1] = TAG_MOK_TOOL
;
608 } else if (MyStriCmp(FlagName
, L
"firmware")) {
609 GlobalConfig
.ShowTools
[i
- 1] = TAG_FIRMWARE
;
610 } else if (MyStriCmp(FlagName
, L
"memtest86") || MyStriCmp(FlagName
, L
"memtest")) {
611 GlobalConfig
.ShowTools
[i
- 1] = TAG_MEMTEST
;
612 } else if (MyStriCmp(FlagName
, L
"netboot")) {
613 GlobalConfig
.ShowTools
[i
- 1] = TAG_NETBOOT
;
615 Print(L
" unknown showtools flag: '%s'\n", FlagName
);
617 } // showtools options
619 } else if (MyStriCmp(TokenList
[0], L
"banner")) {
620 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.BannerFileName
));
622 } else if (MyStriCmp(TokenList
[0], L
"banner_scale") && (TokenCount
== 2)) {
623 if (MyStriCmp(TokenList
[1], L
"noscale")) {
624 GlobalConfig
.BannerScale
= BANNER_NOSCALE
;
625 } else if (MyStriCmp(TokenList
[1], L
"fillscreen") || MyStriCmp(TokenList
[1], L
"fullscreen")) {
626 GlobalConfig
.BannerScale
= BANNER_FILLSCREEN
;
628 Print(L
" unknown banner_type flag: '%s'\n", TokenList
[1]);
631 } else if (MyStriCmp(TokenList
[0], L
"small_icon_size") && (TokenCount
== 2)) {
632 HandleInt(TokenList
, TokenCount
, &i
);
634 GlobalConfig
.IconSizes
[ICON_SIZE_SMALL
] = i
;
636 } else if (MyStriCmp(TokenList
[0], L
"big_icon_size") && (TokenCount
== 2)) {
637 HandleInt(TokenList
, TokenCount
, &i
);
639 GlobalConfig
.IconSizes
[ICON_SIZE_BIG
] = i
;
640 GlobalConfig
.IconSizes
[ICON_SIZE_BADGE
] = i
/ 4;
643 } else if (MyStriCmp(TokenList
[0], L
"selection_small")) {
644 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionSmallFileName
));
646 } else if (MyStriCmp(TokenList
[0], L
"selection_big")) {
647 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionBigFileName
));
649 } else if (MyStriCmp(TokenList
[0], L
"default_selection")) {
650 if (TokenCount
== 4) {
651 SetDefaultByTime(TokenList
, &(GlobalConfig
.DefaultSelection
));
653 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.DefaultSelection
));
656 } else if (MyStriCmp(TokenList
[0], L
"textonly")) {
657 GlobalConfig
.TextOnly
= HandleBoolean(TokenList
, TokenCount
);
659 } else if (MyStriCmp(TokenList
[0], L
"textmode")) {
660 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.RequestedTextMode
));
662 } else if (MyStriCmp(TokenList
[0], L
"resolution") && ((TokenCount
== 2) || (TokenCount
== 3))) {
663 GlobalConfig
.RequestedScreenWidth
= Atoi(TokenList
[1]);
665 GlobalConfig
.RequestedScreenHeight
= Atoi(TokenList
[2]);
667 GlobalConfig
.RequestedScreenHeight
= 0;
669 } else if (MyStriCmp(TokenList
[0], L
"screensaver")) {
670 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.ScreensaverTime
));
672 } else if (MyStriCmp(TokenList
[0], L
"use_graphics_for")) {
673 if ((TokenCount
== 2) || ((TokenCount
> 2) && (!MyStriCmp(TokenList
[1], L
"+"))))
674 GlobalConfig
.GraphicsFor
= 0;
675 for (i
= 1; i
< TokenCount
; i
++) {
676 if (MyStriCmp(TokenList
[i
], L
"osx")) {
677 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_OSX
;
678 } else if (MyStriCmp(TokenList
[i
], L
"linux")) {
679 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_LINUX
;
680 } else if (MyStriCmp(TokenList
[i
], L
"elilo")) {
681 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_ELILO
;
682 } else if (MyStriCmp(TokenList
[i
], L
"grub")) {
683 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_GRUB
;
684 } else if (MyStriCmp(TokenList
[i
], L
"windows")) {
685 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_WINDOWS
;
687 } // for (graphics_on tokens)
689 } else if (MyStriCmp(TokenList
[0], L
"font") && (TokenCount
== 2)) {
690 egLoadFont(TokenList
[1]);
692 } else if (MyStriCmp(TokenList
[0], L
"scan_all_linux_kernels")) {
693 GlobalConfig
.ScanAllLinux
= HandleBoolean(TokenList
, TokenCount
);
695 } else if (MyStriCmp(TokenList
[0], L
"fold_linux_kernels")) {
696 GlobalConfig
.FoldLinuxKernels
= HandleBoolean(TokenList
, TokenCount
);
698 } else if (MyStriCmp(TokenList
[0], L
"max_tags")) {
699 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.MaxTags
));
701 } else if (MyStriCmp(TokenList
[0], L
"enable_and_lock_vmx")) {
702 GlobalConfig
.EnableAndLockVMX
= HandleBoolean(TokenList
, TokenCount
);
704 } else if (MyStriCmp(TokenList
[0], L
"spoof_osx_version")) {
705 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SpoofOSXVersion
));
707 } else if (MyStriCmp(TokenList
[0], L
"include") && (TokenCount
== 2) && MyStriCmp(FileName
, GlobalConfig
.ConfigFilename
)) {
708 if (!MyStriCmp(TokenList
[1], FileName
)) {
709 ReadConfig(TokenList
[1]);
714 FreeTokenLine(&TokenList
, &TokenCount
);
716 if ((GlobalConfig
.DontScanFiles
) && (GlobalConfig
.WindowsRecoveryFiles
))
717 MergeStrings(&(GlobalConfig
.DontScanFiles
), GlobalConfig
.WindowsRecoveryFiles
, L
',');
718 MyFreePool(File
.Buffer
);
720 if (!FileExists(SelfDir
, L
"icons") && !FileExists(SelfDir
, GlobalConfig
.IconsDir
)) {
721 Print(L
"Icons directory doesn't exist; setting textonly = TRUE!\n");
722 GlobalConfig
.TextOnly
= TRUE
;
724 } /* VOID ReadConfig() */
726 // Finds a volume with the specified Identifier (a filesystem label, a
727 // partition name, a partition GUID, or a number followed by a colon). If
728 // found, sets *Volume to point to that volume. If not, leaves it unchanged.
729 // Returns TRUE if a match was found, FALSE if not.
730 static BOOLEAN
FindVolume(REFIT_VOLUME
**Volume
, CHAR16
*Identifier
) {
731 UINTN i
= 0, CountedVolumes
= 0, Length
;
733 BOOLEAN Found
= FALSE
, IdIsGuid
= FALSE
;
734 EFI_GUID VolGuid
, NullGuid
= NULL_GUID_VALUE
;
736 VolGuid
= StringAsGuid(Identifier
);
737 Length
= StrLen(Identifier
);
738 if ((Length
>= 2) && (Identifier
[Length
- 1] == L
':') &&
739 (Identifier
[0] >= L
'0') && (Identifier
[0] <= L
'9')) {
740 Number
= (INTN
) Atoi(Identifier
);
741 } else if (IsGuid(Identifier
)) {
744 while ((i
< VolumesCount
) && (!Found
)) {
745 if (Number
>= 0) { // User specified a volume by number
746 if (Volumes
[i
]->IsReadable
) {
747 if (CountedVolumes
== Number
) {
748 *Volume
= Volumes
[i
];
753 } else { // User specified a volume by label or GUID
754 if (MyStriCmp(Identifier
, Volumes
[i
]->VolName
) || MyStriCmp(Identifier
, Volumes
[i
]->PartName
)) {
755 *Volume
= Volumes
[i
];
758 if (IdIsGuid
&& !Found
) {
759 if (GuidsAreEqual(&VolGuid
, &(Volumes
[i
]->PartGuid
)) && !GuidsAreEqual(&NullGuid
, &(Volumes
[i
]->PartGuid
))) {
760 *Volume
= Volumes
[i
];
768 } // static VOID FindVolume()
770 static VOID
AddSubmenu(LOADER_ENTRY
*Entry
, REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
771 REFIT_MENU_SCREEN
*SubScreen
;
772 LOADER_ENTRY
*SubEntry
;
776 SubScreen
= InitializeSubScreen(Entry
);
778 // Set defaults for the new entry; will be modified based on lines read from the config. file....
779 SubEntry
= InitializeLoaderEntry(Entry
);
781 if ((SubEntry
== NULL
) || (SubScreen
== NULL
))
783 SubEntry
->me
.Title
= StrDuplicate(Title
);
785 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StrCmp(TokenList
[0], L
"}") != 0)) {
787 if (MyStriCmp(TokenList
[0], L
"loader") && (TokenCount
> 1)) { // set the boot loader filename
788 MyFreePool(SubEntry
->LoaderPath
);
789 SubEntry
->LoaderPath
= StrDuplicate(TokenList
[1]);
790 SubEntry
->DevicePath
= FileDevicePath(Volume
->DeviceHandle
, SubEntry
->LoaderPath
);
792 } else if (MyStriCmp(TokenList
[0], L
"volume") && (TokenCount
> 1)) {
793 if (FindVolume(&Volume
, TokenList
[1])) {
794 if ((Volume
!= NULL
) && (Volume
->IsReadable
) && (Volume
->RootDir
)) {
795 MyFreePool(SubEntry
->me
.Title
);
796 SubEntry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
797 SPrint(SubEntry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", Volume
->VolName
);
798 SubEntry
->me
.BadgeImage
= Volume
->VolBadgeImage
;
799 SubEntry
->VolName
= Volume
->VolName
;
800 } // if volume is readable
803 } else if (MyStriCmp(TokenList
[0], L
"initrd")) {
804 MyFreePool(SubEntry
->InitrdPath
);
805 SubEntry
->InitrdPath
= NULL
;
806 if (TokenCount
> 1) {
807 SubEntry
->InitrdPath
= StrDuplicate(TokenList
[1]);
810 } else if (MyStriCmp(TokenList
[0], L
"options")) {
811 MyFreePool(SubEntry
->LoadOptions
);
812 SubEntry
->LoadOptions
= NULL
;
813 if (TokenCount
> 1) {
814 SubEntry
->LoadOptions
= StrDuplicate(TokenList
[1]);
817 } else if (MyStriCmp(TokenList
[0], L
"add_options") && (TokenCount
> 1)) {
818 MergeStrings(&SubEntry
->LoadOptions
, TokenList
[1], L
' ');
820 } else if (MyStriCmp(TokenList
[0], L
"graphics") && (TokenCount
> 1)) {
821 SubEntry
->UseGraphicsMode
= MyStriCmp(TokenList
[1], L
"on");
823 } else if (MyStriCmp(TokenList
[0], L
"disabled")) {
824 SubEntry
->Enabled
= FALSE
;
827 FreeTokenLine(&TokenList
, &TokenCount
);
830 if (SubEntry
->InitrdPath
!= NULL
) {
831 MergeStrings(&SubEntry
->LoadOptions
, L
"initrd=", L
' ');
832 MergeStrings(&SubEntry
->LoadOptions
, SubEntry
->InitrdPath
, 0);
833 MyFreePool(SubEntry
->InitrdPath
);
834 SubEntry
->InitrdPath
= NULL
;
836 if (SubEntry
->Enabled
== TRUE
) {
837 AddMenuEntry(SubScreen
, (REFIT_MENU_ENTRY
*)SubEntry
);
839 Entry
->me
.SubScreen
= SubScreen
;
840 } // VOID AddSubmenu()
842 // Adds the options from a SINGLE refind.conf stanza to a new loader entry and returns
843 // that entry. The calling function is then responsible for adding the entry to the
845 static LOADER_ENTRY
* AddStanzaEntries(REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
849 BOOLEAN DefaultsSet
= FALSE
, AddedSubmenu
= FALSE
;
850 REFIT_VOLUME
*CurrentVolume
= Volume
;
852 // prepare the menu entry
853 Entry
= InitializeLoaderEntry(NULL
);
857 Entry
->Title
= StrDuplicate(Title
);
858 Entry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
859 SPrint(Entry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
861 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
862 Entry
->VolName
= CurrentVolume
->VolName
;
864 // Parse the config file to add options for a single stanza, terminating when the token
865 // is "}" or when the end of file is reached.
866 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StrCmp(TokenList
[0], L
"}") != 0)) {
867 if (MyStriCmp(TokenList
[0], L
"loader") && (TokenCount
> 1)) { // set the boot loader filename
868 Entry
->LoaderPath
= StrDuplicate(TokenList
[1]);
869 Entry
->DevicePath
= FileDevicePath(CurrentVolume
->DeviceHandle
, Entry
->LoaderPath
);
870 SetLoaderDefaults(Entry
, TokenList
[1], CurrentVolume
);
871 MyFreePool(Entry
->LoadOptions
);
872 Entry
->LoadOptions
= NULL
; // Discard default options, if any
875 } else if (MyStriCmp(TokenList
[0], L
"volume") && (TokenCount
> 1)) {
876 if (FindVolume(&CurrentVolume
, TokenList
[1])) {
877 if ((CurrentVolume
!= NULL
) && (CurrentVolume
->IsReadable
) && (CurrentVolume
->RootDir
)) {
878 MyFreePool(Entry
->me
.Title
);
879 Entry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
880 SPrint(Entry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
881 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
882 Entry
->VolName
= CurrentVolume
->VolName
;
883 } // if volume is readable
886 } else if (MyStriCmp(TokenList
[0], L
"icon") && (TokenCount
> 1)) {
887 MyFreePool(Entry
->me
.Image
);
888 Entry
->me
.Image
= egLoadIcon(CurrentVolume
->RootDir
, TokenList
[1], GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
889 if (Entry
->me
.Image
== NULL
) {
890 Entry
->me
.Image
= DummyImage(GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
893 } else if (MyStriCmp(TokenList
[0], L
"initrd") && (TokenCount
> 1)) {
894 MyFreePool(Entry
->InitrdPath
);
895 Entry
->InitrdPath
= StrDuplicate(TokenList
[1]);
897 } else if (MyStriCmp(TokenList
[0], L
"options") && (TokenCount
> 1)) {
898 MyFreePool(Entry
->LoadOptions
);
899 Entry
->LoadOptions
= StrDuplicate(TokenList
[1]);
901 } else if (MyStriCmp(TokenList
[0], L
"ostype") && (TokenCount
> 1)) {
902 if (TokenCount
> 1) {
903 Entry
->OSType
= TokenList
[1][0];
906 } else if (MyStriCmp(TokenList
[0], L
"graphics") && (TokenCount
> 1)) {
907 Entry
->UseGraphicsMode
= MyStriCmp(TokenList
[1], L
"on");
909 } else if (MyStriCmp(TokenList
[0], L
"disabled")) {
910 Entry
->Enabled
= FALSE
;
912 } else if (MyStriCmp(TokenList
[0], L
"submenuentry") && (TokenCount
> 1)) {
913 AddSubmenu(Entry
, File
, CurrentVolume
, TokenList
[1]);
916 } // set options to pass to the loader program
917 FreeTokenLine(&TokenList
, &TokenCount
);
921 AddMenuEntry(Entry
->me
.SubScreen
, &MenuEntryReturn
);
923 if (Entry
->InitrdPath
) {
924 MergeStrings(&Entry
->LoadOptions
, L
"initrd=", L
' ');
925 MergeStrings(&Entry
->LoadOptions
, Entry
->InitrdPath
, 0);
926 MyFreePool(Entry
->InitrdPath
);
927 Entry
->InitrdPath
= NULL
;
931 SetLoaderDefaults(Entry
, L
"\\EFI\\BOOT\\nemo.efi", CurrentVolume
); // user included no "loader" line; use bogus one
934 } // static VOID AddStanzaEntries()
936 // Read the user-configured menu entries from refind.conf and add or delete
937 // entries based on the contents of that file....
938 VOID
ScanUserConfigured(CHAR16
*FileName
)
942 REFIT_VOLUME
*Volume
;
944 CHAR16
*Title
= NULL
;
945 UINTN TokenCount
, size
;
948 if (FileExists(SelfDir
, FileName
)) {
949 Status
= ReadFile(SelfDir
, FileName
, &File
, &size
);
950 if (EFI_ERROR(Status
))
955 while ((TokenCount
= ReadTokenLine(&File
, &TokenList
)) > 0) {
956 if (MyStriCmp(TokenList
[0], L
"menuentry") && (TokenCount
> 1)) {
957 Title
= StrDuplicate(TokenList
[1]);
958 Entry
= AddStanzaEntries(&File
, Volume
, TokenList
[1]);
959 if (Entry
->Enabled
) {
960 if (Entry
->me
.SubScreen
== NULL
)
961 GenerateSubScreen(Entry
, Volume
, TRUE
);
962 AddPreparedLoaderEntry(Entry
);
968 } else if (MyStriCmp(TokenList
[0], L
"include") && (TokenCount
== 2) &&
969 MyStriCmp(FileName
, GlobalConfig
.ConfigFilename
)) {
970 if (!MyStriCmp(TokenList
[1], FileName
)) {
971 ScanUserConfigured(TokenList
[1]);
975 FreeTokenLine(&TokenList
, &TokenCount
);
978 } // VOID ScanUserConfigured()
980 // Create an options file based on /etc/fstab. The resulting file has two options
981 // lines, one of which boots the system with "ro root={rootfs}" and the other of
982 // which boots the system with "ro root={rootfs} single", where "{rootfs}" is the
983 // filesystem identifier associated with the "/" line in /etc/fstab.
984 static REFIT_FILE
* GenerateOptionsFromEtcFstab(REFIT_VOLUME
*Volume
) {
986 REFIT_FILE
*Options
= NULL
, *Fstab
= NULL
;
988 CHAR16
**TokenList
, *Line
, Root
[100];
990 if (FileExists(Volume
->RootDir
, L
"\\etc\\fstab")) {
991 Options
= AllocateZeroPool(sizeof(REFIT_FILE
));
992 Fstab
= AllocateZeroPool(sizeof(REFIT_FILE
));
993 Status
= ReadFile(Volume
->RootDir
, L
"\\etc\\fstab", Fstab
, &i
);
994 if (CheckError(Status
, L
"while reading /etc/fstab")) {
1001 } else { // File read; locate root fs and create entries
1002 Options
->Encoding
= ENCODING_UTF16_LE
;
1003 while ((TokenCount
= ReadTokenLine(Fstab
, &TokenList
)) > 0) {
1004 if (TokenCount
> 2) {
1006 if (StrCmp(TokenList
[1], L
"\\") == 0) {
1007 SPrint(Root
, 99, L
"%s", TokenList
[0]);
1008 } else if (StrCmp(TokenList
[2], L
"\\") == 0) {
1009 SPrint(Root
, 99, L
"%s=%s", TokenList
[0], TokenList
[1]);
1010 } // if/elseif/elseif
1011 if (Root
[0] != L
'\0') {
1012 for (i
= 0; i
< StrLen(Root
); i
++)
1013 if (Root
[i
] == '\\')
1015 Line
= PoolPrint(L
"\"Boot with normal options\" \"ro root=%s\"\n", Root
);
1016 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1018 Line
= PoolPrint(L
"\"Boot into single-user mode\" \"ro root=%s single\"\n", Root
);
1019 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1020 Options
->BufferSize
= StrLen((CHAR16
*) Options
->Buffer
) * sizeof(CHAR16
);
1023 FreeTokenLine(&TokenList
, &TokenCount
);
1026 if (Options
->Buffer
) {
1027 Options
->Current8Ptr
= (CHAR8
*)Options
->Buffer
;
1028 Options
->End8Ptr
= Options
->Current8Ptr
+ Options
->BufferSize
;
1029 Options
->Current16Ptr
= (CHAR16
*)Options
->Buffer
;
1030 Options
->End16Ptr
= Options
->Current16Ptr
+ (Options
->BufferSize
>> 1);
1032 MyFreePool(Options
);
1036 MyFreePool(Fstab
->Buffer
);
1038 } // if/else file read error
1039 } // if /etc/fstab exists
1041 } // GenerateOptionsFromEtcFstab()
1043 // Create options from partition type codes. Specifically, if the earlier
1044 // partition scan found a partition with a type code corresponding to a root
1045 // filesystem according to the Freedesktop.org Discoverable Partitions Spec
1046 // (http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/),
1047 // this function returns an appropriate file with two lines, one with
1048 // "ro root=/dev/disk/by-partuuid/{GUID}" and the other with that plus "single".
1049 // Note that this function returns the LAST partition found with the
1050 // appropriate type code, so this will work poorly on dual-boot systems or
1051 // if the type code is set incorrectly.
1052 static REFIT_FILE
* GenerateOptionsFromPartTypes(VOID
) {
1053 REFIT_FILE
*Options
= NULL
;
1054 CHAR16
*Line
, *GuidString
, *WriteStatus
;
1056 if (GlobalConfig
.DiscoveredRoot
) {
1057 Options
= AllocateZeroPool(sizeof(REFIT_FILE
));
1059 Options
->Encoding
= ENCODING_UTF16_LE
;
1060 GuidString
= GuidAsString(&(GlobalConfig
.DiscoveredRoot
->PartGuid
));
1061 WriteStatus
= GlobalConfig
.DiscoveredRoot
->IsMarkedReadOnly
? L
"ro" : L
"rw";
1062 ToLower(GuidString
);
1064 Line
= PoolPrint(L
"\"Boot with normal options\" \"%s root=/dev/disk/by-partuuid/%s\"\n", WriteStatus
, GuidString
);
1065 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1067 Line
= PoolPrint(L
"\"Boot into single-user mode\" \"%s root=/dev/disk/by-partuuid/%s single\"\n", WriteStatus
, GuidString
);
1068 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1070 MyFreePool(GuidString
);
1071 } // if (GuidString)
1072 Options
->BufferSize
= StrLen((CHAR16
*) Options
->Buffer
) * sizeof(CHAR16
);
1074 Options
->Current8Ptr
= (CHAR8
*)Options
->Buffer
;
1075 Options
->End8Ptr
= Options
->Current8Ptr
+ Options
->BufferSize
;
1076 Options
->Current16Ptr
= (CHAR16
*)Options
->Buffer
;
1077 Options
->End16Ptr
= Options
->Current16Ptr
+ (Options
->BufferSize
>> 1);
1078 } // if (Options allocated OK)
1079 } // if (partition has root GUID)
1081 } // REFIT_FILE * GenerateOptionsFromPartTypes()
1083 // Read a Linux kernel options file for a Linux boot loader into memory. The LoaderPath
1084 // and Volume variables identify the location of the options file, but not its name --
1085 // you pass this function the filename of the Linux kernel, initial RAM disk, or other
1086 // file in the target directory, and this function finds the file with a name in the
1087 // comma-delimited list of names specified by LINUX_OPTIONS_FILENAMES within that
1088 // directory and loads it. This function tries multiple files because I originally
1089 // used the filename linux.conf, but close on the heels of that decision, the Linux
1090 // kernel developers decided to use that name for a similar purpose, but with a
1091 // different file format. Thus, I'm migrating rEFInd to use the name refind_linux.conf,
1092 // but I want a migration period in which both names are used.
1093 // If a rEFInd options file can't be found, try to generate minimal options from
1094 // /etc/fstab on the same volume as the kernel. This typically works only if the
1095 // kernel is being read from the Linux root filesystem.
1097 // The return value is a pointer to the REFIT_FILE handle for the file, or NULL if
1099 REFIT_FILE
* ReadLinuxOptionsFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
1100 CHAR16
*OptionsFilename
, *FullFilename
;
1101 BOOLEAN GoOn
= TRUE
, FileFound
= FALSE
;
1103 REFIT_FILE
*File
= NULL
;
1107 OptionsFilename
= FindCommaDelimited(LINUX_OPTIONS_FILENAMES
, i
++);
1108 FullFilename
= FindPath(LoaderPath
);
1109 if ((OptionsFilename
!= NULL
) && (FullFilename
!= NULL
)) {
1110 MergeStrings(&FullFilename
, OptionsFilename
, '\\');
1111 if (FileExists(Volume
->RootDir
, FullFilename
)) {
1112 File
= AllocateZeroPool(sizeof(REFIT_FILE
));
1113 Status
= ReadFile(Volume
->RootDir
, FullFilename
, File
, &size
);
1114 if (CheckError(Status
, L
"while loading the Linux options file")) {
1123 } else { // a filename string is NULL
1126 MyFreePool(OptionsFilename
);
1127 MyFreePool(FullFilename
);
1128 OptionsFilename
= FullFilename
= NULL
;
1131 // No refind_linux.conf file; look for /etc/fstab and try to pull values from there....
1132 File
= GenerateOptionsFromEtcFstab(Volume
);
1133 // If still no joy, try to use Freedesktop.org Discoverable Partitions Spec....
1135 File
= GenerateOptionsFromPartTypes();
1138 } // static REFIT_FILE * ReadLinuxOptionsFile()
1140 // Retrieve a single line of options from a Linux kernel options file
1141 CHAR16
* GetFirstOptionsFromFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
1143 CHAR16
*Options
= NULL
;
1147 File
= ReadLinuxOptionsFile(LoaderPath
, Volume
);
1149 TokenCount
= ReadTokenLine(File
, &TokenList
);
1151 Options
= StrDuplicate(TokenList
[1]);
1152 FreeTokenLine(&TokenList
, &TokenCount
);
1156 } // static CHAR16 * GetOptionsFile()