From nobody Tue May 7 17:30:08 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+82879+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+82879+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1635469490; cv=none; d=zohomail.com; s=zohoarc; b=Y0qTq0BT0BnqvlWK4kJf8NbmsFyFMYRrRhtMPaiUQk3+QBBMrxobNLErfbvOEb8op08l96OXEGsGWSWXaKUGh47xN7M9i6ZkJVPrfUHTL+DxilIchWcLVQQSQvOCVIVPXQMHOR6OiEf9POTaG7RPhRuM4XNvzCTbVataCsir1QI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1635469490; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=Zb9bBPmDfNVwBUkg31bs/8azFrXmy3L0OLyvsEIvPUQ=; b=A3YlqwC0BSSc3p9utaha/mS6JXqc24vaSiKEOqVgldi84NWi5ICOoJIh2YM+9ow3LtNMcT0TSytZStR9BtSiJaPQNEBcF198yJsodwEjIdFhWC7dratDh8fI1KJ73JJ64Xad5LIlaQmh562+5R8S/T/mBTvpE17YIs6jmL90ZcM= 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+82879+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1635469490725971.5998058884796; Thu, 28 Oct 2021 18:04:50 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id AhoWYY1788612xin6jvvUoEG; Thu, 28 Oct 2021 18:04:50 -0700 X-Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by mx.groups.io with SMTP id smtpd.web09.2827.1635469489398990510 for ; Thu, 28 Oct 2021 18:04:49 -0700 X-Received: by mail-wr1-f44.google.com with SMTP id z14so13339332wrg.6 for ; Thu, 28 Oct 2021 18:04:49 -0700 (PDT) X-Gm-Message-State: jviWiuqwYDRvWeJBl1dXs5ktx1787277AA= X-Google-Smtp-Source: ABdhPJwSW55DA9Yt8ehGE5gdClblW954llg16pGrJUVFZhIURNDC2dFeOVpgO3/uKF6nyzgAAuWV5g== X-Received: by 2002:adf:d0cf:: with SMTP id z15mr10148578wrh.219.1635469487473; Thu, 28 Oct 2021 18:04:47 -0700 (PDT) X-Received: from localhost.localdomain (bl8-253-151.dsl.telepac.pt. [85.241.253.151]) by smtp.gmail.com with ESMTPSA id c1sm1355426wrt.14.2021.10.28.18.04.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Oct 2021 18:04:47 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Leif Lindholm , Michael D Kinney Subject: [edk2-devel] [edk2-platforms PATCH] Ext4Pkg: Add uninitialized extents support Date: Fri, 29 Oct 2021 02:04:32 +0100 Message-Id: MIME-Version: 1.0 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,pedro.falcato@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1635469490; bh=Rcww5/O50wg2+1vROW/iUlHYjUxo3bBHVZn5yYVjL4I=; h=Cc:Date:From:Reply-To:Subject:To; b=HdsDPxH1zxsNjGtG2YhneFE/UXTSH5aCDveywTQaQIF0rq+82UWqtungV/drk4YHs6Z gb1zNU7QjYvCIzDn/R/j6nxrRPGOY8on94SAw1v3nVhFqoEimriyQ9neiN8VBS9njVpVg ZafBJmq1v7pZ9XlSI0nQxbAE26oJJadJzHU= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1635469491191100002 Content-Type: text/plain; charset="utf-8" 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; =20 +/** + * 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; =20 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 ); =20 +/** + 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; } =20 - 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; =20 - 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; } =20 @@ -593,3 +593,23 @@ Ext4CheckExtentChecksum ( =20 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 ( =20 HasBackingExtent =3D Status !=3D EFI_NO_MAPPING; =20 - 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 -=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 (#82879): https://edk2.groups.io/g/devel/message/82879 Mute This Topic: https://groups.io/mt/86667035/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-