> Date: Wed, 21 Feb 2024 10:52:55 +0000
> From: Sad Clouds <cryintotheblue...@gmail.com>
> 
> Hello, for most operating systems determining the size of a block
> device can be done with:
> 
> lseek(fd, 0, SEEK_END);
> 
> However, on NetBSD this does not seem to work.

Internally, this is happens for more or less the same reason that
stat(2) doesn't return the size of a block device in st_size.

Each file system on which device nodes can reside implements its own
VOP_GETATTR (used by both lseek(2) and stat(2)), and most of them use
the _inode_ size (more or less) rather than querying the block device
that the device node represents for its physical size.

I think this is a bug, and it would be great if stat(2) just returned
the physical medium's size in st_size -- currently doing this reliably
takes at least three different ioctls to handle all storage media, if
I counted correctly in sbin/fsck/partutil.c's getdiskinfo.

But it's a little annoying to make that happen because it requires
going through all the file systems that have device nodes and
convincing their VOP_GETATTR implementations to do something different
for block devices (and ideally also character devices, if they
represent fixed-size media too).

Reply via email to