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
13 changes: 10 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ pub(crate) enum CorruptKind {
/// Absolute block index.
block_index: u64,

/// Absolute block index, without remapping from the journal. If
/// this block was not remapped by the journal, this field will
/// be the same as `block_index`.
original_block_index: u64,

/// Offset in bytes within the block.
offset_within_block: u32,

Expand Down Expand Up @@ -464,12 +469,13 @@ impl Display for CorruptKind {
}
Self::BlockRead {
block_index,
original_block_index,
offset_within_block,
read_len,
} => {
write!(
f,
"invalid read of length {read_len} from block {block_index} at offset {offset_within_block}"
"invalid read of length {read_len} from block {block_index} (originally {original_block_index}) at offset {offset_within_block}"
)
}
}
Expand Down Expand Up @@ -629,19 +635,20 @@ mod tests {
fn test_corrupt_format() {
let err: Ext4Error = CorruptKind::BlockRead {
block_index: 123,
original_block_index: 124,
offset_within_block: 456,
read_len: 789,
}
.into();

assert_eq!(
format!("{err}"),
"corrupt filesystem: invalid read of length 789 from block 123 at offset 456"
"corrupt filesystem: invalid read of length 789 from block 123 (originally 124) at offset 456"
);

assert_eq!(
format!("{err:?}"),
"Corrupt(BlockRead { block_index: 123, offset_within_block: 456, read_len: 789 })"
"Corrupt(BlockRead { block_index: 123, original_block_index: 124, offset_within_block: 456, read_len: 789 })"
);
}

Expand Down
8 changes: 5 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,20 +291,21 @@ impl Ext4 {
/// error is returned.
fn read_from_block(
&self,
block_index: u64,
original_block_index: u64,
offset_within_block: u32,
dst: &mut [u8],
) -> Result<(), Ext4Error> {
let block_index = self.0.journal.map_block_index(original_block_index);

let err = || {
Ext4Error::from(CorruptKind::BlockRead {
block_index,
original_block_index,
offset_within_block,
read_len: dst.len(),
})
};

let block_index = self.0.journal.map_block_index(block_index);

// The first 1024 bytes are reserved for non-filesystem
// data. This conveniently allows for something like a null
// pointer check.
Expand Down Expand Up @@ -681,6 +682,7 @@ mod tests {
) -> CorruptKind {
CorruptKind::BlockRead {
block_index,
original_block_index: block_index,
offset_within_block,
read_len,
}
Expand Down
Loading