]>
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 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 Deletes the file & Closes the file handle.
22 @param FHand - Handle to the file to delete.
24 @retval EFI_SUCCESS - Delete the file successfully.
25 @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
31 IN EFI_FILE_PROTOCOL
*FHand
40 IFile
= IFILE_FROM_FHAND (FHand
);
43 FatWaitNonblockingTask (IFile
);
51 // If the file is read-only, then don't delete it
53 if (IFile
->ReadOnly
) {
54 Status
= EFI_WRITE_PROTECTED
;
58 // If the file is the root dir, then don't delete it
60 if (OFile
->Parent
== NULL
) {
61 Status
= EFI_ACCESS_DENIED
;
65 // If the file has a permanant error, skip the delete
67 Status
= OFile
->Error
;
68 if (!EFI_ERROR (Status
)) {
70 // If this is a directory, make sure it's empty before
71 // allowing it to be deleted
73 if (OFile
->ODir
!= NULL
) {
75 // We do not allow to delete nonempty directory
77 FatResetODirCursor (OFile
);
78 for (Round
= 0; Round
< 3; Round
++) {
79 Status
= FatGetNextDirEnt (OFile
, &DirEnt
);
80 if ((EFI_ERROR (Status
)) ||
81 ((Round
< 2) && (DirEnt
== NULL
|| !FatIsDotDirEnt (DirEnt
))) ||
82 ((Round
== 2) && (DirEnt
!= NULL
))
84 Status
= EFI_ACCESS_DENIED
;
90 // Return the file's space by setting its size to 0
92 FatTruncateOFile (OFile
, 0);
94 // Free the directory entry for this file
96 Status
= FatRemoveDirEnt (OFile
->Parent
, OFile
->DirEnt
);
97 if (EFI_ERROR (Status
)) {
101 // Set a permanent error for this OFile in case there
102 // are still opened IFiles attached
104 OFile
->Error
= EFI_NOT_FOUND
;
105 } else if (OFile
->Error
== EFI_NOT_FOUND
) {
106 Status
= EFI_SUCCESS
;
111 // Always close the handle
113 FatIFileClose (IFile
);
117 Status
= FatCleanupVolume (OFile
->Volume
, NULL
, Status
, NULL
);
120 if (EFI_ERROR (Status
)) {
121 Status
= EFI_WARN_DELETE_FAILURE
;