]> git.proxmox.com Git - pxar.git/commitdiff
expose full entry ranges for unsafe access
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 May 2020 11:51:33 +0000 (13:51 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 May 2020 11:51:33 +0000 (13:51 +0200)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/accessor.rs
src/accessor/sync.rs

index b3c7585289a79a640d444402138c3771c9bd9292..57032e0c6c1347fa267c93e5e1bcded4271ab2a8 100644 (file)
@@ -163,6 +163,17 @@ impl<T: Clone + ReadAt> AccessorImpl<T> {
         )
         .await
     }
+
+    /// Allow opening a directory at a specified offset.
+    pub async unsafe fn open_dir_at_end(&self, offset: u64) -> io::Result<DirectoryImpl<T>> {
+        DirectoryImpl::open_at_end(
+            self.input.clone(),
+            offset,
+            "/".into(),
+            Arc::clone(&self.caches),
+        )
+        .await
+    }
 }
 
 /// The directory random-access state machine implementation.
@@ -335,7 +346,7 @@ impl<T: Clone + ReadAt> DirectoryImpl<T> {
         Ok(FileEntryImpl {
             input: self.input.clone(),
             entry,
-            end_offset: self.end_offset(),
+            entry_range: self.entry_range(),
             caches: Arc::clone(&self.caches),
         })
     }
@@ -479,7 +490,7 @@ impl<T: Clone + ReadAt> DirectoryImpl<T> {
 pub(crate) struct FileEntryImpl<T: Clone + ReadAt> {
     input: T,
     entry: Entry,
-    end_offset: u64,
+    entry_range: Range<u64>,
     caches: Arc<Caches>,
 }
 
@@ -491,7 +502,7 @@ impl<T: Clone + ReadAt> FileEntryImpl<T> {
 
         DirectoryImpl::open_at_end(
             self.input.clone(),
-            self.end_offset,
+            self.entry_range.end,
             self.entry.path.clone(),
             Arc::clone(&self.caches),
         )
@@ -523,6 +534,12 @@ impl<T: Clone + ReadAt> FileEntryImpl<T> {
     pub fn entry(&self) -> &Entry {
         &self.entry
     }
+
+    /// Exposed for raw by-offset access methods (use with `open_dir_at_end`).
+    #[inline]
+    pub fn entry_range(&self) -> Range<u64> {
+        self.entry_range.clone()
+    }
 }
 
 /// An iterator over the contents of a directory.
@@ -580,7 +597,6 @@ impl<'a, T: Clone + ReadAt> DirEntryImpl<'a, T> {
     }
 
     async fn decode_entry(&self) -> io::Result<FileEntryImpl<T>> {
-        let end_offset = self.entry_range.end;
         let (entry, _decoder) = self
             .dir
             .decode_one_entry(self.entry_range.clone(), Some(&self.file_name))
@@ -589,10 +605,16 @@ impl<'a, T: Clone + ReadAt> DirEntryImpl<'a, T> {
         Ok(FileEntryImpl {
             input: self.dir.input.clone(),
             entry,
-            end_offset,
+            entry_range: self.entry_range(),
             caches: Arc::clone(&self.caches),
         })
     }
+
+    /// Exposed for raw by-offset access methods.
+    #[inline]
+    pub fn entry_range(&self) -> Range<u64> {
+        self.entry_range.clone()
+    }
 }
 
 /// A reader for file contents.
index 5ecd7e9dd76fa7cb512ed9a9c0a251d7fb502023..16db5d1572d463882246f8877244ad3c5ccba43f 100644 (file)
@@ -1,6 +1,7 @@
 //! Blocking `pxar` random access handling.
 
 use std::io;
+use std::ops::Range;
 use std::os::unix::fs::FileExt;
 use std::path::Path;
 use std::pin::Pin;
@@ -99,6 +100,11 @@ impl<T: Clone + ReadAt> Accessor<T> {
     pub fn open_root(&self) -> io::Result<Directory<T>> {
         Ok(Directory::new(poll_result_once(self.inner.open_root())?))
     }
+
+    /// Allow opening a directory at a specified offset.
+    pub async unsafe fn open_dir_at_end(&self, offset: u64) -> io::Result<Directory<T>> {
+        Ok(Directory::new(poll_result_once(self.inner.open_dir_at_end(offset))?))
+    }
 }
 
 /// Adapter for FileExt readers.
@@ -217,6 +223,12 @@ impl<T: Clone + ReadAt> FileEntry<T> {
     pub fn entry(&self) -> &Entry {
         &self.inner.entry()
     }
+
+    /// Exposed for raw by-offset access methods (use with `open_dir_at_end`).
+    #[inline]
+    pub fn entry_range(&self) -> Range<u64> {
+        self.inner.entry_range()
+    }
 }
 
 impl<T: Clone + ReadAt> std::ops::Deref for FileEntry<T> {
@@ -283,6 +295,13 @@ impl<'a, T: Clone + ReadAt> DirEntry<'a, T> {
     pub fn decode_entry(&self) -> io::Result<FileEntry<T>> {
         poll_result_once(self.inner.decode_entry()).map(|inner| FileEntry { inner })
     }
+
+
+    /// Exposed for raw by-offset access methods.
+    #[inline]
+    pub fn entry_range(&self) -> Range<u64> {
+        self.inner.entry_range()
+    }
 }
 
 /// A reader for file contents.