From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 1E3C92115BE19 for ; Wed, 13 Jun 2018 22:43:58 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jun 2018 22:43:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,222,1526367600"; d="scan'208";a="57214827" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga002.fm.intel.com with ESMTP; 13 Jun 2018 22:43:57 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 13 Jun 2018 22:43:57 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.87]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.70]) with mapi id 14.03.0319.002; Thu, 14 Jun 2018 13:43:55 +0800 From: "Ni, Ruiyu" To: =?iso-8859-1?Q?Marvin_H=E4user?= , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" , "Gao, Liming" Thread-Topic: [PATCH v2] MdePkg/UefiFileHandleLib: Fix the Root directory determination. Thread-Index: AQHT7dxnT2a6E5yCNEyTecFsY1Idi6RfaSCQ Date: Thu, 14 Jun 2018 05:43:55 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5BD33F39@SHSMSX104.ccr.corp.intel.com> References: <396ef0a31f51da8581a8100ed1c6a6358974038e.1526560735.git.Marvin.Haeuser@outlook.com> In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] MdePkg/UefiFileHandleLib: Fix the Root directory determination. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Jun 2018 05:43:58 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Thanks/Ray > -----Original Message----- > From: edk2-devel On Behalf Of Marvin > H=E4user > Sent: Thursday, May 17, 2018 8:42 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Gao, Liming > > Subject: [edk2] [PATCH v2] MdePkg/UefiFileHandleLib: Fix the Root directo= ry > determination. >=20 > The current implementation of the FileHandleGetFileName() function > assumes that the Root directory always has the FileName '\0'. > However, the only requirement the UEFI specification defines is that > a prepended '\\' must be supported to access files and folders > relative to the Root directory. > This patch removes this assumption and supports constructing valid > paths for any value of FileName for the Root Directory. >=20 > In praxis, this fixes compatibility issues with File System drivers > that report '\\' as the FileName of the Root directory, which > currently is both generating an invalid path ("\\\\") and resulting > in an EFI_NOT_FOUND result from the CurrentHandle->Open() call. >=20 > V2: > - Do not change the copyright date as requested. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Marvin Haeuser > --- > MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c | 27 > ++++++++++++++------ > 1 file changed, 19 insertions(+), 8 deletions(-) >=20 > diff --git a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > index 57aad77bc135..251cbc55edb5 100644 > --- a/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > +++ b/MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.c > @@ -820,10 +820,25 @@ FileHandleGetFileName ( > Status =3D EFI_OUT_OF_RESOURCES; > break; > } else { > + // > + // Prepare to move to the parent directory. > + // Also determine whether CurrentHandle refers to the Root direc= tory. > + // > + Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHandle= , > L"..", EFI_FILE_MODE_READ, 0); > // > // We got info... do we have a name? if yes precede the current = path > with it... > // > - if (StrLen (FileInfo->FileName) =3D=3D 0) { > + if ((StrLen (FileInfo->FileName) =3D=3D 0) || EFI_ERROR (Status)= ) { > + // > + // Both FileInfo->FileName being '\0' and EFI_ERROR() suggest = that > + // CurrentHandle refers to the Root directory. As this loop e= nsures > + // FullFileName is starting with '\\' at all times, signal suc= cess > + // and exit the loop. > + // While FileInfo->FileName could theoretically be a value oth= er than > + // '\0' or '\\', '\\' is guaranteed to be supported by the > + // specification and hence its value can safely be ignored. > + // Per spec, Open("..") request on root directory should return error status. So I think to keep code simple enough, we could remove the "StrLen(..) =3D= =3D 0" check. UEFI Spec 2.7: ".." Opens the parent directory for the current location. If the location= is the root directory the request will return an error, as there is no parent dire= ctory for the root directory. > + Status =3D EFI_SUCCESS; > if (*FullFileName =3D=3D NULL) { > ASSERT((*FullFileName =3D=3D NULL && Size =3D=3D 0) || (*Ful= lFileName !=3D > NULL)); > *FullFileName =3D StrnCatGrowLeft(FullFileName, &Size, L"\\"= , 0); > @@ -841,15 +856,11 @@ FileHandleGetFileName ( > FreePool(FileInfo); > } > } > - // > - // Move to the parent directory > - // > - Status =3D CurrentHandle->Open (CurrentHandle, &NextHigherHandle, > L"..", EFI_FILE_MODE_READ, 0); > - if (EFI_ERROR (Status)) { > - break; > - } >=20 > FileHandleClose(CurrentHandle); > + // > + // Move to the parent directory > + // > CurrentHandle =3D NextHigherHandle; > } > } else if (Status =3D=3D EFI_NOT_FOUND) { > -- > 2.17.0.windows.1 >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel