Skip to content

Commit

Permalink
Opt out of unstable feature int_roundings until the naming is settled
Browse files Browse the repository at this point in the history
  • Loading branch information
Blaidd-Drwg committed Oct 31, 2021
1 parent 0adaecf commit 3002e24
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/ext4/block_group.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::mem::{size_of, MaybeUninit};
use std::ops::Range;

use num::Integer;

use crate::bitmap::Bitmap;
use crate::ext4::{
BlockCount, BlockGroupIdx, BlockIdx, BlockSize, Ext4GroupDescriptor, HasSuperBlock, InodeCount, InodeInner,
Expand Down Expand Up @@ -66,7 +68,7 @@ impl<'a> BlockGroup<'a> {
match info.superblock_construction_info {
SuperBlockConstructionInfo::Yes { group_descriptor_count, .. } => {
let gdt_size = size_of::<Ext4GroupDescriptor>() * group_descriptor_count;
let gdt_blocks_count = gdt_size.div_ceil(usize::fromx(info.block_size));
let gdt_blocks_count = gdt_size.div_ceil(&usize::fromx(info.block_size));
let metadata_blocks = std::mem::take(block_group_metadata);
let (gdt_blocks, remaining_blocks) = Self::split_at_block_mut(metadata_blocks, gdt_blocks_count, info);
*block_group_metadata = remaining_blocks;
Expand Down
8 changes: 5 additions & 3 deletions src/ext4/dentry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::convert::TryFrom;
use std::mem::size_of;

use anyhow::{bail, Result};
use num::Integer;

use crate::ext4::InodeNo;

Expand All @@ -23,7 +24,8 @@ pub struct Ext4DentrySized {
}

impl Ext4Dentry {
pub const MAX_LEN: usize = aligned_length(EXT4_NAME_MAX_LEN + size_of::<Ext4DentrySized>(), ALIGNMENT);
// = aligned_length(EXT4_NAME_MAX_LEN + size_of::<Ext4DentrySized>(), ALIGNMENT);
pub const MAX_LEN: usize = EXT4_NAME_MAX_LEN + 1 + size_of::<Ext4DentrySized>();

pub fn new(inode_no: InodeNo, name: String) -> Result<Self> {
// FAT32 allows names up to 255 UCS-2 characters, which may be longer than 255 bytes
Expand Down Expand Up @@ -60,6 +62,6 @@ impl Ext4DentrySized {
}
}

const fn aligned_length(n: usize, alignment: usize) -> usize {
n.next_multiple_of(alignment)
fn aligned_length(n: usize, alignment: usize) -> usize {
n.next_multiple_of(&alignment)
}
24 changes: 11 additions & 13 deletions src/ext4/extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::ops::Range;
use std::slice;

use anyhow::{bail, Context, Result};
use num::Integer;
use static_assertions::const_assert_eq;

use crate::allocator::{AllocatedClusterIdx, Allocator};
Expand Down Expand Up @@ -202,25 +203,22 @@ impl<'a> ExtentTree<'a> {

let mut result = 0;
for level in 1..level_count {
let blocks_in_level = extent_count.div_ceil(extents_per_block.pow(level));
let blocks_in_level = extent_count.div_ceil(&extents_per_block.pow(level));
result += blocks_in_level;
}
result
}

pub fn add_extent(&mut self, extent: Extent) -> Result<Vec<BlockIdx>> {
match self.root.add_extent(extent, self.allocator) {
Ok(allocated_blocks) => Ok(allocated_blocks),
Err(_) => {
let block_for_previous_root = self.make_deeper()?;
let mut allocated_blocks = self
.root
.add_extent(extent, self.allocator)
.expect("Unable to add new extent despite `make_deeper` succeeding");
allocated_blocks.push(block_for_previous_root);
Ok(allocated_blocks)
}
}
self.root.add_extent(extent, self.allocator).or_else(|_| {
let block_for_previous_root = self.make_deeper()?;
let mut allocated_blocks = self
.root
.add_extent(extent, self.allocator)
.expect("Unable to add new extent despite `make_deeper` succeeding");
allocated_blocks.push(block_for_previous_root);
Ok(allocated_blocks)
})
}

fn make_deeper(&mut self) -> Result<BlockIdx> {
Expand Down
9 changes: 5 additions & 4 deletions src/ext4/superblock.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::convert::TryFrom;

use anyhow::{bail, Context, Result};
use num::Integer;
use uuid::Uuid;

use crate::ext4::{
Expand Down Expand Up @@ -220,7 +221,7 @@ impl SuperBlock {
);
}

let block_group_count = data_block_count.div_ceil(BlockCount::fromx(sb.s_blocks_per_group));
let block_group_count = data_block_count.div_ceil(&BlockCount::fromx(sb.s_blocks_per_group));
let block_group_count = BlockGroupCount::try_from(block_group_count)
// This can only happen with absurdly large filesystems in the petabye range
.context("Filesystem too large, it would have more than 2^32 block groups.")?;
Expand Down Expand Up @@ -287,12 +288,12 @@ impl SuperBlock {

fn gdt_block_count(&self) -> BlockCount {
let descriptors_per_gdt_block = self.block_size() / BlockSize::from(self.s_desc_size);
BlockCount::fromx(self.block_group_count().div_ceil(descriptors_per_gdt_block))
BlockCount::fromx(self.block_group_count().div_ceil(&descriptors_per_gdt_block))
}

pub fn inode_table_block_count(&self) -> BlockCount {
let inode_table_size = usize::fromx(self.s_inodes_per_group) * usize::from(self.s_inode_size);
inode_table_size.div_ceil(usize::fromx(self.block_size()))
inode_table_size.div_ceil(&usize::fromx(self.block_size()))
}

pub fn block_size(&self) -> BlockSize {
Expand Down Expand Up @@ -322,7 +323,7 @@ impl SuperBlock {
pub fn block_group_count(&self) -> BlockGroupCount {
let count = self
.block_count_without_padding()
.div_ceil(BlockCount::fromx(self.s_blocks_per_group));
.div_ceil(&BlockCount::fromx(self.s_blocks_per_group));
BlockGroupCount::try_from(count)
.expect("We made sure in `Self::new` that the block group count fits into a u32.")
}
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(step_trait)]
#![feature(iter_advance_by)]
#![feature(int_roundings)]
#![feature(maybe_uninit_extra)]
#![feature(maybe_uninit_slice)]
#![feature(maybe_uninit_write_slice)]
Expand Down Expand Up @@ -49,7 +48,7 @@ const_assert!(size_of::<usize>() <= size_of::<u64>());

fn main() -> Result<()> {
let matches =
App::new("ofs-convert")
App::new("ofs-convert-rs")
.arg(
Arg::with_name("PARTITION_PATH")
.required(true)
Expand Down
4 changes: 2 additions & 2 deletions src/partition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ mod tests {
use std::io::{self, Write};

use itertools::Itertools;
use tempfile::NamedTempFile;
use rand::distributions::Standard;
use rand::{self, Rng};
use rand::distributions::{Standard};
use tempfile::NamedTempFile;

use super::*;

Expand Down
2 changes: 1 addition & 1 deletion src/serialization/stream_archiver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'a> StreamArchiver<'a> {
}

/// SAFETY: Only safe if consistent with the preceding header. I.e. either:
/// 1) The preceding header `h` is followed by `h.len` objects. Then `object must be of type `Header`; or
/// 1) The preceding header `h` is followed by `h.len` objects. Then `object` must be of type `Header`; or
/// 2) The preceding header `h` is followed by fewer than `h.len` objects. Then `T` must have the ID `h.type_id`.
/// PANICS: Panics if `size_of::<Option<PageIdx>>() + size_of::<T>() > self.page_size`
unsafe fn add_object<T>(&mut self, object: T) -> Result<()> {
Expand Down

0 comments on commit 3002e24

Please sign in to comment.