VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/VirtioFsDxe/SimpleFsDelete.c

Last change on this file was 99404, checked in by vboxsync, 2 years ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/** @file
2 EFI_FILE_PROTOCOL.Delete() member function for the Virtio Filesystem driver.
3
4 Copyright (C) 2020, Red Hat, Inc.
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7**/
8
9#include <Library/BaseLib.h> // RemoveEntryList()
10#include <Library/MemoryAllocationLib.h> // FreePool()
11
12#include "VirtioFsDxe.h"
13
14EFI_STATUS
15EFIAPI
16VirtioFsSimpleFileDelete (
17 IN EFI_FILE_PROTOCOL *This
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 //
41 VirtioFsFuseReleaseFileOrDir (
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 //
63 Status = VirtioFsLookupMostSpecificParentDir (
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 //
75 Status = VirtioFsFuseRemoveFileOrDir (
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}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette