Skip to content

Commit

Permalink
Replace abandoned binread dependency by its binrw successor crate.
Browse files Browse the repository at this point in the history
This is recommended now: jam1garner/binread#46
  • Loading branch information
ColinFinck committed Jun 13, 2023
1 parent a490444 commit 509b1d6
Show file tree
Hide file tree
Showing 29 changed files with 67 additions and 64 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ categories = ["filesystem", "no-std", "os::windows-apis", "parser-implementation

[dependencies]
arrayvec = { version = "0.7.2", default-features = false }
binread = { version = "2.2.0", features = ["const_generics"], default-features = false }
binrw = { version = "0.11.2", default-features = false }
byteorder = { version = "1.4.3", default-features = false }
bitflags = "2.3.1"
derive_more = "0.99.17"
Expand All @@ -32,7 +32,7 @@ time = { version = "0.3.9", features = ["formatting", "large-dates", "macros"],

[features]
default = ["std"]
std = ["arrayvec/std", "binread/std", "byteorder/std", "nt-string/std", "time?/std"]
std = ["arrayvec/std", "binrw/std", "byteorder/std", "nt-string/std", "time?/std"]

[[example]]
name = "ntfs-shell"
Expand Down
2 changes: 1 addition & 1 deletion src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use core::iter::FusedIterator;
use core::ops::Range;
use core::{fmt, mem};

use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};
use bitflags::bitflags;
use byteorder::{ByteOrder, LittleEndian};
use enumn::N;
Expand Down
2 changes: 1 addition & 1 deletion src/attribute_value/attribute_list_non_resident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// Connected attributes are stored in a way that the first attribute reports the entire data size and all further attributes report a zero value length.
// We have to go down to the Data Run level to get trustable lengths again, and this is what `NtfsAttributeListNonResidentAttributeValue` does here.

use binread::io::{Read, Seek, SeekFrom};
use binrw::io::{Read, Seek, SeekFrom};

use super::{DataRunsState, NtfsDataRuns, StreamState};
use crate::attribute::{NtfsAttribute, NtfsAttributeType};
Expand Down
6 changes: 3 additions & 3 deletions src/attribute_value/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0
//
//! Readers for attribute value types.
Expand All @@ -11,8 +11,8 @@ pub use attribute_list_non_resident::*;
pub use non_resident::*;
pub use resident::*;

use binread::io;
use binread::io::{Read, Seek, SeekFrom};
use binrw::io;
use binrw::io::{Read, Seek, SeekFrom};

use crate::error::{NtfsError, Result};
use crate::traits::NtfsReadSeek;
Expand Down
10 changes: 5 additions & 5 deletions src/attribute_value/non_resident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
use core::iter::FusedIterator;
use core::mem;

use binread::io;
use binread::io::Cursor;
use binread::io::{Read, Seek, SeekFrom};
use binread::BinRead;
use binrw::io;
use binrw::io::Cursor;
use binrw::io::{Read, Seek, SeekFrom};
use binrw::BinRead;

use super::seek_contiguous;
use crate::error::{NtfsError, Result};
Expand Down Expand Up @@ -723,7 +723,7 @@ impl StreamState {

#[cfg(test)]
mod tests {
use binread::io::SeekFrom;
use binrw::io::SeekFrom;

use crate::indexes::NtfsFileNameIndex;
use crate::ntfs::Ntfs;
Expand Down
4 changes: 2 additions & 2 deletions src/attribute_value/resident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//! are always read into a buffer first and then fixed up in memory.
//! Further accesses to the record data can then happen via slices.

use binread::io::{Read, Seek, SeekFrom};
use binrw::io::{Read, Seek, SeekFrom};

use super::seek_contiguous;
use crate::error::Result;
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'f> NtfsReadSeek for NtfsResidentAttributeValue<'f> {

#[cfg(test)]
mod tests {
use binread::io::SeekFrom;
use binrw::io::SeekFrom;

use crate::indexes::NtfsFileNameIndex;
use crate::ntfs::Ntfs;
Expand Down
4 changes: 2 additions & 2 deletions src/boot_sector.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::ops::RangeInclusive;

use binread::BinRead;
use binrw::BinRead;
use memoffset::offset_of;

use crate::error::{NtfsError, Result};
Expand Down
20 changes: 10 additions & 10 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub enum NtfsError {
previous_lcn: Lcn,
},
/// I/O error: {0:?}
Io(binread::io::Error),
Io(binrw::io::Error),
/// The Logical Cluster Number (LCN) {lcn} is too big to be multiplied by the cluster size
LcnTooBig { lcn: Lcn },
/// The index root at byte position {position:#x} is a large index, but no matching index allocation attribute was provided
Expand Down Expand Up @@ -227,31 +227,31 @@ pub enum NtfsError {
VcnTooBig { vcn: Vcn },
}

impl From<binread::error::Error> for NtfsError {
fn from(error: binread::error::Error) -> Self {
if let binread::error::Error::Io(io_error) = error {
impl From<binrw::error::Error> for NtfsError {
fn from(error: binrw::error::Error) -> Self {
if let binrw::error::Error::Io(io_error) = error {
Self::Io(io_error)
} else {
// We don't use any binread attributes that result in other errors.
unreachable!("Got a binread error of unexpected type: {:?}", error);
// We don't use any binrw attributes that result in other errors.
unreachable!("Got a binrw error of unexpected type: {:?}", error);
}
}
}

impl From<binread::io::Error> for NtfsError {
fn from(error: binread::io::Error) -> Self {
impl From<binrw::io::Error> for NtfsError {
fn from(error: binrw::io::Error) -> Self {
Self::Io(error)
}
}

// To stay compatible with standardized interfaces (e.g. io::Read, io::Seek),
// we sometimes need to convert from NtfsError to io::Error.
impl From<NtfsError> for binread::io::Error {
impl From<NtfsError> for binrw::io::Error {
fn from(error: NtfsError) -> Self {
if let NtfsError::Io(io_error) = error {
io_error
} else {
binread::io::Error::new(binread::io::ErrorKind::Other, error)
binrw::io::Error::new(binrw::io::ErrorKind::Other, error)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::fmt;
use core::num::NonZeroU64;

use alloc::vec;
use binread::io::{Read, Seek, SeekFrom};
use binrw::io::{Read, Seek, SeekFrom};
use bitflags::bitflags;
use byteorder::{ByteOrder, LittleEndian};
use memoffset::offset_of;
Expand Down
6 changes: 3 additions & 3 deletions src/file_reference.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2021 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use crate::error::Result;
use crate::file::NtfsFile;
use crate::ntfs::Ntfs;
use binread::io::{Read, Seek};
use binread::BinRead;
use binrw::io::{Read, Seek};
use binrw::BinRead;

/// Absolute reference to a File Record on the filesystem, composed out of a File Record Number and a Sequence Number.
///
Expand Down
4 changes: 2 additions & 2 deletions src/guid.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use binread::BinRead;
use binrw::BinRead;
use core::fmt;

/// Size of a single GUID on disk (= size of all GUID fields).
Expand Down
2 changes: 1 addition & 1 deletion src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::marker::PhantomData;

use alloc::vec;
use alloc::vec::Vec;
use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};

use crate::attribute::{NtfsAttributeItem, NtfsAttributeType};
use crate::error::{NtfsError, Result};
Expand Down
4 changes: 2 additions & 2 deletions src/index_entry.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::iter::FusedIterator;
Expand All @@ -7,7 +7,7 @@ use core::ops::Range;
use core::{fmt, mem};

use alloc::vec::Vec;
use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};
use bitflags::bitflags;
use byteorder::{ByteOrder, LittleEndian};
use memoffset::offset_of;
Expand Down
2 changes: 1 addition & 1 deletion src/index_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: MIT OR Apache-2.0

use alloc::vec;
use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};
use byteorder::{ByteOrder, LittleEndian};
use core::ops::Range;
use memoffset::offset_of;
Expand Down
2 changes: 1 addition & 1 deletion src/indexes/file_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::indexes::{NtfsIndexEntryHasFileReference, NtfsIndexEntryType};
use crate::ntfs::Ntfs;
use crate::structured_values::NtfsFileName;
use crate::upcase_table::UpcaseOrd;
use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};

/// Defines the [`NtfsIndexEntryType`] for filename indexes (commonly known as "directories").
#[derive(Clone, Copy, Debug)]
Expand Down
4 changes: 2 additions & 2 deletions src/ntfs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use binread::io::{Read, Seek, SeekFrom};
use binread::BinReaderExt;
use binrw::io::{Read, Seek, SeekFrom};
use binrw::BinReaderExt;

use crate::attribute::NtfsAttributeType;
use crate::boot_sector::BootSector;
Expand Down
4 changes: 2 additions & 2 deletions src/structured_values/attribute_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use core::mem;

use arrayvec::ArrayVec;
use binread::io::{Cursor, Read, Seek, SeekFrom};
use binread::{BinRead, BinReaderExt};
use binrw::io::{Cursor, Read, Seek, SeekFrom};
use binrw::{BinRead, BinReaderExt};
use nt_string::u16strle::U16StrLe;

use crate::attribute::{NtfsAttribute, NtfsAttributeType};
Expand Down
6 changes: 3 additions & 3 deletions src/structured_values/file_name.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::mem;

use arrayvec::ArrayVec;
use binread::io::{Cursor, Read, Seek};
use binread::{BinRead, BinReaderExt};
use binrw::io::{Cursor, Read, Seek};
use binrw::{BinRead, BinReaderExt};
use enumn::N;
use nt_string::u16strle::U16StrLe;

Expand Down
4 changes: 2 additions & 2 deletions src/structured_values/index_allocation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use crate::attribute::NtfsAttributeType;
Expand All @@ -9,7 +9,7 @@ use crate::ntfs::Ntfs;
use crate::structured_values::NtfsStructuredValue;
use crate::traits::NtfsReadSeek;
use crate::types::Vcn;
use binread::io::{Read, Seek, SeekFrom};
use binrw::io::{Read, Seek, SeekFrom};
use core::iter::FusedIterator;

/// Structure of an $INDEX_ALLOCATION attribute.
Expand Down
2 changes: 1 addition & 1 deletion src/structured_values/index_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use core::ops::Range;

use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};
use byteorder::{ByteOrder, LittleEndian};
use memoffset::offset_of;

Expand Down
4 changes: 2 additions & 2 deletions src/structured_values/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0
//
//! Various types of NTFS Attribute structured values.
Expand Down Expand Up @@ -26,7 +26,7 @@ pub use volume_name::*;
use crate::attribute::NtfsAttributeType;
use crate::attribute_value::{NtfsAttributeValue, NtfsResidentAttributeValue};
use crate::error::Result;
use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};
use bitflags::bitflags;

bitflags! {
Expand Down
6 changes: 3 additions & 3 deletions src/structured_values/object_id.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use binread::io::{Cursor, Read, Seek};
use binread::BinReaderExt;
use binrw::io::{Cursor, Read, Seek};
use binrw::BinReaderExt;

use crate::attribute::NtfsAttributeType;
use crate::attribute_value::{NtfsAttributeValue, NtfsResidentAttributeValue};
Expand Down
4 changes: 2 additions & 2 deletions src/structured_values/standard_information.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use binread::io::{Cursor, Read, Seek};
use binread::{BinRead, BinReaderExt};
use binrw::io::{Cursor, Read, Seek};
use binrw::{BinRead, BinReaderExt};

use crate::attribute::NtfsAttributeType;
use crate::attribute_value::{NtfsAttributeValue, NtfsResidentAttributeValue};
Expand Down
6 changes: 3 additions & 3 deletions src/structured_values/volume_information.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::fmt;

use binread::io::{Cursor, Read, Seek};
use binread::{BinRead, BinReaderExt};
use binrw::io::{Cursor, Read, Seek};
use binrw::{BinRead, BinReaderExt};
use bitflags::bitflags;

use crate::attribute::NtfsAttributeType;
Expand Down
4 changes: 2 additions & 2 deletions src/structured_values/volume_name.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright 2021-2022 Colin Finck <colin@reactos.org>
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use core::mem;

use arrayvec::ArrayVec;
use binread::io::{Cursor, Read, Seek};
use binrw::io::{Cursor, Read, Seek};
use nt_string::u16strle::U16StrLe;

use crate::attribute::NtfsAttributeType;
Expand Down
2 changes: 1 addition & 1 deletion src/time.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use binread::BinRead;
use binrw::BinRead;
use derive_more::From;

#[cfg(feature = "time")]
Expand Down
7 changes: 5 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright 2021-2023 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: MIT OR Apache-2.0

use crate::error::{NtfsError, Result};
use binread::io;
use binread::io::{Read, Seek, SeekFrom};
use binrw::io;
use binrw::io::{Read, Seek, SeekFrom};

/// Trait to read/seek in a source by the help of a temporarily passed mutable reference to the filesystem reader.
///
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use core::fmt;
use core::num::NonZeroU64;
use core::ops::{Add, AddAssign};

use binread::BinRead;
use binrw::BinRead;
use derive_more::{Binary, Display, From, LowerHex, Octal, UpperHex};

use crate::error::{NtfsError, Result};
Expand Down
2 changes: 1 addition & 1 deletion src/upcase_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::mem;

use alloc::vec;
use alloc::vec::Vec;
use binread::io::{Read, Seek};
use binrw::io::{Read, Seek};
use nt_string::u16strle::U16StrLe;

use crate::attribute::NtfsAttributeType;
Expand Down

0 comments on commit 509b1d6

Please sign in to comment.