From nobody Mon May 6 08:05:50 2024 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+79592+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+79592+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1629408563; cv=none; d=zohomail.com; s=zohoarc; b=N4GgrNysf5gE3bbOdxRtc2DzXyrdpLBK12FczQoReuoQKwbIZnvcTjIYWAKRh8MGoawORZqa4hkdHxaQNcfF5lAmV5l2N1JdsAFgVxJxWkBTBL9JdmZ+9eI19zWxv1O8ADyl0OovimOJeLmlcqGaU1B3RahWh+WC36ZbTIFtCH4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629408563; 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=d3RLkGvdXIOYIzTnUVVvOdLh5xDMOcdbkGDclhLCq8o=; b=BwrD9efpvl4nCrUkTLZiWl3tC+9pzF6xr5e7of4Afib1aaefl2LZ10ZgaICW7wdXvs8VdynLUqLmE1GtYc0F97oPkXzJ10FaRR7DfYpYGTHPKGPfBt10EUpboxCZCMiCSt2rqtxinWl+nGhKqG2xHmepBqEx0ELy8/0q9A1/b4I= 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+79592+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 162940856384221.55502726018733; Thu, 19 Aug 2021 14:29:23 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id UZ68YY1788612xdQm0tNJmL2; Thu, 19 Aug 2021 14:29:23 -0700 X-Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by mx.groups.io with SMTP id smtpd.web08.75960.1629408562623119602 for ; Thu, 19 Aug 2021 14:29:22 -0700 X-Received: by mail-wr1-f53.google.com with SMTP id q11so11072267wrr.9 for ; Thu, 19 Aug 2021 14:29:22 -0700 (PDT) X-Gm-Message-State: SnJBvtqiqi6disLrwPrHTWR8x1787277AA= X-Google-Smtp-Source: ABdhPJwmJLdeFXgLVLuw4MiojvbDkqKjzVcsa3aPMsiV7eIq+oY9I5Rwm5LWJUE3NOjeu85pQxvEWQ== X-Received: by 2002:a5d:40cb:: with SMTP id b11mr6035225wrq.135.1629408561050; Thu, 19 Aug 2021 14:29:21 -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 p12sm3118387wmq.44.2021.08.19.14.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 14:29:20 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Leif Lindholm , Michael D Kinney , Bret Barkelew Subject: [edk2-devel] [PATCH 1/3] Ext4Pkg: Fix incorrect usage of Ext4InitExtentsMap. Date: Thu, 19 Aug 2021 22:28:41 +0100 Message-Id: <20210819212843.37454-2-pedro.falcato@gmail.com> In-Reply-To: <20210819212843.37454-1-pedro.falcato@gmail.com> References: <20210819212843.37454-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=1629408563; bh=JOPE5j5W3Tb/llfp4r2sclHWQ9fEqc3Cdvvd8ZLXF0k=; h=Cc:Date:From:Reply-To:Subject:To; b=cadlAtq10KIzRNi+Hia5iE6rsW191L+w+rfhJ/GAmrWgo3/ipZ35nUmYg0dDWDn/vqX AyibW3BRqnbiiuAOUwSDMIVF9MJSd+EkGnimUtk8uoBkLY0tZ/YQiWyJCWp7huZIDU46K 9K9A9RWKr4hXkFQz0JuyguFF0QJq3EJ8sTs= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1629408710686100010 Content-Type: text/plain; charset="utf-8" Fixes bug triggered by ShellPkg code, in usage of EFI_FILE_PROTOCOL's Open(). Cc: Leif Lindholm Cc: Michael D Kinney Cc: Bret Barkelew Signed-off-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/File.c | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/Fil= e.c index 0f5fa6f73f..a3eff2b48a 100644 --- a/Features/Ext4Pkg/Ext4Dxe/File.c +++ b/Features/Ext4Pkg/Ext4Dxe/File.c @@ -207,6 +207,11 @@ Ext4Open ( =20 FileName +=3D Length; =20 + if (StrCmp(PathSegment, L".") =3D=3D 0) { + // Opens of "." are a no-op + continue; + } + DEBUG ((DEBUG_FS, "[ext4] Opening %s\n", PathSegment)); =20 if (!Ext4FileIsDir (Current)) { @@ -512,12 +517,20 @@ Ext4GetFileInfo ( IN EXT4_FILE *File, OUT EFI_FILE_INFO *Info, IN OUT UINTN *BufferSize ) { - UINTN FileNameLen; - UINTN FileNameSize; - UINTN NeededLength; + UINTN FileNameLen; + UINTN FileNameSize; + UINTN NeededLength; + CONST CHAR16 *FileName; + + if (File->InodeNum =3D=3D 2) { + // Root inode gets a filename of "", regardless of how it was opened. + FileName =3D L""; + } else { + FileName =3D File->FileName; + } =20 - FileNameLen =3D StrLen (File->FileName); - FileNameSize =3D StrSize (File->FileName); + FileNameLen =3D StrLen (FileName); + FileNameSize =3D StrSize (FileName); =20 NeededLength =3D SIZE_OF_EFI_FILE_INFO + FileNameSize; =20 @@ -540,7 +553,7 @@ Ext4GetFileInfo ( =20 *BufferSize =3D NeededLength; =20 - return StrCpyS (Info->FileName, FileNameLen + 1, File->FileName); + return StrCpyS (Info->FileName, FileNameLen + 1, FileName); } =20 /** @@ -687,6 +700,7 @@ Ext4DuplicateFile ( { EXT4_PARTITION *Partition; EXT4_FILE *File; + EFI_STATUS Status; =20 Partition =3D Original->Partition; File =3D AllocateZeroPool (sizeof (EXT4_FILE)); @@ -717,7 +731,8 @@ Ext4DuplicateFile ( File->InodeNum =3D Original->InodeNum; File->OpenMode =3D 0; // Will be filled by other code =20 - if (!Ext4InitExtentsMap (File)) { + Status =3D Ext4InitExtentsMap (File); + if (EFI_ERROR (Status)) { FreePool (File->FileName); FreePool (File->Inode); FreePool (File); --=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 (#79592): https://edk2.groups.io/g/devel/message/79592 Mute This Topic: https://groups.io/mt/85007621/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- From nobody Mon May 6 08:05:50 2024 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+79593+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+79593+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1629408564; cv=none; d=zohomail.com; s=zohoarc; b=ckmOt6UxpQQAGei8D16Y+CkMFGS+3CEdX9C69CV3U4fly4klRf9V9CU7K9aYWq0Igz5x9tR2uUj4WN1z6JkRBzmhXVRmrS3zdhc1xZKtFkZV4FYP8mNEUHEs07Oo6fzUXTiswRliSAaP93EITIljUxQ11Djs7WrOisbegPFrND4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629408564; 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=EMhugg13h9zxF+JsZ4RaMmf86u3un311iOnr1bzdOSc=; b=AhKN3/gBeBVTq2JeDUMoupsbxR5/nsnOz4jS8QnjpFZ0kDeBIyEgWTYW8Adwh5X6h6jrUtwY1xYGKliHhX+g0Cf6ic7zPfka+iBvrR1hHVGiUJF/4IgWzKhutiLAosPIrmS7ATHW1VUlO2vVwoJ2GXcezT+B1eWN57QRJYK1k7o= 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+79593+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 1629408564734897.9622196952204; Thu, 19 Aug 2021 14:29:24 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id XO7cYY1788612xdJfGy3B3x5; Thu, 19 Aug 2021 14:29:24 -0700 X-Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) by mx.groups.io with SMTP id smtpd.web11.75468.1629408563730652193 for ; Thu, 19 Aug 2021 14:29:24 -0700 X-Received: by mail-wr1-f53.google.com with SMTP id l11so11098014wrx.4 for ; Thu, 19 Aug 2021 14:29:23 -0700 (PDT) X-Gm-Message-State: fqPLGpVohnL8QNM9bQ5y0JdYx1787277AA= X-Google-Smtp-Source: ABdhPJxp7BLnDi0pm6iEo4BeqdK5/KDcnn2cWEVhuzby/xPyvGo0HOwsFJe/+w9JJEv5cpjUZGRbDA== X-Received: by 2002:a5d:668f:: with SMTP id l15mr6318259wru.390.1629408562124; Thu, 19 Aug 2021 14:29:22 -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 p12sm3118387wmq.44.2021.08.19.14.29.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 14:29:21 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Leif Lindholm , Michael D Kinney , Bret Barkelew Subject: [edk2-devel] [PATCH 2/3] Ext4Pkg: Hide "." and ".." entries from Read() callers. Date: Thu, 19 Aug 2021 22:28:42 +0100 Message-Id: <20210819212843.37454-3-pedro.falcato@gmail.com> In-Reply-To: <20210819212843.37454-1-pedro.falcato@gmail.com> References: <20210819212843.37454-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=1629408564; bh=e+FWQmNvB3iFs8QvkZyuH3BeRQSyXuA15DXL4rTcMbs=; h=Cc:Date:From:Reply-To:Subject:To; b=nboBwiLMLPX/3b0YO9HW42AAwPPGRikoQfzluQd0vcNFdKIOeCETBVdbNjwziJ6o2XS 0tQlAtIGEwg2SZsv5f2uZcUhlNHan6459kn7s1xO4YbbYEZ/G6Oo1AALJBA29QLpzkqy6 D/uiDl477kMy6MKKMxVd4J43IQMMFS+kQ5Q= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1629408710705100011 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 081c6bf0f4..c85c4df6d5 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 93f0a8a04a..1aafc60ab5 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 1bbff9e69f..982b19c763 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 (#79593): https://edk2.groups.io/g/devel/message/79593 Mute This Topic: https://groups.io/mt/85007622/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- From nobody Mon May 6 08:05:50 2024 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+79594+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+79594+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1629408566; cv=none; d=zohomail.com; s=zohoarc; b=R1bIzbXjr5oO8RHQX7mK/DYhPF/qFpNnBezEMbMMFsml2iuWk+GZ3AJqGXTSz/R4jPgi2NEAmP8O92saPRt4SWp9VB9d3frS5rw9CJWFLjU/w3py0F1wW9kByOugO/h+7v4ZENVAJ2Iu7gftGbLe5NoqMvi6Oo43E2ewJ7qYV64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629408566; 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=chslgIrnRUS4oSR6SnFnV0PTUwyNMnMvSwZm60eKHAs=; b=eiYsDj4/3Fzk9Pf5WnCOK1ZRzKHDfhkjfYdZ9+VUJuNpNLcwkRbxux3H815SV74uiTn1ib7bSn1Ej9ZbTTZcsodYUwQq998y9I5ylPQkXasb0hHEJhUDZkybl9k4chkGOg0KOloeg7OslpWsyD5nfyifsp03zWn+LHCJtVn9aGg= 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+79594+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 1629408566106898.7533861653366; Thu, 19 Aug 2021 14:29:26 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id GbYdYY1788612xWkaEwoTv5l; Thu, 19 Aug 2021 14:29:25 -0700 X-Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) by mx.groups.io with SMTP id smtpd.web08.75961.1629408564890160021 for ; Thu, 19 Aug 2021 14:29:25 -0700 X-Received: by mail-wr1-f41.google.com with SMTP id q10so11091494wro.2 for ; Thu, 19 Aug 2021 14:29:24 -0700 (PDT) X-Gm-Message-State: QHK0vYDhla6aTpJK1d8aSsigx1787277AA= X-Google-Smtp-Source: ABdhPJyxKaUCJWIXGePkm9KVAxxW7cpKdVeBCTX2RdZaOJaYpuNwo+2Yh0upfDMi5qwbdYWFvdH/yg== X-Received: by 2002:adf:a3c6:: with SMTP id m6mr6029285wrb.32.1629408563196; Thu, 19 Aug 2021 14:29:23 -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 p12sm3118387wmq.44.2021.08.19.14.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Aug 2021 14:29:22 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Leif Lindholm , Michael D Kinney , Bret Barkelew Subject: [edk2-devel] [PATCH 3/3] Ext4Pkg: Add a directory entry tree. Date: Thu, 19 Aug 2021 22:28:43 +0100 Message-Id: <20210819212843.37454-4-pedro.falcato@gmail.com> In-Reply-To: <20210819212843.37454-1-pedro.falcato@gmail.com> References: <20210819212843.37454-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=1629408565; bh=t9NENBBQUzRCuV6rNWeLwkowD8bJT6G95hCqscYT06Y=; h=Cc:Date:From:Reply-To:Subject:To; b=m6Q2pdCmnnLZ0zrOseAt7MO3PihV3Z18JBw/untBBlw7HbHC/PM4I5dqGdRB5qvOOVE 3Ya2TssEaPXleeT2c5fZ273In4vQlOgJ71lfGskI+FMvYOg2x0yBPOG1YwVZQHy2bHBcT DqtWTeMEDZB5iqAUaYthnWuEYsmdRr231GI= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1629408710721100012 Content-Type: text/plain; charset="utf-8" This helps us track directories and directory entries, which helps us getting a general idea of how the filesystem looks. In the future, it might serve as a directory cache. Right now, it only lets us know which name "." and ".." may refer to, which fixes a EFI_FILE_PROTOCOL::GetInfo() bug that got triggered by ShellPkg, in some MdePkg code. Cc: Leif Lindholm Cc: Michael D Kinney Cc: Bret Barkelew Signed-off-by: Pedro Falcato --- Features/Ext4Pkg/Ext4Dxe/Directory.c | 238 +++++++++++++++++++++----- Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h | 3 + Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 67 +++++++- Features/Ext4Pkg/Ext4Dxe/File.c | 24 +-- Features/Ext4Pkg/Ext4Dxe/Inode.c | 2 +- Features/Ext4Pkg/Ext4Dxe/Partition.c | 7 + Features/Ext4Pkg/Ext4Dxe/Superblock.c | 24 ++- 7 files changed, 301 insertions(+), 64 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Directory.c b/Features/Ext4Pkg/Ext4Dx= e/Directory.c index c85c4df6d5..7d1b2dcfe5 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Directory.c +++ b/Features/Ext4Pkg/Ext4Dxe/Directory.c @@ -194,13 +194,8 @@ Ext4OpenDirent ( ) { EFI_STATUS Status; - CHAR16 FileNameBuf[EXT4_NAME_MAX + 1]; + CHAR16 FileName[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 @@ -209,23 +204,32 @@ Ext4OpenDirent ( goto Error; } =20 - Status =3D Ext4GetUcs2DirentName (Entry, FileNameBuf); + Status =3D Ext4GetUcs2DirentName (Entry, FileName); =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; - } + if (StrCmp (FileName, L".") =3D=3D 0) { + // We're using the parent directory's dentry + File->Dentry =3D Directory->Dentry; =20 - File->FileName =3D AllocateZeroPool (StrSize (FileName)); + ASSERT (File->Dentry !=3D NULL); =20 - if (!File->FileName) { - Status =3D EFI_OUT_OF_RESOURCES; - goto Error; + Ext4RefDentry (File->Dentry); + } else if (StrCmp (FileName, L"..") =3D=3D 0) { + // Using the parent's parent's dentry + File->Dentry =3D Directory->Dentry->Parent; + + ASSERT (File->Dentry !=3D NULL); + + Ext4RefDentry (File->Dentry); + } else { + File->Dentry =3D Ext4CreateDentry (FileName, Directory->Dentry); + + if (!File->Dentry) { + goto Error; + } } =20 Status =3D Ext4InitExtentsMap (File); @@ -234,9 +238,6 @@ Ext4OpenDirent ( goto Error; } =20 - // This should not fail. - StrCpyS (File->FileName, DestMax, FileName); - File->InodeNum =3D Entry->inode; =20 Ext4SetupFile (File, Partition); @@ -255,8 +256,8 @@ Ext4OpenDirent ( =20 Error: if (File !=3D NULL) { - if (File->FileName !=3D NULL) { - FreePool (File->FileName); + if (File->Dentry !=3D NULL) { + Ext4UnrefDentry (File->Dentry); } =20 if (File->ExtentsMap !=3D NULL) { @@ -333,52 +334,47 @@ Ext4OpenVolume ( OUT EFI_FILE_PROTOCOL **Root ) { - EXT4_INODE *RootInode; - EFI_STATUS Status; - EXT4_FILE *RootDir; + EXT4_INODE *RootInode; + EFI_STATUS Status; + EXT4_FILE *RootDir; + EXT4_PARTITION *Partition; + + Partition =3D (EXT4_PARTITION *)This; =20 - // 2 is always the root inode number in ext4 - Status =3D Ext4ReadInode ((EXT4_PARTITION *)This, 2, &RootInode); + Status =3D Ext4ReadInode (Partition, EXT4_ROOT_INODE_NR, &RootInode); =20 if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "[ext4] Could not open root inode - status %x\n",= Status)); + DEBUG ((DEBUG_ERROR, "[ext4] Could not open root inode - error %r\n", = Status)); return Status; } =20 RootDir =3D AllocateZeroPool (sizeof (EXT4_FILE)); =20 - if (!RootDir) { + if (RootDir =3D=3D NULL) { FreePool (RootInode); return EFI_OUT_OF_RESOURCES; } =20 - // The filename will be "\"(null terminated of course) - RootDir->FileName =3D AllocateZeroPool (2 * sizeof (CHAR16)); - - if (!RootDir->FileName) { - FreePool (RootDir); - FreePool (RootInode); - return EFI_OUT_OF_RESOURCES; - } - - RootDir->FileName[0] =3D L'\\'; - RootDir->Inode =3D RootInode; - RootDir->InodeNum =3D 2; + RootDir->InodeNum =3D EXT4_ROOT_INODE_NR; =20 Status =3D Ext4InitExtentsMap (RootDir); =20 if (EFI_ERROR (Status)) { - FreePool (RootDir->FileName); FreePool (RootInode); FreePool (RootDir); return EFI_OUT_OF_RESOURCES; } =20 - Ext4SetupFile (RootDir, (EXT4_PARTITION *)This); + Ext4SetupFile (RootDir, Partition); *Root =3D &RootDir->Protocol; =20 - InsertTailList (&((EXT4_PARTITION *)This)->OpenFiles, &RootDir->OpenFile= sListNode); + InsertTailList (&Partition->OpenFiles, &RootDir->OpenFilesListNode); + + ASSERT (Partition->RootDentry !=3D NULL); + RootDir->Dentry =3D Partition->RootDentry; + + Ext4RefDentry (RootDir->Dentry); =20 return EFI_SUCCESS; } @@ -525,3 +521,159 @@ Ext4ReadDir ( Out: return Status; } + +/** + Removes a dentry from the other's list. + + @param[in out] Parent Pointer to the parent EXT4_DENTR= Y. + @param[in out] ToBeRemoved Pointer to the child EXT4_DENTRY. +**/ +STATIC +VOID +Ext4RemoveDentry ( + IN OUT EXT4_DENTRY *Parent, + IN OUT EXT4_DENTRY *ToBeRemoved + ) +{ + EXT4_DENTRY *D; + LIST_ENTRY *Entry; + LIST_ENTRY *NextEntry; + + BASE_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Parent->Children) { + D =3D EXT4_DENTRY_FROM_DENTRY_LIST (Entry); + + if (D =3D=3D ToBeRemoved) { + RemoveEntryList (Entry); + return; + } + } + + DEBUG ((DEBUG_ERROR, "[ext4] Ext4RemoveDentry did not find the asked-for= dentry\n")); +} + +/** + Adds a dentry to the other's list. + + The dentry that is added to the other one's list gets ->Parent set to P= arent, + and the parent gets its reference count incremented. + + @param[in out] Parent Pointer to the parent EXT4_DENTR= Y. + @param[in out] ToBeAdded Pointer to the child EXT4_DENTRY. +**/ +STATIC +VOID +Ext4AddDentry ( + IN OUT EXT4_DENTRY *Parent, + IN OUT EXT4_DENTRY *ToBeAdded + ) +{ + ToBeAdded->Parent =3D Parent; + InsertTailList (&Parent->Children, &ToBeAdded->ListNode); + Ext4RefDentry (Parent); +} + +/** + Creates a new dentry object. + + @param[in] Name Name of the dentry. + @param[in out opt] Parent Parent dentry, if it's not NULL. + + @return The new allocated and initialised dentry. + The ref count will be set to 1. +**/ +EXT4_DENTRY * +Ext4CreateDentry ( + IN CONST CHAR16 *Name, + IN OUT EXT4_DENTRY *Parent OPTIONAL + ) +{ + EXT4_DENTRY *Dentry; + EFI_STATUS Status; + + Dentry =3D AllocateZeroPool (sizeof (EXT4_DENTRY)); + + if (Dentry =3D=3D NULL) { + return NULL; + } + + Dentry->RefCount =3D 1; + + // This StrCpyS should not fail. + Status =3D StrCpyS (Dentry->Name, ARRAY_SIZE (Dentry->Name), Name); + + ASSERT_EFI_ERROR (Status); + + InitializeListHead (&Dentry->Children); + + if (Parent !=3D NULL) { + Ext4AddDentry (Parent, Dentry); + } + + DEBUG ((DEBUG_FS, "[ext4] Created dentry %s\n", Name)); + + return Dentry; +} + +/** + Increments the ref count of the dentry. + + @param[in out] Dentry Pointer to a valid EXT4_DENTRY. +**/ +VOID +Ext4RefDentry ( + IN OUT EXT4_DENTRY *Dentry + ) +{ + UINTN OldRef; + + OldRef =3D Dentry->RefCount; + + Dentry->RefCount++; + + // I'm not sure if this (Refcount overflow) is a valid concern, + // but it's better to be safe than sorry. + ASSERT (OldRef < Dentry->RefCount); +} + +/** + Deletes the dentry. + + @param[in out] Dentry Pointer to a valid EXT4_DENTRY. +**/ +STATIC +VOID +Ext4DeleteDentry ( + IN OUT EXT4_DENTRY *Dentry + ) +{ + if (Dentry->Parent) { + Ext4RemoveDentry (Dentry->Parent, Dentry); + Ext4UnrefDentry (Dentry->Parent); + } + + DEBUG ((DEBUG_FS, "[ext4] Deleted dentry %s\n", Dentry->Name)); + FreePool (Dentry); +} + +/** + Decrements the ref count of the dentry. + If the ref count is 0, it's destroyed. + + @param[in out] Dentry Pointer to a valid EXT4_DENTRY. + + @retval True if it was destroyed, false if it's alive. +**/ +BOOLEAN +Ext4UnrefDentry ( + IN OUT EXT4_DENTRY *Dentry + ) +{ + Dentry->RefCount--; + + if (Dentry->RefCount =3D=3D 0) { + Ext4DeleteDentry (Dentry); + return TRUE; + } + + return FALSE; +} diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h b/Features/Ext4Pkg/Ext4Dxe= /Ext4Disk.h index b387ebcd36..070eb5a9c8 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Disk.h @@ -451,4 +451,7 @@ typedef struct { typedef UINT64 EXT4_BLOCK_NR; typedef UINT32 EXT4_INO_NR; =20 +// 2 is always the root inode number in ext4 +#define EXT4_ROOT_INODE_NR 2 + #endif diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 1aafc60ab5..db938c2524 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -55,6 +55,7 @@ Ext4OpenPartition ( ); =20 typedef struct _Ext4File EXT4_FILE; +typedef struct _Ext4_Dentry EXT4_DENTRY; =20 typedef struct _Ext4_PARTITION { EFI_SIMPLE_FILE_SYSTEM_PROTOCOL Interface; @@ -81,8 +82,68 @@ typedef struct _Ext4_PARTITION { UINT32 InitialSeed; =20 LIST_ENTRY OpenFiles; + + EXT4_DENTRY *RootDentry; } EXT4_PARTITION; =20 +/** + This structure represents a directory entry inside our directory entry = tree. + For now, it will be used as a way to track file names inside our openin= g code, + but it may very well be used as a directory cache in the future. + Because it's not being used as a directory cache right now, + an EXT4_DENTRY structure is not necessarily unique name-wise in the lis= t of + children. Therefore, the dentry tree does not accurately reflect the fi= lesystem + structure. + */ +struct _Ext4_Dentry { + UINTN RefCount; + CHAR16 Name[EXT4_NAME_MAX + 1]; + EXT4_INO_NR Inode; + struct _Ext4_Dentry *Parent; + LIST_ENTRY Children; + LIST_ENTRY ListNode; +}; + +#define EXT4_DENTRY_FROM_DENTRY_LIST(Node) BASE_CR (Node, EXT4_DENTRY, Li= stNode) + +/** + Creates a new dentry object. + + @param[in] Name Name of the dentry. + @param[in out opt] Parent Parent dentry, if it's not NULL. + + @return The new allocated and initialised dentry. + The ref count will be set to 1. +**/ +EXT4_DENTRY * +Ext4CreateDentry ( + IN CONST CHAR16 *Name, + IN OUT EXT4_DENTRY *Parent OPTIONAL + ); + +/** + Increments the ref count of the dentry. + + @param[in out] Dentry Pointer to a valid EXT4_DENTRY. +**/ +VOID +Ext4RefDentry ( + IN OUT EXT4_DENTRY *Dentry + ); + +/** + Decrements the ref count of the dentry. + If the ref count is 0, it's destroyed. + + @param[in out] Dentry Pointer to a valid EXT4_DENTRY. + + @retval True if it was destroyed, false if it's alive. +**/ +BOOLEAN +Ext4UnrefDentry ( + IN OUT EXT4_DENTRY *Dentry + ); + /** Opens and parses the superblock. =20 @@ -126,7 +187,7 @@ Ext4OpenSuperblock ( @param[in] Partition Pointer to the opened ext4 partition. @return The media ID associated with the partition. **/ -#define EXT4_MEDIA_ID(Partition) Partition->BlockIo->Media->MediaId +#define EXT4_MEDIA_ID(Partition) Partition->BlockIo->Media->MediaId =20 /** Reads from the partition's disk using the DISK_IO protocol. @@ -299,11 +360,13 @@ struct _Ext4File { UINT64 Position; =20 EXT4_PARTITION *Partition; - CHAR16 *FileName; =20 ORDERED_COLLECTION *ExtentsMap; =20 LIST_ENTRY OpenFilesListNode; + + // Owning reference to this file's directory entry. + EXT4_DENTRY *Dentry; }; =20 #define EXT4_FILE_FROM_OPEN_FILES_NODE(Node) BASE_CR (Node, EXT4_FILE, Op= enFilesListNode) diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/Fil= e.c index a3eff2b48a..021d10b1ed 100644 --- a/Features/Ext4Pkg/Ext4Dxe/File.c +++ b/Features/Ext4Pkg/Ext4Dxe/File.c @@ -207,7 +207,7 @@ Ext4Open ( =20 FileName +=3D Length; =20 - if (StrCmp(PathSegment, L".") =3D=3D 0) { + if (StrCmp (PathSegment, L".") =3D=3D 0) { // Opens of "." are a no-op continue; } @@ -272,7 +272,7 @@ Ext4Open ( =20 *NewHandle =3D &Current->Protocol; =20 - DEBUG ((DEBUG_FS, "Opened filename %s\n", Current->FileName)); + DEBUG ((DEBUG_FS, "[ext4] Opened filename %s\n", Current->Dentry->Name)); return EFI_SUCCESS; } =20 @@ -312,9 +312,9 @@ Ext4CloseInternal ( =20 DEBUG ((DEBUG_FS, "[ext4] Closed file %p (inode %lu)\n", File, File->Ino= deNum)); RemoveEntryList (&File->OpenFilesListNode); - FreePool (File->FileName); FreePool (File->Inode); Ext4FreeExtentsMap (File); + Ext4UnrefDentry (File->Dentry); FreePool (File); return EFI_SUCCESS; } @@ -522,11 +522,11 @@ Ext4GetFileInfo ( UINTN NeededLength; CONST CHAR16 *FileName; =20 - if (File->InodeNum =3D=3D 2) { + if (File->InodeNum =3D=3D EXT4_ROOT_INODE_NR) { // Root inode gets a filename of "", regardless of how it was opened. FileName =3D L""; } else { - FileName =3D File->FileName; + FileName =3D File->Dentry->Name; } =20 FileNameLen =3D StrLen (FileName); @@ -717,15 +717,6 @@ Ext4DuplicateFile ( =20 CopyMem (File->Inode, Original->Inode, Partition->InodeSize); =20 - File->FileName =3D AllocateZeroPool (StrSize (Original->FileName)); - if (File->FileName =3D=3D NULL) { - FreePool (File->Inode); - FreePool (File); - return NULL; - } - - StrCpyS (File->FileName, StrLen (Original->FileName) + 1, Original->File= Name); - File->Position =3D 0; Ext4SetupFile (File, Partition); File->InodeNum =3D Original->InodeNum; @@ -733,12 +724,15 @@ Ext4DuplicateFile ( =20 Status =3D Ext4InitExtentsMap (File); if (EFI_ERROR (Status)) { - FreePool (File->FileName); FreePool (File->Inode); FreePool (File); return NULL; } =20 + File->Dentry =3D Original->Dentry; + + Ext4RefDentry (File->Dentry); + InsertTailList (&Partition->OpenFiles, &File->OpenFilesListNode); =20 return File; diff --git a/Features/Ext4Pkg/Ext4Dxe/Inode.c b/Features/Ext4Pkg/Ext4Dxe/In= ode.c index 982b19c763..a2f8b4135f 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(%s, Offset %lu, Length %lu)\n", File-= >FileName, Offset, *Length)); + DEBUG ((DEBUG_FS, "[ext4] Ext4Read(%s, Offset %lu, Length %lu)\n", File-= >Dentry->Name, Offset, *Length)); EXT4_INODE *Inode; UINT64 InodeSize; UINT64 CurrentSeek; diff --git a/Features/Ext4Pkg/Ext4Dxe/Partition.c b/Features/Ext4Pkg/Ext4Dx= e/Partition.c index 2258bac76a..afa0392024 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Partition.c +++ b/Features/Ext4Pkg/Ext4Dxe/Partition.c @@ -108,6 +108,7 @@ Ext4UnmountAndFreePartition ( LIST_ENTRY *Entry; LIST_ENTRY *NextEntry; EXT4_FILE *File; + BOOLEAN DeletedRootDentry; =20 Partition->Unmounting =3D TRUE; Ext4CloseInternal (Partition->Root); @@ -118,6 +119,12 @@ Ext4UnmountAndFreePartition ( Ext4CloseInternal (File); } =20 + DeletedRootDentry =3D Ext4UnrefDentry (Partition->RootDentry); + + if (!DeletedRootDentry) { + DEBUG ((DEBUG_ERROR, "[ext4] Failed to delete root dentry - resource l= eak present.\n")); + } + FreePool (Partition->BlockGroups); FreePool (Partition); =20 diff --git a/Features/Ext4Pkg/Ext4Dxe/Superblock.c b/Features/Ext4Pkg/Ext4D= xe/Superblock.c index 8231831115..3efb047dc5 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Superblock.c +++ b/Features/Ext4Pkg/Ext4Dxe/Superblock.c @@ -6,6 +6,7 @@ **/ =20 #include "Ext4Dxe.h" +#include "Uefi/UefiBaseType.h" =20 STATIC CONST UINT32 gSupportedCompatFeat =3D EXT4_FEATURE_COMPAT_EXT_ATTR; =20 @@ -167,8 +168,11 @@ Ext4OpenSuperblock ( // accidentally opening an ext2/3/4 filesystem we don't understand, whic= h would be disasterous. =20 if (Partition->FeaturesIncompat & ~gSupportedIncompatFeat) { - DEBUG ((DEBUG_ERROR, "[ext4] Unsupported features %lx\n", - Partition->FeaturesIncompat & ~gSupportedIncompatFeat)); + DEBUG (( + DEBUG_ERROR, + "[ext4] Unsupported features %lx\n", + Partition->FeaturesIncompat & ~gSupportedIncompatFeat + )); return EFI_UNSUPPORTED; } =20 @@ -247,7 +251,7 @@ Ext4OpenSuperblock ( =20 Partition->BlockGroups =3D Ext4AllocAndReadBlocks (Partition, NrBlocks, = Partition->BlockSize =3D=3D 1024 ? 2 : 1); =20 - if (!Partition->BlockGroups) { + if (Partition->BlockGroups =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; } =20 @@ -255,13 +259,27 @@ Ext4OpenSuperblock ( Desc =3D Ext4GetBlockGroupDesc (Partition, Index); if (!Ext4VerifyBlockGroupDescChecksum (Partition, Desc, Index)) { DEBUG ((DEBUG_ERROR, "[ext4] Block group descriptor %u has an invali= d checksum\n", Index)); + FreePool (Partition->BlockGroups); return EFI_VOLUME_CORRUPTED; } } =20 + // RootDentry will serve as the basis of our directory entry tree. + Partition->RootDentry =3D Ext4CreateDentry (L"\\", NULL); + + if (Partition->RootDentry =3D=3D NULL) { + FreePool (Partition->BlockGroups); + return EFI_OUT_OF_RESOURCES; + } + // Note that the cast below is completely safe, because EXT4_FILE is a s= pecialisation of EFI_FILE_PROTOCOL Status =3D Ext4OpenVolume (&Partition->Interface, (EFI_FILE_PROTOCOL **)= &Partition->Root); =20 + if (EFI_ERROR (Status)) { + Ext4UnrefDentry (Partition->RootDentry); + FreePool (Partition->BlockGroups); + } + return Status; } =20 --=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 (#79594): https://edk2.groups.io/g/devel/message/79594 Mute This Topic: https://groups.io/mt/85007624/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-