From nobody Mon Feb 9 12:26:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+79663+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79663+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1629557301; cv=none; d=zohomail.com; s=zohoarc; b=TgsVlb1PQY1zGtMEatd37rrS5sdQsAe+Y5o2ckxr5vT10I3w3RRiHt7YSz628SPO0eHkoDQqHUo9vUZBdI0MilezpjcQ9yI1kO7RSaxWXSlVbKZMav3PJ1tPFyO+qmxbrNg6d9kT1f49WQST7JaDowoP19YUMLwW5RFHAidxSOA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629557301; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=h+TXAlk4CMVNCaxRiJ9DOXkhc0tZXQmyYo3zl6vuBvM=; b=C5yHIzvyJstItT2sSuirme+37OZGwhjoq5S/EwBM+a1V+MFReV6NpuuVWf+FKMU30xgA2XpPL8DISCJ61I5yoCrMEc8Za4h32spOZIEXAzgTDyWcOApJwU/+ifuou17gqPrxe7GESMLTnEBa30F3zo2RQrTvhYTEupNDVHCiVzE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+79663+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1629557301981691.8593361949777; Sat, 21 Aug 2021 07:48:21 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id fGyzYY1788612xyGmNP8IXiY; Sat, 21 Aug 2021 07:48:21 -0700 X-Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) by mx.groups.io with SMTP id smtpd.web09.11632.1629557300939028022 for ; Sat, 21 Aug 2021 07:48:21 -0700 X-Received: by mail-wm1-f51.google.com with SMTP id u15so7632738wmj.1 for ; Sat, 21 Aug 2021 07:48:20 -0700 (PDT) X-Gm-Message-State: YJn7MmnKqBZTguh3galoQTawx1787277AA= X-Google-Smtp-Source: ABdhPJzVObs6KcQLJr87wXKqkoRGejvnurhDU7eEIRbn+pBYHSce2YKZPjKW2ML44Uttyeu9L5PgUQ== X-Received: by 2002:a05:600c:154f:: with SMTP id f15mr7349712wmg.124.1629557299294; Sat, 21 Aug 2021 07:48:19 -0700 (PDT) X-Received: from PC-PEDRO.lan (bl8-253-151.dsl.telepac.pt. [85.241.253.151]) by smtp.gmail.com with ESMTPSA id j17sm9118036wrt.69.2021.08.21.07.48.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Aug 2021 07:48:19 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Leif Lindholm , Michael D Kinney , Bret Barkelew Subject: [edk2-devel] [edk2-platforms PATCH v2 2/5] Ext4Pkg: Hide "." and ".." entries from Read() callers. Date: Sat, 21 Aug 2021 15:47:07 +0100 Message-Id: <20210821144711.39546-3-pedro.falcato@gmail.com> In-Reply-To: <20210821144711.39546-1-pedro.falcato@gmail.com> References: <20210821144711.39546-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pedro.falcato@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1629557301; bh=4I9xT8cD7trOxk2NiyDzx8lvaRk4eYBfDpQE5Ujertk=; h=Cc:Date:From:Reply-To:Subject:To; b=v1Xc8zuJubp3tVJSc8RKJZ0pe49s7PNHZFGuXr+4khreprBBc4YFca4TNSLdzSElwkW uA44CCvkxGvj9Oobp0RWQjPpny3jLXgRQ8bZKs+cBWtwnznKVvctjM9n5Y9NBpfXkmkrJ bQwshPhBTYIqWlbwc0qAZuFBoivuHpBWxQk= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1629558204091100001 Content-Type: text/plain; charset="utf-8" This makes it so callers that may expect FAT32 filesystems (most do) have more normal looking ReadDir() results. This commit also presents a better filename for files opened through Open("."). Cc: Leif Lindholm Cc: Michael D Kinney Cc: Bret Barkelew Signed-off-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Directory.c | 45 +++++++++++++++++++++++----- Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 4 ++- Features/Ext4Pkg/Ext4Dxe/Inode.c | 2 +- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index 081c6bf0f435..c85c4df6d5c5 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -180,6 +180,7 @@ Ext4RetrieveDirent ( @param[in] OpenMode Mode in which the file is supposed to be op= en. @param[out] OutFile Pointer to the newly opened file. @param[in] Entry Directory entry to be used. + @param[in] Directory Pointer to the opened directory. =20 @retval EFI_STATUS Result of the operation **/ @@ -188,12 +189,18 @@ Ext4OpenDirent ( IN EXT4_PARTITION *Partition, IN UINT64 OpenMode, OUT EXT4_FILE **OutFile, - IN EXT4_DIR_ENTRY *Entry + IN EXT4_DIR_ENTRY *Entry, + IN EXT4_FILE *Directory ) { EFI_STATUS Status; - CHAR16 FileName[EXT4_NAME_MAX + 1]; + CHAR16 FileNameBuf[EXT4_NAME_MAX + 1]; EXT4_FILE *File; + CHAR16 *FileName; + UINTN DestMax; + + FileName =3D FileNameBuf; + DestMax =3D ARRAY_SIZE (FileNameBuf); =20 File =3D AllocateZeroPool (sizeof (EXT4_FILE)); =20 @@ -202,12 +209,18 @@ Ext4OpenDirent ( goto Error; } =20 - Status =3D Ext4GetUcs2DirentName (Entry, FileName); + Status =3D Ext4GetUcs2DirentName (Entry, FileNameBuf); =20 if (EFI_ERROR (Status)) { goto Error; } =20 + if (StrCmp (FileNameBuf, L".") =3D=3D 0) { + // We're using the parent directory's name + FileName =3D Directory->FileName; + DestMax =3D StrLen (FileName) + 1; + } + File->FileName =3D AllocateZeroPool (StrSize (FileName)); =20 if (!File->FileName) { @@ -222,7 +235,7 @@ Ext4OpenDirent ( } =20 // This should not fail. - StrCpyS (File->FileName, ARRAY_SIZE (FileName), FileName); + StrCpyS (File->FileName, DestMax, FileName); =20 File->InodeNum =3D Entry->inode; =20 @@ -290,7 +303,7 @@ Ext4OpenFile ( return EFI_NOT_FOUND; } =20 - return Ext4OpenDirent (Partition, OpenMode, OutFile, &Entry); + return Ext4OpenDirent (Partition, OpenMode, OutFile, &Entry, Directory); } =20 /** @@ -429,6 +442,8 @@ Ext4ReadDir ( UINT32 BlockRemainder; EXT4_DIR_ENTRY Entry; EXT4_FILE *TempFile; + BOOLEAN ShouldSkip; + BOOLEAN IsDotOrDotDot; =20 DirIno =3D File->Inode; Status =3D EFI_SUCCESS; @@ -470,13 +485,27 @@ Ext4ReadDir ( goto Out; } =20 - if (Entry.inode =3D=3D 0) { - // When inode =3D 0, it's unused + // We don't care about passing . or .. entries to the caller of ReadDi= r(), + // since they're generally useless entries *and* may break things if t= oo + // many callers assume FAT32. + + // Entry.name_len may be 0 if it's a nameless entry, like an unused en= try + // or a checksum at the end of the directory block. + // memcmp (and CompareMem) return 0 when the passed length is 0. + + IsDotOrDotDot =3D Entry.name_len !=3D 0 && + (CompareMem (Entry.name, ".", Entry.name_len) =3D=3D 0= || + CompareMem (Entry.name, "..", Entry.name_len) =3D=3D = 0); + + // When inode =3D 0, it's unused. + ShouldSkip =3D Entry.inode =3D=3D 0 || IsDotOrDotDot; + + if (ShouldSkip) { Offset +=3D Entry.rec_len; continue; } =20 - Status =3D Ext4OpenDirent (Partition, EFI_FILE_MODE_READ, &TempFile, &= Entry); + Status =3D Ext4OpenDirent (Partition, EFI_FILE_MODE_READ, &TempFile, &= Entry, File); =20 if (EFI_ERROR (Status)) { goto Out; diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 93f0a8a04add..1aafc60ab57d 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -353,6 +353,7 @@ Ext4OpenFile ( @param[in] OpenMode Mode in which the file is supposed to be op= en. @param[out] OutFile Pointer to the newly opened file. @param[in] Entry Directory entry to be used. + @param[in] Directory Pointer to the opened directory. =20 @retval EFI_STATUS Result of the operation **/ @@ -361,7 +362,8 @@ Ext4OpenDirent ( IN EXT4_PARTITION *Partition, IN UINT64 OpenMode, OUT EXT4_FILE **OutFile, - IN EXT4_DIR_ENTRY *Entry + IN EXT4_DIR_ENTRY *Entry, + IN EXT4_FILE *Directory ); =20 /** diff --git a/Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/In= ode.c index 1bbff9e69f4c..982b19c763d0 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Inode.c +++ b/Features/Ext4Pkg/Ext4Dxe/Inode.c @@ -89,7 +89,7 @@ Ext4Read ( IN OUT UINTN *Length ) { - DEBUG ((DEBUG_FS, "[ext4] Ext4Read(Offset %lu, Length %lu)\n", Offset, *= Length)); + DEBUG ((DEBUG_FS, "[ext4] Ext4Read(%s, Offset %lu, Length %lu)\n", File-= >FileName, Offset, *Length)); EXT4_INODE *Inode; UINT64 InodeSize; UINT64 CurrentSeek; --=20 2.33.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#79663): https://edk2.groups.io/g/devel/message/79663 Mute This Topic: https://groups.io/mt/85043012/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-