From 7e8c83f7d4823009d1f37ec6a0fa2c4ef888c2d5 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Wed, 16 Dec 2020 22:10:54 +0100 Subject: OvmfPkg/VirtioFsDxe: manage path lifecycle in OpenVolume, Close, Delete MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a canonical pathname field to VIRTIO_FS_FILE. Initialize the new field in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(). Release the new field in EFI_FILE_PROTOCOL.Close() and EFI_FILE_PROTOCOL.Delete(). Cc: Ard Biesheuvel Cc: Jordan Justen Cc: Philippe Mathieu-Daudé Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Signed-off-by: Laszlo Ersek Message-Id: <20201216211125.19496-18-lersek@redhat.com> Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsClose.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsDelete.c | 1 + OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c | 13 ++++++++++++- OvmfPkg/VirtioFsDxe/VirtioFsDxe.h | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) (limited to 'OvmfPkg/VirtioFsDxe') diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c index bc91ad726b..04b4f2c382 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsClose.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsClose.c @@ -59,6 +59,7 @@ VirtioFsSimpleFileClose ( // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); + FreePool (VirtioFsFile->CanonicalPathname); FreePool (VirtioFsFile); return EFI_SUCCESS; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c index bbad64bf78..e2fc2d72df 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c @@ -63,6 +63,7 @@ VirtioFsSimpleFileDelete ( // RemoveEntryList (&VirtioFsFile->OpenFilesEntry); + FreePool (VirtioFsFile->CanonicalPathname); FreePool (VirtioFsFile); return Status; } diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c index 67d2deb6bd..9c0ab434c1 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c @@ -28,6 +28,7 @@ VirtioFsOpenVolume ( VIRTIO_FS *VirtioFs; VIRTIO_FS_FILE *VirtioFsFile; EFI_STATUS Status; + CHAR8 *CanonicalPathname; UINT64 RootDirHandle; VirtioFs = VIRTIO_FS_FROM_SIMPLE_FS (This); @@ -37,13 +38,19 @@ VirtioFsOpenVolume ( return EFI_OUT_OF_RESOURCES; } + CanonicalPathname = AllocateCopyPool (sizeof "/", "/"); + if (CanonicalPathname == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto FreeVirtioFsFile; + } + // // Open the root directory. // Status = VirtioFsFuseOpenDir (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID, &RootDirHandle); if (EFI_ERROR (Status)) { - goto FreeVirtioFsFile; + goto FreeCanonicalPathname; } // @@ -64,6 +71,7 @@ VirtioFsOpenVolume ( VirtioFsFile->IsDirectory = TRUE; VirtioFsFile->IsOpenForWriting = FALSE; VirtioFsFile->OwnerFs = VirtioFs; + VirtioFsFile->CanonicalPathname = CanonicalPathname; VirtioFsFile->NodeId = VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID; VirtioFsFile->FuseHandle = RootDirHandle; @@ -75,6 +83,9 @@ VirtioFsOpenVolume ( *Root = &VirtioFsFile->SimpleFile; return EFI_SUCCESS; +FreeCanonicalPathname: + FreePool (CanonicalPathname); + FreeVirtioFsFile: FreePool (VirtioFsFile); diff --git a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h index f4fed64c72..487d215c7f 100644 --- a/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h +++ b/OvmfPkg/VirtioFsDxe/VirtioFsDxe.h @@ -137,6 +137,7 @@ typedef struct { BOOLEAN IsOpenForWriting; VIRTIO_FS *OwnerFs; LIST_ENTRY OpenFilesEntry; + CHAR8 *CanonicalPathname; // // 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, by the -- cgit v1.2.3