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 (StriCmp(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) && (StriCmp(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) && ((StriCmp(TokenList
[1], L
"0") == 0) ||
394 (StriCmp(TokenList
[1], L
"false") == 0) ||
395 (StriCmp(TokenList
[1], L
"off") == 0))) {
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 (StriCmp(FileName
, GlobalConfig
.ConfigFilename
) == 0) {
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 (StriCmp(TokenList
[0], L
"timeout") == 0) {
501 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.Timeout
));
503 } else if (StriCmp(TokenList
[0], L
"hideui") == 0) {
504 for (i
= 1; i
< TokenCount
; i
++) {
505 FlagName
= TokenList
[i
];
506 if (StriCmp(FlagName
, L
"banner") == 0) {
507 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BANNER
;
508 } else if (StriCmp(FlagName
, L
"label") == 0) {
509 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_LABEL
;
510 } else if (StriCmp(FlagName
, L
"singleuser") == 0) {
511 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SINGLEUSER
;
512 } else if (StriCmp(FlagName
, L
"hwtest") == 0) {
513 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HWTEST
;
514 } else if (StriCmp(FlagName
, L
"arrows") == 0) {
515 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_ARROWS
;
516 } else if (StriCmp(FlagName
, L
"hints") == 0) {
517 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HINTS
;
518 } else if (StriCmp(FlagName
, L
"editor") == 0) {
519 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_EDITOR
;
520 } else if (StriCmp(FlagName
, L
"safemode") == 0) {
521 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SAFEMODE
;
522 } else if (StriCmp(FlagName
, L
"badges") == 0) {
523 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BADGES
;
524 } else if (StriCmp(FlagName
, L
"all") == 0) {
525 GlobalConfig
.HideUIFlags
= HIDEUI_FLAG_ALL
;
527 Print(L
" unknown hideui flag: '%s'\n", FlagName
);
531 } else if (StriCmp(TokenList
[0], L
"icons_dir") == 0) {
532 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.IconsDir
));
534 } else if (StriCmp(TokenList
[0], L
"scanfor") == 0) {
535 for (i
= 0; i
< NUM_SCAN_OPTIONS
; i
++) {
537 GlobalConfig
.ScanFor
[i
] = TokenList
[i
][0];
539 GlobalConfig
.ScanFor
[i
] = ' ';
542 } else if (StriCmp(TokenList
[0], L
"uefi_deep_legacy_scan") == 0) {
543 GlobalConfig
.DeepLegacyScan
= HandleBoolean(TokenList
, TokenCount
);
545 } else if ((StriCmp(TokenList
[0], L
"scan_delay") == 0) && (TokenCount
== 2)) {
546 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.ScanDelay
));
548 } else if (StriCmp(TokenList
[0], L
"also_scan_dirs") == 0) {
549 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.AlsoScan
));
551 } else if ((StriCmp(TokenList
[0], L
"don't_scan_volumes") == 0) || (StriCmp(TokenList
[0], L
"dont_scan_volumes") == 0)) {
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 ((StriCmp(TokenList
[0], L
"don't_scan_dirs") == 0) || (StriCmp(TokenList
[0], L
"dont_scan_dirs") == 0)) {
560 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DontScanDirs
));
562 } else if ((StriCmp(TokenList
[0], L
"don't_scan_files") == 0) || (StriCmp(TokenList
[0], L
"dont_scan_files") == 0)) {
563 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DontScanFiles
));
565 } else if (StriCmp(TokenList
[0], L
"windows_recovery_files") == 0) {
566 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.WindowsRecoveryFiles
));
568 } else if (StriCmp(TokenList
[0], L
"scan_driver_dirs") == 0) {
569 HandleStrings(TokenList
, TokenCount
, &(GlobalConfig
.DriverDirs
));
571 } else if (StriCmp(TokenList
[0], L
"showtools") == 0) {
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 (StriCmp(FlagName
, L
"shell") == 0) {
576 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHELL
;
577 } else if (StriCmp(FlagName
, L
"gptsync") == 0) {
578 GlobalConfig
.ShowTools
[i
- 1] = TAG_GPTSYNC
;
579 } else if (StriCmp(FlagName
, L
"gdisk") == 0) {
580 GlobalConfig
.ShowTools
[i
- 1] = TAG_GDISK
;
581 } else if (StriCmp(FlagName
, L
"about") == 0) {
582 GlobalConfig
.ShowTools
[i
- 1] = TAG_ABOUT
;
583 } else if (StriCmp(FlagName
, L
"exit") == 0) {
584 GlobalConfig
.ShowTools
[i
- 1] = TAG_EXIT
;
585 } else if (StriCmp(FlagName
, L
"reboot") == 0) {
586 GlobalConfig
.ShowTools
[i
- 1] = TAG_REBOOT
;
587 } else if (StriCmp(FlagName
, L
"shutdown") == 0) {
588 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHUTDOWN
;
589 } else if (StriCmp(FlagName
, L
"apple_recovery") == 0) {
590 GlobalConfig
.ShowTools
[i
- 1] = TAG_APPLE_RECOVERY
;
591 } else if (StriCmp(FlagName
, L
"windows_recovery") == 0) {
592 GlobalConfig
.ShowTools
[i
- 1] = TAG_WINDOWS_RECOVERY
;
593 } else if (StriCmp(FlagName
, L
"mok_tool") == 0) {
594 GlobalConfig
.ShowTools
[i
- 1] = TAG_MOK_TOOL
;
595 } else if (StriCmp(FlagName
, L
"firmware") == 0) {
596 GlobalConfig
.ShowTools
[i
- 1] = TAG_FIRMWARE
;
597 } else if ((StriCmp(FlagName
, L
"memtest86") == 0) || (StriCmp(FlagName
, L
"memtest") == 0)) {
598 GlobalConfig
.ShowTools
[i
- 1] = TAG_MEMTEST
;
599 } else if (StriCmp(FlagName
, L
"netboot") == 0) {
600 GlobalConfig
.ShowTools
[i
- 1] = TAG_NETBOOT
;
602 Print(L
" unknown showtools flag: '%s'\n", FlagName
);
604 } // showtools options
606 } else if (StriCmp(TokenList
[0], L
"banner") == 0) {
607 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.BannerFileName
));
609 } else if ((StriCmp(TokenList
[0], L
"banner_scale") == 0) && (TokenCount
== 2)) {
610 if (StriCmp(TokenList
[1], L
"noscale") == 0) {
611 GlobalConfig
.BannerScale
= BANNER_NOSCALE
;
612 } else if ((StriCmp(TokenList
[1], L
"fillscreen") == 0) || (StriCmp(TokenList
[1], L
"fullscreen") == 0)) {
613 GlobalConfig
.BannerScale
= BANNER_FILLSCREEN
;
615 Print(L
" unknown banner_type flag: '%s'\n", TokenList
[1]);
618 } else if ((StriCmp(TokenList
[0], L
"small_icon_size") == 0) && (TokenCount
== 2)) {
619 HandleInt(TokenList
, TokenCount
, &i
);
621 GlobalConfig
.IconSizes
[ICON_SIZE_SMALL
] = i
;
623 } else if ((StriCmp(TokenList
[0], L
"big_icon_size") == 0) && (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 (StriCmp(TokenList
[0], L
"selection_small") == 0) {
631 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionSmallFileName
));
633 } else if (StriCmp(TokenList
[0], L
"selection_big") == 0) {
634 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionBigFileName
));
636 } else if (StriCmp(TokenList
[0], L
"default_selection") == 0) {
637 if (TokenCount
== 4) {
638 SetDefaultByTime(TokenList
, &(GlobalConfig
.DefaultSelection
));
640 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.DefaultSelection
));
643 } else if (StriCmp(TokenList
[0], L
"textonly") == 0) {
644 GlobalConfig
.TextOnly
= HandleBoolean(TokenList
, TokenCount
);
646 } else if (StriCmp(TokenList
[0], L
"textmode") == 0) {
647 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.RequestedTextMode
));
649 } else if ((StriCmp(TokenList
[0], L
"resolution") == 0) && ((TokenCount
== 2) || (TokenCount
== 3))) {
650 GlobalConfig
.RequestedScreenWidth
= Atoi(TokenList
[1]);
652 GlobalConfig
.RequestedScreenHeight
= Atoi(TokenList
[2]);
654 GlobalConfig
.RequestedScreenHeight
= 0;
656 } else if (StriCmp(TokenList
[0], L
"screensaver") == 0) {
657 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.ScreensaverTime
));
659 } else if (StriCmp(TokenList
[0], L
"use_graphics_for") == 0) {
660 if ((TokenCount
== 2) || ((TokenCount
> 2) && (StriCmp(TokenList
[1], L
"+") != 0)))
661 GlobalConfig
.GraphicsFor
= 0;
662 for (i
= 1; i
< TokenCount
; i
++) {
663 if (StriCmp(TokenList
[i
], L
"osx") == 0) {
664 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_OSX
;
665 } else if (StriCmp(TokenList
[i
], L
"linux") == 0) {
666 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_LINUX
;
667 } else if (StriCmp(TokenList
[i
], L
"elilo") == 0) {
668 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_ELILO
;
669 } else if (StriCmp(TokenList
[i
], L
"grub") == 0) {
670 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_GRUB
;
671 } else if (StriCmp(TokenList
[i
], L
"windows") == 0) {
672 GlobalConfig
.GraphicsFor
|= GRAPHICS_FOR_WINDOWS
;
674 } // for (graphics_on tokens)
676 } else if ((StriCmp(TokenList
[0], L
"font") == 0) && (TokenCount
== 2)) {
677 egLoadFont(TokenList
[1]);
679 } else if (StriCmp(TokenList
[0], L
"scan_all_linux_kernels") == 0) {
680 GlobalConfig
.ScanAllLinux
= HandleBoolean(TokenList
, TokenCount
);
682 } else if (StriCmp(TokenList
[0], L
"fold_linux_kernels") == 0) {
683 GlobalConfig
.FoldLinuxKernels
= HandleBoolean(TokenList
, TokenCount
);
685 } else if (StriCmp(TokenList
[0], L
"max_tags") == 0) {
686 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.MaxTags
));
688 } else if (StriCmp(TokenList
[0], L
"enable_and_lock_vmx") == 0) {
689 GlobalConfig
.EnableAndLockVMX
= HandleBoolean(TokenList
, TokenCount
);
691 } else if ((StriCmp(TokenList
[0], L
"include") == 0) && (TokenCount
== 2) &&
692 (StriCmp(FileName
, GlobalConfig
.ConfigFilename
) == 0)) {
693 if (StriCmp(TokenList
[1], FileName
) != 0) {
694 ReadConfig(TokenList
[1]);
699 FreeTokenLine(&TokenList
, &TokenCount
);
701 if ((GlobalConfig
.DontScanFiles
) && (GlobalConfig
.WindowsRecoveryFiles
))
702 MergeStrings(&(GlobalConfig
.DontScanFiles
), GlobalConfig
.WindowsRecoveryFiles
, L
',');
703 MyFreePool(File
.Buffer
);
705 if (!FileExists(SelfDir
, L
"icons") && !FileExists(SelfDir
, GlobalConfig
.IconsDir
)) {
706 Print(L
"Icons directory doesn't exist; setting textonly = TRUE!\n");
707 GlobalConfig
.TextOnly
= TRUE
;
709 } /* VOID ReadConfig() */
711 // Finds a volume with the specified Identifier (a filesystem label, a
712 // partition name, a partition GUID, or a number followed by a colon). If
713 // found, sets *Volume to point to that volume. If not, leaves it unchanged.
714 // Returns TRUE if a match was found, FALSE if not.
715 static BOOLEAN
FindVolume(REFIT_VOLUME
**Volume
, CHAR16
*Identifier
) {
716 UINTN i
= 0, CountedVolumes
= 0, Length
;
718 BOOLEAN Found
= FALSE
, IdIsGuid
= FALSE
;
719 EFI_GUID VolGuid
, NullGuid
= NULL_GUID_VALUE
;
721 VolGuid
= StringAsGuid(Identifier
);
722 Length
= StrLen(Identifier
);
723 if ((Length
>= 2) && (Identifier
[Length
- 1] == L
':') &&
724 (Identifier
[0] >= L
'0') && (Identifier
[0] <= L
'9')) {
725 Number
= (INTN
) Atoi(Identifier
);
726 } else if (IsGuid(Identifier
)) {
729 while ((i
< VolumesCount
) && (!Found
)) {
730 if (Number
>= 0) { // User specified a volume by number
731 if (Volumes
[i
]->IsReadable
) {
732 if (CountedVolumes
== Number
) {
733 *Volume
= Volumes
[i
];
738 } else { // User specified a volume by label or GUID
739 if ((StriCmp(Identifier
, Volumes
[i
]->VolName
) == 0) ||
740 (StriCmp(Identifier
, Volumes
[i
]->PartName
) == 0)) {
741 *Volume
= Volumes
[i
];
744 if (IdIsGuid
&& !Found
) {
745 if (GuidsAreEqual(&VolGuid
, &(Volumes
[i
]->PartGuid
)) && !GuidsAreEqual(&NullGuid
, &(Volumes
[i
]->PartGuid
))) {
746 *Volume
= Volumes
[i
];
754 } // static VOID FindVolume()
756 static VOID
AddSubmenu(LOADER_ENTRY
*Entry
, REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
757 REFIT_MENU_SCREEN
*SubScreen
;
758 LOADER_ENTRY
*SubEntry
;
762 SubScreen
= InitializeSubScreen(Entry
);
764 // Set defaults for the new entry; will be modified based on lines read from the config. file....
765 SubEntry
= InitializeLoaderEntry(Entry
);
767 if ((SubEntry
== NULL
) || (SubScreen
== NULL
))
769 SubEntry
->me
.Title
= StrDuplicate(Title
);
771 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StriCmp(TokenList
[0], L
"}") != 0)) {
773 if ((StriCmp(TokenList
[0], L
"loader") == 0) && (TokenCount
> 1)) { // set the boot loader filename
774 MyFreePool(SubEntry
->LoaderPath
);
775 SubEntry
->LoaderPath
= StrDuplicate(TokenList
[1]);
776 SubEntry
->DevicePath
= FileDevicePath(Volume
->DeviceHandle
, SubEntry
->LoaderPath
);
778 } else if ((StriCmp(TokenList
[0], L
"volume") == 0) && (TokenCount
> 1)) {
779 if (FindVolume(&Volume
, TokenList
[1])) {
780 if ((Volume
!= NULL
) && (Volume
->IsReadable
) && (Volume
->RootDir
)) {
781 MyFreePool(SubEntry
->me
.Title
);
782 SubEntry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
783 SPrint(SubEntry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", Volume
->VolName
);
784 SubEntry
->me
.BadgeImage
= Volume
->VolBadgeImage
;
785 SubEntry
->VolName
= Volume
->VolName
;
786 } // if volume is readable
789 } else if (StriCmp(TokenList
[0], L
"initrd") == 0) {
790 MyFreePool(SubEntry
->InitrdPath
);
791 SubEntry
->InitrdPath
= NULL
;
792 if (TokenCount
> 1) {
793 SubEntry
->InitrdPath
= StrDuplicate(TokenList
[1]);
796 } else if (StriCmp(TokenList
[0], L
"options") == 0) {
797 MyFreePool(SubEntry
->LoadOptions
);
798 SubEntry
->LoadOptions
= NULL
;
799 if (TokenCount
> 1) {
800 SubEntry
->LoadOptions
= StrDuplicate(TokenList
[1]);
803 } else if ((StriCmp(TokenList
[0], L
"add_options") == 0) && (TokenCount
> 1)) {
804 MergeStrings(&SubEntry
->LoadOptions
, TokenList
[1], L
' ');
806 } else if ((StriCmp(TokenList
[0], L
"graphics") == 0) && (TokenCount
> 1)) {
807 SubEntry
->UseGraphicsMode
= (StriCmp(TokenList
[1], L
"on") == 0);
809 } else if (StriCmp(TokenList
[0], L
"disabled") == 0) {
810 SubEntry
->Enabled
= FALSE
;
813 FreeTokenLine(&TokenList
, &TokenCount
);
816 if (SubEntry
->InitrdPath
!= NULL
) {
817 MergeStrings(&SubEntry
->LoadOptions
, L
"initrd=", L
' ');
818 MergeStrings(&SubEntry
->LoadOptions
, SubEntry
->InitrdPath
, 0);
819 MyFreePool(SubEntry
->InitrdPath
);
820 SubEntry
->InitrdPath
= NULL
;
822 if (SubEntry
->Enabled
== TRUE
) {
823 AddMenuEntry(SubScreen
, (REFIT_MENU_ENTRY
*)SubEntry
);
825 Entry
->me
.SubScreen
= SubScreen
;
826 } // VOID AddSubmenu()
828 // Adds the options from a SINGLE refind.conf stanza to a new loader entry and returns
829 // that entry. The calling function is then responsible for adding the entry to the
831 static LOADER_ENTRY
* AddStanzaEntries(REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
835 BOOLEAN DefaultsSet
= FALSE
, AddedSubmenu
= FALSE
;
836 REFIT_VOLUME
*CurrentVolume
= Volume
;
838 // prepare the menu entry
839 Entry
= InitializeLoaderEntry(NULL
);
843 Entry
->Title
= StrDuplicate(Title
);
844 Entry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
845 SPrint(Entry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
847 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
848 Entry
->VolName
= CurrentVolume
->VolName
;
850 // Parse the config file to add options for a single stanza, terminating when the token
851 // is "}" or when the end of file is reached.
852 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StriCmp(TokenList
[0], L
"}") != 0)) {
853 if ((StriCmp(TokenList
[0], L
"loader") == 0) && (TokenCount
> 1)) { // set the boot loader filename
854 Entry
->LoaderPath
= StrDuplicate(TokenList
[1]);
855 Entry
->DevicePath
= FileDevicePath(CurrentVolume
->DeviceHandle
, Entry
->LoaderPath
);
856 SetLoaderDefaults(Entry
, TokenList
[1], CurrentVolume
);
857 MyFreePool(Entry
->LoadOptions
);
858 Entry
->LoadOptions
= NULL
; // Discard default options, if any
861 } else if ((StriCmp(TokenList
[0], L
"volume") == 0) && (TokenCount
> 1)) {
862 if (FindVolume(&CurrentVolume
, TokenList
[1])) {
863 if ((CurrentVolume
!= NULL
) && (CurrentVolume
->IsReadable
) && (CurrentVolume
->RootDir
)) {
864 MyFreePool(Entry
->me
.Title
);
865 Entry
->me
.Title
= AllocateZeroPool(256 * sizeof(CHAR16
));
866 SPrint(Entry
->me
.Title
, 255, L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
867 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
868 Entry
->VolName
= CurrentVolume
->VolName
;
869 } // if volume is readable
872 } else if ((StriCmp(TokenList
[0], L
"icon") == 0) && (TokenCount
> 1)) {
873 MyFreePool(Entry
->me
.Image
);
874 Entry
->me
.Image
= egLoadIcon(CurrentVolume
->RootDir
, TokenList
[1], GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
875 if (Entry
->me
.Image
== NULL
) {
876 Entry
->me
.Image
= DummyImage(GlobalConfig
.IconSizes
[ICON_SIZE_BIG
]);
879 } else if ((StriCmp(TokenList
[0], L
"initrd") == 0) && (TokenCount
> 1)) {
880 MyFreePool(Entry
->InitrdPath
);
881 Entry
->InitrdPath
= StrDuplicate(TokenList
[1]);
883 } else if ((StriCmp(TokenList
[0], L
"options") == 0) && (TokenCount
> 1)) {
884 MyFreePool(Entry
->LoadOptions
);
885 Entry
->LoadOptions
= StrDuplicate(TokenList
[1]);
887 } else if ((StriCmp(TokenList
[0], L
"ostype") == 0) && (TokenCount
> 1)) {
888 if (TokenCount
> 1) {
889 Entry
->OSType
= TokenList
[1][0];
892 } else if ((StriCmp(TokenList
[0], L
"graphics") == 0) && (TokenCount
> 1)) {
893 Entry
->UseGraphicsMode
= (StriCmp(TokenList
[1], L
"on") == 0);
895 } else if (StriCmp(TokenList
[0], L
"disabled") == 0) {
896 Entry
->Enabled
= FALSE
;
898 } else if ((StriCmp(TokenList
[0], L
"submenuentry") == 0) && (TokenCount
> 1)) {
899 AddSubmenu(Entry
, File
, CurrentVolume
, TokenList
[1]);
902 } // set options to pass to the loader program
903 FreeTokenLine(&TokenList
, &TokenCount
);
907 AddMenuEntry(Entry
->me
.SubScreen
, &MenuEntryReturn
);
909 if (Entry
->InitrdPath
) {
910 MergeStrings(&Entry
->LoadOptions
, L
"initrd=", L
' ');
911 MergeStrings(&Entry
->LoadOptions
, Entry
->InitrdPath
, 0);
912 MyFreePool(Entry
->InitrdPath
);
913 Entry
->InitrdPath
= NULL
;
917 SetLoaderDefaults(Entry
, L
"\\EFI\\BOOT\\nemo.efi", CurrentVolume
); // user included no "loader" line; use bogus one
920 } // static VOID AddStanzaEntries()
922 // Read the user-configured menu entries from refind.conf and add or delete
923 // entries based on the contents of that file....
924 VOID
ScanUserConfigured(CHAR16
*FileName
)
928 REFIT_VOLUME
*Volume
;
930 CHAR16
*Title
= NULL
;
931 UINTN TokenCount
, size
;
934 if (FileExists(SelfDir
, FileName
)) {
935 Status
= ReadFile(SelfDir
, FileName
, &File
, &size
);
936 if (EFI_ERROR(Status
))
941 while ((TokenCount
= ReadTokenLine(&File
, &TokenList
)) > 0) {
942 if ((StriCmp(TokenList
[0], L
"menuentry") == 0) && (TokenCount
> 1)) {
943 Title
= StrDuplicate(TokenList
[1]);
944 Entry
= AddStanzaEntries(&File
, Volume
, TokenList
[1]);
945 if (Entry
->Enabled
) {
946 if (Entry
->me
.SubScreen
== NULL
)
947 GenerateSubScreen(Entry
, Volume
, TRUE
);
948 AddPreparedLoaderEntry(Entry
);
954 } else if ((StriCmp(TokenList
[0], L
"include") == 0) && (TokenCount
== 2) &&
955 (StriCmp(FileName
, GlobalConfig
.ConfigFilename
) == 0)) {
956 if (StriCmp(TokenList
[1], FileName
) != 0) {
957 ScanUserConfigured(TokenList
[1]);
961 FreeTokenLine(&TokenList
, &TokenCount
);
964 } // VOID ScanUserConfigured()
966 // Create an options file based on /etc/fstab. The resulting file has two options
967 // lines, one of which boots the system with "ro root={rootfs}" and the other of
968 // which boots the system with "ro root={rootfs} single", where "{rootfs}" is the
969 // filesystem identifier associated with the "/" line in /etc/fstab.
970 static REFIT_FILE
* GenerateOptionsFromEtcFstab(REFIT_VOLUME
*Volume
) {
972 REFIT_FILE
*Options
= NULL
, *Fstab
= NULL
;
974 CHAR16
**TokenList
, *Line
, Root
[100];
976 if (FileExists(Volume
->RootDir
, L
"\\etc\\fstab")) {
977 Options
= AllocateZeroPool(sizeof(REFIT_FILE
));
978 Fstab
= AllocateZeroPool(sizeof(REFIT_FILE
));
979 Status
= ReadFile(Volume
->RootDir
, L
"\\etc\\fstab", Fstab
, &i
);
980 if (CheckError(Status
, L
"while reading /etc/fstab")) {
987 } else { // File read; locate root fs and create entries
988 Options
->Encoding
= ENCODING_UTF16_LE
;
989 while ((TokenCount
= ReadTokenLine(Fstab
, &TokenList
)) > 0) {
990 if (TokenCount
> 2) {
992 if (StriCmp(TokenList
[1], L
"\\") == 0) {
993 SPrint(Root
, 99, L
"%s", TokenList
[0]);
994 } else if (StriCmp(TokenList
[2], L
"\\") == 0) {
995 SPrint(Root
, 99, L
"%s=%s", TokenList
[0], TokenList
[1]);
996 } // if/elseif/elseif
997 if (Root
[0] != L
'\0') {
998 for (i
= 0; i
< StrLen(Root
); i
++)
1001 Line
= PoolPrint(L
"\"Boot with normal options\" \"ro root=%s\"\n", Root
);
1002 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1004 Line
= PoolPrint(L
"\"Boot into single-user mode\" \"ro root=%s single\"\n", Root
);
1005 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1006 Options
->BufferSize
= StrLen((CHAR16
*) Options
->Buffer
) * sizeof(CHAR16
);
1009 FreeTokenLine(&TokenList
, &TokenCount
);
1012 Options
->Current8Ptr
= (CHAR8
*)Options
->Buffer
;
1013 Options
->End8Ptr
= Options
->Current8Ptr
+ Options
->BufferSize
;
1014 Options
->Current16Ptr
= (CHAR16
*)Options
->Buffer
;
1015 Options
->End16Ptr
= Options
->Current16Ptr
+ (Options
->BufferSize
>> 1);
1017 MyFreePool(Fstab
->Buffer
);
1019 } // if/else file read error
1020 } // if /etc/fstab exists
1022 } // GenerateOptionsFromEtcFstab()
1024 // Create options from partition type codes. Specifically, if the earlier
1025 // partition scan found a partition with a type code corresponding to a root
1026 // filesystem according to the Freedesktop.org Discoverable Partitions Spec
1027 // (http://www.freedesktop.org/wiki/Specifications/DiscoverablePartitionsSpec/),
1028 // this function returns an appropriate file with two lines, one with
1029 // "ro root=PARTUUID={GUID}" and the other with that plus "single".
1030 // Note that this function returns the LAST partition found with the
1031 // appropriate type code, so this will work poorly on dual-boot systems or
1032 // if the type code is set incorrectly.
1033 static REFIT_FILE
* GenerateOptionsFromPartTypes(VOID
) {
1034 REFIT_FILE
*Options
= NULL
;
1035 CHAR16
*Line
, *GuidString
;
1037 if (GlobalConfig
.DiscoveredRoot
) {
1038 Options
= AllocateZeroPool(sizeof(REFIT_FILE
));
1040 Options
->Encoding
= ENCODING_UTF16_LE
;
1041 GuidString
= GuidAsString(&(GlobalConfig
.DiscoveredRoot
->PartGuid
));
1042 ToLower(GuidString
);
1044 Line
= PoolPrint(L
"\"Boot with normal options\" \"ro root=/dev/disk/by-partuuid/%s\"\n", GuidString
);
1045 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1047 Line
= PoolPrint(L
"\"Boot into single-user mode\" \"ro root=/dev/disk/by-partuuid/%s single\"\n", GuidString
);
1048 MergeStrings((CHAR16
**) &(Options
->Buffer
), Line
, 0);
1050 MyFreePool(GuidString
);
1051 } // if (GuidString)
1052 Options
->BufferSize
= StrLen((CHAR16
*) Options
->Buffer
) * sizeof(CHAR16
);
1054 Options
->Current8Ptr
= (CHAR8
*)Options
->Buffer
;
1055 Options
->End8Ptr
= Options
->Current8Ptr
+ Options
->BufferSize
;
1056 Options
->Current16Ptr
= (CHAR16
*)Options
->Buffer
;
1057 Options
->End16Ptr
= Options
->Current16Ptr
+ (Options
->BufferSize
>> 1);
1058 } // if (Options allocated OK)
1059 } // if (partition has root GUID)
1061 } // REFIT_FILE * GenerateOptionsFromPartTypes()
1063 // Read a Linux kernel options file for a Linux boot loader into memory. The LoaderPath
1064 // and Volume variables identify the location of the options file, but not its name --
1065 // you pass this function the filename of the Linux kernel, initial RAM disk, or other
1066 // file in the target directory, and this function finds the file with a name in the
1067 // comma-delimited list of names specified by LINUX_OPTIONS_FILENAMES within that
1068 // directory and loads it. This function tries multiple files because I originally
1069 // used the filename linux.conf, but close on the heels of that decision, the Linux
1070 // kernel developers decided to use that name for a similar purpose, but with a
1071 // different file format. Thus, I'm migrating rEFInd to use the name refind_linux.conf,
1072 // but I want a migration period in which both names are used.
1073 // If a rEFInd options file can't be found, try to generate minimal options from
1074 // /etc/fstab on the same volume as the kernel. This typically works only if the
1075 // kernel is being read from the Linux root filesystem.
1077 // The return value is a pointer to the REFIT_FILE handle for the file, or NULL if
1079 REFIT_FILE
* ReadLinuxOptionsFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
1080 CHAR16
*OptionsFilename
, *FullFilename
;
1081 BOOLEAN GoOn
= TRUE
, FileFound
= FALSE
;
1083 REFIT_FILE
*File
= NULL
;
1087 OptionsFilename
= FindCommaDelimited(LINUX_OPTIONS_FILENAMES
, i
++);
1088 FullFilename
= FindPath(LoaderPath
);
1089 if ((OptionsFilename
!= NULL
) && (FullFilename
!= NULL
)) {
1090 MergeStrings(&FullFilename
, OptionsFilename
, '\\');
1091 if (FileExists(Volume
->RootDir
, FullFilename
)) {
1092 File
= AllocateZeroPool(sizeof(REFIT_FILE
));
1093 Status
= ReadFile(Volume
->RootDir
, FullFilename
, File
, &size
);
1094 if (CheckError(Status
, L
"while loading the Linux options file")) {
1103 } else { // a filename string is NULL
1106 MyFreePool(OptionsFilename
);
1107 MyFreePool(FullFilename
);
1108 OptionsFilename
= FullFilename
= NULL
;
1111 // No refind_linux.conf file; look for /etc/fstab and try to pull values from there....
1112 File
= GenerateOptionsFromEtcFstab(Volume
);
1113 // If still no joy, try to use Freedesktop.org Discoverable Partitions Spec....
1115 File
= GenerateOptionsFromPartTypes();
1118 } // static REFIT_FILE * ReadLinuxOptionsFile()
1120 // Retrieve a single line of options from a Linux kernel options file
1121 CHAR16
* GetFirstOptionsFromFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
1123 CHAR16
*Options
= NULL
;
1127 File
= ReadLinuxOptionsFile(LoaderPath
, Volume
);
1129 TokenCount
= ReadTokenLine(File
, &TokenList
);
1131 Options
= StrDuplicate(TokenList
[1]);
1132 FreeTokenLine(&TokenList
, &TokenCount
);
1136 } // static CHAR16 * GetOptionsFile()