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

Linux/OSX: Fix reversed fsync check #903

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

ali1234
Copy link
Contributor

@ali1234 ali1234 commented Aug 7, 2024

This if() condition checks the result of seek, write, flush and fsync. The first three are methods on QFile, so return a truthy value on success. write() returns number of bytes written while seek() and flush() return bool true on success. Therefore they have to be inverted to detect errors. However, fsync() is a posix system call, so it returns zero (false) on success. Therefore it should not be inverted.

Note that currently this entire code block can never run. knownsize is always zero because QFile.size() currently cannot determine the size of a block device. However, when I asked to confirm this behavior, a Qt maintainer decided to implement it, so there is now a PR. If that is released then this code block will become live and the reversed fsync check will cause a problem.

PR: https://codereview.qt-project.org/c/qt/qtbase/+/581443

This if() condition checks the result of seek, write, flush
and fsync. The first three are methods on QFile, so return
a truthy value on success. write() returns number of bytes
written while seek() and flush() return bool true on success.
Therefore they have to be inverted to detect errors. However,
fsync() is a posix system call, so it returns zero (false) on
success. Therefore it should not be inverted.

Note that currently this entire code block can never run.
knownsize is always zero because QFile.size() currently
cannot determine the size of a block device. However, when I
asked to confirm this behavior, a Qt maintainer decided to
implement it, so there is now a PR. If that is released then
this code block will become live and the reversed fsync check
will cause a problem.

PR: https://codereview.qt-project.org/c/qt/qtbase/+/581443
@tdewey-rpi tdewey-rpi merged commit 7725ce7 into raspberrypi:qml Aug 7, 2024
@tdewey-rpi
Copy link
Collaborator

Thanks for the submission, @ali1234

@lurch
Copy link
Contributor

lurch commented Aug 7, 2024

knownsize is always zero because QFile.size() currently cannot determine the size of a block device. However, when I asked to confirm this behavior, a Qt maintainer decided to implement it, so there is now a PR. If that is released then this code block will become live and the reversed fsync check will cause a problem.

It might be a while until a version of QT containing that fix filters down to RPi Imager? In the meantime, I think the drivelist code might report the exact size of the drive's block device? (or maybe it only reports it to the nearest MB / GB, I can't remember)

@maxnet
Copy link
Collaborator

maxnet commented Aug 7, 2024

In the meantime, I think the drivelist code might report the exact size of the drive's block device?

Wouldn't bother with that.

Just get the Unix file descriptor of the QFile with handle() and perform the same ioctl() the Qt guys are going to implement....

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.

4 participants