Thread: [Large file][Value too large for defined data type]

  1. #1
    Registered User
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    11

    [Large file][Value too large for defined data type]

    This is my little program for open Large File, but don't work.
    Code:
    /* Support Large File */
    #define _FILE_OFFSET_BITS 64
    
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <errno.h>
    
    int main() 
    {
    
    	FILE *fsource;
    	long img_size;
    
        	/* Open Image File */
        	if ((fsource = fopen("gnomebaker.iso", "rb")) == NULL)
    		{
                     	fprintf(stderr, "%s\n", strerror(errno));
                     	exit(EXIT_FAILURE);                                  
                    }   
    
            fseek(fsource, 0L, SEEK_END);  	
      
      	img_size = (ftell(fsource));   
    
      	printf("%s : size file %ld \n", strerror(errno), img_size); 
       
     	return 1;
    }

    I've put in the first line "_FILE_OFFSET_BITS 64" for enable support file over 2GBs, but result all times is Value too large for defined data type.

    this is result with strace.
    execve("./prova", ["./prova"], [/* 31 vars */]) = 0
    uname({sys="Linux", node="debian", ...}) = 0
    brk(0) = 0x804a000
    access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
    mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f80000
    access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
    open("/etc/ld.so.cache", O_RDONLY) = 3
    fstat64(3, {st_mode=S_IFREG|0644, st_size=49486, ...}) = 0
    mmap2(NULL, 49486, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f73000
    close(3) = 0
    access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
    open("/lib/tls/i686/cmov/libc.so.6", O_RDONLY) = 3
    read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\2 40O\1"..., 512) = 512
    fstat64(3, {st_mode=S_IFREG|0644, st_size=1241392, ...}) = 0
    mmap2(NULL, 1247388, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7e42000
    mmap2(0xb7f69000, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x127) = 0xb7f69000
    mmap2(0xb7f70000, 10396, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7f70000
    close(3) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7e41000
    mprotect(0xb7f69000, 20480, PROT_READ) = 0
    set_thread_area({entry_number:-1 -> 6, base_addr:0xb7e418e0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
    munmap(0xb7f73000, 49486) = 0
    brk(0) = 0x804a000
    brk(0x806b000) = 0x806b000
    open("gnomebaker.iso", O_RDONLY|O_LARGEFILE) = 3
    fstat64(3, {st_mode=S_IFREG|0644, st_size=4700372992, ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f7f000
    fstat64(3, {st_mode=S_IFREG|0644, st_size=4700372992, ...}) = 0
    _llseek(3, 4700372992, [4700372992], SEEK_SET) = 0
    fstat64(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 3), ...}) = 0
    mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f7e000
    write(1, "Value too large for defined data"..., 54Value too large for defined data type : size file -1
    ) = 54
    munmap(0xb7f7e000, 4096) = 0
    exit_group(1) = ?
    Process 3534 detached
    This is command for compiling program
    gcc -Wall prova.c -o prova
    This is info about FILE LARGE
    Code:
    salsan@debian:~$ isoinfo -d  -i gnomebaker.iso
    CD-ROM is in ISO 9660 format
    System id: LINUX
    Volume id: Debian 4.0 r2 i386 Bin-1
    Volume set id:
    Publisher id:
    Data preparer id:
    Application id: MKISOFS ISO 9660/HFS FILESYSTEM BUILDER & CDRECORD CD-R/DVD CREATOR (C) 1993 E.YOUNGDALE (C) 1997 J.PEARSON/J.SCHILLING
    Copyright File id:
    Abstract File id:
    Bibliographic File id:
    Volume set size is: 1
    Volume set sequence number is: 1
    Logical block size is: 2048
    Volume size is: 2293868
    El Torito VD version 1 found, boot catalog is in sector 7007
    Joliet with UCS level 3 found
    Rock Ridge signatures version 1 found
    Eltorito validation header:
        Hid 1
        Arch 0 (x86)
        ID ''
        Key 55 AA
        Eltorito defaultboot header:
            Bootid 88 (bootable)
            Boot media 0 (No Emulation Boot)
            Load segment 0
            Sys type 0
            Nsect 4
            Bootoff 1B60 7008
    This is my OS
    salsan@debian:~$ uname -a
    Linux debian 2.6.18-6-k7 #1 SMP Wed Jan 23 04:01:26 UTC 2008 i686 GNU/Linux
    Any idea ?

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    I don't think _FILE_OFFSET_BITS=64 will affect ftell() or fseek(). You'll have to use ftello() and fseeko() with the off_t type (from unistd.h). Or you could use fgetpos() and fsetpos() with the fpos_t type.

    http://www.gnu.org/software/libc/man...le-Positioning
    http://www.gnu.org/software/libc/man...le-Positioning

    gg

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes indeed, if your file is bigger than a "long", then you get:
    Quote Originally Posted by HMUG man page
    Code:
    [EOVERFLOW]        The resulting file offset would be a value which can-
                            not be represented correctly in an object of type
                            off_t for fseeko() and ftello() or long for fseek()
                            and ftell().
    I take it that "gnomebaker.iso" is bigger than 2GB?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    11
    Quote Originally Posted by Codeplug View Post
    I don't think _FILE_OFFSET_BITS=64 will affect ftell() or fseek(). You'll have to use ftello() and fseeko() with the off_t type (from unistd.h).
    I've tried now with fseeko and ftello but this is result with gcc

    prova.c: In function ‘main’:
    prova.c:24: warning: implicit declaration of function ‘fseeko’
    prova.c:26: warning: implicit declaration of function ‘ftello’
    this is my new code
    Code:
    /* Support Large File */
    #define _FILE_OFFSET_BITS 64
    
    #include <stdio.h>
    #include <unistd.h>
    #include <string.h>
    #include <stdlib.h>
    #include <errno.h>
    
    
    int main() 
    {
    
    	FILE *fsource;
    	off_t img_size;
    
        	/* Open Image File */
        	if ((fsource = fopen("gnomebaker.iso", "rb")) == NULL)
    		{
                     	fprintf(stderr, "%s\n", strerror(errno));
                     	exit(EXIT_FAILURE);                                  
                    }   
    
            fseeko(fsource, 0L, SEEK_END);  	
      
      	img_size = (ftello(fsource));   
    
      	printf("%s : size file %ld \n", strerror(errno),(long int)(img_size)); 
       
     	return 1;
    }
    This is my Gcc version
    salsan@debian:~$ gcc -v
    Using built-in specs.
    Target: i486-linux-gnu
    Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu
    Thread model: posix
    gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
    Quote Originally Posted by matsp
    I take it that "gnomebaker.iso" is bigger than 2GB?
    yep is 4,4 GB (4700372992 byte).

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Reading the stdio.h header tells me that you need to #define __USE_LARGEFILE before including anything in order for these to be available.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    11
    I've get this info from

    /usr/include
    This is my stdio.h

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, it looks like you should add
    Code:
    #define __USE_LARGEFILE64
    before your first #include.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    11
    Quote Originally Posted by matsp View Post
    Yes, it looks like you should add
    Code:
    #define __USE_LARGEFILE64
    before your first #include.
    Code:
    /* Support Large File */
    #define _FILE_OFFSET_BITS 64
    #define __USE_LARGEFILE64
    
    #include <stdio.h>
    #include <unistd.h>
    #include <string.h>
    #include <stdlib.h>
    #include <errno.h>
    
    
    int main() 
    {
    
    	FILE *fsource;
    	off_t img_size;
    
        	/* Open Image File */
        	if ((fsource = fopen("gnomebaker.iso", "rb")) == NULL)
    		{
                     	fprintf(stderr, "%s\n", strerror(errno));
                     	exit(EXIT_FAILURE);                                  
                    }   
    
            fseeko(fsource, 0L, SEEK_END);  	
      
      	img_size = (ftello(fsource));   
    
      	printf("%s : size file %ld \n", strerror(errno),(long int)(img_size)); 
       
     	return 1;
    }
    salsan@debian:~$ gcc -Wall prova.c -o prova
    prova.c: In function ‘main’:
    prova.c:25: warning: implicit declaration of function ‘fseeko’
    prova.c:27: warning: implicit declaration of function ‘ftello’

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Not 64. Just __USE_LARGEFILE.

    Or 64, and use fseeko64 and friends.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  10. #10
    Registered User
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    11
    This is result if try with __USE_LARGEFILE
    - __USE_LARGEFILE64
    + __USE_LARGEFILE
    salsan@debian:~$ gcc -Wall prova.c -o prova
    prova.c: In function ‘main’:
    prova.c:25: warning: implicit declaration of function ‘fseeko’
    prova.c:27: warning: implicit declaration of function ‘ftello’

  11. #11
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Works for me, without the warning.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  12. #12
    Registered User
    Join Date
    Jun 2005
    Location
    Italy
    Posts
    11
    Thanks more for your help, but is possible know version of your

    stdio.h

    ISO C99 Standard: 7.19 Input/output <stdio.h>
    gcc

    Using built-in specs.
    Target: i486-linux-gnu
    Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --with-tune=i686 --enable-checking=release i486-linux-gnu
    Thread model: posix
    gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
    and your system ?

    Linux debian 2.6.18-6-k7 #1 SMP Wed Jan 23 04:01:26 UTC 2008 i686 GNU/Linux
    Because don't understand in my system make this warning.


    Now work this is my solution

    Code:
    /* Support Large File */
    #define _FILE_OFFSET_BITS 64
    #define _LARGEFILE_SOURCE
    
    #include <stdio.h>
    #include <unistd.h>
    #include <string.h>
    #include <stdlib.h>
    #include <errno.h>
    
    
    int main() 
    {
    
    	FILE *fsource;
    	off_t img_size;
    
        	/* Open Image File */
        	if ((fsource = fopen("gnomebaker.iso", "rb")) == NULL)
    		{
                     	fprintf(stderr, "&#37;s\n", strerror(errno));
                     	exit(EXIT_FAILURE);                                  
                    }   
    
            fseeko(fsource, 0L, SEEK_END);  	
      
      	img_size = (ftello(fsource));   
    
      	printf("%s : size file %ld \n", strerror(errno),(long int)(img_size)); 
       
     	return 1;
    }
    Last edited by salsan; 02-05-2008 at 04:57 AM. Reason: fixed problem :-)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting/interpreting large amounts of data
    By robot-ic in forum Networking/Device Communication
    Replies: 1
    Last Post: 02-27-2009, 12:26 PM
  2. Problem collecting large string of data
    By gkoenig in forum C Programming
    Replies: 3
    Last Post: 03-01-2008, 05:34 PM
  3. large data handling
    By re- in forum C++ Programming
    Replies: 2
    Last Post: 05-26-2007, 02:36 PM
  4. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM
  5. accepting large amounts of data
    By Sekti in forum C++ Programming
    Replies: 1
    Last Post: 04-05-2002, 05:45 PM