{\r
CHAR16 *FileName;\r
EFI_STATUS Status;\r
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
- EFI_FILE_PROTOCOL *Handle1;\r
- EFI_FILE_PROTOCOL *Handle2;\r
- CHAR16 *FnafPathName;\r
- UINTN PathLen;\r
- EFI_HANDLE DeviceHandle;\r
+ EFI_FILE_PROTOCOL *File;\r
\r
if (FilePath == NULL || FileHandle == NULL) {\r
return (EFI_INVALID_PARAMETER);\r
//\r
// use old shell method.\r
//\r
- Status = gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid,\r
- FilePath,\r
- &DeviceHandle);\r
+ Status = EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attributes);\r
if (EFI_ERROR (Status)) {\r
return Status;\r
}\r
- Status = gBS->OpenProtocol(DeviceHandle,\r
- &gEfiSimpleFileSystemProtocolGuid,\r
- (VOID**)&EfiSimpleFileSystemProtocol,\r
- gImageHandle,\r
- NULL,\r
- EFI_OPEN_PROTOCOL_GET_PROTOCOL);\r
- if (EFI_ERROR (Status)) {\r
- return Status;\r
- }\r
- Status = EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemProtocol, &Handle1);\r
- if (EFI_ERROR (Status)) {\r
- FileHandle = NULL;\r
- return Status;\r
- }\r
-\r
- //\r
- // go down directories one node at a time.\r
- //\r
- while (!IsDevicePathEnd (*FilePath)) {\r
- //\r
- // For file system access each node should be a file path component\r
- //\r
- if (DevicePathType (*FilePath) != MEDIA_DEVICE_PATH ||\r
- DevicePathSubType (*FilePath) != MEDIA_FILEPATH_DP\r
- ) {\r
- FileHandle = NULL;\r
- return (EFI_INVALID_PARAMETER);\r
- }\r
- //\r
- // Open this file path node\r
- //\r
- Handle2 = Handle1;\r
- Handle1 = NULL;\r
-\r
- //\r
- // File Name Alignment Fix (FNAF)\r
- // Handle2->Open may be incapable of handling a unaligned CHAR16 data.\r
- // The structure pointed to by FilePath may be not CHAR16 aligned.\r
- // This code copies the potentially unaligned PathName data from the\r
- // FilePath structure to the aligned FnafPathName for use in the\r
- // calls to Handl2->Open.\r
- //\r
-\r
- //\r
- // Determine length of PathName, in bytes.\r
- //\r
- PathLen = DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE_PATH;\r
-\r
- //\r
- // Allocate memory for the aligned copy of the string Extra allocation is to allow for forced alignment\r
- // Copy bytes from possibly unaligned location to aligned location\r
- //\r
- FnafPathName = AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_PATH*)*FilePath)->PathName);\r
- if (FnafPathName == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
- }\r
-\r
- //\r
- // Try to test opening an existing file\r
- //\r
- Status = Handle2->Open (\r
- Handle2,\r
- &Handle1,\r
- FnafPathName,\r
- OpenMode &~EFI_FILE_MODE_CREATE,\r
- 0\r
- );\r
-\r
- //\r
- // see if the error was that it needs to be created\r
- //\r
- if ((EFI_ERROR (Status)) && (OpenMode != (OpenMode &~EFI_FILE_MODE_CREATE))) {\r
- Status = Handle2->Open (\r
- Handle2,\r
- &Handle1,\r
- FnafPathName,\r
- OpenMode,\r
- Attributes\r
- );\r
- }\r
-\r
- //\r
- // Free the alignment buffer\r
- //\r
- FreePool(FnafPathName);\r
-\r
- //\r
- // Close the last node\r
- //\r
- Handle2->Close (Handle2);\r
-\r
- if (EFI_ERROR(Status)) {\r
- return (Status);\r
- }\r
-\r
- //\r
- // Get the next node\r
- //\r
- *FilePath = NextDevicePathNode (*FilePath);\r
- }\r
\r
//\r
// This is a weak spot since if the undefined SHELL_FILE_HANDLE format changes this must change also!\r
//\r
- *FileHandle = (VOID*)Handle1;\r
+ *FileHandle = (VOID*)File;\r
return (EFI_SUCCESS);\r
}\r
\r