From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by mx.groups.io with SMTP id smtpd.web10.41548.1673481567266644865 for ; Wed, 11 Jan 2023 15:59:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=lbRDk4+6; spf=pass (domain: gmail.com, ip: 209.85.128.41, mailfrom: pedro.falcato@gmail.com) Received: by mail-wm1-f41.google.com with SMTP id k22-20020a05600c1c9600b003d1ee3a6289so13860414wms.2 for ; Wed, 11 Jan 2023 15:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YXdDTQvHJuMdurGkusro8rFSKcaYq7gieN6vom13LY0=; b=lbRDk4+6TqlwKSseA+ecJUFg6cZelU45W2/zR0ytw3btAe5zA/D4LM4HV7CkWHlQzs vKdqAWmXoGjzSuV7h2OrNrZUKsomjv+Kp6N2VtxbTjNAq3aSjcBF0ePYMTlM9xNyYjlm 4oT2KTGMNw21Nt1CVjEBNoEkmeRq5c2mEtaD4XwVevhZg0beUkQC1i/aGCO4z8XMe3Pt aMpvPgk3RH59i1Ebtbc2tM1BywAjZw+6u4VgpAP+tfZpkZ9Lfg0ta2YEWbraX00eG1W3 HPCN7YhtU7zC8hcsud+mU6CDoXKIdG6MmWQDZNrGTIehabq9g32bCTtiUUNmGFJZYHum 4GEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YXdDTQvHJuMdurGkusro8rFSKcaYq7gieN6vom13LY0=; b=rxLwkTh5NGpUe8t+//T1dhuGmFPK3ASa8+0nm/xy3XUVgDBJGfsPJwPdxqMl7yYd7I nYFwr3+y3uww2f51BuOmGNJUe7pj2QPljI/lJ3GaCi8/iDpcgoR64ebaQ9eRQHESjAEM jMogEoemGfyAL1unGCWYcbRDiQeTTP+Dkvj2+AS9shmpMBYsgQwt+x/vf0LdfM+ZftAr f/PePgUbqYDJqgqRCHpSDjvPAOED4dfS1fawyiL02o+b5ENt60kqmBL8lLIuvx9bZfLN ocIA5udK/9aoETp7tZEgHEEiHbkInpXYuPF9ASjunwWUonnotGIvtOyNJx3oGQVi0fF5 UxcQ== X-Gm-Message-State: AFqh2kq+PIedo6OoZhOVr9+W3Dh8E3rUymF2hcSBIpLuEWJB8aBfOjMw BF4LsL3PYk+CLjrNePMmLBcZb2e46o0tCw== X-Google-Smtp-Source: AMrXdXs8Eqg4tdXLhp8KSkukiGzpYgZkLMP8EaHCqZuwjfr+PeZcq2/qKuhmSFl6PGafWgFk2Xq2gQ== X-Received: by 2002:a05:600c:3550:b0:3d9:ed30:6a73 with SMTP id i16-20020a05600c355000b003d9ed306a73mr10812387wmq.9.1673481565489; Wed, 11 Jan 2023 15:59:25 -0800 (PST) Return-Path: Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id p21-20020a7bcc95000000b003c65c9a36dfsm19276102wma.48.2023.01.11.15.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Jan 2023 15:59:25 -0800 (PST) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , =?UTF-8?q?Marvin=20H=C3=A4user?= Subject: [PATCH 1/2] Ext4Pkg: Add documentation surrounding ext4 directory entries Date: Wed, 11 Jan 2023 23:59:16 +0000 Message-Id: <20230111235920.252317-2-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230111235920.252317-1-pedro.falcato@gmail.com> References: <20230111235920.252317-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Marvin Häuser --- 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