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
impl EncryptedFs
pub fn new( data_dir: &str, password: &str, cipher: Cipher, derive_key_hash_rounds: u32 ) -> FsResult<Self>
pub fn node_exists(&self, ino: u64) -> bool
pub fn is_dir(&self, ino: u64) -> bool
pub fn is_file(&self, ino: u64) -> bool
sourcepub fn create_nod(
&mut self,
parent: u64,
name: &str,
attr: FileAttr,
read: bool,
write: bool
) -> FsResult<(u64, FileAttr)>
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.
pub fn find_by_name( &mut self, parent: u64, name: &str ) -> FsResult<Option<FileAttr>>
sourcepub fn children_count(&self, ino: u64) -> FsResult<usize>
pub fn children_count(&self, ino: u64) -> FsResult<usize>
Count children of a directory. This includes also .
and ..
.
pub fn remove_dir(&mut self, parent: u64, name: &str) -> FsResult<()>
pub fn remove_file(&mut self, parent: u64, name: &str) -> FsResult<()>
pub fn exists_by_name(&self, parent: u64, name: &str) -> bool
pub fn read_dir(&self, ino: u64) -> FsResult<DirectoryEntryIterator>
sourcepub fn read_dir_plus(&self, ino: u64) -> FsResult<DirectoryEntryPlusIterator>
pub fn read_dir_plus(&self, ino: u64) -> FsResult<DirectoryEntryPlusIterator>
pub fn get_inode(&mut self, ino: u64) -> FsResult<FileAttr>
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<()>
sourcepub fn read(
&mut self,
ino: u64,
offset: u64,
buf: &mut [u8],
handle: u64
) -> FsResult<usize>
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’].
pub fn release_handle(&mut self, handle: u64) -> FsResult<()>
sourcepub fn is_read_handle(&self, fh: u64) -> bool
pub fn is_read_handle(&self, fh: u64) -> bool
Check if a file is opened for read with this handle.
sourcepub fn is_write_handle(&self, fh: u64) -> bool
pub fn is_write_handle(&self, fh: u64) -> bool
Check if a file is opened for write with this handle.
sourcepub fn write_all(
&mut self,
ino: u64,
offset: u64,
buf: &[u8],
handle: u64
) -> FsResult<()>
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’].
sourcepub 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>
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.
sourcepub fn open(&mut self, ino: u64, read: bool, write: bool) -> FsResult<u64>
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.
pub fn truncate(&mut self, ino: u64, size: u64) -> FsResult<()>
pub fn rename( &mut self, parent: u64, name: &str, new_parent: u64, new_name: &str ) -> FsResult<()>
sourcepub fn create_encryptor(&self, file: File) -> Encryptor<File>
pub fn create_encryptor(&self, file: File) -> Encryptor<File>
Create an encryptor using internal encryption info.
sourcepub fn create_decryptor(&self, file: File) -> Decryptor<File>
pub fn create_decryptor(&self, file: File) -> Decryptor<File>
Create a decryptor using internal encryption info.
sourcepub fn encrypt_string(&self, s: &str) -> String
pub fn encrypt_string(&self, s: &str) -> String
Encrypts a string using internal encryption info.
sourcepub fn decrypt_string(&self, s: &str) -> String
pub fn decrypt_string(&self, s: &str) -> String
Decrypts a string using internal encryption info.
sourcepub fn normalize_end_encrypt_file_name(&self, name: &str) -> String
pub fn normalize_end_encrypt_file_name(&self, name: &str) -> String
Normalize and encrypt a file name.