2 EFI_FILE_PROTOCOL.Close() member function for the Virtio Filesystem driver.
4 Copyright (C) 2020, Red Hat, Inc.
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Library/BaseLib.h> // RemoveEntryList()
10 #include <Library/MemoryAllocationLib.h> // FreePool()
12 #include "VirtioFsDxe.h"
16 VirtioFsSimpleFileClose (
17 IN EFI_FILE_PROTOCOL
*This
20 VIRTIO_FS_FILE
*VirtioFsFile
;
23 VirtioFsFile
= VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This
);
24 VirtioFs
= VirtioFsFile
->OwnerFs
;
27 // All actions in this function are "best effort"; the UEFI spec requires
28 // EFI_FILE_PROTOCOL.Close() to sync all data to the device, but it also
29 // requires EFI_FILE_PROTOCOL.Close() to release resources unconditionally,
30 // and to return EFI_SUCCESS unconditionally.
32 // Flush, sync, release, and (if needed) forget. If any action fails, we
33 // still try the others.
35 if (VirtioFsFile
->IsOpenForWriting
) {
36 if (!VirtioFsFile
->IsDirectory
) {
40 VirtioFsFile
->FuseHandle
44 VirtioFsFuseFsyncFileOrDir (
47 VirtioFsFile
->FuseHandle
,
48 VirtioFsFile
->IsDirectory
52 VirtioFsFuseReleaseFileOrDir (
55 VirtioFsFile
->FuseHandle
,
56 VirtioFsFile
->IsDirectory
60 // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId
61 // is still valid. If we've known VirtioFsFile->NodeId from a lookup, then
62 // now we should ask the server to forget it *once*.
64 if (VirtioFsFile
->NodeId
!= VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID
) {
65 VirtioFsFuseForget (VirtioFs
, VirtioFsFile
->NodeId
);
69 // One fewer file left open for the owner filesystem.
71 RemoveEntryList (&VirtioFsFile
->OpenFilesEntry
);
73 FreePool (VirtioFsFile
->CanonicalPathname
);
74 if (VirtioFsFile
->FileInfoArray
!= NULL
) {
75 FreePool (VirtioFsFile
->FileInfoArray
);
78 FreePool (VirtioFsFile
);