Commit Graph
216 Commits
Author SHA1 Message Date
cozis dd74106935 Ignore .wal and .tmp files 2025-11-17 22:49:20 +01:00
Francesco CozzutoandGitHub a1c2e52ec1 Merge pull request #14 from cozis/claude/add-file-seek-mocks-01VBJ2woEagtYiZ4EXZj1ou1
Add mocks for lseek and SetFilePointer
2025-11-17 22:46:04 +01:00
Claude 2ab69e43fc Add mocks for lseek and SetFilePointer
- Added mock_lseek declaration and implementation for Linux
- Added mock_SetFilePointer declaration and implementation for Windows
- Added sys_lseek and sys_SetFilePointer macros for both BUILD_TEST and production modes
- Mocks follow existing pattern: validate descriptors, check type, forward to real functions
- Both mocks properly handle error cases and set errno/SetLastError
2025-11-17 21:44:39 +00:00
cozis 94744ede6f Use mocked version of MoveFileExW in wal.c 2025-11-17 22:34:38 +01:00
Francesco CozzutoandGitHub ba4936f565 Merge pull request #13 from cozis/claude/make-auth-system-018EC3ZfTMZUjJbR5SXo5J7K
Add MoveFileExW mock to system.h/.c
2025-11-17 22:32:09 +01:00
Claude 047203a745 Add MoveFileExW mock to system.h/.c
Add mock implementation for MoveFileExW Windows API function following
the existing pattern in the codebase. The mock forwards calls to the
real Windows API, allowing for future interception in the simulation
framework if needed.
2025-11-17 21:30:24 +00:00
Francesco CozzutoandGitHub 57ec853b4d Merge pull request #12 from cozis/claude/fix-wal-metadata-server-01Dva8AjnwAxq3JKaimzpRiY
Complete implementation of WAL for the metadata server
2025-11-17 22:25:37 +01:00
Claude e195c3b3b2 Fix critical data loss bug in Windows WAL rotation
CRITICAL BUG FIX: The previous Windows implementation had a fatal flaw
where it deleted the old WAL file before renaming, creating a window
where all data could be lost if the rename failed.

Previous (BROKEN) Windows code:
    remove_file_or_dir(wal->file_path);  // Delete old file
    rename(...);  // <-- If this fails, we've lost all data!

New implementation uses MoveFileExW with MOVEFILE_REPLACE_EXISTING:
- Windows: MoveFileExW(..., MOVEFILE_REPLACE_EXISTING) atomically
  replaces the destination file, matching Unix semantics
- Unix/Linux: rename() continues to atomically replace as before
- Both platforms now have atomic file replacement with no data loss window

This ensures durability on both platforms - if the operation fails at
any point, we still have either the old file or the new file, never
losing all data.
2025-11-17 21:17:11 +00:00
Claude e8d1e059c3 Improve WAL robustness: fix lifetime issues and use dynamic allocation
This commit addresses several important robustness issues in the WAL
implementation:

1. Fixed file_path lifetime issue:
   - The file_path argument to wal_open() may not have the same lifetime
     as the WAL structure
   - Now allocate and copy the path string to ensure WAL owns its data
   - Properly free the allocated path in wal_close()
   - Added error cleanup path in wal_open() to prevent memory leaks

2. Replaced static arrays with dynamic allocation in next_entry():
   - Static arrays were not thread-safe and had limited lifetimes
   - Now dynamically allocate path buffer and hash buffers using sys_malloc
   - Caller must free allocated fields after using the entry
   - Added proper error cleanup to free allocations on failure
   - Updated wal_open() to free entry fields after processing each entry

3. Improved swap_file() for cross-platform compatibility:
   - On Unix/Linux: rename() atomically replaces the destination file
   - On Windows: rename() doesn't overwrite, so delete old file first
   - Added platform-specific handling with #ifdef _WIN32
   - Ensures WAL rotation works correctly on both platforms

4. Added system.h include for sys_malloc/sys_free definitions

These changes ensure proper memory management, prevent leaks, and make
the WAL implementation more robust across different platforms.
2025-11-17 21:12:33 +00:00
Claude 52bc1ff450 Complete WAL implementation with file rotation
This commit completes the Write-Ahead Log (WAL) implementation for the
metadata server, including all missing functionality and error fixes:

File System Changes (src/file_system.c):
- Implemented file_set_offset() using lseek (Linux) and SetFilePointer (Windows)
- Implemented file_get_offset() to get current file position

WAL Header Changes (src/wal.h):
- Added file_tree pointer to WAL structure for snapshot serialization
- Added file_path to WAL structure for rotation operations

WAL Implementation (src/wal.c):
- Fixed handle assignment bug in wal_open (was using wal->handle before assignment)
- Fixed missing return statement in append_begin()
- Implemented serialize_callback for writing file tree snapshots to WAL
- Implemented deserialize_callback for reading file tree snapshots from WAL
- Implemented next_entry() to read WAL entries from file during recovery
- Implemented wal_append_write() to write file modifications to WAL
- Implemented swap_file() for complete WAL file rotation:
  * Creates temporary file with new snapshot
  * Writes WAL header and serialized file tree
  * Atomically replaces old WAL file
  * Resets entry counter for new rotation cycle
- Added WAL file initialization for newly created files
- Added helper functions: read_exact, read_u8, read_u16, read_u32, read_u64, write_u32
- Fixed typo in comment (Not -> Now)

The WAL now supports:
- Full crash recovery by replaying logged operations
- Automatic file rotation when entry limit is reached
- Atomic file replacement to ensure durability
- Proper file locking throughout rotation process
2025-11-17 21:02:19 +00:00
cozis fb28e94a83 Continued work on the WAL 2025-11-17 21:52:44 +01:00
cozis 6126a2e932 Draft of wal.c/.h 2025-11-17 15:49:09 +01:00
cozis eaa3f3a8a1 Implement FileTree serialization and deserialization routines 2025-11-17 15:02:22 +01:00
cozis fbcfd80f6d Add TODO.txt entry 2025-11-17 13:08:14 +01:00
cozis b7fc855a80 Move miscellaneous files to the misc folder 2025-11-17 13:06:51 +01:00
cozis cd865a5cdf Simplify Features bullet points to make them easier to read 2025-11-17 13:04:56 +01:00
cozis ec159a2c6a Minor reorganization of test in the README.md 2025-11-17 13:03:01 +01:00
cozis 04a706dad9 Add code snippet to README.md 2025-11-17 13:01:30 +01:00
cozis bc0a95a9a5 Turn TODO.txt in a list of checkboxes 2025-11-17 12:54:06 +01:00
cozis 4accabc4e2 Add Features paragraph to README.md 2025-11-17 12:48:52 +01:00
cozis 09f1ed4b3e Reorganize types in ToastyFS.h by placing them near function interfaces that reference them 2025-11-17 11:50:22 +01:00
cozis 3fc1e12623 Modify Makefile clean rule to remove compilation artifacts by their extension (.exe, .out, ...), not their full name 2025-11-17 11:46:23 +01:00
cozis 46db334a2e Resolve compilation errors and implement blocking API 2025-11-17 11:32:09 +01:00
cozis ee05547981 Fix compilation errors 2025-11-16 16:16:54 +01:00
cozis c6cac0155e Change client.c to match the new ToastyFS.h API 2025-11-16 16:07:03 +01:00
cozis b591408cc9 Fix some build errors 2025-11-16 13:01:08 +01:00
cozis f7dc52ae8f Add example of the blocking API 2025-11-16 12:21:31 +01:00
cozis 58d2d7def3 Polish API in ToastyFS.h 2025-11-16 11:59:58 +01:00
cozis 914419df6d Add timeout logic to toastyfs_wait 2025-11-16 11:59:39 +01:00
cozis 91a2395448 Add README 2025-11-16 02:21:37 +01:00
cozis e1cdc28d4d Rename project to ToastyFS 2025-11-16 02:10:59 +01:00
cozis a4a37b7a36 Minor fixes 2025-11-16 01:18:05 +01:00
cozis 7af1bc27b5 Fix value of CHUNK_SERVER_RECONNECT_TIME by expressing it in seconds, also change it to a runtime-modifiable value 2025-11-15 12:10:26 +01:00
cozis 11054cae86 Add new chunk hashes to the cs_add_list when creating or updating them in the chunk server 2025-11-15 10:55:11 +01:00
cozis a366b46398 Bug fixes 2025-11-15 10:38:45 +01:00
cozis a11740ab41 Fix uninitialized BinaryReader struct when parsing auth response message 2025-11-14 21:14:33 +01:00
cozis bbae5fdb7f Fix compilation errors 2025-11-14 21:06:38 +01:00
cozis 3df1745d69 Add comments 2025-11-14 12:07:32 +01:00
cozis 2bbe1ac0e8 Clean up download logic for missing/lost chunks 2025-11-14 11:56:29 +01:00
Francesco CozzutoandGitHub 787807031b Merge pull request #11 from cozis/improve-chunk-management-policy
Improve chunk management policy
2025-11-14 01:17:57 +01:00
cozis 9a944feb01 Rewrote simulation scheduler and fixed some bugs 2025-11-14 01:16:48 +01:00
cozis 3a2173c154 Minor bug fixes 2025-11-13 23:37:42 +01:00
cozis 3048f3d66b Bug fixes 2025-11-13 23:02:25 +01:00
Francesco CozzutoandGitHub de3391c34a Merge pull request #10 from cozis/claude/measure-branch-coverage-0168rdcTg6viLER3ufRwoAye
Measure branch coverage of the simulation testing
2025-11-13 21:53:39 +01:00
Claude d4ecf6db17 Replace custom HTML generation with lcov/genhtml
Use the standard lcov tools instead of custom HTML generation.

