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.20; helo=mga02.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (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 7FBD0210ED768 for ; Fri, 17 Aug 2018 13:35:09 -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 orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Aug 2018 13:35:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,251,1531810800"; d="scan'208";a="77780845" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga002.fm.intel.com with ESMTP; 17 Aug 2018 13:35:03 -0700 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 17 Aug 2018 13:35:03 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 17 Aug 2018 13:35:02 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.143]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.240]) with mapi id 14.03.0319.002; Sat, 18 Aug 2018 04:35:01 +0800 From: "Gao, Liming" To: Laszlo Ersek , edk2-devel-01 CC: "Kinney, Michael D" , "Ni, Ruiyu" Thread-Topic: [PATCH 1/4] MdePkg/UefiLib: don't special-case EFI_FILE_MODE_CREATE in OpenMode Thread-Index: AQHUNjecGWBohc9HJ0qObgxubCQ6x6TEZw+A Date: Fri, 17 Aug 2018 20:35:00 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E2E52C8@SHSMSX104.ccr.corp.intel.com> References: <20180817143534.28393-1-lersek@redhat.com> <20180817143534.28393-2-lersek@redhat.com> In-Reply-To: <20180817143534.28393-2-lersek@redhat.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNTFhYTU5ZGYtZmZjMy00N2M3LWI4MTUtY2Q0YzE2ZTRkZTVkIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiRnpuU0R3XC8yRlllTVFYdzU1dFRJbW11Mlh0VCtINFBtSGJpQXhKVWlBVXU3Y0pOMDFOK2o2ZlJPN2Q0c2xSSHoifQ== dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 1/4] MdePkg/UefiLib: don't special-case EFI_FILE_MODE_CREATE in OpenMode X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Aug 2018 20:35:10 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Liming Gao > -----Original Message----- > From: Laszlo Ersek [mailto:lersek@redhat.com] > Sent: Friday, August 17, 2018 7:36 AM > To: edk2-devel-01 > Cc: Gao, Liming ; Kinney, Michael D ; Ni, Ruiyu > Subject: [PATCH 1/4] MdePkg/UefiLib: don't special-case EFI_FILE_MODE_CRE= ATE in OpenMode >=20 > While reviewing the patch that would land as 768b611136d0 > ("MdePkg/UefiLib: introduce EfiOpenFileByDevicePath()", 2018-08-16), Ray > pointed out that distinguishing EFI_FILE_MODE_CREATE was wasteful. Per > spec, if the file to create exists, then EFI_FILE_MODE_CREATE is ignored > by EFI_FILE_PROTOCOL.Open(), and the existent file is opened. >=20 > Therefore we don't need an attempt to "open-but-not-create" first, and a > fallback to "open-and-create-too" second -- that behavior is internal to > EFI_FILE_PROTOCOL.Open(). Remove the special-casing of > EFI_FILE_MODE_CREATE. >=20 > Cc: Liming Gao > Cc: Michael D Kinney > Cc: Ruiyu Ni > Suggested-by: Ruiyu Ni > Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D1074 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Laszlo Ersek > --- >=20 > Notes: > Tested with MdeModulePkg/RamDiskDxe: created a virtual disk from an I= SO > file, using the HII form; browsed the disk contents from the UEFI she= ll. >=20 > MdePkg/Include/Library/UefiLib.h | 19 ++-------- > MdePkg/Library/UefiLib/UefiLib.c | 40 +++----------------- > 2 files changed, 9 insertions(+), 50 deletions(-) >=20 > diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/Ue= fiLib.h > index f950f1c9c648..f80067f11103 100644 > --- a/MdePkg/Include/Library/UefiLib.h > +++ b/MdePkg/Include/Library/UefiLib.h > @@ -1533,12 +1533,7 @@ EfiLocateProtocolBuffer ( >=20 > 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 m= asks > - EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If > - EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CR= EATE, > - then the operation is retried with the caller's OpenMode and Attribute= s > - unmodified. > + EFI_FILE_PROTOCOL.Open(). >=20 > (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attr= ibutes > includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a= single > @@ -1570,18 +1565,10 @@ EfiLocateProtocolBuffer ( > the last node in FilePath. >=20 > @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 spe= cified > - pathname fragment with EFI_FILE_MODE_CREATE m= asked > - out of OpenMode and with Attributes set to 0,= and > - only retries the operation with EFI_FILE_MODE= _CREATE > - unmasked and Attributes propagated if the fir= st open > - attempt fails. > + EFI_FILE_PROTOCOL.Open(). >=20 > @param[in] Attributes The Attributes parameter to pass to > - EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_= CREATE > - is propagated unmasked in OpenMode. > + EFI_FILE_PROTOCOL.Open(). >=20 > @retval EFI_SUCCESS The file or directory has been opened o= r > created. > diff --git a/MdePkg/Library/UefiLib/UefiLib.c b/MdePkg/Library/UefiLib/Ue= fiLib.c > index 7bcac5613768..39d0ce2b21b3 100644 > --- a/MdePkg/Library/UefiLib/UefiLib.c > +++ b/MdePkg/Library/UefiLib/UefiLib.c > @@ -1730,12 +1730,7 @@ EfiLocateProtocolBuffer ( >=20 > 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 m= asks > - EFI_FILE_MODE_CREATE out of OpenMode, and passes 0 for Attributes. If > - EFI_FILE_PROTOCOL.Open() fails, and OpenMode includes EFI_FILE_MODE_CR= EATE, > - then the operation is retried with the caller's OpenMode and Attribute= s > - unmodified. > + EFI_FILE_PROTOCOL.Open(). >=20 > (As a consequence, if OpenMode includes EFI_FILE_MODE_CREATE, and Attr= ibutes > includes EFI_FILE_DIRECTORY, and each FILEPATH_DEVICE_PATH specifies a= single > @@ -1767,18 +1762,10 @@ EfiLocateProtocolBuffer ( > the last node in FilePath. >=20 > @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 spe= cified > - pathname fragment with EFI_FILE_MODE_CREATE m= asked > - out of OpenMode and with Attributes set to 0,= and > - only retries the operation with EFI_FILE_MODE= _CREATE > - unmasked and Attributes propagated if the fir= st open > - attempt fails. > + EFI_FILE_PROTOCOL.Open(). >=20 > @param[in] Attributes The Attributes parameter to pass to > - EFI_FILE_PROTOCOL.Open(), when EFI_FILE_MODE_= CREATE > - is propagated unmasked in OpenMode. > + EFI_FILE_PROTOCOL.Open(). >=20 > @retval EFI_SUCCESS The file or directory has been opened o= r > created. > @@ -1889,31 +1876,16 @@ EfiOpenFileByDevicePath ( > } >=20 > // > - // Open the next pathname fragment with EFI_FILE_MODE_CREATE masked = out and > - // with Attributes set to 0. > + // Open or create the file corresponding to the next pathname fragme= nt. > // > Status =3D LastFile->Open ( > LastFile, > &NextFile, > PathName, > - OpenMode & ~(UINT64)EFI_FILE_MODE_CREATE, > - 0 > + OpenMode, > + Attributes > ); >=20 > - // > - // Retry with EFI_FILE_MODE_CREATE and the original Attributes if th= e 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; Path= Name is > // no longer needed. > -- > 2.14.1.3.gb7cf6e02401b >=20