Fat.h 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008
  1. /** @file
  2. Main header file for EFI FAT file system driver.
  3. Copyright (c) 2005 - 2013, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _FAT_H_
  7. #define _FAT_H_
  8. #include <Uefi.h>
  9. #include <Guid/FileInfo.h>
  10. #include <Guid/FileSystemInfo.h>
  11. #include <Guid/FileSystemVolumeLabelInfo.h>
  12. #include <Protocol/BlockIo.h>
  13. #include <Protocol/DiskIo.h>
  14. #include <Protocol/DiskIo2.h>
  15. #include <Protocol/SimpleFileSystem.h>
  16. #include <Protocol/UnicodeCollation.h>
  17. #include <Library/PcdLib.h>
  18. #include <Library/DebugLib.h>
  19. #include <Library/UefiLib.h>
  20. #include <Library/BaseLib.h>
  21. #include <Library/BaseMemoryLib.h>
  22. #include <Library/MemoryAllocationLib.h>
  23. #include <Library/UefiDriverEntryPoint.h>
  24. #include <Library/UefiBootServicesTableLib.h>
  25. #include <Library/UefiRuntimeServicesTableLib.h>
  26. #include "FatFileSystem.h"
  27. //
  28. // The FAT signature
  29. //
  30. #define FAT_VOLUME_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'v')
  31. #define FAT_IFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'i')
  32. #define FAT_ODIR_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'd')
  33. #define FAT_DIRENT_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'e')
  34. #define FAT_OFILE_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'o')
  35. #define FAT_TASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'T')
  36. #define FAT_SUBTASK_SIGNATURE SIGNATURE_32 ('f', 'a', 't', 'S')
  37. #define ASSERT_VOLUME_LOCKED(a) ASSERT_LOCKED (&FatFsLock)
  38. #define IFILE_FROM_FHAND(a) CR (a, FAT_IFILE, Handle, FAT_IFILE_SIGNATURE)
  39. #define DIRENT_FROM_LINK(a) CR (a, FAT_DIRENT, Link, FAT_DIRENT_SIGNATURE)
  40. #define VOLUME_FROM_ROOT_DIRENT(a) CR (a, FAT_VOLUME, RootDirEnt, FAT_VOLUME_SIGNATURE)
  41. #define VOLUME_FROM_VOL_INTERFACE(a) CR (a, FAT_VOLUME, VolumeInterface, FAT_VOLUME_SIGNATURE);
  42. #define ODIR_FROM_DIRCACHELINK(a) CR (a, FAT_ODIR, DirCacheLink, FAT_ODIR_SIGNATURE)
  43. #define OFILE_FROM_CHECKLINK(a) CR (a, FAT_OFILE, CheckLink, FAT_OFILE_SIGNATURE)
  44. #define OFILE_FROM_CHILDLINK(a) CR (a, FAT_OFILE, ChildLink, FAT_OFILE_SIGNATURE)
  45. //
  46. // Minimum sector size is 512B, Maximum sector size is 4096B
  47. // Max sectors per cluster is 128
  48. //
  49. #define MAX_BLOCK_ALIGNMENT 12
  50. #define MIN_BLOCK_ALIGNMENT 9
  51. #define MAX_SECTORS_PER_CLUSTER_ALIGNMENT 7
  52. //
  53. // Efi Time Definition
  54. //
  55. #define IS_LEAP_YEAR(a) (((a) % 4 == 0) && (((a) % 100 != 0) || ((a) % 400 == 0)))
  56. //
  57. // Minimum fat page size is 8K, maximum fat page alignment is 32K
  58. // Minimum data page size is 8K, maximum fat page alignment is 64K
  59. //
  60. #define FAT_FATCACHE_PAGE_MIN_ALIGNMENT 13
  61. #define FAT_FATCACHE_PAGE_MAX_ALIGNMENT 15
  62. #define FAT_DATACACHE_PAGE_MIN_ALIGNMENT 13
  63. #define FAT_DATACACHE_PAGE_MAX_ALIGNMENT 16
  64. #define FAT_DATACACHE_GROUP_COUNT 64
  65. #define FAT_FATCACHE_GROUP_MIN_COUNT 1
  66. #define FAT_FATCACHE_GROUP_MAX_COUNT 16
  67. //
  68. // Used in 8.3 generation algorithm
  69. //
  70. #define MAX_SPEC_RETRY 4
  71. #define SPEC_BASE_TAG_LEN 6
  72. #define HASH_BASE_TAG_LEN 2
  73. #define HASH_VALUE_TAG_LEN (SPEC_BASE_TAG_LEN - HASH_BASE_TAG_LEN)
  74. //
  75. // Path name separator is back slash
  76. //
  77. #define PATH_NAME_SEPARATOR L'\\'
  78. #define EFI_PATH_STRING_LENGTH 260
  79. #define EFI_FILE_STRING_LENGTH 255
  80. #define FAT_MAX_ALLOCATE_SIZE 0xA00000
  81. #define LC_ISO_639_2_ENTRY_SIZE 3
  82. #define MAX_LANG_CODE_SIZE 100
  83. #define FAT_MAX_DIR_CACHE_COUNT 8
  84. #define FAT_MAX_DIRENTRY_COUNT 0xFFFF
  85. typedef CHAR8 LC_ISO_639_2;
  86. //
  87. // The fat types we support
  88. //
  89. typedef enum {
  90. Fat12,
  91. Fat16,
  92. Fat32,
  93. FatUndefined
  94. } FAT_VOLUME_TYPE;
  95. typedef enum {
  96. CacheFat,
  97. CacheData,
  98. CacheMaxType
  99. } CACHE_DATA_TYPE;
  100. //
  101. // Used in FatDiskIo
  102. //
  103. typedef enum {
  104. ReadDisk = 0, // raw disk read
  105. WriteDisk = 1, // raw disk write
  106. ReadFat = 2, // read fat cache
  107. WriteFat = 3, // write fat cache
  108. ReadData = 6, // read data cache
  109. WriteData = 7 // write data cache
  110. } IO_MODE;
  111. #define CACHE_ENABLED(a) ((a) >= 2)
  112. #define RAW_ACCESS(a) ((IO_MODE)((a) & 0x1))
  113. #define CACHE_TYPE(a) ((CACHE_DATA_TYPE)((a) >> 2))
  114. //
  115. // Disk cache tag
  116. //
  117. typedef struct {
  118. UINTN PageNo;
  119. UINTN RealSize;
  120. BOOLEAN Dirty;
  121. } CACHE_TAG;
  122. typedef struct {
  123. UINT64 BaseAddress;
  124. UINT64 LimitAddress;
  125. UINT8 *CacheBase;
  126. BOOLEAN Dirty;
  127. UINT8 PageAlignment;
  128. UINTN GroupMask;
  129. CACHE_TAG CacheTag[FAT_DATACACHE_GROUP_COUNT];
  130. } DISK_CACHE;
  131. //
  132. // Hash table size
  133. //
  134. #define HASH_TABLE_SIZE 0x400
  135. #define HASH_TABLE_MASK (HASH_TABLE_SIZE - 1)
  136. //
  137. // The directory entry for opened directory
  138. //
  139. typedef struct _FAT_DIRENT FAT_DIRENT;
  140. typedef struct _FAT_ODIR FAT_ODIR;
  141. typedef struct _FAT_OFILE FAT_OFILE;
  142. typedef struct _FAT_VOLUME FAT_VOLUME;
  143. struct _FAT_DIRENT {
  144. UINTN Signature;
  145. UINT16 EntryPos; // The position of this directory entry in the parent directory file
  146. UINT8 EntryCount; // The count of the directory entry in the parent directory file
  147. BOOLEAN Invalid; // Indicate whether this directory entry is valid
  148. CHAR16 *FileString; // The unicode long file name for this directory entry
  149. FAT_OFILE *OFile; // The OFile of the corresponding directory entry
  150. FAT_DIRENT *ShortNameForwardLink; // Hash successor link for short filename
  151. FAT_DIRENT *LongNameForwardLink; // Hash successor link for long filename
  152. LIST_ENTRY Link; // Connection of every directory entry
  153. FAT_DIRECTORY_ENTRY Entry; // The physical directory entry stored in disk
  154. };
  155. struct _FAT_ODIR {
  156. UINTN Signature;
  157. UINT32 CurrentEndPos; // Current end position of the directory
  158. UINT32 CurrentPos; // Current position of the directory
  159. LIST_ENTRY *CurrentCursor; // Current directory entry pointer
  160. LIST_ENTRY ChildList; // List of all directory entries
  161. BOOLEAN EndOfDir; // Indicate whether we have reached the end of the directory
  162. LIST_ENTRY DirCacheLink; // Linked in Volume->DirCacheList when discarded
  163. UINTN DirCacheTag; // The identification of the directory when in directory cache
  164. FAT_DIRENT *LongNameHashTable[HASH_TABLE_SIZE];
  165. FAT_DIRENT *ShortNameHashTable[HASH_TABLE_SIZE];
  166. };
  167. typedef struct {
  168. UINTN Signature;
  169. EFI_FILE_PROTOCOL Handle;
  170. UINT64 Position;
  171. BOOLEAN ReadOnly;
  172. FAT_OFILE *OFile;
  173. LIST_ENTRY Tasks; // List of all FAT_TASKs
  174. LIST_ENTRY Link; // Link to other IFiles
  175. } FAT_IFILE;
  176. typedef struct {
  177. UINTN Signature;
  178. EFI_FILE_IO_TOKEN *FileIoToken;
  179. FAT_IFILE *IFile;
  180. LIST_ENTRY Subtasks; // List of all FAT_SUBTASKs
  181. LIST_ENTRY Link; // Link to other FAT_TASKs
  182. } FAT_TASK;
  183. typedef struct {
  184. UINTN Signature;
  185. EFI_DISK_IO2_TOKEN DiskIo2Token;
  186. FAT_TASK *Task;
  187. BOOLEAN Write;
  188. UINT64 Offset;
  189. VOID *Buffer;
  190. UINTN BufferSize;
  191. LIST_ENTRY Link;
  192. } FAT_SUBTASK;
  193. //
  194. // FAT_OFILE - Each opened file
  195. //
  196. struct _FAT_OFILE {
  197. UINTN Signature;
  198. FAT_VOLUME *Volume;
  199. //
  200. // A permanant error code to return to all accesses to
  201. // this opened file
  202. //
  203. EFI_STATUS Error;
  204. //
  205. // A list of the IFILE instances for this OFile
  206. //
  207. LIST_ENTRY Opens;
  208. //
  209. // The dynamic infomation
  210. //
  211. UINTN FileSize;
  212. UINTN FileCluster;
  213. UINTN FileCurrentCluster;
  214. UINTN FileLastCluster;
  215. //
  216. // Dirty is set if there have been any updates to the
  217. // file
  218. // Archive is set if the archive attribute in the file's
  219. // directory entry needs to be set when performing flush
  220. // PreserveLastMod is set if the last modification of the
  221. // file is specified by SetInfo API
  222. //
  223. BOOLEAN Dirty;
  224. BOOLEAN IsFixedRootDir;
  225. BOOLEAN PreserveLastModification;
  226. BOOLEAN Archive;
  227. //
  228. // Set by an OFile SetPosition
  229. //
  230. UINTN Position; // within file
  231. UINT64 PosDisk; // on the disk
  232. UINTN PosRem; // remaining in this disk run
  233. //
  234. // The opened parent, full path length and currently opened child files
  235. //
  236. FAT_OFILE *Parent;
  237. UINTN FullPathLen;
  238. LIST_ENTRY ChildHead;
  239. LIST_ENTRY ChildLink;
  240. //
  241. // The opened directory structure for a directory; if this
  242. // OFile represents a file, then ODir = NULL
  243. //
  244. FAT_ODIR *ODir;
  245. //
  246. // The directory entry for the Ofile
  247. //
  248. FAT_DIRENT *DirEnt;
  249. //
  250. // Link in Volume's reference list
  251. //
  252. LIST_ENTRY CheckLink;
  253. };
  254. struct _FAT_VOLUME {
  255. UINTN Signature;
  256. EFI_HANDLE Handle;
  257. BOOLEAN Valid;
  258. BOOLEAN DiskError;
  259. EFI_SIMPLE_FILE_SYSTEM_PROTOCOL VolumeInterface;
  260. //
  261. // If opened, the parent handle and BlockIo interface
  262. //
  263. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  264. EFI_DISK_IO_PROTOCOL *DiskIo;
  265. EFI_DISK_IO2_PROTOCOL *DiskIo2;
  266. UINT32 MediaId;
  267. BOOLEAN ReadOnly;
  268. //
  269. // Computed values from fat bpb info
  270. //
  271. UINT64 VolumeSize;
  272. UINT64 FatPos; // Disk pos of fat tables
  273. UINT64 RootPos; // Disk pos of root directory
  274. UINT64 FirstClusterPos; // Disk pos of first cluster
  275. UINTN FatSize; // Number of bytes in each fat
  276. UINTN MaxCluster; // Max cluster number
  277. UINTN ClusterSize; // Cluster size of fat partition
  278. UINT8 ClusterAlignment; // Equal to log_2 (clustersize);
  279. FAT_VOLUME_TYPE FatType;
  280. //
  281. // Current part of fat table that's present
  282. //
  283. UINT64 FatEntryPos; // Location of buffer
  284. UINTN FatEntrySize; // Size of buffer
  285. UINT32 FatEntryBuffer; // The buffer
  286. FAT_INFO_SECTOR FatInfoSector; // Free cluster info
  287. UINTN FreeInfoPos; // Pos with the free cluster info
  288. BOOLEAN FreeInfoValid; // If free cluster info is valid
  289. //
  290. // Unpacked Fat BPB info
  291. //
  292. UINTN NumFats;
  293. UINTN RootEntries; // < FAT32, root dir is fixed size
  294. UINTN RootCluster; // >= FAT32, root cluster chain head
  295. //
  296. // info for marking the volume dirty or not
  297. //
  298. BOOLEAN FatDirty; // If fat-entries have been updated
  299. UINT32 DirtyValue;
  300. UINT32 NotDirtyValue;
  301. //
  302. // The root directory entry and opened root file
  303. //
  304. FAT_DIRENT RootDirEnt;
  305. //
  306. // File Name of root OFile, it is empty string
  307. //
  308. CHAR16 RootFileString[1];
  309. FAT_OFILE *Root;
  310. //
  311. // New OFiles are added to this list so they
  312. // can be cleaned up if they aren't referenced.
  313. //
  314. LIST_ENTRY CheckRef;
  315. //
  316. // Directory cache List
  317. //
  318. LIST_ENTRY DirCacheList;
  319. UINTN DirCacheCount;
  320. //
  321. // Disk Cache for this volume
  322. //
  323. VOID *CacheBuffer;
  324. DISK_CACHE DiskCache[CacheMaxType];
  325. };
  326. //
  327. // Function Prototypes
  328. //
  329. /**
  330. Implements Open() of Simple File System Protocol.
  331. @param FHand - File handle of the file serves as a starting reference point.
  332. @param NewHandle - Handle of the file that is newly opened.
  333. @param FileName - File name relative to FHand.
  334. @param OpenMode - Open mode.
  335. @param Attributes - Attributes to set if the file is created.
  336. @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
  337. The OpenMode is not supported.
  338. The Attributes is not the valid attributes.
  339. @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
  340. @retval EFI_SUCCESS - Open the file successfully.
  341. @return Others - The status of open file.
  342. **/
  343. EFI_STATUS
  344. EFIAPI
  345. FatOpen (
  346. IN EFI_FILE_PROTOCOL *FHand,
  347. OUT EFI_FILE_PROTOCOL **NewHandle,
  348. IN CHAR16 *FileName,
  349. IN UINT64 OpenMode,
  350. IN UINT64 Attributes
  351. )
  352. ;
  353. /**
  354. Implements OpenEx() of Simple File System Protocol.
  355. @param FHand - File handle of the file serves as a starting reference point.
  356. @param NewHandle - Handle of the file that is newly opened.
  357. @param FileName - File name relative to FHand.
  358. @param OpenMode - Open mode.
  359. @param Attributes - Attributes to set if the file is created.
  360. @param Token - A pointer to the token associated with the transaction.
  361. @retval EFI_INVALID_PARAMETER - The FileName is NULL or the file string is empty.
  362. The OpenMode is not supported.
  363. The Attributes is not the valid attributes.
  364. @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for file string.
  365. @retval EFI_SUCCESS - Open the file successfully.
  366. @return Others - The status of open file.
  367. **/
  368. EFI_STATUS
  369. EFIAPI
  370. FatOpenEx (
  371. IN EFI_FILE_PROTOCOL *FHand,
  372. OUT EFI_FILE_PROTOCOL **NewHandle,
  373. IN CHAR16 *FileName,
  374. IN UINT64 OpenMode,
  375. IN UINT64 Attributes,
  376. IN OUT EFI_FILE_IO_TOKEN *Token
  377. )
  378. ;
  379. /**
  380. Get the file's position of the file
  381. @param FHand - The handle of file.
  382. @param Position - The file's position of the file.
  383. @retval EFI_SUCCESS - Get the info successfully.
  384. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
  385. @retval EFI_UNSUPPORTED - The open file is not a file.
  386. **/
  387. EFI_STATUS
  388. EFIAPI
  389. FatGetPosition (
  390. IN EFI_FILE_PROTOCOL *FHand,
  391. OUT UINT64 *Position
  392. )
  393. ;
  394. /**
  395. Get the some types info of the file into Buffer
  396. @param FHand - The handle of file.
  397. @param Type - The type of the info.
  398. @param BufferSize - Size of Buffer.
  399. @param Buffer - Buffer containing volume info.
  400. @retval EFI_SUCCESS - Get the info successfully.
  401. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
  402. **/
  403. EFI_STATUS
  404. EFIAPI
  405. FatGetInfo (
  406. IN EFI_FILE_PROTOCOL *FHand,
  407. IN EFI_GUID *Type,
  408. IN OUT UINTN *BufferSize,
  409. OUT VOID *Buffer
  410. )
  411. ;
  412. /**
  413. Set the some types info of the file into Buffer.
  414. @param FHand - The handle of file.
  415. @param Type - The type of the info.
  416. @param BufferSize - Size of Buffer.
  417. @param Buffer - Buffer containing volume info.
  418. @retval EFI_SUCCESS - Set the info successfully.
  419. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
  420. **/
  421. EFI_STATUS
  422. EFIAPI
  423. FatSetInfo (
  424. IN EFI_FILE_PROTOCOL *FHand,
  425. IN EFI_GUID *Type,
  426. IN UINTN BufferSize,
  427. IN VOID *Buffer
  428. )
  429. ;
  430. /**
  431. Flushes all data associated with the file handle.
  432. @param FHand - Handle to file to flush
  433. @retval EFI_SUCCESS - Flushed the file successfully
  434. @retval EFI_WRITE_PROTECTED - The volume is read only
  435. @retval EFI_ACCESS_DENIED - The volume is not read only
  436. but the file is read only
  437. @return Others - Flushing of the file is failed
  438. **/
  439. EFI_STATUS
  440. EFIAPI
  441. FatFlush (
  442. IN EFI_FILE_PROTOCOL *FHand
  443. )
  444. ;
  445. /**
  446. Flushes all data associated with the file handle.
  447. @param FHand - Handle to file to flush.
  448. @param Token - A pointer to the token associated with the transaction.
  449. @retval EFI_SUCCESS - Flushed the file successfully.
  450. @retval EFI_WRITE_PROTECTED - The volume is read only.
  451. @retval EFI_ACCESS_DENIED - The file is read only.
  452. @return Others - Flushing of the file failed.
  453. **/
  454. EFI_STATUS
  455. EFIAPI
  456. FatFlushEx (
  457. IN EFI_FILE_PROTOCOL *FHand,
  458. IN EFI_FILE_IO_TOKEN *Token
  459. )
  460. ;
  461. /**
  462. Flushes & Closes the file handle.
  463. @param FHand - Handle to the file to delete.
  464. @retval EFI_SUCCESS - Closed the file successfully.
  465. **/
  466. EFI_STATUS
  467. EFIAPI
  468. FatClose (
  469. IN EFI_FILE_PROTOCOL *FHand
  470. )
  471. ;
  472. /**
  473. Deletes the file & Closes the file handle.
  474. @param FHand - Handle to the file to delete.
  475. @retval EFI_SUCCESS - Delete the file successfully.
  476. @retval EFI_WARN_DELETE_FAILURE - Fail to delete the file.
  477. **/
  478. EFI_STATUS
  479. EFIAPI
  480. FatDelete (
  481. IN EFI_FILE_PROTOCOL *FHand
  482. )
  483. ;
  484. /**
  485. Set the file's position of the file.
  486. @param FHand - The handle of file
  487. @param Position - The file's position of the file
  488. @retval EFI_SUCCESS - Set the info successfully
  489. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file
  490. @retval EFI_UNSUPPORTED - Set a directory with a not-zero position
  491. **/
  492. EFI_STATUS
  493. EFIAPI
  494. FatSetPosition (
  495. IN EFI_FILE_PROTOCOL *FHand,
  496. IN UINT64 Position
  497. )
  498. ;
  499. /**
  500. Get the file info.
  501. @param FHand - The handle of the file.
  502. @param BufferSize - Size of Buffer.
  503. @param Buffer - Buffer containing read data.
  504. @retval EFI_SUCCESS - Get the file info successfully.
  505. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
  506. @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
  507. @return other - An error occurred when operation the disk.
  508. **/
  509. EFI_STATUS
  510. EFIAPI
  511. FatRead (
  512. IN EFI_FILE_PROTOCOL *FHand,
  513. IN OUT UINTN *BufferSize,
  514. OUT VOID *Buffer
  515. )
  516. ;
  517. /**
  518. Get the file info.
  519. @param FHand - The handle of the file.
  520. @param Token - A pointer to the token associated with the transaction.
  521. @retval EFI_SUCCESS - Get the file info successfully.
  522. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
  523. @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
  524. @return other - An error occurred when operation the disk.
  525. **/
  526. EFI_STATUS
  527. EFIAPI
  528. FatReadEx (
  529. IN EFI_FILE_PROTOCOL *FHand,
  530. IN OUT EFI_FILE_IO_TOKEN *Token
  531. )
  532. ;
  533. /**
  534. Set the file info.
  535. @param FHand - The handle of the file.
  536. @param BufferSize - Size of Buffer.
  537. @param Buffer - Buffer containing write data.
  538. @retval EFI_SUCCESS - Set the file info successfully.
  539. @retval EFI_WRITE_PROTECTED - The disk is write protected.
  540. @retval EFI_ACCESS_DENIED - The file is read-only.
  541. @retval EFI_DEVICE_ERROR - The OFile is not valid.
  542. @retval EFI_UNSUPPORTED - The open file is not a file.
  543. - The writing file size is larger than 4GB.
  544. @return other - An error occurred when operation the disk.
  545. **/
  546. EFI_STATUS
  547. EFIAPI
  548. FatWrite (
  549. IN EFI_FILE_PROTOCOL *FHand,
  550. IN OUT UINTN *BufferSize,
  551. IN VOID *Buffer
  552. )
  553. ;
  554. /**
  555. Get the file info.
  556. @param FHand - The handle of the file.
  557. @param Token - A pointer to the token associated with the transaction.
  558. @retval EFI_SUCCESS - Get the file info successfully.
  559. @retval EFI_DEVICE_ERROR - Can not find the OFile for the file.
  560. @retval EFI_VOLUME_CORRUPTED - The file type of open file is error.
  561. @return other - An error occurred when operation the disk.
  562. **/
  563. EFI_STATUS
  564. EFIAPI
  565. FatWriteEx (
  566. IN EFI_FILE_PROTOCOL *FHand,
  567. IN OUT EFI_FILE_IO_TOKEN *Token
  568. )
  569. ;
  570. //
  571. // DiskCache.c
  572. //
  573. /**
  574. Initialize the disk cache according to Volume's FatType.
  575. @param Volume - FAT file system volume.
  576. @retval EFI_SUCCESS - The disk cache is successfully initialized.
  577. @retval EFI_OUT_OF_RESOURCES - Not enough memory to allocate disk cache.
  578. **/
  579. EFI_STATUS
  580. FatInitializeDiskCache (
  581. IN FAT_VOLUME *Volume
  582. );
  583. /**
  584. Read BufferSize bytes from the position of Offset into Buffer,
  585. or write BufferSize bytes from Buffer into the position of Offset.
  586. Base on the parameter of CACHE_DATA_TYPE, the data access will be divided into
  587. the access of FAT cache (CACHE_FAT) and the access of Data cache (CACHE_DATA):
  588. 1. Access of FAT cache (CACHE_FAT): Access the data in the FAT cache, if there is cache
  589. page hit, just return the cache page; else update the related cache page and return
  590. the right cache page.
  591. 2. Access of Data cache (CACHE_DATA):
  592. The access data will be divided into UnderRun data, Aligned data and OverRun data;
  593. The UnderRun data and OverRun data will be accessed by the Data cache,
  594. but the Aligned data will be accessed with disk directly.
  595. @param Volume - FAT file system volume.
  596. @param CacheDataType - The type of cache: CACHE_DATA or CACHE_FAT.
  597. @param IoMode - Indicate the type of disk access.
  598. @param Offset - The starting byte offset to read from.
  599. @param BufferSize - Size of Buffer.
  600. @param Buffer - Buffer containing cache data.
  601. @param Task point to task instance.
  602. @retval EFI_SUCCESS - The data was accessed correctly.
  603. @retval EFI_MEDIA_CHANGED - The MediaId does not match the current device.
  604. @return Others - An error occurred when accessing cache.
  605. **/
  606. EFI_STATUS
  607. FatAccessCache (
  608. IN FAT_VOLUME *Volume,
  609. IN CACHE_DATA_TYPE CacheDataType,
  610. IN IO_MODE IoMode,
  611. IN UINT64 Offset,
  612. IN UINTN BufferSize,
  613. IN OUT UINT8 *Buffer,
  614. IN FAT_TASK *Task
  615. );
  616. /**
  617. Flush all the dirty cache back, include the FAT cache and the Data cache.
  618. @param Volume - FAT file system volume.
  619. @param Task point to task instance.
  620. @retval EFI_SUCCESS - Flush all the dirty cache back successfully
  621. @return other - An error occurred when writing the data into the disk
  622. **/
  623. EFI_STATUS
  624. FatVolumeFlushCache (
  625. IN FAT_VOLUME *Volume,
  626. IN FAT_TASK *Task
  627. );
  628. //
  629. // Flush.c
  630. //
  631. /**
  632. Flush the data associated with an open file.
  633. In this implementation, only last Mod/Access time is updated.
  634. @param OFile - The open file.
  635. @retval EFI_SUCCESS - The OFile is flushed successfully.
  636. @return Others - An error occurred when flushing this OFile.
  637. **/
  638. EFI_STATUS
  639. FatOFileFlush (
  640. IN FAT_OFILE *OFile
  641. );
  642. /**
  643. Check the references of the OFile.
  644. If the OFile (that is checked) is no longer
  645. referenced, then it is freed.
  646. @param OFile - The OFile to be checked.
  647. @retval TRUE - The OFile is not referenced and freed.
  648. @retval FALSE - The OFile is kept.
  649. **/
  650. BOOLEAN
  651. FatCheckOFileRef (
  652. IN FAT_OFILE *OFile
  653. );
  654. /**
  655. Set the OFile and its child OFile with the error Status
  656. @param OFile - The OFile whose permanent error code is to be set.
  657. @param Status - Error code to be set.
  658. **/
  659. VOID
  660. FatSetVolumeError (
  661. IN FAT_OFILE *OFile,
  662. IN EFI_STATUS Status
  663. );
  664. /**
  665. Close the open file instance.
  666. @param IFile - Open file instance.
  667. @retval EFI_SUCCESS - Closed the file successfully.
  668. **/
  669. EFI_STATUS
  670. FatIFileClose (
  671. FAT_IFILE *IFile
  672. );
  673. /**
  674. Set error status for a specific OFile, reference checking the volume.
  675. If volume is already marked as invalid, and all resources are freed
  676. after reference checking, the file system protocol is uninstalled and
  677. the volume structure is freed.
  678. @param Volume - the Volume that is to be reference checked and unlocked.
  679. @param OFile - the OFile whose permanent error code is to be set.
  680. @param EfiStatus - error code to be set.
  681. @param Task point to task instance.
  682. @retval EFI_SUCCESS - Clean up the volume successfully.
  683. @return Others - Cleaning up of the volume is failed.
  684. **/
  685. EFI_STATUS
  686. FatCleanupVolume (
  687. IN FAT_VOLUME *Volume,
  688. IN FAT_OFILE *OFile,
  689. IN EFI_STATUS EfiStatus,
  690. IN FAT_TASK *Task
  691. );
  692. //
  693. // FileSpace.c
  694. //
  695. /**
  696. Shrink the end of the open file base on the file size.
  697. @param OFile - The open file.
  698. @retval EFI_SUCCESS - Shrinked sucessfully.
  699. @retval EFI_VOLUME_CORRUPTED - There are errors in the file's clusters.
  700. **/
  701. EFI_STATUS
  702. FatShrinkEof (
  703. IN FAT_OFILE *OFile
  704. );
  705. /**
  706. Grow the end of the open file base on the NewSizeInBytes.
  707. @param OFile - The open file.
  708. @param NewSizeInBytes - The new size in bytes of the open file.
  709. @retval EFI_SUCCESS - The file is grown sucessfully.
  710. @retval EFI_UNSUPPORTED - The file size is larger than 4GB.
  711. @retval EFI_VOLUME_CORRUPTED - There are errors in the files' clusters.
  712. @retval EFI_VOLUME_FULL - The volume is full and can not grow the file.
  713. **/
  714. EFI_STATUS
  715. FatGrowEof (
  716. IN FAT_OFILE *OFile,
  717. IN UINT64 NewSizeInBytes
  718. );
  719. /**
  720. Get the size of directory of the open file.
  721. @param Volume - The File System Volume.
  722. @param Cluster - The Starting cluster.
  723. @return The physical size of the file starting at the input cluster, if there is error in the
  724. cluster chain, the return value is 0.
  725. **/
  726. UINTN
  727. FatPhysicalDirSize (
  728. IN FAT_VOLUME *Volume,
  729. IN UINTN Cluster
  730. );
  731. /**
  732. Get the physical size of a file on the disk.
  733. @param Volume - The file system volume.
  734. @param RealSize - The real size of a file.
  735. @return The physical size of a file on the disk.
  736. **/
  737. UINT64
  738. FatPhysicalFileSize (
  739. IN FAT_VOLUME *Volume,
  740. IN UINTN RealSize
  741. );
  742. /**
  743. Seek OFile to requested position, and calculate the number of
  744. consecutive clusters from the position in the file
  745. @param OFile - The open file.
  746. @param Position - The file's position which will be accessed.
  747. @param PosLimit - The maximum length current reading/writing may access
  748. @retval EFI_SUCCESS - Set the info successfully.
  749. @retval EFI_VOLUME_CORRUPTED - Cluster chain corrupt.
  750. **/
  751. EFI_STATUS
  752. FatOFilePosition (
  753. IN FAT_OFILE *OFile,
  754. IN UINTN Position,
  755. IN UINTN PosLimit
  756. );
  757. /**
  758. Update the free cluster info of FatInfoSector of the volume.
  759. @param Volume - FAT file system volume.
  760. **/
  761. VOID
  762. FatComputeFreeInfo (
  763. IN FAT_VOLUME *Volume
  764. );
  765. //
  766. // Init.c
  767. //
  768. /**
  769. Allocates volume structure, detects FAT file system, installs protocol,
  770. and initialize cache.
  771. @param Handle - The handle of parent device.
  772. @param DiskIo - The DiskIo of parent device.
  773. @param DiskIo2 - The DiskIo2 of parent device.
  774. @param BlockIo - The BlockIo of parent devicel
  775. @retval EFI_SUCCESS - Allocate a new volume successfully.
  776. @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
  777. @return Others - Allocating a new volume failed.
  778. **/
  779. EFI_STATUS
  780. FatAllocateVolume (
  781. IN EFI_HANDLE Handle,
  782. IN EFI_DISK_IO_PROTOCOL *DiskIo,
  783. IN EFI_DISK_IO2_PROTOCOL *DiskIo2,
  784. IN EFI_BLOCK_IO_PROTOCOL *BlockIo
  785. );
  786. /**
  787. Detects FAT file system on Disk and set relevant fields of Volume.
  788. @param Volume - The volume structure.
  789. @retval EFI_SUCCESS - The Fat File System is detected successfully
  790. @retval EFI_UNSUPPORTED - The volume is not FAT file system.
  791. @retval EFI_VOLUME_CORRUPTED - The volume is corrupted.
  792. **/
  793. EFI_STATUS
  794. FatOpenDevice (
  795. IN OUT FAT_VOLUME *Volume
  796. );
  797. /**
  798. Called by FatDriverBindingStop(), Abandon the volume.
  799. @param Volume - The volume to be abandoned.
  800. @retval EFI_SUCCESS - Abandoned the volume successfully.
  801. @return Others - Can not uninstall the protocol interfaces.
  802. **/
  803. EFI_STATUS
  804. FatAbandonVolume (
  805. IN FAT_VOLUME *Volume
  806. );
  807. //
  808. // Misc.c
  809. //
  810. /**
  811. Create the task
  812. @param IFile - The instance of the open file.
  813. @param Token - A pointer to the token associated with the transaction.
  814. @return FAT_TASK * - Return the task instance.
  815. **/
  816. FAT_TASK *
  817. FatCreateTask (
  818. FAT_IFILE *IFile,
  819. EFI_FILE_IO_TOKEN *Token
  820. );
  821. /**
  822. Destroy the task.
  823. @param Task - The task to be destroyed.
  824. **/
  825. VOID
  826. FatDestroyTask (
  827. FAT_TASK *Task
  828. );
  829. /**
  830. Wait all non-blocking requests complete.
  831. @param IFile - The instance of the open file.
  832. **/
  833. VOID
  834. FatWaitNonblockingTask (
  835. FAT_IFILE *IFile
  836. );
  837. /**
  838. Remove the subtask from subtask list.
  839. @param Subtask - The subtask to be removed.
  840. @return LIST_ENTRY * - The next node in the list.
  841. **/
  842. LIST_ENTRY *
  843. FatDestroySubtask (
  844. FAT_SUBTASK *Subtask
  845. );
  846. /**
  847. Execute the task.
  848. @param IFile - The instance of the open file.
  849. @param Task - The task to be executed.
  850. @retval EFI_SUCCESS - The task was executed sucessfully.
  851. @return other - An error occurred when executing the task.
  852. **/
  853. EFI_STATUS
  854. FatQueueTask (
  855. IN FAT_IFILE *IFile,
  856. IN FAT_TASK *Task
  857. );
  858. /**
  859. Set the volume as dirty or not.
  860. @param Volume - FAT file system volume.
  861. @param IoMode - The access mode.
  862. @param DirtyValue - Set the volume as dirty or not.
  863. @retval EFI_SUCCESS - Set the new FAT entry value sucessfully.
  864. @return other - An error occurred when operation the FAT entries.
  865. **/
  866. EFI_STATUS
  867. FatAccessVolumeDirty (
  868. IN FAT_VOLUME *Volume,
  869. IN IO_MODE IoMode,
  870. IN VOID *DirtyValue
  871. );
  872. /**
  873. General disk access function.
  874. @param Volume - FAT file system volume.
  875. @param IoMode - The access mode (disk read/write or cache access).
  876. @param Offset - The starting byte offset to read from.
  877. @param BufferSize - Size of Buffer.
  878. @param Buffer - Buffer containing read data.
  879. @param Task point to task instance.
  880. @retval EFI_SUCCESS - The operation is performed successfully.
  881. @retval EFI_VOLUME_CORRUPTED - The accesss is
  882. @return Others - The status of read/write the disk
  883. **/
  884. EFI_STATUS
  885. FatDiskIo (
  886. IN FAT_VOLUME *Volume,
  887. IN IO_MODE IoMode,
  888. IN UINT64 Offset,
  889. IN UINTN BufferSize,
  890. IN OUT VOID *Buffer,
  891. IN FAT_TASK *Task
  892. );
  893. /**
  894. Lock the volume.
  895. **/
  896. VOID
  897. FatAcquireLock (
  898. VOID
  899. );
  900. /**
  901. Unlock the volume.
  902. **/
  903. VOID
  904. FatReleaseLock (
  905. VOID
  906. );
  907. /**
  908. Lock the volume.
  909. If the lock is already in the acquired state, then EFI_ACCESS_DENIED is returned.
  910. Otherwise, EFI_SUCCESS is returned.
  911. @retval EFI_SUCCESS - The volume is locked.
  912. @retval EFI_ACCESS_DENIED - The volume could not be locked because it is already locked.
  913. **/
  914. EFI_STATUS
  915. FatAcquireLockOrFail (
  916. VOID
  917. );
  918. /**
  919. Free directory entry.
  920. @param DirEnt - The directory entry to be freed.
  921. **/
  922. VOID
  923. FatFreeDirEnt (
  924. IN FAT_DIRENT *DirEnt
  925. );
  926. /**
  927. Free volume structure (including the contents of directory cache and disk cache).
  928. @param Volume - The volume structure to be freed.
  929. **/
  930. VOID
  931. FatFreeVolume (
  932. IN FAT_VOLUME *Volume
  933. );
  934. /**
  935. Translate EFI time to FAT time.
  936. @param ETime - The time of EFI_TIME.
  937. @param FTime - The time of FAT_DATE_TIME.
  938. **/
  939. VOID
  940. FatEfiTimeToFatTime (
  941. IN EFI_TIME *ETime,
  942. OUT FAT_DATE_TIME *FTime
  943. );
  944. /**
  945. Translate Fat time to EFI time.
  946. @param FTime - The time of FAT_DATE_TIME.
  947. @param ETime - The time of EFI_TIME..
  948. **/
  949. VOID
  950. FatFatTimeToEfiTime (
  951. IN FAT_DATE_TIME *FTime,
  952. OUT EFI_TIME *ETime
  953. );
  954. /**
  955. Get Current FAT time.
  956. @param FatTime - Current FAT time.
  957. **/
  958. VOID
  959. FatGetCurrentFatTime (
  960. OUT FAT_DATE_TIME *FatTime
  961. );
  962. /**
  963. Check whether a time is valid.
  964. @param Time - The time of EFI_TIME.
  965. @retval TRUE - The time is valid.
  966. @retval FALSE - The time is not valid.
  967. **/
  968. BOOLEAN
  969. FatIsValidTime (
  970. IN EFI_TIME *Time
  971. );
  972. //
  973. // UnicodeCollation.c
  974. //
  975. /**
  976. Initialize Unicode Collation support.
  977. It tries to locate Unicode Collation 2 protocol and matches it with current
  978. platform language code. If for any reason the first attempt fails, it then tries to
  979. use Unicode Collation Protocol.
  980. @param AgentHandle The handle used to open Unicode Collation (2) protocol.
  981. @retval EFI_SUCCESS The Unicode Collation (2) protocol has been successfully located.
  982. @retval Others The Unicode Collation (2) protocol has not been located.
  983. **/
  984. EFI_STATUS
  985. InitializeUnicodeCollationSupport (
  986. IN EFI_HANDLE AgentHandle
  987. );
  988. /**
  989. Convert FAT string to unicode string.
  990. @param FatSize The size of FAT string.
  991. @param Fat The FAT string.
  992. @param String The unicode string.
  993. @return None.
  994. **/
  995. VOID
  996. FatFatToStr (
  997. IN UINTN FatSize,
  998. IN CHAR8 *Fat,
  999. OUT CHAR16 *String
  1000. );
  1001. /**
  1002. Convert unicode string to Fat string.
  1003. @param String The unicode string.
  1004. @param FatSize The size of the FAT string.
  1005. @param Fat The FAT string.
  1006. @retval TRUE Convert successfully.
  1007. @retval FALSE Convert error.
  1008. **/
  1009. BOOLEAN
  1010. FatStrToFat (
  1011. IN CHAR16 *String,
  1012. IN UINTN FatSize,
  1013. OUT CHAR8 *Fat
  1014. );
  1015. /**
  1016. Lowercase a string
  1017. @param Str The string which will be lower-cased.
  1018. **/
  1019. VOID
  1020. FatStrLwr (
  1021. IN CHAR16 *Str
  1022. );
  1023. /**
  1024. Uppercase a string.
  1025. @param Str The string which will be upper-cased.
  1026. **/
  1027. VOID
  1028. FatStrUpr (
  1029. IN CHAR16 *Str
  1030. );
  1031. /**
  1032. Performs a case-insensitive comparison of two Null-terminated Unicode strings.
  1033. @param Str1 A pointer to a Null-terminated Unicode string.
  1034. @param Str2 A pointer to a Null-terminated Unicode string.
  1035. @retval 0 S1 is equivalent to S2.
  1036. @retval >0 S1 is lexically greater than S2.
  1037. @retval <0 S1 is lexically less than S2.
  1038. **/
  1039. INTN
  1040. FatStriCmp (
  1041. IN CHAR16 *Str1,
  1042. IN CHAR16 *Str2
  1043. );
  1044. //
  1045. // Open.c
  1046. //
  1047. /**
  1048. Open a file for a file name relative to an existing OFile.
  1049. The IFile of the newly opened file is passed out.
  1050. @param OFile - The file that serves as a starting reference point.
  1051. @param NewIFile - The newly generated IFile instance.
  1052. @param FileName - The file name relative to the OFile.
  1053. @param OpenMode - Open mode.
  1054. @param Attributes - Attributes to set if the file is created.
  1055. @retval EFI_SUCCESS - Open the file successfully.
  1056. @retval EFI_INVALID_PARAMETER - The open mode is conflict with the attributes
  1057. or the file name is not valid.
  1058. @retval EFI_NOT_FOUND - Conficts between dir intention and attribute.
  1059. @retval EFI_WRITE_PROTECTED - Can't open for write if the volume is read only.
  1060. @retval EFI_ACCESS_DENIED - If the file's attribute is read only, and the
  1061. open is for read-write fail it.
  1062. @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
  1063. **/
  1064. EFI_STATUS
  1065. FatOFileOpen (
  1066. IN FAT_OFILE *OFile,
  1067. OUT FAT_IFILE **NewIFile,
  1068. IN CHAR16 *FileName,
  1069. IN UINT64 OpenMode,
  1070. IN UINT8 Attributes
  1071. );
  1072. /**
  1073. Create an Open instance for the existing OFile.
  1074. The IFile of the newly opened file is passed out.
  1075. @param OFile - The file that serves as a starting reference point.
  1076. @param PtrIFile - The newly generated IFile instance.
  1077. @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory for the IFile
  1078. @retval EFI_SUCCESS - Create the new IFile for the OFile successfully
  1079. **/
  1080. EFI_STATUS
  1081. FatAllocateIFile (
  1082. IN FAT_OFILE *OFile,
  1083. OUT FAT_IFILE **PtrIFile
  1084. );
  1085. //
  1086. // OpenVolume.c
  1087. //
  1088. /**
  1089. Implements Simple File System Protocol interface function OpenVolume().
  1090. @param This - Calling context.
  1091. @param File - the Root Directory of the volume.
  1092. @retval EFI_OUT_OF_RESOURCES - Can not allocate the memory.
  1093. @retval EFI_VOLUME_CORRUPTED - The FAT type is error.
  1094. @retval EFI_SUCCESS - Open the volume successfully.
  1095. **/
  1096. EFI_STATUS
  1097. EFIAPI
  1098. FatOpenVolume (
  1099. IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
  1100. OUT EFI_FILE_PROTOCOL **File
  1101. );
  1102. //
  1103. // ReadWrite.c
  1104. //
  1105. /**
  1106. This function reads data from a file or writes data to a file.
  1107. It uses OFile->PosRem to determine how much data can be accessed in one time.
  1108. @param OFile - The open file.
  1109. @param IoMode - Indicate whether the access mode is reading or writing.
  1110. @param Position - The position where data will be accessed.
  1111. @param DataBufferSize - Size of Buffer.
  1112. @param UserBuffer - Buffer containing data.
  1113. @param Task point to task instance.
  1114. @retval EFI_SUCCESS - Access the data successfully.
  1115. @return other - An error occurred when operating on the disk.
  1116. **/
  1117. EFI_STATUS
  1118. FatAccessOFile (
  1119. IN FAT_OFILE *OFile,
  1120. IN IO_MODE IoMode,
  1121. IN UINTN Position,
  1122. IN UINTN *DataBufferSize,
  1123. IN UINT8 *UserBuffer,
  1124. IN FAT_TASK *Task
  1125. );
  1126. /**
  1127. Expand OFile by appending zero bytes at the end of OFile.
  1128. @param OFile - The open file.
  1129. @param ExpandedSize - The number of zero bytes appended at the end of the file.
  1130. @retval EFI_SUCCESS - The file is expanded successfully.
  1131. @return other - An error occurred when expanding file.
  1132. **/
  1133. EFI_STATUS
  1134. FatExpandOFile (
  1135. IN FAT_OFILE *OFile,
  1136. IN UINT64 ExpandedSize
  1137. );
  1138. /**
  1139. Write zero pool from the WritePos to the end of OFile.
  1140. @param OFile - The open file to write zero pool.
  1141. @param WritePos - The number of zero bytes written.
  1142. @retval EFI_SUCCESS - Write the zero pool successfully.
  1143. @retval EFI_OUT_OF_RESOURCES - Not enough memory to perform the operation.
  1144. @return other - An error occurred when writing disk.
  1145. **/
  1146. EFI_STATUS
  1147. FatWriteZeroPool (
  1148. IN FAT_OFILE *OFile,
  1149. IN UINTN WritePos
  1150. );
  1151. /**
  1152. Truncate the OFile to smaller file size.
  1153. @param OFile - The open file.
  1154. @param TruncatedSize - The new file size.
  1155. @retval EFI_SUCCESS - The file is truncated successfully.
  1156. @return other - An error occurred when truncating file.
  1157. **/
  1158. EFI_STATUS
  1159. FatTruncateOFile (
  1160. IN FAT_OFILE *OFile,
  1161. IN UINTN TruncatedSize
  1162. );
  1163. //
  1164. // DirectoryManage.c
  1165. //
  1166. /**
  1167. Set the OFile's current directory cursor to the list head.
  1168. @param OFile - The directory OFile whose directory cursor is reset.
  1169. **/
  1170. VOID
  1171. FatResetODirCursor (
  1172. IN FAT_OFILE *OFile
  1173. );
  1174. /**
  1175. Set the directory's cursor to the next and get the next directory entry.
  1176. @param OFile - The parent OFile.
  1177. @param PtrDirEnt - The next directory entry.
  1178. @retval EFI_SUCCESS - We get the next directory entry successfully.
  1179. @return other - An error occurred when get next directory entry.
  1180. **/
  1181. EFI_STATUS
  1182. FatGetNextDirEnt (
  1183. IN FAT_OFILE *OFile,
  1184. OUT FAT_DIRENT **PtrDirEnt
  1185. );
  1186. /**
  1187. Remove this directory entry node from the list of directory entries and hash table.
  1188. @param OFile - The parent OFile.
  1189. @param DirEnt - The directory entry to be removed.
  1190. @retval EFI_SUCCESS - The directory entry is successfully removed.
  1191. @return other - An error occurred when removing the directory entry.
  1192. **/
  1193. EFI_STATUS
  1194. FatRemoveDirEnt (
  1195. IN FAT_OFILE *OFile,
  1196. IN FAT_DIRENT *DirEnt
  1197. );
  1198. /**
  1199. Save the directory entry to disk.
  1200. @param OFile - The parent OFile which needs to update.
  1201. @param DirEnt - The directory entry to be saved.
  1202. @retval EFI_SUCCESS - Store the directory entry successfully.
  1203. @return other - An error occurred when writing the directory entry.
  1204. **/
  1205. EFI_STATUS
  1206. FatStoreDirEnt (
  1207. IN FAT_OFILE *OFile,
  1208. IN FAT_DIRENT *DirEnt
  1209. );
  1210. /**
  1211. Create a directory entry in the parent OFile.
  1212. @param OFile - The parent OFile.
  1213. @param FileName - The filename of the newly-created directory entry.
  1214. @param Attributes - The attribute of the newly-created directory entry.
  1215. @param PtrDirEnt - The pointer to the newly-created directory entry.
  1216. @retval EFI_SUCCESS - The directory entry is successfully created.
  1217. @retval EFI_OUT_OF_RESOURCES - Not enough memory to create the directory entry.
  1218. @return other - An error occurred when creating the directory entry.
  1219. **/
  1220. EFI_STATUS
  1221. FatCreateDirEnt (
  1222. IN FAT_OFILE *OFile,
  1223. IN CHAR16 *FileName,
  1224. IN UINT8 Attributes,
  1225. OUT FAT_DIRENT **PtrDirEnt
  1226. );
  1227. /**
  1228. Determine whether the directory entry is "." or ".." entry.
  1229. @param DirEnt - The corresponding directory entry.
  1230. @retval TRUE - The directory entry is "." or ".." directory entry
  1231. @retval FALSE - The directory entry is not "." or ".." directory entry
  1232. **/
  1233. BOOLEAN
  1234. FatIsDotDirEnt (
  1235. IN FAT_DIRENT *DirEnt
  1236. );
  1237. /**
  1238. Set the OFile's cluster and size info in its directory entry.
  1239. @param OFile - The corresponding OFile.
  1240. **/
  1241. VOID
  1242. FatUpdateDirEntClusterSizeInfo (
  1243. IN FAT_OFILE *OFile
  1244. );
  1245. /**
  1246. Copy all the information of DirEnt2 to DirEnt1 except for 8.3 name.
  1247. @param DirEnt1 - The destination directory entry.
  1248. @param DirEnt2 - The source directory entry.
  1249. **/
  1250. VOID
  1251. FatCloneDirEnt (
  1252. IN FAT_DIRENT *DirEnt1,
  1253. IN FAT_DIRENT *DirEnt2
  1254. );
  1255. /**
  1256. Get the directory entry's info into Buffer.
  1257. @param Volume - FAT file system volume.
  1258. @param DirEnt - The corresponding directory entry.
  1259. @param BufferSize - Size of Buffer.
  1260. @param Buffer - Buffer containing file info.
  1261. @retval EFI_SUCCESS - Get the file info successfully.
  1262. @retval EFI_BUFFER_TOO_SMALL - The buffer is too small.
  1263. **/
  1264. EFI_STATUS
  1265. FatGetDirEntInfo (
  1266. IN FAT_VOLUME *Volume,
  1267. IN FAT_DIRENT *DirEnt,
  1268. IN OUT UINTN *BufferSize,
  1269. OUT VOID *Buffer
  1270. );
  1271. /**
  1272. Open the directory entry to get the OFile.
  1273. @param Parent - The parent OFile.
  1274. @param DirEnt - The directory entry to be opened.
  1275. @retval EFI_SUCCESS - The directory entry is successfully opened.
  1276. @retval EFI_OUT_OF_RESOURCES - not enough memory to allocate a new OFile.
  1277. @return other - An error occurred when opening the directory entry.
  1278. **/
  1279. EFI_STATUS
  1280. FatOpenDirEnt (
  1281. IN FAT_OFILE *OFile,
  1282. IN FAT_DIRENT *DirEnt
  1283. );
  1284. /**
  1285. Create "." and ".." directory entries in the newly-created parent OFile.
  1286. @param OFile - The parent OFile.
  1287. @retval EFI_SUCCESS - The dot directory entries are successfully created.
  1288. @return other - An error occurred when creating the directory entry.
  1289. **/
  1290. EFI_STATUS
  1291. FatCreateDotDirEnts (
  1292. IN FAT_OFILE *OFile
  1293. );
  1294. /**
  1295. Close the directory entry and free the OFile.
  1296. @param DirEnt - The directory entry to be closed.
  1297. **/
  1298. VOID
  1299. FatCloseDirEnt (
  1300. IN FAT_DIRENT *DirEnt
  1301. );
  1302. /**
  1303. Traverse filename and open all OFiles that can be opened.
  1304. Update filename pointer to the component that can't be opened.
  1305. If more than one name component remains, returns an error;
  1306. otherwise, return the remaining name component so that the caller might choose to create it.
  1307. @param PtrOFile - As input, the reference OFile; as output, the located OFile.
  1308. @param FileName - The file name relevant to the OFile.
  1309. @param Attributes - The attribute of the destination OFile.
  1310. @param NewFileName - The remaining file name.
  1311. @retval EFI_NOT_FOUND - The file name can't be opened and there is more than one
  1312. components within the name left (this means the name can
  1313. not be created either).
  1314. @retval EFI_INVALID_PARAMETER - The parameter is not valid.
  1315. @retval EFI_SUCCESS - Open the file successfully.
  1316. @return other - An error occured when locating the OFile.
  1317. **/
  1318. EFI_STATUS
  1319. FatLocateOFile (
  1320. IN OUT FAT_OFILE **PtrOFile,
  1321. IN CHAR16 *FileName,
  1322. IN UINT8 Attributes,
  1323. OUT CHAR16 *NewFileName
  1324. );
  1325. /**
  1326. Get the directory entry for the volume.
  1327. @param Volume - FAT file system volume.
  1328. @param Name - The file name of the volume.
  1329. @retval EFI_SUCCESS - Update the volume with the directory entry sucessfully.
  1330. @return others - An error occurred when getting volume label.
  1331. **/
  1332. EFI_STATUS
  1333. FatGetVolumeEntry (
  1334. IN FAT_VOLUME *Volume,
  1335. IN CHAR16 *Name
  1336. );
  1337. /**
  1338. Set the relevant directory entry into disk for the volume.
  1339. @param Volume - FAT file system volume.
  1340. @param Name - The new file name of the volume.
  1341. @retval EFI_SUCCESS - Update the Volume sucessfully.
  1342. @retval EFI_UNSUPPORTED - The input label is not a valid volume label.
  1343. @return other - An error occurred when setting volume label.
  1344. **/
  1345. EFI_STATUS
  1346. FatSetVolumeEntry (
  1347. IN FAT_VOLUME *Volume,
  1348. IN CHAR16 *Name
  1349. );
  1350. //
  1351. // Hash.c
  1352. //
  1353. /**
  1354. Search the long name hash table for the directory entry.
  1355. @param ODir - The directory to be searched.
  1356. @param LongNameString - The long name string to search.
  1357. @return The previous long name hash node of the directory entry.
  1358. **/
  1359. FAT_DIRENT **
  1360. FatLongNameHashSearch (
  1361. IN FAT_ODIR *ODir,
  1362. IN CHAR16 *LongNameString
  1363. );
  1364. /**
  1365. Search the short name hash table for the directory entry.
  1366. @param ODir - The directory to be searched.
  1367. @param ShortNameString - The short name string to search.
  1368. @return The previous short name hash node of the directory entry.
  1369. **/
  1370. FAT_DIRENT **
  1371. FatShortNameHashSearch (
  1372. IN FAT_ODIR *ODir,
  1373. IN CHAR8 *ShortNameString
  1374. );
  1375. /**
  1376. Insert directory entry to hash table.
  1377. @param ODir - The parent directory.
  1378. @param DirEnt - The directory entry node.
  1379. **/
  1380. VOID
  1381. FatInsertToHashTable (
  1382. IN FAT_ODIR *ODir,
  1383. IN FAT_DIRENT *DirEnt
  1384. );
  1385. /**
  1386. Delete directory entry from hash table.
  1387. @param ODir - The parent directory.
  1388. @param DirEnt - The directory entry node.
  1389. **/
  1390. VOID
  1391. FatDeleteFromHashTable (
  1392. IN FAT_ODIR *ODir,
  1393. IN FAT_DIRENT *DirEnt
  1394. );
  1395. //
  1396. // FileName.c
  1397. //
  1398. /**
  1399. This function checks whether the input FileName is a valid 8.3 short name.
  1400. If the input FileName is a valid 8.3, the output is the 8.3 short name;
  1401. otherwise, the output is the base tag of 8.3 short name.
  1402. @param FileName - The input unicode filename.
  1403. @param File8Dot3Name - The output ascii 8.3 short name or base tag of 8.3 short name.
  1404. @retval TRUE - The input unicode filename is a valid 8.3 short name.
  1405. @retval FALSE - The input unicode filename is not a valid 8.3 short name.
  1406. **/
  1407. BOOLEAN
  1408. FatCheckIs8Dot3Name (
  1409. IN CHAR16 *FileName,
  1410. OUT CHAR8 *File8Dot3Name
  1411. );
  1412. /**
  1413. This function generates 8Dot3 name from user specified name for a newly created file.
  1414. @param Parent - The parent directory.
  1415. @param DirEnt - The directory entry whose 8Dot3Name needs to be generated.
  1416. **/
  1417. VOID
  1418. FatCreate8Dot3Name (
  1419. IN FAT_OFILE *Parent,
  1420. IN FAT_DIRENT *DirEnt
  1421. );
  1422. /**
  1423. Convert the ascii fat name to the unicode string and strip trailing spaces,
  1424. and if necessary, convert the unicode string to lower case.
  1425. @param FatName - The Char8 string needs to be converted.
  1426. @param Len - The length of the fat name.
  1427. @param LowerCase - Indicate whether to convert the string to lower case.
  1428. @param Str - The result of the convertion.
  1429. **/
  1430. VOID
  1431. FatNameToStr (
  1432. IN CHAR8 *FatName,
  1433. IN UINTN Len,
  1434. IN UINTN LowerCase,
  1435. IN CHAR16 *Str
  1436. );
  1437. /**
  1438. Set the caseflag value for the directory entry.
  1439. @param DirEnt - The logical directory entry whose caseflag value is to be set.
  1440. **/
  1441. VOID
  1442. FatSetCaseFlag (
  1443. IN FAT_DIRENT *DirEnt
  1444. );
  1445. /**
  1446. Convert the 8.3 ASCII fat name to cased Unicode string according to case flag.
  1447. @param DirEnt - The corresponding directory entry.
  1448. @param FileString - The output Unicode file name.
  1449. @param FileStringMax The max length of FileString.
  1450. **/
  1451. VOID
  1452. FatGetFileNameViaCaseFlag (
  1453. IN FAT_DIRENT *DirEnt,
  1454. IN OUT CHAR16 *FileString,
  1455. IN UINTN FileStringMax
  1456. );
  1457. /**
  1458. Get the Check sum for a short name.
  1459. @param ShortNameString - The short name for a file.
  1460. @retval Sum - UINT8 checksum.
  1461. **/
  1462. UINT8
  1463. FatCheckSum (
  1464. IN CHAR8 *ShortNameString
  1465. );
  1466. /**
  1467. Takes Path as input, returns the next name component
  1468. in Name, and returns the position after Name (e.g., the
  1469. start of the next name component)
  1470. @param Path - The path of one file.
  1471. @param Name - The next name component in Path.
  1472. The position after Name in the Path
  1473. **/
  1474. CHAR16*
  1475. FatGetNextNameComponent (
  1476. IN CHAR16 *Path,
  1477. OUT CHAR16 *Name
  1478. );
  1479. /**
  1480. Check whether the IFileName is valid long file name. If the IFileName is a valid
  1481. long file name, then we trim the possible leading blanks and leading/trailing dots.
  1482. the trimmed filename is stored in OutputFileName
  1483. @param InputFileName - The input file name.
  1484. @param OutputFileName - The output file name.
  1485. @retval TRUE - The InputFileName is a valid long file name.
  1486. @retval FALSE - The InputFileName is not a valid long file name.
  1487. **/
  1488. BOOLEAN
  1489. FatFileNameIsValid (
  1490. IN CHAR16 *InputFileName,
  1491. OUT CHAR16 *OutputFileName
  1492. );
  1493. //
  1494. // DirectoryCache.c
  1495. //
  1496. /**
  1497. Discard the directory structure when an OFile will be freed.
  1498. Volume will cache this directory if the OFile does not represent a deleted file.
  1499. @param OFile - The OFile whose directory structure is to be discarded.
  1500. **/
  1501. VOID
  1502. FatDiscardODir (
  1503. IN FAT_OFILE *OFile
  1504. );
  1505. /**
  1506. Request the directory structure when an OFile is newly generated.
  1507. If the directory structure is cached by volume, then just return this directory;
  1508. Otherwise, allocate a new one for OFile.
  1509. @param OFile - The OFile which requests directory structure.
  1510. **/
  1511. VOID
  1512. FatRequestODir (
  1513. IN FAT_OFILE *OFile
  1514. );
  1515. /**
  1516. Clean up all the cached directory structures when the volume is going to be abandoned.
  1517. @param Volume - FAT file system volume.
  1518. **/
  1519. VOID
  1520. FatCleanupODirCache (
  1521. IN FAT_VOLUME *Volume
  1522. );
  1523. //
  1524. // Global Variables
  1525. //
  1526. extern EFI_DRIVER_BINDING_PROTOCOL gFatDriverBinding;
  1527. extern EFI_COMPONENT_NAME_PROTOCOL gFatComponentName;
  1528. extern EFI_COMPONENT_NAME2_PROTOCOL gFatComponentName2;
  1529. extern EFI_LOCK FatFsLock;
  1530. extern EFI_LOCK FatTaskLock;
  1531. extern EFI_FILE_PROTOCOL FatFileInterface;
  1532. #endif