TianoCore EDK2 master
Loading...
Searching...
No Matches
SimpleFsDelete.c
Go to the documentation of this file.
1
9#include <Library/BaseLib.h> // RemoveEntryList()
10#include <Library/MemoryAllocationLib.h> // FreePool()
11
12#include "VirtioFsDxe.h"
13
15EFIAPI
16VirtioFsSimpleFileDelete (
18 )
19{
20 VIRTIO_FS_FILE *VirtioFsFile;
21 VIRTIO_FS *VirtioFs;
22 EFI_STATUS Status;
23
24 VirtioFsFile = VIRTIO_FS_FILE_FROM_SIMPLE_FILE (This);
25 VirtioFs = VirtioFsFile->OwnerFs;
26
27 //
28 // All actions in this function are "best effort"; the UEFI spec requires
29 // EFI_FILE_PROTOCOL.Delete() to release resources unconditionally. If a step
30 // related to removing the file fails, it's only reflected in the return
31 // status (EFI_WARN_DELETE_FAILURE rather than EFI_SUCCESS).
32 //
33 // Release, remove, and (if needed) forget. We don't waste time flushing and
34 // syncing; if the EFI_FILE_PROTOCOL user cares enough, they should keep the
35 // parent directory open until after this function call returns, and then
36 // force a sync on *that* EFI_FILE_PROTOCOL instance, using either the
37 // Flush() member function, or the Close() member function.
38 //
39 // If any action fails below, we still try the others.
40 //
42 VirtioFs,
43 VirtioFsFile->NodeId,
44 VirtioFsFile->FuseHandle,
45 VirtioFsFile->IsDirectory
46 );
47
48 //
49 // VirtioFsFile->FuseHandle is gone at this point, but VirtioFsFile->NodeId
50 // is still valid. Continue with removing the file or directory. The result
51 // of this operation determines the return status of the function.
52 //
53 if (VirtioFsFile->IsOpenForWriting) {
54 UINT64 ParentNodeId;
55 CHAR8 *LastComponent;
56
57 //
58 // Split our canonical pathname into most specific parent directory
59 // (identified by NodeId), and single-component filename within that
60 // directory. If This stands for the root directory "/", then the following
61 // function call will gracefully fail.
62 //
64 VirtioFs,
65 VirtioFsFile->CanonicalPathname,
66 &ParentNodeId,
67 &LastComponent
68 );
69 if (!EFI_ERROR (Status)) {
70 //
71 // Attempt the actual removal. Regardless of the outcome, ParentNodeId
72 // must be forgotten right after (unless it stands for the root
73 // directory).
74 //
76 VirtioFs,
77 ParentNodeId,
78 LastComponent,
79 VirtioFsFile->IsDirectory
80 );
81 if (ParentNodeId != VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) {
82 VirtioFsFuseForget (VirtioFs, ParentNodeId);
83 }
84 }
85
86 if (EFI_ERROR (Status)) {
87 //
88 // Map any failure to the spec-mandated warning code.
89 //
90 Status = EFI_WARN_DELETE_FAILURE;
91 }
92 } else {
93 Status = EFI_WARN_DELETE_FAILURE;
94 }
95
96 //
97 // Finally, if we've known VirtioFsFile->NodeId from a lookup, then we should
98 // also ask the server to forget it *once*.
99 //
100 if (VirtioFsFile->NodeId != VIRTIO_FS_FUSE_ROOT_DIR_NODE_ID) {
101 VirtioFsFuseForget (VirtioFs, VirtioFsFile->NodeId);
102 }
103
104 //
105 // One fewer file left open for the owner filesystem.
106 //
107 RemoveEntryList (&VirtioFsFile->OpenFilesEntry);
108
109 FreePool (VirtioFsFile->CanonicalPathname);
110 if (VirtioFsFile->FileInfoArray != NULL) {
111 FreePool (VirtioFsFile->FileInfoArray);
112 }
113
114 FreePool (VirtioFsFile);
115 return Status;
116}
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
Definition: LinkedList.c:590
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS VirtioFsFuseForget(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId)
Definition: FuseForget.c:36
EFI_STATUS VirtioFsFuseReleaseFileOrDir(IN OUT VIRTIO_FS *VirtioFs, IN UINT64 NodeId, IN UINT64 FuseHandle, IN BOOLEAN IsDir)
Definition: FuseRelease.c:41
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS VirtioFsLookupMostSpecificParentDir(IN OUT VIRTIO_FS *VirtioFs, IN OUT CHAR8 *Path, OUT UINT64 *DirNodeId, OUT CHAR8 **LastComponent)
Definition: Helpers.c:1701