Revision: 14905
          http://sourceforge.net/p/edk2/code/14905
Author:   gdong1
Date:     2013-11-27 09:08:29 +0000 (Wed, 27 Nov 2013)
Log Message:
-----------
Makes DxeDeferImageLoadLib not depend on 

Signed-off-by: Dong Guo <[email protected]>
Reviewed-by: Ni, Ruiyu <[email protected]>
Reviewed-by: Ouyang, Qian <[email protected]>

Modified Paths:
--------------
    trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.c
    trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.h
    trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.inf

Modified: 
trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.c
===================================================================
--- trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.c  
2013-11-27 08:57:11 UTC (rev 14904)
+++ trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.c  
2013-11-27 09:08:29 UTC (rev 14905)
@@ -1,7 +1,7 @@
 /** @file
   Implement defer image load services for user identification in UEFI2.2.
 
-Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials 
 are licensed and made available under the terms and conditions of the BSD 
License 
 which accompanies this distribution.  The full text of the license may be 
found at 
@@ -263,57 +263,107 @@
   return EFI_NOT_FOUND;
 }
 
-
 /**
-  Convert the '/' to '\' in the specified string.
+  Get file name from device path.
 
-  @param[in, out]  Str       Points to the string to convert.
+  The file name may contain one or more device path node. Save the file name 
in a 
+  buffer if file name is found. The caller is responsible to free the buffer.  
+  
+  @param[in]  DevicePath     A pointer to a device path.
+  @param[out] FileName       The callee allocated buffer to save the file name 
if file name is found.
+  @param[out] FileNameOffset The offset of file name in device path if file 
name is found.
+  
+  @retval     UINTN          The file name length. 0 means file name is not 
found.
 
 **/
