From: "Qi Zhou" <atm...@outlook.com> Subject: [PATCH] unwritten extent suuport
the real lenght of uninitialized/unwritten extent should be (ee_len - (1UL << 15)), and all related block should been read as zeros. see: https://github.com/torvalds/linux/blob/d25f27432f80a800a3592db128254c8140bd71bf/fs/ext4/ext4_extents.h#L156 Signed-off-by: Qi Zhou <atm...@outlook.com> --- Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 5 +++++ Features/Ext4Pkg/Ext4Dxe/Extents.c | 4 ++-- Features/Ext4Pkg/Ext4Dxe/Inode.c | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h index 070eb5a..7ca8eee 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h @@ -402,6 +402,11 @@ typedef struct { #define EXT4_MIN_DIR_ENTRY_LEN 8 +#define EXTENT_INIT_MAX_LEN (1UL << 15) + +#define EXTENT_REAL_LEN(x) ((UINT16)(x <= EXTENT_INIT_MAX_LEN ? x : (x - EXTENT_INIT_MAX_LEN))) +#define EXTENT_IS_UNWRITTEN(x) (x > EXTENT_INIT_MAX_LEN) + // This on-disk structure is present at the bottom of the extent tree typedef struct { // First logical block diff --git a/Features/Ext4Pkg/Ext4Dxe/Extents.c b/Features/Ext4Pkg/Ext4Dxe/Extents.c index 5fa2fe0..21af573 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Extents.c +++ b/Features/Ext4Pkg/Ext4Dxe/Extents.c @@ -332,7 +332,7 @@ Ext4GetExtent ( return EFI_NO_MAPPING; } - if (!(LogicalBlock >= Ext->ee_block && Ext->ee_block + Ext->ee_len > LogicalBlock)) { + if (!(LogicalBlock >= Ext->ee_block && Ext->ee_block + EXTENT_REAL_LEN(Ext->ee_len) > LogicalBlock)) { // This extent does not cover the block if (Buffer != NULL) { FreePool (Buffer); @@ -413,7 +413,7 @@ Ext4ExtentsMapKeyCompare ( Extent = UserStruct; Block = (UINT32)(UINTN)StandaloneKey; - if (Block >= Extent->ee_block && Block < Extent->ee_block + Extent->ee_len) { + if (Block >= Extent->ee_block && Block < Extent->ee_block + EXTENT_REAL_LEN(Extent->ee_len)) { return 0; } diff --git a/Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/Inode.c index 63cecec..d691ec7 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Inode.c +++ b/Features/Ext4Pkg/Ext4Dxe/Inode.c @@ -151,6 +151,11 @@ Ext4Read ( // Potential improvement: In the future, we could get the hole's tota // size and memset all that SetMem (Buffer, WasRead, 0); + } else if(EXTENT_IS_UNWRITTEN(Extent.ee_len)) { + HoleOff = CurrentSeek - (UINT64)Extent.ee_block * Partition->BlockSize; + HoleLen = EXTENT_REAL_LEN(Extent.ee_len) * Partition->BlockSize - HoleOff; + WasRead = HoleLen > RemainingRead ? RemainingRead : HoleLen; + SetMem (Buffer, WasRead, 0); } else { ExtentStartBytes = MultU64x32 ( LShiftU64 (Extent.ee_start_hi, 32) | -- 2.17.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#82757): https://edk2.groups.io/g/devel/message/82757 Mute This Topic: https://groups.io/mt/86629612/21656 Group Owner: devel+ow...@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-