@@ -25,7 +25,8 @@ extension EXT4 {
2525 /// The `EXT4.Formatter` class provides methods to format a block device with the ext4 filesystem.
2626 /// It allows customization of block size and maximum disk size.
2727 public class Formatter {
28- let blockSize : UInt32
28+ private let logBlockSize : UInt32 = 2
29+ var blockSize : UInt32 { 1024 << logBlockSize }
2930 private var size : UInt64
3031 private let groupDescriptorSize : UInt32 = 32
3132
@@ -61,8 +62,6 @@ extension EXT4 {
6162 ///
6263 /// - Parameters:
6364 /// - devicePath: The path to the block device where the ext4 filesystem will be created.
64- /// - blockSize: The block size of the ext4 filesystem, specified in bytes. Common values are
65- /// 4096 (4KB) or 1024 (1KB). Default is 4096 (4KB)
6665 /// - minDiskSize: The minimum disk size required for the formatted filesystem.
6766 ///
6867 /// - Note: This ext4 formatter is designed for creating block devices out of container images and does not support all the
@@ -71,7 +70,7 @@ extension EXT4 {
7170 ///
7271 /// - Important: Ensure that the destination block device is accessible and has sufficient permissions
7372 /// for formatting. The formatting process will erase all existing data on the device.
74- public init ( _ devicePath: FilePath , blockSize : UInt32 = 4096 , minDiskSize: UInt64 = 256 . kib ( ) ) throws {
73+ public init ( _ devicePath: FilePath , minDiskSize: UInt64 = 256 . kib ( ) ) throws {
7574 /// The constructor performs the following steps:
7675 ///
7776 /// 1. Creates the first 10 inodes:
@@ -96,7 +95,6 @@ extension EXT4 {
9695 throw Error . notFound ( devicePath)
9796 }
9897 self . handle = fileHandle
99- self . blockSize = blockSize
10098 self . size = minDiskSize
10199 // make this a 0 byte file
102100 guard ftruncate ( self . handle. fileDescriptor, 0 ) == 0 else {
@@ -850,8 +848,8 @@ extension EXT4 {
850848 let freeInodesCount = computedInodes. lo - totalInodes
851849 superblock. freeInodesCount = freeInodesCount
852850 superblock. firstDataBlock = 0
853- superblock. logBlockSize = 2
854- superblock. logClusterSize = 2
851+ superblock. logBlockSize = logBlockSize
852+ superblock. logClusterSize = logBlockSize
855853 superblock. blocksPerGroup = self . blocksPerGroup
856854 superblock. clustersPerGroup = self . blocksPerGroup
857855 superblock. inodesPerGroup = blockGroupSize. inodesPerGroup
0 commit comments