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

Get the correct size for block devices #207

Merged
merged 1 commit into from
Dec 25, 2021

Conversation

RyuzakiKK
Copy link
Contributor

The function Size() of FileInfo returns the length in bytes for
regular files. However if we use a block device, Size() will return a
length of zero.

To chunk a file, we use the size to split the expected work in even
parts.

For this reason, when we wanted to generate an index from a block
device, due to the incorrect reported zero size, the whole task was
carried out by a single Goroutine.

With this commit we use the ioctl BLKGETSIZE64 to get the correct size
for block devices.

In a test environment the make operation against a block device took 2
minutes and 20 seconds to complete with the current master branch and
only 24 seconds with this patch.

The function `Size()` of `FileInfo` returns the length in bytes for
regular files. However if we use a block device, `Size()` will return a
length of zero.

To chunk a file, we use the size to split the expected work in even
parts.

For this reason, when we wanted to generate an index from a block
device, due to the incorrect reported zero size, the whole task was
carried out by a single Goroutine.

With this commit we use the ioctl `BLKGETSIZE64` to get the correct size
for block devices.

In a test environment the `make` operation against a block device took 2
minutes and 20 seconds to complete with the current master branch and
only 24 seconds with this patch.

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
Copy link
Owner

@folbricht folbricht left a comment

Choose a reason for hiding this comment

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

Nice one!

@folbricht folbricht merged commit 0bac841 into folbricht:master Dec 25, 2021
@RyuzakiKK RyuzakiKK deleted the fix_devices_size branch January 5, 2022 10:01
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 this pull request may close these issues.

2 participants