Changes:
- Completely rewrite generate_coverage_html.sh to use lcov
- Install lcov if not available
- Use lcov to capture coverage data from .gcda files
- Use genhtml to create HTML reports with branch coverage
- Add scripts/README.md with usage instructions

Benefits:
- Professional HTML reports with standard lcov styling
- Better branch coverage visualization
- Sortable tables by line/function/branch coverage
- Source code view with execution counts
- Much simpler script (30 lines vs 200+ lines)

The reports now show:
- 32.1% branch coverage (781/2431 branches)
- 43.5% line coverage
- 61.3% function coverage
2025-11-13 20:41:28 +00:00
Claude abaa12c5b3 Remove all CSS styling from HTML reports, use browser defaults
Remove all custom styling and CSS to use only plain HTML with
browser default rendering.

Changes:
- Remove all <style> tags and CSS
- Remove CSS classes from generated HTML
- Simplify source code display to plain text format
- Use simple line number: execution count: source code format
- Browser will render with its own default styles

The reports are now pure HTML with no styling at all.
2025-11-13 20:26:20 +00:00
Claude b6b926a659 Simplify HTML coverage report styling to use minimal default styles
Remove fancy styling (rounded corners, shadows, progress bars, colors)
and use simple, clean HTML with basic tables and minimal CSS.

Changes:
- Use simple sans-serif font instead of Segoe UI
- Remove container divs, shadows, and rounded corners
- Replace progress bars with plain percentage text
- Simplify color scheme (light green/red for branch coverage)
- Remove emoji and decorative elements
- Clean up table styling to basic borders

The report is now much cleaner and follows standard HTML conventions.
2025-11-13 20:24:04 +00:00
Claude 4c0b3429f0 Add .gitattributes to enforce LF line endings for shell scripts
This fixes issues when running scripts in WSL where CRLF line endings
cause 'No such file or directory' errors. Also add a fix_line_endings.sh
script for users who already have the wrong line endings.
2025-11-13 20:07:57 +00:00
Claude d288b2896f Move coverage scripts to scripts/ directory and add Makefile targets
Reorganize coverage tooling for better project structure and easier usage.

Changes:
- Move measure_coverage.sh and generate_coverage_html.sh to scripts/
- Add Makefile targets:
  - make coverage-report: Generate text coverage summary (5s simulation)
  - make coverage-html: Generate HTML coverage report (5s simulation)
- Update measure_coverage.sh to find generate_coverage_html.sh using relative path

Usage:
  make coverage-report    # Quick text summary
  make coverage-html      # Full HTML report with branch details

The HTML report provides interactive visualization of which branches
were taken during simulation execution, with color-coded source views.
2025-11-13 19:58:14 +00:00
Claude b465d5282e Add HTML coverage reports with branch-level detail
Enhance the branch coverage measurement tool with HTML report generation
that shows exactly which branches were taken during simulation execution.

Changes:
- Add generate_coverage_html.sh script to create interactive HTML reports
- Update measure_coverage.sh with --html flag to generate reports
- Add *.gcov, *.gcda, *.gcno to .gitignore
- HTML reports show:
  - Overall coverage summary with visual progress bars
  - Per-file coverage breakdown with clickable links
  - Source code view with color-coded branch coverage
  - Green highlight: branches taken
  - Red highlight: branches not taken
  - Branch execution counts and percentages

Usage:
  ./measure_coverage.sh [duration] --html

The HTML report is generated in coverage_report/index.html and can be
viewed in any web browser. Each source file links to a detailed view
showing which specific branches were executed.
2025-11-13 19:55:08 +00:00