Closed zentasumu closed 4 years ago
Does not compile as-is on macOS. Need to not define lseek
as lseek64
and off_t
as off64_t
. macOS's off_t
is already 64 bit (it is typedef'd from __int64_t
), and there is no lseek64
.
Having said that, changing the #if 1
to #if 0
gets it to compile, and it works. Shows the same sector count & max sectors as the previous version (using the ioctl
code).
Probably other systems also have a 64 bit off_t
and lseek
already - need to come up with some way to figure that out. (The only other system I have to test on is OpenBSD, which also has off_t
as 64 bit and no lseek64
... unfortunately, I can't test it there because the link stage fails.) Other than that, this code seems to work.
Thanks for the input. That explains why they don't work on Windows as is too.
We'll just make a 64 bit flag
NEED_OFFSET_64
Or there might be defines that specify the bit size of off_t. Check if _OFFSET_BITS exists and its value or if _LARGE_FILE exists and defined. Those are possible starting points.
Honestly the block size check algorithm is a bit useless since 4k block size HDDs emulate 512 bytes so the read will succeed and return 512 anyway (?)
And the sector count algorithm counts by that block size (which in previous macOS it computes from what ioctl gives).
Should we just hard code the traditional 512 block size?
macOS doesn't have either _OFFSET_BITS
or _LARGE_FILE
defined anywhere. I did see a reference to _FILE_OFFSET_BITS
in zlib.h, but that may be some internal thing it sets in certain conditions; it's not reference anywhere else. I do see a define for __LP64_OFF64
, which may work, but may also only be defined on macOS. There is also OFF_MIN
and OFF_MAX
, which are defined to LLONG_MIN
and LLONG_MAX
respectively. That could be tested against. May need to pull in <limits.h>
for that.
And you probably can just hard code the 512 block size. PFS is set at 512 block size anyway. The reason I coded it the way I did for the ioctl
case was that I was getting a value directly and working with that, rather than reading anything.
_FILE_OFFSET_BITS
is the correct one.
and also
"On 64 bit systems this macro has no effect since the *64 functions are identical to the normal functions." (www.gnu.org)
So it should cause no conflict.
Confirmed working on Windows. Please test again on other platforms.
Thank you for submitting your changes. I apologize for taking a while to merge your changes.
Fixed an overflow that was making seek and off_t act up, either setting off an infinite loop or returning an invalid argument error.
Reports full drive size on Windows. Please check on other platforms.