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