2016-12-09 03:07:49 +01:00
|
|
|
/** @file
|
|
|
|
Function that deletes a file.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2013-10-30 04:13:16 +01:00
|
|
|
Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
|
2010-04-26 03:24:39 +02:00
|
|
|
This program and the accompanying materials are licensed and made available
|
2007-12-20 10:16:45 +01:00
|
|
|
under the terms and conditions of the BSD License which accompanies this
|
|
|
|
distribution. The full text of the license may be found at
|
|
|
|
http://opensource.org/licenses/bsd-license.php
|
|
|
|
|
|
|
|
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
#include "Fat.h"
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
Deletes the file & Closes the file handle.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param FHand - Handle to the file to delete.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@retval EFI_SUCCESS - Delete the file successfully.
|
|
|
|
@retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
FatDelete (
|
2009-09-22 04:48:17 +02:00
|
|
|
IN EFI_FILE_PROTOCOL *FHand
|
2007-12-20 10:16:45 +01:00
|
|
|
)
|
|
|
|
{
|
|
|
|
FAT_IFILE *IFile;
|
|
|
|
FAT_OFILE *OFile;
|
|
|
|
FAT_DIRENT *DirEnt;
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN Round;
|
|
|
|
|
|
|
|
IFile = IFILE_FROM_FHAND (FHand);
|
|
|
|
OFile = IFile->OFile;
|
|
|
|
|
2013-10-30 04:13:16 +01:00
|
|
|
FatWaitNonblockingTask (IFile);
|
|
|
|
|
2007-12-20 10:16:45 +01:00
|
|
|
//
|
|
|
|
// Lock the volume
|
|
|
|
//
|
|
|
|
FatAcquireLock ();
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the file is read-only, then don't delete it
|
|
|
|
//
|
|
|
|
if (IFile->ReadOnly) {
|
|
|
|
Status = EFI_WRITE_PROTECTED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// If the file is the root dir, then don't delete it
|
|
|
|
//
|
|
|
|
if (OFile->Parent == NULL) {
|
|
|
|
Status = EFI_ACCESS_DENIED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// If the file has a permanant error, skip the delete
|
|
|
|
//
|
|
|
|
Status = OFile->Error;
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
//
|
|
|
|
// If this is a directory, make sure it's empty before
|
|
|
|
// allowing it to be deleted
|
|
|
|
//
|
|
|
|
if (OFile->ODir != NULL) {
|
|
|
|
//
|
|
|
|
// We do not allow to delete nonempty directory
|
|
|
|
//
|
|
|
|
FatResetODirCursor (OFile);
|
|
|
|
for (Round = 0; Round < 3; Round++) {
|
|
|
|
Status = FatGetNextDirEnt (OFile, &DirEnt);
|
|
|
|
if ((EFI_ERROR (Status)) ||
|
|
|
|
((Round < 2) && (DirEnt == NULL || !FatIsDotDirEnt (DirEnt))) ||
|
|
|
|
((Round == 2) && (DirEnt != NULL))
|
|
|
|
) {
|
|
|
|
Status = EFI_ACCESS_DENIED;
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Return the file's space by setting its size to 0
|
|
|
|
//
|
|
|
|
FatTruncateOFile (OFile, 0);
|
|
|
|
//
|
|
|
|
// Free the directory entry for this file
|
|
|
|
//
|
|
|
|
Status = FatRemoveDirEnt (OFile->Parent, OFile->DirEnt);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto Done;
|
|
|
|
}
|
|
|
|
//
|
|
|
|
// Set a permanent error for this OFile in case there
|
|
|
|
// are still opened IFiles attached
|
|
|
|
//
|
|
|
|
OFile->Error = EFI_NOT_FOUND;
|
|
|
|
} else if (OFile->Error == EFI_NOT_FOUND) {
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
Done:
|
|
|
|
//
|
|
|
|
// Always close the handle
|
|
|
|
//
|
|
|
|
FatIFileClose (IFile);
|
|
|
|
//
|
|
|
|
// Done
|
|
|
|
//
|
2013-10-30 04:13:16 +01:00
|
|
|
Status = FatCleanupVolume (OFile->Volume, NULL, Status, NULL);
|
2007-12-20 10:16:45 +01:00
|
|
|
FatReleaseLock ();
|
|
|
|
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
Status = EFI_WARN_DELETE_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
|
|
|
}
|