Bug 91149 - fix man page: read(2) and write(2) can return EINVAL for unaligned access to block devices
Summary: fix man page: read(2) and write(2) can return EINVAL for unaligned access to ...
Status: In Progress
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-doc (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-12-31 18:10 UTC by Justin T. Gibbs
Modified: 2020-04-29 15:06 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Justin T. Gibbs 2005-12-31 18:10:03 UTC
	The read system call will return EINVAL if the current file
	offset is not a multiple of the block size.  The read(2) man
	page should be updated to reflect this.

Fix: 

Update man page so an examination of kernel code is not required
	to determine why EINVAL is being returned. :-)
How-To-Repeat: 	Run /usr/ports/security/bcwipe.  It attempts to determine a
	block device's size vi a binary lseek search.  The current code
	does not round down the address passed to lseek to a multiple
	of the device block size.  Notice that subsequent read calls
	fail with EINVAL.
Comment 1 Matthias Andree freebsd_committer 2017-08-26 10:44:52 UTC
This should also be added to write(2); I have recently received a truss report from FreeBSD 12 running e2fsck that showed this fragment:

lseek(4,0x430,SEEK_SET)                 = 1072 (0x430)
write(4,"\^F0\M-!Y\0\0",6)             ERR#22 'Invalid argument'

where fd 4 is /dev/da0s1, an external 2015 Western Digital My Passport Ultra USB hard disk of 1 TB with this diskinfo (identifying information removed):

# diskinfo -v /dev/da0
/dev/da0
        512             # sectorsize
        1000170586112   # mediasize in bytes (931G)
        1953458176      # mediasize in sectors
        4096            # stripesize
        0               # stripeoffset
        121597          # Cylinders according to firmware.
        255             # Heads according to firmware.
        63              # Sectors according to firmware.
        WD My Passport 0830     # Disk descr.
        [REMOVED]       # Disk ident.
        Not_Zoned       # Zone Mode
Comment 2 Alexey Dokuchaev freebsd_committer 2020-04-26 08:50:41 UTC
I've just got bitten by this as well.  Please fix the manpage.  This bug had been reported in 2005 and still not fixed, how come?
Comment 3 Benedict Reuschling freebsd_committer 2020-04-29 15:06:28 UTC
I've started a first attempt at fixing the man pages. My review is here: https://reviews.freebsd.org/D24617