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 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 "refit_call_wrapper.h"
56 #define CONFIG_FILE_NAME L"refind.conf"
57 #define LINUX_OPTIONS_FILENAMES L"refind_linux.conf,refind-linux.conf,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 static REFIT_MENU_ENTRY MenuEntryReturn
= { L
"Return to Main Menu", TAG_RETURN
, 0, 0, 0, NULL
, NULL
, NULL
};
67 // read a file into a buffer
70 static EFI_STATUS
ReadFile(IN EFI_FILE_HANDLE BaseDir
, CHAR16
*FileName
, REFIT_FILE
*File
)
73 EFI_FILE_HANDLE FileHandle
;
74 EFI_FILE_INFO
*FileInfo
;
80 // read the file, allocating a buffer on the way
81 Status
= refit_call5_wrapper(BaseDir
->Open
, BaseDir
, &FileHandle
, FileName
, EFI_FILE_MODE_READ
, 0);
82 if (CheckError(Status
, L
"while loading the configuration file"))
85 FileInfo
= LibFileInfo(FileHandle
);
86 if (FileInfo
== NULL
) {
87 // TODO: print and register the error
88 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
89 return EFI_LOAD_ERROR
;
91 ReadSize
= FileInfo
->FileSize
;
92 if (ReadSize
> MAXCONFIGFILESIZE
)
93 ReadSize
= MAXCONFIGFILESIZE
;
96 File
->BufferSize
= (UINTN
)ReadSize
; // was limited to a few K before, so this is safe
97 File
->Buffer
= AllocatePool(File
->BufferSize
);
98 Status
= refit_call3_wrapper(FileHandle
->Read
, FileHandle
, &File
->BufferSize
, File
->Buffer
);
99 if (CheckError(Status
, L
"while loading the configuration file")) {
100 FreePool(File
->Buffer
);
102 refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
105 Status
= refit_call1_wrapper(FileHandle
->Close
, FileHandle
);
108 File
->Current8Ptr
= (CHAR8
*)File
->Buffer
;
109 File
->End8Ptr
= File
->Current8Ptr
+ File
->BufferSize
;
110 File
->Current16Ptr
= (CHAR16
*)File
->Buffer
;
111 File
->End16Ptr
= File
->Current16Ptr
+ (File
->BufferSize
>> 1);
114 File
->Encoding
= ENCODING_ISO8859_1
; // default: 1:1 translation of CHAR8 to CHAR16
115 if (File
->BufferSize
>= 4) {
116 if (File
->Buffer
[0] == 0xFF && File
->Buffer
[1] == 0xFE) {
117 // BOM in UTF-16 little endian (or UTF-32 little endian)
118 File
->Encoding
= ENCODING_UTF16_LE
; // use CHAR16 as is
119 File
->Current16Ptr
++;
120 } else if (File
->Buffer
[0] == 0xEF && File
->Buffer
[1] == 0xBB && File
->Buffer
[2] == 0xBF) {
122 File
->Encoding
= ENCODING_UTF8
; // translate from UTF-8 to UTF-16
123 File
->Current8Ptr
+= 3;
124 } else if (File
->Buffer
[1] == 0 && File
->Buffer
[3] == 0) {
125 File
->Encoding
= ENCODING_UTF16_LE
; // use CHAR16 as is
127 // TODO: detect other encodings as they are implemented
134 // get a single line of text from a file
137 static CHAR16
*ReadLine(REFIT_FILE
*File
)
142 if (File
->Buffer
== NULL
)
145 if (File
->Encoding
== ENCODING_ISO8859_1
|| File
->Encoding
== ENCODING_UTF8
) {
147 CHAR8
*p
, *LineStart
, *LineEnd
;
149 p
= File
->Current8Ptr
;
150 if (p
>= File
->End8Ptr
)
154 for (; p
< File
->End8Ptr
; p
++)
155 if (*p
== 13 || *p
== 10)
158 for (; p
< File
->End8Ptr
; p
++)
159 if (*p
!= 13 && *p
!= 10)
161 File
->Current8Ptr
= p
;
163 LineLength
= (UINTN
)(LineEnd
- LineStart
) + 1;
164 Line
= AllocatePool(LineLength
* sizeof(CHAR16
));
169 if (File
->Encoding
== ENCODING_ISO8859_1
) {
170 for (p
= LineStart
; p
< LineEnd
; )
172 } else if (File
->Encoding
== ENCODING_UTF8
) {
173 // TODO: actually handle UTF-8
174 for (p
= LineStart
; p
< LineEnd
; )
179 } else if (File
->Encoding
== ENCODING_UTF16_LE
) {
181 CHAR16
*p
, *LineStart
, *LineEnd
;
183 p
= File
->Current16Ptr
;
184 if (p
>= File
->End16Ptr
)
188 for (; p
< File
->End16Ptr
; p
++)
189 if (*p
== 13 || *p
== 10)
192 for (; p
< File
->End16Ptr
; p
++)
193 if (*p
!= 13 && *p
!= 10)
195 File
->Current16Ptr
= p
;
197 LineLength
= (UINTN
)(LineEnd
- LineStart
) + 1;
198 Line
= AllocatePool(LineLength
* sizeof(CHAR16
));
202 for (p
= LineStart
, q
= Line
; p
< LineEnd
; )
207 return NULL
; // unsupported encoding
213 // get a line of tokens from a file
216 UINTN
ReadTokenLine(IN REFIT_FILE
*File
, OUT CHAR16
***TokenList
)
218 BOOLEAN LineFinished
, IsQuoted
= FALSE
;
219 CHAR16
*Line
, *Token
, *p
;
220 UINTN TokenCount
= 0;
224 while (TokenCount
== 0) {
225 Line
= ReadLine(File
);
230 LineFinished
= FALSE
;
231 while (!LineFinished
) {
233 while ((*p
== ' ' || *p
== '\t' || *p
== '=' || *p
== ',') && !IsQuoted
)
235 if (*p
== 0 || *p
== '#')
239 IsQuoted
= !IsQuoted
;
245 while (*p
&& *p
!= '"' && ((*p
!= ' ' && *p
!= '\t' && *p
!= '=' && *p
!= '#' && *p
!= ',') || IsQuoted
)) {
246 if ((*p
== '/') && !IsQuoted
) // Switch Unix-style to DOS-style directory separators
251 IsQuoted
= !IsQuoted
;
252 if (*p
== 0 || *p
== '#')
256 AddListElement((VOID
***)TokenList
, &TokenCount
, (VOID
*)StrDuplicate(Token
));
262 } /* ReadTokenLine() */
264 VOID
FreeTokenLine(IN OUT CHAR16
***TokenList
, IN OUT UINTN
*TokenCount
)
266 // TODO: also free the items
267 FreeList((VOID
***)TokenList
, TokenCount
);
271 // handle a parameter with a single integer argument
274 static VOID
HandleInt(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT UINTN
*Value
)
276 if (TokenCount
< 2) {
279 if (TokenCount
> 2) {
282 *Value
= Atoi(TokenList
[1]);
286 // handle a parameter with a single string argument
289 static VOID
HandleString(IN CHAR16
**TokenList
, IN UINTN TokenCount
, OUT CHAR16
**Value
)
291 if (TokenCount
< 2) {
294 if (TokenCount
> 2) {
297 *Value
= StrDuplicate(TokenList
[1]);
304 VOID
ReadConfig(VOID
)
312 if (!FileExists(SelfDir
, CONFIG_FILE_NAME
)) {
313 Print(L
"Configuration file missing!\n");
317 Status
= ReadFile(SelfDir
, CONFIG_FILE_NAME
, &File
);
318 if (EFI_ERROR(Status
))
322 TokenCount
= ReadTokenLine(&File
, &TokenList
);
326 if (StriCmp(TokenList
[0], L
"timeout") == 0) {
327 HandleInt(TokenList
, TokenCount
, &(GlobalConfig
.Timeout
));
329 // Note: I'm using "disable" as equivalent to "hideui" for the moment (as of rEFInd 0.2.4)
330 // because I've folded two options into one and removed some values, so I want to catch
331 // existing configurations as much as possible. The "disable" equivalency to "hideui" will
332 // be removed sooner or later, leaving only "hideui".
333 } else if ((StriCmp(TokenList
[0], L
"hideui") == 0) || (StriCmp(TokenList
[0], L
"disable") == 0)) {
334 for (i
= 1; i
< TokenCount
; i
++) {
335 FlagName
= TokenList
[i
];
336 if (StriCmp(FlagName
, L
"banner") == 0) {
337 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_BANNER
;
338 } else if (StriCmp(FlagName
, L
"label") == 0) {
339 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_LABEL
;
340 } else if (StriCmp(FlagName
, L
"singleuser") == 0) {
341 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_SINGLEUSER
;
342 } else if (StriCmp(FlagName
, L
"hwtest") == 0) {
343 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_HWTEST
;
344 } else if (StriCmp(FlagName
, L
"arrows") == 0) {
345 GlobalConfig
.HideUIFlags
|= HIDEUI_FLAG_ARROWS
;
346 } else if (StriCmp(FlagName
, L
"all") == 0) {
347 GlobalConfig
.HideUIFlags
= HIDEUI_ALL
;
349 Print(L
" unknown hideui flag: '%s'\n", FlagName
);
353 } else if (StriCmp(TokenList
[0], L
"scanfor") == 0) {
354 for (i
= 0; i
< NUM_SCAN_OPTIONS
; i
++) {
356 GlobalConfig
.ScanFor
[i
] = TokenList
[i
][0];
358 GlobalConfig
.ScanFor
[i
] = ' ';
360 } else if (StriCmp(TokenList
[0], L
"showtools") == 0) {
361 SetMem(GlobalConfig
.ShowTools
, NUM_TOOLS
* sizeof(UINTN
), 0);
362 for (i
= 1; (i
< TokenCount
) && (i
< NUM_TOOLS
); i
++) {
363 FlagName
= TokenList
[i
];
364 if (StriCmp(FlagName
, L
"shell") == 0) {
365 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHELL
;
366 } else if (StriCmp(FlagName
, L
"gptsync") == 0) {
367 GlobalConfig
.ShowTools
[i
- 1] = TAG_GPTSYNC
;
368 } else if (StriCmp(FlagName
, L
"about") == 0) {
369 GlobalConfig
.ShowTools
[i
- 1] = TAG_ABOUT
;
370 } else if (StriCmp(FlagName
, L
"exit") == 0) {
371 GlobalConfig
.ShowTools
[i
- 1] = TAG_EXIT
;
372 } else if (StriCmp(FlagName
, L
"reboot") == 0) {
373 GlobalConfig
.ShowTools
[i
- 1] = TAG_REBOOT
;
374 } else if (StriCmp(FlagName
, L
"shutdown") == 0) {
375 GlobalConfig
.ShowTools
[i
- 1] = TAG_SHUTDOWN
;
377 Print(L
" unknown showtools flag: '%s'\n", FlagName
);
379 } // showtools options
381 } else if (StriCmp(TokenList
[0], L
"banner") == 0) {
382 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.BannerFileName
));
384 } else if (StriCmp(TokenList
[0], L
"selection_small") == 0) {
385 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionSmallFileName
));
387 } else if (StriCmp(TokenList
[0], L
"selection_big") == 0) {
388 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.SelectionBigFileName
));
390 } else if (StriCmp(TokenList
[0], L
"default_selection") == 0) {
391 HandleString(TokenList
, TokenCount
, &(GlobalConfig
.DefaultSelection
));
393 } else if (StriCmp(TokenList
[0], L
"textonly") == 0) {
394 GlobalConfig
.TextOnly
= TRUE
;
396 } else if ((StriCmp(TokenList
[0], L
"}") == 0) || (StriCmp(TokenList
[0], L
"loader") == 0) ||
397 (StriCmp(TokenList
[0], L
"icon") == 0) || (StriCmp(TokenList
[0], L
"options") == 0)) {
398 // Do nothing; handled by ScanUserConfigured()
399 } else if ((StriCmp(TokenList
[0], L
"max_tags") == 0) && (TokenCount
> 1)) {
400 GlobalConfig
.MaxTags
= Atoi(TokenList
[1]);
403 FreeTokenLine(&TokenList
, &TokenCount
);
405 FreePool(File
.Buffer
);
406 } /* VOID ReadConfig() */
408 static VOID
AddSubmenu(LOADER_ENTRY
*Entry
, REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
409 REFIT_MENU_SCREEN
*SubScreen
;
410 LOADER_ENTRY
*SubEntry
;
414 SubScreen
= InitializeSubScreen(Entry
);
416 // Set defaults for the new entry; will be modified based on lines read from the config. file....
417 SubEntry
= InitializeLoaderEntry(Entry
);
419 if ((SubEntry
== NULL
) || (SubScreen
== NULL
))
421 SubEntry
->me
.Title
= StrDuplicate(Title
);
423 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StriCmp(TokenList
[0], L
"}") != 0)) {
424 if ((StriCmp(TokenList
[0], L
"loader") == 0) && (TokenCount
> 1)) { // set the boot loader filename
425 if (SubEntry
->LoaderPath
!= NULL
)
426 FreePool(SubEntry
->LoaderPath
);
427 SubEntry
->LoaderPath
= StrDuplicate(TokenList
[1]);
428 SubEntry
->DevicePath
= FileDevicePath(Volume
->DeviceHandle
, SubEntry
->LoaderPath
);
429 } else if (StriCmp(TokenList
[0], L
"initrd") == 0) {
430 if (SubEntry
->InitrdPath
!= NULL
)
431 FreePool(SubEntry
->InitrdPath
);
432 SubEntry
->InitrdPath
= NULL
;
433 if (TokenCount
> 1) {
434 SubEntry
->InitrdPath
= StrDuplicate(TokenList
[1]);
436 } else if (StriCmp(TokenList
[0], L
"options") == 0) {
437 if (SubEntry
->LoadOptions
!= NULL
)
438 FreePool(SubEntry
->LoadOptions
);
439 SubEntry
->LoadOptions
= NULL
;
440 if (TokenCount
> 1) {
441 SubEntry
->LoadOptions
= StrDuplicate(TokenList
[1]);
443 } else if ((StriCmp(TokenList
[0], L
"add_options") == 0) && (TokenCount
> 1)) {
444 MergeStrings(&SubEntry
->LoadOptions
, TokenList
[1], L
' ');
445 } else if ((StriCmp(TokenList
[0], L
"graphics") == 0) && (TokenCount
> 1)) {
446 SubEntry
->UseGraphicsMode
= (StriCmp(TokenList
[1], L
"on") == 0);
447 } else if (StriCmp(TokenList
[0], L
"disabled") == 0) {
448 SubEntry
->Enabled
= FALSE
;
450 FreeTokenLine(&TokenList
, &TokenCount
);
452 if (SubEntry
->InitrdPath
!= NULL
) {
453 MergeStrings(&SubEntry
->LoadOptions
, L
"initrd=", L
' ');
454 MergeStrings(&SubEntry
->LoadOptions
, SubEntry
->InitrdPath
, 0);
455 FreePool(SubEntry
->InitrdPath
);
456 SubEntry
->InitrdPath
= NULL
;
458 if (SubEntry
->Enabled
== TRUE
) {
459 AddMenuEntry(SubScreen
, (REFIT_MENU_ENTRY
*)SubEntry
);
461 Entry
->me
.SubScreen
= SubScreen
;
462 } // VOID AddSubmenu()
464 // Finds a volume with the specified Identifier (a volume label, for the moment).
465 // If found, sets *Volume to point to that volume. If not, leaves it unchanged.
466 // Returns TRUE if a match was found, FALSE if not.
467 static BOOLEAN
FindVolume(REFIT_VOLUME
**Volume
, CHAR16
*Identifier
) {
469 BOOLEAN Found
= FALSE
;
471 while ((i
< VolumesCount
) && (!Found
)) {
472 if (StriCmp(Identifier
, Volumes
[i
]->VolName
) == 0) {
473 *Volume
= Volumes
[i
];
479 } // static VOID FindVolume()
481 // Adds the options from a SINGLE loaders.conf stanza to a new loader entry and returns
482 // that entry. The calling function is then responsible for adding the entry to the
484 static LOADER_ENTRY
* AddStanzaEntries(REFIT_FILE
*File
, REFIT_VOLUME
*Volume
, CHAR16
*Title
) {
488 BOOLEAN DefaultsSet
= FALSE
, AddedSubmenu
= FALSE
;
489 REFIT_VOLUME
*CurrentVolume
= Volume
;
491 // prepare the menu entry
492 Entry
= InitializeLoaderEntry(NULL
);
496 Entry
->Title
= StrDuplicate(Title
);
497 Entry
->me
.Title
= PoolPrint(L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
499 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
500 Entry
->VolName
= CurrentVolume
->VolName
;
502 // Parse the config file to add options for a single stanza, terminating when the token
503 // is "}" or when the end of file is reached.
504 while (((TokenCount
= ReadTokenLine(File
, &TokenList
)) > 0) && (StriCmp(TokenList
[0], L
"}") != 0)) {
505 if ((StriCmp(TokenList
[0], L
"loader") == 0) && (TokenCount
> 1)) { // set the boot loader filename
506 Entry
->LoaderPath
= StrDuplicate(TokenList
[1]);
507 Entry
->DevicePath
= FileDevicePath(CurrentVolume
->DeviceHandle
, Entry
->LoaderPath
);
508 SetLoaderDefaults(Entry
, TokenList
[1], CurrentVolume
);
509 FreePool(Entry
->LoadOptions
);
510 Entry
->LoadOptions
= NULL
; // Discard default options, if any
512 } else if ((StriCmp(TokenList
[0], L
"volume") == 0) && (TokenCount
> 1)) {
513 if (FindVolume(&CurrentVolume
, TokenList
[1])) {
514 FreePool(Entry
->me
.Title
);
515 Entry
->me
.Title
= PoolPrint(L
"Boot %s from %s", (Title
!= NULL
) ? Title
: L
"Unknown", CurrentVolume
->VolName
);
516 Entry
->me
.BadgeImage
= CurrentVolume
->VolBadgeImage
;
517 Entry
->VolName
= CurrentVolume
->VolName
;
519 } else if ((StriCmp(TokenList
[0], L
"icon") == 0) && (TokenCount
> 1)) {
520 FreePool(Entry
->me
.Image
);
521 Entry
->me
.Image
= LoadIcns(CurrentVolume
->RootDir
, TokenList
[1], 128);
522 if (Entry
->me
.Image
== NULL
) {
523 Entry
->me
.Image
= DummyImage(128);
525 } else if ((StriCmp(TokenList
[0], L
"initrd") == 0) && (TokenCount
> 1)) {
526 if (Entry
->InitrdPath
)
527 FreePool(Entry
->InitrdPath
);
528 Entry
->InitrdPath
= StrDuplicate(TokenList
[1]);
529 } else if ((StriCmp(TokenList
[0], L
"options") == 0) && (TokenCount
> 1)) {
530 if (Entry
->LoadOptions
)
531 FreePool(Entry
->LoadOptions
);
532 Entry
->LoadOptions
= StrDuplicate(TokenList
[1]);
533 } else if ((StriCmp(TokenList
[0], L
"ostype") == 0) && (TokenCount
> 1)) {
534 if (TokenCount
> 1) {
535 Entry
->OSType
= TokenList
[1][0];
537 } else if ((StriCmp(TokenList
[0], L
"graphics") == 0) && (TokenCount
> 1)) {
538 Entry
->UseGraphicsMode
= (StriCmp(TokenList
[1], L
"on") == 0);
539 } else if (StriCmp(TokenList
[0], L
"disabled") == 0) {
540 Entry
->Enabled
= FALSE
;
541 } else if ((StriCmp(TokenList
[0], L
"submenuentry") == 0) && (TokenCount
> 1)) {
542 AddSubmenu(Entry
, File
, CurrentVolume
, TokenList
[1]);
544 } // set options to pass to the loader program
545 FreeTokenLine(&TokenList
, &TokenCount
);
549 AddMenuEntry(Entry
->me
.SubScreen
, &MenuEntryReturn
);
551 if (Entry
->InitrdPath
) {
552 MergeStrings(&Entry
->LoadOptions
, L
"initrd=", L
' ');
553 MergeStrings(&Entry
->LoadOptions
, Entry
->InitrdPath
, 0);
554 FreePool(Entry
->InitrdPath
);
555 Entry
->InitrdPath
= NULL
;
559 SetLoaderDefaults(Entry
, L
"\\EFI\\BOOT\\nemo.efi", CurrentVolume
); // user included no entry; use bogus one
562 } // static VOID AddStanzaEntries()
564 // Read the user-configured loaders file, refind_loaders.conf, and add or delete
565 // entries based on the contents of that file....
566 VOID
ScanUserConfigured(VOID
)
570 REFIT_VOLUME
*Volume
;
572 CHAR16
*Title
= NULL
;
576 if (FileExists(SelfDir
, CONFIG_FILE_NAME
)) {
577 Status
= ReadFile(SelfDir
, CONFIG_FILE_NAME
, &File
);
578 if (EFI_ERROR(Status
))
582 // TODO: Figure out how to set volumes (on per-image basis, preferably)
584 while ((TokenCount
= ReadTokenLine(&File
, &TokenList
)) > 0) {
585 if ((StriCmp(TokenList
[0], L
"menuentry") == 0) && (TokenCount
> 1)) {
586 Title
= StrDuplicate(TokenList
[1]);
587 Entry
= AddStanzaEntries(&File
, Volume
, TokenList
[1]);
588 if (Entry
->Enabled
) {
589 if (Entry
->me
.SubScreen
== NULL
)
590 GenerateSubScreen(Entry
, Volume
);
591 AddPreparedLoaderEntry(Entry
);
597 FreeTokenLine(&TokenList
, &TokenCount
);
600 } // VOID ScanUserConfigured()
602 // Read a Linux kernel options file for a Linux boot loader into memory. The LoaderPath
603 // and Volume variables identify the location of the options file, but not its name --
604 // you pass this function the filename of the Linux kernel, initial RAM disk, or other
605 // file in the target directory, and this function finds the file with a name in the
606 // comma-delimited list of names specified by LINUX_OPTIONS_FILENAMES within that
607 // directory and loads it. This function tries multiple files because I originally
608 // used the filename linux.conf, but close on the heels of that decision, the Linux
609 // kernel developers decided to use that name for a similar purpose, but with a
610 // different file format. Thus, I'm migrating rEFInd to use the name refind_linux.conf,
611 // but I want a migration period in which both names are used.
613 // The return value is a pointer to the REFIT_FILE handle for the file, or NULL if
615 REFIT_FILE
* ReadLinuxOptionsFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
616 CHAR16
*OptionsFilename
, *FullFilename
;
619 REFIT_FILE
*File
= NULL
;
623 OptionsFilename
= FindCommaDelimited(LINUX_OPTIONS_FILENAMES
, i
++);
624 FullFilename
= FindPath(LoaderPath
);
625 if ((OptionsFilename
!= NULL
) && (FullFilename
!= NULL
)) {
626 MergeStrings(&FullFilename
, OptionsFilename
, '\\');
627 if (FileExists(Volume
->RootDir
, FullFilename
)) {
628 File
= AllocateZeroPool(sizeof(REFIT_FILE
));
629 Status
= ReadFile(Volume
->RootDir
, FullFilename
, File
);
631 if (CheckError(Status
, L
"while loading the Linux options file")) {
638 } else { // a filename string is NULL
641 if (OptionsFilename
!= NULL
)
642 FreePool(OptionsFilename
);
643 if (FullFilename
!= NULL
)
644 FreePool(FullFilename
);
645 OptionsFilename
= FullFilename
= NULL
;
648 } // static REFIT_FILE * ReadLinuxOptionsFile()
650 // Retrieve a single line of options from a Linux kernel options file
651 CHAR16
* GetFirstOptionsFromFile(IN CHAR16
*LoaderPath
, IN REFIT_VOLUME
*Volume
) {
653 CHAR16
*Options
= NULL
;
657 File
= ReadLinuxOptionsFile(LoaderPath
, Volume
);
659 TokenCount
= ReadTokenLine(File
, &TokenList
);
661 Options
= StrDuplicate(TokenList
[1]);
662 FreeTokenLine(&TokenList
, &TokenCount
);
666 } // static CHAR16 * GetOptionsFile()