From nobody Tue Apr 16 09:05:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+83895+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83895+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1637285474; cv=none; d=zohomail.com; s=zohoarc; b=gO12RTBK42O5RZ/P0gCMZtdRJ1PT8Xpi6FgVNmwkFmOSTmHJ/sTbUYZXptUEuCk0o53YIc43BDrsicyfot0cxUGzOcmqKktC4IMmSnTWf8T8SRQKI93/mLnkGfiF+mrSV5GHO6d/sGmYvTYpaIFK7b3fShvZsiWLOmwD8arNTgk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637285474; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=6HG3ALIVPisoWJdAOvCOUzhZfiaIkwUNA7aYR6kR8jY=; b=ivVdgMfyxkUYdZL+O97rnneFRpf59bYhmiLUOFdNeGvVZU1dJGMNasP8yQzM4BqgA5sJmxZiLFWL12CBnYk1fjRhcbIbcK+4NoLtOe30M5dJvZOGZrJAQZ/mplAAt95W8MTdEHXRVGqVcacnEJ05HeyTF5FWGZtqyBlcl1QFoy4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+83895+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1637285472943262.9636850960843; Thu, 18 Nov 2021 17:31:12 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id beEDYY1788612xom6a6RP2NY; Thu, 18 Nov 2021 17:31:12 -0800 X-Received: from mail.byosoft.com.cn (mail.byosoft.com.cn [58.240.74.242]) by mx.groups.io with SMTP id smtpd.web08.2464.1637285470110735101 for ; Thu, 18 Nov 2021 17:31:10 -0800 X-Received: from DESKTOPS6D0PVI ([58.246.60.130]) (envelope-sender ) by 192.168.6.13 with ESMTP for ; Fri, 19 Nov 2021 09:31:04 +0800 X-WM-Sender: gaoliming@byosoft.com.cn X-Originating-IP: 58.246.60.130 X-WM-AuthFlag: YES X-WM-AuthUser: gaoliming@byosoft.com.cn From: "gaoliming" To: , Cc: "'Leif Lindholm'" , "'Michael D Kinney'" References: <16B25AD607AC994B.20978@groups.io> In-Reply-To: Subject: =?UTF-8?B?5Zue5aSNOiBbZWRrMi1kZXZlbF0gW2VkazItcGxhdGZvcm1zIFBBVENIXSBFeHQ0UGtnOiBBZGQgdW5pbml0aWFsaXplZCBleHRlbnRzIHN1cHBvcnQ=?= Date: Fri, 19 Nov 2021 09:31:06 +0800 Message-ID: <004a01d7dce5$1fcf9bc0$5f6ed340$@byosoft.com.cn> MIME-Version: 1.0 Thread-Index: AQIl2jZuJP2eVKOy/BCVmUZS01qFsgHKSBmNAcEchJmrUbm2UA== Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,gaoliming@byosoft.com.cn X-Gm-Message-State: BUTTZXYMb9oJyRfMQHoK20eix1787277AA= Content-Type: multipart/alternative; boundary="----=_NextPart_000_004B_01D7DD28.2DF4B080" Content-Language: zh-cn DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1637285472; bh=g7S3mu/c55BZBD/T1vjdAbdvqa7wCKKKP6BaatleCl4=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=bi3Sx6QgP9f3s8UfYOWNrtXW02Ky+/CNwC17Y/7nwZPJNE7IR33ch1pEr0xUF7v/ho7 LX7ifAFM6TtuTgTFfBuXcyenCA/x01svN9n/2spdJmCW8+vXSSFs8TVBfIlsyzk6tG+NI tUhdDyomrWyuLci1vBN0TBHv/MIXyrrLMhE= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1637285475895100001 ------=_NextPart_000_004B_01D7DD28.2DF4B080 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Pedro=EF=BC=9A I review this patch. This change looks good. Reviewed-by: Liming Gao =20 Besides, I want to confirm whether Ext4Dxe support Ext2/Ext3/Ext4 file sys= tem or only Ext4 file system. =20 Thanks Liming =E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io = =E4=BB=A3=E8=A1=A8 Pedro Falcato =E5=8F=91=E9=80=81=E6=97=B6=E9=97=B4: 2021=E5=B9=B411=E6=9C=8819=E6=97=A5 4= :31 =E6=94=B6=E4=BB=B6=E4=BA=BA: edk2-devel-groups-io ; P= edro Falcato =E6=8A=84=E9=80=81: Leif Lindholm ; Michael D Kinney =E4=B8=BB=E9=A2=98: Re: [edk2-devel] [edk2-platforms PATCH] Ext4Pkg: Add un= initialized extents support =20 It's been over two weeks and a quick Rb would be great, since this patch is= relatively trivial and it would fix a bug. Again, if I'm doing anything wr= ong, please let me know. =20 =20 Thanks, Pedro =20 On Mon, Nov 1, 2021 at 9:29 PM Pedro Falcato > wrote: Quick PS: I CC'd the edk2-platforms stewards on the patch because there's n= o co-maintainer, and from what I gathered, that's what I'm supposed to do. = If I'm mistaken, please let me know. =20 Thanks, Pedro =20 On Fri, Oct 29, 2021 at 2:04 AM Pedro Falcato via groups.io > wr= ote: Uninitialized extents are special extents that have blocks allocated, but are specified as uninitialized and therefore, reads behave the same as file holes (reads 0), while writes already have blocks allocated. Cc: Leif Lindholm > Cc: Michael D Kinney > Signed-off-by: Pedro Falcato > --- Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 8 ++++++++ Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 21 +++++++++++++++++++++ Features/Ext4Pkg/Ext4Dxe/Extents.c | 24 ++++++++++++++++++++++-- Features/Ext4Pkg/Ext4Dxe/Inode.c | 14 +++++++++++--- 4 files changed, 62 insertions(+), 5 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe= /Ext4Disk.h index 070eb5a9c8..756b1bbe10 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h @@ -448,6 +448,14 @@ typedef struct { UINT32 eb_checksum; } EXT4_EXTENT_TAIL; +/** + * EXT4 has this feature called uninitialized extents: + * An extent has a maximum of 32768 blocks (2^15 or 1 << 15). + * When we find an extent with > 32768 blocks, this extent is called unini= tialized. + * Long story short, it's an extent that behaves as a file hole but has bl= ocks already allocated. + */ +#define EXT4_EXTENT_MAX_INITIALIZED (1 << 15) + typedef UINT64 EXT4_BLOCK_NR; typedef UINT32 EXT4_INO_NR; diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index a9b932ed52..1d9a4ac6ba 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -1131,4 +1131,25 @@ Ext4SuperblockCheckMagic ( IN EFI_BLOCK_IO_PROTOCOL *BlockIo ); +/** + Check if the extent is uninitialized + + @param[in] Extent Pointer to the EXT4_EXTENT + + @returns True if uninitialized, else false. +**/ +#define EXT4_EXTENT_IS_UNINITIALIZED(Extent) ((Extent)->ee_len > EXT4_EXTE= NT_MAX_INITIALIZED) + +/** + Retrieves the extent's length, dealing with uninitialized extents in th= e process. + + @param[in] Extent Pointer to the EXT4_EXTENT + + @returns Extent's length, in filesystem blocks. +**/ +EXT4_BLOCK_NR +Ext4GetExtentLength ( + IN CONST EXT4_EXTENT *Extent + ); + #endif diff --git a/Features/Ext4Pkg/Ext4Dxe/Extents.c b/Features/Ext4Pkg/Ext4Dxe/= Extents.c index 5fa2fe098d..1ae175f417 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Extents.c +++ b/Features/Ext4Pkg/Ext4Dxe/Extents.c @@ -332,7 +332,7 @@ Ext4GetExtent ( return EFI_NO_MAPPING; } - if (!(LogicalBlock >=3D Ext->ee_block && Ext->ee_block + Ext->ee_len > L= ogicalBlock)) { + if (!(LogicalBlock >=3D Ext->ee_block && Ext->ee_block + Ext4GetExtentLe= ngth (Ext) > LogicalBlock)) { // This extent does not cover the block if (Buffer !=3D NULL) { FreePool (Buffer); @@ -413,7 +413,7 @@ Ext4ExtentsMapKeyCompare ( Extent =3D UserStruct; Block =3D (UINT32)(UINTN)StandaloneKey; - if (Block >=3D Extent->ee_block && Block < Extent->ee_block + Extent->ee= _len) { + if (Block >=3D Extent->ee_block && Block < Extent->ee_block + Ext4GetExt= entLength (Extent)) { return 0; } @@ -593,3 +593,23 @@ Ext4CheckExtentChecksum ( return Tail->eb_checksum =3D=3D Ext4CalculateExtentChecksum (ExtHeader, = File); } + +/** + Retrieves the extent's length, dealing with uninitialized extents in th= e process. + + @param[in] Extent Pointer to the EXT4_EXTENT + + @returns Extent's length, in filesystem blocks. +**/ +EXT4_BLOCK_NR +Ext4GetExtentLength ( + IN CONST EXT4_EXTENT *Extent + ) +{ + // If it's an unintialized extent, the true length is ee_len - 2^15 + if (EXT4_EXTENT_IS_UNINITIALIZED (Extent)) { + return Extent->ee_len - EXT4_EXTENT_MAX_INITIALIZED; + } + + return Extent->ee_len; +} diff --git a/Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/In= ode.c index 63cecec1f7..48bfe026a3 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Inode.c +++ b/Features/Ext4Pkg/Ext4Dxe/Inode.c @@ -144,11 +144,19 @@ Ext4Read ( HasBackingExtent =3D Status !=3D EFI_NO_MAPPING; - if (!HasBackingExtent) { + if (!HasBackingExtent || EXT4_EXTENT_IS_UNINITIALIZED (&Extent)) { + HoleOff =3D BlockOff; - HoleLen =3D Partition->BlockSize - HoleOff; + + if (!HasBackingExtent) { + HoleLen =3D Partition->BlockSize - HoleOff; + } else { + // Uninitialized extents behave exactly the same as file holes. + HoleLen =3D Ext4GetExtentLength (&Extent) - HoleOff; + } + WasRead =3D HoleLen > RemainingRead ? RemainingRead : HoleLen; - // Potential improvement: In the future, we could get the hole's tota + // Potential improvement: In the future, we could get the file hole'= s total // size and memset all that SetMem (Buffer, WasRead, 0); } else { --=20 2.33.1.windows.1 ------------ Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82879): https://edk2.groups.io/g/devel/message/82879 Mute This Topic: https://groups.io/mt/86667035/5946980 Group Owner: devel+owner@edk2.groups.io =20 Unsubscribe: https://edk2.groups.io/g/devel/unsub [pedro.falcato@gmail.com = ] ------------ =20 --=20 Pedro Falcato --=20 Pedro Falcato -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#83895): https://edk2.groups.io/g/devel/message/83895 Mute This Topic: https://groups.io/mt/87158604/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- ------=_NextPart_000_004B_01D7DD28.2DF4B080 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Pedro=EF=BC=9A<= o:p>

