Track actual bytes read in read operations

Add functionality to determine the actual number of bytes read during
read operations, making it possible to detect when a read was truncated
because it went past the end of the file.

Changes:
- Modified file_tree_read() to calculate and return actual_bytes via
  new output parameter
- Updated metadata server to send actual_bytes in READ_SUCCESS messages
- Added bytes_read field to ToastyResult structure
- Modified client to parse, store, and report actual bytes read
- Updated toasty_read() to return the actual number of bytes read
  instead of always returning 0
- Fixed web server to use bytes_read field instead of non-existent
  count field

This allows clients to distinguish between:
- Reading zeros because the file is sparse (has holes)
- Reading past the end of the file (truncated read)
This commit is contained in:
Claude
2025-11-22 22:22:43 +00:00
parent b930ba08e3
commit f856bd0e05
6 changed files with 44 additions and 10 deletions
+10 -1
View File
@@ -406,8 +406,9 @@ process_client_read(MetadataServer *state, int conn_idx, ByteView msg)
#define MAX_READ_HASHES 128
uint64_t chunk_size;
uint64_t actual_bytes;
SHA256 hashes[MAX_READ_HASHES];
int ret = file_tree_read(&state->file_tree, path, offset, length, &chunk_size, hashes, MAX_READ_HASHES);
int ret = file_tree_read(&state->file_tree, path, offset, length, &chunk_size, hashes, MAX_READ_HASHES, &actual_bytes);
if (ret < 0) {
@@ -439,6 +440,14 @@ process_client_read(MetadataServer *state, int conn_idx, ByteView msg)
uint32_t tmp = chunk_size;
message_write(&writer, &tmp, sizeof(tmp));
// Send the actual number of bytes that can be read
if (actual_bytes > UINT32_MAX) {
message_writer_free(&writer);
return -1;
}
uint32_t tmp_actual = actual_bytes;
message_write(&writer, &tmp_actual, sizeof(tmp_actual));
uint32_t num_hashes = ret;
message_write(&writer, &num_hashes, sizeof(num_hashes));