Sector Sizes of 4096
Posted: Tue Nov 24, 2020 10:53 pm
Just for your information, and since I haven't found much on this subject, I thought I would comment about sector sizes other than 512 bytes.
Those of us that use QEMU may have noticed that a recent update brought the NVMe emulation to version 1.3. With this addition, the NVMe drive now supports sectors sizes that are larger than the default 512-byte sectors.
For example, use similar command line arguments to:
This allows you to have 4096-byte sectors.
At this point, you can't really do anything with it, other than recognizing that the media is using a sector size other than 512 bytes. For example, you actually need a file system that supports different sector sizes.
With gratitude toward him, the author of the LEAN file system has allowed me to work with his file system through its revisions, and I have added a few small details to allow this file system to work on media devices with sector sizes other than 512 bytes. With some tests of my code, I was able to mount and use a LEAN file system formatted with 4096-byte sectors. As long as the sector size is equal to or greater than 512 bytes *and* is a power of two, it works just fine.
The additions I added:
- changed the version to 0x0007 (from 0x0006)
- an indicator byte in the Super Block to compare the physical sector size and the formatted sector size to be sure they match before mount time. (0 = 512, 1 = 1024, 2 = 2048, 3 = 4095, etc)
- specifying that an Indirect Block uses all remaining space in the sector for its extents. (ex: with 512-byte sectors, there is room for 38. With 4096-byte sectors, there is room for 336)
- the Super Block's CRC is calculated on the whole sector, not just the super block data. i.e.: Don't assume 512-byte sectors.
- all remaining space after the INODE and before the end of the sector is used no matter the size of the sector. i.e.: Don't assume 512-byte sectors.
The only thing to consider with the new revisions are that as long as you only use 38 extents in the Indirect, a version 0x0006 driver will handle a version 0x0007 partition just fine and visa-versa. i.e.: I have made no change to the file system other than the specification that the Indirect Block can use all remaining space within the sector for extents. This holds true to either version, though with only one exception:
- The extent count member in the Indirect block now must be a WORD sized member rather than a BYTE sized member. With this in mind, if a version 0x0007 ever writes more than 255 extents to this Indirect Block, then a version 0x0006 driver ever reads the count, it will read an incorrect count. Hence the addition to the Super Block to first verify the size of the sector, and of course the version field.
Back to my point, as far as I know, QEMU and the NVMe is the only form of emulation allowing TRUE emulation of 4096-byte sectors. All other forms of emulation require the physically attached media to support this sector size. (Please correct me if I am wrong, and point me to the means of doing this).
Anyway, you now have a way to test your media and file system drivers with sector sizes other than 512 bytes.
There are some things to remember though.
- You can't boot a Legacy system with the media having a sector size other than 512 bytes. However, you can boot something else first. For example, boot FAT32, as one of the media devices, having an additional NVMe device with one or more namespaces.
- The file system must support a sector size other than 512 bytes. FAT? haha. Good luck. It will have to be something built to allow non-standard sizes.
After getting the Lean author's permission, I will post an updated specification.
Also, I have started the 4096-byte sector function of my image utility as well. It currently allows different sized sectors, though I only tested with a simple LEAN FS partition. It is still experimental.
Thanks,
Ben
- http://www.fysnet.net/osdesign_book_series.htm
Those of us that use QEMU may have noticed that a recent update brought the NVMe emulation to version 1.3. With this addition, the NVMe drive now supports sectors sizes that are larger than the default 512-byte sectors.
For example, use similar command line arguments to:
Code: Select all
-drive file=four_k_sects.img,format=raw,if=none,id=ID4096
-device nvme,drive=ID4096,serial=1234,physical_block_size=4096,logical_block_size=4096
At this point, you can't really do anything with it, other than recognizing that the media is using a sector size other than 512 bytes. For example, you actually need a file system that supports different sector sizes.
With gratitude toward him, the author of the LEAN file system has allowed me to work with his file system through its revisions, and I have added a few small details to allow this file system to work on media devices with sector sizes other than 512 bytes. With some tests of my code, I was able to mount and use a LEAN file system formatted with 4096-byte sectors. As long as the sector size is equal to or greater than 512 bytes *and* is a power of two, it works just fine.
The additions I added:
- changed the version to 0x0007 (from 0x0006)
- an indicator byte in the Super Block to compare the physical sector size and the formatted sector size to be sure they match before mount time. (0 = 512, 1 = 1024, 2 = 2048, 3 = 4095, etc)
- specifying that an Indirect Block uses all remaining space in the sector for its extents. (ex: with 512-byte sectors, there is room for 38. With 4096-byte sectors, there is room for 336)
- the Super Block's CRC is calculated on the whole sector, not just the super block data. i.e.: Don't assume 512-byte sectors.
- all remaining space after the INODE and before the end of the sector is used no matter the size of the sector. i.e.: Don't assume 512-byte sectors.
The only thing to consider with the new revisions are that as long as you only use 38 extents in the Indirect, a version 0x0006 driver will handle a version 0x0007 partition just fine and visa-versa. i.e.: I have made no change to the file system other than the specification that the Indirect Block can use all remaining space within the sector for extents. This holds true to either version, though with only one exception:
- The extent count member in the Indirect block now must be a WORD sized member rather than a BYTE sized member. With this in mind, if a version 0x0007 ever writes more than 255 extents to this Indirect Block, then a version 0x0006 driver ever reads the count, it will read an incorrect count. Hence the addition to the Super Block to first verify the size of the sector, and of course the version field.
Back to my point, as far as I know, QEMU and the NVMe is the only form of emulation allowing TRUE emulation of 4096-byte sectors. All other forms of emulation require the physically attached media to support this sector size. (Please correct me if I am wrong, and point me to the means of doing this).
Anyway, you now have a way to test your media and file system drivers with sector sizes other than 512 bytes.
There are some things to remember though.
- You can't boot a Legacy system with the media having a sector size other than 512 bytes. However, you can boot something else first. For example, boot FAT32, as one of the media devices, having an additional NVMe device with one or more namespaces.
- The file system must support a sector size other than 512 bytes. FAT? haha. Good luck. It will have to be something built to allow non-standard sizes.
After getting the Lean author's permission, I will post an updated specification.
Also, I have started the 4096-byte sector function of my image utility as well. It currently allows different sized sectors, though I only tested with a simple LEAN FS partition. It is still experimental.
Thanks,
Ben
- http://www.fysnet.net/osdesign_book_series.htm