File tree Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Expand file tree Collapse file tree 2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -251,7 +251,7 @@ impl Ext4 {
251
251
/// Read bytes into `dst`, starting at `start_byte`.
252
252
fn read_bytes (
253
253
& self ,
254
- start_byte : u64 ,
254
+ mut start_byte : u64 ,
255
255
mut dst : & mut [ u8 ] ,
256
256
) -> Result < ( ) , Ext4Error > {
257
257
// The first 1024 bytes are reserved for non-filesystem
@@ -268,7 +268,7 @@ impl Ext4 {
268
268
let block_index = self . 0 . journal . map_block_index ( block_index) ;
269
269
let offset_within_block = start_byte % block_size. to_u64 ( ) ;
270
270
271
- let read_len = {
271
+ let read_len: usize = {
272
272
// OK to unwrap: `offset_within_block` is always less
273
273
// than the block size, and the block size always fits
274
274
// in a `u32`. We assume a `usize` is always at least as
@@ -280,14 +280,15 @@ impl Ext4 {
280
280
281
281
let partial_dst = & mut dst[ ..read_len] ;
282
282
283
- let start_byte =
283
+ let partial_start_byte =
284
284
block_index * block_size. to_u64 ( ) + offset_within_block;
285
285
self . 0
286
286
. reader
287
287
. borrow_mut ( )
288
- . read ( start_byte , partial_dst)
288
+ . read ( partial_start_byte , partial_dst)
289
289
. map_err ( Ext4Error :: Io ) ?;
290
290
291
+ start_byte += util:: u64_from_usize ( read_len) ;
291
292
dst = & mut dst[ read_len..] ;
292
293
}
293
294
Original file line number Diff line number Diff line change @@ -28,6 +28,26 @@ pub(crate) const fn usize_from_u32(val: u32) -> usize {
28
28
}
29
29
}
30
30
31
+ /// Convert a `usize` to a `u64`.
32
+ ///
33
+ /// TODO, but on platforms
34
+ /// supported by this crate, this conversion is infallible.
35
+ ///
36
+ /// # Panics
37
+ ///
38
+ /// Panics if `val` does not fit in this platform's `u64`.
39
+ #[ inline]
40
+ #[ must_use]
41
+ pub ( crate ) const fn u64_from_usize ( val : usize ) -> u64 {
42
+ assert ! ( size_of:: <u64 >( ) >= size_of:: <usize >( ) ) ;
43
+
44
+ // Cannot use `usize::try_from` in a `const fn`.
45
+ #[ expect( clippy:: as_conversions) ]
46
+ {
47
+ val as u64
48
+ }
49
+ }
50
+
31
51
/// Create a `u64` from two `u32` values.
32
52
#[ inline]
33
53
#[ must_use]
You can’t perform that action at this time.
0 commit comments