Fix file size tracking to use actual written bytes
Previously, file_size was calculated as num_chunks * chunk_size, which incorrectly treated the file size as the full capacity of all allocated chunks. The actual file size should be the offset of the last byte written plus 1. Changes: - Added file_size field to File structure to track actual file extent - Initialize file_size to 0 when creating new files - Update file_size in file_tree_write() based on write offset + length - Modified file_tree_read() to use file_size instead of num_chunks * chunk_size - Updated serialization/deserialization to handle file_size field This ensures that actual_bytes calculations correctly reflect the true file size, not just the allocated chunk capacity.
This commit is contained in:
@@ -18,6 +18,7 @@ typedef struct Entity Entity;
|
||||
typedef struct {
|
||||
uint64_t chunk_size; // TODO: this should be an u32
|
||||
uint64_t num_chunks; // TODO: and this too
|
||||
uint64_t file_size; // Offset of last byte written + 1
|
||||
SHA256 *chunks;
|
||||
} File;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user