Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

stat function limit for files over 2GB ?

112 views
Skip to first unread message

Colossus

unread,
Dec 23, 2005, 8:33:56 AM12/23/05
to
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

Jan Vidar Krey

unread,
Dec 23, 2005, 9:01:48 AM12/23/05
to
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

Igmar Palsenberg

unread,
Dec 23, 2005, 9:01:01 AM12/23/05
to
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

Colossus

unread,
Dec 23, 2005, 9:08:56 AM12/23/05
to
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,

Igmar Palsenberg

unread,
Dec 23, 2005, 9:11:30 AM12/23/05
to
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

Message has been deleted

Colossus

unread,
Dec 23, 2005, 9:25:20 AM12/23/05
to
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)

Robert Harris

unread,
Dec 23, 2005, 9:54:32 AM12/23/05
to
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

Ralf Fassel

unread,
Dec 23, 2005, 10:25:44 AM12/23/05
to
* "Colossus" <colos...@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'

Valentin Nechayev

unread,
Dec 23, 2005, 11:03:12 AM12/23/05
to

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-

Robert Harris

unread,
Dec 23, 2005, 12:11:31 PM12/23/05
to
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.

Valentin Nechayev

unread,
Dec 23, 2005, 12:33:41 PM12/23/05
to

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-

Jordan Abel

unread,
Dec 23, 2005, 2:09:56 PM12/23/05
to
On 2005-12-23, Valentin Nechayev <ne...@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 new messages