man 2 open has wrong size and unit for file triggering EOVERFLOW?

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

 



Hello. Please refer to
http://man7.org/linux/man-pages/man2/open.2.html -- the paragraph
under EOVERFLOW. It reads that -D_FILE_OFFSET_BITS=64 is required
while compiling to access files under size (2<<31)-1 *bits*. This
seems to be wrong on two counts: that the numerical value is (2<<30)-1
and not (2<<31)-1, and that the unit should be bytes and not bits.
Please see the following transcript from a Kubuntu Trusty 32 bit
system on an ext3 filesystem:

$ cat test.c
# include <stdio.h>
int main () {
        FILE * fp = fopen("toobigfile", "r");
        if (fp) printf("Success\n"); else printf("Failure\n");
}
$ clang -o test test.c

Creating file of size (2<<30)-1 *bytes*:

$ truncate -s 2147483647 toobigfile

It opens fine:

$ strace -f -eopen ./test
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/i386-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("toobigfile", O_RDONLY)            = 3
Success
+++ exited with 0 +++

Increase it by one byte i.e. to (2<<30) bytes and it fails:

$ truncate -s 2147483648 toobigfile
$ strace -f -eopen ./test
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/i386-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("toobigfile", O_RDONLY)            = -1 EOVERFLOW (Value too
large for defined data type)
Failure
+++ exited with 0 +++

Compile the prog with the prescribed def and it succeeds:

$ clang -o test test.c -D_FILE_OFFSET_BITS=64
$ strace -f -eopen ./test
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
open("/lib/i386-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("toobigfile", O_RDONLY|O_LARGEFILE) = 3
Success
+++ exited with 0 +++

This shows that the threshold is actually 2 GiB which is (2<<30)
*bytes* and not (2<<31) *bits*. Note the difference in both the shift
length and units.

Note also that (2<<31) bits is (2<<28) bytes which is just 512 MiB and
certainly 32-bit apps can access 600 MiB files without special
compilation flags.

If you find this correct, please update the manpage. If you find this
incorrect, please inform me why. Thank you!

-- 
Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux