Skip to content

Commit 3002e24

Browse files
committed
Opt out of unstable feature int_roundings until the naming is settled
See rust-lang/rust#89184
1 parent 0adaecf commit 3002e24

File tree

7 files changed

+28
-26
lines changed

7 files changed

+28
-26
lines changed

src/ext4/block_group.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::mem::{size_of, MaybeUninit};
22
use std::ops::Range;
33

4+
use num::Integer;
5+
46
use crate::bitmap::Bitmap;
57
use crate::ext4::{
68
BlockCount, BlockGroupIdx, BlockIdx, BlockSize, Ext4GroupDescriptor, HasSuperBlock, InodeCount, InodeInner,
@@ -66,7 +68,7 @@ impl<'a> BlockGroup<'a> {
6668
match info.superblock_construction_info {
6769
SuperBlockConstructionInfo::Yes { group_descriptor_count, .. } => {
6870
let gdt_size = size_of::<Ext4GroupDescriptor>() * group_descriptor_count;
69-
let gdt_blocks_count = gdt_size.div_ceil(usize::fromx(info.block_size));
71+
let gdt_blocks_count = gdt_size.div_ceil(&usize::fromx(info.block_size));
7072
let metadata_blocks = std::mem::take(block_group_metadata);
7173
let (gdt_blocks, remaining_blocks) = Self::split_at_block_mut(metadata_blocks, gdt_blocks_count, info);
7274
*block_group_metadata = remaining_blocks;

src/ext4/dentry.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::convert::TryFrom;
22
use std::mem::size_of;
33

44
use anyhow::{bail, Result};
5+
use num::Integer;
56

67
use crate::ext4::InodeNo;
78

@@ -23,7 +24,8 @@ pub struct Ext4DentrySized {
2324
}
2425

2526
impl Ext4Dentry {
26-
pub const MAX_LEN: usize = aligned_length(EXT4_NAME_MAX_LEN + size_of::<Ext4DentrySized>(), ALIGNMENT);
27+
// = aligned_length(EXT4_NAME_MAX_LEN + size_of::<Ext4DentrySized>(), ALIGNMENT);
28+
pub const MAX_LEN: usize = EXT4_NAME_MAX_LEN + 1 + size_of::<Ext4DentrySized>();
2729

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

63-
const fn aligned_length(n: usize, alignment: usize) -> usize {
64-
n.next_multiple_of(alignment)
65+
fn aligned_length(n: usize, alignment: usize) -> usize {
66+
n.next_multiple_of(&alignment)
6567
}

src/ext4/extent.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ops::Range;
44
use std::slice;
55

66
use anyhow::{bail, Context, Result};
7+
use num::Integer;
78
use static_assertions::const_assert_eq;
89

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

203204
let mut result = 0;
204205
for level in 1..level_count {
205-
let blocks_in_level = extent_count.div_ceil(extents_per_block.pow(level));
206+
let blocks_in_level = extent_count.div_ceil(&extents_per_block.pow(level));
206207
result += blocks_in_level;
207208
}
208209
result
209210
}
210211

211212
pub fn add_extent(&mut self, extent: Extent) -> Result<Vec<BlockIdx>> {
212-
match self.root.add_extent(extent, self.allocator) {
213-
Ok(allocated_blocks) => Ok(allocated_blocks),
214-
Err(_) => {
215-
let block_for_previous_root = self.make_deeper()?;
216-
let mut allocated_blocks = self
217-
.root
218-
.add_extent(extent, self.allocator)
219-
.expect("Unable to add new extent despite `make_deeper` succeeding");
220-
allocated_blocks.push(block_for_previous_root);
221-
Ok(allocated_blocks)
222-
}
223-
}
213+
self.root.add_extent(extent, self.allocator).or_else(|_| {
214+
let block_for_previous_root = self.make_deeper()?;
215+
let mut allocated_blocks = self
216+
.root
217+
.add_extent(extent, self.allocator)
218+
.expect("Unable to add new extent despite `make_deeper` succeeding");
219+
allocated_blocks.push(block_for_previous_root);
220+
Ok(allocated_blocks)
221+
})
224222
}
225223

226224
fn make_deeper(&mut self) -> Result<BlockIdx> {

src/ext4/superblock.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::convert::TryFrom;
22

33
use anyhow::{bail, Context, Result};
4+
use num::Integer;
45
use uuid::Uuid;
56

67
use crate::ext4::{
@@ -220,7 +221,7 @@ impl SuperBlock {
220221
);
221222
}
222223

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

288289
fn gdt_block_count(&self) -> BlockCount {
289290
let descriptors_per_gdt_block = self.block_size() / BlockSize::from(self.s_desc_size);
290-
BlockCount::fromx(self.block_group_count().div_ceil(descriptors_per_gdt_block))
291+
BlockCount::fromx(self.block_group_count().div_ceil(&descriptors_per_gdt_block))
291292
}
292293

293294
pub fn inode_table_block_count(&self) -> BlockCount {
294295
let inode_table_size = usize::fromx(self.s_inodes_per_group) * usize::from(self.s_inode_size);
295-
inode_table_size.div_ceil(usize::fromx(self.block_size()))
296+
inode_table_size.div_ceil(&usize::fromx(self.block_size()))
296297
}
297298

298299
pub fn block_size(&self) -> BlockSize {
@@ -322,7 +323,7 @@ impl SuperBlock {
322323
pub fn block_group_count(&self) -> BlockGroupCount {
323324
let count = self
324325
.block_count_without_padding()
325-
.div_ceil(BlockCount::fromx(self.s_blocks_per_group));
326+
.div_ceil(&BlockCount::fromx(self.s_blocks_per_group));
326327
BlockGroupCount::try_from(count)
327328
.expect("We made sure in `Self::new` that the block group count fits into a u32.")
328329
}

src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#![feature(step_trait)]
22
#![feature(iter_advance_by)]
3-
#![feature(int_roundings)]
43
#![feature(maybe_uninit_extra)]
54
#![feature(maybe_uninit_slice)]
65
#![feature(maybe_uninit_write_slice)]
@@ -49,7 +48,7 @@ const_assert!(size_of::<usize>() <= size_of::<u64>());
4948

5049
fn main() -> Result<()> {
5150
let matches =
52-
App::new("ofs-convert")
51+
App::new("ofs-convert-rs")
5352
.arg(
5453
Arg::with_name("PARTITION_PATH")
5554
.required(true)

src/partition.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ mod tests {
9090
use std::io::{self, Write};
9191

9292
use itertools::Itertools;
93-
use tempfile::NamedTempFile;
93+
use rand::distributions::Standard;
9494
use rand::{self, Rng};
95-
use rand::distributions::{Standard};
95+
use tempfile::NamedTempFile;
9696

9797
use super::*;
9898

src/serialization/stream_archiver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'a> StreamArchiver<'a> {
138138
}
139139

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

0 commit comments

Comments
 (0)