TianoCore EDK2 master
Loading...
Searching...
No Matches
SimpleFsWrite.c
Go to the documentation of this file.
1
9#include "VirtioFsDxe.h"
10
12EFIAPI
13VirtioFsSimpleFileWrite (
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}
UINT64 UINTN
EFI_STATUS VirtioFsFuseWrite(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN UINT64 Offset, IN OUT UINT32 *Size, IN VOID *Data)
Definition: FuseWrite.c:54
#define MIN(a, b)
Definition: Base.h:1007
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112