Skip to main content

MkfsConfig

Struct MkfsConfig 

Source
pub struct MkfsConfig {
    pub fs_type: FsType,
    pub block_size: u32,
    pub label: Option<String>,
    pub uuid: Option<[u8; 16]>,
    pub journal: bool,
    pub inode_size: u32,
}
Expand description

Configuration for creating an ext4 filesystem.

Fields§

§fs_type: FsType

Filesystem type (ext2, ext3, or ext4)

§block_size: u32

Block size in bytes (1024, 2048, or 4096)

§label: Option<String>

Volume label (max 16 characters)

§uuid: Option<[u8; 16]>

UUID for the filesystem

§journal: bool

Enable journaling (only for ext3/ext4)

§inode_size: u32

Inode size (128 or 256)

Implementations§

Source§

impl MkfsConfig

Source

pub fn new() -> Self

Create a new configuration with default values.

Examples found in repository?
examples/mkfs_file.rs (line 30)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let path = "test_disk.img";
11    let size: u64 = 10 * 1024 * 1024; // 10 MB
12
13    println!("Creating disk image: {} ({} bytes)", path, size);
14
15    // Create and size the file
16    {
17        let mut file = File::create(path)?;
18        file.seek(SeekFrom::Start(size - 1))?;
19        file.write_all(&[0])?;
20        file.sync_all()?;
21    }
22
23    // Open for read/write
24    let file = OpenOptions::new().read(true).write(true).open(path)?;
25
26    // Create block device wrapper (512-byte sectors)
27    let device = IoBlockDevice::new(file, 512, size);
28
29    // Configure and create filesystem
30    let config = MkfsConfig::new()
31        .fs_type(FsType::Ext4)
32        .block_size(4096)
33        .label("test_volume");
34
35    println!("Formatting as ext4...");
36    mkfs(device, config)?;
37
38    println!("Done! You can verify with: file {} or dumpe2fs {}", path, path);
39
40    Ok(())
41}
Source

pub fn fs_type(self, fs_type: FsType) -> Self

Set the filesystem type.

Examples found in repository?
examples/mkfs_file.rs (line 31)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let path = "test_disk.img";
11    let size: u64 = 10 * 1024 * 1024; // 10 MB
12
13    println!("Creating disk image: {} ({} bytes)", path, size);
14
15    // Create and size the file
16    {
17        let mut file = File::create(path)?;
18        file.seek(SeekFrom::Start(size - 1))?;
19        file.write_all(&[0])?;
20        file.sync_all()?;
21    }
22
23    // Open for read/write
24    let file = OpenOptions::new().read(true).write(true).open(path)?;
25
26    // Create block device wrapper (512-byte sectors)
27    let device = IoBlockDevice::new(file, 512, size);
28
29    // Configure and create filesystem
30    let config = MkfsConfig::new()
31        .fs_type(FsType::Ext4)
32        .block_size(4096)
33        .label("test_volume");
34
35    println!("Formatting as ext4...");
36    mkfs(device, config)?;
37
38    println!("Done! You can verify with: file {} or dumpe2fs {}", path, path);
39
40    Ok(())
41}
Source

pub fn block_size(self, size: u32) -> Self

Set the block size.

Examples found in repository?
examples/mkfs_file.rs (line 32)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let path = "test_disk.img";
11    let size: u64 = 10 * 1024 * 1024; // 10 MB
12
13    println!("Creating disk image: {} ({} bytes)", path, size);
14
15    // Create and size the file
16    {
17        let mut file = File::create(path)?;
18        file.seek(SeekFrom::Start(size - 1))?;
19        file.write_all(&[0])?;
20        file.sync_all()?;
21    }
22
23    // Open for read/write
24    let file = OpenOptions::new().read(true).write(true).open(path)?;
25
26    // Create block device wrapper (512-byte sectors)
27    let device = IoBlockDevice::new(file, 512, size);
28
29    // Configure and create filesystem
30    let config = MkfsConfig::new()
31        .fs_type(FsType::Ext4)
32        .block_size(4096)
33        .label("test_volume");
34
35    println!("Formatting as ext4...");
36    mkfs(device, config)?;
37
38    println!("Done! You can verify with: file {} or dumpe2fs {}", path, path);
39
40    Ok(())
41}
Source

pub fn label(self, label: impl Into<String>) -> Self

Set the volume label.

Examples found in repository?
examples/mkfs_file.rs (line 33)
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    let path = "test_disk.img";
11    let size: u64 = 10 * 1024 * 1024; // 10 MB
12
13    println!("Creating disk image: {} ({} bytes)", path, size);
14
15    // Create and size the file
16    {
17        let mut file = File::create(path)?;
18        file.seek(SeekFrom::Start(size - 1))?;
19        file.write_all(&[0])?;
20        file.sync_all()?;
21    }
22
23    // Open for read/write
24    let file = OpenOptions::new().read(true).write(true).open(path)?;
25
26    // Create block device wrapper (512-byte sectors)
27    let device = IoBlockDevice::new(file, 512, size);
28
29    // Configure and create filesystem
30    let config = MkfsConfig::new()
31        .fs_type(FsType::Ext4)
32        .block_size(4096)
33        .label("test_volume");
34
35    println!("Formatting as ext4...");
36    mkfs(device, config)?;
37
38    println!("Done! You can verify with: file {} or dumpe2fs {}", path, path);
39
40    Ok(())
41}
Source

pub fn uuid(self, uuid: [u8; 16]) -> Self

Set the UUID.

Source

pub fn journal(self, enable: bool) -> Self

Enable or disable journaling.

Source

pub fn inode_size(self, size: u32) -> Self

Set the inode size.

Trait Implementations§

Source§

impl Clone for MkfsConfig

Source§

fn clone(&self) -> MkfsConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MkfsConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MkfsConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.