diff --git a/Cargo.toml b/Cargo.toml index 370fe60..cd33ecf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,11 @@ categories = ["filesystem", "no-std", "os::windows-apis", "parser-implementation arrayvec = { version = "0.7.2", default-features = false } binread = { version = "2.2.0", features = ["const_generics"], default-features = false } byteorder = { version = "1.4.3", default-features = false } -bitflags = "1.3.2" +bitflags = "2.3.1" derive_more = "0.99.17" displaydoc = { version = "0.2.3", default-features = false } enumn = "0.1.3" -memoffset = "0.8.0" +memoffset = "0.9.0" nt-string = { version = "0.1.1", features = ["alloc"], default-features = false } strum_macros = "0.24.0" time = { version = "0.3.9", features = ["large-dates", "macros"], default-features = false, optional = true } diff --git a/examples/ntfs-shell/main.rs b/examples/ntfs-shell/main.rs index e848e5f..2a2ba13 100644 --- a/examples/ntfs-shell/main.rs +++ b/examples/ntfs-shell/main.rs @@ -365,7 +365,7 @@ fn fileinfo_std(attribute: NtfsAttribute) -> Result<()> { let std_info = attribute.resident_structured_value::()?; - println!("{:34}{:?}", "Attributes:", std_info.file_attributes()); + println!("{:34}{}", "Attributes:", std_info.file_attributes()); let atime = OffsetDateTime::from(std_info.access_time()) .format(TIME_FORMAT) diff --git a/src/attribute.rs b/src/attribute.rs index ebacc1f..10cc047 100644 --- a/src/attribute.rs +++ b/src/attribute.rs @@ -2,8 +2,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use core::iter::FusedIterator; -use core::mem; use core::ops::Range; +use core::{fmt, mem}; use binread::io::{Read, Seek}; use bitflags::bitflags; @@ -49,6 +49,7 @@ struct NtfsAttributeHeader { bitflags! { /// Flags returned by [`NtfsAttribute::flags`]. + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NtfsAttributeFlags: u16 { /// The attribute value is compressed. const COMPRESSED = 0x0001; @@ -59,6 +60,12 @@ bitflags! { } } +impl fmt::Display for NtfsAttributeFlags { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + /// On-disk structure of the extra header of an NTFS Attribute that has a resident value. #[repr(C, packed)] struct NtfsResidentAttributeHeader { diff --git a/src/file.rs b/src/file.rs index 94ea84e..213844b 100644 --- a/src/file.rs +++ b/src/file.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use core::cmp::Ordering; +use core::fmt; use core::num::NonZeroU64; use alloc::vec; @@ -96,6 +97,7 @@ struct FileRecordHeader { bitflags! { /// Flags returned by [`NtfsFile::flags`]. + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NtfsFileFlags: u16 { /// Record is in use. const IN_USE = 0x0001; @@ -104,6 +106,12 @@ bitflags! { } } +impl fmt::Display for NtfsFileFlags { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + /// A single NTFS File Record. /// /// These records are denoted via a `FILE` signature on the filesystem. diff --git a/src/index_entry.rs b/src/index_entry.rs index 779f1ec..f37773f 100644 --- a/src/index_entry.rs +++ b/src/index_entry.rs @@ -3,8 +3,8 @@ use core::iter::FusedIterator; use core::marker::PhantomData; -use core::mem; use core::ops::Range; +use core::{fmt, mem}; use alloc::vec::Vec; use binread::io::{Read, Seek}; @@ -43,6 +43,7 @@ struct IndexEntryHeader { bitflags! { /// Flags returned by [`NtfsIndexEntry::flags`]. + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NtfsIndexEntryFlags: u8 { /// This Index Entry points to a sub-node. const HAS_SUBNODE = 0x01; @@ -51,6 +52,12 @@ bitflags! { } } +impl fmt::Display for NtfsIndexEntryFlags { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + #[derive(Clone, Debug)] pub(crate) struct IndexEntryRange where diff --git a/src/structured_values/mod.rs b/src/structured_values/mod.rs index 7f05194..ee51277 100644 --- a/src/structured_values/mod.rs +++ b/src/structured_values/mod.rs @@ -12,6 +12,8 @@ mod standard_information; mod volume_information; mod volume_name; +use core::fmt; + pub use attribute_list::*; pub use file_name::*; pub use index_allocation::*; @@ -36,6 +38,7 @@ bitflags! { /// Returned by [`NtfsStandardInformation::file_attributes`] and [`NtfsFileName::file_attributes`]. /// /// [`NtfsAttribute`]: crate::attribute::NtfsAttribute + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NtfsFileAttributeFlags: u32 { /// File is marked read-only. const READ_ONLY = 0x0001; @@ -71,6 +74,12 @@ bitflags! { } } +impl fmt::Display for NtfsFileAttributeFlags { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + /// Trait implemented by every NTFS attribute structured value. pub trait NtfsStructuredValue<'n, 'f>: Sized { const TY: NtfsAttributeType; diff --git a/src/structured_values/volume_information.rs b/src/structured_values/volume_information.rs index 6ee5a9d..b51580d 100644 --- a/src/structured_values/volume_information.rs +++ b/src/structured_values/volume_information.rs @@ -1,6 +1,8 @@ // Copyright 2021-2022 Colin Finck // SPDX-License-Identifier: MIT OR Apache-2.0 +use core::fmt; + use binread::io::{Cursor, Read, Seek}; use binread::{BinRead, BinReaderExt}; use bitflags::bitflags; @@ -26,6 +28,7 @@ struct VolumeInformationData { bitflags! { /// Flags returned by [`NtfsVolumeInformation::flags`]. + #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct NtfsVolumeFlags: u16 { /// The volume needs to be checked by `chkdsk`. const IS_DIRTY = 0x0001; @@ -39,6 +42,12 @@ bitflags! { } } +impl fmt::Display for NtfsVolumeFlags { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) + } +} + /// Structure of a $VOLUME_INFORMATION attribute. /// /// This attribute is only used by the top-level $Volume file and contains general information about the filesystem.