ext4_lwext4/lib.rs
1//! A safe Rust wrapper for ext2/3/4 filesystem operations based on lwext4.
2//!
3//! This crate provides a high-level, idiomatic Rust API for working with ext2, ext3,
4//! and ext4 filesystems. It wraps the lwext4 C library, providing memory safety and
5//! ergonomic interfaces.
6//!
7//! # Features
8//!
9//! - Create ext2/3/4 filesystems with `mkfs`
10//! - Mount and unmount filesystems
11//! - File operations: create, read, write, truncate, seek
12//! - Directory operations: create, remove, iterate
13//! - Symbolic and hard links
14//! - File metadata and permissions
15//! - Block device abstraction for various backing stores
16//!
17//! # Example
18//!
19//! ```no_run
20//! use ext4_lwext4::{mkfs, Ext4Fs, MkfsOptions, OpenFlags, FileBlockDevice};
21//! use std::io::{Read, Write};
22//!
23//! // Create a disk image
24//! let mut device = FileBlockDevice::create("disk.img", 100 * 1024 * 1024).unwrap();
25//!
26//! // Format as ext4
27//! mkfs(device, &MkfsOptions::default()).unwrap();
28//!
29//! // Reopen and mount
30//! let device = FileBlockDevice::open("disk.img").unwrap();
31//! let fs = Ext4Fs::mount(device, false).unwrap();
32//!
33//! // Create a directory
34//! fs.mkdir("/data", 0o755).unwrap();
35//!
36//! // Write a file
37//! {
38//! let mut file = fs.open("/data/hello.txt", OpenFlags::CREATE | OpenFlags::WRITE).unwrap();
39//! file.write_all(b"Hello, ext4!").unwrap();
40//! }
41//!
42//! // Read it back
43//! {
44//! let mut file = fs.open("/data/hello.txt", OpenFlags::READ).unwrap();
45//! let mut content = String::new();
46//! file.read_to_string(&mut content).unwrap();
47//! println!("Content: {}", content);
48//! }
49//!
50//! // List directory
51//! for entry in fs.open_dir("/data").unwrap() {
52//! let entry = entry.unwrap();
53//! println!("{}: {:?}", entry.name(), entry.file_type());
54//! }
55//!
56//! // Unmount
57//! fs.umount().unwrap();
58//! ```
59//!
60//! # Block Devices
61//!
62//! The crate provides several block device implementations:
63//!
64//! - [`FileBlockDevice`]: Backed by a file (disk image)
65//! - [`MemoryBlockDevice`]: In-memory storage (for testing/embedded)
66//!
67//! You can implement the [`BlockDevice`] trait for custom storage backends.
68
69pub mod blockdev;
70pub mod dir;
71pub mod error;
72pub mod file;
73pub mod fs;
74pub mod mkfs;
75pub mod types;
76
77// Re-export main types at crate root
78pub use blockdev::{BlockDevice, BlockDeviceExt, FileBlockDevice, MemoryBlockDevice};
79pub use dir::{Dir, DirEntry};
80pub use error::{Error, Result};
81pub use file::File;
82pub use fs::Ext4Fs;
83pub use mkfs::{mkfs, MkfsOptions};
84pub use types::{FileType, FsStats, FsType, Metadata, OpenFlags, SeekFrom};