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)
66#define MAX_BLOCK_ALIGNMENT 12
67#define MIN_BLOCK_ALIGNMENT 9
68#define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
73#define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
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
88typedef UINT64 DIRTY_BLOCKS;
89#define BITS_PER_BYTE 8
90#define DIRTY_BITS_PER_BLOCK ((sizeof (DIRTY_BLOCKS) * BITS_PER_BYTE))
93#define DIRTY_BITS ((1 << FAT_DATACACHE_PAGE_MAX_ALIGNMENT) / (1 << MIN_BLOCK_ALIGNMENT))
96#define DIRTY_BLOCKS_SIZE (DIRTY_BITS / sizeof (DIRTY_BLOCKS))
98STATIC_ASSERT ((((1 << FAT_DATACACHE_PAGE_MAX_ALIGNMENT) / (1 << MIN_BLOCK_ALIGNMENT)) %
sizeof (DIRTY_BLOCKS)) == 0,
"DIRTY_BLOCKS not a proper size");
103#define MAX_SPEC_RETRY 4
104#define SPEC_BASE_TAG_LEN 6
105#define HASH_BASE_TAG_LEN 2
106#define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
111#define PATH_NAME_SEPARATOR L'\\'
113#define EFI_PATH_STRING_LENGTH 260
114#define EFI_FILE_STRING_LENGTH 255
115#define FAT_MAX_ALLOCATE_SIZE 0xA00000
116#define LC_ISO_639_2_ENTRY_SIZE 3
117#define MAX_LANG_CODE_SIZE 100
119#define FAT_MAX_DIR_CACHE_COUNT 8
120#define FAT_MAX_DIRENTRY_COUNT 0xFFFF
121typedef CHAR8 LC_ISO_639_2;
151#define CACHE_ENABLED(a) ((a) >= 2)
152#define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
153#define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
162 DIRTY_BLOCKS DirtyBlocks[DIRTY_BLOCKS_SIZE];
173 CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
179#define HASH_TABLE_SIZE 0x400
180#define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
206 UINT32 CurrentEndPos;
213 FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
214 FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
267 UINTN FileCurrentCluster;
268 UINTN FileLastCluster;
279 BOOLEAN IsFixedRootDir;
280 BOOLEAN PreserveLastModification;
336 UINT64 FirstClusterPos;
340 UINT8 ClusterAlignment;
341 FAT_VOLUME_TYPE FatType;
348 UINT32 FatEntryBuffer;
351 BOOLEAN FreeInfoValid;
363 UINT32 NotDirtyValue;
372 CHAR16 RootFileString[1];
454 IN UINT64 Attributes,
761 IN CACHE_DATA_TYPE CacheDataType,
765 IN OUT UINT8 *Buffer,
910 IN UINT64 NewSizeInBytes
1152 IN OUT VOID *Buffer,
1395 IN CHAR16 *FileName,
1467 IN UINT8 *UserBuffer,
1485 IN UINT64 ExpandedSize
1607 IN CHAR16 *FileName,
1608 IN UINT8 Attributes,
1742 IN CHAR16 *FileName,
1743 IN UINT8 Attributes,
1744 OUT CHAR16 *NewFileName
1799 IN CHAR16 *LongNameString
1815 IN CHAR8 *ShortNameString
1865 IN CHAR16 *FileName,
1866 OUT CHAR8 *File8Dot3Name
1926 IN OUT CHAR16 *FileString,
1941 IN CHAR8 *ShortNameString
1977 IN CHAR16 *InputFileName,
1978 OUT CHAR16 *OutputFileName
EFI_STATUS EFIAPI FatReadEx(IN EFI_FILE_PROTOCOL *FHand, IN OUT EFI_FILE_IO_TOKEN *Token)
FAT_DIRENT ** FatShortNameHashSearch(IN FAT_ODIR *ODir, IN CHAR8 *ShortNameString)
BOOLEAN FatFileNameIsValid(IN CHAR16 *InputFileName, OUT CHAR16 *OutputFileName)
VOID FatFreeVolume(IN FAT_VOLUME *Volume)
EFI_STATUS FatInitializeDiskCache(IN FAT_VOLUME *Volume)
EFI_STATUS FatRemoveDirEnt(IN FAT_OFILE *OFile, IN FAT_DIRENT *DirEnt)
VOID FatDestroyTask(FAT_TASK *Task)
VOID FatFatTimeToEfiTime(IN FAT_DATE_TIME *FTime, OUT EFI_TIME *ETime)
EFI_STATUS EFIAPI FatRead(IN EFI_FILE_PROTOCOL *FHand, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
FAT_TASK * FatCreateTask(FAT_IFILE *IFile, EFI_FILE_IO_TOKEN *Token)
EFI_STATUS EFIAPI FatGetInfo(IN EFI_FILE_PROTOCOL *FHand, IN EFI_GUID *Type, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
EFI_STATUS FatStoreDirEnt(IN FAT_OFILE *OFile, IN FAT_DIRENT *DirEnt)
BOOLEAN FatStrToFat(IN CHAR16 *String, IN UINTN FatSize, OUT CHAR8 *Fat)
VOID FatEfiTimeToFatTime(IN EFI_TIME *ETime, OUT FAT_DATE_TIME *FTime)
VOID FatFatToStr(IN UINTN FatSize, IN CHAR8 *Fat, OUT CHAR16 *String)
EFI_STATUS FatVolumeFlushCache(IN FAT_VOLUME *Volume, IN FAT_TASK *Task)
UINTN FatPhysicalDirSize(IN FAT_VOLUME *Volume, IN UINTN Cluster)
EFI_STATUS FatWriteZeroPool(IN FAT_OFILE *OFile, IN UINTN WritePos)
EFI_STATUS FatGetDirEntInfo(IN FAT_VOLUME *Volume, IN FAT_DIRENT *DirEnt, IN OUT UINTN *BufferSize, OUT VOID *Buffer)
EFI_STATUS FatCreateDirEnt(IN FAT_OFILE *OFile, IN CHAR16 *FileName, IN UINT8 Attributes, OUT FAT_DIRENT **PtrDirEnt)
VOID FatInsertToHashTable(IN FAT_ODIR *ODir, IN FAT_DIRENT *DirEnt)
EFI_STATUS FatQueueTask(IN FAT_IFILE *IFile, IN FAT_TASK *Task)
BOOLEAN FatIsDotDirEnt(IN FAT_DIRENT *DirEnt)
VOID FatNameToStr(IN CHAR8 *FatName, IN UINTN Len, IN UINTN LowerCase, IN CHAR16 *Str)
EFI_STATUS FatOFileFlush(IN FAT_OFILE *OFile)
EFI_STATUS EFIAPI FatWrite(IN EFI_FILE_PROTOCOL *FHand, IN OUT UINTN *BufferSize, IN VOID *Buffer)
VOID FatRequestODir(IN FAT_OFILE *OFile)
EFI_STATUS FatExpandOFile(IN FAT_OFILE *OFile, IN UINT64 ExpandedSize)
EFI_STATUS FatOpenDevice(IN OUT FAT_VOLUME *Volume)
EFI_STATUS FatAcquireLockOrFail(VOID)
EFI_STATUS FatLocateOFile(IN OUT FAT_OFILE **PtrOFile, IN CHAR16 *FileName, IN UINT8 Attributes, OUT CHAR16 *NewFileName)
VOID FatGetFileNameViaCaseFlag(IN FAT_DIRENT *DirEnt, IN OUT CHAR16 *FileString, IN UINTN FileStringMax)
EFI_STATUS FatGrowEof(IN FAT_OFILE *OFile, IN UINT64 NewSizeInBytes)
EFI_STATUS FatOFilePosition(IN FAT_OFILE *OFile, IN UINTN Position, IN UINTN PosLimit)
VOID FatDiscardODir(IN FAT_OFILE *OFile)
LIST_ENTRY * FatDestroySubtask(FAT_SUBTASK *Subtask)
EFI_STATUS EFIAPI FatGetPosition(IN EFI_FILE_PROTOCOL *FHand, OUT UINT64 *Position)
EFI_STATUS FatSetVolumeEntry(IN FAT_VOLUME *Volume, IN CHAR16 *Name)
VOID FatSetCaseFlag(IN FAT_DIRENT *DirEnt)
INTN FatStriCmp(IN CHAR16 *Str1, IN CHAR16 *Str2)
VOID FatWaitNonblockingTask(FAT_IFILE *IFile)
BOOLEAN FatIsValidTime(IN EFI_TIME *Time)
EFI_STATUS FatCreateDotDirEnts(IN FAT_OFILE *OFile)
EFI_STATUS FatGetNextDirEnt(IN FAT_OFILE *OFile, OUT FAT_DIRENT **PtrDirEnt)
EFI_STATUS EFIAPI FatFlushEx(IN EFI_FILE_PROTOCOL *FHand, IN EFI_FILE_IO_TOKEN *Token)
VOID FatComputeFreeInfo(IN FAT_VOLUME *Volume)
EFI_STATUS FatGetVolumeEntry(IN FAT_VOLUME *Volume, IN CHAR16 *Name)
UINT64 FatPhysicalFileSize(IN FAT_VOLUME *Volume, IN UINTN RealSize)
EFI_STATUS FatIFileClose(FAT_IFILE *IFile)
EFI_STATUS FatAllocateIFile(IN FAT_OFILE *OFile, OUT FAT_IFILE **PtrIFile)
BOOLEAN FatCheckOFileRef(IN FAT_OFILE *OFile)
VOID FatCleanupODirCache(IN FAT_VOLUME *Volume)
VOID FatStrLwr(IN CHAR16 *Str)
EFI_STATUS EFIAPI FatFlush(IN EFI_FILE_PROTOCOL *FHand)
EFI_STATUS EFIAPI FatOpenVolume(IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This, OUT EFI_FILE_PROTOCOL **File)
VOID FatCreate8Dot3Name(IN FAT_OFILE *Parent, IN FAT_DIRENT *DirEnt)
EFI_STATUS FatShrinkEof(IN FAT_OFILE *OFile)
EFI_STATUS EFIAPI FatDelete(IN EFI_FILE_PROTOCOL *FHand)
EFI_STATUS FatDiskIo(IN FAT_VOLUME *Volume, IN IO_MODE IoMode, IN UINT64 Offset, IN UINTN BufferSize, IN OUT VOID *Buffer, IN FAT_TASK *Task)
EFI_STATUS EFIAPI FatOpenEx(IN EFI_FILE_PROTOCOL *FHand, OUT EFI_FILE_PROTOCOL **NewHandle, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes, IN OUT EFI_FILE_IO_TOKEN *Token)
VOID FatSetVolumeError(IN FAT_OFILE *OFile, IN EFI_STATUS Status)
EFI_STATUS FatAllocateVolume(IN EFI_HANDLE Handle, IN EFI_DISK_IO_PROTOCOL *DiskIo, IN EFI_DISK_IO2_PROTOCOL *DiskIo2, IN EFI_BLOCK_IO_PROTOCOL *BlockIo)
EFI_STATUS FatAccessOFile(IN FAT_OFILE *OFile, IN IO_MODE IoMode, IN UINTN Position, IN UINTN *DataBufferSize, IN UINT8 *UserBuffer, IN FAT_TASK *Task)
UINT8 FatCheckSum(IN CHAR8 *ShortNameString)
VOID FatCloneDirEnt(IN FAT_DIRENT *DirEnt1, IN FAT_DIRENT *DirEnt2)
EFI_STATUS FatAccessVolumeDirty(IN FAT_VOLUME *Volume, IN IO_MODE IoMode, IN VOID *DirtyValue)
VOID FatFreeDirEnt(IN FAT_DIRENT *DirEnt)
VOID FatAcquireLock(VOID)
EFI_STATUS EFIAPI FatClose(IN EFI_FILE_PROTOCOL *FHand)
EFI_STATUS FatAbandonVolume(IN FAT_VOLUME *Volume)
EFI_STATUS EFIAPI FatSetInfo(IN EFI_FILE_PROTOCOL *FHand, IN EFI_GUID *Type, IN UINTN BufferSize, IN VOID *Buffer)
EFI_STATUS FatOpenDirEnt(IN FAT_OFILE *OFile, IN FAT_DIRENT *DirEnt)
VOID FatUpdateDirEntClusterSizeInfo(IN FAT_OFILE *OFile)
VOID FatReleaseLock(VOID)
VOID FatDeleteFromHashTable(IN FAT_ODIR *ODir, IN FAT_DIRENT *DirEnt)
EFI_STATUS EFIAPI FatSetPosition(IN EFI_FILE_PROTOCOL *FHand, IN UINT64 Position)
EFI_STATUS EFIAPI FatOpen(IN EFI_FILE_PROTOCOL *FHand, OUT EFI_FILE_PROTOCOL **NewHandle, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT64 Attributes)
VOID FatGetCurrentFatTime(OUT FAT_DATE_TIME *FatTime)
EFI_STATUS FatTruncateOFile(IN FAT_OFILE *OFile, IN UINTN TruncatedSize)
CHAR16 * FatGetNextNameComponent(IN CHAR16 *Path, OUT CHAR16 *Name)
EFI_STATUS FatOFileOpen(IN FAT_OFILE *OFile, OUT FAT_IFILE **NewIFile, IN CHAR16 *FileName, IN UINT64 OpenMode, IN UINT8 Attributes)
VOID FatResetODirCursor(IN FAT_OFILE *OFile)
VOID FatStrUpr(IN CHAR16 *Str)
BOOLEAN FatCheckIs8Dot3Name(IN CHAR16 *FileName, OUT CHAR8 *File8Dot3Name)
EFI_STATUS EFIAPI FatWriteEx(IN EFI_FILE_PROTOCOL *FHand, IN OUT EFI_FILE_IO_TOKEN *Token)
VOID FatCloseDirEnt(IN FAT_DIRENT *DirEnt)
EFI_STATUS FatCleanupVolume(IN FAT_VOLUME *Volume, IN FAT_OFILE *OFile, IN EFI_STATUS EfiStatus, IN FAT_TASK *Task)
EFI_STATUS FatAccessCache(IN FAT_VOLUME *Volume, IN CACHE_DATA_TYPE CacheDataType, IN IO_MODE IoMode, IN UINT64 Offset, IN UINTN BufferSize, IN OUT UINT8 *Buffer, IN FAT_TASK *Task)
EFI_STATUS InitializeUnicodeCollationSupport(IN EFI_HANDLE AgentHandle)
FAT_DIRENT ** FatLongNameHashSearch(IN FAT_ODIR *ODir, IN CHAR16 *LongNameString)