\r
#include "DevicePath.h"\r
\r
-/**\r
- Function unpacks a device path data structure so that all the nodes of a device path\r
- are naturally aligned.\r
-\r
- @param DevPath A pointer to a device path data structure\r
-\r
- @return If the memory for the device path is successfully allocated, then a pointer to the\r
- new device path is returned. Otherwise, NULL is returned.\r
-\r
-**/\r
-EFI_DEVICE_PATH_PROTOCOL *\r
-UnpackDevicePath (\r
- IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath\r
- )\r
-{\r
- CONST EFI_DEVICE_PATH_PROTOCOL *Src;\r
- EFI_DEVICE_PATH_PROTOCOL *Dest;\r
- EFI_DEVICE_PATH_PROTOCOL *NewPath;\r
- UINTN Size;\r
-\r
- if (DevPath == NULL) {\r
- return NULL;\r
- }\r
- //\r
- // Walk device path and round sizes to valid boundries\r
- //\r
- Src = DevPath;\r
- Size = 0;\r
- for (;;) {\r
- Size += DevicePathNodeLength (Src);\r
- Size += ALIGN_SIZE (Size);\r
-\r
- if (IsDevicePathEnd (Src)) {\r
- break;\r
- }\r
-\r
- Src = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (Src);\r
- }\r
- //\r
- // Allocate space for the unpacked path\r
- //\r
- NewPath = AllocateZeroPool (Size);\r
- if (NewPath != NULL) {\r
-\r
- ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0);\r
-\r
- //\r
- // Copy each node\r
- //\r
- Src = DevPath;\r
- Dest = NewPath;\r
- for (;;) {\r
- Size = DevicePathNodeLength (Src);\r
- CopyMem (Dest, Src, Size);\r
- Size += ALIGN_SIZE (Size);\r
- SetDevicePathNodeLength (Dest, Size);\r
- Dest->Type |= EFI_DP_TYPE_UNPACKED;\r
- Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size);\r
-\r
- if (IsDevicePathEnd (Src)) {\r
- break;\r
- }\r
-\r
- Src = (EFI_DEVICE_PATH_PROTOCOL *) NextDevicePathNode (Src);\r
- }\r
- }\r
-\r
- return NewPath;\r
-}\r
-\r
/**\r
Adjusts the size of a previously allocated buffer.\r
\r
{\r
POOL_PRINT Str;\r
EFI_DEVICE_PATH_PROTOCOL *DevPathNode;\r
- EFI_DEVICE_PATH_PROTOCOL *UnpackDevPath;\r
+ EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode;\r
UINTN Index;\r
UINTN NewSize;\r
VOID (*DumpNode) (POOL_PRINT *, VOID *, BOOLEAN, BOOLEAN);\r
\r
ZeroMem (&Str, sizeof (Str));\r
\r
- //\r
- // Unpacked the device path\r
- //\r
- UnpackDevPath = UnpackDevicePath ((EFI_DEVICE_PATH_PROTOCOL *) DevicePath);\r
- ASSERT (UnpackDevPath != NULL);\r
-\r
//\r
// Process each device path node\r
//\r
- DevPathNode = UnpackDevPath;\r
+ DevPathNode = (EFI_DEVICE_PATH_PROTOCOL *) DevicePath;\r
while (!IsDevicePathEnd (DevPathNode)) {\r
//\r
// Find the handler to dump this device path node\r
CatPrint (&Str, L"/");\r
}\r
}\r
+ \r
+ AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength (DevPathNode), DevPathNode);\r
//\r
// Print this node of the device path\r
//\r
- DumpNode (&Str, DevPathNode, DisplayOnly, AllowShortcuts);\r
-\r
+ DumpNode (&Str, AlignedDevPathNode, DisplayOnly, AllowShortcuts);\r
+ FreePool (AlignedDevPathNode);\r
+ \r
//\r
// Next device path node\r
//\r
DevPathNode = NextDevicePathNode (DevPathNode);\r
}\r
- //\r
- // Shrink pool used for string allocation\r
- //\r
- FreePool (UnpackDevPath);\r
\r
NewSize = (Str.Len + 1) * sizeof (CHAR16);\r
Str.Str = ReallocatePool (Str.Str, NewSize, NewSize);\r