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 @@ -254,7 +254,7 @@ impl Ext4 {
254
254
/// Read bytes into `dst`, starting at `start_byte`.
255
255
fn read_bytes (
256
256
& self ,
257
- start_byte : u64 ,
257
+ mut start_byte : u64 ,
258
258
mut dst : & mut [ u8 ] ,
259
259
) -> Result < ( ) , Ext4Error > {
260
260
// The first 1024 bytes are reserved for non-filesystem
@@ -271,7 +271,7 @@ impl Ext4 {
271
271
let block_index = self . 0 . journal . map_block_index ( block_index) ;
272
272
let offset_within_block = start_byte % block_size. to_u64 ( ) ;
273
273
274
- let read_len = {
274
+ let read_len: usize = {
275
275
// OK to unwrap: `offset_within_block` is always less
276
276
// than the block size, and the block size always fits
277
277
// in a `u32`. We assume a `usize` is always at least as
@@ -283,14 +283,15 @@ impl Ext4 {
283
283
284
284
let partial_dst = & mut dst[ ..read_len] ;
285
285
286
- let start_byte =
286
+ let partial_start_byte =
287
287
block_index * block_size. to_u64 ( ) + offset_within_block;
288
288
self . 0
289
289
. reader
290
290
. borrow_mut ( )
291
- . read ( start_byte , partial_dst)
291
+ . read ( partial_start_byte , partial_dst)
292
292
. map_err ( Ext4Error :: Io ) ?;
293
293
294
+ start_byte += util:: u64_from_usize ( read_len) ;
294
295
dst = & mut dst[ read_len..] ;
295
296
}
296
297
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