]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Delete.c
2 Function that deletes a file.
4 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
14 Deletes the file & Closes the file handle.
16 @param FHand - Handle to the file to delete.
18 @retval EFI_SUCCESS - Delete the file successfully.
19 @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
25 IN EFI_FILE_PROTOCOL
*FHand
34 IFile
= IFILE_FROM_FHAND (FHand
);
37 FatWaitNonblockingTask (IFile
);
45 // If the file is read-only, then don't delete it
47 if (IFile
->ReadOnly
) {
48 Status
= EFI_WRITE_PROTECTED
;
53 // If the file is the root dir, then don't delete it
55 if (OFile
->Parent
== NULL
) {
56 Status
= EFI_ACCESS_DENIED
;
61 // If the file has a permanent error, skip the delete
63 Status
= OFile
->Error
;
64 if (!EFI_ERROR (Status
)) {
66 // If this is a directory, make sure it's empty before
67 // allowing it to be deleted
69 if (OFile
->ODir
!= NULL
) {
71 // We do not allow to delete nonempty directory
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
))
81 Status
= EFI_ACCESS_DENIED
;
88 // Return the file's space by setting its size to 0
90 FatTruncateOFile (OFile
, 0);
92 // Free the directory entry for this file
94 Status
= FatRemoveDirEnt (OFile
->Parent
, OFile
->DirEnt
);
95 if (EFI_ERROR (Status
)) {
100 // Set a permanent error for this OFile in case there
101 // are still opened IFiles attached
103 OFile
->Error
= EFI_NOT_FOUND
;
104 } else if (OFile
->Error
== EFI_NOT_FOUND
) {
105 Status
= EFI_SUCCESS
;
110 // Always close the handle
112 FatIFileClose (IFile
);
116 Status
= FatCleanupVolume (OFile
->Volume
, NULL
, Status
, NULL
);
119 if (EFI_ERROR (Status
)) {
120 Status
= EFI_WARN_DELETE_FAILURE
;