Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

29 changes: 0 additions & 29 deletions issues/a-stop-mid-append-leaves-a-fat-volume-s-leak-for-ever.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ among them, so the commit makes durable an entry whose new extents name
blocks that never received its pages. In the same boot the file still reads
right: its pages stay dirty in its object and the next sync tries them
again. After a stop before that, it reads what those blocks last held,
which may be a deleted file's bytes
(`issues/a-reallocated-extent-on-data-keeps-the-deleted-files-bytes.md`).
which may be a deleted file's bytes.

An fsync does not: a carried file whose pages are refused refuses the
commit (`Files::fsync`).
Expand Down
21 changes: 0 additions & 21 deletions issues/a-write-back-the-device-refused-waits-for-the-next-write.md

This file was deleted.

34 changes: 0 additions & 34 deletions issues/nothing-reclaims-what-a-stop-leaves-on-a-fat-volume.md

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 7 additions & 1 deletion lib/fat32/src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ impl DirScan {
}
}

/// Entries read so far: the end marker or the chain's end, once
/// [`Self::next`] has answered `None`.
pub(crate) fn scanned(&self) -> u32 {
self.index
}

fn drop_run(&mut self) {
self.run_valid = false;
self.run_units = 0;
Expand Down Expand Up @@ -589,7 +595,7 @@ impl<D: BlockDev> Fat32<D> {
/// What a `..` entry must name for a given parent. Zero when the parent is
/// the root, which is what the format requires and what `fsck` checks: the
/// root has no cluster number a `..` entry may name.
fn dotdot_target(&self, parent: Cluster) -> u32 {
pub(crate) fn dotdot_target(&self, parent: Cluster) -> u32 {
if parent == self.geometry().root() { 0 } else { parent.raw() }
}

Expand Down
4 changes: 2 additions & 2 deletions lib/fat32/src/fat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub(crate) const END_OF_CHAIN: u32 = 0x0FFF_FFFF;
/// A FAT32 entry is 28 bits. The top four belong to whoever formatted the
/// volume and are preserved across every write, which is why `set_fat_entry`
/// reads before it writes.
const ENTRY_MASK: u32 = 0x0FFF_FFFF;
pub(crate) const ENTRY_MASK: u32 = 0x0FFF_FFFF;

impl<D: BlockDev> Fat32<D> {
/// One FAT entry, masked to its 28 significant bits.
Expand Down Expand Up @@ -49,7 +49,7 @@ impl<D: BlockDev> Fat32<D> {

/// One FAT copy's entry, preserving the four reserved high bits the format
/// leaves to whoever made the volume.
async fn write_fat_entry(&mut self, fat: u32, cluster: Cluster, value: u32) -> Result<(), Error> {
pub(crate) async fn write_fat_entry(&mut self, fat: u32, cluster: Cluster, value: u32) -> Result<(), Error> {
let offset = self.geom.fat_entry_offset(fat, cluster);
let mut raw = [0u8; 4];
self.dev.read_at(offset, &mut raw).await?;
Expand Down
23 changes: 23 additions & 0 deletions lib/fat32/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ impl<D: BlockDev> Fat32<D> {
/// the handle once the repair carries the shrink: a refusal before that
/// has written nothing, and the handle's old size is what makes the retry
/// shrink again.
///
/// **The entry stops naming the clusters before they are freed**, so a
/// stop between the two leaks them and never leaves an entry naming free
/// space.
async fn shrink_chain(&mut self, f: &mut File, len: u64) -> Result<(), Error> {
let bpc = self.geom.bytes_per_cluster() as u64;
let keep = len.div_ceil(bpc);
Expand All @@ -831,6 +835,23 @@ impl<D: BlockDev> Fat32<D> {
// part of a chain and frees the rest, and a loop between the two
// halves is how live clusters reach the allocator.
self.verify_acyclic(first).await?;
let unnamed = keep == 0 && f.entry_cluster.is_some();
if f.entry_size as u64 > len || unnamed {
let mut raw = self.live_entry(f).await?;
if keep == 0 {
raw.set_first_cluster(0);
}
raw.set_size(len as u32);
let mark = self.repair.len();
self.write_entry_at(f.loc.entry_offset, &raw).await?;
self.dev.flush().await?;
// Landed: the free that follows only goes forward.
self.repair.truncate(mark);
f.entry_size = len as u32;
if keep == 0 {
f.entry_cluster = None;
}
}
if keep == 0 {
f.first_cluster = None;
f.size = len as u32;
Expand Down Expand Up @@ -1068,6 +1089,7 @@ impl<D: BlockDev> Fat32<D> {
/// up to the last erase, carried forward from it by [`Self::atomic`].
async fn erase_committed(&mut self, loc: Loc, chain: Option<Cluster>) -> Result<(), Error> {
self.erase_entries(loc).await?;
self.dev.flush().await?;
self.commit();
if let Some(c) = chain {
self.queue(Repair::Free { start: c, anchor: None });
Expand Down Expand Up @@ -1102,6 +1124,7 @@ impl<D: BlockDev> Fat32<D> {
}

self.insert_entry(new_dir, &new_name, &node.raw).await?;
self.dev.flush().await?;
self.erase_entries(loc).await?;
if let Some(c) = moved_dir {
if new_dir != loc.dir_start {
Expand Down
2 changes: 2 additions & 0 deletions lib/fat32/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mod error;
mod fat;
mod fs;
mod name;
mod recover;
mod repair;
mod time;

Expand All @@ -90,5 +91,6 @@ pub use dir::MAX_DIR_ENTRIES;
pub use error::Error;
pub use fs::{DirEntry, Extent, Fat32, File, Metadata, ReplaceFailed, Replaced};
pub use name::MAX_LFN_CHARS;
pub use recover::{Recovered, Recovery};
pub use repair::MAX_REPAIR_STEPS;
pub use time::FatTime;
Loading
Loading