forked from M-Labs/rust-fatfs
switch to rs-core_io
This commit is contained in:
parent
3290f78d73
commit
c73cb4c566
15
Cargo.toml
15
Cargo.toml
@ -23,15 +23,14 @@ std = ["byteorder/std"]
|
|||||||
# Use dynamic allocation - required for LFN support. When used without std please enable core_io/collections
|
# Use dynamic allocation - required for LFN support. When used without std please enable core_io/collections
|
||||||
alloc = []
|
alloc = []
|
||||||
# Default features
|
# Default features
|
||||||
default = ["chrono", "std", "alloc"]
|
default = ["std", "alloc"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = { version = "1", default-features = false }
|
byteorder = { version = ">=1.3, <1.5", default-features = false }
|
||||||
bitflags = "1.0"
|
bitflags = "1.0"
|
||||||
log = "0.4"
|
log = ">=0.4.14, <0.4.19"
|
||||||
chrono = { version = "0.4", optional = true }
|
|
||||||
core_io = { version = "0.1", optional = true }
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dependencies.core_io]
|
||||||
env_logger = "0.5"
|
git = "https://git.m-labs.hk/srenblad/rs-core_io.git"
|
||||||
fscommon = "0.1"
|
branch = "main"
|
||||||
|
optional = true
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
cargo build --no-default-features --features core_io
|
cargo build --no-default-features --features core_io
|
||||||
cargo build --no-default-features --features core_io,alloc,core_io/collections
|
cargo build --no-default-features --features core_io,alloc
|
||||||
|
@ -851,7 +851,6 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_determine_sectors_per_fat() {
|
fn test_determine_sectors_per_fat() {
|
||||||
let _ = env_logger::try_init();
|
|
||||||
|
|
||||||
test_determine_sectors_per_fat_for_multiple_sizes(512, FatType::Fat12, 1, 2, 512);
|
test_determine_sectors_per_fat_for_multiple_sizes(512, FatType::Fat12, 1, 2, 512);
|
||||||
test_determine_sectors_per_fat_for_multiple_sizes(512, FatType::Fat12, 1, 1, 512);
|
test_determine_sectors_per_fat_for_multiple_sizes(512, FatType::Fat12, 1, 1, 512);
|
||||||
@ -870,7 +869,6 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_format_boot_sector() {
|
fn test_format_boot_sector() {
|
||||||
let _ = env_logger::try_init();
|
|
||||||
let bytes_per_sector = 512u16;
|
let bytes_per_sector = 512u16;
|
||||||
// test all partition sizes from 1MB to 2TB (u32::MAX sectors is 2TB - 1 for 512 byte sectors)
|
// test all partition sizes from 1MB to 2TB (u32::MAX sectors is 2TB - 1 for 512 byte sectors)
|
||||||
let mut total_sectors_vec = Vec::new();
|
let mut total_sectors_vec = Vec::new();
|
||||||
|
@ -48,7 +48,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_u8(&mut self) -> Result<u8> {
|
fn read_u8(&mut self) -> Result<u8> {
|
||||||
let mut buf = [0; 1];
|
let mut buf = [0; 1];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(buf[0])
|
Ok(buf[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_i8(&mut self) -> Result<i8> {
|
fn read_i8(&mut self) -> Result<i8> {
|
||||||
let mut buf = [0; 1];
|
let mut buf = [0; 1];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(buf[0] as i8)
|
Ok(buf[0] as i8)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_u16<T: ByteOrder>(&mut self) -> Result<u16> {
|
fn read_u16<T: ByteOrder>(&mut self) -> Result<u16> {
|
||||||
let mut buf = [0; 2];
|
let mut buf = [0; 2];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_u16(&buf))
|
Ok(T::read_u16(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_i16<T: ByteOrder>(&mut self) -> Result<i16> {
|
fn read_i16<T: ByteOrder>(&mut self) -> Result<i16> {
|
||||||
let mut buf = [0; 2];
|
let mut buf = [0; 2];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_i16(&buf))
|
Ok(T::read_i16(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_u24<T: ByteOrder>(&mut self) -> Result<u32> {
|
fn read_u24<T: ByteOrder>(&mut self) -> Result<u32> {
|
||||||
let mut buf = [0; 3];
|
let mut buf = [0; 3];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_u24(&buf))
|
Ok(T::read_u24(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_i24<T: ByteOrder>(&mut self) -> Result<i32> {
|
fn read_i24<T: ByteOrder>(&mut self) -> Result<i32> {
|
||||||
let mut buf = [0; 3];
|
let mut buf = [0; 3];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_i24(&buf))
|
Ok(T::read_i24(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,7 +210,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_u32<T: ByteOrder>(&mut self) -> Result<u32> {
|
fn read_u32<T: ByteOrder>(&mut self) -> Result<u32> {
|
||||||
let mut buf = [0; 4];
|
let mut buf = [0; 4];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_u32(&buf))
|
Ok(T::read_u32(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +236,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_i32<T: ByteOrder>(&mut self) -> Result<i32> {
|
fn read_i32<T: ByteOrder>(&mut self) -> Result<i32> {
|
||||||
let mut buf = [0; 4];
|
let mut buf = [0; 4];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_i32(&buf))
|
Ok(T::read_i32(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_u64<T: ByteOrder>(&mut self) -> Result<u64> {
|
fn read_u64<T: ByteOrder>(&mut self) -> Result<u64> {
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_u64(&buf))
|
Ok(T::read_u64(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +288,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_i64<T: ByteOrder>(&mut self) -> Result<i64> {
|
fn read_i64<T: ByteOrder>(&mut self) -> Result<i64> {
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_i64(&buf))
|
Ok(T::read_i64(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_u128<T: ByteOrder>(&mut self) -> Result<u128> {
|
fn read_u128<T: ByteOrder>(&mut self) -> Result<u128> {
|
||||||
let mut buf = [0; 16];
|
let mut buf = [0; 16];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_u128(&buf))
|
Ok(T::read_u128(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_i128<T: ByteOrder>(&mut self) -> Result<i128> {
|
fn read_i128<T: ByteOrder>(&mut self) -> Result<i128> {
|
||||||
let mut buf = [0; 16];
|
let mut buf = [0; 16];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_i128(&buf))
|
Ok(T::read_i128(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,7 +371,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_uint<T: ByteOrder>(&mut self, nbytes: usize) -> Result<u64> {
|
fn read_uint<T: ByteOrder>(&mut self, nbytes: usize) -> Result<u64> {
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
try!(self.read_exact(&mut buf[..nbytes]));
|
self.read_exact(&mut buf[..nbytes])?;
|
||||||
Ok(T::read_uint(&buf[..nbytes], nbytes))
|
Ok(T::read_uint(&buf[..nbytes], nbytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -396,7 +396,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_int<T: ByteOrder>(&mut self, nbytes: usize) -> Result<i64> {
|
fn read_int<T: ByteOrder>(&mut self, nbytes: usize) -> Result<i64> {
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
try!(self.read_exact(&mut buf[..nbytes]));
|
self.read_exact(&mut buf[..nbytes])?;
|
||||||
Ok(T::read_int(&buf[..nbytes], nbytes))
|
Ok(T::read_int(&buf[..nbytes], nbytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,7 +405,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_uint128<T: ByteOrder>(&mut self, nbytes: usize) -> Result<u128> {
|
fn read_uint128<T: ByteOrder>(&mut self, nbytes: usize) -> Result<u128> {
|
||||||
let mut buf = [0; 16];
|
let mut buf = [0; 16];
|
||||||
try!(self.read_exact(&mut buf[..nbytes]));
|
self.read_exact(&mut buf[..nbytes])?;
|
||||||
Ok(T::read_uint128(&buf[..nbytes], nbytes))
|
Ok(T::read_uint128(&buf[..nbytes], nbytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -414,7 +414,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_int128<T: ByteOrder>(&mut self, nbytes: usize) -> Result<i128> {
|
fn read_int128<T: ByteOrder>(&mut self, nbytes: usize) -> Result<i128> {
|
||||||
let mut buf = [0; 16];
|
let mut buf = [0; 16];
|
||||||
try!(self.read_exact(&mut buf[..nbytes]));
|
self.read_exact(&mut buf[..nbytes])?;
|
||||||
Ok(T::read_int128(&buf[..nbytes], nbytes))
|
Ok(T::read_int128(&buf[..nbytes], nbytes))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,7 +445,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_f32<T: ByteOrder>(&mut self) -> Result<f32> {
|
fn read_f32<T: ByteOrder>(&mut self) -> Result<f32> {
|
||||||
let mut buf = [0; 4];
|
let mut buf = [0; 4];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_f32(&buf))
|
Ok(T::read_f32(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +476,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn read_f64<T: ByteOrder>(&mut self) -> Result<f64> {
|
fn read_f64<T: ByteOrder>(&mut self) -> Result<f64> {
|
||||||
let mut buf = [0; 8];
|
let mut buf = [0; 8];
|
||||||
try!(self.read_exact(&mut buf));
|
self.read_exact(&mut buf)?;
|
||||||
Ok(T::read_f64(&buf))
|
Ok(T::read_f64(&buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,7 +509,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_u16_into<T: ByteOrder>(&mut self, dst: &mut [u16]) -> Result<()> {
|
fn read_u16_into<T: ByteOrder>(&mut self, dst: &mut [u16]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_u16(dst);
|
T::from_slice_u16(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -544,7 +544,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_u32_into<T: ByteOrder>(&mut self, dst: &mut [u32]) -> Result<()> {
|
fn read_u32_into<T: ByteOrder>(&mut self, dst: &mut [u32]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_u32(dst);
|
T::from_slice_u32(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -582,7 +582,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_u64_into<T: ByteOrder>(&mut self, dst: &mut [u64]) -> Result<()> {
|
fn read_u64_into<T: ByteOrder>(&mut self, dst: &mut [u64]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_u64(dst);
|
T::from_slice_u64(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -621,7 +621,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_u128_into<T: ByteOrder>(&mut self, dst: &mut [u128]) -> Result<()> {
|
fn read_u128_into<T: ByteOrder>(&mut self, dst: &mut [u128]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let mut buf = unsafe { slice_to_u8_mut(dst) };
|
let mut buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_u128(dst);
|
T::from_slice_u128(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -656,7 +656,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_i16_into<T: ByteOrder>(&mut self, dst: &mut [i16]) -> Result<()> {
|
fn read_i16_into<T: ByteOrder>(&mut self, dst: &mut [i16]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_i16(dst);
|
T::from_slice_i16(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -691,7 +691,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_i32_into<T: ByteOrder>(&mut self, dst: &mut [i32]) -> Result<()> {
|
fn read_i32_into<T: ByteOrder>(&mut self, dst: &mut [i32]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_i32(dst);
|
T::from_slice_i32(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -729,7 +729,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_i64_into<T: ByteOrder>(&mut self, dst: &mut [i64]) -> Result<()> {
|
fn read_i64_into<T: ByteOrder>(&mut self, dst: &mut [i64]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_i64(dst);
|
T::from_slice_i64(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -768,7 +768,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_i128_into<T: ByteOrder>(&mut self, dst: &mut [i128]) -> Result<()> {
|
fn read_i128_into<T: ByteOrder>(&mut self, dst: &mut [i128]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let mut buf = unsafe { slice_to_u8_mut(dst) };
|
let mut buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_i128(dst);
|
T::from_slice_i128(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -809,7 +809,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_f32_into<T: ByteOrder>(&mut self, dst: &mut [f32]) -> Result<()> {
|
fn read_f32_into<T: ByteOrder>(&mut self, dst: &mut [f32]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_f32(dst);
|
T::from_slice_f32(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -891,7 +891,7 @@ pub trait ReadBytesExt: io::Read {
|
|||||||
fn read_f64_into<T: ByteOrder>(&mut self, dst: &mut [f64]) -> Result<()> {
|
fn read_f64_into<T: ByteOrder>(&mut self, dst: &mut [f64]) -> Result<()> {
|
||||||
{
|
{
|
||||||
let buf = unsafe { slice_to_u8_mut(dst) };
|
let buf = unsafe { slice_to_u8_mut(dst) };
|
||||||
try!(self.read_exact(buf));
|
self.read_exact(buf)?;
|
||||||
}
|
}
|
||||||
T::from_slice_f64(dst);
|
T::from_slice_f64(dst);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user