Skip to content

Commit 0a6f392

Browse files
Allow loading filesystems with the recovery bit
This is the final step of enabling journal support. Since the test filesystem can now be loaded, this commit also adds some tests.
1 parent 5c0c7fa commit 0a6f392

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
* Added `Ext4::uuid` to get the filesystem UUID.
2929
* Made the `Corrupt` type opaque. It is no longer possible to `match` on
3030
specific types of corruption.
31+
* Added support for reading filesystems that weren't cleanly unmounted.
3132

3233
## 0.7.0
3334

src/journal.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,24 @@ impl Journal {
5959
*self.block_map.get(&block_index).unwrap_or(&block_index)
6060
}
6161
}
62+
63+
#[cfg(all(test, feature = "std"))]
64+
mod tests {
65+
use crate::test_util::load_compressed_filesystem;
66+
use alloc::rc::Rc;
67+
68+
#[test]
69+
fn test_journal() {
70+
let mut fs =
71+
load_compressed_filesystem("test_disk_4k_block_journal.bin.zst");
72+
73+
let test_dir = "/dir500";
74+
75+
// With the journal in place, this directory exists.
76+
assert!(fs.exists(test_dir).unwrap());
77+
78+
// Clear the journal, and verify that the directory no longer exists.
79+
Rc::get_mut(&mut fs.0).unwrap().journal.block_map.clear();
80+
assert!(!fs.exists(test_dir).unwrap());
81+
}
82+
}

src/journal/superblock.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,28 @@ fn check_incompat_features(
197197
#[cfg(all(test, feature = "std"))]
198198
mod tests {
199199
use super::*;
200+
use crate::test_util::load_compressed_filesystem;
201+
202+
#[test]
203+
fn test_load_journal_superblock() {
204+
let fs =
205+
load_compressed_filesystem("test_disk_4k_block_journal.bin.zst");
206+
let journal_inode =
207+
Inode::read(&fs, fs.0.superblock.journal_inode.unwrap()).unwrap();
208+
let superblock = JournalSuperblock::load(&fs, &journal_inode).unwrap();
209+
assert_eq!(
210+
superblock,
211+
JournalSuperblock {
212+
block_size: 4096,
213+
sequence: 3,
214+
start_block: 289,
215+
uuid: Uuid([
216+
0x6c, 0x48, 0x4f, 0x1b, 0x7f, 0x71, 0x47, 0x4c, 0xa1, 0xf9,
217+
0x3b, 0x50, 0x0c, 0xc1, 0xe2, 0x74
218+
]),
219+
}
220+
);
221+
}
200222

201223
fn write_u32be(bytes: &mut [u8], offset: usize, value: u32) {
202224
bytes[offset..offset + 4].copy_from_slice(&value.to_be_bytes());

src/superblock.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ fn check_incompat_features(
201201
// relax some of these in the future.
202202
let required_features = IncompatibleFeatures::FILE_TYPE_IN_DIR_ENTRY;
203203
let disallowed_features = IncompatibleFeatures::COMPRESSION
204-
| IncompatibleFeatures::RECOVERY
205204
| IncompatibleFeatures::SEPARATE_JOURNAL_DEVICE
206205
| IncompatibleFeatures::META_BLOCK_GROUPS
207206
| IncompatibleFeatures::MULTIPLE_MOUNT_PROTECTION

0 commit comments

Comments
 (0)