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