]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/RamDiskDxe: replace OpenFileByDevicePath() with UefiLib API
authorLaszlo Ersek <lersek@redhat.com>
Wed, 18 Jul 2018 17:38:40 +0000 (19:38 +0200)
committerLaszlo Ersek <lersek@redhat.com>
Thu, 16 Aug 2018 18:02:50 +0000 (20:02 +0200)
Replace the OpenFileByDevicePath() function with EfiOpenFileByDevicePath()
from UefiLib, correcting the following issues:

- imprecise comments on OpenFileByDevicePath(),
- code duplication between this module and other modules,
- local variable name "EfiSimpleFileSystemProtocol" starting with "Efi"
  prefix,
- bogus "FileHandle = NULL" assignments,
- passing a potentially unaligned "FILEPATH_DEVICE_PATH.PathName" field to
  a protocol member function (forbidden by the UEFI spec),
- leaking "Handle1" when the device path type/subtype check fails in the
  loop,
- stale SHELL_FILE_HANDLE reference in a comment.

Cc: Eric Dong <eric.dong@intel.com>
Cc: Jiaxin Wu <jiaxin.wu@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Siyuan Fu <siyuan.fu@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1008
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Star Zeng <star.zeng@intel.com>
Reviewed-by: Jaben Carsey <jaben.carsey@intel.com>
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c
MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h

index cdd2da69041105669e7ec1a5f21a04b4cc0f2ba0..da00e4a420e7ad0663d303b59afc45f8f90c44b6 100644 (file)
@@ -75,7 +75,6 @@
   gEfiDevicePathProtocolGuid                     ## PRODUCES\r
   gEfiBlockIoProtocolGuid                        ## PRODUCES\r
   gEfiBlockIo2ProtocolGuid                       ## PRODUCES\r
-  gEfiSimpleFileSystemProtocolGuid               ## SOMETIMES_CONSUMES\r
   gEfiAcpiTableProtocolGuid                      ## SOMETIMES_CONSUMES\r
   gEfiAcpiSdtProtocolGuid                        ## SOMETIMES_CONSUMES\r
 \r
index 2cfd4bbf6ce85c7711c08f22873f6da378d625ef..95d676fc3939993b4495b9befac823d3b975f4b0 100644 (file)
@@ -111,143 +111,3 @@ FileInfo (
 \r
   return Buffer;\r
 }\r
