Ext4Dxe.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /** @file
  2. Common header for the driver
  3. Copyright (c) 2021 - 2023 Pedro Falcato All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef EXT4_H_
  7. #define EXT4_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 <Library/BaseLib.h>
  17. #include <Library/BaseMemoryLib.h>
  18. #include <Library/DebugLib.h>
  19. #include <Library/MemoryAllocationLib.h>
  20. #include <Library/OrderedCollectionLib.h>
  21. #include <Library/PcdLib.h>
  22. #include <Library/UefiBootServicesTableLib.h>
  23. #include <Library/UefiDriverEntryPoint.h>
  24. #include <Library/UefiLib.h>
  25. #include <Library/UefiRuntimeServicesTableLib.h>
  26. #include "Ext4Disk.h"
  27. #define SYMLOOP_MAX 8
  28. //
  29. // We need to specify path length limit for security purposes, to prevent possible
  30. // overflows and dead-loop conditions. Originally this limit is absent in FS design,
  31. // but present in UNIX distros and shell environments, which may varies from 1024 to 4096.
  32. //
  33. #define EXT4_EFI_PATH_MAX 4096
  34. #define EXT4_DRIVER_VERSION 0x0000
  35. //
  36. // The EXT4 Specification doesn't strictly limit block size and this value could be up to 2^31,
  37. // but in practice it is limited by PAGE_SIZE due to performance significant impact.
  38. // Many EXT4 implementations have size of block limited to PAGE_SIZE. In many cases it's limited
  39. // to 4096, which is a commonly supported page size on most MMU-capable hardware, and up to 65536.
  40. // So, to take a balance between compatibility and security measures, it is decided to use the
  41. // value of 2MiB as the limit, which is equal to large page size on new hardware.
  42. // As for supporting big block sizes, EXT4 has a RO_COMPAT_FEATURE called BIGALLOC, which changes
  43. // EXT4 to use clustered allocation, so that each bit in the ext4 block allocation bitmap addresses
  44. // a power of two number of blocks. So it would be wiser to implement and use this feature
  45. // if there is such a need instead of big block size.
  46. //
  47. #define EXT4_LOG_BLOCK_SIZE_MAX 11
  48. /**
  49. Opens an ext4 partition and installs the Simple File System protocol.
  50. @param[in] DeviceHandle Handle to the block device.
  51. @param[in] DiskIo Pointer to an EFI_DISK_IO_PROTOCOL.
  52. @param[in opt] DiskIo2 Pointer to an EFI_DISK_IO2_PROTOCOL,
  53. if supported.
  54. @param[in] BlockIo Pointer to an EFI_BLOCK_IO_PROTOCOL.
  55. @retval EFI_SUCCESS The opening was successful.
  56. !EFI_SUCCESS Opening failed.
  57. **/
  58. EFI_STATUS
  59. Ext4OpenPartition (
  60. IN EFI_HANDLE DeviceHandle,
  61. IN EFI_DISK_IO_PROTOCOL *DiskIo,
  62. IN OPTIONAL EFI_DISK_IO2_PROTOCOL *DiskIo2,
  63. IN EFI_BLOCK_IO_PROTOCOL *BlockIo
  64. );
  65. typedef struct _Ext4File EXT4_FILE;
  66. typedef struct _Ext4_Dentry EXT4_DENTRY;
  67. typedef struct _Ext4_PARTITION {
  68. EFI_SIMPLE_FILE_SYSTEM_PROTOCOL Interface;
  69. EFI_DISK_IO_PROTOCOL *DiskIo;
  70. EFI_DISK_IO2_PROTOCOL *DiskIo2;
  71. EFI_BLOCK_IO_PROTOCOL *BlockIo;
  72. EXT4_SUPERBLOCK SuperBlock;
  73. BOOLEAN Unmounting;
  74. UINT32 FeaturesIncompat;
  75. UINT32 FeaturesCompat;
  76. UINT32 FeaturesRoCompat;
  77. UINT32 InodeSize;
  78. UINT32 BlockSize;
  79. BOOLEAN ReadOnly;
  80. UINT64 NumberBlockGroups;
  81. EXT4_BLOCK_NR NumberBlocks;
  82. EXT4_BLOCK_GROUP_DESC *BlockGroups;
  83. UINT32 DescSize;
  84. EXT4_FILE *Root;
  85. UINT32 InitialSeed;
  86. LIST_ENTRY OpenFiles;
  87. EXT4_DENTRY *RootDentry;
  88. } EXT4_PARTITION;
  89. /**
  90. This structure represents a directory entry inside our directory entry tree.
  91. For now, it will be used as a way to track file names inside our opening
  92. code, but it may very well be used as a directory cache in the future.
  93. Because it's not being used as a directory cache right now,
  94. an EXT4_DENTRY structure is not necessarily unique name-wise in the list of
  95. children. Therefore, the dentry tree does not accurately reflect the
  96. filesystem structure.
  97. */
  98. struct _Ext4_Dentry {
  99. UINTN RefCount;
  100. CHAR16 Name[EXT4_NAME_MAX + 1];
  101. EXT4_INO_NR Inode;
  102. struct _Ext4_Dentry *Parent;
  103. LIST_ENTRY Children;
  104. LIST_ENTRY ListNode;
  105. };
  106. #define EXT4_DENTRY_FROM_DENTRY_LIST(Node) BASE_CR(Node, EXT4_DENTRY, ListNode)
  107. /**
  108. Creates a new dentry object.
  109. @param[in] Name Name of the dentry.
  110. @param[in out opt] Parent Parent dentry, if it's not NULL.
  111. @return The new allocated and initialised dentry.
  112. The ref count will be set to 1.
  113. **/
  114. EXT4_DENTRY *
  115. Ext4CreateDentry (
  116. IN CONST CHAR16 *Name,
  117. IN OUT EXT4_DENTRY *Parent OPTIONAL
  118. );
  119. /**
  120. Increments the ref count of the dentry.
  121. @param[in out] Dentry Pointer to a valid EXT4_DENTRY.
  122. **/
  123. VOID
  124. Ext4RefDentry (
  125. IN OUT EXT4_DENTRY *Dentry
  126. );
  127. /**
  128. Decrements the ref count of the dentry.
  129. If the ref count is 0, it's destroyed.
  130. @param[in out] Dentry Pointer to a valid EXT4_DENTRY.
  131. @retval True if it was destroyed, false if it's alive.
  132. **/
  133. BOOLEAN
  134. Ext4UnrefDentry (
  135. IN OUT EXT4_DENTRY *Dentry
  136. );
  137. /**
  138. Opens and parses the superblock.
  139. @param[out] Partition Partition structure to fill with filesystem
  140. details.
  141. @retval EFI_SUCCESS Parsing was successful and the partition is a
  142. valid ext4 partition.
  143. **/
  144. EFI_STATUS
  145. Ext4OpenSuperblock (
  146. OUT EXT4_PARTITION *Partition
  147. );
  148. /**
  149. Retrieves the EFI_BLOCK_IO_PROTOCOL of the partition.
  150. @param[in] Partition Pointer to the opened ext4 partition.
  151. @return The Block IO protocol associated with the partition.
  152. **/
  153. #define EXT4_BLOCK_IO(Partition) Partition->BlockIo
  154. /**
  155. Retrieves the EFI_DISK_IO_PROTOCOL of the partition.
  156. @param[in] Partition Pointer to the opened ext4 partition.
  157. @return The Disk IO protocol associated with the partition.
  158. **/
  159. #define EXT4_DISK_IO(Partition) Partition->DiskIo
  160. /**
  161. Retrieves the EFI_DISK_IO2_PROTOCOL of the partition.
  162. @param[in] Partition Pointer to the opened ext4 partition.
  163. @return The Disk IO 2 protocol associated with the partition, or NULL if
  164. not supported.
  165. **/
  166. #define EXT4_DISK_IO2(Partition) Partition->DiskIo2
  167. /**
  168. Retrieves the media ID of the partition.
  169. @param[in] Partition Pointer to the opened ext4 partition.
  170. @return The media ID associated with the partition.
  171. **/
  172. #define EXT4_MEDIA_ID(Partition) Partition->BlockIo->Media->MediaId
  173. /**
  174. Reads from the partition's disk using the DISK_IO protocol.
  175. @param[in] Partition Pointer to the opened ext4 partition.
  176. @param[out] Buffer Pointer to a destination buffer.
  177. @param[in] Length Length of the destination buffer.
  178. @param[in] Offset Offset, in bytes, of the location to read.
  179. @return Success status of the disk read.
  180. **/
  181. EFI_STATUS
  182. Ext4ReadDiskIo (
  183. IN EXT4_PARTITION *Partition,
  184. OUT VOID *Buffer,
  185. IN UINTN Length,
  186. IN UINT64 Offset
  187. );
  188. /**
  189. Reads blocks from the partition's disk using the DISK_IO protocol.
  190. @param[in] Partition Pointer to the opened ext4 partition.
  191. @param[out] Buffer Pointer to a destination buffer.
  192. @param[in] NumberBlocks Length of the read, in filesystem blocks.
  193. @param[in] BlockNumber Starting block number.
  194. @return Success status of the read.
  195. **/
  196. EFI_STATUS
  197. Ext4ReadBlocks (
  198. IN EXT4_PARTITION *Partition,
  199. OUT VOID *Buffer,
  200. IN UINTN NumberBlocks,
  201. IN EXT4_BLOCK_NR BlockNumber
  202. );
  203. /**
  204. Allocates a buffer and reads blocks from the partition's disk using the
  205. DISK_IO protocol. This function is deprecated and will be removed in the future.
  206. @param[in] Partition Pointer to the opened ext4 partition.
  207. @param[in] NumberBlocks Length of the read, in filesystem blocks.
  208. @param[in] BlockNumber Starting block number.
  209. @return Buffer allocated by AllocatePool, or NULL if some part of the process
  210. failed.
  211. **/
  212. VOID *
  213. Ext4AllocAndReadBlocks (
  214. IN EXT4_PARTITION *Partition,
  215. IN UINTN NumberBlocks,
  216. IN EXT4_BLOCK_NR BlockNumber
  217. );
  218. /**
  219. Checks if the opened partition has the 64-bit feature (see
  220. EXT4_FEATURE_INCOMPAT_64BIT).
  221. @param[in] Partition Pointer to the opened ext4 partition.
  222. @return TRUE if EXT4_FEATURE_INCOMPAT_64BIT is enabled, else FALSE.
  223. **/
  224. #define EXT4_IS_64_BIT(Partition) \
  225. ((Partition->FeaturesIncompat & EXT4_FEATURE_INCOMPAT_64BIT) != 0)
  226. /**
  227. Composes an EXT4_BLOCK_NR safely, from two halfs.
  228. @param[in] Partition Pointer to the opened ext4 partition.
  229. @param[in] Low Low half of the block number.
  230. @param[in] High High half of the block number.
  231. @return The block number formed by Low, and if 64 bit is enabled, High.
  232. **/
  233. #define EXT4_BLOCK_NR_FROM_HALFS(Partition, Low, High) \
  234. EXT4_IS_64_BIT(Partition) ? (Low | LShiftU64(High, 32)) : Low
  235. /**
  236. Retrieves a block group descriptor of the ext4 filesystem.
  237. @param[in] Partition Pointer to the opened ext4 partition.
  238. @param[in] BlockGroup Block group number.
  239. @return A pointer to the block group descriptor.
  240. **/
  241. EXT4_BLOCK_GROUP_DESC *
  242. Ext4GetBlockGroupDesc (
  243. IN EXT4_PARTITION *Partition,
  244. IN UINT32 BlockGroup
  245. );
  246. /**
  247. Checks inode number validity across superblock of the opened partition.
  248. @param[in] Partition Pointer to the opened ext4 partition.
  249. @return TRUE if inode number is valid.
  250. **/
  251. #define EXT4_IS_VALID_INODE_NR(Partition, InodeNum) \
  252. (((InodeNum) > 0) && (InodeNum) <= (Partition->SuperBlock.s_inodes_count))
  253. /**
  254. Reads an inode from disk.
  255. @param[in] Partition Pointer to the opened partition.
  256. @param[in] InodeNum Number of the desired Inode
  257. @param[out] OutIno Pointer to where it will be stored a pointer to the
  258. read inode.
  259. @return Status of the inode read.
  260. **/
  261. EFI_STATUS
  262. Ext4ReadInode (
  263. IN EXT4_PARTITION *Partition,
  264. IN EXT4_INO_NR InodeNum,
  265. OUT EXT4_INODE **OutIno
  266. );
  267. /**
  268. Converts blocks to bytes.
  269. @param[in] Partition Pointer to the opened partition.
  270. @param[in] Block Block number/number of blocks.
  271. @return The number of bytes.
  272. **/
  273. #define EXT4_BLOCK_TO_BYTES(Partition, Block) \
  274. MultU64x32(Block, Partition->BlockSize)
  275. /**
  276. Reads from an EXT4 inode.
  277. @param[in] Partition Pointer to the opened EXT4 partition.
  278. @param[in] File Pointer to the opened file.
  279. @param[out] Buffer Pointer to the buffer.
  280. @param[in] Offset Offset of the read.
  281. @param[in out] Length Pointer to the length of the buffer, in bytes.
  282. After a successful read, it's updated to the
  283. number of read bytes.
  284. @return Status of the read operation.
  285. **/
  286. EFI_STATUS
  287. Ext4Read (
  288. IN EXT4_PARTITION *Partition,
  289. IN EXT4_FILE *File,
  290. OUT VOID *Buffer,
  291. IN UINT64 Offset,
  292. IN OUT UINTN *Length
  293. );
  294. /**
  295. Retrieves the size of the inode.
  296. @param[in] Inode Pointer to the ext4 inode.
  297. @return The size of the inode, in bytes.
  298. **/
  299. #define EXT4_INODE_SIZE(Inode) \
  300. (LShiftU64(Inode->i_size_hi, 32) | Inode->i_size_lo)
  301. /**
  302. Retrieves an extent from an EXT4 inode.
  303. @param[in] Partition Pointer to the opened EXT4 partition.
  304. @param[in] File Pointer to the opened file.
  305. @param[in] LogicalBlock Block number which the returned extent must
  306. cover.
  307. @param[out] Extent Pointer to the output buffer, where the extent
  308. will be copied to.
  309. @retval EFI_SUCCESS Retrieval was successful.
  310. @retval EFI_NO_MAPPING Block has no mapping.
  311. **/
  312. EFI_STATUS
  313. Ext4GetExtent (
  314. IN EXT4_PARTITION *Partition,
  315. IN EXT4_FILE *File,
  316. IN EXT4_BLOCK_NR LogicalBlock,
  317. OUT EXT4_EXTENT *Extent
  318. );
  319. struct _Ext4File {
  320. EFI_FILE_PROTOCOL Protocol;
  321. EXT4_INODE *Inode;
  322. EXT4_INO_NR InodeNum;
  323. UINT64 OpenMode;
  324. UINT64 Position;
  325. UINT32 SymLoops;
  326. EXT4_PARTITION *Partition;
  327. ORDERED_COLLECTION *ExtentsMap;
  328. LIST_ENTRY OpenFilesListNode;
  329. // Owning reference to this file's directory entry.
  330. EXT4_DENTRY *Dentry;
  331. };
  332. #define EXT4_FILE_FROM_THIS(This) BASE_CR ((This), EXT4_FILE, Protocol)
  333. #define EXT4_FILE_FROM_OPEN_FILES_NODE(Node) \
  334. BASE_CR(Node, EXT4_FILE, OpenFilesListNode)
  335. /**
  336. Retrieves a directory entry.
  337. @param[in] Directory Pointer to the opened directory.
  338. @param[in] NameUnicode Pointer to the UCS-2 formatted filename.
  339. @param[in] Partition Pointer to the ext4 partition.
  340. @param[out] Result Pointer to the destination directory entry.
  341. @return The result of the operation.
  342. **/
  343. EFI_STATUS
  344. Ext4RetrieveDirent (
  345. IN EXT4_FILE *Directory,
  346. IN CONST CHAR16 *NameUnicode,
  347. IN EXT4_PARTITION *Partition,
  348. OUT EXT4_DIR_ENTRY *Result
  349. );
  350. /**
  351. Opens a file.
  352. @param[in] Directory Pointer to the opened directory.
  353. @param[in] Name Pointer to the UCS-2 formatted filename.
  354. @param[in] Partition Pointer to the ext4 partition.
  355. @param[in] OpenMode Mode in which the file is supposed to be open.
  356. @param[out] OutFile Pointer to the newly opened file.
  357. @return Result of the operation.
  358. **/
  359. EFI_STATUS
  360. Ext4OpenFile (
  361. IN EXT4_FILE *Directory,
  362. IN CONST CHAR16 *Name,
  363. IN EXT4_PARTITION *Partition,
  364. IN UINT64 OpenMode,
  365. OUT EXT4_FILE **OutFile
  366. );
  367. /**
  368. Opens a file using a directory entry.
  369. @param[in] Partition Pointer to the ext4 partition.
  370. @param[in] OpenMode Mode in which the file is supposed to be open.
  371. @param[out] OutFile Pointer to the newly opened file.
  372. @param[in] Entry Directory entry to be used.
  373. @param[in] Directory Pointer to the opened directory.
  374. @retval EFI_STATUS Result of the operation
  375. **/
  376. EFI_STATUS
  377. Ext4OpenDirent (
  378. IN EXT4_PARTITION *Partition,
  379. IN UINT64 OpenMode,
  380. OUT EXT4_FILE **OutFile,
  381. IN EXT4_DIR_ENTRY *Entry,
  382. IN EXT4_FILE *Directory
  383. );
  384. /**
  385. Allocates a zeroed inode structure.
  386. @param[in] Partition Pointer to the opened EXT4 partition.
  387. @return Pointer to the allocated structure, from the pool,
  388. with size Partition->InodeSize.
  389. **/
  390. EXT4_INODE *
  391. Ext4AllocateInode (
  392. IN EXT4_PARTITION *Partition
  393. );
  394. // Part of the EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
  395. /**
  396. Open the root directory on a volume.
  397. @param[in] This A pointer to the volume to open the root directory.
  398. @param[out] Root A pointer to the location to return the opened file handle
  399. for the root directory.
  400. @retval EFI_SUCCESS The device was opened.
  401. @retval EFI_UNSUPPORTED This volume does not support the requested file
  402. system type.
  403. @retval EFI_NO_MEDIA The device has no medium.
  404. @retval EFI_DEVICE_ERROR The device reported an error.
  405. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  406. @retval EFI_ACCESS_DENIED The service denied access to the file.
  407. @retval EFI_OUT_OF_RESOURCES The volume was not opened due to lack of
  408. resources.
  409. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
  410. medium is no longer supported. Any existing file handles for this volume are no
  411. longer valid. To access the files on the new medium, the volume must be reopened
  412. with OpenVolume().
  413. **/
  414. EFI_STATUS
  415. EFIAPI
  416. Ext4OpenVolume (
  417. IN EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *This,
  418. IN EFI_FILE_PROTOCOL **Root
  419. );
  420. // End of EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
  421. /**
  422. Sets up the protocol and metadata of a file that is being opened.
  423. @param[in out] File Pointer to the file.
  424. @param[in] Partition Pointer to the opened partition.
  425. **/
  426. VOID
  427. Ext4SetupFile (
  428. IN OUT EXT4_FILE *File,
  429. IN EXT4_PARTITION *Partition
  430. );
  431. /**
  432. Opens a new file relative to the source file's location.
  433. @param[out] FoundFile A pointer to the location to return the opened handle for the new
  434. file.
  435. @param[in] Source A pointer to the EXT4_FILE instance that is the file
  436. handle to the source location. This would typically be an open
  437. handle to a directory.
  438. @param[in] FileName The Null-terminated string of the name of the file to be opened.
  439. The file name may contain the following path modifiers: "\", ".",
  440. and "..".
  441. @param[in] OpenMode The mode to open the file. The only valid combinations that the
  442. file may be opened with are: Read, Read/Write, or Create/Read/Write.
  443. @param[in] Attributes Only valid for EFI_FILE_MODE_CREATE, in which case these are the
  444. attribute bits for the newly created file.
  445. @retval EFI_SUCCESS The file was opened.
  446. @retval EFI_NOT_FOUND The specified file could not be found on the device.
  447. @retval EFI_NO_MEDIA The device has no medium.
  448. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the medium is no
  449. longer supported.
  450. @retval EFI_DEVICE_ERROR The device reported an error.
  451. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  452. @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a file for write
  453. when the media is write-protected.
  454. @retval EFI_ACCESS_DENIED The service denied access to the file.
  455. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the file.
  456. @retval EFI_VOLUME_FULL The volume is full.
  457. **/
  458. EFI_STATUS
  459. Ext4OpenInternal (
  460. OUT EXT4_FILE **FoundFile,
  461. IN EXT4_FILE *Source,
  462. IN CHAR16 *FileName,
  463. IN UINT64 OpenMode,
  464. IN UINT64 Attributes
  465. );
  466. /**
  467. Closes a file.
  468. @param[in] File Pointer to the file.
  469. @return Status of the closing of the file.
  470. **/
  471. EFI_STATUS
  472. Ext4CloseInternal (
  473. IN EXT4_FILE *File
  474. );
  475. // Part of the EFI_FILE_PROTOCOL
  476. /**
  477. Opens a new file relative to the source file's location.
  478. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is the
  479. file handle to the source location. This would typically be an open handle to a
  480. directory.
  481. @param[out] NewHandle A pointer to the location to return the opened handle
  482. for the new file.
  483. @param[in] FileName The Null-terminated string of the name of the file to
  484. be opened. The file name may contain the following path modifiers: "\", ".", and
  485. "..".
  486. @param[in] OpenMode The mode to open the file. The only valid combinations
  487. that the file may be opened with are: Read, Read/Write, or Create/Read/Write.
  488. @param[in] Attributes Only valid for EFI_FILE_MODE_CREATE, in which case
  489. these are the attribute bits for the newly created file.
  490. @retval EFI_SUCCESS The file was opened.
  491. @retval EFI_NOT_FOUND The specified file could not be found on the
  492. device.
  493. @retval EFI_NO_MEDIA The device has no medium.
  494. @retval EFI_MEDIA_CHANGED The device has a different medium in it or the
  495. medium is no longer supported.
  496. @retval EFI_DEVICE_ERROR The device reported an error.
  497. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  498. @retval EFI_WRITE_PROTECTED An attempt was made to create a file, or open a
  499. file for write when the media is write-protected.
  500. @retval EFI_ACCESS_DENIED The service denied access to the file.
  501. @retval EFI_OUT_OF_RESOURCES Not enough resources were available to open the
  502. file.
  503. @retval EFI_VOLUME_FULL The volume is full.
  504. **/
  505. EFI_STATUS
  506. EFIAPI
  507. Ext4Open (
  508. IN EFI_FILE_PROTOCOL *This,
  509. OUT EFI_FILE_PROTOCOL **NewHandle,
  510. IN CHAR16 *FileName,
  511. IN UINT64 OpenMode,
  512. IN UINT64 Attributes
  513. );
  514. /**
  515. Closes a specified file handle.
  516. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that is
  517. the file handle to close.
  518. @retval EFI_SUCCESS The file was closed.
  519. **/
  520. EFI_STATUS
  521. EFIAPI
  522. Ext4Close (
  523. IN EFI_FILE_PROTOCOL *This
  524. );
  525. /**
  526. Close and delete the file handle.
  527. @param[in] This A pointer to the EFI_FILE_PROTOCOL
  528. instance that is the handle to the file to delete.
  529. @retval EFI_SUCCESS The file was closed and deleted, and the
  530. handle was closed.
  531. @retval EFI_WARN_DELETE_FAILURE The handle was closed, but the file was not
  532. deleted.
  533. **/
  534. EFI_STATUS
  535. EFIAPI
  536. Ext4Delete (
  537. IN EFI_FILE_PROTOCOL *This
  538. );
  539. /**
  540. Reads data from a file.
  541. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance
  542. that is the file handle to read data from.
  543. @param[in out] BufferSize On input, the size of the Buffer. On output,
  544. the amount of data returned in Buffer. In both cases, the size is measured in
  545. bytes.
  546. @param[out] Buffer The buffer into which the data is read.
  547. @retval EFI_SUCCESS Data was read.
  548. @retval EFI_NO_MEDIA The device has no medium.
  549. @retval EFI_DEVICE_ERROR The device reported an error.
  550. @retval EFI_DEVICE_ERROR An attempt was made to read from a deleted file.
  551. @retval EFI_DEVICE_ERROR On entry, the current file position is beyond the
  552. end of the file.
  553. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  554. @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current
  555. directory entry. BufferSize has been updated with the size needed to complete
  556. the request.
  557. **/
  558. EFI_STATUS
  559. EFIAPI
  560. Ext4ReadFile (
  561. IN EFI_FILE_PROTOCOL *This,
  562. IN OUT UINTN *BufferSize,
  563. OUT VOID *Buffer
  564. );
  565. /**
  566. Writes data to a file.
  567. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that
  568. is the file handle to write data to.
  569. @param[in out] BufferSize On input, the size of the Buffer. On output, the
  570. amount of data actually written. In both cases, the size is measured in bytes.
  571. @param[in] Buffer The buffer of data to write.
  572. @retval EFI_SUCCESS Data was written.
  573. @retval EFI_UNSUPPORTED Writes to open directory files are not supported.
  574. @retval EFI_NO_MEDIA The device has no medium.
  575. @retval EFI_DEVICE_ERROR The device reported an error.
  576. @retval EFI_DEVICE_ERROR An attempt was made to write to a deleted file.
  577. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  578. @retval EFI_WRITE_PROTECTED The file or medium is write-protected.
  579. @retval EFI_ACCESS_DENIED The file was opened read only.
  580. @retval EFI_VOLUME_FULL The volume is full.
  581. **/
  582. EFI_STATUS
  583. EFIAPI
  584. Ext4WriteFile (
  585. IN EFI_FILE_PROTOCOL *This,
  586. IN OUT UINTN *BufferSize,
  587. IN VOID *Buffer
  588. );
  589. /**
  590. Returns a file's current position.
  591. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that
  592. is the file handle to get the current position on.
  593. @param[out] Position The address to return the file's current position
  594. value.
  595. @retval EFI_SUCCESS The position was returned.
  596. @retval EFI_UNSUPPORTED The request is not valid on open directories.
  597. @retval EFI_DEVICE_ERROR An attempt was made to get the position from a
  598. deleted file.
  599. **/
  600. EFI_STATUS
  601. EFIAPI
  602. Ext4GetPosition (
  603. IN EFI_FILE_PROTOCOL *This,
  604. OUT UINT64 *Position
  605. );
  606. /**
  607. Sets a file's current position.
  608. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that
  609. is the file handle to set the requested position on.
  610. @param[in] Position The byte position from the start of the file to
  611. set.
  612. @retval EFI_SUCCESS The position was set.
  613. @retval EFI_UNSUPPORTED The seek request for nonzero is not valid on open
  614. directories.
  615. @retval EFI_DEVICE_ERROR An attempt was made to set the position of a deleted
  616. file.
  617. **/
  618. EFI_STATUS
  619. EFIAPI
  620. Ext4SetPosition (
  621. IN EFI_FILE_PROTOCOL *This,
  622. IN UINT64 Position
  623. );
  624. /**
  625. Returns information about a file.
  626. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance
  627. that is the file handle the requested information is for.
  628. @param[in] InformationType The type identifier for the information being
  629. requested.
  630. @param[in out] BufferSize On input, the size of Buffer. On output, the
  631. amount of data returned in Buffer. In both cases, the size is measured in bytes.
  632. @param[out] Buffer A pointer to the data buffer to return. The
  633. buffer's type is indicated by InformationType.
  634. @retval EFI_SUCCESS The information was returned.
  635. @retval EFI_UNSUPPORTED The InformationType is not known.
  636. @retval EFI_NO_MEDIA The device has no medium.
  637. @retval EFI_DEVICE_ERROR The device reported an error.
  638. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  639. @retval EFI_BUFFER_TOO_SMALL The BufferSize is too small to read the current
  640. directory entry. BufferSize has been updated with the size needed to complete
  641. the request.
  642. **/
  643. EFI_STATUS
  644. EFIAPI
  645. Ext4GetInfo (
  646. IN EFI_FILE_PROTOCOL *This,
  647. IN EFI_GUID *InformationType,
  648. IN OUT UINTN *BufferSize,
  649. OUT VOID *Buffer
  650. );
  651. /**
  652. Sets information about a file.
  653. @param[in] This A pointer to the EFI_FILE_PROTOCOL instance that
  654. is the file handle the information is for.
  655. @param[in] InformationType The type identifier for the information being set.
  656. @param[in] BufferSize The size, in bytes, of Buffer.
  657. @param[in] Buffer A pointer to the data buffer to write. The
  658. buffer's type is indicated by InformationType.
  659. @retval EFI_SUCCESS The information was set.
  660. @retval EFI_UNSUPPORTED The InformationType is not known.
  661. @retval EFI_NO_MEDIA The device has no medium.
  662. @retval EFI_DEVICE_ERROR The device reported an error.
  663. @retval EFI_VOLUME_CORRUPTED The file system structures are corrupted.
  664. @retval EFI_WRITE_PROTECTED InformationType is EFI_FILE_INFO_ID and the media
  665. is read-only.
  666. @retval EFI_WRITE_PROTECTED InformationType is
  667. EFI_FILE_PROTOCOL_SYSTEM_INFO_ID and the media is read only.
  668. @retval EFI_WRITE_PROTECTED InformationType is
  669. EFI_FILE_SYSTEM_VOLUME_LABEL_ID and the media is read-only.
  670. @retval EFI_ACCESS_DENIED An attempt is made to change the name of a file
  671. to a file that is already present.
  672. @retval EFI_ACCESS_DENIED An attempt is being made to change the
  673. EFI_FILE_DIRECTORY Attribute.
  674. @retval EFI_ACCESS_DENIED An attempt is being made to change the size of a
  675. directory.
  676. @retval EFI_ACCESS_DENIED InformationType is EFI_FILE_INFO_ID and the file
  677. was opened read-only and an attempt is being made to modify a field other than
  678. Attribute.
  679. @retval EFI_VOLUME_FULL The volume is full.
  680. @retval EFI_BAD_BUFFER_SIZE BufferSize is smaller than the size of the type
  681. indicated by InformationType.
  682. **/
  683. EFI_STATUS
  684. EFIAPI
  685. Ext4SetInfo (
  686. IN EFI_FILE_PROTOCOL *This,
  687. IN EFI_GUID *InformationType,
  688. IN UINTN BufferSize,
  689. IN VOID *Buffer
  690. );
  691. // EFI_FILE_PROTOCOL implementation ends here.
  692. /**
  693. Checks if a file is a directory.
  694. @param[in] File Pointer to the opened file.
  695. @return TRUE if file is a directory.
  696. **/
  697. BOOLEAN
  698. Ext4FileIsDir (
  699. IN CONST EXT4_FILE *File
  700. );
  701. /**
  702. Checks if a file is a symlink.
  703. @param[in] File Pointer to the opened file.
  704. @return BOOLEAN Whether file is a symlink
  705. **/
  706. BOOLEAN
  707. Ext4FileIsSymlink (
  708. IN CONST EXT4_FILE *File
  709. );
  710. /**
  711. Checks if a file is a regular file.
  712. @param[in] File Pointer to the opened file.
  713. @return BOOLEAN TRUE if file is a regular file.
  714. **/
  715. BOOLEAN
  716. Ext4FileIsReg (
  717. IN CONST EXT4_FILE *File
  718. );
  719. // In EFI we can't open FIFO pipes, UNIX sockets, character/block devices since
  720. // these concepts are at the kernel level and are OS dependent.
  721. /**
  722. Checks if a file is openable.
  723. @param[in] File Pointer to the file trying to be opened.
  724. @return TRUE if file is openable. A file is considered openable if
  725. it's a regular file or a directory, since most other file types
  726. don't make sense under UEFI.
  727. **/
  728. #define Ext4FileIsOpenable(File) (Ext4FileIsReg (File) || Ext4FileIsDir (File) || Ext4FileIsSymlink (File))
  729. #define EXT4_INODE_HAS_FIELD(Inode, Field) \
  730. (Inode->i_extra_isize + EXT4_GOOD_OLD_INODE_SIZE >= \
  731. OFFSET_OF(EXT4_INODE, Field) + sizeof(((EXT4_INODE *)NULL)->Field))
  732. /**
  733. Calculates the physical space used by a file.
  734. @param[in] File Pointer to the opened file.
  735. @return Physical space used by a file, in bytes.
  736. **/
  737. UINT64
  738. Ext4FilePhysicalSpace (
  739. IN EXT4_FILE *File
  740. );
  741. /**
  742. Gets the file's last access time.
  743. @param[in] File Pointer to the opened file.
  744. @param[out] Time Pointer to an EFI_TIME structure.
  745. **/
  746. VOID
  747. Ext4FileATime (
  748. IN EXT4_FILE *File,
  749. OUT EFI_TIME *Time
  750. );
  751. /**
  752. Gets the file's last (data) modification time.
  753. @param[in] File Pointer to the opened file.
  754. @param[out] Time Pointer to an EFI_TIME structure.
  755. **/
  756. VOID
  757. Ext4FileMTime (
  758. IN EXT4_FILE *File,
  759. OUT EFI_TIME *Time
  760. );
  761. /**
  762. Gets the file's creation time, if possible.
  763. @param[in] File Pointer to the opened file.
  764. @param[out] Time Pointer to an EFI_TIME structure.
  765. In the case where the the creation time isn't
  766. recorded, Time is zeroed.
  767. **/
  768. VOID
  769. Ext4FileCreateTime (
  770. IN EXT4_FILE *File,
  771. OUT EFI_TIME *Time
  772. );
  773. /**
  774. Initialises Unicode collation, which is needed for case-insensitive string
  775. comparisons within the driver (a good example of an application of this is
  776. filename comparison).
  777. @param[in] DriverHandle Handle to the driver image.
  778. @retval EFI_SUCCESS Unicode collation was successfully initialised.
  779. @retval !EFI_SUCCESS Failure.
  780. **/
  781. EFI_STATUS
  782. Ext4InitialiseUnicodeCollation (
  783. EFI_HANDLE DriverHandle
  784. );
  785. /**
  786. Does a case-insensitive string comparison. Refer to
  787. EFI_UNICODE_COLLATION_PROTOCOL's StriColl for more details.
  788. @param[in] Str1 Pointer to a null terminated string.
  789. @param[in] Str2 Pointer to a null terminated string.
  790. @retval 0 Str1 is equivalent to Str2.
  791. @retval >0 Str1 is lexically greater than Str2.
  792. @retval <0 Str1 is lexically less than Str2.
  793. **/
  794. INTN
  795. Ext4StrCmpInsensitive (
  796. IN CHAR16 *Str1,
  797. IN CHAR16 *Str2
  798. );
  799. /**
  800. Retrieves the filename of the directory entry and converts it to UTF-16/UCS-2
  801. @param[in] Entry Pointer to a EXT4_DIR_ENTRY.
  802. @param[out] Ucs2FileName Pointer to an array of CHAR16's, of size EXT4_NAME_MAX + 1.
  803. @retval EFI_SUCCESS The filename was successfully retrieved and converted to UCS2.
  804. @retval EFI_INVALID_PARAMETER The filename is not valid UTF-8.
  805. @retval !EFI_SUCCESS Failure.
  806. **/
  807. EFI_STATUS
  808. Ext4GetUcs2DirentName (
  809. IN EXT4_DIR_ENTRY *Entry,
  810. OUT CHAR16 Ucs2FileName[EXT4_NAME_MAX + 1]
  811. );
  812. /**
  813. Retrieves information about the file and stores it in the EFI_FILE_INFO
  814. format.
  815. @param[in] File Pointer to an opened file.
  816. @param[out] Info Pointer to a EFI_FILE_INFO.
  817. @param[in out] BufferSize Pointer to the buffer size
  818. @return Status of the file information request.
  819. **/
  820. EFI_STATUS
  821. Ext4GetFileInfo (
  822. IN EXT4_FILE *File,
  823. OUT EFI_FILE_INFO *Info,
  824. IN OUT UINTN *BufferSize
  825. );
  826. /**
  827. Reads a directory entry.
  828. @param[in] Partition Pointer to the ext4 partition.
  829. @param[in] File Pointer to the open directory.
  830. @param[out] Buffer Pointer to the output buffer.
  831. @param[in] Offset Initial directory position.
  832. @param[in out] OutLength Pointer to a UINTN that contains the length of
  833. the buffer, and the length of the actual EFI_FILE_INFO after the call.
  834. @return Result of the operation.
  835. **/
  836. EFI_STATUS
  837. Ext4ReadDir (
  838. IN EXT4_PARTITION *Partition,
  839. IN EXT4_FILE *File,
  840. OUT VOID *Buffer,
  841. IN UINT64 Offset,
  842. IN OUT UINTN *OutLength
  843. );
  844. /**
  845. Initialises the (empty) extents map, that will work as a cache of extents.
  846. @param[in] File Pointer to the open file.
  847. @return Result of the operation.
  848. **/
  849. EFI_STATUS
  850. Ext4InitExtentsMap (
  851. IN EXT4_FILE *File
  852. );
  853. /**
  854. Frees the extents map, deleting every extent stored.
  855. @param[in] File Pointer to the open file.
  856. **/
  857. VOID
  858. Ext4FreeExtentsMap (
  859. IN EXT4_FILE *File
  860. );
  861. /**
  862. Calculates the checksum of the given buffer.
  863. @param[in] Partition Pointer to the opened EXT4 partition.
  864. @param[in] Buffer Pointer to the buffer.
  865. @param[in] Length Length of the buffer, in bytes.
  866. @param[in] InitialValue Initial value of the CRC.
  867. @return The checksum.
  868. **/
  869. UINT32
  870. Ext4CalculateChecksum (
  871. IN CONST EXT4_PARTITION *Partition,
  872. IN CONST VOID *Buffer,
  873. IN UINTN Length,
  874. IN UINT32 InitialValue
  875. );
  876. /**
  877. Calculates the checksum of the given inode.
  878. @param[in] Partition Pointer to the opened EXT4 partition.
  879. @param[in] Inode Pointer to the inode.
  880. @param[in] InodeNum Inode number.
  881. @return The checksum.
  882. **/
  883. UINT32
  884. Ext4CalculateInodeChecksum (
  885. IN CONST EXT4_PARTITION *Partition,
  886. IN CONST EXT4_INODE *Inode,
  887. IN EXT4_INO_NR InodeNum
  888. );
  889. /**
  890. Checks if the checksum of the inode is correct.
  891. @param[in] Partition Pointer to the opened EXT4 partition.
  892. @param[in] Inode Pointer to the inode.
  893. @param[in] InodeNum Inode number.
  894. @return TRUE if checksum is correct, FALSE if there is corruption.
  895. **/
  896. BOOLEAN
  897. Ext4CheckInodeChecksum (
  898. IN CONST EXT4_PARTITION *Partition,
  899. IN CONST EXT4_INODE *Inode,
  900. IN EXT4_INO_NR InodeNum
  901. );
  902. /**
  903. Unmounts and frees an ext4 partition.
  904. @param[in] Partition Pointer to the opened partition.
  905. @return Status of the unmount.
  906. **/
  907. EFI_STATUS
  908. Ext4UnmountAndFreePartition (
  909. IN EXT4_PARTITION *Partition
  910. );
  911. /**
  912. Checks if the checksum of the block group descriptor is correct.
  913. @param[in] Partition Pointer to the opened EXT4 partition.
  914. @param[in] BlockGroupDesc Pointer to the block group descriptor.
  915. @param[in] BlockGroupNum Number of the block group.
  916. @return TRUE if checksum is correct, FALSE if there is corruption.
  917. **/
  918. BOOLEAN
  919. Ext4VerifyBlockGroupDescChecksum (
  920. IN CONST EXT4_PARTITION *Partition,
  921. IN CONST EXT4_BLOCK_GROUP_DESC *BlockGroupDesc,
  922. IN UINT32 BlockGroupNum
  923. );
  924. /**
  925. Calculates the checksum of the block group descriptor.
  926. @param[in] Partition Pointer to the opened EXT4 partition.
  927. @param[in] BlockGroupDesc Pointer to the block group descriptor.
  928. @param[in] BlockGroupNum Number of the block group.
  929. @return The checksum.
  930. **/
  931. UINT16
  932. Ext4CalculateBlockGroupDescChecksum (
  933. IN CONST EXT4_PARTITION *Partition,
  934. IN CONST EXT4_BLOCK_GROUP_DESC *BlockGroupDesc,
  935. IN UINT32 BlockGroupNum
  936. );
  937. /**
  938. Verifies the existence of a particular RO compat feature set.
  939. @param[in] Partition Pointer to the opened EXT4 partition.
  940. @param[in] RoCompatFeatureSet Feature set to test.
  941. @return TRUE if all features are supported, else FALSE.
  942. **/
  943. #define EXT4_HAS_RO_COMPAT(Partition, RoCompatFeatureSet) \
  944. ((Partition->FeaturesRoCompat & RoCompatFeatureSet) == RoCompatFeatureSet)
  945. /**
  946. Verifies the existence of a particular compat feature set.
  947. @param[in] Partition Pointer to the opened EXT4 partition.
  948. @param[in] CompatFeatureSet Feature set to test.
  949. @return TRUE if all features are supported, else FALSE.
  950. **/
  951. #define EXT4_HAS_COMPAT(Partition, CompatFeatureSet) \
  952. ((Partition->FeaturesCompat & CompatFeatureSet) == CompatFeatureSet)
  953. /**
  954. Verifies the existence of a particular compat feature set.
  955. @param[in] Partition Pointer to the opened EXT4 partition.
  956. @param[in] IncompatFeatureSet Feature set to test.
  957. @return TRUE if all features are supported, else FALSE.
  958. **/
  959. #define EXT4_HAS_INCOMPAT(Partition, IncompatFeatureSet) \
  960. ((Partition->FeaturesIncompat & IncompatFeatureSet) == IncompatFeatureSet)
  961. // Note: Might be a good idea to provide generic Ext4Has$feature() through
  962. // macros.
  963. /**
  964. Checks if metadata_csum is enabled on the partition.
  965. @param[in] Partition Pointer to the opened EXT4 partition.
  966. @return TRUE if the metadata_csum is supported, else FALSE.
  967. **/
  968. #define EXT4_HAS_METADATA_CSUM(Partition) \
  969. EXT4_HAS_RO_COMPAT(Partition, EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
  970. /**
  971. Checks if gdt_csum is enabled on the partition.
  972. @param[in] Partition Pointer to the opened EXT4 partition.
  973. @return TRUE if the gdt_csum is supported, else FALSE.
  974. **/
  975. #define EXT4_HAS_GDT_CSUM(Partition) \
  976. EXT4_HAS_RO_COMPAT(Partition, EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
  977. /**
  978. Retrieves the volume name.
  979. @param[in] Part Pointer to the opened partition.
  980. @param[out] Info Pointer to a CHAR16*.
  981. @param[out] BufferSize Pointer to a UINTN, where the string length
  982. of the name will be put.
  983. @return Status of the volume name request.
  984. **/
  985. EFI_STATUS
  986. Ext4GetVolumeName (
  987. IN EXT4_PARTITION *Partition,
  988. OUT CHAR16 **OutVolName,
  989. OUT UINTN *VolNameLen
  990. );
  991. /**
  992. Checks the superblock's magic value.
  993. @param[in] DiskIo Pointer to the DiskIo.
  994. @param[in] BlockIo Pointer to the BlockIo.
  995. @returns Whether the partition has a valid EXT4 superblock magic value.
  996. **/
  997. BOOLEAN
  998. Ext4SuperblockCheckMagic (
  999. IN EFI_DISK_IO_PROTOCOL *DiskIo,
  1000. IN EFI_BLOCK_IO_PROTOCOL *BlockIo
  1001. );
  1002. /**
  1003. Check if the extent is uninitialized
  1004. @param[in] Extent Pointer to the EXT4_EXTENT
  1005. @returns True if uninitialized, else false.
  1006. **/
  1007. #define EXT4_EXTENT_IS_UNINITIALIZED(Extent) \
  1008. ((Extent)->ee_len > EXT4_EXTENT_MAX_INITIALIZED)
  1009. /**
  1010. Retrieves the extent's length, dealing with uninitialized extents in the
  1011. process.
  1012. @param[in] Extent Pointer to the EXT4_EXTENT
  1013. @returns Extent's length, in filesystem blocks.
  1014. **/
  1015. EXT4_BLOCK_NR
  1016. Ext4GetExtentLength (
  1017. IN CONST EXT4_EXTENT *Extent
  1018. );
  1019. /**
  1020. Retrieves an extent from an EXT2/3 inode (with a blockmap).
  1021. @param[in] Partition Pointer to the opened EXT4 partition.
  1022. @param[in] File Pointer to the opened file.
  1023. @param[in] LogicalBlock Block number which the returned extent must cover.
  1024. @param[out] Extent Pointer to the output buffer, where the extent will be copied to.
  1025. @retval EFI_SUCCESS Retrieval was successful.
  1026. @retval EFI_NO_MAPPING Block has no mapping.
  1027. **/
  1028. EFI_STATUS
  1029. Ext4GetBlocks (
  1030. IN EXT4_PARTITION *Partition,
  1031. IN EXT4_FILE *File,
  1032. IN EXT2_BLOCK_NR LogicalBlock,
  1033. OUT EXT4_EXTENT *Extent
  1034. );
  1035. #endif