Skip to content

High-Speed Direct Block Copy & Imaging

fparted includes a high-performance native C engine (fparted_copy_jni.c) and Dart FFI/Platform Channel bindings to perform multi-gigabyte block device imaging, partition replication, and whole-disk backups.


⚡ Direct I/O Block Engine

The native copying pipeline is implemented in optimized C with POSIX system primitives:

flowchart LR
    Src[Source Block Device /dev/block/sda] -->|open O_RDONLY| C[Native C Worker]
    C -->|posix_fadvise POSIX_FADV_SEQUENTIAL| Kernel[Linux VFS]
    C -->|4MiB Direct Memory Buffer| Dst[Destination Image / Partition]
    C -->|ioctl BLKGETSIZE64 / fstat| Size[Exact Capacity Check]
    C -->|fallocate| Prealloc[Preallocate Destination Space]
    C -->|pthread Cancellation Flag| Progress[Stream Speed & Percentage to Flutter UI]

Engine Features

  • 4 MiB Page-Aligned Buffers: Maximizes throughput across NVMe, UFS 3.1/4.0, and USB 3.2 buses.
  • Sequential Read Optimization: Uses posix_fadvise(..., POSIX_FADV_SEQUENTIAL) to instruct the kernel read-ahead logic.
  • Cooperative Cancellation: Checks atomic cancellation handles between buffer cycles to cleanly abort operations without leaving half-written locks.
  • Sync on Completion: Calls fsync() / fdatasync() before reporting completion to ensure dirty buffers are flushed to non-volatile storage.

💾 Whole-Disk & Partition Image Dumps (SAF)

The Dump Disk feature integrates with Android's Storage Access Framework (SAF): 1. User picks target destination directory or OTG storage. 2. App requests native document creation URI. 3. Streams block-level data directly to raw .img image files. 4. Provides real-time bandwidth indicators (KiB/s, MiB/s, GiB/s) and estimated time remaining.