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 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
,
56 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
57 EMU_EFI_FILE_PRIVATE
*NewPrivateFile
;
60 // Check for obvious invalid parameters.
62 if (This
== NULL
|| NewHandle
== NULL
|| FileName
== NULL
) {
63 return EFI_INVALID_PARAMETER
;
67 case EFI_FILE_MODE_CREATE
| EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
68 if (Attributes
&~EFI_FILE_VALID_ATTR
) {
69 return EFI_INVALID_PARAMETER
;
72 if (Attributes
& EFI_FILE_READ_ONLY
) {
73 return EFI_INVALID_PARAMETER
;
79 case EFI_FILE_MODE_READ
:
80 case EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
:
84 return EFI_INVALID_PARAMETER
;
87 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
89 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
91 NewPrivateFile
= AllocateCopyPool (sizeof (EMU_EFI_FILE_PRIVATE
), PrivateFile
);
92 if (NewPrivateFile
== NULL
) {
93 Status
= EFI_OUT_OF_RESOURCES
;
98 Status
= PrivateFile
->Io
->Open (PrivateFile
->Io
, &NewPrivateFile
->Io
, FileName
, OpenMode
, Attributes
);
99 if (!EFI_ERROR (Status
)) {
100 *NewHandle
= &NewPrivateFile
->EfiFile
;
103 FreePool (NewPrivateFile
);
107 gBS
->RestoreTPL (OldTpl
);
115 Close the file handle
117 @param This Protocol instance pointer.
119 @retval EFI_SUCCESS The file was closed.
124 EmuSimpleFileSystemClose (
125 IN EFI_FILE_PROTOCOL
*This
129 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
133 return EFI_INVALID_PARAMETER
;
136 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
138 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
140 Status
= PrivateFile
->Io
->Close (PrivateFile
->Io
);
141 if (!EFI_ERROR (Status
)) {
142 gBS
->FreePool (PrivateFile
);
145 gBS
->RestoreTPL (OldTpl
);
152 Close and delete the file handle.
154 @param This Protocol instance pointer.
156 @retval EFI_SUCCESS The file was closed and deleted.
157 @retval EFI_WARN_DELETE_FAILURE The handle was closed but the file was not deleted.
162 EmuSimpleFileSystemDelete (
163 IN EFI_FILE_PROTOCOL
*This
167 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
171 return EFI_INVALID_PARAMETER
;
174 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
176 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
178 Status
= PrivateFile
->Io
->Delete (PrivateFile
->Io
);
179 if (!EFI_ERROR (Status
)) {
180 gBS
->FreePool (PrivateFile
);
183 gBS
->RestoreTPL (OldTpl
);
190 Read data from the file.
192 @param This Protocol instance pointer.
193 @param BufferSize On input size of buffer, on output amount of data in buffer.
194 @param Buffer The buffer in which data is read.
196 @retval EFI_SUCCESS Data was read.
197 @retval EFI_NO_MEDIA The device has no media.
198 @retval EFI_DEVICE_ERROR The device reported an error.
199 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
200 @retval EFI_BUFFER_TO_SMALL BufferSize is too small. BufferSize contains required size.
205 EmuSimpleFileSystemRead (
206 IN EFI_FILE_PROTOCOL
*This
,
207 IN OUT UINTN
*BufferSize
,
212 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
215 if (This
== NULL
|| BufferSize
== NULL
) {
216 return EFI_INVALID_PARAMETER
;
219 if ((*BufferSize
!= 0) && (Buffer
== NULL
)) {
220 // Buffer can be NULL if *BufferSize is zero
221 return EFI_INVALID_PARAMETER
;
224 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
226 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
228 Status
= PrivateFile
->Io
->Read (PrivateFile
->Io
, BufferSize
, Buffer
);
230 gBS
->RestoreTPL (OldTpl
);
236 Write data to a file.
238 @param This Protocol instance pointer.
239 @param BufferSize On input size of buffer, on output amount of data in buffer.
240 @param Buffer The buffer in which data to write.
242 @retval EFI_SUCCESS Data was written.
243 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
244 @retval EFI_NO_MEDIA The device has no media.
245 @retval EFI_DEVICE_ERROR The device reported an error.
246 @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
247 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
248 @retval EFI_WRITE_PROTECTED The device is write protected.
249 @retval EFI_ACCESS_DENIED The file was open for read only.
250 @retval EFI_VOLUME_FULL The volume is full.
255 EmuSimpleFileSystemWrite (
256 IN EFI_FILE_PROTOCOL
*This
,
257 IN OUT UINTN
*BufferSize
,
262 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
265 if (This
== NULL
|| BufferSize
== NULL
|| Buffer
== NULL
) {
266 return EFI_INVALID_PARAMETER
;
269 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
271 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
273 Status
= PrivateFile
->Io
->Write (PrivateFile
->Io
, BufferSize
, Buffer
);
275 gBS
->RestoreTPL (OldTpl
);
281 Get a file's current position
283 @param This Protocol instance pointer.
284 @param Position Byte position from the start of the file.
286 @retval EFI_SUCCESS Position was updated.
287 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open.
292 EmuSimpleFileSystemGetPosition (
293 IN EFI_FILE_PROTOCOL
*This
,
298 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
301 if (This
== NULL
|| Position
== NULL
) {
302 return EFI_INVALID_PARAMETER
;
305 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
307 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
309 Status
= PrivateFile
->Io
->GetPosition (PrivateFile
->Io
, Position
);
311 gBS
->RestoreTPL (OldTpl
);
318 Set file's current position
320 @param This Protocol instance pointer.
321 @param Position Byte position from the start of the file.
323 @retval EFI_SUCCESS Position was updated.
324 @retval EFI_UNSUPPORTED Seek request for non-zero is not valid on open..
329 EmuSimpleFileSystemSetPosition (
330 IN EFI_FILE_PROTOCOL
*This
,
335 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
339 return EFI_INVALID_PARAMETER
;
342 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
344 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
346 Status
= PrivateFile
->Io
->SetPosition (PrivateFile
->Io
, Position
);
348 gBS
->RestoreTPL (OldTpl
);
354 Get information about a file.
356 @param This Protocol instance pointer.
357 @param InformationType Type of information to return in Buffer.
358 @param BufferSize On input size of buffer, on output amount of data in buffer.
359 @param Buffer The buffer to return data.
361 @retval EFI_SUCCESS Data was returned.
362 @retval EFI_UNSUPPORTED InformationType is not supported.
363 @retval EFI_NO_MEDIA The device has no media.
364 @retval EFI_DEVICE_ERROR The device reported an error.
365 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
366 @retval EFI_WRITE_PROTECTED The device is write protected.
367 @retval EFI_ACCESS_DENIED The file was open for read only.
368 @retval EFI_BUFFER_TOO_SMALL Buffer was too small; required size returned in BufferSize.
373 EmuSimpleFileSystemGetInfo (
374 IN EFI_FILE_PROTOCOL
*This
,
375 IN EFI_GUID
*InformationType
,
376 IN OUT UINTN
*BufferSize
,
381 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
384 if (This
== NULL
|| InformationType
== NULL
|| BufferSize
== NULL
) {
385 return EFI_INVALID_PARAMETER
;
388 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
390 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
392 Status
= PrivateFile
->Io
->GetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
394 gBS
->RestoreTPL (OldTpl
);
400 Set information about a file
402 @param File Protocol instance pointer.
403 @param InformationType Type of information in Buffer.
404 @param BufferSize Size of buffer.
405 @param Buffer The data to write.
407 @retval EFI_SUCCESS Data was set.
408 @retval EFI_UNSUPPORTED InformationType is not supported.
409 @retval EFI_NO_MEDIA The device has no media.
410 @retval EFI_DEVICE_ERROR The device reported an error.
411 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
412 @retval EFI_WRITE_PROTECTED The device is write protected.
413 @retval EFI_ACCESS_DENIED The file was open for read only.
418 EmuSimpleFileSystemSetInfo (
419 IN EFI_FILE_PROTOCOL
*This
,
420 IN EFI_GUID
*InformationType
,
426 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
430 // Check for invalid parameters.
432 if (This
== NULL
|| InformationType
== NULL
|| BufferSize
== 0 || Buffer
== NULL
) {
433 return EFI_INVALID_PARAMETER
;
436 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
438 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
440 Status
= PrivateFile
->Io
->SetInfo (PrivateFile
->Io
, InformationType
, BufferSize
, Buffer
);
442 gBS
->RestoreTPL (OldTpl
);
448 Flush data back for the file handle.
450 @param This Protocol instance pointer.
452 @retval EFI_SUCCESS Data was flushed.
453 @retval EFI_UNSUPPORTED Writes to Open directory are not supported.
454 @retval EFI_NO_MEDIA The device has no media.
455 @retval EFI_DEVICE_ERROR The device reported an error.
456 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
457 @retval EFI_WRITE_PROTECTED The device is write protected.
458 @retval EFI_ACCESS_DENIED The file was open for read only.
459 @retval EFI_VOLUME_FULL The volume is full.
464 EmuSimpleFileSystemFlush (
465 IN EFI_FILE_PROTOCOL
*This
469 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
473 return EFI_INVALID_PARAMETER
;
476 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
478 PrivateFile
= EMU_EFI_FILE_PRIVATE_DATA_FROM_THIS (This
);
480 Status
= PrivateFile
->Io
->Flush (PrivateFile
->Io
);
482 gBS
->RestoreTPL (OldTpl
);
489 Open the root directory on a volume.
491 @param This Protocol instance pointer.
492 @param Root Returns an Open file handle for the root directory
494 @retval EFI_SUCCESS The device was opened.
495 @retval EFI_UNSUPPORTED This volume does not support the file system.
496 @retval EFI_NO_MEDIA The device has no media.
497 @retval EFI_DEVICE_ERROR The device reported an error.
498 @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
499 @retval EFI_ACCESS_DENIED The service denied access to the file.
500 @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of resources.
505 EmuSimpleFileSystemOpenVolume (
506 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
507 OUT EFI_FILE_PROTOCOL
**Root
511 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
512 EMU_EFI_FILE_PRIVATE
*PrivateFile
;
515 Status
= EFI_UNSUPPORTED
;
517 if (This
== NULL
|| Root
== NULL
) {
518 return EFI_INVALID_PARAMETER
;
521 OldTpl
= gBS
->RaiseTPL (TPL_CALLBACK
);
523 Private
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (This
);
525 PrivateFile
= AllocatePool (sizeof (EMU_EFI_FILE_PRIVATE
));
526 if (PrivateFile
== NULL
) {
527 Status
= EFI_OUT_OF_RESOURCES
;
531 PrivateFile
->Signature
= EMU_EFI_FILE_PRIVATE_SIGNATURE
;
532 PrivateFile
->IoThunk
= Private
->IoThunk
;
533 PrivateFile
->SimpleFileSystem
= This
;
535 ZeroMem (&PrivateFile
->EfiFile
, sizeof (PrivateFile
->EfiFile
));
536 PrivateFile
->EfiFile
.Revision
= EFI_FILE_PROTOCOL_REVISION
;
537 PrivateFile
->EfiFile
.Open
= EmuSimpleFileSystemOpen
;
538 PrivateFile
->EfiFile
.Close
= EmuSimpleFileSystemClose
;
539 PrivateFile
->EfiFile
.Delete
= EmuSimpleFileSystemDelete
;
540 PrivateFile
->EfiFile
.Read
= EmuSimpleFileSystemRead
;
541 PrivateFile
->EfiFile
.Write
= EmuSimpleFileSystemWrite
;
542 PrivateFile
->EfiFile
.GetPosition
= EmuSimpleFileSystemGetPosition
;
543 PrivateFile
->EfiFile
.SetPosition
= EmuSimpleFileSystemSetPosition
;
544 PrivateFile
->EfiFile
.GetInfo
= EmuSimpleFileSystemGetInfo
;
545 PrivateFile
->EfiFile
.SetInfo
= EmuSimpleFileSystemSetInfo
;
546 PrivateFile
->EfiFile
.Flush
= EmuSimpleFileSystemFlush
;
548 *Root
= &PrivateFile
->EfiFile
;
550 Status
= Private
->Io
->OpenVolume (Private
->Io
, &PrivateFile
->Io
);
551 if (EFI_ERROR (Status
)) {
557 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
558 &Private
->ControllerNameTable
,
559 Private
->IoThunk
->ConfigString
,
565 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
566 &Private
->ControllerNameTable
,
567 Private
->IoThunk
->ConfigString
,
573 if (EFI_ERROR (Status
)) {
575 gBS
->FreePool (PrivateFile
);
581 gBS
->RestoreTPL (OldTpl
);
587 Tests to see if this driver supports a given controller. If a child device is provided,
588 it further tests to see if this driver supports creating a handle for the specified child device.
590 This function checks to see if the driver specified by This supports the device specified by
591 ControllerHandle. Drivers will typically use the device path attached to
592 ControllerHandle and/or the services from the bus I/O abstraction attached to
593 ControllerHandle to determine if the driver supports ControllerHandle. This function
594 may be called many times during platform initialization. In order to reduce boot times, the tests
595 performed by this function must be very small, and take as little time as possible to execute. This
596 function must not change the state of any hardware devices, and this function must be aware that the
597 device specified by ControllerHandle may already be managed by the same driver or a
598 different driver. This function must match its calls to AllocatePages() with FreePages(),
599 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
600 Because ControllerHandle may have been previously started by the same driver, if a protocol is
601 already in the opened state, then it must not be closed with CloseProtocol(). This is required
602 to guarantee the state of ControllerHandle is not modified by this function.
604 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
605 @param[in] ControllerHandle The handle of the controller to test. This handle
606 must support a protocol interface that supplies
607 an I/O abstraction to the driver.
608 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
609 parameter is ignored by device drivers, and is optional for bus
610 drivers. For bus drivers, if this parameter is not NULL, then
611 the bus driver must determine if the bus controller specified
612 by ControllerHandle and the child controller specified
613 by RemainingDevicePath are both supported by this
616 @retval EFI_SUCCESS The device specified by ControllerHandle and
617 RemainingDevicePath is supported by the driver specified by This.
618 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
619 RemainingDevicePath is already being managed by the driver
621 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
622 RemainingDevicePath is already being managed by a different
623 driver or an application that requires exclusive access.
624 Currently not implemented.
625 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
626 RemainingDevicePath is not supported by the driver specified by This.
630 EmuSimpleFileSystemDriverBindingSupported (
631 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
632 IN EFI_HANDLE ControllerHandle
,
633 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
637 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
640 // Open the IO Abstraction(s) needed to perform the supported test
642 Status
= gBS
->OpenProtocol (
644 &gEmuIoThunkProtocolGuid
,
645 (VOID
**)&EmuIoThunk
,
646 This
->DriverBindingHandle
,
648 EFI_OPEN_PROTOCOL_BY_DRIVER
650 if (EFI_ERROR (Status
)) {
655 // Make sure GUID is for a File System handle.
657 Status
= EFI_UNSUPPORTED
;
658 if (CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
659 Status
= EFI_SUCCESS
;
663 // Close the I/O Abstraction(s) used to perform the supported test
667 &gEmuIoThunkProtocolGuid
,
668 This
->DriverBindingHandle
,
678 Starts a device controller or a bus controller.
680 The Start() function is designed to be invoked from the EFI boot service ConnectController().
681 As a result, much of the error checking on the parameters to Start() has been moved into this
682 common boot service. It is legal to call Start() from other locations,
683 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
684 1. ControllerHandle must be a valid EFI_HANDLE.
685 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
686 EFI_DEVICE_PATH_PROTOCOL.
687 3. Prior to calling Start(), the Supported() function for the driver specified by This must
688 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
690 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
691 @param[in] ControllerHandle The handle of the controller to start. This handle
692 must support a protocol interface that supplies
693 an I/O abstraction to the driver.
694 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
695 parameter is ignored by device drivers, and is optional for bus
696 drivers. For a bus driver, if this parameter is NULL, then handles
697 for all the children of Controller are created by this driver.
698 If this parameter is not NULL and the first Device Path Node is
699 not the End of Device Path Node, then only the handle for the
700 child device specified by the first Device Path Node of
701 RemainingDevicePath is created by this driver.
702 If the first Device Path Node of RemainingDevicePath is
703 the End of Device Path Node, no child handle is created by this
706 @retval EFI_SUCCESS The device was started.
707 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
708 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
709 @retval Others The driver failded to start the device.
714 EmuSimpleFileSystemDriverBindingStart (
715 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
716 IN EFI_HANDLE ControllerHandle
,
717 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
721 EMU_IO_THUNK_PROTOCOL
*EmuIoThunk
;
722 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
727 // Open the IO Abstraction(s) needed
729 Status
= gBS
->OpenProtocol (
731 &gEmuIoThunkProtocolGuid
,
732 (VOID
**)&EmuIoThunk
,
733 This
->DriverBindingHandle
,
735 EFI_OPEN_PROTOCOL_BY_DRIVER
737 if (EFI_ERROR (Status
)) {
744 if (!CompareGuid (EmuIoThunk
->Protocol
, &gEfiSimpleFileSystemProtocolGuid
)) {
745 Status
= EFI_UNSUPPORTED
;
749 Private
= AllocateZeroPool (sizeof (EMU_SIMPLE_FILE_SYSTEM_PRIVATE
));
750 if (Private
== NULL
) {
751 Status
= EFI_OUT_OF_RESOURCES
;
755 Status
= EmuIoThunk
->Open (EmuIoThunk
);
756 if (EFI_ERROR (Status
)) {
760 Private
->Signature
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_SIGNATURE
;
761 Private
->IoThunk
= EmuIoThunk
;
762 Private
->Io
= EmuIoThunk
->Interface
;
764 Private
->SimpleFileSystem
.Revision
= EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION
;
765 Private
->SimpleFileSystem
.OpenVolume
= EmuSimpleFileSystemOpenVolume
;
767 Private
->ControllerNameTable
= NULL
;
771 gEmuSimpleFileSystemComponentName
.SupportedLanguages
,
772 &Private
->ControllerNameTable
,
773 EmuIoThunk
->ConfigString
,
779 gEmuSimpleFileSystemComponentName2
.SupportedLanguages
,
780 &Private
->ControllerNameTable
,
781 EmuIoThunk
->ConfigString
,
785 Status
= gBS
->InstallMultipleProtocolInterfaces (
787 &gEfiSimpleFileSystemProtocolGuid
, &Private
->SimpleFileSystem
,
792 if (EFI_ERROR (Status
)) {
793 if (Private
!= NULL
) {
794 if (Private
->ControllerNameTable
!= NULL
) {
795 FreeUnicodeStringTable (Private
->ControllerNameTable
);
798 gBS
->FreePool (Private
);
804 &gEmuIoThunkProtocolGuid
,
805 This
->DriverBindingHandle
,
815 Stops a device controller or a bus controller.
817 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
818 As a result, much of the error checking on the parameters to Stop() has been moved
819 into this common boot service. It is legal to call Stop() from other locations,
820 but the following calling restrictions must be followed, or the system behavior will not be deterministic.
821 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
822 same driver's Start() function.
823 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
824 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
825 Start() function, and the Start() function must have called OpenProtocol() on
826 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
828 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
829 @param[in] ControllerHandle A handle to the device being stopped. The handle must
830 support a bus specific I/O protocol for the driver
831 to use to stop the device.
832 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
833 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
834 if NumberOfChildren is 0.
836 @retval EFI_SUCCESS The device was stopped.
837 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
842 EmuSimpleFileSystemDriverBindingStop (
843 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
844 IN EFI_HANDLE ControllerHandle
,
845 IN UINTN NumberOfChildren
,
846 IN EFI_HANDLE
*ChildHandleBuffer
850 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
851 EMU_SIMPLE_FILE_SYSTEM_PRIVATE
*Private
;
854 // Get our context back
856 Status
= gBS
->OpenProtocol (
858 &gEfiSimpleFileSystemProtocolGuid
,
859 (VOID
**)&SimpleFileSystem
,
860 This
->DriverBindingHandle
,
862 EFI_OPEN_PROTOCOL_GET_PROTOCOL
864 if (EFI_ERROR (Status
)) {
865 return EFI_UNSUPPORTED
;
868 Private
= EMU_SIMPLE_FILE_SYSTEM_PRIVATE_DATA_FROM_THIS (SimpleFileSystem
);
871 // Uninstall the Simple File System Protocol from ControllerHandle
873 Status
= gBS
->UninstallMultipleProtocolInterfaces (
875 &gEfiSimpleFileSystemProtocolGuid
, &Private
->SimpleFileSystem
,
878 if (!EFI_ERROR (Status
)) {
879 Status
= gBS
->CloseProtocol (
881 &gEmuIoThunkProtocolGuid
,
882 This
->DriverBindingHandle
,
885 ASSERT_EFI_ERROR (Status
);
887 // Destroy the IO interface.
889 Status
= Private
->IoThunk
->Close (Private
->IoThunk
);
890 ASSERT_EFI_ERROR (Status
);
892 // Free our instance data
894 FreeUnicodeStringTable (Private
->ControllerNameTable
);
895 gBS
->FreePool (Private
);
902 EFI_DRIVER_BINDING_PROTOCOL gEmuSimpleFileSystemDriverBinding
= {
903 EmuSimpleFileSystemDriverBindingSupported
,
904 EmuSimpleFileSystemDriverBindingStart
,
905 EmuSimpleFileSystemDriverBindingStop
,
915 The user Entry Point for module EmuSimpleFileSystem. The user code starts with this function.
917 @param[in] ImageHandle The firmware allocated handle for the EFI image.
918 @param[in] SystemTable A pointer to the EFI System Table.
920 @retval EFI_SUCCESS The entry point is executed successfully.
921 @retval other Some error occurs when executing this entry point.
926 InitializeEmuSimpleFileSystem(
927 IN EFI_HANDLE ImageHandle
,
928 IN EFI_SYSTEM_TABLE
*SystemTable
933 Status
= EfiLibInstallDriverBindingComponentName2 (
936 &gEmuSimpleFileSystemDriverBinding
,
938 &gEmuSimpleFileSystemComponentName
,
939 &gEmuSimpleFileSystemComponentName2
941 ASSERT_EFI_ERROR (Status
);