summaryrefslogtreecommitdiffstats
path: root/OvmfPkg/VirtioFsDxe
diff options
context:
space:
mode:
authorLaszlo Ersek <lersek@redhat.com>2020-12-16 22:11:16 +0100
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2020-12-21 17:16:23 +0000
commit44f43f94cebec44c80ca5db6f16de165204cfff2 (patch)
tree454ba736b2511994496ffcd4e7c7b3ba057f9d9d /OvmfPkg/VirtioFsDxe
parent6f7bc7196ff2d7174fec382d66aa5dfea31a7026 (diff)
downloadedk2-44f43f94cebec44c80ca5db6f16de165204cfff2.tar.gz
edk2-44f43f94cebec44c80ca5db6f16de165204cfff2.tar.bz2
edk2-44f43f94cebec44c80ca5db6f16de165204cfff2.zip
OvmfPkg/VirtioFsDxe: implement EFI_FILE_PROTOCOL.Write()
Using the functions introduced previously, we can now implement VirtioFsSimpleFileWrite(). Cc: Ard Biesheuvel <ard.biesheuvel@arm.com> Cc: Jordan Justen <jordan.l.justen@intel.com> Cc: Philippe Mathieu-Daudé <philmd@redhat.com> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097 Signed-off-by: Laszlo Ersek <lersek@redhat.com> Message-Id: <20201216211125.19496-40-lersek@redhat.com> Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
Diffstat (limited to 'OvmfPkg/VirtioFsDxe')
-rw-r--r--OvmfPkg/VirtioFsDxe/SimpleFsWrite.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c b/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c
index 90d82bd722..8ae317c88e 100644
--- a/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c
+++ b/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c
@@ -16,5 +16,66 @@ VirtioFsSimpleFileWrite (
IN VOID *Buffer
)
{
- return EFI_NO_MEDIA;
+ VIRTIO_FS_FILE *VirtioFsFile;
+ VIRTIO_FS *VirtioFs;
+ EFI_STATUS Status;
+ UINTN Transferred;
+ UINTN Left;
+
+ VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
+ VirtioFs = VirtioFsFile->OwnerFs;
+
+ if (VirtioFsFile->IsDirectory) {
+ return EFI_UNSUPPORTED;
+ }
+ if (!VirtioFsFile->IsOpenForWriting) {
+ return EFI_ACCESS_DENIED;
+ }
+
+ Status = EFI_SUCCESS;
+ Transferred = 0;
+ Left = *BufferSize;
+ while (Left > 0) {
+ UINT32 WriteSize;
+
+ //
+ // Honor the write buffer size limit.
+ //
+ WriteSize = (UINT32)MIN ((UINTN)VirtioFs->MaxWrite, Left);
+ Status = VirtioFsFuseWrite (
+ VirtioFs,
+ VirtioFsFile->NodeId,
+ VirtioFsFile->FuseHandle,
+ VirtioFsFile->FilePosition + Transferred,
+ &WriteSize,
+ (UINT8 *)Buffer + Transferred
+ );
+ if (!EFI_ERROR (Status) && WriteSize == 0) {
+ //
+ // Progress should have been made.
+ //
+ Status = EFI_DEVICE_ERROR;
+ }
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+ Transferred += WriteSize;
+ Left -= WriteSize;
+ }
+
+ *BufferSize = Transferred;
+ VirtioFsFile->FilePosition += Transferred;
+ //
+ // According to the UEFI spec,
+ //
+ // - 'Partial writes only occur when there has been a data error during the
+ // write attempt (such as "file space full")', and
+ //
+ // - (as an example) EFI_VOLUME_FULL is returned when 'The volume is full'.
+ //
+ // These together imply that after a partial write, we have to return an
+ // error. In other words, (Transferred > 0) is inconsequential for the return
+ // value.
+ //
+ return Status;
}