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

Potential bug in fuse's reported block size #4239

Closed
0xAdk opened this issue Mar 7, 2023 · 1 comment · Fixed by #4240
Closed

Potential bug in fuse's reported block size #4239

0xAdk opened this issue Mar 7, 2023 · 1 comment · Fixed by #4240

Comments

@0xAdk
Copy link

0xAdk commented Mar 7, 2023

Hi, I happened to stumble across this old pr #447 with this line

a.Blocks = (f.node.Size / blockSize) + 1

I don't think this is doing what you expect. I see two issues:

  1. The blocks field is (unintuitively) supposed to be the "Number of 512 B blocks allocated" - stat(3type), not the number of blockSize blocks as it is currently.
    This isn't an issue at present since blockSize is a constant 512, but it will be if the constant is changed in the future.

  2. file_size / block_size + 1 isn't a good way of doing "rounded up" integer division since it breaks when block_size divides evenly into file_size. For example with this code a file that is 512 bytes or 1 block, this issue means the code would report it as 2 blocks.

@greatroar
Copy link
Contributor

The blockSize constant exists to give exactly that number a name and is documented as such. It won't change.

But you're right about the computation. The right size is

(f.node.Size + blockSize - 1) / blockSize

greatroar added a commit to greatroar/restic that referenced this issue Mar 7, 2023
greatroar added a commit to greatroar/restic that referenced this issue Mar 7, 2023
greatroar added a commit to greatroar/restic that referenced this issue Mar 7, 2023
greatroar added a commit to greatroar/restic that referenced this issue Mar 7, 2023
MichaelEischer pushed a commit to MichaelEischer/restic that referenced this issue Apr 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants