Files
system76-edk2/OvmfPkg/VirtioFsDxe/SimpleFsSetPosition.c
Laszlo Ersek b845de89d0 OvmfPkg/VirtioFsDxe: add EFI_FILE_INFO cache fields to VIRTIO_FS_FILE
For reading through a directory stream with tolerable performance, we'll
have to call FUSE_READDIRPLUS each time with such a buffer that can
deliver a good number of variable size records
(VIRTIO_FS_FUSE_DIRENTPLUS_RESPONSE elements). Every time we'll do that,
we'll turn the whole bunch into an array of EFI_FILE_INFOs immediately.
EFI_FILE_PROTOCOL.Read() invocations (on directories) will be served from
this EFI_FILE_INFO cache.

Add the fields for the EFI_FILE_INFO cache to VIRTIO_FS_FILE:
- initialize them in Open() and OpenVolume(),
- release the cache in Close() and Delete(),
- also release the cache when the directory is rewound, in SetPosition().

Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3097
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20201216211125.19496-36-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
2020-12-21 17:16:23 +00:00

68 lines
1.6 KiB
C

/** @file
EFI_FILE_PROTOCOL.SetPosition() member function for the Virtio Filesystem
driver.
Copyright (C) 2020, Red Hat, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/MemoryAllocationLib.h> // FreePool()
#include "VirtioFsDxe.h"
EFI_STATUS
EFIAPI
VirtioFsSimpleFileSetPosition (
IN EFI_FILE_PROTOCOL *This,
IN UINT64 Position
)
{
VIRTIO_FS_FILE *VirtioFsFile;
VIRTIO_FS *VirtioFs;
EFI_STATUS Status;
VIRTIO_FS_FUSE_ATTRIBUTES_RESPONSE FuseAttr;
VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
//
// Directories can only be rewound, per spec.
//
if (VirtioFsFile->IsDirectory) {
if (Position != 0) {
return EFI_UNSUPPORTED;
}
VirtioFsFile->FilePosition = 0;
if (VirtioFsFile->FileInfoArray != NULL) {
FreePool (VirtioFsFile->FileInfoArray);
VirtioFsFile->FileInfoArray = NULL;
}
VirtioFsFile->SingleFileInfoSize = 0;
VirtioFsFile->NumFileInfo = 0;
VirtioFsFile->NextFileInfo = 0;
return EFI_SUCCESS;
}
//
// Regular file.
//
if (Position < MAX_UINT64) {
//
// Caller is requesting absolute file position.
//
VirtioFsFile->FilePosition = Position;
return EFI_SUCCESS;
}
//
// Caller is requesting a seek to EOF.
//
VirtioFs = VirtioFsFile->OwnerFs;
Status = VirtioFsFuseGetAttr (VirtioFs, VirtioFsFile->NodeId, &FuseAttr);
if (EFI_ERROR (Status)) {
return Status;
}
VirtioFsFile->FilePosition = FuseAttr.Size;
return EFI_SUCCESS;
}