From 867cb9f60caf35d44600b6bdc3dc5252b83de9a1 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Wed, 16 Dec 2020 22:11:14 +0100 Subject: [PATCH] OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Flush() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For directories, implement EFI_FILE_PROTOCOL.Flush() by sending the FUSE_FSYNCDIR command to the Virtio Filesystem device. For regular files, send FUSE_FLUSH, followed by FUSE_FSYNC. 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-38-lersek@redhat.com> Acked-by: Ard Biesheuvel --- OvmfPkg/VirtioFsDxe/SimpleFsFlush.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c b/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c index e48d92140f..ba4a611e5a 100644 --- a/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c +++ b/OvmfPkg/VirtioFsDxe/SimpleFsFlush.c @@ -14,5 +14,29 @@ VirtioFsSimpleFileFlush ( IN EFI_FILE_PROTOCOL *This ) { - return EFI_NO_MEDIA; + VIRTIO_FS_FILE *VirtioFsFile; + VIRTIO_FS *VirtioFs; + EFI_STATUS Status; + + VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This); + VirtioFs = VirtioFsFile->OwnerFs; + + if (!VirtioFsFile->IsOpenForWriting) { + return EFI_ACCESS_DENIED; + } + + // + // FUSE_FLUSH is for regular files only. + // + if (!VirtioFsFile->IsDirectory) { + Status = VirtioFsFuseFlush (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle); + if (EFI_ERROR (Status)) { + return Status; + } + } + + Status = VirtioFsFuseFsyncFileOrDir (VirtioFs, VirtioFsFile->NodeId, + VirtioFsFile->FuseHandle, VirtioFsFile->IsDirectory); + return Status; }