VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c@ 109019

Last change on this file since 109019 was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1/** @file
2 EFI_FILE_PROTOCOL.Write() member function for the Virtio Filesystem driver.
3
4 Copyright (C) 2020, Red Hat, Inc.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7**/
8
9#include "VirtioFsDxe.h"
10
11EFI_STATUS
12EFIAPI
13VirtioFsSimpleFileWrite (
14 IN EFI_FILE_PROTOCOL *This,
15 IN OUT UINTN *BufferSize,
16 IN VOID *Buffer
17 )
18{
19 VIRTIO_FS_FILE *VirtioFsFile;
20 VIRTIO_FS *VirtioFs;
21 EFI_STATUS Status;
22 UINTN Transferred;
23 UINTN Left;
24
25 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
26 VirtioFs = VirtioFsFile->OwnerFs;
27
28 if (VirtioFsFile->IsDirectory) {
29 return EFI_UNSUPPORTED;
30 }
31
32 if (!VirtioFsFile->IsOpenForWriting) {
33 return EFI_ACCESS_DENIED;
34 }
35
36 Status = EFI_SUCCESS;
37 Transferred = 0;
38 Left = *BufferSize;
39 while (Left > 0) {
40 UINT32 WriteSize;
41
42 //
43 // Honor the write buffer size limit.
44 //
45 WriteSize = (UINT32)MIN ((UINTN)VirtioFs->MaxWrite, Left);
46 Status = VirtioFsFuseWrite (
47 VirtioFs,
48 VirtioFsFile->NodeId,
49 VirtioFsFile->FuseHandle,
50 VirtioFsFile->FilePosition + Transferred,
51 &WriteSize,
52 (UINT8 *)Buffer + Transferred
53 );
54 if (!EFI_ERROR (Status) && (WriteSize == 0)) {
55 //
56 // Progress should have been made.
57 //
58 Status = EFI_DEVICE_ERROR;
59 }
60
61 if (EFI_ERROR (Status)) {
62 break;
63 }
64
65 Transferred += WriteSize;
66 Left -= WriteSize;
67 }
68
69 *BufferSize = Transferred;
70 VirtioFsFile->FilePosition += Transferred;
71 //
72 // According to the UEFI spec,
73 //
74 // - 'Partial writes only occur when there has been a data error during the
75 // write attempt (such as "file space full")', and
76 //
77 // - (as an example) EFI_VOLUME_FULL is returned when 'The volume is full'.
78 //
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
81 // value.
82 //
83 return Status;
84}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette