2 Main header file for EFI FAT file system driver.
4 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
14 #include <Guid/FileInfo.h>
15 #include <Guid/FileSystemInfo.h>
16 #include <Guid/FileSystemVolumeLabelInfo.h>
17 #include <Protocol/BlockIo.h>
18 #include <Protocol/DiskIo.h>
19 #include <Protocol/DiskIo2.h>
20 #include <Protocol/SimpleFileSystem.h>
21 #include <Protocol/UnicodeCollation.h>
23 #include <Library/PcdLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/BaseLib.h>
27 #include <Library/BaseMemoryLib.h>
28 #include <Library/MemoryAllocationLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
33 #include "FatFileSystem.h"
38 #define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
39 #define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
40 #define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
41 #define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
42 #define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
43 #define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
44 #define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
46 #define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
48 #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
50 #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
52 #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
54 #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
56 #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
58 #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
60 #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
63 // Minimum sector size is 512B, Maximum sector size is 4096B
64 // Max sectors per cluster is 128
66 #define MAX_BLOCK_ALIGNMENT 12
67 #define MIN_BLOCK_ALIGNMENT 9
68 #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
71 // Efi Time Definition
73 #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
76 // Minimum fat page size is 8K, maximum fat page alignment is 32K
77 // Minimum data page size is 8K, maximum fat page alignment is 64K
79 #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13
80 #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15
81 #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13
82 #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16
83 #define FAT_DATACACHE_GROUP_COUNT 64
84 #define FAT_FATCACHE_GROUP_MIN_COUNT 1
85 #define FAT_FATCACHE_GROUP_MAX_COUNT 16
88 // Used in 8.3 generation algorithm
90 #define MAX_SPEC_RETRY 4
91 #define SPEC_BASE_TAG_LEN 6
92 #define HASH_BASE_TAG_LEN 2
93 #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
96 // Path name separator is back slash
98 #define PATH_NAME_SEPARATOR L'\\'
101 #define EFI_PATH_STRING_LENGTH 260
102 #define EFI_FILE_STRING_LENGTH 255
103 #define FAT_MAX_ALLOCATE_SIZE 0xA00000
104 #define LC_ISO_639_2_ENTRY_SIZE 3
105 #define MAX_LANG_CODE_SIZE 100
107 #define FAT_MAX_DIR_CACHE_COUNT 8
108 #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
109 typedef CHAR8 LC_ISO_639_2
;
112 // The fat types we support
131 ReadDisk
= 0, // raw disk read
132 WriteDisk
= 1, // raw disk write
133 ReadFat
= 2, // read fat cache
134 WriteFat
= 3, // write fat cache
135 ReadData
= 6, // read data cache
136 WriteData
= 7 // write data cache
139 #define CACHE_ENABLED(a) ((a) >= 2)
140 #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
141 #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
159 CACHE_TAG CacheTag
[FAT_DATACACHE_GROUP_COUNT
];
165 #define HASH_TABLE_SIZE 0x400
166 #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
169 // The directory entry for opened directory
172 typedef struct _FAT_DIRENT FAT_DIRENT
;
173 typedef struct _FAT_ODIR FAT_ODIR
;
174 typedef struct _FAT_OFILE FAT_OFILE
;
175 typedef struct _FAT_VOLUME FAT_VOLUME
;
179 UINT16 EntryPos
; // The position of this directory entry in the parent directory file
180 UINT8 EntryCount
; // The count of the directory entry in the parent directory file
181 BOOLEAN Invalid
; // Indicate whether this directory entry is valid
182 CHAR16
*FileString
; // The unicode long file name for this directory entry
183 FAT_OFILE
*OFile
; // The OFile of the corresponding directory entry
184 FAT_DIRENT
*ShortNameForwardLink
; // Hash successor link for short filename
185 FAT_DIRENT
*LongNameForwardLink
; // Hash successor link for long filename
186 LIST_ENTRY Link
; // Connection of every directory entry
187 FAT_DIRECTORY_ENTRY Entry
; // The physical directory entry stored in disk
192 UINT32 CurrentEndPos
; // Current end position of the directory
193 UINT32 CurrentPos
; // Current position of the directory
194 LIST_ENTRY
*CurrentCursor
; // Current directory entry pointer
195 LIST_ENTRY ChildList
; // List of all directory entries
196 BOOLEAN EndOfDir
; // Indicate whether we have reached the end of the directory
197 LIST_ENTRY DirCacheLink
; // Linked in Volume->DirCacheList when discarded
198 UINTN DirCacheTag
; // The identification of the directory when in directory cache
199 FAT_DIRENT
*LongNameHashTable
[HASH_TABLE_SIZE
];
200 FAT_DIRENT
*ShortNameHashTable
[HASH_TABLE_SIZE
];
205 EFI_FILE_PROTOCOL Handle
;
209 LIST_ENTRY Tasks
; // List of all FAT_TASKs
210 LIST_ENTRY Link
; // Link to other IFiles
215 EFI_FILE_IO_TOKEN
*FileIoToken
;
217 LIST_ENTRY Subtasks
; // List of all FAT_SUBTASKs
218 LIST_ENTRY Link
; // Link to other FAT_TASKs
223 EFI_DISK_IO2_TOKEN DiskIo2Token
;
233 // FAT_OFILE - Each opened file
239 // A permanant error code to return to all accesses to
244 // A list of the IFILE instances for this OFile
249 // The dynamic infomation
253 UINTN FileCurrentCluster
;
254 UINTN FileLastCluster
;
257 // Dirty is set if there have been any updates to the
259 // Archive is set if the archive attribute in the file's
260 // directory entry needs to be set when performing flush
261 // PreserveLastMod is set if the last modification of the
262 // file is specified by SetInfo API
265 BOOLEAN IsFixedRootDir
;
266 BOOLEAN PreserveLastModification
;
269 // Set by an OFile SetPosition
271 UINTN Position
; // within file
272 UINT64 PosDisk
; // on the disk
273 UINTN PosRem
; // remaining in this disk run
275 // The opened parent, full path length and currently opened child files
279 LIST_ENTRY ChildHead
;
280 LIST_ENTRY ChildLink
;
283 // The opened directory structure for a directory; if this
284 // OFile represents a file, then ODir = NULL
288 // The directory entry for the Ofile
293 // Link in Volume's reference list
295 LIST_ENTRY CheckLink
;
305 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface
;
308 // If opened, the parent handle and BlockIo interface
310 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
311 EFI_DISK_IO_PROTOCOL
*DiskIo
;
312 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
317 // Computed values from fat bpb info
320 UINT64 FatPos
; // Disk pos of fat tables
321 UINT64 RootPos
; // Disk pos of root directory
322 UINT64 FirstClusterPos
; // Disk pos of first cluster
323 UINTN FatSize
; // Number of bytes in each fat
324 UINTN MaxCluster
; // Max cluster number
325 UINTN ClusterSize
; // Cluster size of fat partition
326 UINT8 ClusterAlignment
; // Equal to log_2 (clustersize);
327 FAT_VOLUME_TYPE FatType
;
330 // Current part of fat table that's present
332 UINT64 FatEntryPos
; // Location of buffer
333 UINTN FatEntrySize
; // Size of buffer
334 UINT32 FatEntryBuffer
; // The buffer
335 FAT_INFO_SECTOR FatInfoSector
; // Free cluster info
336 UINTN FreeInfoPos
; // Pos with the free cluster info
337 BOOLEAN FreeInfoValid
; // If free cluster info is valid
339 // Unpacked Fat BPB info
342 UINTN RootEntries
; // < FAT32, root dir is fixed size
343 UINTN RootCluster
; // >= FAT32, root cluster chain head
345 // info for marking the volume dirty or not
347 BOOLEAN FatDirty
; // If fat-entries have been updated
349 UINT32 NotDirtyValue
;
352 // The root directory entry and opened root file
354 FAT_DIRENT RootDirEnt
;
356 // File Name of root OFile, it is empty string
358 CHAR16 RootFileString
[1];
362 // New OFiles are added to this list so they
363 // can be cleaned up if they aren't referenced.
368 // Directory cache List
370 LIST_ENTRY DirCacheList
;
374 // Disk Cache for this volume
377 DISK_CACHE DiskCache
[CacheMaxType
];
381 // Function Prototypes
386 Implements Open() of Simple File System Protocol.
388 @param FHand - File handle of the file serves as a starting reference point.
389 @param NewHandle - Handle of the file that is newly opened.
390 @param FileName - File name relative to FHand.
391 @param OpenMode - Open mode.
392 @param Attributes - Attributes to set if the file is created.
395 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
396 The OpenMode is not supported.
397 The Attributes is not the valid attributes.
398 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
399 @retval EFI_SUCCESS - Open the file successfully.
400 @return Others - The status of open file.
406 IN EFI_FILE_PROTOCOL
*FHand
,
407 OUT EFI_FILE_PROTOCOL
**NewHandle
,
416 Implements OpenEx() of Simple File System Protocol.
418 @param FHand - File handle of the file serves as a starting reference point.
419 @param NewHandle - Handle of the file that is newly opened.
420 @param FileName - File name relative to FHand.
421 @param OpenMode - Open mode.
422 @param Attributes - Attributes to set if the file is created.
423 @param Token - A pointer to the token associated with the transaction.
425 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
426 The OpenMode is not supported.
427 The Attributes is not the valid attributes.
428 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
429 @retval EFI_SUCCESS - Open the file successfully.
430 @return Others - The status of open file.
436 IN EFI_FILE_PROTOCOL
*FHand
,
437 OUT EFI_FILE_PROTOCOL
**NewHandle
,
440 IN UINT64 Attributes
,
441 IN OUT EFI_FILE_IO_TOKEN
*Token
447 Get the file's position of the file
449 @param FHand - The handle of file.
450 @param Position - The file's position of the file.
452 @retval EFI_SUCCESS - Get the info successfully.
453 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
454 @retval EFI_UNSUPPORTED - The open file is not a file.
460 IN EFI_FILE_PROTOCOL
*FHand
,
467 Get the some types info of the file into Buffer
469 @param FHand - The handle of file.
470 @param Type - The type of the info.
471 @param BufferSize - Size of Buffer.
472 @param Buffer - Buffer containing volume info.
474 @retval EFI_SUCCESS - Get the info successfully.
475 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
481 IN EFI_FILE_PROTOCOL
*FHand
,
483 IN OUT UINTN
*BufferSize
,
490 Set the some types info of the file into Buffer.
492 @param FHand - The handle of file.
493 @param Type - The type of the info.
494 @param BufferSize - Size of Buffer.
495 @param Buffer - Buffer containing volume info.
497 @retval EFI_SUCCESS - Set the info successfully.
498 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
504 IN EFI_FILE_PROTOCOL
*FHand
,
513 Flushes all data associated with the file handle.
515 @param FHand - Handle to file to flush
517 @retval EFI_SUCCESS - Flushed the file successfully
518 @retval EFI_WRITE_PROTECTED - The volume is read only
519 @retval EFI_ACCESS_DENIED - The volume is not read only
520 but the file is read only
521 @return Others - Flushing of the file is failed
527 IN EFI_FILE_PROTOCOL
*FHand
533 Flushes all data associated with the file handle.
535 @param FHand - Handle to file to flush.
536 @param Token - A pointer to the token associated with the transaction.
538 @retval EFI_SUCCESS - Flushed the file successfully.
539 @retval EFI_WRITE_PROTECTED - The volume is read only.
540 @retval EFI_ACCESS_DENIED - The file is read only.
541 @return Others - Flushing of the file failed.
547 IN EFI_FILE_PROTOCOL
*FHand
,
548 IN EFI_FILE_IO_TOKEN
*Token
554 Flushes & Closes the file handle.
556 @param FHand - Handle to the file to delete.
558 @retval EFI_SUCCESS - Closed the file successfully.
564 IN EFI_FILE_PROTOCOL
*FHand
570 Deletes the file & Closes the file handle.
572 @param FHand - Handle to the file to delete.
574 @retval EFI_SUCCESS - Delete the file successfully.
575 @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
581 IN EFI_FILE_PROTOCOL
*FHand
587 Set the file's position of the file.
589 @param FHand - The handle of file
590 @param Position - The file's position of the file
592 @retval EFI_SUCCESS - Set the info successfully
593 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file
594 @retval EFI_UNSUPPORTED - Set a directory with a not-zero position
600 IN EFI_FILE_PROTOCOL
*FHand
,
609 @param FHand - The handle of the file.
610 @param BufferSize - Size of Buffer.
611 @param Buffer - Buffer containing read data.
613 @retval EFI_SUCCESS - Get the file info successfully.
614 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
615 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
616 @return other - An error occurred when operation the disk.
622 IN EFI_FILE_PROTOCOL
*FHand
,
623 IN OUT UINTN
*BufferSize
,
632 @param FHand - The handle of the file.
633 @param Token - A pointer to the token associated with the transaction.
635 @retval EFI_SUCCESS - Get the file info successfully.
636 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
637 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
638 @return other - An error occurred when operation the disk.
644 IN EFI_FILE_PROTOCOL
*FHand
,
645 IN OUT EFI_FILE_IO_TOKEN
*Token
653 @param FHand - The handle of the file.
654 @param BufferSize - Size of Buffer.
655 @param Buffer - Buffer containing write data.
657 @retval EFI_SUCCESS - Set the file info successfully.
658 @retval EFI_WRITE_PROTECTED - The disk is write protected.
659 @retval EFI_ACCESS_DENIED - The file is read-only.
660 @retval EFI_DEVICE_ERROR - The OFile is not valid.
661 @retval EFI_UNSUPPORTED - The open file is not a file.
662 - The writing file size is larger than 4GB.
663 @return other - An error occurred when operation the disk.
669 IN EFI_FILE_PROTOCOL
*FHand
,
670 IN OUT UINTN
*BufferSize
,
679 @param FHand - The handle of the file.
680 @param Token - A pointer to the token associated with the transaction.
682 @retval EFI_SUCCESS - Get the file info successfully.
683 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
684 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
685 @return other - An error occurred when operation the disk.
691 IN EFI_FILE_PROTOCOL
*FHand
,
692 IN OUT EFI_FILE_IO_TOKEN
*Token
701 Initialize the disk cache according to Volume's FatType.
703 @param Volume - FAT file system volume.
705 @retval EFI_SUCCESS - The disk cache is successfully initialized.
706 @retval EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.
710 FatInitializeDiskCache (
711 IN FAT_VOLUME
*Volume
716 Read BufferSize bytes from the position of Offset into Buffer,
717 or write BufferSize bytes from Buffer into the position of Offset.
719 Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into
720 the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):
722 1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache
723 page hit, just return the cache page; else update the related cache page and return
724 the right cache page.
725 2. Access of Data cache (CACHE_DATA):
726 The access data will be divided into UnderRun data, Aligned data and OverRun data;
727 The UnderRun data and OverRun data will be accessed by the Data cache,
728 but the Aligned data will be accessed with disk directly.
730 @param Volume - FAT file system volume.
731 @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.
732 @param IoMode - Indicate the type of disk access.
733 @param Offset - The starting byte offset to read from.
734 @param BufferSize - Size of Buffer.
735 @param Buffer - Buffer containing cache data.
736 @param Task point to task instance.
738 @retval EFI_SUCCESS - The data was accessed correctly.
739 @retval EFI_MEDIA_CHANGED - The MediaId does not match the current device.
740 @return Others - An error occurred when accessing cache.
745 IN FAT_VOLUME
*Volume
,
746 IN CACHE_DATA_TYPE CacheDataType
,
750 IN OUT UINT8
*Buffer
,
756 Flush all the dirty cache back, include the FAT cache and the Data cache.
758 @param Volume - FAT file system volume.
759 @param Task point to task instance.
761 @retval EFI_SUCCESS - Flush all the dirty cache back successfully
762 @return other - An error occurred when writing the data into the disk
766 FatVolumeFlushCache (
767 IN FAT_VOLUME
*Volume
,
776 Flush the data associated with an open file.
777 In this implementation, only last Mod/Access time is updated.
779 @param OFile - The open file.
781 @retval EFI_SUCCESS - The OFile is flushed successfully.
782 @return Others - An error occurred when flushing this OFile.
792 Check the references of the OFile.
793 If the OFile (that is checked) is no longer
794 referenced, then it is freed.
796 @param OFile - The OFile to be checked.
798 @retval TRUE - The OFile is not referenced and freed.
799 @retval FALSE - The OFile is kept.
809 Set the OFile and its child OFile with the error Status
811 @param OFile - The OFile whose permanent error code is to be set.
812 @param Status - Error code to be set.
823 Close the open file instance.
825 @param IFile - Open file instance.
827 @retval EFI_SUCCESS - Closed the file successfully.
837 Set error status for a specific OFile, reference checking the volume.
838 If volume is already marked as invalid, and all resources are freed
839 after reference checking, the file system protocol is uninstalled and
840 the volume structure is freed.
842 @param Volume - the Volume that is to be reference checked and unlocked.
843 @param OFile - the OFile whose permanent error code is to be set.
844 @param EfiStatus - error code to be set.
845 @param Task point to task instance.
847 @retval EFI_SUCCESS - Clean up the volume successfully.
848 @return Others - Cleaning up of the volume is failed.
853 IN FAT_VOLUME
*Volume
,
855 IN EFI_STATUS EfiStatus
,
864 Shrink the end of the open file base on the file size.
866 @param OFile - The open file.
868 @retval EFI_SUCCESS - Shrinked sucessfully.
869 @retval EFI_VOLUME_CORRUPTED - There are errors in the file's clusters.
879 Grow the end of the open file base on the NewSizeInBytes.
881 @param OFile - The open file.
882 @param NewSizeInBytes - The new size in bytes of the open file.
884 @retval EFI_SUCCESS - The file is grown sucessfully.
885 @retval EFI_UNSUPPORTED - The file size is larger than 4GB.
886 @retval EFI_VOLUME_CORRUPTED - There are errors in the files' clusters.
887 @retval EFI_VOLUME_FULL - The volume is full and can not grow the file.
893 IN UINT64 NewSizeInBytes
898 Get the size of directory of the open file.
900 @param Volume - The File System Volume.
901 @param Cluster - The Starting cluster.
903 @return The physical size of the file starting at the input cluster, if there is error in the
904 cluster chain, the return value is 0.
909 IN FAT_VOLUME
*Volume
,
915 Get the physical size of a file on the disk.
917 @param Volume - The file system volume.
918 @param RealSize - The real size of a file.
920 @return The physical size of a file on the disk.
924 FatPhysicalFileSize (
925 IN FAT_VOLUME
*Volume
,
931 Seek OFile to requested position, and calculate the number of
932 consecutive clusters from the position in the file
934 @param OFile - The open file.
935 @param Position - The file's position which will be accessed.
936 @param PosLimit - The maximum length current reading/writing may access
938 @retval EFI_SUCCESS - Set the info successfully.
939 @retval EFI_VOLUME_CORRUPTED - Cluster chain corrupt.
951 Update the free cluster info of FatInfoSector of the volume.
953 @param Volume - FAT file system volume.
958 IN FAT_VOLUME
*Volume
966 Allocates volume structure, detects FAT file system, installs protocol,
967 and initialize cache.
969 @param Handle - The handle of parent device.
970 @param DiskIo - The DiskIo of parent device.
971 @param DiskIo2 - The DiskIo2 of parent device.
972 @param BlockIo - The BlockIo of parent devicel
974 @retval EFI_SUCCESS - Allocate a new volume successfully.
975 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
976 @return Others - Allocating a new volume failed.
981 IN EFI_HANDLE Handle
,
982 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
983 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
984 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
989 Detects FAT file system on Disk and set relevant fields of Volume.
991 @param Volume - The volume structure.
993 @retval EFI_SUCCESS - The Fat File System is detected successfully
994 @retval EFI_UNSUPPORTED - The volume is not FAT file system.
995 @retval EFI_VOLUME_CORRUPTED - The volume is corrupted.
1000 IN OUT FAT_VOLUME
*Volume
1005 Called by FatDriverBindingStop(), Abandon the volume.
1007 @param Volume - The volume to be abandoned.
1009 @retval EFI_SUCCESS - Abandoned the volume successfully.
1010 @return Others - Can not uninstall the protocol interfaces.
1015 IN FAT_VOLUME
*Volume
1025 @param IFile - The instance of the open file.
1026 @param Token - A pointer to the token associated with the transaction.
1028 @return FAT_TASK * - Return the task instance.
1034 EFI_FILE_IO_TOKEN
*Token
1041 @param Task - The task to be destroyed.
1051 Wait all non-blocking requests complete.
1053 @param IFile - The instance of the open file.
1057 FatWaitNonblockingTask (
1063 Remove the subtask from subtask list.
1065 @param Subtask - The subtask to be removed.
1067 @return LIST_ENTRY * - The next node in the list.
1072 FAT_SUBTASK
*Subtask
1079 @param IFile - The instance of the open file.
1080 @param Task - The task to be executed.
1082 @retval EFI_SUCCESS - The task was executed sucessfully.
1083 @return other - An error occurred when executing the task.
1088 IN FAT_IFILE
*IFile
,
1094 Set the volume as dirty or not.
1096 @param Volume - FAT file system volume.
1097 @param IoMode - The access mode.
1098 @param DirtyValue - Set the volume as dirty or not.
1100 @retval EFI_SUCCESS - Set the new FAT entry value sucessfully.
1101 @return other - An error occurred when operation the FAT entries.
1105 FatAccessVolumeDirty (
1106 IN FAT_VOLUME
*Volume
,
1113 General disk access function.
1115 @param Volume - FAT file system volume.
1116 @param IoMode - The access mode (disk read/write or cache access).
1117 @param Offset - The starting byte offset to read from.
1118 @param BufferSize - Size of Buffer.
1119 @param Buffer - Buffer containing read data.
1120 @param Task point to task instance.
1122 @retval EFI_SUCCESS - The operation is performed successfully.
1123 @retval EFI_VOLUME_CORRUPTED - The accesss is
1124 @return Others - The status of read/write the disk
1129 IN FAT_VOLUME
*Volume
,
1132 IN UINTN BufferSize
,
1133 IN OUT VOID
*Buffer
,
1160 If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
1161 Otherwise, EFI_SUCCESS is returned.
1163 @retval EFI_SUCCESS - The volume is locked.
1164 @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.
1168 FatAcquireLockOrFail (
1174 Free directory entry.
1176 @param DirEnt - The directory entry to be freed.
1181 IN FAT_DIRENT
*DirEnt
1186 Free volume structure (including the contents of directory cache and disk cache).
1188 @param Volume - The volume structure to be freed.
1193 IN FAT_VOLUME
*Volume
1198 Translate EFI time to FAT time.
1200 @param ETime - The time of EFI_TIME.
1201 @param FTime - The time of FAT_DATE_TIME.
1205 FatEfiTimeToFatTime (
1207 OUT FAT_DATE_TIME
*FTime
1212 Translate Fat time to EFI time.
1214 @param FTime - The time of FAT_DATE_TIME.
1215 @param ETime - The time of EFI_TIME..
1219 FatFatTimeToEfiTime (
1220 IN FAT_DATE_TIME
*FTime
,
1226 Get Current FAT time.
1228 @param FatTime - Current FAT time.
1232 FatGetCurrentFatTime (
1233 OUT FAT_DATE_TIME
*FatTime
1238 Check whether a time is valid.
1240 @param Time - The time of EFI_TIME.
1242 @retval TRUE - The time is valid.
1243 @retval FALSE - The time is not valid.
1252 // UnicodeCollation.c
1255 Initialize Unicode Collation support.
1257 It tries to locate Unicode Collation 2 protocol and matches it with current
1258 platform language code. If for any reason the first attempt fails, it then tries to
1259 use Unicode Collation Protocol.
1261 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
1263 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
1264 @retval Others The Unicode Collation (2) protocol has not been located.
1268 InitializeUnicodeCollationSupport (
1269 IN EFI_HANDLE AgentHandle
1273 Convert FAT string to unicode string.
1275 @param FatSize The size of FAT string.
1276 @param Fat The FAT string.
1277 @param String The unicode string.
1290 Convert unicode string to Fat string.
1292 @param String The unicode string.
1293 @param FatSize The size of the FAT string.
1294 @param Fat The FAT string.
1296 @retval TRUE Convert successfully.
1297 @retval FALSE Convert error.
1310 @param Str The string which will be lower-cased.
1321 @param Str The string which will be upper-cased.
1330 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
1332 @param Str1 A pointer to a Null-terminated Unicode string.
1333 @param Str2 A pointer to a Null-terminated Unicode string.
1335 @retval 0 S1 is equivalent to S2.
1336 @retval >0 S1 is lexically greater than S2.
1337 @retval <0 S1 is lexically less than S2.
1351 Open a file for a file name relative to an existing OFile.
1352 The IFile of the newly opened file is passed out.
1354 @param OFile - The file that serves as a starting reference point.
1355 @param NewIFile - The newly generated IFile instance.
1356 @param FileName - The file name relative to the OFile.
1357 @param OpenMode - Open mode.
1358 @param Attributes - Attributes to set if the file is created.
1361 @retval EFI_SUCCESS - Open the file successfully.
1362 @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes
1363 or the file name is not valid.
1364 @retval EFI_NOT_FOUND - Conficts between dir intention and attribute.
1365 @retval EFI_WRITE_PROTECTED - Can't open for write if the volume is read only.
1366 @retval EFI_ACCESS_DENIED - If the file's attribute is read only, and the
1367 open is for read-write fail it.
1368 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
1373 IN FAT_OFILE
*OFile
,
1374 OUT FAT_IFILE
**NewIFile
,
1375 IN CHAR16
*FileName
,
1382 Create an Open instance for the existing OFile.
1383 The IFile of the newly opened file is passed out.
1385 @param OFile - The file that serves as a starting reference point.
1386 @param PtrIFile - The newly generated IFile instance.
1388 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for the IFile
1389 @retval EFI_SUCCESS - Create the new IFile for the OFile successfully
1394 IN FAT_OFILE
*OFile
,
1395 OUT FAT_IFILE
**PtrIFile
1403 Implements Simple File System Protocol interface function OpenVolume().
1405 @param This - Calling context.
1406 @param File - the Root Directory of the volume.
1408 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
1409 @retval EFI_VOLUME_CORRUPTED - The FAT type is error.
1410 @retval EFI_SUCCESS - Open the volume successfully.
1416 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
1417 OUT EFI_FILE_PROTOCOL
**File
1425 This function reads data from a file or writes data to a file.
1426 It uses OFile->PosRem to determine how much data can be accessed in one time.
1428 @param OFile - The open file.
1429 @param IoMode - Indicate whether the access mode is reading or writing.
1430 @param Position - The position where data will be accessed.
1431 @param DataBufferSize - Size of Buffer.
1432 @param UserBuffer - Buffer containing data.
1433 @param Task point to task instance.
1435 @retval EFI_SUCCESS - Access the data successfully.
1436 @return other - An error occurred when operating on the disk.
1441 IN FAT_OFILE
*OFile
,
1444 IN UINTN
*DataBufferSize
,
1445 IN UINT8
*UserBuffer
,
1451 Expand OFile by appending zero bytes at the end of OFile.
1453 @param OFile - The open file.
1454 @param ExpandedSize - The number of zero bytes appended at the end of the file.
1456 @retval EFI_SUCCESS - The file is expanded successfully.
1457 @return other - An error occurred when expanding file.
1462 IN FAT_OFILE
*OFile
,
1463 IN UINT64 ExpandedSize
1468 Write zero pool from the WritePos to the end of OFile.
1470 @param OFile - The open file to write zero pool.
1471 @param WritePos - The number of zero bytes written.
1473 @retval EFI_SUCCESS - Write the zero pool successfully.
1474 @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation.
1475 @return other - An error occurred when writing disk.
1480 IN FAT_OFILE
*OFile
,
1486 Truncate the OFile to smaller file size.
1488 @param OFile - The open file.
1489 @param TruncatedSize - The new file size.
1491 @retval EFI_SUCCESS - The file is truncated successfully.
1492 @return other - An error occurred when truncating file.
1497 IN FAT_OFILE
*OFile
,
1498 IN UINTN TruncatedSize
1502 // DirectoryManage.c
1506 Set the OFile's current directory cursor to the list head.
1508 @param OFile - The directory OFile whose directory cursor is reset.
1512 FatResetODirCursor (
1518 Set the directory's cursor to the next and get the next directory entry.
1520 @param OFile - The parent OFile.
1521 @param PtrDirEnt - The next directory entry.
1523 @retval EFI_SUCCESS - We get the next directory entry successfully.
1524 @return other - An error occurred when get next directory entry.
1529 IN FAT_OFILE
*OFile
,
1530 OUT FAT_DIRENT
**PtrDirEnt
1535 Remove this directory entry node from the list of directory entries and hash table.
1537 @param OFile - The parent OFile.
1538 @param DirEnt - The directory entry to be removed.
1540 @retval EFI_SUCCESS - The directory entry is successfully removed.
1541 @return other - An error occurred when removing the directory entry.
1546 IN FAT_OFILE
*OFile
,
1547 IN FAT_DIRENT
*DirEnt
1552 Save the directory entry to disk.
1554 @param OFile - The parent OFile which needs to update.
1555 @param DirEnt - The directory entry to be saved.
1557 @retval EFI_SUCCESS - Store the directory entry successfully.
1558 @return other - An error occurred when writing the directory entry.
1563 IN FAT_OFILE
*OFile
,
1564 IN FAT_DIRENT
*DirEnt
1569 Create a directory entry in the parent OFile.
1571 @param OFile - The parent OFile.
1572 @param FileName - The filename of the newly-created directory entry.
1573 @param Attributes - The attribute of the newly-created directory entry.
1574 @param PtrDirEnt - The pointer to the newly-created directory entry.
1576 @retval EFI_SUCCESS - The directory entry is successfully created.
1577 @retval EFI_OUT_OF_RESOURCES - Not enough memory to create the directory entry.
1578 @return other - An error occurred when creating the directory entry.
1583 IN FAT_OFILE
*OFile
,
1584 IN CHAR16
*FileName
,
1585 IN UINT8 Attributes
,
1586 OUT FAT_DIRENT
**PtrDirEnt
1591 Determine whether the directory entry is "." or ".." entry.
1593 @param DirEnt - The corresponding directory entry.
1595 @retval TRUE - The directory entry is "." or ".." directory entry
1596 @retval FALSE - The directory entry is not "." or ".." directory entry
1601 IN FAT_DIRENT
*DirEnt
1606 Set the OFile's cluster and size info in its directory entry.
1608 @param OFile - The corresponding OFile.
1612 FatUpdateDirEntClusterSizeInfo (
1618 Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.
1620 @param DirEnt1 - The destination directory entry.
1621 @param DirEnt2 - The source directory entry.
1626 IN FAT_DIRENT
*DirEnt1
,
1627 IN FAT_DIRENT
*DirEnt2
1632 Get the directory entry's info into Buffer.
1634 @param Volume - FAT file system volume.
1635 @param DirEnt - The corresponding directory entry.
1636 @param BufferSize - Size of Buffer.
1637 @param Buffer - Buffer containing file info.
1639 @retval EFI_SUCCESS - Get the file info successfully.
1640 @retval EFI_BUFFER_TOO_SMALL - The buffer is too small.
1645 IN FAT_VOLUME
*Volume
,
1646 IN FAT_DIRENT
*DirEnt
,
1647 IN OUT UINTN
*BufferSize
,
1653 Open the directory entry to get the OFile.
1655 @param Parent - The parent OFile.
1656 @param DirEnt - The directory entry to be opened.
1658 @retval EFI_SUCCESS - The directory entry is successfully opened.
1659 @retval EFI_OUT_OF_RESOURCES - not enough memory to allocate a new OFile.
1660 @return other - An error occurred when opening the directory entry.
1665 IN FAT_OFILE
*OFile
,
1666 IN FAT_DIRENT
*DirEnt
1671 Create "." and ".." directory entries in the newly-created parent OFile.
1673 @param OFile - The parent OFile.
1675 @retval EFI_SUCCESS - The dot directory entries are successfully created.
1676 @return other - An error occurred when creating the directory entry.
1680 FatCreateDotDirEnts (
1686 Close the directory entry and free the OFile.
1688 @param DirEnt - The directory entry to be closed.
1693 IN FAT_DIRENT
*DirEnt
1698 Traverse filename and open all OFiles that can be opened.
1699 Update filename pointer to the component that can't be opened.
1700 If more than one name component remains, returns an error;
1701 otherwise, return the remaining name component so that the caller might choose to create it.
1703 @param PtrOFile - As input, the reference OFile; as output, the located OFile.
1704 @param FileName - The file name relevant to the OFile.
1705 @param Attributes - The attribute of the destination OFile.
1706 @param NewFileName - The remaining file name.
1708 @retval EFI_NOT_FOUND - The file name can't be opened and there is more than one
1709 components within the name left (this means the name can
1710 not be created either).
1711 @retval EFI_INVALID_PARAMETER - The parameter is not valid.
1712 @retval EFI_SUCCESS - Open the file successfully.
1713 @return other - An error occured when locating the OFile.
1718 IN OUT FAT_OFILE
**PtrOFile
,
1719 IN CHAR16
*FileName
,
1720 IN UINT8 Attributes
,
1721 OUT CHAR16
*NewFileName
1726 Get the directory entry for the volume.
1728 @param Volume - FAT file system volume.
1729 @param Name - The file name of the volume.
1731 @retval EFI_SUCCESS - Update the volume with the directory entry sucessfully.
1732 @return others - An error occurred when getting volume label.
1737 IN FAT_VOLUME
*Volume
,
1743 Set the relevant directory entry into disk for the volume.
1745 @param Volume - FAT file system volume.
1746 @param Name - The new file name of the volume.
1748 @retval EFI_SUCCESS - Update the Volume sucessfully.
1749 @retval EFI_UNSUPPORTED - The input label is not a valid volume label.
1750 @return other - An error occurred when setting volume label.
1755 IN FAT_VOLUME
*Volume
,
1764 Search the long name hash table for the directory entry.
1766 @param ODir - The directory to be searched.
1767 @param LongNameString - The long name string to search.
1769 @return The previous long name hash node of the directory entry.
1773 FatLongNameHashSearch (
1775 IN CHAR16
*LongNameString
1780 Search the short name hash table for the directory entry.
1782 @param ODir - The directory to be searched.
1783 @param ShortNameString - The short name string to search.
1785 @return The previous short name hash node of the directory entry.
1789 FatShortNameHashSearch (
1791 IN CHAR8
*ShortNameString
1796 Insert directory entry to hash table.
1798 @param ODir - The parent directory.
1799 @param DirEnt - The directory entry node.
1803 FatInsertToHashTable (
1805 IN FAT_DIRENT
*DirEnt
1810 Delete directory entry from hash table.
1812 @param ODir - The parent directory.
1813 @param DirEnt - The directory entry node.
1817 FatDeleteFromHashTable (
1819 IN FAT_DIRENT
*DirEnt
1827 This function checks whether the input FileName is a valid 8.3 short name.
1828 If the input FileName is a valid 8.3, the output is the 8.3 short name;
1829 otherwise, the output is the base tag of 8.3 short name.
1831 @param FileName - The input unicode filename.
1832 @param File8Dot3Name - The output ascii 8.3 short name or base tag of 8.3 short name.
1834 @retval TRUE - The input unicode filename is a valid 8.3 short name.
1835 @retval FALSE - The input unicode filename is not a valid 8.3 short name.
1839 FatCheckIs8Dot3Name (
1840 IN CHAR16
*FileName
,
1841 OUT CHAR8
*File8Dot3Name
1846 This function generates 8Dot3 name from user specified name for a newly created file.
1848 @param Parent - The parent directory.
1849 @param DirEnt - The directory entry whose 8Dot3Name needs to be generated.
1853 FatCreate8Dot3Name (
1854 IN FAT_OFILE
*Parent
,
1855 IN FAT_DIRENT
*DirEnt
1860 Convert the ascii fat name to the unicode string and strip trailing spaces,
1861 and if necessary, convert the unicode string to lower case.
1863 @param FatName - The Char8 string needs to be converted.
1864 @param Len - The length of the fat name.
1865 @param LowerCase - Indicate whether to convert the string to lower case.
1866 @param Str - The result of the convertion.
1879 Set the caseflag value for the directory entry.
1881 @param DirEnt - The logical directory entry whose caseflag value is to be set.
1886 IN FAT_DIRENT
*DirEnt
1891 Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.
1893 @param DirEnt - The corresponding directory entry.
1894 @param FileString - The output Unicode file name.
1895 @param FileStringMax The max length of FileString.
1899 FatGetFileNameViaCaseFlag (
1900 IN FAT_DIRENT
*DirEnt
,
1901 IN OUT CHAR16
*FileString
,
1902 IN UINTN FileStringMax
1907 Get the Check sum for a short name.
1909 @param ShortNameString - The short name for a file.
1911 @retval Sum - UINT8 checksum.
1916 IN CHAR8
*ShortNameString
1921 Takes Path as input, returns the next name component
1922 in Name, and returns the position after Name (e.g., the
1923 start of the next name component)
1925 @param Path - The path of one file.
1926 @param Name - The next name component in Path.
1928 The position after Name in the Path
1932 FatGetNextNameComponent (
1939 Check whether the IFileName is valid long file name. If the IFileName is a valid
1940 long file name, then we trim the possible leading blanks and leading/trailing dots.
1941 the trimmed filename is stored in OutputFileName
1943 @param InputFileName - The input file name.
1944 @param OutputFileName - The output file name.
1946 @retval TRUE - The InputFileName is a valid long file name.
1947 @retval FALSE - The InputFileName is not a valid long file name.
1951 FatFileNameIsValid (
1952 IN CHAR16
*InputFileName
,
1953 OUT CHAR16
*OutputFileName
1961 Discard the directory structure when an OFile will be freed.
1962 Volume will cache this directory if the OFile does not represent a deleted file.
1964 @param OFile - The OFile whose directory structure is to be discarded.
1974 Request the directory structure when an OFile is newly generated.
1975 If the directory structure is cached by volume, then just return this directory;
1976 Otherwise, allocate a new one for OFile.
1978 @param OFile - The OFile which requests directory structure.
1988 Clean up all the cached directory structures when the volume is going to be abandoned.
1990 @param Volume - FAT file system volume.
1994 FatCleanupODirCache (
1995 IN FAT_VOLUME
*Volume
2001 extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
;
2002 extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName
;
2003 extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2
;
2004 extern EFI_LOCK FatFsLock
;
2005 extern EFI_LOCK FatTaskLock
;
2006 extern EFI_FILE_PROTOCOL FatFileInterface
;