From: "Savva Mitrofanov" <savvamtr@gmail.com>
To: devel@edk2.groups.io
Cc: "Marvin Häuser" <mhaeuser@posteo.de>,
"Pedro Falcato" <pedro.falcato@gmail.com>,
"Vitaly Cheptsov" <vit9696@protonmail.com>
Subject: [edk2-platforms][PATCH 03/10] Ext4Pkg: Use 32-bit block number in BlockMap
Date: Tue, 19 Jul 2022 18:10:09 +0600 [thread overview]
Message-ID: <20220719121016.29380-4-savvamtr@gmail.com> (raw)
In-Reply-To: <20220719121016.29380-1-savvamtr@gmail.com>
Replace EXT4_BLOCK_NR with 32-bit EXT2_BLOCK_NR in BlockMap, because we
consider BlockMap is 32-bit fs ext2/3 feature
Cc: Marvin Häuser <mhaeuser@posteo.de>
Cc: Pedro Falcato <pedro.falcato@gmail.com>
Cc: Vitaly Cheptsov <vit9696@protonmail.com>
Signed-off-by: Savva Mitrofanov <savvamtr@gmail.com>
---
Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 1 +
Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 2 +-
Features/Ext4Pkg/Ext4Dxe/BlockMap.c | 14 ++++++++++----
Features/Ext4Pkg/Ext4Dxe/Extents.c | 3 ++-
4 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
index a55cd2fa68ad..3aef6f0e5bb4 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
@@ -463,6 +463,7 @@ typedef struct {
#define EXT4_EXTENT_MAX_INITIALIZED (1 << 15)
typedef UINT64 EXT4_BLOCK_NR;
+typedef UINT32 EXT2_BLOCK_NR;
typedef UINT32 EXT4_INO_NR;
// 2 is always the root inode number in ext4
diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
index b1508482b0a7..b446488b2112 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
@@ -1165,7 +1165,7 @@ EFI_STATUS
Ext4GetBlocks (
IN EXT4_PARTITION *Partition,
IN EXT4_FILE *File,
- IN EXT4_BLOCK_NR LogicalBlock,
+ IN EXT2_BLOCK_NR LogicalBlock,
OUT EXT4_EXTENT *Extent
);
diff --git a/Features/Ext4Pkg/Ext4Dxe/BlockMap.c b/Features/Ext4Pkg/Ext4Dxe/BlockMap.c
index 1a06ac9fbf86..3d9e16035bee 100644
--- a/Features/Ext4Pkg/Ext4Dxe/BlockMap.c
+++ b/Features/Ext4Pkg/Ext4Dxe/BlockMap.c
@@ -70,7 +70,7 @@ UINTN
Ext4GetBlockPath (
IN CONST EXT4_PARTITION *Partition,
IN UINT32 LogicalBlock,
- OUT EXT4_BLOCK_NR BlockPath[EXT4_MAX_BLOCK_PATH]
+ OUT EXT2_BLOCK_NR BlockPath[EXT4_MAX_BLOCK_PATH]
)
{
// The logic behind the block map is very much like a page table
@@ -213,12 +213,12 @@ EFI_STATUS
Ext4GetBlocks (
IN EXT4_PARTITION *Partition,
IN EXT4_FILE *File,
- IN EXT4_BLOCK_NR LogicalBlock,
+ IN EXT2_BLOCK_NR LogicalBlock,
OUT EXT4_EXTENT *Extent
)
{
EXT4_INODE *Inode;
- EXT4_BLOCK_NR BlockPath[EXT4_MAX_BLOCK_PATH];
+ EXT2_BLOCK_NR BlockPath[EXT4_MAX_BLOCK_PATH];
UINTN BlockPathLength;
UINTN Index;
UINT32 *Buffer;
@@ -272,7 +272,13 @@ Ext4GetBlocks (
}
}
- Ext4GetExtentInBlockMap (Buffer, Partition->BlockSize / sizeof (UINT32), BlockPath[BlockPathLength - 1], Extent);
+ Ext4GetExtentInBlockMap (
+ Buffer,
+ Partition->BlockSize / sizeof (UINT32),
+ BlockPath[BlockPathLength - 1],
+ Extent
+ );
+
FreePool (Buffer);
return EFI_SUCCESS;
diff --git a/Features/Ext4Pkg/Ext4Dxe/Extents.c b/Features/Ext4Pkg/Ext4Dxe/Extents.c
index c3874df71751..c5951f78aa62 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Extents.c
+++ b/Features/Ext4Pkg/Ext4Dxe/Extents.c
@@ -259,7 +259,8 @@ Ext4GetExtent (
if (!(Inode->i_flags & EXT4_EXTENTS_FL)) {
// If this is an older ext2/ext3 filesystem, emulate Ext4GetExtent using the block map
- Status = Ext4GetBlocks (Partition, File, LogicalBlock, Extent);
+ // We cast LogicalBlock to UINT32, considering ext2/3 are 32-bit
+ Status = Ext4GetBlocks (Partition, File, (UINT32) LogicalBlock, Extent);
if (!EFI_ERROR (Status)) {
Ext4CacheExtents (File, Extent, 1);
--
2.37.0
next prev parent reply other threads:[~2022-07-19 12:10 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 12:10 [edk2-platforms][PATCH 00/10] Ext4Pkg: Code security and correctness improvements Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 01/10] Ext4Pkg: Replace SetMem(,,0) with ZeroMem Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 02/10] Ext4Pkg: Change HoleLen type to UINT64 Savva Mitrofanov
2022-07-19 12:10 ` Savva Mitrofanov [this message]
2022-07-19 12:10 ` [edk2-platforms][PATCH 04/10] Ext4Pkg: Use assertion in Ext4CalculateChecksum Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 05/10] Ext4Pkg: Fix compiler warnings Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 06/10] Ext4Pkg: Drop dir entry name_len limit extra check Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 07/10] Ext4Pkg: Simplify Ext4RemoveDentry logic Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 08/10] Ext4Pkg: Fix possible int overflow in Ext4ExtentsMapKeyCompare Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 09/10] Ext4Pkg: Return bad block type in Ext4GetBlockpath Savva Mitrofanov
2022-07-19 12:10 ` [edk2-platforms][PATCH 10/10] Ext4Pkg: Group descriptor size must be 4-byte aligned Savva Mitrofanov
2022-07-19 16:19 ` [edk2-platforms][PATCH 00/10] Ext4Pkg: Code security and correctness improvements Pedro Falcato
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220719121016.29380-4-savvamtr@gmail.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox