]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/VirtioFsDxe/SimpleFsDelete.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / VirtioFsDxe / SimpleFsDelete.c
CommitLineData
334c13e1
LE
1/** @file\r
2 EFI_FILE_PROTOCOL.Delete() 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
28092a39
LE
9#include <Library/BaseLib.h> // RemoveEntryList()\r
10#include <Library/MemoryAllocationLib.h> // FreePool()\r
11\r
334c13e1
LE
12#include "VirtioFsDxe.h"\r
13\r
14EFI_STATUS\r
15EFIAPI\r
16VirtioFsSimpleFileDelete (\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
22 EFI_STATUS Status;\r
28092a39
LE
23\r
24 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);\r
25 VirtioFs = VirtioFsFile->OwnerFs;\r
26\r
27 //\r
28 // All actions in this function are "best effort"; the UEFI spec requires\r
29 // EFI_FILE_PROTOCOL.Delete() to release resources unconditionally. If a step\r
30 // related to removing the file fails, it's only reflected in the return\r
31 // status (EFI_WARN_DELETE_FAILURE rather than EFI_SUCCESS).\r
32 //\r
33 // Release, remove, and (if needed) forget. We don't waste time flushing and\r
34 // syncing; if the EFI_FILE_PROTOCOL user cares enough, they should keep the\r
35 // parent directory open until after this function call returns, and then\r
36 // force a sync on *that* EFI_FILE_PROTOCOL instance, using either the\r
37 // Flush() member function, or the Close() member function.\r
38 //\r
39 // If any action fails below, we still try the others.\r
40 //\r
ac0a286f
MK
41 VirtioFsFuseReleaseFileOrDir (\r
42 VirtioFs,\r
43 VirtioFsFile->NodeId,\r
44 VirtioFsFile->FuseHandle,\r
45 VirtioFsFile->IsDirectory\r
46 );\r
28092a39
LE
47\r
48 //\r
49 // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId\r
50 // is still valid. Continue with removing the file or directory. The result\r
51 // of this operation determines the return status of the function.\r
334c13e1 52 //\r
c09441c3 53 if (VirtioFsFile->IsOpenForWriting) {\r
ac0a286f
MK
54 UINT64 ParentNodeId;\r
55 CHAR8 *LastComponent;\r
c09441c3
LE
56\r
57 //\r
58 // Split our canonical pathname into most specific parent directory\r
59 // (identified by NodeId), and single-component filename within that\r
60 // directory. If This stands for the root directory "/", then the following\r
61 // function call will gracefully fail.\r
62 //\r
63 Status = VirtioFsLookupMostSpecificParentDir (\r
64 VirtioFs,\r
65 VirtioFsFile->CanonicalPathname,\r
66 &ParentNodeId,\r
67 &LastComponent\r
68 );\r
69 if (!EFI_ERROR (Status)) {\r
70 //\r
71 // Attempt the actual removal. Regardless of the outcome, ParentNodeId\r
72 // must be forgotten right after (unless it stands for the root\r
73 // directory).\r
74 //\r
75 Status = VirtioFsFuseRemoveFileOrDir (\r
76 VirtioFs,\r
77 ParentNodeId,\r
78 LastComponent,\r
79 VirtioFsFile->IsDirectory\r
80 );\r
81 if (ParentNodeId != VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) {\r
82 VirtioFsFuseForget (VirtioFs, ParentNodeId);\r
83 }\r
84 }\r
ac0a286f 85\r
c09441c3
LE
86 if (EFI_ERROR (Status)) {\r
87 //\r
88 // Map any failure to the spec-mandated warning code.\r
89 //\r
90 Status = EFI_WARN_DELETE_FAILURE;\r
91 }\r
92 } else {\r
93 Status = EFI_WARN_DELETE_FAILURE;\r
94 }\r
28092a39 95\r
334c13e1 96 //\r
28092a39
LE
97 // Finally, if we've known VirtioFsFile->NodeId from a lookup, then we should\r
98 // also ask the server to forget it *once*.\r
334c13e1 99 //\r
28092a39
LE
100 if (VirtioFsFile->NodeId != VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) {\r
101 VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId);\r
102 }\r
103\r
104 //\r
105 // One fewer file left open for the owner filesystem.\r
106 //\r
107 RemoveEntryList (&VirtioFsFile->OpenFilesEntry);\r
108\r
7e8c83f7 109 FreePool (VirtioFsFile->CanonicalPathname);\r
b845de89
LE
110 if (VirtioFsFile->FileInfoArray != NULL) {\r
111 FreePool (VirtioFsFile->FileInfoArray);\r
112 }\r
ac0a286f 113\r
28092a39
LE
114 FreePool (VirtioFsFile);\r
115 return Status;\r
334c13e1 116}\r