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-05-05 08:14:06 +0300
committerColin Finck <colin@reactos.org>2021-05-05 08:14:06 +0300
commit8ff664400cf226ffc778b19fc42c2c4c5eaea6ae (patch)
tree8cff23bd24cb5fe487d8107756a8208ff6e4b4c0
parent0402611794e8d86814e25eba8515d00e1685ce4b (diff)
Implement `NtfsAttributeValue::len` and use it for the structured values
-rw-r--r--src/attribute.rs18
-rw-r--r--src/attribute_value.rs17
-rw-r--r--src/structured_values/file_name.rs5
-rw-r--r--src/structured_values/index_root.rs5
-rw-r--r--src/structured_values/object_id.rs11
-rw-r--r--src/structured_values/standard_information.rs7
-rw-r--r--src/structured_values/volume_information.rs5
-rw-r--r--src/structured_values/volume_name.rs11
8 files changed, 41 insertions, 38 deletions
diff --git a/src/attribute.rs b/src/attribute.rs
index 684ddd9..b6b8a55 100644
--- a/src/attribute.rs
+++ b/src/attribute.rs
@@ -231,35 +231,29 @@ impl<'n> NtfsAttribute<'n> {
match self.ty()? {
NtfsAttributeType::StandardInformation => {
- let inner = NtfsStandardInformation::new(
- self.position,
- attached_value,
- self.value_length(),
- )?;
+ let inner = NtfsStandardInformation::new(self.position, attached_value)?;
Ok(NtfsStructuredValue::StandardInformation(inner))
}
NtfsAttributeType::AttributeList => panic!("TODO"),
NtfsAttributeType::FileName => {
- let inner = NtfsFileName::new(self.position, attached_value, self.value_length())?;
+ let inner = NtfsFileName::new(self.position, attached_value)?;
Ok(NtfsStructuredValue::FileName(inner))
}
NtfsAttributeType::ObjectId => {
- let inner = NtfsObjectId::new(self.position, attached_value, self.value_length())?;
+ let inner = NtfsObjectId::new(self.position, attached_value)?;
Ok(NtfsStructuredValue::ObjectId(inner))
}
NtfsAttributeType::SecurityDescriptor => panic!("TODO"),
NtfsAttributeType::VolumeName => {
- let inner =
- NtfsVolumeName::new(self.position, attached_value, self.value_length())?;
+ let inner = NtfsVolumeName::new(self.position, attached_value)?;
Ok(NtfsStructuredValue::VolumeName(inner))
}
NtfsAttributeType::VolumeInformation => {
- let inner =
- NtfsVolumeInformation::new(self.position, attached_value, self.value_length())?;
+ let inner = NtfsVolumeInformation::new(self.position, attached_value)?;
Ok(NtfsStructuredValue::VolumeInformation(inner))
}
NtfsAttributeType::IndexRoot => {
- let inner = NtfsIndexRoot::new(self.position, attached_value, self.value_length())?;
+ let inner = NtfsIndexRoot::new(self.position, attached_value)?;
Ok(NtfsStructuredValue::IndexRoot(inner))
}
ty => Err(NtfsError::UnsupportedStructuredValue {
diff --git a/src/attribute_value.rs b/src/attribute_value.rs
index b49c684..f7cd840 100644
--- a/src/attribute_value.rs
+++ b/src/attribute_value.rs
@@ -25,7 +25,14 @@ impl<'n> NtfsAttributeValue<'n> {
NtfsAttributeValueAttached::new(fs, self)
}
- pub(crate) fn position(&self) -> u64 {
+ pub fn len(&self) -> u64 {
+ match self {
+ Self::Resident(inner) => inner.len(),
+ Self::NonResident(inner) => inner.len(),
+ }
+ }
+
+ pub fn position(&self) -> u64 {
match self {
Self::Resident(inner) => inner.position(),
Self::NonResident(inner) => inner.position(),
@@ -79,6 +86,10 @@ where
self.value
}
+ pub fn len(&self) -> u64 {
+ self.value.len()
+ }
+
pub fn position(&self) -> u64 {
self.value.position()
}
@@ -346,6 +357,10 @@ impl<'n> NtfsAttributeNonResidentValue<'n> {
NtfsDataRuns::new(self.ntfs, self.data_runs_range.clone())
}
+ pub fn len(&self) -> u64 {
+ self.data_size
+ }
+
pub fn position(&self) -> u64 {
self.data_runs_range.start
}
diff --git a/src/structured_values/file_name.rs b/src/structured_values/file_name.rs
index ce7e376..06e3d2a 100644
--- a/src/structured_values/file_name.rs
+++ b/src/structured_values/file_name.rs
@@ -53,17 +53,16 @@ impl NtfsFileName {
pub(crate) fn new<T>(
attribute_position: u64,
mut value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- value_length: u64,
) -> Result<Self>
where
T: Read + Seek,
{
- if value_length < FILE_NAME_MIN_SIZE {
+ if value_attached.len() < FILE_NAME_MIN_SIZE {
return Err(NtfsError::InvalidAttributeSize {
position: attribute_position,
ty: NtfsAttributeType::FileName,
expected: FILE_NAME_MIN_SIZE,
- actual: value_length,
+ actual: value_attached.len(),
});
}
diff --git a/src/structured_values/index_root.rs b/src/structured_values/index_root.rs
index a8c1d44..14873e2 100644
--- a/src/structured_values/index_root.rs
+++ b/src/structured_values/index_root.rs
@@ -37,17 +37,16 @@ impl NtfsIndexRoot {
pub(crate) fn new<T>(
attribute_position: u64,
mut value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- value_length: u64,
) -> Result<Self>
where
T: Read + Seek,
{
- if value_length < INDEX_ROOT_HEADER_SIZE {
+ if value_attached.len() < INDEX_ROOT_HEADER_SIZE {
return Err(NtfsError::InvalidAttributeSize {
position: attribute_position,
ty: NtfsAttributeType::IndexRoot,
expected: INDEX_ROOT_HEADER_SIZE,
- actual: value_length,
+ actual: value_attached.len(),
});
}
diff --git a/src/structured_values/object_id.rs b/src/structured_values/object_id.rs
index db165e4..998536d 100644
--- a/src/structured_values/object_id.rs
+++ b/src/structured_values/object_id.rs
@@ -20,34 +20,33 @@ impl NtfsObjectId {
pub(crate) fn new<T>(
attribute_position: u64,
mut value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- value_length: u64,
) -> Result<Self>
where
T: Read + Seek,
{
- if value_length < GUID_SIZE {
+ if value_attached.len() < GUID_SIZE {
return Err(NtfsError::InvalidAttributeSize {
position: attribute_position,
ty: NtfsAttributeType::ObjectId,
expected: GUID_SIZE,
- actual: value_length,
+ actual: value_attached.len(),
});
}
let object_id = value_attached.read_le::<NtfsGuid>()?;
let mut birth_volume_id = None;
- if value_length >= 2 * GUID_SIZE {
+ if value_attached.len() >= 2 * GUID_SIZE {
birth_volume_id = Some(value_attached.read_le::<NtfsGuid>()?);
}
let mut birth_object_id = None;
- if value_length >= 3 * GUID_SIZE {
+ if value_attached.len() >= 3 * GUID_SIZE {
birth_object_id = Some(value_attached.read_le::<NtfsGuid>()?);
}
let mut domain_id = None;
- if value_length >= 4 * GUID_SIZE {
+ if value_attached.len() >= 4 * GUID_SIZE {
domain_id = Some(value_attached.read_le::<NtfsGuid>()?);
}
diff --git a/src/structured_values/standard_information.rs b/src/structured_values/standard_information.rs
index dc68d2e..3975be5 100644
--- a/src/structured_values/standard_information.rs
+++ b/src/structured_values/standard_information.rs
@@ -45,24 +45,23 @@ impl NtfsStandardInformation {
pub(crate) fn new<T>(
attribute_position: u64,
mut value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- value_length: u64,
) -> Result<Self>
where
T: Read + Seek,
{
- if value_length < STANDARD_INFORMATION_SIZE_NTFS1 {
+ 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_length,
+ actual: value_attached.len(),
});
}
let data = value_attached.read_le::<StandardInformationData>()?;
let mut ntfs3_data = None;
- if value_length >= STANDARD_INFORMATION_SIZE_NTFS3 {
+ if value_attached.len() >= STANDARD_INFORMATION_SIZE_NTFS3 {
ntfs3_data = Some(value_attached.read_le::<StandardInformationDataNtfs3>()?);
}
diff --git a/src/structured_values/volume_information.rs b/src/structured_values/volume_information.rs
index 8b075fa..4dc3cb1 100644
--- a/src/structured_values/volume_information.rs
+++ b/src/structured_values/volume_information.rs
@@ -42,17 +42,16 @@ impl NtfsVolumeInformation {
pub(crate) fn new<T>(
attribute_position: u64,
mut value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- value_length: u64,
) -> Result<Self>
where
T: Read + Seek,
{
- if value_length < VOLUME_INFORMATION_SIZE {
+ if value_attached.len() < VOLUME_INFORMATION_SIZE {
return Err(NtfsError::InvalidAttributeSize {
position: attribute_position,
ty: NtfsAttributeType::StandardInformation,
expected: VOLUME_INFORMATION_SIZE,
- actual: value_length,
+ actual: value_attached.len(),
});
}
diff --git a/src/structured_values/volume_name.rs b/src/structured_values/volume_name.rs
index eafeaab..9633f78 100644
--- a/src/structured_values/volume_name.rs
+++ b/src/structured_values/volume_name.rs
@@ -24,29 +24,28 @@ impl NtfsVolumeName {
pub(crate) fn new<T>(
attribute_position: u64,
value_attached: NtfsAttributeValueAttached<'_, '_, T>,
- value_length: u64,
) -> Result<Self>
where
T: Read + Seek,
{
- if value_length < VOLUME_NAME_MIN_SIZE {
+ if value_attached.len() < VOLUME_NAME_MIN_SIZE {
return Err(NtfsError::InvalidAttributeSize {
position: attribute_position,
ty: NtfsAttributeType::VolumeName,
expected: VOLUME_NAME_MIN_SIZE,
- actual: value_length,
+ actual: value_attached.len(),
});
- } else if value_length > VOLUME_NAME_MAX_SIZE {
+ } else if value_attached.len() > VOLUME_NAME_MAX_SIZE {
return Err(NtfsError::InvalidAttributeSize {
position: attribute_position,
ty: NtfsAttributeType::VolumeName,
expected: VOLUME_NAME_MAX_SIZE,
- actual: value_length,
+ actual: value_attached.len(),
});
}
let name_position = value_attached.position();
- let name_length = value_length as u16;
+ let name_length = value_attached.len() as u16;
Ok(Self {
name_position,