From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533298547891648.1685808317517; Fri, 3 Aug 2018 05:15:47 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 27CFE210D8507; Fri, 3 Aug 2018 05:15:46 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 16144210D8503 for ; Fri, 3 Aug 2018 05:15:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B7CF402347F; Fri, 3 Aug 2018 12:15:44 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0C1D7C38; Fri, 3 Aug 2018 12:15:41 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:31 +0200 Message-Id: <20180803121537.32123-2-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:44 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 1/7] MdePkg/UefiLib: introduce EfiOpenFileByDevicePath() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Eric Dong , Liming Gao , Michael D Kinney , Jiaxin Wu , Jiewen Yao , Star Zeng , Jaben Carsey , Siyuan Fu , Chao Zhang MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The EfiOpenFileByDevicePath() function centralizes functionality from - MdeModulePkg/Universal/Disk/RamDiskDxe - NetworkPkg/TlsAuthConfigDxe - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe - ShellPkg/Library/UefiShellLib unifying the implementation and fixing various bugs. (Ray suggested that we eliminate the special handling of EFI_FILE_MODE_CREATE in the "OpenMode" input parameter as well. We plan to implement that separately, under .) Cc: Chao Zhang Cc: Eric Dong Cc: Jaben Carsey Cc: Jiaxin Wu Cc: Jiewen Yao Cc: Liming Gao Cc: Michael D Kinney Cc: Roman Bacik Cc: Ruiyu Ni Cc: Siyuan Fu Cc: Star Zeng Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Ruiyu Ni --- Notes: v2: =20 - add the following sentence to the FilePath parameter's documentation: "The caller is responsible for ensuring that the device path pointed-to by FilePath is well-formed." [Jiewen] =20 - lift the definition of the local variables that relate to the current device path node from the loop to the top of the function ("FilePathNode", "AlignedPathName", "PathName", "NextFile") [Ray] =20 - report new TianoCore BZ -- "don't distinguish EFI_FILE_MODE_CREATE in EfiOpenFileByDevicePath() / OpenMode" --, and reference it in the commit message, as future work [Ray] =20 - explain ASSERT (EFI_ERROR (Status)) -- as opposed to ASSERT_EFI_ERROR (Status) -- with a code comment [Jaben, Ray] =20 - pick up none of the received Reviewed-by tags (namely from Jaben, Liming, and Ray) due to the *sum* of changes above MdePkg/Library/UefiLib/UefiLib.inf | 1 + MdePkg/Include/Library/UefiLib.h | 88 ++++++++ MdePkg/Library/UefiLib/UefiLib.c | 227 ++++++++++++++++++++ 3 files changed, 316 insertions(+) diff --git a/MdePkg/Library/UefiLib/UefiLib.inf b/MdePkg/Library/UefiLib/Ue= fiLib.inf index f69f0a43b576..a6c739ef3d6d 100644 --- a/MdePkg/Library/UefiLib/UefiLib.inf +++ b/MdePkg/Library/UefiLib/UefiLib.inf @@ -68,6 +68,7 @@ [Protocols] gEfiSimpleTextOutProtocolGuid ## SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES gEfiHiiFontProtocolGuid ## SOMETIMES_CONSUMES + gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES gEfiUgaDrawProtocolGuid | gEfiMdePkgTokenSpaceGuid.PcdUgaConsumeSupport = ## SOMETIMES_CONSUMES # Consumes if gEfiGraphicsOutputProto= colGuid uninstalled gEfiComponentNameProtocolGuid | NOT gEfiMdePkgTokenSpaceGuid.PcdCompone= ntNameDisable ## SOMETIMES_PRODUCES # User chooses to produce it gEfiComponentName2ProtocolGuid | NOT gEfiMdePkgTokenSpaceGuid.PcdCompone= ntName2Disable ## SOMETIMES_PRODUCES # User chooses to produce it diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/Uefi= Lib.h index 7c6fde620c74..f950f1c9c648 100644 --- a/MdePkg/Include/Library/UefiLib.h +++ b/MdePkg/Include/Library/UefiLib.h @@ -33,6 +33,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. #include #include #include +#include +#include =20 #include =20 @@ -1520,4 +1522,90 @@ EfiLocateProtocolBuffer ( OUT UINTN *NoProtocols, OUT VOID ***Buffer ); + +/** + Open or create a file or directory, possibly creating the chain of + directories leading up to the directory. + + EfiOpenFileByDevicePath() first locates EFI_SIMPLE_FILE_SYSTEM_PROTOCOL = on + FilePath, and opens the root directory of that filesystem with + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). + + On the remaining device path, the longest initial sequence of + FILEPATH_DEVICE_PATH nodes is node-wise traversed with + EFI_FILE_PROTOCOL.Open(). For the pathname fragment specified by each + traversed FILEPATH_DEVICE_PATH node, EfiOpenFileByDevicePath() first mas= ks + EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If + EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CREA= TE, + then the operation is retried with the caller's OpenMode and Attributes + unmodified. + + (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attrib= utes + includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a s= ingle + pathname component, then EfiOpenFileByDevicePath() ensures that the spec= ified + series of subdirectories exist on return.) + + The EFI_FILE_PROTOCOL identified by the last FILEPATH_DEVICE_PATH node is + output to the caller; intermediate EFI_FILE_PROTOCOL instances are close= d. If + there are no FILEPATH_DEVICE_PATH nodes past the node that identifies the + filesystem, then the EFI_FILE_PROTOCOL of the root directory of the + filesystem is output to the caller. If a device path node that is differ= ent + from FILEPATH_DEVICE_PATH is encountered relative to the filesystem, the + traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is outp= ut. + + @param[in,out] FilePath On input, the device path to the file or direct= ory + to open or create. The caller is responsible for + ensuring that the device path pointed-to by Fil= ePath + is well-formed. On output, FilePath points one = past + the last node in the original device path that = has + been successfully processed. FilePath is set on + output even if EfiOpenFileByDevicePath() return= s an + error. + + @param[out] File On error, File is set to NULL. On success, File= is + set to the EFI_FILE_PROTOCOL of the root direct= ory + of the filesystem, if there are no + FILEPATH_DEVICE_PATH nodes in FilePath; otherwi= se, + File is set to the EFI_FILE_PROTOCOL identified= by + the last node in FilePath. + + @param[in] OpenMode The OpenMode parameter to pass to + EFI_FILE_PROTOCOL.Open(). For each + FILEPATH_DEVICE_PATH node in FilePath, + EfiOpenFileByDevicePath() first opens the speci= fied + pathname fragment with EFI_FILE_MODE_CREATE mas= ked + out of OpenMode and with Attributes set to 0, a= nd + only retries the operation with EFI_FILE_MODE_C= REATE + unmasked and Attributes propagated if the first= open + attempt fails. + + @param[in] Attributes The Attributes parameter to pass to + EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_CR= EATE + is propagated unmasked in OpenMode. + + @retval EFI_SUCCESS The file or directory has been opened or + created. + + @retval EFI_INVALID_PARAMETER FilePath is NULL; or File is NULL; or Fil= ePath + contains a device path node, past the node + that identifies + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, that is = not a + FILEPATH_DEVICE_PATH node. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @return Error codes propagated from the + LocateDevicePath() and OpenProtocol() boot + services, and from the + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolum= e() + and EFI_FILE_PROTOCOL.Open() member funct= ions. +**/ +EFI_STATUS +EFIAPI +EfiOpenFileByDevicePath ( + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, + OUT EFI_FILE_PROTOCOL **File, + IN UINT64 OpenMode, + IN UINT64 Attributes + ); #endif diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/Uefi= Lib.c index 828a54ce7a97..7bcac5613768 100644 --- a/MdePkg/Library/UefiLib/UefiLib.c +++ b/MdePkg/Library/UefiLib/UefiLib.c @@ -1719,3 +1719,230 @@ EfiLocateProtocolBuffer ( =20 return EFI_SUCCESS; } + +/** + Open or create a file or directory, possibly creating the chain of + directories leading up to the directory. + + EfiOpenFileByDevicePath() first locates EFI_SIMPLE_FILE_SYSTEM_PROTOCOL = on + FilePath, and opens the root directory of that filesystem with + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). + + On the remaining device path, the longest initial sequence of + FILEPATH_DEVICE_PATH nodes is node-wise traversed with + EFI_FILE_PROTOCOL.Open(). For the pathname fragment specified by each + traversed FILEPATH_DEVICE_PATH node, EfiOpenFileByDevicePath() first mas= ks + EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If + EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CREA= TE, + then the operation is retried with the caller's OpenMode and Attributes + unmodified. + + (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attrib= utes + includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a s= ingle + pathname component, then EfiOpenFileByDevicePath() ensures that the spec= ified + series of subdirectories exist on return.) + + The EFI_FILE_PROTOCOL identified by the last FILEPATH_DEVICE_PATH node is + output to the caller; intermediate EFI_FILE_PROTOCOL instances are close= d. If + there are no FILEPATH_DEVICE_PATH nodes past the node that identifies the + filesystem, then the EFI_FILE_PROTOCOL of the root directory of the + filesystem is output to the caller. If a device path node that is differ= ent + from FILEPATH_DEVICE_PATH is encountered relative to the filesystem, the + traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is outp= ut. + + @param[in,out] FilePath On input, the device path to the file or direct= ory + to open or create. The caller is responsible for + ensuring that the device path pointed-to by Fil= ePath + is well-formed. On output, FilePath points one = past + the last node in the original device path that = has + been successfully processed. FilePath is set on + output even if EfiOpenFileByDevicePath() return= s an + error. + + @param[out] File On error, File is set to NULL. On success, File= is + set to the EFI_FILE_PROTOCOL of the root direct= ory + of the filesystem, if there are no + FILEPATH_DEVICE_PATH nodes in FilePath; otherwi= se, + File is set to the EFI_FILE_PROTOCOL identified= by + the last node in FilePath. + + @param[in] OpenMode The OpenMode parameter to pass to + EFI_FILE_PROTOCOL.Open(). For each + FILEPATH_DEVICE_PATH node in FilePath, + EfiOpenFileByDevicePath() first opens the speci= fied + pathname fragment with EFI_FILE_MODE_CREATE mas= ked + out of OpenMode and with Attributes set to 0, a= nd + only retries the operation with EFI_FILE_MODE_C= REATE + unmasked and Attributes propagated if the first= open + attempt fails. + + @param[in] Attributes The Attributes parameter to pass to + EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_CR= EATE + is propagated unmasked in OpenMode. + + @retval EFI_SUCCESS The file or directory has been opened or + created. + + @retval EFI_INVALID_PARAMETER FilePath is NULL; or File is NULL; or Fil= ePath + contains a device path node, past the node + that identifies + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, that is = not a + FILEPATH_DEVICE_PATH node. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @return Error codes propagated from the + LocateDevicePath() and OpenProtocol() boot + services, and from the + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolum= e() + and EFI_FILE_PROTOCOL.Open() member funct= ions. +**/ +EFI_STATUS +EFIAPI +EfiOpenFileByDevicePath ( + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, + OUT EFI_FILE_PROTOCOL **File, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ + EFI_STATUS Status; + EFI_HANDLE FileSystemHandle; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem; + EFI_FILE_PROTOCOL *LastFile; + FILEPATH_DEVICE_PATH *FilePathNode; + CHAR16 *AlignedPathName; + CHAR16 *PathName; + EFI_FILE_PROTOCOL *NextFile; + + if (File =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *File =3D NULL; + + if (FilePath =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Look up the filesystem. + // + Status =3D gBS->LocateDevicePath ( + &gEfiSimpleFileSystemProtocolGuid, + FilePath, + &FileSystemHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D gBS->OpenProtocol ( + FileSystemHandle, + &gEfiSimpleFileSystemProtocolGuid, + (VOID **)&FileSystem, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Open the root directory of the filesystem. After this operation succe= eds, + // we have to release LastFile on error. + // + Status =3D FileSystem->OpenVolume (FileSystem, &LastFile); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Traverse the device path nodes relative to the filesystem. + // + while (!IsDevicePathEnd (*FilePath)) { + if (DevicePathType (*FilePath) !=3D MEDIA_DEVICE_PATH || + DevicePathSubType (*FilePath) !=3D MEDIA_FILEPATH_DP) { + Status =3D EFI_INVALID_PARAMETER; + goto CloseLastFile; + } + FilePathNode =3D (FILEPATH_DEVICE_PATH *)*FilePath; + + // + // FilePathNode->PathName may be unaligned, and the UEFI specification + // requires pointers that are passed to protocol member functions to be + // aligned. Create an aligned copy of the pathname if necessary. + // + if ((UINTN)FilePathNode->PathName % sizeof *FilePathNode->PathName =3D= =3D 0) { + AlignedPathName =3D NULL; + PathName =3D FilePathNode->PathName; + } else { + AlignedPathName =3D AllocateCopyPool ( + (DevicePathNodeLength (FilePathNode) - + SIZE_OF_FILEPATH_DEVICE_PATH), + FilePathNode->PathName + ); + if (AlignedPathName =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto CloseLastFile; + } + PathName =3D AlignedPathName; + } + + // + // Open the next pathname fragment with EFI_FILE_MODE_CREATE masked ou= t and + // with Attributes set to 0. + // + Status =3D LastFile->Open ( + LastFile, + &NextFile, + PathName, + OpenMode & ~(UINT64)EFI_FILE_MODE_CREATE, + 0 + ); + + // + // Retry with EFI_FILE_MODE_CREATE and the original Attributes if the = first + // attempt failed, and the caller specified EFI_FILE_MODE_CREATE. + // + if (EFI_ERROR (Status) && (OpenMode & EFI_FILE_MODE_CREATE) !=3D 0) { + Status =3D LastFile->Open ( + LastFile, + &NextFile, + PathName, + OpenMode, + Attributes + ); + } + + // + // Release any AlignedPathName on both error and success paths; PathNa= me is + // no longer needed. + // + if (AlignedPathName !=3D NULL) { + FreePool (AlignedPathName); + } + if (EFI_ERROR (Status)) { + goto CloseLastFile; + } + + // + // Advance to the next device path node. + // + LastFile->Close (LastFile); + LastFile =3D NextFile; + *FilePath =3D NextDevicePathNode (FilePathNode); + } + + *File =3D LastFile; + return EFI_SUCCESS; + +CloseLastFile: + LastFile->Close (LastFile); + + // + // We are on the error path; we must have set an error Status for return= ing + // to the caller. + // + ASSERT (EFI_ERROR (Status)); + return Status; +} --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533298551552489.82080480456034; Fri, 3 Aug 2018 05:15:51 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 56C90210D850E; Fri, 3 Aug 2018 05:15:47 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id EE0B3210D7F46 for ; Fri, 3 Aug 2018 05:15:45 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3225E406E885; Fri, 3 Aug 2018 12:15:45 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84EF67C38; Fri, 3 Aug 2018 12:15:44 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:32 +0200 Message-Id: <20180803121537.32123-3-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 03 Aug 2018 12:15:45 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Fri, 03 Aug 2018 12:15:45 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 2/7] IntelFrameworkPkg/FrameworkUefiLib: introduce EfiOpenFileByDevicePath() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Copy the EfiOpenFileByDevicePath() implementation from the previous (MdePkg/UefiLib) patch to FrameworkUefiLib. (Note that the FrameworkUefiLib instance too will be updated for .) Cc: Liming Gao Cc: Michael D Kinney Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- Notes: v2: =20 - new patch: with the MdePkg instance finalized, include the implementation in IntelFrameworkPkg too [Liming, Laszlo] =20 - build-tested with: =20 build -a IA32 -a X64 -b NOOPT -t GCC48 \ -p IntelFrameworkPkg/IntelFrameworkPkg.dsc \ -m IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.inf IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.inf | 1 + IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c | 227 ++++= ++++++++++++++++ 2 files changed, 228 insertions(+) diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.in= f b/IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.inf index 8cff19fa3124..182d20fca051 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.inf +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.inf @@ -61,6 +61,7 @@ [Protocols] gEfiSimpleTextOutProtocolGuid ## SOMETIMES_CONSUMES gEfiGraphicsOutputProtocolGuid ## SOMETIMES_CONSUMES gEfiHiiFontProtocolGuid ## SOMETIMES_CONSUMES + gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES gEfiComponentNameProtocolGuid ## SOMETIMES_PRODUCES gEfiComponentName2ProtocolGuid ## SOMETIMES_PRODUCES gEfiDriverConfigurationProtocolGuid ## SOMETIMES_PRODUCES diff --git a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c b/IntelFr= ameworkPkg/Library/FrameworkUefiLib/UefiLib.c index 0aa4506b8f4d..b283d775b470 100644 --- a/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c +++ b/IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLib.c @@ -1691,3 +1691,230 @@ EfiLocateProtocolBuffer ( =20 return EFI_SUCCESS; } + +/** + Open or create a file or directory, possibly creating the chain of + directories leading up to the directory. + + EfiOpenFileByDevicePath() first locates EFI_SIMPLE_FILE_SYSTEM_PROTOCOL = on + FilePath, and opens the root directory of that filesystem with + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). + + On the remaining device path, the longest initial sequence of + FILEPATH_DEVICE_PATH nodes is node-wise traversed with + EFI_FILE_PROTOCOL.Open(). For the pathname fragment specified by each + traversed FILEPATH_DEVICE_PATH node, EfiOpenFileByDevicePath() first mas= ks + EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If + EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CREA= TE, + then the operation is retried with the caller's OpenMode and Attributes + unmodified. + + (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attrib= utes + includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a s= ingle + pathname component, then EfiOpenFileByDevicePath() ensures that the spec= ified + series of subdirectories exist on return.) + + The EFI_FILE_PROTOCOL identified by the last FILEPATH_DEVICE_PATH node is + output to the caller; intermediate EFI_FILE_PROTOCOL instances are close= d. If + there are no FILEPATH_DEVICE_PATH nodes past the node that identifies the + filesystem, then the EFI_FILE_PROTOCOL of the root directory of the + filesystem is output to the caller. If a device path node that is differ= ent + from FILEPATH_DEVICE_PATH is encountered relative to the filesystem, the + traversal is stopped with an error, and a NULL EFI_FILE_PROTOCOL is outp= ut. + + @param[in,out] FilePath On input, the device path to the file or direct= ory + to open or create. The caller is responsible for + ensuring that the device path pointed-to by Fil= ePath + is well-formed. On output, FilePath points one = past + the last node in the original device path that = has + been successfully processed. FilePath is set on + output even if EfiOpenFileByDevicePath() return= s an + error. + + @param[out] File On error, File is set to NULL. On success, File= is + set to the EFI_FILE_PROTOCOL of the root direct= ory + of the filesystem, if there are no + FILEPATH_DEVICE_PATH nodes in FilePath; otherwi= se, + File is set to the EFI_FILE_PROTOCOL identified= by + the last node in FilePath. + + @param[in] OpenMode The OpenMode parameter to pass to + EFI_FILE_PROTOCOL.Open(). For each + FILEPATH_DEVICE_PATH node in FilePath, + EfiOpenFileByDevicePath() first opens the speci= fied + pathname fragment with EFI_FILE_MODE_CREATE mas= ked + out of OpenMode and with Attributes set to 0, a= nd + only retries the operation with EFI_FILE_MODE_C= REATE + unmasked and Attributes propagated if the first= open + attempt fails. + + @param[in] Attributes The Attributes parameter to pass to + EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_CR= EATE + is propagated unmasked in OpenMode. + + @retval EFI_SUCCESS The file or directory has been opened or + created. + + @retval EFI_INVALID_PARAMETER FilePath is NULL; or File is NULL; or Fil= ePath + contains a device path node, past the node + that identifies + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, that is = not a + FILEPATH_DEVICE_PATH node. + + @retval EFI_OUT_OF_RESOURCES Memory allocation failed. + + @return Error codes propagated from the + LocateDevicePath() and OpenProtocol() boot + services, and from the + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolum= e() + and EFI_FILE_PROTOCOL.Open() member funct= ions. +**/ +EFI_STATUS +EFIAPI +EfiOpenFileByDevicePath ( + IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, + OUT EFI_FILE_PROTOCOL **File, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ + EFI_STATUS Status; + EFI_HANDLE FileSystemHandle; + EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *FileSystem; + EFI_FILE_PROTOCOL *LastFile; + FILEPATH_DEVICE_PATH *FilePathNode; + CHAR16 *AlignedPathName; + CHAR16 *PathName; + EFI_FILE_PROTOCOL *NextFile; + + if (File =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + *File =3D NULL; + + if (FilePath =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Look up the filesystem. + // + Status =3D gBS->LocateDevicePath ( + &gEfiSimpleFileSystemProtocolGuid, + FilePath, + &FileSystemHandle + ); + if (EFI_ERROR (Status)) { + return Status; + } + Status =3D gBS->OpenProtocol ( + FileSystemHandle, + &gEfiSimpleFileSystemProtocolGuid, + (VOID **)&FileSystem, + gImageHandle, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Open the root directory of the filesystem. After this operation succe= eds, + // we have to release LastFile on error. + // + Status =3D FileSystem->OpenVolume (FileSystem, &LastFile); + if (EFI_ERROR (Status)) { + return Status; + } + + // + // Traverse the device path nodes relative to the filesystem. + // + while (!IsDevicePathEnd (*FilePath)) { + if (DevicePathType (*FilePath) !=3D MEDIA_DEVICE_PATH || + DevicePathSubType (*FilePath) !=3D MEDIA_FILEPATH_DP) { + Status =3D EFI_INVALID_PARAMETER; + goto CloseLastFile; + } + FilePathNode =3D (FILEPATH_DEVICE_PATH *)*FilePath; + + // + // FilePathNode->PathName may be unaligned, and the UEFI specification + // requires pointers that are passed to protocol member functions to be + // aligned. Create an aligned copy of the pathname if necessary. + // + if ((UINTN)FilePathNode->PathName % sizeof *FilePathNode->PathName =3D= =3D 0) { + AlignedPathName =3D NULL; + PathName =3D FilePathNode->PathName; + } else { + AlignedPathName =3D AllocateCopyPool ( + (DevicePathNodeLength (FilePathNode) - + SIZE_OF_FILEPATH_DEVICE_PATH), + FilePathNode->PathName + ); + if (AlignedPathName =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto CloseLastFile; + } + PathName =3D AlignedPathName; + } + + // + // Open the next pathname fragment with EFI_FILE_MODE_CREATE masked ou= t and + // with Attributes set to 0. + // + Status =3D LastFile->Open ( + LastFile, + &NextFile, + PathName, + OpenMode & ~(UINT64)EFI_FILE_MODE_CREATE, + 0 + ); + + // + // Retry with EFI_FILE_MODE_CREATE and the original Attributes if the = first + // attempt failed, and the caller specified EFI_FILE_MODE_CREATE. + // + if (EFI_ERROR (Status) && (OpenMode & EFI_FILE_MODE_CREATE) !=3D 0) { + Status =3D LastFile->Open ( + LastFile, + &NextFile, + PathName, + OpenMode, + Attributes + ); + } + + // + // Release any AlignedPathName on both error and success paths; PathNa= me is + // no longer needed. + // + if (AlignedPathName !=3D NULL) { + FreePool (AlignedPathName); + } + if (EFI_ERROR (Status)) { + goto CloseLastFile; + } + + // + // Advance to the next device path node. + // + LastFile->Close (LastFile); + LastFile =3D NextFile; + *FilePath =3D NextDevicePathNode (FilePathNode); + } + + *File =3D LastFile; + return EFI_SUCCESS; + +CloseLastFile: + LastFile->Close (LastFile); + + // + // We are on the error path; we must have set an error Status for return= ing + // to the caller. + // + ASSERT (EFI_ERROR (Status)); + return Status; +} --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533298555591483.11596282932624; Fri, 3 Aug 2018 05:15:55 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 84AFA210D850A; Fri, 3 Aug 2018 05:15:48 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 35334210D83FD for ; Fri, 3 Aug 2018 05:15:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 760494012962; Fri, 3 Aug 2018 12:15:46 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6CB1F1D083; Fri, 3 Aug 2018 12:15:45 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:33 +0200 Message-Id: <20180803121537.32123-4-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:46 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:46 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 3/7] MdeModulePkg/RamDiskDxe: replace OpenFileByDevicePath() with UefiLib API X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Siyuan Fu , Jiaxin Wu , Eric Dong , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D 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 Cc: Jiaxin Wu Cc: Ruiyu Ni Cc: Siyuan Fu Cc: Star Zeng Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Star Zeng Reviewed-by: Jaben Carsey --- Notes: v2: - pick up Star's and Jaben's R-b's MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf | 1 - MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h | 39 ------ MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c | 140 -------= ------------- MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c | 2 +- 4 files changed, 1 insertion(+), 181 deletions(-) diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf b/MdeMod= ulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf index cdd2da690411..da00e4a420e7 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskDxe.inf @@ -75,7 +75,6 @@ [Protocols] gEfiDevicePathProtocolGuid ## PRODUCES gEfiBlockIoProtocolGuid ## PRODUCES gEfiBlockIo2ProtocolGuid ## PRODUCES - gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES gEfiAcpiTableProtocolGuid ## SOMETIMES_CONSUMES gEfiAcpiSdtProtocolGuid ## SOMETIMES_CONSUMES =20 diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h b/MdeModu= lePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h index 077bb77b25bf..08a8ca94c9db 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.h @@ -605,45 +605,6 @@ FileInfo ( ); =20 =20 -/** - This function will open a file or directory referenced by DevicePath. - - This function opens a file with the open mode according to the file path= . The - Attributes is valid only for EFI_FILE_MODE_CREATE. - - @param[in, out] FilePath On input, the device path to the file. - On output, the remaining device path. - @param[out] FileHandle Pointer to the file handle. - @param[in] OpenMode The mode to open the file with. - @param[in] Attributes The file's file attributes. - - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid val= ue. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on= the - device or the file system could not be f= ound - on the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it = or - the medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to o= pen - the file. - @retval EFI_VOLUME_FULL The volume is full. -**/ -EFI_STATUS -EFIAPI -OpenFileByDevicePath( - IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_FILE_HANDLE *FileHandle, - IN UINT64 OpenMode, - IN UINT64 Attributes - ); - - /** Publish the RAM disk NVDIMM Firmware Interface Table (NFIT) to the ACPI table. diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c b= /MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c index 2cfd4bbf6ce8..95d676fc3939 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskFileExplorer.c @@ -111,143 +111,3 @@ FileInfo ( =20 return Buffer; } - - -/** - This function will open a file or directory referenced by DevicePath. - - This function opens a file with the open mode according to the file path= . The - Attributes is valid only for EFI_FILE_MODE_CREATE. - - @param[in, out] FilePath On input, the device path to the file. - On output, the remaining device path. - @param[out] FileHandle Pointer to the file handle. - @param[in] OpenMode The mode to open the file with. - @param[in] Attributes The file's file attributes. - - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid val= ue. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found on= the - device or the file system could not be f= ound - on the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it = or - the medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to o= pen - the file. - @retval EFI_VOLUME_FULL The volume is full. -**/ -EFI_STATUS -EFIAPI -OpenFileByDevicePath( - IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_FILE_HANDLE *FileHandle, - IN UINT64 OpenMode, - IN UINT64 Attributes - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol; - EFI_FILE_PROTOCOL *Handle1; - EFI_FILE_PROTOCOL *Handle2; - EFI_HANDLE DeviceHandle; - - if ((FilePath =3D=3D NULL || FileHandle =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Status =3D gBS->LocateDevicePath ( - &gEfiSimpleFileSystemProtocolGuid, - FilePath, - &DeviceHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->OpenProtocol( - DeviceHandle, - &gEfiSimpleFileSystemProtocolGuid, - (VOID**)&EfiSimpleFileSystemProtocol, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemPr= otocol, &Handle1); - if (EFI_ERROR (Status)) { - FileHandle =3D NULL; - return Status; - } - - // - // go down directories one node at a time. - // - while (!IsDevicePathEnd (*FilePath)) { - // - // For file system access each node should be a file path component - // - if (DevicePathType (*FilePath) !=3D MEDIA_DEVICE_PATH || - DevicePathSubType (*FilePath) !=3D MEDIA_FILEPATH_DP - ) { - FileHandle =3D NULL; - return (EFI_INVALID_PARAMETER); - } - // - // Open this file path node - // - Handle2 =3D Handle1; - Handle1 =3D NULL; - - // - // Try to test opening an existing file - // - Status =3D Handle2->Open ( - Handle2, - &Handle1, - ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName, - OpenMode &~EFI_FILE_MODE_CREATE, - 0 - ); - - // - // see if the error was that it needs to be created - // - if ((EFI_ERROR (Status)) && (OpenMode !=3D (OpenMode &~EFI_FILE_MODE_C= REATE))) { - Status =3D Handle2->Open ( - Handle2, - &Handle1, - ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName, - OpenMode, - Attributes - ); - } - // - // Close the last node - // - Handle2->Close (Handle2); - - if (EFI_ERROR(Status)) { - return (Status); - } - - // - // Get the next node - // - *FilePath =3D NextDevicePathNode (*FilePath); - } - - // - // This is a weak spot since if the undefined SHELL_FILE_HANDLE format c= hanges this must change also! - // - *FileHandle =3D (VOID*)Handle1; - return EFI_SUCCESS; -} diff --git a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c b/MdeModu= lePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c index 7ebd397fe68a..62933a2d6201 100644 --- a/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c +++ b/MdeModulePkg/Universal/Disk/RamDiskDxe/RamDiskImpl.c @@ -656,7 +656,7 @@ RamDiskCallback ( // // Open the file. // - Status =3D OpenFileByDevicePath ( + Status =3D EfiOpenFileByDevicePath ( &FileDevPath, &FileHandle, EFI_FILE_MODE_READ, --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533298559987404.9522399663655; Fri, 3 Aug 2018 05:15:59 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id AF807210D8511; Fri, 3 Aug 2018 05:15:49 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0E370210D850A for ; Fri, 3 Aug 2018 05:15:48 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5B896401297E; Fri, 3 Aug 2018 12:15:47 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id AFECC7C38; Fri, 3 Aug 2018 12:15:46 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:34 +0200 Message-Id: <20180803121537.32123-5-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:47 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 4/7] NetworkPkg/TlsAuthConfigDxe: replace OpenFileByDevicePath() with UefiLib API X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Siyuan Fu , Jiaxin Wu MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D 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: Jiaxin Wu Cc: Siyuan Fu Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Jiaxin Wu Reviewed-by: Jaben Carsey --- Notes: v2: - pick up Jiaxin's and Jaben's R-b's NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf | 1 - NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c | 141 +------------------- 2 files changed, 1 insertion(+), 141 deletions(-) diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf b/NetworkPkg/= TlsAuthConfigDxe/TlsAuthConfigDxe.inf index 3cfcdb9983f1..e5face7b4de5 100644 --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigDxe.inf @@ -57,7 +57,6 @@ [LibraryClasses] [Protocols] gEfiDevicePathProtocolGuid ## PRODUCES gEfiHiiConfigAccessProtocolGuid ## PRODUCES - gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES =20 [Guids] gTlsAuthConfigGuid ## PRODUCES ## GUID diff --git a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c b/NetworkPkg/T= lsAuthConfigDxe/TlsAuthConfigImpl.c index 31450b3e4a1b..7259c5e82f61 100644 --- a/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c +++ b/NetworkPkg/TlsAuthConfigDxe/TlsAuthConfigImpl.c @@ -574,145 +574,6 @@ ON_EXIT: return Status; } =20 -/** - This function will open a file or directory referenced by DevicePath. - - This function opens a file with the open mode according to the file path= . The - Attributes is valid only for EFI_FILE_MODE_CREATE. - - @param[in, out] FilePath On input, the device path to the file. - On output, the remaining device path. - @param[out] FileHandle Pointer to the file handle. - @param[in] OpenMode The mode to open the file with. - @param[in] Attributes The file's file attributes. - - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid va= lue. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found o= n the - device or the file system could not be = found on - the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it= or the - medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupte= d. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to = open the - file. - @retval EFI_VOLUME_FULL The volume is full. -**/ -EFI_STATUS -EFIAPI -OpenFileByDevicePath ( - IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_FILE_HANDLE *FileHandle, - IN UINT64 OpenMode, - IN UINT64 Attributes - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol; - EFI_FILE_PROTOCOL *Handle1; - EFI_FILE_PROTOCOL *Handle2; - EFI_HANDLE DeviceHandle; - - if ((FilePath =3D=3D NULL || FileHandle =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Status =3D gBS->LocateDevicePath ( - &gEfiSimpleFileSystemProtocolGuid, - FilePath, - &DeviceHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->OpenProtocol( - DeviceHandle, - &gEfiSimpleFileSystemProtocolGuid, - (VOID**)&EfiSimpleFileSystemProtocol, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemPr= otocol, &Handle1); - if (EFI_ERROR (Status)) { - FileHandle =3D NULL; - return Status; - } - - // - // go down directories one node at a time. - // - while (!IsDevicePathEnd (*FilePath)) { - // - // For file system access each node should be a file path component - // - if (DevicePathType (*FilePath) !=3D MEDIA_DEVICE_PATH || - DevicePathSubType (*FilePath) !=3D MEDIA_FILEPATH_DP - ) { - FileHandle =3D NULL; - return (EFI_INVALID_PARAMETER); - } - // - // Open this file path node - // - Handle2 =3D Handle1; - Handle1 =3D NULL; - - // - // Try to test opening an existing file - // - Status =3D Handle2->Open ( - Handle2, - &Handle1, - ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName, - OpenMode &~EFI_FILE_MODE_CREATE, - 0 - ); - - // - // see if the error was that it needs to be created - // - if ((EFI_ERROR (Status)) && (OpenMode !=3D (OpenMode &~EFI_FILE_MODE_C= REATE))) { - Status =3D Handle2->Open ( - Handle2, - &Handle1, - ((FILEPATH_DEVICE_PATH*)*FilePath)->PathName, - OpenMode, - Attributes - ); - } - // - // Close the last node - // - Handle2->Close (Handle2); - - if (EFI_ERROR(Status)) { - return (Status); - } - - // - // Get the next node - // - *FilePath =3D NextDevicePathNode (*FilePath); - } - - // - // This is a weak spot since if the undefined SHELL_FILE_HANDLE format c= hanges this must change also! - // - *FileHandle =3D (VOID*)Handle1; - return EFI_SUCCESS; -} - /** This function converts an input device structure to a Unicode string. =20 @@ -1039,7 +900,7 @@ UpdatePage( =20 mTlsAuthPrivateData->FileContext->FileName =3D FileName; =20 - OpenFileByDevicePath ( + EfiOpenFileByDevicePath ( &FilePath, &mTlsAuthPrivateData->FileContext->FHandle, EFI_FILE_MODE_READ, --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533298564514967.819018158269; Fri, 3 Aug 2018 05:16:04 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D517E210D851C; Fri, 3 Aug 2018 05:15:50 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 0EEBB210D8511 for ; Fri, 3 Aug 2018 05:15:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 606754012962; Fri, 3 Aug 2018 12:15:48 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 957747C38; Fri, 3 Aug 2018 12:15:47 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:35 +0200 Message-Id: <20180803121537.32123-6-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:48 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 5/7] SecurityPkg/SecureBootConfigDxe: replace OpenFileByDevicePath() with UefiLib API X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jiewen Yao , Chao Zhang MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 =3D NULL" assignments, - leaking "Handle1" when the device path type/subtype check or the realignment-motivated AllocateCopyPool() fails in the loop, - stale SHELL_FILE_HANDLE reference in a comment. Cc: Chao Zhang Cc: Jiewen Yao Cc: Roman Bacik Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Chao Zhang Reviewed-by: Jaben Carsey Reviewed-by : Chao Zhang --- Notes: v2: =20 - pick up Chao's and Jaben's R-b's =20 - insert a space character between "EfiOpenFileByDevicePath" and "(" -- it was missing from the pre-patch code too SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigDxe.= inf | 1 - SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfigFile= Explorer.c | 151 +------------------- 2 files changed, 1 insertion(+), 151 deletions(-) diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigDxe.inf b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/Sec= ureBootConfigDxe.inf index 487fc8cda917..caf95ddac7d9 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gDxe.inf +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gDxe.inf @@ -114,7 +114,6 @@ [Guids] [Protocols] gEfiHiiConfigAccessProtocolGuid ## PRODUCES gEfiDevicePathProtocolGuid ## PRODUCES - gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES gEfiBlockIoProtocolGuid ## SOMETIMES_CONSUMES =20 [Depex] diff --git a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBo= otConfigFileExplorer.c b/SecurityPkg/VariableAuthenticated/SecureBootConfig= Dxe/SecureBootConfigFileExplorer.c index 2a26c20f394c..aef85c470143 100644 --- a/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gFileExplorer.c +++ b/SecurityPkg/VariableAuthenticated/SecureBootConfigDxe/SecureBootConfi= gFileExplorer.c @@ -80,155 +80,6 @@ CleanUpPage ( ); } =20 -/** - This function will open a file or directory referenced by DevicePath. - - This function opens a file with the open mode according to the file path= . The - Attributes is valid only for EFI_FILE_MODE_CREATE. - - @param[in, out] FilePath On input, the device path to the file. - On output, the remaining device path. - @param[out] FileHandle Pointer to the file handle. - @param[in] OpenMode The mode to open the file with. - @param[in] Attributes The file's file attributes. - - @retval EFI_SUCCESS The information was set. - @retval EFI_INVALID_PARAMETER One of the parameters has an invalid va= lue. - @retval EFI_UNSUPPORTED Could not open the file path. - @retval EFI_NOT_FOUND The specified file could not be found o= n the - device or the file system could not be = found on - the device. - @retval EFI_NO_MEDIA The device has no medium. - @retval EFI_MEDIA_CHANGED The device has a different medium in it= or the - medium is no longer supported. - @retval EFI_DEVICE_ERROR The device reported an error. - @retval EFI_VOLUME_CORRUPTED The file system structures are corrupte= d. - @retval EFI_WRITE_PROTECTED The file or medium is write protected. - @retval EFI_ACCESS_DENIED The file was opened read only. - @retval EFI_OUT_OF_RESOURCES Not enough resources were available to = open the - file. - @retval EFI_VOLUME_FULL The volume is full. -**/ -EFI_STATUS -EFIAPI -OpenFileByDevicePath( - IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_FILE_HANDLE *FileHandle, - IN UINT64 OpenMode, - IN UINT64 Attributes - ) -{ - EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol; - EFI_FILE_PROTOCOL *Handle1; - EFI_FILE_PROTOCOL *Handle2; - EFI_HANDLE DeviceHandle; - CHAR16 *PathName; - UINTN PathLength; - - if ((FilePath =3D=3D NULL || FileHandle =3D=3D NULL)) { - return EFI_INVALID_PARAMETER; - } - - Status =3D gBS->LocateDevicePath ( - &gEfiSimpleFileSystemProtocolGuid, - FilePath, - &DeviceHandle - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D gBS->OpenProtocol( - DeviceHandle, - &gEfiSimpleFileSystemProtocolGuid, - (VOID**)&EfiSimpleFileSystemProtocol, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL - ); - if (EFI_ERROR (Status)) { - return Status; - } - - Status =3D EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemPr= otocol, &Handle1); - if (EFI_ERROR (Status)) { - FileHandle =3D NULL; - return Status; - } - - // - // go down directories one node at a time. - // - while (!IsDevicePathEnd (*FilePath)) { - // - // For file system access each node should be a file path component - // - if (DevicePathType (*FilePath) !=3D MEDIA_DEVICE_PATH || - DevicePathSubType (*FilePath) !=3D MEDIA_FILEPATH_DP - ) { - FileHandle =3D NULL; - return (EFI_INVALID_PARAMETER); - } - // - // Open this file path node - // - Handle2 =3D Handle1; - Handle1 =3D NULL; - PathLength =3D DevicePathNodeLength (*FilePath) - sizeof (EFI_DEVICE_P= ATH_PROTOCOL); - PathName =3D AllocateCopyPool (PathLength, ((FILEPATH_DEVICE_PATH*)*Fi= lePath)->PathName); - if (PathName =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Try to test opening an existing file - // - Status =3D Handle2->Open ( - Handle2, - &Handle1, - PathName, - OpenMode &~EFI_FILE_MODE_CREATE, - 0 - ); - - // - // see if the error was that it needs to be created - // - if ((EFI_ERROR (Status)) && (OpenMode !=3D (OpenMode &~EFI_FILE_MODE_C= REATE))) { - Status =3D Handle2->Open ( - Handle2, - &Handle1, - PathName, - OpenMode, - Attributes - ); - } - // - // Close the last node - // - Handle2->Close (Handle2); - - FreePool (PathName); - - if (EFI_ERROR(Status)) { - return (Status); - } - - // - // Get the next node - // - *FilePath =3D NextDevicePathNode (*FilePath); - } - - // - // This is a weak spot since if the undefined SHELL_FILE_HANDLE format c= hanges this must change also! - // - *FileHandle =3D (VOID*)Handle1; - return EFI_SUCCESS; -} - - /** Extract filename from device path. The returned buffer is allocated usin= g AllocateCopyPool. The caller is responsible for freeing the allocated buffer using FreePoo= l(). If return NULL @@ -312,7 +163,7 @@ UpdatePage( =20 gSecureBootPrivateData->FileContext->FileName =3D FileName; =20 - OpenFileByDevicePath( + EfiOpenFileByDevicePath ( &FilePath, &gSecureBootPrivateData->FileContext->FHandle, EFI_FILE_MODE_READ, --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1533298568788784.110085331499; Fri, 3 Aug 2018 05:16:08 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 11D89210D8521; Fri, 3 Aug 2018 05:15:52 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 42E63210D851B for ; Fri, 3 Aug 2018 05:15:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94E4D401297E; Fri, 3 Aug 2018 12:15:49 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9944B7C38; Fri, 3 Aug 2018 12:15:48 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:36 +0200 Message-Id: <20180803121537.32123-7-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:49 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 6/7] ShellPkg/UefiShellLib: drop DeviceHandle param of ShellOpenFileByDevicePath() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey , Ruiyu Ni MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The ShellOpenFileByDevicePath() API promises to set the DeviceHandle output parameter to the handle of the filesystem identified by the FilePath input parameter. However, this doesn't actually happen when the UEFI Shell 2.0 method is used (which is basically "always" nowadays). Accordingly, the only caller of ShellOpenFileByDevicePath(), namely ShellOpenFileByName(), defines a (dummy) local DeviceHandle variable just so it can call ShellOpenFileByDevicePath(). Remove the useless output parameter. Cc: Jaben Carsey Cc: Ruiyu Ni Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Jaben Carsey Reviewed-by: Ruiyu Ni --- Notes: v2: - pick up Jaben's R-b ShellPkg/Library/UefiShellLib/UefiShellLib.inf | 2 +- ShellPkg/Include/Library/ShellLib.h | 2 -- ShellPkg/Library/UefiShellLib/UefiShellLib.c | 11 ++++------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.inf b/ShellPkg/Libr= ary/UefiShellLib/UefiShellLib.inf index 0df632378fe6..38d9a4b81f5f 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.inf +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.inf @@ -19,7 +19,7 @@ [Defines] BASE_NAME =3D UefiShellLib FILE_GUID =3D 449D0F00-2148-4a43-9836-F10B3980ECF5 MODULE_TYPE =3D UEFI_DRIVER - VERSION_STRING =3D 1.1 + VERSION_STRING =3D 1.2 LIBRARY_CLASS =3D ShellLib|UEFI_APPLICATION UEFI_DRIVER= DXE_RUNTIME_DRIVER DXE_DRIVER CONSTRUCTOR =3D ShellLibConstructor DESTRUCTOR =3D ShellLibDestructor diff --git a/ShellPkg/Include/Library/ShellLib.h b/ShellPkg/Include/Library= /ShellLib.h index e360a67ac751..92fddc50f5dd 100644 --- a/ShellPkg/Include/Library/ShellLib.h +++ b/ShellPkg/Include/Library/ShellLib.h @@ -89,7 +89,6 @@ ShellSetFileInfo ( =20 @param[in, out] FilePath On input, the device path to the file. O= n output, the remaining device path. - @param[out] DeviceHandle Pointer to the system device handle. @param[out] FileHandle Pointer to the file handle. @param[in] OpenMode The mode to open the file with. @param[in] Attributes The file's file attributes. @@ -115,7 +114,6 @@ EFI_STATUS EFIAPI ShellOpenFileByDevicePath( IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_HANDLE *DeviceHandle, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Librar= y/UefiShellLib/UefiShellLib.c index 3c24ba1742bf..18c3be4a8bc7 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -472,7 +472,6 @@ ShellSetFileInfo ( =20 @param FilePath on input the device path to the file. On output the remaining device path. - @param DeviceHandle pointer to the system device handle. @param FileHandle pointer to the file handle. @param OpenMode the mode to open the file with. @param Attributes the file's file attributes. @@ -498,7 +497,6 @@ EFI_STATUS EFIAPI ShellOpenFileByDevicePath( IN OUT EFI_DEVICE_PATH_PROTOCOL **FilePath, - OUT EFI_HANDLE *DeviceHandle, OUT SHELL_FILE_HANDLE *FileHandle, IN UINT64 OpenMode, IN UINT64 Attributes @@ -511,8 +509,9 @@ ShellOpenFileByDevicePath( EFI_FILE_PROTOCOL *Handle2; CHAR16 *FnafPathName; UINTN PathLen; + EFI_HANDLE DeviceHandle; =20 - if (FilePath =3D=3D NULL || FileHandle =3D=3D NULL || DeviceHandle =3D= =3D NULL) { + if (FilePath =3D=3D NULL || FileHandle =3D=3D NULL) { return (EFI_INVALID_PARAMETER); } =20 @@ -538,11 +537,11 @@ ShellOpenFileByDevicePath( // Status =3D gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, FilePath, - DeviceHandle); + &DeviceHandle); if (EFI_ERROR (Status)) { return Status; } - Status =3D gBS->OpenProtocol(*DeviceHandle, + Status =3D gBS->OpenProtocol(DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, (VOID**)&EfiSimpleFileSystemProtocol, gImageHandle, @@ -690,7 +689,6 @@ ShellOpenFileByName( IN UINT64 Attributes ) { - EFI_HANDLE DeviceHandle; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_STATUS Status; EFI_FILE_INFO *FileInfo; @@ -774,7 +772,6 @@ ShellOpenFileByName( FilePath =3D mEfiShellEnvironment2->NameToPath ((CHAR16*)FileName); if (FilePath !=3D NULL) { return (ShellOpenFileByDevicePath(&FilePath, - &DeviceHandle, FileHandle, OpenMode, Attributes)); --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Tue Apr 23 17:09:59 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 15332985726194.757129011522807; Fri, 3 Aug 2018 05:16:12 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3FA9E210D8525; Fri, 3 Aug 2018 05:15:52 -0700 (PDT) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 386EF210D851A for ; Fri, 3 Aug 2018 05:15:51 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7983A4012962; Fri, 3 Aug 2018 12:15:50 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-198.rdu2.redhat.com [10.10.120.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEB7A1D083; Fri, 3 Aug 2018 12:15:49 +0000 (UTC) X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=66.187.233.73; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Fri, 3 Aug 2018 14:15:37 +0200 Message-Id: <20180803121537.32123-8-lersek@redhat.com> In-Reply-To: <20180803121537.32123-1-lersek@redhat.com> References: <20180803121537.32123-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 03 Aug 2018 12:15:50 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'lersek@redhat.com' RCPT:'' Subject: [edk2] [PATCH v2 7/7] ShellPkg/UefiShellLib: rebase ShellOpenFileByDevicePath() to UefiLib API X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jaben Carsey , Ruiyu Ni MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RDMRC_1 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Replace the "old shell method" implementation in ShellOpenFileByDevicePath() with EfiOpenFileByDevicePath() from UefiLib, correcting the following issues: - code duplication between this module and other modules, - local variable name "EfiSimpleFileSystemProtocol" starting with "Efi" prefix, - bogus "FileHandle =3D NULL" assignments, - leaking "Handle1" when the device path type/subtype check or the realignment-motivated AllocateCopyPool() fails in the loop. Cc: Jaben Carsey Cc: Ruiyu Ni Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1008 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek Reviewed-by: Jaben Carsey Reviewed-by: Ruiyu Ni --- Notes: v2: - pick up Jaben's R-b ShellPkg/Library/UefiShellLib/UefiShellLib.inf | 1 - ShellPkg/Library/UefiShellLib/UefiShellLib.c | 113 +------------------- 2 files changed, 3 insertions(+), 111 deletions(-) diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.inf b/ShellPkg/Libr= ary/UefiShellLib/UefiShellLib.inf index 38d9a4b81f5f..aacddbbf9765 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.inf +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.inf @@ -51,7 +51,6 @@ [LibraryClasses] SortLib =20 [Protocols] - gEfiSimpleFileSystemProtocolGuid ## SOMETIMES_CONSUMES gEfiUnicodeCollation2ProtocolGuid ## CONSUMES =20 # shell 2.0 diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Librar= y/UefiShellLib/UefiShellLib.c index 18c3be4a8bc7..f04adbb63ffe 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -504,12 +504,7 @@ ShellOpenFileByDevicePath( { CHAR16 *FileName; EFI_STATUS Status; - EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *EfiSimpleFileSystemProtocol; - EFI_FILE_PROTOCOL *Handle1; - EFI_FILE_PROTOCOL *Handle2; - CHAR16 *FnafPathName; - UINTN PathLen; - EFI_HANDLE DeviceHandle; + EFI_FILE_PROTOCOL *File; =20 if (FilePath =3D=3D NULL || FileHandle =3D=3D NULL) { return (EFI_INVALID_PARAMETER); @@ -535,117 +530,15 @@ ShellOpenFileByDevicePath( // // use old shell method. // - Status =3D gBS->LocateDevicePath (&gEfiSimpleFileSystemProtocolGuid, - FilePath, - &DeviceHandle); + Status =3D EfiOpenFileByDevicePath (FilePath, &File, OpenMode, Attribute= s); if (EFI_ERROR (Status)) { return Status; } - Status =3D gBS->OpenProtocol(DeviceHandle, - &gEfiSimpleFileSystemProtocolGuid, - (VOID**)&EfiSimpleFileSystemProtocol, - gImageHandle, - NULL, - EFI_OPEN_PROTOCOL_GET_PROTOCOL); - if (EFI_ERROR (Status)) { - return Status; - } - Status =3D EfiSimpleFileSystemProtocol->OpenVolume(EfiSimpleFileSystemPr= otocol, &Handle1); - if (EFI_ERROR (Status)) { - FileHandle =3D NULL; - return Status; - } - - // - // go down directories one node at a time. - // - while (!IsDevicePathEnd (*FilePath)) { - // - // For file system access each node should be a file path component - // - if (DevicePathType (*FilePath) !=3D MEDIA_DEVICE_PATH || - DevicePathSubType (*FilePath) !=3D MEDIA_FILEPATH_DP - ) { - FileHandle =3D NULL; - return (EFI_INVALID_PARAMETER); - } - // - // Open this file path node - // - Handle2 =3D Handle1; - Handle1 =3D NULL; - - // - // File Name Alignment Fix (FNAF) - // Handle2->Open may be incapable of handling a unaligned CHAR16 data. - // The structure pointed to by FilePath may be not CHAR16 aligned. - // This code copies the potentially unaligned PathName data from the - // FilePath structure to the aligned FnafPathName for use in the - // calls to Handl2->Open. - // - - // - // Determine length of PathName, in bytes. - // - PathLen =3D DevicePathNodeLength (*FilePath) - SIZE_OF_FILEPATH_DEVICE= _PATH; - - // - // Allocate memory for the aligned copy of the string Extra allocation= is to allow for forced alignment - // Copy bytes from possibly unaligned location to aligned location - // - FnafPathName =3D AllocateCopyPool(PathLen, (UINT8 *)((FILEPATH_DEVICE_= PATH*)*FilePath)->PathName); - if (FnafPathName =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Try to test opening an existing file - // - Status =3D Handle2->Open ( - Handle2, - &Handle1, - FnafPathName, - OpenMode &~EFI_FILE_MODE_CREATE, - 0 - ); - - // - // see if the error was that it needs to be created - // - if ((EFI_ERROR (Status)) && (OpenMode !=3D (OpenMode &~EFI_FILE_MODE_C= REATE))) { - Status =3D Handle2->Open ( - Handle2, - &Handle1, - FnafPathName, - OpenMode, - Attributes - ); - } - - // - // Free the alignment buffer - // - FreePool(FnafPathName); - - // - // Close the last node - // - Handle2->Close (Handle2); - - if (EFI_ERROR(Status)) { - return (Status); - } - - // - // Get the next node - // - *FilePath =3D NextDevicePathNode (*FilePath); - } =20 // // This is a weak spot since if the undefined SHELL_FILE_HANDLE format c= hanges this must change also! // - *FileHandle =3D (VOID*)Handle1; + *FileHandle =3D (VOID*)File; return (EFI_SUCCESS); } =20 --=20 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel