2 Produce Simple File System abstractions for directories on your PC using Posix APIs.
3 The configuration of what devices to mount or emulate comes from UNIX
4 environment variables. The variables must be visible to the Microsoft*
5 Developer Studio for them to work.
7 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
8 Portions copyright (c) 2011, Apple Inc. All rights reserved.
9 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "EmuSimpleFileSystem.h"
19 Opens a new file relative to the source file's location.
21 @param This The protocol instance pointer.
22 @param NewHandle Returns File Handle for FileName.
23 @param FileName Null terminated string. "\", ".", and ".." are supported.
24 @param OpenMode Open mode for file.
25 @param Attributes Only used for EFI_FILE_MODE_CREATE.
27 @retval EFI_SUCCESS The device was opened.
28 @retval EFI_NOT_FOUND The specified file could not be found on the device.
29 @retval EFI_NO_MEDIA The device has no media.
30 @retval EFI_MEDIA_CHANGED The media has changed.
31 @retval EFI_DEVICE_ERROR The device reported an error.
32 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
33 @retval EFI_ACCESS_DENIED The service denied access to the file.
34 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
35 @retval EFI_VOLUME_FULL The volume is full.
40 EmuSimpleFileSystemOpen (
41 IN EFI_FILE_PROTOCOL
*This
,
42 OUT EFI_FILE_PROTOCOL
**NewHandle
,
50 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
51 EMU_EFI_FILE_PRIVATE
*NewPrivateFile
;
54 // Check for obvious invalid parameters.
56 if (This
== NULL
|| NewHandle
== NULL
|| FileName
== NULL
) {
57 return EFI_INVALID_PARAMETER
;
61 case EFI_FILE_MODE_CREATE
| EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
62 if (Attributes
&~EFI_FILE_VALID_ATTR
) {
63 return EFI_INVALID_PARAMETER
;
66 if (Attributes
& EFI_FILE_READ_ONLY
) {
67 return EFI_INVALID_PARAMETER
;
73 case EFI_FILE_MODE_READ
:
74 case EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
78 return EFI_INVALID_PARAMETER
;
81 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
83 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
85 NewPrivateFile
= AllocateCopyPool (sizeof (EMU_EFI_FILE_PRIVATE
), PrivateFile
);
86 if (NewPrivateFile
== NULL
) {
87 Status
= EFI_OUT_OF_RESOURCES
;
92 Status
= PrivateFile
->Io
->Open (PrivateFile
->Io
, &NewPrivateFile
->Io
, FileName
, OpenMode
, Attributes
);
93 if (!EFI_ERROR (Status
)) {
94 *NewHandle
= &NewPrivateFile
->EfiFile
;
97 FreePool (NewPrivateFile
);
101 gBS
->RestoreTPL (OldTpl
);
109 Close the file handle
111 @param This Protocol instance pointer.
113 @retval EFI_SUCCESS The file was closed.
118 EmuSimpleFileSystemClose (
119 IN EFI_FILE_PROTOCOL
*This
123 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
127 return EFI_INVALID_PARAMETER
;
130 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
132 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
134 Status
= PrivateFile
->Io
->Close (PrivateFile
->Io
);
135 if (!EFI_ERROR (Status
)) {
136 gBS
->FreePool (PrivateFile
);
139 gBS
->RestoreTPL (OldTpl
);
146 Close and delete the file handle.
148 @param This Protocol instance pointer.
150 @retval EFI_SUCCESS The file was closed and deleted.
151 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
156 EmuSimpleFileSystemDelete (
157 IN EFI_FILE_PROTOCOL
*This
161 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
165 return EFI_INVALID_PARAMETER
;
168 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
170 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
172 Status
= PrivateFile
->Io
->Delete (PrivateFile
->Io
);
173 if (!EFI_ERROR (Status
)) {
174 gBS
->FreePool (PrivateFile
);
177 gBS
->RestoreTPL (OldTpl
);
184 Read data from the file.
186 @param This Protocol instance pointer.
187 @param BufferSize On input size of buffer, on output amount of data in buffer.
188 @param Buffer The buffer in which data is read.
190 @retval EFI_SUCCESS Data was read.
191 @retval EFI_NO_MEDIA The device has no media.
192 @retval EFI_DEVICE_ERROR The device reported an error.
193 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
194 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
199 EmuSimpleFileSystemRead (
200 IN EFI_FILE_PROTOCOL
*This
,
201 IN OUT UINTN
*BufferSize
,
206 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
209 if (This
== NULL
|| BufferSize
== NULL
) {
210 return EFI_INVALID_PARAMETER
;
213 if ((*BufferSize
!= 0) && (Buffer
== NULL
)) {
214 // Buffer can be NULL if *BufferSize is zero
215 return EFI_INVALID_PARAMETER
;
218 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
220 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
222 Status
= PrivateFile
->Io
->Read (PrivateFile
->Io
, BufferSize
, Buffer
);
224 gBS
->RestoreTPL (OldTpl
);
230 Write data to a file.
232 @param This Protocol instance pointer.
233 @param BufferSize On input size of buffer, on output amount of data in buffer.
234 @param Buffer The buffer in which data to write.
236 @retval EFI_SUCCESS Data was written.
237 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
238 @retval EFI_NO_MEDIA The device has no media.
239 @retval EFI_DEVICE_ERROR The device reported an error.
240 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
241 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
242 @retval EFI_WRITE_PROTECTED The device is write protected.
243 @retval EFI_ACCESS_DENIED The file was open for read only.
244 @retval EFI_VOLUME_FULL The volume is full.
249 EmuSimpleFileSystemWrite (
250 IN EFI_FILE_PROTOCOL
*This
,
251 IN OUT UINTN
*BufferSize
,
256 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
259 if (This
== NULL
|| BufferSize
== NULL
|| Buffer
== NULL
) {
260 return EFI_INVALID_PARAMETER
;
263 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
265 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
267 Status
= PrivateFile
->Io
->Write (PrivateFile
->Io
, BufferSize
, Buffer
);
269 gBS
->RestoreTPL (OldTpl
);
275 Get a file's current position
277 @param This Protocol instance pointer.
278 @param Position Byte position from the start of the file.
280 @retval EFI_SUCCESS Position was updated.
281 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
286 EmuSimpleFileSystemGetPosition (
287 IN EFI_FILE_PROTOCOL
*This
,
292 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
295 if (This
== NULL
|| Position
== NULL
) {
296 return EFI_INVALID_PARAMETER
;
299 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
301 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
303 Status
= PrivateFile
->Io
->GetPosition (PrivateFile
->Io
, Position
);
305 gBS
->RestoreTPL (OldTpl
);
312 Set file's current position
314 @param This Protocol instance pointer.
315 @param Position Byte position from the start of the file.
317 @retval EFI_SUCCESS Position was updated.
318 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
323 EmuSimpleFileSystemSetPosition (
324 IN EFI_FILE_PROTOCOL
*This
,
329 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
333 return EFI_INVALID_PARAMETER
;
336 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
338 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
340 Status
= PrivateFile
->Io
->SetPosition (PrivateFile
->Io
, Position
);
342 gBS
->RestoreTPL (OldTpl
);
348 Get information about a file.
350 @param This Protocol instance pointer.
351 @param InformationType Type of information to return in Buffer.
352 @param BufferSize On input size of buffer, on output amount of data in buffer.
353 @param Buffer The buffer to return data.
355 @retval EFI_SUCCESS Data was returned.
356 @retval EFI_UNSUPPORTED InformationType is not supported.
357 @retval EFI_NO_MEDIA The device has no media.
358 @retval EFI_DEVICE_ERROR The device reported an error.
359 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
360 @retval EFI_WRITE_PROTECTED The device is write protected.
361 @retval EFI_ACCESS_DENIED The file was open for read only.
362 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
367 EmuSimpleFileSystemGetInfo (
368 IN EFI_FILE_PROTOCOL
*This
,
369 IN EFI_GUID
*InformationType
,
370 IN OUT UINTN
*BufferSize
,
375 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
378 if (This
== NULL
|| InformationType
== NULL
|| BufferSize
== NULL
) {
379 return EFI_INVALID_PARAMETER
;
382 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
384 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
386 Status
= PrivateFile
->Io
->GetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
388 gBS
->RestoreTPL (OldTpl
);
394 Set information about a file
396 @param File Protocol instance pointer.
397 @param InformationType Type of information in Buffer.
398 @param BufferSize Size of buffer.
399 @param Buffer The data to write.
401 @retval EFI_SUCCESS Data was set.
402 @retval EFI_UNSUPPORTED InformationType is not supported.
403 @retval EFI_NO_MEDIA The device has no media.
404 @retval EFI_DEVICE_ERROR The device reported an error.
405 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
406 @retval EFI_WRITE_PROTECTED The device is write protected.
407 @retval EFI_ACCESS_DENIED The file was open for read only.
412 EmuSimpleFileSystemSetInfo (
413 IN EFI_FILE_PROTOCOL
*This
,
414 IN EFI_GUID
*InformationType
,
420 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
424 // Check for invalid parameters.
426 if (This
== NULL
|| InformationType
== NULL
|| BufferSize
== 0 || Buffer
== NULL
) {
427 return EFI_INVALID_PARAMETER
;
430 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
432 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
434 Status
= PrivateFile
->Io
->SetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
436 gBS
->RestoreTPL (OldTpl
);
442 Flush data back for the file handle.
444 @param This Protocol instance pointer.
446 @retval EFI_SUCCESS Data was flushed.
447 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
448 @retval EFI_NO_MEDIA The device has no media.
449 @retval EFI_DEVICE_ERROR The device reported an error.
450 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
451 @retval EFI_WRITE_PROTECTED The device is write protected.
452 @retval EFI_ACCESS_DENIED The file was open for read only.
453 @retval EFI_VOLUME_FULL The volume is full.
458 EmuSimpleFileSystemFlush (
459 IN EFI_FILE_PROTOCOL
*This
463 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
467 return EFI_INVALID_PARAMETER
;
470 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
472 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
474 Status
= PrivateFile
->Io
->Flush (PrivateFile
->Io
);
476 gBS
->RestoreTPL (OldTpl
);
483 Open the root directory on a volume.
485 @param This Protocol instance pointer.
486 @param Root Returns an Open file handle for the root directory
488 @retval EFI_SUCCESS The device was opened.
489 @retval EFI_UNSUPPORTED This volume does not support the file system.
490 @retval EFI_NO_MEDIA The device has no media.
491 @retval EFI_DEVICE_ERROR The device reported an error.
492 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
493 @retval EFI_ACCESS_DENIED The service denied access to the file.
494 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
499 EmuSimpleFileSystemOpenVolume (
500 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
501 OUT EFI_FILE_PROTOCOL
**Root
505 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
506 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
509 Status
= EFI_UNSUPPORTED
;
511 if (This
== NULL
|| Root
== NULL
) {
512 return EFI_INVALID_PARAMETER
;
515 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
517 Private
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This
);
519 PrivateFile
= AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE
));
520 if (PrivateFile
== NULL
) {
521 Status
= EFI_OUT_OF_RESOURCES
;
525 PrivateFile
->Signature
= EMU_EFI_FILE_PRIVATE_SIGNATURE
;
526 PrivateFile
->IoThunk
= Private
->IoThunk
;
527 PrivateFile
->SimpleFileSystem
= This
;
529 ZeroMem (&PrivateFile
->EfiFile
, sizeof (PrivateFile
->EfiFile
));
530 PrivateFile
->EfiFile
.Revision
= EFI_FILE_PROTOCOL_REVISION
;
531 PrivateFile
->EfiFile
.Open
= EmuSimpleFileSystemOpen
;
532 PrivateFile
->EfiFile
.Close
= EmuSimpleFileSystemClose
;
533 PrivateFile
->EfiFile
.Delete
= EmuSimpleFileSystemDelete
;
534 PrivateFile
->EfiFile
.Read
= EmuSimpleFileSystemRead
;
535 PrivateFile
->EfiFile
.Write
= EmuSimpleFileSystemWrite
;
536 PrivateFile
->EfiFile
.GetPosition
= EmuSimpleFileSystemGetPosition
;
537 PrivateFile
->EfiFile
.SetPosition
= EmuSimpleFileSystemSetPosition
;
538 PrivateFile
->EfiFile
.GetInfo
= EmuSimpleFileSystemGetInfo
;
539 PrivateFile
->EfiFile
.SetInfo
= EmuSimpleFileSystemSetInfo
;
540 PrivateFile
->EfiFile
.Flush
= EmuSimpleFileSystemFlush
;
542 *Root
= &PrivateFile
->EfiFile
;
544 Status
= Private
->Io
->OpenVolume (Private
->Io
, &PrivateFile
->Io
);
545 if (EFI_ERROR (Status
)) {
551 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
552 &Private
->ControllerNameTable
,
553 Private
->IoThunk
->ConfigString
,
559 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
560 &Private
->ControllerNameTable
,
561 Private
->IoThunk
->ConfigString
,
567 if (EFI_ERROR (Status
)) {
569 gBS
->FreePool (PrivateFile
);
575 gBS
->RestoreTPL (OldTpl
);
581 Tests to see if this driver supports a given controller. If a child device is provided,
582 it further tests to see if this driver supports creating a handle for the specified child device.
584 This function checks to see if the driver specified by This supports the device specified by
585 ControllerHandle. Drivers will typically use the device path attached to
586 ControllerHandle and/or the services from the bus I/O abstraction attached to
587 ControllerHandle to determine if the driver supports ControllerHandle. This function
588 may be called many times during platform initialization. In order to reduce boot times, the tests
589 performed by this function must be very small, and take as little time as possible to execute. This
590 function must not change the state of any hardware devices, and this function must be aware that the
591 device specified by ControllerHandle may already be managed by the same driver or a
592 different driver. This function must match its calls to AllocatePages() with FreePages(),
593 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
594 Because ControllerHandle may have been previously started by the same driver, if a protocol is
595 already in the opened state, then it must not be closed with CloseProtocol(). This is required
596 to guarantee the state of ControllerHandle is not modified by this function.
598 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
599 @param[in] ControllerHandle The handle of the controller to test. This handle
600 must support a protocol interface that supplies
601 an I/O abstraction to the driver.
602 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
603 parameter is ignored by device drivers, and is optional for bus
604 drivers. For bus drivers, if this parameter is not NULL, then
605 the bus driver must determine if the bus controller specified
606 by ControllerHandle and the child controller specified
607 by RemainingDevicePath are both supported by this
610 @retval EFI_SUCCESS The device specified by ControllerHandle and
611 RemainingDevicePath is supported by the driver specified by This.
612 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
613 RemainingDevicePath is already being managed by the driver
615 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
616 RemainingDevicePath is already being managed by a different
617 driver or an application that requires exclusive access.
618 Currently not implemented.
619 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
620 RemainingDevicePath is not supported by the driver specified by This.
624 EmuSimpleFileSystemDriverBindingSupported (
625 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
626 IN EFI_HANDLE ControllerHandle
,
627 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
631 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
634 // Open the IO Abstraction(s) needed to perform the supported test
636 Status
= gBS
->OpenProtocol (
638 &gEmuIoThunkProtocolGuid
,
639 (VOID
**)&EmuIoThunk
,
640 This
->DriverBindingHandle
,
642 EFI_OPEN_PROTOCOL_BY_DRIVER
644 if (EFI_ERROR (Status
)) {
649 // Make sure GUID is for a File System handle.
651 Status
= EFI_UNSUPPORTED
;
652 if (CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
653 Status
= EFI_SUCCESS
;
657 // Close the I/O Abstraction(s) used to perform the supported test
661 &gEmuIoThunkProtocolGuid
,
662 This
->DriverBindingHandle
,
672 Starts a device controller or a bus controller.
674 The Start() function is designed to be invoked from the EFI boot service ConnectController().
675 As a result, much of the error checking on the parameters to Start() has been moved into this
676 common boot service. It is legal to call Start() from other locations,
677 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
678 1. ControllerHandle must be a valid EFI_HANDLE.
679 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
680 EFI_DEVICE_PATH_PROTOCOL.
681 3. Prior to calling Start(), the Supported() function for the driver specified by This must
682 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
684 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
685 @param[in] ControllerHandle The handle of the controller to start. This handle
686 must support a protocol interface that supplies
687 an I/O abstraction to the driver.
688 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
689 parameter is ignored by device drivers, and is optional for bus
690 drivers. For a bus driver, if this parameter is NULL, then handles
691 for all the children of Controller are created by this driver.
692 If this parameter is not NULL and the first Device Path Node is
693 not the End of Device Path Node, then only the handle for the
694 child device specified by the first Device Path Node of
695 RemainingDevicePath is created by this driver.
696 If the first Device Path Node of RemainingDevicePath is
697 the End of Device Path Node, no child handle is created by this
700 @retval EFI_SUCCESS The device was started.
701 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
702 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
703 @retval Others The driver failded to start the device.
708 EmuSimpleFileSystemDriverBindingStart (
709 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
710 IN EFI_HANDLE ControllerHandle
,
711 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
715 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
716 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
721 // Open the IO Abstraction(s) needed
723 Status
= gBS
->OpenProtocol (
725 &gEmuIoThunkProtocolGuid
,
726 (VOID
**)&EmuIoThunk
,
727 This
->DriverBindingHandle
,
729 EFI_OPEN_PROTOCOL_BY_DRIVER
731 if (EFI_ERROR (Status
)) {
738 if (!CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
739 Status
= EFI_UNSUPPORTED
;
743 Private
= AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE
));
744 if (Private
== NULL
) {
745 Status
= EFI_OUT_OF_RESOURCES
;
749 Status
= EmuIoThunk
->Open (EmuIoThunk
);
750 if (EFI_ERROR (Status
)) {
754 Private
->Signature
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE
;
755 Private
->IoThunk
= EmuIoThunk
;
756 Private
->Io
= EmuIoThunk
->Interface
;
758 Private
->SimpleFileSystem
.Revision
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
;
759 Private
->SimpleFileSystem
.OpenVolume
= EmuSimpleFileSystemOpenVolume
;
761 Private
->ControllerNameTable
= NULL
;
765 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
766 &Private
->ControllerNameTable
,
767 EmuIoThunk
->ConfigString
,
773 gEmuSimpleFileSystemComponentName2
.SupportedLanguages
,
774 &Private
->ControllerNameTable
,
775 EmuIoThunk
->ConfigString
,
779 Status
= gBS
->InstallMultipleProtocolInterfaces (
781 &gEfiSimpleFileSystemProtocolGuid
, &Private
->SimpleFileSystem
,
786 if (EFI_ERROR (Status
)) {
787 if (Private
!= NULL
) {
788 if (Private
->ControllerNameTable
!= NULL
) {
789 FreeUnicodeStringTable (Private
->ControllerNameTable
);
792 gBS
->FreePool (Private
);
798 &gEmuIoThunkProtocolGuid
,
799 This
->DriverBindingHandle
,
809 Stops a device controller or a bus controller.
811 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
812 As a result, much of the error checking on the parameters to Stop() has been moved
813 into this common boot service. It is legal to call Stop() from other locations,
814 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
815 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
816 same driver's Start() function.
817 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
818 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
819 Start() function, and the Start() function must have called OpenProtocol() on
820 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
822 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
823 @param[in] ControllerHandle A handle to the device being stopped. The handle must
824 support a bus specific I/O protocol for the driver
825 to use to stop the device.
826 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
827 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
828 if NumberOfChildren is 0.
830 @retval EFI_SUCCESS The device was stopped.
831 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
836 EmuSimpleFileSystemDriverBindingStop (
837 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
838 IN EFI_HANDLE ControllerHandle
,
839 IN UINTN NumberOfChildren
,
840 IN EFI_HANDLE
*ChildHandleBuffer
844 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
845 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
848 // Get our context back
850 Status
= gBS
->OpenProtocol (
852 &gEfiSimpleFileSystemProtocolGuid
,
853 (VOID
**)&SimpleFileSystem
,
854 This
->DriverBindingHandle
,
856 EFI_OPEN_PROTOCOL_GET_PROTOCOL
858 if (EFI_ERROR (Status
)) {
859 return EFI_UNSUPPORTED
;
862 Private
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem
);
865 // Uninstall the Simple File System Protocol from ControllerHandle
867 Status
= gBS
->UninstallMultipleProtocolInterfaces (
869 &gEfiSimpleFileSystemProtocolGuid
, &Private
->SimpleFileSystem
,
872 if (!EFI_ERROR (Status
)) {
873 Status
= gBS
->CloseProtocol (
875 &gEmuIoThunkProtocolGuid
,
876 This
->DriverBindingHandle
,
879 ASSERT_EFI_ERROR (Status
);
881 // Destroy the IO interface.
883 Status
= Private
->IoThunk
->Close (Private
->IoThunk
);
884 ASSERT_EFI_ERROR (Status
);
886 // Free our instance data
888 FreeUnicodeStringTable (Private
->ControllerNameTable
);
889 gBS
->FreePool (Private
);
896 EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding
= {
897 EmuSimpleFileSystemDriverBindingSupported
,
898 EmuSimpleFileSystemDriverBindingStart
,
899 EmuSimpleFileSystemDriverBindingStop
,
909 The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.
911 @param[in] ImageHandle The firmware allocated handle for the EFI image.
912 @param[in] SystemTable A pointer to the EFI System Table.
914 @retval EFI_SUCCESS The entry point is executed successfully.
915 @retval other Some error occurs when executing this entry point.
920 InitializeEmuSimpleFileSystem(
921 IN EFI_HANDLE ImageHandle
,
922 IN EFI_SYSTEM_TABLE
*SystemTable
927 Status
= EfiLibInstallDriverBindingComponentName2 (
930 &gEmuSimpleFileSystemDriverBinding
,
932 &gEmuSimpleFileSystemComponentName
,
933 &gEmuSimpleFileSystemComponentName2
935 ASSERT_EFI_ERROR (Status
);