Skip to content
Open
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
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/block/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ where
let count = core::cmp::min(bg.blocks_count as usize - ofs, size);
trans.block_deallocation_on_bg(ino, bgid, bg.block_bitmap_lba, ofs, count);
size -= count;
lba = lba + (count as u64);
lba += count as u64;
}
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions src/block/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,15 @@ impl<C: Config, const BLK_SIZE: usize> Manager<C, BLK_SIZE> {
pub(crate) fn get_mut_noload<'l, 'j>(
&'l self,
lba: LogicalBlockNumber,
collector: &'j Collector,
collector: Option<&'j Collector>,
) -> Result<BlockRef<'l, 'j, C, BLK_SIZE, true>, FsError>
where
'l: 'j,
{
let mut created = false;
collector.track(lba);
if let Some(collector) = collector {
collector.track(lba);
}
Ok(self
.blocks
.get_or_insert_arc::<_, ()>(lba, |_| {
Expand Down
6 changes: 3 additions & 3 deletions src/block_group/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl<const BLK_SIZE: usize> BlockGroup<BLK_SIZE> {
if flags.contains(BlockGroupFlag::BLOCK_UNINIT) {
let bref = fs
.blocks
.get_mut_noload(self.block_bitmap_lba, &tx.collector)?;
.get_mut_noload(self.block_bitmap_lba, Some(&tx.collector))?;
let mut guard = bref.write();
let mut block_bitmap = ByteRw::new(guard.as_mut());
let mut base = (fs.sb.first_data_block as u64 + desc_blocks) as usize + 1;
Expand All @@ -204,7 +204,7 @@ impl<const BLK_SIZE: usize> BlockGroup<BLK_SIZE> {
if flags.contains(BlockGroupFlag::INODE_UNINIT) {
let bref = fs
.blocks
.get_mut_noload(self.inode_bitmap_lba, &tx.collector)?;
.get_mut_noload(self.inode_bitmap_lba, Some(&tx.collector))?;

let mut guard = bref.write();
ByteRw::new(guard.as_mut()).set_bitmap(fs.sb.inodes_per_group as usize..BLK_SIZE * 8);
Expand All @@ -214,7 +214,7 @@ impl<const BLK_SIZE: usize> BlockGroup<BLK_SIZE> {
..self.inode_table_first_block.0 + inode_blocks)
.map(LogicalBlockNumber)
{
let _ = fs.blocks.get_mut_noload(lba, &tx.collector)?;
let _ = fs.blocks.get_mut_noload(lba, Some(&tx.collector))?;
}
nflags.insert(BlockGroupFlag::ITABLE_ZEROED);
}
Expand Down
6 changes: 4 additions & 2 deletions src/directory/htree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl<
// Allocate new block.
let (dx_fba, new_blk) = dispatch_cursor_last_mut!(inode, fs, tx, |mut c| {
let lba = c.or_allocated(false).unwrap();
(c.fba(), fs.blocks.get_mut_noload(lba, &tx.collector)?)
(c.fba(), fs.blocks.get_mut_noload(lba, Some(&tx.collector))?)
});

let size = inode.get_size();
Expand Down Expand Up @@ -637,7 +637,9 @@ impl<
DirectoryBlock::new(&mut **blk.write(), fs).clear();
}
inode.set_size(BLK_SIZE as u64 * 2, tx);
let raw = fs.blocks.get_mut_noload(root_block_addr, &tx.collector)?;
let raw = fs
.blocks
.get_mut_noload(root_block_addr, Some(&tx.collector))?;

{
let mut guard = raw.write();
Expand Down
2 changes: 1 addition & 1 deletion src/directory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl<C: Config, const BLK_SIZE: usize> Directory<C, BLK_SIZE> {

#[cfg(test)]
mod tests {
use crate::tests::run_test;
use crate::std::tests::run_test;
use crate::FileType;

#[test]
Expand Down
7 changes: 4 additions & 3 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl<C: Config, const BLK_SIZE: usize> File<C, BLK_SIZE> {

#[cfg(test)]
mod tests {
use crate::tests::run_test;
use crate::std::tests::run_test;
use crate::FileType;

#[test]
Expand All @@ -231,8 +231,9 @@ mod tests {

#[test]
fn write_big() {
// const SIZE: usize = 4 * 1024 *1024 * 1024;
// const SIZE: usize = 4 * 1024 * 1024 * 1024;
const SIZE: usize = 256 * 1024 * 1024;
// const SIZE: usize = 16 * 1024 * 1024 * 1024;
run_test(
|fs| {
let buf = Box::new([0; 4096]);
Expand All @@ -251,7 +252,7 @@ mod tests {
println!("wb");
tx.done(&fs).unwrap();
},
(SIZE as u64) / 1024 / 1024 + 100,
(SIZE as u64) / 1024 / 1024 + 1000,
);
}
}
63 changes: 58 additions & 5 deletions src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl<'a> FormatAux<'a> {
feat_ro: Ext4FeatureReadOnly::SPARSE_SUPER
| Ext4FeatureReadOnly::LARGE_FILE
| Ext4FeatureReadOnly::GDT_CSUM,
feat_com: Ext4FeatureCompatible::DIR_INDEX,
feat_com: Ext4FeatureCompatible::DIR_INDEX, // ### No journal disk
// feat_com: Ext4FeatureCompatible::DIR_INDEX | Ext4FeatureCompatible::HAS_JOURNAL, // ### Has journal disk
feat_incom: Ext4FeatureIncompatible::FILETYPE | Ext4FeatureIncompatible::EXTENTS,
uuid,
volumn_name,
Expand Down Expand Up @@ -117,6 +118,10 @@ fn make_sb<C: Config, const BLK_SIZE: usize>(
sb.first_inode().set(11);
sb.inode_size().set(256);

if feat_com.contains(Ext4FeatureCompatible::HAS_JOURNAL) {
sb.journal_inum().set(8); // ### Journal inode number = 8
}

sb.rw.b.as_mut()[0x68..0x78].copy_from_slice(uuid);
sb.rw.b.as_mut()[0x78..0x88].copy_from_slice(volumn_name);
sb.rw.b.as_mut()[0xEC..0xFC].copy_from_slice(hash_seed);
Expand Down Expand Up @@ -183,9 +188,19 @@ fn fill_bg<C: Config, const BLK_SIZE: usize>(
.as_mut(),
);
if bgid.0 == 0 {
// ino 2 -> Root, ino 8 -> Journal
inode_bitmap.set_bitmap(0..1);
inode_bitmap.set_bitmap(2..10);
free_inodes -= 9;
if sb
.features_compatible
.contains(Ext4FeatureCompatible::HAS_JOURNAL)
{
inode_bitmap.set_bitmap(2..7);
inode_bitmap.set_bitmap(8..10);
free_inodes -= 8;
} else {
inode_bitmap.set_bitmap(2..10);
free_inodes -= 9;
}
}
// Set end of inode bitmap. kill 1) unusable 2) padding.
inode_bitmap.set_bitmap(sb.inodes_per_group as usize..BLK_SIZE * 8);
Expand Down Expand Up @@ -267,6 +282,39 @@ fn fill_bg<C: Config, const BLK_SIZE: usize>(
Ok(())
}

pub fn make_journal_disk<C: Config, const BLK_SIZE: usize>(
fs: &Arc<FileSystem<C, BLK_SIZE>>,
) -> Result<(), FsError> {
if !fs
.sb
.features_compatible
.contains(Ext4FeatureCompatible::HAS_JOURNAL)
{
// No journal disk
return Ok(());
}
let journal_inum = 8;
let ino = fs
.inodes
.allocator
.try_allocate_at(journal_inum, fs)?
.unwrap();
let tx = fs.open_transaction();
let guard = fs.get_block_group(BlockGroupId(0))?;
let bg = guard.as_ref().unwrap();
let de = FileType::Directory;

bg.allocate_inode_on_bg(journal_inum - 1, &tx, de);
fs.sb.dec_free_inodes_count(&tx);
let _inode = fs
.inodes
.inodes
.get_or_insert::<_, ()>(ino, |ino| Ok(Inode::new(fs, ino, de)))
.unwrap();

tx.done(fs)
}

fn make_root<C: Config, const BLK_SIZE: usize>(
fs: &Arc<FileSystem<C, BLK_SIZE>>,
) -> Result<(), FsError> {
Expand Down Expand Up @@ -317,15 +365,20 @@ pub fn format<C: Config, const BLK_SIZE: usize>(
);
let mut sb = make_sb::<C, BLK_SIZE>(aux);
fill_bg(&dev, &mut sb)?;
dev.write_bytes(1024, &sb.manipulator.lock().rw.inner().0)?;
const BUFSIZE: usize = 1024;
let mut buf = C::Buffer::<BUFSIZE>::zeroed();
buf.as_mut()[0..BUFSIZE]
.copy_from_slice(sb.manipulator.lock().rw.inner().0[0..BUFSIZE].as_ref());
dev.write_bytes(1024, &buf)?;
let fs = FileSystem::<C, BLK_SIZE>::new(dev, sb);
make_journal_disk(&fs)?;
make_root(&fs)?;
Ok(fs)
}

#[cfg(test)]
mod tests {
use crate::tests::{make_disk, test_oracle};
use crate::std::tests::{make_disk, test_oracle};

const M: u64 = 1024 * 1024;
const G: u64 = 1024 * 1024 * 1024;
Expand Down
2 changes: 1 addition & 1 deletion src/inode/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl<C: Config> Allocator<C> {
loop {
// CAS to get bits.
let val = bits.load(Ordering::Relaxed);
let x = val ^ core::u8::MAX;
let x = val ^ u8::MAX;
if x != 0 {
// toggle all bits.
let (mask, ret) = {
Expand Down
2 changes: 1 addition & 1 deletion src/inode/extent/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ where
for i in 0..len {
self.fs
.blocks
.get_mut_noload(n + (i as u64), &self.tx.collector)?;
.get_mut_noload(n + (i as u64), Some(&self.tx.collector))?;
}
}

Expand Down
Loading