From nobody Mon Feb 9 14:33:57 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+69025+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+69025+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608154491; cv=none; d=zohomail.com; s=zohoarc; b=Cv9sMZvbFr6DDzDrSHEmHalyKdQdfkqfHDeM/zs8aj9h83LTd5c2Gi0cKdF6Bu02VBgVVZVbsznFkWxFI4VP+EF4+L9j/MFz1hSdpfwI81V8MlZYrvyybSKAnSOaXn1vffv0EHMCxykk0x017L1+1R/GTESH9pObSlapfyv0XhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608154491; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=1bXBT5KqgiK5xrY6A8+f4CJNvrkPHsFCj39AKceOsak=; b=LkJLpNgCMcFLsYLZeK91mL0Fn4TmBq4QxVgq3phEyNI8akn33fCOQkbEjVgzx1+Hgms06QaJPylHtTR2gy056mGCnV4/Kzst5KqgroAcDIHMQyfo2EwMwN45GH81LOttOj24k3ucRWKCMo+VQFPwZNTf37OACdSvasL532Udmd8= 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+69025+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1608154491595882.3816324608936; Wed, 16 Dec 2020 13:34:51 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id 5k5QYY1788612x7WmH2Cc5Hy; Wed, 16 Dec 2020 13:34:50 -0800 X-Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.groups.io with SMTP id smtpd.web12.3899.1608154485034633403 for ; Wed, 16 Dec 2020 13:34:45 -0800 X-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-397-Hm_DG1HaNv6t5phAjwv-Pg-1; Wed, 16 Dec 2020 16:34:41 -0500 X-MC-Unique: Hm_DG1HaNv6t5phAjwv-Pg-1 X-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5D771801817; Wed, 16 Dec 2020 21:34:40 +0000 (UTC) X-Received: from lacos-laptop-7.usersys.redhat.com (ovpn-114-152.ams2.redhat.com [10.36.114.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE04E106D5A4; Wed, 16 Dec 2020 21:34:34 +0000 (UTC) From: "Laszlo Ersek" To: devel@edk2.groups.io, virtio-fs@redhat.com, lersek@redhat.com Cc: Ard Biesheuvel , Jordan Justen , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [edk2-devel] [edk2 PATCH 11/48] OvmfPkg/VirtioFsDxe: implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() Date: Wed, 16 Dec 2020 22:10:48 +0100 Message-Id: <20201216211125.19496-12-lersek@redhat.com> In-Reply-To: <20201216211125.19496-1-lersek@redhat.com> References: <20201216211125.19496-1-lersek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Precedence: Bulk List-Unsubscribe: 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,lersek@redhat.com X-Gm-Message-State: AvXHdODNoFTrNNYNpVGWSJmlx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1608154490; bh=1bXBT5KqgiK5xrY6A8+f4CJNvrkPHsFCj39AKceOsak=; h=Cc:Content-Type:Date:From:Reply-To:Subject:To; b=xKaFyUb8xo+DtE5GB/pbo3+06M0bCYG075v4E+t8w2QepqpdThL3WkjWjskpGj8JnVU MIwZ75QXnx/+19P92pSkzyH6HstA++39GyOB0X0m8ScKsembSzFSs06pNXc1iRZX/vwRR gvbCFv2OwT6Wb1YN7AJuhBirVDRxdpUizAI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" With the help of the VirtioFsFuseOpenDir() and VirtioFsFuseReleaseFileOrDir() functions introduced previously, we can now open and close the root directory. So let's implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). OpenVolume() creates a new EFI_FILE_PROTOCOL object -- a reference to the root directory of the filesystem. Thus, we have to start tracking references to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, lest we unbind the virtio-fs device while files are open. There are two methods that release an EFI_FILE_PROTOCOL object: the Close() and the Delete() member functions. In particular, they are not allowed to fail with regard to resource management -- they must release resources unconditionally. Thus, for rolling back the resource accounting that we do in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(), we have to implement the first versions of EFI_FILE_PROTOCOL.Close() and EFI_FILE_PROTOCOL.Delete() in this patch as well. With this patch applied, the UEFI shell can enter the root directory of the Virtio Filesystem (such as with the "FS3:" shell command), and the "DIR" shell command exercises FUSE_OPENDIR and FUSE_RELEASEDIR, according to the virtiofsd log. The "DIR" command reports the root directory as if it were empty; probably because at this time, we only allow the shell to open and to close the root directory, but not to read it. Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daud=C3=A9 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3097 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/IndustryStandard/VirtioFs.h | 5 + OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf | 10 ++ OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 117 ++++++++++++++++++++ OvmfPkg/VirtioFsDxe/DriverBinding.c | 5 + OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 48 ++++++++ OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 29 +++++ OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 18 +++ OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c | 21 ++++ OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpen.c | 22 ++++ OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 57 +++++++++- OvmfPkg/VirtioFsDxe/SimpleFsRead.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c | 21 ++++ OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c | 20 ++++ OvmfPkg/VirtioFsDxe/SimpleFsWrite.c | 20 ++++ 15 files changed, 432 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/Include/IndustryStandard/VirtioFs.h b/OvmfPkg/Include/= IndustryStandard/VirtioFs.h index c17a43c160e3..67fcf975e8b2 100644 --- a/OvmfPkg/Include/IndustryStandard/VirtioFs.h +++ b/OvmfPkg/Include/IndustryStandard/VirtioFs.h @@ -71,16 +71,21 @@ typedef struct { // out at commit (c6ff213fe5b8^) =3D d78092e4937d ("fuse: fix page derefer= ence // after free", 2020-09-18); that is, right before commit c6ff213fe5b8 ("f= use: // add submount support to ", 2020-09-18) introduces FU= SE // interface version 7.32. // #define VIRTIO_FS_FUSE_MAJOR 7 #define VIRTIO_FS_FUSE_MINOR 31 =20 +// +// The inode number of the root directory. +// +#define VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID 1 + // // FUSE operation codes. // typedef enum { VirtioFsFuseOpRelease =3D 18, VirtioFsFuseOpInit =3D 26, VirtioFsFuseOpOpenDir =3D 27, VirtioFsFuseOpReleaseDir =3D 29, diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf b/OvmfPkg/VirtioFsDxe/Virt= ioFsDxe.inf index 95b1a5a8f60a..28e66082ecfe 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.inf @@ -81,17 +81,27 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [Sources] DriverBinding.c FuseInit.c FuseOpenDir.c FuseRelease.c Helpers.c + SimpleFsClose.c + SimpleFsDelete.c + SimpleFsFlush.c + SimpleFsGetInfo.c + SimpleFsGetPosition.c + SimpleFsOpen.c SimpleFsOpenVolume.c + SimpleFsRead.c + SimpleFsSetInfo.c + SimpleFsSetPosition.c + SimpleFsWrite.c VirtioFsDxe.h =20 [LibraryClasses] BaseLib DebugLib MemoryAllocationLib UefiBootServicesTableLib UefiDriverEntryPoint diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/Virtio= FsDxe.h index a99625d0473a..34574d0596fc 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -14,16 +14,19 @@ #include // VIRTIO_FS_TAG_BYTES #include // CR() #include // EFI_SIMPLE_FILE_SYSTEM_PROTOCOL #include // VIRTIO_DEVICE_PROTOCOL #include // EFI_EVENT =20 #define VIRTIO_FS_SIG SIGNATURE_64 ('V', 'I', 'R', 'T', 'I', 'O', 'F', 'S') =20 +#define VIRTIO_FS_FILE_SIG \ + SIGNATURE_64 ('V', 'I', 'O', 'F', 'S', 'F', 'I', 'L') + // // Filesystem label encoded in UCS-2, transformed from the UTF-8 represent= ation // in "VIRTIO_FS_CONFIG.Tag", and NUL-terminated. Only the printable ASCII= code // points (U+0020 through U+007E) are supported. // typedef CHAR16 VIRTIO_FS_LABEL[VIRTIO_FS_TAG_BYTES + 1]; =20 // @@ -41,16 +44,17 @@ typedef struct { UINT64 Signature; // DriverBindingStart 0 VIRTIO_DEVICE_PROTOCOL *Virtio; // DriverBindingStart 0 VIRTIO_FS_LABEL Label; // VirtioFsInit 1 UINT16 QueueSize; // VirtioFsInit 1 VRING Ring; // VirtioRingInit 2 VOID *RingMap; // VirtioRingMap 2 UINT64 RequestId; // FuseInitSession 1 EFI_EVENT ExitBoot; // DriverBindingStart 0 + LIST_ENTRY OpenFiles; // DriverBindingStart 0 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL SimpleFs; // DriverBindingStart 0 } VIRTIO_FS; =20 #define VIRTIO_FS_FROM_SIMPLE_FS(SimpleFsReference) \ CR (SimpleFsReference, VIRTIO_FS, SimpleFs, VIRTIO_FS_SIG); =20 // // Structure for describing a contiguous buffer, potentially mapped for Vi= rtio @@ -93,16 +97,49 @@ typedef struct { UINTN NumVec; // // TotalSize is calculated when the scatter-gather list is initially // validated. // UINT32 TotalSize; } VIRTIO_FS_SCATTER_GATHER_LIST; =20 +// +// Private context structure that exposes EFI_FILE_PROTOCOL on top of an o= pen +// FUSE file reference. +// +typedef struct { + UINT64 Signature; + EFI_FILE_PROTOCOL SimpleFile; + BOOLEAN IsDirectory; + VIRTIO_FS *OwnerFs; + LIST_ENTRY OpenFilesEntry; + // + // In the FUSE wire protocol, every request except FUSE_INIT refers to a + // file, namely by the "VIRTIO_FS_FUSE_REQUEST.NodeId" field; that is, b= y the + // inode number of the file. However, some of the FUSE requests that we = need + // for some of the EFI_FILE_PROTOCOL member functions require an open fi= le + // handle *in addition* to the inode number. For simplicity, whenever a + // VIRTIO_FS_FILE object is created, primarily defined by its NodeId fie= ld, + // we also *open* the referenced file at once, and save the returned file + // handle in the FuseHandle field. This way, when an EFI_FILE_PROTOCOL m= ember + // function must send a FUSE request that needs the file handle *in addi= tion* + // to the inode number, FuseHandle will be at our disposal at once. + // + UINT64 NodeId; + UINT64 FuseHandle; +} VIRTIO_FS_FILE; + +#define VIRTIO_FS_FILE_FROM_SIMPLE_FILE(SimpleFileReference) \ + CR (SimpleFileReference, VIRTIO_FS_FILE, SimpleFile, VIRTIO_FS_FILE_SIG); + +#define VIRTIO_FS_FILE_FROM_OPEN_FILES_ENTRY(OpenFilesEntryReference) \ + CR (OpenFilesEntryReference, VIRTIO_FS_FILE, OpenFilesEntry, \ + VIRTIO_FS_FILE_SIG); + // // Initialization and helper routines for the Virtio Filesystem device. // =20 EFI_STATUS VirtioFsInit ( IN OUT VIRTIO_FS *VirtioFs ); @@ -185,9 +222,89 @@ VirtioFsFuseOpenDir ( =20 EFI_STATUS EFIAPI VirtioFsOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root ); =20 +// +// EFI_FILE_PROTOCOL member functions for the Virtio Filesystem driver. +// + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileClose ( + IN EFI_FILE_PROTOCOL *This + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileDelete ( + IN EFI_FILE_PROTOCOL *This + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileFlush ( + IN EFI_FILE_PROTOCOL *This + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetPosition ( + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileRead ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN UINTN BufferSize, + IN VOID *Buffer + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetPosition ( + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position + ); + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileWrite ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer + ); + #endif // VIRTIO_FS_DXE_H_ diff --git a/OvmfPkg/VirtioFsDxe/DriverBinding.c b/OvmfPkg/VirtioFsDxe/Driv= erBinding.c index 4f77ffaa9953..e273c9f362eb 100644 --- a/OvmfPkg/VirtioFsDxe/DriverBinding.c +++ b/OvmfPkg/VirtioFsDxe/DriverBinding.c @@ -90,16 +90,17 @@ VirtioFsBindingStart ( } =20 Status =3D gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_CALLBACK, VirtioFsExitBoot, VirtioFs, &VirtioFs->ExitBoot); if (EFI_ERROR (Status)) { goto UninitVirtioFs; } =20 + InitializeListHead (&VirtioFs->OpenFiles); VirtioFs->SimpleFs.Revision =3D EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISI= ON; VirtioFs->SimpleFs.OpenVolume =3D VirtioFsOpenVolume; =20 Status =3D gBS->InstallProtocolInterface (&ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, EFI_NATIVE_INTERFACE, &VirtioFs->SimpleFs); if (EFI_ERROR (Status)) { goto CloseExitBoot; @@ -144,16 +145,20 @@ VirtioFsBindingStop ( This->DriverBindingHandle, ControllerHandle, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (EFI_ERROR (Status)) { return Status; } =20 VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (SimpleFs); =20 + if (!IsListEmpty (&VirtioFs->OpenFiles)) { + return EFI_ACCESS_DENIED; + } + Status =3D gBS->UninstallProtocolInterface (ControllerHandle, &gEfiSimpleFileSystemProtocolGuid, SimpleFs); if (EFI_ERROR (Status)) { return Status; } =20 Status =3D gBS->CloseEvent (VirtioFs->ExitBoot); ASSERT_EFI_ERROR (Status); diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c b/OvmfPkg/VirtioFsDxe/Simp= leFsClose.c new file mode 100644 index 000000000000..01bbeae21473 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c @@ -0,0 +1,48 @@ +/** @file + EFI_FILE_PROTOCOL.Close() member function for the Virtio Filesystem driv= er. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include // RemoveEntryList() +#include // FreePool() + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileClose ( + IN EFI_FILE_PROTOCOL *This + ) +{ + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + + VirtioFsFile =3D VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs =3D VirtioFsFile->OwnerFs; + + // + // At this point, the implementation is only suitable for closing the + // VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). + // + ASSERT (VirtioFsFile->IsDirectory); + ASSERT (VirtioFsFile->NodeId =3D=3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID); + // + // Close the root directory. + // + // Ignore any errors, because EFI_FILE_PROTOCOL.Close() is required to + // release the EFI_FILE_PROTOCOL object unconditionally. + // + VirtioFsFuseReleaseFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + + // + // One fewer file left open for the owner filesystem. + // + RemoveEntryList (&VirtioFsFile->OpenFilesEntry); + + FreePool (VirtioFsFile); + return EFI_SUCCESS; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/Sim= pleFsDelete.c new file mode 100644 index 000000000000..3209923d1e49 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -0,0 +1,29 @@ +/** @file + EFI_FILE_PROTOCOL.Delete() member function for the Virtio Filesystem dri= ver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileDelete ( + IN EFI_FILE_PROTOCOL *This + ) +{ + // + // At this point, the implementation is only suitable for closing the + // VIRTIO_FS_FILE that was created by VirtioFsOpenVolume(). + // + // Actually deleting the root directory is not possible, so we're only g= oing + // to release resources, and return EFI_WARN_DELETE_FAILURE. + // + // In order to release resources, VirtioFsSimpleFileClose() is just right + // here. + // + VirtioFsSimpleFileClose (This); + return EFI_WARN_DELETE_FAILURE; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c b/OvmfPkg/VirtioFsDxe/Simp= leFsFlush.c new file mode 100644 index 000000000000..e48d92140f64 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c @@ -0,0 +1,18 @@ +/** @file + EFI_FILE_PROTOCOL.Flush() member function for the Virtio Filesystem driv= er. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileFlush ( + IN EFI_FILE_PROTOCOL *This + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsGetInfo.c new file mode 100644 index 000000000000..6e870460c014 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsGetInfo.c @@ -0,0 +1,21 @@ +/** @file + EFI_FILE_PROTOCOL.GetInfo() member function for the Virtio Filesystem dr= iver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsGetPosition.c new file mode 100644 index 000000000000..2f40d2be2693 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsGetPosition.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.GetPosition() member function for the Virtio Filesystem + driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileGetPosition ( + IN EFI_FILE_PROTOCOL *This, + OUT UINT64 *Position + ) +{ + return EFI_DEVICE_ERROR; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsOpen.c new file mode 100644 index 000000000000..f0e249184079 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpen.c @@ -0,0 +1,22 @@ +/** @file + EFI_FILE_PROTOCOL.Open() member function for the Virtio Filesystem drive= r. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileOpen ( + IN EFI_FILE_PROTOCOL *This, + OUT EFI_FILE_PROTOCOL **NewHandle, + IN CHAR16 *FileName, + IN UINT64 OpenMode, + IN UINT64 Attributes + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe= /SimpleFsOpenVolume.c index a5a66a27d84c..8c1457a68aad 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -2,25 +2,80 @@ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Vir= tio Filesystem driver. =20 Copyright (C) 2020, Red Hat, Inc. =20 SPDX-License-Identifier: BSD-2-Clause-Patent **/ =20 +#include // InsertTailList() +#include // AllocatePool() + #include "VirtioFsDxe.h" =20 /** Open the root directory on the Virtio Filesystem. =20 Refer to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME for the interface contract. **/ EFI_STATUS EFIAPI VirtioFsOpenVolume ( IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **Root ) { - return EFI_NO_MEDIA; + VIRTIO_FS *VirtioFs; + VIRTIO_FS_FILE *VirtioFsFile; + EFI_STATUS Status; + UINT64 RootDirHandle; + + VirtioFs =3D VIRTIO_FS_FROM_SIMPLE_FS (This); + + VirtioFsFile =3D AllocatePool (sizeof *VirtioFsFile); + if (VirtioFsFile =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + // + // Open the root directory. + // + Status =3D VirtioFsFuseOpenDir (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE_I= D, + &RootDirHandle); + if (EFI_ERROR (Status)) { + goto FreeVirtioFsFile; + } + + // + // Populate the new VIRTIO_FS_FILE object. + // + VirtioFsFile->Signature =3D VIRTIO_FS_FILE_SIG; + VirtioFsFile->SimpleFile.Revision =3D EFI_FILE_PROTOCOL_REVISION; + VirtioFsFile->SimpleFile.Open =3D VirtioFsSimpleFileOpen; + VirtioFsFile->SimpleFile.Close =3D VirtioFsSimpleFileClose; + VirtioFsFile->SimpleFile.Delete =3D VirtioFsSimpleFileDelete; + VirtioFsFile->SimpleFile.Read =3D VirtioFsSimpleFileRead; + VirtioFsFile->SimpleFile.Write =3D VirtioFsSimpleFileWrite; + VirtioFsFile->SimpleFile.GetPosition =3D VirtioFsSimpleFileGetPosition; + VirtioFsFile->SimpleFile.SetPosition =3D VirtioFsSimpleFileSetPosition; + VirtioFsFile->SimpleFile.GetInfo =3D VirtioFsSimpleFileGetInfo; + VirtioFsFile->SimpleFile.SetInfo =3D VirtioFsSimpleFileSetInfo; + VirtioFsFile->SimpleFile.Flush =3D VirtioFsSimpleFileFlush; + VirtioFsFile->IsDirectory =3D TRUE; + VirtioFsFile->OwnerFs =3D VirtioFs; + VirtioFsFile->NodeId =3D VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; + VirtioFsFile->FuseHandle =3D RootDirHandle; + + // + // One more file open for the filesystem. + // + InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry); + + *Root =3D &VirtioFsFile->SimpleFile; + return EFI_SUCCESS; + +FreeVirtioFsFile: + FreePool (VirtioFsFile); + + return Status; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsRead.c b/OvmfPkg/VirtioFsDxe/Simpl= eFsRead.c new file mode 100644 index 000000000000..e737d5e33204 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsRead.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.Read() member function for the Virtio Filesystem drive= r. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileRead ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + OUT VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c b/OvmfPkg/VirtioFsDxe/Si= mpleFsSetInfo.c new file mode 100644 index 000000000000..200b7a1bcd20 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetInfo.c @@ -0,0 +1,21 @@ +/** @file + EFI_FILE_PROTOCOL.SetInfo() member function for the Virtio Filesystem dr= iver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetInfo ( + IN EFI_FILE_PROTOCOL *This, + IN EFI_GUID *InformationType, + IN UINTN BufferSize, + IN VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c b/OvmfPkg/VirtioFsDx= e/SimpleFsSetPosition.c new file mode 100644 index 000000000000..ee8cb1f4e465 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem + driver. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileSetPosition ( + IN EFI_FILE_PROTOCOL *This, + IN UINT64 Position + ) +{ + return EFI_DEVICE_ERROR; +} diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c b/OvmfPkg/VirtioFsDxe/Simp= leFsWrite.c new file mode 100644 index 000000000000..90d82bd722b1 --- /dev/null +++ b/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c @@ -0,0 +1,20 @@ +/** @file + EFI_FILE_PROTOCOL.Write() member function for the Virtio Filesystem driv= er. + + Copyright (C) 2020, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include "VirtioFsDxe.h" + +EFI_STATUS +EFIAPI +VirtioFsSimpleFileWrite ( + IN EFI_FILE_PROTOCOL *This, + IN OUT UINTN *BufferSize, + IN VOID *Buffer + ) +{ + return EFI_NO_MEDIA; +} --=20 2.19.1.3.g30247aa5d201 -=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 (#69025): https://edk2.groups.io/g/devel/message/69025 Mute This Topic: https://groups.io/mt/79022983/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-