I can't find a C way to find the size of block devices on NetBSD and OpenBSD. lseek to end doesn't work, like on most other systems. Do I really need to go through disklabel (poorly documented?)? What about uninitialized disks? NetBSD disklabels don't support 2 TB disks?
You could probably do a portable replacement via binary search with pread, looking for first block offset that gives a read error.
-
-
I would guess lseek SEEK_END not working is a remnant of ancient design. It does respect the offset for writes though. It would be great if
@NetBSD and OpenBSD implemented finding the size of block devices by lseek(2)'ing to SEEK_END. -
I found a solution using disklabel (see the other branch of the thread). I don't know how to handle partitions though, NetBSD doesn't support 2TB+ disks, and NetBSD doesn't seem to have a solution for uninitialized disks.
-
Not going to add non-O(1) workarounds for what the kernel should just have put in st_size or the result of lseek to SEEK_END. If I don't find good solutions, users of my program on such systems will have to live without a small feature on block devices.
-
My Sortix fills in the block device size in stat(2)'s st_size field, and lseek(2) SEEK_END also reports the size. But I take a different approach than other systems, I can respect mknod(2) working on any filesystem because device files are just a shim.
-
Turns out OpenBSD defines SEEK_END in terms of st_size, so it's internally consistent that SEEK_END on a block device seeks to 0 since the block device file doesn't have any actual filesystem contents (read/writes are intercepted).
-
st_size could be intercepted, like with read and write on block devices. Seems fairly doable with some BSD kernel experience, just had a quick look at the sources. The user-space fallout is more interesting, now du(1) and such needs to not count block devices.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.