stat function limit for files over 2GB ?

  • Follow


Hi,

I have an iso image file of 3.5 GB. When I open it with stat I get this
error:

Value too large for defined data type. Is there a woekaround ? I'm
using Linux 2.6.13.

Thanks,
--
Colossus
Xarchiver, a GTK2 only archive manager -
http://xarchiver.sourceforge.net
Cpsed, a Linux OpenGL 3D scene editor - http://cpsed.sourceforge.net
Mizio, a QT proxy hunter scanner tool - http://mizio.sourceforge.net

0
Reply colossus73 (14) 12/23/2005 1:33:56 PM

Colossus wrote:
> Hi,
> 
> I have an iso image file of 3.5 GB. When I open it with stat I get this
> error:
> 
> Value too large for defined data type. Is there a woekaround ? I'm
> using Linux 2.6.13.

Recompile with -D_FILE_OFFSET_BITS=64


	Igmar
0
Reply Igmar 12/23/2005 2:01:01 PM


Colossus wrote:
> I have an iso image file of 3.5 GB. When I open it with stat I get this
> error:
> 
> Value too large for defined data type. Is there a woekaround ? I'm
> using Linux 2.6.13.

You can try defining _LARGEFILE64_SOURCE. This should make off_t be 64 bit,
and thus change st_size in stat struct.

Hope this helps.

Cheers

-- 
Jan Vidar Krey
Unix Software Developer

0
Reply Jan 12/23/2005 2:01:48 PM

Hi guys,

thank you for replying, I did both the things, adding
-D_FILE_OFFSET_BITS=64 in the Makefile and _LARGEFILE64_SOURCE as
following in file iso.h:

#ifndef ISO_H
#define ISO_H

 #include <gtk/gtk.h>
 #include <sys/types.h>
 #include <sys/stat.h>

 #include "callbacks.h"
 #include "interface.h"
 #include "support.h"
 #include "main.h"

#define _LARGEFILE_SOURCE 1
#define _LARGEFILE64_SOURCE 1
#define _FILE_OFFSET_BITS 64

struct iso_primary_descriptor
{

CUT

But it still no works, could you please tell me the exact syntax for
the above define ?

Thank you,
--
Colossus
Xarchiver, a GTK2 only archive manager -
http://xarchiver.sourceforge.net
Cpsed, a Linux OpenGL 3D scene editor - http://cpsed.sourceforge.net
Mizio, a QT proxy hunter scanner tool - http://mizio.sourceforge.net

0
Reply Colossus 12/23/2005 2:08:56 PM

Colossus wrote:
> Hi guys,
> 
> thank you for replying, I did both the things, adding
> -D_FILE_OFFSET_BITS=64 in the Makefile and _LARGEFILE64_SOURCE as
> following in file iso.h:
> 
> #ifndef ISO_H
> #define ISO_H
> 
>  #include <gtk/gtk.h>
>  #include <sys/types.h>
>  #include <sys/stat.h>
> 
>  #include "callbacks.h"
>  #include "interface.h"
>  #include "support.h"
>  #include "main.h"
> 
> #define _LARGEFILE_SOURCE 1
> #define _LARGEFILE64_SOURCE 1
> #define _FILE_OFFSET_BITS 64

Include those *before* including header files.

The compile syntax :

gcc -o x x.c -D_FILE_OFFSET_BITS=64


