]> git.proxmox.com Git - mirror_edk2.git/blame - FatPkg/EnhancedFatDxe/Delete.c
1. Correct File header to ## @file 2. Remove unnecessary .common] postfix on section.
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Delete.c
CommitLineData
b9ec9330
QH
1/*++\r
2\r
dba03ba1 3Copyright (c) 2005 - 2009, Intel Corporation\r
b9ec9330
QH
4All rights reserved. This program and the accompanying materials are licensed and made available\r
5under the terms and conditions of the BSD License which accompanies this\r
6distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12\r
13Module Name:\r
14\r
15 delete.c\r
16\r
17Abstract:\r
18\r
19 Function that deletes a file\r
20\r
21Revision History\r
22\r
23--*/\r
24\r
25#include "Fat.h"\r
26\r
27EFI_STATUS\r
28EFIAPI\r
29FatDelete (\r
dba03ba1 30 IN EFI_FILE_PROTOCOL *FHand\r
b9ec9330
QH
31 )\r
32/*++\r
33\r
34Routine Description:\r
35\r
36 Deletes the file & Closes the file handle.\r
37\r
38Arguments:\r
39\r
40 FHand - Handle to the file to delete.\r
41\r
42Returns:\r
43\r
44 EFI_SUCCESS - Delete the file successfully.\r
45 EFI_WARN_DELETE_FAILURE - Fail to delete the file.\r
46\r
47--*/\r
48{\r
49 FAT_IFILE *IFile;\r
50 FAT_OFILE *OFile;\r
51 FAT_DIRENT *DirEnt;\r
52 EFI_STATUS Status;\r
53 UINTN Round;\r
54\r
55 IFile = IFILE_FROM_FHAND (FHand);\r
56 OFile = IFile->OFile;\r
57\r
58 //\r
59 // Lock the volume\r
60 //\r
61 FatAcquireLock ();\r
62\r
63 //\r
64 // If the file is read-only, then don't delete it\r
65 //\r
66 if (IFile->ReadOnly) {\r
67 Status = EFI_WRITE_PROTECTED;\r
68 goto Done;\r
69 }\r
70 //\r
71 // If the file is the root dir, then don't delete it\r
72 //\r
73 if (OFile->Parent == NULL) {\r
74 Status = EFI_ACCESS_DENIED;\r
75 goto Done;\r
76 }\r
77 //\r
78 // If the file has a permanant error, skip the delete\r
79 //\r
80 Status = OFile->Error;\r
81 if (!EFI_ERROR (Status)) {\r
82 //\r
83 // If this is a directory, make sure it's empty before\r
84 // allowing it to be deleted\r
85 //\r
86 if (OFile->ODir != NULL) {\r
87 //\r
88 // We do not allow to delete nonempty directory\r
89 //\r
90 FatResetODirCursor (OFile);\r
91 for (Round = 0; Round < 3; Round++) {\r
92 Status = FatGetNextDirEnt (OFile, &DirEnt);\r
93 if ((EFI_ERROR (Status)) ||\r
94 ((Round < 2) && (DirEnt == NULL || !FatIsDotDirEnt (DirEnt))) ||\r
95 ((Round == 2) && (DirEnt != NULL))\r
96 ) {\r
97 Status = EFI_ACCESS_DENIED;\r
98 goto Done;\r
99 }\r
100 }\r
101 }\r
102 //\r
103 // Return the file's space by setting its size to 0\r
104 //\r
105 FatTruncateOFile (OFile, 0);\r
106 //\r
107 // Free the directory entry for this file\r
108 //\r
109 Status = FatRemoveDirEnt (OFile->Parent, OFile->DirEnt);\r
110 if (EFI_ERROR (Status)) {\r
111 goto Done;\r
112 }\r
113 //\r
114 // Set a permanent error for this OFile in case there\r
115 // are still opened IFiles attached\r
116 //\r
117 OFile->Error = EFI_NOT_FOUND;\r
118 } else if (OFile->Error == EFI_NOT_FOUND) {\r
119 Status = EFI_SUCCESS;\r
120 }\r
121\r
122Done:\r
123 //\r
124 // Always close the handle\r
125 //\r
126 FatIFileClose (IFile);\r
127 //\r
128 // Done\r
129 //\r
130 Status = FatCleanupVolume (OFile->Volume, NULL, Status);\r
131 FatReleaseLock ();\r
132\r
133 if (EFI_ERROR (Status)) {\r
134 Status = EFI_WARN_DELETE_FAILURE;\r
135 }\r
136\r
137 return Status;\r
138}\r