EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol;\r
EFI_FILE_PROTOCOL *Handle1;\r
EFI_FILE_PROTOCOL *Handle2;\r
+ CHAR16 *FnafPathName;\r
+ UINTN PathLen;\r
\r
if (FilePath == NULL || FileHandle == NULL || DeviceHandle == NULL) {\r
return (EFI_INVALID_PARAMETER);\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
- ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
+ FnafPathName,\r
OpenMode &~EFI_FILE_MODE_CREATE,\r
0\r
);\r
Status = Handle2->Open (\r
Handle2,\r
&Handle1,\r
- ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\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