]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Delete.c
Fix a typo when checking the 16-bit alignment of Unicode String.
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Delete.c
1 /*++
2
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
8
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.
11
12
13 Module Name:
14
15 delete.c
16
17 Abstract:
18
19 Function that deletes a file
20
21 Revision History
22
23 --*/
24
25 #include "Fat.h"
26
27 EFI_STATUS
28 EFIAPI
29 FatDelete (
30 IN EFI_FILE *FHand
31 )
32 /*++
33
34 Routine Description:
35
36 Deletes the file & Closes the file handle.
37
38 Arguments:
39
40 FHand - Handle to the file to delete.
41
42 Returns:
43
44 EFI_SUCCESS - Delete the file successfully.
45 EFI_WARN_DELETE_FAILURE - Fail to delete the file.
46
47 --*/
48 {
49 FAT_IFILE *IFile;
50 FAT_OFILE *OFile;
51 FAT_DIRENT *DirEnt;
52 EFI_STATUS Status;
53 UINTN Round;
54
55 IFile = IFILE_FROM_FHAND (FHand);
56 OFile = IFile->OFile;
57
58 //
59 // Lock the volume
60 //
61 FatAcquireLock ();
62
63 //
64 // If the file is read-only, then don't delete it
65 //
66 if (IFile->ReadOnly) {
67 Status = EFI_WRITE_PROTECTED;
68 goto Done;
69 }
70 //
71 // If the file is the root dir, then don't delete it
72 //
73 if (OFile->Parent == NULL) {
74 Status = EFI_ACCESS_DENIED;
75 goto Done;
76 }
77 //
78 // If the file has a permanant error, skip the delete
79 //
80 Status = OFile->Error;
81 if (!EFI_ERROR (Status)) {
82 //
83 // If this is a directory, make sure it's empty before
84 // allowing it to be deleted
85 //
86 if (OFile->ODir != NULL) {
87 //
88 // We do not allow to delete nonempty directory
89 //
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))
96 ) {
97 Status = EFI_ACCESS_DENIED;
98 goto Done;
99 }
100 }
101 }
102 //
103 // Return the file's space by setting its size to 0
104 //
105 FatTruncateOFile (OFile, 0);
106 //
107 // Free the directory entry for this file
108 //
109 Status = FatRemoveDirEnt (OFile->Parent, OFile->DirEnt);
110 if (EFI_ERROR (Status)) {
111 goto Done;
112 }
113 //
114 // Set a permanent error for this OFile in case there
115 // are still opened IFiles attached
116 //
117 OFile->Error = EFI_NOT_FOUND;
118 } else if (OFile->Error == EFI_NOT_FOUND) {
119 Status = EFI_SUCCESS;
120 }
121
122 Done:
123 //
124 // Always close the handle
125 //
126 FatIFileClose (IFile);
127 //
128 // Done
129 //
130 Status = FatCleanupVolume (OFile->Volume, NULL, Status);
131 FatReleaseLock ();
132
133 if (EFI_ERROR (Status)) {
134 Status = EFI_WARN_DELETE_FAILURE;
135 }
136
137 return Status;
138 }