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"
16 Opens a new file relative to the source file's location.
18 @param This The protocol instance pointer.
19 @param NewHandle Returns File Handle for FileName.
20 @param FileName Null terminated string. "\", ".", and ".." are supported.
21 @param OpenMode Open mode for file.
22 @param Attributes Only used for EFI_FILE_MODE_CREATE.
24 @retval EFI_SUCCESS The device was opened.
25 @retval EFI_NOT_FOUND The specified file could not be found on the device.
26 @retval EFI_NO_MEDIA The device has no media.
27 @retval EFI_MEDIA_CHANGED The media has changed.
28 @retval EFI_DEVICE_ERROR The device reported an error.
29 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
30 @retval EFI_ACCESS_DENIED The service denied access to the file.
31 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
32 @retval EFI_VOLUME_FULL The volume is full.
37 EmuSimpleFileSystemOpen (
38 IN EFI_FILE_PROTOCOL
*This
,
39 OUT EFI_FILE_PROTOCOL
**NewHandle
,
47 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
48 EMU_EFI_FILE_PRIVATE
*NewPrivateFile
;
51 // Check for obvious invalid parameters.
53 if ((This
== NULL
) || (NewHandle
== NULL
) || (FileName
== NULL
)) {
54 return EFI_INVALID_PARAMETER
;
58 case EFI_FILE_MODE_CREATE
| EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
59 if (Attributes
&~EFI_FILE_VALID_ATTR
) {
60 return EFI_INVALID_PARAMETER
;
63 if (Attributes
& EFI_FILE_READ_ONLY
) {
64 return EFI_INVALID_PARAMETER
;
70 case EFI_FILE_MODE_READ
:
71 case EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
75 return EFI_INVALID_PARAMETER
;
78 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
80 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
82 NewPrivateFile
= AllocateCopyPool (sizeof (EMU_EFI_FILE_PRIVATE
), PrivateFile
);
83 if (NewPrivateFile
== NULL
) {
84 Status
= EFI_OUT_OF_RESOURCES
;
88 Status
= PrivateFile
->Io
->Open (PrivateFile
->Io
, &NewPrivateFile
->Io
, FileName
, OpenMode
, Attributes
);
89 if (!EFI_ERROR (Status
)) {
90 *NewHandle
= &NewPrivateFile
->EfiFile
;
93 FreePool (NewPrivateFile
);
97 gBS
->RestoreTPL (OldTpl
);
103 Close the file handle
105 @param This Protocol instance pointer.
107 @retval EFI_SUCCESS The file was closed.
112 EmuSimpleFileSystemClose (
113 IN EFI_FILE_PROTOCOL
*This
117 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
121 return EFI_INVALID_PARAMETER
;
124 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
126 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
128 Status
= PrivateFile
->Io
->Close (PrivateFile
->Io
);
129 if (!EFI_ERROR (Status
)) {
130 gBS
->FreePool (PrivateFile
);
133 gBS
->RestoreTPL (OldTpl
);
139 Close and delete the file handle.
141 @param This Protocol instance pointer.
143 @retval EFI_SUCCESS The file was closed and deleted.
144 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
149 EmuSimpleFileSystemDelete (
150 IN EFI_FILE_PROTOCOL
*This
154 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
158 return EFI_INVALID_PARAMETER
;
161 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
163 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
165 Status
= PrivateFile
->Io
->Delete (PrivateFile
->Io
);
166 if (!EFI_ERROR (Status
)) {
167 gBS
->FreePool (PrivateFile
);
170 gBS
->RestoreTPL (OldTpl
);
176 Read data from the file.
178 @param This Protocol instance pointer.
179 @param BufferSize On input size of buffer, on output amount of data in buffer.
180 @param Buffer The buffer in which data is read.
182 @retval EFI_SUCCESS Data was read.
183 @retval EFI_NO_MEDIA The device has no media.
184 @retval EFI_DEVICE_ERROR The device reported an error.
185 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
186 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
191 EmuSimpleFileSystemRead (
192 IN EFI_FILE_PROTOCOL
*This
,
193 IN OUT UINTN
*BufferSize
,
198 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
201 if ((This
== NULL
) || (BufferSize
== NULL
)) {
202 return EFI_INVALID_PARAMETER
;
205 if ((*BufferSize
!= 0) && (Buffer
== NULL
)) {
206 // Buffer can be NULL if *BufferSize is zero
207 return EFI_INVALID_PARAMETER
;
210 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
212 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
214 Status
= PrivateFile
->Io
->Read (PrivateFile
->Io
, BufferSize
, Buffer
);
216 gBS
->RestoreTPL (OldTpl
);
221 Write data to a file.
223 @param This Protocol instance pointer.
224 @param BufferSize On input size of buffer, on output amount of data in buffer.
225 @param Buffer The buffer in which data to write.
227 @retval EFI_SUCCESS Data was written.
228 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
229 @retval EFI_NO_MEDIA The device has no media.
230 @retval EFI_DEVICE_ERROR The device reported an error.
231 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
232 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
233 @retval EFI_WRITE_PROTECTED The device is write protected.
234 @retval EFI_ACCESS_DENIED The file was open for read only.
235 @retval EFI_VOLUME_FULL The volume is full.
240 EmuSimpleFileSystemWrite (
241 IN EFI_FILE_PROTOCOL
*This
,
242 IN OUT UINTN
*BufferSize
,
247 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
250 if ((This
== NULL
) || (BufferSize
== NULL
) || (Buffer
== NULL
)) {
251 return EFI_INVALID_PARAMETER
;
254 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
256 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
258 Status
= PrivateFile
->Io
->Write (PrivateFile
->Io
, BufferSize
, Buffer
);
260 gBS
->RestoreTPL (OldTpl
);
265 Get a file's current position
267 @param This Protocol instance pointer.
268 @param Position Byte position from the start of the file.
270 @retval EFI_SUCCESS Position was updated.
271 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
276 EmuSimpleFileSystemGetPosition (
277 IN EFI_FILE_PROTOCOL
*This
,
282 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
285 if ((This
== NULL
) || (Position
== NULL
)) {
286 return EFI_INVALID_PARAMETER
;
289 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
291 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
293 Status
= PrivateFile
->Io
->GetPosition (PrivateFile
->Io
, Position
);
295 gBS
->RestoreTPL (OldTpl
);
300 Set file's current position
302 @param This Protocol instance pointer.
303 @param Position Byte position from the start of the file.
305 @retval EFI_SUCCESS Position was updated.
306 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
311 EmuSimpleFileSystemSetPosition (
312 IN EFI_FILE_PROTOCOL
*This
,
317 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
321 return EFI_INVALID_PARAMETER
;
324 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
326 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
328 Status
= PrivateFile
->Io
->SetPosition (PrivateFile
->Io
, Position
);
330 gBS
->RestoreTPL (OldTpl
);
335 Get information about a file.
337 @param This Protocol instance pointer.
338 @param InformationType Type of information to return in Buffer.
339 @param BufferSize On input size of buffer, on output amount of data in buffer.
340 @param Buffer The buffer to return data.
342 @retval EFI_SUCCESS Data was returned.
343 @retval EFI_UNSUPPORTED InformationType is not supported.
344 @retval EFI_NO_MEDIA The device has no media.
345 @retval EFI_DEVICE_ERROR The device reported an error.
346 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
347 @retval EFI_WRITE_PROTECTED The device is write protected.
348 @retval EFI_ACCESS_DENIED The file was open for read only.
349 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
354 EmuSimpleFileSystemGetInfo (
355 IN EFI_FILE_PROTOCOL
*This
,
356 IN EFI_GUID
*InformationType
,
357 IN OUT UINTN
*BufferSize
,
362 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
365 if ((This
== NULL
) || (InformationType
== NULL
) || (BufferSize
== NULL
)) {
366 return EFI_INVALID_PARAMETER
;
369 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
371 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
373 Status
= PrivateFile
->Io
->GetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
375 gBS
->RestoreTPL (OldTpl
);
380 Set information about a file
382 @param File Protocol instance pointer.
383 @param InformationType Type of information in Buffer.
384 @param BufferSize Size of buffer.
385 @param Buffer The data to write.
387 @retval EFI_SUCCESS Data was set.
388 @retval EFI_UNSUPPORTED InformationType is not supported.
389 @retval EFI_NO_MEDIA The device has no media.
390 @retval EFI_DEVICE_ERROR The device reported an error.
391 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
392 @retval EFI_WRITE_PROTECTED The device is write protected.
393 @retval EFI_ACCESS_DENIED The file was open for read only.
398 EmuSimpleFileSystemSetInfo (
399 IN EFI_FILE_PROTOCOL
*This
,
400 IN EFI_GUID
*InformationType
,
406 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
410 // Check for invalid parameters.
412 if ((This
== NULL
) || (InformationType
== NULL
) || (BufferSize
== 0) || (Buffer
== NULL
)) {
413 return EFI_INVALID_PARAMETER
;
416 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
418 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
420 Status
= PrivateFile
->Io
->SetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
422 gBS
->RestoreTPL (OldTpl
);
427 Flush data back for the file handle.
429 @param This Protocol instance pointer.
431 @retval EFI_SUCCESS Data was flushed.
432 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
433 @retval EFI_NO_MEDIA The device has no media.
434 @retval EFI_DEVICE_ERROR The device reported an error.
435 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
436 @retval EFI_WRITE_PROTECTED The device is write protected.
437 @retval EFI_ACCESS_DENIED The file was open for read only.
438 @retval EFI_VOLUME_FULL The volume is full.
443 EmuSimpleFileSystemFlush (
444 IN EFI_FILE_PROTOCOL
*This
448 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
452 return EFI_INVALID_PARAMETER
;
455 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
457 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
459 Status
= PrivateFile
->Io
->Flush (PrivateFile
->Io
);
461 gBS
->RestoreTPL (OldTpl
);
466 Open the root directory on a volume.
468 @param This Protocol instance pointer.
469 @param Root Returns an Open file handle for the root directory
471 @retval EFI_SUCCESS The device was opened.
472 @retval EFI_UNSUPPORTED This volume does not support the file system.
473 @retval EFI_NO_MEDIA The device has no media.
474 @retval EFI_DEVICE_ERROR The device reported an error.
475 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
476 @retval EFI_ACCESS_DENIED The service denied access to the file.
477 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
482 EmuSimpleFileSystemOpenVolume (
483 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
484 OUT EFI_FILE_PROTOCOL
**Root
488 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
489 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
492 Status
= EFI_UNSUPPORTED
;
494 if ((This
== NULL
) || (Root
== NULL
)) {
495 return EFI_INVALID_PARAMETER
;
498 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
500 Private
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This
);
502 PrivateFile
= AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE
));
503 if (PrivateFile
== NULL
) {
504 Status
= EFI_OUT_OF_RESOURCES
;
508 PrivateFile
->Signature
= EMU_EFI_FILE_PRIVATE_SIGNATURE
;
509 PrivateFile
->IoThunk
= Private
->IoThunk
;
510 PrivateFile
->SimpleFileSystem
= This
;
512 ZeroMem (&PrivateFile
->EfiFile
, sizeof (PrivateFile
->EfiFile
));
513 PrivateFile
->EfiFile
.Revision
= EFI_FILE_PROTOCOL_REVISION
;
514 PrivateFile
->EfiFile
.Open
= EmuSimpleFileSystemOpen
;
515 PrivateFile
->EfiFile
.Close
= EmuSimpleFileSystemClose
;
516 PrivateFile
->EfiFile
.Delete
= EmuSimpleFileSystemDelete
;
517 PrivateFile
->EfiFile
.Read
= EmuSimpleFileSystemRead
;
518 PrivateFile
->EfiFile
.Write
= EmuSimpleFileSystemWrite
;
519 PrivateFile
->EfiFile
.GetPosition
= EmuSimpleFileSystemGetPosition
;
520 PrivateFile
->EfiFile
.SetPosition
= EmuSimpleFileSystemSetPosition
;
521 PrivateFile
->EfiFile
.GetInfo
= EmuSimpleFileSystemGetInfo
;
522 PrivateFile
->EfiFile
.SetInfo
= EmuSimpleFileSystemSetInfo
;
523 PrivateFile
->EfiFile
.Flush
= EmuSimpleFileSystemFlush
;
525 *Root
= &PrivateFile
->EfiFile
;
527 Status
= Private
->Io
->OpenVolume (Private
->Io
, &PrivateFile
->Io
);
528 if (EFI_ERROR (Status
)) {
534 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
535 &Private
->ControllerNameTable
,
536 Private
->IoThunk
->ConfigString
,
542 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
543 &Private
->ControllerNameTable
,
544 Private
->IoThunk
->ConfigString
,
549 if (EFI_ERROR (Status
)) {
551 gBS
->FreePool (PrivateFile
);
557 gBS
->RestoreTPL (OldTpl
);
563 Tests to see if this driver supports a given controller. If a child device is provided,
564 it further tests to see if this driver supports creating a handle for the specified child device.
566 This function checks to see if the driver specified by This supports the device specified by
567 ControllerHandle. Drivers will typically use the device path attached to
568 ControllerHandle and/or the services from the bus I/O abstraction attached to
569 ControllerHandle to determine if the driver supports ControllerHandle. This function
570 may be called many times during platform initialization. In order to reduce boot times, the tests
571 performed by this function must be very small, and take as little time as possible to execute. This
572 function must not change the state of any hardware devices, and this function must be aware that the
573 device specified by ControllerHandle may already be managed by the same driver or a
574 different driver. This function must match its calls to AllocatePages() with FreePages(),
575 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
576 Because ControllerHandle may have been previously started by the same driver, if a protocol is
577 already in the opened state, then it must not be closed with CloseProtocol(). This is required
578 to guarantee the state of ControllerHandle is not modified by this function.
580 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
581 @param[in] ControllerHandle The handle of the controller to test. This handle
582 must support a protocol interface that supplies
583 an I/O abstraction to the driver.
584 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
585 parameter is ignored by device drivers, and is optional for bus
586 drivers. For bus drivers, if this parameter is not NULL, then
587 the bus driver must determine if the bus controller specified
588 by ControllerHandle and the child controller specified
589 by RemainingDevicePath are both supported by this
592 @retval EFI_SUCCESS The device specified by ControllerHandle and
593 RemainingDevicePath is supported by the driver specified by This.
594 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
595 RemainingDevicePath is already being managed by the driver
597 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
598 RemainingDevicePath is already being managed by a different
599 driver or an application that requires exclusive access.
600 Currently not implemented.
601 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
602 RemainingDevicePath is not supported by the driver specified by This.
606 EmuSimpleFileSystemDriverBindingSupported (
607 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
608 IN EFI_HANDLE ControllerHandle
,
609 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
613 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
616 // Open the IO Abstraction(s) needed to perform the supported test
618 Status
= gBS
->OpenProtocol (
620 &gEmuIoThunkProtocolGuid
,
621 (VOID
**)&EmuIoThunk
,
622 This
->DriverBindingHandle
,
624 EFI_OPEN_PROTOCOL_BY_DRIVER
626 if (EFI_ERROR (Status
)) {
631 // Make sure GUID is for a File System handle.
633 Status
= EFI_UNSUPPORTED
;
634 if (CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
635 Status
= EFI_SUCCESS
;
639 // Close the I/O Abstraction(s) used to perform the supported test
643 &gEmuIoThunkProtocolGuid
,
644 This
->DriverBindingHandle
,
652 Starts a device controller or a bus controller.
654 The Start() function is designed to be invoked from the EFI boot service ConnectController().
655 As a result, much of the error checking on the parameters to Start() has been moved into this
656 common boot service. It is legal to call Start() from other locations,
657 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
658 1. ControllerHandle must be a valid EFI_HANDLE.
659 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
660 EFI_DEVICE_PATH_PROTOCOL.
661 3. Prior to calling Start(), the Supported() function for the driver specified by This must
662 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
664 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
665 @param[in] ControllerHandle The handle of the controller to start. This handle
666 must support a protocol interface that supplies
667 an I/O abstraction to the driver.
668 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
669 parameter is ignored by device drivers, and is optional for bus
670 drivers. For a bus driver, if this parameter is NULL, then handles
671 for all the children of Controller are created by this driver.
672 If this parameter is not NULL and the first Device Path Node is
673 not the End of Device Path Node, then only the handle for the
674 child device specified by the first Device Path Node of
675 RemainingDevicePath is created by this driver.
676 If the first Device Path Node of RemainingDevicePath is
677 the End of Device Path Node, no child handle is created by this
680 @retval EFI_SUCCESS The device was started.
681 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
682 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
683 @retval Others The driver failded to start the device.
688 EmuSimpleFileSystemDriverBindingStart (
689 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
690 IN EFI_HANDLE ControllerHandle
,
691 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
695 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
696 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
701 // Open the IO Abstraction(s) needed
703 Status
= gBS
->OpenProtocol (
705 &gEmuIoThunkProtocolGuid
,
706 (VOID
**)&EmuIoThunk
,
707 This
->DriverBindingHandle
,
709 EFI_OPEN_PROTOCOL_BY_DRIVER
711 if (EFI_ERROR (Status
)) {
718 if (!CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
719 Status
= EFI_UNSUPPORTED
;
723 Private
= AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE
));
724 if (Private
== NULL
) {
725 Status
= EFI_OUT_OF_RESOURCES
;
729 Status
= EmuIoThunk
->Open (EmuIoThunk
);
730 if (EFI_ERROR (Status
)) {
734 Private
->Signature
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE
;
735 Private
->IoThunk
= EmuIoThunk
;
736 Private
->Io
= EmuIoThunk
->Interface
;
738 Private
->SimpleFileSystem
.Revision
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
;
739 Private
->SimpleFileSystem
.OpenVolume
= EmuSimpleFileSystemOpenVolume
;
741 Private
->ControllerNameTable
= NULL
;
745 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
746 &Private
->ControllerNameTable
,
747 EmuIoThunk
->ConfigString
,
753 gEmuSimpleFileSystemComponentName2
.SupportedLanguages
,
754 &Private
->ControllerNameTable
,
755 EmuIoThunk
->ConfigString
,
759 Status
= gBS
->InstallMultipleProtocolInterfaces (
761 &gEfiSimpleFileSystemProtocolGuid
,
762 &Private
->SimpleFileSystem
,
767 if (EFI_ERROR (Status
)) {
768 if (Private
!= NULL
) {
769 if (Private
->ControllerNameTable
!= NULL
) {
770 FreeUnicodeStringTable (Private
->ControllerNameTable
);
773 gBS
->FreePool (Private
);
778 &gEmuIoThunkProtocolGuid
,
779 This
->DriverBindingHandle
,
788 Stops a device controller or a bus controller.
790 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
791 As a result, much of the error checking on the parameters to Stop() has been moved
792 into this common boot service. It is legal to call Stop() from other locations,
793 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
794 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
795 same driver's Start() function.
796 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
797 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
798 Start() function, and the Start() function must have called OpenProtocol() on
799 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
801 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
802 @param[in] ControllerHandle A handle to the device being stopped. The handle must
803 support a bus specific I/O protocol for the driver
804 to use to stop the device.
805 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
806 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
807 if NumberOfChildren is 0.
809 @retval EFI_SUCCESS The device was stopped.
810 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
815 EmuSimpleFileSystemDriverBindingStop (
816 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
817 IN EFI_HANDLE ControllerHandle
,
818 IN UINTN NumberOfChildren
,
819 IN EFI_HANDLE
*ChildHandleBuffer
823 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
824 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
827 // Get our context back
829 Status
= gBS
->OpenProtocol (
831 &gEfiSimpleFileSystemProtocolGuid
,
832 (VOID
**)&SimpleFileSystem
,
833 This
->DriverBindingHandle
,
835 EFI_OPEN_PROTOCOL_GET_PROTOCOL
837 if (EFI_ERROR (Status
)) {
838 return EFI_UNSUPPORTED
;
841 Private
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem
);
844 // Uninstall the Simple File System Protocol from ControllerHandle
846 Status
= gBS
->UninstallMultipleProtocolInterfaces (
848 &gEfiSimpleFileSystemProtocolGuid
,
849 &Private
->SimpleFileSystem
,
852 if (!EFI_ERROR (Status
)) {
853 Status
= gBS
->CloseProtocol (
855 &gEmuIoThunkProtocolGuid
,
856 This
->DriverBindingHandle
,
859 ASSERT_EFI_ERROR (Status
);
861 // Destroy the IO interface.
863 Status
= Private
->IoThunk
->Close (Private
->IoThunk
);
864 ASSERT_EFI_ERROR (Status
);
866 // Free our instance data
868 FreeUnicodeStringTable (Private
->ControllerNameTable
);
869 gBS
->FreePool (Private
);
875 EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding
= {
876 EmuSimpleFileSystemDriverBindingSupported
,
877 EmuSimpleFileSystemDriverBindingStart
,
878 EmuSimpleFileSystemDriverBindingStop
,
885 The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.
887 @param[in] ImageHandle The firmware allocated handle for the EFI image.
888 @param[in] SystemTable A pointer to the EFI System Table.
890 @retval EFI_SUCCESS The entry point is executed successfully.
891 @retval other Some error occurs when executing this entry point.
896 InitializeEmuSimpleFileSystem (
897 IN EFI_HANDLE ImageHandle
,
898 IN EFI_SYSTEM_TABLE
*SystemTable
903 Status
= EfiLibInstallDriverBindingComponentName2 (
906 &gEmuSimpleFileSystemDriverBinding
,
908 &gEmuSimpleFileSystemComponentName
,
909 &gEmuSimpleFileSystemComponentName2
911 ASSERT_EFI_ERROR (Status
);