]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/BdsDxe/BootMaint/FileExplorer.c
Update all files to follow doxygen style file header.
[mirror_edk2.git] / MdeModulePkg / Universal / BdsDxe / BootMaint / FileExplorer.c
1 /** @file
2 File explorer related functions.
3
4 Copyright (c) 2004 - 2008, Intel Corporation. <BR>
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "BootMaint.h"
16
17 VOID
18 UpdateFileExplorePage (
19 IN BMM_CALLBACK_DATA *CallbackData,
20 BM_MENU_OPTION *MenuOption
21 )
22 /*++
23 Routine Description:
24 Update the File Explore page.
25
26 Arguments:
27 MenuOption - Pointer to menu options to display.
28
29 Returns:
30 None.
31
32 --*/
33 {
34 UINTN Index;
35 BM_MENU_ENTRY *NewMenuEntry;
36 BM_FILE_CONTEXT *NewFileContext;
37 EFI_FORM_ID FormId;
38
39 NewMenuEntry = NULL;
40 NewFileContext = NULL;
41 FormId = 0;
42
43 RefreshUpdateData ();
44
45 for (Index = 0; Index < MenuOption->MenuNumber; Index++) {
46 NewMenuEntry = BOpt_GetMenuEntry (MenuOption, Index);
47 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;
48
49 if (NewFileContext->IsBootLegacy) {
50 continue;
51 }
52
53 if ((NewFileContext->IsDir) || (BOOT_FROM_FILE_STATE == CallbackData->FeCurrentState)) {
54 //
55 // Create Text opcode for directory, also create Text opcode for file in BOOT_FROM_FILE_STATE.
56 //
57 CreateActionOpCode (
58 (UINT16) (FILE_OPTION_OFFSET + Index),
59 NewMenuEntry->DisplayStringToken,
60 STRING_TOKEN (STR_NULL_STRING),
61 EFI_IFR_FLAG_CALLBACK,
62 0,
63 &gUpdateData
64 );
65 } else {
66 //
67 // Create Goto opcode for file in ADD_BOOT_OPTION_STATE or ADD_DRIVER_OPTION_STATE.
68 //
69 if (ADD_BOOT_OPTION_STATE == CallbackData->FeCurrentState) {
70 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;
71 } else if (ADD_DRIVER_OPTION_STATE == CallbackData->FeCurrentState) {
72 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;
73 }
74
75 CreateGotoOpCode (
76 FormId,
77 NewMenuEntry->DisplayStringToken,
78 STRING_TOKEN (STR_NULL_STRING),
79 EFI_IFR_FLAG_CALLBACK,
80 (UINT16) (FILE_OPTION_OFFSET + Index),
81 &gUpdateData
82 );
83 }
84 }
85
86 IfrLibUpdateForm (
87 CallbackData->FeHiiHandle,
88 &mFileExplorerGuid,
89 FORM_FILE_EXPLORER_ID,
90 FORM_FILE_EXPLORER_ID,
91 FALSE,
92 &gUpdateData
93 );
94 }
95
96 BOOLEAN
97 UpdateFileExplorer (
98 IN BMM_CALLBACK_DATA *CallbackData,
99 IN UINT16 KeyValue
100 )
101 /*++
102
103 Routine Description:
104 Update the file explower page with the refershed file system.
105
106 Arguments:
107 CallbackData - BMM context data
108 KeyValue - Key value to identify the type of data to expect.
109
110 Returns:
111 TRUE - Inform the caller to create a callback packet to exit file explorer.
112 FALSE - Indicate that there is no need to exit file explorer.
113
114 --*/
115 {
116 UINT16 FileOptionMask;
117 BM_MENU_ENTRY *NewMenuEntry;
118 BM_FILE_CONTEXT *NewFileContext;
119 EFI_FORM_ID FormId;
120 BOOLEAN ExitFileExplorer;
121 EFI_STATUS Status;
122
123 NewMenuEntry = NULL;
124 NewFileContext = NULL;
125 ExitFileExplorer = FALSE;
126
127 FileOptionMask = (UINT16) (FILE_OPTION_MASK & KeyValue);
128
129 if (UNKNOWN_CONTEXT == CallbackData->FeDisplayContext) {
130 //
131 // First in, display file system.
132 //
133 BOpt_FreeMenu (&FsOptionMenu);
134 BOpt_FindFileSystem (CallbackData);
135 CreateMenuStringToken (CallbackData, CallbackData->FeHiiHandle, &FsOptionMenu);
136
137 UpdateFileExplorePage (CallbackData, &FsOptionMenu);
138
139 CallbackData->FeDisplayContext = FILE_SYSTEM;
140 } else {
141 if (FILE_SYSTEM == CallbackData->FeDisplayContext) {
142 NewMenuEntry = BOpt_GetMenuEntry (&FsOptionMenu, FileOptionMask);
143 } else if (DIRECTORY == CallbackData->FeDisplayContext) {
144 NewMenuEntry = BOpt_GetMenuEntry (&DirectoryMenu, FileOptionMask);
145 }
146
147 CallbackData->FeDisplayContext = DIRECTORY;
148
149 NewFileContext = (BM_FILE_CONTEXT *) NewMenuEntry->VariableContext;
150
151 if (NewFileContext->IsDir ) {
152 RemoveEntryList (&NewMenuEntry->Link);
153 BOpt_FreeMenu (&DirectoryMenu);
154 Status = BOpt_FindFiles (CallbackData, NewMenuEntry);
155 if (EFI_ERROR (Status)) {
156 ExitFileExplorer = TRUE;
157 goto exit;
158 }
159 CreateMenuStringToken (CallbackData, CallbackData->FeHiiHandle, &DirectoryMenu);
160 BOpt_DestroyMenuEntry (NewMenuEntry);
161
162 UpdateFileExplorePage (CallbackData, &DirectoryMenu);
163
164 } else {
165 switch (CallbackData->FeCurrentState) {
166 case BOOT_FROM_FILE_STATE:
167 //
168 // Here boot from file
169 //
170 BootThisFile (NewFileContext);
171 ExitFileExplorer = TRUE;
172 break;
173
174 case ADD_BOOT_OPTION_STATE:
175 case ADD_DRIVER_OPTION_STATE:
176 if (ADD_BOOT_OPTION_STATE == CallbackData->FeCurrentState) {
177 FormId = FORM_BOOT_ADD_DESCRIPTION_ID;
178 } else {
179 FormId = FORM_DRIVER_ADD_FILE_DESCRIPTION_ID;
180 }
181
182 CallbackData->MenuEntry = NewMenuEntry;
183 CallbackData->LoadContext->FilePathList = ((BM_FILE_CONTEXT *) (CallbackData->MenuEntry->VariableContext))->DevicePath;
184
185 //
186 // Create Subtitle op-code for the display string of the option.
187 //
188 RefreshUpdateData ();
189
190 CreateSubTitleOpCode (
191 NewMenuEntry->DisplayStringToken,
192 0,
193 0,
194 0,
195 &gUpdateData
196 );
197
198 IfrLibUpdateForm (
199 CallbackData->FeHiiHandle,
200 &mFileExplorerGuid,
201 FormId,
202 FormId,
203 FALSE,
204 &gUpdateData
205 );
206 break;
207
208 default:
209 break;
210 }
211 }
212 }
213 exit:
214 return ExitFileExplorer;
215 }
216
217 EFI_STATUS
218 EFIAPI
219 FileExplorerCallback (
220 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
221 IN EFI_BROWSER_ACTION Action,
222 IN EFI_QUESTION_ID QuestionId,
223 IN UINT8 Type,
224 IN EFI_IFR_TYPE_VALUE *Value,
225 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
226 )
227 /*++
228
229 Routine Description:
230 This function processes the results of changes in configuration.
231
232 Arguments:
233 This - Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
234 Action - Specifies the type of action taken by the browser.
235 QuestionId - A unique value which is sent to the original exporting driver
236 so that it can identify the type of data to expect.
237 Type - The type of value for the question.
238 Value - A pointer to the data being sent to the original exporting driver.
239 ActionRequest - On return, points to the action requested by the callback function.
240
241 Returns:
242 EFI_SUCCESS - The callback successfully handled the action.
243 EFI_OUT_OF_RESOURCES - Not enough storage is available to hold the variable and its data.
244 EFI_DEVICE_ERROR - The variable could not be saved.
245 EFI_UNSUPPORTED - The specified Action is not supported by the callback.
246
247 --*/
248 {
249 BMM_CALLBACK_DATA *Private;
250 FILE_EXPLORER_NV_DATA *NvRamMap;
251 EFI_STATUS Status;
252 UINTN BufferSize;
253
254 if ((Value == NULL) || (ActionRequest == NULL)) {
255 return EFI_INVALID_PARAMETER;
256 }
257
258 Status = EFI_SUCCESS;
259 Private = FE_CALLBACK_DATA_FROM_THIS (This);
260 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
261
262 //
263 // Retrive uncommitted data from Form Browser
264 //
265 NvRamMap = &Private->FeFakeNvData;
266 BufferSize = sizeof (FILE_EXPLORER_NV_DATA);
267 Status = GetBrowserData (NULL, NULL, &BufferSize, (UINT8 *) NvRamMap);
268 if (EFI_ERROR (Status)) {
269 return Status;
270 }
271
272 if (QuestionId == KEY_VALUE_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_SAVE_AND_EXIT_DRIVER) {
273 //
274 // Apply changes and exit formset
275 //
276 if (ADD_BOOT_OPTION_STATE == Private->FeCurrentState) {
277 Status = Var_UpdateBootOption (Private, NvRamMap);
278 if (EFI_ERROR (Status)) {
279 return Status;
280 }
281
282 BOpt_GetBootOptions (Private);
283 CreateMenuStringToken (Private, Private->FeHiiHandle, &BootOptionMenu);
284 } else if (ADD_DRIVER_OPTION_STATE == Private->FeCurrentState) {
285 Status = Var_UpdateDriverOption (
286 Private,
287 Private->FeHiiHandle,
288 NvRamMap->DescriptionData,
289 NvRamMap->OptionalData,
290 NvRamMap->ForceReconnect
291 );
292 if (EFI_ERROR (Status)) {
293 return Status;
294 }
295
296 BOpt_GetDriverOptions (Private);
297 CreateMenuStringToken (Private, Private->FeHiiHandle, &DriverOptionMenu);
298 }
299
300 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
301 } else if (QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_BOOT || QuestionId == KEY_VALUE_NO_SAVE_AND_EXIT_DRIVER) {
302 //
303 // Discard changes and exit formset
304 //
305 NvRamMap->OptionalData[0] = 0x0000;
306 NvRamMap->DescriptionData[0] = 0x0000;
307 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
308 } else if (QuestionId < FILE_OPTION_OFFSET) {
309 //
310 // Exit File Explorer formset
311 //
312 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
313 } else {
314 if (UpdateFileExplorer (Private, QuestionId)) {
315 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_EXIT;
316 }
317 }
318
319 return Status;
320 }