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 - 2011, Intel Corporation. All rights reserved.<BR>
8 Portions copyright (c) 2011, Apple Inc. All rights reserved.
9 This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "EmuSimpleFileSystem.h"
25 Opens a new file relative to the source file's location.
27 @param This The protocol instance pointer.
28 @param NewHandle Returns File Handle for FileName.
29 @param FileName Null terminated string. "\", ".", and ".." are supported.
30 @param OpenMode Open mode for file.
31 @param Attributes Only used for EFI_FILE_MODE_CREATE.
33 @retval EFI_SUCCESS The device was opened.
34 @retval EFI_NOT_FOUND The specified file could not be found on the device.
35 @retval EFI_NO_MEDIA The device has no media.
36 @retval EFI_MEDIA_CHANGED The media has changed.
37 @retval EFI_DEVICE_ERROR The device reported an error.
38 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
39 @retval EFI_ACCESS_DENIED The service denied access to the file.
40 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
41 @retval EFI_VOLUME_FULL The volume is full.
46 EmuSimpleFileSystemOpen (
47 IN EFI_FILE_PROTOCOL
*This
,
48 OUT EFI_FILE_PROTOCOL
**NewHandle
,
54 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
57 // Check for obvious invalid parameters.
59 if (This
== NULL
|| NewHandle
== NULL
|| FileName
== NULL
) {
60 return EFI_INVALID_PARAMETER
;
64 case EFI_FILE_MODE_CREATE
| EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
65 if (Attributes
&~EFI_FILE_VALID_ATTR
) {
66 return EFI_INVALID_PARAMETER
;
69 if (Attributes
& EFI_FILE_READ_ONLY
) {
70 return EFI_INVALID_PARAMETER
;
76 case EFI_FILE_MODE_READ
:
77 case EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
81 return EFI_INVALID_PARAMETER
;
84 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
86 return PrivateFile
->Io
->Open (PrivateFile
->Io
, NewHandle
, FileName
, OpenMode
, Attributes
);
94 @param This Protocol instance pointer.
96 @retval EFI_SUCCESS The file was closed.
101 EmuSimpleFileSystemClose (
102 IN EFI_FILE_PROTOCOL
*This
106 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
110 return EFI_INVALID_PARAMETER
;
113 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
115 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
117 Status
= PrivateFile
->Io
->Close (PrivateFile
->Io
);
118 if (!EFI_ERROR (Status
)) {
119 gBS
->FreePool (PrivateFile
);
122 gBS
->RestoreTPL (OldTpl
);
129 Close and delete the file handle.
131 @param This Protocol instance pointer.
133 @retval EFI_SUCCESS The file was closed and deleted.
134 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
139 EmuSimpleFileSystemDelete (
140 IN EFI_FILE_PROTOCOL
*This
144 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
148 return EFI_INVALID_PARAMETER
;
151 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
153 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
155 Status
= PrivateFile
->Io
->Delete (PrivateFile
->Io
);
156 if (!EFI_ERROR (Status
)) {
157 gBS
->FreePool (PrivateFile
);
160 gBS
->RestoreTPL (OldTpl
);
167 Read data from the file.
169 @param This Protocol instance pointer.
170 @param BufferSize On input size of buffer, on output amount of data in buffer.
171 @param Buffer The buffer in which data is read.
173 @retval EFI_SUCCESS Data was read.
174 @retval EFI_NO_MEDIA The device has no media.
175 @retval EFI_DEVICE_ERROR The device reported an error.
176 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
177 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
182 EmuSimpleFileSystemRead (
183 IN EFI_FILE_PROTOCOL
*This
,
184 IN OUT UINTN
*BufferSize
,
189 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
192 if (This
== NULL
|| BufferSize
== NULL
) {
193 return EFI_INVALID_PARAMETER
;
196 if ((*BufferSize
!= 0) && (Buffer
== NULL
)) {
197 // Buffer can be NULL if *BufferSize is zero
198 return EFI_INVALID_PARAMETER
;
201 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
203 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
205 Status
= PrivateFile
->Io
->Read (PrivateFile
->Io
, BufferSize
, Buffer
);
207 gBS
->RestoreTPL (OldTpl
);
213 Write data to a file.
215 @param This Protocol instance pointer.
216 @param BufferSize On input size of buffer, on output amount of data in buffer.
217 @param Buffer The buffer in which data to write.
219 @retval EFI_SUCCESS Data was written.
220 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
221 @retval EFI_NO_MEDIA The device has no media.
222 @retval EFI_DEVICE_ERROR The device reported an error.
223 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
224 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
225 @retval EFI_WRITE_PROTECTED The device is write protected.
226 @retval EFI_ACCESS_DENIED The file was open for read only.
227 @retval EFI_VOLUME_FULL The volume is full.
232 EmuSimpleFileSystemWrite (
233 IN EFI_FILE_PROTOCOL
*This
,
234 IN OUT UINTN
*BufferSize
,
239 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
242 if (This
== NULL
|| BufferSize
== NULL
|| Buffer
== NULL
) {
243 return EFI_INVALID_PARAMETER
;
246 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
248 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
250 Status
= PrivateFile
->Io
->Write (PrivateFile
->Io
, BufferSize
, Buffer
);
252 gBS
->RestoreTPL (OldTpl
);
258 Set a files current position
260 @param This Protocol instance pointer.
261 @param Position Byte position from the start of the file.
263 @retval EFI_SUCCESS Position was updated.
264 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
269 EmuSimpleFileSystemGetPosition (
270 IN EFI_FILE_PROTOCOL
*This
,
275 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
278 if (This
== NULL
|| Position
== NULL
) {
279 return EFI_INVALID_PARAMETER
;
282 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
284 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
286 Status
= PrivateFile
->Io
->GetPosition (PrivateFile
->Io
, Position
);
288 gBS
->RestoreTPL (OldTpl
);
295 Get a file's current position
297 @param This Protocol instance pointer.
298 @param Position Byte position from the start of the file.
300 @retval EFI_SUCCESS Position was updated.
301 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
306 EmuSimpleFileSystemSetPosition (
307 IN EFI_FILE_PROTOCOL
*This
,
312 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
316 return EFI_INVALID_PARAMETER
;
319 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
321 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
323 Status
= PrivateFile
->Io
->SetPosition (PrivateFile
->Io
, Position
);
325 gBS
->RestoreTPL (OldTpl
);
331 Get information about a file.
333 @param This Protocol instance pointer.
334 @param InformationType Type of information to return in Buffer.
335 @param BufferSize On input size of buffer, on output amount of data in buffer.
336 @param Buffer The buffer to return data.
338 @retval EFI_SUCCESS Data was returned.
339 @retval EFI_UNSUPPORTED InformationType is not supported.
340 @retval EFI_NO_MEDIA The device has no media.
341 @retval EFI_DEVICE_ERROR The device reported an error.
342 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
343 @retval EFI_WRITE_PROTECTED The device is write protected.
344 @retval EFI_ACCESS_DENIED The file was open for read only.
345 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
350 EmuSimpleFileSystemGetInfo (
351 IN EFI_FILE_PROTOCOL
*This
,
352 IN EFI_GUID
*InformationType
,
353 IN OUT UINTN
*BufferSize
,
358 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
361 if (This
== NULL
|| InformationType
== NULL
|| BufferSize
== NULL
) {
362 return EFI_INVALID_PARAMETER
;
365 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
367 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
369 Status
= PrivateFile
->Io
->GetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
371 gBS
->RestoreTPL (OldTpl
);
377 Set information about a file
379 @param File Protocol instance pointer.
380 @param InformationType Type of information in Buffer.
381 @param BufferSize Size of buffer.
382 @param Buffer The data to write.
384 @retval EFI_SUCCESS Data was set.
385 @retval EFI_UNSUPPORTED InformationType is not supported.
386 @retval EFI_NO_MEDIA The device has no media.
387 @retval EFI_DEVICE_ERROR The device reported an error.
388 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
389 @retval EFI_WRITE_PROTECTED The device is write protected.
390 @retval EFI_ACCESS_DENIED The file was open for read only.
395 EmuSimpleFileSystemSetInfo (
396 IN EFI_FILE_PROTOCOL
*This
,
397 IN EFI_GUID
*InformationType
,
403 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
407 // Check for invalid parameters.
409 if (This
== NULL
|| InformationType
== NULL
|| BufferSize
== 0 || Buffer
== NULL
) {
410 return EFI_INVALID_PARAMETER
;
413 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
415 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
417 Status
= PrivateFile
->Io
->SetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
419 gBS
->RestoreTPL (OldTpl
);
425 Flush data back for the file handle.
427 @param This Protocol instance pointer.
429 @retval EFI_SUCCESS Data was flushed.
430 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
431 @retval EFI_NO_MEDIA The device has no media.
432 @retval EFI_DEVICE_ERROR The device reported an error.
433 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
434 @retval EFI_WRITE_PROTECTED The device is write protected.
435 @retval EFI_ACCESS_DENIED The file was open for read only.
436 @retval EFI_VOLUME_FULL The volume is full.
441 EmuSimpleFileSystemFlush (
442 IN EFI_FILE_PROTOCOL
*This
446 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
450 return EFI_INVALID_PARAMETER
;
453 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
455 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
457 Status
= PrivateFile
->Io
->Flush (PrivateFile
->Io
);
459 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
) {
507 PrivateFile
->Signature
= EMU_EFI_FILE_PRIVATE_SIGNATURE
;
508 PrivateFile
->IoThunk
= Private
->IoThunk
;
509 PrivateFile
->SimpleFileSystem
= This
;
510 PrivateFile
->EfiFile
.Revision
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
;
511 PrivateFile
->EfiFile
.Open
= EmuSimpleFileSystemOpen
;
512 PrivateFile
->EfiFile
.Close
= EmuSimpleFileSystemClose
;
513 PrivateFile
->EfiFile
.Delete
= EmuSimpleFileSystemDelete
;
514 PrivateFile
->EfiFile
.Read
= EmuSimpleFileSystemRead
;
515 PrivateFile
->EfiFile
.Write
= EmuSimpleFileSystemWrite
;
516 PrivateFile
->EfiFile
.GetPosition
= EmuSimpleFileSystemGetPosition
;
517 PrivateFile
->EfiFile
.SetPosition
= EmuSimpleFileSystemSetPosition
;
518 PrivateFile
->EfiFile
.GetInfo
= EmuSimpleFileSystemGetInfo
;
519 PrivateFile
->EfiFile
.SetInfo
= EmuSimpleFileSystemSetInfo
;
520 PrivateFile
->EfiFile
.Flush
= EmuSimpleFileSystemFlush
;
522 *Root
= &PrivateFile
->EfiFile
;
524 Status
= Private
->Io
->OpenVolume (Private
->Io
, &PrivateFile
->Io
);
525 if (EFI_ERROR (Status
)) {
531 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
532 &Private
->ControllerNameTable
,
533 Private
->IoThunk
->ConfigString
,
539 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
540 &Private
->ControllerNameTable
,
541 Private
->IoThunk
->ConfigString
,
547 if (EFI_ERROR (Status
)) {
549 gBS
->FreePool (PrivateFile
);
555 gBS
->RestoreTPL (OldTpl
);
561 Tests to see if this driver supports a given controller. If a child device is provided,
562 it further tests to see if this driver supports creating a handle for the specified child device.
564 This function checks to see if the driver specified by This supports the device specified by
565 ControllerHandle. Drivers will typically use the device path attached to
566 ControllerHandle and/or the services from the bus I/O abstraction attached to
567 ControllerHandle to determine if the driver supports ControllerHandle. This function
568 may be called many times during platform initialization. In order to reduce boot times, the tests
569 performed by this function must be very small, and take as little time as possible to execute. This
570 function must not change the state of any hardware devices, and this function must be aware that the
571 device specified by ControllerHandle may already be managed by the same driver or a
572 different driver. This function must match its calls to AllocatePages() with FreePages(),
573 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
574 Because ControllerHandle may have been previously started by the same driver, if a protocol is
575 already in the opened state, then it must not be closed with CloseProtocol(). This is required
576 to guarantee the state of ControllerHandle is not modified by this function.
578 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
579 @param[in] ControllerHandle The handle of the controller to test. This handle
580 must support a protocol interface that supplies
581 an I/O abstraction to the driver.
582 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
583 parameter is ignored by device drivers, and is optional for bus
584 drivers. For bus drivers, if this parameter is not NULL, then
585 the bus driver must determine if the bus controller specified
586 by ControllerHandle and the child controller specified
587 by RemainingDevicePath are both supported by this
590 @retval EFI_SUCCESS The device specified by ControllerHandle and
591 RemainingDevicePath is supported by the driver specified by This.
592 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
593 RemainingDevicePath is already being managed by the driver
595 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
596 RemainingDevicePath is already being managed by a different
597 driver or an application that requires exclusive access.
598 Currently not implemented.
599 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
600 RemainingDevicePath is not supported by the driver specified by This.
604 EmuSimpleFileSystemDriverBindingSupported (
605 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
606 IN EFI_HANDLE ControllerHandle
,
607 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
611 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
614 // Open the IO Abstraction(s) needed to perform the supported test
616 Status
= gBS
->OpenProtocol (
618 &gEmuIoThunkProtocolGuid
,
619 (VOID
**)&EmuIoThunk
,
620 This
->DriverBindingHandle
,
622 EFI_OPEN_PROTOCOL_BY_DRIVER
624 if (EFI_ERROR (Status
)) {
629 // Make sure GUID is for a File System handle.
631 Status
= EFI_UNSUPPORTED
;
632 if (CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
633 Status
= EFI_SUCCESS
;
637 // Close the I/O Abstraction(s) used to perform the supported test
641 &gEmuIoThunkProtocolGuid
,
642 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
) {
728 Status
= EmuIoThunk
->Open (EmuIoThunk
);
729 if (EFI_ERROR (Status
)) {
733 Private
->Signature
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE
;
734 Private
->IoThunk
= EmuIoThunk
;
735 Private
->Io
= EmuIoThunk
->Interface
;
737 Private
->SimpleFileSystem
.Revision
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
;
738 Private
->SimpleFileSystem
.OpenVolume
= EmuSimpleFileSystemOpenVolume
;
740 Private
->ControllerNameTable
= NULL
;
744 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
745 &Private
->ControllerNameTable
,
746 EmuIoThunk
->ConfigString
,
752 gEmuSimpleFileSystemComponentName2
.SupportedLanguages
,
753 &Private
->ControllerNameTable
,
754 EmuIoThunk
->ConfigString
,
758 Status
= gBS
->InstallMultipleProtocolInterfaces (
760 &gEfiSimpleFileSystemProtocolGuid
, &Private
->SimpleFileSystem
,
765 if (EFI_ERROR (Status
)) {
766 if (Private
!= NULL
) {
767 if (Private
->ControllerNameTable
!= NULL
) {
768 FreeUnicodeStringTable (Private
->ControllerNameTable
);
771 gBS
->FreePool (Private
);
777 &gEmuIoThunkProtocolGuid
,
778 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
);
842 Status
= Private
->IoThunk
->Close (Private
->IoThunk
);
845 // Uninstall the Simple File System Protocol from ControllerHandle
847 Status
= gBS
->UninstallMultipleProtocolInterfaces (
849 &gEfiSimpleFileSystemProtocolGuid
, &Private
->SimpleFileSystem
,
852 if (!EFI_ERROR (Status
)) {
853 Status
= gBS
->CloseProtocol (
855 &gEmuIoThunkProtocolGuid
,
856 This
->DriverBindingHandle
,
861 if (!EFI_ERROR (Status
)) {
863 // Free our instance data
865 FreeUnicodeStringTable (Private
->ControllerNameTable
);
866 gBS
->FreePool (Private
);
873 EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding
= {
874 EmuSimpleFileSystemDriverBindingSupported
,
875 EmuSimpleFileSystemDriverBindingStart
,
876 EmuSimpleFileSystemDriverBindingStop
,
886 The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.
888 @param[in] ImageHandle The firmware allocated handle for the EFI image.
889 @param[in] SystemTable A pointer to the EFI System Table.
891 @retval EFI_SUCCESS The entry point is executed successfully.
892 @retval other Some error occurs when executing this entry point.
897 InitializeEmuSimpleFileSystem(
898 IN EFI_HANDLE ImageHandle
,
899 IN EFI_SYSTEM_TABLE
*SystemTable
904 Status
= EfiLibInstallDriverBindingComponentName2 (
907 &gEmuSimpleFileSystemDriverBinding
,
909 &gEmuSimpleFileSystemComponentName
,
910 &gEmuSimpleFileSystemComponentName2
912 ASSERT_EFI_ERROR (Status
);