=C2=A0I review this patch. Thi= s change looks good. Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn&g= t;

 

=

=C2=A0Besides, I want to confirm whether Ext4Dxe su= pport Ext2/Ext3/Ext4 file system or only Ext4 file system.

 

Thanks

Liming

=E5=8F=91=E4=BB=B6=E4=BA=BA: devel@edk2.groups.io <devel@edk2.gro= ups.io> =E4=BB=A3=E8=A1=A8 Pedro Falcato
=E5=8F=91=E9=80= =81=E6=97=B6=E9=97=B4: 2021=E5=B9=B411=E6=9C=8819=E6=97=A5 4:31
=E6=94=B6=E4=BB=B6=E4=BA=BA: edk2-devel-groups-io <devel@edk2.gro= ups.io>; Pedro Falcato <pedro.falcato@gmail.com>
=E6= =8A=84=E9=80=81: Leif Lind= holm <leif@nuviainc.com>; Michael D Kinney <michael.d.kinney@intel= .com>
=E4=B8=BB=E9=A2=98: Re: [edk2-devel] [edk2-platforms PATCH] Ext4Pkg: Add uninit= ialized extents support

 

It's been over two weeks and a quick Rb wou= ld be great, since this patch is relatively trivial and it would fix a bug.= Again, if I'm doing anything wrong, please let me know.<= /p>

 

 =

