Changeset 2316 for trunk


Ignore:
Timestamp:
Aug 29, 2005, 5:35:39 AM (20 years ago)
Author:
bird
Message:

o Reworked the open backend, adding directory support. Some O_*

flags was changed in the process, breaking the old ABI.
This is not fully tested.

o Added more BSD fields to struct stat, breaking the old ABI.

The mtime field and ctime fields will now keep the same values
and the creation time is to be found in birthtime. This means that
ctime will be updated in a few places where it doesn't on unix - but
this is probably better than previously where it wasn't ever updated
when it should.

Location:
trunk/src/emx
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/ChangeLog.LIBC

    • Property cvs2svn:cvs-rev changed from 1.134 to 1.135
    r2315 r2316  
    33TODO: open replace on RAMFS fails with error 32!
    44
    5 2005-08-29: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    6     - libc:
    7         o Removed forwarder dlls since struct stat and __LIBC_FH is incompatible in rc2.
     52005-08-28: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     6    - libc:
     7        o Reworked the open backend, adding directory support. Some O_*
     8          flags was changed in the process, breaking the old ABI.
     9          This is not fully tested.
     10        o Added more BSD fields to struct stat, breaking the old ABI.
     11          The mtime field and ctime fields will now keep the same values
     12          and the creation time is to be found in birthtime. This means that
     13          ctime will be updated in a few places where it doesn't on unix - but
     14          this is probably better than previously where it wasn't ever updated
     15          when it should.
     16        o Removed forwarder dlls since struct stat, O_* and __LIBC_FH is
     17          soon going to be incompatible with rc1 and older versions.
    818    - version.smak:
    919        o Changed version number back to 3.3.5 / 0.6 rc2.
    1020
    11 2005-08-28: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     212005-08-27: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    1222    - libc:
    1323        o Fixed lot's of unix attribute (in EA) handling.
     
    1626          This will break libsocket backwards compatability.
    1727        o Added _hstrdup.
    18 
    19 2005-08-27: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    20     - libc:
    2128        o Fixed two cases where the signal semaphore was incorrectly unlocked
    2229          after signalDeliver().
  • trunk/src/emx/include/InnoTekLIBC/backend.h

    • Property cvs2svn:cvs-rev changed from 1.33 to 1.34
    r2315 r2316  
    398398
    399399/**
    400  * Opens a file.
     400 * Opens or creates a file.
    401401 *
    402402 * @returns Filehandle to the opened file on success.
    403403 * @returns Negative error code (errno.h) on failure.
    404404 * @param   pszFile     Path to the file.
    405  * @param   fFlags      Open flags.
     405 * @param   fLibc       The LIBC open flags (O_*).
     406 * @param   fShare      The share flags (SH_*).
    406407 * @param   cbInitial   Initial filesize.
    407408 * @param   Mode        The specified permission mask.
    408  * @param   fLibc       LIBC filehandle flags.
    409409 * @param   ppFH        Where to store the LIBC filehandle structure which was created
    410410 *                      for the opened file.
    411411 */
    412 int __libc_Back_ioFileOpen(const char *pszFile, int fFlags, off_t cbInitial, mode_t Mode, unsigned fLibc, PLIBCFH *ppFH);
     412int __libc_Back_ioFileOpen(const char *pszFile, unsigned fLibc, int fShare, off_t cbInitial, mode_t Mode, PLIBCFH *ppFH);
    413413
    414414/**
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.19 to 1.20
    r2315 r2316  
    3636/*      O_NONBLOCK  0x00000004 */
    3737/*      O_APPEND    0x00000008 */
    38 /* emx  O_TEXT      0x00000010 */
    39 /* emx  O_SIZE      0x00000020 */
    40 /*      free        0x00000040 */
     38/*      reserved    0x00000010 O_SHLOCK */
     39/*      reserved    0x00000020 O_EXLOCK */
     40/*      reserved    0x00000040 O_ASYNC */
    4141/*      O_(F)SYNC   0x00000080 */
    42 /*      O_SYNC      0x00000080 */
    43 /* emx  O_BINARY    0x00000100 */
     42/*      O_NOFOLLOW  0x00000100 */
    4443/*      O_CREAT     0x00000200 */
    4544/*      O_TRUNC     0x00000400 */
    4645/*      O_EXCL      0x00000800 */
    4746/* emx  O_NOINHERIT 0x00001000 */
    48 /*      free        0x00002000 */
    49 /*      free        0x00004000 */
     47/*      free?       0x00002000 */
     48/*      free?       0x00004000 */
    5049/*      O_NOCTTY    0x00008000 */
     50/*      O_DIRECT    0x00010000 */
     51/* emx  O_BINARY    0x00020000 */
     52/* emx  O_TEXT      0x00040000 */
     53/* emx  O_SIZE      0x00080000 */
    5154#define F_EOF       0x00100000
    5255#define F_TERMIO    0x00200000
  • trunk/src/emx/include/sys/fcntl.h

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r2315 r2316  
    126126/* bird: EMX used 0x2000 for O_SYNC. */
    127127#define O_SYNC          0x0080          /* POSIX synonym for O_FSYNC */
    128 #if 0  /* bird: not implemented - start */
    129128#if __BSD_VISIBLE
    130129#define O_NOFOLLOW      0x0100          /* don't follow symlinks */
    131130#endif
    132 #endif /* bird: not implemented - end */
    133131#define O_CREAT         0x0200          /* create if nonexistent */
    134132#define O_TRUNC         0x0400          /* truncate to zero length */
     
    145143#define O_NOCTTY        0x8000          /* don't assign controlling terminal */
    146144
    147 #if 0  /* bird: not implemented - start */
    148145#if __BSD_VISIBLE
    149146/* Attempt to bypass buffer cache */
    150147#define O_DIRECT        0x00010000
    151148#endif
    152 #endif /* bird: not implemented - end */
    153149
    154150/*
     
    279275#if !defined (O_TEXT)
    280276/* Open flags.
    281    As stated in the FreeBSD part, there is supposidly a limited number of bits
    282    available. We'll try keep it suitable for 16bit just in case (don't care to
    283    check what we use right now) because that'll enable us to share a 32-bit flag
    284    variable per handle to both status (O_*) flags and descriptor (FD_*) flags.
    285 
    286    When we've disabled a few BSD flags and leave out KERNEL stuff the following
    287    bits are available:
    288         0x0010, 0x0020, 0x0040, 0x0100, 0x1000, 0x4000*, 0x2000
    289 */
    290 #define O_TEXT          0x0010
    291 #define O_BINARY        0x0100
    292 #define O_SIZE          0x0020          /* EMX used 0x8000 for O_SIZE. */
     277 *      There is some limits to the available bits, generally FreeBSD limits
     278 *      it's range to the first 16-bits. See emx\io.h for the complete
     279 *      assignments.
     280 */
     281#define O_BINARY    0x00020000
     282#define O_TEXT      0x00040000
     283#define O_SIZE      0x00080000
    293284#if !defined (_POSIX_SOURCE) || defined(__USE_EMX)
    294 #define O_NOINHERIT     0x1000          /* EMX used 0x1000 for O_NOINHERIT. */
     285#define O_NOINHERIT 0x00001000
    295286#endif
    296287#endif
  • trunk/src/emx/include/sys/stat.h

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r2315 r2316  
    137137struct stat {
    138138        __dev_t   st_dev;               /* inode's device */
     139#if 1 /* bird: emx: */
     140        __uint32_t st_attr;             /* emx: OS/2 & DOS attributes */
     141#endif
    139142        ino_t     st_ino;               /* inode's number */
    140143        mode_t    st_mode;              /* inode protection mode */
     
    143146        gid_t     st_gid;               /* group ID of the file's group */
    144147        __dev_t   st_rdev;              /* device type */
    145 #if 1 /* bird: emx */
    146         time_t    st_atime;
    147         time_t    st_mtime;
    148         time_t    st_ctime;
    149 #else /* bird: emx */
     148#if 1 /* bird: emx - better alignment of 64-bit types */
     149        __int32_t st_lspare;
     150#endif /* bird */
    150151#if __BSD_VISIBLE
    151152        struct  timespec st_atimespec;  /* time of last access */
     
    160161        long      st_ctimensec;         /* nsec of last file status change */
    161162#endif
    162 #endif /* bird: emx */
    163163        off_t     st_size;              /* file size, in bytes */
    164164        __int64_t st_blocks;            /* blocks allocated for file */
    165165        __uint32_t st_blksize;          /* optimal blocksize for I/O */
    166 #if 1 /* bird: emx: */
    167         long      st_attr;              /* emx: OS/2 & DOS attributes */
    168 #else /* bird: emx */
    169 
    170166        fflags_t  st_flags;             /* user defined flags for file */
    171167        __uint32_t st_gen;              /* file generation number */
     168#if 0 /* bird: !emx - it's higher up for packing reasons */
    172169        __int32_t st_lspare;
     170#endif /* bird */
    173171#if __BSD_VISIBLE
    174172        struct timespec st_birthtimespec; /* time of file creation */
     
    189187        unsigned int :(8 / 2) * (16 - (int)sizeof(struct __timespec));
    190188#endif
    191 #endif /* bird: emx - end */
    192189};
    193190
     
    220217#endif /* bird: emx */
    221218
    222 #if 0  /* bird: emx */
    223219#if __BSD_VISIBLE
    224220#define st_atime st_atimespec.tv_sec
     
    227223#define st_birthtime st_birthtimespec.tv_sec
    228224#endif
    229 #endif /* bird: emx */
    230225
    231226#define S_ISUID 0004000                 /* set user id on execution */
  • trunk/src/emx/src/lib/io/_vsopen.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r2315 r2316  
    1111#include <emx/syscalls.h>
    1212#include <InnoTekLIBC/backend.h>
     13#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
     14#include <InnoTekLIBC/logstrict.h>
    1315
    14 /* Bugs: O_TRUNC|O_RDONLY not implemented */
     16/* Bugs: O_TRUNC|O_RDONLY not implemented - bird: rejecting it makes more sense, just ask the OpenBSD guys. */
    1517/*       O_TEXT|O_WRONLY  does/can not overwrite Ctrl-Z */
    1618
     
    3234int _vsopen(const char *pszName, int fOpen, int fShare, va_list va)
    3335{
    34     int     hFile;
    35     /** Flags is for __open.
    36      *  0 -  1  Access mode (O_RDONLY, O_WRONLY, O_RDWR).
    37      *  4 -  6  Shared (SH_*)
    38      *  8 - 15  File attributes (DOS style).
    39      * 16 - 23  __open flags, _SO_*
    40      */
    41     int         fFlags;
    42     unsigned    fLibc;                  /* LIBC handle flags. */
    43     int         saved_errno;
    44     char        chDummy;
    45     int         fCtrlZKludge = 0;
    46     off_t       cbInitial;
    47     mode_t      cmode = 0;
    48     PLIBCFH     pFH;
     36    LIBCLOG_ENTER("pszName=%p:{%s} fOpen=%#x fShare=%#x ...\n", (void *)pszName, pszName, fOpen, fShare);
    4937
    5038    /*
    5139     * Validate input
    5240     */
    53     if ((fOpen & O_ACCMODE) == O_RDONLY && (fOpen & (O_TRUNC|O_CREAT)))
     41    if (    (fOpen & O_ACCMODE) == O_RDONLY
     42        &&  (fOpen & (O_TRUNC | O_CREAT)))
    5443    {
    5544        errno = EINVAL;
    56         return -1;
     45        LIBCLOG_ERROR_RETURN_INT(-1);
    5746    }
    5847
    5948    /*
    60      * Build fFlags.
     49     * Build fLibc
     50     *  - It's pretty much fOpen but we need to remove irrelevant flags and add O_TEXT/O_BINARY and such.
    6151     */
    62     fLibc = fOpen & (O_ACCMODE|O_NDELAY|O_APPEND|O_SYNC/*|O_DIRECT*/|O_NOINHERIT);
     52    unsigned fLibc = fOpen & (O_ACCMODE | O_NDELAY | O_APPEND | O_SYNC | O_DIRECT | O_NOINHERIT | O_CREAT | O_EXCL | O_TRUNC | O_NOINHERIT | O_SIZE);
    6353    if (   !(fOpen & O_BINARY)
    6454        && ((fOpen & O_TEXT) || !_fmode_bin))
    6555        fLibc |= O_TEXT;
    66 
    67     if ((fLibc & O_TEXT) && (fOpen & O_APPEND) && (fOpen & O_ACCMODE) == O_WRONLY)
     56    else
     57        fLibc |= O_BINARY;
     58    if ((fLibc & (O_EXCL | O_CREAT)) == O_EXCL)
    6859    {
    69         /* The caller requests to open a text file for appending in
    70            write-only.  To remove the Ctrl-Z (if there is any), we have
    71            to temporarily open the file in read/write mode. */
    72 
    73         fFlags = O_RDWR | (fShare & SH_MASK);
    74         fCtrlZKludge = 1;
    75     }
    76     else
    77         fFlags = (fOpen & O_ACCMODE) | (fShare & SH_MASK);
    78 
    79     /* cmode(=attr) - attr is 2nd byte of flags. */
    80     if (fOpen & O_CREAT)
    81     {
    82         int attr;
    83 
    84         attr = 0;
    85         cmode = va_arg(va, mode_t);
    86         if (!(cmode & S_IWRITE))
    87             attr |= _A_RDONLY;
    88         fFlags |= (attr << 8) | _SO_CREAT;
    89         if (fOpen & O_EXCL)
    90             fFlags |= _SO_EXCL;
     60        fLibc &= ~O_EXCL;               /* O_EXCL doesn't make sense without O_CREATE. */
     61        LIBCLOG_MSG("No O_CREAT, stripping O_EXCL.\n");
    9162    }
    9263
    93     if (fOpen & O_TRUNC)
    94         fFlags |= _SO_TRUNC;
     64    /*
     65     * If the caller requests to open a text file for appending in write-only
     66     * we have some trouble reading and stripping away any Ctrl-Z that may
     67     * reside at the end of the file. Thus, first open the file in O_RDWR mode
     68     * to do the stripping, close it, and reopen it in O_WRONLY mode.
     69     */
     70    int fCtrlZKludge = 0;
     71    if ((fLibc & (O_TEXT | O_APPEND | O_ACCMODE | O_EXCL)) == (O_TEXT | O_APPEND | O_WRONLY))
     72    {
     73        fCtrlZKludge = 1;
     74        fLibc = (fLibc & ~O_ACCMODE) | O_RDWR;
     75        LIBCLOG_MSG("Ctrl-Z: Applying the kludge.\n");
     76    }
    9577
    96     if (fOpen & O_NOINHERIT)
    97         fFlags |= _SO_NOINHERIT;
     78    /*
     79     * The file mode is only available if O_CREAT is specified.
     80     */
     81    mode_t  Mode = 0;
     82    if (fLibc & O_CREAT)
     83    {
     84        Mode = va_arg(va, mode_t);
     85        LIBCLOG_MSG("O_CREATE: Mode=0%o\n", Mode);
     86    }
    9887
    99     if (fOpen & O_SYNC)
    100         fFlags |= _SO_SYNC;
    101 
    102     /* Initial file size */
    103     cbInitial = 0;
    104     if (fOpen & O_SIZE)
     88    /*
     89     * The initial file size is only available if O_SIZE is specified.
     90     */
     91    off_t cbInitial = 0;
     92    if (fLibc & O_SIZE)
    10593    {
    10694        cbInitial = va_arg(va, off_t);
    107         fFlags |= _SO_SIZE;
     95        LIBCLOG_MSG("O_SIZE: cbInitial=%#llx\n", cbInitial);
    10896    }
    10997
     
    11199     * Open - note Ctrl-Z hack.
    112100     */
    113     saved_errno = errno;
    114     hFile = __libc_Back_ioFileOpen(pszName, fFlags, cbInitial, cmode, fLibc, &pFH);
    115     if (hFile < 0 && fCtrlZKludge && errno == EACCES)
     101    int     saved_errno = errno;
     102    PLIBCFH pFH;
     103    int     fd = __libc_Back_ioFileOpen(pszName, fLibc, fShare, cbInitial, Mode, &pFH);
     104    if (fd == -EACCES && fCtrlZKludge)
    116105    {
    117         /* Perhaps read access is denied. Try again. */
     106        LIBCLOG_MSG("Ctrl-Z: Open failed, retries without the kludge.\n");
    118107        fCtrlZKludge = 0;
    119         fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
    120         hFile = __libc_Back_ioFileOpen(pszName, fFlags, cbInitial, cmode, fLibc, &pFH);
     108        fLibc = (fLibc & ~O_ACCMODE) | O_WRONLY;
     109        fd = __libc_Back_ioFileOpen(pszName, fLibc, fShare, cbInitial, Mode, &pFH);
    121110    }
    122     if (hFile < 0)
     111    if (fd < 0)
    123112    {
    124         errno = -hFile;
    125         return -1;
     113        errno = -fd;
     114        LIBCLOG_ERROR_RETURN_INT(-1);
    126115    }
    127116    fLibc = pFH->fFlags;                /* get the updated flags. */
     
    130119     * Check what we got a handle to.
    131120     */
    132     if ((fLibc & __LIBC_FH_TYPEMASK) == F_DEV)
    133         fOpen &= ~O_APPEND;
     121    if (   (fLibc & O_APPEND)
     122        && (fLibc & __LIBC_FH_TYPEMASK) != F_FILE)
     123    {
     124        fLibc &= ~O_APPEND;
     125        LIBCLOG_MSG("Not a F_FILE, stripping O_APPEND!\n"); /** @todo __libc_Back_ioFileOpen should strip this! */
     126    }
    134127
    135128    /*
    136      * For text files we shall remove eventual ending Ctrl-Z.
     129     * For text files we shall remove the eventual Ctrl-Z at the end of the file.
    137130     */
    138     if (    (fLibc & __LIBC_FH_TYPEMASK) != F_DEV
    139         &&  (fLibc & O_TEXT))
     131    if (    (fLibc & (__LIBC_FH_TYPEMASK | O_TEXT | O_BINARY)) == (F_FILE | O_TEXT)
     132        &&  (fLibc & O_ACCMODE) != O_RDONLY)
    140133    {
    141         off_t cbSize;
    142 
    143134        /* Remove the last character of the file if it is a Ctrl-Z.  Do
    144135           this even if O_SIZE is given as we don't know whether the
    145136           file existed before; removing a spurious Ctrl-Z due to O_SIZE
    146137           should be harmless. */
    147 
    148         cbSize = __libc_Back_ioSeek(hFile, -1, SEEK_END);
     138        off_t cbSize = __libc_Back_ioSeek(fd, -1, SEEK_END);
    149139        if (cbSize >= 0)
    150140        {
    151             if (__read(hFile, &chDummy, 1) == 1 && chDummy == 0x1a)
    152                 __libc_Back_ioFileSizeSet(hFile, cbSize, 0); /* Remove Ctrl-Z */
    153             __libc_Back_ioSeek(hFile, 0, SEEK_SET);
     141            char chDummy = 127;
     142            if (    __read(fd, &chDummy, 1) == 1
     143                &&  chDummy == 0x1a)
     144            {
     145                int rc2 = __libc_Back_ioFileSizeSet(fd, cbSize, 0); /* Remove Ctrl-Z */
     146                LIBCLOG_MSG("Ctrl-Z: Strip attempt rc=%d, cbSize=%#llx\n", rc2, cbSize); (void)rc2;
     147            }
     148            else
     149                LIBCLOG_MSG("Ctrl-Z: Strip attempt chDummy=0x%02x, cbSize=%#llx.\n", chDummy, cbSize);
     150            __libc_Back_ioSeek(fd, 0, SEEK_SET);
    154151        }
     152        else
     153            LIBCLOG_MSG("Ctrl-Z: Failed to search to end of file, cbSize=%lld\n", cbSize);
    155154    }
    156155
    157156    /*
    158      * Reopen the file in write-only mode if Ctrl-Z hack applied.
     157     * Reopen the file in write-only Mode if Ctrl-Z hack applied.
    159158     */
    160159    if (fCtrlZKludge)
    161160    {
    162         __close(hFile);
    163         fFlags = (fFlags & ~O_ACCMODE) | (fOpen & O_ACCMODE);
    164         fFlags &= ~_SO_EXCL;       /* Ignore O_EXCL */
    165         hFile = __libc_Back_ioFileOpen(pszName, fFlags, cbInitial, cmode, fLibc & ~__LIBC_FH_TYPEMASK, &pFH);
    166         if (hFile < 0)
     161        LIBCLOG_MSG("Ctrl-Z: Reopening the file in O_WRONLY mode.\n");
     162        __close(fd);
     163        int fLibcSaved = fLibc;
     164        fLibc = (fLibc & ~(O_ACCMODE | O_EXCL | __LIBC_FH_TYPEMASK)) | O_WRONLY; /* Ignore exclusive open. */
     165        fd = __libc_Back_ioFileOpen(pszName, fLibc, fShare, cbInitial, Mode, &pFH);
     166        if (fd < 0)
    167167        {
    168             errno = -hFile;
    169             return -1;
     168            errno = -fd;
     169            LIBCLOG_ERROR_RETURN_INT(-1);
    170170        }
     171        if (fLibcSaved & O_EXCL)
     172            pFH->fFlags |= O_EXCL;
     173        fLibc = pFH->fFlags;
    171174    }
    172175
     
    177180    if (    (fLibc & __LIBC_FH_TYPEMASK) == F_FILE
    178181        &&  (fLibc & O_APPEND))
    179         __libc_Back_ioSeek(hFile, 0, SEEK_END);
     182    {
     183        off_t cbSize = __libc_Back_ioSeek(fd, 0, SEEK_END);
     184        LIBCLOG_MSG("O_APPEND: seek cbSize=%#llx\n", cbSize); (void)cbSize;
     185    }
     186
    180187    errno = saved_errno;
     188    LIBCLOG_RETURN_INT(fd);
     189}
    181190
    182     return hFile;
    183 }
  • trunk/src/emx/src/lib/sys/b_dir.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r2315 r2316  
    3838#include <errno.h>
    3939#include <limits.h>
     40#include <sys/fcntl.h>
    4041#include <emx/umalloc.h>
     42#include <emx/io.h>
    4143#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_IO
    4244#include <InnoTekLIBC/logstrict.h>
     
    252254 * @param   pszNativePath       Pointer to the native path. The buffer must be on stack
    253255 *                              and must have space for 4 extra bytes!
     256 * @param   fInUnixTree         Set if the native path is in the unix tree.
    254257 * @param   fLibc               The LIBC open() flags.
    255  */
    256 int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fLibc)
    257 {
    258     LIBCLOG_ENTER("pszNativePath=%p:{%s} fLibc=%#x\n", (void *)pszNativePath, pszNativePath, fLibc);
    259 
    260     /* setting up a temporary handle; allocate buffer and suchlike. */
     258 * @param   pStat               Pointer to the stat structure for the directory.
     259 */
     260int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat)
     261{
     262    LIBCLOG_ENTER("pszNativePath=%p:{%s} fInUnixTree=%d fLibc=%#x pStat=%p\n", (void *)pszNativePath, pszNativePath, fInUnixTree, fLibc, (void *)pStat);
     263
     264    /*
     265     * Validate input.
     266     */
     267    if (!S_ISDIR(pStat->st_mode))
     268        LIBCLOG_ERROR_RETURN_INT(-ENOTDIR);
     269    if ((fLibc & O_ACCMODE) != O_RDONLY)
     270        LIBCLOG_ERROR_RETURN_INT(-EISDIR);
     271    if ((fLibc & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))
     272        LIBCLOG_ERROR_RETURN_INT(-EEXIST);
     273    if (fLibc & (O_TRUNC | O_APPEND))
     274        LIBCLOG_ERROR_RETURN_INT(-EPERM);
     275    if (fLibc & (O_TRUNC | O_APPEND | O_SIZE))
     276        LIBCLOG_ERROR_RETURN_INT(-EINVAL);
     277
     278    /*
     279     * Directory handles are binary, period.
     280     */
     281    fLibc &= ~O_TEXT;
     282    fLibc |= O_BINARY;
     283
     284    /*
     285     * Setting up a temporary handle; allocate buffer and suchlike.
     286     */
    261287    int             rc = -ENOMEM;
    262288    __LIBC_FHDIR    Tmp;
     
    314340                    pFHDir->fType       = Tmp.fType;
    315341                    pFHDir->uBuf.pv     = Tmp.uBuf.pv;
    316                     pFHDir->uCur.pv     = Tmp.uBuf.pv; /* (this is correct) */
     342                    pFHDir->uCur.pv     = Tmp.uCur.pv;
    317343                    pFHDir->cFiles      = Tmp.cFiles;
    318344                    pFHDir->cbBuf       = Tmp.cbBuf;
    319345
    320346                    FS_RESTORE();
     347                    LIBCLOG_MSG("pFHDir=%p:{.hDir=%#lx, .fType=%d, .cFiles=%ld, .cbBuf=%#x} fh=%d\n",
     348                                (void *)pFHDir, pFHDir->hDir, pFHDir->fType, pFHDir->cFiles, pFHDir->cbBuf, fh);
    321349                    LIBCLOG_RETURN_INT(fh);
    322350                }
     351
     352                /* bailout */
    323353                DosFindClose(Tmp.hDir);
    324354            }
  • trunk/src/emx/src/lib/sys/b_dir.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r2315 r2316  
    3939    /** The directory handle. */
    4040    HDIR            hDir;
     41    /** Set if the path is in the unix tree, else clear.
     42     * This is for fchdir() handling. */
     43    unsigned        fInUnixTree;
    4144    /** The find operation type. */
    4245    unsigned        fType;
     
    6770
    6871
    69 int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fLibc);
     72int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat);
    7073
    7174
  • trunk/src/emx/src/lib/sys/b_fsFileStatFH.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r2315 r2316  
    44 * LIBC SYS Backend - fstat.
    55 *
    6  * Copyright (c) 2003-2004 knut st. osmundsen <bird@innotek.de>
     6 * Copyright (c) 2003-2005 knut st. osmundsen <bird@innotek.de>
    77 *
    88 *
     
    142142             */
    143143            /* Times: FAT might not return create and access time. */
    144             pStat->st_mtime = _sys_p2t(info.fsts4.ftimeLastWrite, info.fsts4.fdateLastWrite);
     144            pStat->st_ctime = pStat->st_mtime = _sys_p2t(info.fsts4.ftimeLastWrite, info.fsts4.fdateLastWrite);
    145145            if (    FTIMEZEROP(info.fsts4.ftimeCreation)
    146146                &&  FDATEZEROP(info.fsts4.fdateCreation))
    147                 pStat->st_ctime = pStat->st_mtime;
    148             else
    149                 pStat->st_ctime = _sys_p2t(info.fsts4.ftimeCreation, info.fsts4.fdateCreation);
     147                pStat->st_birthtime = pStat->st_mtime;
     148            else
     149                pStat->st_birthtime = _sys_p2t(info.fsts4.ftimeCreation, info.fsts4.fdateCreation);
    150150            if (    FTIMEZEROP(info.fsts4.ftimeLastAccess)
    151151                &&  FDATEZEROP(info.fsts4.fdateLastAccess))
     
    237237    //}
    238238
    239     LIBCLOG_MSG("st_dev:     %#x\n",  pStat->st_dev);
    240     LIBCLOG_MSG("st_ino:     %#018llx\n",pStat->st_ino);
    241     LIBCLOG_MSG("st_mode:    0%o\n",  pStat->st_mode);
    242     LIBCLOG_MSG("st_nlink:   %u\n",   pStat->st_nlink);
    243     LIBCLOG_MSG("st_uid:     %u\n",   pStat->st_uid);
    244     LIBCLOG_MSG("st_gid:     %u\n",   pStat->st_gid);
    245     LIBCLOG_MSG("st_rdev:    %#x\n",  pStat->st_rdev);
    246     LIBCLOG_MSG("st_atime:   %d\n",   pStat->st_atime);
    247     LIBCLOG_MSG("st_mtime:   %d\n",   pStat->st_mtime);
    248     LIBCLOG_MSG("st_ctime:   %d\n",   pStat->st_ctime);
    249     LIBCLOG_MSG("st_size:    %lld\n", pStat->st_size);
    250     LIBCLOG_MSG("st_blocks:  %lld\n", pStat->st_blocks);
    251     LIBCLOG_MSG("st_blksize: %u\n",   pStat->st_blksize);
    252     LIBCLOG_MSG("st_attr:    %ld\n",  pStat->st_attr);
     239    LIBCLOG_MSG("%02x - st_dev:       %#x\n",  offsetof(struct stat, st_dev),       pStat->st_dev);
     240    LIBCLOG_MSG("%02x - st_attr:      %#x\n",  offsetof(struct stat, st_attr),      pStat->st_attr);
     241    LIBCLOG_MSG("%02x - st_ino:       %#llx\n",offsetof(struct stat, st_ino),       (long long)pStat->st_ino);
     242    LIBCLOG_MSG("%02x - st_mode:      %#x\n",  offsetof(struct stat, st_mode),      pStat->st_mode);
     243    LIBCLOG_MSG("%02x - st_nlink:     %u\n",   offsetof(struct stat, st_nlink),     pStat->st_nlink);
     244    LIBCLOG_MSG("%02x - st_uid:       %u\n",   offsetof(struct stat, st_uid),       pStat->st_uid);
     245    LIBCLOG_MSG("%02x - st_gid:       %u\n",   offsetof(struct stat, st_gid),       pStat->st_gid);
     246    LIBCLOG_MSG("%02x - st_rdev:      %#x\n",  offsetof(struct stat, st_rdev),      pStat->st_rdev);
     247    LIBCLOG_MSG("%02x - st_lspare:    %#x\n",  offsetof(struct stat, st_lspare),    pStat->st_lspare);
     248    LIBCLOG_MSG("%02x - st_atime:     %d\n",   offsetof(struct stat, st_atime),     pStat->st_atime);
     249    LIBCLOG_MSG("%02x - st_mtime:     %d\n",   offsetof(struct stat, st_mtime),     pStat->st_mtime);
     250    LIBCLOG_MSG("%02x - st_ctime:     %d\n",   offsetof(struct stat, st_ctime),     pStat->st_ctime);
     251    LIBCLOG_MSG("%02x - st_size:      %lld\n", offsetof(struct stat, st_size),      (long long)pStat->st_size);
     252    LIBCLOG_MSG("%02x - st_blocks:    %lld\n", offsetof(struct stat, st_blocks),    (long long)pStat->st_blocks);
     253    LIBCLOG_MSG("%02x - st_blksize:   %u\n",   offsetof(struct stat, st_blksize),   pStat->st_blksize);
     254    LIBCLOG_MSG("%02x - st_flags:     %#x\n",  offsetof(struct stat, st_flags),     pStat->st_flags);
     255    LIBCLOG_MSG("%02x - st_gen:       %#x\n",  offsetof(struct stat, st_gen),       pStat->st_gen);
     256    LIBCLOG_MSG("%02x - st_birthtime: %d\n",   offsetof(struct stat, st_birthtime), pStat->st_birthtime);
    253257    LIBCLOG_RETURN_INT(0);
    254258}
  • trunk/src/emx/src/lib/sys/b_fsNativeFileStat.c

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r2315 r2316  
    44 * LIBC SYS Backend - internal stat.
    55 *
    6  * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     6 * Copyright (c) 2004-2005 knut st. osmundsen <bird@innotek.de>
    77 *
    88 *
     
    128128     */
    129129    /* Times: FAT might not return create and access time. */
    130     pStat->st_mtime = _sys_p2t(info.fsts4.ftimeLastWrite, info.fsts4.fdateLastWrite);
     130    pStat->st_mtime = pStat->st_mtime = _sys_p2t(info.fsts4.ftimeLastWrite, info.fsts4.fdateLastWrite);
    131131    if (   FTIMEZEROP(info.fsts4.ftimeCreation)
    132132        && FDATEZEROP(info.fsts4.fdateCreation))
    133         pStat->st_ctime = pStat->st_mtime;
    134     else
    135         pStat->st_ctime = _sys_p2t(info.fsts4.ftimeCreation, info.fsts4.fdateCreation);
     133        pStat->st_birthtime = pStat->st_mtime;
     134    else
     135        pStat->st_birthtime = _sys_p2t(info.fsts4.ftimeCreation, info.fsts4.fdateCreation);
    136136    if (   FTIMEZEROP(info.fsts4.ftimeLastAccess)
    137137        && FDATEZEROP(info.fsts4.fdateLastAccess))
     
    204204        pStat->st_dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &pStat->st_ino);
    205205
    206     LIBCLOG_MSG("st_dev:     %#x\n",  pStat->st_dev);
    207     LIBCLOG_MSG("st_ino:     %#llx\n",  pStat->st_ino);
    208     LIBCLOG_MSG("st_mode:    %#x\n",  pStat->st_mode);
    209     LIBCLOG_MSG("st_nlink:   %u\n",   pStat->st_nlink);
    210     LIBCLOG_MSG("st_uid:     %u\n",   pStat->st_uid);
    211     LIBCLOG_MSG("st_gid:     %u\n",   pStat->st_gid);
    212     LIBCLOG_MSG("st_rdev:    %#x\n",  pStat->st_rdev);
    213     LIBCLOG_MSG("st_atime:   %d\n",   pStat->st_atime);
    214     LIBCLOG_MSG("st_mtime:   %d\n",   pStat->st_mtime);
    215     LIBCLOG_MSG("st_ctime:   %d\n",   pStat->st_ctime);
    216     LIBCLOG_MSG("st_size:    %lld\n", pStat->st_size);
    217     LIBCLOG_MSG("st_blocks:  %lld\n", pStat->st_blocks);
    218     LIBCLOG_MSG("st_blksize: %u\n",   pStat->st_blksize);
    219     LIBCLOG_MSG("st_attr:    %ld\n",  pStat->st_attr);
     206    LIBCLOG_MSG("%02x - st_dev:       %#x\n",  offsetof(struct stat, st_dev),       pStat->st_dev);
     207    LIBCLOG_MSG("%02x - st_attr:      %#x\n",  offsetof(struct stat, st_attr),      pStat->st_attr);
     208    LIBCLOG_MSG("%02x - st_ino:       %#llx\n",offsetof(struct stat, st_ino),       (long long)pStat->st_ino);
     209    LIBCLOG_MSG("%02x - st_mode:      %#x\n",  offsetof(struct stat, st_mode),      pStat->st_mode);
     210    LIBCLOG_MSG("%02x - st_nlink:     %u\n",   offsetof(struct stat, st_nlink),     pStat->st_nlink);
     211    LIBCLOG_MSG("%02x - st_uid:       %u\n",   offsetof(struct stat, st_uid),       pStat->st_uid);
     212    LIBCLOG_MSG("%02x - st_gid:       %u\n",   offsetof(struct stat, st_gid),       pStat->st_gid);
     213    LIBCLOG_MSG("%02x - st_rdev:      %#x\n",  offsetof(struct stat, st_rdev),      pStat->st_rdev);
     214    LIBCLOG_MSG("%02x - st_lspare:    %#x\n",  offsetof(struct stat, st_lspare),    pStat->st_lspare);
     215    LIBCLOG_MSG("%02x - st_atime:     %d\n",   offsetof(struct stat, st_atime),     pStat->st_atime);
     216    LIBCLOG_MSG("%02x - st_mtime:     %d\n",   offsetof(struct stat, st_mtime),     pStat->st_mtime);
     217    LIBCLOG_MSG("%02x - st_ctime:     %d\n",   offsetof(struct stat, st_ctime),     pStat->st_ctime);
     218    LIBCLOG_MSG("%02x - st_size:      %lld\n", offsetof(struct stat, st_size),      (long long)pStat->st_size);
     219    LIBCLOG_MSG("%02x - st_blocks:    %lld\n", offsetof(struct stat, st_blocks),    (long long)pStat->st_blocks);
     220    LIBCLOG_MSG("%02x - st_blksize:   %u\n",   offsetof(struct stat, st_blksize),   pStat->st_blksize);
     221    LIBCLOG_MSG("%02x - st_flags:     %#x\n",  offsetof(struct stat, st_flags),     pStat->st_flags);
     222    LIBCLOG_MSG("%02x - st_gen:       %#x\n",  offsetof(struct stat, st_gen),       pStat->st_gen);
     223    LIBCLOG_MSG("%02x - st_birthtime: %d\n",   offsetof(struct stat, st_birthtime), pStat->st_birthtime);
    220224    LIBCLOG_RETURN_INT(0);
    221225}
  • trunk/src/emx/src/lib/sys/b_ioFileOpen.c

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r2315 r2316  
    4141#include <share.h>
    4242#include <sys/stat.h>
     43#include <sys/fcntl.h>
    4344#include <emx/umalloc.h>
    4445#include <emx/syscalls.h>
     
    5354
    5455/**
    55  * Opens a file.
     56 * Opens or creates a file.
    5657 *
    5758 * @returns Filehandle to the opened file on success.
    5859 * @returns Negative error code (errno.h) on failure.
    5960 * @param   pszFile     Path to the file.
    60  * @param   fFlags      Open flags.
     61 * @param   fLibc       The LIBC open flags (O_*).
     62 * @param   fShare      The share flags (SH_*).
    6163 * @param   cbInitial   Initial filesize.
    6264 * @param   Mode        The specified permission mask.
    63  * @param   fLibc       LIBC filehandle flags.
    6465 * @param   ppFH        Where to store the LIBC filehandle structure which was created
    6566 *                      for the opened file.
    6667 */
    67 int __libc_Back_ioFileOpen(const char *pszFile, int fFlags, off_t cbInitial, mode_t Mode, unsigned fLibc, PLIBCFH *ppFH)
     68int __libc_Back_ioFileOpen(const char *pszFile, unsigned fLibc, int fShare, off_t cbInitial, mode_t Mode, PLIBCFH *ppFH)
    6869{
    69     LIBCLOG_ENTER("pszFile=%s fFlags=%#x cbInitial=%lld Mode=0%o fLibc=%#x ppFH=%p\n",
    70                   pszFile, fFlags, cbInitial, Mode, fLibc, (void*)ppFH);
    71     FS_VAR();
     70    LIBCLOG_ENTER("pszFile=%p:{%s} fLibc=%#x fShare=%#x cbInitial=%lld Mode=0%o ppFH=%p\n",
     71                  pszFile, pszFile, fLibc, fShare, cbInitial, Mode, (void*)ppFH);
     72
     73    /*
     74     * Validate input.
     75     */
     76    if (    (fLibc & O_ACCMODE) == O_RDONLY
     77        &&  (fLibc & (O_TRUNC | O_CREAT)))
     78        LIBCLOG_ERROR_RETURN_INT(-EINVAL);
    7279
    7380    /*
    7481     * The SH_COMPAT mode is weird and unless supported by the host we map it to SH_DENYNO.
    7582     */
    76     if ((fFlags & SH_MASK) == SH_COMPAT)
    77         fFlags = (fFlags & ~SH_MASK) | SH_DENYNO;
    78 
    79     /*
    80      * Extract the access mode and sharing mode bits.
    81      */
    82     ULONG flOpenMode = fFlags & 0x77;
    83 
    84     /*
    85      * File O_NOINHERIT and O_SYNC.
    86      */
    87     if (fFlags & _SO_NOINHERIT)
     83    fShare &= SH_MASK;
     84    if (fShare == SH_COMPAT)
     85        fShare = SH_DENYNO;
     86
     87    /*
     88     * Correct the initial size.
     89     */
     90    if (!(fLibc & O_SIZE))
     91        cbInitial = 0;
     92
     93    /*
     94     * Calc the open mode mask from the libc flags and the shared flags in flFlags.
     95     * Assumes:     OPEN_ACCESS_READONLY == O_RDONLY
     96     *              OPEN_ACCESS_WRITEONLY == O_WRONLY
     97     *              OPEN_ACCESS_READWRITE == O_RDWR
     98     */
     99    ULONG flOpenMode = fShare & SH_MASK;
     100    flOpenMode |= fLibc & O_ACCMODE;
     101    if (fLibc & O_NOINHERIT)
    88102        flOpenMode |= OPEN_FLAGS_NOINHERIT;
    89     if (fFlags & _SO_SYNC)
     103
     104    if (fLibc & (O_FSYNC | O_SYNC))
    90105        flOpenMode |= OPEN_FLAGS_WRITE_THROUGH;
    91 
    92     /*
    93      * Extract the file flAttribute bits.
    94      */
    95     ULONG flAttr = (fFlags >> 8) & 0xff;
    96     if (__libc_gfsUMask & S_IWUSR)
    97         flAttr |= FILE_READONLY;
     106    if (fLibc & O_DIRECT)
     107        flOpenMode |= OPEN_FLAGS_NO_CACHE;
    98108
    99109    /*
     
    103113
    104114    /*
    105      * Compute `flOpenFlags' depending on `fFlags'.  Note that _SO_CREAT is
    106      * set for O_CREAT.
     115     * Compute the flOpenFlags using fLibc.
    107116     */
    108117    ULONG flOpenFlags;
    109     if (fFlags & _SO_CREAT)
    110     {
    111         if (fFlags & _SO_EXCL)
     118    if (fLibc & O_CREAT)
     119    {
     120        if (fLibc & O_EXCL)
    112121        {
    113122            flOpenFlags = OPEN_ACTION_FAIL_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
    114123            rcOpenFailed = -EEXIST;
    115124        }
    116         else if (fFlags & _SO_TRUNC)
     125        else if (fLibc & O_TRUNC)
    117126            flOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
    118127        else
    119128            flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW;
    120129    }
    121     else if (fFlags & _SO_TRUNC)
    122         flOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
    123130    else
    124         flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
    125 
    126     if (!(fFlags & _SO_SIZE))
    127         cbInitial = 0;
     131    {
     132        fLibc &= ~O_EXCL; /* O_EXCL doesn't make sense without O_CREAT */
     133        if (fLibc & O_TRUNC)
     134            flOpenFlags = OPEN_ACTION_REPLACE_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
     135        else
     136            flOpenFlags = OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_FAIL_IF_NEW;
     137    }
    128138
    129139    /*
    130140     * Resolve the specified file path.
    131141     */
    132     char szNativePath[PATH_MAX + 5];
     142    char szNativePath[PATH_MAX + 4];
     143    int fInUnixTree = 0;
    133144    int rc = __libc_back_fsResolve(pszFile,
    134145                                   (flOpenFlags & OPEN_ACTION_FAIL_IF_NEW
    135                                         ? BACKFS_FLAGS_RESOLVE_FULL       | BACKFS_FLAGS_RESOLVE_DIR_MAYBE
    136                                         : BACKFS_FLAGS_RESOLVE_FULL_MAYBE | BACKFS_FLAGS_RESOLVE_DIR_MAYBE),
     146                                        ? fLibc & O_NOFOLLOW
     147                                            ? BACKFS_FLAGS_RESOLVE_FULL_SYMLINK       | BACKFS_FLAGS_RESOLVE_DIR_MAYBE
     148                                            : BACKFS_FLAGS_RESOLVE_FULL               | BACKFS_FLAGS_RESOLVE_DIR_MAYBE
     149                                        : fLibc & O_NOFOLLOW
     150                                            ? BACKFS_FLAGS_RESOLVE_FULL_SYMLINK_MAYBE | BACKFS_FLAGS_RESOLVE_DIR_MAYBE
     151                                            : BACKFS_FLAGS_RESOLVE_FULL_MAYBE         | BACKFS_FLAGS_RESOLVE_DIR_MAYBE),
    137152                                   &szNativePath[0],
    138                                    NULL);
     153                                   &fInUnixTree);
    139154    if (rc)
    140155        LIBCLOG_ERROR_RETURN_INT(rc);
    141156
    142     /*
    143      * Create Unix attributes for a new file.
    144      */
    145157    dev_t   Dev = 0;
    146158    ino_t   Inode = 0;
    147159    PEAOP2 pEaOp2 = NULL;
    148     if (    (flOpenFlags & (OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS))
    149         &&  !__libc_gfNoUnix)
    150     {
    151         Mode &= ~__libc_gfsUMask;
    152         Mode &= S_IRWXG | S_IRWXO | S_IRWXU | S_ISUID | S_ISGID | S_ISTXT | S_ISVTX;
    153         Mode |= S_IFREG;
    154 
    155         pEaOp2 = alloca(sizeof(EAOP2) + sizeof(__libc_gFsUnixAttribsCreateFEA2List));
    156         struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas = (struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *)(pEaOp2 + 1);
    157         *pFEas = __libc_gFsUnixAttribsCreateFEA2List;
    158         Dev = __libc_back_fsUnixAttribsInit(pFEas, szNativePath, Mode);
    159         Inode = pFEas->u64INO;
    160         pEaOp2->fpGEA2List = NULL;
    161         pEaOp2->fpFEA2List = (PFEA2LIST)pFEas;
    162         pEaOp2->oError     = 0;
    163     }
     160    if (!__libc_gfNoUnix)
     161    {
     162        /*
     163         * Stat the file to see if it's there, and if it is what kind of file it is.
     164         * For some of the file types there are race conditions involved, but we don't care.
     165         */
     166        struct stat st;
     167        rc = __libc_back_fsNativeFileStat(szNativePath, &st);
     168        if (!rc)
     169        {
     170            /*
     171             * If we're truncating a file and no Mode bits are specified, we'll
     172             * use the ones from the original file.
     173             */
     174            /** @todo Check if O_TRUNC and the OS/2 semantics really match.. I don't think O_TRUNC mean replace really. */
     175            Mode &= ALLPERMS;
     176            if (!Mode && (fLibc & (O_CREAT | O_TRUNC)) == O_TRUNC)
     177                Mode = st.st_mode;
     178
     179            /*
     180             * Take action based on the type of file we're facing.
     181             */
     182            switch (st.st_mode & S_IFMT)
     183            {
     184                /*
     185                 * Regular file:    Presently we don't have to do anything special.
     186                 */
     187                case S_IFREG:
     188                    /** @todo handle st_flags. */
     189                    break;
     190
     191                /*
     192                 * Directory:       Open it as a directory.
     193                 */
     194                case S_IFDIR:
     195                {
     196                    rc = __libc_Back_dirOpenNative(szNativePath, fInUnixTree, fLibc, &st);
     197                    if (rc >= 0)
     198                        LIBCLOG_RETURN_INT(rc);
     199                    LIBCLOG_ERROR_RETURN_INT(rc);
     200                    break;
     201                }
     202
     203                /*
     204                 * Named Pipe:      Open / create the named pipe.
     205                 */
     206                case S_IFIFO:
     207                {
     208                    /** @todo implement named pipes. */
     209                    LIBCLOG_ERROR_RETURN_INT(-ENOTSUP);
     210                }
     211
     212                /*
     213                 * Character device or Block device:
     214                 *                  Translate the major/minor to an OS/2 device name and open that.
     215                 */
     216                case S_IFCHR:
     217                case S_IFBLK:
     218                {
     219                    /** @todo assign major & minor numbers and do translations. */
     220                    LIBCLOG_ERROR_RETURN_INT(-ENOTSUP);
     221                }
     222
     223                /*
     224                 * Symbolic link:   These cannot be opened by open().
     225                 */
     226                case S_IFLNK:
     227                    LIBCLOG_ERROR_RETURN_INT(-EMLINK);
     228
     229
     230                /*
     231                 * Local socket:    Open the local socket.
     232                 */
     233                case S_IFSOCK:
     234                {
     235                    /** @todo integrate sockets with libc. */
     236                    LIBCLOG_ERROR_RETURN_INT(-ENOTSUP);
     237                }
     238
     239                /*
     240                 * Stat cannot return anything else.
     241                 */
     242                default:
     243                    __libc_Back_panic(0, NULL, "Invalid file type returned in st_mode=0x%x for '%s'\n", st.st_mode, szNativePath);
     244                    break;
     245            }
     246        }
     247        /* else: didn't find it, just go ahead. */
     248
     249        /*
     250         * Create Unix attributes for a file which is potentially created / replaced.
     251         */
     252        if (flOpenFlags & (OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS))
     253        {
     254            pEaOp2 = alloca(sizeof(EAOP2) + sizeof(__libc_gFsUnixAttribsCreateFEA2List));
     255            struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas = (struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *)(pEaOp2 + 1);
     256            *pFEas = __libc_gFsUnixAttribsCreateFEA2List;
     257            Dev = __libc_back_fsUnixAttribsInit(pFEas, szNativePath, Mode);
     258            Inode = pFEas->u64INO;
     259            pEaOp2->fpGEA2List = NULL;
     260            pEaOp2->fpFEA2List = (PFEA2LIST)pFEas;
     261            pEaOp2->oError     = 0;
     262        }
     263    }
     264
     265    /*
     266     * Normalize the mode mask and calc the file attributes.
     267     */
     268    Mode &= ~__libc_gfsUMask;
     269    Mode &= ACCESSPERMS;
     270    Mode |= S_IFREG;
     271
     272    ULONG flAttr = Mode & S_IWUSR ? FILE_NORMAL : FILE_READONLY;
    164273
    165274    /*
    166275     * Try to open the file.
    167276     */
    168     FS_SAVE_LOAD();
     277    FS_VAR_SAVE_LOAD();
    169278    ULONG   cExpandRetries;
    170279    ULONG   ulAction;
     
    211320    if (!rc)
    212321    {
    213         ULONG   fulType;
    214         ULONG   fulDevFlags;
    215 
    216322        /*
    217323         * Figure the handle type.
    218324         */
     325        ULONG   fulType;
     326        ULONG   fulDevFlags;
    219327        rc = DosQueryHType(hFile, &fulType, &fulDevFlags);
    220         if (!rc)
     328        if (__predict_true(!rc))
    221329        {
    222330            switch (fulType & 0xff)
     
    245353                    break;
    246354                case HANDTYPE_PIPE:
    247                     fLibc |= F_PIPE;
     355                    fLibc |= F_PIPE; /** @todo this is a named pipe! */
    248356                    Dev = makedev('p', 0);
    249357                    __libc_back_fsPathCalcInodeAndDev(szNativePath, &Inode);
     
    256364            __LIBC_PFH pFH;
    257365            rc = __libc_FHAllocate(hFile, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL);
    258             if (!rc)
     366            if (__predict_true(!rc))
    259367            {
    260                 pFH->Inode = Inode;
    261                 pFH->Dev = Dev;
    262                 pFH->pFsInfo = __libc_back_fsInfoObjByDev(Dev);
    263                 pFH->pszNativePath = _hstrdup(szNativePath);
     368                pFH->Inode          = Inode;
     369                pFH->Dev            = Dev;
     370                pFH->pFsInfo        = __libc_back_fsInfoObjByDev(Dev);
     371                pFH->pszNativePath  = _hstrdup(szNativePath);
    264372
    265373                if (ppFH)
    266374                    *ppFH = pFH;
     375                FS_RESTORE();
    267376                LIBCLOG_MSG("pFH=%p hFile=%#lx fLibc=%#x fulType=%#lx ulAction=%lu Dev=%#x Inode=%#llx\n",
    268377                            (void *)pFH, hFile, fLibc, fulType, ulAction, Dev, Inode);
     
    273382            DosClose(hFile);
    274383    }
    275 #if 0  /** @todo Try open directories. */
    276     else if (   rc == ERROR_???
    277              && (fFlags & ...) == ...
    278              )
    279     {
    280         /*
    281          * Try open directory.
    282          */
    283         rc = __libc_Back_dirOpenNative(szNativePath, fLibc);
    284         FS_RESTORE();
    285         LIBCLOG_RETURN_INT(rc);
    286     }
    287 #endif
    288384    FS_RESTORE();
    289385
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.24 to 1.25
    r2315 r2316  
    541541{
    542542    /*
    543      * Preallocated or heap?
     543     * Free and zero resources referenced by the handle.
     544     */
     545    pFH->fFlags     = 0;
     546    pFH->iLookAhead = 0;
     547    pFH->pOps       = NULL;
     548    pFH->Dev        = 0;
     549    pFH->Inode      = 0;
     550    if (pFH->pFsInfo)
     551    {
     552        __libc_back_fsInfoObjRelease(pFH->pFsInfo);
     553        pFH->pFsInfo = NULL;
     554    }
     555    if (pFH->pszNativePath)
     556    {
     557        free(pFH->pszNativePath);
     558        pFH->pszNativePath = NULL;
     559    }
     560
     561    /*
     562     * Free the handle it self.
    544563     */
    545564    if (    pFH >= &gaPreAllocated[0]
    546565        &&  pFH <  &gaPreAllocated[sizeof(gaPreAllocated) / sizeof(gaPreAllocated[0])])
    547     {
    548         pFH->fFlags     = 0;
    549         pFH->iLookAhead = 0;
    550         pFH->pOps       = NULL;
    551566        gcPreAllocatedAvail++;
    552     }
    553567    else
    554568        free(pFH);
  • trunk/src/emx/src/lib/sys/fs.c

    • Property cvs2svn:cvs-rev changed from 1.23 to 1.24
    r2315 r2316  
    13921392                            pStat->st_rdev = u32;
    13931393                        else if (COMPARE_EANAME(__libc_gszGenEA))
    1394                             /* pStat->st_gen  = u32 - not implemented */;
     1394                            pStat->st_gen  = u32;
    13951395                        else if (COMPARE_EANAME(__libc_gszFlagsEA))
    1396                             /* pStat->st_flags = u32 - not implemented */;
     1396                            pStat->st_flags = u32;
    13971397                        else
    13981398                            LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d! u32=%#x (%d)\n", pFea2->szName, pFea2->cbName, u32, u32);
Note: See TracChangeset for help on using the changeset viewer.