]> git.proxmox.com Git - mirror_edk2.git/blame - FatPkg/EnhancedFatDxe/Fat.h
FatPkg/EnhancedFatDxe: Make the comments align with EDKIIcoding style
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Fat.h
CommitLineData
cae7420b
DB
1/** @file\r
2 Main header file for EFI FAT file system driver.\r
b9ec9330 3\r
149d6335 4Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>\r
6163cc98 5This program and the accompanying materials are licensed and made available\r
b9ec9330
QH
6under the terms and conditions of the BSD License which accompanies this\r
7distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
cae7420b 13**/\r
b9ec9330
QH
14\r
15#ifndef _FAT_H_\r
16#define _FAT_H_\r
17\r
18#include <Uefi.h>\r
19\r
20#include <Guid/FileInfo.h>\r
21#include <Guid/FileSystemInfo.h>\r
22#include <Guid/FileSystemVolumeLabelInfo.h>\r
b9ec9330
QH
23#include <Protocol/BlockIo.h>\r
24#include <Protocol/DiskIo.h>\r
149d6335 25#include <Protocol/DiskIo2.h>\r
b9ec9330
QH
26#include <Protocol/SimpleFileSystem.h>\r
27#include <Protocol/UnicodeCollation.h>\r
28\r
29#include <Library/PcdLib.h>\r
30#include <Library/DebugLib.h>\r
31#include <Library/UefiLib.h>\r
32#include <Library/BaseLib.h>\r
33#include <Library/BaseMemoryLib.h>\r
34#include <Library/MemoryAllocationLib.h>\r
35#include <Library/UefiDriverEntryPoint.h>\r
36#include <Library/UefiBootServicesTableLib.h>\r
37#include <Library/UefiRuntimeServicesTableLib.h>\r
38\r
39#include "FatFileSystem.h"\r
40\r
41//\r
42// The FAT signature\r
43//\r
bcc9adde
QH
44#define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')\r
45#define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')\r
46#define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')\r
47#define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')\r
48#define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')\r
149d6335
RN
49#define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')\r
50#define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')\r
b9ec9330
QH
51\r
52#define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)\r
53\r
54#define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)\r
55\r
56#define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)\r
57\r
58#define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)\r
59\r
60#define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);\r
61\r
62#define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)\r
63\r
64#define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)\r
65\r
66#define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)\r
67\r
68//\r
69// Minimum sector size is 512B, Maximum sector size is 4096B\r
70// Max sectors per cluster is 128\r
71//\r
72#define MAX_BLOCK_ALIGNMENT 12\r
73#define MIN_BLOCK_ALIGNMENT 9\r
74#define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7\r
75\r
76//\r
77// Efi Time Definition\r
78//\r
79#define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))\r
80\r
81//\r
82// Minimum fat page size is 8K, maximum fat page alignment is 32K\r
83// Minimum data page size is 8K, maximum fat page alignment is 64K\r
84//\r
85#define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13\r
86#define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15\r
87#define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13\r
88#define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16\r
89#define FAT_DATACACHE_GROUP_COUNT 64\r
90#define FAT_FATCACHE_GROUP_MIN_COUNT 1\r
91#define FAT_FATCACHE_GROUP_MAX_COUNT 16\r
92\r
93//\r
94// Used in 8.3 generation algorithm\r
95//\r
96#define MAX_SPEC_RETRY 4\r
97#define SPEC_BASE_TAG_LEN 6\r
98#define HASH_BASE_TAG_LEN 2\r
99#define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)\r
100\r
101//\r
102// Path name separator is back slash\r
103//\r
104#define PATH_NAME_SEPARATOR L'\\'\r
105\r
106\r
107#define EFI_PATH_STRING_LENGTH 260\r
108#define EFI_FILE_STRING_LENGTH 255\r
109#define FAT_MAX_ALLOCATE_SIZE 0xA00000\r
110#define LC_ISO_639_2_ENTRY_SIZE 3\r
111#define MAX_LANG_CODE_SIZE 100\r
112\r
113#define FAT_MAX_DIR_CACHE_COUNT 8\r
114#define FAT_MAX_DIRENTRY_COUNT 0xFFFF\r
115typedef CHAR8 LC_ISO_639_2;\r
116\r
117//\r
118// The fat types we support\r
119//\r
120typedef enum {\r
c1680e88
DB
121 Fat12,\r
122 Fat16,\r
123 Fat32,\r
b9ec9330
QH
124 FatUndefined\r
125} FAT_VOLUME_TYPE;\r
126\r
127typedef enum {\r
c1680e88
DB
128 CacheFat,\r
129 CacheData,\r
130 CacheMaxType\r
b9ec9330
QH
131} CACHE_DATA_TYPE;\r
132\r
133//\r
134// Used in FatDiskIo\r
135//\r
136typedef enum {\r
c1680e88
DB
137 ReadDisk = 0, // raw disk read\r
138 WriteDisk = 1, // raw disk write\r
139 ReadFat = 2, // read fat cache\r
140 WriteFat = 3, // write fat cache\r
141 ReadData = 6, // read data cache\r
142 WriteData = 7 // write data cache\r
b9ec9330
QH
143} IO_MODE;\r
144\r
145#define CACHE_ENABLED(a) ((a) >= 2)\r
146#define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))\r
147#define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))\r
148\r
149//\r
150// Disk cache tag\r
151//\r
152typedef struct {\r
153 UINTN PageNo;\r
154 UINTN RealSize;\r
155 BOOLEAN Dirty;\r
156} CACHE_TAG;\r
157\r
158typedef struct {\r
159 UINT64 BaseAddress;\r
160 UINT64 LimitAddress;\r
161 UINT8 *CacheBase;\r
162 BOOLEAN Dirty;\r
163 UINT8 PageAlignment;\r
164 UINTN GroupMask;\r
165 CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];\r
166} DISK_CACHE;\r
167\r
168//\r
169// Hash table size\r
170//\r
171#define HASH_TABLE_SIZE 0x400\r
172#define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)\r
173\r
174//\r
175// The directory entry for opened directory\r
176//\r
6b7e4498
DB
177\r
178typedef struct _FAT_DIRENT FAT_DIRENT;\r
179typedef struct _FAT_ODIR FAT_ODIR;\r
180typedef struct _FAT_OFILE FAT_OFILE;\r
181typedef struct _FAT_VOLUME FAT_VOLUME;\r
182\r
183struct _FAT_DIRENT {\r
b9ec9330
QH
184 UINTN Signature;\r
185 UINT16 EntryPos; // The position of this directory entry in the parent directory file\r
186 UINT8 EntryCount; // The count of the directory entry in the parent directory file\r
187 BOOLEAN Invalid; // Indicate whether this directory entry is valid\r
188 CHAR16 *FileString; // The unicode long file name for this directory entry\r
6b7e4498
DB
189 FAT_OFILE *OFile; // The OFile of the corresponding directory entry\r
190 FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename\r
191 FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename\r
b9ec9330
QH
192 LIST_ENTRY Link; // Connection of every directory entry\r
193 FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk\r
6b7e4498 194};\r
b9ec9330 195\r
6b7e4498 196struct _FAT_ODIR {\r
b9ec9330
QH
197 UINTN Signature;\r
198 UINT32 CurrentEndPos; // Current end position of the directory\r
199 UINT32 CurrentPos; // Current position of the directory\r
200 LIST_ENTRY *CurrentCursor; // Current directory entry pointer\r
201 LIST_ENTRY ChildList; // List of all directory entries\r
202 BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory\r
203 LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded\r
204 UINTN DirCacheTag; // The identification of the directory when in directory cache\r
205 FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];\r
206 FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];\r
6b7e4498 207};\r
b9ec9330
QH
208\r
209typedef struct {\r
210 UINTN Signature;\r
dba03ba1 211 EFI_FILE_PROTOCOL Handle;\r
b9ec9330
QH
212 UINT64 Position;\r
213 BOOLEAN ReadOnly;\r
6b7e4498 214 FAT_OFILE *OFile;\r
149d6335
RN
215 LIST_ENTRY Tasks; // List of all FAT_TASKs\r
216 LIST_ENTRY Link; // Link to other IFiles\r
b9ec9330
QH
217} FAT_IFILE;\r
218\r
149d6335
RN
219typedef struct {\r
220 UINTN Signature;\r
221 EFI_FILE_IO_TOKEN *FileIoToken;\r
222 FAT_IFILE *IFile;\r
223 LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs\r
224 LIST_ENTRY Link; // Link to other FAT_TASKs\r
225} FAT_TASK;\r
226\r
227typedef struct {\r
228 UINTN Signature;\r
229 EFI_DISK_IO2_TOKEN DiskIo2Token;\r
230 FAT_TASK *Task;\r
231 BOOLEAN Write;\r
232 UINT64 Offset;\r
233 VOID *Buffer;\r
234 UINTN BufferSize;\r
235 LIST_ENTRY Link;\r
236} FAT_SUBTASK;\r
237\r
b9ec9330
QH
238//\r
239// FAT_OFILE - Each opened file\r
240//\r
6b7e4498 241struct _FAT_OFILE {\r
b9ec9330 242 UINTN Signature;\r
6b7e4498 243 FAT_VOLUME *Volume;\r
b9ec9330
QH
244 //\r
245 // A permanant error code to return to all accesses to\r
246 // this opened file\r
247 //\r
248 EFI_STATUS Error;\r
249 //\r
250 // A list of the IFILE instances for this OFile\r
251 //\r
252 LIST_ENTRY Opens;\r
253\r
254 //\r
255 // The dynamic infomation\r
256 //\r
257 UINTN FileSize;\r
258 UINTN FileCluster;\r
259 UINTN FileCurrentCluster;\r
260 UINTN FileLastCluster;\r
261\r
262 //\r
263 // Dirty is set if there have been any updates to the\r
264 // file\r
c3b8ec43 265 // Archive is set if the archive attribute in the file's\r
b9ec9330
QH
266 // directory entry needs to be set when performing flush\r
267 // PreserveLastMod is set if the last modification of the\r
268 // file is specified by SetInfo API\r
269 //\r
270 BOOLEAN Dirty;\r
271 BOOLEAN IsFixedRootDir;\r
272 BOOLEAN PreserveLastModification;\r
273 BOOLEAN Archive;\r
274 //\r
275 // Set by an OFile SetPosition\r
276 //\r
277 UINTN Position; // within file\r
278 UINT64 PosDisk; // on the disk\r
279 UINTN PosRem; // remaining in this disk run\r
280 //\r
281 // The opened parent, full path length and currently opened child files\r
282 //\r
6b7e4498 283 FAT_OFILE *Parent;\r
b9ec9330
QH
284 UINTN FullPathLen;\r
285 LIST_ENTRY ChildHead;\r
286 LIST_ENTRY ChildLink;\r
287\r
288 //\r
289 // The opened directory structure for a directory; if this\r
290 // OFile represents a file, then ODir = NULL\r
291 //\r
292 FAT_ODIR *ODir;\r
293 //\r
294 // The directory entry for the Ofile\r
295 //\r
296 FAT_DIRENT *DirEnt;\r
297\r
298 //\r
299 // Link in Volume's reference list\r
300 //\r
301 LIST_ENTRY CheckLink;\r
6b7e4498 302};\r
b9ec9330 303\r
6b7e4498 304struct _FAT_VOLUME {\r
b9ec9330
QH
305 UINTN Signature;\r
306\r
307 EFI_HANDLE Handle;\r
308 BOOLEAN Valid;\r
309 BOOLEAN DiskError;\r
310\r
311 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;\r
312\r
313 //\r
314 // If opened, the parent handle and BlockIo interface\r
315 //\r
316 EFI_BLOCK_IO_PROTOCOL *BlockIo;\r
317 EFI_DISK_IO_PROTOCOL *DiskIo;\r
149d6335 318 EFI_DISK_IO2_PROTOCOL *DiskIo2;\r
b9ec9330
QH
319 UINT32 MediaId;\r
320 BOOLEAN ReadOnly;\r
321\r
322 //\r
323 // Computed values from fat bpb info\r
324 //\r
325 UINT64 VolumeSize;\r
326 UINT64 FatPos; // Disk pos of fat tables\r
327 UINT64 RootPos; // Disk pos of root directory\r
328 UINT64 FirstClusterPos; // Disk pos of first cluster\r
329 UINTN FatSize; // Number of bytes in each fat\r
330 UINTN MaxCluster; // Max cluster number\r
331 UINTN ClusterSize; // Cluster size of fat partition\r
332 UINT8 ClusterAlignment; // Equal to log_2 (clustersize);\r
333 FAT_VOLUME_TYPE FatType;\r
334\r
335 //\r
336 // Current part of fat table that's present\r
337 //\r
338 UINT64 FatEntryPos; // Location of buffer\r
339 UINTN FatEntrySize; // Size of buffer\r
340 UINT32 FatEntryBuffer; // The buffer\r
341 FAT_INFO_SECTOR FatInfoSector; // Free cluster info\r
342 UINTN FreeInfoPos; // Pos with the free cluster info\r
343 BOOLEAN FreeInfoValid; // If free cluster info is valid\r
344 //\r
345 // Unpacked Fat BPB info\r
346 //\r
347 UINTN NumFats;\r
348 UINTN RootEntries; // < FAT32, root dir is fixed size\r
349 UINTN RootCluster; // >= FAT32, root cluster chain head\r
350 //\r
351 // info for marking the volume dirty or not\r
352 //\r
353 BOOLEAN FatDirty; // If fat-entries have been updated\r
354 UINT32 DirtyValue;\r
355 UINT32 NotDirtyValue;\r
356\r
357 //\r
358 // The root directory entry and opened root file\r
359 //\r
360 FAT_DIRENT RootDirEnt;\r
361 //\r
362 // File Name of root OFile, it is empty string\r
363 //\r
364 CHAR16 RootFileString[1];\r
6b7e4498 365 FAT_OFILE *Root;\r
b9ec9330
QH
366\r
367 //\r
368 // New OFiles are added to this list so they\r
369 // can be cleaned up if they aren't referenced.\r
370 //\r
371 LIST_ENTRY CheckRef;\r
372\r
373 //\r
374 // Directory cache List\r
375 //\r
376 LIST_ENTRY DirCacheList;\r
377 UINTN DirCacheCount;\r
378\r
379 //\r
380 // Disk Cache for this volume\r
381 //\r
382 VOID *CacheBuffer;\r
c1680e88 383 DISK_CACHE DiskCache[CacheMaxType];\r
6b7e4498 384};\r
b9ec9330
QH
385\r
386//\r
387// Function Prototypes\r
388//\r
cae7420b
DB
389\r
390/**\r
391\r
392 Implements Open() of Simple File System Protocol.\r
393\r
394 @param FHand - File handle of the file serves as a starting reference point.\r
395 @param NewHandle - Handle of the file that is newly opened.\r
396 @param FileName - File name relative to FHand.\r
397 @param OpenMode - Open mode.\r
398 @param Attributes - Attributes to set if the file is created.\r
399\r
400\r
401 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r
402 The OpenMode is not supported.\r
403 The Attributes is not the valid attributes.\r
404 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.\r
405 @retval EFI_SUCCESS - Open the file successfully.\r
406 @return Others - The status of open file.\r
407\r
408**/\r
b9ec9330
QH
409EFI_STATUS\r
410EFIAPI\r
411FatOpen (\r
dba03ba1
QH
412 IN EFI_FILE_PROTOCOL *FHand,\r
413 OUT EFI_FILE_PROTOCOL **NewHandle,\r
b9ec9330
QH
414 IN CHAR16 *FileName,\r
415 IN UINT64 OpenMode,\r
416 IN UINT64 Attributes\r
417 )\r
cae7420b 418;\r
b9ec9330 419\r
cae7420b 420/**\r
b9ec9330 421\r
cae7420b 422 Implements OpenEx() of Simple File System Protocol.\r
b9ec9330 423\r
cae7420b
DB
424 @param FHand - File handle of the file serves as a starting reference point.\r
425 @param NewHandle - Handle of the file that is newly opened.\r
426 @param FileName - File name relative to FHand.\r
427 @param OpenMode - Open mode.\r
428 @param Attributes - Attributes to set if the file is created.\r
429 @param Token - A pointer to the token associated with the transaction.\r
b9ec9330 430\r
cae7420b 431 @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.\r
b9ec9330
QH
432 The OpenMode is not supported.\r
433 The Attributes is not the valid attributes.\r
cae7420b
DB
434 @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.\r
435 @retval EFI_SUCCESS - Open the file successfully.\r
436 @return Others - The status of open file.\r
b9ec9330 437\r
cae7420b 438**/\r
149d6335 439EFI_STATUS\r
833b5a77 440EFIAPI\r
149d6335
RN
441FatOpenEx (\r
442 IN EFI_FILE_PROTOCOL *FHand,\r
443 OUT EFI_FILE_PROTOCOL **NewHandle,\r
444 IN CHAR16 *FileName,\r
445 IN UINT64 OpenMode,\r
446 IN UINT64 Attributes,\r
447 IN OUT EFI_FILE_IO_TOKEN *Token\r
448 )\r
cae7420b 449;\r
149d6335 450\r
cae7420b 451/**\r
149d6335 452\r
cae7420b 453 Get the file's position of the file\r
149d6335 454\r
cae7420b
DB
455 @param FHand - The handle of file.\r
456 @param Position - The file's position of the file.\r
149d6335 457\r
cae7420b
DB
458 @retval EFI_SUCCESS - Get the info successfully.\r
459 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r
460 @retval EFI_UNSUPPORTED - The open file is not a file.\r
149d6335 461\r
cae7420b 462**/\r
b9ec9330
QH
463EFI_STATUS\r
464EFIAPI\r
465FatGetPosition (\r
dba03ba1 466 IN EFI_FILE_PROTOCOL *FHand,\r
b9ec9330
QH
467 OUT UINT64 *Position\r
468 )\r
cae7420b 469;\r
b9ec9330 470\r
cae7420b 471/**\r
b9ec9330 472\r
cae7420b 473 Get the some types info of the file into Buffer\r
b9ec9330 474\r
cae7420b
DB
475 @param FHand - The handle of file.\r
476 @param Type - The type of the info.\r
477 @param BufferSize - Size of Buffer.\r
478 @param Buffer - Buffer containing volume info.\r
b9ec9330 479\r
cae7420b
DB
480 @retval EFI_SUCCESS - Get the info successfully.\r
481 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r
b9ec9330 482\r
cae7420b 483**/\r
b9ec9330
QH
484EFI_STATUS\r
485EFIAPI\r
486FatGetInfo (\r
dba03ba1
QH
487 IN EFI_FILE_PROTOCOL *FHand,\r
488 IN EFI_GUID *Type,\r
489 IN OUT UINTN *BufferSize,\r
490 OUT VOID *Buffer\r
b9ec9330 491 )\r
cae7420b 492;\r
b9ec9330 493\r
cae7420b 494/**\r
b9ec9330 495\r
cae7420b 496 Set the some types info of the file into Buffer.\r
b9ec9330 497\r
cae7420b
DB
498 @param FHand - The handle of file.\r
499 @param Type - The type of the info.\r
500 @param BufferSize - Size of Buffer.\r
501 @param Buffer - Buffer containing volume info.\r
b9ec9330 502\r
cae7420b
DB
503 @retval EFI_SUCCESS - Set the info successfully.\r
504 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r
b9ec9330 505\r
cae7420b 506**/\r
b9ec9330
QH
507EFI_STATUS\r
508EFIAPI\r
509FatSetInfo (\r
dba03ba1 510 IN EFI_FILE_PROTOCOL *FHand,\r
b9ec9330
QH
511 IN EFI_GUID *Type,\r
512 IN UINTN BufferSize,\r
513 IN VOID *Buffer\r
514 )\r
cae7420b 515;\r
b9ec9330 516\r
cae7420b 517/**\r
b9ec9330 518\r
cae7420b 519 Flushes all data associated with the file handle.\r
b9ec9330 520\r
cae7420b 521 @param FHand - Handle to file to flush\r
b9ec9330 522\r
cae7420b
DB
523 @retval EFI_SUCCESS - Flushed the file successfully\r
524 @retval EFI_WRITE_PROTECTED - The volume is read only\r
525 @retval EFI_ACCESS_DENIED - The volume is not read only\r
526 but the file is read only\r
527 @return Others - Flushing of the file is failed\r
b9ec9330 528\r
cae7420b 529**/\r
b9ec9330
QH
530EFI_STATUS\r
531EFIAPI\r
532FatFlush (\r
dba03ba1 533 IN EFI_FILE_PROTOCOL *FHand\r
b9ec9330 534 )\r
cae7420b 535;\r
b9ec9330 536\r
cae7420b 537/**\r
b9ec9330 538\r
cae7420b 539 Flushes all data associated with the file handle.\r
b9ec9330 540\r
cae7420b
DB
541 @param FHand - Handle to file to flush.\r
542 @param Token - A pointer to the token associated with the transaction.\r
b9ec9330 543\r
cae7420b
DB
544 @retval EFI_SUCCESS - Flushed the file successfully.\r
545 @retval EFI_WRITE_PROTECTED - The volume is read only.\r
546 @retval EFI_ACCESS_DENIED - The file is read only.\r
547 @return Others - Flushing of the file failed.\r
b9ec9330 548\r
cae7420b 549**/\r
149d6335
RN
550EFI_STATUS\r
551EFIAPI\r
552FatFlushEx (\r
553 IN EFI_FILE_PROTOCOL *FHand,\r
554 IN EFI_FILE_IO_TOKEN *Token\r
555 )\r
cae7420b 556;\r
149d6335 557\r
cae7420b 558/**\r
149d6335 559\r
cae7420b 560 Flushes & Closes the file handle.\r
149d6335 561\r
cae7420b 562 @param FHand - Handle to the file to delete.\r
149d6335 563\r
cae7420b 564 @retval EFI_SUCCESS - Closed the file successfully.\r
149d6335 565\r
cae7420b 566**/\r
b9ec9330
QH
567EFI_STATUS\r
568EFIAPI\r
569FatClose (\r
dba03ba1 570 IN EFI_FILE_PROTOCOL *FHand\r
b9ec9330 571 )\r
cae7420b 572;\r
b9ec9330 573\r
cae7420b 574/**\r
b9ec9330 575\r
cae7420b 576 Deletes the file & Closes the file handle.\r
b9ec9330 577\r
cae7420b 578 @param FHand - Handle to the file to delete.\r
b9ec9330 579\r
cae7420b
DB
580 @retval EFI_SUCCESS - Delete the file successfully.\r
581 @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.\r
b9ec9330 582\r
cae7420b 583**/\r
b9ec9330
QH
584EFI_STATUS\r
585EFIAPI\r
586FatDelete (\r
dba03ba1 587 IN EFI_FILE_PROTOCOL *FHand\r
b9ec9330 588 )\r
cae7420b 589;\r
b9ec9330 590\r
cae7420b 591/**\r
b9ec9330 592\r
cae7420b 593 Set the file's position of the file.\r
b9ec9330 594\r
cae7420b
DB
595 @param FHand - The handle of file\r
596 @param Position - The file's position of the file\r
b9ec9330 597\r
cae7420b
DB
598 @retval EFI_SUCCESS - Set the info successfully\r
599 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file\r
600 @retval EFI_UNSUPPORTED - Set a directory with a not-zero position\r
b9ec9330 601\r
cae7420b 602**/\r
b9ec9330
QH
603EFI_STATUS\r
604EFIAPI\r
605FatSetPosition (\r
dba03ba1 606 IN EFI_FILE_PROTOCOL *FHand,\r
b9ec9330
QH
607 IN UINT64 Position\r
608 )\r
cae7420b 609;\r
b9ec9330 610\r
cae7420b 611/**\r
b9ec9330 612\r
cae7420b 613 Get the file info.\r
b9ec9330 614\r
cae7420b
DB
615 @param FHand - The handle of the file.\r
616 @param BufferSize - Size of Buffer.\r
617 @param Buffer - Buffer containing read data.\r
b9ec9330 618\r
cae7420b
DB
619 @retval EFI_SUCCESS - Get the file info successfully.\r
620 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r
621 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.\r
622 @return other - An error occurred when operation the disk.\r
b9ec9330 623\r
cae7420b 624**/\r
b9ec9330
QH
625EFI_STATUS\r
626EFIAPI\r
627FatRead (\r
dba03ba1
QH
628 IN EFI_FILE_PROTOCOL *FHand,\r
629 IN OUT UINTN *BufferSize,\r
630 OUT VOID *Buffer\r
b9ec9330 631 )\r
cae7420b 632;\r
b9ec9330 633\r
cae7420b 634/**\r
b9ec9330
QH
635\r
636 Get the file info.\r
637\r
cae7420b
DB
638 @param FHand - The handle of the file.\r
639 @param Token - A pointer to the token associated with the transaction.\r
b9ec9330 640\r
cae7420b
DB
641 @retval EFI_SUCCESS - Get the file info successfully.\r
642 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r
643 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.\r
644 @return other - An error occurred when operation the disk.\r
b9ec9330 645\r
cae7420b 646**/\r
149d6335
RN
647EFI_STATUS\r
648EFIAPI\r
649FatReadEx (\r
650 IN EFI_FILE_PROTOCOL *FHand,\r
651 IN OUT EFI_FILE_IO_TOKEN *Token\r
652 )\r
cae7420b 653;\r
149d6335 654\r
cae7420b 655/**\r
149d6335 656\r
cae7420b 657 Set the file info.\r
149d6335 658\r
cae7420b
DB
659 @param FHand - The handle of the file.\r
660 @param BufferSize - Size of Buffer.\r
661 @param Buffer - Buffer containing write data.\r
149d6335 662\r
cae7420b
DB
663 @retval EFI_SUCCESS - Set the file info successfully.\r
664 @retval EFI_WRITE_PROTECTED - The disk is write protected.\r
665 @retval EFI_ACCESS_DENIED - The file is read-only.\r
666 @retval EFI_DEVICE_ERROR - The OFile is not valid.\r
667 @retval EFI_UNSUPPORTED - The open file is not a file.\r
668 - The writing file size is larger than 4GB.\r
669 @return other - An error occurred when operation the disk.\r
149d6335 670\r
cae7420b 671**/\r
b9ec9330
QH
672EFI_STATUS\r
673EFIAPI\r
674FatWrite (\r
dba03ba1
QH
675 IN EFI_FILE_PROTOCOL *FHand,\r
676 IN OUT UINTN *BufferSize,\r
677 IN VOID *Buffer\r
b9ec9330 678 )\r
cae7420b 679;\r
b9ec9330 680\r
cae7420b 681/**\r
b9ec9330 682\r
cae7420b 683 Get the file info.\r
b9ec9330 684\r
cae7420b
DB
685 @param FHand - The handle of the file.\r
686 @param Token - A pointer to the token associated with the transaction.\r
b9ec9330 687\r
cae7420b
DB
688 @retval EFI_SUCCESS - Get the file info successfully.\r
689 @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.\r
690 @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.\r
691 @return other - An error occurred when operation the disk.\r
b9ec9330 692\r
cae7420b 693**/\r
149d6335
RN
694EFI_STATUS\r
695EFIAPI\r
696FatWriteEx (\r
697 IN EFI_FILE_PROTOCOL *FHand,\r
698 IN OUT EFI_FILE_IO_TOKEN *Token\r
699 )\r
149d6335
RN
700;\r
701\r
b9ec9330
QH
702//\r
703// DiskCache.c\r
704//\r
705EFI_STATUS\r
706FatInitializeDiskCache (\r
707 IN FAT_VOLUME *Volume\r
708 );\r
709\r
710EFI_STATUS\r
711FatAccessCache (\r
712 IN FAT_VOLUME *Volume,\r
713 IN CACHE_DATA_TYPE CacheDataType,\r
714 IN IO_MODE IoMode,\r
715 IN UINT64 Offset,\r
716 IN UINTN BufferSize,\r
149d6335
RN
717 IN OUT UINT8 *Buffer,\r
718 IN FAT_TASK *Task\r
b9ec9330
QH
719 );\r
720\r
721EFI_STATUS\r
722FatVolumeFlushCache (\r
149d6335
RN
723 IN FAT_VOLUME *Volume,\r
724 IN FAT_TASK *Task\r
b9ec9330
QH
725 );\r
726\r
727//\r
728// Flush.c\r
729//\r
730EFI_STATUS\r
731FatOFileFlush (\r
732 IN FAT_OFILE *OFile\r
733 );\r
734\r
735BOOLEAN\r
736FatCheckOFileRef (\r
737 IN FAT_OFILE *OFile\r
738 );\r
739\r
740VOID\r
741FatSetVolumeError (\r
742 IN FAT_OFILE *OFile,\r
743 IN EFI_STATUS Status\r
744 );\r
745\r
746EFI_STATUS\r
747FatIFileClose (\r
748 FAT_IFILE *IFile\r
749 );\r
750\r
751EFI_STATUS\r
752FatCleanupVolume (\r
753 IN FAT_VOLUME *Volume,\r
754 IN FAT_OFILE *OFile,\r
149d6335
RN
755 IN EFI_STATUS EfiStatus,\r
756 IN FAT_TASK *Task\r
b9ec9330
QH
757 );\r
758\r
759//\r
760// FileSpace.c\r
761//\r
762EFI_STATUS\r
763FatShrinkEof (\r
764 IN FAT_OFILE *OFile\r
765 );\r
766\r
767EFI_STATUS\r
768FatGrowEof (\r
769 IN FAT_OFILE *OFile,\r
770 IN UINT64 NewSizeInBytes\r
771 );\r
772\r
773UINTN\r
774FatPhysicalDirSize (\r
775 IN FAT_VOLUME *Volume,\r
776 IN UINTN Cluster\r
777 );\r
778\r
779UINT64\r
780FatPhysicalFileSize (\r
781 IN FAT_VOLUME *Volume,\r
782 IN UINTN RealSize\r
783 );\r
784\r
785EFI_STATUS\r
786FatOFilePosition (\r
787 IN FAT_OFILE *OFile,\r
788 IN UINTN Position,\r
789 IN UINTN PosLimit\r
790 );\r
791\r
792VOID\r
793FatComputeFreeInfo (\r
794 IN FAT_VOLUME *Volume\r
795 );\r
796\r
797//\r
798// Init.c\r
799//\r
800EFI_STATUS\r
801FatAllocateVolume (\r
802 IN EFI_HANDLE Handle,\r
803 IN EFI_DISK_IO_PROTOCOL *DiskIo,\r
149d6335 804 IN EFI_DISK_IO2_PROTOCOL *DiskIo2,\r
b9ec9330
QH
805 IN EFI_BLOCK_IO_PROTOCOL *BlockIo\r
806 );\r
807\r
808EFI_STATUS\r
809FatOpenDevice (\r
810 IN OUT FAT_VOLUME *Volume\r
811 );\r
812\r
813EFI_STATUS\r
814FatAbandonVolume (\r
815 IN FAT_VOLUME *Volume\r
816 );\r
817\r
818//\r
819// Misc.c\r
820//\r
149d6335
RN
821FAT_TASK *\r
822FatCreateTask (\r
823 FAT_IFILE *IFile,\r
824 EFI_FILE_IO_TOKEN *Token\r
825 );\r
826\r
827VOID\r
828FatDestroyTask (\r
829 FAT_TASK *Task\r
830 );\r
831\r
832VOID\r
833FatWaitNonblockingTask (\r
834 FAT_IFILE *IFile\r
835 );\r
836\r
837LIST_ENTRY *\r
838FatDestroySubtask (\r
839 FAT_SUBTASK *Subtask\r
840 );\r
841\r
842EFI_STATUS\r
843FatQueueTask (\r
844 IN FAT_IFILE *IFile,\r
845 IN FAT_TASK *Task\r
846 );\r
847\r
b9ec9330
QH
848EFI_STATUS\r
849FatAccessVolumeDirty (\r
850 IN FAT_VOLUME *Volume,\r
851 IN IO_MODE IoMode,\r
852 IN VOID *DirtyValue\r
853 );\r
854\r
855EFI_STATUS\r
856FatDiskIo (\r
857 IN FAT_VOLUME *Volume,\r
858 IN IO_MODE IoMode,\r
859 IN UINT64 Offset,\r
860 IN UINTN BufferSize,\r
149d6335
RN
861 IN OUT VOID *Buffer,\r
862 IN FAT_TASK *Task\r
b9ec9330
QH
863 );\r
864\r
865VOID\r
866FatAcquireLock (\r
867 VOID\r
868 );\r
869\r
870VOID\r
871FatReleaseLock (\r
872 VOID\r
873 );\r
874\r
25ce9b1f
QH
875EFI_STATUS\r
876FatAcquireLockOrFail (\r
b9ec9330
QH
877 VOID\r
878 );\r
879\r
880VOID\r
881FatFreeDirEnt (\r
882 IN FAT_DIRENT *DirEnt\r
883 );\r
884\r
885VOID\r
886FatFreeVolume (\r
887 IN FAT_VOLUME *Volume\r
888 );\r
889\r
890VOID\r
891FatEfiTimeToFatTime (\r
892 IN EFI_TIME *ETime,\r
893 OUT FAT_DATE_TIME *FTime\r
894 );\r
895\r
896VOID\r
897FatFatTimeToEfiTime (\r
898 IN FAT_DATE_TIME *FTime,\r
899 OUT EFI_TIME *ETime\r
900 );\r
901\r
902VOID\r
903FatGetCurrentFatTime (\r
904 OUT FAT_DATE_TIME *FatTime\r
905 );\r
906\r
907BOOLEAN\r
908FatIsValidTime (\r
909 IN EFI_TIME *Time\r
910 );\r
911\r
912//\r
913// UnicodeCollation.c\r
914//\r
915EFI_STATUS\r
916InitializeUnicodeCollationSupport (\r
917 IN EFI_HANDLE AgentHandle\r
918 );\r
919\r
920VOID\r
921FatFatToStr (\r
922 IN UINTN FatSize,\r
923 IN CHAR8 *Fat,\r
924 OUT CHAR16 *String\r
925 );\r
926\r
927BOOLEAN\r
928FatStrToFat (\r
929 IN CHAR16 *String,\r
930 IN UINTN FatSize,\r
931 OUT CHAR8 *Fat\r
932 );\r
933\r
934VOID\r
935FatStrLwr (\r
936 IN CHAR16 *Str\r
937 );\r
938\r
939VOID\r
940FatStrUpr (\r
941 IN CHAR16 *Str\r
942 );\r
943\r
944INTN\r
945FatStriCmp (\r
946 IN CHAR16 *Str1,\r
947 IN CHAR16 *Str2\r
948 );\r
949\r
950//\r
951// Open.c\r
952//\r
953EFI_STATUS\r
954FatOFileOpen (\r
955 IN FAT_OFILE *OFile,\r
956 OUT FAT_IFILE **NewIFile,\r
957 IN CHAR16 *FileName,\r
958 IN UINT64 OpenMode,\r
959 IN UINT8 Attributes\r
960 );\r
961\r
962EFI_STATUS\r
963FatAllocateIFile (\r
964 IN FAT_OFILE *OFile,\r
965 OUT FAT_IFILE **PtrIFile\r
966 );\r
967\r
968//\r
969// OpenVolume.c\r
970//\r
971EFI_STATUS\r
972EFIAPI\r
973FatOpenVolume (\r
974 IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,\r
dba03ba1 975 OUT EFI_FILE_PROTOCOL **File\r
b9ec9330
QH
976 );\r
977\r
978//\r
979// ReadWrite.c\r
980//\r
981EFI_STATUS\r
982FatAccessOFile (\r
983 IN FAT_OFILE *OFile,\r
984 IN IO_MODE IoMode,\r
985 IN UINTN Position,\r
986 IN UINTN *DataBufferSize,\r
149d6335
RN
987 IN UINT8 *UserBuffer,\r
988 IN FAT_TASK *Task\r
b9ec9330
QH
989 );\r
990\r
991EFI_STATUS\r
992FatExpandOFile (\r
993 IN FAT_OFILE *OFile,\r
994 IN UINT64 ExpandedSize\r
995 );\r
996\r
997EFI_STATUS\r
998FatWriteZeroPool (\r
999 IN FAT_OFILE *OFile,\r
1000 IN UINTN WritePos\r
1001 );\r
1002\r
1003EFI_STATUS\r
1004FatTruncateOFile (\r
1005 IN FAT_OFILE *OFile,\r
1006 IN UINTN TruncatedSize\r
1007 );\r
1008\r
1009//\r
1010// DirectoryManage.c\r
1011//\r
1012VOID\r
1013FatResetODirCursor (\r
1014 IN FAT_OFILE *OFile\r
1015 );\r
1016\r
1017EFI_STATUS\r
1018FatGetNextDirEnt (\r
c1680e88 1019 IN FAT_OFILE *OFile,\r
b9ec9330
QH
1020 OUT FAT_DIRENT **PtrDirEnt\r
1021 );\r
1022\r
1023EFI_STATUS\r
1024FatRemoveDirEnt (\r
1025 IN FAT_OFILE *OFile,\r
1026 IN FAT_DIRENT *DirEnt\r
1027 );\r
1028\r
1029EFI_STATUS\r
1030FatStoreDirEnt (\r
1031 IN FAT_OFILE *OFile,\r
1032 IN FAT_DIRENT *DirEnt\r
1033 );\r
1034\r
1035EFI_STATUS\r
1036FatCreateDirEnt (\r
1037 IN FAT_OFILE *OFile,\r
1038 IN CHAR16 *FileName,\r
1039 IN UINT8 Attributes,\r
1040 OUT FAT_DIRENT **PtrDirEnt\r
1041 );\r
1042\r
1043BOOLEAN\r
1044FatIsDotDirEnt (\r
1045 IN FAT_DIRENT *DirEnt\r
1046 );\r
1047\r
1048VOID\r
1049FatUpdateDirEntClusterSizeInfo (\r
1050 IN FAT_OFILE *OFile\r
1051 );\r
1052\r
1053VOID\r
1054FatCloneDirEnt (\r
1055 IN FAT_DIRENT *DirEnt1,\r
1056 IN FAT_DIRENT *DirEnt2\r
1057 );\r
1058\r
1059EFI_STATUS\r
1060FatGetDirEntInfo (\r
1061 IN FAT_VOLUME *Volume,\r
1062 IN FAT_DIRENT *DirEnt,\r
1063 IN OUT UINTN *BufferSize,\r
1064 OUT VOID *Buffer\r
1065 );\r
1066\r
1067EFI_STATUS\r
1068FatOpenDirEnt (\r
1069 IN FAT_OFILE *OFile,\r
1070 IN FAT_DIRENT *DirEnt\r
1071 );\r
1072\r
1073EFI_STATUS\r
1074FatCreateDotDirEnts (\r
1075 IN FAT_OFILE *OFile\r
1076 );\r
1077\r
1078VOID\r
1079FatCloseDirEnt (\r
1080 IN FAT_DIRENT *DirEnt\r
1081 );\r
1082\r
1083EFI_STATUS\r
1084FatLocateOFile (\r
1085 IN OUT FAT_OFILE **PtrOFile,\r
1086 IN CHAR16 *FileName,\r
1087 IN UINT8 Attributes,\r
1088 OUT CHAR16 *NewFileName\r
1089 );\r
1090\r
1091EFI_STATUS\r
1092FatGetVolumeEntry (\r
1093 IN FAT_VOLUME *Volume,\r
1094 IN CHAR16 *Name\r
1095 );\r
1096\r
1097EFI_STATUS\r
1098FatSetVolumeEntry (\r
1099 IN FAT_VOLUME *Volume,\r
1100 IN CHAR16 *Name\r
1101 );\r
1102\r
1103//\r
1104// Hash.c\r
1105//\r
1106FAT_DIRENT **\r
1107FatLongNameHashSearch (\r
1108 IN FAT_ODIR *ODir,\r
1109 IN CHAR16 *LongNameString\r
1110 );\r
1111\r
1112FAT_DIRENT **\r
1113FatShortNameHashSearch (\r
1114 IN FAT_ODIR *ODir,\r
1115 IN CHAR8 *ShortNameString\r
1116 );\r
1117\r
1118VOID\r
1119FatInsertToHashTable (\r
1120 IN FAT_ODIR *ODir,\r
1121 IN FAT_DIRENT *DirEnt\r
1122 );\r
1123\r
1124VOID\r
1125FatDeleteFromHashTable (\r
1126 IN FAT_ODIR *ODir,\r
1127 IN FAT_DIRENT *DirEnt\r
1128 );\r
1129\r
1130//\r
1131// FileName.c\r
1132//\r
1133BOOLEAN\r
1134FatCheckIs8Dot3Name (\r
1135 IN CHAR16 *FileName,\r
1136 OUT CHAR8 *File8Dot3Name\r
1137 );\r
1138\r
1139VOID\r
1140FatCreate8Dot3Name (\r
1141 IN FAT_OFILE *Parent,\r
1142 IN FAT_DIRENT *DirEnt\r
1143 );\r
1144\r
1145VOID\r
1146FatNameToStr (\r
1147 IN CHAR8 *FatName,\r
1148 IN UINTN Len,\r
1149 IN UINTN LowerCase,\r
1150 IN CHAR16 *Str\r
1151 );\r
1152\r
1153VOID\r
1154FatSetCaseFlag (\r
1155 IN FAT_DIRENT *DirEnt\r
1156 );\r
1157\r
1158VOID\r
1159FatGetFileNameViaCaseFlag (\r
e76bc43e
HW
1160 IN FAT_DIRENT *DirEnt,\r
1161 IN OUT CHAR16 *FileString,\r
1162 IN UINTN FileStringMax\r
b9ec9330
QH
1163 );\r
1164\r
1165UINT8\r
1166FatCheckSum (\r
1167 IN CHAR8 *ShortNameString\r
1168 );\r
1169\r
1170CHAR16*\r
1171FatGetNextNameComponent (\r
1172 IN CHAR16 *Path,\r
1173 OUT CHAR16 *Name\r
1174 );\r
1175\r
1176BOOLEAN\r
1177FatFileNameIsValid (\r
1178 IN CHAR16 *InputFileName,\r
1179 OUT CHAR16 *OutputFileName\r
1180 );\r
1181\r
1182//\r
1183// DirectoryCache.c\r
1184//\r
1185VOID\r
1186FatDiscardODir (\r
1187 IN FAT_OFILE *OFile\r
1188 );\r
1189\r
1190VOID\r
1191FatRequestODir (\r
1192 IN FAT_OFILE *OFile\r
1193 );\r
1194\r
1195VOID\r
1196FatCleanupODirCache (\r
1197 IN FAT_VOLUME *Volume\r
1198 );\r
1199\r
1200//\r
1201// Global Variables\r
1202//\r
1203extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;\r
1204extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;\r
1205extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;\r
1206extern EFI_LOCK FatFsLock;\r
149d6335 1207extern EFI_LOCK FatTaskLock;\r
dba03ba1 1208extern EFI_FILE_PROTOCOL FatFileInterface;\r
b9ec9330
QH
1209\r
1210#endif\r