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-06-04 12:46:52 +0300
committerColin Finck <colin@reactos.org>2021-06-04 12:46:52 +0300
commitcba70d68b52025dda25d07e516d27ca7c73b607f (patch)
tree8e1b59d70ff04a8cf99e9f0be7406cc9ab47857f /src/structured_values/standard_information.rs
parent98ffe4dec521551bb1b0ae904d730d360d3673eb (diff)
Make all structured values ready for indexes and non-resident attributes
This introduces a `NewNtfsStructuredValue` trait for the `new` function of all structured values. Indexes later need that to return the structured value specified by a type parameter. We also have to pass an explicit length and can't just rely on the end of the passed `NtfsAttributeValue`/`NtfsAttributeValueAttached`. For structured values of non-resident attributes, we have to store an `NtfsAttributeValue` instead of an absolute byte position, in order to let a structured value read additional data (e.g. the name of an `NtfsFileName`). The `NtfsAttributeValue` properly moves between data runs while reading.
Diffstat (limited to 'src/structured_values/standard_information.rs')
-rw-r--r--src/structured_values/standard_information.rs56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/structured_values/standard_information.rs b/src/structured_values/standard_information.rs
index 3975be5..a596d2c 100644
--- a/src/structured_values/standard_information.rs
+++ b/src/structured_values/standard_information.rs
@@ -2,9 +2,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
use crate::attribute::NtfsAttributeType;
-use crate::attribute_value::NtfsAttributeValueAttached;
+use crate::attribute_value::NtfsAttributeValue;
use crate::error::{NtfsError, Result};
-use crate::structured_values::NtfsFileAttributeFlags;
+use crate::structured_values::{NewNtfsStructuredValue, NtfsFileAttributeFlags};
use crate::time::NtfsTime;
use binread::io::{Read, Seek};
use binread::{BinRead, BinReaderExt};
@@ -42,32 +42,6 @@ pub struct NtfsStandardInformation {
}
impl NtfsStandardInformation {
- pub(crate) fn new<T>(
- attribute_position: u64,
- mut value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- ) -> Result<Self>
- where
- T: Read + Seek,
- {
- if value_attached.len() < STANDARD_INFORMATION_SIZE_NTFS1 {
- return Err(NtfsError::InvalidAttributeSize {
- position: attribute_position,
- ty: NtfsAttributeType::StandardInformation,
- expected: STANDARD_INFORMATION_SIZE_NTFS1,
- actual: value_attached.len(),
- });
- }
-
- let data = value_attached.read_le::<StandardInformationData>()?;
-
- let mut ntfs3_data = None;
- if value_attached.len() >= STANDARD_INFORMATION_SIZE_NTFS3 {
- ntfs3_data = Some(value_attached.read_le::<StandardInformationDataNtfs3>()?);
- }
-
- Ok(Self { data, ntfs3_data })
- }
-
pub fn access_time(&self) -> NtfsTime {
self.data.access_time
}
@@ -117,6 +91,32 @@ impl NtfsStandardInformation {
}
}
+impl<'n> NewNtfsStructuredValue<'n> for NtfsStandardInformation {
+ fn new<T>(fs: &mut T, value: NtfsAttributeValue<'n>, length: u64) -> Result<Self>
+ where
+ T: Read + Seek,
+ {
+ if length < STANDARD_INFORMATION_SIZE_NTFS1 {
+ return Err(NtfsError::InvalidStructuredValueSize {
+ position: value.data_position().unwrap(),
+ ty: NtfsAttributeType::StandardInformation,
+ expected: STANDARD_INFORMATION_SIZE_NTFS1,
+ actual: length,
+ });
+ }
+
+ let mut value_attached = value.attach(fs);
+ let data = value_attached.read_le::<StandardInformationData>()?;
+
+ let mut ntfs3_data = None;
+ if length >= STANDARD_INFORMATION_SIZE_NTFS3 {
+ ntfs3_data = Some(value_attached.read_le::<StandardInformationDataNtfs3>()?);
+ }
+
+ Ok(Self { data, ntfs3_data })
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;