public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH][Ext4Pkg] unwritten extent suuport
@ 2021-10-27 13:37 atmgnd
  2021-10-27 14:56 ` Pedro Falcato
  0 siblings, 1 reply; 8+ messages in thread
From: atmgnd @ 2021-10-27 13:37 UTC (permalink / raw)
  To: devel@edk2.groups.io; +Cc: pedro.falcato@gmail.com

From: "Qi Zhou" <atmgnd@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 <atmgnd@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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-10-28 13:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-10-27 13:37 [PATCH][Ext4Pkg] unwritten extent suuport atmgnd
2021-10-27 14:56 ` Pedro Falcato
2021-10-27 15:44   ` qi zhou
2021-10-27 21:34     ` Pedro Falcato
2021-10-28  0:43       ` qi zhou
2021-10-28  1:09         ` [edk2-devel] " Kevin@Insyde
2021-10-28 13:57         ` Pedro Falcato
     [not found]   ` <7A0482AF-274E-474C-80FB-6F9FFFE4F2C3@getmailspring.com>
2021-10-27 15:48     ` qi zhou

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox