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:
+13
-1
@@ -411,7 +411,7 @@ int file_tree_write(FileTree *ft, string path,
|
||||
|
||||
int file_tree_read(FileTree *ft, string path,
|
||||
uint64_t off, uint64_t len, uint64_t *chunk_size,
|
||||
SHA256 *hashes, int max_hashes)
|
||||
SHA256 *hashes, int max_hashes, uint64_t *actual_bytes)
|
||||
{
|
||||
int num_comps;
|
||||
string comps[MAX_COMPS];
|
||||
@@ -432,6 +432,18 @@ int file_tree_read(FileTree *ft, string path,
|
||||
|
||||
*chunk_size = f->chunk_size;
|
||||
|
||||
// Calculate file size (number of chunks * chunk size)
|
||||
uint64_t file_size = f->num_chunks * f->chunk_size;
|
||||
|
||||
// Calculate actual bytes that can be read
|
||||
if (off >= file_size) {
|
||||
*actual_bytes = 0;
|
||||
} else if (off + len > file_size) {
|
||||
*actual_bytes = file_size - off;
|
||||
} else {
|
||||
*actual_bytes = len;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user