]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/VirtioFsDxe/SimpleFsWrite.c
2 EFI_FILE_PROTOCOL.Write() member function for the Virtio Filesystem driver.
4 Copyright (C) 2020, Red Hat, Inc.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "VirtioFsDxe.h"
13 VirtioFsSimpleFileWrite (
14 IN EFI_FILE_PROTOCOL
*This
,
15 IN OUT UINTN
*BufferSize
,
19 VIRTIO_FS_FILE
*VirtioFsFile
;
25 VirtioFsFile
= VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This
);
26 VirtioFs
= VirtioFsFile
->OwnerFs
;
28 if (VirtioFsFile
->IsDirectory
) {
29 return EFI_UNSUPPORTED
;
32 if (!VirtioFsFile
->IsOpenForWriting
) {
33 return EFI_ACCESS_DENIED
;
43 // Honor the write buffer size limit.
45 WriteSize
= (UINT32
)MIN ((UINTN
)VirtioFs
->MaxWrite
, Left
);
46 Status
= VirtioFsFuseWrite (
49 VirtioFsFile
->FuseHandle
,
50 VirtioFsFile
->FilePosition
+ Transferred
,
52 (UINT8
*)Buffer
+ Transferred
54 if (!EFI_ERROR (Status
) && (WriteSize
== 0)) {
56 // Progress should have been made.
58 Status
= EFI_DEVICE_ERROR
;
61 if (EFI_ERROR (Status
)) {
65 Transferred
+= WriteSize
;
69 *BufferSize
= Transferred
;
70 VirtioFsFile
->FilePosition
+= Transferred
;
72 // According to the UEFI spec,
74 // - 'Partial writes only occur when there has been a data error during the
75 // write attempt (such as "file space full")', and
77 // - (as an example) EFI_VOLUME_FULL is returned when 'The volume is full'.
79 // These together imply that after a partial write, we have to return an
80 // error. In other words, (Transferred > 0) is inconsequential for the return