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-26 20:22:08 +0300
committerColin Finck <colin@reactos.org>2021-07-26 20:25:28 +0300
commit5775089c8e0196fcc50b509138b181551a63a3a2 (patch)
tree04fec3669b8f6587e5e71ba9f43e81c091375485
parent2bddeb867856f96060971945884424fe16c637f7 (diff)
NtfsStructuredValueFromData -> NtfsStructuredValueFromSlice
This prevents naming collisions with NTFS fields called "data".
-rw-r--r--src/attribute.rs6
-rw-r--r--src/index_entry.rs52
-rw-r--r--src/structured_values/file_name.rs16
-rw-r--r--src/structured_values/index_root.rs38
-rw-r--r--src/structured_values/mod.rs4
-rw-r--r--src/structured_values/object_id.rs18
-rw-r--r--src/structured_values/standard_information.rs14
-rw-r--r--src/structured_values/volume_information.rs12
-rw-r--r--src/structured_values/volume_name.rs16
9 files changed, 88 insertions, 88 deletions
diff --git a/src/attribute.rs b/src/attribute.rs
index 1ea83d8..11f19de 100644
--- a/src/attribute.rs
+++ b/src/attribute.rs
@@ -8,7 +8,7 @@ use crate::error::{NtfsError, Result};
use crate::ntfs_file::NtfsFile;
use crate::string::NtfsString;
use crate::structured_values::{
- NtfsStructuredValueFromData, NtfsStructuredValueFromNonResidentAttributeValue,
+ NtfsStructuredValueFromNonResidentAttributeValue, NtfsStructuredValueFromSlice,
};
use crate::types::Vcn;
use binread::io::{Read, Seek};
@@ -242,7 +242,7 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
pub fn resident_structured_value<S>(&self) -> Result<S>
where
- S: NtfsStructuredValueFromData<'f>,
+ S: NtfsStructuredValueFromSlice<'f>,
{
let ty = self.ty()?;
if ty != S::TY {
@@ -259,7 +259,7 @@ impl<'n, 'f> NtfsAttribute<'n, 'f> {
}
let resident_value = self.resident_value()?;
- S::from_data(resident_value.data(), self.position())
+ S::from_slice(resident_value.data(), self.position())
}
pub(crate) fn resident_value(&self) -> Result<NtfsResidentAttributeValue<'f>> {
diff --git a/src/index_entry.rs b/src/index_entry.rs
index 0fb4503..a3e54f4 100644
--- a/src/index_entry.rs
+++ b/src/index_entry.rs
@@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later
use crate::error::Result;
-use crate::structured_values::NtfsStructuredValueFromData;
+use crate::structured_values::NtfsStructuredValueFromSlice;
use crate::types::Vcn;
use bitflags::bitflags;
use byteorder::{ByteOrder, LittleEndian};
@@ -41,35 +41,35 @@ impl IndexEntryRange {
Self { range, position }
}
- pub(crate) fn to_entry<'d>(&self, data: &'d [u8]) -> NtfsIndexEntry<'d> {
- NtfsIndexEntry::new(&data[self.range.clone()], self.position)
+ pub(crate) fn to_entry<'s>(&self, slice: &'s [u8]) -> NtfsIndexEntry<'s> {
+ NtfsIndexEntry::new(&slice[self.range.clone()], self.position)
}
}
#[derive(Clone, Debug)]
-pub struct NtfsIndexEntry<'d> {
- data: &'d [u8],
+pub struct NtfsIndexEntry<'s> {
+ slice: &'s [u8],
position: u64,
}
-impl<'d> NtfsIndexEntry<'d> {
- pub(crate) const fn new(data: &'d [u8], position: u64) -> Self {
- Self { data, position }
+impl<'s> NtfsIndexEntry<'s> {
+ pub(crate) const fn new(slice: &'s [u8], position: u64) -> Self {
+ Self { slice, position }
}
pub fn flags(&self) -> NtfsIndexEntryFlags {
- let flags = self.data[offset_of!(IndexEntryHeader, flags)];
+ let flags = self.slice[offset_of!(IndexEntryHeader, flags)];
NtfsIndexEntryFlags::from_bits_truncate(flags)
}
pub fn index_entry_length(&self) -> u16 {
let start = offset_of!(IndexEntryHeader, index_entry_length);
- LittleEndian::read_u16(&self.data[start..])
+ LittleEndian::read_u16(&self.slice[start..])
}
pub fn key_length(&self) -> u16 {
let start = offset_of!(IndexEntryHeader, key_length);
- LittleEndian::read_u16(&self.data[start..])
+ LittleEndian::read_u16(&self.slice[start..])
}
/// Returns the structured value of the key of this Index Entry,
@@ -77,7 +77,7 @@ impl<'d> NtfsIndexEntry<'d> {
/// The last Index Entry never has a key.
pub fn key_structured_value<K>(&self) -> Option<Result<K>>
where
- K: NtfsStructuredValueFromData<'d>,
+ K: NtfsStructuredValueFromSlice<'s>,
{
// The key/stream is only set when the last entry flag is not set.
// https://flatcap.org/linux-ntfs/ntfs/concepts/index_entry.html
@@ -89,7 +89,7 @@ impl<'d> NtfsIndexEntry<'d> {
let end = start + self.key_length() as usize;
let position = self.position + start as u64;
- let structured_value = iter_try!(K::from_data(&self.data[start..end], position));
+ let structured_value = iter_try!(K::from_slice(&self.slice[start..end], position));
Some(Ok(structured_value))
}
@@ -102,7 +102,7 @@ impl<'d> NtfsIndexEntry<'d> {
// Get the subnode VCN from the very end of the Index Entry.
let start = self.index_entry_length() as usize - mem::size_of::<Vcn>();
- let vcn = Vcn::from(LittleEndian::read_i64(&self.data[start..]));
+ let vcn = Vcn::from(LittleEndian::read_i64(&self.slice[start..]));
Some(vcn)
}
@@ -161,37 +161,37 @@ impl Iterator for IndexNodeEntryRanges {
impl FusedIterator for IndexNodeEntryRanges {}
#[derive(Clone, Debug)]
-pub struct NtfsIndexNodeEntries<'d> {
- data: &'d [u8],
+pub struct NtfsIndexNodeEntries<'s> {
+ slice: &'s [u8],
position: u64,
}
-impl<'d> NtfsIndexNodeEntries<'d> {
- pub(crate) const fn new(data: &'d [u8], position: u64) -> Self {
- Self { data, position }
+impl<'s> NtfsIndexNodeEntries<'s> {
+ pub(crate) fn new(slice: &'s [u8], position: u64) -> Self {
+ Self { slice, position }
}
}
-impl<'d> Iterator for NtfsIndexNodeEntries<'d> {
- type Item = NtfsIndexEntry<'d>;
+impl<'s> Iterator for NtfsIndexNodeEntries<'s> {
+ type Item = NtfsIndexEntry<'s>;
fn next(&mut self) -> Option<Self::Item> {
- if self.data.is_empty() {
+ if self.slice.is_empty() {
return None;
}
// Get the current entry.
- let entry = NtfsIndexEntry::new(self.data, self.position);
+ let entry = NtfsIndexEntry::new(self.slice, self.position);
if entry.flags().contains(NtfsIndexEntryFlags::LAST_ENTRY) {
// This is the last entry.
// Ensure that we don't read any other entries by emptying the slice.
- self.data = &[];
+ self.slice = &[];
} else {
// This is not the last entry.
// Advance our iterator to the next entry.
let bytes_to_advance = entry.index_entry_length() as usize;
- self.data = &self.data[bytes_to_advance..];
+ self.slice = &self.slice[bytes_to_advance..];
self.position += bytes_to_advance as u64;
}
@@ -199,4 +199,4 @@ impl<'d> Iterator for NtfsIndexNodeEntries<'d> {
}
}
-impl<'d> FusedIterator for NtfsIndexNodeEntries<'d> {}
+impl<'s> FusedIterator for NtfsIndexNodeEntries<'s> {}
diff --git a/src/structured_values/file_name.rs b/src/structured_values/file_name.rs
index a98aff1..32e40dc 100644
--- a/src/structured_values/file_name.rs
+++ b/src/structured_values/file_name.rs
@@ -6,7 +6,7 @@ use crate::error::{NtfsError, Result};
use crate::file_reference::NtfsFileReference;
use crate::string::NtfsString;
use crate::structured_values::{
- NtfsFileAttributeFlags, NtfsStructuredValue, NtfsStructuredValueFromData,
+ NtfsFileAttributeFlags, NtfsStructuredValue, NtfsStructuredValueFromSlice,
};
use crate::time::NtfsTime;
use alloc::vec::Vec;
@@ -137,27 +137,27 @@ impl NtfsStructuredValue for NtfsFileName {
const TY: NtfsAttributeType = NtfsAttributeType::FileName;
}
-impl<'d> NtfsStructuredValueFromData<'d> for NtfsFileName {
- fn from_data(data: &'d [u8], position: u64) -> Result<Self> {
- if data.len() < FILE_NAME_MIN_SIZE {
+impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsFileName {
+ fn from_slice(slice: &'s [u8], position: u64) -> Result<Self> {
+ if slice.len() < FILE_NAME_MIN_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::FileName,
expected: FILE_NAME_MIN_SIZE,
- actual: data.len(),
+ actual: slice.len(),
});
}
- let mut cursor = Cursor::new(data);
+ let mut cursor = Cursor::new(slice);
let header = cursor.read_le::<FileNameHeader>()?;
let mut file_name = Self {
header,
name: Vec::new(),
};
- file_name.validate_name_length(data.len(), position)?;
+ file_name.validate_name_length(slice.len(), position)?;
file_name.validate_namespace(position)?;
- file_name.read_name(data);
+ file_name.read_name(slice);
Ok(file_name)
}
diff --git a/src/structured_values/index_root.rs b/src/structured_values/index_root.rs
index 098330f..797fd56 100644
--- a/src/structured_values/index_root.rs
+++ b/src/structured_values/index_root.rs
@@ -5,7 +5,7 @@ use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
use crate::index_entry::{IndexNodeEntryRanges, NtfsIndexNodeEntries};
use crate::index_record::{IndexNodeHeader, INDEX_NODE_HEADER_SIZE};
-use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromData};
+use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromSlice};
use byteorder::{ByteOrder, LittleEndian};
use core::ops::Range;
use memoffset::offset_of;
@@ -23,7 +23,7 @@ struct IndexRootHeader {
#[derive(Clone, Debug)]
pub struct NtfsIndexRoot<'f> {
- data: &'f [u8],
+ slice: &'f [u8],
position: u64,
}
@@ -32,9 +32,9 @@ const LARGE_INDEX_FLAG: u8 = 0x01;
impl<'f> NtfsIndexRoot<'f> {
pub fn entries(&self) -> Result<NtfsIndexNodeEntries<'f>> {
let (entries_range, position) = self.entries_range_and_position();
- let data = &self.data[entries_range];
+ let slice = &self.slice[entries_range];
- Ok(NtfsIndexNodeEntries::new(data, position))
+ Ok(NtfsIndexNodeEntries::new(slice, position))
}
fn entries_range_and_position(&self) -> (Range<usize>, u64) {
@@ -47,7 +47,7 @@ impl<'f> NtfsIndexRoot<'f> {
pub(crate) fn entry_ranges(&self) -> IndexNodeEntryRanges {
let (entries_range, position) = self.entries_range_and_position();
- let entries_data = self.data[entries_range].to_vec();
+ let entries_data = self.slice[entries_range].to_vec();
let range = 0..entries_data.len();
IndexNodeEntryRanges::new(entries_data, range, position)
@@ -55,22 +55,22 @@ impl<'f> NtfsIndexRoot<'f> {
pub fn index_allocated_size(&self) -> u32 {
let start = INDEX_ROOT_HEADER_SIZE + offset_of!(IndexNodeHeader, allocated_size);
- LittleEndian::read_u32(&self.data[start..])
+ LittleEndian::read_u32(&self.slice[start..])
}
fn index_entries_offset(&self) -> u32 {
let start = INDEX_ROOT_HEADER_SIZE + offset_of!(IndexNodeHeader, entries_offset);
- LittleEndian::read_u32(&self.data[start..])
+ LittleEndian::read_u32(&self.slice[start..])
}
pub fn index_record_size(&self) -> u32 {
let start = offset_of!(IndexRootHeader, index_record_size);
- LittleEndian::read_u32(&self.data[start..])
+ LittleEndian::read_u32(&self.slice[start..])
}
pub fn index_used_size(&self) -> u32 {
let start = INDEX_ROOT_HEADER_SIZE + offset_of!(IndexNodeHeader, index_size);
- LittleEndian::read_u32(&self.data[start..])
+ LittleEndian::read_u32(&self.slice[start..])
}
/// Returns whether the index belonging to this Index Root is large enough
@@ -78,7 +78,7 @@ impl<'f> NtfsIndexRoot<'f> {
/// Otherwise, the entire index information is stored in this Index Root.
pub fn is_large_index(&self) -> bool {
let start = INDEX_ROOT_HEADER_SIZE + offset_of!(IndexNodeHeader, flags);
- (self.data[start] & LARGE_INDEX_FLAG) != 0
+ (self.slice[start] & LARGE_INDEX_FLAG) != 0
}
pub fn position(&self) -> u64 {
@@ -88,19 +88,19 @@ impl<'f> NtfsIndexRoot<'f> {
fn validate_sizes(&self) -> Result<()> {
let (entries_range, _position) = self.entries_range_and_position();
- if entries_range.start >= self.data.len() {
+ if entries_range.start >= self.slice.len() {
return Err(NtfsError::InvalidIndexRootEntriesOffset {
position: self.position,
expected: entries_range.start,
- actual: self.data.len(),
+ actual: self.slice.len(),
});
}
- if entries_range.end > self.data.len() {
+ if entries_range.end > self.slice.len() {
return Err(NtfsError::InvalidIndexRootUsedSize {
position: self.position,
expected: entries_range.end,
- actual: self.data.len(),
+ actual: self.slice.len(),
});
}
@@ -112,18 +112,18 @@ impl<'f> NtfsStructuredValue for NtfsIndexRoot<'f> {
const TY: NtfsAttributeType = NtfsAttributeType::IndexRoot;
}
-impl<'f> NtfsStructuredValueFromData<'f> for NtfsIndexRoot<'f> {
- fn from_data(data: &'f [u8], position: u64) -> Result<Self> {
- if data.len() < INDEX_ROOT_HEADER_SIZE + INDEX_NODE_HEADER_SIZE {
+impl<'f> NtfsStructuredValueFromSlice<'f> for NtfsIndexRoot<'f> {
+ fn from_slice(slice: &'f [u8], position: u64) -> Result<Self> {
+ if slice.len() < INDEX_ROOT_HEADER_SIZE + INDEX_NODE_HEADER_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::IndexRoot,
expected: INDEX_ROOT_HEADER_SIZE,
- actual: data.len(),
+ actual: slice.len(),
});
}
- let index_root = Self { data, position };
+ let index_root = Self { slice, position };
index_root.validate_sizes()?;
Ok(index_root)
diff --git a/src/structured_values/mod.rs b/src/structured_values/mod.rs
index ce716d2..2f9bbc8 100644
--- a/src/structured_values/mod.rs
+++ b/src/structured_values/mod.rs
@@ -51,8 +51,8 @@ pub trait NtfsStructuredValue: Sized {
/// Create a structured value from an arbitrary data slice.
/// This handles Resident Attributes of File Records AND Keys of Index Records (when an attribute is indexed).
-pub trait NtfsStructuredValueFromData<'d>: NtfsStructuredValue {
- fn from_data(data: &'d [u8], position: u64) -> Result<Self>;
+pub trait NtfsStructuredValueFromSlice<'s>: NtfsStructuredValue {
+ fn from_slice(slice: &'s [u8], position: u64) -> Result<Self>;
}
/// Create a structured value from a Non-Resident Attribute Value.
diff --git a/src/structured_values/object_id.rs b/src/structured_values/object_id.rs
index 292308a..1a327f3 100644
--- a/src/structured_values/object_id.rs
+++ b/src/structured_values/object_id.rs
@@ -4,7 +4,7 @@
use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
use crate::guid::{NtfsGuid, GUID_SIZE};
-use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromData};
+use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromSlice};
use binread::io::Cursor;
use binread::BinReaderExt;
@@ -38,32 +38,32 @@ 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 {
+impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsObjectId {
+ fn from_slice(slice: &'s [u8], position: u64) -> Result<Self> {
+ if slice.len() < GUID_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::ObjectId,
expected: GUID_SIZE,
- actual: data.len(),
+ actual: slice.len(),
});
}
- let mut cursor = Cursor::new(data);
+ let mut cursor = Cursor::new(slice);
let object_id = cursor.read_le::<NtfsGuid>()?;
let mut birth_volume_id = None;
- if data.len() >= 2 * GUID_SIZE {
+ if slice.len() >= 2 * GUID_SIZE {
birth_volume_id = Some(cursor.read_le::<NtfsGuid>()?);
}
let mut birth_object_id = None;
- if data.len() >= 3 * GUID_SIZE {
+ if slice.len() >= 3 * GUID_SIZE {
birth_object_id = Some(cursor.read_le::<NtfsGuid>()?);
}
let mut domain_id = None;
- if data.len() >= 4 * GUID_SIZE {
+ if slice.len() >= 4 * GUID_SIZE {
domain_id = Some(cursor.read_le::<NtfsGuid>()?);
}
diff --git a/src/structured_values/standard_information.rs b/src/structured_values/standard_information.rs
index e6b3ffc..bc533c5 100644
--- a/src/structured_values/standard_information.rs
+++ b/src/structured_values/standard_information.rs
@@ -4,7 +4,7 @@
use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
use crate::structured_values::{
- NtfsFileAttributeFlags, NtfsStructuredValue, NtfsStructuredValueFromData,
+ NtfsFileAttributeFlags, NtfsStructuredValue, NtfsStructuredValueFromSlice,
};
use crate::time::NtfsTime;
use binread::io::Cursor;
@@ -96,22 +96,22 @@ impl NtfsStructuredValue for NtfsStandardInformation {
const TY: NtfsAttributeType = NtfsAttributeType::StandardInformation;
}
-impl<'d> NtfsStructuredValueFromData<'d> for NtfsStandardInformation {
- fn from_data(data: &'d [u8], position: u64) -> Result<Self> {
- if data.len() < STANDARD_INFORMATION_SIZE_NTFS1 {
+impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsStandardInformation {
+ fn from_slice(slice: &'s [u8], position: u64) -> Result<Self> {
+ if slice.len() < STANDARD_INFORMATION_SIZE_NTFS1 {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::StandardInformation,
expected: STANDARD_INFORMATION_SIZE_NTFS1,
- actual: data.len(),
+ actual: slice.len(),
});
}
- let mut cursor = Cursor::new(data);
+ let mut cursor = Cursor::new(slice);
let ntfs1_data = cursor.read_le::<StandardInformationDataNtfs1>()?;
let mut ntfs3_data = None;
- if data.len() >= STANDARD_INFORMATION_SIZE_NTFS3 {
+ if slice.len() >= STANDARD_INFORMATION_SIZE_NTFS3 {
ntfs3_data = Some(cursor.read_le::<StandardInformationDataNtfs3>()?);
}
diff --git a/src/structured_values/volume_information.rs b/src/structured_values/volume_information.rs
index dfc2290..4550bc1 100644
--- a/src/structured_values/volume_information.rs
+++ b/src/structured_values/volume_information.rs
@@ -3,7 +3,7 @@
use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
-use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromData};
+use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromSlice};
use binread::io::Cursor;
use binread::{BinRead, BinReaderExt};
use bitflags::bitflags;
@@ -56,18 +56,18 @@ impl NtfsStructuredValue for NtfsVolumeInformation {
const TY: NtfsAttributeType = NtfsAttributeType::VolumeInformation;
}
-impl<'d> NtfsStructuredValueFromData<'d> for NtfsVolumeInformation {
- fn from_data(data: &'d [u8], position: u64) -> Result<Self> {
- if data.len() < VOLUME_INFORMATION_SIZE {
+impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsVolumeInformation {
+ fn from_slice(slice: &'s [u8], position: u64) -> Result<Self> {
+ if slice.len() < VOLUME_INFORMATION_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::StandardInformation,
expected: VOLUME_INFORMATION_SIZE,
- actual: data.len(),
+ actual: slice.len(),
});
}
- let mut cursor = Cursor::new(data);
+ let mut cursor = Cursor::new(slice);
let info = cursor.read_le::<VolumeInformationData>()?;
Ok(Self { info })
diff --git a/src/structured_values/volume_name.rs b/src/structured_values/volume_name.rs
index 066ebe0..77b2c8e 100644
--- a/src/structured_values/volume_name.rs
+++ b/src/structured_values/volume_name.rs
@@ -4,7 +4,7 @@
use crate::attribute::NtfsAttributeType;
use crate::error::{NtfsError, Result};
use crate::string::NtfsString;
-use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromData};
+use crate::structured_values::{NtfsStructuredValue, NtfsStructuredValueFromSlice};
use alloc::vec::Vec;
use core::mem;
@@ -37,25 +37,25 @@ impl NtfsStructuredValue for NtfsVolumeName {
const TY: NtfsAttributeType = NtfsAttributeType::VolumeName;
}
-impl<'d> NtfsStructuredValueFromData<'d> for NtfsVolumeName {
- fn from_data(data: &'d [u8], position: u64) -> Result<Self> {
- if data.len() < VOLUME_NAME_MIN_SIZE {
+impl<'s> NtfsStructuredValueFromSlice<'s> for NtfsVolumeName {
+ fn from_slice(slice: &'s [u8], position: u64) -> Result<Self> {
+ if slice.len() < VOLUME_NAME_MIN_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::VolumeName,
expected: VOLUME_NAME_MIN_SIZE,
- actual: data.len(),
+ actual: slice.len(),
});
- } else if data.len() > VOLUME_NAME_MAX_SIZE {
+ } else if slice.len() > VOLUME_NAME_MAX_SIZE {
return Err(NtfsError::InvalidStructuredValueSize {
position,
ty: NtfsAttributeType::VolumeName,
expected: VOLUME_NAME_MAX_SIZE,
- actual: data.len(),
+ actual: slice.len(),
});
}
- let name = data.to_vec();
+ let name = slice.to_vec();
Ok(Self { name })
}
}