Changeset 2323


Ignore:
Timestamp:
Sep 25, 2005, 1:01:36 PM (20 years ago)
Author:
bird
Message:

o Implemented fchdir().
o Implemented inheritance of open directory handles. Unfortunately,

I ran out of size bits for the bundle type, so the SPM bit is no
longer compatible with earlier versions. The consequences
of this are related to inheritance and signaling - so recompile!

Location:
trunk/src/emx
Files:
2 added
13 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.135 to 1.136
    r2322 r2323  
    22
    33TODO: open replace on RAMFS fails with error 32!
     4
     52005-09-25: knut st. osmundsen <bird-gccos2-spam@anduin.net>
     6    - libc:
     7        o Implemented fchdir().
     8        o Implemented inheritance of open directory handles. Unfortunately,
     9          I ran out of size bits for the bundle type, so the SPM bit is no
     10          longer compatible with earlier versions. The consequences
     11          of this are related to inheritance and signaling - so recompile!
    412
    5132005-08-28: knut st. osmundsen <bird-gccos2-spam@anduin.net>
  • trunk/src/emx/include/InnoTekLIBC/backend.h

    • Property cvs2svn:cvs-rev changed from 1.34 to 1.35
    r2322 r2323  
    235235 */
    236236int __libc_Back_fsDirCurrentSet(const char *pszPath, int fDrive);
     237
     238/**
     239 * Changes the current directory of the process.
     240 *
     241 * @returns 0 on success.
     242 * @returns Negative error code (errno.h) on failure.
     243 * @param   fh          The handle of an open directory.
     244 * @param   fDrive      Force a change of the current drive too.
     245 */
     246int __libc_Back_fsDirCurrentSetFH(int fh, int fDrive);
    237247
    238248/**
  • trunk/src/emx/include/InnoTekLIBC/sharedpm.h

    • Property cvs2svn:cvs-rev changed from 1.24 to 1.25
    r2322 r2323  
    3737
    3838/** The name of the shared semaphore protecting the memory. */
    39 #define SPM_MUTEX_NAME          "\\SEM32\\INNOTEKLIBC-V1.1"
     39#define SPM_MUTEX_NAME          "\\SEM32\\INNOTEKLIBC-V1.3"
    4040
    4141/** The name of the shared memory. */
    42 #define SPM_MEMORY_NAME         "\\SHAREMEM\\INNOTEKLIBC-V1.1"
     42#define SPM_MEMORY_NAME         "\\SHAREMEM\\INNOTEKLIBC-V1.3"
    4343
    4444/** The timeout for accessing the shared mem semaphore. */
     
    6060 * The SPM version.
    6161 */
    62 #define SPM_VERSION             0x00010002
     62#define SPM_VERSION             0x00010003
    6363
    6464
     
    163163#define __LIBC_SPM_INH_FHB_TYPE_END         (0)
    164164/** Standard bundle. */
    165 #define __LIBC_SPM_INH_FHB_TYPE_STANDARD    (0x10 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t)))
    166 /** The old standard bundle. */
    167 #define __LIBC_SPM_INH_FHB_TYPE_STANDARD_OLD (0x10 | sizeof(unsigned))
     165#define __LIBC_SPM_INH_FHB_TYPE_STANDARD    (0xe0 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t) + sizeof(unsigned)))
     166/** Directory bundle. */
     167#define __LIBC_SPM_INH_FHB_TYPE_DIRECTORY   (0xc0 | (sizeof(unsigned) + sizeof(ino_t) + sizeof(dev_t) + sizeof(unsigned) + sizeof(unsigned)))
    168168/** Socket bundle, using the BSD 4.4 backend. */
    169 #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_44   (0x20 | (sizeof(unsigned) + sizeof(unsigned short)))
     169#define __LIBC_SPM_INH_FHB_TYPE_SOCKET_44   (0xa0 | (sizeof(unsigned) + sizeof(unsigned short)))
    170170/** Socket bundle, using the BSD 4.3 backend. */
    171 #define __LIBC_SPM_INH_FHB_TYPE_SOCKET_43   (0x30 | (sizeof(unsigned) + sizeof(unsigned short)))
     171#define __LIBC_SPM_INH_FHB_TYPE_SOCKET_43   (0x80 | (sizeof(unsigned) + sizeof(unsigned short)))
     172/*#define __LIBC_SPM_INH_FHB_TYPE_            (0x60 | (sizeof(unsigned) + ))*/
     173/*#define __LIBC_SPM_INH_FHB_TYPE_            (0x40 | (sizeof(unsigned) + ))*/
     174/*#define __LIBC_SPM_INH_FHB_TYPE_            (0x20 | (sizeof(unsigned) + ))*/
     175/*#define __LIBC_SPM_INH_FHB_TYPE_            (0x00 | (sizeof(unsigned) + ))*/
    172176/** Get the per file handle size from the bundle type. */
    173 #define __LIBC_SPM_INH_FHB_SIZE(type)   ((type) & 0x0f)
     177#define __LIBC_SPM_INH_FHB_SIZE(type)   ((type) & 0x1f)
    174178/** @} */
    175179
     
    182186    /** Bundle type. */
    183187    unsigned char   uchType;
    184     /** Cound of handles in this bundle. */
     188    /** Count of handles in this bundle. */
    185189    unsigned char   cHandles;
    186190    /** Start handle number. */
     
    204208    struct
    205209    {
    206         /** The flags */
     210        /** The flags. */
    207211        unsigned            fFlags;
    208212        /** The inode number. */
     
    210214        /** The device number. */
    211215        dev_t               Dev;
     216        /** String table offset of the native path. */
     217        unsigned            offNativePath : 24;
     218        unsigned            u8Reserved : 8;
    212219    } aHandles[1];
    213220} __LIBC_SPMINHFHBSTD;
     
    217224
    218225/**
    219  * SPM standard filehandle inherit bundle
    220  * This is used for OS/2 filehandles which only needs flags
    221  * transfered.
     226 * SPM directory filehandle inherit bundle.
    222227 */
    223228#pragma pack(1)
    224 typedef struct __libc_SPMInhFHOld
     229typedef struct __libc_SPMInhFHDir
    225230{
    226231    /** The common bundle header. */
    227232    __LIBC_SPMINHFHBHDR Hdr;
    228233    /** Array of flags of Hdr.cHandles entries. */
    229     unsigned            afFlags[1];
    230 } __LIBC_SPMINHFHBSTDOLD;
     234    struct
     235    {
     236        /** The flags. */
     237        unsigned            fFlags;
     238        /** The inode number. */
     239        ino_t               Inode;
     240        /** The device number. */
     241        dev_t               Dev;
     242        /** String table offset of the native path. */
     243        unsigned            offNativePath : 24;
     244        /** Set if this path is in the unix tree. */
     245        unsigned            fInUnixTree : 1;
     246        unsigned            u7Reserved : 7;
     247        /** The current position. */
     248        unsigned            uCurEntry;
     249    } aHandles[1];
     250} __LIBC_SPMINHFHBDIR;
    231251#pragma pack()
    232 /** Pointer to SPM standard filehandle inherit bundle. */
    233 typedef __LIBC_SPMINHFHBSTDOLD *__LIBC_PSPMINHFHBSTDOLD;
     252/** Pointer to SPM directory filehandle inherit bundle. */
     253typedef __LIBC_SPMINHFHBDIR *__LIBC_PSPMINHFHBDIR;
    234254
    235255/**
     
    303323    /** Pointer to the signal part. If NULL default values are assumed. */
    304324    __LIBC_PSPMINHSIG       pSig;
    305 
     325    /** Pointer to strings (filenames++).
     326     * All the strings are NULL terminated and referenced by offset. */
     327    char                   *pszStrings;
    306328} __LIBC_SPMINHERIT;
    307329/** Pointer to inherit data. */
  • trunk/src/emx/include/fts.h

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2322 r2323  
    4949        dev_t fts_dev;                  /* starting device # */
    5050        char *fts_path;                 /* path for this descent */
    51 #ifdef __EMX__
    52         char *fts_rdir;                 /* path of root */
    53 #else
    5451        int fts_rfd;                    /* fd for root */
    55 #endif
    5652        int fts_pathlen;                /* sizeof(path) */
    5753        int fts_nitems;                 /* elements in the sort array */
     
    6662#define FTS_SEEDOT      0x020           /* return dot and dot-dot */
    6763#define FTS_XDEV        0x040           /* don't cross devices */
    68 #ifndef __EMX__
    6964#define FTS_WHITEOUT    0x080           /* return whiteout information */
    70 #endif
    7165#define FTS_OPTIONMASK  0x0ff           /* valid user option mask */
    7266
     
    8680        char *fts_path;                 /* root path */
    8781        int fts_errno;                  /* errno for this node */
    88 #ifndef __EMX__
    8982        int fts_symfd;                  /* fd for symlink */
    90 #endif
    9183        u_short fts_pathlen;            /* strlen(fts_path) */
    9284        u_short fts_namelen;            /* strlen(fts_name) */
     
    113105#define FTS_SL          12              /* symbolic link */
    114106#define FTS_SLNONE      13              /* symbolic link without target */
    115 #ifndef __EMX__
    116107#define FTS_W           14              /* whiteout object */
    117 #endif
    118108        u_short fts_info;               /* user flags for FTSENT structure */
    119109
    120110#define FTS_DONTCHDIR    0x01           /* don't chdir .. to the parent */
    121111#define FTS_SYMFOLLOW    0x02           /* followed a symlink to get here */
    122 #ifndef __EMX__
    123112#define FTS_ISW          0x04           /* this is a whiteout object */
    124 #endif
    125113        u_short fts_flags;              /* private flags for FTSENT structure */
    126114
  • trunk/src/emx/include/unistd.h

    • Property cvs2svn:cvs-rev changed from 1.35 to 1.36
    r2322 r2323  
    441441/** @todo char  *ctermid(char *); */            /* XXX ??? */
    442442void     encrypt(char *, int);                  /* bird: SuS say it returns void, and so does our implementation */
    443 /** @todo int    fchdir(int); */
     443int      fchdir(int);
    444444/* tcpip: long   gethostid(void); */
    445445pid_t    getpgid(pid_t _pid);       /* bird: SuS say pid_r return. */
  • trunk/src/emx/src/lib/bsd/gen/fts.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2322 r2323  
    4040#endif
    4141#ifndef __EMX__
    42 # define HAVE_FCHDIR
    4342# define IS_SLASH(ch)   ( (ch) == '/' )
    4443#else
     
    225224         * descriptor we run anyway, just more slowly.
    226225         */
    227 #ifdef HAVE_FCHDIR
    228226        if (!ISSET(FTS_NOCHDIR) && (sp->fts_rfd = _open(".", O_RDONLY, 0)) < 0)
    229 #else
    230         if (!ISSET(FTS_NOCHDIR) && (sp->fts_rdir = getcwd(NULL, 0)) != NULL)
    231 #endif
    232             SET(FTS_NOCHDIR);
     227                SET(FTS_NOCHDIR);
    233228
    234229        return (sp);
     
    319314        /* Return to original directory, save errno if necessary. */
    320315        if (!ISSET(FTS_NOCHDIR)) {
    321 #ifdef HAVE_FCHDIR
    322316                saved_errno = fchdir(sp->fts_rfd) ? errno : 0;
    323317                (void)_close(sp->fts_rfd);
    324 #else
    325                 saved_errno = chdir(sp->fts_rdir) ? errno : 0;
    326                 free(sp->fts_rdir); sp->fts_rdir = NULL;
    327 #endif
    328318
    329319                /* Set errno and return. */
     
    340330        return (0);
    341331}
    342 
    343332
    344333/*
     
    386375                p->fts_info = fts_stat(sp, p, 1);
    387376                if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
    388 #ifdef HAVE_FCHDIR
    389377                        if ((p->fts_symfd = _open(".", O_RDONLY, 0)) < 0) {
    390378                                p->fts_errno = errno;
     
    392380                        } else
    393381                                p->fts_flags |= FTS_SYMFOLLOW;
    394 #endif
    395382                }
    396383                return (p);
     
    402389                if (instr == FTS_SKIP ||
    403390                    (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
    404 #ifdef HAVE_FCHDIR
    405391                        if (p->fts_flags & FTS_SYMFOLLOW)
    406392                                (void)_close(p->fts_symfd);
    407 #endif
    408393                        if (sp->fts_child) {
    409394                                fts_lfree(sp->fts_child);
     
    462447                 */
    463448                if (p->fts_level == FTS_ROOTLEVEL) {
    464 #ifdef HAVE_FCHDIR
    465449                        if (FCHDIR(sp, sp->fts_rfd)) {
    466 #else
    467                         if (FCHDIR(sp, sp->fts_rdir)) {
    468 #endif
    469450                                SET(FTS_STOP);
    470451                                return (NULL);
     
    484465                        p->fts_info = fts_stat(sp, p, 1);
    485466                        if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
    486 #ifdef HAVE_FCHDIR
    487467                                if ((p->fts_symfd =
    488468                                    _open(".", O_RDONLY, 0)) < 0) {
     
    491471                                } else
    492472                                        p->fts_flags |= FTS_SYMFOLLOW;
    493 #endif
    494473                        }
    495474                        p->fts_instr = FTS_NOINSTR;
     
    525504         */
    526505        if (p->fts_level == FTS_ROOTLEVEL) {
    527 #ifdef HAVE_FCHDIR
    528506                if (FCHDIR(sp, sp->fts_rfd)) {
    529 #else
    530                 if (FCHDIR(sp, sp->fts_rdir)) {
    531 #endif
    532507                        SET(FTS_STOP);
    533508                        return (NULL);
    534509                }
    535 #ifdef HAVE_FCHDIR
    536510        } else if (p->fts_flags & FTS_SYMFOLLOW) {
    537511                if (FCHDIR(sp, p->fts_symfd)) {
     
    543517                }
    544518                (void)_close(p->fts_symfd);
    545 #else
    546         (void)saved_errno;
    547 #endif
    548519        } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
    549520            fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
     
    583554{
    584555        FTSENT *p;
    585 #ifdef HAVE_FCHDIR
    586556        int fd;
    587 #else
    588         char *pszRoot;
    589         int rc;
    590 #endif
     557
    591558        if (instr != 0 && instr != FTS_NAMEONLY) {
    592559                errno = EINVAL;
     
    640607                return (sp->fts_child = fts_build(sp, instr));
    641608
    642 #ifdef HAVE_FCHDIR
    643609        if ((fd = _open(".", O_RDONLY, 0)) < 0)
    644 #else
    645         if ((pszRoot = getcwd(NULL, 0)) == NULL)
    646 #endif
    647610                return (NULL);
    648611        sp->fts_child = fts_build(sp, instr);
    649 #ifdef HAVE_FCHDIR
    650612        if (fchdir(fd))
    651613                return (NULL);
    652614        (void)_close(fd);
    653 #else
    654         rc = chdir(pszRoot);
    655         free(pszRoot);
    656         if (rc)
    657             return NULL;
    658 #endif
    659615        return (sp->fts_child);
    660616}
     
    725681         * If being called from fts_read, set the fts_info field.
    726682         */
    727 #ifdef FTS_WHITEOUT
     683#if defined(FTS_WHITEOUT) && !defined(__EMX__)
    728684        if (ISSET(FTS_WHITEOUT))
    729685                oflag = DTF_NODUP | DTF_REWIND;
     
    784740        cderrno = 0;
    785741        if (nlinks || type == BREAD) {
    786 #ifdef HAVE_FCHDIR
    787742                if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
    788 #else
    789                 if (fts_safe_changedir(sp, cur, dirfd(dirp), cur->fts_accpath)) {
    790 #endif
    791743                        if (nlinks && type == BREAD)
    792744                                cur->fts_errno = errno;
     
    953905        if (descend && (type == BCHILD || !nitems) &&
    954906            (cur->fts_level == FTS_ROOTLEVEL ?
    955 #ifdef HAVE_FCHDIR
    956907            FCHDIR(sp, sp->fts_rfd) :
    957 #else
    958             FCHDIR(sp, sp->fts_rdir) :
    959 #endif
    960908            fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
    961909                cur->fts_info = FTS_ERR;
     
    12591207        if (ISSET(FTS_NOCHDIR))
    12601208                return (0);
    1261 #ifdef HAVE_FCHDIR
    12621209        if (fd < 0 && (newfd = _open(path, O_RDONLY, 0)) < 0)
    12631210                return (-1);
    12641211        if (_fstat(newfd, &sb)) {
    1265 #else
    1266         (void)newfd;
    1267         if (_stat(path, &sb)) {
    1268 #endif
    12691212                ret = -1;
    12701213                goto bail;
     
    12751218                goto bail;
    12761219        }
    1277 #ifdef HAVE_FCHDIR
    12781220        ret = fchdir(newfd);
    1279 #else
    1280         ret = chdir(path);
    1281 #endif
    12821221bail:
    1283 #ifdef HAVE_FCHDIR
    12841222        oerrno = errno;
    12851223        if (fd < 0)
    12861224                (void)_close(newfd);
    12871225        errno = oerrno;
    1288 #else
    1289         (void)oerrno;
    1290 #endif
    12911226        return (ret);
    12921227}
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.138 to 1.139
    r2322 r2323  
    19481948    "__hstrdup" @1946
    19491949    "___libc_Back_dirOpenNative" @1947
     1950    "___libc_Back_fsDirCurrentSetFH" @1948
     1951    "__std_fchdir" @1949
  • trunk/src/emx/src/lib/sys/__spawnve.c

    • Property cvs2svn:cvs-rev changed from 1.21 to 1.22
    r2322 r2323  
    4242    LIBCLOG_ENTER("\n");
    4343    __LIBC_PSPMINHERIT      pRet = NULL;
     44    size_t                  cbStrings = 0;
     45    char                   *pszStrings = NULL;
    4446
    4547    /*
     
    4850    size_t                  cbFH;
    4951    __LIBC_PSPMINHFHBHDR    pFH;
    50     pFH = __libc_fhInheritPack(&cbFH);
     52    pFH = __libc_fhInheritPack(&cbFH, &pszStrings, &cbStrings);
    5153    if (pFH)
    5254    {
     
    6870                 * Allocate shared memory.
    6971                 */
    70                 size_t  cb = sizeof(__LIBC_SPMINHERIT) + ((cbFH + 3) & ~3) + ((cbFS + 3) & ~3) + ((cbSig + 3) & ~3);
     72                #define ALIGNIT(cb) (((cb) + 3) & ~3)
     73                size_t  cb = sizeof(__LIBC_SPMINHERIT) + ALIGNIT(cbFH) + ALIGNIT(cbFS) + ALIGNIT(cbSig) + ALIGNIT(cbStrings);
    7174                pRet = __libc_spmAlloc(cb);
    7275                if (pRet)
    7376                {
     77                    pRet->cb = sizeof(*pRet);
     78                    char *p = (char *)(pRet + 1);
     79
    7480                    /* fh */
    75                     pRet->cb = sizeof(*pRet);
    76                     pRet->pFHBundles = (__LIBC_PSPMINHFHBHDR)(pRet + 1);
     81                    pRet->pFHBundles = (__LIBC_PSPMINHFHBHDR)p;
     82                    p += ALIGNIT(cbFH);
    7783                    memcpy(pRet->pFHBundles, pFH, cbFH);
    7884                    free(pFH);
     
    8187                    if (pFS)
    8288                    {
    83                         pRet->pFS = (__LIBC_PSPMINHFS)((char *)pRet->pFHBundles + ((cbFH + 3) & ~3));
     89                        pRet->pFS = (__LIBC_PSPMINHFS)p;
     90                        p += ALIGNIT(cbFS);
    8491                        memcpy(pRet->pFS, pFS, cbFS);
    8592                        free(pFS);
     
    9198                    if (pSig)
    9299                    {
    93                         pRet->pSig = (__LIBC_PSPMINHSIG)((char *)pRet->pFHBundles + ((cbFH + 3) & ~3) + ((cbFS + 3) & ~3));
     100                        pRet->pSig = (__LIBC_PSPMINHSIG)p;
     101                        p += ALIGNIT(cbSig);
    94102                        memcpy(pRet->pSig, pSig, cbSig);
    95103                        free(pSig);
    96104                    }
     105                    else
     106                        pRet->pSig = NULL;
     107
     108                    /* strings */
     109                    if (pszStrings)
     110                    {
     111                        pRet->pszStrings = p;
     112                        /*p += ALIGNIT(cbStrings);*/
     113                        memcpy(pRet->pszStrings, pszStrings, cbStrings);
     114                        free(pszStrings);
     115                    }
     116                    else
     117                        pRet->pszStrings = NULL;
    97118
    98119                    /* done! */
     
    108129        free(pFH);
    109130    }
     131    free(pszStrings);
    110132
    111133    LIBCLOG_RETURN_P(pRet);
  • trunk/src/emx/src/lib/sys/b_dir.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2322 r2323  
    3939#include <limits.h>
    4040#include <sys/fcntl.h>
     41#include <sys/dirent.h>
    4142#include <emx/umalloc.h>
    4243#include <emx/io.h>
     
    5455static int dirFileControl(__LIBC_PFH pFH, int fh, int iRequest, int iArg, int *prc);
    5556static int dirIOControl(__LIBC_PFH pFH, int fh, int iIOControl, int iArg, int *prc);
     57static int dirSeek(__LIBC_PFH pFH, int fh, off_t off, int iMethod, off_t *poffNew);
    5658static int dirSelect(int cFHs, struct fd_set *pRead, struct fd_set *pWrite, struct fd_set *pExcept, struct timeval *tv, int *prc);
    5759static int dirForkChild(__LIBC_PFH pFH, int fh, __LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation);
     60static int dirOpen(const char *pszNativePath, unsigned fLibc, int *pfh, __LIBC_PFHDIR *ppFHDir);
    5861
    5962
     
    7376    dirFileControl,
    7477    dirIOControl,
     78    //dirSeek,
    7579    dirSelect,
    7680    NULL,
     
    200204    LIBCLOG_ENTER("pFH=%p fh=%d iIOControl=%d iArg=%d prc=%p\n", (void *)pFH, fh, iIOControl, iArg, (void *)prc);
    201205    LIBCLOG_ERROR_RETURN_INT(-EOPNOTSUPP);
     206}
     207
     208
     209/** Seek to a new position in the 'file'.
     210 *
     211 * @returns 0 on success.
     212 * @returns OS/2 error code or negated errno on failure.
     213 * @param   pFH         Pointer to the handle structure to operate on.
     214 * @param   fh          It's associated filehandle.
     215 * @param   off         The offset to seek. The meaning depends on SEEK_.
     216 * @param   iMethod     The seek method, any of the SEEK_* macros.
     217 * @param   poffNew     Where to store the new file offset.
     218 */
     219static int dirSeek(__LIBC_PFH pFH, int fh, off_t off, int iMethod, off_t *poffNew)
     220{
     221    /** @todo Implement reading and seeking. */
     222    return -1;
    202223}
    203224
     
    238259static int dirForkChild(__LIBC_PFH pFH, int fh, __LIBC_PFORKHANDLE pForkHandle, __LIBC_FORKOP enmOperation)
    239260{
    240     /** @todo reopen the handle, same as for duplicate! */
     261    switch (enmOperation)
     262    {
     263        case __LIBC_FORK_OP_FORK_CHILD:
     264        {
     265            __LIBC_PFHDIR pFHDir = (__LIBC_PFHDIR)pFH;
     266
     267            /* make pattern */
     268            char szNativePath[PATH_MAX + 5];
     269            size_t cch = strlen(pFH->pszNativePath);
     270            memcpy(szNativePath, pFH->pszNativePath, cch);
     271            szNativePath[cch] = '/';
     272            szNativePath[cch + 1] = '*';
     273            szNativePath[cch + 2] = '\0';
     274
     275            pFHDir->hDir   = HDIR_CREATE;
     276            pFHDir->cFiles = pFHDir->cbBuf / 40;
     277#if OFF_MAX > LONG_MAX
     278            if (pFHDir->fType == FIL_QUERYEASIZEL)  /* the L version is buggy!! Make sure there is enough space. */
     279                pFHDir->cFiles = pFHDir->cbBuf / sizeof(FILEFINDBUF4L);
     280#endif
     281            pFHDir->uCur.pv = pFHDir->uBuf.pv;
     282            bzero(pFHDir->uBuf.pv, pFHDir->cbBuf);
     283
     284            int rc = DosFindFirst((PCSZ)szNativePath,
     285                                  &pFHDir->hDir,
     286                                  FILE_NORMAL | FILE_READONLY | FILE_HIDDEN | FILE_SYSTEM | FILE_DIRECTORY | FILE_ARCHIVED,
     287                                  pFHDir->uBuf.pv,
     288                                  pFHDir->cbBuf,
     289                                  &pFHDir->cFiles,
     290                                  pFHDir->fType);
     291            if (rc)
     292            {
     293                pFHDir->hDir = HDIR_CREATE;
     294                return rc;
     295            }
     296            if (pFHDir->uCurEntry)
     297            {
     298                unsigned uCurEntry = pFHDir->uCurEntry;
     299                pFHDir->uCurEntry = 0;
     300                dirSeek(&pFHDir->Core, fh, uCurEntry * sizeof(struct dirent), SEEK_SET, NULL);
     301            }
     302            break;
     303        }
     304
     305        default:
     306            break;
     307    }
    241308    return 0;
    242309}
     
    248315
    249316/**
    250  * Opens a directory specified by a path already made native.
    251  *
    252  * @returns File handle (>=0) on success.
    253  * @returns negative error code (errno.h) on failure.
     317 * Opens a directory.
     318 * Internal worker used by the other open/inherit calls.
     319 *
     320 * @returns 0 on success.
     321 * @returns Negated errno on failure.
    254322 * @param   pszNativePath       Pointer to the native path. The buffer must be on stack
    255323 *                              and must have space for 4 extra bytes!
    256  * @param   fInUnixTree         Set if the native path is in the unix tree.
    257  * @param   fLibc               The LIBC open() flags.
    258  * @param   pStat               Pointer to the stat structure for the directory.
    259  */
    260 int __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;
     324 * @param   pfh                 On input the requested filehandle. -1 means any.
     325 *                              On output (success only) the allocated file handle.
     326 * @param   ppFHDir             Where to store the handle structure pointer on success.
     327 */
     328static int dirOpen(const char *pszNativePath, unsigned fLibc, int *pfh, __LIBC_PFHDIR *ppFHDir)
     329{
     330    LIBC_ASSERT((fLibc & (O_BINARY | __LIBC_FH_TYPEMASK)) == (O_BINARY | F_DIR));
    283331
    284332    /*
     
    327375            if (!rc)
    328376            {
    329                 int fh;
    330377                __LIBC_PFH pFH;
    331                 rc = __libc_FHAllocate(-1, fLibc, sizeof(__LIBC_FHDIR), &gDirOps, &pFH, &fh);
     378                rc = __libc_FHAllocate(*pfh, fLibc, sizeof(__LIBC_FHDIR), &gDirOps, &pFH, pfh);
    332379                if (!rc)
    333380                {
    334                     pFH->Dev            = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &pFH->Inode);
    335381                    pFH->pFsInfo        = __libc_back_fsInfoObjByDev(pFH->Dev);
    336382                    pFH->pszNativePath  = Tmp.Core.pszNativePath;
     
    343389                    pFHDir->cFiles      = Tmp.cFiles;
    344390                    pFHDir->cbBuf       = Tmp.cbBuf;
    345 
     391                    pFHDir->uCurEntry   = 0;
     392
     393                    *ppFHDir = pFHDir;
    346394                    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);
    349                     LIBCLOG_RETURN_INT(fh);
     395                    return 0;
    350396                }
    351397
     
    361407    if (rc > 0)
    362408        rc = -__libc_native2errno(rc);
     409    return rc;
     410}
     411
     412
     413/**
     414 * Re-opens a directory we inherited from our parent process.
     415 *
     416 * @returns 0 on success.
     417 * @returns Negated error code (errno.h) on failure.
     418 * @param   fh                  The file handle this directory shall have.
     419 * @param   pszNativePath       Pointer to the native path.
     420 * @param   fInUnixTree         Flag indicating whether the open() call was referencing a path in the unix tree or not.
     421 * @param   fFlags              Filehandle flags.
     422 * @param   Inode               The inode number of the directory.
     423 * @param   Dev                 The device number of the device with the directory.
     424 * @param   uCurEntry           The current position.
     425 */
     426int __libc_back_dirInherit(int fh, const char *pszNativePath, unsigned fInUnixTree, unsigned fFlags, ino_t Inode, dev_t Dev, unsigned uCurEntry)
     427{
     428    LIBCLOG_ENTER("fh=%d pszNativePath=%p:{%s} fInUnixTree=%d fFlags=%#x Inode=%#llx Dev=%#x uCurEntry=%d\n",
     429                  fh, (void *)pszNativePath, pszNativePath, fInUnixTree, fFlags, (unsigned long long)Inode, Dev, uCurEntry);
     430
     431    /*
     432     * Open the directory.
     433     */
     434    __LIBC_PFHDIR pFHDir;
     435    char szNativePath[PATH_MAX + 5];
     436    strcpy(szNativePath, pszNativePath);
     437    int rc = dirOpen(szNativePath, fFlags, &fh, &pFHDir);
     438    if (!rc)
     439    {
     440        pFHDir->Core.Inode = Inode;
     441        pFHDir->Core.Dev   = Dev;
     442
     443        /*
     444         * Seek to the current positions.
     445         */
     446        if (uCurEntry)
     447            dirSeek(&pFHDir->Core, fh, uCurEntry * sizeof(struct dirent), SEEK_SET, NULL);
     448
     449        LIBCLOG_MSG("pFHDir=%p:{.hDir=%#lx, .fType=%d, .cFiles=%ld, .cbBuf=%#x, .uCurEntry=%d} fh=%d\n",
     450                    (void *)pFHDir, pFHDir->hDir, pFHDir->fType, pFHDir->cFiles, pFHDir->cbBuf, pFHDir->uCurEntry, fh);
     451        LIBCLOG_RETURN_INT(0);
     452    }
    363453    LIBCLOG_ERROR_RETURN_INT(rc);
    364 }
    365 
     454
     455}
     456
     457
     458/**
     459 * Opens a directory specified by a path already made native.
     460 *
     461 * @returns File handle (>=0) on success.
     462 * @returns negative error code (errno.h) on failure.
     463 * @param   pszNativePath       Pointer to the native path. The buffer must be on stack
     464 *                              and must have space for 4 extra bytes!
     465 * @param   fInUnixTree         Set if the native path is in the unix tree.
     466 * @param   fLibc               The LIBC open() flags.
     467 * @param   pStat               Pointer to the stat structure for the directory.
     468 */
     469int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat)
     470{
     471    LIBCLOG_ENTER("pszNativePath=%p:{%s} fInUnixTree=%d fLibc=%#x pStat=%p\n", (void *)pszNativePath, pszNativePath, fInUnixTree, fLibc, (void *)pStat);
     472
     473    /*
     474     * Validate input.
     475     */
     476    if (!S_ISDIR(pStat->st_mode))
     477        LIBCLOG_ERROR_RETURN_INT(-ENOTDIR);
     478    if ((fLibc & O_ACCMODE) != O_RDONLY)
     479        LIBCLOG_ERROR_RETURN_INT(-EISDIR);
     480    if ((fLibc & (O_EXCL | O_CREAT)) == (O_EXCL | O_CREAT))
     481        LIBCLOG_ERROR_RETURN_INT(-EEXIST);
     482    if (fLibc & (O_TRUNC | O_APPEND))
     483        LIBCLOG_ERROR_RETURN_INT(-EPERM);
     484    if (fLibc & (O_TRUNC | O_APPEND | O_SIZE))
     485        LIBCLOG_ERROR_RETURN_INT(-EINVAL);
     486
     487    /*
     488     * Directory handles are binary, period.
     489     */
     490    fLibc &= ~(O_TEXT | __LIBC_FH_TYPEMASK | __LIBC_FH_FDFLAGS_MASK);
     491    fLibc |= O_BINARY | F_DIR;
     492
     493    /*
     494     * Open the directory.
     495     */
     496    int fh = -1;
     497    __LIBC_PFHDIR pFHDir;
     498    int rc = dirOpen(pszNativePath, fLibc, &fh, &pFHDir);
     499    if (!rc)
     500    {
     501        pFHDir->Core.Inode = pStat->st_ino;
     502        pFHDir->Core.Dev   = pStat->st_dev;
     503
     504        LIBCLOG_MSG("pFHDir=%p:{.hDir=%#lx, .fType=%d, .cFiles=%ld, .cbBuf=%#x} fh=%d\n",
     505                    (void *)pFHDir, pFHDir->hDir, pFHDir->fType, pFHDir->cFiles, pFHDir->cbBuf, fh);
     506        LIBCLOG_RETURN_INT(fh);
     507    }
     508    LIBCLOG_ERROR_RETURN_INT(rc);
     509}
     510
  • trunk/src/emx/src/lib/sys/b_dir.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2322 r2323  
    6565    /** The size of the find buffer. */
    6666    unsigned        cbBuf;
     67    /** Current entry number (total, for seeking). */
     68    unsigned        uCurEntry;
    6769} __LIBC_FHDIR;
    6870/** Pointer to the a directory handle. */
     
    7173
    7274int __libc_Back_dirOpenNative(char *pszNativePath, unsigned fInUnixTree, unsigned fLibc, struct stat *pStat);
     75int __libc_back_dirInherit(int fh, const char *pszNativePath, unsigned fInUnixTree, unsigned fFlags,
     76                           ino_t Inode, dev_t Dev, unsigned uCurEntry);
    7377
    7478
  • trunk/src/emx/src/lib/sys/b_fsDirCurrentSet.c

    • Property cvs2svn:cvs-rev changed from 1.5 to 1.6
    r2322 r2323  
    4949{
    5050    LIBCLOG_ENTER("pszPath=%p:{%s} fDrive=%d\n", (void *)pszPath, pszPath, fDrive);
    51     FS_VAR();
    5251
    5352    /*
     
    7372         * when in the unix compartement or when fDrive is set.
    7473         */
    75         FS_SAVE_LOAD();
     74        FS_VAR_SAVE_LOAD();
    7675        int rc = DosSetCurrentDir((PCSZ)&szNativePath[0]);
    77         FS_RESTORE();
    7876        if (!rc)
    7977        {
     
    8482                    ULONG ulDrive = szNativePath[0] - (szNativePath[0] >= 'A' && szNativePath[0] <= 'Z' ? 'A' - 1 : 'a' -1);
    8583                    rc = DosSetDefaultDisk(ulDrive);
    86                     LIBC_ASSERTM(!rc, "DosSetDefaultDisk(%ld) -> %d. unix drive is %c\n", ulDrive, rc, szNativePath[0]);
     84                    LIBC_ASSERTM(!rc, "DosSetDefaultDisk(%ld) -> %d. drive is %c\n", ulDrive, rc, szNativePath[0]);
    8785                    rc = 0;             /* ignore this kind of errors. */
    8886                    __libc_gfInUnixTree = fInUnixTree;
     
    9290        else
    9391            rc = -__libc_native2errno(rc);
     92        FS_RESTORE();
    9493    }
    9594
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.25 to 1.26
    r2322 r2323  
    5353#include "syscalls.h"
    5454#include "b_fs.h"
    55 
     55#include "b_dir.h"
     56
     57#include <InnoTekLIBC/backend.h>
    5658#define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_INITTERM
    5759#include <InnoTekLIBC/logstrict.h>
     
    170172            __LIBC_PSPMINHFHBHDR    pHdr;
    171173            __LIBC_PSPMINHFHBSTD    pStds;
    172             __LIBC_PSPMINHFHBSTDOLD pStdsOld;
     174            __LIBC_PSPMINHFHBDIR    pDirs;
    173175            __LIBC_PSPMINHFHBSOCK   pSockets;
    174176            uintptr_t               u;
     
    189191                        if (fhAllocate(iFH, u.pStds->aHandles[i].fFlags, sizeof(__LIBC_FH), NULL, &pFH, NULL, 0))
    190192                        {
    191                             LIBC_ASSERTM_FAILED("Failed to allocated inherited file handle! iFH=%d\n", iFH);
     193                            __libc_Back_panic(0, NULL, "Failed to allocated inherited file handle! iFH=%d\n", iFH);
    192194                            __libc_spmInheritRelease();
    193195                            return -1;
     
    196198                        pFH->Dev = u.pStds->aHandles[i].Dev;
    197199                        pFH->pFsInfo = __libc_back_fsInfoObjByDev(pFH->Dev);
    198                         pFH->pszNativePath = NULL;
     200                        pFH->pszNativePath = u.pStds->aHandles[i].offNativePath
     201                            ? _hstrdup(pInherit->pszStrings + u.pStds->aHandles[i].offNativePath) : NULL;
    199202                    }
    200203                    u.pv = &u.pStds->aHandles[c];
    201204                    break;
    202205
    203                 case __LIBC_SPM_INH_FHB_TYPE_STANDARD_OLD:
     206                case __LIBC_SPM_INH_FHB_TYPE_DIRECTORY:
    204207                    for (i = 0; i < c; i++)
    205208                    {
    206                         if (fhAllocate(iFH, u.pStdsOld->afFlags[i], sizeof(__LIBC_FH), NULL, NULL, NULL, 0))
     209                        const char *pszPath = u.pDirs->aHandles[i].offNativePath ? pInherit->pszStrings + u.pDirs->aHandles[i].offNativePath : NULL;
     210                        int rc = __libc_back_dirInherit(iFH, pszPath, u.pDirs->aHandles[i].fInUnixTree,
     211                                                        u.pDirs->aHandles[i].fFlags, u.pDirs->aHandles[i].Inode,
     212                                                        u.pDirs->aHandles[i].Dev, u.pDirs->aHandles[i].uCurEntry);
     213                        if (rc)
    207214                        {
    208                             LIBC_ASSERTM_FAILED("Failed to allocated inherited file handle! iFH=%d\n", iFH);
     215                            __libc_Back_panic(0, NULL, "Failed to allocated inherited directory handle! rc=%d iFH=%d path=%s\n", rc, iFH, pszPath);
    209216                            __libc_spmInheritRelease();
    210217                            return -1;
    211218                        }
    212219                    }
    213                     u.pv = &u.pStdsOld->afFlags[c];
     220                    u.pv = &u.pDirs->aHandles[c];
    214221                    break;
    215222
     
    220227                        if (rc)
    221228                        {
    222                             LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.4) handle! rc=%d iFH=%d iSocket=%d\n",
    223                                                 rc, iFH, u.pSockets->aHandles[i].usSocket);
     229                            __libc_Back_panic(0, NULL, "Failed to allocated inherited socket (4.4) handle! rc=%d iFH=%d iSocket=%d\n",
     230                                              rc, iFH, u.pSockets->aHandles[i].usSocket);
    224231                            __libc_spmInheritRelease();
    225232                            return -1;
     
    235242                        if (rc)
    236243                        {
    237                             LIBC_ASSERTM_FAILED("Failed to allocated inherited socket (4.3) handle! rc=%d iFH=%d iSocket=%d\n",
    238                                                 rc, iFH, u.pSockets->aHandles[i].usSocket);
     244                            __libc_Back_panic(0, NULL, "Failed to allocated inherited socket (4.3) handle! rc=%d iFH=%d iSocket=%d\n",
     245                                              rc, iFH, u.pSockets->aHandles[i].usSocket);
    239246                            __libc_spmInheritRelease();
    240247                            return -1;
     
    295302
    296303/**
     304 * Adds a string to the string table.
     305 */
     306static inline unsigned fhAddString(const char *pszString, char **ppszStrings, size_t *pcbAlloc, size_t *pcb)
     307{
     308    if (!pszString)
     309        return 0;
     310
     311    size_t      cb  = strlen(pszString) + 1;
     312    unsigned    off = *pcb;
     313
     314    /* need more space? */
     315    if (cb + off > *pcbAlloc)
     316    {
     317        size_t cbAlloc = (cb + off + !off + 0xfff) & ~0xfff;
     318        void *pv = _hrealloc(*ppszStrings, cbAlloc);
     319        if (!pv)
     320            return 0;
     321        *ppszStrings = (char *)pv;
     322        *pcbAlloc = cbAlloc;
     323        if (!off)
     324        {
     325            *pcb = off = 1;
     326            **ppszStrings = '\0';
     327        }
     328    }
     329
     330    /* copy */
     331    memcpy(*ppszStrings + off, pszString, cb);
     332    *pcb += cb;
     333    return off;
     334}
     335
     336
     337/**
    297338 * Pack down file handles for exec.
    298339 *
     
    303344 * @param   pcb     Where to store the size of the returned data.
    304345 */
    305 __LIBC_PSPMINHFHBHDR    __libc_fhInheritPack(size_t *pcb)
     346__LIBC_PSPMINHFHBHDR    __libc_fhInheritPack(size_t *pcb, char **ppszStrings, size_t *pcbStrings)
    306347{
    307348    LIBCLOG_ENTER("pcb=%p\n", (void *)pcb);
    308     size_t                  cb = 0x1000;
     349    size_t                  cbStringAlloc = *pcbStrings;
     350    size_t                  cb = 0x2000;
    309351    unsigned                iFH;
    310352    unsigned                cFHs;
     
    314356    {
    315357        __LIBC_PSPMINHFHBHDR    pHdr;
     358        __LIBC_PSPMINHFHBDIR    pDirs;
    316359        __LIBC_PSPMINHFHBSTD    pStds;
    317360        __LIBC_PSPMINHFHBSOCK   pSockets;
     
    321364
    322365    /*
    323      * Allocate buffer.
    324      */
     366     * Allocate buffers.
     367     */
     368    LIBC_ASSERT(cb > sizeof(u.pDirs->aHandles[0]) * 256 + sizeof(*u.pDirs));
    325369    pRet = _hmalloc(cb);
    326370    if (!pRet)
     
    361405         */
    362406        /* Ensure space for max sized bundle and termination record. */
    363         if ( ((uintptr_t)&u.pSockets->aHandles[256] + sizeof(__LIBC_SPMINHFHBHDR) - (uintptr_t)pRet) > cb)
    364         {
    365             void *pv = realloc(pRet, cb + 0x1000);
     407        if ( ((uintptr_t)&u.pDirs->aHandles[256] + sizeof(__LIBC_SPMINHFHBHDR) - (uintptr_t)pRet) > cb )
     408        {
     409            void *pv = realloc(pRet, cb + 0x2000);
    366410            if (!pv)
    367411            {
     
    372416            u.u += (uintptr_t)pv - (uintptr_t)pv;
    373417            pRet = pv;
    374             cb += 0x1000;
     418            cb += 0x2000;
    375419        }
    376420        /* init the bundle. */
     
    388432                    u.pStds->aHandles[i].Inode  = gpapFHs[iFH]->Inode;
    389433                    u.pStds->aHandles[i].Dev    = gpapFHs[iFH]->Dev;
     434                    u.pStds->aHandles[i].offNativePath = fhAddString(gpapFHs[iFH]->pszNativePath, ppszStrings, &cbStringAlloc, pcbStrings);
    390435                    /* next */
    391436                    i++; iFH++;
     
    400445                u.pStds->Hdr.cHandles = i;
    401446                u.pv = &u.pStds->aHandles[i];
     447                break;
     448            }
     449
     450            case enmFH_Directory:
     451            {
     452                u.pDirs->Hdr.uchType = __LIBC_SPM_INH_FHB_TYPE_DIRECTORY;
     453                u.pDirs->Hdr.StartFH = iFH;
     454                /* walk file handles. */
     455                for (i = 0; ; )
     456                {
     457                    u.pDirs->aHandles[i].fFlags        = gpapFHs[iFH]->fFlags;
     458                    u.pDirs->aHandles[i].Inode         = gpapFHs[iFH]->Inode;
     459                    u.pDirs->aHandles[i].Dev           = gpapFHs[iFH]->Dev;
     460                    LIBC_ASSERT(gpapFHs[iFH]->pszNativePath && *gpapFHs[iFH]->pszNativePath);
     461                    u.pDirs->aHandles[i].offNativePath = fhAddString(gpapFHs[iFH]->pszNativePath, ppszStrings, &cbStringAlloc, pcbStrings);
     462                    if (!u.pDirs->aHandles[i].offNativePath)
     463                    {
     464                        _fmutex_release(&gmtx);
     465                        free(pRet);
     466                        LIBCLOG_ERROR_RETURN_P(NULL);
     467                    }
     468                    u.pDirs->aHandles[i].fInUnixTree   = !!((__LIBC_PFHDIR)gpapFHs[iFH])->fInUnixTree;
     469                    u.pDirs->aHandles[i].uCurEntry     = ((__LIBC_PFHDIR)gpapFHs[iFH])->uCurEntry;
     470                    /* next */
     471                    i++; iFH++;
     472                    if (    i >= 255
     473                        ||  iFH >= cFHs
     474                        ||  !gpapFHs[iFH]
     475                        ||  !gpapFHs[iFH]->pOps
     476                        ||  (gpapFHs[iFH]->pOps->enmType != enmType)
     477                        ||  (gpapFHs[iFH]->fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT)) )
     478                        break;
     479                }
     480                /* commit the bundle. */
     481                u.pStds->Hdr.cHandles = i;
     482                u.pv = &u.pDirs->aHandles[i];
    402483                break;
    403484            }
  • trunk/src/emx/src/lib/sys/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.16 to 1.17
    r2322 r2323  
    126126/** @defgroup grp_sys_inherit   Inherit Function
    127127 * @{ */
    128 __LIBC_PSPMINHFHBHDR    __libc_fhInheritPack(size_t *pcb);
     128__LIBC_PSPMINHFHBHDR    __libc_fhInheritPack(size_t *pcb, char **ppszStrings, size_t *pcbStrings);
    129129void                    __libc_fhInheritDone(void);
    130130/** @} */
Note: See TracChangeset for help on using the changeset viewer.