I need to seek around in large files of between 30GB-500GB. Unfortunately I need to do this on a 32-bit system.
I've just crashed into PHP's 2GB limit with fseek()
, in a way I've not seen documented online.
$ php -r 'var_dump(fseek(fopen("/dev/sda", "r"), 0, SEEK_END));'
int(-1)
So the syscall is returning -1
. I wonder why:
$ strace php -r 'var_dump(fseek(fopen("/dev/sda", "r"), 0, SEEK_END));'
...
lstat64("/dev/sda", {st_mode=S_IFBLK|0660, st_rdev=makedev(8, 0), ...}) = 0
lstat64("/dev", {st_mode=S_IFDIR|0755, st_size=5460, ...}) = 0
open("/dev/sda", O_RDONLY) = 3
fstat64(3, {st_mode=S_IFBLK|0660, st_rdev=makedev(8, 0), ...}) = 0
lseek(3, 0, SEEK_CUR) = 0
lseek(3, 0, SEEK_END) = -1 EOVERFLOW (Value too large for defined data type)
This is happening on a file only 60GB in size.
So I can't even seek to the end - lseek()
is apparently incapable of representing the file pointer back to PHP.
On a separate note, repeatedly seeking forward with SEEK_CUR seems to get stuck at 4GB - I can't move the file pointer past that point. I need to seek to the end of 500GB files.
What are my alternatives? My current plans are to use dd
(this is on Linux), and the tool I'm writing might as well be a shell script at this point...