Coding question: finding the size of a block device

Dan Nelson dnelson at allantgroup.com
Thu Jun 22 22:53:14 UTC 2006


In the last episode (Jun 22), Mike Meyer said:
> In <1151008839.2360.30.camel at LatitudeFC5.network>, Andrew <andrew.chace at gmail.com> typed:
> > So I guess my question is: is there a POSIX compatible function that
> > will allow me to check the size of a given block device?
> 
> I'd be surprised - POSIX doesn't seem to deal with block devices at all.
> 
> Checking the sources to df, it uses statfs to get the
> information. Linux appears to have it as well, so it may be portable.

statfs only works on mounted filesystems, not arbitrary block devices.

/usr/sbin/diskinfo uses ioctl(fd, DIOCGMEDIASIZE, &mediasize), where
mediasize is an off_t.  

-- 
	Dan Nelson
	dnelson at allantgroup.com


More information about the freebsd-hackers mailing list