]> git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/Fat.h
Change Fat driver to support asynchronous File IO introduced in UEFI spec 2.3.1.D.
[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 FatOpenEx (
429 IN EFI_FILE_PROTOCOL *FHand,
430 OUT EFI_FILE_PROTOCOL **NewHandle,
431 IN CHAR16 *FileName,
432 IN UINT64 OpenMode,
433 IN UINT64 Attributes,
434 IN OUT EFI_FILE_IO_TOKEN *Token
435 )
436 /*++
437 Routine Description:
438
439 Implements OpenEx() of Simple File System Protocol.
440
441 Arguments:
442
443 FHand - File handle of the file serves as a starting reference point.
444 NewHandle - Handle of the file that is newly opened.
445 FileName - File name relative to FHand.
446 OpenMode - Open mode.
447 Attributes - Attributes to set if the file is created.
448 Token - A pointer to the token associated with the transaction.
449
450 Returns:
451
452 EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
453 The OpenMode is not supported.
454 The Attributes is not the valid attributes.
455 EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
456 EFI_SUCCESS - Open the file successfully.
457 Others - The status of open file.
458
459 --*/
460 ;
461
462 EFI_STATUS
463 EFIAPI
464 FatGetPosition (
465 IN EFI_FILE_PROTOCOL *FHand,
466 OUT UINT64 *Position
467 )
468 /*++
469
470 Routine Description:
471
472 Get the file's position of the file
473
474 Arguments:
475
476 FHand - The handle of file.
477 Position - The file's position of the file.
478
479 Returns:
480
481 EFI_SUCCESS - Get the info successfully.
482 EFI_DEVICE_ERROR - Can not find the OFile for the file.
483 EFI_UNSUPPORTED - The open file is not a file.
484
485 --*/
486 ;
487
488 EFI_STATUS
489 EFIAPI
490 FatGetInfo (
491 IN EFI_FILE_PROTOCOL *FHand,
492 IN EFI_GUID *Type,
493 IN OUT UINTN *BufferSize,
494 OUT VOID *Buffer
495 )
496 /*++
497
498 Routine Description:
499
500 Get the some types info of the file into Buffer
501
502 Arguments:
503
504 FHand - The handle of file.
505 Type - The type of the info.
506 BufferSize - Size of Buffer.
507 Buffer - Buffer containing volume info.
508
509 Returns:
510
511 EFI_SUCCESS - Get the info successfully.
512 EFI_DEVICE_ERROR - Can not find the OFile for the file.
513
514 --*/
515 ;
516
517 EFI_STATUS
518 EFIAPI
519 FatSetInfo (
520 IN EFI_FILE_PROTOCOL *FHand,
521 IN EFI_GUID *Type,
522 IN UINTN BufferSize,
523 IN VOID *Buffer
524 )
525 /*++
526
527 Routine Description:
528
529 Set the some types info of the file into Buffer
530
531 Arguments:
532
533 FHand - The handle of file.
534 Type - The type of the info.
535 BufferSize - Size of Buffer.
536 Buffer - Buffer containing volume info.
537
538 Returns:
539
540 EFI_SUCCESS - Set the info successfully.
541 EFI_DEVICE_ERROR - Can not find the OFile for the file.
542
543 --*/
544 ;
545
546 EFI_STATUS
547 EFIAPI
548 FatFlush (
549 IN EFI_FILE_PROTOCOL *FHand
550 )
551 /*++
552
553 Routine Description:
554
555 Flushes all data associated with the file handle
556
557 Arguments:
558
559 FHand - Handle to file to flush
560
561 Returns:
562
563 EFI_SUCCESS - Flushed the file successfully
564 EFI_WRITE_PROTECTED - The volume is read only
565 EFI_ACCESS_DENIED - The volume is not read only
566 but the file is read only
567 Others - Flushing of the file is failed
568
569 --*/
570 ;
571
572 EFI_STATUS
573 EFIAPI
574 FatFlushEx (
575 IN EFI_FILE_PROTOCOL *FHand,
576 IN EFI_FILE_IO_TOKEN *Token
577 )
578 /*++
579
580 Routine Description:
581
582 Flushes all data associated with the file handle.
583
584 Arguments:
585
586 FHand - Handle to file to flush.
587 Token - A pointer to the token associated with the transaction.
588
589 Returns:
590
591 EFI_SUCCESS - Flushed the file successfully.
592 EFI_WRITE_PROTECTED - The volume is read only.
593 EFI_ACCESS_DENIED - The file is read only.
594 Others - Flushing of the file failed.
595
596 --*/
597 ;
598
599 EFI_STATUS
600 EFIAPI
601 FatClose (
602 IN EFI_FILE_PROTOCOL *FHand
603 )
604 /*++
605
606 Routine Description:
607
608 Flushes & Closes the file handle.
609
610 Arguments:
611
612 FHand - Handle to the file to delete.
613
614 Returns:
615
616 EFI_SUCCESS - Closed the file successfully.
617
618 --*/
619 ;
620
621 EFI_STATUS
622 EFIAPI
623 FatDelete (
624 IN EFI_FILE_PROTOCOL *FHand
625 )
626 /*++
627
628 Routine Description:
629
630 Deletes the file & Closes the file handle.
631
632 Arguments:
633
634 FHand - Handle to the file to delete.
635
636 Returns:
637
638 EFI_SUCCESS - Delete the file successfully.
639 EFI_WARN_DELETE_FAILURE - Fail to delete the file.
640
641 --*/
642 ;
643
644 EFI_STATUS
645 EFIAPI
646 FatSetPosition (
647 IN EFI_FILE_PROTOCOL *FHand,
648 IN UINT64 Position
649 )
650 /*++
651
652 Routine Description:
653
654 Set the file's position of the file
655
656 Arguments:
657
658 FHand - The handle of file
659 Position - The file's position of the file
660
661 Returns:
662
663 EFI_SUCCESS - Set the info successfully
664 EFI_DEVICE_ERROR - Can not find the OFile for the file
665 EFI_UNSUPPORTED - Set a directory with a not-zero position
666
667 --*/
668 ;
669
670 EFI_STATUS
671 EFIAPI
672 FatRead (
673 IN EFI_FILE_PROTOCOL *FHand,
674 IN OUT UINTN *BufferSize,
675 OUT VOID *Buffer
676 )
677 /*++
678
679 Routine Description:
680
681 Get the file info.
682
683 Arguments:
684
685 FHand - The handle of the file.
686 BufferSize - Size of Buffer.
687 Buffer - Buffer containing read data.
688
689 Returns:
690
691 EFI_SUCCESS - Get the file info successfully.
692 EFI_DEVICE_ERROR - Can not find the OFile for the file.
693 EFI_VOLUME_CORRUPTED - The file type of open file is error.
694 other - An error occurred when operation the disk.
695
696 --*/
697 ;
698
699 EFI_STATUS
700 EFIAPI
701 FatReadEx (
702 IN EFI_FILE_PROTOCOL *FHand,
703 IN OUT EFI_FILE_IO_TOKEN *Token
704 )
705 /*++
706
707 Routine Description:
708
709 Get the file info.
710
711 Arguments:
712
713 FHand - The handle of the file.
714 Token - A pointer to the token associated with the transaction.
715
716 Returns:
717
718 EFI_SUCCESS - Get the file info successfully.
719 EFI_DEVICE_ERROR - Can not find the OFile for the file.
720 EFI_VOLUME_CORRUPTED - The file type of open file is error.
721 other - An error occurred when operation the disk.
722
723 --*/
724 ;
725
726 EFI_STATUS
727 EFIAPI
728 FatWrite (
729 IN EFI_FILE_PROTOCOL *FHand,
730 IN OUT UINTN *BufferSize,
731 IN VOID *Buffer
732 )
733 /*++
734
735 Routine Description:
736
737 Set the file info.
738
739 Arguments:
740
741 FHand - The handle of the file.
742 BufferSize - Size of Buffer.
743 Buffer - Buffer containing write data.
744
745 Returns:
746
747 EFI_SUCCESS - Set the file info successfully.
748 EFI_WRITE_PROTECTED - The disk is write protected.
749 EFI_ACCESS_DENIED - The file is read-only.
750 EFI_DEVICE_ERROR - The OFile is not valid.
751 EFI_UNSUPPORTED - The open file is not a file.
752 - The writing file size is larger than 4GB.
753 other - An error occurred when operation the disk.
754
755 --*/
756 ;
757
758 EFI_STATUS
759 EFIAPI
760 FatWriteEx (
761 IN EFI_FILE_PROTOCOL *FHand,
762 IN OUT EFI_FILE_IO_TOKEN *Token
763 )
764 /*++
765
766 Routine Description:
767
768 Get the file info.
769
770 Arguments:
771
772 FHand - The handle of the file.
773 Token - A pointer to the token associated with the transaction.
774
775 Returns:
776
777 EFI_SUCCESS - Get the file info successfully.
778 EFI_DEVICE_ERROR - Can not find the OFile for the file.
779 EFI_VOLUME_CORRUPTED - The file type of open file is error.
780 other - An error occurred when operation the disk.
781
782 --*/
783 ;
784
785 //
786 // DiskCache.c
787 //
788 EFI_STATUS
789 FatInitializeDiskCache (
790 IN FAT_VOLUME *Volume
791 );
792
793 EFI_STATUS
794 FatAccessCache (
795 IN FAT_VOLUME *Volume,
796 IN CACHE_DATA_TYPE CacheDataType,
797 IN IO_MODE IoMode,
798 IN UINT64 Offset,
799 IN UINTN BufferSize,
800 IN OUT UINT8 *Buffer,
801 IN FAT_TASK *Task
802 );
803
804 EFI_STATUS
805 FatVolumeFlushCache (
806 IN FAT_VOLUME *Volume,
807 IN FAT_TASK *Task
808 );
809
810 //
811 // Flush.c
812 //
813 EFI_STATUS
814 FatOFileFlush (
815 IN FAT_OFILE *OFile
816 );
817
818 BOOLEAN
819 FatCheckOFileRef (
820 IN FAT_OFILE *OFile
821 );
822
823 VOID
824 FatSetVolumeError (
825 IN FAT_OFILE *OFile,
826 IN EFI_STATUS Status
827 );
828
829 EFI_STATUS
830 FatIFileClose (
831 FAT_IFILE *IFile
832 );
833
834 EFI_STATUS
835 FatCleanupVolume (
836 IN FAT_VOLUME *Volume,
837 IN FAT_OFILE *OFile,
838 IN EFI_STATUS EfiStatus,
839 IN FAT_TASK *Task
840 );
841
842 //
843 // FileSpace.c
844 //
845 EFI_STATUS
846 FatShrinkEof (
847 IN FAT_OFILE *OFile
848 );
849
850 EFI_STATUS
851 FatGrowEof (
852 IN FAT_OFILE *OFile,
853 IN UINT64 NewSizeInBytes
854 );
855
856 UINTN
857 FatPhysicalDirSize (
858 IN FAT_VOLUME *Volume,
859 IN UINTN Cluster
860 );
861
862 UINT64
863 FatPhysicalFileSize (
864 IN FAT_VOLUME *Volume,
865 IN UINTN RealSize
866 );
867
868 EFI_STATUS
869 FatOFilePosition (
870 IN FAT_OFILE *OFile,
871 IN UINTN Position,
872 IN UINTN PosLimit
873 );
874
875 VOID
876 FatComputeFreeInfo (
877 IN FAT_VOLUME *Volume
878 );
879
880 //
881 // Init.c
882 //
883 EFI_STATUS
884 FatAllocateVolume (
885 IN EFI_HANDLE Handle,
886 IN EFI_DISK_IO_PROTOCOL *DiskIo,
887 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
888 IN EFI_BLOCK_IO_PROTOCOL *BlockIo
889 );
890
891 EFI_STATUS
892 FatOpenDevice (
893 IN OUT FAT_VOLUME *Volume
894 );
895
896 EFI_STATUS
897 FatAbandonVolume (
898 IN FAT_VOLUME *Volume
899 );
900
901 //
902 // Misc.c
903 //
904 FAT_TASK *
905 FatCreateTask (
906 FAT_IFILE *IFile,
907 EFI_FILE_IO_TOKEN *Token
908 );
909
910 VOID
911 FatDestroyTask (
912 FAT_TASK *Task
913 );
914
915 VOID
916 FatWaitNonblockingTask (
917 FAT_IFILE *IFile
918 );
919
920 LIST_ENTRY *
921 FatDestroySubtask (
922 FAT_SUBTASK *Subtask
923 );
924
925 EFI_STATUS
926 FatQueueTask (
927 IN FAT_IFILE *IFile,
928 IN FAT_TASK *Task
929 );
930
931 EFI_STATUS
932 FatAccessVolumeDirty (
933 IN FAT_VOLUME *Volume,
934 IN IO_MODE IoMode,
935 IN VOID *DirtyValue
936 );
937
938 EFI_STATUS
939 FatDiskIo (
940 IN FAT_VOLUME *Volume,
941 IN IO_MODE IoMode,
942 IN UINT64 Offset,
943 IN UINTN BufferSize,
944 IN OUT VOID *Buffer,
945 IN FAT_TASK *Task
946 );
947
948 VOID
949 FatAcquireLock (
950 VOID
951 );
952
953 VOID
954 FatReleaseLock (
955 VOID
956 );
957
958 EFI_STATUS
959 FatAcquireLockOrFail (
960 VOID
961 );
962
963 VOID
964 FatFreeDirEnt (
965 IN FAT_DIRENT *DirEnt
966 );
967
968 VOID
969 FatFreeVolume (
970 IN FAT_VOLUME *Volume
971 );
972
973 VOID
974 FatEfiTimeToFatTime (
975 IN EFI_TIME *ETime,
976 OUT FAT_DATE_TIME *FTime
977 );
978
979 VOID
980 FatFatTimeToEfiTime (
981 IN FAT_DATE_TIME *FTime,
982 OUT EFI_TIME *ETime
983 );
984
985 VOID
986 FatGetCurrentFatTime (
987 OUT FAT_DATE_TIME *FatTime
988 );
989
990 BOOLEAN
991 FatIsValidTime (
992 IN EFI_TIME *Time
993 );
994
995 //
996 // UnicodeCollation.c
997 //
998 EFI_STATUS
999 InitializeUnicodeCollationSupport (
1000 IN EFI_HANDLE AgentHandle
1001 );
1002
1003 VOID
1004 FatFatToStr (
1005 IN UINTN FatSize,
1006 IN CHAR8 *Fat,
1007 OUT CHAR16 *String
1008 );
1009
1010 BOOLEAN
1011 FatStrToFat (
1012 IN CHAR16 *String,
1013 IN UINTN FatSize,
1014 OUT CHAR8 *Fat
1015 );
1016
1017 VOID
1018 FatStrLwr (
1019 IN CHAR16 *Str
1020 );
1021
1022 VOID
1023 FatStrUpr (
1024 IN CHAR16 *Str
1025 );
1026
1027 INTN
1028 FatStriCmp (
1029 IN CHAR16 *Str1,
1030 IN CHAR16 *Str2
1031 );
1032
1033 //
1034 // Open.c
1035 //
1036 EFI_STATUS
1037 FatOFileOpen (
1038 IN FAT_OFILE *OFile,
1039 OUT FAT_IFILE **NewIFile,
1040 IN CHAR16 *FileName,
1041 IN UINT64 OpenMode,
1042 IN UINT8 Attributes
1043 );
1044
1045 EFI_STATUS
1046 FatAllocateIFile (
1047 IN FAT_OFILE *OFile,
1048 OUT FAT_IFILE **PtrIFile
1049 );
1050
1051 //
1052 // OpenVolume.c
1053 //
1054 EFI_STATUS
1055 EFIAPI
1056 FatOpenVolume (
1057 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
1058 OUT EFI_FILE_PROTOCOL **File
1059 );
1060
1061 //
1062 // ReadWrite.c
1063 //
1064 EFI_STATUS
1065 FatAccessOFile (
1066 IN FAT_OFILE *OFile,
1067 IN IO_MODE IoMode,
1068 IN UINTN Position,
1069 IN UINTN *DataBufferSize,
1070 IN UINT8 *UserBuffer,
1071 IN FAT_TASK *Task
1072 );
1073
1074 EFI_STATUS
1075 FatExpandOFile (
1076 IN FAT_OFILE *OFile,
1077 IN UINT64 ExpandedSize
1078 );
1079
1080 EFI_STATUS
1081 FatWriteZeroPool (
1082 IN FAT_OFILE *OFile,
1083 IN UINTN WritePos
1084 );
1085
1086 EFI_STATUS
1087 FatTruncateOFile (
1088 IN FAT_OFILE *OFile,
1089 IN UINTN TruncatedSize
1090 );
1091
1092 //
1093 // DirectoryManage.c
1094 //
1095 VOID
1096 FatResetODirCursor (
1097 IN FAT_OFILE *OFile
1098 );
1099
1100 EFI_STATUS
1101 FatGetNextDirEnt (
1102 IN FAT_OFILE *OFILE,
1103 OUT FAT_DIRENT **PtrDirEnt
1104 );
1105
1106 EFI_STATUS
1107 FatRemoveDirEnt (
1108 IN FAT_OFILE *OFile,
1109 IN FAT_DIRENT *DirEnt
1110 );
1111
1112 EFI_STATUS
1113 FatStoreDirEnt (
1114 IN FAT_OFILE *OFile,
1115 IN FAT_DIRENT *DirEnt
1116 );
1117
1118 EFI_STATUS
1119 FatCreateDirEnt (
1120 IN FAT_OFILE *OFile,
1121 IN CHAR16 *FileName,
1122 IN UINT8 Attributes,
1123 OUT FAT_DIRENT **PtrDirEnt
1124 );
1125
1126 BOOLEAN
1127 FatIsDotDirEnt (
1128 IN FAT_DIRENT *DirEnt
1129 );
1130
1131 VOID
1132 FatUpdateDirEntClusterSizeInfo (
1133 IN FAT_OFILE *OFile
1134 );
1135
1136 VOID
1137 FatCloneDirEnt (
1138 IN FAT_DIRENT *DirEnt1,
1139 IN FAT_DIRENT *DirEnt2
1140 );
1141
1142 EFI_STATUS
1143 FatGetDirEntInfo (
1144 IN FAT_VOLUME *Volume,
1145 IN FAT_DIRENT *DirEnt,
1146 IN OUT UINTN *BufferSize,
1147 OUT VOID *Buffer
1148 );
1149
1150 EFI_STATUS
1151 FatOpenDirEnt (
1152 IN FAT_OFILE *OFile,
1153 IN FAT_DIRENT *DirEnt
1154 );
1155
1156 EFI_STATUS
1157 FatCreateDotDirEnts (
1158 IN FAT_OFILE *OFile
1159 );
1160
1161 VOID
1162 FatCloseDirEnt (
1163 IN FAT_DIRENT *DirEnt
1164 );
1165
1166 EFI_STATUS
1167 FatLocateOFile (
1168 IN OUT FAT_OFILE **PtrOFile,
1169 IN CHAR16 *FileName,
1170 IN UINT8 Attributes,
1171 OUT CHAR16 *NewFileName
1172 );
1173
1174 EFI_STATUS
1175 FatGetVolumeEntry (
1176 IN FAT_VOLUME *Volume,
1177 IN CHAR16 *Name
1178 );
1179
1180 EFI_STATUS
1181 FatSetVolumeEntry (
1182 IN FAT_VOLUME *Volume,
1183 IN CHAR16 *Name
1184 );
1185
1186 //
1187 // Hash.c
1188 //
1189 FAT_DIRENT **
1190 FatLongNameHashSearch (
1191 IN FAT_ODIR *ODir,
1192 IN CHAR16 *LongNameString
1193 );
1194
1195 FAT_DIRENT **
1196 FatShortNameHashSearch (
1197 IN FAT_ODIR *ODir,
1198 IN CHAR8 *ShortNameString
1199 );
1200
1201 VOID
1202 FatInsertToHashTable (
1203 IN FAT_ODIR *ODir,
1204 IN FAT_DIRENT *DirEnt
1205 );
1206
1207 VOID
1208 FatDeleteFromHashTable (
1209 IN FAT_ODIR *ODir,
1210 IN FAT_DIRENT *DirEnt
1211 );
1212
1213 //
1214 // FileName.c
1215 //
1216 BOOLEAN
1217 FatCheckIs8Dot3Name (
1218 IN CHAR16 *FileName,
1219 OUT CHAR8 *File8Dot3Name
1220 );
1221
1222 VOID
1223 FatCreate8Dot3Name (
1224 IN FAT_OFILE *Parent,
1225 IN FAT_DIRENT *DirEnt
1226 );
1227
1228 VOID
1229 FatNameToStr (
1230 IN CHAR8 *FatName,
1231 IN UINTN Len,
1232 IN UINTN LowerCase,
1233 IN CHAR16 *Str
1234 );
1235
1236 VOID
1237 FatSetCaseFlag (
1238 IN FAT_DIRENT *DirEnt
1239 );
1240
1241 VOID
1242 FatGetFileNameViaCaseFlag (
1243 IN FAT_DIRENT *DirEnt,
1244 OUT CHAR16 *FileString
1245 );
1246
1247 UINT8
1248 FatCheckSum (
1249 IN CHAR8 *ShortNameString
1250 );
1251
1252 CHAR16*
1253 FatGetNextNameComponent (
1254 IN CHAR16 *Path,
1255 OUT CHAR16 *Name
1256 );
1257
1258 BOOLEAN
1259 FatFileNameIsValid (
1260 IN CHAR16 *InputFileName,
1261 OUT CHAR16 *OutputFileName
1262 );
1263
1264 //
1265 // DirectoryCache.c
1266 //
1267 VOID
1268 FatDiscardODir (
1269 IN FAT_OFILE *OFile
1270 );
1271
1272 VOID
1273 FatRequestODir (
1274 IN FAT_OFILE *OFile
1275 );
1276
1277 VOID
1278 FatCleanupODirCache (
1279 IN FAT_VOLUME *Volume
1280 );
1281
1282 //
1283 // Global Variables
1284 //
1285 extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
1286 extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
1287 extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
1288 extern EFI_LOCK FatFsLock;
1289 extern EFI_LOCK FatTaskLock;
1290 extern EFI_FILE_PROTOCOL FatFileInterface;
1291
1292 #endif