How to confirm whether a block device is not being written anymore after a file write?

125 views Asked by At

When I finish writing a file into a device block (for example, /dev/sda), I have to wait a while to ensure that the buffer is still not being written anymore to the device. I have to set a callback to trigger a UI event when that finishes.

I have tried using the ejectable property from udisks2, and as the documentation says, it's only a guess. It has not been reliable in my experiments.

I have noticed that when the flushing finishes my file manager (Nautilus) lets me unmount the device. What API provides me with such device property?

1

There are 1 answers

0
noconst On

Calling fsync on the file descriptor of the device confirms that the buffer is done writing.