From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mx.groups.io with SMTP id smtpd.web11.41797.1673481896574590845 for ; Wed, 11 Jan 2023 16:04:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TLpsE0qE; spf=pass (domain: gmail.com, ip: 209.85.210.174, mailfrom: pedro.falcato@gmail.com) Received: by mail-pf1-f174.google.com with SMTP id y5so12635349pfe.2 for ; Wed, 11 Jan 2023 16:04:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=YuhUWjswZJUQi8eRWKlQvQhRLmow8lAx3twfmD+rNy0=; b=TLpsE0qEm+nJ5C03RuMJi29lVrqGIujFxn9VERlWsDgDfuEtIFT/wQLsXoc1KPTbPd bPNYX0Snmw2j9pt3inBZald6tAyRfsW8LQ4C3yILTkRFL3BnOYFnzRoxpHxFK1U8BWfe oONNgccqOCyOlC2r59sYdNrxwTLGvPrmztAiQLZR9rbMjsnpbaYEmxKC1pkZsslm5AG8 S6hMydkS4oW+Wop3W/T+eMqOFqwyC7Ly/k2Msc9Ml3jPCqrf4rVqmQJhMfKq35MLTw2U 2Y/uNvWfWKsbKa7Od9EkVV9ripfMOBslisR716kw/o7pYOKO/aVRoEFpfBDd5TfzudmS d8sQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YuhUWjswZJUQi8eRWKlQvQhRLmow8lAx3twfmD+rNy0=; b=kAAI3KYsmDuzOTOZ8D0sW3RR+fTe+neg2Vyd6OzaSW8ZWtLamTs0T+XEpR3kn7TATO jZrBWo6gxnjMyvlh+6p91HKmkYNej4I/o8XGIj75NoPG3zoXY8dEyVV+ru39PNNMSBr0 PcE3cLHErjQpwdrl6qC8ClsSlGdusVctpoRo6bLOO3lp9pekl2U/y1uKl+mhQmZqZzJu H0FH2HMetsLwH9m7pG+TjssVojy1+I6pqqVq7NSKc78ny0MkJHKRvfTeYJpBWoUu/9MO VCFmCZRT0iXyUj27V4+W7l7sBqcsv/S0pu3N10qohqKzmE3kFuat83jS7UKAlflTNJsu 1oJA== X-Gm-Message-State: AFqh2kpIPvzERk7Tb1L2/Z40LUacRnOhn3er4b6syx0etLIaCm6NiTod bqsLH3qnhlhVhQ1degKQXXlxBEaej/904Rc9q4xzzQtKn3WmyQ== X-Google-Smtp-Source: AMrXdXu7qyGsBMR0GTVLB4rcqBCtZKcuH4H7mStT9ylHt6evOfUlxhzVQscEbo17EQTBuVjVUcuzZqrOGLj9U0cUKO8= X-Received: by 2002:a63:b0e:0:b0:44e:466f:4759 with SMTP id 14-20020a630b0e000000b0044e466f4759mr4753475pgl.194.1673481895693; Wed, 11 Jan 2023 16:04:55 -0800 (PST) MIME-Version: 1.0 References: <20230111235920.252317-1-pedro.falcato@gmail.com> <1739669F06B92E95.23170@groups.io> In-Reply-To: <1739669F06B92E95.23170@groups.io> From: "Pedro Falcato" Date: Thu, 12 Jan 2023 00:04:44 +0000 Message-ID: Subject: Re: [edk2-devel] [PATCH 2/3] Ext4Pkg: Add documentation surrounding ext4 directory entries To: devel@edk2.groups.io, pedro.falcato@gmail.com Cc: =?UTF-8?Q?Marvin_H=C3=A4user?= Content-Type: multipart/alternative; boundary="000000000000ee548f05f205dd29" --000000000000ee548f05f205dd29 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Apologies for the duplicate send of these patches, small mistake using git send-email *.patch ;) Please only consider the patches that start with [PATCH N/3]. On Wed, Jan 11, 2023 at 11:59 PM Pedro Falcato via groups.io wrote: > 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=C3=A4user > --- > 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 >=3D name_len + EXT4_MIN_DIR_ENTRY_LEN an= d > rec_len % 4 =3D=3D 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 byt= e > 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 preven= t > possible > // overflows and dead-loop conditions. Originally this limit is absent i= n > FS design, > -- > 2.39.0 > > > >=20 > > > --=20 Pedro --000000000000ee548f05f205dd29 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Apologies for the duplicate send of these patches, sm= all mistake using git send-email *.patch ;)
Please only consider = the patches that start with [PATCH N/3].

