Page MenuHomeFreeBSD

Mention write(2) can return EINVAL in when the target is a block device
ClosedPublic

Authored by felix.the.red_gmail.com on Jul 3 2025, 12:20 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jul 31, 10:47 AM
Unknown Object (File)
Mon, Jul 28, 11:25 PM
Unknown Object (File)
Mon, Jul 28, 8:10 PM
Unknown Object (File)
Mon, Jul 28, 5:36 PM
Unknown Object (File)
Mon, Jul 28, 4:07 PM
Unknown Object (File)
Mon, Jul 28, 3:52 PM
Unknown Object (File)
Mon, Jul 28, 11:51 AM
Unknown Object (File)
Mon, Jul 28, 8:29 AM

Details

Summary

lib/libsys/write.2: Add EINVAL entry for when nbytes (write size)
is not a multiple of the sector's block size.

From the original PR:
When coming from Linux, people are surprised by the fact
that write(2) to a device must be aligned to block size.
Writing a non-aligned block onto a raw device is a case
where EINVAL is also returned but the manpage does not mention this.

PR:227185

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Yea, when this write(2) man page was written, this wasn't a restriction because we had both char and block devices for the disks and the former allowed any offset / size, while the latter had the restriction. Then phk rewrote the block layer and enforced this restriction.... So this has been the case for maybe 20 years now?

This revision is now accepted and ready to land.Jul 3 2025, 8:21 PM

Awesome. Thank you both so much, I'll merge this now!

Wait, should we have two EINVAL entries and not rewrite them both into one?

Wait, should we have two EINVAL entries and not rewrite them both into one?

Apparently allowed. See EPIPE earlier in that manual page.

Wait, should we have two EINVAL entries and not rewrite them both into one?

Apparently allowed. See EPIPE earlier in that manual page.

Happens all the time for EINVAL too and matches the POSIX docs.

Awesome, thank you so much, just wanted to check! I'll merge this when I get home, unless someone else wants to!

This revision was automatically updated to reflect the committed changes.