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/attribute_value.rs')
-rw-r--r--src/attribute_value.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/attribute_value.rs b/src/attribute_value.rs
index 6f4f75f..522e22b 100644
--- a/src/attribute_value.rs
+++ b/src/attribute_value.rs
@@ -365,6 +365,16 @@ impl<'n, 'f> NtfsNonResidentAttributeValue<'n, 'f> {
})
}
+ pub fn attach<'a, T>(
+ self,
+ fs: &'a mut T,
+ ) -> NtfsNonResidentAttributeValueAttached<'n, 'f, 'a, T>
+ where
+ T: Read + Seek,
+ {
+ NtfsNonResidentAttributeValueAttached::new(fs, self)
+ }
+
/// Returns the absolute current data seek position within the filesystem, in bytes.
/// This may be `None` if:
/// * The current seek position is outside the valid range, or
@@ -543,6 +553,50 @@ impl<'n, 'f> NtfsReadSeek for NtfsNonResidentAttributeValue<'n, 'f> {
}
}
+pub struct NtfsNonResidentAttributeValueAttached<'n, 'f, 'a, T: Read + Seek> {
+ fs: &'a mut T,
+ value: NtfsNonResidentAttributeValue<'n, 'f>,
+}
+
+impl<'n, 'f, 'a, T> NtfsNonResidentAttributeValueAttached<'n, 'f, 'a, T>
+where
+ T: Read + Seek,
+{
+ fn new(fs: &'a mut T, value: NtfsNonResidentAttributeValue<'n, 'f>) -> Self {
+ Self { fs, value }
+ }
+
+ pub fn data_position(&self) -> Option<u64> {
+ self.value.data_position()
+ }
+
+ pub fn detach(self) -> NtfsNonResidentAttributeValue<'n, 'f> {
+ self.value
+ }
+
+ pub fn len(&self) -> u64 {
+ self.value.len()
+ }
+}
+
+impl<'n, 'f, 'a, T> Read for NtfsNonResidentAttributeValueAttached<'n, 'f, 'a, T>
+where
+ T: Read + Seek,
+{
+ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ self.value.read(self.fs, buf).map_err(io::Error::from)
+ }
+}
+
+impl<'n, 'f, 'a, T> Seek for NtfsNonResidentAttributeValueAttached<'n, 'f, 'a, T>
+where
+ T: Read + Seek,
+{
+ fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
+ self.value.seek(self.fs, pos).map_err(io::Error::from)
+ }
+}
+
#[derive(Clone, Debug)]
pub struct NtfsResidentAttributeValue<'f> {
data: &'f [u8],