Files
system76-edk2/OvmfPkg/VirtioFsDxe/SimpleFsOpenVolume.c
Laszlo Ersek 334c13e106 OvmfPkg/VirtioFsDxe: implement EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume()
With the help of the VirtioFsFuseOpenDir() and
VirtioFsFuseReleaseFileOrDir() functions introduced previously, we can now
open and close the root directory. So let's implement
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume().

OpenVolume() creates a new EFI_FILE_PROTOCOL object -- a reference to the
root directory of the filesystem. Thus, we have to start tracking
references to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL, lest we unbind the
virtio-fs device while files are open.

There are two methods that release an EFI_FILE_PROTOCOL object: the
Close() and the Delete() member functions. In particular, they are not
allowed to fail with regard to resource management -- they must release
resources unconditionally. Thus, for rolling back the resource accounting
that we do in EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume(), we have to
implement the first versions of EFI_FILE_PROTOCOL.Close() and
EFI_FILE_PROTOCOL.Delete() in this patch as well.

With this patch applied, the UEFI shell can enter the root directory of
the Virtio Filesystem (such as with the "FS3:" shell command), and the
"DIR" shell command exercises FUSE_OPENDIR and FUSE_RELEASEDIR, according
to the virtiofsd log. The "DIR" command reports the root directory as if
it were empty; probably because at this time, we only allow the shell to
open and to close the root directory, but not to read it.

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-12-lersek@redhat.com>
Acked-by: Ard Biesheuvel <ard.biesheuvel@arm.com>
2020-12-21 17:16:23 +00:00

82 lines
2.5 KiB
C

/** @file
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL.OpenVolume() member function for the Virtio
Filesystem driver.
Copyright (C) 2020, Red Hat, Inc.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <Library/BaseLib.h> // InsertTailList()
#include <Library/MemoryAllocationLib.h> // AllocatePool()
#include "VirtioFsDxe.h"
/**
Open the root directory on the Virtio Filesystem.
Refer to EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_OPEN_VOLUME for the interface
contract.
**/
EFI_STATUS
EFIAPI
VirtioFsOpenVolume (
IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
OUT EFI_FILE_PROTOCOL **Root
)
{
VIRTIO_FS *VirtioFs;
VIRTIO_FS_FILE *VirtioFsFile;
EFI_STATUS Status;
UINT64 RootDirHandle;
VirtioFs = VIRTIO_FS_FROM_SIMPLE_FS (This);
VirtioFsFile = AllocatePool (sizeof *VirtioFsFile);
if (VirtioFsFile == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Open the root directory.
//
Status = VirtioFsFuseOpenDir (VirtioFs, VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID,
&RootDirHandle);
if (EFI_ERROR (Status)) {
goto FreeVirtioFsFile;
}
//
// Populate the new VIRTIO_FS_FILE object.
//
VirtioFsFile->Signature = VIRTIO_FS_FILE_SIG;
VirtioFsFile->SimpleFile.Revision = EFI_FILE_PROTOCOL_REVISION;
VirtioFsFile->SimpleFile.Open = VirtioFsSimpleFileOpen;
VirtioFsFile->SimpleFile.Close = VirtioFsSimpleFileClose;
VirtioFsFile->SimpleFile.Delete = VirtioFsSimpleFileDelete;
VirtioFsFile->SimpleFile.Read = VirtioFsSimpleFileRead;
VirtioFsFile->SimpleFile.Write = VirtioFsSimpleFileWrite;
VirtioFsFile->SimpleFile.GetPosition = VirtioFsSimpleFileGetPosition;
VirtioFsFile->SimpleFile.SetPosition = VirtioFsSimpleFileSetPosition;
VirtioFsFile->SimpleFile.GetInfo = VirtioFsSimpleFileGetInfo;
VirtioFsFile->SimpleFile.SetInfo = VirtioFsSimpleFileSetInfo;
VirtioFsFile->SimpleFile.Flush = VirtioFsSimpleFileFlush;
VirtioFsFile->IsDirectory = TRUE;
VirtioFsFile->OwnerFs = VirtioFs;
VirtioFsFile->NodeId = VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID;
VirtioFsFile->FuseHandle = RootDirHandle;
//
// One more file open for the filesystem.
//
InsertTailList (&VirtioFs->OpenFiles, &VirtioFsFile->OpenFilesEntry);
*Root = &VirtioFsFile->SimpleFile;
return EFI_SUCCESS;
FreeVirtioFsFile:
FreePool (VirtioFsFile);
return Status;
}