[lug] FW: HELP!

Aaron Crane aaron.crane at pobox.com
Mon Oct 30 21:50:15 MST 2000


Sean Reifschneider <jafo at tummy.com> writes:
> There are specific functions that must be called to deal with files larger
> than 2GB on a system in which int is otherwise 32-bit.  I believe they are
> fseeko() and the like.

fseeko() is just a stdio function that uses an off_t to represent a file
offset, rather than a long.  (ISO C requires that fseek() use a long to
represent a file offset; Single Unix defined fseeko() so that Unix could
separate off_t from long.)

The way to access LFS calls is to define certain pre-processor symbols
before including any headers.  The two interesting ones are as follows:

  #define _LARGEFILE64_SOURCE
    This makes available a number of functions such as open64() and
    lseek64(), as well as a type off64_t which can represent file offsets in
    large files.  Similarly, <stdio.h> gets a new type fpos64_t and a wide
    variety of new operations including fopen64(), fseeko64(), and
    ftell64().

  #define _FILE_OFFSET_BITS 64
    This transparently replaces the normal file-system types and functions
    in the compilation environment with ones that can handle 64-bit offsets.
    (Note that fseek() is still the 32-bit one, but fseeko() is now 64-bit
    friendly.)  If this option is available, and if your code is
    sufficiently well-written as to avoid any assumptions about the size of
    off_t, then this is the simplest way to access large files.

Of course, all this about compilation is just a libc issue -- you still need
both your kernel and the relevant file-system to be LFS-aware if you want to
actually read and write large files.  As far as I can tell, that isn't the
case for ext2fs on 2.2.x kernels, though it does seem to work for block
devices.

-- 
Aaron Crane   <aaron.crane at pobox.com>   <URL:http://pobox.com/~aaronc/>





More information about the LUG mailing list