#![forbid(unsafe_code)]
pub mod detect;
pub mod filter;
pub mod fusefs;
pub mod inode_map;
pub mod session;
pub mod types;
#[cfg(unix)]
pub mod fuse_unix;
pub mod fuse_windows;
#[cfg(feature = "ext4")]
pub mod fs_ext4;
#[cfg(feature = "iso")]
pub mod fs_iso;
pub mod fs_raw;
pub use types::*;
use std::io;
use std::path::Path;
pub struct MountOptions {
pub read_only: bool,
pub daemon: bool,
pub fs_name: String,
}
impl Default for MountOptions {
fn default() -> Self {
Self {
read_only: false,
daemon: false,
fs_name: "4n6mount".to_string(),
}
}
}
pub trait ForensicFs {
fn root_ino(&self) -> u64;
fn read_dir(&mut self, ino: u64) -> FsResult<Vec<FsDirEntry>>;
fn lookup(&mut self, parent_ino: u64, name: &[u8]) -> FsResult<Option<u64>>;
fn metadata(&mut self, ino: u64) -> FsResult<FsMetadata>;
fn read_file(&mut self, ino: u64) -> FsResult<Vec<u8>>;
fn read_file_range(&mut self, ino: u64, offset: u64, len: u64) -> FsResult<Vec<u8>>;
fn read_link(&mut self, ino: u64) -> FsResult<Vec<u8>>;
fn deleted_inodes(&mut self) -> FsResult<Vec<FsDeletedInode>> {
Ok(vec![])
}
fn recover_file(&mut self, _ino: u64) -> FsResult<FsRecoveryResult> {
Err(not_supported("recover_file"))
}
fn timeline(&mut self) -> FsResult<Vec<FsTimelineEvent>> {
Ok(vec![])
}
fn unallocated_blocks(&mut self) -> FsResult<Vec<FsBlockRange>> {
Ok(vec![])
}
fn read_unallocated(&mut self, _range: &FsBlockRange) -> FsResult<Vec<u8>> {
Err(not_supported("read_unallocated"))
}
fn journal_transactions(&mut self) -> FsResult<Vec<FsTransaction>> {
Ok(vec![])
}
fn fs_info(&self) -> FsResult<serde_json::Value> {
Ok(serde_json::Value::Null)
}
fn block_size(&self) -> u64 {
4096
}
}
pub fn mount(
fs: Box<dyn ForensicFs + Send>,
mountpoint: &Path,
session: Option<session::Session>,
options: &MountOptions,
) -> io::Result<()> {
#[cfg(unix)]
{
fuse_unix::mount_unix(fs, mountpoint, session, options)
}
#[cfg(windows)]
{
fuse_windows::mount_windows(fs, mountpoint, session, options)
}
#[cfg(not(any(unix, windows)))]
{
let _ = (fs, mountpoint, session, options);
Err(io::Error::new(
io::ErrorKind::Unsupported,
"no FUSE support on this platform",
))
}
}