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:16:12 +0300
committerColin Finck <colin@reactos.org>2021-07-21 21:16:12 +0300
commitb659b7861b19dde96819620c71bee883f23d3e13 (patch)
tree9e3a3347868e9c7355fe6cca1a4f62cbede4ae47 /src/structured_values/object_id.rs
parent9fa9dda7eede3ca5689e67ad6e7ca76398443603 (diff)
Implement Update Sequence Array parsing and record fixups.
This is where things get dirty. As NTFS requires us to fix up records, we can't continue our previous design of avoiding dynamic allocations and reading everything on demand via `io::Read`. Instead, we now read an entire record (usually not larger than 4 KiB), fix it up, and store it in a `Vec`. This required changes almost everywhere. It should be noted that many non-resident attributes are not part of a record, which is why structured values are now implemented differently depending on the attribute type. On the plus side, many structures need less borrowing now, which makes them more comfortable to use. I have also added missing sanity checks with precise errors where appropriate.
Diffstat (limited to 'src/structured_values/object_id.rs')
-rw-r--r--src/structured_values/object_id.rs44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/structured_values/object_id.rs b/src/structured_values/object_id.rs
index f9c84aa..292308a 100644
--- a/src/structured_values/object_id.rs
+++ b/src/structured_values/object_id.rs
@@ -2,12 +2,10 @@
// SPDX-License-Identifier: GPL-2.0-or-later
use crate::attribute::NtfsAttributeType;
-use crate::attribute_value::NtfsAttributeValue;
use crate::error::{NtfsError, Result};
use crate::guid::{NtfsGuid, GUID_SIZE};
-use crate::ntfs::Ntfs;
-use crate::structured_values::NewNtfsStructuredValue;
-use binread::io::{Read, Seek};
+use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromData};
+use binread::io::Cursor;
use binread::BinReaderExt;
#[derive(Clone, Debug)]
@@ -36,41 +34,37 @@ impl NtfsObjectId {
}
}
-impl<'n> NewNtfsStructuredValue<'n> for NtfsObjectId {
- fn new<T>(
- _ntfs: &'n Ntfs,
- fs: &mut T,
- value: NtfsAttributeValue<'n>,
- length: u64,
- ) -> Result<Self>
- where
- T: Read + Seek,
- {
- if length < GUID_SIZE {
+impl NtfsStructuredValue for NtfsObjectId {
+ const TY: NtfsAttributeType = NtfsAttributeType::ObjectId;
+}
+
+impl<'d> NtfsStructuredValueFromData<'d> for NtfsObjectId {
+ fn from_data(data: &'d [u8], position: u64) -> Result<Self> {
+ if data.len() < GUID_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
- position: value.data_position().unwrap(),
+ position,
ty: NtfsAttributeType::ObjectId,
expected: GUID_SIZE,
- actual: length,
+ actual: data.len(),
});
}
- let mut value_attached = value.attach(fs);
- let object_id = value_attached.read_le::<NtfsGuid>()?;
+ let mut cursor = Cursor::new(data);
+ let object_id = cursor.read_le::<NtfsGuid>()?;
let mut birth_volume_id = None;
- if length >= 2 * GUID_SIZE {
- birth_volume_id = Some(value_attached.read_le::<NtfsGuid>()?);
+ if data.len() >= 2 * GUID_SIZE {
+ birth_volume_id = Some(cursor.read_le::<NtfsGuid>()?);
}
let mut birth_object_id = None;
- if length >= 3 * GUID_SIZE {
- birth_object_id = Some(value_attached.read_le::<NtfsGuid>()?);
+ if data.len() >= 3 * GUID_SIZE {
+ birth_object_id = Some(cursor.read_le::<NtfsGuid>()?);
}
let mut domain_id = None;
- if length >= 4 * GUID_SIZE {
- domain_id = Some(value_attached.read_le::<NtfsGuid>()?);
+ if data.len() >= 4 * GUID_SIZE {
+ domain_id = Some(cursor.read_le::<NtfsGuid>()?);
}
Ok(Self {