On Wed, Jan 11, 2023 at 1= 1:59 PM Pedro Falcato via groups.io <pe= dro.falcato=3Dgmail.com@groups.io> wrote:
Sev= eral 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=C3=A4user <mhaeuser@posteo.de>
---
=C2=A0Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 21 +++++++++++++++++++--
=C2=A0Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h=C2=A0 |=C2=A0 5 ++---
=C2=A02 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 @@
=C2=A0/** @file
=C2=A0 =C2=A0Raw filesystem data structures

-=C2=A0 Copyright (c) 2021 Pedro Falcato All rights reserved.
+=C2=A0 Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
=C2=A0 =C2=A0SPDX-License-Identifier: BSD-2-Clause-Patent

=C2=A0 =C2=A0Layout of an EXT2/3/4 filesystem:
@@ -397,12 +397,29 @@ typedef struct _Ext4Inode {
=C2=A0 =C2=A0UINT32=C2=A0 =C2=A0 =C2=A0 =C2=A0i_projid;
=C2=A0} EXT4_INODE;

+#define EXT4_NAME_MAX=C2=A0 255
+
=C2=A0typedef struct {
+=C2=A0 // offset 0x0: inode number (if 0, unused entry, should skip.)
=C2=A0 =C2=A0UINT32=C2=A0 =C2=A0 inode;
+=C2=A0 // offset 0x4: Directory entry's length.
+=C2=A0 //=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Note: rec_len >= ;=3D name_len + EXT4_MIN_DIR_ENTRY_LEN and rec_len % 4 =3D=3D 0.
=C2=A0 =C2=A0UINT16=C2=A0 =C2=A0 rec_len;
+=C2=A0 // offset 0x6: Directory entry's name's length
=C2=A0 =C2=A0UINT8=C2=A0 =C2=A0 =C2=A0name_len;
+=C2=A0 // offset 0x7: Directory entry's file type indicator
=C2=A0 =C2=A0UINT8=C2=A0 =C2=A0 =C2=A0file_type;
-=C2=A0 CHAR8=C2=A0 =C2=A0 =C2=A0name[255];
+=C2=A0 // offset 0x8: name[name_len]: Variable length character array; not= null-terminated.
+=C2=A0 CHAR8=C2=A0 =C2=A0 =C2=A0name[EXT4_NAME_MAX];
+=C2=A0 // Further notes on names:
+=C2=A0 // 1) We use EXT4_NAME_MAX here instead of flexible arrays for ease= of use around the driver.
+=C2=A0 //
+=C2=A0 // 2) ext4 directories are defined, as the documentation puts it, a= s:
+=C2=A0 // "a directory is more or less a flat file that maps an arbit= rary byte string
+=C2=A0 // (usually ASCII) to an inode number on the filesystem". So, = they are not
+=C2=A0 // necessarily encoded with ASCII, UTF-8, or any of the sort. We mu= st treat it
+=C2=A0 // as a bag of bytes. When interacting with EFI interfaces themselv= es (which expect UCS-2)
+=C2=A0 // we skip any directory entry that is not valid UTF-8.
=C2=A0} EXT4_DIR_ENTRY;

=C2=A0#define EXT4_MIN_DIR_ENTRY_LEN=C2=A0 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 @@
=C2=A0/** @file
=C2=A0 =C2=A0Common header for the driver

-=C2=A0 Copyright (c) 2021 - 2022 Pedro Falcato All rights reserved.
+=C2=A0 Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
=C2=A0 =C2=A0SPDX-License-Identifier: BSD-2-Clause-Patent
=C2=A0**/

@@ -31,8 +31,7 @@

=C2=A0#include "Ext4Disk.h"

-#define SYMLOOP_MAX=C2=A0 =C2=A0 8
-#define EXT4_NAME_MAX=C2=A0 255
+#define SYMLOOP_MAX=C2=A0 8
=C2=A0//
=C2=A0// We need to specify path length limit for security purposes, to pre= vent possible
=C2=A0// overflows and dead-loop conditions. Originally this limit is absen= t in FS design,
--
2.39.0








--
Pedro
--000000000000ee548f05f205dd29--