]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Fat.h
f49acee24e65eeec87beec48f6c45de72c15e82c
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Fat.h
1 /*++
2
3 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 Fat.h
16
17 Abstract:
18
19 Main header file for EFI FAT file system driver
20
21 Revision History
22
23 --*/
24
25 #ifndef _FAT_H_
26 #define _FAT_H_
27
28 #include <Uefi.h>
29
30 #include <Guid/FileInfo.h>
31 #include <Guid/FileSystemInfo.h>
32 #include <Guid/FileSystemVolumeLabelInfo.h>
33 #include <Protocol/BlockIo.h>
34 #include <Protocol/DiskIo.h>
35 #include <Protocol/DiskIo2.h>
36 #include <Protocol/SimpleFileSystem.h>
37 #include <Protocol/UnicodeCollation.h>
38
39 #include <Library/PcdLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/UefiLib.h>
42 #include <Library/BaseLib.h>
43 #include <Library/BaseMemoryLib.h>
44 #include <Library/MemoryAllocationLib.h>
45 #include <Library/UefiDriverEntryPoint.h>
46 #include <Library/UefiBootServicesTableLib.h>
47 #include <Library/UefiRuntimeServicesTableLib.h>
48
49 #include "FatFileSystem.h"
50
51 //
52 // The FAT signature
53 //
54 #define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
55 #define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
56 #define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
57 #define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
58 #define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
59 #define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
60 #define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
61
62 #define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
63
64 #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
65
66 #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
67
68 #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
69
70 #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
71
72 #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
73
74 #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
75
76 #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
77
78 //
79 // Minimum sector size is 512B, Maximum sector size is 4096B
80 // Max sectors per cluster is 128
81 //
82 #define MAX_BLOCK_ALIGNMENT 12
83 #define MIN_BLOCK_ALIGNMENT 9
84 #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
85
86 //
87 // Efi Time Definition
88 //
89 #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
90
91 //
92 // Minimum fat page size is 8K, maximum fat page alignment is 32K
93 // Minimum data page size is 8K, maximum fat page alignment is 64K
94 //
95 #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13
96 #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15
97 #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13
98 #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16
99 #define FAT_DATACACHE_GROUP_COUNT 64
100 #define FAT_FATCACHE_GROUP_MIN_COUNT 1
101 #define FAT_FATCACHE_GROUP_MAX_COUNT 16
102
103 //
104 // Used in 8.3 generation algorithm
105 //
106 #define MAX_SPEC_RETRY 4
107 #define SPEC_BASE_TAG_LEN 6
108 #define HASH_BASE_TAG_LEN 2
109 #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
110
111 //
112 // Path name separator is back slash
113 //
114 #define PATH_NAME_SEPARATOR L'\\'
115
116
117 #define EFI_PATH_STRING_LENGTH 260
118 #define EFI_FILE_STRING_LENGTH 255
119 #define FAT_MAX_ALLOCATE_SIZE 0xA00000
120 #define LC_ISO_639_2_ENTRY_SIZE 3
121 #define MAX_LANG_CODE_SIZE 100
122
123 #define FAT_MAX_DIR_CACHE_COUNT 8
124 #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
125 typedef CHAR8 LC_ISO_639_2;
126
127 //
128 // The fat types we support
129 //
130 typedef enum {
131 Fat12,
132 Fat16,
133 Fat32,
134 FatUndefined
135 } FAT_VOLUME_TYPE;
136
137 typedef enum {
138 CacheFat,
139 CacheData,
140 CacheMaxType
141 } CACHE_DATA_TYPE;
142
143 //
144 // Used in FatDiskIo
145 //
146 typedef enum {
147 ReadDisk = 0, // raw disk read
148 WriteDisk = 1, // raw disk write
149 ReadFat = 2, // read fat cache
150 WriteFat = 3, // write fat cache
151 ReadData = 6, // read data cache
152 WriteData = 7 // write data cache
153 } IO_MODE;
154
155 #define CACHE_ENABLED(a) ((a) >= 2)
156 #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
157 #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
158
159 //
160 // Disk cache tag
161 //
162 typedef struct {
163 UINTN PageNo;
164 UINTN RealSize;
165 BOOLEAN Dirty;
166 } CACHE_TAG;
167
168 typedef struct {
169 UINT64 BaseAddress;
170 UINT64 LimitAddress;
171 UINT8 *CacheBase;
172 BOOLEAN Dirty;
173 UINT8 PageAlignment;
174 UINTN GroupMask;
175 CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
176 } DISK_CACHE;
177
178 //
179 // Hash table size
180 //
181 #define HASH_TABLE_SIZE 0x400
182 #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
183
184 //
185 // The directory entry for opened directory
186 //
187
188 typedef struct _FAT_DIRENT FAT_DIRENT;
189 typedef struct _FAT_ODIR FAT_ODIR;
190 typedef struct _FAT_OFILE FAT_OFILE;
191 typedef struct _FAT_VOLUME FAT_VOLUME;
192
193 struct _FAT_DIRENT {
194 UINTN Signature;
195 UINT16 EntryPos; // The position of this directory entry in the parent directory file
196 UINT8 EntryCount; // The count of the directory entry in the parent directory file
197 BOOLEAN Invalid; // Indicate whether this directory entry is valid
198 CHAR16 *FileString; // The unicode long file name for this directory entry
199 FAT_OFILE *OFile; // The OFile of the corresponding directory entry
200 FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename
201 FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename
202 LIST_ENTRY Link; // Connection of every directory entry
203 FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk
204 };
205
206 struct _FAT_ODIR {
207 UINTN Signature;
208 UINT32 CurrentEndPos; // Current end position of the directory
209 UINT32 CurrentPos; // Current position of the directory
210 LIST_ENTRY *CurrentCursor; // Current directory entry pointer
211 LIST_ENTRY ChildList; // List of all directory entries
212 BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory
213 LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded
214 UINTN DirCacheTag; // The identification of the directory when in directory cache
215 FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
216 FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
217 };
218
219 typedef struct {
220 UINTN Signature;
221 EFI_FILE_PROTOCOL Handle;
222 UINT64 Position;
223 BOOLEAN ReadOnly;
224 FAT_OFILE *OFile;
225 LIST_ENTRY Tasks; // List of all FAT_TASKs
226 LIST_ENTRY Link; // Link to other IFiles
227 } FAT_IFILE;
228
229 typedef struct {
230 UINTN Signature;
231 EFI_FILE_IO_TOKEN *FileIoToken;
232 FAT_IFILE *IFile;
233 LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs
234 LIST_ENTRY Link; // Link to other FAT_TASKs
235 } FAT_TASK;
236
237 typedef struct {
238 UINTN Signature;
239 EFI_DISK_IO2_TOKEN DiskIo2Token;
240 FAT_TASK *Task;
241 BOOLEAN Write;
242 UINT64 Offset;
243 VOID *Buffer;
244 UINTN BufferSize;
245 LIST_ENTRY Link;
246 } FAT_SUBTASK;
247
248 //
249 // FAT_OFILE - Each opened file
250 //
251 struct _FAT_OFILE {
252 UINTN Signature;
253 FAT_VOLUME *Volume;
254 //
255 // A permanant error code to return to all accesses to
256 // this opened file
257 //
258 EFI_STATUS Error;
259 //
260 // A list of the IFILE instances for this OFile
261 //
262 LIST_ENTRY Opens;
263
264 //
265 // The dynamic infomation
266 //
267 UINTN FileSize;
268 UINTN FileCluster;
269 UINTN FileCurrentCluster;
270 UINTN FileLastCluster;
271
272 //
273 // Dirty is set if there have been any updates to the
274 // file
275 // Archive is set if the archive attribute in the file's
276 // directory entry needs to be set when performing flush
277 // PreserveLastMod is set if the last modification of the
278 // file is specified by SetInfo API
279 //
280 BOOLEAN Dirty;
281 BOOLEAN IsFixedRootDir;
282 BOOLEAN PreserveLastModification;
283 BOOLEAN Archive;
284 //
285 // Set by an OFile SetPosition
286 //
287 UINTN Position; // within file
288 UINT64 PosDisk; // on the disk
289 UINTN PosRem; // remaining in this disk run
290 //
291 // The opened parent, full path length and currently opened child files
292 //
293 FAT_OFILE *Parent;
294 UINTN FullPathLen;
295 LIST_ENTRY ChildHead;
296 LIST_ENTRY ChildLink;
297
298 //
299 // The opened directory structure for a directory; if this
300 // OFile represents a file, then ODir = NULL
301 //
302 FAT_ODIR *ODir;
303 //
304 // The directory entry for the Ofile
305 //
306 FAT_DIRENT *DirEnt;
307
308 //
309 // Link in Volume's reference list
310 //
311 LIST_ENTRY CheckLink;
312 };
313
314 struct _FAT_VOLUME {
315 UINTN Signature;
316
317 EFI_HANDLE Handle;
318 BOOLEAN Valid;
319 BOOLEAN DiskError;
320
321 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;
322
323 //
324 // If opened, the parent handle and BlockIo interface
325 //
326 EFI_BLOCK_IO_PROTOCOL *BlockIo;
327 EFI_DISK_IO_PROTOCOL *DiskIo;
328 EFI_DISK_IO2_PROTOCOL *DiskIo2;
329 UINT32 MediaId;
330 BOOLEAN ReadOnly;
331
332 //
333 // Computed values from fat bpb info
334 //
335 UINT64 VolumeSize;
336 UINT64 FatPos; // Disk pos of fat tables
337 UINT64 RootPos; // Disk pos of root directory
338 UINT64 FirstClusterPos; // Disk pos of first cluster
339 UINTN FatSize; // Number of bytes in each fat
340 UINTN MaxCluster; // Max cluster number
341 UINTN ClusterSize; // Cluster size of fat partition
342 UINT8 ClusterAlignment; // Equal to log_2 (clustersize);
343 FAT_VOLUME_TYPE FatType;
344
345 //
346 // Current part of fat table that's present
347 //
348 UINT64 FatEntryPos; // Location of buffer
349 UINTN FatEntrySize; // Size of buffer
350 UINT32 FatEntryBuffer; // The buffer
351 FAT_INFO_SECTOR FatInfoSector; // Free cluster info
352 UINTN FreeInfoPos; // Pos with the free cluster info
353 BOOLEAN FreeInfoValid; // If free cluster info is valid
354 //
355 // Unpacked Fat BPB info
356 //
357 UINTN NumFats;
358 UINTN RootEntries; // < FAT32, root dir is fixed size
359 UINTN RootCluster; // >= FAT32, root cluster chain head
360 //
361 // info for marking the volume dirty or not
362 //
363 BOOLEAN FatDirty; // If fat-entries have been updated
364 UINT32 DirtyValue;
365 UINT32 NotDirtyValue;
366
367 //
368 // The root directory entry and opened root file
369 //
370 FAT_DIRENT RootDirEnt;
371 //
372 // File Name of root OFile, it is empty string
373 //
374 CHAR16 RootFileString[1];
375 FAT_OFILE *Root;
376
377 //
378 // New OFiles are added to this list so they
379 // can be cleaned up if they aren't referenced.
380 //
381 LIST_ENTRY CheckRef;
382
383 //
384 // Directory cache List
385 //
386 LIST_ENTRY DirCacheList;
387 UINTN DirCacheCount;
388
389 //
390 // Disk Cache for this volume
391 //
392 VOID *CacheBuffer;
393 DISK_CACHE DiskCache[CacheMaxType];
394 };
395
396 //
397 // Function Prototypes
398 //
399 EFI_STATUS
400 EFIAPI
401 FatOpen (
402 IN EFI_FILE_PROTOCOL *FHand,
403 OUT EFI_FILE_PROTOCOL **NewHandle,
404 IN CHAR16 *FileName,
405 IN UINT64 OpenMode,
406 IN UINT64 Attributes
407 )
408 /*++
409 Routine Description:
410
411 Implements Open() of Simple File System Protocol.
412
413 Arguments:
414
415 FHand - File handle of the file serves as a starting reference point.
416 NewHandle - Handle of the file that is newly opened.
417 FileName - File name relative to FHand.
418 OpenMode - Open mode.
419 Attributes - Attributes to set if the file is created.
420
421 Returns:
422
423 EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
424 The OpenMode is not supported.
425 The Attributes is not the valid attributes.
426 EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
427 EFI_SUCCESS - Open the file successfully.
428 Others - The status of open file.
429
430 --*/
431 ;
432
433 EFI_STATUS
434 EFIAPI
435 FatOpenEx (
436 IN EFI_FILE_PROTOCOL *FHand,
437 OUT EFI_FILE_PROTOCOL **NewHandle,
438 IN CHAR16 *FileName,
439 IN UINT64 OpenMode,
440 IN UINT64 Attributes,
441 IN OUT EFI_FILE_IO_TOKEN *Token
442 )
443 /*++
444 Routine Description:
445
446 Implements OpenEx() of Simple File System Protocol.
447
448 Arguments:
449
450 FHand - File handle of the file serves as a starting reference point.
451 NewHandle - Handle of the file that is newly opened.
452 FileName - File name relative to FHand.
453 OpenMode - Open mode.
454 Attributes - Attributes to set if the file is created.
455 Token - A pointer to the token associated with the transaction.
456
457 Returns:
458
459 EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
460 The OpenMode is not supported.
461 The Attributes is not the valid attributes.
462 EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
463 EFI_SUCCESS - Open the file successfully.
464 Others - The status of open file.
465
466 --*/
467 ;
468
469 EFI_STATUS
470 EFIAPI
471 FatGetPosition (
472 IN EFI_FILE_PROTOCOL *FHand,
473 OUT UINT64 *Position
474 )
475 /*++
476
477 Routine Description:
478
479 Get the file's position of the file
480
481 Arguments:
482
483 FHand - The handle of file.
484 Position - The file's position of the file.
485
486 Returns:
487
488 EFI_SUCCESS - Get the info successfully.
489 EFI_DEVICE_ERROR - Can not find the OFile for the file.
490 EFI_UNSUPPORTED - The open file is not a file.
491
492 --*/
493 ;
494
495 EFI_STATUS
496 EFIAPI
497 FatGetInfo (
498 IN EFI_FILE_PROTOCOL *FHand,
499 IN EFI_GUID *Type,
500 IN OUT UINTN *BufferSize,
501 OUT VOID *Buffer
502 )
503 /*++
504
505 Routine Description:
506
507 Get the some types info of the file into Buffer
508
509 Arguments:
510
511 FHand - The handle of file.
512 Type - The type of the info.
513 BufferSize - Size of Buffer.
514 Buffer - Buffer containing volume info.
515
516 Returns:
517
518 EFI_SUCCESS - Get the info successfully.
519 EFI_DEVICE_ERROR - Can not find the OFile for the file.
520
521 --*/
522 ;
523
524 EFI_STATUS
525 EFIAPI
526 FatSetInfo (
527 IN EFI_FILE_PROTOCOL *FHand,
528 IN EFI_GUID *Type,
529 IN UINTN BufferSize,
530 IN VOID *Buffer
531 )
532 /*++
533
534 Routine Description:
535
536 Set the some types info of the file into Buffer
537
538 Arguments:
539
540 FHand - The handle of file.
541 Type - The type of the info.
542 BufferSize - Size of Buffer.
543 Buffer - Buffer containing volume info.
544
545 Returns:
546
547 EFI_SUCCESS - Set the info successfully.
548 EFI_DEVICE_ERROR - Can not find the OFile for the file.
549
550 --*/
551 ;
552
553 EFI_STATUS
554 EFIAPI
555 FatFlush (
556 IN EFI_FILE_PROTOCOL *FHand
557 )
558 /*++
559
560 Routine Description:
561
562 Flushes all data associated with the file handle
563
564 Arguments:
565
566 FHand - Handle to file to flush
567
568 Returns:
569
570 EFI_SUCCESS - Flushed the file successfully
571 EFI_WRITE_PROTECTED - The volume is read only
572 EFI_ACCESS_DENIED - The volume is not read only
573 but the file is read only
574 Others - Flushing of the file is failed
575
576 --*/
577 ;
578
579 EFI_STATUS
580 EFIAPI
581 FatFlushEx (
582 IN EFI_FILE_PROTOCOL *FHand,
583 IN EFI_FILE_IO_TOKEN *Token
584 )
585 /*++
586
587 Routine Description:
588
589 Flushes all data associated with the file handle.
590
591 Arguments:
592
593 FHand - Handle to file to flush.
594 Token - A pointer to the token associated with the transaction.
595
596 Returns:
597
598 EFI_SUCCESS - Flushed the file successfully.
599 EFI_WRITE_PROTECTED - The volume is read only.
600 EFI_ACCESS_DENIED - The file is read only.
601 Others - Flushing of the file failed.
602
603 --*/
604 ;
605
606 EFI_STATUS
607 EFIAPI
608 FatClose (
609 IN EFI_FILE_PROTOCOL *FHand
610 )
611 /*++
612
613 Routine Description:
614
615 Flushes & Closes the file handle.
616
617 Arguments:
618
619 FHand - Handle to the file to delete.
620
621 Returns:
622
623 EFI_SUCCESS - Closed the file successfully.
624
625 --*/
626 ;
627
628 EFI_STATUS
629 EFIAPI
630 FatDelete (
631 IN EFI_FILE_PROTOCOL *FHand
632 )
633 /*++
634
635 Routine Description:
636
637 Deletes the file & Closes the file handle.
638
639 Arguments:
640
641 FHand - Handle to the file to delete.
642
643 Returns:
644
645 EFI_SUCCESS - Delete the file successfully.
646 EFI_WARN_DELETE_FAILURE - Fail to delete the file.
647
648 --*/
649 ;
650
651 EFI_STATUS
652 EFIAPI
653 FatSetPosition (
654 IN EFI_FILE_PROTOCOL *FHand,
655 IN UINT64 Position
656 )
657 /*++
658
659 Routine Description:
660
661 Set the file's position of the file
662
663 Arguments:
664
665 FHand - The handle of file
666 Position - The file's position of the file
667
668 Returns:
669
670 EFI_SUCCESS - Set the info successfully
671 EFI_DEVICE_ERROR - Can not find the OFile for the file
672 EFI_UNSUPPORTED - Set a directory with a not-zero position
673
674 --*/
675 ;
676
677 EFI_STATUS
678 EFIAPI
679 FatRead (
680 IN EFI_FILE_PROTOCOL *FHand,
681 IN OUT UINTN *BufferSize,
682 OUT VOID *Buffer
683 )
684 /*++
685
686 Routine Description:
687
688 Get the file info.
689
690 Arguments:
691
692 FHand - The handle of the file.
693 BufferSize - Size of Buffer.
694 Buffer - Buffer containing read data.
695
696 Returns:
697
698 EFI_SUCCESS - Get the file info successfully.
699 EFI_DEVICE_ERROR - Can not find the OFile for the file.
700 EFI_VOLUME_CORRUPTED - The file type of open file is error.
701 other - An error occurred when operation the disk.
702
703 --*/
704 ;
705
706 EFI_STATUS
707 EFIAPI
708 FatReadEx (
709 IN EFI_FILE_PROTOCOL *FHand,
710 IN OUT EFI_FILE_IO_TOKEN *Token
711 )
712 /*++
713
714 Routine Description:
715
716 Get the file info.
717
718 Arguments:
719
720 FHand - The handle of the file.
721 Token - A pointer to the token associated with the transaction.
722
723 Returns:
724
725 EFI_SUCCESS - Get the file info successfully.
726 EFI_DEVICE_ERROR - Can not find the OFile for the file.
727 EFI_VOLUME_CORRUPTED - The file type of open file is error.
728 other - An error occurred when operation the disk.
729
730 --*/
731 ;
732
733 EFI_STATUS
734 EFIAPI
735 FatWrite (
736 IN EFI_FILE_PROTOCOL *FHand,
737 IN OUT UINTN *BufferSize,
738 IN VOID *Buffer
739 )
740 /*++
741
742 Routine Description:
743
744 Set the file info.
745
746 Arguments:
747
748 FHand - The handle of the file.
749 BufferSize - Size of Buffer.
750 Buffer - Buffer containing write data.
751
752 Returns:
753
754 EFI_SUCCESS - Set the file info successfully.
755 EFI_WRITE_PROTECTED - The disk is write protected.
756 EFI_ACCESS_DENIED - The file is read-only.
757 EFI_DEVICE_ERROR - The OFile is not valid.
758 EFI_UNSUPPORTED - The open file is not a file.
759 - The writing file size is larger than 4GB.
760 other - An error occurred when operation the disk.
761
762 --*/
763 ;
764
765 EFI_STATUS
766 EFIAPI
767 FatWriteEx (
768 IN EFI_FILE_PROTOCOL *FHand,
769 IN OUT EFI_FILE_IO_TOKEN *Token
770 )
771 /*++
772
773 Routine Description:
774
775 Get the file info.
776
777 Arguments:
778
779 FHand - The handle of the file.
780 Token - A pointer to the token associated with the transaction.
781
782 Returns:
783
784 EFI_SUCCESS - Get the file info successfully.
785 EFI_DEVICE_ERROR - Can not find the OFile for the file.
786 EFI_VOLUME_CORRUPTED - The file type of open file is error.
787 other - An error occurred when operation the disk.
788
789 --*/
790 ;
791
792 //
793 // DiskCache.c
794 //
795 EFI_STATUS
796 FatInitializeDiskCache (
797 IN FAT_VOLUME *Volume
798 );
799
800 EFI_STATUS
801 FatAccessCache (
802 IN FAT_VOLUME *Volume,
803 IN CACHE_DATA_TYPE CacheDataType,
804 IN IO_MODE IoMode,
805 IN UINT64 Offset,
806 IN UINTN BufferSize,
807 IN OUT UINT8 *Buffer,
808 IN FAT_TASK *Task
809 );
810
811 EFI_STATUS
812 FatVolumeFlushCache (
813 IN FAT_VOLUME *Volume,
814 IN FAT_TASK *Task
815 );
816
817 //
818 // Flush.c
819 //
820 EFI_STATUS
821 FatOFileFlush (
822 IN FAT_OFILE *OFile
823 );
824
825 BOOLEAN
826 FatCheckOFileRef (
827 IN FAT_OFILE *OFile
828 );
829
830 VOID
831 FatSetVolumeError (
832 IN FAT_OFILE *OFile,
833 IN EFI_STATUS Status
834 );
835
836 EFI_STATUS
837 FatIFileClose (
838 FAT_IFILE *IFile
839 );
840
841 EFI_STATUS
842 FatCleanupVolume (
843 IN FAT_VOLUME *Volume,
844 IN FAT_OFILE *OFile,
845 IN EFI_STATUS EfiStatus,
846 IN FAT_TASK *Task
847 );
848
849 //
850 // FileSpace.c
851 //
852 EFI_STATUS
853 FatShrinkEof (
854 IN FAT_OFILE *OFile
855 );
856
857 EFI_STATUS
858 FatGrowEof (
859 IN FAT_OFILE *OFile,
860 IN UINT64 NewSizeInBytes
861 );
862
863 UINTN
864 FatPhysicalDirSize (
865 IN FAT_VOLUME *Volume,
866 IN UINTN Cluster
867 );
868
869 UINT64
870 FatPhysicalFileSize (
871 IN FAT_VOLUME *Volume,
872 IN UINTN RealSize
873 );
874
875 EFI_STATUS
876 FatOFilePosition (
877 IN FAT_OFILE *OFile,
878 IN UINTN Position,
879 IN UINTN PosLimit
880 );
881
882 VOID
883 FatComputeFreeInfo (
884 IN FAT_VOLUME *Volume
885 );
886
887 //
888 // Init.c
889 //
890 EFI_STATUS
891 FatAllocateVolume (
892 IN EFI_HANDLE Handle,
893 IN EFI_DISK_IO_PROTOCOL *DiskIo,
894 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
895 IN EFI_BLOCK_IO_PROTOCOL *BlockIo
896 );
897
898 EFI_STATUS
899 FatOpenDevice (
900 IN OUT FAT_VOLUME *Volume
901 );
902
903 EFI_STATUS
904 FatAbandonVolume (
905 IN FAT_VOLUME *Volume
906 );
907
908 //
909 // Misc.c
910 //
911 FAT_TASK *
912 FatCreateTask (
913 FAT_IFILE *IFile,
914 EFI_FILE_IO_TOKEN *Token
915 );
916
917 VOID
918 FatDestroyTask (
919 FAT_TASK *Task
920 );
921
922 VOID
923 FatWaitNonblockingTask (
924 FAT_IFILE *IFile
925 );
926
927 LIST_ENTRY *
928 FatDestroySubtask (
929 FAT_SUBTASK *Subtask
930 );
931
932 EFI_STATUS
933 FatQueueTask (
934 IN FAT_IFILE *IFile,
935 IN FAT_TASK *Task
936 );
937
938 EFI_STATUS
939 FatAccessVolumeDirty (
940 IN FAT_VOLUME *Volume,
941 IN IO_MODE IoMode,
942 IN VOID *DirtyValue
943 );
944
945 EFI_STATUS
946 FatDiskIo (
947 IN FAT_VOLUME *Volume,
948 IN IO_MODE IoMode,
949 IN UINT64 Offset,
950 IN UINTN BufferSize,
951 IN OUT VOID *Buffer,
952 IN FAT_TASK *Task
953 );
954
955 VOID
956 FatAcquireLock (
957 VOID
958 );
959
960 VOID
961 FatReleaseLock (
962 VOID
963 );
964
965 EFI_STATUS
966 FatAcquireLockOrFail (
967 VOID
968 );
969
970 VOID
971 FatFreeDirEnt (
972 IN FAT_DIRENT *DirEnt
973 );
974
975 VOID
976 FatFreeVolume (
977 IN FAT_VOLUME *Volume
978 );
979
980 VOID
981 FatEfiTimeToFatTime (
982 IN EFI_TIME *ETime,
983 OUT FAT_DATE_TIME *FTime
984 );
985
986 VOID
987 FatFatTimeToEfiTime (
988 IN FAT_DATE_TIME *FTime,
989 OUT EFI_TIME *ETime
990 );
991
992 VOID
993 FatGetCurrentFatTime (
994 OUT FAT_DATE_TIME *FatTime
995 );
996
997 BOOLEAN
998 FatIsValidTime (
999 IN EFI_TIME *Time
1000 );
1001
1002 //
1003 // UnicodeCollation.c
1004 //
1005 EFI_STATUS
1006 InitializeUnicodeCollationSupport (
1007 IN EFI_HANDLE AgentHandle
1008 );
1009
1010 VOID
1011 FatFatToStr (
1012 IN UINTN FatSize,
1013 IN CHAR8 *Fat,
1014 OUT CHAR16 *String
1015 );
1016
1017 BOOLEAN
1018 FatStrToFat (
1019 IN CHAR16 *String,
1020 IN UINTN FatSize,
1021 OUT CHAR8 *Fat
1022 );
1023
1024 VOID
1025 FatStrLwr (
1026 IN CHAR16 *Str
1027 );
1028
1029 VOID
1030 FatStrUpr (
1031 IN CHAR16 *Str
1032 );
1033
1034 INTN
1035 FatStriCmp (
1036 IN CHAR16 *Str1,
1037 IN CHAR16 *Str2
1038 );
1039
1040 //
1041 // Open.c
1042 //
1043 EFI_STATUS
1044 FatOFileOpen (
1045 IN FAT_OFILE *OFile,
1046 OUT FAT_IFILE **NewIFile,
1047 IN CHAR16 *FileName,
1048 IN UINT64 OpenMode,
1049 IN UINT8 Attributes
1050 );
1051
1052 EFI_STATUS
1053 FatAllocateIFile (
1054 IN FAT_OFILE *OFile,
1055 OUT FAT_IFILE **PtrIFile
1056 );
1057
1058 //
1059 // OpenVolume.c
1060 //
1061 EFI_STATUS
1062 EFIAPI
1063 FatOpenVolume (
1064 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
1065 OUT EFI_FILE_PROTOCOL **File
1066 );
1067
1068 //
1069 // ReadWrite.c
1070 //
1071 EFI_STATUS
1072 FatAccessOFile (
1073 IN FAT_OFILE *OFile,
1074 IN IO_MODE IoMode,
1075 IN UINTN Position,
1076 IN UINTN *DataBufferSize,
1077 IN UINT8 *UserBuffer,
1078 IN FAT_TASK *Task
1079 );
1080
1081 EFI_STATUS
1082 FatExpandOFile (
1083 IN FAT_OFILE *OFile,
1084 IN UINT64 ExpandedSize
1085 );
1086
1087 EFI_STATUS
1088 FatWriteZeroPool (
1089 IN FAT_OFILE *OFile,
1090 IN UINTN WritePos
1091 );
1092
1093 EFI_STATUS
1094 FatTruncateOFile (
1095 IN FAT_OFILE *OFile,
1096 IN UINTN TruncatedSize
1097 );
1098
1099 //
1100 // DirectoryManage.c
1101 //
1102 VOID
1103 FatResetODirCursor (
1104 IN FAT_OFILE *OFile
1105 );
1106
1107 EFI_STATUS
1108 FatGetNextDirEnt (
1109 IN FAT_OFILE *OFile,
1110 OUT FAT_DIRENT **PtrDirEnt
1111 );
1112
1113 EFI_STATUS
1114 FatRemoveDirEnt (
1115 IN FAT_OFILE *OFile,
1116 IN FAT_DIRENT *DirEnt
1117 );
1118
1119 EFI_STATUS
1120 FatStoreDirEnt (
1121 IN FAT_OFILE *OFile,
1122 IN FAT_DIRENT *DirEnt
1123 );
1124
1125 EFI_STATUS
1126 FatCreateDirEnt (
1127 IN FAT_OFILE *OFile,
1128 IN CHAR16 *FileName,
1129 IN UINT8 Attributes,
1130 OUT FAT_DIRENT **PtrDirEnt
1131 );
1132
1133 BOOLEAN
1134 FatIsDotDirEnt (
1135 IN FAT_DIRENT *DirEnt
1136 );
1137
1138 VOID
1139 FatUpdateDirEntClusterSizeInfo (
1140 IN FAT_OFILE *OFile
1141 );
1142
1143 VOID
1144 FatCloneDirEnt (
1145 IN FAT_DIRENT *DirEnt1,
1146 IN FAT_DIRENT *DirEnt2
1147 );
1148
1149 EFI_STATUS
1150 FatGetDirEntInfo (
1151 IN FAT_VOLUME *Volume,
1152 IN FAT_DIRENT *DirEnt,
1153 IN OUT UINTN *BufferSize,
1154 OUT VOID *Buffer
1155 );
1156
1157 EFI_STATUS
1158 FatOpenDirEnt (
1159 IN FAT_OFILE *OFile,
1160 IN FAT_DIRENT *DirEnt
1161 );
1162
1163 EFI_STATUS
1164 FatCreateDotDirEnts (
1165 IN FAT_OFILE *OFile
1166 );
1167
1168 VOID
1169 FatCloseDirEnt (
1170 IN FAT_DIRENT *DirEnt
1171 );
1172
1173 EFI_STATUS
1174 FatLocateOFile (
1175 IN OUT FAT_OFILE **PtrOFile,
1176 IN CHAR16 *FileName,
1177 IN UINT8 Attributes,
1178 OUT CHAR16 *NewFileName
1179 );
1180
1181 EFI_STATUS
1182 FatGetVolumeEntry (
1183 IN FAT_VOLUME *Volume,
1184 IN CHAR16 *Name
1185 );
1186
1187 EFI_STATUS
1188 FatSetVolumeEntry (
1189 IN FAT_VOLUME *Volume,
1190 IN CHAR16 *Name
1191 );
1192
1193 //
1194 // Hash.c
1195 //
1196 FAT_DIRENT **
1197 FatLongNameHashSearch (
1198 IN FAT_ODIR *ODir,
1199 IN CHAR16 *LongNameString
1200 );
1201
1202 FAT_DIRENT **
1203 FatShortNameHashSearch (
1204 IN FAT_ODIR *ODir,
1205 IN CHAR8 *ShortNameString
1206 );
1207
1208 VOID
1209 FatInsertToHashTable (
1210 IN FAT_ODIR *ODir,
1211 IN FAT_DIRENT *DirEnt
1212 );
1213
1214 VOID
1215 FatDeleteFromHashTable (
1216 IN FAT_ODIR *ODir,
1217 IN FAT_DIRENT *DirEnt
1218 );
1219
1220 //
1221 // FileName.c
1222 //
1223 BOOLEAN
1224 FatCheckIs8Dot3Name (
1225 IN CHAR16 *FileName,
1226 OUT CHAR8 *File8Dot3Name
1227 );
1228
1229 VOID
1230 FatCreate8Dot3Name (
1231 IN FAT_OFILE *Parent,
1232 IN FAT_DIRENT *DirEnt
1233 );
1234
1235 VOID
1236 FatNameToStr (
1237 IN CHAR8 *FatName,
1238 IN UINTN Len,
1239 IN UINTN LowerCase,
1240 IN CHAR16 *Str
1241 );
1242
1243 VOID
1244 FatSetCaseFlag (
1245 IN FAT_DIRENT *DirEnt
1246 );
1247
1248 VOID
1249 FatGetFileNameViaCaseFlag (
1250 IN FAT_DIRENT *DirEnt,
1251 IN OUT CHAR16 *FileString,
1252 IN UINTN FileStringMax
1253 );
1254
1255 UINT8
1256 FatCheckSum (
1257 IN CHAR8 *ShortNameString
1258 );
1259
1260 CHAR16*
1261 FatGetNextNameComponent (
1262 IN CHAR16 *Path,
1263 OUT CHAR16 *Name
1264 );
1265
1266 BOOLEAN
1267 FatFileNameIsValid (
1268 IN CHAR16 *InputFileName,
1269 OUT CHAR16 *OutputFileName
1270 );
1271
1272 //
1273 // DirectoryCache.c
1274 //
1275 VOID
1276 FatDiscardODir (
1277 IN FAT_OFILE *OFile
1278 );
1279
1280 VOID
1281 FatRequestODir (
1282 IN FAT_OFILE *OFile
1283 );
1284
1285 VOID
1286 FatCleanupODirCache (
1287 IN FAT_VOLUME *Volume
1288 );
1289
1290 //
1291 // Global Variables
1292 //
1293 extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
1294 extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
1295 extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
1296 extern EFI_LOCK FatFsLock;
1297 extern EFI_LOCK FatTaskLock;
1298 extern EFI_FILE_PROTOCOL FatFileInterface;
1299
1300 #endif