Thanks,<= /o:p>

Pedro

 

O= n Mon, Nov 1, 2021 at 9:29 PM Pedro Falcato <pedro.falcato@gmail.com> wrote:

Quick PS: I CC'd the edk2-platforms stewards o= n the patch because there's no co-maintainer, and from what I gathered, tha= t's what I'm supposed to do. If I'm mistaken, please let me know.

 <= /span>

Thanks,

Pedro

=  

On= Fri, Oct 29, 2021 at 2:04 AM Pedro Falcato via groups.io <pedro.falcato=3Dgmail.com@groups.io> wrote:=

=

Unin= itialized extents are special extents that have blocks allocated,
but ar= e specified as uninitialized and therefore, reads behave the
same as fil= e holes (reads 0), while writes already have blocks allocated.

Cc: L= eif Lindholm <lei= f@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com><= br>Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
---
 Featu= res/Ext4Pkg/Ext4Dxe/Ext4Disk.h |  8 ++++++++
 Features/Ext4Pkg= /Ext4Dxe/Ext4Dxe.h  | 21 +++++++++++++++++++++
 Features/Ext4P= kg/Ext4Dxe/Extents.c  | 24 ++++++++++++++++++++++--
 Features/= Ext4Pkg/Ext4Dxe/Inode.c    | 14 +++++++++++---
 4 files c= hanged, 62 insertions(+), 5 deletions(-)

