Fat.h 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118
  1. /*++
  2. Copyright (c) 2005 - 2010, Intel Corporation. All rights reserved.<BR>
  3. This program and the accompanying materials are licensed and made available
  4. under the terms and conditions of the BSD License which accompanies this
  5. distribution. The full text of the license may be found at
  6. http://opensource.org/licenses/bsd-license.php
  7. THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  9. Module Name:
  10. Fat.h
  11. Abstract:
  12. Main header file for EFI FAT file system driver
  13. Revision History
  14. --*/
  15. #ifndef _FAT_H_
  16. #define _FAT_H_
  17. #include <Uefi.h>
  18. #include <Guid/FileInfo.h>
  19. #include <Guid/FileSystemInfo.h>
  20. #include <Guid/FileSystemVolumeLabelInfo.h>
  21. #include <Protocol/BlockIo.h>
  22. #include <Protocol/DiskIo.h>
  23. #include <Protocol/SimpleFileSystem.h>
  24. #include <Protocol/UnicodeCollation.h>
  25. #include <Library/PcdLib.h>
  26. #include <Library/DebugLib.h>
  27. #include <Library/UefiLib.h>
  28. #include <Library/BaseLib.h>
  29. #include <Library/BaseMemoryLib.h>
  30. #include <Library/MemoryAllocationLib.h>
  31. #include <Library/UefiDriverEntryPoint.h>
  32. #include <Library/UefiBootServicesTableLib.h>
  33. #include <Library/UefiRuntimeServicesTableLib.h>
  34. #include "FatFileSystem.h"
  35. //
  36. // The FAT signature
  37. //
  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 ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
  44. #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
  45. #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
  46. #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
  47. #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
  48. #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
  49. #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
  50. #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
  51. //
  52. // Minimum sector size is 512B, Maximum sector size is 4096B
  53. // Max sectors per cluster is 128
  54. //
  55. #define MAX_BLOCK_ALIGNMENT 12
  56. #define MIN_BLOCK_ALIGNMENT 9
  57. #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
  58. //
  59. // Efi Time Definition
  60. //
  61. #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
  62. //
  63. // Minimum fat page size is 8K, maximum fat page alignment is 32K
  64. // Minimum data page size is 8K, maximum fat page alignment is 64K
  65. //
  66. #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13
  67. #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15
  68. #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13
  69. #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16
  70. #define FAT_DATACACHE_GROUP_COUNT 64
  71. #define FAT_FATCACHE_GROUP_MIN_COUNT 1
  72. #define FAT_FATCACHE_GROUP_MAX_COUNT 16
  73. //
  74. // Used in 8.3 generation algorithm
  75. //
  76. #define MAX_SPEC_RETRY 4
  77. #define SPEC_BASE_TAG_LEN 6
  78. #define HASH_BASE_TAG_LEN 2
  79. #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
  80. //
  81. // Path name separator is back slash
  82. //
  83. #define PATH_NAME_SEPARATOR L'\\'
  84. #define EFI_PATH_STRING_LENGTH 260
  85. #define EFI_FILE_STRING_LENGTH 255
  86. #define FAT_MAX_ALLOCATE_SIZE 0xA00000
  87. #define LC_ISO_639_2_ENTRY_SIZE 3
  88. #define MAX_LANG_CODE_SIZE 100
  89. #define FAT_MAX_DIR_CACHE_COUNT 8
  90. #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
  91. typedef CHAR8 LC_ISO_639_2;
  92. //
  93. // The fat types we support
  94. //
  95. typedef enum {
  96. FAT12,
  97. FAT16,
  98. FAT32,
  99. FatUndefined
  100. } FAT_VOLUME_TYPE;
  101. typedef enum {
  102. CACHE_FAT,
  103. CACHE_DATA,
  104. CACHE_MAX_TYPE
  105. } CACHE_DATA_TYPE;
  106. //
  107. // Used in FatDiskIo
  108. //
  109. typedef enum {
  110. READ_DISK = 0, // raw disk read
  111. WRITE_DISK = 1, // raw disk write
  112. READ_FAT = 2, // read fat cache
  113. WRITE_FAT = 3, // write fat cache
  114. READ_DATA = 6, // read data cache
  115. WRITE_DATA = 7 // write data cache
  116. } IO_MODE;
  117. #define CACHE_ENABLED(a) ((a) >= 2)
  118. #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
  119. #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
  120. //
  121. // Disk cache tag
  122. //
  123. typedef struct {
  124. UINTN PageNo;
  125. UINTN RealSize;
  126. BOOLEAN Dirty;
  127. } CACHE_TAG;
  128. typedef struct {
  129. UINT64 BaseAddress;
  130. UINT64 LimitAddress;
  131. UINT8 *CacheBase;
  132. BOOLEAN Dirty;
  133. UINT8 PageAlignment;
  134. UINTN GroupMask;
  135. CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
  136. } DISK_CACHE;
  137. //
  138. // Hash table size
  139. //
  140. #define HASH_TABLE_SIZE 0x400
  141. #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
  142. //
  143. // The directory entry for opened directory
  144. //
  145. typedef struct _FAT_DIRENT {
  146. UINTN Signature;
  147. UINT16 EntryPos; // The position of this directory entry in the parent directory file
  148. UINT8 EntryCount; // The count of the directory entry in the parent directory file
  149. BOOLEAN Invalid; // Indicate whether this directory entry is valid
  150. CHAR16 *FileString; // The unicode long file name for this directory entry
  151. struct _FAT_OFILE *OFile; // The OFile of the corresponding directory entry
  152. struct _FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename
  153. struct _FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename
  154. LIST_ENTRY Link; // Connection of every directory entry
  155. FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk
  156. } FAT_DIRENT;
  157. typedef struct _FAT_ODIR {
  158. UINTN Signature;
  159. UINT32 CurrentEndPos; // Current end position of the directory
  160. UINT32 CurrentPos; // Current position of the directory
  161. LIST_ENTRY *CurrentCursor; // Current directory entry pointer
  162. LIST_ENTRY ChildList; // List of all directory entries
  163. BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory
  164. LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded
  165. UINTN DirCacheTag; // The identification of the directory when in directory cache
  166. FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
  167. FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
  168. } FAT_ODIR;
  169. typedef struct {
  170. UINTN Signature;
  171. EFI_FILE_PROTOCOL Handle;
  172. UINT64 Position;
  173. BOOLEAN ReadOnly;
  174. struct _FAT_OFILE *OFile;
  175. LIST_ENTRY Link;
  176. } FAT_IFILE;
  177. //
  178. // FAT_OFILE - Each opened file
  179. //
  180. typedef struct _FAT_OFILE {
  181. UINTN Signature;
  182. struct _FAT_VOLUME *Volume;
  183. //
  184. // A permanant error code to return to all accesses to
  185. // this opened file
  186. //
  187. EFI_STATUS Error;
  188. //
  189. // A list of the IFILE instances for this OFile
  190. //
  191. LIST_ENTRY Opens;
  192. //
  193. // The dynamic infomation
  194. //
  195. UINTN FileSize;
  196. UINTN FileCluster;
  197. UINTN FileCurrentCluster;
  198. UINTN FileLastCluster;
  199. //
  200. // Dirty is set if there have been any updates to the
  201. // file
  202. // Archive is set if the archive attribute in the file's
  203. // directory entry needs to be set when performing flush
  204. // PreserveLastMod is set if the last modification of the
  205. // file is specified by SetInfo API
  206. //
  207. BOOLEAN Dirty;
  208. BOOLEAN IsFixedRootDir;
  209. BOOLEAN PreserveLastModification;
  210. BOOLEAN Archive;
  211. //
  212. // Set by an OFile SetPosition
  213. //
  214. UINTN Position; // within file
  215. UINT64 PosDisk; // on the disk
  216. UINTN PosRem; // remaining in this disk run
  217. //
  218. // The opened parent, full path length and currently opened child files
  219. //
  220. struct _FAT_OFILE *Parent;
  221. UINTN FullPathLen;
  222. LIST_ENTRY ChildHead;
  223. LIST_ENTRY ChildLink;
  224. //
  225. // The opened directory structure for a directory; if this
  226. // OFile represents a file, then ODir = NULL
  227. //
  228. FAT_ODIR *ODir;
  229. //
  230. // The directory entry for the Ofile
  231. //
  232. FAT_DIRENT *DirEnt;
  233. //
  234. // Link in Volume's reference list
  235. //
  236. LIST_ENTRY CheckLink;
  237. } FAT_OFILE;
  238. typedef struct _FAT_VOLUME {
  239. UINTN Signature;
  240. EFI_HANDLE Handle;
  241. BOOLEAN Valid;
  242. BOOLEAN DiskError;
  243. EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;
  244. //
  245. // If opened, the parent handle and BlockIo interface
  246. //
  247. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  248. EFI_DISK_IO_PROTOCOL *DiskIo;
  249. UINT32 MediaId;
  250. BOOLEAN ReadOnly;
  251. //
  252. // Computed values from fat bpb info
  253. //
  254. UINT64 VolumeSize;
  255. UINT64 FatPos; // Disk pos of fat tables
  256. UINT64 RootPos; // Disk pos of root directory
  257. UINT64 FirstClusterPos; // Disk pos of first cluster
  258. UINTN FatSize; // Number of bytes in each fat
  259. UINTN MaxCluster; // Max cluster number
  260. UINTN ClusterSize; // Cluster size of fat partition
  261. UINT8 ClusterAlignment; // Equal to log_2 (clustersize);
  262. FAT_VOLUME_TYPE FatType;
  263. //
  264. // Current part of fat table that's present
  265. //
  266. UINT64 FatEntryPos; // Location of buffer
  267. UINTN FatEntrySize; // Size of buffer
  268. UINT32 FatEntryBuffer; // The buffer
  269. FAT_INFO_SECTOR FatInfoSector; // Free cluster info
  270. UINTN FreeInfoPos; // Pos with the free cluster info
  271. BOOLEAN FreeInfoValid; // If free cluster info is valid
  272. //
  273. // Unpacked Fat BPB info
  274. //
  275. UINTN NumFats;
  276. UINTN RootEntries; // < FAT32, root dir is fixed size
  277. UINTN RootCluster; // >= FAT32, root cluster chain head
  278. //
  279. // info for marking the volume dirty or not
  280. //
  281. BOOLEAN FatDirty; // If fat-entries have been updated
  282. UINT32 DirtyValue;
  283. UINT32 NotDirtyValue;
  284. //
  285. // The root directory entry and opened root file
  286. //
  287. FAT_DIRENT RootDirEnt;
  288. //
  289. // File Name of root OFile, it is empty string
  290. //
  291. CHAR16 RootFileString[1];
  292. struct _FAT_OFILE *Root;
  293. //
  294. // New OFiles are added to this list so they
  295. // can be cleaned up if they aren't referenced.
  296. //
  297. LIST_ENTRY CheckRef;
  298. //
  299. // Directory cache List
  300. //
  301. LIST_ENTRY DirCacheList;
  302. UINTN DirCacheCount;
  303. //
  304. // Disk Cache for this volume
  305. //
  306. VOID *CacheBuffer;
  307. DISK_CACHE DiskCache[CACHE_MAX_TYPE];
  308. } FAT_VOLUME;
  309. //
  310. // Function Prototypes
  311. //
  312. EFI_STATUS
  313. EFIAPI
  314. FatOpen (
  315. IN EFI_FILE_PROTOCOL *FHand,
  316. OUT EFI_FILE_PROTOCOL **NewHandle,
  317. IN CHAR16 *FileName,
  318. IN UINT64 OpenMode,
  319. IN UINT64 Attributes
  320. )
  321. /*++
  322. Routine Description:
  323. Implements Open() of Simple File System Protocol.
  324. Arguments:
  325. FHand - File handle of the file serves as a starting reference point.
  326. NewHandle - Handle of the file that is newly opened.
  327. FileName - File name relative to FHand.
  328. OpenMode - Open mode.
  329. Attributes - Attributes to set if the file is created.
  330. Returns:
  331. EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
  332. The OpenMode is not supported.
  333. The Attributes is not the valid attributes.
  334. EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
  335. EFI_SUCCESS - Open the file successfully.
  336. Others - The status of open file.
  337. --*/
  338. ;
  339. EFI_STATUS
  340. EFIAPI
  341. FatGetPosition (
  342. IN EFI_FILE_PROTOCOL *FHand,
  343. OUT UINT64 *Position
  344. )
  345. /*++
  346. Routine Description:
  347. Get the file's position of the file
  348. Arguments:
  349. FHand - The handle of file.
  350. Position - The file's position of the file.
  351. Returns:
  352. EFI_SUCCESS - Get the info successfully.
  353. EFI_DEVICE_ERROR - Can not find the OFile for the file.
  354. EFI_UNSUPPORTED - The open file is not a file.
  355. --*/
  356. ;
  357. EFI_STATUS
  358. EFIAPI
  359. FatGetInfo (
  360. IN EFI_FILE_PROTOCOL *FHand,
  361. IN EFI_GUID *Type,
  362. IN OUT UINTN *BufferSize,
  363. OUT VOID *Buffer
  364. )
  365. /*++
  366. Routine Description:
  367. Get the some types info of the file into Buffer
  368. Arguments:
  369. FHand - The handle of file.
  370. Type - The type of the info.
  371. BufferSize - Size of Buffer.
  372. Buffer - Buffer containing volume info.
  373. Returns:
  374. EFI_SUCCESS - Get the info successfully.
  375. EFI_DEVICE_ERROR - Can not find the OFile for the file.
  376. --*/
  377. ;
  378. EFI_STATUS
  379. EFIAPI
  380. FatSetInfo (
  381. IN EFI_FILE_PROTOCOL *FHand,
  382. IN EFI_GUID *Type,
  383. IN UINTN BufferSize,
  384. IN VOID *Buffer
  385. )
  386. /*++
  387. Routine Description:
  388. Set the some types info of the file into Buffer
  389. Arguments:
  390. FHand - The handle of file.
  391. Type - The type of the info.
  392. BufferSize - Size of Buffer.
  393. Buffer - Buffer containing volume info.
  394. Returns:
  395. EFI_SUCCESS - Set the info successfully.
  396. EFI_DEVICE_ERROR - Can not find the OFile for the file.
  397. --*/
  398. ;
  399. EFI_STATUS
  400. EFIAPI
  401. FatFlush (
  402. IN EFI_FILE_PROTOCOL *FHand
  403. )
  404. /*++
  405. Routine Description:
  406. Flushes all data associated with the file handle
  407. Arguments:
  408. FHand - Handle to file to flush
  409. Returns:
  410. EFI_SUCCESS - Flushed the file successfully
  411. EFI_WRITE_PROTECTED - The volume is read only
  412. EFI_ACCESS_DENIED - The volume is not read only
  413. but the file is read only
  414. Others - Flushing of the file is failed
  415. --*/
  416. ;
  417. EFI_STATUS
  418. EFIAPI
  419. FatClose (
  420. IN EFI_FILE_PROTOCOL *FHand
  421. )
  422. /*++
  423. Routine Description:
  424. Flushes & Closes the file handle.
  425. Arguments:
  426. FHand - Handle to the file to delete.
  427. Returns:
  428. EFI_SUCCESS - Closed the file successfully.
  429. --*/
  430. ;
  431. EFI_STATUS
  432. EFIAPI
  433. FatDelete (
  434. IN EFI_FILE_PROTOCOL *FHand
  435. )
  436. /*++
  437. Routine Description:
  438. Deletes the file & Closes the file handle.
  439. Arguments:
  440. FHand - Handle to the file to delete.
  441. Returns:
  442. EFI_SUCCESS - Delete the file successfully.
  443. EFI_WARN_DELETE_FAILURE - Fail to delete the file.
  444. --*/
  445. ;
  446. EFI_STATUS
  447. EFIAPI
  448. FatSetPosition (
  449. IN EFI_FILE_PROTOCOL *FHand,
  450. IN UINT64 Position
  451. )
  452. /*++
  453. Routine Description:
  454. Set the file's position of the file
  455. Arguments:
  456. FHand - The handle of file
  457. Position - The file's position of the file
  458. Returns:
  459. EFI_SUCCESS - Set the info successfully
  460. EFI_DEVICE_ERROR - Can not find the OFile for the file
  461. EFI_UNSUPPORTED - Set a directory with a not-zero position
  462. --*/
  463. ;
  464. EFI_STATUS
  465. EFIAPI
  466. FatRead (
  467. IN EFI_FILE_PROTOCOL *FHand,
  468. IN OUT UINTN *BufferSize,
  469. OUT VOID *Buffer
  470. )
  471. /*++
  472. Routine Description:
  473. Get the file info.
  474. Arguments:
  475. FHand - The handle of the file.
  476. BufferSize - Size of Buffer.
  477. Buffer - Buffer containing read data.
  478. Returns:
  479. EFI_SUCCESS - Get the file info successfully.
  480. EFI_DEVICE_ERROR - Can not find the OFile for the file.
  481. EFI_VOLUME_CORRUPTED - The file type of open file is error.
  482. other - An error occurred when operation the disk.
  483. --*/
  484. ;
  485. EFI_STATUS
  486. EFIAPI
  487. FatWrite (
  488. IN EFI_FILE_PROTOCOL *FHand,
  489. IN OUT UINTN *BufferSize,
  490. IN VOID *Buffer
  491. )
  492. /*++
  493. Routine Description:
  494. Set the file info.
  495. Arguments:
  496. FHand - The handle of the file.
  497. BufferSize - Size of Buffer.
  498. Buffer - Buffer containing write data.
  499. Returns:
  500. EFI_SUCCESS - Set the file info successfully.
  501. EFI_WRITE_PROTECTED - The disk is write protected.
  502. EFI_ACCESS_DENIED - The file is read-only.
  503. EFI_DEVICE_ERROR - The OFile is not valid.
  504. EFI_UNSUPPORTED - The open file is not a file.
  505. - The writing file size is larger than 4GB.
  506. other - An error occurred when operation the disk.
  507. --*/
  508. ;
  509. //
  510. // DiskCache.c
  511. //
  512. EFI_STATUS
  513. FatInitializeDiskCache (
  514. IN FAT_VOLUME *Volume
  515. );
  516. EFI_STATUS
  517. FatAccessCache (
  518. IN FAT_VOLUME *Volume,
  519. IN CACHE_DATA_TYPE CacheDataType,
  520. IN IO_MODE IoMode,
  521. IN UINT64 Offset,
  522. IN UINTN BufferSize,
  523. IN OUT UINT8 *Buffer
  524. );
  525. EFI_STATUS
  526. FatVolumeFlushCache (
  527. IN FAT_VOLUME *Volume
  528. );
  529. //
  530. // Flush.c
  531. //
  532. EFI_STATUS
  533. FatOFileFlush (
  534. IN FAT_OFILE *OFile
  535. );
  536. BOOLEAN
  537. FatCheckOFileRef (
  538. IN FAT_OFILE *OFile
  539. );
  540. VOID
  541. FatSetVolumeError (
  542. IN FAT_OFILE *OFile,
  543. IN EFI_STATUS Status
  544. );
  545. EFI_STATUS
  546. FatIFileClose (
  547. FAT_IFILE *IFile
  548. );
  549. EFI_STATUS
  550. FatCleanupVolume (
  551. IN FAT_VOLUME *Volume,
  552. IN FAT_OFILE *OFile,
  553. IN EFI_STATUS EfiStatus
  554. );
  555. //
  556. // FileSpace.c
  557. //
  558. EFI_STATUS
  559. FatShrinkEof (
  560. IN FAT_OFILE *OFile
  561. );
  562. EFI_STATUS
  563. FatGrowEof (
  564. IN FAT_OFILE *OFile,
  565. IN UINT64 NewSizeInBytes
  566. );
  567. UINTN
  568. FatPhysicalDirSize (
  569. IN FAT_VOLUME *Volume,
  570. IN UINTN Cluster
  571. );
  572. UINT64
  573. FatPhysicalFileSize (
  574. IN FAT_VOLUME *Volume,
  575. IN UINTN RealSize
  576. );
  577. EFI_STATUS
  578. FatOFilePosition (
  579. IN FAT_OFILE *OFile,
  580. IN UINTN Position,
  581. IN UINTN PosLimit
  582. );
  583. VOID
  584. FatComputeFreeInfo (
  585. IN FAT_VOLUME *Volume
  586. );
  587. //
  588. // Init.c
  589. //
  590. EFI_STATUS
  591. FatAllocateVolume (
  592. IN EFI_HANDLE Handle,
  593. IN EFI_DISK_IO_PROTOCOL *DiskIo,
  594. IN EFI_BLOCK_IO_PROTOCOL *BlockIo
  595. );
  596. EFI_STATUS
  597. FatOpenDevice (
  598. IN OUT FAT_VOLUME *Volume
  599. );
  600. EFI_STATUS
  601. FatAbandonVolume (
  602. IN FAT_VOLUME *Volume
  603. );
  604. //
  605. // Misc.c
  606. //
  607. EFI_STATUS
  608. FatAccessVolumeDirty (
  609. IN FAT_VOLUME *Volume,
  610. IN IO_MODE IoMode,
  611. IN VOID *DirtyValue
  612. );
  613. EFI_STATUS
  614. FatDiskIo (
  615. IN FAT_VOLUME *Volume,
  616. IN IO_MODE IoMode,
  617. IN UINT64 Offset,
  618. IN UINTN BufferSize,
  619. IN OUT VOID *Buffer
  620. );
  621. VOID
  622. FatAcquireLock (
  623. VOID
  624. );
  625. VOID
  626. FatReleaseLock (
  627. VOID
  628. );
  629. EFI_STATUS
  630. FatAcquireLockOrFail (
  631. VOID
  632. );
  633. VOID
  634. FatFreeDirEnt (
  635. IN FAT_DIRENT *DirEnt
  636. );
  637. VOID
  638. FatFreeVolume (
  639. IN FAT_VOLUME *Volume
  640. );
  641. VOID
  642. FatEfiTimeToFatTime (
  643. IN EFI_TIME *ETime,
  644. OUT FAT_DATE_TIME *FTime
  645. );
  646. VOID
  647. FatFatTimeToEfiTime (
  648. IN FAT_DATE_TIME *FTime,
  649. OUT EFI_TIME *ETime
  650. );
  651. VOID
  652. FatGetCurrentFatTime (
  653. OUT FAT_DATE_TIME *FatTime
  654. );
  655. BOOLEAN
  656. FatIsValidTime (
  657. IN EFI_TIME *Time
  658. );
  659. //
  660. // UnicodeCollation.c
  661. //
  662. EFI_STATUS
  663. InitializeUnicodeCollationSupport (
  664. IN EFI_HANDLE AgentHandle
  665. );
  666. VOID
  667. FatFatToStr (
  668. IN UINTN FatSize,
  669. IN CHAR8 *Fat,
  670. OUT CHAR16 *String
  671. );
  672. BOOLEAN
  673. FatStrToFat (
  674. IN CHAR16 *String,
  675. IN UINTN FatSize,
  676. OUT CHAR8 *Fat
  677. );
  678. VOID
  679. FatStrLwr (
  680. IN CHAR16 *Str
  681. );
  682. VOID
  683. FatStrUpr (
  684. IN CHAR16 *Str
  685. );
  686. INTN
  687. FatStriCmp (
  688. IN CHAR16 *Str1,
  689. IN CHAR16 *Str2
  690. );
  691. //
  692. // Open.c
  693. //
  694. EFI_STATUS
  695. FatOFileOpen (
  696. IN FAT_OFILE *OFile,
  697. OUT FAT_IFILE **NewIFile,
  698. IN CHAR16 *FileName,
  699. IN UINT64 OpenMode,
  700. IN UINT8 Attributes
  701. );
  702. EFI_STATUS
  703. FatAllocateIFile (
  704. IN FAT_OFILE *OFile,
  705. OUT FAT_IFILE **PtrIFile
  706. );
  707. //
  708. // OpenVolume.c
  709. //
  710. EFI_STATUS
  711. EFIAPI
  712. FatOpenVolume (
  713. IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
  714. OUT EFI_FILE_PROTOCOL **File
  715. );
  716. //
  717. // ReadWrite.c
  718. //
  719. EFI_STATUS
  720. FatAccessOFile (
  721. IN FAT_OFILE *OFile,
  722. IN IO_MODE IoMode,
  723. IN UINTN Position,
  724. IN UINTN *DataBufferSize,
  725. IN UINT8 *UserBuffer
  726. );
  727. EFI_STATUS
  728. FatExpandOFile (
  729. IN FAT_OFILE *OFile,
  730. IN UINT64 ExpandedSize
  731. );
  732. EFI_STATUS
  733. FatWriteZeroPool (
  734. IN FAT_OFILE *OFile,
  735. IN UINTN WritePos
  736. );
  737. EFI_STATUS
  738. FatTruncateOFile (
  739. IN FAT_OFILE *OFile,
  740. IN UINTN TruncatedSize
  741. );
  742. //
  743. // DirectoryManage.c
  744. //
  745. VOID
  746. FatResetODirCursor (
  747. IN FAT_OFILE *OFile
  748. );
  749. EFI_STATUS
  750. FatGetNextDirEnt (
  751. IN FAT_OFILE *OFILE,
  752. OUT FAT_DIRENT **PtrDirEnt
  753. );
  754. EFI_STATUS
  755. FatRemoveDirEnt (
  756. IN FAT_OFILE *OFile,
  757. IN FAT_DIRENT *DirEnt
  758. );
  759. EFI_STATUS
  760. FatStoreDirEnt (
  761. IN FAT_OFILE *OFile,
  762. IN FAT_DIRENT *DirEnt
  763. );
  764. EFI_STATUS
  765. FatCreateDirEnt (
  766. IN FAT_OFILE *OFile,
  767. IN CHAR16 *FileName,
  768. IN UINT8 Attributes,
  769. OUT FAT_DIRENT **PtrDirEnt
  770. );
  771. BOOLEAN
  772. FatIsDotDirEnt (
  773. IN FAT_DIRENT *DirEnt
  774. );
  775. VOID
  776. FatUpdateDirEntClusterSizeInfo (
  777. IN FAT_OFILE *OFile
  778. );
  779. VOID
  780. FatCloneDirEnt (
  781. IN FAT_DIRENT *DirEnt1,
  782. IN FAT_DIRENT *DirEnt2
  783. );
  784. EFI_STATUS
  785. FatGetDirEntInfo (
  786. IN FAT_VOLUME *Volume,
  787. IN FAT_DIRENT *DirEnt,
  788. IN OUT UINTN *BufferSize,
  789. OUT VOID *Buffer
  790. );
  791. EFI_STATUS
  792. FatOpenDirEnt (
  793. IN FAT_OFILE *OFile,
  794. IN FAT_DIRENT *DirEnt
  795. );
  796. EFI_STATUS
  797. FatCreateDotDirEnts (
  798. IN FAT_OFILE *OFile
  799. );
  800. VOID
  801. FatCloseDirEnt (
  802. IN FAT_DIRENT *DirEnt
  803. );
  804. EFI_STATUS
  805. FatLocateOFile (
  806. IN OUT FAT_OFILE **PtrOFile,
  807. IN CHAR16 *FileName,
  808. IN UINT8 Attributes,
  809. OUT CHAR16 *NewFileName
  810. );
  811. EFI_STATUS
  812. FatGetVolumeEntry (
  813. IN FAT_VOLUME *Volume,
  814. IN CHAR16 *Name
  815. );
  816. EFI_STATUS
  817. FatSetVolumeEntry (
  818. IN FAT_VOLUME *Volume,
  819. IN CHAR16 *Name
  820. );
  821. //
  822. // Hash.c
  823. //
  824. FAT_DIRENT **
  825. FatLongNameHashSearch (
  826. IN FAT_ODIR *ODir,
  827. IN CHAR16 *LongNameString
  828. );
  829. FAT_DIRENT **
  830. FatShortNameHashSearch (
  831. IN FAT_ODIR *ODir,
  832. IN CHAR8 *ShortNameString
  833. );
  834. VOID
  835. FatInsertToHashTable (
  836. IN FAT_ODIR *ODir,
  837. IN FAT_DIRENT *DirEnt
  838. );
  839. VOID
  840. FatDeleteFromHashTable (
  841. IN FAT_ODIR *ODir,
  842. IN FAT_DIRENT *DirEnt
  843. );
  844. //
  845. // FileName.c
  846. //
  847. BOOLEAN
  848. FatCheckIs8Dot3Name (
  849. IN CHAR16 *FileName,
  850. OUT CHAR8 *File8Dot3Name
  851. );
  852. VOID
  853. FatCreate8Dot3Name (
  854. IN FAT_OFILE *Parent,
  855. IN FAT_DIRENT *DirEnt
  856. );
  857. VOID
  858. FatNameToStr (
  859. IN CHAR8 *FatName,
  860. IN UINTN Len,
  861. IN UINTN LowerCase,
  862. IN CHAR16 *Str
  863. );
  864. VOID
  865. FatSetCaseFlag (
  866. IN FAT_DIRENT *DirEnt
  867. );
  868. VOID
  869. FatGetFileNameViaCaseFlag (
  870. IN FAT_DIRENT *DirEnt,
  871. OUT CHAR16 *FileString
  872. );
  873. UINT8
  874. FatCheckSum (
  875. IN CHAR8 *ShortNameString
  876. );
  877. CHAR16*
  878. FatGetNextNameComponent (
  879. IN CHAR16 *Path,
  880. OUT CHAR16 *Name
  881. );
  882. BOOLEAN
  883. FatFileNameIsValid (
  884. IN CHAR16 *InputFileName,
  885. OUT CHAR16 *OutputFileName
  886. );
  887. //
  888. // DirectoryCache.c
  889. //
  890. VOID
  891. FatDiscardODir (
  892. IN FAT_OFILE *OFile
  893. );
  894. VOID
  895. FatRequestODir (
  896. IN FAT_OFILE *OFile
  897. );
  898. VOID
  899. FatCleanupODirCache (
  900. IN FAT_VOLUME *Volume
  901. );
  902. //
  903. // Global Variables
  904. //
  905. extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
  906. extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
  907. extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
  908. extern EFI_LOCK FatFsLock;
  909. extern EFI_FILE_PROTOCOL FatFileInterface;
  910. #endif