AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  struct stat.mode_t.st_mode for files >2G

    Posted Thu February 01, 2007 03:04 PM

    Originally posted by: SystemAdmin


    Apparently, aix changes the mode of files as their size exceeds 2G.

    Where can I programmically read/write the mode of a file greater than 2G?

    Where is this documented?

    What are the proper flags?

    The data involved is the
    st_mode
    field of type
    mode_t
    in the
    struct stat
    required by
    POSIX.2
    to be in
    <sys/stat.h>

    As an example, I can create a file "small".
    ksh> cat /dev/zero | head -c 2147483640 > small

    I can read its numeric mode with the following sniglet (incomplete code)
    ---- reportmode.c ----
    #include <sys/stat.h>
    #include <stdio.h>
    int main(int argc, char *argv[]){
    struct stat s;
    lstat(argv[1],&s);
    printf("%o\n",s.st_mode);
    }
    ---- reportmode.c ----

    I see the normal S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH for small.
    ksh> ls -l small
    -rw-r--r-- ... 2147483641 ... small
    ksh> ./reportmode small
    100644

    After adding 11 bytes, I no longer see the expected mode.
    ksh> /dev/zero | head -c10 >> small
    ksh> ls -l small
    -rw-r--r-- ... 2147483652 ... small
    ksh> ./reportmode small
    0 <--- Where is the mode programmimatically accessible?

    TIA,


  • 2.  Re: struct stat.mode_t.st_mode for files >2G

    Posted Fri February 02, 2007 03:54 PM

    Originally posted by: SystemAdmin


    This is not a solution.
    It represents what I learned that may help others, or ideally lead to a solution.

    I learned from another forum that
    -D_LARGE_FILES 1
    is required to write aix files larger than >2G.

    Adding this to a c snigglet causes aix to define static macros that transparently use 64bit versions of stdio.h functions.

    Unfortunately, g++-3.3.2 <cstdio> undefs those static macros.
    -D_LARGE_FILES 1
    reports that fopen is unknown (fopen64 is declared, but not sought).

    If aix's defines are left in place, so that fopen64 is called instead of fopen, the code builds without complaint, but file growth stops at 2G.

    What configuration do I need to build large file capable, ANSI c++ code,
    with gcc-3 on aix-5.3?

    TIA,


  • 3.  Re: struct stat.mode_t.st_mode for files >2G

    Posted Fri February 02, 2007 06:46 PM

    Originally posted by: SystemAdmin


    > This is not a solution.
    > It represents what I learned that may help others, or
    > ideally lead to a solution.

    I learned that explicitly including
    <bits/os_defines.h>
    indirectly defines _LARGE_FILES and allows writing files >2G with explicit use of
    fopen64 (not fopen).

    Unfortunately, when compiling c++ code, <bits/os_defines.h> is only included
    after most of the standard c++ headers have been included.
    Consequently errors result from conflict with the static macro definitions that aix uses to transparently substitute 64bit versions of the <cstdio> functions.
    (e.g. "define open open64' causes calls to ofstream::open() to fail.)
    Explicitly including <bits/os_defines.h> before any other header file (confirmed by g++ -E) resolves the compilation errors, but
    ofstream()
    does not call fopen64.

    How can I configure aix to build large-file-capable, ANSI c++ code,
    with gcc-3 on aix-5.3?

    TIA,