]> git.proxmox.com Git - mirror_edk2.git/blame - EmulatorPkg/EmuSimpleFileSystemDxe/EmuSimpleFileSystem.c
EmulatorPkg: Remove all trailing whitespace
[mirror_edk2.git] / EmulatorPkg / EmuSimpleFileSystemDxe / EmuSimpleFileSystem.c
CommitLineData
949f388f 1/*++ @file\r
2 Produce Simple File System abstractions for directories on your PC using Posix APIs.\r
d18d8a1d 3 The configuration of what devices to mount or emulate comes from UNIX\r
4 environment variables. The variables must be visible to the Microsoft*\r
949f388f 5 Developer Studio for them to work.\r
6\r
224e1333 7Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
949f388f 8Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
224e1333 9This program and the accompanying materials\r
10are licensed and made available under the terms and conditions of the BSD License\r
11which accompanies this distribution. The full text of the license may be found at\r
12http://opensource.org/licenses/bsd-license.php\r
13\r
14THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
15WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
949f388f 16\r
17**/\r
18\r
19#include "EmuSimpleFileSystem.h"\r
20\r
21\r
22\r
23\r
24/**\r
25 Opens a new file relative to the source file's location.\r
26\r
27 @param This The protocol instance pointer.\r
28 @param NewHandle Returns File Handle for FileName.\r
29 @param FileName Null terminated string. "\", ".", and ".." are supported.\r
30 @param OpenMode Open mode for file.\r
31 @param Attributes Only used for EFI_FILE_MODE_CREATE.\r
32\r
33 @retval EFI_SUCCESS The device was opened.\r
34 @retval EFI_NOT_FOUND The specified file could not be found on the device.\r
35 @retval EFI_NO_MEDIA The device has no media.\r
36 @retval EFI_MEDIA_CHANGED The media has changed.\r
37 @retval EFI_DEVICE_ERROR The device reported an error.\r
38 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
39 @retval EFI_ACCESS_DENIED The service denied access to the file.\r
40 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r
41 @retval EFI_VOLUME_FULL The volume is full.\r
42\r
43**/\r
44EFI_STATUS\r
45EFIAPI\r
46EmuSimpleFileSystemOpen (\r
47 IN EFI_FILE_PROTOCOL *This,\r
48 OUT EFI_FILE_PROTOCOL **NewHandle,\r
49 IN CHAR16 *FileName,\r
50 IN UINT64 OpenMode,\r
51 IN UINT64 Attributes\r
52 )\r
53{\r
54 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
55\r
56 //\r
57 // Check for obvious invalid parameters.\r
58 //\r
59 if (This == NULL || NewHandle == NULL || FileName == NULL) {\r
60 return EFI_INVALID_PARAMETER;\r
61 }\r
62\r
63 switch (OpenMode) {\r
64 case EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r
65 if (Attributes &~EFI_FILE_VALID_ATTR) {\r
66 return EFI_INVALID_PARAMETER;\r
67 }\r
68\r
69 if (Attributes & EFI_FILE_READ_ONLY) {\r
70 return EFI_INVALID_PARAMETER;\r
71 }\r
72\r
73 //\r
74 // fall through\r
75 //\r
76 case EFI_FILE_MODE_READ:\r
77 case EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE:\r
78 break;\r
79\r
80 default:\r
81 return EFI_INVALID_PARAMETER;\r
82 }\r
83\r
84 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
85\r
86 return PrivateFile->Io->Open (PrivateFile->Io, NewHandle, FileName, OpenMode, Attributes);\r
87}\r
88\r
89\r
90\r
91/**\r
92 Close the file handle\r
93\r
94 @param This Protocol instance pointer.\r
95\r
96 @retval EFI_SUCCESS The file was closed.\r
97\r
98**/\r
99EFI_STATUS\r
100EFIAPI\r
101EmuSimpleFileSystemClose (\r
102 IN EFI_FILE_PROTOCOL *This\r
103 )\r
104{\r
105 EFI_STATUS Status;\r
106 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
107 EFI_TPL OldTpl;\r
108\r
109 if (This == NULL) {\r
110 return EFI_INVALID_PARAMETER;\r
111 }\r
112\r
113 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
114\r
115 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
116\r
117 Status = PrivateFile->Io->Close (PrivateFile->Io);\r
118 if (!EFI_ERROR (Status)) {\r
119 gBS->FreePool (PrivateFile);\r
120 }\r
121\r
122 gBS->RestoreTPL (OldTpl);\r
d18d8a1d 123\r
949f388f 124 return Status;\r
125}\r
126\r
127\r
128/**\r
129 Close and delete the file handle.\r
130\r
131 @param This Protocol instance pointer.\r
d18d8a1d 132\r
949f388f 133 @retval EFI_SUCCESS The file was closed and deleted.\r
134 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.\r
135\r
136**/\r
137EFI_STATUS\r
138EFIAPI\r
139EmuSimpleFileSystemDelete (\r
140 IN EFI_FILE_PROTOCOL *This\r
141 )\r
142{\r
143 EFI_STATUS Status;\r
144 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
145 EFI_TPL OldTpl;\r
146\r
147 if (This == NULL) {\r
148 return EFI_INVALID_PARAMETER;\r
149 }\r
150\r
151 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 152\r
949f388f 153 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
154\r
155 Status = PrivateFile->Io->Delete (PrivateFile->Io);\r
156 if (!EFI_ERROR (Status)) {\r
157 gBS->FreePool (PrivateFile);\r
158 }\r
159\r
160 gBS->RestoreTPL (OldTpl);\r
161\r
162 return Status;\r
163}\r
164\r
165\r
166/**\r
167 Read data from the file.\r
168\r
169 @param This Protocol instance pointer.\r
170 @param BufferSize On input size of buffer, on output amount of data in buffer.\r
171 @param Buffer The buffer in which data is read.\r
172\r
173 @retval EFI_SUCCESS Data was read.\r
174 @retval EFI_NO_MEDIA The device has no media.\r
175 @retval EFI_DEVICE_ERROR The device reported an error.\r
176 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
177 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.\r
178\r
179**/\r
180EFI_STATUS\r
181EFIAPI\r
182EmuSimpleFileSystemRead (\r
183 IN EFI_FILE_PROTOCOL *This,\r
184 IN OUT UINTN *BufferSize,\r
185 OUT VOID *Buffer\r
186 )\r
187{\r
188 EFI_STATUS Status;\r
189 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
190 EFI_TPL OldTpl;\r
191\r
192 if (This == NULL || BufferSize == NULL) {\r
193 return EFI_INVALID_PARAMETER;\r
194 }\r
d18d8a1d 195\r
949f388f 196 if ((*BufferSize != 0) && (Buffer == NULL)) {\r
197 // Buffer can be NULL if *BufferSize is zero\r
198 return EFI_INVALID_PARAMETER;\r
199 }\r
200\r
201 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 202\r
949f388f 203 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
204\r
205 Status = PrivateFile->Io->Read (PrivateFile->Io, BufferSize, Buffer);\r
206\r
207 gBS->RestoreTPL (OldTpl);\r
208 return Status;\r
209}\r
210\r
211\r
212/**\r
213 Write data to a file.\r
214\r
215 @param This Protocol instance pointer.\r
216 @param BufferSize On input size of buffer, on output amount of data in buffer.\r
217 @param Buffer The buffer in which data to write.\r
218\r
219 @retval EFI_SUCCESS Data was written.\r
220 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.\r
221 @retval EFI_NO_MEDIA The device has no media.\r
222 @retval EFI_DEVICE_ERROR The device reported an error.\r
223 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.\r
224 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
225 @retval EFI_WRITE_PROTECTED The device is write protected.\r
226 @retval EFI_ACCESS_DENIED The file was open for read only.\r
227 @retval EFI_VOLUME_FULL The volume is full.\r
228\r
229**/\r
230EFI_STATUS\r
231EFIAPI\r
232EmuSimpleFileSystemWrite (\r
233 IN EFI_FILE_PROTOCOL *This,\r
234 IN OUT UINTN *BufferSize,\r
235 IN VOID *Buffer\r
236 )\r
237{\r
238 EFI_STATUS Status;\r
239 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
240 EFI_TPL OldTpl;\r
241\r
242 if (This == NULL || BufferSize == NULL || Buffer == NULL) {\r
243 return EFI_INVALID_PARAMETER;\r
244 }\r
245\r
246 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
247\r
248 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
249\r
250 Status = PrivateFile->Io->Write (PrivateFile->Io, BufferSize, Buffer);\r
251\r
252 gBS->RestoreTPL (OldTpl);\r
253 return Status;\r
254}\r
255\r
256\r
257/**\r
258 Set a files current position\r
259\r
260 @param This Protocol instance pointer.\r
261 @param Position Byte position from the start of the file.\r
d18d8a1d 262\r
949f388f 263 @retval EFI_SUCCESS Position was updated.\r
264 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.\r
265\r
266**/\r
267EFI_STATUS\r
268EFIAPI\r
269EmuSimpleFileSystemGetPosition (\r
270 IN EFI_FILE_PROTOCOL *This,\r
271 OUT UINT64 *Position\r
272 )\r
273{\r
274 EFI_STATUS Status;\r
275 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
276 EFI_TPL OldTpl;\r
277\r
278 if (This == NULL || Position == NULL) {\r
279 return EFI_INVALID_PARAMETER;\r
280 }\r
281\r
282 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 283\r
949f388f 284 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
285\r
286 Status = PrivateFile->Io->GetPosition (PrivateFile->Io, Position);\r
287\r
288 gBS->RestoreTPL (OldTpl);\r
289 return Status;\r
290}\r
291\r
292\r
293\r
294/**\r
295 Get a file's current position\r
296\r
297 @param This Protocol instance pointer.\r
298 @param Position Byte position from the start of the file.\r
d18d8a1d 299\r
949f388f 300 @retval EFI_SUCCESS Position was updated.\r
301 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..\r
302\r
303**/\r
304EFI_STATUS\r
305EFIAPI\r
306EmuSimpleFileSystemSetPosition (\r
307 IN EFI_FILE_PROTOCOL *This,\r
308 IN UINT64 Position\r
309 )\r
310{\r
311 EFI_STATUS Status;\r
312 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
313 EFI_TPL OldTpl;\r
314\r
315 if (This == NULL) {\r
316 return EFI_INVALID_PARAMETER;\r
317 }\r
318\r
319 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 320\r
949f388f 321 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
322\r
323 Status = PrivateFile->Io->SetPosition (PrivateFile->Io, Position);\r
324\r
325 gBS->RestoreTPL (OldTpl);\r
326 return Status;\r
327}\r
328\r
329\r
330/**\r
331 Get information about a file.\r
332\r
333 @param This Protocol instance pointer.\r
334 @param InformationType Type of information to return in Buffer.\r
335 @param BufferSize On input size of buffer, on output amount of data in buffer.\r
336 @param Buffer The buffer to return data.\r
337\r
338 @retval EFI_SUCCESS Data was returned.\r
339 @retval EFI_UNSUPPORTED InformationType is not supported.\r
340 @retval EFI_NO_MEDIA The device has no media.\r
341 @retval EFI_DEVICE_ERROR The device reported an error.\r
342 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
343 @retval EFI_WRITE_PROTECTED The device is write protected.\r
344 @retval EFI_ACCESS_DENIED The file was open for read only.\r
345 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.\r
346\r
347**/\r
348EFI_STATUS\r
349EFIAPI\r
350EmuSimpleFileSystemGetInfo (\r
351 IN EFI_FILE_PROTOCOL *This,\r
352 IN EFI_GUID *InformationType,\r
353 IN OUT UINTN *BufferSize,\r
354 OUT VOID *Buffer\r
355 )\r
356{\r
357 EFI_STATUS Status;\r
358 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
359 EFI_TPL OldTpl;\r
360\r
361 if (This == NULL || InformationType == NULL || BufferSize == NULL) {\r
362 return EFI_INVALID_PARAMETER;\r
363 }\r
364\r
365 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 366\r
949f388f 367 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
368\r
369 Status = PrivateFile->Io->GetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);\r
370\r
371 gBS->RestoreTPL (OldTpl);\r
372 return Status;\r
373}\r
374\r
375\r
376/**\r
377 Set information about a file\r
378\r
379 @param File Protocol instance pointer.\r
380 @param InformationType Type of information in Buffer.\r
381 @param BufferSize Size of buffer.\r
382 @param Buffer The data to write.\r
383\r
384 @retval EFI_SUCCESS Data was set.\r
385 @retval EFI_UNSUPPORTED InformationType is not supported.\r
386 @retval EFI_NO_MEDIA The device has no media.\r
387 @retval EFI_DEVICE_ERROR The device reported an error.\r
388 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
389 @retval EFI_WRITE_PROTECTED The device is write protected.\r
390 @retval EFI_ACCESS_DENIED The file was open for read only.\r
391\r
392**/\r
393EFI_STATUS\r
394EFIAPI\r
395EmuSimpleFileSystemSetInfo (\r
396 IN EFI_FILE_PROTOCOL*This,\r
397 IN EFI_GUID *InformationType,\r
398 IN UINTN BufferSize,\r
399 IN VOID *Buffer\r
400 )\r
401{\r
402 EFI_STATUS Status;\r
403 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
404 EFI_TPL OldTpl;\r
405\r
406 //\r
407 // Check for invalid parameters.\r
408 //\r
409 if (This == NULL || InformationType == NULL || BufferSize == 0 || Buffer == NULL) {\r
410 return EFI_INVALID_PARAMETER;\r
411 }\r
412\r
413 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 414\r
949f388f 415 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
416\r
417 Status = PrivateFile->Io->SetInfo (PrivateFile->Io, InformationType, BufferSize, Buffer);\r
418\r
d18d8a1d 419 gBS->RestoreTPL (OldTpl);\r
949f388f 420 return Status;\r
421}\r
422\r
423\r
424/**\r
425 Flush data back for the file handle.\r
426\r
427 @param This Protocol instance pointer.\r
428\r
429 @retval EFI_SUCCESS Data was flushed.\r
430 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.\r
431 @retval EFI_NO_MEDIA The device has no media.\r
432 @retval EFI_DEVICE_ERROR The device reported an error.\r
433 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
434 @retval EFI_WRITE_PROTECTED The device is write protected.\r
435 @retval EFI_ACCESS_DENIED The file was open for read only.\r
436 @retval EFI_VOLUME_FULL The volume is full.\r
437\r
438**/\r
439EFI_STATUS\r
440EFIAPI\r
441EmuSimpleFileSystemFlush (\r
442 IN EFI_FILE_PROTOCOL *This\r
443 )\r
444{\r
445 EFI_STATUS Status;\r
446 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
447 EFI_TPL OldTpl;\r
448\r
449 if (This == NULL) {\r
450 return EFI_INVALID_PARAMETER;\r
451 }\r
452\r
453 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
d18d8a1d 454\r
949f388f 455 PrivateFile = EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This);\r
456\r
457 Status = PrivateFile->Io->Flush (PrivateFile->Io);\r
458\r
459 gBS->RestoreTPL (OldTpl);\r
460 return Status;\r
461}\r
462\r
463\r
464\r
465/**\r
466 Open the root directory on a volume.\r
467\r
468 @param This Protocol instance pointer.\r
469 @param Root Returns an Open file handle for the root directory\r
470\r
471 @retval EFI_SUCCESS The device was opened.\r
472 @retval EFI_UNSUPPORTED This volume does not support the file system.\r
473 @retval EFI_NO_MEDIA The device has no media.\r
474 @retval EFI_DEVICE_ERROR The device reported an error.\r
475 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.\r
476 @retval EFI_ACCESS_DENIED The service denied access to the file.\r
477 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.\r
478\r
479**/\r
480EFI_STATUS\r
481EFIAPI\r
482EmuSimpleFileSystemOpenVolume (\r
483 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
484 OUT EFI_FILE_PROTOCOL **Root\r
485 )\r
486{\r
487 EFI_STATUS Status;\r
488 EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
489 EMU_EFI_FILE_PRIVATE *PrivateFile;\r
490 EFI_TPL OldTpl;\r
491\r
54e0b04c 492 Status = EFI_UNSUPPORTED;\r
493\r
949f388f 494 if (This == NULL || Root == NULL) {\r
495 return EFI_INVALID_PARAMETER;\r
496 }\r
497\r
498 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
499\r
500 Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This);\r
501\r
502 PrivateFile = AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE));\r
503 if (PrivateFile == NULL) {\r
504 goto Done;\r
505 }\r
d18d8a1d 506\r
949f388f 507 PrivateFile->Signature = EMU_EFI_FILE_PRIVATE_SIGNATURE;\r
508 PrivateFile->IoThunk = Private->IoThunk;\r
509 PrivateFile->SimpleFileSystem = This;\r
510 PrivateFile->EfiFile.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
511 PrivateFile->EfiFile.Open = EmuSimpleFileSystemOpen;\r
512 PrivateFile->EfiFile.Close = EmuSimpleFileSystemClose;\r
513 PrivateFile->EfiFile.Delete = EmuSimpleFileSystemDelete;\r
514 PrivateFile->EfiFile.Read = EmuSimpleFileSystemRead;\r
515 PrivateFile->EfiFile.Write = EmuSimpleFileSystemWrite;\r
516 PrivateFile->EfiFile.GetPosition = EmuSimpleFileSystemGetPosition;\r
517 PrivateFile->EfiFile.SetPosition = EmuSimpleFileSystemSetPosition;\r
518 PrivateFile->EfiFile.GetInfo = EmuSimpleFileSystemGetInfo;\r
519 PrivateFile->EfiFile.SetInfo = EmuSimpleFileSystemSetInfo;\r
520 PrivateFile->EfiFile.Flush = EmuSimpleFileSystemFlush;\r
521\r
522 *Root = &PrivateFile->EfiFile;\r
523\r
524 Status = Private->Io->OpenVolume (Private->Io, &PrivateFile->Io);\r
525 if (EFI_ERROR (Status)) {\r
526 goto Done;\r
527 }\r
d18d8a1d 528\r
949f388f 529 AddUnicodeString2 (\r
530 "eng",\r
531 gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
532 &Private->ControllerNameTable,\r
533 Private->IoThunk->ConfigString,\r
534 TRUE\r
535 );\r
536\r
537 AddUnicodeString2 (\r
538 "en",\r
539 gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
540 &Private->ControllerNameTable,\r
541 Private->IoThunk->ConfigString,\r
542 FALSE\r
543 );\r
544\r
545\r
546Done:\r
547 if (EFI_ERROR (Status)) {\r
548 if (PrivateFile) {\r
549 gBS->FreePool (PrivateFile);\r
550 }\r
d18d8a1d 551\r
949f388f 552 *Root = NULL;\r
553 }\r
554\r
555 gBS->RestoreTPL (OldTpl);\r
556\r
557 return Status;\r
558}\r
559\r
560/**\r
d18d8a1d 561 Tests to see if this driver supports a given controller. If a child device is provided,\r
949f388f 562 it further tests to see if this driver supports creating a handle for the specified child device.\r
563\r
d18d8a1d 564 This function checks to see if the driver specified by This supports the device specified by\r
565 ControllerHandle. Drivers will typically use the device path attached to\r
566 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
567 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
568 may be called many times during platform initialization. In order to reduce boot times, the tests\r
569 performed by this function must be very small, and take as little time as possible to execute. This\r
570 function must not change the state of any hardware devices, and this function must be aware that the\r
571 device specified by ControllerHandle may already be managed by the same driver or a\r
572 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
573 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
574 Because ControllerHandle may have been previously started by the same driver, if a protocol is\r
575 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
949f388f 576 to guarantee the state of ControllerHandle is not modified by this function.\r
577\r
578 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
d18d8a1d 579 @param[in] ControllerHandle The handle of the controller to test. This handle\r
580 must support a protocol interface that supplies\r
949f388f 581 an I/O abstraction to the driver.\r
d18d8a1d 582 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
583 parameter is ignored by device drivers, and is optional for bus\r
584 drivers. For bus drivers, if this parameter is not NULL, then\r
585 the bus driver must determine if the bus controller specified\r
586 by ControllerHandle and the child controller specified\r
587 by RemainingDevicePath are both supported by this\r
949f388f 588 bus driver.\r
589\r
590 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
591 RemainingDevicePath is supported by the driver specified by This.\r
592 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
593 RemainingDevicePath is already being managed by the driver\r
594 specified by This.\r
595 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
596 RemainingDevicePath is already being managed by a different\r
597 driver or an application that requires exclusive access.\r
598 Currently not implemented.\r
599 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
600 RemainingDevicePath is not supported by the driver specified by This.\r
601**/\r
602EFI_STATUS\r
603EFIAPI\r
604EmuSimpleFileSystemDriverBindingSupported (\r
605 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
606 IN EFI_HANDLE ControllerHandle,\r
607 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
608 )\r
609{\r
610 EFI_STATUS Status;\r
611 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
612\r
613 //\r
614 // Open the IO Abstraction(s) needed to perform the supported test\r
615 //\r
616 Status = gBS->OpenProtocol (\r
617 ControllerHandle,\r
618 &gEmuIoThunkProtocolGuid,\r
619 (VOID **)&EmuIoThunk,\r
620 This->DriverBindingHandle,\r
621 ControllerHandle,\r
622 EFI_OPEN_PROTOCOL_BY_DRIVER\r
623 );\r
624 if (EFI_ERROR (Status)) {\r
625 return Status;\r
626 }\r
627\r
628 //\r
629 // Make sure GUID is for a File System handle.\r
630 //\r
631 Status = EFI_UNSUPPORTED;\r
632 if (CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r
633 Status = EFI_SUCCESS;\r
634 }\r
635\r
636 //\r
637 // Close the I/O Abstraction(s) used to perform the supported test\r
638 //\r
639 gBS->CloseProtocol (\r
640 ControllerHandle,\r
641 &gEmuIoThunkProtocolGuid,\r
642 This->DriverBindingHandle,\r
643 ControllerHandle\r
644 );\r
645\r
646 return Status;\r
647}\r
648\r
649\r
650\r
651/**\r
652 Starts a device controller or a bus controller.\r
653\r
654 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
d18d8a1d 655 As a result, much of the error checking on the parameters to Start() has been moved into this\r
656 common boot service. It is legal to call Start() from other locations,\r
949f388f 657 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
658 1. ControllerHandle must be a valid EFI_HANDLE.\r
659 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
660 EFI_DEVICE_PATH_PROTOCOL.\r
661 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
d18d8a1d 662 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
949f388f 663\r
664 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
d18d8a1d 665 @param[in] ControllerHandle The handle of the controller to start. This handle\r
666 must support a protocol interface that supplies\r
949f388f 667 an I/O abstraction to the driver.\r
d18d8a1d 668 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
669 parameter is ignored by device drivers, and is optional for bus\r
670 drivers. For a bus driver, if this parameter is NULL, then handles\r
671 for all the children of Controller are created by this driver.\r
672 If this parameter is not NULL and the first Device Path Node is\r
673 not the End of Device Path Node, then only the handle for the\r
674 child device specified by the first Device Path Node of\r
949f388f 675 RemainingDevicePath is created by this driver.\r
d18d8a1d 676 If the first Device Path Node of RemainingDevicePath is\r
949f388f 677 the End of Device Path Node, no child handle is created by this\r
678 driver.\r
679\r
680 @retval EFI_SUCCESS The device was started.\r
681 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
682 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
683 @retval Others The driver failded to start the device.\r
684\r
685**/\r
686EFI_STATUS\r
687EFIAPI\r
688EmuSimpleFileSystemDriverBindingStart (\r
689 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
690 IN EFI_HANDLE ControllerHandle,\r
691 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
692 )\r
693{\r
694 EFI_STATUS Status;\r
695 EMU_IO_THUNK_PROTOCOL *EmuIoThunk;\r
696 EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
949f388f 697\r
698 Private = NULL;\r
699\r
700 //\r
701 // Open the IO Abstraction(s) needed\r
702 //\r
703 Status = gBS->OpenProtocol (\r
704 ControllerHandle,\r
705 &gEmuIoThunkProtocolGuid,\r
706 (VOID **)&EmuIoThunk,\r
707 This->DriverBindingHandle,\r
708 ControllerHandle,\r
709 EFI_OPEN_PROTOCOL_BY_DRIVER\r
710 );\r
711 if (EFI_ERROR (Status)) {\r
712 return Status;\r
713 }\r
714\r
715 //\r
716 // Validate GUID\r
717 //\r
718 if (!CompareGuid (EmuIoThunk->Protocol, &gEfiSimpleFileSystemProtocolGuid)) {\r
719 Status = EFI_UNSUPPORTED;\r
720 goto Done;\r
721 }\r
722\r
7e284acb 723 Private = AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE));\r
949f388f 724 if (Private == NULL) {\r
725 goto Done;\r
726 }\r
727\r
728 Status = EmuIoThunk->Open (EmuIoThunk);\r
729 if (EFI_ERROR (Status)) {\r
730 goto Done;\r
731 }\r
732\r
733 Private->Signature = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE;\r
734 Private->IoThunk = EmuIoThunk;\r
735 Private->Io = EmuIoThunk->Interface;\r
d18d8a1d 736\r
949f388f 737 Private->SimpleFileSystem.Revision = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION;\r
738 Private->SimpleFileSystem.OpenVolume = EmuSimpleFileSystemOpenVolume;\r
739\r
740 Private->ControllerNameTable = NULL;\r
741\r
742 AddUnicodeString2 (\r
743 "eng",\r
744 gEmuSimpleFileSystemComponentName.SupportedLanguages,\r
745 &Private->ControllerNameTable,\r
746 EmuIoThunk->ConfigString,\r
747 TRUE\r
748 );\r
d18d8a1d 749\r
949f388f 750 AddUnicodeString2 (\r
751 "en",\r
752 gEmuSimpleFileSystemComponentName2.SupportedLanguages,\r
753 &Private->ControllerNameTable,\r
754 EmuIoThunk->ConfigString,\r
755 FALSE\r
756 );\r
757\r
758 Status = gBS->InstallMultipleProtocolInterfaces (\r
759 &ControllerHandle,\r
760 &gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,\r
761 NULL\r
762 );\r
763\r
764Done:\r
765 if (EFI_ERROR (Status)) {\r
766 if (Private != NULL) {\r
767 if (Private->ControllerNameTable != NULL) {\r
768 FreeUnicodeStringTable (Private->ControllerNameTable);\r
769 }\r
d18d8a1d 770\r
949f388f 771 gBS->FreePool (Private);\r
d18d8a1d 772\r
949f388f 773 }\r
774\r
775 gBS->CloseProtocol (\r
776 ControllerHandle,\r
777 &gEmuIoThunkProtocolGuid,\r
778 This->DriverBindingHandle,\r
779 ControllerHandle\r
780 );\r
781 }\r
782\r
783 return Status;\r
784}\r
785\r
786\r
787/**\r
788 Stops a device controller or a bus controller.\r
d18d8a1d 789\r
790 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
791 As a result, much of the error checking on the parameters to Stop() has been moved\r
792 into this common boot service. It is legal to call Stop() from other locations,\r
949f388f 793 but the following calling restrictions must be followed, or the system behavior will not be deterministic.\r
794 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
795 same driver's Start() function.\r
796 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
797 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
798 Start() function, and the Start() function must have called OpenProtocol() on\r
799 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
d18d8a1d 800\r
949f388f 801 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
d18d8a1d 802 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
803 support a bus specific I/O protocol for the driver\r
949f388f 804 to use to stop the device.\r
805 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
d18d8a1d 806 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
949f388f 807 if NumberOfChildren is 0.\r
808\r
809 @retval EFI_SUCCESS The device was stopped.\r
810 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
811\r
812**/\r
813EFI_STATUS\r
814EFIAPI\r
815EmuSimpleFileSystemDriverBindingStop (\r
816 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
817 IN EFI_HANDLE ControllerHandle,\r
818 IN UINTN NumberOfChildren,\r
819 IN EFI_HANDLE *ChildHandleBuffer\r
820 )\r
821{\r
822 EFI_STATUS Status;\r
823 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;\r
824 EMU_SIMPLE_FILE_SYSTEM_PRIVATE *Private;\r
825\r
826 //\r
827 // Get our context back\r
828 //\r
829 Status = gBS->OpenProtocol (\r
830 ControllerHandle,\r
831 &gEfiSimpleFileSystemProtocolGuid,\r
832 (VOID **)&SimpleFileSystem,\r
833 This->DriverBindingHandle,\r
834 ControllerHandle,\r
835 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
836 );\r
837 if (EFI_ERROR (Status)) {\r
838 return EFI_UNSUPPORTED;\r
839 }\r
840\r
841 Private = EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem);\r
842 Status = Private->IoThunk->Close (Private->IoThunk);\r
843\r
844 //\r
845 // Uninstall the Simple File System Protocol from ControllerHandle\r
846 //\r
847 Status = gBS->UninstallMultipleProtocolInterfaces (\r
848 ControllerHandle,\r
849 &gEfiSimpleFileSystemProtocolGuid, &Private->SimpleFileSystem,\r
850 NULL\r
851 );\r
852 if (!EFI_ERROR (Status)) {\r
853 Status = gBS->CloseProtocol (\r
854 ControllerHandle,\r
855 &gEmuIoThunkProtocolGuid,\r
856 This->DriverBindingHandle,\r
857 ControllerHandle\r
858 );\r
859 }\r
860\r
861 if (!EFI_ERROR (Status)) {\r
862 //\r
863 // Free our instance data\r
864 //\r
865 FreeUnicodeStringTable (Private->ControllerNameTable);\r
866 gBS->FreePool (Private);\r
867 }\r
868\r
869 return Status;\r
870}\r
871\r
872\r
873EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding = {\r
874 EmuSimpleFileSystemDriverBindingSupported,\r
875 EmuSimpleFileSystemDriverBindingStart,\r
876 EmuSimpleFileSystemDriverBindingStop,\r
877 0xa,\r
878 NULL,\r
879 NULL\r
880};\r
881\r
882\r
883\r
884\r
885/**\r
886 The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.\r
887\r
d18d8a1d 888 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
949f388f 889 @param[in] SystemTable A pointer to the EFI System Table.\r
d18d8a1d 890\r
949f388f 891 @retval EFI_SUCCESS The entry point is executed successfully.\r
892 @retval other Some error occurs when executing this entry point.\r
893\r
894**/\r
895EFI_STATUS\r
896EFIAPI\r
897InitializeEmuSimpleFileSystem(\r
898 IN EFI_HANDLE ImageHandle,\r
899 IN EFI_SYSTEM_TABLE *SystemTable\r
900 )\r
901{\r
902 EFI_STATUS Status;\r
903\r
904 Status = EfiLibInstallDriverBindingComponentName2 (\r
905 ImageHandle,\r
906 SystemTable,\r
907 &gEmuSimpleFileSystemDriverBinding,\r
908 ImageHandle,\r
909 &gEmuSimpleFileSystemComponentName,\r
910 &gEmuSimpleFileSystemComponentName2\r
911 );\r
912 ASSERT_EFI_ERROR (Status);\r
913\r
914 return Status;\r
915}\r