VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/VirtioFsDxe/SimpleFsWrite.c@ 94264

Last change on this file since 94264 was 89983, checked in by vboxsync, 4 years ago

Devices/EFI: Merge edk-stable202105 and openssl 1.1.1j and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 2.0 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 if (!VirtioFsFile->IsOpenForWriting) {
32 return EFI_ACCESS_DENIED;
33 }
34
35 Status = EFI_SUCCESS;
36 Transferred = 0;
37 Left = *BufferSize;
38 while (Left > 0) {
39 UINT32 WriteSize;
40
41 //
42 // Honor the write buffer size limit.
43 //
44 WriteSize = (UINT32)MIN ((UINTN)VirtioFs->MaxWrite, Left);
45 Status = VirtioFsFuseWrite (
46 VirtioFs,
47 VirtioFsFile->NodeId,
48 VirtioFsFile->FuseHandle,
49 VirtioFsFile->FilePosition + Transferred,
50 &WriteSize,
51 (UINT8 *)Buffer + Transferred
52 );
53 if (!EFI_ERROR (Status) && WriteSize == 0) {
54 //
55 // Progress should have been made.
56 //
57 Status = EFI_DEVICE_ERROR;
58 }
59 if (EFI_ERROR (Status)) {
60 break;
61 }
62 Transferred += WriteSize;
63 Left -= WriteSize;
64 }
65
66 *BufferSize = Transferred;
67 VirtioFsFile->FilePosition += Transferred;
68 //
69 // According to the UEFI spec,
70 //
71 // - 'Partial writes only occur when there has been a data error during the
72 // write attempt (such as "file space full")', and
73 //
74 // - (as an example) EFI_VOLUME_FULL is returned when 'The volume is full'.
75 //
76 // These together imply that after a partial write, we have to return an
77 // error. In other words, (Transferred > 0) is inconsequential for the return
78 // value.
79 //
80 return Status;
81}
Note: See TracBrowser for help on using the repository browser.

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