From 2b38a102eabe890c9200abb8867eabc672878cbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Hanuszczak?= Date: Wed, 4 Nov 2026 16:36:31 +0100 Subject: [PATCH] Report volume path in `get_file_*_kmx` actions --- .../rrg/src/action/get_file_contents_kmx.rs | 24 +++++++++++++++++++ .../rrg/src/action/get_file_metadata_kmx.rs | 5 ++++ crates/rrg/src/action/get_file_sha256_kmx.rs | 10 ++++++++ proto/rrg/action/get_file_contents_kmx.proto | 6 +++++ proto/rrg/action/get_file_metadata_kmx.proto | 6 +++++ proto/rrg/action/get_file_sha256_kmx.proto | 6 +++++ 6 files changed, 57 insertions(+) diff --git a/crates/rrg/src/action/get_file_contents_kmx.rs b/crates/rrg/src/action/get_file_contents_kmx.rs index 80f9760a..09f8e915 100644 --- a/crates/rrg/src/action/get_file_contents_kmx.rs +++ b/crates/rrg/src/action/get_file_contents_kmx.rs @@ -31,6 +31,8 @@ type Item = Result; /// Result of the `get_file_contents` action in case of success. #[derive(Debug)] pub struct OkItem { + /// Absolute path to the raw volume on which the file is located. + volume_path: std::path::PathBuf, /// Path to the file this result corresponds to. path: keramics_formats::ntfs::NtfsPath, /// Byte offset of the file part sent to the blob sink. @@ -44,6 +46,8 @@ pub struct OkItem { /// Result of the `get_file_contents` action in case of an error. #[derive(Debug)] struct ErrorItem { + /// Absolute path to the raw volume on which the file is located. + volume_path: std::path::PathBuf, /// Path to the file that cause the issue. path: keramics_formats::ntfs::NtfsPath, /// Error that occurred when working with the file. @@ -111,6 +115,7 @@ where Ok(file_entry) => file_entry, Err(error) => { session.reply(Err(ErrorItem { + volume_path: volume_path.clone(), path, error, }))?; @@ -143,6 +148,7 @@ where Ok(file_data_stream) => file_data_stream, Err(error) => { session.reply(Err(ErrorItem { + volume_path: volume_path.clone(), path: path.clone(), error, }))?; @@ -167,6 +173,7 @@ where Ok(_) => (), Err(error) => { session.reply(Err(ErrorItem { + volume_path: volume_path.clone(), path: path.clone(), error: FileError { kind: FileErrorKind::Seek, @@ -190,6 +197,7 @@ where Ok(len_read) => len_read, Err(error) => { session.reply(Err(ErrorItem { + volume_path: volume_path.clone(), path: path.clone(), error: FileError { kind: FileErrorKind::Read, @@ -209,6 +217,7 @@ where session.send(crate::Sink::Blob, blob)?; session.reply(Ok(OkItem { + volume_path: volume_path.clone(), path: path.clone(), offset, len: len_read, @@ -287,6 +296,7 @@ impl crate::response::Item for Item { .map(|comp| String::from_utf16_lossy(&comp.elements)) ); + proto.set_volume_path(item.volume_path.into()); proto.set_path(path.into()); proto.set_offset(item.offset); proto.set_length(item.len as u64); @@ -299,6 +309,7 @@ impl crate::response::Item for Item { .map(|comp| String::from_utf16_lossy(&comp.elements)) ); + proto.set_volume_path(item.volume_path.into()); proto.set_path(path.into()); proto.set_error(item.error.to_string()); } @@ -374,6 +385,7 @@ mod tests { let error_item = session.reply::(0) .as_ref().unwrap_err(); + assert_eq!(error_item.volume_path, ntfs_file.path()); assert_eq!(error_item.path, "\\idonotexist".into()); assert_eq!(error_item.error.kind, FileErrorKind::OpenEntry); } @@ -403,6 +415,7 @@ mod tests { let error_item = session.reply::(0) .as_ref().unwrap_err(); + assert_eq!(error_item.volume_path, ntfs_file.path()); assert_eq!(error_item.path, "\\dir".into()); assert_eq!(error_item.error.kind, FileErrorKind::OpenDataStream); } @@ -458,6 +471,8 @@ mod tests { let item = session.reply::(0) .as_ref().unwrap(); + assert_eq!(item.volume_path, ntfs_file.path()); + assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file")); assert_eq!(item.offset, 0); assert_eq!(item.len, b"0123456789".len()); @@ -494,6 +509,8 @@ mod tests { let item = session.reply::(0) .as_ref().unwrap(); + assert_eq!(item.volume_path, ntfs_file.path()); + assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file")); assert_eq!(item.offset, 5); assert_eq!(item.len, 5); @@ -530,6 +547,8 @@ mod tests { let item = session.reply::(0) .as_ref().unwrap(); + assert_eq!(item.volume_path, ntfs_file.path()); + assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file")); assert_eq!(item.offset, 0); assert_eq!(item.len, 5); @@ -566,6 +585,8 @@ mod tests { let item = session.reply::(0) .as_ref().unwrap(); + assert_eq!(item.volume_path, ntfs_file.path()); + assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\file")); assert_eq!(item.offset, 0xb33f); assert_eq!(item.len, MAX_BLOB_LEN); @@ -727,18 +748,21 @@ mod tests { let item_34 = session.reply::(0) .as_ref().unwrap(); + assert_eq!(item_34.volume_path, ntfs_file.path()); assert_eq!(item_34.path, "\\foo".into()); assert_eq!(item_34.offset, 3); assert_eq!(item_34.len, 2); let item_78 = session.reply::(1) .as_ref().unwrap(); + assert_eq!(item_78.volume_path, ntfs_file.path()); assert_eq!(item_78.path, "\\foo".into()); assert_eq!(item_78.offset, 7); assert_eq!(item_78.len, 2); let item_9 = session.reply::(2) .as_ref().unwrap(); + assert_eq!(item_9.volume_path, ntfs_file.path()); assert_eq!(item_9.path, "\\foo".into()); assert_eq!(item_9.offset, 9); assert_eq!(item_9.len, 1); diff --git a/crates/rrg/src/action/get_file_metadata_kmx.rs b/crates/rrg/src/action/get_file_metadata_kmx.rs index 44a5a5db..a137912f 100644 --- a/crates/rrg/src/action/get_file_metadata_kmx.rs +++ b/crates/rrg/src/action/get_file_metadata_kmx.rs @@ -20,6 +20,7 @@ pub struct Args { /// Result of the `get_file_metadata_kmx` action. pub struct Item { + volume_path: std::path::PathBuf, path: keramics_formats::ntfs::NtfsPath, file_type: FileType, modified: Option, @@ -222,6 +223,7 @@ where log::debug!("sending metadata for '{:?}'", cur.path); session.reply(Item { + volume_path: volume_path.clone(), path: cur.path.clone(), file_type, modified, @@ -345,6 +347,7 @@ impl crate::response::Item for Item { ); let mut proto = rrg_proto::get_file_metadata_kmx::Result::new(); + proto.set_volume_path(self.volume_path.into()); proto.set_path(path.into()); proto.mut_metadata().set_type(self.file_type.into()); proto.mut_metadata().set_size(self.len); @@ -520,6 +523,7 @@ mod tests { assert_eq!(session.reply_count(), 1); let item = session.reply::(0); + assert_eq!(item.volume_path, ntfs_file.path()); assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\link")); assert_eq!(item.file_type, FileType::Symlink); } @@ -551,6 +555,7 @@ mod tests { assert_eq!(session.reply_count(), 1); let item = session.reply::(0); + assert_eq!(item.volume_path, ntfs_file.path()); assert_eq!(item.path, keramics_formats::ntfs::NtfsPath::from("\\link")); assert_eq!(item.file_type, FileType::Symlink); } diff --git a/crates/rrg/src/action/get_file_sha256_kmx.rs b/crates/rrg/src/action/get_file_sha256_kmx.rs index 7d3ebd5e..3ea2e0ad 100644 --- a/crates/rrg/src/action/get_file_sha256_kmx.rs +++ b/crates/rrg/src/action/get_file_sha256_kmx.rs @@ -25,6 +25,8 @@ pub struct Args { /// Result of the `get_file_sha256_kmx` action. struct Item { + /// Absolute path to the raw volume on which the file is located. + volume_path: std::path::PathBuf, /// Path of the file this result corresponds to. path: keramics_formats::ntfs::NtfsPath, /// Byte offset from which the file content was hashed. @@ -119,6 +121,7 @@ where let sha256 = <[u8; 32]>::from(sha256.finalize()); session.reply(Item { + volume_path: volume_path.clone(), path: args.path.clone(), offset, len: len_read_total, @@ -182,6 +185,7 @@ impl crate::response::Item for Item { .map(|comp| String::from_utf16_lossy(&comp.elements)) ); + proto.set_path(self.volume_path.into()); proto.set_path(path.into()); proto.set_offset(self.offset); proto.set_length(self.len); @@ -284,6 +288,7 @@ mod tests { assert_eq!(session.reply_count(), 1); let item = session.reply::(0); + assert_eq!(item.volume_path, ntfs_file.path()); assert_eq!(item.path, "\\foo".into()); assert_eq!(item.offset, 0); assert_eq!(item.len, u64::try_from(b"hello\n".len()).unwrap()); @@ -321,6 +326,7 @@ mod tests { assert_eq!(session.reply_count(), 1); let item = session.reply::(0); + assert_eq!(item.volume_path, ntfs_file.path()); assert_eq!(item.path, "\\foo".into()); assert_eq!(item.offset, u64::try_from(b"".len()).unwrap()); assert_eq!(item.len, u64::try_from(b"hello\n".len()).unwrap()); @@ -361,6 +367,7 @@ mod tests { assert_eq!(session.reply_count(), 2); let item_foo = session.reply::(0); + assert_eq!(item_foo.volume_path, ntfs_file.path()); assert_eq!(item_foo.path, "\\foo".into()); assert_eq!(item_foo.offset, 9); assert_eq!(item_foo.len, 3); @@ -373,6 +380,7 @@ mod tests { ]); let item_bar = session.reply::(1); + assert_eq!(item_bar.volume_path, ntfs_file.path()); assert_eq!(item_bar.path, "\\foo".into()); assert_eq!(item_bar.offset, 21); assert_eq!(item_bar.len, 3); @@ -410,6 +418,7 @@ mod tests { assert_eq!(session.reply_count(), 1); let item = session.reply::(0); + assert_eq!(item.volume_path, ntfs_file.path()); assert_eq!(item.path, "\\foo".into()); assert_eq!(item.offset, 0); assert_eq!(item.len, u64::try_from(b"hello\n".len()).unwrap()); @@ -448,6 +457,7 @@ mod tests { assert_eq!(session.reply_count(), 1); let item = session.reply::(0); + assert_eq!(item.volume_path, ntfs_file.path()); assert_eq!(item.path, "\\foo".into()); assert_eq!(item.offset, 0); assert_eq!(item.len, 13371337); diff --git a/proto/rrg/action/get_file_contents_kmx.proto b/proto/rrg/action/get_file_contents_kmx.proto index 9234a790..62df46d3 100644 --- a/proto/rrg/action/get_file_contents_kmx.proto +++ b/proto/rrg/action/get_file_contents_kmx.proto @@ -39,6 +39,12 @@ message Args { } message Result { + // Absolute path to the raw volume on which the file is located. + // + // This will be the original volume path specified in the arguments, if avail- + // lable or the inferred path if only volume mount path is given. + rrg.fs.Path volume_path = 6; + // Path to the file this result corresponds to. rrg.fs.Path path = 4; diff --git a/proto/rrg/action/get_file_metadata_kmx.proto b/proto/rrg/action/get_file_metadata_kmx.proto index 47b58d5c..bbd5a00a 100644 --- a/proto/rrg/action/get_file_metadata_kmx.proto +++ b/proto/rrg/action/get_file_metadata_kmx.proto @@ -41,6 +41,12 @@ message Args { } message Result { + // Absolute path to the raw volume on which the file is located. + // + // This will be the original volume path specified in the arguments, if avail- + // lable or the inferred path if only volume mount path is given. + rrg.fs.Path volume_path = 3; + // Path to the file. // // This is the original root path of the file as specified in the arguments, diff --git a/proto/rrg/action/get_file_sha256_kmx.proto b/proto/rrg/action/get_file_sha256_kmx.proto index 32ddf51d..03572b2e 100644 --- a/proto/rrg/action/get_file_sha256_kmx.proto +++ b/proto/rrg/action/get_file_sha256_kmx.proto @@ -43,6 +43,12 @@ message Args { } message Result { + // Absolute path to the raw volume on which the file is located. + // + // This will be the original volume path specified in the arguments, if avail- + // lable or the inferred path if only volume mount path is given. + rrg.fs.Path volume_path = 5; + // Path (relative to the volume root) to the file this result corresponds to. rrg.fs.Path path = 1;