Skip to content

Commit 73fca90

Browse files
committed
Add sync_on_write option
- Add sync_on_write parameter to Fat32Volume::open() for controlling file synchronization - Enable sync_on_write for real devices to ensure data safety - Disable sync_on_write for image files to improve performance - Improve data integrity handling for different storage types
1 parent bc6a336 commit 73fca90

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/fat32.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ pub fn read_bpb(file: &mut std::fs::File, offset: u64) -> std::io::Result<Fat32P
4545
}
4646

4747
pub struct Fat32Volume {
48+
sync_on_write: bool,
4849
file: File,
4950
fat_offset: u64,
5051
data_offset: u64,
@@ -56,6 +57,7 @@ pub struct Fat32Volume {
5657

5758
impl Fat32Volume {
5859
pub fn open(
60+
sync_on_write: bool,
5961
device_path: &str,
6062
esp_start_lba: u64,
6163
bytes_per_sector: u16,
@@ -87,6 +89,7 @@ impl Fat32Volume {
8789
* bytes_per_sector_u64;
8890

8991
Ok(Fat32Volume {
92+
sync_on_write,
9093
file,
9194
fat_offset,
9295
data_offset,
@@ -239,6 +242,9 @@ impl Fat32Volume {
239242
fn flush_fat(&mut self) -> io::Result<()> {
240243
self.file.seek(SeekFrom::Start(self.fat_offset))?;
241244
self.file.write_all(&self.fat)?;
245+
if self.sync_on_write {
246+
self.file.sync_all()?;
247+
}
242248
Ok(())
243249
}
244250

@@ -633,6 +639,7 @@ impl Fat32Volume {
633639
}
634640

635641
Fat32Volume::open(
642+
false,
636643
path_str,
637644
0, // lba = 0 для образа
638645
params.bytes_per_sector,
@@ -687,6 +694,7 @@ impl Fat32Volume {
687694
}
688695

689696
Fat32Volume::open(
697+
true, // sync_on_write = true для реальных устройств (безопаснее)
690698
&path,
691699
lba, // LBA
692700
params.bytes_per_sector,

0 commit comments

Comments
 (0)