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/types.rs')
-rw-r--r--src/types.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/types.rs b/src/types.rs
index 563f353..842635c 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -1,11 +1,17 @@
// Copyright 2021 Colin Finck <colin@reactos.org>
// SPDX-License-Identifier: GPL-2.0-or-later
+//
+//! Supplementary helper types.
use crate::error::{NtfsError, Result};
use crate::ntfs::Ntfs;
use binread::BinRead;
use derive_more::{Binary, Display, From, LowerHex, Octal, UpperHex};
+/// A Logical Cluster Number (LCN).
+///
+/// NTFS divides a filesystem into clusters of a given size (power of two), see [`Ntfs::cluster_size`].
+/// The LCN is an absolute cluster index into the filesystem.
#[derive(
Binary,
BinRead,
@@ -25,6 +31,7 @@ use derive_more::{Binary, Display, From, LowerHex, Octal, UpperHex};
pub struct Lcn(u64);
impl Lcn {
+ /// Performs a checked addition of the given Virtual Cluster Number (VCN), returning a new LCN.
pub fn checked_add(&self, vcn: Vcn) -> Option<Lcn> {
if vcn.0 >= 0 {
self.0.checked_add(vcn.0 as u64).map(Into::into)
@@ -35,6 +42,7 @@ impl Lcn {
}
}
+ /// Returns the absolute byte position of this LCN within the filesystem.
pub fn position(&self, ntfs: &Ntfs) -> Result<u64> {
self.0
.checked_mul(ntfs.cluster_size() as u64)
@@ -42,6 +50,11 @@ impl Lcn {
}
}
+/// A Virtual Cluster Number (VCN).
+///
+/// NTFS divides a filesystem into clusters of a given size (power of two), see [`Ntfs::cluster_size`].
+/// The VCN is a cluster index into the filesystem that is relative to a Logical Cluster Number (LCN)
+/// or relative to the start of an attribute value.
#[derive(
Binary,
BinRead,
@@ -61,6 +74,7 @@ impl Lcn {
pub struct Vcn(i64);
impl Vcn {
+ /// Converts this VCN into a byte offset (with respect to the cluster size of the provided [`Ntfs`] filesystem).
pub fn offset(&self, ntfs: &Ntfs) -> Result<i64> {
self.0
.checked_mul(ntfs.cluster_size() as i64)