C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 02-04-2008, 12:47 PM   #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.
Quote:
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
Quote:
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
Quote:
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 ?
salsan is offline   Reply With Quote
Old 02-04-2008, 02:40 PM   #2
Registered User
 
Codeplug's Avatar
 
Join Date: Mar 2003
Posts: 3,900
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
Codeplug is offline   Reply With Quote
Old 02-04-2008, 03:05 PM   #3
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 02-04-2008, 05:02 PM   #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

Quote:
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
Quote:
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).
salsan is offline   Reply With Quote
Old 02-04-2008, 05:07 PM   #5
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Old 02-04-2008, 05:22 PM   #6
Registered User
 
Join Date: Jun 2005
Location: Italy
Posts: 11
I've get this info from

Quote:
/usr/include
This is my stdio.h
salsan is offline   Reply With Quote
Old 02-04-2008, 05:25 PM   #7
Kernel hacker
 
Join Date: Jul 2007
Location: Farncombe, Surrey, England
Posts: 15,686
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.
matsp is offline   Reply With Quote
Old 02-04-2008, 05:31 PM   #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;
}
Quote:
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’
salsan is offline   Reply With Quote
Old 02-04-2008, 05:43 PM   #9
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Old 02-05-2008, 03:56 AM   #10
Registered User
 
Join Date: Jun 2005
Location: Italy
Posts: 11
This is result if try with __USE_LARGEFILE
Quote:
- __USE_LARGEFILE64
+ __USE_LARGEFILE
Quote:
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’
salsan is offline   Reply With Quote
Old 02-05-2008, 04:03 AM   #11
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Old 02-05-2008, 04:18 AM   #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

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

Quote:
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 ?

Quote:
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, "%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 :-)
salsan is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 01:25 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22