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'\\'
100 #define EFI_PATH_STRING_LENGTH 260
101 #define EFI_FILE_STRING_LENGTH 255
102 #define FAT_MAX_ALLOCATE_SIZE 0xA00000
103 #define LC_ISO_639_2_ENTRY_SIZE 3
104 #define MAX_LANG_CODE_SIZE 100
106 #define FAT_MAX_DIR_CACHE_COUNT 8
107 #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
108 typedef CHAR8 LC_ISO_639_2
;
111 // The fat types we support
130 ReadDisk
= 0, // raw disk read
131 WriteDisk
= 1, // raw disk write
132 ReadFat
= 2, // read fat cache
133 WriteFat
= 3, // write fat cache
134 ReadData
= 6, // read data cache
135 WriteData
= 7 // write data cache
138 #define CACHE_ENABLED(a) ((a) >= 2)
139 #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
140 #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
158 CACHE_TAG CacheTag
[FAT_DATACACHE_GROUP_COUNT
];
164 #define HASH_TABLE_SIZE 0x400
165 #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
168 // The directory entry for opened directory
171 typedef struct _FAT_DIRENT FAT_DIRENT
;
172 typedef struct _FAT_ODIR FAT_ODIR
;
173 typedef struct _FAT_OFILE FAT_OFILE
;
174 typedef struct _FAT_VOLUME FAT_VOLUME
;
178 UINT16 EntryPos
; // The position of this directory entry in the parent directory file
179 UINT8 EntryCount
; // The count of the directory entry in the parent directory file
180 BOOLEAN Invalid
; // Indicate whether this directory entry is valid
181 CHAR16
*FileString
; // The unicode long file name for this directory entry
182 FAT_OFILE
*OFile
; // The OFile of the corresponding directory entry
183 FAT_DIRENT
*ShortNameForwardLink
; // Hash successor link for short filename
184 FAT_DIRENT
*LongNameForwardLink
; // Hash successor link for long filename
185 LIST_ENTRY Link
; // Connection of every directory entry
186 FAT_DIRECTORY_ENTRY Entry
; // The physical directory entry stored in disk
191 UINT32 CurrentEndPos
; // Current end position of the directory
192 UINT32 CurrentPos
; // Current position of the directory
193 LIST_ENTRY
*CurrentCursor
; // Current directory entry pointer
194 LIST_ENTRY ChildList
; // List of all directory entries
195 BOOLEAN EndOfDir
; // Indicate whether we have reached the end of the directory
196 LIST_ENTRY DirCacheLink
; // Linked in Volume->DirCacheList when discarded
197 UINTN DirCacheTag
; // The identification of the directory when in directory cache
198 FAT_DIRENT
*LongNameHashTable
[HASH_TABLE_SIZE
];
199 FAT_DIRENT
*ShortNameHashTable
[HASH_TABLE_SIZE
];
204 EFI_FILE_PROTOCOL Handle
;
208 LIST_ENTRY Tasks
; // List of all FAT_TASKs
209 LIST_ENTRY Link
; // Link to other IFiles
214 EFI_FILE_IO_TOKEN
*FileIoToken
;
216 LIST_ENTRY Subtasks
; // List of all FAT_SUBTASKs
217 LIST_ENTRY Link
; // Link to other FAT_TASKs
222 EFI_DISK_IO2_TOKEN DiskIo2Token
;
232 // FAT_OFILE - Each opened file
238 // A permanent error code to return to all accesses to
243 // A list of the IFILE instances for this OFile
248 // The dynamic information
252 UINTN FileCurrentCluster
;
253 UINTN FileLastCluster
;
256 // Dirty is set if there have been any updates to the
258 // Archive is set if the archive attribute in the file's
259 // directory entry needs to be set when performing flush
260 // PreserveLastMod is set if the last modification of the
261 // file is specified by SetInfo API
264 BOOLEAN IsFixedRootDir
;
265 BOOLEAN PreserveLastModification
;
268 // Set by an OFile SetPosition
270 UINTN Position
; // within file
271 UINT64 PosDisk
; // on the disk
272 UINTN PosRem
; // remaining in this disk run
274 // The opened parent, full path length and currently opened child files
278 LIST_ENTRY ChildHead
;
279 LIST_ENTRY ChildLink
;
282 // The opened directory structure for a directory; if this
283 // OFile represents a file, then ODir = NULL
287 // The directory entry for the Ofile
292 // Link in Volume's reference list
294 LIST_ENTRY CheckLink
;
304 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface
;
307 // If opened, the parent handle and BlockIo interface
309 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
310 EFI_DISK_IO_PROTOCOL
*DiskIo
;
311 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
316 // Computed values from fat bpb info
319 UINT64 FatPos
; // Disk pos of fat tables
320 UINT64 RootPos
; // Disk pos of root directory
321 UINT64 FirstClusterPos
; // Disk pos of first cluster
322 UINTN FatSize
; // Number of bytes in each fat
323 UINTN MaxCluster
; // Max cluster number
324 UINTN ClusterSize
; // Cluster size of fat partition
325 UINT8 ClusterAlignment
; // Equal to log_2 (clustersize);
326 FAT_VOLUME_TYPE FatType
;
329 // Current part of fat table that's present
331 UINT64 FatEntryPos
; // Location of buffer
332 UINTN FatEntrySize
; // Size of buffer
333 UINT32 FatEntryBuffer
; // The buffer
334 FAT_INFO_SECTOR FatInfoSector
; // Free cluster info
335 UINTN FreeInfoPos
; // Pos with the free cluster info
336 BOOLEAN FreeInfoValid
; // If free cluster info is valid
338 // Unpacked Fat BPB info
341 UINTN RootEntries
; // < FAT32, root dir is fixed size
342 UINTN RootCluster
; // >= FAT32, root cluster chain head
344 // info for marking the volume dirty or not
346 BOOLEAN FatDirty
; // If fat-entries have been updated
348 UINT32 NotDirtyValue
;
351 // The root directory entry and opened root file
353 FAT_DIRENT RootDirEnt
;
355 // File Name of root OFile, it is empty string
357 CHAR16 RootFileString
[1];
361 // New OFiles are added to this list so they
362 // can be cleaned up if they aren't referenced.
367 // Directory cache List
369 LIST_ENTRY DirCacheList
;
373 // Disk Cache for this volume
376 DISK_CACHE DiskCache
[CacheMaxType
];
380 // Function Prototypes
385 Implements Open() of Simple File System Protocol.
387 @param FHand - File handle of the file serves as a starting reference point.
388 @param NewHandle - Handle of the file that is newly opened.
389 @param FileName - File name relative to FHand.
390 @param OpenMode - Open mode.
391 @param Attributes - Attributes to set if the file is created.
394 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
395 The OpenMode is not supported.
396 The Attributes is not the valid attributes.
397 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
398 @retval EFI_SUCCESS - Open the file successfully.
399 @return Others - The status of open file.
405 IN EFI_FILE_PROTOCOL
*FHand
,
406 OUT EFI_FILE_PROTOCOL
**NewHandle
,
415 Implements OpenEx() of Simple File System Protocol.
417 @param FHand - File handle of the file serves as a starting reference point.
418 @param NewHandle - Handle of the file that is newly opened.
419 @param FileName - File name relative to FHand.
420 @param OpenMode - Open mode.
421 @param Attributes - Attributes to set if the file is created.
422 @param Token - A pointer to the token associated with the transaction.
424 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
425 The OpenMode is not supported.
426 The Attributes is not the valid attributes.
427 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
428 @retval EFI_SUCCESS - Open the file successfully.
429 @return Others - The status of open file.
435 IN EFI_FILE_PROTOCOL
*FHand
,
436 OUT EFI_FILE_PROTOCOL
**NewHandle
,
439 IN UINT64 Attributes
,
440 IN OUT EFI_FILE_IO_TOKEN
*Token
446 Get the file's position of the file
448 @param FHand - The handle of file.
449 @param Position - The file's position of the file.
451 @retval EFI_SUCCESS - Get the info successfully.
452 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
453 @retval EFI_UNSUPPORTED - The open file is not a file.
459 IN EFI_FILE_PROTOCOL
*FHand
,
466 Get the some types info of the file into Buffer
468 @param FHand - The handle of file.
469 @param Type - The type of the info.
470 @param BufferSize - Size of Buffer.
471 @param Buffer - Buffer containing volume info.
473 @retval EFI_SUCCESS - Get the info successfully.
474 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
480 IN EFI_FILE_PROTOCOL
*FHand
,
482 IN OUT UINTN
*BufferSize
,
489 Set the some types info of the file into Buffer.
491 @param FHand - The handle of file.
492 @param Type - The type of the info.
493 @param BufferSize - Size of Buffer.
494 @param Buffer - Buffer containing volume info.
496 @retval EFI_SUCCESS - Set the info successfully.
497 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
503 IN EFI_FILE_PROTOCOL
*FHand
,
512 Flushes all data associated with the file handle.
514 @param FHand - Handle to file to flush
516 @retval EFI_SUCCESS - Flushed the file successfully
517 @retval EFI_WRITE_PROTECTED - The volume is read only
518 @retval EFI_ACCESS_DENIED - The volume is not read only
519 but the file is read only
520 @return Others - Flushing of the file is failed
526 IN EFI_FILE_PROTOCOL
*FHand
532 Flushes all data associated with the file handle.
534 @param FHand - Handle to file to flush.
535 @param Token - A pointer to the token associated with the transaction.
537 @retval EFI_SUCCESS - Flushed the file successfully.
538 @retval EFI_WRITE_PROTECTED - The volume is read only.
539 @retval EFI_ACCESS_DENIED - The file is read only.
540 @return Others - Flushing of the file failed.
546 IN EFI_FILE_PROTOCOL
*FHand
,
547 IN EFI_FILE_IO_TOKEN
*Token
553 Flushes & Closes the file handle.
555 @param FHand - Handle to the file to delete.
557 @retval EFI_SUCCESS - Closed the file successfully.
563 IN EFI_FILE_PROTOCOL
*FHand
569 Deletes the file & Closes the file handle.
571 @param FHand - Handle to the file to delete.
573 @retval EFI_SUCCESS - Delete the file successfully.
574 @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
580 IN EFI_FILE_PROTOCOL
*FHand
586 Set the file's position of the file.
588 @param FHand - The handle of file
589 @param Position - The file's position of the file
591 @retval EFI_SUCCESS - Set the info successfully
592 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file
593 @retval EFI_UNSUPPORTED - Set a directory with a not-zero position
599 IN EFI_FILE_PROTOCOL
*FHand
,
608 @param FHand - The handle of the file.
609 @param BufferSize - Size of Buffer.
610 @param Buffer - Buffer containing read data.
612 @retval EFI_SUCCESS - Get the file info successfully.
613 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
614 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
615 @return other - An error occurred when operation the disk.
621 IN EFI_FILE_PROTOCOL
*FHand
,
622 IN OUT UINTN
*BufferSize
,
631 @param FHand - The handle of the file.
632 @param Token - A pointer to the token associated with the transaction.
634 @retval EFI_SUCCESS - Get the file info successfully.
635 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
636 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
637 @return other - An error occurred when operation the disk.
643 IN EFI_FILE_PROTOCOL
*FHand
,
644 IN OUT EFI_FILE_IO_TOKEN
*Token
652 @param FHand - The handle of the file.
653 @param BufferSize - Size of Buffer.
654 @param Buffer - Buffer containing write data.
656 @retval EFI_SUCCESS - Set the file info successfully.
657 @retval EFI_WRITE_PROTECTED - The disk is write protected.
658 @retval EFI_ACCESS_DENIED - The file is read-only.
659 @retval EFI_DEVICE_ERROR - The OFile is not valid.
660 @retval EFI_UNSUPPORTED - The open file is not a file.
661 - The writing file size is larger than 4GB.
662 @return other - An error occurred when operation the disk.
668 IN EFI_FILE_PROTOCOL
*FHand
,
669 IN OUT UINTN
*BufferSize
,
678 @param FHand - The handle of the file.
679 @param Token - A pointer to the token associated with the transaction.
681 @retval EFI_SUCCESS - Get the file info successfully.
682 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
683 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
684 @return other - An error occurred when operation the disk.
690 IN EFI_FILE_PROTOCOL
*FHand
,
691 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
,
777 Flush the data associated with an open file.
778 In this implementation, only last Mod/Access time is updated.
780 @param OFile - The open file.
782 @retval EFI_SUCCESS - The OFile is flushed successfully.
783 @return Others - An error occurred when flushing this OFile.
793 Check the references of the OFile.
794 If the OFile (that is checked) is no longer
795 referenced, then it is freed.
797 @param OFile - The OFile to be checked.
799 @retval TRUE - The OFile is not referenced and freed.
800 @retval FALSE - The OFile is kept.
810 Set the OFile and its child OFile with the error Status
812 @param OFile - The OFile whose permanent error code is to be set.
813 @param Status - Error code to be set.
824 Close the open file instance.
826 @param IFile - Open file instance.
828 @retval EFI_SUCCESS - Closed the file successfully.
838 Set error status for a specific OFile, reference checking the volume.
839 If volume is already marked as invalid, and all resources are freed
840 after reference checking, the file system protocol is uninstalled and
841 the volume structure is freed.
843 @param Volume - the Volume that is to be reference checked and unlocked.
844 @param OFile - the OFile whose permanent error code is to be set.
845 @param EfiStatus - error code to be set.
846 @param Task point to task instance.
848 @retval EFI_SUCCESS - Clean up the volume successfully.
849 @return Others - Cleaning up of the volume is failed.
854 IN FAT_VOLUME
*Volume
,
856 IN EFI_STATUS EfiStatus
,
866 Shrink the end of the open file base on the file size.
868 @param OFile - The open file.
870 @retval EFI_SUCCESS - Shrinked successfully.
871 @retval EFI_VOLUME_CORRUPTED - There are errors in the file's clusters.
881 Grow the end of the open file base on the NewSizeInBytes.
883 @param OFile - The open file.
884 @param NewSizeInBytes - The new size in bytes of the open file.
886 @retval EFI_SUCCESS - The file is grown successfully.
887 @retval EFI_UNSUPPORTED - The file size is larger than 4GB.
888 @retval EFI_VOLUME_CORRUPTED - There are errors in the files' clusters.
889 @retval EFI_VOLUME_FULL - The volume is full and can not grow the file.
895 IN UINT64 NewSizeInBytes
900 Get the size of directory of the open file.
902 @param Volume - The File System Volume.
903 @param Cluster - The Starting cluster.
905 @return The physical size of the file starting at the input cluster, if there is error in the
906 cluster chain, the return value is 0.
911 IN FAT_VOLUME
*Volume
,
917 Get the physical size of a file on the disk.
919 @param Volume - The file system volume.
920 @param RealSize - The real size of a file.
922 @return The physical size of a file on the disk.
926 FatPhysicalFileSize (
927 IN FAT_VOLUME
*Volume
,
933 Seek OFile to requested position, and calculate the number of
934 consecutive clusters from the position in the file
936 @param OFile - The open file.
937 @param Position - The file's position which will be accessed.
938 @param PosLimit - The maximum length current reading/writing may access
940 @retval EFI_SUCCESS - Set the info successfully.
941 @retval EFI_VOLUME_CORRUPTED - Cluster chain corrupt.
953 Update the free cluster info of FatInfoSector of the volume.
955 @param Volume - FAT file system volume.
960 IN FAT_VOLUME
*Volume
969 Allocates volume structure, detects FAT file system, installs protocol,
970 and initialize cache.
972 @param Handle - The handle of parent device.
973 @param DiskIo - The DiskIo of parent device.
974 @param DiskIo2 - The DiskIo2 of parent device.
975 @param BlockIo - The BlockIo of parent device.
977 @retval EFI_SUCCESS - Allocate a new volume successfully.
978 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
979 @return Others - Allocating a new volume failed.
984 IN EFI_HANDLE Handle
,
985 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
986 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
987 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
992 Detects FAT file system on Disk and set relevant fields of Volume.
994 @param Volume - The volume structure.
996 @retval EFI_SUCCESS - The Fat File System is detected successfully
997 @retval EFI_UNSUPPORTED - The volume is not FAT file system.
998 @retval EFI_VOLUME_CORRUPTED - The volume is corrupted.
1003 IN OUT FAT_VOLUME
*Volume
1008 Called by FatDriverBindingStop(), Abandon the volume.
1010 @param Volume - The volume to be abandoned.
1012 @retval EFI_SUCCESS - Abandoned the volume successfully.
1013 @return Others - Can not uninstall the protocol interfaces.
1018 IN FAT_VOLUME
*Volume
1029 @param IFile - The instance of the open file.
1030 @param Token - A pointer to the token associated with the transaction.
1032 @return FAT_TASK * - Return the task instance.
1038 EFI_FILE_IO_TOKEN
*Token
1045 @param Task - The task to be destroyed.
1055 Wait all non-blocking requests complete.
1057 @param IFile - The instance of the open file.
1061 FatWaitNonblockingTask (
1067 Remove the subtask from subtask list.
1069 @param Subtask - The subtask to be removed.
1071 @return LIST_ENTRY * - The next node in the list.
1076 FAT_SUBTASK
*Subtask
1083 @param IFile - The instance of the open file.
1084 @param Task - The task to be executed.
1086 @retval EFI_SUCCESS - The task was executed successfully.
1087 @return other - An error occurred when executing the task.
1092 IN FAT_IFILE
*IFile
,
1098 Set the volume as dirty or not.
1100 @param Volume - FAT file system volume.
1101 @param IoMode - The access mode.
1102 @param DirtyValue - Set the volume as dirty or not.
1104 @retval EFI_SUCCESS - Set the new FAT entry value successfully.
1105 @return other - An error occurred when operation the FAT entries.
1109 FatAccessVolumeDirty (
1110 IN FAT_VOLUME
*Volume
,
1117 General disk access function.
1119 @param Volume - FAT file system volume.
1120 @param IoMode - The access mode (disk read/write or cache access).
1121 @param Offset - The starting byte offset to read from.
1122 @param BufferSize - Size of Buffer.
1123 @param Buffer - Buffer containing read data.
1124 @param Task point to task instance.
1126 @retval EFI_SUCCESS - The operation is performed successfully.
1127 @retval EFI_VOLUME_CORRUPTED - The access is
1128 @return Others - The status of read/write the disk
1133 IN FAT_VOLUME
*Volume
,
1136 IN UINTN BufferSize
,
1137 IN OUT VOID
*Buffer
,
1164 If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
1165 Otherwise, EFI_SUCCESS is returned.
1167 @retval EFI_SUCCESS - The volume is locked.
1168 @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.
1172 FatAcquireLockOrFail (
1178 Free directory entry.
1180 @param DirEnt - The directory entry to be freed.
1185 IN FAT_DIRENT
*DirEnt
1190 Free volume structure (including the contents of directory cache and disk cache).
1192 @param Volume - The volume structure to be freed.
1197 IN FAT_VOLUME
*Volume
1202 Translate EFI time to FAT time.
1204 @param ETime - The time of EFI_TIME.
1205 @param FTime - The time of FAT_DATE_TIME.
1209 FatEfiTimeToFatTime (
1211 OUT FAT_DATE_TIME
*FTime
1216 Translate Fat time to EFI time.
1218 @param FTime - The time of FAT_DATE_TIME.
1219 @param ETime - The time of EFI_TIME..
1223 FatFatTimeToEfiTime (
1224 IN FAT_DATE_TIME
*FTime
,
1230 Get Current FAT time.
1232 @param FatTime - Current FAT time.
1236 FatGetCurrentFatTime (
1237 OUT FAT_DATE_TIME
*FatTime
1242 Check whether a time is valid.
1244 @param Time - The time of EFI_TIME.
1246 @retval TRUE - The time is valid.
1247 @retval FALSE - The time is not valid.
1256 // UnicodeCollation.c
1260 Initialize Unicode Collation support.
1262 It tries to locate Unicode Collation 2 protocol and matches it with current
1263 platform language code. If for any reason the first attempt fails, it then tries to
1264 use Unicode Collation Protocol.
1266 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
1268 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
1269 @retval Others The Unicode Collation (2) protocol has not been located.
1273 InitializeUnicodeCollationSupport (
1274 IN EFI_HANDLE AgentHandle
1278 Convert FAT string to unicode string.
1280 @param FatSize The size of FAT string.
1281 @param Fat The FAT string.
1282 @param String The unicode string.
1295 Convert unicode string to Fat string.
1297 @param String The unicode string.
1298 @param FatSize The size of the FAT string.
1299 @param Fat The FAT string.
1301 @retval TRUE Convert successfully.
1302 @retval FALSE Convert error.
1315 @param Str The string which will be lower-cased.
1326 @param Str The string which will be upper-cased.
1335 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
1337 @param Str1 A pointer to a Null-terminated Unicode string.
1338 @param Str2 A pointer to a Null-terminated Unicode string.
1340 @retval 0 S1 is equivalent to S2.
1341 @retval >0 S1 is lexically greater than S2.
1342 @retval <0 S1 is lexically less than S2.
1356 Open a file for a file name relative to an existing OFile.
1357 The IFile of the newly opened file is passed out.
1359 @param OFile - The file that serves as a starting reference point.
1360 @param NewIFile - The newly generated IFile instance.
1361 @param FileName - The file name relative to the OFile.
1362 @param OpenMode - Open mode.
1363 @param Attributes - Attributes to set if the file is created.
1366 @retval EFI_SUCCESS - Open the file successfully.
1367 @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes
1368 or the file name is not valid.
1369 @retval EFI_NOT_FOUND - Conflicts between dir intention and attribute.
1370 @retval EFI_WRITE_PROTECTED - Can't open for write if the volume is read only.
1371 @retval EFI_ACCESS_DENIED - If the file's attribute is read only, and the
1372 open is for read-write fail it.
1373 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
1378 IN FAT_OFILE
*OFile
,
1379 OUT FAT_IFILE
**NewIFile
,
1380 IN CHAR16
*FileName
,
1387 Create an Open instance for the existing OFile.
1388 The IFile of the newly opened file is passed out.
1390 @param OFile - The file that serves as a starting reference point.
1391 @param PtrIFile - The newly generated IFile instance.
1393 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for the IFile
1394 @retval EFI_SUCCESS - Create the new IFile for the OFile successfully
1399 IN FAT_OFILE
*OFile
,
1400 OUT FAT_IFILE
**PtrIFile
1409 Implements Simple File System Protocol interface function OpenVolume().
1411 @param This - Calling context.
1412 @param File - the Root Directory of the volume.
1414 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
1415 @retval EFI_VOLUME_CORRUPTED - The FAT type is error.
1416 @retval EFI_SUCCESS - Open the volume successfully.
1422 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*This
,
1423 OUT EFI_FILE_PROTOCOL
**File
1432 This function reads data from a file or writes data to a file.
1433 It uses OFile->PosRem to determine how much data can be accessed in one time.
1435 @param OFile - The open file.
1436 @param IoMode - Indicate whether the access mode is reading or writing.
1437 @param Position - The position where data will be accessed.
1438 @param DataBufferSize - Size of Buffer.
1439 @param UserBuffer - Buffer containing data.
1440 @param Task point to task instance.
1442 @retval EFI_SUCCESS - Access the data successfully.
1443 @return other - An error occurred when operating on the disk.
1448 IN FAT_OFILE
*OFile
,
1451 IN UINTN
*DataBufferSize
,
1452 IN UINT8
*UserBuffer
,
1458 Expand OFile by appending zero bytes at the end of OFile.
1460 @param OFile - The open file.
1461 @param ExpandedSize - The number of zero bytes appended at the end of the file.
1463 @retval EFI_SUCCESS - The file is expanded successfully.
1464 @return other - An error occurred when expanding file.
1469 IN FAT_OFILE
*OFile
,
1470 IN UINT64 ExpandedSize
1475 Write zero pool from the WritePos to the end of OFile.
1477 @param OFile - The open file to write zero pool.
1478 @param WritePos - The number of zero bytes written.
1480 @retval EFI_SUCCESS - Write the zero pool successfully.
1481 @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation.
1482 @return other - An error occurred when writing disk.
1487 IN FAT_OFILE
*OFile
,
1493 Truncate the OFile to smaller file size.
1495 @param OFile - The open file.
1496 @param TruncatedSize - The new file size.
1498 @retval EFI_SUCCESS - The file is truncated successfully.
1499 @return other - An error occurred when truncating file.
1504 IN FAT_OFILE
*OFile
,
1505 IN UINTN TruncatedSize
1509 // DirectoryManage.c
1514 Set the OFile's current directory cursor to the list head.
1516 @param OFile - The directory OFile whose directory cursor is reset.
1520 FatResetODirCursor (
1526 Set the directory's cursor to the next and get the next directory entry.
1528 @param OFile - The parent OFile.
1529 @param PtrDirEnt - The next directory entry.
1531 @retval EFI_SUCCESS - We get the next directory entry successfully.
1532 @return other - An error occurred when get next directory entry.
1537 IN FAT_OFILE
*OFile
,
1538 OUT FAT_DIRENT
**PtrDirEnt
1543 Remove this directory entry node from the list of directory entries and hash table.
1545 @param OFile - The parent OFile.
1546 @param DirEnt - The directory entry to be removed.
1548 @retval EFI_SUCCESS - The directory entry is successfully removed.
1549 @return other - An error occurred when removing the directory entry.
1554 IN FAT_OFILE
*OFile
,
1555 IN FAT_DIRENT
*DirEnt
1560 Save the directory entry to disk.
1562 @param OFile - The parent OFile which needs to update.
1563 @param DirEnt - The directory entry to be saved.
1565 @retval EFI_SUCCESS - Store the directory entry successfully.
1566 @return other - An error occurred when writing the directory entry.
1571 IN FAT_OFILE
*OFile
,
1572 IN FAT_DIRENT
*DirEnt
1577 Create a directory entry in the parent OFile.
1579 @param OFile - The parent OFile.
1580 @param FileName - The filename of the newly-created directory entry.
1581 @param Attributes - The attribute of the newly-created directory entry.
1582 @param PtrDirEnt - The pointer to the newly-created directory entry.
1584 @retval EFI_SUCCESS - The directory entry is successfully created.
1585 @retval EFI_OUT_OF_RESOURCES - Not enough memory to create the directory entry.
1586 @return other - An error occurred when creating the directory entry.
1591 IN FAT_OFILE
*OFile
,
1592 IN CHAR16
*FileName
,
1593 IN UINT8 Attributes
,
1594 OUT FAT_DIRENT
**PtrDirEnt
1599 Determine whether the directory entry is "." or ".." entry.
1601 @param DirEnt - The corresponding directory entry.
1603 @retval TRUE - The directory entry is "." or ".." directory entry
1604 @retval FALSE - The directory entry is not "." or ".." directory entry
1609 IN FAT_DIRENT
*DirEnt
1614 Set the OFile's cluster and size info in its directory entry.
1616 @param OFile - The corresponding OFile.
1620 FatUpdateDirEntClusterSizeInfo (
1626 Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.
1628 @param DirEnt1 - The destination directory entry.
1629 @param DirEnt2 - The source directory entry.
1634 IN FAT_DIRENT
*DirEnt1
,
1635 IN FAT_DIRENT
*DirEnt2
1640 Get the directory entry's info into Buffer.
1642 @param Volume - FAT file system volume.
1643 @param DirEnt - The corresponding directory entry.
1644 @param BufferSize - Size of Buffer.
1645 @param Buffer - Buffer containing file info.
1647 @retval EFI_SUCCESS - Get the file info successfully.
1648 @retval EFI_BUFFER_TOO_SMALL - The buffer is too small.
1653 IN FAT_VOLUME
*Volume
,
1654 IN FAT_DIRENT
*DirEnt
,
1655 IN OUT UINTN
*BufferSize
,
1661 Open the directory entry to get the OFile.
1663 @param Parent - The parent OFile.
1664 @param DirEnt - The directory entry to be opened.
1666 @retval EFI_SUCCESS - The directory entry is successfully opened.
1667 @retval EFI_OUT_OF_RESOURCES - not enough memory to allocate a new OFile.
1668 @return other - An error occurred when opening the directory entry.
1673 IN FAT_OFILE
*OFile
,
1674 IN FAT_DIRENT
*DirEnt
1679 Create "." and ".." directory entries in the newly-created parent OFile.
1681 @param OFile - The parent OFile.
1683 @retval EFI_SUCCESS - The dot directory entries are successfully created.
1684 @return other - An error occurred when creating the directory entry.
1688 FatCreateDotDirEnts (
1694 Close the directory entry and free the OFile.
1696 @param DirEnt - The directory entry to be closed.
1701 IN FAT_DIRENT
*DirEnt
1706 Traverse filename and open all OFiles that can be opened.
1707 Update filename pointer to the component that can't be opened.
1708 If more than one name component remains, returns an error;
1709 otherwise, return the remaining name component so that the caller might choose to create it.
1711 @param PtrOFile - As input, the reference OFile; as output, the located OFile.
1712 @param FileName - The file name relevant to the OFile.
1713 @param Attributes - The attribute of the destination OFile.
1714 @param NewFileName - The remaining file name.
1716 @retval EFI_NOT_FOUND - The file name can't be opened and there is more than one
1717 components within the name left (this means the name can
1718 not be created either).
1719 @retval EFI_INVALID_PARAMETER - The parameter is not valid.
1720 @retval EFI_SUCCESS - Open the file successfully.
1721 @return other - An error occurred when locating the OFile.
1726 IN OUT FAT_OFILE
**PtrOFile
,
1727 IN CHAR16
*FileName
,
1728 IN UINT8 Attributes
,
1729 OUT CHAR16
*NewFileName
1734 Get the directory entry for the volume.
1736 @param Volume - FAT file system volume.
1737 @param Name - The file name of the volume.
1739 @retval EFI_SUCCESS - Update the volume with the directory entry successfully.
1740 @return others - An error occurred when getting volume label.
1745 IN FAT_VOLUME
*Volume
,
1751 Set the relevant directory entry into disk for the volume.
1753 @param Volume - FAT file system volume.
1754 @param Name - The new file name of the volume.
1756 @retval EFI_SUCCESS - Update the Volume successfully.
1757 @retval EFI_UNSUPPORTED - The input label is not a valid volume label.
1758 @return other - An error occurred when setting volume label.
1763 IN FAT_VOLUME
*Volume
,
1773 Search the long name hash table for the directory entry.
1775 @param ODir - The directory to be searched.
1776 @param LongNameString - The long name string to search.
1778 @return The previous long name hash node of the directory entry.
1782 FatLongNameHashSearch (
1784 IN CHAR16
*LongNameString
1789 Search the short name hash table for the directory entry.
1791 @param ODir - The directory to be searched.
1792 @param ShortNameString - The short name string to search.
1794 @return The previous short name hash node of the directory entry.
1798 FatShortNameHashSearch (
1800 IN CHAR8
*ShortNameString
1805 Insert directory entry to hash table.
1807 @param ODir - The parent directory.
1808 @param DirEnt - The directory entry node.
1812 FatInsertToHashTable (
1814 IN FAT_DIRENT
*DirEnt
1819 Delete directory entry from hash table.
1821 @param ODir - The parent directory.
1822 @param DirEnt - The directory entry node.
1826 FatDeleteFromHashTable (
1828 IN FAT_DIRENT
*DirEnt
1837 This function checks whether the input FileName is a valid 8.3 short name.
1838 If the input FileName is a valid 8.3, the output is the 8.3 short name;
1839 otherwise, the output is the base tag of 8.3 short name.
1841 @param FileName - The input unicode filename.
1842 @param File8Dot3Name - The output ascii 8.3 short name or base tag of 8.3 short name.
1844 @retval TRUE - The input unicode filename is a valid 8.3 short name.
1845 @retval FALSE - The input unicode filename is not a valid 8.3 short name.
1849 FatCheckIs8Dot3Name (
1850 IN CHAR16
*FileName
,
1851 OUT CHAR8
*File8Dot3Name
1856 This function generates 8Dot3 name from user specified name for a newly created file.
1858 @param Parent - The parent directory.
1859 @param DirEnt - The directory entry whose 8Dot3Name needs to be generated.
1863 FatCreate8Dot3Name (
1864 IN FAT_OFILE
*Parent
,
1865 IN FAT_DIRENT
*DirEnt
1870 Convert the ascii fat name to the unicode string and strip trailing spaces,
1871 and if necessary, convert the unicode string to lower case.
1873 @param FatName - The Char8 string needs to be converted.
1874 @param Len - The length of the fat name.
1875 @param LowerCase - Indicate whether to convert the string to lower case.
1876 @param Str - The result of the conversion.
1889 Set the caseflag value for the directory entry.
1891 @param DirEnt - The logical directory entry whose caseflag value is to be set.
1896 IN FAT_DIRENT
*DirEnt
1901 Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.
1903 @param DirEnt - The corresponding directory entry.
1904 @param FileString - The output Unicode file name.
1905 @param FileStringMax The max length of FileString.
1909 FatGetFileNameViaCaseFlag (
1910 IN FAT_DIRENT
*DirEnt
,
1911 IN OUT CHAR16
*FileString
,
1912 IN UINTN FileStringMax
1917 Get the Check sum for a short name.
1919 @param ShortNameString - The short name for a file.
1921 @retval Sum - UINT8 checksum.
1926 IN CHAR8
*ShortNameString
1931 Takes Path as input, returns the next name component
1932 in Name, and returns the position after Name (e.g., the
1933 start of the next name component)
1935 @param Path - The path of one file.
1936 @param Name - The next name component in Path.
1938 The position after Name in the Path
1942 FatGetNextNameComponent (
1949 Check whether the IFileName is valid long file name. If the IFileName is a valid
1950 long file name, then we trim the possible leading blanks and leading/trailing dots.
1951 the trimmed filename is stored in OutputFileName
1953 @param InputFileName - The input file name.
1954 @param OutputFileName - The output file name.
1956 @retval TRUE - The InputFileName is a valid long file name.
1957 @retval FALSE - The InputFileName is not a valid long file name.
1961 FatFileNameIsValid (
1962 IN CHAR16
*InputFileName
,
1963 OUT CHAR16
*OutputFileName
1972 Discard the directory structure when an OFile will be freed.
1973 Volume will cache this directory if the OFile does not represent a deleted file.
1975 @param OFile - The OFile whose directory structure is to be discarded.
1985 Request the directory structure when an OFile is newly generated.
1986 If the directory structure is cached by volume, then just return this directory;
1987 Otherwise, allocate a new one for OFile.
1989 @param OFile - The OFile which requests directory structure.
1999 Clean up all the cached directory structures when the volume is going to be abandoned.
2001 @param Volume - FAT file system volume.
2005 FatCleanupODirCache (
2006 IN FAT_VOLUME
*Volume
2012 extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
;
2013 extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName
;
2014 extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2
;
2015 extern EFI_LOCK FatFsLock
;
2016 extern EFI_LOCK FatTaskLock
;
2017 extern EFI_FILE_PROTOCOL FatFileInterface
;