-\r
-\r
-/**\r
-  This function will open a file or directory referenced by DevicePath.\r
-\r
-  This function opens a file with the open mode according to the file path. The\r
-  Attributes is valid only for EFI_FILE_MODE_CREATE.\r
-\r
-  @param[in, out] FilePath   On input, the device path to the file.\r
-                             On output, the remaining device path.\r
-  @param[out]     FileHandle Pointer to the file handle.\r
-  @param[in]      OpenMode   The mode to open the file with.\r
-  @param[in]      Attributes The file's file attributes.\r
-\r
-  @retval EFI_SUCCESS             The information was set.\r
-  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED         Could not open the file path.\r
-  @retval EFI_NOT_FOUND           The specified file could not be found on the\r
-                                  device or the file system could not be found\r
-                                  on the device.\r
-  @retval EFI_NO_MEDIA            The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or\r
-                                  the medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR        The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED       The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open\r
-                                  the file.\r
-  @retval EFI_VOLUME_FULL         The volume is full.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-OpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL           **FilePath,\r
-  OUT EFI_FILE_HANDLE                       *FileHandle,\r
-  IN UINT64                                 OpenMode,\r
-  IN UINT64                                 Attributes\r
-  )\r
-{\r
-  EFI_STATUS                           Status;\r
-  EFI_SIMPLE_FILE_SYSTEM_PROTOCOL      *EfiSimpleFileSystemProtocol;\r
-  EFI_FILE_PROTOCOL                    *Handle1;\r
-  EFI_FILE_PROTOCOL                    *Handle2;\r
-  EFI_HANDLE                           DeviceHandle;\r
-\r
-  if ((FilePath == NULL || FileHandle == NULL)) {\r
-    return EFI_INVALID_PARAMETER;\r
-  }\r
-\r
-  Status = gBS->LocateDevicePath (\r
-                  &gEfiSimpleFileSystemProtocolGuid,\r
-                  FilePath,\r
-                  &DeviceHandle\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\r
-\r
-  Status = gBS->OpenProtocol(\r
-                  DeviceHandle,\r
-                  &gEfiSimpleFileSystemProtocolGuid,\r
-                  (VOID**)&EfiSimpleFileSystemProtocol,\r
-                  gImageHandle,\r
-                  NULL,\r
-                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
-                  );\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
-  }\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
-    // Try to test opening an existing file\r
-    //\r
-    Status = Handle2->Open (\r
-                          Handle2,\r
-                          &Handle1,\r
-                          ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\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
-                            ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName,\r
-                            OpenMode,\r
-                            Attributes\r
-                           );\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
-  return EFI_SUCCESS;\r
-}\r
index 7ebd397fe68a0e1abc3a508432edbb71255a8517..62933a2d6201654d8dd932182c5eac81016154c6 100644 (file)
@@ -656,7 +656,7 @@ RamDiskCallback (
         //\r
         // Open the file.\r
         //\r
-        Status = OpenFileByDevicePath (\r
+        Status = EfiOpenFileByDevicePath (\r
                    &FileDevPath,\r
                    &FileHandle,\r
                    EFI_FILE_MODE_READ,\r
index 077bb77b25bfab58f1b3f54670bc8f51e0f92902..08a8ca94c9db68ee5680e6988a58c20d850b4918 100644 (file)
@@ -605,45 +605,6 @@ FileInfo (
   );\r
 \r
 \r
-/**\r
-  This function will open a file or directory referenced by DevicePath.\r
-\r
-  This function opens a file with the open mode according to the file path. The\r
-  Attributes is valid only for EFI_FILE_MODE_CREATE.\r
-\r
-  @param[in, out] FilePath   On input, the device path to the file.\r
-                             On output, the remaining device path.\r
-  @param[out]     FileHandle Pointer to the file handle.\r
-  @param[in]      OpenMode   The mode to open the file with.\r
-  @param[in]      Attributes The file's file attributes.\r
-\r
-  @retval EFI_SUCCESS             The information was set.\r
-  @retval EFI_INVALID_PARAMETER   One of the parameters has an invalid value.\r
-  @retval EFI_UNSUPPORTED         Could not open the file path.\r
-  @retval EFI_NOT_FOUND           The specified file could not be found on the\r
-                                  device or the file system could not be found\r
-                                  on the device.\r
-  @retval EFI_NO_MEDIA            The device has no medium.\r
-  @retval EFI_MEDIA_CHANGED       The device has a different medium in it or\r
-                                  the medium is no longer supported.\r
-  @retval EFI_DEVICE_ERROR        The device reported an error.\r
-  @retval EFI_VOLUME_CORRUPTED    The file system structures are corrupted.\r
-  @retval EFI_WRITE_PROTECTED     The file or medium is write protected.\r
-  @retval EFI_ACCESS_DENIED       The file was opened read only.\r
-  @retval EFI_OUT_OF_RESOURCES    Not enough resources were available to open\r
-                                  the file.\r
-  @retval EFI_VOLUME_FULL         The volume is full.\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-OpenFileByDevicePath(\r
-  IN OUT EFI_DEVICE_PATH_PROTOCOL           **FilePath,\r
-  OUT EFI_FILE_HANDLE                       *FileHandle,\r
-  IN UINT64                                 OpenMode,\r
-  IN UINT64                                 Attributes\r
-  );\r
-\r
-\r
 /**\r
   Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI\r
   table.\r