TianoCore EDK2 master
Loading...
Searching...
No Matches
Delete.c
Go to the documentation of this file.
1
10#include "Fat.h"
11
23EFIAPI
26 )
27{
28 FAT_IFILE *IFile;
29 FAT_OFILE *OFile;
30 FAT_DIRENT *DirEnt;
31 EFI_STATUS Status;
32 UINTN Round;
33
34 IFile = IFILE_FROM_FHAND (FHand);
35 OFile = IFile->OFile;
36
38
39 //
40 // Lock the volume
41 //
43
44 //
45 // If the file is read-only, then don't delete it
46 //
47 if (IFile->ReadOnly) {
48 Status = EFI_WRITE_PROTECTED;
49 goto Done;
50 }
51
52 //
53 // If the file is the root dir, then don't delete it
54 //
55 if (OFile->Parent == NULL) {
56 Status = EFI_ACCESS_DENIED;
57 goto Done;
58 }
59
60 //
61 // If the file has a permanent error, skip the delete
62 //
63 Status = OFile->Error;
64 if (!EFI_ERROR (Status)) {
65 //
66 // If this is a directory, make sure it's empty before
67 // allowing it to be deleted
68 //
69 if (OFile->ODir != NULL) {
70 //
71 // We do not allow to delete nonempty directory
72 //
73 FatResetODirCursor (OFile);
74 for (Round = 0; Round < 3; Round++) {
75 Status = FatGetNextDirEnt (OFile, &DirEnt);
76 if ((EFI_ERROR (Status)) ||
77 ((Round < 2) && ((DirEnt == NULL) || !FatIsDotDirEnt (DirEnt))) ||
78 ((Round == 2) && (DirEnt != NULL))
79 )
80 {
81 Status = EFI_ACCESS_DENIED;
82 goto Done;
83 }
84 }
85 }
86
87 //
88 // Return the file's space by setting its size to 0
89 //
90 FatTruncateOFile (OFile, 0);
91 //
92 // Free the directory entry for this file
93 //
94 Status = FatRemoveDirEnt (OFile->Parent, OFile->DirEnt);
95 if (EFI_ERROR (Status)) {
96 goto Done;
97 }
98
99 //
100 // Set a permanent error for this OFile in case there
101 // are still opened IFiles attached
102 //
103 OFile->Error = EFI_NOT_FOUND;
104 } else if (OFile->Error == EFI_NOT_FOUND) {
105 Status = EFI_SUCCESS;
106 }
107
108Done:
109 //
110 // Always close the handle
111 //
112 FatIFileClose (IFile);
113 //
114 // Done
115 //
116 Status = FatCleanupVolume (OFile->Volume, NULL, Status, NULL);
118
119 if (EFI_ERROR (Status)) {
120 Status = EFI_WARN_DELETE_FAILURE;
121 }
122
123 return Status;
124}
UINT64 UINTN
EFI_STATUS EFIAPI FatDelete(IN EFI_FILE_PROTOCOL *FHand)
Definition: Delete.c:24
EFI_STATUS FatRemoveDirEnt(IN FAT_OFILE *OFile, IN FAT_DIRENT *DirEnt)
BOOLEAN FatIsDotDirEnt(IN FAT_DIRENT *DirEnt)
EFI_STATUS FatGetNextDirEnt(IN FAT_OFILE *OFile, OUT FAT_DIRENT **PtrDirEnt)
VOID FatResetODirCursor(IN FAT_OFILE *OFile)
VOID FatWaitNonblockingTask(FAT_IFILE *IFile)
Definition: Misc.c:75
EFI_STATUS FatIFileClose(FAT_IFILE *IFile)
Definition: Flush.c:173
VOID FatAcquireLock(VOID)
Definition: Misc.c:395
VOID FatReleaseLock(VOID)
Definition: Misc.c:426
EFI_STATUS FatTruncateOFile(IN FAT_OFILE *OFile, IN UINTN TruncatedSize)
Definition: ReadWrite.c:622
EFI_STATUS FatCleanupVolume(IN FAT_VOLUME *Volume, IN FAT_OFILE *OFile, IN EFI_STATUS EfiStatus, IN FAT_TASK *Task)
Definition: Flush.c:382
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
Definition: Fat.h:217