2 Main header file for EFI FAT file system driver.
4 Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include <Guid/FileInfo.h>
21 #include <Guid/FileSystemInfo.h>
22 #include <Guid/FileSystemVolumeLabelInfo.h>
23 #include <Protocol/BlockIo.h>
24 #include <Protocol/DiskIo.h>
25 #include <Protocol/DiskIo2.h>
26 #include <Protocol/SimpleFileSystem.h>
27 #include <Protocol/UnicodeCollation.h>
29 #include <Library/PcdLib.h>
30 #include <Library/DebugLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/BaseLib.h>
33 #include <Library/BaseMemoryLib.h>
34 #include <Library/MemoryAllocationLib.h>
35 #include <Library/UefiDriverEntryPoint.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
39 #include "FatFileSystem.h"
44 #define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
45 #define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
46 #define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
47 #define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
48 #define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
49 #define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
50 #define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
52 #define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
54 #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
56 #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
58 #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
60 #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
62 #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
64 #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
66 #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
69 // Minimum sector size is 512B, Maximum sector size is 4096B
70 // Max sectors per cluster is 128
72 #define MAX_BLOCK_ALIGNMENT 12
73 #define MIN_BLOCK_ALIGNMENT 9
74 #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
77 // Efi Time Definition
79 #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
82 // Minimum fat page size is 8K, maximum fat page alignment is 32K
83 // Minimum data page size is 8K, maximum fat page alignment is 64K
85 #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13
86 #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15
87 #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13
88 #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16
89 #define FAT_DATACACHE_GROUP_COUNT 64
90 #define FAT_FATCACHE_GROUP_MIN_COUNT 1
91 #define FAT_FATCACHE_GROUP_MAX_COUNT 16
94 // Used in 8.3 generation algorithm
96 #define MAX_SPEC_RETRY 4
97 #define SPEC_BASE_TAG_LEN 6
98 #define HASH_BASE_TAG_LEN 2
99 #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
102 // Path name separator is back slash
104 #define PATH_NAME_SEPARATOR L'\\'
107 #define EFI_PATH_STRING_LENGTH 260
108 #define EFI_FILE_STRING_LENGTH 255
109 #define FAT_MAX_ALLOCATE_SIZE 0xA00000
110 #define LC_ISO_639_2_ENTRY_SIZE 3
111 #define MAX_LANG_CODE_SIZE 100
113 #define FAT_MAX_DIR_CACHE_COUNT 8
114 #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
115 typedef CHAR8 LC_ISO_639_2
;
118 // The fat types we support
137 ReadDisk
= 0, // raw disk read
138 WriteDisk
= 1, // raw disk write
139 ReadFat
= 2, // read fat cache
140 WriteFat
= 3, // write fat cache
141 ReadData
= 6, // read data cache
142 WriteData
= 7 // write data cache
145 #define CACHE_ENABLED(a) ((a) >= 2)
146 #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
147 #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
165 CACHE_TAG CacheTag
[FAT_DATACACHE_GROUP_COUNT
];
171 #define HASH_TABLE_SIZE 0x400
172 #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
175 // The directory entry for opened directory
178 typedef struct _FAT_DIRENT FAT_DIRENT
;
179 typedef struct _FAT_ODIR FAT_ODIR
;
180 typedef struct _FAT_OFILE FAT_OFILE
;
181 typedef struct _FAT_VOLUME FAT_VOLUME
;
185 UINT16 EntryPos
; // The position of this directory entry in the parent directory file
186 UINT8 EntryCount
; // The count of the directory entry in the parent directory file
187 BOOLEAN Invalid
; // Indicate whether this directory entry is valid
188 CHAR16
*FileString
; // The unicode long file name for this directory entry
189 FAT_OFILE
*OFile
; // The OFile of the corresponding directory entry
190 FAT_DIRENT
*ShortNameForwardLink
; // Hash successor link for short filename
191 FAT_DIRENT
*LongNameForwardLink
; // Hash successor link for long filename
192 LIST_ENTRY Link
; // Connection of every directory entry
193 FAT_DIRECTORY_ENTRY Entry
; // The physical directory entry stored in disk
198 UINT32 CurrentEndPos
; // Current end position of the directory
199 UINT32 CurrentPos
; // Current position of the directory
200 LIST_ENTRY
*CurrentCursor
; // Current directory entry pointer
201 LIST_ENTRY ChildList
; // List of all directory entries
202 BOOLEAN EndOfDir
; // Indicate whether we have reached the end of the directory
203 LIST_ENTRY DirCacheLink
; // Linked in Volume->DirCacheList when discarded
204 UINTN DirCacheTag
; // The identification of the directory when in directory cache
205 FAT_DIRENT
*LongNameHashTable
[HASH_TABLE_SIZE
];
206 FAT_DIRENT
*ShortNameHashTable
[HASH_TABLE_SIZE
];
211 EFI_FILE_PROTOCOL Handle
;
215 LIST_ENTRY Tasks
; // List of all FAT_TASKs
216 LIST_ENTRY Link
; // Link to other IFiles
221 EFI_FILE_IO_TOKEN
*FileIoToken
;
223 LIST_ENTRY Subtasks
; // List of all FAT_SUBTASKs
224 LIST_ENTRY Link
; // Link to other FAT_TASKs
229 EFI_DISK_IO2_TOKEN DiskIo2Token
;
239 // FAT_OFILE - Each opened file
245 // A permanant error code to return to all accesses to
250 // A list of the IFILE instances for this OFile
255 // The dynamic infomation
259 UINTN FileCurrentCluster
;
260 UINTN FileLastCluster
;
263 // Dirty is set if there have been any updates to the
265 // Archive is set if the archive attribute in the file's
266 // directory entry needs to be set when performing flush
267 // PreserveLastMod is set if the last modification of the
268 // file is specified by SetInfo API
271 BOOLEAN IsFixedRootDir
;
272 BOOLEAN PreserveLastModification
;
275 // Set by an OFile SetPosition
277 UINTN Position
; // within file
278 UINT64 PosDisk
; // on the disk
279 UINTN PosRem
; // remaining in this disk run
281 // The opened parent, full path length and currently opened child files
285 LIST_ENTRY ChildHead
;
286 LIST_ENTRY ChildLink
;
289 // The opened directory structure for a directory; if this
290 // OFile represents a file, then ODir = NULL
294 // The directory entry for the Ofile
299 // Link in Volume's reference list
301 LIST_ENTRY CheckLink
;
311 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface
;
314 // If opened, the parent handle and BlockIo interface
316 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
317 EFI_DISK_IO_PROTOCOL
*DiskIo
;
318 EFI_DISK_IO2_PROTOCOL
*DiskIo2
;
323 // Computed values from fat bpb info
326 UINT64 FatPos
; // Disk pos of fat tables
327 UINT64 RootPos
; // Disk pos of root directory
328 UINT64 FirstClusterPos
; // Disk pos of first cluster
329 UINTN FatSize
; // Number of bytes in each fat
330 UINTN MaxCluster
; // Max cluster number
331 UINTN ClusterSize
; // Cluster size of fat partition
332 UINT8 ClusterAlignment
; // Equal to log_2 (clustersize);
333 FAT_VOLUME_TYPE FatType
;
336 // Current part of fat table that's present
338 UINT64 FatEntryPos
; // Location of buffer
339 UINTN FatEntrySize
; // Size of buffer
340 UINT32 FatEntryBuffer
; // The buffer
341 FAT_INFO_SECTOR FatInfoSector
; // Free cluster info
342 UINTN FreeInfoPos
; // Pos with the free cluster info
343 BOOLEAN FreeInfoValid
; // If free cluster info is valid
345 // Unpacked Fat BPB info
348 UINTN RootEntries
; // < FAT32, root dir is fixed size
349 UINTN RootCluster
; // >= FAT32, root cluster chain head
351 // info for marking the volume dirty or not
353 BOOLEAN FatDirty
; // If fat-entries have been updated
355 UINT32 NotDirtyValue
;
358 // The root directory entry and opened root file
360 FAT_DIRENT RootDirEnt
;
362 // File Name of root OFile, it is empty string
364 CHAR16 RootFileString
[1];
368 // New OFiles are added to this list so they
369 // can be cleaned up if they aren't referenced.
374 // Directory cache List
376 LIST_ENTRY DirCacheList
;
380 // Disk Cache for this volume
383 DISK_CACHE DiskCache
[CacheMaxType
];
387 // Function Prototypes
392 Implements Open() of Simple File System Protocol.
394 @param FHand - File handle of the file serves as a starting reference point.
395 @param NewHandle - Handle of the file that is newly opened.
396 @param FileName - File name relative to FHand.
397 @param OpenMode - Open mode.
398 @param Attributes - Attributes to set if the file is created.
401 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
402 The OpenMode is not supported.
403 The Attributes is not the valid attributes.
404 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
405 @retval EFI_SUCCESS - Open the file successfully.
406 @return Others - The status of open file.
412 IN EFI_FILE_PROTOCOL
*FHand
,
413 OUT EFI_FILE_PROTOCOL
**NewHandle
,
422 Implements OpenEx() of Simple File System Protocol.
424 @param FHand - File handle of the file serves as a starting reference point.
425 @param NewHandle - Handle of the file that is newly opened.
426 @param FileName - File name relative to FHand.
427 @param OpenMode - Open mode.
428 @param Attributes - Attributes to set if the file is created.
429 @param Token - A pointer to the token associated with the transaction.
431 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
432 The OpenMode is not supported.
433 The Attributes is not the valid attributes.
434 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
435 @retval EFI_SUCCESS - Open the file successfully.
436 @return Others - The status of open file.
442 IN EFI_FILE_PROTOCOL
*FHand
,
443 OUT EFI_FILE_PROTOCOL
**NewHandle
,
446 IN UINT64 Attributes
,
447 IN OUT EFI_FILE_IO_TOKEN
*Token
453 Get the file's position of the file
455 @param FHand - The handle of file.
456 @param Position - The file's position of the file.
458 @retval EFI_SUCCESS - Get the info successfully.
459 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
460 @retval EFI_UNSUPPORTED - The open file is not a file.
466 IN EFI_FILE_PROTOCOL
*FHand
,
473 Get the some types info of the file into Buffer
475 @param FHand - The handle of file.
476 @param Type - The type of the info.
477 @param BufferSize - Size of Buffer.
478 @param Buffer - Buffer containing volume info.
480 @retval EFI_SUCCESS - Get the info successfully.
481 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
487 IN EFI_FILE_PROTOCOL
*FHand
,
489 IN OUT UINTN
*BufferSize
,
496 Set the some types info of the file into Buffer.
498 @param FHand - The handle of file.
499 @param Type - The type of the info.
500 @param BufferSize - Size of Buffer.
501 @param Buffer - Buffer containing volume info.
503 @retval EFI_SUCCESS - Set the info successfully.
504 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
510 IN EFI_FILE_PROTOCOL
*FHand
,
519 Flushes all data associated with the file handle.
521 @param FHand - Handle to file to flush
523 @retval EFI_SUCCESS - Flushed the file successfully
524 @retval EFI_WRITE_PROTECTED - The volume is read only
525 @retval EFI_ACCESS_DENIED - The volume is not read only
526 but the file is read only
527 @return Others - Flushing of the file is failed
533 IN EFI_FILE_PROTOCOL
*FHand
539 Flushes all data associated with the file handle.
541 @param FHand - Handle to file to flush.
542 @param Token - A pointer to the token associated with the transaction.
544 @retval EFI_SUCCESS - Flushed the file successfully.
545 @retval EFI_WRITE_PROTECTED - The volume is read only.
546 @retval EFI_ACCESS_DENIED - The file is read only.
547 @return Others - Flushing of the file failed.
553 IN EFI_FILE_PROTOCOL
*FHand
,
554 IN EFI_FILE_IO_TOKEN
*Token
560 Flushes & Closes the file handle.
562 @param FHand - Handle to the file to delete.
564 @retval EFI_SUCCESS - Closed the file successfully.
570 IN EFI_FILE_PROTOCOL
*FHand
576 Deletes the file & Closes the file handle.
578 @param FHand - Handle to the file to delete.
580 @retval EFI_SUCCESS - Delete the file successfully.
581 @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
587 IN EFI_FILE_PROTOCOL
*FHand
593 Set the file's position of the file.
595 @param FHand - The handle of file
596 @param Position - The file's position of the file
598 @retval EFI_SUCCESS - Set the info successfully
599 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file
600 @retval EFI_UNSUPPORTED - Set a directory with a not-zero position
606 IN EFI_FILE_PROTOCOL
*FHand
,
615 @param FHand - The handle of the file.
616 @param BufferSize - Size of Buffer.
617 @param Buffer - Buffer containing read data.
619 @retval EFI_SUCCESS - Get the file info successfully.
620 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
621 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
622 @return other - An error occurred when operation the disk.
628 IN EFI_FILE_PROTOCOL
*FHand
,
629 IN OUT UINTN
*BufferSize
,
638 @param FHand - The handle of the file.
639 @param Token - A pointer to the token associated with the transaction.
641 @retval EFI_SUCCESS - Get the file info successfully.
642 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
643 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
644 @return other - An error occurred when operation the disk.
650 IN EFI_FILE_PROTOCOL
*FHand
,
651 IN OUT EFI_FILE_IO_TOKEN
*Token
659 @param FHand - The handle of the file.
660 @param BufferSize - Size of Buffer.
661 @param Buffer - Buffer containing write data.
663 @retval EFI_SUCCESS - Set the file info successfully.
664 @retval EFI_WRITE_PROTECTED - The disk is write protected.
665 @retval EFI_ACCESS_DENIED - The file is read-only.
666 @retval EFI_DEVICE_ERROR - The OFile is not valid.
667 @retval EFI_UNSUPPORTED - The open file is not a file.
668 - The writing file size is larger than 4GB.
669 @return other - An error occurred when operation the disk.
675 IN EFI_FILE_PROTOCOL
*FHand
,
676 IN OUT UINTN
*BufferSize
,
685 @param FHand - The handle of the file.
686 @param Token - A pointer to the token associated with the transaction.
688 @retval EFI_SUCCESS - Get the file info successfully.
689 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
690 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
691 @return other - An error occurred when operation the disk.
697 IN EFI_FILE_PROTOCOL
*FHand
,
698 IN OUT EFI_FILE_IO_TOKEN
*Token
707 Initialize the disk cache according to Volume's FatType.
709 @param Volume - FAT file system volume.
711 @retval EFI_SUCCESS - The disk cache is successfully initialized.
712 @retval EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.
716 FatInitializeDiskCache (
717 IN FAT_VOLUME
*Volume
722 Read BufferSize bytes from the position of Offset into Buffer,
723 or write BufferSize bytes from Buffer into the position of Offset.
725 Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into
726 the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):
728 1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache
729 page hit, just return the cache page; else update the related cache page and return
730 the right cache page.
731 2. Access of Data cache (CACHE_DATA):
732 The access data will be divided into UnderRun data, Aligned data and OverRun data;
733 The UnderRun data and OverRun data will be accessed by the Data cache,
734 but the Aligned data will be accessed with disk directly.
736 @param Volume - FAT file system volume.
737 @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.
738 @param IoMode - Indicate the type of disk access.
739 @param Offset - The starting byte offset to read from.
740 @param BufferSize - Size of Buffer.
741 @param Buffer - Buffer containing cache data.
742 @param Task point to task instance.
744 @retval EFI_SUCCESS - The data was accessed correctly.
745 @retval EFI_MEDIA_CHANGED - The MediaId does not match the current device.
746 @return Others - An error occurred when accessing cache.
751 IN FAT_VOLUME
*Volume
,
752 IN CACHE_DATA_TYPE CacheDataType
,
756 IN OUT UINT8
*Buffer
,
762 Flush all the dirty cache back, include the FAT cache and the Data cache.
764 @param Volume - FAT file system volume.
765 @param Task point to task instance.
767 @retval EFI_SUCCESS - Flush all the dirty cache back successfully
768 @return other - An error occurred when writing the data into the disk
772 FatVolumeFlushCache (
773 IN FAT_VOLUME
*Volume
,
782 Flush the data associated with an open file.
783 In this implementation, only last Mod/Access time is updated.
785 @param OFile - The open file.
787 @retval EFI_SUCCESS - The OFile is flushed successfully.
788 @return Others - An error occurred when flushing this OFile.
798 Check the references of the OFile.
799 If the OFile (that is checked) is no longer
800 referenced, then it is freed.
802 @param OFile - The OFile to be checked.
804 @retval TRUE - The OFile is not referenced and freed.
805 @retval FALSE - The OFile is kept.
815 Set the OFile and its child OFile with the error Status
817 @param OFile - The OFile whose permanent error code is to be set.
818 @param Status - Error code to be set.
829 Close the open file instance.
831 @param IFile - Open file instance.
833 @retval EFI_SUCCESS - Closed the file successfully.
843 Set error status for a specific OFile, reference checking the volume.
844 If volume is already marked as invalid, and all resources are freed
845 after reference checking, the file system protocol is uninstalled and
846 the volume structure is freed.
848 @param Volume - the Volume that is to be reference checked and unlocked.
849 @param OFile - the OFile whose permanent error code is to be set.
850 @param EfiStatus - error code to be set.
851 @param Task point to task instance.
853 @retval EFI_SUCCESS - Clean up the volume successfully.
854 @return Others - Cleaning up of the volume is failed.
859 IN FAT_VOLUME
*Volume
,
861 IN EFI_STATUS EfiStatus
,
870 Shrink the end of the open file base on the file size.
872 @param OFile - The open file.
874 @retval EFI_SUCCESS - Shrinked sucessfully.
875 @retval EFI_VOLUME_CORRUPTED - There are errors in the file's clusters.
885 Grow the end of the open file base on the NewSizeInBytes.
887 @param OFile - The open file.
888 @param NewSizeInBytes - The new size in bytes of the open file.
890 @retval EFI_SUCCESS - The file is grown sucessfully.
891 @retval EFI_UNSUPPORTED - The file size is larger than 4GB.
892 @retval EFI_VOLUME_CORRUPTED - There are errors in the files' clusters.
893 @retval EFI_VOLUME_FULL - The volume is full and can not grow the file.
899 IN UINT64 NewSizeInBytes
904 Get the size of directory of the open file.
906 @param Volume - The File System Volume.
907 @param Cluster - The Starting cluster.
909 @return The physical size of the file starting at the input cluster, if there is error in the
910 cluster chain, the return value is 0.
915 IN FAT_VOLUME
*Volume
,
921 Get the physical size of a file on the disk.
923 @param Volume - The file system volume.
924 @param RealSize - The real size of a file.
926 @return The physical size of a file on the disk.
930 FatPhysicalFileSize (
931 IN FAT_VOLUME
*Volume
,
937 Seek OFile to requested position, and calculate the number of
938 consecutive clusters from the position in the file
940 @param OFile - The open file.
941 @param Position - The file's position which will be accessed.
942 @param PosLimit - The maximum length current reading/writing may access
944 @retval EFI_SUCCESS - Set the info successfully.
945 @retval EFI_VOLUME_CORRUPTED - Cluster chain corrupt.
957 Update the free cluster info of FatInfoSector of the volume.
959 @param Volume - FAT file system volume.
964 IN FAT_VOLUME
*Volume
972 Allocates volume structure, detects FAT file system, installs protocol,
973 and initialize cache.
975 @param Handle - The handle of parent device.
976 @param DiskIo - The DiskIo of parent device.
977 @param DiskIo2 - The DiskIo2 of parent device.
978 @param BlockIo - The BlockIo of parent devicel
980 @retval EFI_SUCCESS - Allocate a new volume successfully.
981 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
982 @return Others - Allocating a new volume failed.
987 IN EFI_HANDLE Handle
,
988 IN EFI_DISK_IO_PROTOCOL
*DiskIo
,
989 IN EFI_DISK_IO2_PROTOCOL
*DiskIo2
,
990 IN EFI_BLOCK_IO_PROTOCOL
*BlockIo
995 Detects FAT file system on Disk and set relevant fields of Volume.
997 @param Volume - The volume structure.
999 @retval EFI_SUCCESS - The Fat File System is detected successfully
1000 @retval EFI_UNSUPPORTED - The volume is not FAT file system.
1001 @retval EFI_VOLUME_CORRUPTED - The volume is corrupted.
1006 IN OUT FAT_VOLUME
*Volume
1011 Called by FatDriverBindingStop(), Abandon the volume.
1013 @param Volume - The volume to be abandoned.
1015 @retval EFI_SUCCESS - Abandoned the volume successfully.
1016 @return Others - Can not uninstall the protocol interfaces.
1021 IN FAT_VOLUME
*Volume
1031 @param IFile - The instance of the open file.
1032 @param Token - A pointer to the token associated with the transaction.
1034 @return FAT_TASK * - Return the task instance.
1040 EFI_FILE_IO_TOKEN
*Token
1047 @param Task - The task to be destroyed.
1057 Wait all non-blocking requests complete.
1059 @param IFile - The instance of the open file.
1063 FatWaitNonblockingTask (
1069 Remove the subtask from subtask list.
1071 @param Subtask - The subtask to be removed.
1073 @return LIST_ENTRY * - The next node in the list.
1078 FAT_SUBTASK
*Subtask
1085 @param IFile - The instance of the open file.
1086 @param Task - The task to be executed.
1088 @retval EFI_SUCCESS - The task was executed sucessfully.
1089 @return other - An error occurred when executing the task.
1094 IN FAT_IFILE
*IFile
,
1100 Set the volume as dirty or not.
1102 @param Volume - FAT file system volume.
1103 @param IoMode - The access mode.
1104 @param DirtyValue - Set the volume as dirty or not.
1106 @retval EFI_SUCCESS - Set the new FAT entry value sucessfully.
1107 @return other - An error occurred when operation the FAT entries.
1111 FatAccessVolumeDirty (
1112 IN FAT_VOLUME
*Volume
,
1119 General disk access function.
1121 @param Volume - FAT file system volume.
1122 @param IoMode - The access mode (disk read/write or cache access).
1123 @param Offset - The starting byte offset to read from.
1124 @param BufferSize - Size of Buffer.
1125 @param Buffer - Buffer containing read data.
1126 @param Task point to task instance.
1128 @retval EFI_SUCCESS - The operation is performed successfully.
1129 @retval EFI_VOLUME_CORRUPTED - The accesss is
1130 @return Others - The status of read/write the disk
1135 IN FAT_VOLUME
*Volume
,
1138 IN UINTN BufferSize
,
1139 IN OUT VOID
*Buffer
,
1166 If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
1167 Otherwise, EFI_SUCCESS is returned.
1169 @retval EFI_SUCCESS - The volume is locked.
1170 @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.
1174 FatAcquireLockOrFail (
1180 Free directory entry.
1182 @param DirEnt - The directory entry to be freed.
1187 IN FAT_DIRENT
*DirEnt
1192 Free volume structure (including the contents of directory cache and disk cache).
1194 @param Volume - The volume structure to be freed.
1199 IN FAT_VOLUME
*Volume
1204 Translate EFI time to FAT time.
1206 @param ETime - The time of EFI_TIME.
1207 @param FTime - The time of FAT_DATE_TIME.
1211 FatEfiTimeToFatTime (
1213 OUT FAT_DATE_TIME
*FTime
1218 Translate Fat time to EFI time.
1220 @param FTime - The time of FAT_DATE_TIME.
1221 @param ETime - The time of EFI_TIME..
1225 FatFatTimeToEfiTime (
1226 IN FAT_DATE_TIME
*FTime
,
1232 Get Current FAT time.
1234 @param FatTime - Current FAT time.
1238 FatGetCurrentFatTime (
1239 OUT FAT_DATE_TIME
*FatTime
1244 Check whether a time is valid.
1246 @param Time - The time of EFI_TIME.
1248 @retval TRUE - The time is valid.
1249 @retval FALSE - The time is not valid.
1258 // UnicodeCollation.c
1261 Initialize Unicode Collation support.
1263 It tries to locate Unicode Collation 2 protocol and matches it with current
1264 platform language code. If for any reason the first attempt fails, it then tries to
1265 use Unicode Collation Protocol.
1267 @param AgentHandle The handle used to open Unicode Collation (2) protocol.
1269 @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
1270 @retval Others The Unicode Collation (2) protocol has not been located.
1274 InitializeUnicodeCollationSupport (
1275 IN EFI_HANDLE AgentHandle
1279 Convert FAT string to unicode string.
1281 @param FatSize The size of FAT string.
1282 @param Fat The FAT string.
1283 @param String The unicode string.
1296 Convert unicode string to Fat string.
1298 @param String The unicode string.
1299 @param FatSize The size of the FAT string.
1300 @param Fat The FAT string.
1302 @retval TRUE Convert successfully.
1303 @retval FALSE Convert error.
1316 @param Str The string which will be lower-cased.
1327 @param Str The string which will be upper-cased.
1336 Performs a case-insensitive comparison of two Null-terminated Unicode strings.
1338 @param Str1 A pointer to a Null-terminated Unicode string.
1339 @param Str2 A pointer to a Null-terminated Unicode string.
1341 @retval 0 S1 is equivalent to S2.
1342 @retval >0 S1 is lexically greater than S2.
1343 @retval <0 S1 is lexically less than S2.
1357 Open a file for a file name relative to an existing OFile.
1358 The IFile of the newly opened file is passed out.
1360 @param OFile - The file that serves as a starting reference point.
1361 @param NewIFile - The newly generated IFile instance.
1362 @param FileName - The file name relative to the OFile.
1363 @param OpenMode - Open mode.
1364 @param Attributes - Attributes to set if the file is created.
1367 @retval EFI_SUCCESS - Open the file successfully.
1368 @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes
1369 or the file name is not valid.
1370 @retval EFI_NOT_FOUND - Conficts between dir intention and attribute.
1371 @retval EFI_WRITE_PROTECTED - Can't open for write if the volume is read only.
1372 @retval EFI_ACCESS_DENIED - If the file's attribute is read only, and the
1373 open is for read-write fail it.
1374 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
1379 IN FAT_OFILE
*OFile
,
1380 OUT FAT_IFILE
**NewIFile
,
1381 IN CHAR16
*FileName
,
1388 Create an Open instance for the existing OFile.
1389 The IFile of the newly opened file is passed out.
1391 @param OFile - The file that serves as a starting reference point.
1392 @param PtrIFile - The newly generated IFile instance.
1394 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for the IFile
1395 @retval EFI_SUCCESS - Create the new IFile for the OFile successfully
1400 IN FAT_OFILE
*OFile
,
1401 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
1431 This function reads data from a file or writes data to a file.
1432 It uses OFile->PosRem to determine how much data can be accessed in one time.
1434 @param OFile - The open file.
1435 @param IoMode - Indicate whether the access mode is reading or writing.
1436 @param Position - The position where data will be accessed.
1437 @param DataBufferSize - Size of Buffer.
1438 @param UserBuffer - Buffer containing data.
1439 @param Task point to task instance.
1441 @retval EFI_SUCCESS - Access the data successfully.
1442 @return other - An error occurred when operating on the disk.
1447 IN FAT_OFILE
*OFile
,
1450 IN UINTN
*DataBufferSize
,
1451 IN UINT8
*UserBuffer
,
1457 Expand OFile by appending zero bytes at the end of OFile.
1459 @param OFile - The open file.
1460 @param ExpandedSize - The number of zero bytes appended at the end of the file.
1462 @retval EFI_SUCCESS - The file is expanded successfully.
1463 @return other - An error occurred when expanding file.
1468 IN FAT_OFILE
*OFile
,
1469 IN UINT64 ExpandedSize
1474 Write zero pool from the WritePos to the end of OFile.
1476 @param OFile - The open file to write zero pool.
1477 @param WritePos - The number of zero bytes written.
1479 @retval EFI_SUCCESS - Write the zero pool successfully.
1480 @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation.
1481 @return other - An error occurred when writing disk.
1486 IN FAT_OFILE
*OFile
,
1492 Truncate the OFile to smaller file size.
1494 @param OFile - The open file.
1495 @param TruncatedSize - The new file size.
1497 @retval EFI_SUCCESS - The file is truncated successfully.
1498 @return other - An error occurred when truncating file.
1503 IN FAT_OFILE
*OFile
,
1504 IN UINTN TruncatedSize
1508 // DirectoryManage.c
1512 Set the OFile's current directory cursor to the list head.
1514 @param OFile - The directory OFile whose directory cursor is reset.
1518 FatResetODirCursor (
1524 Set the directory's cursor to the next and get the next directory entry.
1526 @param OFile - The parent OFile.
1527 @param PtrDirEnt - The next directory entry.
1529 @retval EFI_SUCCESS - We get the next directory entry successfully.
1530 @return other - An error occurred when get next directory entry.
1535 IN FAT_OFILE
*OFile
,
1536 OUT FAT_DIRENT
**PtrDirEnt
1541 Remove this directory entry node from the list of directory entries and hash table.
1543 @param OFile - The parent OFile.
1544 @param DirEnt - The directory entry to be removed.
1546 @retval EFI_SUCCESS - The directory entry is successfully removed.
1547 @return other - An error occurred when removing the directory entry.
1552 IN FAT_OFILE
*OFile
,
1553 IN FAT_DIRENT
*DirEnt
1558 Save the directory entry to disk.
1560 @param OFile - The parent OFile which needs to update.
1561 @param DirEnt - The directory entry to be saved.
1563 @retval EFI_SUCCESS - Store the directory entry successfully.
1564 @return other - An error occurred when writing the directory entry.
1569 IN FAT_OFILE
*OFile
,
1570 IN FAT_DIRENT
*DirEnt
1575 Create a directory entry in the parent OFile.
1577 @param OFile - The parent OFile.
1578 @param FileName - The filename of the newly-created directory entry.
1579 @param Attributes - The attribute of the newly-created directory entry.
1580 @param PtrDirEnt - The pointer to the newly-created directory entry.
1582 @retval EFI_SUCCESS - The directory entry is successfully created.
1583 @retval EFI_OUT_OF_RESOURCES - Not enough memory to create the directory entry.
1584 @return other - An error occurred when creating the directory entry.
1589 IN FAT_OFILE
*OFile
,
1590 IN CHAR16
*FileName
,
1591 IN UINT8 Attributes
,
1592 OUT FAT_DIRENT
**PtrDirEnt
1597 Determine whether the directory entry is "." or ".." entry.
1599 @param DirEnt - The corresponding directory entry.
1601 @retval TRUE - The directory entry is "." or ".." directory entry
1602 @retval FALSE - The directory entry is not "." or ".." directory entry
1607 IN FAT_DIRENT
*DirEnt
1612 Set the OFile's cluster and size info in its directory entry.
1614 @param OFile - The corresponding OFile.
1618 FatUpdateDirEntClusterSizeInfo (
1624 Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.
1626 @param DirEnt1 - The destination directory entry.
1627 @param DirEnt2 - The source directory entry.
1632 IN FAT_DIRENT
*DirEnt1
,
1633 IN FAT_DIRENT
*DirEnt2
1638 Get the directory entry's info into Buffer.
1640 @param Volume - FAT file system volume.
1641 @param DirEnt - The corresponding directory entry.
1642 @param BufferSize - Size of Buffer.
1643 @param Buffer - Buffer containing file info.
1645 @retval EFI_SUCCESS - Get the file info successfully.
1646 @retval EFI_BUFFER_TOO_SMALL - The buffer is too small.
1651 IN FAT_VOLUME
*Volume
,
1652 IN FAT_DIRENT
*DirEnt
,
1653 IN OUT UINTN
*BufferSize
,
1659 Open the directory entry to get the OFile.
1661 @param Parent - The parent OFile.
1662 @param DirEnt - The directory entry to be opened.
1664 @retval EFI_SUCCESS - The directory entry is successfully opened.
1665 @retval EFI_OUT_OF_RESOURCES - not enough memory to allocate a new OFile.
1666 @return other - An error occurred when opening the directory entry.
1671 IN FAT_OFILE
*OFile
,
1672 IN FAT_DIRENT
*DirEnt
1677 Create "." and ".." directory entries in the newly-created parent OFile.
1679 @param OFile - The parent OFile.
1681 @retval EFI_SUCCESS - The dot directory entries are successfully created.
1682 @return other - An error occurred when creating the directory entry.
1686 FatCreateDotDirEnts (
1692 Close the directory entry and free the OFile.
1694 @param DirEnt - The directory entry to be closed.
1699 IN FAT_DIRENT
*DirEnt
1704 Traverse filename and open all OFiles that can be opened.
1705 Update filename pointer to the component that can't be opened.
1706 If more than one name component remains, returns an error;
1707 otherwise, return the remaining name component so that the caller might choose to create it.
1709 @param PtrOFile - As input, the reference OFile; as output, the located OFile.
1710 @param FileName - The file name relevant to the OFile.
1711 @param Attributes - The attribute of the destination OFile.
1712 @param NewFileName - The remaining file name.
1714 @retval EFI_NOT_FOUND - The file name can't be opened and there is more than one
1715 components within the name left (this means the name can
1716 not be created either).
1717 @retval EFI_INVALID_PARAMETER - The parameter is not valid.
1718 @retval EFI_SUCCESS - Open the file successfully.
1719 @return other - An error occured when locating the OFile.
1724 IN OUT FAT_OFILE
**PtrOFile
,
1725 IN CHAR16
*FileName
,
1726 IN UINT8 Attributes
,
1727 OUT CHAR16
*NewFileName
1732 Get the directory entry for the volume.
1734 @param Volume - FAT file system volume.
1735 @param Name - The file name of the volume.
1737 @retval EFI_SUCCESS - Update the volume with the directory entry sucessfully.
1738 @return others - An error occurred when getting volume label.
1743 IN FAT_VOLUME
*Volume
,
1749 Set the relevant directory entry into disk for the volume.
1751 @param Volume - FAT file system volume.
1752 @param Name - The new file name of the volume.
1754 @retval EFI_SUCCESS - Update the Volume sucessfully.
1755 @retval EFI_UNSUPPORTED - The input label is not a valid volume label.
1756 @return other - An error occurred when setting volume label.
1761 IN FAT_VOLUME
*Volume
,
1770 Search the long name hash table for the directory entry.
1772 @param ODir - The directory to be searched.
1773 @param LongNameString - The long name string to search.
1775 @return The previous long name hash node of the directory entry.
1779 FatLongNameHashSearch (
1781 IN CHAR16
*LongNameString
1786 Search the short name hash table for the directory entry.
1788 @param ODir - The directory to be searched.
1789 @param ShortNameString - The short name string to search.
1791 @return The previous short name hash node of the directory entry.
1795 FatShortNameHashSearch (
1797 IN CHAR8
*ShortNameString
1802 Insert directory entry to hash table.
1804 @param ODir - The parent directory.
1805 @param DirEnt - The directory entry node.
1809 FatInsertToHashTable (
1811 IN FAT_DIRENT
*DirEnt
1816 Delete directory entry from hash table.
1818 @param ODir - The parent directory.
1819 @param DirEnt - The directory entry node.
1823 FatDeleteFromHashTable (
1825 IN FAT_DIRENT
*DirEnt
1833 This function checks whether the input FileName is a valid 8.3 short name.
1834 If the input FileName is a valid 8.3, the output is the 8.3 short name;
1835 otherwise, the output is the base tag of 8.3 short name.
1837 @param FileName - The input unicode filename.
1838 @param File8Dot3Name - The output ascii 8.3 short name or base tag of 8.3 short name.
1840 @retval TRUE - The input unicode filename is a valid 8.3 short name.
1841 @retval FALSE - The input unicode filename is not a valid 8.3 short name.
1845 FatCheckIs8Dot3Name (
1846 IN CHAR16
*FileName
,
1847 OUT CHAR8
*File8Dot3Name
1852 This function generates 8Dot3 name from user specified name for a newly created file.
1854 @param Parent - The parent directory.
1855 @param DirEnt - The directory entry whose 8Dot3Name needs to be generated.
1859 FatCreate8Dot3Name (
1860 IN FAT_OFILE
*Parent
,
1861 IN FAT_DIRENT
*DirEnt
1866 Convert the ascii fat name to the unicode string and strip trailing spaces,
1867 and if necessary, convert the unicode string to lower case.
1869 @param FatName - The Char8 string needs to be converted.
1870 @param Len - The length of the fat name.
1871 @param LowerCase - Indicate whether to convert the string to lower case.
1872 @param Str - The result of the convertion.
1885 Set the caseflag value for the directory entry.
1887 @param DirEnt - The logical directory entry whose caseflag value is to be set.
1892 IN FAT_DIRENT
*DirEnt
1897 Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.
1899 @param DirEnt - The corresponding directory entry.
1900 @param FileString - The output Unicode file name.
1901 @param FileStringMax The max length of FileString.
1905 FatGetFileNameViaCaseFlag (
1906 IN FAT_DIRENT
*DirEnt
,
1907 IN OUT CHAR16
*FileString
,
1908 IN UINTN FileStringMax
1913 Get the Check sum for a short name.
1915 @param ShortNameString - The short name for a file.
1917 @retval Sum - UINT8 checksum.
1922 IN CHAR8
*ShortNameString
1927 Takes Path as input, returns the next name component
1928 in Name, and returns the position after Name (e.g., the
1929 start of the next name component)
1931 @param Path - The path of one file.
1932 @param Name - The next name component in Path.
1934 The position after Name in the Path
1938 FatGetNextNameComponent (
1945 Check whether the IFileName is valid long file name. If the IFileName is a valid
1946 long file name, then we trim the possible leading blanks and leading/trailing dots.
1947 the trimmed filename is stored in OutputFileName
1949 @param InputFileName - The input file name.
1950 @param OutputFileName - The output file name.
1952 @retval TRUE - The InputFileName is a valid long file name.
1953 @retval FALSE - The InputFileName is not a valid long file name.
1957 FatFileNameIsValid (
1958 IN CHAR16
*InputFileName
,
1959 OUT CHAR16
*OutputFileName
1967 Discard the directory structure when an OFile will be freed.
1968 Volume will cache this directory if the OFile does not represent a deleted file.
1970 @param OFile - The OFile whose directory structure is to be discarded.
1980 Request the directory structure when an OFile is newly generated.
1981 If the directory structure is cached by volume, then just return this directory;
1982 Otherwise, allocate a new one for OFile.
1984 @param OFile - The OFile which requests directory structure.
1994 Clean up all the cached directory structures when the volume is going to be abandoned.
1996 @param Volume - FAT file system volume.
2000 FatCleanupODirCache (
2001 IN FAT_VOLUME
*Volume
2007 extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding
;
2008 extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName
;
2009 extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2
;
2010 extern EFI_LOCK FatFsLock
;
2011 extern EFI_LOCK FatTaskLock
;
2012 extern EFI_FILE_PROTOCOL FatFileInterface
;