diff --git a/Features/Ext4P= kg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
index 070eb5= a9c8..756b1bbe10 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
+++= b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
@@ -448,6 +448,14 @@ typedef stru= ct {
   UINT32    eb_checksum;
 } EXT4_EXTEN= T_TAIL;

+/**
+ * EXT4 has this feature called uninitialized exten= ts:
+ * An extent has a maximum of 32768 blocks (2^15 or 1 << 15).=
+ * When we find an extent with > 32768 blocks, this extent is calle= d uninitialized.
+ * Long story short, it's an extent that behaves as a = file hole but has blocks already allocated.
+ */
+#define EXT4_EXTENT= _MAX_INITIALIZED  (1 << 15)
+
 typedef UINT64  E= XT4_BLOCK_NR;
 typedef UINT32  EXT4_INO_NR;

diff --git = a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.hindex a9b932ed52..1d9a4ac6ba 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext= 4Dxe.h
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
@@ -1131,4 +1131,25 @= @ Ext4SuperblockCheckMagic (
   IN EFI_BLOCK_IO_PROTOCOL = *BlockIo
   );

+/**
+   Check if the exte= nt is uninitialized
+
+   @param[in] Extent    Po= inter to the EXT4_EXTENT
+
+   @returns True if uninitializ= ed, else false.
+**/
+#define EXT4_EXTENT_IS_UNINITIALIZED(Extent) ((= Extent)->ee_len > EXT4_EXTENT_MAX_INITIALIZED)
+
+/**
+ = ;  Retrieves the extent's length, dealing with uninitialized extents i= n the process.
+
+   @param[in] Extent      = Pointer to the EXT4_EXTENT
+
+   @returns Extent's length, = in filesystem blocks.
+**/
+EXT4_BLOCK_NR
+Ext4GetExtentLength (+  IN CONST EXT4_EXTENT  *Extent
+  );
+
 #e= ndif
diff --git a/Features/Ext4Pkg/Ext4Dxe/Extents.c b/Features/Ext4Pkg/= Ext4Dxe/Extents.c
index 5fa2fe098d..1ae175f417 100644
--- a/Features/= Ext4Pkg/Ext4Dxe/Extents.c
+++ b/Features/Ext4Pkg/Ext4Dxe/Extents.c
@@= -332,7 +332,7 @@ Ext4GetExtent (
     return EFI_NO_MAPP= ING;
   }

