2 EFI_FILE_PROTOCOL.Read() 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"
12 Read from a regular file.
17 IN OUT VIRTIO_FS_FILE
*VirtioFsFile
,
18 IN OUT UINTN
*BufferSize
,
24 VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr
;
28 VirtioFs
= VirtioFsFile
->OwnerFs
;
30 // The UEFI spec forbids reads that start beyond the end of the file.
32 Status
= VirtioFsFuseGetAttr (VirtioFs
, VirtioFsFile
->NodeId
, &FuseAttr
);
33 if (EFI_ERROR (Status
) || VirtioFsFile
->FilePosition
> FuseAttr
.Size
) {
34 return EFI_DEVICE_ERROR
;
44 // FUSE_READ cannot express a >=4GB buffer size.
46 ReadSize
= (UINT32
)MIN ((UINTN
)MAX_UINT32
, Left
);
47 Status
= VirtioFsFuseReadFileOrDir (
50 VirtioFsFile
->FuseHandle
,
52 VirtioFsFile
->FilePosition
+ Transferred
,
54 (UINT8
*)Buffer
+ Transferred
56 if (EFI_ERROR (Status
) || ReadSize
== 0) {
59 Transferred
+= ReadSize
;
63 *BufferSize
= Transferred
;
64 VirtioFsFile
->FilePosition
+= Transferred
;
66 // If we managed to read some data, return success. If zero bytes were
67 // transferred due to zero-sized buffer on input or due to EOF on first read,
68 // return SUCCESS. Otherwise, return the error due to which zero bytes were
71 return (Transferred
> 0) ? EFI_SUCCESS
: Status
;
76 VirtioFsSimpleFileRead (
77 IN EFI_FILE_PROTOCOL
*This
,
78 IN OUT UINTN
*BufferSize
,
82 VIRTIO_FS_FILE
*VirtioFsFile
;
85 VirtioFsFile
= VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This
);
87 if (VirtioFsFile
->IsDirectory
) {
88 Status
= EFI_NO_MEDIA
;
90 Status
= ReadRegularFile (VirtioFsFile
, BufferSize
, Buffer
);