Struct encrypted_fs::encrypted_fs::EncryptedFs

source ·
pub struct EncryptedFs { /* private fields */ }
Expand description

Encrypted FS that stores encrypted files in a dedicated directory with a specific structure based on inode.

Implementations§

source§

impl EncryptedFs

source

pub fn new( data_dir: &str, password: &str, cipher: Cipher, derive_key_hash_rounds: u32 ) -> FsResult<Self>

source

pub fn node_exists(&self, ino: u64) -> bool

source

pub fn is_dir(&self, ino: u64) -> bool

source

pub fn is_file(&self, ino: u64) -> bool

source

pub fn create_nod( &mut self, parent: u64, name: &str, attr: FileAttr, read: bool, write: bool ) -> FsResult<(u64, FileAttr)>

Create a new node in the filesystem You don’t need to provide attr.ino, it will be auto-generated anyway.

source

pub fn find_by_name( &mut self, parent: u64, name: &str ) -> FsResult<Option<FileAttr>>

source

pub fn children_count(&self, ino: u64) -> FsResult<usize>

Count children of a directory. This includes also . and ...

source

pub fn remove_dir(&mut self, parent: u64, name: &str) -> FsResult<()>

source

pub fn remove_file(&mut self, parent: u64, name: &str) -> FsResult<()>

source

pub fn exists_by_name(&self, parent: u64, name: &str) -> bool

source

pub fn read_dir(&self, ino: u64) -> FsResult<DirectoryEntryIterator>

source

pub fn read_dir_plus(&self, ino: u64) -> FsResult<DirectoryEntryPlusIterator>

Like read_dir but with FileAttr so we don’t need to query again for those.

source

pub fn get_inode(&mut self, ino: u64) -> FsResult<FileAttr>

source

pub fn update_inode( &mut self, ino: u64, perm: u16, atime: SystemTime, mtime: SystemTime, ctime: SystemTime, crtime: SystemTime, uid: u32, gid: u32, size: u64, nlink: u32, flags: u32 ) -> FsResult<()>

source

pub fn read( &mut self, ino: u64, offset: u64, buf: &mut [u8], handle: u64 ) -> FsResult<usize>

Read the contents from an ‘offset’. If we try to read outside of file size, we return 0 bytes. Depending on the encryption type we might need to re-read bytes until the ‘offset’, in some case even from the beginning of the file to the desired offset. This will slow down the read operation if we read from very distanced offsets. The most speed is obtained when we read sequentially from the beginning of the file. If the file is not opened for read, it will return an error of type [‘FsError::InvalidFileHandle’].

source

pub fn release_handle(&mut self, handle: u64) -> FsResult<()>

source

pub fn is_read_handle(&self, fh: u64) -> bool

Check if a file is opened for read with this handle.

source

pub fn is_write_handle(&self, fh: u64) -> bool

Check if a file is opened for write with this handle.

source

pub fn write_all( &mut self, ino: u64, offset: u64, buf: &[u8], handle: u64 ) -> FsResult<()>

Writes the contents of buf to the file at ino starting at offset. Depending on the encryption type we might need to re-write bytes until the ‘offset’, in some case even from the beginning of the file to the desired offset. This will slow down the write operation if we write to very distanced offsets. The most speed is obtained when we write sequentially from the beginning of the file. If we write outside of file size, we fill up with zeros until offset. If the file is not opened for write, it will return an error of type [‘FsError::InvalidFileHandle’].

source

pub fn flush(&mut self, handle: u64) -> FsResult<()>

Flush the data to the underlying storage.

source

pub fn copy_file_range( &mut self, src_ino: u64, src_offset: u64, dest_ino: u64, dest_offset: u64, size: usize, src_fh: u64, dest_fh: u64 ) -> FsResult<usize>

Helpful when we want to copy just some portions of the file.

source

pub fn open(&mut self, ino: u64, read: bool, write: bool) -> FsResult<u64>

Open a file. We can open multiple times for read but only one for write at a time.

source

pub fn truncate(&mut self, ino: u64, size: u64) -> FsResult<()>

source

pub fn rename( &mut self, parent: u64, name: &str, new_parent: u64, new_name: &str ) -> FsResult<()>

source

pub fn create_encryptor(&self, file: File) -> Encryptor<File>

Create an encryptor using internal encryption info.

source

pub fn create_decryptor(&self, file: File) -> Decryptor<File>

Create a decryptor using internal encryption info.

source

pub fn encrypt_string(&self, s: &str) -> String

Encrypts a string using internal encryption info.

source

pub fn decrypt_string(&self, s: &str) -> String

Decrypts a string using internal encryption info.

source

pub fn normalize_end_encrypt_file_name(&self, name: &str) -> String

Normalize and encrypt a file name.

source

pub fn change_password( data_dir: &str, old_password: &str, new_password: &str, cipher: &Cipher, derive_key_hash_rounds: u32 ) -> FsResult<()>

Change the password of the filesystem used to access the encryption key.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more