]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Delete.c
3 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Function that deletes a file
30 IN EFI_FILE_PROTOCOL
*FHand
36 Deletes the file & Closes the file handle.
40 FHand - Handle to the file to delete.
44 EFI_SUCCESS - Delete the file successfully.
45 EFI_WARN_DELETE_FAILURE - Fail to delete the file.
55 IFile
= IFILE_FROM_FHAND (FHand
);
58 FatWaitNonblockingTask (IFile
);
66 // If the file is read-only, then don't delete it
68 if (IFile
->ReadOnly
) {
69 Status
= EFI_WRITE_PROTECTED
;
73 // If the file is the root dir, then don't delete it
75 if (OFile
->Parent
== NULL
) {
76 Status
= EFI_ACCESS_DENIED
;
80 // If the file has a permanant error, skip the delete
82 Status
= OFile
->Error
;
83 if (!EFI_ERROR (Status
)) {
85 // If this is a directory, make sure it's empty before
86 // allowing it to be deleted
88 if (OFile
->ODir
!= NULL
) {
90 // We do not allow to delete nonempty directory
92 FatResetODirCursor (OFile
);
93 for (Round
= 0; Round
< 3; Round
++) {
94 Status
= FatGetNextDirEnt (OFile
, &DirEnt
);
95 if ((EFI_ERROR (Status
)) ||
96 ((Round
< 2) && (DirEnt
== NULL
|| !FatIsDotDirEnt (DirEnt
))) ||
97 ((Round
== 2) && (DirEnt
!= NULL
))
99 Status
= EFI_ACCESS_DENIED
;
105 // Return the file's space by setting its size to 0
107 FatTruncateOFile (OFile
, 0);
109 // Free the directory entry for this file
111 Status
= FatRemoveDirEnt (OFile
->Parent
, OFile
->DirEnt
);
112 if (EFI_ERROR (Status
)) {
116 // Set a permanent error for this OFile in case there
117 // are still opened IFiles attached
119 OFile
->Error
= EFI_NOT_FOUND
;
120 } else if (OFile
->Error
== EFI_NOT_FOUND
) {
121 Status
= EFI_SUCCESS
;
126 // Always close the handle
128 FatIFileClose (IFile
);
132 Status
= FatCleanupVolume (OFile
->Volume
, NULL
, Status
, NULL
);
135 if (EFI_ERROR (Status
)) {
136 Status
= EFI_WARN_DELETE_FAILURE
;