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.31; helo=mga06.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 603D021103DA9 for ; Tue, 28 Aug 2018 18:51:52 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2018 18:51:52 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,300,1531810800"; d="scan'208";a="68633556" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga007.jf.intel.com with ESMTP; 28 Aug 2018 18:51:50 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 28 Aug 2018 18:51:38 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.143]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.185]) with mapi id 14.03.0319.002; Wed, 29 Aug 2018 09:51:37 +0800 From: "Wu, Hao A" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: Andrew Fish Thread-Topic: [PATCH 05/10] EmulatorPkg/Win: Do not zero out file content Thread-Index: AQHUPdr2tWxcTeMgAEKhAT4JOShPyKTV+W2g Date: Wed, 29 Aug 2018 01:51:36 +0000 Message-ID: References: <20180827075330.269224-1-ruiyu.ni@intel.com> <20180827075330.269224-6-ruiyu.ni@intel.com> In-Reply-To: <20180827075330.269224-6-ruiyu.ni@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH 05/10] EmulatorPkg/Win: Do not zero out file content 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: Wed, 29 Aug 2018 01:51:53 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable > -----Original Message----- > From: Ni, Ruiyu > Sent: Monday, August 27, 2018 3:53 PM > To: edk2-devel@lists.01.org > Cc: Wu, Hao A; Andrew Fish > Subject: [PATCH 05/10] EmulatorPkg/Win: Do not zero out file content >=20 > The patch changes the behavior to not zero out file content > when the file size is not multiple of block size. > Instead, it just provides access to the contents that are > multiple of block size and leaves the remaining content (less than > block size) untouched. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Ruiyu Ni > Cc: Hao Wu > Cc: Andrew Fish > --- > EmulatorPkg/Win/Host/WinBlockIo.c | 28 +++++++++++++++++++++++++--- > 1 file changed, 25 insertions(+), 3 deletions(-) >=20 > diff --git a/EmulatorPkg/Win/Host/WinBlockIo.c > b/EmulatorPkg/Win/Host/WinBlockIo.c > index 14491a6e90..7df7d42c7c 100644 > --- a/EmulatorPkg/Win/Host/WinBlockIo.c > +++ b/EmulatorPkg/Win/Host/WinBlockIo.c > @@ -90,6 +90,7 @@ WinNtBlockIoOpenDevice ( > { > EFI_STATUS Status; > UINT64 FileSize; > + UINT64 EndOfFile; >=20 > // > // If the device is already opened, close it > @@ -112,7 +113,7 @@ WinNtBlockIoOpenDevice ( > ); >=20 > if (Private->NtHandle =3D=3D INVALID_HANDLE_VALUE) { > - DEBUG ((EFI_D_INFO, "OpenBlock: Could not open %S, %x\n", Private- > >FileName, GetLastError ())); > + DEBUG ((EFI_D_INFO, "PlOpenBlock: Could not open %S, %x\n", Private- > >FileName, GetLastError ())); > Media->MediaPresent =3D FALSE; > Status =3D EFI_NO_MEDIA; > goto Done; > @@ -124,14 +125,35 @@ WinNtBlockIoOpenDevice ( > Status =3D SetFilePointer64 (Private, 0, &FileSize, FILE_END); >=20 > if (EFI_ERROR (Status)) { > - DEBUG ((EFI_D_ERROR, "OpenBlock: Could not get filesize of %s\n", Pr= ivate- > >FileName)); > + DEBUG ((EFI_D_ERROR, "PlOpenBlock: Could not get filesize of %s\n", > Private->FileName)); > Status =3D EFI_UNSUPPORTED; > goto Done; > } >=20 > Media->LastBlock =3D DivU64x32 (FileSize, (UINT32)Private->BlockSize) = - 1; >=20 > - DEBUG ((EFI_D_INIT, "OpenBlock: opened %S\n", Private->FileName)); > + EndOfFile =3D MultU64x32 (Media->LastBlock + 1, (UINT32)Private->Block= Size); > + Hi Ray, The below logic seems actually zeroing out the file content if the file size is not a multiple of block size. Could you help to double confirm this one? Best Regards, Hao Wu > + if (FileSize !=3D EndOfFile) { > + // > + // file is not the proper size, change it > + // > + DEBUG ((EFI_D_INIT, "PlOpenBlock: Initializing block device: %hs\n", > Private->FileName)); > + > + // > + // first set it to 0 > + // > + SetFilePointer64 (Private, 0, NULL, FILE_BEGIN); > + SetEndOfFile (Private->NtHandle); > + > + // > + // then set it to the needed file size (OS will zero fill it) > + // > + SetFilePointer64 (Private, EndOfFile, NULL, FILE_BEGIN); > + SetEndOfFile (Private->NtHandle); > + } > + > + DEBUG ((EFI_D_INIT, "PlOpenBlock: opened %S\n", Private->FileName)); > Status =3D EFI_SUCCESS; >=20 > Done: > -- > 2.16.1.windows.1