Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support 64 bit filesizes when calling ACE_OS::fstat() and _FILE_OFFSE… #2254

Merged
merged 4 commits into from
Feb 3, 2025

Conversation

esohns
Copy link
Contributor

@esohns esohns commented Jul 13, 2024

…T_BITS==64 on Win32 systems

Summary by CodeRabbit

  • Bug Fixes
    • Improved file statistics handling for large files on Windows platforms.
    • Enhanced error handling for file size detection.
    • Ensured consistent assignment of file metadata across different file sizes.

Copy link
Contributor

coderabbitai bot commented Jan 31, 2025

Caution

Review failed

The head commit changed during the review from 231f0c0 to 57e1062.

Walkthrough

The changes modify the fstat function in the ACE_OS namespace for Windows platforms, focusing on improving error handling and file size management. The updated implementation restructures the logic for handling large file sizes, ensuring more robust file statistics retrieval. The modifications address potential issues with file size assignments, particularly when dealing with files larger than 4GB, by using ULARGE_INTEGER and adding more precise error checking.

Changes

File Change Summary
ACE/ace/OS_NS_sys_stat.inl Refactored fstat function error handling and file size assignment for Windows platforms, including improved logic for large file sizes and unconditional assignment of file statistics.

Poem

🐰 In bytes of wisdom, a rabbit's tale unfolds,
File stats now dance with Windows' mighty holds
Large sizes bow to logic clean and bright
No overflow shall dim our coding might!
A patch of courage, small yet strong and true 🗂️


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
ACE/ace/OS_NS_sys_stat.inl (1)

53-60: Consider using constants for file mode composition.

The field assignments look good, but the file mode composition could be more maintainable using predefined constants.

Consider this more readable approach:

-    stp->st_mode = S_IXOTH | S_IROTH |
-      (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0 : S_IWOTH) |
-      (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? S_IFDIR : S_IFREG);
+    const mode_t BASE_MODE = S_IXOTH | S_IROTH;
+    const mode_t WRITE_MODE = (fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY) ? 0 : S_IWOTH;
+    const mode_t TYPE_MODE = (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? S_IFDIR : S_IFREG;
+    stp->st_mode = BASE_MODE | WRITE_MODE | TYPE_MODE;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 408bd95 and 0a73dd4.

📒 Files selected for processing (1)
  • ACE/ace/OS_NS_sys_stat.inl (1 hunks)
🔇 Additional comments (3)
ACE/ace/OS_NS_sys_stat.inl (3)

39-43: LGTM! Good safety check for large file sizes.

The condition prevents silent truncation of large file sizes by explicitly checking if the high part is non-zero and if the target type can't hold the full size. Setting errno to EINVAL is appropriate in this case.


45-52: LGTM! Proper implementation of 64-bit file size support.

The code correctly uses ULARGE_INTEGER for 64-bit support while maintaining backward compatibility. This implementation aligns perfectly with the PR's objective of supporting large file sizes on Win32.


39-61: Verify handling of edge cases.

Please verify the implementation handles these edge cases correctly:

  1. Special files (pipes, devices, etc.)
  2. File sizes exactly at 4GB (32-bit boundary)
  3. File sizes exactly at 16EB (64-bit boundary)
✅ Verification successful

Implementation correctly handles supported cases within Windows limitations

The current implementation is appropriate because:

  • File size handling is robust with proper 32/64-bit support and overflow checks
  • Windows-specific file types (regular files and directories) are correctly mapped
  • Unsupported POSIX file types (pipes, devices, etc.) are intentionally not handled as Windows lacks direct equivalents
  • The implementation safely returns errors rather than attempting unsafe mappings
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for test cases covering edge cases in fstat implementation

# Look for test files
echo "Searching for fstat test files..."
fd -e cpp -e h -e inl "test.*fstat"

# Look for specific test patterns
echo "Searching for edge case tests..."
rg -l "fstat.*4GB|fstat.*pipe|fstat.*device" 

# Look for existing implementations handling special files
echo "Searching for special file handling..."
ast-grep --pattern 'if \($FILE_ATTRIBUTE_DEVICE\) {
  $$$
}'

Length of output: 557


Script:

#!/bin/bash
# Search for file size and attribute handling tests
echo "Searching for size-related tests..."
rg -l "FileSizeHigh|FileSizeLow|_FILE_OFFSET_BITS.*64" --type cpp --type h

echo "Searching for Windows file attribute handling..."
rg "FILE_ATTRIBUTE_" -A 3 -B 3

echo "Searching for special file type handling..."
rg "S_IF(CHR|BLK|FIFO|SOCK)" -A 2 -B 2

Length of output: 6662

    * ACE/ace/OS_NS_sys_stat.inl:
@jwillemsen
Copy link
Member

@coderabbitai full review

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

✅ Actions performed

Full review triggered.

@jwillemsen jwillemsen merged commit 13acc82 into DOCGroup:master Feb 3, 2025
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants