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:
Diffstat (limited to 'src/structured_values/index_allocation.rs')
-rw-r--r--src/structured_values/index_allocation.rs54
1 files changed, 29 insertions, 25 deletions
diff --git a/src/structured_values/index_allocation.rs b/src/structured_values/index_allocation.rs
index a062a79..0f6742d 100644
--- a/src/structured_values/index_allocation.rs
+++ b/src/structured_values/index_allocation.rs
@@ -4,25 +4,25 @@
use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
use crate::index_record::NtfsIndexRecord;
+use crate::ntfs::Ntfs;
use crate::structured_values::index_root::NtfsIndexRoot;
-use crate::structured_values::{
- NtfsStructuredValue, NtfsStructuredValueFromNonResidentAttributeValue,
-};
+use crate::structured_values::NtfsStructuredValue;
use crate::traits::NtfsReadSeek;
use crate::types::Vcn;
-use crate::value::non_resident_attribute::NtfsNonResidentAttributeValue;
+use crate::value::NtfsValue;
use binread::io::{Read, Seek, SeekFrom};
use core::iter::FusedIterator;
#[derive(Clone, Debug)]
pub struct NtfsIndexAllocation<'n, 'f> {
- value: NtfsNonResidentAttributeValue<'n, 'f>,
+ ntfs: &'n Ntfs,
+ value: NtfsValue<'n, 'f>,
}
impl<'n, 'f> NtfsIndexAllocation<'n, 'f> {
pub fn iter(&self, index_root: &NtfsIndexRoot) -> NtfsIndexRecords<'n, 'f> {
let index_record_size = index_root.index_record_size();
- NtfsIndexRecords::new(self.value.clone(), index_record_size)
+ NtfsIndexRecords::new(self.clone(), index_record_size)
}
pub fn record_from_vcn<T>(
@@ -36,24 +36,24 @@ impl<'n, 'f> NtfsIndexAllocation<'n, 'f> {
{
// Seek to the byte offset of the given VCN.
let mut value = self.value.clone();
- let offset = vcn.offset(self.value.ntfs())?;
+ let offset = vcn.offset(self.ntfs)?;
value.seek(fs, SeekFrom::Current(offset))?;
if value.stream_position() >= value.len() {
return Err(NtfsError::VcnOutOfBoundsInIndexAllocation {
- position: self.value.position(),
+ position: self.value.data_position().unwrap(),
vcn,
});
}
// Get the record.
let index_record_size = index_root.index_record_size();
- let record = NtfsIndexRecord::new(fs, value, index_record_size)?;
+ let record = NtfsIndexRecord::new(self.ntfs, fs, value, index_record_size)?;
// Validate that the VCN in the record is the requested one.
if record.vcn() != vcn {
return Err(NtfsError::VcnMismatchInIndexAllocation {
- position: self.value.position(),
+ position: self.value.data_position().unwrap(),
expected: vcn,
actual: record.vcn(),
});
@@ -63,34 +63,36 @@ impl<'n, 'f> NtfsIndexAllocation<'n, 'f> {
}
}
-impl<'n, 'f> NtfsStructuredValue for NtfsIndexAllocation<'n, 'f> {
+impl<'n, 'f> NtfsStructuredValue<'n, 'f> for NtfsIndexAllocation<'n, 'f> {
const TY: NtfsAttributeType = NtfsAttributeType::IndexAllocation;
-}
-impl<'n, 'f> NtfsStructuredValueFromNonResidentAttributeValue<'n, 'f>
- for NtfsIndexAllocation<'n, 'f>
-{
- fn from_non_resident_attribute_value<T>(
- _fs: &mut T,
- value: NtfsNonResidentAttributeValue<'n, 'f>,
- ) -> Result<Self>
+ fn from_value<T>(_fs: &mut T, value: NtfsValue<'n, 'f>) -> Result<Self>
where
T: Read + Seek,
{
- Ok(Self { value })
+ let ntfs = match &value {
+ NtfsValue::AttributeListNonResidentAttribute(value) => value.ntfs(),
+ NtfsValue::NonResidentAttribute(value) => value.ntfs(),
+ NtfsValue::Slice(_) => {
+ let position = value.data_position().unwrap();
+ return Err(NtfsError::UnexpectedResidentAttribute { position });
+ }
+ };
+
+ Ok(Self { ntfs, value })
}
}
#[derive(Clone, Debug)]
pub struct NtfsIndexRecords<'n, 'f> {
- value: NtfsNonResidentAttributeValue<'n, 'f>,
+ index_allocation: NtfsIndexAllocation<'n, 'f>,
index_record_size: u32,
}
impl<'n, 'f> NtfsIndexRecords<'n, 'f> {
- fn new(value: NtfsNonResidentAttributeValue<'n, 'f>, index_record_size: u32) -> Self {
+ fn new(index_allocation: NtfsIndexAllocation<'n, 'f>, index_record_size: u32) -> Self {
Self {
- value,
+ index_allocation,
index_record_size,
}
}
@@ -106,19 +108,21 @@ impl<'n, 'f> NtfsIndexRecords<'n, 'f> {
where
T: Read + Seek,
{
- if self.value.stream_position() >= self.value.len() {
+ if self.index_allocation.value.stream_position() >= self.index_allocation.value.len() {
return None;
}
// Get the current record.
let record = iter_try!(NtfsIndexRecord::new(
+ self.index_allocation.ntfs,
fs,
- self.value.clone(),
+ self.index_allocation.value.clone(),
self.index_record_size
));
// Advance our iterator to the next record.
iter_try!(self
+ .index_allocation
.value
.seek(fs, SeekFrom::Current(self.index_record_size as i64)));