<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jul 21, 2021, at 6:20 PM, gaoliming <<a href="mailto:gaoliming@byosoft.com.cn" class="">gaoliming@byosoft.com.cn</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">-----邮件原件-----<br class="">发件人:<span class="Apple-converted-space"> </span><a href="mailto:rfc@edk2.groups.io" class="">rfc@edk2.groups.io</a><span class="Apple-converted-space"> </span><<a href="mailto:rfc@edk2.groups.io" class="">rfc@edk2.groups.io</a>> 代表 Pedro Falcato<br class="">发送时间: 2021年7月22日 7:12<br class="">收件人:<span class="Apple-converted-space"> </span><a href="mailto:devel@edk2.groups.io" class="">devel@edk2.groups.io</a><br class="">抄送:<span class="Apple-converted-space"> </span><a href="mailto:rfc@edk2.groups.io" class="">rfc@edk2.groups.io</a><br class="">主题: [edk2-rfc] RFC: EXT4 filesystem driver<br class=""><br class="">EXT4 (fourth extended filesystem) is a filesystem developed for Linux<br class="">that has been in wide use (desktops, servers, smartphones) since 2008.<br class=""><br class="">The Ext4Pkg implements the Simple File System Protocol for a partition<br class="">that is formatted with the EXT4 file system. This allows UEFI Drivers,<br class="">UEFI Applications, UEFI OS Loaders, and the UEFI Shell to access files<br class="">on an EXT4 partition and supports booting a UEFI OS Loader from an<br class="">EXT4 partition.<br class="">This project is one of the TianoCore Google Summer of Code projects.<br class=""><br class="">Right now, Ext4Pkg only contains a single member, Ext4Dxe, which is a<br class="">UEFI driver that consumes Block I/O, Disk I/O and (optionally) Disk<br class="">I/O 2 Protocols, and produces the Simple File System protocol. It<br class="">allows mounting ext4 filesystems exclusively.<br class=""><br class="">Brief overhead of EXT4:<br class="">Layout of an EXT2/3/4 filesystem:<br class="">(note: this driver has been developed using<br class=""><a href="https://www.kernel.org/doc/html/latest/filesystems/ext4/index.html" class="">https://www.kernel.org/doc/html/latest/filesystems/ext4/index.html</a> as<br class="">documentation).<br class=""><br class="">An ext2/3/4 filesystem (here on out referred to as simply an ext4 filesystem,<br class="">due to the similarities) is composed of various concepts:<br class=""><br class="">1) Superblock<br class="">The superblock is the structure near (1024 bytes offset from the start)<br class="">the start of the partition, and describes the filesystem in general.<br class="">Here, we get to know the size of the filesystem's blocks, which features<br class="">it supports or not, whether it's been cleanly unmounted, how many blocks<br class="">we have, etc.<br class=""><br class="">2) Block groups<br class="">EXT4 filesystems are divided into block groups, and each block group covers<br class="">s_blocks_per_group(8 * Block Size) blocks. Each block group has an<br class="">associated block group descriptor; these are present directly after the<br class="">superblock. Each block group descriptor contains the location of the<br class="">inode table, and the inode and block bitmaps (note these bitmaps are only<br class="">a block long, which gets us the 8 * Block Size formula covered previously).<br class=""><br class="">3) Blocks<br class="">The ext4 filesystem is divided into blocks, of size s_log_block_size ^ 1024.<br class="">Blocks can be allocated using individual block groups's bitmaps. Note<br class="">that block 0 is invalid and its presence on extents/block tables means<br class="">it's part of a file hole, and that particular location must be read as<br class="">a block full of zeros.<br class=""><br class="">4) Inodes<br class="">The ext4 filesystem divides files/directories into inodes (originally<br class="">index nodes). Each file/socket/symlink/directory/etc (here on out referred<br class="">to as a file, since there is no distinction under the ext4 filesystem) is<br class="">stored as a /nameless/ inode, that is stored in some block group's inode<br class="">table. Each inode has s_inode_size size (or GOOD_OLD_INODE_SIZE if it's<br class="">an old filesystem), and holds various metadata about the file. Since the<br class="">largest inode structure right now is ~160 bytes, the rest of the inode<br class="">contains inline extended attributes. Inodes' data is stored using either<br class="">data blocks (under ext2/3) or extents (under ext4).<br class=""><br class="">5) Extents<br class="">Ext4 inodes store data in extents. These let N contiguous logical blocks<br class="">that are represented by N contiguous physical blocks be represented by a<br class="">single extent structure, which minimizes filesystem metadata bloat and<br class="">speeds up block mapping (particularly due to the fact that high-quality<br class="">ext4 implementations like linux's try /really/ hard to make the file<br class="">contiguous, so it's common to have files with almost 0 fragmentation).<br class="">Inodes that use extents store them in a tree, and the top of the tree<br class="">is stored on i_data. The tree's leaves always start with an<br class="">EXT4_EXTENT_HEADER and contain EXT4_EXTENT_INDEX on eh_depth != 0<br class="">and<br class="">EXT4_EXTENT on eh_depth = 0; these entries are always sorted by logical<br class="">block.<br class=""><br class="">6) Directories<br class="">Ext4 directories are files that store name -> inode mappings for the<br class="">logical directory; this is where files get their names, which means ext4<br class="">inodes do not themselves have names, since they can be linked (present)<br class="">multiple times with different names. Directories can store entries in two<br class="">different ways:<br class="">1) Classical linear directories: They store entries as a mostly-linked<br class="">mostly-list of EXT4_DIR_ENTRY.<br class="">2) Hash tree directories: These are used for larger directories, with<br class="">hundreds of entries, and are designed in a backwards-compatible way.<br class="">These are not yet implemented in the Ext4Dxe driver.<br class=""><br class="">7) Journal<br class="">Ext3/4 filesystems have a journal to help protect the filesystem against<br class="">system crashes. This is not yet implemented in Ext4Dxe but is described<br class="">in detail in the Linux kernel's documentation.<br class=""><br class="">The EDK2 implementation of ext4 is based only on the public documentation<br class="">available at<br class=""><a href="https://www.kernel.org/doc/html/latest/filesystems/ext4/index.html" class="">https://www.kernel.org/doc/html/latest/filesystems/ext4/index.html</a><br class="">and<br class="">the FreeBSD ext2fs driver (available at<br class="">https://github.com/freebsd/freebsd-src/tree/main/sys/fs/ext2fs,<br class="">BSD-2-Clause-FreeBSD licensed). It is licensed as<br class="">SPDX-License-Identifier: BSD-2-Clause-Patent.<br class=""><br class="">After a brief discussion with the community, the proposed package<br class="">location is edk2-platform/Features/Ext4Pkg<br class="">(relevant discussion: https://edk2.groups.io/g/devel/topic/83060185).<br class=""><br class="">I was the main contributor and I would like to maintain the package in<br class="">the future, if possible.<br class=""><br class="">Current limitations:<br class="">1) The Ext4Dxe driver is, at the moment, read-only.<br class="">2) The Ext4Dxe driver at the moment cannot mount older (ext2/3)<br class="">filesystems. Ensuring compatibility with<br class="">those may not be a bad idea.<br class=""><br class="">I intend to test the package using the UEFI SCTs present in edk2-test,<br class="">and implement any other needed unit tests myself using the already<br class="">available unit test framework. I also intend to (privately) fuzz the<br class="">UEFI driver with bad/unusual disk images, to improve the security and<br class="">reliability of the driver.<br class=""><br class="">In the future, ext4 write support should be added so edk2 has a<br class="">fully-featured RW ext4 driver. There could also be a focus on<br class="">supporting the older ext4-like filesystems, as I mentioned in the<br class="">limitations, but that is open for discussion.<br class=""><br class="">The driver's handling of unclean unmounting through forced shutdown is<br class="">unclear.<br class="">Is there a position in edk2 on how to handle such cases? I don't think<br class="">FAT32 has a "this filesystem is/was dirty" and even though it seems to<br class="">me that stopping a system from booting/opening the partition because<br class="">"we may find some tiny irregularities" is not the best course of<br class="">action, I can't find a clear answer.<br class=""><br class="">The driver also had to add implementations of CRC32C and CRC16, and<br class="">after talking with my mentor we quickly reached the conclusion that<br class="">these may be good candidates for inclusion in MdePkg. We also<br class="">discussed moving the Ucs2 <-> Utf8 conversion library in RedfishPkg<br class="">(BaseUcs2Utf8Lib) into MdePkg as well. Any comments?<br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Current MdePkg BaseLib has CalculateCrc32(). So, CRC32C and CRC16 can be added into BaseLib.<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">If more modules need to consume Ucs2 <-> Utf8 conversion library, BaseUcs2Utf8Lib is generic enough</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">to be placed in MdePkg.<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""></div></blockquote><div><br class=""></div><div>I think the Terminal driver may have some similar logic to convert UTF-8 terminals to/from the UEFI UCS-2?</div><div><br class=""></div><div><a href="https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/Console/TerminalDxe/Vtutf8.c#L186" class="">https://github.com/tianocore/edk2/blob/master/MdeModulePkg/Universal/Console/TerminalDxe/Vtutf8.c#L186</a></div><div><br class=""></div><div>Thanks,</div><div><br class=""></div><div>Andrew Fish</div><br class=""><blockquote type="cite" class=""><div class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Thanks</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">Liming</span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="">Feel free to ask any questions you may find relevant.<br class=""><br class="">Best Regards,<br class=""><br class="">Pedro Falcato<br class=""><br class=""><br class=""><br class=""><br class=""></blockquote><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class=""></span></div></blockquote></div><br class=""></body></html>


 <div width="1" style="color:white;clear:both">_._,_._,_</div> <hr>   Groups.io Links:<p>   You receive all messages sent to this group.    <p> <a target="_blank" href="https://edk2.groups.io/g/devel/message/78051">View/Reply Online (#78051)</a> |    |  <a target="_blank" href="https://groups.io/mt/84371999/1813853">Mute This Topic</a>  | <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>    <a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> | <a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |  <a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>  [edk2-devel-archive@redhat.com]<br> <div width="1" style="color:white;clear:both">_._,_._,_</div>