Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/ntfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Finck <colin@reactos.org>2021-07-21 21:32:31 +0300
committerColin Finck <colin@reactos.org>2021-07-21 21:32:31 +0300
commit831f6a6152a9e98c16845169985e396b1c04b139 (patch)
tree4367f2f7db43c97b98cbee99b9467f17185f45cd
parentc76c87e1cf3164da01e872f26e3160a1d80bdb7f (diff)
Remove "Ntfs" prefix from `NtfsError` members, make it non-exhaustive.
-rw-r--r--src/attribute.rs12
-rw-r--r--src/error.rs93
-rw-r--r--src/index_record.rs6
-rw-r--r--src/ntfs.rs4
-rw-r--r--src/ntfs_file.rs6
-rw-r--r--src/structured_values/file_name.rs4
-rw-r--r--src/structured_values/index_root.rs4
-rw-r--r--src/time.rs6
8 files changed, 68 insertions, 67 deletions
diff --git a/src/attribute.rs b/src/attribute.rs
index 6655adb..1ea83d8 100644
--- a/src/attribute.rs
+++ b/src/attribute.rs
@@ -285,13 +285,13 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
LittleEndian::read_u16(&self.file.record_data()[start..])
}
- /// Returns the type of this NTFS attribute, or [`NtfsError::UnsupportedNtfsAttributeType`]
+ /// Returns the type of this NTFS attribute, or [`NtfsError::UnsupportedAttributeType`]
/// if it's an unknown type.
pub fn ty(&self) -> Result<NtfsAttributeType> {
let start = self.offset + offset_of!(NtfsAttributeHeader, ty);
let ty = LittleEndian::read_u32(&self.file.record_data()[start..]);
- NtfsAttributeType::n(ty).ok_or(NtfsError::UnsupportedNtfsAttributeType {
+ NtfsAttributeType::n(ty).ok_or(NtfsError::UnsupportedAttributeType {
position: self.position(),
actual: ty,
})
@@ -300,7 +300,7 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
fn validate_name_sizes(&self) -> Result<()> {
let start = self.name_offset();
if start as u32 >= self.attribute_length() {
- return Err(NtfsError::InvalidNtfsAttributeNameOffset {
+ return Err(NtfsError::InvalidAttributeNameOffset {
position: self.position(),
expected: start,
actual: self.attribute_length(),
@@ -309,7 +309,7 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
let end = start as usize + self.name_length();
if end > self.attribute_length() as usize {
- return Err(NtfsError::InvalidNtfsAttributeNameLength {
+ return Err(NtfsError::InvalidAttributeNameLength {
position: self.position(),
expected: end,
actual: self.attribute_length(),
@@ -324,7 +324,7 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
let start = self.resident_value_offset();
if start as u32 >= self.attribute_length() {
- return Err(NtfsError::InvalidNtfsResidentAttributeValueOffset {
+ return Err(NtfsError::InvalidResidentAttributeValueOffset {
position: self.position(),
expected: start,
actual: self.attribute_length(),
@@ -333,7 +333,7 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
let end = start as u32 + self.resident_value_length();
if end > self.attribute_length() {
- return Err(NtfsError::InvalidNtfsResidentAttributeValueLength {
+ return Err(NtfsError::InvalidResidentAttributeValueLength {
position: self.position(),
expected: end,
actual: self.attribute_length(),
diff --git a/src/error.rs b/src/error.rs
index 1836be3..89e8d7b 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -10,6 +10,7 @@ pub type Result<T, E = NtfsError> = core::result::Result<T, E>;
/// Central error type of ntfs.
#[derive(Debug, Display)]
+#[non_exhaustive]
pub enum NtfsError {
/// The NTFS file at byte position {position:#010x} has no attribute of type {ty:?}, but it was expected
AttributeNotFound {
@@ -18,90 +19,88 @@ pub enum NtfsError {
},
/// The given buffer should have at least {expected} bytes, but it only has {actual} bytes
BufferTooSmall { expected: usize, actual: usize },
- /// The NTFS data run header at byte position {position:#010x} indicates a maximum byte count of {expected}, but {actual} is the limit
- InvalidByteCountInDataRunHeader {
+ /// The NTFS attribute at byte position {position:#010x} indicates a name length up to offset {expected}, but the attribute only has a size of {actual} bytes
+ InvalidAttributeNameLength {
position: u64,
- expected: u8,
- actual: u8,
+ expected: usize,
+ actual: u32,
},
- /// The cluster count {cluster_count} is too big
- InvalidClusterCount { cluster_count: u64 },
/// The NTFS attribute at byte position {position:#010x} indicates that its name starts at offset {expected}, but the attribute only has a size of {actual} bytes
- InvalidNtfsAttributeNameOffset {
+ InvalidAttributeNameOffset {
position: u64,
expected: u16,
actual: u32,
},
- /// The NTFS attribute at byte position {position:#010x} indicates a name length up to offset {expected}, but the attribute only has a size of {actual} bytes
- InvalidNtfsAttributeNameLength {
+ /// The NTFS data run header at byte position {position:#010x} indicates a maximum byte count of {expected}, but {actual} is the limit
+ InvalidByteCountInDataRunHeader {
position: u64,
- expected: usize,
- actual: u32,
+ expected: u8,
+ actual: u8,
},
+ /// The cluster count {cluster_count} is too big
+ InvalidClusterCount { cluster_count: u64 },
+ /// The requested NTFS file {n} is invalid
+ InvalidFile { n: u64 },
/// The NTFS file record at byte position {position:#010x} indicates an allocated size of {expected} bytes, but the record only has a size of {actual} bytes
- InvalidNtfsFileAllocatedSize {
+ InvalidFileAllocatedSize {
position: u64,
expected: u32,
actual: u32,
},
+ /// The NTFS file record at byte position {position:#010x} should have signature {expected:?}, but it has signature {actual:?}
+ InvalidFileSignature {
+ position: u64,
+ expected: &'static [u8],
+ actual: [u8; 4],
+ },
/// The NTFS file record at byte position {position:#010x} indicates a used size of {expected} bytes, but only {actual} bytes are allocated
- InvalidNtfsFileUsedSize {
+ InvalidFileUsedSize {
position: u64,
expected: u32,
actual: u32,
},
- /// The resident NTFS attribute at byte position {position:#010x} indicates that its value starts at offset {expected}, but the attribute only has a size of {actual} bytes
- InvalidNtfsResidentAttributeValueOffset {
+ /// The NTFS index record at byte position {position:#010x} indicates an allocated size of {expected} bytes, but the record only has a size of {actual} bytes
+ InvalidIndexAllocatedSize {
position: u64,
- expected: u16,
+ expected: u32,
actual: u32,
},
- /// The resident NTFS attribute at byte position {position:#010x} indicates a value length up to offset {expected}, but the attribute only has a size of {actual} bytes
- InvalidNtfsResidentAttributeValueLength {
+ /// The NTFS index root at byte position {position:#010x} indicates that its entries start at offset {expected}, but the index root only has a size of {actual} bytes
+ InvalidIndexRootEntriesOffset {
position: u64,
- expected: u32,
- actual: u32,
+ expected: usize,
+ actual: usize,
},
- /// The requested NTFS file {n} is invalid
- InvalidNtfsFile { n: u64 },
- /// The NTFS file record at byte position {position:#010x} should have signature {expected:?}, but it has signature {actual:?}
- InvalidNtfsFileSignature {
+ /// The NTFS index root at byte position {position:#010x} indicates a used size up to offset {expected}, but the index root only has a size of {actual} bytes
+ InvalidIndexRootUsedSize {
position: u64,
- expected: &'static [u8],
- actual: [u8; 4],
+ expected: usize,
+ actual: usize,
},
/// The NTFS index record at byte position {position:#010x} should have signature {expected:?}, but it has signature {actual:?}
- InvalidNtfsIndexSignature {
+ InvalidIndexSignature {
position: u64,
expected: &'static [u8],
actual: [u8; 4],
},
- /// The NTFS index record at byte position {position:#010x} indicates an allocated size of {expected} bytes, but the record only has a size of {actual} bytes
- InvalidNtfsIndexAllocatedSize {
+ /// The NTFS index record at byte position {position:#010x} indicates a used size of {expected} bytes, but only {actual} bytes are allocated
+ InvalidIndexUsedSize {
position: u64,
expected: u32,
actual: u32,
},
- /// The NTFS index record at byte position {position:#010x} indicates a used size of {expected} bytes, but only {actual} bytes are allocated
- InvalidNtfsIndexUsedSize {
+ /// The resident NTFS attribute at byte position {position:#010x} indicates a value length up to offset {expected}, but the attribute only has a size of {actual} bytes
+ InvalidResidentAttributeValueLength {
position: u64,
expected: u32,
actual: u32,
},
- /// The NTFS index root at byte position {position:#010x} indicates that its entries start at offset {expected}, but the index root only has a size of {actual} bytes
- InvalidNtfsIndexRootEntriesOffset {
- position: u64,
- expected: usize,
- actual: usize,
- },
- /// The NTFS index root at byte position {position:#010x} indicates a used size up to offset {expected}, but the index root only has a size of {actual} bytes
- InvalidNtfsIndexRootUsedSize {
+ /// The resident NTFS attribute at byte position {position:#010x} indicates that its value starts at offset {expected}, but the attribute only has a size of {actual} bytes
+ InvalidResidentAttributeValueOffset {
position: u64,
- expected: usize,
- actual: usize,
+ expected: u16,
+ actual: u32,
},
- /// The given time can't be represented as an NtfsTime
- InvalidNtfsTime,
/// A record size field in the BIOS Parameter Block denotes {size_info}, which is invalid considering the cluster size of {cluster_size} bytes
InvalidRecordSizeInfo { size_info: i8, cluster_size: u32 },
/// The NTFS structured value at byte position {position:#010x} of type {ty:?} has {actual} bytes where {expected} bytes were expected
@@ -111,6 +110,8 @@ pub enum NtfsError {
expected: usize,
actual: usize,
},
+ /// The given time can't be represented as an NtfsTime
+ InvalidTime,
/// The 2-byte signature field at byte position {position:#010x} should contain {expected:?}, but it contains {actual:?}
InvalidTwoByteSignature {
position: u64,
@@ -138,12 +139,12 @@ pub enum NtfsError {
UnexpectedNonResidentAttribute { position: u64 },
/// The NTFS attribute at byte position {position:#010x} should be non-resident, but it is resident
UnexpectedResidentAttribute { position: u64 },
+ /// The type of the NTFS attribute at byte position {position:#010x} is {actual:#010x}, which is not supported
+ UnsupportedAttributeType { position: u64, actual: u32 },
/// The cluster size is {actual} bytes, but the maximum supported one is {expected}
UnsupportedClusterSize { expected: u32, actual: u32 },
- /// The type of the NTFS attribute at byte position {position:#010x} is {actual:#010x}, which is not supported
- UnsupportedNtfsAttributeType { position: u64, actual: u32 },
/// The namespace of the NTFS file name starting at byte position {position:#010x} is {actual}, which is not supported
- UnsupportedNtfsFileNamespace { position: u64, actual: u8 },
+ UnsupportedFileNamespace { position: u64, actual: u8 },
/// The Update Sequence Array (USA) of the record at byte position {position:#010x} has entries for {array_count} sectors of {sector_size} bytes, but the record is only {record_size} bytes long
UpdateSequenceArrayExceedsRecordSize {
position: u64,
diff --git a/src/index_record.rs b/src/index_record.rs
index b6120c1..e6fccd3 100644
--- a/src/index_record.rs
+++ b/src/index_record.rs
@@ -116,7 +116,7 @@ impl<'n> NtfsIndexRecord<'n> {
if signature == expected {
Ok(())
} else {
- Err(NtfsError::InvalidNtfsIndexSignature {
+ Err(NtfsError::InvalidIndexSignature {
position: self.record.position(),
expected,
actual: *signature,
@@ -131,7 +131,7 @@ impl<'n> NtfsIndexRecord<'n> {
// the size defined for all index records of this index.
let total_allocated_size = INDEX_RECORD_HEADER_SIZE + self.index_allocated_size();
if total_allocated_size > index_record_size {
- return Err(NtfsError::InvalidNtfsIndexAllocatedSize {
+ return Err(NtfsError::InvalidIndexAllocatedSize {
position: self.record.position(),
expected: index_record_size,
actual: total_allocated_size,
@@ -142,7 +142,7 @@ impl<'n> NtfsIndexRecord<'n> {
// larger than the total allocated size.
let total_used_size = INDEX_RECORD_HEADER_SIZE + self.index_used_size();
if total_used_size > total_allocated_size {
- return Err(NtfsError::InvalidNtfsIndexUsedSize {
+ return Err(NtfsError::InvalidIndexUsedSize {
position: self.record.position(),
expected: total_allocated_size,
actual: total_used_size,
diff --git a/src/ntfs.rs b/src/ntfs.rs
index bfe9621..d1fb214 100644
--- a/src/ntfs.rs
+++ b/src/ntfs.rs
@@ -80,11 +80,11 @@ impl Ntfs {
{
let offset = n
.checked_mul(self.file_record_size as u64)
- .ok_or(NtfsError::InvalidNtfsFile { n })?;
+ .ok_or(NtfsError::InvalidFile { n })?;
let position = self
.mft_position
.checked_add(offset)
- .ok_or(NtfsError::InvalidNtfsFile { n })?;
+ .ok_or(NtfsError::InvalidFile { n })?;
NtfsFile::new(&self, fs, position)
}
diff --git a/src/ntfs_file.rs b/src/ntfs_file.rs
index 056b3bb..770ca67 100644
--- a/src/ntfs_file.rs
+++ b/src/ntfs_file.rs
@@ -126,7 +126,7 @@ impl<'n> NtfsFile<'n> {
if signature == expected {
Ok(())
} else {
- Err(NtfsError::InvalidNtfsFileSignature {
+ Err(NtfsError::InvalidFileSignature {
position: self.record.position(),
expected,
actual: *signature,
@@ -136,7 +136,7 @@ impl<'n> NtfsFile<'n> {
fn validate_sizes(&self) -> Result<()> {
if self.allocated_size() > self.record.len() {
- return Err(NtfsError::InvalidNtfsFileAllocatedSize {
+ return Err(NtfsError::InvalidFileAllocatedSize {
position: self.record.position(),
expected: self.allocated_size(),
actual: self.record.len(),
@@ -144,7 +144,7 @@ impl<'n> NtfsFile<'n> {
}
if self.used_size() > self.allocated_size() {
- return Err(NtfsError::InvalidNtfsFileUsedSize {
+ return Err(NtfsError::InvalidFileUsedSize {
position: self.record.position(),
expected: self.used_size(),
actual: self.allocated_size(),
diff --git a/src/structured_values/file_name.rs b/src/structured_values/file_name.rs
index e58efeb..96fcf92 100644
--- a/src/structured_values/file_name.rs
+++ b/src/structured_values/file_name.rs
@@ -92,7 +92,7 @@ impl NtfsFileName {
self.header.name_length as usize * mem::size_of::<u16>()
}
- /// Returns the namespace this name belongs to, or [`NtfsError::UnsupportedNtfsFileNamespace`]
+ /// Returns the namespace this name belongs to, or [`NtfsError::UnsupportedFileNamespace`]
/// if it's an unknown namespace.
pub fn namespace(&self) -> NtfsFileNamespace {
NtfsFileNamespace::n(self.header.namespace).unwrap()
@@ -122,7 +122,7 @@ impl NtfsFileName {
fn validate_namespace(&self, position: u64) -> Result<()> {
if NtfsFileNamespace::n(self.header.namespace).is_none() {
- return Err(NtfsError::UnsupportedNtfsFileNamespace {
+ return Err(NtfsError::UnsupportedFileNamespace {
position,
actual: self.header.namespace,
});
diff --git a/src/structured_values/index_root.rs b/src/structured_values/index_root.rs
index 731d0da..098330f 100644
--- a/src/structured_values/index_root.rs
+++ b/src/structured_values/index_root.rs
@@ -89,7 +89,7 @@ impl<'f> NtfsIndexRoot<'f> {
let (entries_range, _position) = self.entries_range_and_position();
if entries_range.start >= self.data.len() {
- return Err(NtfsError::InvalidNtfsIndexRootEntriesOffset {
+ return Err(NtfsError::InvalidIndexRootEntriesOffset {
position: self.position,
expected: entries_range.start,
actual: self.data.len(),
@@ -97,7 +97,7 @@ impl<'f> NtfsIndexRoot<'f> {
}
if entries_range.end > self.data.len() {
- return Err(NtfsError::InvalidNtfsIndexRootUsedSize {
+ return Err(NtfsError::InvalidIndexRootUsedSize {
position: self.position,
expected: entries_range.end,
actual: self.data.len(),
diff --git a/src/time.rs b/src/time.rs
index 3f218da..325d4ee 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -72,13 +72,13 @@ impl TryFrom<DateTime<Utc>> for NtfsTime {
let num_days_from_ce = dt.num_days_from_ce();
let num_days_from_1601 = num_days_from_ce
.checked_sub(DAYS_FROM_0001_TO_1601)
- .ok_or(NtfsError::InvalidNtfsTime)?;
+ .ok_or(NtfsError::InvalidTime)?;
let intervals_days = INTERVALS_PER_DAY
.checked_mul(num_days_from_1601 as u64)
- .ok_or(NtfsError::InvalidNtfsTime)?;
+ .ok_or(NtfsError::InvalidTime)?;
intervals = intervals
.checked_add(intervals_days)
- .ok_or(NtfsError::InvalidNtfsTime)?;
+ .ok_or(NtfsError::InvalidTime)?;
Ok(Self(intervals))
}