tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Issues with lseek(2) on a block device



On Wed, Feb 21, 2024 at 09:20:55PM +0000, Taylor R Campbell wrote:
> > Date: Wed, 21 Feb 2024 10:52:55 +0000
> > From: Sad Clouds <cryintothebluesky%gmail.com@localhost>
> > 
> > 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.

I am not sure this can be done for all block devices.  Tapes have block
devices, and open-reel tape drives do not really know the length of the
loaded media, while on any other tape drive supporting compression, there
may really be no such size.



Home | Main Index | Thread Index | Old Index