]>
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
;
52 // If the file is the root dir, then don't delete it
54 if (OFile
->Parent
== NULL
) {
55 Status
= EFI_ACCESS_DENIED
;
59 // If the file has a permanant error, skip the delete
61 Status
= OFile
->Error
;
62 if (!EFI_ERROR (Status
)) {
64 // If this is a directory, make sure it's empty before
65 // allowing it to be deleted
67 if (OFile
->ODir
!= NULL
) {
69 // We do not allow to delete nonempty directory
71 FatResetODirCursor (OFile
);
72 for (Round
= 0; Round
< 3; Round
++) {
73 Status
= FatGetNextDirEnt (OFile
, &DirEnt
);
74 if ((EFI_ERROR (Status
)) ||
75 ((Round
< 2) && (DirEnt
== NULL
|| !FatIsDotDirEnt (DirEnt
))) ||
76 ((Round
== 2) && (DirEnt
!= NULL
))
78 Status
= EFI_ACCESS_DENIED
;
84 // Return the file's space by setting its size to 0
86 FatTruncateOFile (OFile
, 0);
88 // Free the directory entry for this file
90 Status
= FatRemoveDirEnt (OFile
->Parent
, OFile
->DirEnt
);
91 if (EFI_ERROR (Status
)) {
95 // Set a permanent error for this OFile in case there
96 // are still opened IFiles attached
98 OFile
->Error
= EFI_NOT_FOUND
;
99 } else if (OFile
->Error
== EFI_NOT_FOUND
) {
100 Status
= EFI_SUCCESS
;
105 // Always close the handle
107 FatIFileClose (IFile
);
111 Status
= FatCleanupVolume (OFile
->Volume
, NULL
, Status
, NULL
);
114 if (EFI_ERROR (Status
)) {
115 Status
= EFI_WARN_DELETE_FAILURE
;