diff options
author | Colin Finck <colin@reactos.org> | 2021-06-04 12:46:52 +0300 |
---|---|---|
committer | Colin Finck <colin@reactos.org> | 2021-06-04 12:46:52 +0300 |
commit | cba70d68b52025dda25d07e516d27ca7c73b607f (patch) | |
tree | 8e1b59d70ff04a8cf99e9f0be7406cc9ab47857f /src/structured_values/index_root.rs | |
parent | 98ffe4dec521551bb1b0ae904d730d360d3673eb (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/index_root.rs')
-rw-r--r-- | src/structured_values/index_root.rs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/structured_values/index_root.rs b/src/structured_values/index_root.rs index 14873e2..26c7115 100644 --- a/src/structured_values/index_root.rs +++ b/src/structured_values/index_root.rs @@ -2,8 +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::NewNtfsStructuredValue; use binread::io::{Read, Seek}; use binread::{BinRead, BinReaderExt}; @@ -33,23 +34,21 @@ pub struct NtfsIndexRoot { header: IndexRootHeader, } -impl NtfsIndexRoot { - pub(crate) fn new<T>( - attribute_position: u64, - mut value_attached: NtfsAttributeValueAttached<'_, '_, T>, - ) -> Result<Self> +impl<'n> NewNtfsStructuredValue<'n> for NtfsIndexRoot<'n> { + fn new<T>(fs: &mut T, value: NtfsAttributeValue<'n>, _length: u64) -> Result<Self> where T: Read + Seek, { - if value_attached.len() < INDEX_ROOT_HEADER_SIZE { - return Err(NtfsError::InvalidAttributeSize { - position: attribute_position, + if value.len() < INDEX_ROOT_HEADER_SIZE { + return Err(NtfsError::InvalidStructuredValueSize { + position: value.data_position().unwrap(), ty: NtfsAttributeType::IndexRoot, expected: INDEX_ROOT_HEADER_SIZE, - actual: value_attached.len(), + actual: value.len(), }); } + let mut value_attached = value.clone().attach(fs); let header = value_attached.read_le::<IndexRootHeader>()?; Ok(Self { header }) |