-  if (!(LogicalBlock >=3D Ext->ee= _block && Ext->ee_block + Ext->ee_len > LogicalBlock)) {+  if (!(LogicalBlock >=3D Ext->ee_block && Ext->ee= _block + Ext4GetExtentLength (Ext) > LogicalBlock)) {
    &= nbsp;// This extent does not cover the block
     if (Buf= fer !=3D NULL) {
       FreePool (Buffer);
@@ -41= 3,7 +413,7 @@ Ext4ExtentsMapKeyCompare (
   Extent =3D UserStr= uct;
   Block  =3D (UINT32)(UINTN)StandaloneKey;

-=   if (Block >=3D Extent->ee_block && Block < Extent-&= gt;ee_block + Extent->ee_len) {
+  if (Block >=3D Extent->= ee_block && Block < Extent->ee_block + Ext4GetExtentLength (E= xtent)) {
     return 0;
   }

@@ -593= ,3 +593,23 @@ Ext4CheckExtentChecksum (

   return Tail->= ;eb_checksum =3D=3D Ext4CalculateExtentChecksum (ExtHeader, File);
 = ;}
+
+/**
+   Retrieves the extent's length, dealing wit= h uninitialized extents in the process.
+
+   @param[in] Ex= tent      Pointer to the EXT4_EXTENT
+
+   @= returns Extent's length, in filesystem blocks.
+**/
+EXT4_BLOCK_NR+Ext4GetExtentLength (
+  IN CONST EXT4_EXTENT  *Extent
+&= nbsp; )
+{
+  // If it's an unintialized extent, the true length= is ee_len - 2^15
+  if (EXT4_EXTENT_IS_UNINITIALIZED (Extent)) {+    return Extent->ee_len - EXT4_EXTENT_MAX_INITIALIZED;+  }
+
+  return Extent->ee_len;
+}
diff --git a/= Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/Inode.c
inde= x 63cecec1f7..48bfe026a3 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Inode.c+++ b/Features/Ext4Pkg/Ext4Dxe/Inode.c
@@ -144,11 +144,19 @@ Ext4Read = (

     HasBackingExtent =3D Status !=3D EFI_NO_MAPPIN= G;

-    if (!HasBackingExtent) {
+    if (!Ha= sBackingExtent || EXT4_EXTENT_IS_UNINITIALIZED (&Extent)) {
+
&nb= sp;      HoleOff =3D BlockOff;
-      Hole= Len =3D Partition->BlockSize - HoleOff;
+
+      if= (!HasBackingExtent) {
+        HoleLen =3D Partitio= n->BlockSize - HoleOff;
+      } else {
+  &nb= sp;     // Uninitialized extents behave exactly the same as file = holes.
+        HoleLen =3D Ext4GetExtentLength (&am= p;Extent) - HoleOff;
+      }
+
     = ;  WasRead =3D HoleLen > RemainingRead ? RemainingRead : HoleLen;-      // Potential improvement: In the future, we could g= et the hole's tota
+      // Potential improvement: In th= e future, we could get the file hole's total
       = // size and memset all that
       SetMem (Buffer, W= asRead, 0);
     } else {
--
2.33.1.windows.1
<= br>

------------
Groups.io Links: You receive all messages sent t= o this group.
View/Reply Online (#82879): https://edk2.groups.io/g/devel= /message/82879
Mute This Topic: https://groups.io/mt/86667035/5946980Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel= /unsub [pe= dro.falcato@gmail.com]
------------


 =

--

Pedro Falcat= o

=

--

<= p class=3DMsoNormal>Pedro Falcato

<= /div>

_._,_._,_

G= roups.io Links:

You receive all messages sent to this group.

Vi= ew/Reply Online (#83895) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [importer@patchew.org]
_._,_._,_

=20 ------=_NextPart_000_004B_01D7DD28.2DF4B080--