]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Delete.c
3 Copyright (c) 2005, Intel Corporation
4 All rights reserved. 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
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
);
64 // If the file is read-only, then don't delete it
66 if (IFile
->ReadOnly
) {
67 Status
= EFI_WRITE_PROTECTED
;
71 // If the file is the root dir, then don't delete it
73 if (OFile
->Parent
== NULL
) {
74 Status
= EFI_ACCESS_DENIED
;
78 // If the file has a permanant error, skip the delete
80 Status
= OFile
->Error
;
81 if (!EFI_ERROR (Status
)) {
83 // If this is a directory, make sure it's empty before
84 // allowing it to be deleted
86 if (OFile
->ODir
!= NULL
) {
88 // We do not allow to delete nonempty directory
90 FatResetODirCursor (OFile
);
91 for (Round
= 0; Round
< 3; Round
++) {
92 Status
= FatGetNextDirEnt (OFile
, &DirEnt
);
93 if ((EFI_ERROR (Status
)) ||
94 ((Round
< 2) && (DirEnt
== NULL
|| !FatIsDotDirEnt (DirEnt
))) ||
95 ((Round
== 2) && (DirEnt
!= NULL
))
97 Status
= EFI_ACCESS_DENIED
;
103 // Return the file's space by setting its size to 0
105 FatTruncateOFile (OFile
, 0);
107 // Free the directory entry for this file
109 Status
= FatRemoveDirEnt (OFile
->Parent
, OFile
->DirEnt
);
110 if (EFI_ERROR (Status
)) {
114 // Set a permanent error for this OFile in case there
115 // are still opened IFiles attached
117 OFile
->Error
= EFI_NOT_FOUND
;
118 } else if (OFile
->Error
== EFI_NOT_FOUND
) {
119 Status
= EFI_SUCCESS
;
124 // Always close the handle
126 FatIFileClose (IFile
);
130 Status
= FatCleanupVolume (OFile
->Volume
, NULL
, Status
);
133 if (EFI_ERROR (Status
)) {
134 Status
= EFI_WARN_DELETE_FAILURE
;