]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/SimpleFsClose.c
OvmfPkg/BaseMemEncryptSevLib: skip the pre-validated system RAM
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / SimpleFsClose.c
CommitLineData
334c13e1
LE
1/** @file\r
2 EFI_FILE_PROTOCOL.Close() member function for the Virtio Filesystem driver.\r
3\r
4 Copyright (C) 2020, Red Hat, Inc.\r
5\r
6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
7**/\r
8\r
9#include <Library/BaseLib.h> // RemoveEntryList()\r
10#include <Library/MemoryAllocationLib.h> // FreePool()\r
11\r
12#include "VirtioFsDxe.h"\r
13\r
14EFI_STATUS\r
15EFIAPI\r
16VirtioFsSimpleFileClose (\r
ac0a286f 17 IN EFI_FILE_PROTOCOL *This\r
334c13e1
LE
18 )\r
19{\r
ac0a286f
MK
20 VIRTIO_FS_FILE *VirtioFsFile;\r
21 VIRTIO_FS *VirtioFs;\r
334c13e1
LE
22\r
23 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);\r
24 VirtioFs = VirtioFsFile->OwnerFs;\r
25\r
26 //\r
28092a39
LE
27 // All actions in this function are "best effort"; the UEFI spec requires\r
28 // EFI_FILE_PROTOCOL.Close() to sync all data to the device, but it also\r
29 // requires EFI_FILE_PROTOCOL.Close() to release resources unconditionally,\r
30 // and to return EFI_SUCCESS unconditionally.\r
334c13e1 31 //\r
28092a39
LE
32 // Flush, sync, release, and (if needed) forget. If any action fails, we\r
33 // still try the others.\r
334c13e1 34 //\r
28092a39
LE
35 if (VirtioFsFile->IsOpenForWriting) {\r
36 if (!VirtioFsFile->IsDirectory) {\r
ac0a286f
MK
37 VirtioFsFuseFlush (\r
38 VirtioFs,\r
39 VirtioFsFile->NodeId,\r
40 VirtioFsFile->FuseHandle\r
41 );\r
28092a39
LE
42 }\r
43\r
ac0a286f
MK
44 VirtioFsFuseFsyncFileOrDir (\r
45 VirtioFs,\r
46 VirtioFsFile->NodeId,\r
47 VirtioFsFile->FuseHandle,\r
48 VirtioFsFile->IsDirectory\r
49 );\r
28092a39
LE
50 }\r
51\r
ac0a286f
MK
52 VirtioFsFuseReleaseFileOrDir (\r
53 VirtioFs,\r
54 VirtioFsFile->NodeId,\r
55 VirtioFsFile->FuseHandle,\r
56 VirtioFsFile->IsDirectory\r
57 );\r
334c13e1 58\r
28092a39
LE
59 //\r
60 // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId\r
61 // is still valid. If we've known VirtioFsFile->NodeId from a lookup, then\r
62 // now we should ask the server to forget it *once*.\r
63 //\r
64 if (VirtioFsFile->NodeId != VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) {\r
65 VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId);\r
66 }\r
67\r
334c13e1
LE
68 //\r
69 // One fewer file left open for the owner filesystem.\r
70 //\r
71 RemoveEntryList (&VirtioFsFile->OpenFilesEntry);\r
72\r
7e8c83f7 73 FreePool (VirtioFsFile->CanonicalPathname);\r
b845de89
LE
74 if (VirtioFsFile->FileInfoArray != NULL) {\r
75 FreePool (VirtioFsFile->FileInfoArray);\r
76 }\r
ac0a286f 77\r
334c13e1
LE
78 FreePool (VirtioFsFile);\r
79 return EFI_SUCCESS;\r
80}\r