From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) by mx.groups.io with SMTP id smtpd.web12.8124.1662559353599798596 for ; Wed, 07 Sep 2022 07:02:33 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AIWzR9pz; spf=pass (domain: gmail.com, ip: 209.85.208.179, mailfrom: savvamtr@gmail.com) Received: by mail-lj1-f179.google.com with SMTP id by6so16063906ljb.11 for ; Wed, 07 Sep 2022 07:02:33 -0700 (PDT) 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; bh=7zuIt70KNwRmJJ+0CY+0OjOn/+KL5nQ0kv6HCDWGmiw=; b=AIWzR9pz4oJWux9ZQinwO7Zfbrg1pbvsrJv5gISA0aQ1VLLdUf+X+Woj11kfE/N0Nh zLPbWmjYKODNN056gsOUrqcQDYsk03WX9wbPN8dZXG4p2Jskm1Gw1vAKYeKBGTivC2W6 lgIii8W2HrwKykxbrmT2hra4tQlkxcn/t90SjnCPY3wqKfTX11evTsUNkuD6efunkEsO 7TOC7fN331bHhacWXpFVZve+JDKNkbzV4gw+j4Ie5zZAzrZyBzQl3JCKit4mZhhYMkGo Yc5l3iUJK7Evyokx1kHDDrnl6iw7PdAKyGTt9f4zn811KhXNqudIUuSgeHH2Tk2tWRdh SSng== 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; bh=7zuIt70KNwRmJJ+0CY+0OjOn/+KL5nQ0kv6HCDWGmiw=; b=AbA2V00Nht0BAX0zdaPFq49gkiVq16WSY3m0KuZf83KBMrU3OE4RbUGmMtR4m8R3Nk T+3Ya9pFoutvxy+gceWlPxMo5yI8Dja4tQXZp4W6oGrC9oNIviz931F9Hhpmq9rWPm6x kIvMPzbKADhtvJN8ki7O4t4DhAplvR5zFyxovfPFObAPJAzEePxoS1KF0Sj+EV1w2Poq SEXml0EQ2QoyiA9LjsPylUMeka2BXqTKG5aNUyPIRqdHm4de4XzOzgvKGNo5Mu0W6HPC EPcTobYKRwAbZtVIfIm9VQ17FuxSiATQnlv96MLD8IfbLDVCnfDgDGr4N+ZSY264Z/UQ XvJw== X-Gm-Message-State: ACgBeo3ozwzCorNMeB8UMDCuF0ZW+cqkcvo43vFe44ZEOE9dbdAN8LDK c8h6b5vKyKLIkZAb8NgFwPupLA+0UQU= X-Google-Smtp-Source: AA6agR7qZSHKTnAe3HN8rgd+2KF+KZ5qAS1UOKVUrEfi5or2VqZwihGsHbDDtjMESPdx/VAioOzZ4w== X-Received: by 2002:a2e:a448:0:b0:262:f7c4:31ad with SMTP id v8-20020a2ea448000000b00262f7c431admr1035408ljn.283.1662559351658; Wed, 07 Sep 2022 07:02:31 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([176.59.149.223]) by smtp.gmail.com with ESMTPSA id o12-20020ac24e8c000000b0049482979fe0sm2506399lfr.179.2022.09.07.07.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Sep 2022 07:02:31 -0700 (PDT) From: "Savva Mitrofanov" To: devel@edk2.groups.io Cc: =?UTF-8?q?Marvin=20H=C3=A4user?= , Pedro Falcato , Vitaly Cheptsov Subject: [edk2-platforms][PATCH v5 2/2] Ext4Pkg: Add base containing record macro for EXT4_FILE Date: Wed, 7 Sep 2022 20:02:13 +0600 Message-Id: <20220907140213.13286-3-savvamtr@gmail.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220907140213.13286-1-savvamtr@gmail.com> References: <20220907140213.13286-1-savvamtr@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable We shouldn't use direct casts, because in the future it could break the code, so using BASE_CR would be safe against possible structure changes and rearrangements Cc: Marvin H=C3=A4user Cc: Pedro Falcato Cc: Vitaly Cheptsov Signed-off-by: Savva Mitrofanov Reviewed-by: Marvin H=C3=A4user --- Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h | 2 ++ Features/Ext4Pkg/Ext4Dxe/File.c | 16 ++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h b/Features/Ext4Pkg/Ext4Dxe/= Ext4Dxe.h index 6d352d3995f1..adf3c13f6ea9 100644 --- a/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h +++ b/Features/Ext4Pkg/Ext4Dxe/Ext4Dxe.h @@ -386,6 +386,8 @@ struct _Ext4File { EXT4_DENTRY *Dentry;=0D };=0D =0D +#define EXT4_FILE_FROM_THIS(This) BASE_CR ((This), EXT4_FILE, Protocol)=0D +=0D #define EXT4_FILE_FROM_OPEN_FILES_NODE(Node) = \=0D BASE_CR(Node, EXT4_FILE, OpenFilesListNode)=0D =0D diff --git a/Features/Ext4Pkg/Ext4Dxe/File.c b/Features/Ext4Pkg/Ext4Dxe/Fil= e.c index 86ccfff8603a..04198a53bfc0 100644 --- a/Features/Ext4Pkg/Ext4Dxe/File.c +++ b/Features/Ext4Pkg/Ext4Dxe/File.c @@ -372,7 +372,7 @@ Ext4Open ( EXT4_FILE *FoundFile;=0D EXT4_FILE *Source;=0D =0D - Source =3D (EXT4_FILE *)This;=0D + Source =3D EXT4_FILE_FROM_THIS (This);=0D =0D //=0D // Reset SymLoops counter=0D @@ -409,7 +409,7 @@ Ext4Close ( IN EFI_FILE_PROTOCOL *This=0D )=0D {=0D - return Ext4CloseInternal ((EXT4_FILE *)This);=0D + return Ext4CloseInternal (EXT4_FILE_FROM_THIS (This));=0D }=0D =0D /**=0D @@ -490,7 +490,7 @@ Ext4ReadFile ( EXT4_PARTITION *Partition;=0D EFI_STATUS Status;=0D =0D - File =3D (EXT4_FILE *)This;=0D + File =3D EXT4_FILE_FROM_THIS (This);=0D Partition =3D File->Partition;=0D =0D ASSERT (Ext4FileIsOpenable (File));=0D @@ -541,7 +541,7 @@ Ext4WriteFile ( {=0D EXT4_FILE *File;=0D =0D - File =3D (EXT4_FILE *)This;=0D + File =3D EXT4_FILE_FROM_THIS (This);=0D =0D if (!(File->OpenMode & EFI_FILE_MODE_WRITE)) {=0D return EFI_ACCESS_DENIED;=0D @@ -571,7 +571,7 @@ Ext4GetPosition ( {=0D EXT4_FILE *File;=0D =0D - File =3D (EXT4_FILE *)This;=0D + File =3D EXT4_FILE_FROM_THIS (This);=0D =0D if (Ext4FileIsDir (File)) {=0D return EFI_UNSUPPORTED;=0D @@ -604,7 +604,7 @@ Ext4SetPosition ( {=0D EXT4_FILE *File;=0D =0D - File =3D (EXT4_FILE *)This;=0D + File =3D EXT4_FILE_FROM_THIS (This);=0D =0D // Only seeks to 0 (so it resets the ReadDir operation) are allowed=0D if (Ext4FileIsDir (File) && (Position !=3D 0)) {=0D @@ -872,7 +872,7 @@ Ext4GetInfo ( EXT4_FILE *File;=0D EXT4_PARTITION *Partition;=0D =0D - File =3D (EXT4_FILE *)This;=0D + File =3D EXT4_FILE_FROM_THIS (This);=0D Partition =3D File->Partition;=0D =0D if (CompareGuid (InformationType, &gEfiFileInfoGuid)) {=0D @@ -989,7 +989,7 @@ Ext4SetInfo ( EXT4_FILE *File;=0D EXT4_PARTITION *Partition;=0D =0D - File =3D (EXT4_FILE *)This;=0D + File =3D EXT4_FILE_FROM_THIS (This);=0D Partition =3D File->Partition;=0D =0D if (Partition->ReadOnly) {=0D --=20 2.37.3