-VOID
-ConvertDPStr (
-  IN OUT EFI_STRING                     Str 
+UINTN 
+GetFileName (
+  IN  CONST EFI_DEVICE_PATH_PROTOCOL          *DevicePath,
+  OUT UINT8                                   **FileName,
+  OUT UINTN                                   *FileNameOffset
   )
 {
-  INTN                                  Count;
-  INTN                                  Index;
-  
-  Count = StrSize(Str) / 2 - 1;
+  UINTN                                       Length;
+  EFI_DEVICE_PATH_PROTOCOL                    *TmpDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL                    *RootDevicePath;
+  CHAR8                                       *NodeStr;
+  UINTN                                       NodeStrLength;
+  CHAR16                                      LastNodeChar;
+  CHAR16                                      FirstNodeChar;
 
-  if (Count < 4) {
-    return;
+  //
+  // Get the length of DevicePath before file name.
+  //
+  Length = 0;
+  RootDevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
+  while (!IsDevicePathEnd (RootDevicePath)) {
+    if ((DevicePathType(RootDevicePath) == MEDIA_DEVICE_PATH) && 
(DevicePathSubType(RootDevicePath) == MEDIA_FILEPATH_DP)) {
+      break;
+    }
+    Length += DevicePathNodeLength (RootDevicePath);
+    RootDevicePath = NextDevicePathNode (RootDevicePath);
   }
-  
+
+  *FileNameOffset = Length;
+  if (Length == 0) {
+    return 0;
+  }
+
   //
-  // Convert device path string.
+  // Get the file name length.
   //
-  Index = Count - 1;
-  while (Index > 0) {
-    //
-    // Find the last '/'.
-    //
-    for (Index = Count - 1; Index > 0; Index--) {
-      if (Str[Index] == L'/')
-        break;
+  Length = 0;
+  TmpDevicePath = RootDevicePath;
+  while (!IsDevicePathEnd (TmpDevicePath)) {
+    if ((DevicePathType(TmpDevicePath) != MEDIA_DEVICE_PATH) || 
(DevicePathSubType(TmpDevicePath) != MEDIA_FILEPATH_DP)) {
+      break;
     }
+    Length += DevicePathNodeLength (TmpDevicePath) - sizeof 
(EFI_DEVICE_PATH_PROTOCOL);
+    TmpDevicePath = NextDevicePathNode (TmpDevicePath);
+  }
+  if (Length == 0) {
+    return 0;
+  }
 
-    //
-    // Check next char.
-    //
-    if (Str[Index + 1] == L'\\')
-      return;
+  *FileName = AllocateZeroPool (Length);
+  ASSERT (*FileName != NULL);
+
+  //
+  // Copy the file name to the buffer.
+  //
+  Length = 0;
+  LastNodeChar = '\\';
+  TmpDevicePath = RootDevicePath;
+  while (!IsDevicePathEnd (TmpDevicePath)) {
+    if ((DevicePathType(TmpDevicePath) != MEDIA_DEVICE_PATH) || 
(DevicePathSubType(TmpDevicePath) != MEDIA_FILEPATH_DP)) {
+      break;
+    }
+
+    FirstNodeChar = (CHAR16) ReadUnaligned16 ((UINT16 *)((UINT8 
*)TmpDevicePath + sizeof (EFI_DEVICE_PATH_PROTOCOL)));
+    NodeStr = (CHAR8 *)TmpDevicePath + sizeof (EFI_DEVICE_PATH_PROTOCOL);
+    NodeStrLength = DevicePathNodeLength (TmpDevicePath) - sizeof 
(EFI_DEVICE_PATH_PROTOCOL) - sizeof(CHAR16);
     
-    Str[Index] = L'\\';
+    if ((FirstNodeChar == '\\') && (LastNodeChar == '\\')) {
+      //
+      // Skip separator "\" when there are two separators.
+      //
+      NodeStr += sizeof (CHAR16);
+      NodeStrLength -= sizeof (CHAR16);      
+    } else if ((FirstNodeChar != '\\') && (LastNodeChar != '\\')) {
+      //
+      // Add separator "\" when there is no separator.
+      //
+      WriteUnaligned16 ((UINT16 *)(*FileName + Length), '\\');
+      Length += sizeof (CHAR16);
+    } 
+    CopyMem (*FileName + Length, NodeStr, NodeStrLength);
+    Length += NodeStrLength;
     
-    //
-    // Check previous char.
-    //
-    if ((Index > 0) && (Str[Index - 1] == L'\\')) {
-      CopyMem (&Str[Index - 1], &Str[Index], (UINTN) ((Count - Index + 1) * 
sizeof (CHAR16)));
-      return;
-    }
-    Index--;
-  }
+    LastNodeChar  = (CHAR16) ReadUnaligned16 ((UINT16 *) (NodeStr + 
NodeStrLength - sizeof(CHAR16)));
+    TmpDevicePath = NextDevicePathNode (TmpDevicePath);
+  }    
+
+  return Length;
 }
 
 
@@ -342,54 +392,72 @@
   IN  CONST EFI_DEVICE_PATH_PROTOCOL          *DevicePath2
   )
 {
-  EFI_STATUS                            Status;
-  EFI_STRING                            DevicePathStr1;
-  EFI_STRING                            DevicePathStr2;
-  UINTN                                 StrLen1;
-  UINTN                                 StrLen2;
-  EFI_DEVICE_PATH_TO_TEXT_PROTOCOL      *DevicePathText;
-  BOOLEAN                               DevicePathEqual;
+  UINTN                                       DevicePathSize;
+  UINTN                                       FileNameSize1;
+  UINTN                                       FileNameSize2;
+  UINT8                                       *FileName1;
+  UINT8                                       *FileName2;
+  UINTN                                       FileNameOffset1;
+  UINTN                                       FileNameOffset2;
+  BOOLEAN                                     DevicePathEqual;
 
+  FileName1       = NULL;
+  FileName2       = NULL;
+  DevicePathEqual = TRUE;
+
   ASSERT (DevicePath1 != NULL);
   ASSERT (DevicePath2 != NULL);
+  if (IsDevicePathEnd (DevicePath1)) {
+    return FALSE;
+  }
   
-  DevicePathEqual = FALSE;
-  DevicePathText  = NULL;
-  Status = gBS->LocateProtocol ( 
-                  &gEfiDevicePathToTextProtocolGuid,
-                  NULL,
-                  (VOID **) &DevicePathText
-                  );
-  ASSERT (Status == EFI_SUCCESS);
-  
   //
-  // Get first device path string.
+  // The file name may contain one or more device path node. 
+  // To compare the file name, copy file name to a buffer and compare the 
buffer.
   //
-  DevicePathStr1 = DevicePathText->ConvertDevicePathToText (DevicePath1, TRUE, 
TRUE);
-  ConvertDPStr (DevicePathStr1);
+  FileNameSize1 = GetFileName (DevicePath1, &FileName1, &FileNameOffset1);
+  if (FileNameSize1 != 0) {
+    FileNameSize2 = GetFileName (DevicePath2, &FileName2, &FileNameOffset2);
+    if (FileNameOffset1 != FileNameOffset2) {
+      DevicePathEqual = FALSE;
+      goto Done;
+    }
+    if (CompareMem (DevicePath1, DevicePath2, FileNameOffset1) != 0) {      
+      DevicePathEqual = FALSE;
+      goto Done;
+    }
+    if (FileNameSize1 > FileNameSize2) {
+      DevicePathEqual = FALSE;
+      goto Done;
+    }
+    if (CompareMem (FileName1, FileName2, FileNameSize1) != 0) {      
+      DevicePathEqual = FALSE;
+      goto Done;
+    }
+    DevicePathEqual = TRUE;
+    goto Done;
+  }
+
+  DevicePathSize = GetDevicePathSize (DevicePath1);
+  if (DevicePathSize > GetDevicePathSize (DevicePath2)) {
+    return FALSE;
+  }
+
   //
-  // Get second device path string.
+  // Exclude the end of device path node.
   //
-  DevicePathStr2 = DevicePathText->ConvertDevicePathToText (DevicePath2, TRUE, 
TRUE);
-  ConvertDPStr (DevicePathStr2);
-  
-  //
-  // Compare device path string.
-  //
-  StrLen1 = StrSize (DevicePathStr1);
-  StrLen2 = StrSize (DevicePathStr2);
-  if (StrLen1 > StrLen2) {
+  DevicePathSize -= sizeof (EFI_DEVICE_PATH_PROTOCOL);
+  if (CompareMem (DevicePath1, DevicePath2, DevicePathSize) != 0) {
     DevicePathEqual = FALSE;
-    goto Done;
-  }
+  } 
   
-  if (CompareMem (DevicePathStr1, DevicePathStr2, StrLen1) == 0) {
-    DevicePathEqual = TRUE;
+Done: 
+  if (FileName1 != NULL) {
+    FreePool (FileName1);
   }
-
-Done:
-  FreePool (DevicePathStr1);
-  FreePool (DevicePathStr2);
+  if (FileName2 != NULL) {
+    FreePool (FileName2);
+  }
   return DevicePathEqual;
 }
 

Modified: 
trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.h
===================================================================
--- trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.h  
2013-11-27 08:57:11 UTC (rev 14904)
+++ trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.h  
2013-11-27 09:08:29 UTC (rev 14905)
@@ -2,7 +2,7 @@
   The internal header file includes the common header files, defines
   internal structure and functions used by DeferImageLoadLib.
 
-Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
 This program and the accompanying materials 
 are licensed and made available under the terms and conditions of the BSD 
License 
 which accompanies this distribution.  The full text of the license may be 
found at 
@@ -34,7 +34,6 @@
 #include <Protocol/DeferredImageLoad.h>
 #include <Protocol/UserCredential.h>
 #include <Protocol/UserManager.h>
-#include <Protocol/DevicePathToText.h>
 
 #include <Guid/GlobalVariable.h>
 

Modified: 
trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.inf
===================================================================
--- 
trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.inf    
    2013-11-27 08:57:11 UTC (rev 14904)
+++ 
trunk/edk2/SecurityPkg/Library/DxeDeferImageLoadLib/DxeDeferImageLoadLib.inf    
    2013-11-27 09:08:29 UTC (rev 14905)
@@ -1,7 +1,7 @@
 ## @file
 #  The library instance provides security service of deferring image load.
 #
-# Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2009 - 2013, Intel Corporation. All rights reserved.<BR>
 # This program and the accompanying materials
 # are licensed and made available under the terms and conditions of the BSD 
License
 # which accompanies this distribution. The full text of the license may be 
found at
@@ -53,7 +53,6 @@
   gEfiSimpleFileSystemProtocolGuid
   gEfiUserManagerProtocolGuid
   gEfiDeferredImageLoadProtocolGuid
-  gEfiDevicePathToTextProtocolGuid
   
 [Guids]
   gEfiGlobalVariableGuid

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351&iu=/4140/ostg.clktrk
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to