	Igmar
0
Reply Igmar 12/23/2005 2:11:30 PM

>Include those *before* including header files.

I have a project composed by many files, where before shall I put the
define ?? This is the list of my project files:

[gt@Paradise Xarchiver-0.4]$ ls src/*.c
src/7zip.c  src/bzip2.c      src/gzip.c       src/iso.c   src/rar.c
src/support.c  src/zip.c
src/arj.c   src/callbacks.c  src/interface.c  src/main.c  src/rpm.c
src/tar.c

0
Reply Colossus 12/23/2005 2:15:04 PM

Ok, sorry, it works ! But I have problem in displaying the size with
the printf, the size is wrong. Is it correct to use

printf ("Size: %lld\n",size)

Thank you,
--
Colossus
Xarchiver, a GTK2 only archive manager -
http://xarchiver.sourceforge.net
Cpsed, a Linux OpenGL 3D scene editor - http://cpsed.sourceforge.net
Mizio, a QT proxy hunter scanner tool - http://mizio.sourceforge.net

0
Reply Colossus 12/23/2005 2:25:20 PM

Colossus wrote:
> Ok, sorry, it works ! But I have problem in displaying the size with
> the printf, the size is wrong. Is it correct to use
> 
> printf ("Size: %lld\n",size)
Yes. The libc manual with your system (info libc) should tell you about it.

Robert
0
Reply Robert 12/23/2005 2:54:32 PM

* "Colossus" <colossus73@gmail.com>
| >Include those *before* including header files.
| 
| I have a project composed by many files, where before shall I put
| the define ??

Include them in the commandline flags for gcc (via -D in your
Makefile).  If you put them in a header file you must make sure that
this header file is included _before_ anything else in _every_ source
file (old and new), otherwise you may end up with different sized
off_t's in different compilation units.

R'
0
Reply Ralf 12/23/2005 3:25:44 PM

 Fri, Dec 23, 2005 at 06:25:20, colossus73 (Colossus) wrote about "stat function limit for files over 2GB ?": 

C> Ok, sorry, it works ! But I have problem in displaying the size with
C> the printf, the size is wrong. Is it correct to use
C> printf ("Size: %lld\n",size)

Generally you shall not depend on fact the platform has `size_t'
identical to `long long'. If platform supports C99, print size_t as
%ju (or %jd if it can be signed, e.g. as returned from read()):

printf("Size: %ju\n", size);

Otherwise, use %lld and convert size to `long long'):

printf("Size: %llu\n", (long long) size);

For modern Linux, %ju and size_t is enough. But don't rely on kernel
version (and your story of using kernel 2.6.13 doesn't matter), rely
on [g]libc version.


-netch-
0
Reply Valentin 12/23/2005 4:03:12 PM

Valentin Nechayev wrote:
>  Fri, Dec 23, 2005 at 06:25:20, colossus73 (Colossus) wrote about "stat function limit for files over 2GB ?": 
> 
> C> Ok, sorry, it works ! But I have problem in displaying the size with
> C> the printf, the size is wrong. Is it correct to use
> C> printf ("Size: %lld\n",size)
> 
> Generally you shall not depend on fact the platform has `size_t'
> identical to `long long'. If platform supports C99, print size_t as
> %ju (or %jd if it can be signed, e.g. as returned from read()):
The type of a file offset is not size_t (which is the unsigned integer 
type returned by sizeof, usually the same size as a pointer, 32 bits on 
a 32-bit PC) but off_t. And the C99 printf flag for a size_t is %zu. 
(%ju is for a maxint_t, the largest integer type defined on the system).

Now the C language standard doesn't know about file offsets. And printf 
doesn't have a flag to describe their size.
> 
> [snip]
> 
> Otherwise, use %lld and convert size to `long long'):
> 
> printf("Size: %llu\n", (long long) size);
This is the safe way.
0
Reply Robert 12/23/2005 5:11:31 PM

 Fri, Dec 23, 2005 at 17:11:31, robert.f.harris (Robert Harris) wrote about "stat function limit for files over 2GB ?": 

> C>> Ok, sorry, it works ! But I have problem in displaying the size with
> C>> the printf, the size is wrong. Is it correct to use
> C>> printf ("Size: %lld\n",size)
>> Generally you shall not depend on fact the platform has `size_t'
>> identical to `long long'. If platform supports C99, print size_t as
>> %ju (or %jd if it can be signed, e.g. as returned from read()):
RH> The type of a file offset is not size_t (which is the unsigned integer 
RH> type returned by sizeof, usually the same size as a pointer, 32 bits on 
RH> a 32-bit PC) but off_t. And the C99 printf flag for a size_t is %zu. 
RH> (%ju is for a maxint_t, the largest integer type defined on the system).
Correct, I thought for [u]intmax_t but said for size_t.

RH> Now the C language standard doesn't know about file offsets. And printf 
RH> doesn't have a flag to describe their size.
So, conversion to [u]intmax_t is the only working way (if system
supports [u]intmax_t and its format conversions).

>> Otherwise, use %lld and convert size to `long long'):
>> 
>> printf("Size: %llu\n", (long long) size);
RH> This is the safe way.

In case when `long long' is no narrower than `off_t', yes.


-netch-
0
Reply Valentin 12/23/2005 5:33:41 PM

On 2005-12-23, Valentin Nechayev <netch@segfault.kiev.ua> wrote:
>
>  Fri, Dec 23, 2005 at 06:25:20, colossus73 (Colossus) wrote about "stat function limit for files over 2GB ?": 
>
> C> Ok, sorry, it works ! But I have problem in displaying the size with
> C> the printf, the size is wrong. Is it correct to use
> C> printf ("Size: %lld\n",size)
>
> Generally you shall not depend on fact the platform has `size_t'
> identical to `long long'. If platform supports C99, print size_t as
> %ju (or %jd if it can be signed, e.g. as returned from read()):
>
> printf("Size: %ju\n", size);

whoa - j is intmax_t - z is for size_t.
0
Reply Jordan 12/23/2005 7:09:56 PM

12 Replies
615 Views

(page loaded in 0.832 seconds)

Similiar Articles:


















7/24/2012 10:06:12 AM


Reply: