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