Search in very large files on 32-bit systems

I currently have a little battle involving seekC running in a 32-bit (x86) window.

In particular, I seem to be unable to look beyond the seemingly rather arbitrary file offset.

If I do this:

unsigned long long pos = 15032385535LLU;
int r = fseek(fd, pos, SEEK_SET);

then i will get

fstat64(3, {st_mode=S_IFREG|0644, st_size=1000000000000, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb77c3000
_llseek(3, 2147479552, [2147479552], SEEK_SET) = 0
read(3, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 4095) = 4095

TL DR is working.

However, if I increase posonly by 1 ...

unsigned long long pos = 15032385536LLU;
int r = fseek(fd, pos, SEEK_SET);

... then everything falls apart spectacularly:

fstat64(3, {st_mode=S_IFREG|0644, st_size=1000000000000, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb771e000
_llseek(3, 18446744071562067968, 0xbfd0f5f8, SEEK_SET) = -1 EINVAL (Invalid argument)

I completely lost why. What am I doing wrong?

The only significant tidbits that I can come up with are that 15032385535there is 37FFFFFFFone that seems interesting, as well as the fact that the number seems to be related to a temporary reduction .

-D_FILE_OFFSET_BITS=64, , , , , , . -DLARGEFILES -D_LARGEFILE_SOURCE , , , .

 

( ): truncate, 32- (); - - , , -, Range: . nginx Perl. ( Slackware - ), Python SimpleHTTPServer , thttpd mmap-. ...

+4
1

, ( ).

15032385535 = 0x37fffffff
15032385536 = 0x380000000

unsigned long - 32- , unsigned long long - 64- .

fseek long.

unsigned long long pos = …;
int r = fseek(fd, pos, SEEK_SET);

. - unsigned long long - unsigned long - undefined, , , , ,

fseek(fd, pos & 0xffffffff, SEEK_SET)

0xffffffff - unsigned long. pos = 0x37fffffff, 0x7fffffff = 2147483647. , fseek ! , .

pos = 0x380000000 : , , ( ) . , ; it -0x80000000 = -2147483648. _llseek, 64- ( 32- ). -0x80000000, strace 64- - 18446744071562067968 = 0xffffffff80000000.

C , , long. POSIX, fseeko, fseek, off_t long. -D_FILE_OFFSET_BITS=64, off_t - 64- .

+5

Source: https://habr.com/ru/post/1689803/


All Articles