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), a copy of which must be distributed
42 * with this source code or binaries made from it.
52 #include "../include/refit_call_wrapper.h"
53 #include "../mok/mok.h"
57 #define LINUX_OPTIONS_FILENAMES L"refind_linux.conf,refind-linux.conf"
58 #define MAXCONFIGFILESIZE (128*1024)
60 #define ENCODING_ISO8859_1 (0)
61 #define ENCODING_UTF8 (1)
62 #define ENCODING_UTF16_LE (2)
64 #define GetTime ST->RuntimeServices->GetTime
65 #define LAST_MINUTE 1439 /* Last minute of a day */
67 extern REFIT_MENU_ENTRY MenuEntryReturn
;
68 //static REFIT_MENU_ENTRY MenuEntryReturn = { L"Return to Main Menu", TAG_RETURN, 0, 0, 0, NULL, NULL, NULL };
71 // read a file into a buffer
74 EFI_STATUS
ReadFile(IN EFI_FILE_HANDLE BaseDir
, IN CHAR16
*FileName
, IN OUT REFIT_FILE
*File
, OUT UINTN
*size
)
77 EFI_FILE_HANDLE FileHandle
;
78 EFI_FILE_INFO
*FileInfo
;
85 // read the file, allocating a buffer on the way
86 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
, EFI_FILE_MODE_READ
, 0);
87 SPrint(Message
, 255, L
"while loading the file '%s'", FileName
);
88 if (CheckError(Status
, Message
))
91 FileInfo
= LibFileInfo(FileHandle
);
92 if (FileInfo
== NULL
) {
93 // TODO: print and register the error
94 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
95 return EFI_LOAD_ERROR
;
97 ReadSize
= FileInfo
->FileSize
;
100 File
->BufferSize
= (UINTN
)ReadSize
;
101 File
->Buffer
= AllocatePool(File
->BufferSize
);
102 if (File
->Buffer
== NULL
) {
104 return EFI_OUT_OF_RESOURCES
;
106 *size
= File
->BufferSize
;
108 Status
= refit_call3_wrapper(FileHandle
->Read
, FileHandle
, &File
->BufferSize
, File
->Buffer
);
109 if (CheckError(Status
, Message
)) {
110 MyFreePool(File
->Buffer
);
112 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
115 Status
= refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
118 File
->Current8Ptr
= (CHAR8
*)File
->Buffer
;
119 File
->End8Ptr
= File
->Current8Ptr
+ File
->BufferSize
;
120 File
->Current16Ptr
= (CHAR16
*)File
->Buffer
;
121 File
->End16Ptr
= File
->Current16Ptr
+ (File
->BufferSize
>> 1);
124 File
->Encoding
= ENCODING_ISO8859_1
; // default: 1:1 translation of CHAR8 to CHAR16
125 if (File
->BufferSize
>= 4) {
126 if (File
->Buffer
[0] == 0xFF && File
->Buffer
[1] == 0xFE) {
127 // BOM in UTF-16 little endian (or UTF-32 little endian)
128 File
->Encoding
= ENCODING_UTF16_LE
; // use CHAR16 as is
129 File
->Current16Ptr
++;
130 } else if (File
->Buffer
[0] == 0xEF && File
->Buffer
[1] == 0xBB && File
->Buffer
[2] == 0xBF) {
132 File
->Encoding
= ENCODING_UTF8
; // translate from UTF-8 to UTF-16
133 File
->Current8Ptr
+= 3;
134 } else if (File
->Buffer
[1] == 0 && File
->Buffer
[3] == 0) {
135 File
->Encoding
= ENCODING_UTF16_LE
; // use CHAR16 as is
137 // TODO: detect other encodings as they are implemented
144 // get a single line of text from a file
147 static CHAR16
*ReadLine(REFIT_FILE
*File
)
152 if (File
->Buffer
== NULL
)
155 if (File
->Encoding
== ENCODING_ISO8859_1
|| File
->Encoding
== ENCODING_UTF8
) {
157 CHAR8
*p
, *LineStart
, *LineEnd
;
159 p
= File
->Current8Ptr
;
160 if (p
>= File
->End8Ptr
)
164 for (; p
< File
->End8Ptr
; p
++)
165 if (*p
== 13 || *p
== 10)
168 for (; p
< File
->End8Ptr
; p
++)
169 if (*p
!= 13 && *p
!= 10)
171 File
->Current8Ptr
= p
;
173 LineLength
= (UINTN
)(LineEnd
- LineStart
) + 1;
174 Line
= AllocatePool(LineLength
* sizeof(CHAR16
));
179 if (File
->Encoding
== ENCODING_ISO8859_1
) {
180 for (p
= LineStart
; p
< LineEnd
; )
182 } else if (File
->Encoding
== ENCODING_UTF8
) {
183 // TODO: actually handle UTF-8
184 for (p
= LineStart
; p
< LineEnd
; )
189 } else if (File
->Encoding
== ENCODING_UTF16_LE
) {
191 CHAR16
*p
, *LineStart
, *LineEnd
;
193 p
= File
->Current16Ptr
;
194 if (p
>= File
->End16Ptr
)
198 for (; p
< File
->End16Ptr
; p
++)
199 if (*p
== 13 || *p
== 10)
202 for (; p
< File
->End16Ptr
; p
++)
203 if (*p
!= 13 && *p
!= 10)
205 File
->Current16Ptr
= p
;
207 LineLength
= (UINTN
)(LineEnd
- LineStart
) + 1;
208 Line
= AllocatePool(LineLength
* sizeof(CHAR16
));
212 for (p
= LineStart
, q
= Line
; p
< LineEnd
; )
217 return NULL
; // unsupported encoding
222 // Returns FALSE if *p points to the end of a token, TRUE otherwise.
223 // Also modifies *p **IF** the first and second characters are both
224 // quotes ('"'); it deletes one of them.
225 static BOOLEAN
KeepReading(IN OUT CHAR16
*p
, IN OUT BOOLEAN
*IsQuoted
) {
226 BOOLEAN MoreToRead
= FALSE
;
229 if ((p
== NULL
) || (IsQuoted
== NULL
))
235 if ((*p
!= ' ' && *p
!= '\t' && *p
!= '=' && *p
!= '#' && *p
!= ',') || *IsQuoted
) {
240 Temp
= StrDuplicate(&p
[1]);
247 *IsQuoted
= !(*IsQuoted
);
249 } // if/else second character is a quote
250 } // if first character is a quote
253 } // BOOLEAN KeepReading()
256 // get a line of tokens from a file
258 UINTN
ReadTokenLine(IN REFIT_FILE
*File
, OUT CHAR16
***TokenList
)
260 BOOLEAN LineFinished
, IsQuoted
= FALSE
;
261 CHAR16
*Line
, *Token
, *p
;
262 UINTN TokenCount
= 0;
266 while (TokenCount
== 0) {
267 Line
= ReadLine(File
);
270 if (Line
[0] == L
'\0') {
276 LineFinished
= FALSE
;
277 while (!LineFinished
) {
278 // skip whitespace & find start of token
279 while ((*p
== ' ' || *p
== '\t' || *p
== '=' || *p
== ',') && !IsQuoted
)
281 if (*p
== 0 || *p
== '#')
285 IsQuoted
= !IsQuoted
;
291 while (KeepReading(p
, &IsQuoted
)) {
292 if ((*p
== L
'/') && !IsQuoted
) // Switch Unix-style to DOS-style directory separators
296 if (*p
== L
'\0' || *p
== L
'#')
300 AddListElement((VOID
***)TokenList
, &TokenCount
, (VOID
*)StrDuplicate(Token
));
306 } /* ReadTokenLine() */
308 VOID
FreeTokenLine(IN OUT CHAR16
***TokenList
, IN OUT UINTN
*TokenCount
)
310 // TODO: also free the items
311 FreeList((VOID
***)TokenList
, TokenCount
);
314 // handle a parameter with a single integer argument
315 static VOID
HandleInt(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT UINTN
*Value
)
317 if (TokenCount
== 2) {
318 if (StrCmp(TokenList
[1], L
"-1") == 0)
321 *Value
= Atoi(TokenList
[1]);
325 // handle a parameter with a single string argument
326 static VOID
HandleString(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT CHAR16
**Target
) {
327 if ((TokenCount
== 2) && Target
) {
328 if ((StrLen(TokenList
[1]) > 1) && (TokenList
[1][0] == L
'+') &&
329 ((TokenList
[1][1] == L
',') || (TokenList
[1][1] == L
' '))) {
331 MergeStrings(Target
, TokenList
[1] + 2, L
',');
333 *Target
= StrDuplicate(TokenList
[1] + 2);
337 *Target
= StrDuplicate(TokenList
[1]);
340 } // static VOID HandleString()
342 // Handle a parameter with a series of string arguments, to replace or be added to a
343 // comma-delimited list. Passes each token through the CleanUpPathNameSlashes() function
344 // to ensure consistency in subsequent comparisons of filenames. If the first
345 // non-keyword token is "+", the list is added to the existing target string; otherwise,
346 // the tokens replace the current string.
347 static VOID
HandleStrings(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT CHAR16
**Target
) {
349 BOOLEAN AddMode
= FALSE
;
351 if ((TokenCount
> 2) && (StrCmp(TokenList
[1], L
"+") == 0)) {
355 if ((*Target
!= NULL
) && !AddMode
) {
359 for (i
= 1; i
< TokenCount
; i
++) {
360 if ((i
!= 1) || !AddMode
) {
361 CleanUpPathNameSlashes(TokenList
[i
]);
362 MergeStrings(Target
, TokenList
[i
], L
',');
365 } // static VOID HandleStrings()
367 // Convert TimeString (in "HH:MM" format) to a pure-minute format. Values should be
368 // in the range from 0 (for 00:00, or midnight) to 1439 (for 23:59; aka LAST_MINUTE).
369 // Any value outside that range denotes an error in the specification. Note that if
370 // the input is a number that includes no colon, this function will return the original
371 // number in UINTN form.
372 static UINTN
HandleTime(IN CHAR16
*TimeString
) {
373 UINTN Hour
= 0, Minute
= 0, TimeLength
, i
= 0;
375 TimeLength
= StrLen(TimeString
);
376 while (i
< TimeLength
) {
377 if (TimeString
[i
] == L
':') {
381 if ((TimeString
[i
] >= L
'0') && (TimeString
[i
] <= '9')) {
383 Minute
+= (TimeString
[i
] - L
'0');
387 return (Hour
* 60 + Minute
);
388 } // BOOLEAN HandleTime()
390 static BOOLEAN
HandleBoolean(IN CHAR16
**TokenList
, IN UINTN TokenCount
) {
391 BOOLEAN TruthValue
= TRUE
;
393 if ((TokenCount
>= 2) && ((StrCmp(TokenList
[1], L
"0") == 0) ||
394 MyStriCmp(TokenList
[1], L
"false") ||
395 MyStriCmp(TokenList
[1], L
"off"))) {
400 } // BOOLEAN HandleBoolean
402 // Sets the default boot loader IF the current time is within the bounds
403 // defined by the third and fourth tokens in the TokenList.
404 static VOID
SetDefaultByTime(IN CHAR16
**TokenList
, OUT CHAR16
**Default
) {
406 EFI_TIME CurrentTime
;
407 UINTN StartTime
, EndTime
, Now
;
408 BOOLEAN SetIt
= FALSE
;
410 StartTime
= HandleTime(TokenList
[2]);
411 EndTime
= HandleTime(TokenList
[3]);
413 if ((StartTime
<= LAST_MINUTE
) && (EndTime
<= LAST_MINUTE
)) {
414 Status
= refit_call2_wrapper(GetTime
, &CurrentTime
, NULL
);
415 if (Status
!= EFI_SUCCESS
)
417 Now
= CurrentTime
.Hour
* 60 + CurrentTime
.Minute
;
419 if (Now
> LAST_MINUTE
) { // Shouldn't happen; just being paranoid
420 Print(L
"Warning: Impossible system time: %d:%d\n", CurrentTime
.Hour
, CurrentTime
.Minute
);
422 } // if impossible time
424 if (StartTime
< EndTime
) { // Time range does NOT cross midnight
425 if ((Now
>= StartTime
) && (Now
<= EndTime
))
427 } else { // Time range DOES cross midnight
428 if ((Now
>= StartTime
) && (Now
<= EndTime
))
430 } // if/else time range crosses midnight
433 MyFreePool(*Default
);
434 *Default
= StrDuplicate(TokenList
[1]);
436 } // if ((StartTime <= LAST_MINUTE) && (EndTime <= LAST_MINUTE))
437 } // VOID SetDefaultByTime()
440 VOID
ReadConfig(CHAR16
*FileName
)
446 CHAR16
*TempStr
= NULL
;
448 EFI_GUID RefindGuid
= REFIND_GUID_VALUE
;
450 // Set a few defaults only if we're loading the default file.
451 if (MyStriCmp(FileName
, GlobalConfig
.ConfigFilename
)) {
452 MyFreePool(GlobalConfig
.AlsoScan
);
453 GlobalConfig
.AlsoScan
= StrDuplicate(ALSO_SCAN_DIRS
);
454 MyFreePool(GlobalConfig
.DontScanDirs
);
456 if (SelfVolume
->VolName
) {
457 TempStr
= SelfVolume
->VolName
? StrDuplicate(SelfVolume
->VolName
) : NULL
;
459 TempStr
= AllocateZeroPool(256 * sizeof(CHAR16
));
461 SPrint(TempStr
, 255, L
"fs%d", SelfVolume
->VolNumber
);
464 MergeStrings(&TempStr
, SelfDirPath
, L
':');
465 MergeStrings(&TempStr
, MEMTEST_LOCATIONS
, L
',');
466 GlobalConfig
.DontScanDirs
= TempStr
;
467 MyFreePool(GlobalConfig
.DontScanFiles
);
468 GlobalConfig
.DontScanFiles
= StrDuplicate(DONT_SCAN_FILES
);
469 MergeStrings(&(GlobalConfig
.DontScanFiles
), MOK_NAMES
, L
',');
470 MyFreePool(GlobalConfig
.DontScanVolumes
);
471 GlobalConfig
.DontScanVolumes
= StrDuplicate(DONT_SCAN_VOLUMES
);
472 GlobalConfig
.WindowsRecoveryFiles
= StrDuplicate(WINDOWS_RECOVERY_FILES
);
473 if (GlobalConfig
.DefaultSelection
!= NULL
) {
474 MyFreePool(GlobalConfig
.DefaultSelection
);
475 GlobalConfig
.DefaultSelection
= NULL
;
477 Status
= EfivarGetRaw(&RefindGuid
, L
"PreviousBoot", (CHAR8
**) &(GlobalConfig
.DefaultSelection
), &i
);
478 if (Status
!= EFI_SUCCESS
)
479 GlobalConfig
.DefaultSelection
= NULL
;
482 if (!FileExists(SelfDir
, FileName
)) {
483 Print(L
"Configuration file '%s' missing!\n", FileName
);
484 if (!FileExists(SelfDir
, L
"icons")) {
485 Print(L
"Icons directory doesn't exist; setting textonly = TRUE!\n");
486 GlobalConfig
.TextOnly
= TRUE
;
491 Status
= ReadFile(SelfDir
, FileName
, &File
, &i
);
492 if (EFI_ERROR(Status
))
496 TokenCount
= ReadTokenLine(&File
, &TokenList
);
500 if (MyStriCmp(TokenList
[0], L
"timeout")) {
501 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.Timeout
));
503 } else if (MyStriCmp(TokenList
[0], L
"hideui")) {
504 for (i
= 1; i
< TokenCount
; i
++) {
505 FlagName
= TokenList
[i
];
506 if (MyStriCmp(FlagName
, L
"banner")) {
507 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BANNER
;
508 } else if (MyStriCmp(FlagName
, L
"label")) {
509 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_LABEL
;
510 } else if (MyStriCmp(FlagName
, L
"singleuser")) {
511 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SINGLEUSER
;
512 } else if (MyStriCmp(FlagName
, L
"hwtest")) {
513 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HWTEST
;
514 } else if (MyStriCmp(FlagName
, L
"arrows")) {
515 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_ARROWS
;
516 } else if (MyStriCmp(FlagName
, L
"hints")) {
517 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HINTS
;
518 } else if (MyStriCmp(FlagName
, L
"editor")) {
519 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_EDITOR
;
520 } else if (MyStriCmp(FlagName
, L
"safemode")) {
521 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SAFEMODE
;
522 } else if (MyStriCmp(FlagName
, L
"badges")) {
523 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BADGES
;
524 } else if (MyStriCmp(FlagName
, L
"all")) {
525 GlobalConfig
.HideUIFlags
= HIDEUI_FLAG_ALL
;
527 Print(L
" unknown hideui flag: '%s'\n", FlagName
);
531 } else if (MyStriCmp(TokenList
[0], L
"icons_dir")) {
532 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.IconsDir
));
534 } else if (MyStriCmp(TokenList
[0], L
"scanfor")) {
535 for (i
= 0; i
< NUM_SCAN_OPTIONS
; i
++) {
537 GlobalConfig
.ScanFor
[i
] = TokenList
[i
][0];
539 GlobalConfig
.ScanFor
[i
] = ' ';
542 } else if (MyStriCmp(TokenList
[0], L
"uefi_deep_legacy_scan")) {
543 GlobalConfig
.DeepLegacyScan
= HandleBoolean(TokenList
, TokenCount
);
545 } else if (MyStriCmp(TokenList
[0], L
"scan_delay") && (TokenCount
== 2)) {
546 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.ScanDelay
));
548 } else if (MyStriCmp(TokenList
[0], L
"also_scan_dirs")) {
549 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.AlsoScan
));
551 } else if (MyStriCmp(TokenList
[0], L
"don't_scan_volumes") || MyStriCmp(TokenList
[0], L
"dont_scan_volumes")) {
552 // Note: Don't use HandleStrings() because it modifies slashes, which might be present in volume name
553 MyFreePool(GlobalConfig
.DontScanVolumes
);
554 GlobalConfig
.DontScanVolumes
= NULL
;
555 for (i
= 1; i
< TokenCount
; i
++) {
556 MergeStrings(&GlobalConfig
.DontScanVolumes
, TokenList
[i
], L
',');
559 } else if (MyStriCmp(TokenList
[0], L
"don't_scan_dirs") || MyStriCmp(TokenList
[0], L
"dont_scan_dirs")) {
560 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DontScanDirs
));
562 } else if (MyStriCmp(TokenList
[0], L
"don't_scan_files") || MyStriCmp(TokenList
[0], L
"dont_scan_files")) {
563 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DontScanFiles
));
565 } else if (MyStriCmp(TokenList
[0], L
"windows_recovery_files")) {
566 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.WindowsRecoveryFiles
));
568 } else if (MyStriCmp(TokenList
[0], L
"scan_driver_dirs")) {
569 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DriverDirs
));
571 } else if (MyStriCmp(TokenList
[0], L
"showtools")) {
572 SetMem(GlobalConfig
.ShowTools
, NUM_TOOLS
* sizeof(UINTN
), 0);
573 for (i
= 1; (i
< TokenCount
) && (i
< NUM_TOOLS
); i
++) {
574 FlagName
= TokenList
[i
];
575 if (MyStriCmp(FlagName
, L
"shell")) {
576 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHELL
;
577 } else if (MyStriCmp(FlagName
, L
"gptsync")) {
578 GlobalConfig
.ShowTools
[i
- 1] = TAG_GPTSYNC
;
579 } else if (MyStriCmp(FlagName
, L
"gdisk")) {
580 GlobalConfig
.ShowTools
[i
- 1] = TAG_GDISK
;
581 } else if (MyStriCmp(FlagName
, L
"about")) {
582 GlobalConfig
.ShowTools
[i
- 1] = TAG_ABOUT
;
583 } else if (MyStriCmp(FlagName
, L
"exit")) {
584 GlobalConfig
.ShowTools
[i
- 1] = TAG_EXIT
;
585 } else if (MyStriCmp(FlagName
, L
"reboot")) {
586 GlobalConfig
.ShowTools
[i
- 1] = TAG_REBOOT
;
587 } else if (MyStriCmp(FlagName
, L
"shutdown")) {
588 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHUTDOWN
;
589 } else if (MyStriCmp(FlagName
, L
"apple_recovery")) {
590 GlobalConfig
.ShowTools
[i
- 1] = TAG_APPLE_RECOVERY
;
591 } else if (MyStriCmp(FlagName
, L
"windows_recovery")) {
592 GlobalConfig
.ShowTools
[i
- 1] = TAG_WINDOWS_RECOVERY
;
593 } else if (MyStriCmp(FlagName
, L
"mok_tool")) {
594 GlobalConfig
.ShowTools
[i
- 1] = TAG_MOK_TOOL
;
595 } else if (MyStriCmp(FlagName
, L
"firmware")) {
596 GlobalConfig
.ShowTools
[i
- 1] = TAG_FIRMWARE
;
597 } else if (MyStriCmp(FlagName
, L
"memtest86") || MyStriCmp(FlagName
, L
"memtest")) {
598 GlobalConfig
.ShowTools
[i
- 1] = TAG_MEMTEST
;
599 } else if (MyStriCmp(FlagName
, L
"netboot")) {
600 GlobalConfig
.ShowTools
[i
- 1] = TAG_NETBOOT
;
602 Print(L
" unknown showtools flag: '%s'\n", FlagName
);
604 } // showtools options
606 } else if (MyStriCmp(TokenList
[0], L
"banner")) {
607 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.BannerFileName
));
609 } else if (MyStriCmp(TokenList
[0], L
"banner_scale") && (TokenCount
== 2)) {
610 if (MyStriCmp(TokenList
[1], L
"noscale")) {
611 GlobalConfig
.BannerScale
= BANNER_NOSCALE
;
612 } else if (MyStriCmp(TokenList
[1], L
"fillscreen") || MyStriCmp(TokenList
[1], L
"fullscreen")) {
613 GlobalConfig
.BannerScale
= BANNER_FILLSCREEN
;
615 Print(L
" unknown banner_type flag: '%s'\n", TokenList
[1]);
618 } else if (MyStriCmp(TokenList
[0], L
"small_icon_size") && (TokenCount
== 2)) {
619 HandleInt(TokenList
, TokenCount
, &i
);
621 GlobalConfig
.IconSizes
[ICON_SIZE_SMALL
] = i
;
623 } else if (MyStriCmp(TokenList
[0], L
"big_icon_size") && (TokenCount
== 2)) {
624 HandleInt(TokenList
, TokenCount
, &i
);
626 GlobalConfig
.IconSizes
[ICON_SIZE_BIG
] = i
;
627 GlobalConfig
.IconSizes
[ICON_SIZE_BADGE
] = i
/ 4;
630 } else if (MyStriCmp(TokenList
[0], L
"selection_small")) {
631 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionSmallFileName
));
633 } else if (MyStriCmp(TokenList
[0], L
"selection_big")) {
634 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionBigFileName
));
636 } else if (MyStriCmp(TokenList
[0], L
"default_selection")) {
637 if (TokenCount
== 4) {
638 SetDefaultByTime(TokenList
, &(GlobalConfig
.DefaultSelection
));
640 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.DefaultSelection
));
643 } else if (MyStriCmp(TokenList
[0], L
"textonly")) {
644 GlobalConfig
.TextOnly
= HandleBoolean(TokenList
, TokenCount
);
646 } else if (MyStriCmp(TokenList
[0], L
"textmode")) {
647 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.RequestedTextMode
));
649 } else if (MyStriCmp(TokenList
[0], L
"resolution") && ((TokenCount
== 2) || (TokenCount
== 3))) {
650 GlobalConfig
.RequestedScreenWidth
= Atoi(TokenList
[1]);
652 GlobalConfig
.RequestedScreenHeight
= Atoi(TokenList
[2]);
654 GlobalConfig
.RequestedScreenHeight
= 0;
656 } else if (MyStriCmp(TokenList
[0], L
"screensaver")) {
657 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.ScreensaverTime
));
659 } else if (MyStriCmp(TokenList
[0], L
"use_graphics_for")) {
660 if ((TokenCount
== 2) || ((TokenCount
> 2) && (!MyStriCmp(TokenList
[1], L
"+"))))
661 GlobalConfig
.GraphicsFor
= 0;
662 for (i
= 1; i
< TokenCount
; i
++) {
663 if (MyStriCmp(TokenList
[i
], L
"osx")) {
664 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_OSX
;
665 } else if (MyStriCmp(TokenList
[i
], L
"linux")) {
666 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_LINUX
;
667 } else if (MyStriCmp(TokenList
[i
], L
"elilo")) {
668 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_ELILO
;
669 } else if (MyStriCmp(TokenList
[i
], L
"grub")) {
670 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_GRUB
;
671 } else if (MyStriCmp(TokenList
[i
], L
"windows")) {
672 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_WINDOWS
;
674 } // for (graphics_on tokens)
676 } else if (MyStriCmp(TokenList
[0], L
"font") && (TokenCount
== 2)) {
677 egLoadFont(TokenList
[1]);
679 } else if (MyStriCmp(TokenList
[0], L
"scan_all_linux_kernels")) {
680 GlobalConfig
.ScanAllLinux
= HandleBoolean(TokenList
, TokenCount
);
682 } else if (MyStriCmp(TokenList
[0], L
"fold_linux_kernels")) {
683 GlobalConfig
.FoldLinuxKernels
= HandleBoolean(TokenList
, TokenCount
);
685 } else if (MyStriCmp(TokenList
[0], L
"max_tags")) {
686 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.MaxTags
));
688 } else if (MyStriCmp(TokenList
[0], L
"enable_and_lock_vmx")) {
689 GlobalConfig
.EnableAndLockVMX
= HandleBoolean(TokenList
, TokenCount
);
691 } else if (MyStriCmp(TokenList
[0], L
"include") && (TokenCount
== 2) && MyStriCmp(FileName
, GlobalConfig
.ConfigFilename
)) {
692 if (!MyStriCmp(TokenList
[1], FileName
)) {
693 ReadConfig(TokenList
[1]);
698 FreeTokenLine(&TokenList
, &TokenCount
);
700 if ((GlobalConfig
.DontScanFiles
) && (GlobalConfig
.WindowsRecoveryFiles
))
701 MergeStrings(&(GlobalConfig
.DontScanFiles
), GlobalConfig
.WindowsRecoveryFiles
, L
',');
702 MyFreePool(File
.Buffer
);
704 if (!FileExists(SelfDir
, L
"icons") && !FileExists(SelfDir
, GlobalConfig
.IconsDir
)) {
705 Print(L
"Icons directory doesn't exist; setting textonly = TRUE!\n");
706 GlobalConfig
.TextOnly
= TRUE
;
708 } /* VOID ReadConfig() */
710 // Finds a volume with the specified Identifier (a filesystem label, a
711 // partition name, a partition GUID, or a number followed by a colon). If
712 // found, sets *Volume to point to that volume. If not, leaves it unchanged.
713 // Returns TRUE if a match was found, FALSE if not.
714 static BOOLEAN
FindVolume(REFIT_VOLUME
**Volume
, CHAR16
*Identifier
) {
715 UINTN i
= 0, CountedVolumes
= 0, Length
;
717 BOOLEAN Found
= FALSE
, IdIsGuid
= FALSE
;
718 EFI_GUID VolGuid
, NullGuid
= NULL_GUID_VALUE
;
720 VolGuid
= StringAsGuid(Identifier
);
721 Length
= StrLen(Identifier
);
722 if ((Length
>= 2) && (Identifier
[Length
- 1] == L
':') &&
723 (Identifier
[0] >= L
'0') && (Identifier
[0] <= L
'9')) {
724 Number
= (INTN
) Atoi(Identifier
);
725 } else if (IsGuid(Identifier
)) {
728 while ((i
< VolumesCount
) && (!Found
)) {
729 if (Number
>= 0) { // User specified a volume by number
730 if (Volumes
[i
]->IsReadable
) {
731 if (CountedVolumes
== Number
) {
732 *Volume
= Volumes
[i
];
737 } else { // User specified a volume by label or GUID
738 if (MyStriCmp(Identifier
, Volumes
[i
]->VolName
) || MyStriCmp(Identifier
, Volumes
[i
]->PartName
)) {
739 *Volume
= Volumes
[i
];
742 if (IdIsGuid
&& !Found
) {
743 if (GuidsAreEqual(&VolGuid
, &(Volumes
[i
]->PartGuid
)) && !GuidsAreEqual(&NullGuid
, &(Volumes
[i
]->PartGuid
))) {
744 *Volume
= Volumes
[i
];
752 } // static VOID FindVolume()
754 static VOID
AddSubmenu(LOADER_ENTRY
*Entry
, REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
755 REFIT_MENU_SCREEN
*SubScreen
;
756 LOADER_ENTRY
*SubEntry
;
760 SubScreen
= InitializeSubScreen(Entry
);
762 // Set defaults for the new entry; will be modified based on lines read from the config. file....
763 SubEntry
= InitializeLoaderEntry(Entry
);
765 if ((SubEntry
== NULL
) || (SubScreen
== NULL
))
767 SubEntry
->me
.Title
= StrDuplicate(Title
);
769 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StrCmp(TokenList
[0], L
"}") != 0)) {
771 if (MyStriCmp(TokenList
[0], L
"loader") && (TokenCount
> 1)) { // set the boot loader filename
772 MyFreePool(SubEntry
->LoaderPath
);
773 SubEntry
->LoaderPath
= StrDuplicate(TokenList
[1]);
774 SubEntry
->DevicePath
= FileDevicePath(Volume
->DeviceHandle
, SubEntry
->LoaderPath
);
776 } else if (MyStriCmp(TokenList
[0], L
"volume") && (TokenCount
> 1)) {
777 if (FindVolume(&Volume
, TokenList
[1])) {
778 if ((Volume
!= NULL
) && (Volume
->IsReadable
) && (Volume
->RootDir
)) {
779 MyFreePool(SubEntry
->me
.Title
);
780 SubEntry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
781 SPrint(SubEntry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", Volume
->VolName
);
782 SubEntry
->me
.BadgeImage
= Volume
->VolBadgeImage
;
783 SubEntry
->VolName
= Volume
->VolName
;
784 } // if volume is readable
787 } else if (MyStriCmp(TokenList
[0], L
"initrd")) {
788 MyFreePool(SubEntry
->InitrdPath
);
789 SubEntry
->InitrdPath
= NULL
;
790 if (TokenCount
> 1) {
791 SubEntry
->InitrdPath
= StrDuplicate(TokenList
[1]);
794 } else if (MyStriCmp(TokenList
[0], L
"options")) {
795 MyFreePool(SubEntry
->LoadOptions
);
796 SubEntry
->LoadOptions
= NULL
;
797 if (TokenCount
> 1) {
798 SubEntry
->LoadOptions
= StrDuplicate(TokenList
[1]);
801 } else if (MyStriCmp(TokenList
[0], L
"add_options") && (TokenCount
> 1)) {
802 MergeStrings(&SubEntry
->LoadOptions
, TokenList
[1], L
' ');
804 } else if (MyStriCmp(TokenList
[0], L
"graphics") && (TokenCount
> 1)) {
805 SubEntry
->UseGraphicsMode
= MyStriCmp(TokenList
[1], L
"on");
807 } else if (MyStriCmp(TokenList
[0], L
"disabled")) {
808 SubEntry
->Enabled
= FALSE
;
811 FreeTokenLine(&TokenList
, &TokenCount
);
814 if (SubEntry
->InitrdPath
!= NULL
) {
815 MergeStrings(&SubEntry
->LoadOptions
, L
"initrd=", L
' ');
816 MergeStrings(&SubEntry
->LoadOptions
, SubEntry
->InitrdPath
, 0);
817 MyFreePool(SubEntry
->InitrdPath
);
818 SubEntry
->InitrdPath
= NULL
;
820 if (SubEntry
->Enabled
== TRUE
) {
821 AddMenuEntry(SubScreen
, (REFIT_MENU_ENTRY
*)SubEntry
);
823 Entry
->me
.SubScreen
= SubScreen
;
824 } // VOID AddSubmenu()
826 // Adds the options from a SINGLE refind.conf stanza to a new loader entry and returns
827 // that entry. The calling function is then responsible for adding the entry to the
829 static LOADER_ENTRY
* AddStanzaEntries(REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
833 BOOLEAN DefaultsSet
= FALSE
, AddedSubmenu
= FALSE
;
834 REFIT_VOLUME
*CurrentVolume
= Volume
;
836 // prepare the menu entry
837 Entry
= InitializeLoaderEntry(NULL
);
841 Entry
->Title
= StrDuplicate(Title
);
842 Entry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
843 SPrint(Entry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
845 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
846 Entry
->VolName
= CurrentVolume
->VolName
;
848 // Parse the config file to add options for a single stanza, terminating when the token
849 // is "}" or when the end of file is reached.
850 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StrCmp(TokenList
[0], L
"}") != 0)) {
851 if (MyStriCmp(TokenList
[0], L
"loader") && (TokenCount
> 1)) { // set the boot loader filename
852 Entry
->LoaderPath
= StrDuplicate(TokenList
[1]);
853 Entry
->DevicePath
= FileDevicePath(CurrentVolume
->DeviceHandle
, Entry
->LoaderPath
);
854 SetLoaderDefaults(Entry
, TokenList
[1], CurrentVolume
);
855 MyFreePool(Entry
->LoadOptions
);
856 Entry
->LoadOptions
= NULL
; // Discard default options, if any
859 } else if (MyStriCmp(TokenList
[0], L
"volume") && (TokenCount
> 1)) {
860 if (FindVolume(&CurrentVolume
, TokenList
[1])) {
861 if ((CurrentVolume
!= NULL
) && (CurrentVolume
->IsReadable
) && (CurrentVolume
->RootDir
)) {
862 MyFreePool(Entry
->me
.Title
);
863 Entry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
864 SPrint(Entry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
865 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
866 Entry
->VolName
= CurrentVolume
->VolName
;
867 } // if volume is readable
870 } else if (MyStriCmp(TokenList
[0], L
"icon") && (TokenCount
> 1)) {
871 MyFreePool(Entry
->me
.Image
);
872 Entry
->me
.Image
= egLoadIcon(CurrentVolume
->RootDir
, TokenList
[1], GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
873 if (Entry
->me
.Image
== NULL
) {
874 Entry
->me
.Image
= DummyImage(GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
877 } else if (MyStriCmp(TokenList
[0], L
"initrd") && (TokenCount
> 1)) {
878 MyFreePool(Entry
->InitrdPath
);
879 Entry
->InitrdPath
= StrDuplicate(TokenList
[1]);
881 } else if (MyStriCmp(TokenList
[0], L
"options") && (TokenCount
> 1)) {
882 MyFreePool(Entry
->LoadOptions
);
883 Entry
->LoadOptions
= StrDuplicate(TokenList
[1]);
885 } else if (MyStriCmp(TokenList
[0], L
"ostype") && (TokenCount
> 1)) {
886 if (TokenCount
> 1) {
887 Entry
->OSType
= TokenList
[1][0];
890 } else if (MyStriCmp(TokenList
[0], L
"graphics") && (TokenCount
> 1)) {
891 Entry
->UseGraphicsMode
= MyStriCmp(TokenList
[1], L
"on");
893 } else if (MyStriCmp(TokenList
[0], L
"disabled")) {
894 Entry
->Enabled
= FALSE
;
896 } else if (MyStriCmp(TokenList
[0], L
"submenuentry") && (TokenCount
> 1)) {
897 AddSubmenu(Entry
, File
, CurrentVolume
, TokenList
[1]);
900 } // set options to pass to the loader program
901 FreeTokenLine(&TokenList
, &TokenCount
);
905 AddMenuEntry(Entry
->me
.SubScreen
, &MenuEntryReturn
);
907 if (Entry
->InitrdPath
) {
908 MergeStrings(&Entry
->LoadOptions
, L
"initrd=", L
' ');
909 MergeStrings(&Entry
->LoadOptions
, Entry
->InitrdPath
, 0);
910 MyFreePool(Entry
->InitrdPath
);
911 Entry
->InitrdPath
= NULL
;
915 SetLoaderDefaults(Entry
, L
"\\EFI\\BOOT\\nemo.efi", CurrentVolume
); // user included no "loader" line; use bogus one
918 } // static VOID AddStanzaEntries()
920 // Read the user-configured menu entries from refind.conf and add or delete
921 // entries based on the contents of that file....
922 VOID
ScanUserConfigured(CHAR16
*FileName
)
926 REFIT_VOLUME
*Volume
;
928 CHAR16
*Title
= NULL
;
929 UINTN TokenCount
, size
;
932 if (FileExists(SelfDir
, FileName
)) {
933 Status
= ReadFile(SelfDir
, FileName
, &File
, &size
);
934 if (EFI_ERROR(Status
))
939 while ((TokenCount
= ReadTokenLine(&File
, &TokenList
)) > 0) {
940 if (MyStriCmp(TokenList
[0], L
"menuentry") && (TokenCount
> 1)) {
941 Title
= StrDuplicate(TokenList
[1]);
942 Entry
= AddStanzaEntries(&File
, Volume
, TokenList
[1]);
943 if (Entry
->Enabled
) {
944 if (Entry
->me
.SubScreen
== NULL
)
945 GenerateSubScreen(Entry
, Volume
, TRUE
);
946 AddPreparedLoaderEntry(Entry
);
952 } else if (MyStriCmp(TokenList
[0], L
"include") && (TokenCount
== 2) &&
953 MyStriCmp(FileName
, GlobalConfig
.ConfigFilename
)) {
954 if (!MyStriCmp(TokenList
[1], FileName
)) {
955 ScanUserConfigured(TokenList
[1]);
959 FreeTokenLine(&TokenList
, &TokenCount
);
962 } // VOID ScanUserConfigured()
964 // Create an options file based on /etc/fstab. The resulting file has two options
965 // lines, one of which boots the system with "ro root={rootfs}" and the other of
966 // which boots the system with "ro root={rootfs} single", where "{rootfs}" is the
967 // filesystem identifier associated with the "/" line in /etc/fstab.
968 static REFIT_FILE
* GenerateOptionsFromEtcFstab(REFIT_VOLUME
*Volume
) {
970 REFIT_FILE
*Options
= NULL
, *Fstab
= NULL
;
972 CHAR16
**TokenList
, *Line
, Root
[100];
974 if (FileExists(Volume
->RootDir
, L
"\\etc\\fstab")) {
975 Options
= AllocateZeroPool(sizeof(REFIT_FILE
));
976 Fstab
= AllocateZeroPool(sizeof(REFIT_FILE
));
977 Status
= ReadFile(Volume
->RootDir
, L
"\\etc\\fstab", Fstab
, &i
);
978 if (CheckError(Status
, L
"while reading /etc/fstab")) {
985 } else { // File read; locate root fs and create entries
986 Options
->Encoding
= ENCODING_UTF16_LE
;
987 while ((TokenCount
= ReadTokenLine(Fstab
, &TokenList
)) > 0) {
988 if (TokenCount
> 2) {
990 if (StrCmp(TokenList
[1], L
"\\") == 0) {
991 SPrint(Root
, 99, L
"%s", TokenList
[0]);
992 } else if (StrCmp(TokenList
[2], L
"\\") == 0) {
993 SPrint(Root
, 99, L
"%s=%s", TokenList
[0], TokenList
[1]);
994 } // if/elseif/elseif
995 if (Root
[0] != L
'\0') {
996 for (i
= 0; i
< StrLen(Root
); i
++)
999 Line
= PoolPrint(L
"\"Boot with normal options\" \"ro root=%s\"\n", Root
);
1000 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1002 Line
= PoolPrint(L
"\"Boot into single-user mode\" \"ro root=%s single\"\n", Root
);
1003 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1004 Options
->BufferSize
= StrLen((CHAR16
*) Options
->Buffer
) * sizeof(CHAR16
);
1007 FreeTokenLine(&TokenList
, &TokenCount
);
1010 if (Options
->Buffer
) {
1011 Options
->Current8Ptr
= (CHAR8
*)Options
->Buffer
;
1012 Options
->End8Ptr
= Options
->Current8Ptr
+ Options
->BufferSize
;
1013 Options
->Current16Ptr
= (CHAR16
*)Options
->Buffer
;
1014 Options
->End16Ptr
= Options
->Current16Ptr
+ (Options
->BufferSize
>> 1);
1016 MyFreePool(Options
);
1020 MyFreePool(Fstab
->Buffer
);
1022 } // if/else file read error
1023 } // if /etc/fstab exists
1025 } // GenerateOptionsFromEtcFstab()
1027 // Create options from partition type codes. Specifically, if the earlier
1028 // partition scan found a partition with a type code corresponding to a root
1029 // filesystem according to the Freedesktop.org Discoverable Partitions Spec
1030 // (http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/),
1031 // this function returns an appropriate file with two lines, one with
1032 // "ro root=/dev/disk/by-partuuid/{GUID}" and the other with that plus "single".
1033 // Note that this function returns the LAST partition found with the
1034 // appropriate type code, so this will work poorly on dual-boot systems or
1035 // if the type code is set incorrectly.
1036 static REFIT_FILE
* GenerateOptionsFromPartTypes(VOID
) {
1037 REFIT_FILE
*Options
= NULL
;
1038 CHAR16
*Line
, *GuidString
, *WriteStatus
;
1040 if (GlobalConfig
.DiscoveredRoot
) {
1041 Options
= AllocateZeroPool(sizeof(REFIT_FILE
));
1043 Options
->Encoding
= ENCODING_UTF16_LE
;
1044 GuidString
= GuidAsString(&(GlobalConfig
.DiscoveredRoot
->PartGuid
));
1045 WriteStatus
= GlobalConfig
.DiscoveredRoot
->IsMarkedReadOnly
? L
"ro" : L
"rw";
1046 ToLower(GuidString
);
1048 Line
= PoolPrint(L
"\"Boot with normal options\" \"%s root=/dev/disk/by-partuuid/%s\"\n", WriteStatus
, GuidString
);
1049 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1051 Line
= PoolPrint(L
"\"Boot into single-user mode\" \"%s root=/dev/disk/by-partuuid/%s single\"\n", WriteStatus
, GuidString
);
1052 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1054 MyFreePool(GuidString
);
1055 } // if (GuidString)
1056 Options
->BufferSize
= StrLen((CHAR16
*) Options
->Buffer
) * sizeof(CHAR16
);
1058 Options
->Current8Ptr
= (CHAR8
*)Options
->Buffer
;
1059 Options
->End8Ptr
= Options
->Current8Ptr
+ Options
->BufferSize
;
1060 Options
->Current16Ptr
= (CHAR16
*)Options
->Buffer
;
1061 Options
->End16Ptr
= Options
->Current16Ptr
+ (Options
->BufferSize
>> 1);
1062 } // if (Options allocated OK)
1063 } // if (partition has root GUID)
1065 } // REFIT_FILE * GenerateOptionsFromPartTypes()
1067 // Read a Linux kernel options file for a Linux boot loader into memory. The LoaderPath
1068 // and Volume variables identify the location of the options file, but not its name --
1069 // you pass this function the filename of the Linux kernel, initial RAM disk, or other
1070 // file in the target directory, and this function finds the file with a name in the
1071 // comma-delimited list of names specified by LINUX_OPTIONS_FILENAMES within that
1072 // directory and loads it. This function tries multiple files because I originally
1073 // used the filename linux.conf, but close on the heels of that decision, the Linux
1074 // kernel developers decided to use that name for a similar purpose, but with a
1075 // different file format. Thus, I'm migrating rEFInd to use the name refind_linux.conf,
1076 // but I want a migration period in which both names are used.
1077 // If a rEFInd options file can't be found, try to generate minimal options from
1078 // /etc/fstab on the same volume as the kernel. This typically works only if the
1079 // kernel is being read from the Linux root filesystem.
1081 // The return value is a pointer to the REFIT_FILE handle for the file, or NULL if
1083 REFIT_FILE
* ReadLinuxOptionsFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
1084 CHAR16
*OptionsFilename
, *FullFilename
;
1085 BOOLEAN GoOn
= TRUE
, FileFound
= FALSE
;
1087 REFIT_FILE
*File
= NULL
;
1091 OptionsFilename
= FindCommaDelimited(LINUX_OPTIONS_FILENAMES
, i
++);
1092 FullFilename
= FindPath(LoaderPath
);
1093 if ((OptionsFilename
!= NULL
) && (FullFilename
!= NULL
)) {
1094 MergeStrings(&FullFilename
, OptionsFilename
, '\\');
1095 if (FileExists(Volume
->RootDir
, FullFilename
)) {
1096 File
= AllocateZeroPool(sizeof(REFIT_FILE
));
1097 Status
= ReadFile(Volume
->RootDir
, FullFilename
, File
, &size
);
1098 if (CheckError(Status
, L
"while loading the Linux options file")) {
1107 } else { // a filename string is NULL
1110 MyFreePool(OptionsFilename
);
1111 MyFreePool(FullFilename
);
1112 OptionsFilename
= FullFilename
= NULL
;
1115 // No refind_linux.conf file; look for /etc/fstab and try to pull values from there....
1116 File
= GenerateOptionsFromEtcFstab(Volume
);
1117 // If still no joy, try to use Freedesktop.org Discoverable Partitions Spec....
1119 File
= GenerateOptionsFromPartTypes();
1122 } // static REFIT_FILE * ReadLinuxOptionsFile()
1124 // Retrieve a single line of options from a Linux kernel options file
1125 CHAR16
* GetFirstOptionsFromFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
1127 CHAR16
*Options
= NULL
;
1131 File
= ReadLinuxOptionsFile(LoaderPath
, Volume
);
1133 TokenCount
= ReadTokenLine(File
, &TokenList
);
1135 Options
= StrDuplicate(TokenList
[1]);
1136 FreeTokenLine(&TokenList
, &TokenCount
);
1140 } // static CHAR16 * GetOptionsFile()