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