]>
Commit | Line | Data |
---|---|---|
cae7420b DB |
1 | /** @file\r |
2 | Main header file for EFI FAT file system driver.\r | |
b9ec9330 | 3 | \r |
149d6335 | 4 | Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r |
6163cc98 | 5 | This program and the accompanying materials are licensed and made available\r |
b9ec9330 QH |
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 | |
cae7420b | 13 | **/\r |
b9ec9330 QH |
14 | \r |
15 | #ifndef _FAT_H_\r | |
16 | #define _FAT_H_\r | |
17 | \r | |
18 | #include <Uefi.h>\r | |
19 | \r | |
20 | #include <Guid/FileInfo.h>\r | |
21 | #include <Guid/FileSystemInfo.h>\r | |
22 | #include <Guid/FileSystemVolumeLabelInfo.h>\r | |
b9ec9330 QH |
23 | #include <Protocol/BlockIo.h>\r |
24 | #include <Protocol/DiskIo.h>\r | |
149d6335 | 25 | #include <Protocol/DiskIo2.h>\r |
b9ec9330 QH |
26 | #include <Protocol/SimpleFileSystem.h>\r |
27 | #include <Protocol/UnicodeCollation.h>\r | |
28 | \r | |
29 | #include <Library/PcdLib.h>\r | |
30 | #include <Library/DebugLib.h>\r | |
31 | #include <Library/UefiLib.h>\r | |
32 | #include <Library/BaseLib.h>\r | |
33 | #include <Library/BaseMemoryLib.h>\r | |
34 | #include <Library/MemoryAllocationLib.h>\r | |
35 | #include <Library/UefiDriverEntryPoint.h>\r | |
36 | #include <Library/UefiBootServicesTableLib.h>\r | |
37 | #include <Library/UefiRuntimeServicesTableLib.h>\r | |
38 | \r | |
39 | #include "FatFileSystem.h"\r | |
40 | \r | |
41 | //\r | |
42 | // The FAT signature\r | |
43 | //\r | |
bcc9adde QH |
44 | #define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')\r |
45 | #define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')\r | |
46 | #define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')\r | |
47 | #define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')\r | |
48 | #define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')\r | |
149d6335 RN |
49 | #define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')\r |
50 | #define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')\r | |
b9ec9330 QH |
51 | \r |
52 | #define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)\r | |
53 | \r | |
54 | #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)\r | |
55 | \r | |
56 | #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)\r | |
57 | \r | |
58 | #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)\r | |
59 | \r | |
60 | #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);\r | |
61 | \r | |
62 | #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)\r | |
63 | \r | |
64 | #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)\r | |
65 | \r | |
66 | #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)\r | |
67 | \r | |
68 | //\r | |
69 | // Minimum sector size is 512B, Maximum sector size is 4096B\r | |
70 | // Max sectors per cluster is 128\r | |
71 | //\r | |
72 | #define MAX_BLOCK_ALIGNMENT 12\r | |
73 | #define MIN_BLOCK_ALIGNMENT 9\r | |
74 | #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7\r | |
75 | \r | |
76 | //\r | |
77 | // Efi Time Definition\r | |
78 | //\r | |
79 | #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))\r | |
80 | \r | |
81 | //\r | |
82 | // Minimum fat page size is 8K, maximum fat page alignment is 32K\r | |
83 | // Minimum data page size is 8K, maximum fat page alignment is 64K\r | |
84 | //\r | |
85 | #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13\r | |
86 | #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15\r | |
87 | #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13\r | |
88 | #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16\r | |
89 | #define FAT_DATACACHE_GROUP_COUNT 64\r | |
90 | #define FAT_FATCACHE_GROUP_MIN_COUNT 1\r | |
91 | #define FAT_FATCACHE_GROUP_MAX_COUNT 16\r | |
92 | \r | |
93 | //\r | |
94 | // Used in 8.3 generation algorithm\r | |
95 | //\r | |
96 | #define MAX_SPEC_RETRY 4\r | |
97 | #define SPEC_BASE_TAG_LEN 6\r | |
98 | #define HASH_BASE_TAG_LEN 2\r | |
99 | #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)\r | |
100 | \r | |
101 | //\r | |
102 | // Path name separator is back slash\r | |
103 | //\r | |
104 | #define PATH_NAME_SEPARATOR L'\\'\r | |
105 | \r | |
106 | \r | |
107 | #define EFI_PATH_STRING_LENGTH 260\r | |
108 | #define EFI_FILE_STRING_LENGTH 255\r | |
109 | #define FAT_MAX_ALLOCATE_SIZE 0xA00000\r | |
110 | #define LC_ISO_639_2_ENTRY_SIZE 3\r | |
111 | #define MAX_LANG_CODE_SIZE 100\r | |
112 | \r | |
113 | #define FAT_MAX_DIR_CACHE_COUNT 8\r | |
114 | #define FAT_MAX_DIRENTRY_COUNT 0xFFFF\r | |
115 | typedef CHAR8 LC_ISO_639_2;\r | |
116 | \r | |
117 | //\r | |
118 | // The fat types we support\r | |
119 | //\r | |
120 | typedef enum {\r | |
c1680e88 DB |
121 | Fat12,\r |
122 | Fat16,\r | |
123 | Fat32,\r | |
b9ec9330 QH |
124 | FatUndefined\r |
125 | } FAT_VOLUME_TYPE;\r | |
126 | \r | |
127 | typedef enum {\r | |
c1680e88 DB |
128 | CacheFat,\r |
129 | CacheData,\r | |
130 | CacheMaxType\r | |
b9ec9330 QH |
131 | } CACHE_DATA_TYPE;\r |
132 | \r | |
133 | //\r | |
134 | // Used in FatDiskIo\r | |
135 | //\r | |
136 | typedef enum {\r | |
c1680e88 DB |
137 | ReadDisk = 0, // raw disk read\r |
138 | WriteDisk = 1, // raw disk write\r | |
139 | ReadFat = 2, // read fat cache\r | |
140 | WriteFat = 3, // write fat cache\r | |
141 | ReadData = 6, // read data cache\r | |
142 | WriteData = 7 // write data cache\r | |
b9ec9330 QH |
143 | } IO_MODE;\r |
144 | \r | |
145 | #define CACHE_ENABLED(a) ((a) >= 2)\r | |
146 | #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))\r | |
147 | #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))\r | |
148 | \r | |
149 | //\r | |
150 | // Disk cache tag\r | |
151 | //\r | |
152 | typedef struct {\r | |
153 | UINTN PageNo;\r | |
154 | UINTN RealSize;\r | |
155 | BOOLEAN Dirty;\r | |
156 | } CACHE_TAG;\r | |
157 | \r | |
158 | typedef struct {\r | |
159 | UINT64 BaseAddress;\r | |
160 | UINT64 LimitAddress;\r | |
161 | UINT8 *CacheBase;\r | |
162 | BOOLEAN Dirty;\r | |
163 | UINT8 PageAlignment;\r | |
164 | UINTN GroupMask;\r | |
165 | CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];\r | |
166 | } DISK_CACHE;\r | |
167 | \r | |
168 | //\r | |
169 | // Hash table size\r | |
170 | //\r | |
171 | #define HASH_TABLE_SIZE 0x400\r | |
172 | #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)\r | |
173 | \r | |
174 | //\r | |
175 | // The directory entry for opened directory\r | |
176 | //\r | |
6b7e4498 DB |
177 | \r |
178 | typedef struct _FAT_DIRENT FAT_DIRENT;\r | |
179 | typedef struct _FAT_ODIR FAT_ODIR;\r | |
180 | typedef struct _FAT_OFILE FAT_OFILE;\r | |
181 | typedef struct _FAT_VOLUME FAT_VOLUME;\r | |
182 | \r | |
183 | struct _FAT_DIRENT {\r | |
b9ec9330 QH |
184 | UINTN Signature;\r |
185 | UINT16 EntryPos; // The position of this directory entry in the parent directory file\r | |
186 | UINT8 EntryCount; // The count of the directory entry in the parent directory file\r | |
187 | BOOLEAN Invalid; // Indicate whether this directory entry is valid\r | |
188 | CHAR16 *FileString; // The unicode long file name for this directory entry\r | |
6b7e4498 DB |
189 | FAT_OFILE *OFile; // The OFile of the corresponding directory entry\r |
190 | FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename\r | |
191 | FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename\r | |
b9ec9330 QH |
192 | LIST_ENTRY Link; // Connection of every directory entry\r |
193 | FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk\r | |
6b7e4498 | 194 | };\r |
b9ec9330 | 195 | \r |
6b7e4498 | 196 | struct _FAT_ODIR {\r |
b9ec9330 QH |
197 | UINTN Signature;\r |
198 | UINT32 CurrentEndPos; // Current end position of the directory\r | |
199 | UINT32 CurrentPos; // Current position of the directory\r | |
200 | LIST_ENTRY *CurrentCursor; // Current directory entry pointer\r | |
201 | LIST_ENTRY ChildList; // List of all directory entries\r | |
202 | BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory\r | |
203 | LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded\r | |
204 | UINTN DirCacheTag; // The identification of the directory when in directory cache\r | |
205 | FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];\r | |
206 | FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];\r | |
6b7e4498 | 207 | };\r |
b9ec9330 QH |
208 | \r |
209 | typedef struct {\r | |
210 | UINTN Signature;\r | |
dba03ba1 | 211 | EFI_FILE_PROTOCOL Handle;\r |
b9ec9330 QH |
212 | UINT64 Position;\r |
213 | BOOLEAN ReadOnly;\r | |
6b7e4498 | 214 | FAT_OFILE *OFile;\r |
149d6335 RN |
215 | LIST_ENTRY Tasks; // List of all FAT_TASKs\r |
216 | LIST_ENTRY Link; // Link to other IFiles\r | |
b9ec9330 QH |
217 | } FAT_IFILE;\r |
218 | \r | |
149d6335 RN |
219 | typedef struct {\r |
220 | UINTN Signature;\r | |
221 | EFI_FILE_IO_TOKEN *FileIoToken;\r | |
222 | FAT_IFILE *IFile;\r | |
223 | LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs\r | |
224 | LIST_ENTRY Link; // Link to other FAT_TASKs\r | |
225 | } FAT_TASK;\r | |
226 | \r | |
227 | typedef struct {\r | |
228 | UINTN Signature;\r | |
229 | EFI_DISK_IO2_TOKEN DiskIo2Token;\r | |
230 | FAT_TASK *Task;\r | |
231 | BOOLEAN Write;\r | |
232 | UINT64 Offset;\r | |
233 | VOID *Buffer;\r | |
234 | UINTN BufferSize;\r | |
235 | LIST_ENTRY Link;\r | |
236 | } FAT_SUBTASK;\r | |
237 | \r | |
b9ec9330 QH |
238 | //\r |
239 | // FAT_OFILE - Each opened file\r | |
240 | //\r | |
6b7e4498 | 241 | struct _FAT_OFILE {\r |
b9ec9330 | 242 | UINTN Signature;\r |
6b7e4498 | 243 | FAT_VOLUME *Volume;\r |
b9ec9330 QH |
244 | //\r |
245 | // A permanant error code to return to all accesses to\r | |
246 | // this opened file\r | |
247 | //\r | |
248 | EFI_STATUS Error;\r | |
249 | //\r | |
250 | // A list of the IFILE instances for this OFile\r | |
251 | //\r | |
252 | LIST_ENTRY Opens;\r | |
253 | \r | |
254 | //\r | |
255 | // The dynamic infomation\r | |
256 | //\r | |
257 | UINTN FileSize;\r | |
258 | UINTN FileCluster;\r | |
259 | UINTN FileCurrentCluster;\r | |
260 | UINTN FileLastCluster;\r | |
261 | \r | |
262 | //\r | |
263 | // Dirty is set if there have been any updates to the\r | |
264 | // file\r | |
c3b8ec43 | 265 | // Archive is set if the archive attribute in the file's\r |
b9ec9330 QH |
266 | // directory entry needs to be set when performing flush\r |
267 | // PreserveLastMod is set if the last modification of the\r | |
268 | // file is specified by SetInfo API\r | |
269 | //\r | |
270 | BOOLEAN Dirty;\r | |
271 | BOOLEAN IsFixedRootDir;\r | |
272 | BOOLEAN PreserveLastModification;\r | |
273 | BOOLEAN Archive;\r | |
274 | //\r | |
275 | // Set by an OFile SetPosition\r | |
276 | //\r | |
277 | UINTN Position; // within file\r | |
278 | UINT64 PosDisk; // on the disk\r | |
279 | UINTN PosRem; // remaining in this disk run\r | |
280 | //\r | |
281 | // The opened parent, full path length and currently opened child files\r | |
282 | //\r | |
6b7e4498 | 283 | FAT_OFILE *Parent;\r |
b9ec9330 QH |
284 | UINTN FullPathLen;\r |
285 | LIST_ENTRY ChildHead;\r | |
286 | LIST_ENTRY ChildLink;\r | |
287 | \r | |
288 | //\r | |
289 | // The opened directory structure for a directory; if this\r | |
290 | // OFile represents a file, then ODir = NULL\r | |
291 | //\r | |
292 | FAT_ODIR *ODir;\r | |
293 | //\r | |
294 | // The directory entry for the Ofile\r | |
295 | //\r | |
296 | FAT_DIRENT *DirEnt;\r | |
297 | \r | |
298 | //\r | |
299 | // Link in Volume's reference list\r | |
300 | //\r | |
301 | LIST_ENTRY CheckLink;\r | |
6b7e4498 | 302 | };\r |
b9ec9330 | 303 | \r |
6b7e4498 | 304 | struct _FAT_VOLUME {\r |
b9ec9330 QH |
305 | UINTN Signature;\r |
306 | \r | |
307 | EFI_HANDLE Handle;\r | |
308 | BOOLEAN Valid;\r | |
309 | BOOLEAN DiskError;\r | |
310 | \r | |
311 | EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;\r | |
312 | \r | |
313 | //\r | |
314 | // If opened, the parent handle and BlockIo interface\r | |
315 | //\r | |
316 | EFI_BLOCK_IO_PROTOCOL *BlockIo;\r | |
317 | EFI_DISK_IO_PROTOCOL *DiskIo;\r | |
149d6335 | 318 | EFI_DISK_IO2_PROTOCOL *DiskIo2;\r |
b9ec9330 QH |
319 | UINT32 MediaId;\r |
320 | BOOLEAN ReadOnly;\r | |
321 | \r | |
322 | //\r | |
323 | // Computed values from fat bpb info\r | |
324 | //\r | |
325 | UINT64 VolumeSize;\r | |
326 | UINT64 FatPos; // Disk pos of fat tables\r | |
327 | UINT64 RootPos; // Disk pos of root directory\r | |
328 | UINT64 FirstClusterPos; // Disk pos of first cluster\r | |
329 | UINTN FatSize; // Number of bytes in each fat\r | |
330 | UINTN MaxCluster; // Max cluster number\r | |
331 | UINTN ClusterSize; // Cluster size of fat partition\r | |
332 | UINT8 ClusterAlignment; // Equal to log_2 (clustersize);\r | |
333 | FAT_VOLUME_TYPE FatType;\r | |
334 | \r | |
335 | //\r | |
336 | // Current part of fat table that's present\r | |
337 | //\r | |
338 | UINT64 FatEntryPos; // Location of buffer\r | |
339 | UINTN FatEntrySize; // Size of buffer\r | |
340 | UINT32 FatEntryBuffer; // The buffer\r | |
341 | FAT_INFO_SECTOR FatInfoSector; // Free cluster info\r | |
342 | UINTN FreeInfoPos; // Pos with the free cluster info\r | |
343 | BOOLEAN FreeInfoValid; // If free cluster info is valid\r | |
344 | //\r | |
345 | // Unpacked Fat BPB info\r | |
346 | //\r | |
347 | UINTN NumFats;\r | |
348 | UINTN RootEntries; // < FAT32, root dir is fixed size\r | |
349 | UINTN RootCluster; // >= FAT32, root cluster chain head\r | |
350 | //\r | |
351 | // info for marking the volume dirty or not\r | |
352 | //\r | |
353 | BOOLEAN FatDirty; // If fat-entries have been updated\r | |
354 | UINT32 DirtyValue;\r | |
355 | UINT32 NotDirtyValue;\r | |
356 | \r | |
357 | //\r | |
358 | // The root directory entry and opened root file\r | |
359 | //\r | |
360 | FAT_DIRENT RootDirEnt;\r | |
361 | //\r | |
362 | // File Name of root OFile, it is empty string\r | |
363 | //\r | |
364 | CHAR16 RootFileString[1];\r | |
6b7e4498 | 365 | FAT_OFILE *Root;\r |
b9ec9330 QH |
366 | \r |
367 | //\r | |
368 | // New OFiles are added to this list so they\r | |
369 | // can be cleaned up if they aren't referenced.\r | |
370 | //\r | |
371 | LIST_ENTRY CheckRef;\r | |
372 | \r | |
373 | //\r | |
374 | // Directory cache List\r | |
375 | //\r | |
376 | LIST_ENTRY DirCacheList;\r | |
377 | UINTN DirCacheCount;\r | |
378 | \r | |
379 | //\r | |
380 | // Disk Cache for this volume\r | |
381 | //\r | |
382 | VOID *CacheBuffer;\r | |
c1680e88 | 383 | DISK_CACHE DiskCache[CacheMaxType];\r |
6b7e4498 | 384 | };\r |
b9ec9330 QH |
385 | \r |
386 | //\r | |
387 | // Function Prototypes\r | |
388 | //\r | |
cae7420b DB |
389 | \r |
390 | /**\r | |
391 | \r | |
392 | Implements Open() of Simple File System Protocol.\r | |
393 | \r | |
394 | @param FHand - File handle of the file serves as a starting reference point.\r | |
395 | @param NewHandle - Handle of the file that is newly opened.\r | |
396 | @param FileName - File name relative to FHand.\r | |
397 | @param OpenMode - Open mode.\r | |
398 | @param Attributes - Attributes to set if the file is created.\r | |
399 | \r | |
400 | \r | |
401 | @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r | |
402 | The OpenMode is not supported.\r | |
403 | The Attributes is not the valid attributes.\r | |
404 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.\r | |
405 | @retval EFI_SUCCESS - Open the file successfully.\r | |
406 | @return Others - The status of open file.\r | |
407 | \r | |
408 | **/\r | |
b9ec9330 QH |
409 | EFI_STATUS\r |
410 | EFIAPI\r | |
411 | FatOpen (\r | |
dba03ba1 QH |
412 | IN EFI_FILE_PROTOCOL *FHand,\r |
413 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
b9ec9330 QH |
414 | IN CHAR16 *FileName,\r |
415 | IN UINT64 OpenMode,\r | |
416 | IN UINT64 Attributes\r | |
417 | )\r | |
cae7420b | 418 | ;\r |
b9ec9330 | 419 | \r |
cae7420b | 420 | /**\r |
b9ec9330 | 421 | \r |
cae7420b | 422 | Implements OpenEx() of Simple File System Protocol.\r |
b9ec9330 | 423 | \r |
cae7420b DB |
424 | @param FHand - File handle of the file serves as a starting reference point.\r |
425 | @param NewHandle - Handle of the file that is newly opened.\r | |
426 | @param FileName - File name relative to FHand.\r | |
427 | @param OpenMode - Open mode.\r | |
428 | @param Attributes - Attributes to set if the file is created.\r | |
429 | @param Token - A pointer to the token associated with the transaction.\r | |
b9ec9330 | 430 | \r |
cae7420b | 431 | @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r |
b9ec9330 QH |
432 | The OpenMode is not supported.\r |
433 | The Attributes is not the valid attributes.\r | |
cae7420b DB |
434 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.\r |
435 | @retval EFI_SUCCESS - Open the file successfully.\r | |
436 | @return Others - The status of open file.\r | |
b9ec9330 | 437 | \r |
cae7420b | 438 | **/\r |
149d6335 | 439 | EFI_STATUS\r |
833b5a77 | 440 | EFIAPI\r |
149d6335 RN |
441 | FatOpenEx (\r |
442 | IN EFI_FILE_PROTOCOL *FHand,\r | |
443 | OUT EFI_FILE_PROTOCOL **NewHandle,\r | |
444 | IN CHAR16 *FileName,\r | |
445 | IN UINT64 OpenMode,\r | |
446 | IN UINT64 Attributes,\r | |
447 | IN OUT EFI_FILE_IO_TOKEN *Token\r | |
448 | )\r | |
cae7420b | 449 | ;\r |
149d6335 | 450 | \r |
cae7420b | 451 | /**\r |
149d6335 | 452 | \r |
cae7420b | 453 | Get the file's position of the file\r |
149d6335 | 454 | \r |
cae7420b DB |
455 | @param FHand - The handle of file.\r |
456 | @param Position - The file's position of the file.\r | |
149d6335 | 457 | \r |
cae7420b DB |
458 | @retval EFI_SUCCESS - Get the info successfully.\r |
459 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r | |
460 | @retval EFI_UNSUPPORTED - The open file is not a file.\r | |
149d6335 | 461 | \r |
cae7420b | 462 | **/\r |
b9ec9330 QH |
463 | EFI_STATUS\r |
464 | EFIAPI\r | |
465 | FatGetPosition (\r | |
dba03ba1 | 466 | IN EFI_FILE_PROTOCOL *FHand,\r |
b9ec9330 QH |
467 | OUT UINT64 *Position\r |
468 | )\r | |
cae7420b | 469 | ;\r |
b9ec9330 | 470 | \r |
cae7420b | 471 | /**\r |
b9ec9330 | 472 | \r |
cae7420b | 473 | Get the some types info of the file into Buffer\r |
b9ec9330 | 474 | \r |
cae7420b DB |
475 | @param FHand - The handle of file.\r |
476 | @param Type - The type of the info.\r | |
477 | @param BufferSize - Size of Buffer.\r | |
478 | @param Buffer - Buffer containing volume info.\r | |
b9ec9330 | 479 | \r |
cae7420b DB |
480 | @retval EFI_SUCCESS - Get the info successfully.\r |
481 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r | |
b9ec9330 | 482 | \r |
cae7420b | 483 | **/\r |
b9ec9330 QH |
484 | EFI_STATUS\r |
485 | EFIAPI\r | |
486 | FatGetInfo (\r | |
dba03ba1 QH |
487 | IN EFI_FILE_PROTOCOL *FHand,\r |
488 | IN EFI_GUID *Type,\r | |
489 | IN OUT UINTN *BufferSize,\r | |
490 | OUT VOID *Buffer\r | |
b9ec9330 | 491 | )\r |
cae7420b | 492 | ;\r |
b9ec9330 | 493 | \r |
cae7420b | 494 | /**\r |
b9ec9330 | 495 | \r |
cae7420b | 496 | Set the some types info of the file into Buffer.\r |
b9ec9330 | 497 | \r |
cae7420b DB |
498 | @param FHand - The handle of file.\r |
499 | @param Type - The type of the info.\r | |
500 | @param BufferSize - Size of Buffer.\r | |
501 | @param Buffer - Buffer containing volume info.\r | |
b9ec9330 | 502 | \r |
cae7420b DB |
503 | @retval EFI_SUCCESS - Set the info successfully.\r |
504 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r | |
b9ec9330 | 505 | \r |
cae7420b | 506 | **/\r |
b9ec9330 QH |
507 | EFI_STATUS\r |
508 | EFIAPI\r | |
509 | FatSetInfo (\r | |
dba03ba1 | 510 | IN EFI_FILE_PROTOCOL *FHand,\r |
b9ec9330 QH |
511 | IN EFI_GUID *Type,\r |
512 | IN UINTN BufferSize,\r | |
513 | IN VOID *Buffer\r | |
514 | )\r | |
cae7420b | 515 | ;\r |
b9ec9330 | 516 | \r |
cae7420b | 517 | /**\r |
b9ec9330 | 518 | \r |
cae7420b | 519 | Flushes all data associated with the file handle.\r |
b9ec9330 | 520 | \r |
cae7420b | 521 | @param FHand - Handle to file to flush\r |
b9ec9330 | 522 | \r |
cae7420b DB |
523 | @retval EFI_SUCCESS - Flushed the file successfully\r |
524 | @retval EFI_WRITE_PROTECTED - The volume is read only\r | |
525 | @retval EFI_ACCESS_DENIED - The volume is not read only\r | |
526 | but the file is read only\r | |
527 | @return Others - Flushing of the file is failed\r | |
b9ec9330 | 528 | \r |
cae7420b | 529 | **/\r |
b9ec9330 QH |
530 | EFI_STATUS\r |
531 | EFIAPI\r | |
532 | FatFlush (\r | |
dba03ba1 | 533 | IN EFI_FILE_PROTOCOL *FHand\r |
b9ec9330 | 534 | )\r |
cae7420b | 535 | ;\r |
b9ec9330 | 536 | \r |
cae7420b | 537 | /**\r |
b9ec9330 | 538 | \r |
cae7420b | 539 | Flushes all data associated with the file handle.\r |
b9ec9330 | 540 | \r |
cae7420b DB |
541 | @param FHand - Handle to file to flush.\r |
542 | @param Token - A pointer to the token associated with the transaction.\r | |
b9ec9330 | 543 | \r |
cae7420b DB |
544 | @retval EFI_SUCCESS - Flushed the file successfully.\r |
545 | @retval EFI_WRITE_PROTECTED - The volume is read only.\r | |
546 | @retval EFI_ACCESS_DENIED - The file is read only.\r | |
547 | @return Others - Flushing of the file failed.\r | |
b9ec9330 | 548 | \r |
cae7420b | 549 | **/\r |
149d6335 RN |
550 | EFI_STATUS\r |
551 | EFIAPI\r | |
552 | FatFlushEx (\r | |
553 | IN EFI_FILE_PROTOCOL *FHand,\r | |
554 | IN EFI_FILE_IO_TOKEN *Token\r | |
555 | )\r | |
cae7420b | 556 | ;\r |
149d6335 | 557 | \r |
cae7420b | 558 | /**\r |
149d6335 | 559 | \r |
cae7420b | 560 | Flushes & Closes the file handle.\r |
149d6335 | 561 | \r |
cae7420b | 562 | @param FHand - Handle to the file to delete.\r |
149d6335 | 563 | \r |
cae7420b | 564 | @retval EFI_SUCCESS - Closed the file successfully.\r |
149d6335 | 565 | \r |
cae7420b | 566 | **/\r |
b9ec9330 QH |
567 | EFI_STATUS\r |
568 | EFIAPI\r | |
569 | FatClose (\r | |
dba03ba1 | 570 | IN EFI_FILE_PROTOCOL *FHand\r |
b9ec9330 | 571 | )\r |
cae7420b | 572 | ;\r |
b9ec9330 | 573 | \r |
cae7420b | 574 | /**\r |
b9ec9330 | 575 | \r |
cae7420b | 576 | Deletes the file & Closes the file handle.\r |
b9ec9330 | 577 | \r |
cae7420b | 578 | @param FHand - Handle to the file to delete.\r |
b9ec9330 | 579 | \r |
cae7420b DB |
580 | @retval EFI_SUCCESS - Delete the file successfully.\r |
581 | @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.\r | |
b9ec9330 | 582 | \r |
cae7420b | 583 | **/\r |
b9ec9330 QH |
584 | EFI_STATUS\r |
585 | EFIAPI\r | |
586 | FatDelete (\r | |
dba03ba1 | 587 | IN EFI_FILE_PROTOCOL *FHand\r |
b9ec9330 | 588 | )\r |
cae7420b | 589 | ;\r |
b9ec9330 | 590 | \r |
cae7420b | 591 | /**\r |
b9ec9330 | 592 | \r |
cae7420b | 593 | Set the file's position of the file.\r |
b9ec9330 | 594 | \r |
cae7420b DB |
595 | @param FHand - The handle of file\r |
596 | @param Position - The file's position of the file\r | |
b9ec9330 | 597 | \r |
cae7420b DB |
598 | @retval EFI_SUCCESS - Set the info successfully\r |
599 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file\r | |
600 | @retval EFI_UNSUPPORTED - Set a directory with a not-zero position\r | |
b9ec9330 | 601 | \r |
cae7420b | 602 | **/\r |
b9ec9330 QH |
603 | EFI_STATUS\r |
604 | EFIAPI\r | |
605 | FatSetPosition (\r | |
dba03ba1 | 606 | IN EFI_FILE_PROTOCOL *FHand,\r |
b9ec9330 QH |
607 | IN UINT64 Position\r |
608 | )\r | |
cae7420b | 609 | ;\r |
b9ec9330 | 610 | \r |
cae7420b | 611 | /**\r |
b9ec9330 | 612 | \r |
cae7420b | 613 | Get the file info.\r |
b9ec9330 | 614 | \r |
cae7420b DB |
615 | @param FHand - The handle of the file.\r |
616 | @param BufferSize - Size of Buffer.\r | |
617 | @param Buffer - Buffer containing read data.\r | |
b9ec9330 | 618 | \r |
cae7420b DB |
619 | @retval EFI_SUCCESS - Get the file info successfully.\r |
620 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r | |
621 | @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.\r | |
622 | @return other - An error occurred when operation the disk.\r | |
b9ec9330 | 623 | \r |
cae7420b | 624 | **/\r |
b9ec9330 QH |
625 | EFI_STATUS\r |
626 | EFIAPI\r | |
627 | FatRead (\r | |
dba03ba1 QH |
628 | IN EFI_FILE_PROTOCOL *FHand,\r |
629 | IN OUT UINTN *BufferSize,\r | |
630 | OUT VOID *Buffer\r | |
b9ec9330 | 631 | )\r |
cae7420b | 632 | ;\r |
b9ec9330 | 633 | \r |
cae7420b | 634 | /**\r |
b9ec9330 QH |
635 | \r |
636 | Get the file info.\r | |
637 | \r | |
cae7420b DB |
638 | @param FHand - The handle of the file.\r |
639 | @param Token - A pointer to the token associated with the transaction.\r | |
b9ec9330 | 640 | \r |
cae7420b DB |
641 | @retval EFI_SUCCESS - Get the file info successfully.\r |
642 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r | |
643 | @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.\r | |
644 | @return other - An error occurred when operation the disk.\r | |
b9ec9330 | 645 | \r |
cae7420b | 646 | **/\r |
149d6335 RN |
647 | EFI_STATUS\r |
648 | EFIAPI\r | |
649 | FatReadEx (\r | |
650 | IN EFI_FILE_PROTOCOL *FHand,\r | |
651 | IN OUT EFI_FILE_IO_TOKEN *Token\r | |
652 | )\r | |
cae7420b | 653 | ;\r |
149d6335 | 654 | \r |
cae7420b | 655 | /**\r |
149d6335 | 656 | \r |
cae7420b | 657 | Set the file info.\r |
149d6335 | 658 | \r |
cae7420b DB |
659 | @param FHand - The handle of the file.\r |
660 | @param BufferSize - Size of Buffer.\r | |
661 | @param Buffer - Buffer containing write data.\r | |
149d6335 | 662 | \r |
cae7420b DB |
663 | @retval EFI_SUCCESS - Set the file info successfully.\r |
664 | @retval EFI_WRITE_PROTECTED - The disk is write protected.\r | |
665 | @retval EFI_ACCESS_DENIED - The file is read-only.\r | |
666 | @retval EFI_DEVICE_ERROR - The OFile is not valid.\r | |
667 | @retval EFI_UNSUPPORTED - The open file is not a file.\r | |
668 | - The writing file size is larger than 4GB.\r | |
669 | @return other - An error occurred when operation the disk.\r | |
149d6335 | 670 | \r |
cae7420b | 671 | **/\r |
b9ec9330 QH |
672 | EFI_STATUS\r |
673 | EFIAPI\r | |
674 | FatWrite (\r | |
dba03ba1 QH |
675 | IN EFI_FILE_PROTOCOL *FHand,\r |
676 | IN OUT UINTN *BufferSize,\r | |
677 | IN VOID *Buffer\r | |
b9ec9330 | 678 | )\r |
cae7420b | 679 | ;\r |
b9ec9330 | 680 | \r |
cae7420b | 681 | /**\r |
b9ec9330 | 682 | \r |
cae7420b | 683 | Get the file info.\r |
b9ec9330 | 684 | \r |
cae7420b DB |
685 | @param FHand - The handle of the file.\r |
686 | @param Token - A pointer to the token associated with the transaction.\r | |
b9ec9330 | 687 | \r |
cae7420b DB |
688 | @retval EFI_SUCCESS - Get the file info successfully.\r |
689 | @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r | |
690 | @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.\r | |
691 | @return other - An error occurred when operation the disk.\r | |
b9ec9330 | 692 | \r |
cae7420b | 693 | **/\r |
149d6335 RN |
694 | EFI_STATUS\r |
695 | EFIAPI\r | |
696 | FatWriteEx (\r | |
697 | IN EFI_FILE_PROTOCOL *FHand,\r | |
698 | IN OUT EFI_FILE_IO_TOKEN *Token\r | |
699 | )\r | |
149d6335 RN |
700 | ;\r |
701 | \r | |
b9ec9330 QH |
702 | //\r |
703 | // DiskCache.c\r | |
704 | //\r | |
205cc663 DB |
705 | /**\r |
706 | \r | |
707 | Initialize the disk cache according to Volume's FatType.\r | |
708 | \r | |
709 | @param Volume - FAT file system volume.\r | |
710 | \r | |
711 | @retval EFI_SUCCESS - The disk cache is successfully initialized.\r | |
712 | @retval EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.\r | |
713 | \r | |
714 | **/\r | |
b9ec9330 QH |
715 | EFI_STATUS\r |
716 | FatInitializeDiskCache (\r | |
717 | IN FAT_VOLUME *Volume\r | |
718 | );\r | |
719 | \r | |
205cc663 DB |
720 | /**\r |
721 | \r | |
722 | Read BufferSize bytes from the position of Offset into Buffer,\r | |
723 | or write BufferSize bytes from Buffer into the position of Offset.\r | |
724 | \r | |
725 | Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into\r | |
726 | the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):\r | |
727 | \r | |
728 | 1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache\r | |
729 | page hit, just return the cache page; else update the related cache page and return\r | |
730 | the right cache page.\r | |
731 | 2. Access of Data cache (CACHE_DATA):\r | |
732 | The access data will be divided into UnderRun data, Aligned data and OverRun data;\r | |
733 | The UnderRun data and OverRun data will be accessed by the Data cache,\r | |
734 | but the Aligned data will be accessed with disk directly.\r | |
735 | \r | |
736 | @param Volume - FAT file system volume.\r | |
737 | @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.\r | |
738 | @param IoMode - Indicate the type of disk access.\r | |
739 | @param Offset - The starting byte offset to read from.\r | |
740 | @param BufferSize - Size of Buffer.\r | |
741 | @param Buffer - Buffer containing cache data.\r | |
742 | @param Task point to task instance.\r | |
743 | \r | |
744 | @retval EFI_SUCCESS - The data was accessed correctly.\r | |
745 | @retval EFI_MEDIA_CHANGED - The MediaId does not match the current device.\r | |
746 | @return Others - An error occurred when accessing cache.\r | |
747 | \r | |
748 | **/\r | |
b9ec9330 QH |
749 | EFI_STATUS\r |
750 | FatAccessCache (\r | |
751 | IN FAT_VOLUME *Volume,\r | |
752 | IN CACHE_DATA_TYPE CacheDataType,\r | |
753 | IN IO_MODE IoMode,\r | |
754 | IN UINT64 Offset,\r | |
755 | IN UINTN BufferSize,\r | |
149d6335 RN |
756 | IN OUT UINT8 *Buffer,\r |
757 | IN FAT_TASK *Task\r | |
b9ec9330 QH |
758 | );\r |
759 | \r | |
205cc663 DB |
760 | /**\r |
761 | \r | |
762 | Flush all the dirty cache back, include the FAT cache and the Data cache.\r | |
763 | \r | |
764 | @param Volume - FAT file system volume.\r | |
765 | @param Task point to task instance.\r | |
766 | \r | |
767 | @retval EFI_SUCCESS - Flush all the dirty cache back successfully\r | |
768 | @return other - An error occurred when writing the data into the disk\r | |
769 | \r | |
770 | **/\r | |
b9ec9330 QH |
771 | EFI_STATUS\r |
772 | FatVolumeFlushCache (\r | |
149d6335 RN |
773 | IN FAT_VOLUME *Volume,\r |
774 | IN FAT_TASK *Task\r | |
b9ec9330 QH |
775 | );\r |
776 | \r | |
777 | //\r | |
778 | // Flush.c\r | |
779 | //\r | |
205cc663 DB |
780 | /**\r |
781 | \r | |
782 | Flush the data associated with an open file.\r | |
783 | In this implementation, only last Mod/Access time is updated.\r | |
784 | \r | |
785 | @param OFile - The open file.\r | |
786 | \r | |
787 | @retval EFI_SUCCESS - The OFile is flushed successfully.\r | |
788 | @return Others - An error occurred when flushing this OFile.\r | |
789 | \r | |
790 | **/\r | |
b9ec9330 QH |
791 | EFI_STATUS\r |
792 | FatOFileFlush (\r | |
793 | IN FAT_OFILE *OFile\r | |
794 | );\r | |
795 | \r | |
205cc663 DB |
796 | /**\r |
797 | \r | |
798 | Check the references of the OFile.\r | |
799 | If the OFile (that is checked) is no longer\r | |
800 | referenced, then it is freed.\r | |
801 | \r | |
802 | @param OFile - The OFile to be checked.\r | |
803 | \r | |
804 | @retval TRUE - The OFile is not referenced and freed.\r | |
805 | @retval FALSE - The OFile is kept.\r | |
806 | \r | |
807 | **/\r | |
b9ec9330 QH |
808 | BOOLEAN\r |
809 | FatCheckOFileRef (\r | |
810 | IN FAT_OFILE *OFile\r | |
811 | );\r | |
812 | \r | |
205cc663 DB |
813 | /**\r |
814 | \r | |
815 | Set the OFile and its child OFile with the error Status\r | |
816 | \r | |
817 | @param OFile - The OFile whose permanent error code is to be set.\r | |
818 | @param Status - Error code to be set.\r | |
819 | \r | |
820 | **/\r | |
b9ec9330 QH |
821 | VOID\r |
822 | FatSetVolumeError (\r | |
823 | IN FAT_OFILE *OFile,\r | |
824 | IN EFI_STATUS Status\r | |
825 | );\r | |
826 | \r | |
205cc663 DB |
827 | /**\r |
828 | \r | |
829 | Close the open file instance.\r | |
830 | \r | |
831 | @param IFile - Open file instance.\r | |
832 | \r | |
833 | @retval EFI_SUCCESS - Closed the file successfully.\r | |
834 | \r | |
835 | **/\r | |
b9ec9330 QH |
836 | EFI_STATUS\r |
837 | FatIFileClose (\r | |
838 | FAT_IFILE *IFile\r | |
839 | );\r | |
840 | \r | |
205cc663 DB |
841 | /**\r |
842 | \r | |
843 | Set error status for a specific OFile, reference checking the volume.\r | |
844 | If volume is already marked as invalid, and all resources are freed\r | |
845 | after reference checking, the file system protocol is uninstalled and\r | |
846 | the volume structure is freed.\r | |
847 | \r | |
848 | @param Volume - the Volume that is to be reference checked and unlocked.\r | |
849 | @param OFile - the OFile whose permanent error code is to be set.\r | |
850 | @param EfiStatus - error code to be set.\r | |
851 | @param Task point to task instance.\r | |
852 | \r | |
853 | @retval EFI_SUCCESS - Clean up the volume successfully.\r | |
854 | @return Others - Cleaning up of the volume is failed.\r | |
855 | \r | |
856 | **/\r | |
b9ec9330 QH |
857 | EFI_STATUS\r |
858 | FatCleanupVolume (\r | |
859 | IN FAT_VOLUME *Volume,\r | |
860 | IN FAT_OFILE *OFile,\r | |
149d6335 RN |
861 | IN EFI_STATUS EfiStatus,\r |
862 | IN FAT_TASK *Task\r | |
b9ec9330 QH |
863 | );\r |
864 | \r | |
865 | //\r | |
866 | // FileSpace.c\r | |
867 | //\r | |
205cc663 DB |
868 | /**\r |
869 | \r | |
870 | Shrink the end of the open file base on the file size.\r | |
871 | \r | |
872 | @param OFile - The open file.\r | |
873 | \r | |
874 | @retval EFI_SUCCESS - Shrinked sucessfully.\r | |
875 | @retval EFI_VOLUME_CORRUPTED - There are errors in the file's clusters.\r | |
876 | \r | |
877 | **/\r | |
b9ec9330 QH |
878 | EFI_STATUS\r |
879 | FatShrinkEof (\r | |
880 | IN FAT_OFILE *OFile\r | |
881 | );\r | |
882 | \r | |
205cc663 DB |
883 | /**\r |
884 | \r | |
885 | Grow the end of the open file base on the NewSizeInBytes.\r | |
886 | \r | |
887 | @param OFile - The open file.\r | |
888 | @param NewSizeInBytes - The new size in bytes of the open file.\r | |
889 | \r | |
890 | @retval EFI_SUCCESS - The file is grown sucessfully.\r | |
891 | @retval EFI_UNSUPPORTED - The file size is larger than 4GB.\r | |
892 | @retval EFI_VOLUME_CORRUPTED - There are errors in the files' clusters.\r | |
893 | @retval EFI_VOLUME_FULL - The volume is full and can not grow the file.\r | |
894 | \r | |
895 | **/\r | |
b9ec9330 QH |
896 | EFI_STATUS\r |
897 | FatGrowEof (\r | |
898 | IN FAT_OFILE *OFile,\r | |
899 | IN UINT64 NewSizeInBytes\r | |
900 | );\r | |
901 | \r | |
205cc663 DB |
902 | /**\r |
903 | \r | |
904 | Get the size of directory of the open file.\r | |
905 | \r | |
906 | @param Volume - The File System Volume.\r | |
907 | @param Cluster - The Starting cluster.\r | |
908 | \r | |
909 | @return The physical size of the file starting at the input cluster, if there is error in the\r | |
910 | cluster chain, the return value is 0.\r | |
911 | \r | |
912 | **/\r | |
b9ec9330 QH |
913 | UINTN\r |
914 | FatPhysicalDirSize (\r | |
915 | IN FAT_VOLUME *Volume,\r | |
916 | IN UINTN Cluster\r | |
917 | );\r | |
918 | \r | |
205cc663 DB |
919 | /**\r |
920 | \r | |
921 | Get the physical size of a file on the disk.\r | |
922 | \r | |
923 | @param Volume - The file system volume.\r | |
924 | @param RealSize - The real size of a file.\r | |
925 | \r | |
926 | @return The physical size of a file on the disk.\r | |
927 | \r | |
928 | **/\r | |
b9ec9330 QH |
929 | UINT64\r |
930 | FatPhysicalFileSize (\r | |
931 | IN FAT_VOLUME *Volume,\r | |
932 | IN UINTN RealSize\r | |
933 | );\r | |
934 | \r | |
205cc663 DB |
935 | /**\r |
936 | \r | |
937 | Seek OFile to requested position, and calculate the number of\r | |
938 | consecutive clusters from the position in the file\r | |
939 | \r | |
940 | @param OFile - The open file.\r | |
941 | @param Position - The file's position which will be accessed.\r | |
942 | @param PosLimit - The maximum length current reading/writing may access\r | |
943 | \r | |
944 | @retval EFI_SUCCESS - Set the info successfully.\r | |
945 | @retval EFI_VOLUME_CORRUPTED - Cluster chain corrupt.\r | |
946 | \r | |
947 | **/\r | |
b9ec9330 QH |
948 | EFI_STATUS\r |
949 | FatOFilePosition (\r | |
950 | IN FAT_OFILE *OFile,\r | |
951 | IN UINTN Position,\r | |
952 | IN UINTN PosLimit\r | |
953 | );\r | |
954 | \r | |
205cc663 DB |
955 | /**\r |
956 | \r | |
957 | Update the free cluster info of FatInfoSector of the volume.\r | |
958 | \r | |
959 | @param Volume - FAT file system volume.\r | |
960 | \r | |
961 | **/\r | |
b9ec9330 QH |
962 | VOID\r |
963 | FatComputeFreeInfo (\r | |
964 | IN FAT_VOLUME *Volume\r | |
965 | );\r | |
966 | \r | |
967 | //\r | |
968 | // Init.c\r | |
969 | //\r | |
205cc663 DB |
970 | /**\r |
971 | \r | |
972 | Allocates volume structure, detects FAT file system, installs protocol,\r | |
973 | and initialize cache.\r | |
974 | \r | |
975 | @param Handle - The handle of parent device.\r | |
976 | @param DiskIo - The DiskIo of parent device.\r | |
977 | @param DiskIo2 - The DiskIo2 of parent device.\r | |
978 | @param BlockIo - The BlockIo of parent devicel\r | |
979 | \r | |
980 | @retval EFI_SUCCESS - Allocate a new volume successfully.\r | |
981 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.\r | |
982 | @return Others - Allocating a new volume failed.\r | |
983 | \r | |
984 | **/\r | |
b9ec9330 QH |
985 | EFI_STATUS\r |
986 | FatAllocateVolume (\r | |
987 | IN EFI_HANDLE Handle,\r | |
988 | IN EFI_DISK_IO_PROTOCOL *DiskIo,\r | |
149d6335 | 989 | IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r |
b9ec9330 QH |
990 | IN EFI_BLOCK_IO_PROTOCOL *BlockIo\r |
991 | );\r | |
992 | \r | |
205cc663 DB |
993 | /**\r |
994 | \r | |
995 | Detects FAT file system on Disk and set relevant fields of Volume.\r | |
996 | \r | |
997 | @param Volume - The volume structure.\r | |
998 | \r | |
999 | @retval EFI_SUCCESS - The Fat File System is detected successfully\r | |
1000 | @retval EFI_UNSUPPORTED - The volume is not FAT file system.\r | |
1001 | @retval EFI_VOLUME_CORRUPTED - The volume is corrupted.\r | |
1002 | \r | |
1003 | **/\r | |
b9ec9330 QH |
1004 | EFI_STATUS\r |
1005 | FatOpenDevice (\r | |
1006 | IN OUT FAT_VOLUME *Volume\r | |
1007 | );\r | |
1008 | \r | |
205cc663 DB |
1009 | /**\r |
1010 | \r | |
1011 | Called by FatDriverBindingStop(), Abandon the volume.\r | |
1012 | \r | |
1013 | @param Volume - The volume to be abandoned.\r | |
1014 | \r | |
1015 | @retval EFI_SUCCESS - Abandoned the volume successfully.\r | |
1016 | @return Others - Can not uninstall the protocol interfaces.\r | |
1017 | \r | |
1018 | **/\r | |
b9ec9330 QH |
1019 | EFI_STATUS\r |
1020 | FatAbandonVolume (\r | |
1021 | IN FAT_VOLUME *Volume\r | |
1022 | );\r | |
1023 | \r | |
1024 | //\r | |
1025 | // Misc.c\r | |
1026 | //\r | |
205cc663 DB |
1027 | /**\r |
1028 | \r | |
1029 | Create the task\r | |
1030 | \r | |
1031 | @param IFile - The instance of the open file.\r | |
1032 | @param Token - A pointer to the token associated with the transaction.\r | |
1033 | \r | |
1034 | @return FAT_TASK * - Return the task instance.\r | |
1035 | \r | |
1036 | **/\r | |
149d6335 RN |
1037 | FAT_TASK *\r |
1038 | FatCreateTask (\r | |
1039 | FAT_IFILE *IFile,\r | |
1040 | EFI_FILE_IO_TOKEN *Token\r | |
1041 | );\r | |
1042 | \r | |
205cc663 DB |
1043 | /**\r |
1044 | \r | |
1045 | Destroy the task.\r | |
1046 | \r | |
1047 | @param Task - The task to be destroyed.\r | |
1048 | \r | |
1049 | **/\r | |
149d6335 RN |
1050 | VOID\r |
1051 | FatDestroyTask (\r | |
1052 | FAT_TASK *Task\r | |
1053 | );\r | |
1054 | \r | |
205cc663 DB |
1055 | /**\r |
1056 | \r | |
1057 | Wait all non-blocking requests complete.\r | |
1058 | \r | |
1059 | @param IFile - The instance of the open file.\r | |
1060 | \r | |
1061 | **/\r | |
149d6335 RN |
1062 | VOID\r |
1063 | FatWaitNonblockingTask (\r | |
1064 | FAT_IFILE *IFile\r | |
1065 | );\r | |
1066 | \r | |
205cc663 DB |
1067 | /**\r |
1068 | \r | |
1069 | Remove the subtask from subtask list.\r | |
1070 | \r | |
1071 | @param Subtask - The subtask to be removed.\r | |
1072 | \r | |
1073 | @return LIST_ENTRY * - The next node in the list.\r | |
1074 | \r | |
1075 | **/\r | |
149d6335 RN |
1076 | LIST_ENTRY *\r |
1077 | FatDestroySubtask (\r | |
1078 | FAT_SUBTASK *Subtask\r | |
1079 | );\r | |
1080 | \r | |
205cc663 DB |
1081 | /**\r |
1082 | \r | |
1083 | Execute the task.\r | |
1084 | \r | |
1085 | @param IFile - The instance of the open file.\r | |
1086 | @param Task - The task to be executed.\r | |
1087 | \r | |
1088 | @retval EFI_SUCCESS - The task was executed sucessfully.\r | |
1089 | @return other - An error occurred when executing the task.\r | |
1090 | \r | |
1091 | **/\r | |
149d6335 RN |
1092 | EFI_STATUS\r |
1093 | FatQueueTask (\r | |
1094 | IN FAT_IFILE *IFile,\r | |
1095 | IN FAT_TASK *Task\r | |
1096 | );\r | |
1097 | \r | |
205cc663 DB |
1098 | /**\r |
1099 | \r | |
1100 | Set the volume as dirty or not.\r | |
1101 | \r | |
1102 | @param Volume - FAT file system volume.\r | |
1103 | @param IoMode - The access mode.\r | |
1104 | @param DirtyValue - Set the volume as dirty or not.\r | |
1105 | \r | |
1106 | @retval EFI_SUCCESS - Set the new FAT entry value sucessfully.\r | |
1107 | @return other - An error occurred when operation the FAT entries.\r | |
1108 | \r | |
1109 | **/\r | |
b9ec9330 QH |
1110 | EFI_STATUS\r |
1111 | FatAccessVolumeDirty (\r | |
1112 | IN FAT_VOLUME *Volume,\r | |
1113 | IN IO_MODE IoMode,\r | |
1114 | IN VOID *DirtyValue\r | |
1115 | );\r | |
1116 | \r | |
205cc663 DB |
1117 | /**\r |
1118 | \r | |
1119 | General disk access function.\r | |
1120 | \r | |
1121 | @param Volume - FAT file system volume.\r | |
1122 | @param IoMode - The access mode (disk read/write or cache access).\r | |
1123 | @param Offset - The starting byte offset to read from.\r | |
1124 | @param BufferSize - Size of Buffer.\r | |
1125 | @param Buffer - Buffer containing read data.\r | |
1126 | @param Task point to task instance.\r | |
1127 | \r | |
1128 | @retval EFI_SUCCESS - The operation is performed successfully.\r | |
1129 | @retval EFI_VOLUME_CORRUPTED - The accesss is\r | |
1130 | @return Others - The status of read/write the disk\r | |
1131 | \r | |
1132 | **/\r | |
b9ec9330 QH |
1133 | EFI_STATUS\r |
1134 | FatDiskIo (\r | |
1135 | IN FAT_VOLUME *Volume,\r | |
1136 | IN IO_MODE IoMode,\r | |
1137 | IN UINT64 Offset,\r | |
1138 | IN UINTN BufferSize,\r | |
149d6335 RN |
1139 | IN OUT VOID *Buffer,\r |
1140 | IN FAT_TASK *Task\r | |
b9ec9330 QH |
1141 | );\r |
1142 | \r | |
205cc663 DB |
1143 | /**\r |
1144 | \r | |
1145 | Lock the volume.\r | |
1146 | \r | |
1147 | **/\r | |
b9ec9330 QH |
1148 | VOID\r |
1149 | FatAcquireLock (\r | |
1150 | VOID\r | |
1151 | );\r | |
1152 | \r | |
205cc663 DB |
1153 | /**\r |
1154 | \r | |
1155 | Unlock the volume.\r | |
1156 | \r | |
1157 | **/\r | |
b9ec9330 QH |
1158 | VOID\r |
1159 | FatReleaseLock (\r | |
1160 | VOID\r | |
1161 | );\r | |
1162 | \r | |
205cc663 DB |
1163 | /**\r |
1164 | \r | |
1165 | Lock the volume.\r | |
1166 | If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.\r | |
1167 | Otherwise, EFI_SUCCESS is returned.\r | |
1168 | \r | |
1169 | @retval EFI_SUCCESS - The volume is locked.\r | |
1170 | @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.\r | |
1171 | \r | |
1172 | **/\r | |
25ce9b1f QH |
1173 | EFI_STATUS\r |
1174 | FatAcquireLockOrFail (\r | |
b9ec9330 QH |
1175 | VOID\r |
1176 | );\r | |
1177 | \r | |
205cc663 DB |
1178 | /**\r |
1179 | \r | |
1180 | Free directory entry.\r | |
1181 | \r | |
1182 | @param DirEnt - The directory entry to be freed.\r | |
1183 | \r | |
1184 | **/\r | |
b9ec9330 QH |
1185 | VOID\r |
1186 | FatFreeDirEnt (\r | |
1187 | IN FAT_DIRENT *DirEnt\r | |
1188 | );\r | |
1189 | \r | |
205cc663 DB |
1190 | /**\r |
1191 | \r | |
1192 | Free volume structure (including the contents of directory cache and disk cache).\r | |
1193 | \r | |
1194 | @param Volume - The volume structure to be freed.\r | |
1195 | \r | |
1196 | **/\r | |
b9ec9330 QH |
1197 | VOID\r |
1198 | FatFreeVolume (\r | |
1199 | IN FAT_VOLUME *Volume\r | |
1200 | );\r | |
1201 | \r | |
205cc663 DB |
1202 | /**\r |
1203 | \r | |
1204 | Translate EFI time to FAT time.\r | |
1205 | \r | |
1206 | @param ETime - The time of EFI_TIME.\r | |
1207 | @param FTime - The time of FAT_DATE_TIME.\r | |
1208 | \r | |
1209 | **/\r | |
b9ec9330 QH |
1210 | VOID\r |
1211 | FatEfiTimeToFatTime (\r | |
1212 | IN EFI_TIME *ETime,\r | |
1213 | OUT FAT_DATE_TIME *FTime\r | |
1214 | );\r | |
1215 | \r | |
205cc663 DB |
1216 | /**\r |
1217 | \r | |
1218 | Translate Fat time to EFI time.\r | |
1219 | \r | |
1220 | @param FTime - The time of FAT_DATE_TIME.\r | |
1221 | @param ETime - The time of EFI_TIME..\r | |
1222 | \r | |
1223 | **/\r | |
b9ec9330 QH |
1224 | VOID\r |
1225 | FatFatTimeToEfiTime (\r | |
1226 | IN FAT_DATE_TIME *FTime,\r | |
1227 | OUT EFI_TIME *ETime\r | |
1228 | );\r | |
1229 | \r | |
205cc663 DB |
1230 | /**\r |
1231 | \r | |
1232 | Get Current FAT time.\r | |
1233 | \r | |
1234 | @param FatTime - Current FAT time.\r | |
1235 | \r | |
1236 | **/\r | |
b9ec9330 QH |
1237 | VOID\r |
1238 | FatGetCurrentFatTime (\r | |
1239 | OUT FAT_DATE_TIME *FatTime\r | |
1240 | );\r | |
1241 | \r | |
205cc663 DB |
1242 | /**\r |
1243 | \r | |
1244 | Check whether a time is valid.\r | |
1245 | \r | |
1246 | @param Time - The time of EFI_TIME.\r | |
1247 | \r | |
1248 | @retval TRUE - The time is valid.\r | |
1249 | @retval FALSE - The time is not valid.\r | |
1250 | \r | |
1251 | **/\r | |
b9ec9330 QH |
1252 | BOOLEAN\r |
1253 | FatIsValidTime (\r | |
1254 | IN EFI_TIME *Time\r | |
1255 | );\r | |
1256 | \r | |
1257 | //\r | |
1258 | // UnicodeCollation.c\r | |
1259 | //\r | |
205cc663 DB |
1260 | /**\r |
1261 | Initialize Unicode Collation support.\r | |
1262 | \r | |
1263 | It tries to locate Unicode Collation 2 protocol and matches it with current\r | |
1264 | platform language code. If for any reason the first attempt fails, it then tries to\r | |
1265 | use Unicode Collation Protocol.\r | |
1266 | \r | |
1267 | @param AgentHandle The handle used to open Unicode Collation (2) protocol.\r | |
1268 | \r | |
1269 | @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.\r | |
1270 | @retval Others The Unicode Collation (2) protocol has not been located.\r | |
1271 | \r | |
1272 | **/\r | |
b9ec9330 QH |
1273 | EFI_STATUS\r |
1274 | InitializeUnicodeCollationSupport (\r | |
1275 | IN EFI_HANDLE AgentHandle\r | |
1276 | );\r | |
1277 | \r | |
205cc663 DB |
1278 | /**\r |
1279 | Convert FAT string to unicode string.\r | |
1280 | \r | |
1281 | @param FatSize The size of FAT string.\r | |
1282 | @param Fat The FAT string.\r | |
1283 | @param String The unicode string.\r | |
1284 | \r | |
1285 | @return None.\r | |
1286 | \r | |
1287 | **/\r | |
b9ec9330 QH |
1288 | VOID\r |
1289 | FatFatToStr (\r | |
1290 | IN UINTN FatSize,\r | |
1291 | IN CHAR8 *Fat,\r | |
1292 | OUT CHAR16 *String\r | |
1293 | );\r | |
1294 | \r | |
205cc663 DB |
1295 | /**\r |
1296 | Convert unicode string to Fat string.\r | |
1297 | \r | |
1298 | @param String The unicode string.\r | |
1299 | @param FatSize The size of the FAT string.\r | |
1300 | @param Fat The FAT string.\r | |
1301 | \r | |
1302 | @retval TRUE Convert successfully.\r | |
1303 | @retval FALSE Convert error.\r | |
1304 | \r | |
1305 | **/\r | |
b9ec9330 QH |
1306 | BOOLEAN\r |
1307 | FatStrToFat (\r | |
1308 | IN CHAR16 *String,\r | |
1309 | IN UINTN FatSize,\r | |
1310 | OUT CHAR8 *Fat\r | |
1311 | );\r | |
1312 | \r | |
205cc663 DB |
1313 | /**\r |
1314 | Lowercase a string\r | |
1315 | \r | |
1316 | @param Str The string which will be lower-cased.\r | |
1317 | \r | |
1318 | **/\r | |
b9ec9330 QH |
1319 | VOID\r |
1320 | FatStrLwr (\r | |
1321 | IN CHAR16 *Str\r | |
1322 | );\r | |
1323 | \r | |
205cc663 DB |
1324 | /**\r |
1325 | Uppercase a string.\r | |
1326 | \r | |
1327 | @param Str The string which will be upper-cased.\r | |
1328 | \r | |
1329 | **/\r | |
b9ec9330 QH |
1330 | VOID\r |
1331 | FatStrUpr (\r | |
1332 | IN CHAR16 *Str\r | |
1333 | );\r | |
1334 | \r | |
205cc663 DB |
1335 | /**\r |
1336 | Performs a case-insensitive comparison of two Null-terminated Unicode strings.\r | |
1337 | \r | |
1338 | @param Str1 A pointer to a Null-terminated Unicode string.\r | |
1339 | @param Str2 A pointer to a Null-terminated Unicode string.\r | |
1340 | \r | |
1341 | @retval 0 S1 is equivalent to S2.\r | |
1342 | @retval >0 S1 is lexically greater than S2.\r | |
1343 | @retval <0 S1 is lexically less than S2.\r | |
1344 | **/\r | |
b9ec9330 QH |
1345 | INTN\r |
1346 | FatStriCmp (\r | |
1347 | IN CHAR16 *Str1,\r | |
1348 | IN CHAR16 *Str2\r | |
1349 | );\r | |
1350 | \r | |
1351 | //\r | |
1352 | // Open.c\r | |
1353 | //\r | |
205cc663 DB |
1354 | \r |
1355 | /**\r | |
1356 | \r | |
1357 | Open a file for a file name relative to an existing OFile.\r | |
1358 | The IFile of the newly opened file is passed out.\r | |
1359 | \r | |
1360 | @param OFile - The file that serves as a starting reference point.\r | |
1361 | @param NewIFile - The newly generated IFile instance.\r | |
1362 | @param FileName - The file name relative to the OFile.\r | |
1363 | @param OpenMode - Open mode.\r | |
1364 | @param Attributes - Attributes to set if the file is created.\r | |
1365 | \r | |
1366 | \r | |
1367 | @retval EFI_SUCCESS - Open the file successfully.\r | |
1368 | @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes\r | |
1369 | or the file name is not valid.\r | |
1370 | @retval EFI_NOT_FOUND - Conficts between dir intention and attribute.\r | |
1371 | @retval EFI_WRITE_PROTECTED - Can't open for write if the volume is read only.\r | |
1372 | @retval EFI_ACCESS_DENIED - If the file's attribute is read only, and the\r | |
1373 | open is for read-write fail it.\r | |
1374 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.\r | |
1375 | \r | |
1376 | **/\r | |
b9ec9330 QH |
1377 | EFI_STATUS\r |
1378 | FatOFileOpen (\r | |
1379 | IN FAT_OFILE *OFile,\r | |
1380 | OUT FAT_IFILE **NewIFile,\r | |
1381 | IN CHAR16 *FileName,\r | |
1382 | IN UINT64 OpenMode,\r | |
1383 | IN UINT8 Attributes\r | |
1384 | );\r | |
1385 | \r | |
205cc663 DB |
1386 | /**\r |
1387 | \r | |
1388 | Create an Open instance for the existing OFile.\r | |
1389 | The IFile of the newly opened file is passed out.\r | |
1390 | \r | |
1391 | @param OFile - The file that serves as a starting reference point.\r | |
1392 | @param PtrIFile - The newly generated IFile instance.\r | |
1393 | \r | |
1394 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for the IFile\r | |
1395 | @retval EFI_SUCCESS - Create the new IFile for the OFile successfully\r | |
1396 | \r | |
1397 | **/\r | |
b9ec9330 QH |
1398 | EFI_STATUS\r |
1399 | FatAllocateIFile (\r | |
1400 | IN FAT_OFILE *OFile,\r | |
1401 | OUT FAT_IFILE **PtrIFile\r | |
1402 | );\r | |
1403 | \r | |
1404 | //\r | |
1405 | // OpenVolume.c\r | |
1406 | //\r | |
205cc663 DB |
1407 | /**\r |
1408 | \r | |
1409 | Implements Simple File System Protocol interface function OpenVolume().\r | |
1410 | \r | |
1411 | @param This - Calling context.\r | |
1412 | @param File - the Root Directory of the volume.\r | |
1413 | \r | |
1414 | @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.\r | |
1415 | @retval EFI_VOLUME_CORRUPTED - The FAT type is error.\r | |
1416 | @retval EFI_SUCCESS - Open the volume successfully.\r | |
1417 | \r | |
1418 | **/\r | |
b9ec9330 QH |
1419 | EFI_STATUS\r |
1420 | EFIAPI\r | |
1421 | FatOpenVolume (\r | |
1422 | IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r | |
dba03ba1 | 1423 | OUT EFI_FILE_PROTOCOL **File\r |
b9ec9330 QH |
1424 | );\r |
1425 | \r | |
1426 | //\r | |
1427 | // ReadWrite.c\r | |
1428 | //\r | |
205cc663 DB |
1429 | /**\r |
1430 | \r | |
1431 | This function reads data from a file or writes data to a file.\r | |
1432 | It uses OFile->PosRem to determine how much data can be accessed in one time.\r | |
1433 | \r | |
1434 | @param OFile - The open file.\r | |
1435 | @param IoMode - Indicate whether the access mode is reading or writing.\r | |
1436 | @param Position - The position where data will be accessed.\r | |
1437 | @param DataBufferSize - Size of Buffer.\r | |
1438 | @param UserBuffer - Buffer containing data.\r | |
1439 | @param Task point to task instance.\r | |
1440 | \r | |
1441 | @retval EFI_SUCCESS - Access the data successfully.\r | |
1442 | @return other - An error occurred when operating on the disk.\r | |
1443 | \r | |
1444 | **/\r | |
b9ec9330 QH |
1445 | EFI_STATUS\r |
1446 | FatAccessOFile (\r | |
1447 | IN FAT_OFILE *OFile,\r | |
1448 | IN IO_MODE IoMode,\r | |
1449 | IN UINTN Position,\r | |
1450 | IN UINTN *DataBufferSize,\r | |
149d6335 RN |
1451 | IN UINT8 *UserBuffer,\r |
1452 | IN FAT_TASK *Task\r | |
b9ec9330 QH |
1453 | );\r |
1454 | \r | |
205cc663 DB |
1455 | /**\r |
1456 | \r | |
1457 | Expand OFile by appending zero bytes at the end of OFile.\r | |
1458 | \r | |
1459 | @param OFile - The open file.\r | |
1460 | @param ExpandedSize - The number of zero bytes appended at the end of the file.\r | |
1461 | \r | |
1462 | @retval EFI_SUCCESS - The file is expanded successfully.\r | |
1463 | @return other - An error occurred when expanding file.\r | |
1464 | \r | |
1465 | **/\r | |
b9ec9330 QH |
1466 | EFI_STATUS\r |
1467 | FatExpandOFile (\r | |
1468 | IN FAT_OFILE *OFile,\r | |
1469 | IN UINT64 ExpandedSize\r | |
1470 | );\r | |
1471 | \r | |
205cc663 DB |
1472 | /**\r |
1473 | \r | |
1474 | Write zero pool from the WritePos to the end of OFile.\r | |
1475 | \r | |
1476 | @param OFile - The open file to write zero pool.\r | |
1477 | @param WritePos - The number of zero bytes written.\r | |
1478 | \r | |
1479 | @retval EFI_SUCCESS - Write the zero pool successfully.\r | |
1480 | @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation.\r | |
1481 | @return other - An error occurred when writing disk.\r | |
1482 | \r | |
1483 | **/\r | |
b9ec9330 QH |
1484 | EFI_STATUS\r |
1485 | FatWriteZeroPool (\r | |
1486 | IN FAT_OFILE *OFile,\r | |
1487 | IN UINTN WritePos\r | |
1488 | );\r | |
1489 | \r | |
205cc663 DB |
1490 | /**\r |
1491 | \r | |
1492 | Truncate the OFile to smaller file size.\r | |
1493 | \r | |
1494 | @param OFile - The open file.\r | |
1495 | @param TruncatedSize - The new file size.\r | |
1496 | \r | |
1497 | @retval EFI_SUCCESS - The file is truncated successfully.\r | |
1498 | @return other - An error occurred when truncating file.\r | |
1499 | \r | |
1500 | **/\r | |
b9ec9330 QH |
1501 | EFI_STATUS\r |
1502 | FatTruncateOFile (\r | |
1503 | IN FAT_OFILE *OFile,\r | |
1504 | IN UINTN TruncatedSize\r | |
1505 | );\r | |
1506 | \r | |
1507 | //\r | |
1508 | // DirectoryManage.c\r | |
1509 | //\r | |
205cc663 DB |
1510 | /**\r |
1511 | \r | |
1512 | Set the OFile's current directory cursor to the list head.\r | |
1513 | \r | |
1514 | @param OFile - The directory OFile whose directory cursor is reset.\r | |
1515 | \r | |
1516 | **/\r | |
b9ec9330 QH |
1517 | VOID\r |
1518 | FatResetODirCursor (\r | |
1519 | IN FAT_OFILE *OFile\r | |
1520 | );\r | |
1521 | \r | |
205cc663 DB |
1522 | /**\r |
1523 | \r | |
1524 | Set the directory's cursor to the next and get the next directory entry.\r | |
1525 | \r | |
1526 | @param OFile - The parent OFile.\r | |
1527 | @param PtrDirEnt - The next directory entry.\r | |
1528 | \r | |
1529 | @retval EFI_SUCCESS - We get the next directory entry successfully.\r | |
1530 | @return other - An error occurred when get next directory entry.\r | |
1531 | \r | |
1532 | **/\r | |
b9ec9330 QH |
1533 | EFI_STATUS\r |
1534 | FatGetNextDirEnt (\r | |
c1680e88 | 1535 | IN FAT_OFILE *OFile,\r |
b9ec9330 QH |
1536 | OUT FAT_DIRENT **PtrDirEnt\r |
1537 | );\r | |
1538 | \r | |
205cc663 DB |
1539 | /**\r |
1540 | \r | |
1541 | Remove this directory entry node from the list of directory entries and hash table.\r | |
1542 | \r | |
1543 | @param OFile - The parent OFile.\r | |
1544 | @param DirEnt - The directory entry to be removed.\r | |
1545 | \r | |
1546 | @retval EFI_SUCCESS - The directory entry is successfully removed.\r | |
1547 | @return other - An error occurred when removing the directory entry.\r | |
1548 | \r | |
1549 | **/\r | |
b9ec9330 QH |
1550 | EFI_STATUS\r |
1551 | FatRemoveDirEnt (\r | |
1552 | IN FAT_OFILE *OFile,\r | |
1553 | IN FAT_DIRENT *DirEnt\r | |
1554 | );\r | |
1555 | \r | |
205cc663 DB |
1556 | /**\r |
1557 | \r | |
1558 | Save the directory entry to disk.\r | |
1559 | \r | |
1560 | @param OFile - The parent OFile which needs to update.\r | |
1561 | @param DirEnt - The directory entry to be saved.\r | |
1562 | \r | |
1563 | @retval EFI_SUCCESS - Store the directory entry successfully.\r | |
1564 | @return other - An error occurred when writing the directory entry.\r | |
1565 | \r | |
1566 | **/\r | |
b9ec9330 QH |
1567 | EFI_STATUS\r |
1568 | FatStoreDirEnt (\r | |
1569 | IN FAT_OFILE *OFile,\r | |
1570 | IN FAT_DIRENT *DirEnt\r | |
1571 | );\r | |
1572 | \r | |
205cc663 DB |
1573 | /**\r |
1574 | \r | |
1575 | Create a directory entry in the parent OFile.\r | |
1576 | \r | |
1577 | @param OFile - The parent OFile.\r | |
1578 | @param FileName - The filename of the newly-created directory entry.\r | |
1579 | @param Attributes - The attribute of the newly-created directory entry.\r | |
1580 | @param PtrDirEnt - The pointer to the newly-created directory entry.\r | |
1581 | \r | |
1582 | @retval EFI_SUCCESS - The directory entry is successfully created.\r | |
1583 | @retval EFI_OUT_OF_RESOURCES - Not enough memory to create the directory entry.\r | |
1584 | @return other - An error occurred when creating the directory entry.\r | |
1585 | \r | |
1586 | **/\r | |
b9ec9330 QH |
1587 | EFI_STATUS\r |
1588 | FatCreateDirEnt (\r | |
1589 | IN FAT_OFILE *OFile,\r | |
1590 | IN CHAR16 *FileName,\r | |
1591 | IN UINT8 Attributes,\r | |
1592 | OUT FAT_DIRENT **PtrDirEnt\r | |
1593 | );\r | |
1594 | \r | |
205cc663 DB |
1595 | /**\r |
1596 | \r | |
1597 | Determine whether the directory entry is "." or ".." entry.\r | |
1598 | \r | |
1599 | @param DirEnt - The corresponding directory entry.\r | |
1600 | \r | |
1601 | @retval TRUE - The directory entry is "." or ".." directory entry\r | |
1602 | @retval FALSE - The directory entry is not "." or ".." directory entry\r | |
1603 | \r | |
1604 | **/\r | |
b9ec9330 QH |
1605 | BOOLEAN\r |
1606 | FatIsDotDirEnt (\r | |
1607 | IN FAT_DIRENT *DirEnt\r | |
1608 | );\r | |
1609 | \r | |
205cc663 DB |
1610 | /**\r |
1611 | \r | |
1612 | Set the OFile's cluster and size info in its directory entry.\r | |
1613 | \r | |
1614 | @param OFile - The corresponding OFile.\r | |
1615 | \r | |
1616 | **/\r | |
b9ec9330 QH |
1617 | VOID\r |
1618 | FatUpdateDirEntClusterSizeInfo (\r | |
1619 | IN FAT_OFILE *OFile\r | |
1620 | );\r | |
1621 | \r | |
205cc663 DB |
1622 | /**\r |
1623 | \r | |
1624 | Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.\r | |
1625 | \r | |
1626 | @param DirEnt1 - The destination directory entry.\r | |
1627 | @param DirEnt2 - The source directory entry.\r | |
1628 | \r | |
1629 | **/\r | |
b9ec9330 QH |
1630 | VOID\r |
1631 | FatCloneDirEnt (\r | |
1632 | IN FAT_DIRENT *DirEnt1,\r | |
1633 | IN FAT_DIRENT *DirEnt2\r | |
1634 | );\r | |
1635 | \r | |
205cc663 DB |
1636 | /**\r |
1637 | \r | |
1638 | Get the directory entry's info into Buffer.\r | |
1639 | \r | |
1640 | @param Volume - FAT file system volume.\r | |
1641 | @param DirEnt - The corresponding directory entry.\r | |
1642 | @param BufferSize - Size of Buffer.\r | |
1643 | @param Buffer - Buffer containing file info.\r | |
1644 | \r | |
1645 | @retval EFI_SUCCESS - Get the file info successfully.\r | |
1646 | @retval EFI_BUFFER_TOO_SMALL - The buffer is too small.\r | |
1647 | \r | |
1648 | **/\r | |
b9ec9330 QH |
1649 | EFI_STATUS\r |
1650 | FatGetDirEntInfo (\r | |
1651 | IN FAT_VOLUME *Volume,\r | |
1652 | IN FAT_DIRENT *DirEnt,\r | |
1653 | IN OUT UINTN *BufferSize,\r | |
1654 | OUT VOID *Buffer\r | |
1655 | );\r | |
1656 | \r | |
205cc663 DB |
1657 | /**\r |
1658 | \r | |
1659 | Open the directory entry to get the OFile.\r | |
1660 | \r | |
1661 | @param Parent - The parent OFile.\r | |
1662 | @param DirEnt - The directory entry to be opened.\r | |
1663 | \r | |
1664 | @retval EFI_SUCCESS - The directory entry is successfully opened.\r | |
1665 | @retval EFI_OUT_OF_RESOURCES - not enough memory to allocate a new OFile.\r | |
1666 | @return other - An error occurred when opening the directory entry.\r | |
1667 | \r | |
1668 | **/\r | |
b9ec9330 QH |
1669 | EFI_STATUS\r |
1670 | FatOpenDirEnt (\r | |
1671 | IN FAT_OFILE *OFile,\r | |
1672 | IN FAT_DIRENT *DirEnt\r | |
1673 | );\r | |
1674 | \r | |
205cc663 DB |
1675 | /**\r |
1676 | \r | |
1677 | Create "." and ".." directory entries in the newly-created parent OFile.\r | |
1678 | \r | |
1679 | @param OFile - The parent OFile.\r | |
1680 | \r | |
1681 | @retval EFI_SUCCESS - The dot directory entries are successfully created.\r | |
1682 | @return other - An error occurred when creating the directory entry.\r | |
1683 | \r | |
1684 | **/\r | |
b9ec9330 QH |
1685 | EFI_STATUS\r |
1686 | FatCreateDotDirEnts (\r | |
1687 | IN FAT_OFILE *OFile\r | |
1688 | );\r | |
1689 | \r | |
205cc663 DB |
1690 | /**\r |
1691 | \r | |
1692 | Close the directory entry and free the OFile.\r | |
1693 | \r | |
1694 | @param DirEnt - The directory entry to be closed.\r | |
1695 | \r | |
1696 | **/\r | |
b9ec9330 QH |
1697 | VOID\r |
1698 | FatCloseDirEnt (\r | |
1699 | IN FAT_DIRENT *DirEnt\r | |
1700 | );\r | |
1701 | \r | |
205cc663 DB |
1702 | /**\r |
1703 | \r | |
1704 | Traverse filename and open all OFiles that can be opened.\r | |
1705 | Update filename pointer to the component that can't be opened.\r | |
1706 | If more than one name component remains, returns an error;\r | |
1707 | otherwise, return the remaining name component so that the caller might choose to create it.\r | |
1708 | \r | |
1709 | @param PtrOFile - As input, the reference OFile; as output, the located OFile.\r | |
1710 | @param FileName - The file name relevant to the OFile.\r | |
1711 | @param Attributes - The attribute of the destination OFile.\r | |
1712 | @param NewFileName - The remaining file name.\r | |
1713 | \r | |
1714 | @retval EFI_NOT_FOUND - The file name can't be opened and there is more than one\r | |
1715 | components within the name left (this means the name can\r | |
1716 | not be created either).\r | |
1717 | @retval EFI_INVALID_PARAMETER - The parameter is not valid.\r | |
1718 | @retval EFI_SUCCESS - Open the file successfully.\r | |
1719 | @return other - An error occured when locating the OFile.\r | |
1720 | \r | |
1721 | **/\r | |
b9ec9330 QH |
1722 | EFI_STATUS\r |
1723 | FatLocateOFile (\r | |
1724 | IN OUT FAT_OFILE **PtrOFile,\r | |
1725 | IN CHAR16 *FileName,\r | |
1726 | IN UINT8 Attributes,\r | |
1727 | OUT CHAR16 *NewFileName\r | |
1728 | );\r | |
1729 | \r | |
205cc663 DB |
1730 | /**\r |
1731 | \r | |
1732 | Get the directory entry for the volume.\r | |
1733 | \r | |
1734 | @param Volume - FAT file system volume.\r | |
1735 | @param Name - The file name of the volume.\r | |
1736 | \r | |
1737 | @retval EFI_SUCCESS - Update the volume with the directory entry sucessfully.\r | |
1738 | @return others - An error occurred when getting volume label.\r | |
1739 | \r | |
1740 | **/\r | |
b9ec9330 QH |
1741 | EFI_STATUS\r |
1742 | FatGetVolumeEntry (\r | |
1743 | IN FAT_VOLUME *Volume,\r | |
1744 | IN CHAR16 *Name\r | |
1745 | );\r | |
1746 | \r | |
205cc663 DB |
1747 | /**\r |
1748 | \r | |
1749 | Set the relevant directory entry into disk for the volume.\r | |
1750 | \r | |
1751 | @param Volume - FAT file system volume.\r | |
1752 | @param Name - The new file name of the volume.\r | |
1753 | \r | |
1754 | @retval EFI_SUCCESS - Update the Volume sucessfully.\r | |
1755 | @retval EFI_UNSUPPORTED - The input label is not a valid volume label.\r | |
1756 | @return other - An error occurred when setting volume label.\r | |
1757 | \r | |
1758 | **/\r | |
b9ec9330 QH |
1759 | EFI_STATUS\r |
1760 | FatSetVolumeEntry (\r | |
1761 | IN FAT_VOLUME *Volume,\r | |
1762 | IN CHAR16 *Name\r | |
1763 | );\r | |
1764 | \r | |
1765 | //\r | |
1766 | // Hash.c\r | |
1767 | //\r | |
205cc663 DB |
1768 | /**\r |
1769 | \r | |
1770 | Search the long name hash table for the directory entry.\r | |
1771 | \r | |
1772 | @param ODir - The directory to be searched.\r | |
1773 | @param LongNameString - The long name string to search.\r | |
1774 | \r | |
1775 | @return The previous long name hash node of the directory entry.\r | |
1776 | \r | |
1777 | **/\r | |
b9ec9330 QH |
1778 | FAT_DIRENT **\r |
1779 | FatLongNameHashSearch (\r | |
1780 | IN FAT_ODIR *ODir,\r | |
1781 | IN CHAR16 *LongNameString\r | |
1782 | );\r | |
1783 | \r | |
205cc663 DB |
1784 | /**\r |
1785 | \r | |
1786 | Search the short name hash table for the directory entry.\r | |
1787 | \r | |
1788 | @param ODir - The directory to be searched.\r | |
1789 | @param ShortNameString - The short name string to search.\r | |
1790 | \r | |
1791 | @return The previous short name hash node of the directory entry.\r | |
1792 | \r | |
1793 | **/\r | |
b9ec9330 QH |
1794 | FAT_DIRENT **\r |
1795 | FatShortNameHashSearch (\r | |
1796 | IN FAT_ODIR *ODir,\r | |
1797 | IN CHAR8 *ShortNameString\r | |
1798 | );\r | |
1799 | \r | |
205cc663 DB |
1800 | /**\r |
1801 | \r | |
1802 | Insert directory entry to hash table.\r | |
1803 | \r | |
1804 | @param ODir - The parent directory.\r | |
1805 | @param DirEnt - The directory entry node.\r | |
1806 | \r | |
1807 | **/\r | |
b9ec9330 QH |
1808 | VOID\r |
1809 | FatInsertToHashTable (\r | |
1810 | IN FAT_ODIR *ODir,\r | |
1811 | IN FAT_DIRENT *DirEnt\r | |
1812 | );\r | |
1813 | \r | |
205cc663 DB |
1814 | /**\r |
1815 | \r | |
1816 | Delete directory entry from hash table.\r | |
1817 | \r | |
1818 | @param ODir - The parent directory.\r | |
1819 | @param DirEnt - The directory entry node.\r | |
1820 | \r | |
1821 | **/\r | |
b9ec9330 QH |
1822 | VOID\r |
1823 | FatDeleteFromHashTable (\r | |
1824 | IN FAT_ODIR *ODir,\r | |
1825 | IN FAT_DIRENT *DirEnt\r | |
1826 | );\r | |
1827 | \r | |
1828 | //\r | |
1829 | // FileName.c\r | |
1830 | //\r | |
205cc663 DB |
1831 | /**\r |
1832 | \r | |
1833 | This function checks whether the input FileName is a valid 8.3 short name.\r | |
1834 | If the input FileName is a valid 8.3, the output is the 8.3 short name;\r | |
1835 | otherwise, the output is the base tag of 8.3 short name.\r | |
1836 | \r | |
1837 | @param FileName - The input unicode filename.\r | |
1838 | @param File8Dot3Name - The output ascii 8.3 short name or base tag of 8.3 short name.\r | |
1839 | \r | |
1840 | @retval TRUE - The input unicode filename is a valid 8.3 short name.\r | |
1841 | @retval FALSE - The input unicode filename is not a valid 8.3 short name.\r | |
1842 | \r | |
1843 | **/\r | |
b9ec9330 QH |
1844 | BOOLEAN\r |
1845 | FatCheckIs8Dot3Name (\r | |
1846 | IN CHAR16 *FileName,\r | |
1847 | OUT CHAR8 *File8Dot3Name\r | |
1848 | );\r | |
1849 | \r | |
205cc663 DB |
1850 | /**\r |
1851 | \r | |
1852 | This function generates 8Dot3 name from user specified name for a newly created file.\r | |
1853 | \r | |
1854 | @param Parent - The parent directory.\r | |
1855 | @param DirEnt - The directory entry whose 8Dot3Name needs to be generated.\r | |
1856 | \r | |
1857 | **/\r | |
b9ec9330 QH |
1858 | VOID\r |
1859 | FatCreate8Dot3Name (\r | |
1860 | IN FAT_OFILE *Parent,\r | |
1861 | IN FAT_DIRENT *DirEnt\r | |
1862 | );\r | |
1863 | \r | |
205cc663 DB |
1864 | /**\r |
1865 | \r | |
1866 | Convert the ascii fat name to the unicode string and strip trailing spaces,\r | |
1867 | and if necessary, convert the unicode string to lower case.\r | |
1868 | \r | |
1869 | @param FatName - The Char8 string needs to be converted.\r | |
1870 | @param Len - The length of the fat name.\r | |
1871 | @param LowerCase - Indicate whether to convert the string to lower case.\r | |
1872 | @param Str - The result of the convertion.\r | |
1873 | \r | |
1874 | **/\r | |
b9ec9330 QH |
1875 | VOID\r |
1876 | FatNameToStr (\r | |
1877 | IN CHAR8 *FatName,\r | |
1878 | IN UINTN Len,\r | |
1879 | IN UINTN LowerCase,\r | |
1880 | IN CHAR16 *Str\r | |
1881 | );\r | |
1882 | \r | |
205cc663 DB |
1883 | /**\r |
1884 | \r | |
1885 | Set the caseflag value for the directory entry.\r | |
1886 | \r | |
1887 | @param DirEnt - The logical directory entry whose caseflag value is to be set.\r | |
1888 | \r | |
1889 | **/\r | |
b9ec9330 QH |
1890 | VOID\r |
1891 | FatSetCaseFlag (\r | |
1892 | IN FAT_DIRENT *DirEnt\r | |
1893 | );\r | |
1894 | \r | |
205cc663 DB |
1895 | /**\r |
1896 | \r | |
1897 | Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.\r | |
1898 | \r | |
1899 | @param DirEnt - The corresponding directory entry.\r | |
1900 | @param FileString - The output Unicode file name.\r | |
1901 | @param FileStringMax The max length of FileString.\r | |
1902 | \r | |
1903 | **/\r | |
b9ec9330 QH |
1904 | VOID\r |
1905 | FatGetFileNameViaCaseFlag (\r | |
e76bc43e HW |
1906 | IN FAT_DIRENT *DirEnt,\r |
1907 | IN OUT CHAR16 *FileString,\r | |
1908 | IN UINTN FileStringMax\r | |
b9ec9330 QH |
1909 | );\r |
1910 | \r | |
205cc663 DB |
1911 | /**\r |
1912 | \r | |
1913 | Get the Check sum for a short name.\r | |
1914 | \r | |
1915 | @param ShortNameString - The short name for a file.\r | |
1916 | \r | |
1917 | @retval Sum - UINT8 checksum.\r | |
1918 | \r | |
1919 | **/\r | |
b9ec9330 QH |
1920 | UINT8\r |
1921 | FatCheckSum (\r | |
1922 | IN CHAR8 *ShortNameString\r | |
1923 | );\r | |
1924 | \r | |
205cc663 DB |
1925 | /**\r |
1926 | \r | |
1927 | Takes Path as input, returns the next name component\r | |
1928 | in Name, and returns the position after Name (e.g., the\r | |
1929 | start of the next name component)\r | |
1930 | \r | |
1931 | @param Path - The path of one file.\r | |
1932 | @param Name - The next name component in Path.\r | |
1933 | \r | |
1934 | The position after Name in the Path\r | |
1935 | \r | |
1936 | **/\r | |
b9ec9330 QH |
1937 | CHAR16*\r |
1938 | FatGetNextNameComponent (\r | |
1939 | IN CHAR16 *Path,\r | |
1940 | OUT CHAR16 *Name\r | |
1941 | );\r | |
1942 | \r | |
205cc663 DB |
1943 | /**\r |
1944 | \r | |
1945 | Check whether the IFileName is valid long file name. If the IFileName is a valid\r | |
1946 | long file name, then we trim the possible leading blanks and leading/trailing dots.\r | |
1947 | the trimmed filename is stored in OutputFileName\r | |
1948 | \r | |
1949 | @param InputFileName - The input file name.\r | |
1950 | @param OutputFileName - The output file name.\r | |
1951 | \r | |
1952 | @retval TRUE - The InputFileName is a valid long file name.\r | |
1953 | @retval FALSE - The InputFileName is not a valid long file name.\r | |
1954 | \r | |
1955 | **/\r | |
b9ec9330 QH |
1956 | BOOLEAN\r |
1957 | FatFileNameIsValid (\r | |
1958 | IN CHAR16 *InputFileName,\r | |
1959 | OUT CHAR16 *OutputFileName\r | |
1960 | );\r | |
1961 | \r | |
1962 | //\r | |
1963 | // DirectoryCache.c\r | |
1964 | //\r | |
205cc663 DB |
1965 | /**\r |
1966 | \r | |
1967 | Discard the directory structure when an OFile will be freed.\r | |
1968 | Volume will cache this directory if the OFile does not represent a deleted file.\r | |
1969 | \r | |
1970 | @param OFile - The OFile whose directory structure is to be discarded.\r | |
1971 | \r | |
1972 | **/\r | |
b9ec9330 QH |
1973 | VOID\r |
1974 | FatDiscardODir (\r | |
1975 | IN FAT_OFILE *OFile\r | |
1976 | );\r | |
1977 | \r | |
205cc663 DB |
1978 | /**\r |
1979 | \r | |
1980 | Request the directory structure when an OFile is newly generated.\r | |
1981 | If the directory structure is cached by volume, then just return this directory;\r | |
1982 | Otherwise, allocate a new one for OFile.\r | |
1983 | \r | |
1984 | @param OFile - The OFile which requests directory structure.\r | |
1985 | \r | |
1986 | **/\r | |
b9ec9330 QH |
1987 | VOID\r |
1988 | FatRequestODir (\r | |
1989 | IN FAT_OFILE *OFile\r | |
1990 | );\r | |
1991 | \r | |
205cc663 DB |
1992 | /**\r |
1993 | \r | |
1994 | Clean up all the cached directory structures when the volume is going to be abandoned.\r | |
1995 | \r | |
1996 | @param Volume - FAT file system volume.\r | |
1997 | \r | |
1998 | **/\r | |
b9ec9330 QH |
1999 | VOID\r |
2000 | FatCleanupODirCache (\r | |
2001 | IN FAT_VOLUME *Volume\r | |
2002 | );\r | |
2003 | \r | |
2004 | //\r | |
2005 | // Global Variables\r | |
2006 | //\r | |
2007 | extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;\r | |
2008 | extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;\r | |
2009 | extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;\r | |
2010 | extern EFI_LOCK FatFsLock;\r | |
149d6335 | 2011 | extern EFI_LOCK FatTaskLock;\r |
dba03ba1 | 2012 | extern EFI_FILE_PROTOCOL FatFileInterface;\r |
b9ec9330 QH |
2013 | \r |
2014 | #endif\r |