diff --git a/src/encryptedfs.rs b/src/encryptedfs.rs index 03e2b501..0697ec91 100644 --- a/src/encryptedfs.rs +++ b/src/encryptedfs.rs @@ -19,7 +19,7 @@ use tracing::error; #[cfg(test)] mod encryptedfs_test; -pub mod encryptedfs; +pub mod crypto_util; pub(crate) const INODES_DIR: &str = "inodes"; pub(crate) const CONTENTS_DIR: &str = "contents"; @@ -204,9 +204,9 @@ impl Iterator for DirectoryEntryIterator { } else if name == "$.." { name = "..".to_string(); } else { - name = encryptedfs::decrypt_and_unnormalize_end_file_name(&name, &self.1, &self.2); + name = crypto_util::decrypt_and_unnormalize_end_file_name(&name, &self.1, &self.2); } - let res: bincode::Result<(u64, FileType)> = bincode::deserialize_from(encryptedfs::create_decryptor(file, &self.1, &self.2)); + let res: bincode::Result<(u64, FileType)> = bincode::deserialize_from(crypto_util::create_decryptor(file, &self.1, &self.2)); if let Err(e) = res { return Some(Err(e.into())); } @@ -227,13 +227,13 @@ impl Iterator for DirectoryEntryPlusIterator { fn next(&mut self) -> Option { let entry = self.0.next()?; if let Err(e) = entry { - error!("error reading directory entry: {:?}", e); + error!("error reading directory entry: {e}"); return Some(Err(e.into())); } let entry = entry.unwrap(); let file = File::open(entry.path()); if let Err(e) = file { - error!("error opening file: {:?}", e); + error!("error opening file: {e}"); return Some(Err(e.into())); } let file = file.unwrap(); @@ -243,24 +243,24 @@ impl Iterator for DirectoryEntryPlusIterator { } else if name == "$.." { name = "..".to_string(); } else { - name = encryptedfs::decrypt_and_unnormalize_end_file_name(&name, &self.2, &self.3); + name = crypto_util::decrypt_and_unnormalize_end_file_name(&name, &self.2, &self.3); } - let res: bincode::Result<(u64, FileType)> = bincode::deserialize_from(encryptedfs::create_decryptor(file, &self.2, &self.3)); + let res: bincode::Result<(u64, FileType)> = bincode::deserialize_from(crypto_util::create_decryptor(file, &self.2, &self.3)); if let Err(e) = res { - error!("error deserializing directory entry: {:?}", e); + error!("error deserializing directory entry: {e}"); return Some(Err(e.into())); } let (ino, kind): (u64, FileType) = res.unwrap(); let file = File::open(&self.1.join(ino.to_string())); if let Err(e) = file { - error!("error opening file: {:?}", e); + error!("error opening file: {e}"); return Some(Err(e.into())); } let file = file.unwrap(); - let attr = bincode::deserialize_from(encryptedfs::create_decryptor(file, &self.2, &self.3)); + let attr = bincode::deserialize_from(crypto_util::create_decryptor(file, &self.2, &self.3)); if let Err(e) = attr { - error!("error deserializing file attr: {:?}", e); + error!("error deserializing file attr: {e}"); return Some(Err(e.into())); } let attr = attr.unwrap(); @@ -406,9 +406,9 @@ impl EncryptedFs { } else if name == ".." { name = "$.."; } - let name = encryptedfs::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); + let name = crypto_util::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); let file = File::open(self.data_dir.join(CONTENTS_DIR).join(parent.to_string()).join(name))?; - let (inode, _): (u64, FileType) = bincode::deserialize_from(encryptedfs::create_decryptor(file, &self.cipher, &self.key))?; + let (inode, _): (u64, FileType) = bincode::deserialize_from(crypto_util::create_decryptor(file, &self.cipher, &self.key))?; Ok(Some(self.get_inode(inode)?)) } @@ -444,7 +444,7 @@ impl EncryptedFs { // remove contents directory fs::remove_dir_all(self.data_dir.join(CONTENTS_DIR).join(&ino_str))?; // remove from parent directory - let name = encryptedfs::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); + let name = crypto_util::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); fs::remove_file(self.data_dir.join(CONTENTS_DIR).join(parent.to_string()).join(name))?; let mut parent_attr = self.get_inode(parent)?; @@ -474,7 +474,7 @@ impl EncryptedFs { // remove contents file fs::remove_file(self.data_dir.join(CONTENTS_DIR).join(&ino_str))?; // remove from parent directory - let name = encryptedfs::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); + let name = crypto_util::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); fs::remove_file(self.data_dir.join(CONTENTS_DIR).join(parent.to_string()).join(name))?; let mut parent_attr = self.get_inode(parent)?; @@ -491,7 +491,7 @@ impl EncryptedFs { } else if name == ".." { name = "$.."; } - let name = encryptedfs::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); + let name = crypto_util::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); self.data_dir.join(CONTENTS_DIR).join(parent.to_string()).join(name).exists() } @@ -519,7 +519,7 @@ impl EncryptedFs { pub fn get_inode(&mut self, ino: u64) -> FsResult { let path = self.data_dir.join(INODES_DIR).join(ino.to_string()); if let Ok(file) = OpenOptions::new().read(true).write(true).open(path) { - let mut attr: FileAttr = bincode::deserialize_from(encryptedfs::create_decryptor(file, &self.cipher, &self.key))?; + let mut attr: FileAttr = bincode::deserialize_from(crypto_util::create_decryptor(file, &self.cipher, &self.key))?; if self.opened_files_for_write.contains_key(&ino) { // merge time info and size with any open write handles if let Some((attr_handle, _, _, _)) = self.write_handles.get(&self.opened_files_for_write.get(&ino).unwrap()) { @@ -718,8 +718,8 @@ impl EncryptedFs { let tmp_path = self.data_dir.join(CONTENTS_DIR).join(tmp_path_str); let tmp_file = OpenOptions::new().read(true).write(true).create(true).open(tmp_path.clone())?; - let mut decryptor = encryptedfs::create_decryptor(in_file, &self.cipher, &self.key); - let mut encryptor = encryptedfs::create_encryptor(tmp_file, &self.cipher, &self.key); + let mut decryptor = crypto_util::create_decryptor(in_file, &self.cipher, &self.key); + let mut encryptor = crypto_util::create_encryptor(tmp_file, &self.cipher, &self.key); let mut buffer: [u8; 4096] = [0; 4096]; let mut pos_read = 0; @@ -768,7 +768,7 @@ impl EncryptedFs { // if position is before file end we copy the rest of the file from position to the end if *position < attr.size { let mut buffer: [u8; 4096] = [0; 4096]; - let mut decryptor = encryptedfs::create_decryptor(OpenOptions::new().read(true).open(self.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()))?, + let mut decryptor = crypto_util::create_decryptor(OpenOptions::new().read(true).open(self.data_dir.join(CONTENTS_DIR).join(attr.ino.to_string()))?, &self.cipher, &self.key); // move read position to the desired position loop { @@ -968,49 +968,49 @@ impl EncryptedFs { .create(true) .truncate(true) .open(&path)?; - Ok(bincode::serialize_into(encryptedfs::create_encryptor(file, &self.cipher, &self.key), &attr)?) + Ok(bincode::serialize_into(crypto_util::create_encryptor(file, &self.cipher, &self.key), &attr)?) } /// Create an encryptor using internal encryption info. pub fn create_encryptor(&self, file: File) -> write::Encryptor { - encryptedfs::create_encryptor(file, &self.cipher, &self.key) + crypto_util::create_encryptor(file, &self.cipher, &self.key) } /// Create a decryptor using internal encryption info. pub fn create_decryptor(&self, file: File) -> read::Decryptor { - encryptedfs::create_decryptor(file, &self.cipher, &self.key) + crypto_util::create_decryptor(file, &self.cipher, &self.key) } /// Encrypts a string using internal encryption info. pub fn encrypt_string(&self, s: &str) -> String { - encryptedfs::encrypt_string(s, &self.cipher, &self.key) + crypto_util::encrypt_string(s, &self.cipher, &self.key) } /// Decrypts a string using internal encryption info. pub fn decrypt_string(&self, s: &str) -> String { - encryptedfs::decrypt_string(s, &self.cipher, &self.key) + crypto_util::decrypt_string(s, &self.cipher, &self.key) } /// Normalize and encrypt a file name. pub fn normalize_end_encrypt_file_name(&self, name: &str) -> String { - encryptedfs::normalize_end_encrypt_file_name(name, &self.cipher, &self.key) + crypto_util::normalize_end_encrypt_file_name(name, &self.cipher, &self.key) } /// Change the password of the filesystem used to access the encryption key. pub fn change_password(data_dir: &str, old_password: &str, new_password: &str, cipher: Cipher, derive_key_hash_rounds: u32) -> FsResult<()> { let data_dir = PathBuf::from(data_dir); // decrypt key - let initial_key = encryptedfs::derive_key(old_password, &cipher, derive_key_hash_rounds, "salt-42"); + let initial_key = crypto_util::derive_key(old_password, &cipher, derive_key_hash_rounds, "salt-42"); let enc_file = data_dir.join(SECURITY_DIR).join(KEY_ENC_FILENAME); - let mut decryptor = encryptedfs::create_decryptor(File::open(enc_file.clone())?, &cipher, &initial_key); + let mut decryptor = crypto_util::create_decryptor(File::open(enc_file.clone())?, &cipher, &initial_key); let mut key: Vec = vec![]; decryptor.read_to_end(&mut key)?; decryptor.finish(); // encrypt it with new key derived from new password - let new_key = encryptedfs::derive_key(new_password, &cipher, derive_key_hash_rounds, "salt-42"); + let new_key = crypto_util::derive_key(new_password, &cipher, derive_key_hash_rounds, "salt-42"); fs::remove_file(enc_file.clone())?; - let mut encryptor = encryptedfs::create_encryptor(OpenOptions::new().read(true).write(true).create(true).truncate(true).open(enc_file.clone())?, + let mut encryptor = crypto_util::create_encryptor(OpenOptions::new().read(true).write(true).create(true).truncate(true).open(enc_file.clone())?, &cipher, &new_key); encryptor.write_all(&key)?; encryptor.finish()?; @@ -1042,7 +1042,7 @@ impl EncryptedFs { let path = self.data_dir.join(CONTENTS_DIR).join(ino.to_string()); let file = OpenOptions::new().read(true).write(true).open(path)?; - let decryptor = encryptedfs::create_decryptor(file, &self.cipher, &self.key); + let decryptor = crypto_util::create_decryptor(file, &self.cipher, &self.key); let attr = self.get_inode(ino)?; // save attr also to avoid loading it multiple times while reading self.read_handles.insert(handle, (TimeAndSizeFileAttr::from_file_attr(&attr), 0, decryptor)); @@ -1053,7 +1053,7 @@ impl EncryptedFs { let path = self.data_dir.join(CONTENTS_DIR).join(ino.to_string()); let file = OpenOptions::new().read(true).write(true).open(path.clone())?; - let encryptor = encryptedfs::create_encryptor(file, &self.cipher, &self.key); + let encryptor = crypto_util::create_encryptor(file, &self.cipher, &self.key); // save attr also to avoid loading it multiple times while writing let attr = self.get_inode(ino)?; self.write_handles.insert(handle, (TimeAndSizeFileAttr::from_file_attr(&attr), path, 0, encryptor)); @@ -1110,7 +1110,7 @@ impl EncryptedFs { fn insert_directory_entry(&self, parent: u64, entry: DirectoryEntry) -> FsResult<()> { let parent_path = self.data_dir.join(CONTENTS_DIR).join(parent.to_string()); // remove path separators from name - let name = encryptedfs::normalize_end_encrypt_file_name(&entry.name, &self.cipher, &self.key); + let name = crypto_util::normalize_end_encrypt_file_name(&entry.name, &self.cipher, &self.key); let file = OpenOptions::new() .write(true) .create(true) @@ -1119,14 +1119,14 @@ impl EncryptedFs { // write inode and file type let entry = (entry.ino, entry.kind); - bincode::serialize_into(encryptedfs::create_encryptor(file, &self.cipher, &self.key), &entry)?; + bincode::serialize_into(crypto_util::create_encryptor(file, &self.cipher, &self.key), &entry)?; Ok(()) } fn remove_directory_entry(&self, parent: u64, name: &str) -> FsResult<()> { let parent_path = self.data_dir.join(CONTENTS_DIR).join(parent.to_string()); - let name = encryptedfs::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); + let name = crypto_util::normalize_end_encrypt_file_name(name, &self.cipher, &self.key); fs::remove_file(parent_path.join(name))?; Ok(()) } @@ -1193,7 +1193,7 @@ fn merge_attr_time_and_time_obj(attr: &mut FileAttr, from: &TimeAndSizeFileAttr) } fn read_or_create_key(path: PathBuf, password: &str, cipher: &Cipher, rounds: u32) -> FsResult> { - let derived_key = encryptedfs::derive_key(password, cipher, rounds, "salt-42"); + let derived_key = crypto_util::derive_key(password, cipher, rounds, "salt-42"); if !path.exists() { // first time, create a random key and encrypt it with the derived key from password let mut key: Vec = vec![]; @@ -1203,14 +1203,14 @@ fn read_or_create_key(path: PathBuf, password: &str, cipher: &Cipher, rounds: u3 }; key.resize(key_len, 0); OsRng::new()?.fill_bytes(&mut key); - let mut encryptor = encryptedfs::create_encryptor(OpenOptions::new().read(true).write(true).create(true).open(path.clone())?, + let mut encryptor = crypto_util::create_encryptor(OpenOptions::new().read(true).write(true).create(true).open(path.clone())?, cipher, &derived_key); encryptor.write_all(&key)?; encryptor.finish()?; return Ok(key); } - let mut decryptor = encryptedfs::create_decryptor(File::open(path)?, cipher, &derived_key); + let mut decryptor = crypto_util::create_decryptor(File::open(path)?, cipher, &derived_key); let mut key: Vec = vec![]; decryptor.read_to_end(&mut key)?; decryptor.finish(); diff --git a/src/encryptedfs/encryptedfs.rs b/src/encryptedfs/crypto_util.rs similarity index 100% rename from src/encryptedfs/encryptedfs.rs rename to src/encryptedfs/crypto_util.rs diff --git a/src/encryptedfs/encryptedfs_test.rs b/src/encryptedfs/encryptedfs_test.rs index aba8daa7..a84f0e2a 100644 --- a/src/encryptedfs/encryptedfs_test.rs +++ b/src/encryptedfs/encryptedfs_test.rs @@ -75,7 +75,7 @@ fn create_attr_from_type(file_type: FileType) -> FileAttr { #[test] fn test_write_and_get_inode() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_write_and_get_inode") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_write_and_get_inode") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let attr = create_attr(42, FileType::RegularFile); @@ -111,7 +111,7 @@ fn write(path: PathBuf, data: &[u8], fs: &EncryptedFs) { #[test] fn test_create_structure_and_root() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_create_structure_and_root") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_create_structure_and_root") }, |setup| { let fs = setup.fs.as_mut().unwrap(); assert!(fs.node_exists(ROOT_INODE)); @@ -128,7 +128,7 @@ fn test_create_structure_and_root() { #[test] fn test_create_nod() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_create_nod") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_create_nod") }, |setup| { let fs = setup.fs.as_mut().unwrap(); // file in root @@ -197,7 +197,7 @@ fn test_create_nod() { #[test] fn test_read_dir() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_read_dir") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_read_dir") }, |setup| { let fs = setup.fs.as_mut().unwrap(); // file and directory in root @@ -303,7 +303,7 @@ fn test_read_dir() { #[test] fn test_read_dir_plus() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_read_dir_plus") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_read_dir_plus") }, |setup| { let fs = setup.fs.as_mut().unwrap(); // file and directory in root @@ -425,7 +425,7 @@ fn test_read_dir_plus() { #[test] fn test_find_by_name() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_find_by_name") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_find_by_name") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_file = "test-file"; @@ -437,7 +437,7 @@ fn test_find_by_name() { #[test] fn test_remove_dir() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_remove_dir") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_remove_dir") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_dir = "test-dir"; @@ -461,7 +461,7 @@ fn test_remove_dir() { #[test] fn test_remove_file() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_remove_file") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_remove_file") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_file = "test-file"; @@ -478,7 +478,7 @@ fn test_remove_file() { #[test] fn test_write_all() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_write_all") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_write_all") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_file = "test-file"; @@ -543,7 +543,7 @@ fn test_write_all() { #[test] fn test_read() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_read") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_read") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_test_file = "test-file"; @@ -645,7 +645,7 @@ fn test_read() { #[test] fn test_truncate() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_truncate") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_truncate") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let (fh, attr) = fs.create_nod(ROOT_INODE, "test-file", create_attr_from_type(FileType::RegularFile), false, false).unwrap(); @@ -670,7 +670,7 @@ fn test_truncate() { #[test] fn test_copy_file_range() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_copy_file_range") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_copy_file_range") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_file_1 = "test-file-1"; @@ -722,7 +722,7 @@ fn test_copy_file_range() { #[test] fn test_rename() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_rename") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_rename") }, |setup| { let fs = setup.fs.as_mut().unwrap(); // new file in same directory @@ -957,7 +957,7 @@ fn test_rename() { #[test] fn test_open() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_open") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_open") }, |setup| { let fs = setup.fs.as_mut().unwrap(); let test_file = "test-file"; @@ -977,7 +977,7 @@ fn test_open() { #[allow(dead_code)] fn test_sample() { - run_test(TestSetup { data_path: format!("{}{}", TESTS_DATA_DIR, "test_sample") }, |setup| { + run_test(TestSetup { data_path: format!("{TESTS_DATA_DIR}test_sample") }, |setup| { let fs = setup.fs.as_mut().unwrap(); }); } diff --git a/src/encryptedfs_fuse3.rs b/src/encryptedfs_fuse3.rs index 0ea080a1..b5e11f10 100644 --- a/src/encryptedfs_fuse3.rs +++ b/src/encryptedfs_fuse3.rs @@ -63,11 +63,11 @@ impl Iterator for DirectoryEntryIterator { })) } Some(Err(FsError::Io(err))) => { - error!("DirectoryEntryIterator error {:?}", err); + error!("DirectoryEntryIterator error {err}"); Some(Err(err.into())) } Some(Err(err)) => { - error!("DirectoryEntryIterator error {:?}", err); + error!("DirectoryEntryIterator error {err}"); Some(Err(EIO.into())) } None => None, @@ -101,11 +101,11 @@ impl Iterator for DirectoryEntryPlusIterator { })) } Some(Err(FsError::Io(err))) => { - error!("DirectoryEntryPlusIterator error {:?}", err); + error!("DirectoryEntryPlusIterator error {err}"); Some(Err(err.into())) } Some(Err(err)) => { - error!("DirectoryEntryPlusIterator error {:?}", err); + error!("DirectoryEntryPlusIterator error {err}"); Some(Err(EIO.into())) } None => None, @@ -154,7 +154,7 @@ impl EncryptedFsFuse3 { fn create_nod(&self, parent: u64, mut mode: u32, req: &Request, name: &OsStr, read: bool, write: bool) -> std::result::Result<(u64, FileAttr), c_int> { let parent_attr = match self.get_fs().borrow_mut().get_inode(parent) { Err(err) => { - error!("create_nod() error {}", err); + error!("create_nod() error {err}"); return Err(ENOENT); } Ok(parent_attr) => parent_attr, @@ -188,7 +188,7 @@ impl EncryptedFsFuse3 { match self.get_fs().borrow_mut().create_nod(parent, name.to_str().unwrap(), attr, read, write) { Ok((fh, attr)) => Ok((fh, attr)), Err(err) => { - error!("create_nod() error {}", err); + error!("create_nod() error {err}"); match err { FsError::AlreadyExists => { Err(libc::EEXIST) } _ => { return Err(ENOENT); } @@ -250,8 +250,8 @@ impl Filesystem for EncryptedFsFuse3 { match self.get_fs().borrow_mut().get_inode(parent) { Err(err) => { - error!("not found {} {:?} {}", parent, name, err); - return Err(libc::ENOENT.into()); + error!("not found {parent} {} {err}", name.to_str().unwrap()); + return Err(ENOENT.into()); } Ok(parent_attr) => { if !check_access( @@ -270,11 +270,11 @@ impl Filesystem for EncryptedFsFuse3 { let attr = match self.get_fs().borrow_mut().find_by_name(parent, name.to_str().unwrap()) { Ok(Some(attr)) => attr, Err(err) => { - error!("lookup() error {}", err); + error!("lookup() error {err}"); return Err(ENOENT.into()); } _ => { - debug!("not found {} {:?}", parent, name); + debug!("not found {parent} {}", name.to_str().unwrap()); return Err(ENOENT.into()); } }; @@ -294,7 +294,7 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn forget(&self, req: Request, inode: Inode, nlookup: u64) { - debug!("forget() called with {:?}", inode); + debug!("forget() called with {inode}"); } #[instrument(skip(self))] @@ -307,14 +307,14 @@ impl Filesystem for EncryptedFsFuse3 { ) -> Result { match self.get_fs().borrow_mut().get_inode(inode) { Err(err) => { - error!("getattr() error {}", err); + error!("getattr() error {err}"); return Err(ENOENT.into()); } Ok(attr) => { if attr.kind == FileType::Directory { - debug!("dir {}", inode); + debug!("dir {inode}"); } else { - debug!("file {}", inode); + debug!("file {inode}"); } Ok(ReplyAttr { ttl: TTL, @@ -333,15 +333,15 @@ impl Filesystem for EncryptedFsFuse3 { set_attr: SetAttr, ) -> Result { - debug!("setattr() called with {:?} {:#?}", inode, set_attr); + debug!("setattr() called with {inode} {set_attr:#?}"); let mut attr = if let Ok(attr) = self.get_fs().borrow_mut().get_inode(inode) { attr } else { - error!("not found {}", inode); + error!("not found {inode}"); return Err(ENOENT.into()); }; if let Some(mode) = set_attr.mode { - debug!("chmod() called with {:?}, {:o}", inode, mode); + debug!("chmod() called with {inode}, {mode:o}"); if req.uid != 0 && req.uid != attr.uid { return Err(libc::EPERM.into()); } @@ -357,7 +357,7 @@ impl Filesystem for EncryptedFsFuse3 { } attr.ctime = SystemTime::now(); if let Err(err) = self.get_fs().borrow_mut().update_inode(inode, attr.perm, attr.atime, attr.mtime, attr.ctime, attr.crtime, attr.uid, attr.gid, attr.size, attr.nlink, attr.flags) { - error!("setattr() error {}", err); + error!("setattr() error {err}"); return Err(EBADF.into()); } return Ok(ReplyAttr { @@ -367,7 +367,7 @@ impl Filesystem for EncryptedFsFuse3 { } if set_attr.uid.is_some() || set_attr.gid.is_some() { - debug!("chown() called with {:?} {:?} {:?}", inode, set_attr.uid, set_attr.gid); + debug!("chown() called with {inode} {:?} {:?}", set_attr.uid, set_attr.gid); if let Some(gid) = set_attr.gid { // Non-root users can only change gid to a group they're in @@ -406,7 +406,7 @@ impl Filesystem for EncryptedFsFuse3 { } attr.ctime = SystemTime::now(); if let Err(err) = self.get_fs().borrow_mut().update_inode(inode, attr.perm, attr.atime, attr.mtime, attr.ctime, attr.crtime, attr.uid, attr.gid, attr.size, attr.nlink, attr.flags) { - error!("setattr() error {}", err); + error!("setattr() error {err}"); return Err(EBADF.into()); } return Ok(ReplyAttr { @@ -416,10 +416,10 @@ impl Filesystem for EncryptedFsFuse3 { } if let Some(size) = set_attr.size { - debug!("truncate() called with {:?} {:?}", inode, size); + debug!("truncate() called with {inode} {size}"); if let Err(err) = self.get_fs().borrow_mut().truncate(inode, size) { - error!("truncate error {}", err); + error!("truncate error {err}"); return Err(EBADF.into()); } attr.size = size; @@ -429,7 +429,7 @@ impl Filesystem for EncryptedFsFuse3 { } if let Some(atime) = set_attr.atime { - debug!("utimens() called with {:?}, atime={:?}", inode, atime); + debug!("utimens() called with {inode}, atime={atime:?}"); if attr.uid != req.uid && !check_access( @@ -448,7 +448,7 @@ impl Filesystem for EncryptedFsFuse3 { } if let Some(mtime) = set_attr.mtime { - debug!("utimens() called with {:?}, mtime={:?}", inode, mtime); + debug!("utimens() called with {inode}, mtime={mtime:?}"); if attr.uid != req.uid && !check_access( @@ -467,7 +467,7 @@ impl Filesystem for EncryptedFsFuse3 { } if let Err(err) = self.get_fs().borrow_mut().update_inode(inode, attr.perm, attr.atime, attr.mtime, attr.ctime, attr.crtime, attr.uid, attr.gid, attr.size, attr.nlink, attr.flags) { - error!("setattr() error {}", err); + error!("setattr() error {err}"); return Err(EBADF.into()); } @@ -486,7 +486,7 @@ impl Filesystem for EncryptedFsFuse3 { mode: u32, rdev: u32, ) -> Result { - debug!("mknod() called with {:?} {:?} {:o}", parent, name, mode); + debug!("mknod() called with {parent} {} {mode:o}", name.to_str().unwrap()); let file_type = mode & libc::S_IFMT as u32; @@ -495,7 +495,7 @@ impl Filesystem for EncryptedFsFuse3 { && file_type != libc::S_IFDIR as u32 { // TODO - warn!("mknod() implementation is incomplete. Only supports regular files and directories. Got {:o}", mode); + warn!("mknod() implementation is incomplete. Only supports regular files and directories. Got {mode:o}"); return Err(libc::ENOSYS.into()); } @@ -509,7 +509,7 @@ impl Filesystem for EncryptedFsFuse3 { }) } Err(err) => { - error!("mknod() error {}", err); + error!("mknod() error {err}"); Err(err.into()) } } @@ -524,11 +524,11 @@ impl Filesystem for EncryptedFsFuse3 { mode: u32, umask: u32, ) -> Result { - debug!("mkdir() called with {:?} {:?} {:o}", parent, name, mode); + debug!("mkdir() called with {parent} {} {mode:o}", name.to_str().unwrap()); let parent_attr = match self.get_fs().borrow_mut().get_inode(parent) { Err(err) => { - error!("mkdir() error {}", err); + error!("mkdir() error {err}"); return Err(ENOENT.into()); } Ok(parent_attr) => parent_attr, @@ -565,7 +565,7 @@ impl Filesystem for EncryptedFsFuse3 { match self.get_fs().borrow_mut().create_nod(parent, name.to_str().unwrap(), attr, false, false) { Err(err) => { - error!("mkdir() error {}", err); + error!("mkdir() error {err}"); return Err(ENOENT.into()); } Ok((_, attr)) => { @@ -580,11 +580,11 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn unlink(&self, req: Request, parent: Inode, name: &OsStr) -> Result<()> { - debug!("unlink() called with {:?} {:?}", parent, name); + debug!("unlink() called with {parent} {}", name.to_str().unwrap()); let parent_attr = match self.get_fs().borrow_mut().get_inode(parent) { Err(err) => { - error!("unlink() error {}", err); + error!("unlink() error {err}"); return Err(ENOENT.into()); } Ok(attr) => attr, @@ -604,7 +604,7 @@ impl Filesystem for EncryptedFsFuse3 { let attr = match self.get_fs().borrow_mut().find_by_name(parent, name.to_str().unwrap()) { Ok(Some(attr)) => attr, Err(err) => { - error!("unlink() error {}", err); + error!("unlink() error {err}"); return Err(ENOENT.into()); } _ => return Err(ENOENT.into()), @@ -621,7 +621,7 @@ impl Filesystem for EncryptedFsFuse3 { } if let Err(err) = self.get_fs().borrow_mut().remove_file(parent, name.to_str().unwrap()) { - error!("unlink() error {}", err); + error!("unlink() error {err}"); return Err(ENOENT.into()); } @@ -631,10 +631,10 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn rmdir(&self, req: Request, parent: Inode, name: &OsStr) -> Result<()> { - debug!("rmdir() called with {:?} {:?}", parent, name); + debug!("rmdir() called with {parent} {}", name.to_str().unwrap()); let parent_attr = if let Ok(attr) = self.get_fs().borrow_mut().get_inode(parent) { attr } else { - error!("rmdir() not found {} {:?}", parent, name); + error!("rmdir() not found {parent} {}", name.to_str().unwrap()); return Err(ENOENT.into()); }; @@ -652,7 +652,7 @@ impl Filesystem for EncryptedFsFuse3 { let attr = match self.get_fs().borrow_mut().find_by_name(parent, name.to_str().unwrap()) { Ok(Some(attr)) => attr, _ => { - error!("rmdir() name not found {} {:?}", parent, name); + error!("rmdir() name not found {parent} {}", name.to_str().unwrap()); return Err(ENOENT.into()); } }; @@ -672,7 +672,7 @@ impl Filesystem for EncryptedFsFuse3 { } if let Err(err) = self.get_fs().borrow_mut().remove_dir(parent, name.to_str().unwrap()) { - error!("rmdir() error {}", err); + error!("rmdir() error {err}"); return Err(EBADF.into()); } @@ -691,12 +691,12 @@ impl Filesystem for EncryptedFsFuse3 { let attr = if let Ok(Some(attr)) = self.get_fs().borrow_mut().find_by_name(parent, name.to_str().unwrap()) { attr } else { - error!("rename() name not found {} {:?} {} {:?}", parent, name, new_parent, new_name); + error!("rename() name not found {parent} {} {new_parent} {}", name.to_str().unwrap(), new_name.to_str().unwrap()); return Err(ENOENT.into()); }; let parent_attr = if let Ok(attr) = self.get_fs().borrow_mut().get_inode(parent) { attr } else { - error!("rename() parent not found {}", parent); + error!("rename() parent not found {parent}"); return Err(ENOENT.into()); }; @@ -719,7 +719,7 @@ impl Filesystem for EncryptedFsFuse3 { } let new_parent_attr = if let Ok(attr) = self.get_fs().borrow_mut().get_inode(new_parent) { attr } else { - error!("rename() new parent not found {}", new_parent); + error!("rename() new parent not found {new_parent}"); return Err(ENOENT.into()); }; @@ -773,7 +773,7 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn open(&self, req: Request, inode: Inode, flags: u32) -> Result { - debug!("open() called for {:?}", inode); + debug!("open() called for {inode}"); let (access_mask, read, write) = match flags as i32 & libc::O_ACCMODE { libc::O_RDONLY => { @@ -799,7 +799,7 @@ impl Filesystem for EncryptedFsFuse3 { let attr = match self.get_fs().borrow_mut().get_inode(inode) { Ok(attr) => attr, Err(err) => { - error!("open() error {}", err); + error!("open() error {err}"); return Err(EBADF.into()); } }; @@ -808,11 +808,11 @@ impl Filesystem for EncryptedFsFuse3 { let open_flags = if self.direct_io { FOPEN_DIRECT_IO } else { 0 }; match self.get_fs().borrow_mut().open(inode, read, write) { Err(err) => { - error!("open error {}", err); + error!("open error {err}"); return Err(EBADF.into()); } Ok(fh) => { - debug!("opened handle {}", fh); + debug!("opened handle {fh}"); Ok(ReplyOpen { fh, flags: open_flags }) } } @@ -830,12 +830,12 @@ impl Filesystem for EncryptedFsFuse3 { offset: u64, size: u32, ) -> Result { - debug!("read {} {} {} {}", inode, fh, offset, size); + debug!("read {inode} {fh} {offset} {size}"); let mut buf = vec![0; size as usize]; match self.get_fs().borrow_mut().read(inode, offset, &mut buf, fh) { Err(err) => { - error!("read error {}", err); + error!("read error {err}"); return Err(EIO.into()); } Ok(len) => { @@ -858,10 +858,10 @@ impl Filesystem for EncryptedFsFuse3 { _flags: u32, ) -> Result { - debug!("write() called with {:?} offfset {:?} size={:?}", inode, offset, data.len()); + debug!(inode, offset, size = data.len(), "write() called"); if let Err(err) = self.get_fs().borrow_mut().write_all(inode, offset, data, fh) { - error!("write error {}", err); + error!("write error {err}"); return Err(EIO.into()); } @@ -872,7 +872,7 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn statfs(&self, _req: Request, inode: u64) -> Result { - debug!("statfs() called inode {}", inode); + debug!("statfs() called inode {inode}"); warn!("statfs() implementation is a stub"); Ok(STATFS) } @@ -887,17 +887,17 @@ impl Filesystem for EncryptedFsFuse3 { lock_owner: u64, flush: bool, ) -> Result<()> { - debug!("release() called with {:?} {:?} {:?}", inode, fh, lock_owner); + debug!("release() called with {inode} {fh} {lock_owner}"); if flush { if let Err(err) = self.get_fs().borrow_mut().flush(fh) { - error!("flush error {}", err); + error!("flush error {err}"); return Err(EIO.into()); } } if let Err(err) = self.get_fs().borrow_mut().release_handle(fh) { - error!("release error {}", err); + error!("release error {err}"); return Err(EIO.into()); } @@ -907,7 +907,7 @@ impl Filesystem for EncryptedFsFuse3 { // However, xfstests fail in that case clear_suid_sgid(&mut attr); if let Err(err) = self.get_fs().borrow_mut().update_inode(inode, attr.perm, attr.atime, attr.mtime, attr.ctime, attr.crtime, attr.uid, attr.gid, attr.size, attr.nlink, attr.flags) { - error!("replace attr error {}", err); + error!("replace attr error {err}"); return Err(EBADF.into()); } } @@ -917,10 +917,10 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn flush(&self, req: Request, inode: Inode, fh: u64, lock_owner: u64) -> Result<()> { - debug!("flush() called with {:?} {:?} {:?}", inode, fh, lock_owner); + debug!(inode, fh, lock_owner, "flush() called"); if let Err(err) = self.get_fs().borrow_mut().flush(fh) { - error!("flush error {}", err); + error!("flush error {err}"); return Err(EIO.into()); } @@ -929,7 +929,7 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn opendir(&self, req: Request, inode: Inode, flags: u32) -> Result { - debug!("opendir() called on {:?}", inode); + debug!("opendir() called on {inode}"); let (access_mask, _read, _write) = match flags as i32 & libc::O_ACCMODE { libc::O_RDONLY => { @@ -949,7 +949,7 @@ impl Filesystem for EncryptedFsFuse3 { let attr = match self.get_fs().borrow_mut().get_inode(inode) { Err(err) => { - error!("error {}", err); + error!("error {err}"); return Err(ENOENT.into()); } Ok(attr) => attr @@ -983,11 +983,11 @@ impl Filesystem for EncryptedFsFuse3 { fh: u64, offset: i64, ) -> Result>> { - debug!("readdir {} {} {}", inode, fh, offset); + debug!("readdir {inode} {fh} {offset}"); let iter = match self.get_fs().borrow().read_dir(inode) { Err(err) => { - error!("readdir error {}", err); + error!("readdir error {err}"); return Err(EIO.into()); } Ok(iter) => iter, @@ -1001,14 +1001,14 @@ impl Filesystem for EncryptedFsFuse3 { #[instrument(skip(self))] async fn releasedir(&self, req: Request, inode: Inode, fh: u64, flags: u32) -> Result<()> { - debug!("releasedir() called with {:?} {:?}", inode, fh); + debug!("releasedir() called with {inode} {fh}"); Ok(()) } #[instrument(skip(self))] async fn access(&self, req: Request, inode: u64, mask: u32) -> Result<()> { - debug!("access() called with {:?} {:?}", inode, mask); + debug!("access() called with {inode} {mask}"); match self.get_fs().borrow_mut().get_inode(inode) { Ok(attr) => { @@ -1031,7 +1031,7 @@ impl Filesystem for EncryptedFsFuse3 { mode: u32, flags: u32, ) -> Result { - debug!("create() called with {:?} {:?}", parent, name); + debug!("create() called with {parent} {}", name.to_str().unwrap()); let (read, write) = match flags as i32 & libc::O_ACCMODE { libc::O_RDONLY => (true, false), @@ -1045,7 +1045,7 @@ impl Filesystem for EncryptedFsFuse3 { return match self.create_nod(parent, mode, &req, name, read, write) { Ok((handle, attr)) => { - debug!("created handle {}", handle); + debug!("created handle {handle}"); // TODO: implement flags Ok(ReplyCreated { ttl: TTL, @@ -1056,7 +1056,7 @@ impl Filesystem for EncryptedFsFuse3 { }) } Err(err) => { - error!("create() error {}", err); + error!("create() error {err}"); Err(ENOENT.into()) } }; @@ -1073,11 +1073,11 @@ impl Filesystem for EncryptedFsFuse3 { offset: u64, _lock_owner: u64, ) -> Result>> { - debug!("readdirplus {} {}", parent, offset); + debug!("readdirplus {parent} {offset}"); let iter = match self.get_fs().borrow().read_dir_plus(parent) { Err(err) => { - error!("readdirplus error {}", err); + error!("readdirplus error {err}"); return Err(EIO.into()); } Ok(iter) => iter, @@ -1103,14 +1103,12 @@ impl Filesystem for EncryptedFsFuse3 { flags: u64, ) -> Result { debug!( - "copy_file_range() called with src ({}, {}, {}) dest ({}, {}, {}) size={}", - fh_in, inode, off_in, fh_out, inode_out, off_out, length - ); + "copy_file_range() called with src ({fh_in}, {inode}, {off_in}) dest ({fh_out}, {inode_out}, {off_out}) size={length}"); match self.get_fs().borrow_mut() .copy_file_range(inode, off_in, inode_out, off_out, length as usize, fh_in, fh_out) { Err(err) => { - error!("copy_file_range error {}", err); + error!("copy_file_range error {err}"); return Err(EBADF.into()); } Ok(len) => { @@ -1160,7 +1158,7 @@ fn as_file_kind(mut mode: u32) -> FileType { } else if mode == libc::S_IFDIR as u32 { return FileType::Directory; } else { - unimplemented!("{}", mode); + unimplemented!("{mode}"); } } diff --git a/src/main.rs b/src/main.rs index 9f1f0d19..e6d794df 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,14 +28,14 @@ async fn main() { match result { Ok(Ok(_)) => {} Ok(Err(err)) => { - error!("Error panic: {:#?}", err); + error!("Error panic: {err:#?}"); error!("Backtrace: {}", Backtrace::force_capture()); - panic!("Error panic: {:#?}", err); + panic!("Error panic: {err:#?}"); } Err(err) => { - error!("Error panic: {}", err); + error!("Error panic: {err}"); error!("Backtrace: {}", Backtrace::force_capture()); - panic!("Error panic: {}", err); + panic!("Error panic: {err}"); } } } @@ -281,7 +281,7 @@ async fn run_fuse(mountpoint: String, data_dir: &str, password: &str, cipher: Ci process::exit(1); } Err(err) => { - error!("{}", err); + error!("{err}"); process::exit(1); } Ok(fs) =>