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-04-21 22:15:51 +0300
committerColin Finck <colin@reactos.org>2021-04-21 22:15:51 +0300
commit5867e4bb56d605953df1ff2bc0cce9deef497c9a (patch)
tree8d314f10539312c3624ff897a6bac2857b56821c
parent20e0600072e8e837d9b478cc77871a43a16a446d (diff)
Improve interface of `NtfsFile`
-rw-r--r--src/attribute.rs4
-rw-r--r--src/ntfs_file.rs39
2 files changed, 36 insertions, 7 deletions
diff --git a/src/attribute.rs b/src/attribute.rs
index 254fa58..8f4b969 100644
--- a/src/attribute.rs
+++ b/src/attribute.rs
@@ -304,8 +304,8 @@ where
T: Read + Seek,
{
pub(crate) fn new(fs: &'a mut T, file: &NtfsFile) -> Self {
- let start = file.position + file.header.first_attribute_offset as u64;
- let end = file.position + file.header.used_size as u64;
+ let start = file.position() + file.first_attribute_offset() as u64;
+ let end = file.position() + file.used_size() as u64;
let items_range = start..end;
Self { fs, items_range }
diff --git a/src/ntfs_file.rs b/src/ntfs_file.rs
index e663848..4a180b4 100644
--- a/src/ntfs_file.rs
+++ b/src/ntfs_file.rs
@@ -38,16 +38,16 @@ pub(crate) struct NtfsFileRecordHeader {
record_header: NtfsRecordHeader,
sequence_number: u16,
hard_link_count: u16,
- pub(crate) first_attribute_offset: u16,
+ first_attribute_offset: u16,
flags: u16,
- pub(crate) used_size: u32,
+ used_size: u32,
allocated_size: u32,
base_file_record: u64,
next_attribute_number: u16,
}
bitflags! {
- struct NtfsFileRecordFlags: u16 {
+ pub struct NtfsFileFlags: u16 {
/// Record is in use.
const IN_USE = 0x0001;
/// Record is a directory.
@@ -56,8 +56,8 @@ bitflags! {
}
pub struct NtfsFile {
- pub(crate) header: NtfsFileRecordHeader,
- pub(crate) position: u64,
+ header: NtfsFileRecordHeader,
+ position: u64,
}
impl NtfsFile {
@@ -74,6 +74,10 @@ impl NtfsFile {
Ok(file)
}
+ pub fn allocated_size(&self) -> u32 {
+ self.header.allocated_size
+ }
+
pub fn attributes<'a, T>(&self, fs: &'a mut T) -> NtfsAttributes<'a, T>
where
T: Read + Seek,
@@ -81,6 +85,31 @@ impl NtfsFile {
NtfsAttributes::new(fs, &self)
}
+ pub(crate) fn first_attribute_offset(&self) -> u16 {
+ self.header.first_attribute_offset
+ }
+
+ /// Returns flags set for this NTFS file as specified by [`NtfsFileFlags`].
+ pub fn flags(&self) -> NtfsFileFlags {
+ NtfsFileFlags::from_bits_truncate(self.header.flags)
+ }
+
+ pub fn hard_link_count(&self) -> u16 {
+ self.header.hard_link_count
+ }
+
+ pub fn position(&self) -> u64 {
+ self.position
+ }
+
+ pub fn sequence_number(&self) -> u16 {
+ self.header.sequence_number
+ }
+
+ pub fn used_size(&self) -> u32 {
+ self.header.used_size
+ }
+
fn validate_signature(&self) -> Result<()> {
let signature = &self.header.record_header.signature;
let expected = b"FILE";