From: "Pedro Falcato" <pedro.falcato@gmail.com>
To: devel@edk2.groups.io
Cc: "Pedro Falcato" <pedro.falcato@gmail.com>,
"Marvin Häuser" <mhaeuser@posteo.de>
Subject: [PATCH 1/2] Ext4Pkg: Add documentation surrounding ext4 directory entries
Date: Wed, 11 Jan 2023 23:59:16 +0000 [thread overview]
Message-ID: <20230111235920.252317-2-pedro.falcato@gmail.com> (raw)
In-Reply-To: <20230111235920.252317-1-pedro.falcato@gmail.com>
Several questions have popped up regarding the ext4 directory entry
layout and contents off-list. Attempt to clarify these issues by adding
some explanatory comments.
Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
Cc: Marvin Häuser <mhaeuser@posteo.de>
---
Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 21 +++++++++++++++++++--
Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 5 ++---
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
index 4fd91a423324..d0a455d0e572 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h
@@ -1,7 +1,7 @@
/** @file
Raw filesystem data structures
- Copyright (c) 2021 Pedro Falcato All rights reserved.
+ Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Layout of an EXT2/3/4 filesystem:
@@ -397,12 +397,29 @@ typedef struct _Ext4Inode {
UINT32 i_projid;
} EXT4_INODE;
+#define EXT4_NAME_MAX 255
+
typedef struct {
+ // offset 0x0: inode number (if 0, unused entry, should skip.)
UINT32 inode;
+ // offset 0x4: Directory entry's length.
+ // Note: rec_len >= name_len + EXT4_MIN_DIR_ENTRY_LEN and rec_len % 4 == 0.
UINT16 rec_len;
+ // offset 0x6: Directory entry's name's length
UINT8 name_len;
+ // offset 0x7: Directory entry's file type indicator
UINT8 file_type;
- CHAR8 name[255];
+ // offset 0x8: name[name_len]: Variable length character array; not null-terminated.
+ CHAR8 name[EXT4_NAME_MAX];
+ // Further notes on names:
+ // 1) We use EXT4_NAME_MAX here instead of flexible arrays for ease of use around the driver.
+ //
+ // 2) ext4 directories are defined, as the documentation puts it, as:
+ // "a directory is more or less a flat file that maps an arbitrary byte string
+ // (usually ASCII) to an inode number on the filesystem". So, they are not
+ // necessarily encoded with ASCII, UTF-8, or any of the sort. We must treat it
+ // as a bag of bytes. When interacting with EFI interfaces themselves (which expect UCS-2)
+ // we skip any directory entry that is not valid UTF-8.
} EXT4_DIR_ENTRY;
#define EXT4_MIN_DIR_ENTRY_LEN 8
diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
index adf3c13f6ea9..466e49523030 100644
--- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
+++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h
@@ -1,7 +1,7 @@
/** @file
Common header for the driver
- Copyright (c) 2021 - 2022 Pedro Falcato All rights reserved.
+ Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -31,8 +31,7 @@
#include "Ext4Disk.h"
-#define SYMLOOP_MAX 8
-#define EXT4_NAME_MAX 255
+#define SYMLOOP_MAX 8
//
// We need to specify path length limit for security purposes, to prevent possible
// overflows and dead-loop conditions. Originally this limit is absent in FS design,
--
2.39.0
next prev parent reply other threads:[~2023-01-11 23:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-11 23:59 [PATCH 0/3] Ext4Pkg: Small ext4 fixes and improvements Pedro Falcato
2023-01-11 23:59 ` Pedro Falcato [this message]
2023-01-11 23:59 ` [PATCH 1/3] Ext4Pkg: Fix out-of-bounds read in Ext4ReadDir Pedro Falcato
2023-01-14 17:05 ` Marvin Häuser
2023-01-11 23:59 ` [PATCH 2/3] Ext4Pkg: Add documentation surrounding ext4 directory entries Pedro Falcato
2023-01-14 17:10 ` Marvin Häuser
2023-01-11 23:59 ` [PATCH 2/2] Ext4Pkg: Fix and clarify handling regarding non-utf8 dir entries Pedro Falcato
2023-01-11 23:59 ` [PATCH 3/3] " Pedro Falcato
2023-01-14 17:13 ` Marvin Häuser
[not found] ` <1739669F06B92E95.23170@groups.io>
2023-01-12 0:04 ` [edk2-devel] [PATCH 2/3] Ext4Pkg: Add documentation surrounding ext4 directory entries 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=20230111235920.252317-2-pedro.falcato@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