Changeset 2313 for trunk


Ignore:
Timestamp:
Aug 28, 2005, 8:19:49 AM (20 years ago)
Author:
bird
Message:

o Fixed lot's of unix attribute (in EA) handling.
o Started preparing for open() to work on directories so

fchdir() can be implemented and opendir reimplemented.
This will break libsocket backwards compatability.

Location:
trunk/src/emx
Files:
3 added
17 edited

Legend:

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

    • Property cvs2svn:cvs-rev changed from 1.131 to 1.132
    r2312 r2313  
    552005-08-28: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    66    - libc:
     7        o Fixed lot's of unix attribute (in EA) handling.
     8        o Started preparing for open() to work on directories so
     9          fchdir() can be implemented and opendir reimplemented.
     10          This will break libsocket backwards compatability.
    711        o Added _hstrdup.
     12
    8132005-08-27: knut st. osmundsen <bird-gccos2-spam@anduin.net>
    914    - libc:
  • trunk/src/emx/include/emx/io.h

    • Property cvs2svn:cvs-rev changed from 1.18 to 1.19
    r2312 r2313  
    6161/** Type - Socket. */
    6262#define F_SOCKET    0x04000000
     63/** Type - Directory. */
     64#define F_DIR       0x05000000
    6365/*      FD_CLOEXEC  0x10000000 (when shifted) */
    6466/** The shift for the file descriptor part of __LIBC_FH::fFlags. */
     
    333335    enmFH_Socket43,
    334336    /** Socket handle (BSD 4.4 stack). */
    335     enmFH_Socket44
     337    enmFH_Socket44,
     338    /** Directory handle. */
     339    enmFH_Directory
    336340} __LIBC_FHTYPE;
    337341
     
    482486     * this file resides on. This might be NULL... */
    483487    __LIBC_PFSINFO          pFsInfo;
     488    /** Pointer to the native path to this file as specified in the open call.
     489     * This is required to read the unix attributes from EAs if the file isn't
     490     * opened with exclusive access. */
     491    char                   *pszNativePath;
    484492} __LIBC_FH;
    485493/** Pointer to filehandle. */
  • trunk/src/emx/src/lib/libc.def

    • Property cvs2svn:cvs-rev changed from 1.137 to 1.138
    r2312 r2313  
    19461946    "___libc_Back_gfProcessHandleHashBangScripts" @1944
    19471947    "___libc_Back_gfProcessHandlePCBatchScripts" @1945
     1948    "__hstrdup" @1946
     1949    "___libc_Back_dirOpenNative" @1947
  • trunk/src/emx/src/lib/sys/__dup.c

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r2312 r2313  
    88#include <errno.h>
    99#include <emx/io.h>
     10#include <emx/umalloc.h>
     11#include <sys/fcntl.h>
    1012#include <emx/syscalls.h>
    11 #include <sys/fcntl.h>
    1213#include "syscalls.h"
    1314#include "b_fs.h"
     
    6465                pFHNew->Dev         = pFH->Dev;
    6566                pFHNew->pFsInfo     = __libc_back_fsInfoObjAddRef(pFH->pFsInfo);
     67                pFHNew->pszNativePath = _hstrdup(pFH->pszNativePath);
    6668
    6769                /*
  • trunk/src/emx/src/lib/sys/__dup2.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r2312 r2313  
    66#include <os2emx.h>
    77#include <errno.h>
     8#include <string.h>
     9#include <emx/umalloc.h>
    810#include <emx/syscalls.h>
    911#include <emx/io.h>
     
    9799                pFHNew->Dev         = pFH->Dev;
    98100                pFHNew->pFsInfo     = __libc_back_fsInfoObjAddRef(pFH->pFsInfo);
     101                pFHNew->pszNativePath = _hstrdup(pFH->pszNativePath);
    99102
    100103                /*
  • trunk/src/emx/src/lib/sys/b_fs.h

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r2312 r2313  
    4848extern mode_t __libc_gfsUMask;
    4949
     50
     51/** @name   Unix Attribute EA Names
     52 * @{ */
     53/** Symlink EA name. */
     54#define EA_SYMLINK          "SYMLINK"
     55/** File EA owner. */
     56#define EA_UID              "UID"
     57/** File EA group. */
     58#define EA_GID              "GID"
     59/** File EA mode. */
     60#define EA_MODE             "MODE"
     61/** File EA i-node number. */
     62#define EA_INO              "INO"
     63/** File EA rdev number. */
     64#define EA_RDEV             "RDEV"
     65/** File EA gen number. */
     66#define EA_GEN              "GEN"
     67/** File EA user flags. */
     68#define EA_FLAGS            "FLAGS"
     69/** @} */
     70
    5071/** The minimum EA size of a file for it to possibly contain any LIBC Unix EAs. */
    51 #define LIBC_UNIX_EA_MIN    (1 + 1 + 2 + sizeof("LIBC.???") + 2 + 2 + sizeof(uint32_t))
    52 
     72#define LIBC_UNIX_EA_MIN    (1 + 1 + 2 + sizeof("???") + 2 + 2 + sizeof(uint32_t))
    5373
    5474#ifdef _OS2EMX_H
     75
     76/**
     77 * The prefilled FEA2LIST construct for creating all unix attributes except symlink.
     78 */
     79#pragma pack(1)
     80extern const struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST
     81{
     82    ULONG   cbList;
     83
     84    ULONG   offUID;
     85    BYTE    fUIDEA;
     86    BYTE    cbUIDName;
     87    USHORT  cbUIDValue;
     88    CHAR    szUIDName[sizeof(EA_UID)];
     89    USHORT  usUIDType;
     90    USHORT  cbUIDData;
     91    uint32_t u32UID;
     92    CHAR    achUIDAlign[((sizeof(EA_UID) + 4) & ~3) - sizeof(EA_UID)];
     93
     94    ULONG   offGID;
     95    BYTE    fGIDEA;
     96    BYTE    cbGIDName;
     97    USHORT  usGIDValue;
     98    CHAR    szGIDName[sizeof(EA_GID)];
     99    USHORT  usGIDType;
     100    USHORT  cbGIDData;
     101    uint32_t u32GID;
     102    CHAR    achGIDAlign[((sizeof(EA_GID) + 4) & ~3) - sizeof(EA_GID)];
     103
     104    ULONG   offMode;
     105    BYTE    fModeEA;
     106    BYTE    cbModeName;
     107    USHORT  usModeValue;
     108    CHAR    szModeName[sizeof(EA_MODE)];
     109    USHORT  usModeType;
     110    USHORT  cbModeData;
     111    uint32_t u32Mode;
     112    CHAR    achModeAlign[((sizeof(EA_MODE) + 4) & ~3) - sizeof(EA_MODE)];
     113
     114    ULONG   offINO;
     115    BYTE    fINOEA;
     116    BYTE    cbINOName;
     117    USHORT  usINOValue;
     118    CHAR    szINOName[sizeof(EA_INO)];
     119    USHORT  usINOType;
     120    USHORT  cbINOData;
     121    uint64_t u64INO;
     122    CHAR    achINOAlign[((sizeof(EA_INO) + 4) & ~3) - sizeof(EA_INO)];
     123
     124    ULONG   offRDev;
     125    BYTE    fRDevEA;
     126    BYTE    cbRDevName;
     127    USHORT  usRDevValue;
     128    CHAR    szRDevName[sizeof(EA_RDEV)];
     129    USHORT  usRDevType;
     130    USHORT  cbRDevData;
     131    uint32_t u32RDev;
     132    CHAR    achGDAlign[((sizeof(EA_RDEV) + 4) & ~3) - sizeof(EA_RDEV)];
     133
     134    ULONG   offGen;
     135    BYTE    fGenEA;
     136    BYTE    cbGenName;
     137    USHORT  usGenValue;
     138    CHAR    szGenName[sizeof(EA_GEN)];
     139    USHORT  usGenType;
     140    USHORT  cbGenData;
     141    uint32_t u32Gen;
     142    CHAR    achGenAlign[((sizeof(EA_GEN) + 4) & ~3) - sizeof(EA_GEN)];
     143
     144    ULONG   offFlags;
     145    BYTE    fFlagsEA;
     146    BYTE    cbFlagsName;
     147    USHORT  usFlagsValue;
     148    CHAR    szFlagsName[sizeof(EA_FLAGS)];
     149    USHORT  usFlagsType;
     150    USHORT  cbFlagsData;
     151    uint32_t u32Flags;
     152    CHAR    achFlagsAlign[((sizeof(EA_FLAGS) + 4) & ~3) - sizeof(EA_FLAGS)];
     153
     154} __libc_gFsUnixAttribsCreateFEA2List;
     155#pragma pack()
     156
     157
     158/**
     159 * The prefilled GEA2LIST construct for querying all unix attributes.
     160 */
     161#pragma pack(1)
     162extern const struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST
     163{
     164    ULONG   cbList;
     165
     166    ULONG   offSymlink;
     167    BYTE    cbSymlinkName;
     168    CHAR    szSymlinkName[((sizeof(EA_SYMLINK) + 4) & ~3) - 1];
     169
     170    ULONG   offUID;
     171    BYTE    cbUIDName;
     172    CHAR    szUIDName[((sizeof(EA_UID) + 4) & ~3) - 1];
     173
     174    ULONG   offGID;
     175    BYTE    cbGIDName;
     176    CHAR    szGIDName[((sizeof(EA_GID) + 4) & ~3) - 1];
     177
     178    ULONG   offMode;
     179    BYTE    cbModeName;
     180    CHAR    szModeName[((sizeof(EA_MODE) + 4) & ~3) - 1];
     181
     182    ULONG   offINO;
     183    BYTE    cbINOName;
     184    CHAR    szINOName[((sizeof(EA_INO) + 4) & ~3) - 1];
     185
     186    ULONG   offRDev;
     187    BYTE    cbRDevName;
     188    CHAR    szRDevName[((sizeof(EA_RDEV) + 4) & ~3) - 1];
     189
     190    ULONG   offGen;
     191    BYTE    cbGenName;
     192    CHAR    szGenName[((sizeof(EA_GEN) + 4) & ~3) - 1];
     193
     194    ULONG   offFlags;
     195    BYTE    cbFlagsName;
     196    CHAR    szFlagsName[((sizeof(EA_FLAGS) + 4) & ~3) - 1];
     197} __libc_gFsUnixAttribsGEA2List;
     198#pragma pack()
     199
     200
    55201/** @group Large File Support - API pointers.
    56202 * Test if the function pointer is set before calling it.
     
    62208extern ULONG (* _System __libc_gpfnDosSetFileLocksL)(HFILE hFile, __const__ FILELOCKL *pflUnlock, __const__ FILELOCKL *pflLock, ULONG ulTimeout, ULONG flFlags);
    63209/** @} */
    64 #endif
     210
     211#endif /* _OS2EMX_H */
    65212
    66213/**
     
    139286
    140287
    141 /**
    142  * Creates the unix EAs for a new file or directory.
    143  *
    144  * @returns 0 on success.
    145  * @returns Negative errno on failure.
    146  * @param   hFile           File handle to the newly created fs object. If no
    147  *                          handle handy, set to -1.
    148  * @param   pszNativePath   Native path to the newly created fs object.
    149  * @param   mode            The specified file permission mode mask.
    150  * @param   pDev            Where to store the dev number.
    151  * @param   pInode          Where to store the calculated inode number.
    152  */
    153 int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode, dev_t *pDev, ino_t *pInode);
     288#ifdef _OS2EMX_H
     289/**
     290 * Initializes a unix attribute structure before creating a new inode.
     291 * The call must have assigned default values to the the structure before doing this call!
     292 *
     293 * @returns Device number.
     294 * @param   pFEas           The attribute structure to fill with actual values.
     295 * @param   pszNativePath   The native path, used to calculate the inode number.
     296 * @param   Mode            The correct mode (the caller have fixed this!).
     297 */
     298dev_t __libc_back_fsUnixAttribsInit(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas, char *pszNativePath, mode_t Mode);
     299#endif /* _OS2EMX_H */
    154300
    155301/**
     
    172318 *
    173319 * @returns 0 on success.
    174  * @returns -1 and errno on failure.
     320 * @returns Negative error code (errno.h) on failure.
    175321 * @param   pszTarget       The target of the symlink link.
    176322 * @param   pszNativePath   The path to the symbolic link to create.
    177  */
    178 int __libc_back_fsNativeSymlinkCreate(const char *pszTarget, const char *pszNativePath);
     323 *                          This is not 'const' because the unix attribute init routine may have to
     324 *                          temporarily modify it to read the sticky bit from the parent directory.
     325 */
     326int __libc_back_fsNativeSymlinkCreate(const char *pszTarget, char *pszNativePath);
    179327
    180328/**
  • trunk/src/emx/src/lib/sys/b_fsDirCreate.c

    • Property cvs2svn:cvs-rev changed from 1.7 to 1.8
    r2312 r2313  
    3737#include "syscalls.h"
    3838#include <errno.h>
     39#include <sys/stat.h>
     40#include <InnoTekLIBC/libc.h>
    3941#include <InnoTekLIBC/backend.h>
    4042#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS
     
    6062    char szNativePath[PATH_MAX];
    6163    int rc = __libc_back_fsResolve(pszPath, BACKFS_FLAGS_RESOLVE_PARENT | BACKFS_FLAGS_RESOLVE_DIR, &szNativePath[0], NULL);
    62     if (rc)
     64    if (__predict_false(rc != 0))
    6365        LIBCLOG_ERROR_RETURN_INT(rc);
     66
     67    /*
     68     * Unix attributes.
     69     */
     70    PEAOP2 pEaOp2 = NULL;
     71    if (__predict_true(!__libc_gfNoUnix))
     72    {
     73        Mode &= ~__libc_gfsUMask;
     74        Mode &= S_IRWXG | S_IRWXO | S_IRWXU | S_ISUID | S_ISGID | S_ISTXT | S_ISVTX;
     75        Mode |= S_IFDIR;
     76
     77        pEaOp2 = alloca(sizeof(EAOP2) + sizeof(__libc_gFsUnixAttribsCreateFEA2List));
     78        struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas = (struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *)(pEaOp2 + 1);
     79        *pFEas = __libc_gFsUnixAttribsCreateFEA2List;
     80        __libc_back_fsUnixAttribsInit(pFEas, szNativePath, Mode);
     81        pEaOp2->fpGEA2List = NULL;
     82        pEaOp2->fpFEA2List = (PFEA2LIST)pFEas;
     83        pEaOp2->oError     = 0;
     84    }
    6485
    6586    /*
     
    6788     */
    6889    FS_SAVE_LOAD();
    69     rc = DosCreateDir((PCSZ)&szNativePath[0], NULL);
     90    rc = DosCreateDir((PCSZ)&szNativePath[0], pEaOp2);
     91    if (__predict_false(rc == ERROR_EAS_NOT_SUPPORTED))
     92        rc = DosCreateDir((PCSZ)&szNativePath[0], NULL);
    7093    FS_RESTORE();
    71     if (!rc)
    72     {
    73         __libc_back_fsUnixAttribsSet(-1, &szNativePath[0], Mode, NULL, NULL);
     94    if (__predict_true(!rc))
    7495        LIBCLOG_RETURN_INT(0);
    75     }
    7696
    7797    /*
  • trunk/src/emx/src/lib/sys/b_fsFileModeSetFH.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2312 r2313  
    3131#include "libc-alias.h"
    3232#define INCL_FSMACROS
     33#define INCL_ERRORS
    3334#include <os2emx.h>
    3435#include "b_fs.h"
     
    6566     */
    6667    PLIBCFH pFH;
    67 
    6868    int rc = __libc_FHEx(fh, &pFH);
    6969    if (rc)
     
    8383            LIBCLOG_RETURN_INT(0);
    8484
     85        /* use the path access. */
     86        case F_DIR:
     87            if (__predict_false(!pFH->pszNativePath))
     88                LIBCLOG_ERROR_RETURN_INT(-EINVAL);
     89            rc = __libc_back_fsNativeFileModeSet(pFH->pszNativePath, Mode);
     90            if (rc)
     91                LIBCLOG_ERROR_RETURN_INT(rc);
     92            LIBCLOG_RETURN_INT(rc);
     93
    8594        /* treat */
    8695        default:
     
    96105        FS_VAR();
    97106        FS_SAVE_LOAD();
    98         union
    99         {
    100             FILESTATUS4     fsts4;
    101             FILESTATUS4L    fsts4L;
    102         } info;
    103 #if OFF_MAX > LONG_MAX
    104         int     fLarge = 0;
    105 #endif
    106 
    107         /*
    108          * Get file info.
    109          * We have a little hack here, temporarily, write only files
    110          * cannot read EAs.
    111          */
    112 #if OFF_MAX > LONG_MAX
    113         if (__libc_gpfnDosOpenL)
    114         {
    115             rc = DosQueryFileInfo(fh, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
    116             if (rc)
    117             {
    118                 rc = DosQueryFileInfo(fh, FIL_STANDARDL, &info, sizeof(FILESTATUS3L));
    119                 info.fsts4L.cbList = ~0;
    120             }
    121             fLarge = 1;
    122         }
    123         else
    124 #endif
    125         {
    126             rc = DosQueryFileInfo(fh, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
    127             if (rc)
    128             {
    129                 rc = DosQueryFileInfo(fh, FIL_STANDARD, &info, sizeof(FILESTATUS3));
    130                 info.fsts4.cbList = ~0;
    131             }
    132         }
     107        FILESTATUS3 fsts3;
     108
     109        /*
     110         * Get file info, we don't need EA size nor large file sizes.
     111         */
     112        rc = DosQueryFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(FILESTATUS3));
    133113        if (rc)
    134114        {
     
    138118        }
    139119
    140         /* If in unix mode we'll check the EAs (if any). */
    141         if (    !__libc_gfNoUnix
    142             && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
     120        /*
     121         * If in unix mode we'll have to update/add the MODE too.
     122         */
     123        if (!__libc_gfNoUnix)
    143124        {
    144             //__libc_back_fsUnixAttribsGet(fh, 0, pStat);
    145             /* Update unix attributes */
     125            struct stat st = {0};
     126            rc = __libc_back_fsUnixAttribsGet(fh, pFH->pszNativePath, &st);
     127            if (__predict_true(!rc))
     128            {
     129                /* correct the passed in Mode mask. */
     130                Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
     131                Mode |= st.st_mode & ~ALLPERMS;
     132
     133                /* construct FEA2 stuff. */
     134                #pragma pack(1)
     135                struct __LIBC_FSUNIXATTRIBSSETMODE
     136                {
     137                    ULONG   cbList;
     138                    ULONG   off;
     139                    BYTE    fEA;
     140                    BYTE    cbName;
     141                    USHORT  cbValue;
     142                    CHAR    szName[sizeof(EA_MODE)];
     143                    USHORT  usType;
     144                    USHORT  cbData;
     145                    uint32_t u32Mode;
     146                } EAs =
     147                {
     148                    sizeof(EAs), 0, FEA_NEEDEA, sizeof(EA_MODE) - 1, sizeof(uint32_t) + 4, EA_MODE, EAT_BINARY, sizeof(uint32_t), Mode
     149                };
     150                #pragma pack()
     151                EAOP2 EaOp2;
     152                EaOp2.fpGEA2List = NULL;
     153                EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
     154                EaOp2.oError = 0;
     155
     156                /* finally, try update / add the EA. */
     157                rc = DosSetFileInfo(fh, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2));
     158                if (__predict_false(rc != NO_ERROR))
     159                {
     160                    LIBCLOG_ERROR("DosSetFileInfo(%d,,,,) -> %d, oError=%#lx\n", fh, rc, EaOp2.oError);
     161                    if (rc != ERROR_EAS_NOT_SUPPORTED && pFH->pszNativePath)
     162                    {
     163                        EaOp2.oError = 0;
     164                        int rc2 = DosSetPathInfo((PCSZ)pFH->pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
     165                        if (rc2)
     166                            LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pFH->pszNativePath, rc2, EaOp2.oError);
     167                    }
     168                    if (rc == ERROR_EAS_NOT_SUPPORTED)
     169                        rc = 0;
     170                    else
     171                        rc = -__libc_native2errno(rc);
     172                }
     173            }
     174            else if (rc == -ENOTSUP)
     175                rc = 0;
     176
     177            if (__predict_false(rc != 0))
     178            {
     179                FS_RESTORE();
     180                LIBCLOG_ERROR_RETURN_INT(rc);
     181            }
    146182        }
    147183
     
    149185         * Update OS/2 bits.
    150186         */
    151 #if OFF_MAX > LONG_MAX
    152         if (fLarge)
    153         {
    154             if (Mode & S_IWRITE)
    155                 info.fsts4L.attrFile &= ~FILE_READONLY;
    156             else
    157                 info.fsts4L.attrFile = FILE_READONLY;
    158             rc = DosSetFileInfo(fh, FIL_STANDARDL, &info, sizeof(info.fsts4L) - sizeof(info.fsts4L.cbList));
    159         }
     187        if (Mode & S_IWRITE)
     188            fsts3.attrFile &= ~FILE_READONLY;
    160189        else
    161 #endif
    162         {
    163             if (Mode & S_IWRITE)
    164                 info.fsts4.attrFile &= ~FILE_READONLY;
    165             else
    166                 info.fsts4.attrFile |= FILE_READONLY;
    167             rc = DosSetFileInfo(fh, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList));
    168         }
     190            fsts3.attrFile |= FILE_READONLY;
     191        rc = DosSetFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(fsts3));
    169192        FS_RESTORE();
    170193        if (rc)
  • trunk/src/emx/src/lib/sys/b_fsFileStatFH.c

    • Property cvs2svn:cvs-rev changed from 1.8 to 1.9
    r2312 r2313  
    6868
    6969    int rc = __libc_FHEx(fh, &pFH);
    70     if (!pFH)
     70    if (rc)
    7171        LIBCLOG_ERROR_RETURN_INT(rc);
    7272
    73     if (!pFH->pOps)
     73    if (/*!pFH->pOps*/ 1)
    7474    {
    7575        /*
    76          * Standard OS/2 file handle.
    77          *
    7876         * Use query handle type to figure out the file type.
    7977         */
    8078        bzero(pStat, sizeof(*pStat));
    81         switch (pFH->fFlags & __LIBC_FH_TYPEMASK)
    82         {
    83             case F_DEV:     pStat->st_mode = S_IFCHR; break;
    84             case F_SOCKET:  pStat->st_mode = S_IFSOCK; break;
    85             /** @todo needs to check if it's a named pipe or not. */
    86             /* Anonymous pipes are AF_UNIX sockets on (some?) unix systems. */
    87             case F_PIPE:    pStat->st_mode = S_IFSOCK; break;
    88             default:
    89             case F_FILE:    pStat->st_mode = S_IFREG; break;
    90         }
    91 
    9279        /* fake unix stuff */
    93         pStat->st_uid = 0;
    94         pStat->st_gid = 0;
     80        //pStat->st_uid = 0;
     81        //pStat->st_gid = 0;
    9582        pStat->st_ino = pFH->Inode;
    9683        pStat->st_dev = pFH->Dev;
    97         pStat->st_rdev = 0;
     84        //pStat->st_rdev = 0;
    9885        pStat->st_nlink = 1;
    9986        pStat->st_blksize = 4096*12; /* 48KB */
    10087
    101         FS_VAR();
    102         FS_SAVE_LOAD();
    103         if (pStat->st_mode == S_IFREG)
     88        if ((pFH->fFlags & __LIBC_FH_TYPEMASK) == F_FILE)
    10489        {
     90            /*
     91             * Regular OS/2 file.
     92             */
    10593            union
    10694            {
     
    11199            int     fLarge = 0;
    112100#endif
     101            pStat->st_mode = S_IFREG;
    113102
    114103            /*
     
    117106             * cannot read EAs.
    118107             */
     108            FS_VAR_SAVE_LOAD();
    119109#if OFF_MAX > LONG_MAX
    120110            if (__libc_gpfnDosOpenL)
     
    138128                }
    139129            }
     130            FS_RESTORE();
    140131            if (rc)
    141132            {
    142                 FS_RESTORE();
    143133                rc = -__libc_native2errno(rc);
    144134                LIBCLOG_ERROR_RETURN_INT(rc);
     
    180170            pStat->st_attr = rc;
    181171            if (rc & FILE_READONLY)
    182                 pStat->st_mode |= (S_IREAD >> 6) * 0111;
    183             else
    184                 pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     172                pStat->st_mode |= S_IROTH | S_IRGRP | S_IRUSR;
     173            else
     174                pStat->st_mode |= S_IROTH | S_IRGRP | S_IRUSR | S_IWOTH | S_IWGRP | S_IWUSR;
    185175
    186176            /* If in unix mode we'll check the EAs (if any). */
    187177            if (    !__libc_gfNoUnix
    188178                && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
    189                 __libc_back_fsUnixAttribsGet(fh, 0, pStat);
     179                __libc_back_fsUnixAttribsGet(fh, pFH->pszNativePath, pStat);
    190180        }
    191181        else
    192182        {
     183            /*
     184             * Use the native path if we've got it.
     185             */
     186            if (pFH->pszNativePath)
     187            {
     188                struct stat st;
     189                rc = __libc_back_fsNativeFileStat(pFH->pszNativePath, &st);
     190                if (!rc)
     191                {
     192                    *pStat = st;
     193                    LIBCLOG_RETURN_INT(0);
     194                }
     195            }
     196
     197            /*
     198             * Ok, try fake something plausible from the handle data.
     199             */
    193200            if ((pFH->fFlags & O_ACCMODE) == O_RDONLY)
    194                 pStat->st_mode |= (S_IREAD >> 6) * 0111;
    195             else
    196                 pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     201                pStat->st_mode = S_IROTH | S_IRGRP | S_IRUSR;
     202            else
     203                pStat->st_mode = S_IROTH | S_IRGRP | S_IRUSR | S_IWOTH | S_IWGRP | S_IWUSR;
     204
     205            switch (pFH->fFlags & __LIBC_FH_TYPEMASK)
     206            {
     207                case F_DEV:
     208                    pStat->st_mode = S_IFCHR;
     209                    pStat->st_rdev = pFH->Inode;
     210                    break;
     211                case F_SOCKET:
     212                    pStat->st_mode |= S_IFSOCK | S_IXUSR | S_IXGRP | S_IXOTH;
     213                    break;
     214                case F_PIPE:
     215                    pStat->st_mode |= S_IFIFO;
     216                    pStat->st_mode &= ~(S_IRWXO | S_IRWXG);
     217                    break;
     218                case F_DIR:
     219                    pStat->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH;
     220                    break;
     221                default:
     222                    LIBC_ASSERTM_FAILED("Unknown handle type %#x\n", pFH->fFlags & __LIBC_FH_TYPEMASK);
     223                    pStat->st_mode |= S_IFREG;
     224                    break;
     225            }
    197226        }
    198 
    199         FS_RESTORE();
    200227    }
    201     else
    202     {
    203         /*
    204          * Non-standard handle - fail.
    205          */
    206         LIBCLOG_ERROR_RETURN_INT(-EOPNOTSUPP);
    207     }
     228    //else
     229    //{
     230    //    rc = pFH->pOps->pfnStat(pFH, fh, pStat);
     231    //    if (rc)
     232    //    {
     233    //        if (rc > 0)
     234    //            rc = -__libc_native2errno(rc);
     235    //        LIBCLOG_ERROR_RETURN_INT(rc);
     236    //    }
     237    //}
    208238
    209239    LIBCLOG_MSG("st_dev:     %#x\n",  pStat->st_dev);
    210     LIBCLOG_MSG("st_ino:     %#llx\n",  pStat->st_ino);
    211     LIBCLOG_MSG("st_mode:    %#x\n",  pStat->st_mode);
     240    LIBCLOG_MSG("st_ino:     %#018llx\n",pStat->st_ino);
     241    LIBCLOG_MSG("st_mode:    0%o\n",  pStat->st_mode);
    212242    LIBCLOG_MSG("st_nlink:   %u\n",   pStat->st_nlink);
    213243    LIBCLOG_MSG("st_uid:     %u\n",   pStat->st_uid);
  • trunk/src/emx/src/lib/sys/b_fsFileTimesSetFH.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2312 r2313  
    8888            LIBCLOG_RETURN_INT(0);
    8989
     90        /* use the path access. */
     91        case F_DIR:
     92            if (__predict_false(!pFH->pszNativePath))
     93                LIBCLOG_ERROR_RETURN_INT(-EINVAL);
     94            rc = __libc_back_fsNativeFileTimesSet(pFH->pszNativePath, paTimes);
     95            if (rc)
     96                LIBCLOG_ERROR_RETURN_INT(rc);
     97            LIBCLOG_RETURN_INT(rc);
     98
    9099        /* treat */
    91100        default:
     
    122131        FS_VAR();
    123132        FS_SAVE_LOAD();
    124         union
    125         {
    126             FILESTATUS3     fsts3;
    127             FILESTATUS3L    fsts3L;
    128         } info;
    129 #if OFF_MAX > LONG_MAX
    130         int     fLarge = 0;
    131 #endif
     133        FILESTATUS3     fsts3;
    132134
    133135        /*
    134136         * Get file info.
    135          * We have a little hack here, temporarily, write only files
    136          * cannot read EAs.
    137137         */
    138 #if OFF_MAX > LONG_MAX
    139         if (__libc_gpfnDosOpenL)
    140         {
    141             rc = DosQueryFileInfo(fh, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    142             fLarge = 1;
    143         }
    144         else
    145 #endif
    146             rc = DosQueryFileInfo(fh, FIL_STANDARD, &info, sizeof(info.fsts3));
     138        rc = DosQueryFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(fsts3));
    147139        if (rc)
    148140        {
     
    155147         * Update OS/2 bits.
    156148         */
    157 #if OFF_MAX > LONG_MAX
    158         if (fLarge)
     149        __libc_back_timeUnix2FileTime(aTimes[0], &fsts3.ftimeLastAccess, &fsts3.fdateLastAccess);
     150        __libc_back_timeUnix2FileTime(aTimes[1], &fsts3.ftimeLastWrite,  &fsts3.fdateLastWrite);
     151        rc = DosSetFileInfo(fh, FIL_STANDARD, &fsts3, sizeof(fsts3));
     152        if (rc && pFH->pszNativePath)
    159153        {
    160             __libc_back_timeUnix2FileTime(aTimes[0], &info.fsts3L.ftimeLastAccess, &info.fsts3L.fdateLastAccess);
    161             __libc_back_timeUnix2FileTime(aTimes[1], &info.fsts3L.ftimeLastWrite,  &info.fsts3L.fdateLastWrite);
    162             rc = DosSetFileInfo(fh, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    163         }
    164         else
    165 #endif
    166         {
    167             __libc_back_timeUnix2FileTime(aTimes[0], &info.fsts3.ftimeLastAccess, &info.fsts3.fdateLastAccess);
    168             __libc_back_timeUnix2FileTime(aTimes[1], &info.fsts3.ftimeLastWrite,  &info.fsts3.fdateLastWrite);
    169             rc = DosSetFileInfo(fh, FIL_STANDARD, &info, sizeof(info.fsts3));
     154            LIBCLOG_ERROR("DosSetFileInfo(%d,,,) -> %d\n", fh, rc);
     155            rc = DosSetPathInfo((PCSZ)pFH->pszNativePath, FIL_STANDARD, &fsts3, sizeof(fsts3), 0);
     156            if (rc)
     157                LIBCLOG_ERROR("DosSetPathInfo('%s',,,) -> %d\n", pFH->pszNativePath, rc);
    170158        }
    171159        FS_RESTORE();
  • trunk/src/emx/src/lib/sys/b_fsNativeFileModeSet.c

    • Property cvs2svn:cvs-rev changed from 1.3 to 1.4
    r2312 r2313  
    110110#endif
    111111            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList));
    112         info.fsts4L.cbList = 0;
     112        info.fsts4L.cbList = LIBC_UNIX_EA_MIN;
    113113    }
    114114    if (rc)
     
    117117        FS_RESTORE();
    118118        LIBCLOG_ERROR_RETURN_INT(rc);
    119     }
    120 
    121     /* If in unix mode we'll get the EAs (if any). */
    122     rc = -1;
    123     if (    !__libc_gfNoUnix
    124         && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN
    125         /*&&  __libc_back_fsUnixAttribsGet(-1, pszNativePath, pStat) == 0*/)
    126     {
    127         /* Update unix attributes. */
    128119    }
    129120
     
    149140        rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList), 0);
    150141    }
    151 
     142    if (__predict_false(rc != NO_ERROR))
     143    {
     144        FS_RESTORE();
     145        rc = -__libc_native2errno(rc);
     146        LIBCLOG_ERROR_RETURN_INT(rc);
     147    }
     148
     149    /*
     150     * If in unix mode we'll have to update/add the MODE too.
     151     */
     152    if (!__libc_gfNoUnix)
     153    {
     154        struct stat st = {0};
     155        rc = __libc_back_fsUnixAttribsGet(-1, pszNativePath, &st);
     156        if (__predict_true(!rc))
     157        {
     158            /* correct the passed in Mode mask. */
     159            Mode &= ALLPERMS; /** @todo sticky bit and set uid/gid access validation... */
     160            Mode |= st.st_mode & ~ALLPERMS;
     161
     162            /* construct FEA2 stuff. */
     163            #pragma pack(1)
     164            struct __LIBC_FSUNIXATTRIBSSETMODE
     165            {
     166                ULONG   cbList;
     167                ULONG   off;
     168                BYTE    fEA;
     169                BYTE    cbName;
     170                USHORT  cbValue;
     171                CHAR    szName[sizeof(EA_MODE)];
     172                USHORT  usType;
     173                USHORT  cbData;
     174                uint32_t u32Mode;
     175            } EAs =
     176            {
     177                sizeof(EAs), 0, FEA_NEEDEA, sizeof(EA_MODE) - 1, sizeof(uint32_t) + 4, EA_MODE, EAT_BINARY, sizeof(uint32_t), Mode
     178            };
     179            #pragma pack()
     180            EAOP2 EaOp2;
     181            EaOp2.fpGEA2List = NULL;
     182            EaOp2.fpFEA2List = (PFEA2LIST)&EAs;
     183            EaOp2.oError = 0;
     184
     185            /* finally, try update / add the EA. */
     186            rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &EaOp2, sizeof(EaOp2), 0);
     187            if (__predict_false(rc != NO_ERROR))
     188            {
     189                LIBCLOG_ERROR("DosSetPathInfo('%s',,,,) -> %d, oError=%#lx\n", pszNativePath, rc, EaOp2.oError);
     190                if (rc == ERROR_EAS_NOT_SUPPORTED)
     191                    rc = 0;
     192                else
     193                    rc = -__libc_native2errno(rc);
     194            }
     195        }
     196        else if (rc == -ENOTSUP)
     197            rc = 0;
     198
     199        if (__predict_false(rc != 0))
     200        {
     201            FS_RESTORE();
     202            LIBCLOG_ERROR_RETURN_INT(rc);
     203        }
     204    }
    152205    FS_RESTORE();
    153     if (!rc)
    154         LIBCLOG_RETURN_INT(rc);
    155     rc = -__libc_native2errno(rc);
    156     LIBCLOG_ERROR_RETURN_INT(rc);
     206
     207    LIBCLOG_RETURN_INT(0);
    157208}
    158209
  • trunk/src/emx/src/lib/sys/b_fsNativeFileStat.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r2312 r2313  
    112112#endif
    113113            rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts4) - sizeof(info.fsts4.cbList));
    114         info.fsts4L.cbList = 0;
     114        info.fsts4L.cbList = LIBC_UNIX_EA_MIN;
    115115    }
    116116    FS_RESTORE();
     
    146146#endif
    147147    pStat->st_attr = fAttributtes;
     148#if OFF_MAX > LONG_MAX
     149    if (fLarge)
     150    {
     151        pStat->st_size = info.fsts4L.cbFile;
     152        pStat->st_blocks = info.fsts4L.cbFileAlloc / S_BLKSIZE;
     153    }
     154    else
     155#endif
     156    {
     157        pStat->st_size = info.fsts4.cbFile;
     158        pStat->st_blocks = info.fsts4.cbFileAlloc / S_BLKSIZE;
     159    }
    148160    if (fAttributtes & FILE_DIRECTORY)
    149161    {
    150162        /* directory */
    151         pStat->st_mode = S_IFDIR;
    152         pStat->st_mode |= ((S_IREAD|S_IWRITE|S_IEXEC) >> 6) * 0111;
    153         pStat->st_size = 0;
    154     }
    155     else
    156     {
    157 #if OFF_MAX > LONG_MAX
    158         if (fLarge)
    159         {
    160             pStat->st_size = info.fsts4L.cbFile;
    161             pStat->st_blocks = info.fsts4L.cbFileAlloc / S_BLKSIZE;
    162         }
    163         else
    164 #endif
    165         {
    166             pStat->st_size = info.fsts4.cbFile;
    167             pStat->st_blocks = info.fsts4.cbFileAlloc / S_BLKSIZE;
    168         }
     163        pStat->st_mode = S_IFDIR | S_IRWXO | S_IRWXG | S_IRWXU;
     164    }
     165    else
     166    {
    169167        pStat->st_mode = S_IFREG;
    170168        if (rc & FILE_READONLY)
     
    193191    pStat->st_uid = 0;
    194192    pStat->st_gid = 0;
    195     pStat->st_dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &pStat->st_ino);
     193    pStat->st_dev = 0;
     194    pStat->st_ino = 0;
    196195    pStat->st_rdev = 0;
    197196    pStat->st_nlink = 1;
    198197    pStat->st_blksize = 4096 * 12; /* 48kb */
    199198    /* If in unix mode we'll check the EAs (if any). */
     199    rc = 1;
    200200    if (    !__libc_gfNoUnix
    201201        && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
    202         __libc_back_fsUnixAttribsGet(-1, pszNativePath, pStat);
     202        rc = __libc_back_fsUnixAttribsGet(-1, pszNativePath, pStat);
     203    if (rc)
     204        pStat->st_dev = __libc_back_fsPathCalcInodeAndDev(pszNativePath, &pStat->st_ino);
    203205
    204206    LIBCLOG_MSG("st_dev:     %#x\n",  pStat->st_dev);
  • trunk/src/emx/src/lib/sys/b_fsNativeFileTimesSet.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r2312 r2313  
    6464                  paTimes ? paTimes[0].tv_sec : ~0, paTimes ? paTimes[0].tv_usec : ~0,
    6565                  paTimes ? paTimes[1].tv_sec : ~0, paTimes ? paTimes[1].tv_usec : ~0);
    66     union
    67     {
    68         FILESTATUS3     fsts3;
    69         FILESTATUS3L    fsts3L;
    70     } info;
    71 #if OFF_MAX > LONG_MAX
    72     int     fLarge = 0;
    73 #endif
     66    FILESTATUS3 fsts3;
    7467    FS_VAR();
    7568
     
    116109     */
    117110    FS_SAVE_LOAD();
    118     int rc;
    119 #if OFF_MAX > LONG_MAX
    120     if (__libc_gpfnDosOpenL)
    121     {
    122         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    123         fLarge = 1;
    124     }
    125     else
    126 #endif
    127         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts3));
     111    int rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &fsts3, sizeof(fsts3));
    128112    if (rc)
    129113    {
     
    136120     * Update OS/2 attributes.
    137121     */
    138 #if OFF_MAX > LONG_MAX
    139     if (fLarge)
    140     {
    141         __libc_back_timeUnix2FileTime(aTimes[0], &info.fsts3L.ftimeLastAccess, &info.fsts3L.fdateLastAccess);
    142         __libc_back_timeUnix2FileTime(aTimes[1], &info.fsts3L.ftimeLastWrite,  &info.fsts3L.fdateLastWrite);
    143         rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts3L), 0);
    144     }
    145     else
    146 #endif
    147     {
    148         __libc_back_timeUnix2FileTime(aTimes[0], &info.fsts3.ftimeLastAccess, &info.fsts3.fdateLastAccess);
    149         __libc_back_timeUnix2FileTime(aTimes[1], &info.fsts3.ftimeLastWrite,  &info.fsts3.fdateLastWrite);
    150         rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts3), 0);
    151     }
    152 
     122    __libc_back_timeUnix2FileTime(aTimes[0], &fsts3.ftimeLastAccess, &fsts3.fdateLastAccess);
     123    __libc_back_timeUnix2FileTime(aTimes[1], &fsts3.ftimeLastWrite,  &fsts3.fdateLastWrite);
     124    rc = DosSetPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &fsts3, sizeof(fsts3), 0);
    153125    FS_RESTORE();
    154126    if (!rc)
  • trunk/src/emx/src/lib/sys/b_ioFileOpen.c

    • Property cvs2svn:cvs-rev changed from 1.9 to 1.10
    r2312 r2313  
    44 * LIBC SYS Backend - open.
    55 *
    6  * Copyright (c) 2003-2004 knut st. osmundsen <bird@innotek.de>
     6 * Copyright (c) 2003-2005 knut st. osmundsen <bird@innotek.de>
    77 * Copyright (c) 1992-1996 by Eberhard Mattes
    88 *
     
    3535#include <os2emx.h>
    3636#include "b_fs.h"
     37#include "b_dir.h"
    3738#include <string.h>
    3839#include <errno.h>
     
    4041#include <share.h>
    4142#include <sys/stat.h>
     43#include <emx/umalloc.h>
    4244#include <emx/syscalls.h>
    4345#include <emx/io.h>
     
    128130     * Resolve the specified file path.
    129131     */
    130     char szNativePath[PATH_MAX];
     132    char szNativePath[PATH_MAX + 5];
    131133    int rc = __libc_back_fsResolve(pszFile,
    132134                                   (flOpenFlags & OPEN_ACTION_FAIL_IF_NEW
    133                                         ? BACKFS_FLAGS_RESOLVE_FULL
    134                                         : BACKFS_FLAGS_RESOLVE_FULL_MAYBE),
     135                                        ? BACKFS_FLAGS_RESOLVE_FULL       | BACKFS_FLAGS_RESOLVE_DIR_MAYBE
     136                                        : BACKFS_FLAGS_RESOLVE_FULL_MAYBE | BACKFS_FLAGS_RESOLVE_DIR_MAYBE),
    135137                                   &szNativePath[0],
    136138                                   NULL);
     
    138140        LIBCLOG_ERROR_RETURN_INT(rc);
    139141
     142    /*
     143     * Create Unix attributes for a new file.
     144     */
     145    dev_t   Dev = 0;
     146    ino_t   Inode = 0;
     147    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    }
    140164
    141165    /*
     
    152176        {
    153177            LONGLONG cbInitialTmp = cbInitial;
    154             rc = __libc_gpfnDosOpenL((PCSZ)&szNativePath[0], &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
     178            rc = __libc_gpfnDosOpenL((PCSZ)&szNativePath[0], &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, pEaOp2);
    155179        }
    156180        else
     
    162186                LIBCLOG_ERROR_RETURN_INT(-EOVERFLOW);
    163187            }
    164             rc = DosOpen((PCSZ)&szNativePath[0], &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
     188            rc = DosOpen((PCSZ)&szNativePath[0], &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, pEaOp2);
    165189        }
    166190#else
    167191        {
    168192            ULONG cbInitialTmp = cbInitial;
    169             rc = DosOpen((PCSZ)&szNativePath[0], &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
     193            rc = DosOpen((PCSZ)&szNativePath[0], &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, pEaOp2);
    170194        }
    171195#endif
     196        /* Check for EA errors. */
     197        if (pEaOp2 && rc == ERROR_EAS_NOT_SUPPORTED)
     198        {
     199            pEaOp2 = NULL;
     200            continue;
     201        }
     202
    172203        /* Check if we're out of handles. */
    173204        if (rc != ERROR_TOO_MANY_OPEN_FILES)
     
    189220        if (!rc)
    190221        {
    191             dev_t   Dev;
    192             ino_t   Inode;
    193222            switch (fulType & 0xff)
    194223            {
     
    197226                    fLibc |= F_FILE;
    198227                    /* If a new file the unix EAs needs to be established. */
    199                     if (   (ulAction == FILE_CREATED)
    200                         && !__libc_gfNoUnix)
    201                         __libc_back_fsUnixAttribsSet(hFile, szNativePath, Mode, &Dev, &Inode);
    202                     else
     228                    if (    !pEaOp2
     229                        ||  (ulAction != FILE_CREATED && ulAction != FILE_TRUNCATED)) /** @todo validate that FILE_TRUNCATED will have replaced EAs. */
    203230                        Dev = __libc_back_fsPathCalcInodeAndDev(szNativePath, &Inode);
    204231                    break;
     
    226253            /*
    227254             * Register the handle and calc Dev and Inode.
    228              * We calc the Dev/Inode regardless of whether it's stored in an EA or not.
    229255             */
    230             rc = __libc_FHAllocate(hFile, fLibc, sizeof(LIBCFH), NULL, ppFH, NULL);
     256            __LIBC_PFH pFH;
     257            rc = __libc_FHAllocate(hFile, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL);
    231258            if (!rc)
    232259            {
     260                pFH->Inode = Inode;
     261                pFH->Dev = Dev;
     262                pFH->pFsInfo = __libc_back_fsInfoObjByDev(Dev);
     263                pFH->pszNativePath = _hstrdup(szNativePath);
     264
    233265                if (ppFH)
    234                 {
    235                     (*ppFH)->Inode = Inode;
    236                     (*ppFH)->Dev = Dev;
    237                     (*ppFH)->pFsInfo = __libc_back_fsInfoObjByDev(Dev);
    238                 }
    239                 LIBCLOG_MSG("hFile=%#lx fLibc=%#x fulType=%#lx ulAction=%lu Dev=%#x Inode=%#llx\n",
    240                             hFile, fLibc, fulType, ulAction, Dev, Inode);
     266                    *ppFH = pFH;
     267                LIBCLOG_MSG("pFH=%p hFile=%#lx fLibc=%#x fulType=%#lx ulAction=%lu Dev=%#x Inode=%#llx\n",
     268                            (void *)pFH, hFile, fLibc, fulType, ulAction, Dev, Inode);
    241269            }
    242270        }
    243271
    244         if (rc)
     272        if (__predict_false(rc != NO_ERROR))
    245273            DosClose(hFile);
    246274    }
     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
    247288    FS_RESTORE();
    248289
     
    250291     * Handle any errors.
    251292     */
    252     if (rc)
     293    if (__predict_false(rc != NO_ERROR))
    253294    {
    254295        if (rc == ERROR_OPEN_FAILED)
  • trunk/src/emx/src/lib/sys/filehandles.c

    • Property cvs2svn:cvs-rev changed from 1.23 to 1.24
    r2312 r2313  
    196196                        pFH->Dev = u.pStds->aHandles[i].Dev;
    197197                        pFH->pFsInfo = __libc_back_fsInfoObjByDev(pFH->Dev);
     198                        pFH->pszNativePath = NULL;
    198199                    }
    199200                    u.pv = &u.pStds->aHandles[c];
     
    763764        pFH->Dev        = 0;
    764765        pFH->pFsInfo    = NULL;
     766        pFH->pszNativePath = NULL;
    765767
    766768        /*
     
    882884 * @param   cb      Size of the file handle.
    883885 *                  Must not be less than the mandatory size (sizeof(LIBCFH)).
    884  * @param   pOps    Value of the pOps field, NULL not allowed.
     886 * @param   pOps    Value of the pOps field.
    885887 * @param   ppFH    Where to store the allocated file handle struct pointer. (NULL allowed)
    886888 * @param   pfh     Where to store the number of the filehandle allocated.
  • trunk/src/emx/src/lib/sys/fs.c

    • Property cvs2svn:cvs-rev changed from 1.22 to 1.23
    r2312 r2313  
    44 * LIBC SYS Backend - file system stuff.
    55 *
    6  * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     6 * Copyright (c) 2004-2005 knut st. osmundsen <bird@innotek.de>
    77 *
    88 *
     
    4242#include <sys/stat.h>
    4343#include <sys/fmutex.h>
     44#include <sys/smutex.h>
    4445#include <emx/startup.h>
    4546#include "syscalls.h"
     
    7475int     __libc_gcchUnixRoot = 0;
    7576/** The current unix root. */
    76 char    __libc_gszUnixRoot[PATH_MAX];
     77char    __libc_gszUnixRoot[PATH_MAX] = "";
    7778/** The umask of the process. */
    7879mode_t  __libc_gfsUMask = 022;
     
    8384ULONG (* _System __libc_gpfnDosSetFileSizeL)(HFILE hFile, LONGLONG cbSize) = NULL;
    8485ULONG (* _System __libc_gpfnDosSetFileLocksL)(HFILE hFile, __const__ FILELOCKL *pflUnlock, __const__ FILELOCKL *pflLock, ULONG ulTimeout, ULONG flFlags) = NULL;
    85 
    86 /** Symlink EA name. */
    87 #define EA_SYMLINK          "SYMLINK"
    88 /** File EA owner. */
    89 #define EA_UID              "UID"
    90 /** File EA group. */
    91 #define EA_GID              "GID"
    92 /** File EA mode. */
    93 #define EA_MODE             "MODE"
    94 /** File EA i-node number. */
    95 #define EA_INO              "INO"
    96 /** File EA rdev number. */
    97 #define EA_RDEV             "RDEV"
    98 /** File EA gen number. */
    99 #define EA_GEN              "GEN"
    10086
    10187/** Symlink EA name. */
     
    11399/** Gen(eration) EA name. */
    114100static const char __libc_gszGenEA[]     = EA_GEN;
    115 
    116 /* GEA2LIST Structure, just a bit more conveniently laid out.. */
     101/** User flags EA name. */
     102static const char __libc_gszFlagsEA[]   = EA_FLAGS;
     103
     104/**
     105 * The prefilled GEA2LIST construct for querying a symlink.
     106 */
     107#pragma pack(1)
    117108static const struct
    118109{
     
    128119    EA_SYMLINK
    129120};
    130 
    131 /* GEA2LIST Structures, just a bit more conveniently laid out.. */
    132 static const struct GEA2LISTUNIXATTRIBS
    133 {
    134     ULONG   cbList;
    135 
    136     ULONG   offSymlink;
    137     BYTE    cbSymlinkName;
    138     CHAR    szSymlinkName[sizeof(EA_SYMLINK)];
    139 
    140     ULONG   offUID;
    141     BYTE    cbUIDName;
    142     CHAR    szUIDName[sizeof(EA_UID)];
    143 
    144     ULONG   offGID;
    145     BYTE    cbGIDName;
    146     CHAR    szGIDName[sizeof(EA_GID)];
    147 
    148     ULONG   offMode;
    149     BYTE    cbModeName;
    150     CHAR    szModeName[sizeof(EA_MODE)];
    151 
    152     ULONG   offINO;
    153     BYTE    cbINOName;
    154     CHAR    szINOName[sizeof(EA_INO)];
    155 
    156     ULONG   offRDev;
    157     BYTE    cbRDevName;
    158     CHAR    szRDevName[sizeof(EA_RDEV)];
    159 
    160     ULONG   offGen;
    161     BYTE    cbGenName;
    162     CHAR    szGenName[sizeof(EA_GEN)];
    163 } gGEA2ListUnixAttribs =
    164 {
    165     sizeof(gGEA2ListUnixAttribs),
    166     offsetof(struct GEA2LISTUNIXATTRIBS, offUID)  - offsetof(struct GEA2LISTUNIXATTRIBS, offSymlink), sizeof(EA_SYMLINK) - 1, EA_SYMLINK,
    167     offsetof(struct GEA2LISTUNIXATTRIBS, offGID)  - offsetof(struct GEA2LISTUNIXATTRIBS, offUID),     sizeof(EA_UID) - 1,     EA_UID,
    168     offsetof(struct GEA2LISTUNIXATTRIBS, offMode) - offsetof(struct GEA2LISTUNIXATTRIBS, offGID),     sizeof(EA_GID) - 1,     EA_GID,
    169     offsetof(struct GEA2LISTUNIXATTRIBS, offINO)  - offsetof(struct GEA2LISTUNIXATTRIBS, offMode),    sizeof(EA_MODE) - 1,    EA_MODE,
    170     offsetof(struct GEA2LISTUNIXATTRIBS, offRDev) - offsetof(struct GEA2LISTUNIXATTRIBS, offINO),     sizeof(EA_INO) - 1,     EA_INO,
    171     offsetof(struct GEA2LISTUNIXATTRIBS, offGen)  - offsetof(struct GEA2LISTUNIXATTRIBS, offRDev),    sizeof(EA_RDEV) - 1,    EA_RDEV,
    172     0,                                                                                                sizeof(EA_GEN) - 1,     EA_GEN
     121#pragma pack()
     122
     123/**
     124 * The prefilled GEA2LIST construct for querying all unix attributes.
     125 */
     126const struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST __libc_gFsUnixAttribsGEA2List =
     127{
     128#define OFF(a,b)  offsetof(struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST, a) - offsetof(struct __LIBC_BACK_FSUNIXATTRIBSGEA2LIST, b)
     129    sizeof(__libc_gFsUnixAttribsGEA2List),
     130    OFF(offUID,   offSymlink), sizeof(EA_SYMLINK) - 1, EA_SYMLINK,
     131    OFF(offGID,   offUID),     sizeof(EA_UID) - 1,     EA_UID,
     132    OFF(offMode,  offGID),     sizeof(EA_GID) - 1,     EA_GID,
     133    OFF(offINO,   offMode),    sizeof(EA_MODE) - 1,    EA_MODE,
     134    OFF(offRDev,  offINO),     sizeof(EA_INO) - 1,     EA_INO,
     135    OFF(offGen,   offRDev),    sizeof(EA_RDEV) - 1,    EA_RDEV,
     136    OFF(offFlags, offGen),     sizeof(EA_GEN) - 1,     EA_GEN,
     137    0,                         sizeof(EA_FLAGS) - 1,   EA_FLAGS
     138#undef OFF
    173139};
     140#pragma pack()
     141
     142/**
     143 * The prefilled FEA2LIST construct for setting all attributes during a creation operation.
     144 */
     145#pragma pack(1)
     146const struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST __libc_gFsUnixAttribsCreateFEA2List =
     147{
     148#define OFF(a,b)  offsetof(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST, a)  - offsetof(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST, b)
     149    sizeof(__libc_gFsUnixAttribsCreateFEA2List),
     150    OFF(offGID,    offUID),   FEA_NEEDEA,  sizeof(EA_UID) - 1,   sizeof(uint32_t) + 4, EA_UID,   EAT_BINARY, sizeof(uint32_t), 0, "",
     151    OFF(offMode,   offGID),   FEA_NEEDEA,  sizeof(EA_GID) - 1,   sizeof(uint32_t) + 4, EA_GID,   EAT_BINARY, sizeof(uint32_t), 0, "",
     152    OFF(offINO,    offMode),  FEA_NEEDEA,  sizeof(EA_MODE) - 1,  sizeof(uint32_t) + 4, EA_MODE,  EAT_BINARY, sizeof(uint32_t), 0, "",
     153    OFF(offRDev,   offINO),   FEA_NEEDEA,  sizeof(EA_INO) - 1,   sizeof(uint64_t) + 4, EA_INO,   EAT_BINARY, sizeof(uint64_t), 0, "",
     154    OFF(offGen,    offRDev),  FEA_NEEDEA,  sizeof(EA_RDEV) - 1,  sizeof(uint32_t) + 4, EA_RDEV,  EAT_BINARY, sizeof(uint32_t), 0, "",
     155    OFF(offFlags,  offGen),   FEA_NEEDEA,  sizeof(EA_GEN) - 1,   sizeof(uint32_t) + 4, EA_GEN,   EAT_BINARY, sizeof(uint32_t), 0, "",
     156    0,                        FEA_NEEDEA,  sizeof(EA_FLAGS) - 1, sizeof(uint32_t) + 4, EA_FLAGS, EAT_BINARY, sizeof(uint32_t), 0, ""
     157#undef OFF
     158};
     159#pragma pack()
    174160
    175161/**
     
    188174/** Mutex semaphore protecting the g_aFSInfoVolumes array. */
    189175static _fmutex        g_mtxFSInfoVolumes = _FMUTEX_INITIALIZER_EX(_FMC_MUST_COMPLETE, "mtxFSInfoVolumes");
     176
    190177
    191178/*******************************************************************************
     
    195182static int fsResolveOS2(const char *pszUserPath, unsigned fFlags, char *pszNativePath, int *pfInUnixTree);
    196183static uint32_t crc32str(const char *psz);
     184#if 0
    197185static uint32_t djb2(const char *str);
     186#endif
    198187static uint32_t sdbm(const char *str);
    199188
     
    496485}
    497486#endif
    498 
    499 
    500 /**
    501  * Creates a symlink.
    502  *
    503  * @returns 0 on success.
    504  * @returns Negative error code (errno.h) on failure.
    505  * @param   pszTarget       The symlink target.
    506  * @param   pszSymlink      The symlink, the one to be updated.
    507  */
    508 int __libc_back_fsNativeSymlinkCreate(const char *pszTarget, const char *pszNativePath)
    509 {
    510     LIBCLOG_ENTER("pszTarget=%s pszNativePath=%s\n", pszTarget, pszNativePath);
    511 
    512     /*
    513      * Validate input.
    514      */
    515     int cchTarget = strlen(pszTarget);
    516     if (cchTarget >= PATH_MAX)
    517         LIBCLOG_ERROR_RETURN(-ENAMETOOLONG, "ret -ENAMETOOLONG - Target is too long, %d bytes. (%s)\n", cchTarget, pszTarget);
    518 
    519     /*
    520      * Allocate FEA buffer.
    521      */
    522     EAOP2   EaOp = {0,0,0};
    523     int     cb = cchTarget + sizeof(USHORT) * 2 + sizeof(EA_SYMLINK) + sizeof(FEALIST);
    524     EaOp.fpFEA2List = alloca(cb);
    525     if (!EaOp.fpFEA2List)
    526         LIBCLOG_ERROR_RETURN(-ENOMEM, "ret -ENOMEM -Out of stack! alloca(%d) failed\n", cb);
    527 
    528     /*
    529      * Setup the EAOP structure.
    530      */
    531     EaOp.fpFEA2List->cbList = cb;
    532     PFEA2   pFEA = &EaOp.fpFEA2List->list[0];
    533     pFEA->oNextEntryOffset  = 0;
    534     pFEA->cbName            = sizeof(EA_SYMLINK) - 1;
    535     pFEA->cbValue           = cchTarget + sizeof(USHORT) * 2;
    536     pFEA->fEA               = FEA_NEEDEA;
    537     memcpy(pFEA->szName, EA_SYMLINK, sizeof(EA_SYMLINK));
    538     PUSHORT pus = (PUSHORT)&pFEA->szName[sizeof(EA_SYMLINK)];
    539     pus[0]                  = EAT_ASCII;
    540     pus[1]                  = cchTarget;
    541     memcpy(&pus[2], pszTarget, cchTarget);
    542     HFILE   hf = -1;
    543     ULONG   ul = 0;
    544     int rc = DosOpen((PCSZ)pszNativePath, &hf, &ul, cchTarget + 1, FILE_NORMAL,
    545                      OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS,
    546                      OPEN_FLAGS_NOINHERIT | OPEN_SHARE_DENYNONE | OPEN_ACCESS_READWRITE,
    547                      &EaOp);
    548     if (!rc)
    549     {
    550         char *psz = (char *)&pus[2] - (sizeof(EA_SYMLINK "=") - 1);
    551         memcpy(psz, EA_SYMLINK "=", sizeof(EA_SYMLINK "=") - 1);
    552         DosWrite(hf, psz, cchTarget + sizeof(EA_SYMLINK "=") - 1, &ul);
    553         DosClose(hf);
    554         LIBCLOG_RETURN_INT(0);
    555     }
    556 
    557     rc = -__libc_native2errno(rc);
    558     LIBCLOG_ERROR_RETURN_INT(rc);
    559 }
    560 
    561487
    562488
     
    13121238
    13131239
    1314 
    1315 
    1316 /**
    1317  * Creates the unix EAs for a new file or directory.
    1318  *
    1319  * @returns 0 on success.
    1320  * @returns Negative errno on failure.
    1321  * @param   hFile           File handle to the newly created fs object. If no
    1322  *                          handle handy, set to -1.
    1323  * @param   pszNativePath   Native path to the newly created fs object.
    1324  * @param   mode            The specified file permission mode mask.
    1325  * @param   pDev            Where to store the dev number.
    1326  * @param   pInode          Where to store the calculated inode number.
    1327  */
    1328 int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode, dev_t *pDev, ino_t *pInode)
    1329 {
    1330     /*
    1331      * Calc device.
    1332      */
    1333     dev_t   Dev;
    1334     char    chDrv = *pszNativePath;
    1335     if (chDrv == '/' || chDrv == '\\')
    1336         Dev = makedev('U', 0);          /* U as in UNC */
    1337     else
    1338     {
    1339         LIBC_ASSERT(chDrv >= 'A' && chDrv <= 'Z');
    1340         Dev = makedev('V', chDrv);      /* V as in Volume */
    1341     }
    1342 
     1240/**
     1241 * Initializes a unix attribute structure before creating a new inode.
     1242 * The call must have assigned default values to the the structure before doing this call!
     1243 *
     1244 * @returns Device number.
     1245 * @param   pFEas           The attribute structure to fill with actual values.
     1246 * @param   pszNativePath   The native path, used to calculate the inode number.
     1247 * @param   Mode            The correct mode (the caller have fixed this!).
     1248 */
     1249dev_t __libc_back_fsUnixAttribsInit(struct __LIBC_FSUNIXATTRIBSCREATEFEA2LIST *pFEas, char *pszNativePath, mode_t Mode)
     1250{
    13431251    /*
    13441252     * Calc Inode number.
    1345      *
    1346      * Whether to use another hash algorithm here is a bit in the blue now
    1347      * because the stored value might be inaccessible at times.
    1348      */
     1253     * We replace the lower 32-bit with a random value.
     1254     */
     1255    /* low 32-bit - random */
     1256    static union
     1257    {
     1258        uint64_t        u64TSC;
     1259        unsigned short  ausSeed[4];
     1260    } s_Seed = {0};
     1261    static _smutex s_smtxSeed = 0;
     1262    _smutex_request(&s_smtxSeed);
     1263    /* seed it ? */
     1264    if (!s_Seed.ausSeed[3])
     1265    {
     1266        __asm__ __volatile__ ("rdtsc" : "=A" (s_Seed.u64TSC));
     1267        s_Seed.ausSeed[3] = 1;
     1268    }
     1269    pFEas->u64INO = nrand48(&s_Seed.ausSeed[0]) & 0xffffffff;
     1270    _smutex_release(&s_smtxSeed);
     1271
     1272    /* high 32-bit - crc32 */
    13491273    const char *psz = pszNativePath;
    13501274    if (psz[1] == ':')
    13511275        psz += 2;
    1352     ino_t Inode = ((uint64_t)crc32str(psz) << 32) | (uint64_t)djb2(psz);
    1353 
    1354     /** @todo Save unix EAs! */
    1355     if (pDev)
    1356         *pDev = Dev;
    1357     if (pInode)
    1358         *pInode = (Inode & 0xffffffff00000000ULL) | (uint64_t)sdbm(psz);
    1359     return 0;
     1276    pFEas->u64INO |= (uint64_t)crc32str(psz) << 32;
     1277
     1278    /*
     1279     * The other stuff.
     1280     */
     1281    pFEas->u32UID = __libc_spmGetId(__LIBC_SPMID_EUID);
     1282    pFEas->u32GID = __libc_spmGetId(__LIBC_SPMID_EGID); /** @todo sticky bit! */
     1283    pFEas->u32Mode = Mode;
     1284    LIBC_ASSERT(pFEas->u32RDev == 0);
     1285    LIBC_ASSERT(pFEas->u32Gen == 0);
     1286    LIBC_ASSERT(pFEas->u32Flags == 0);
     1287
     1288    /*
     1289     * Calc device.
     1290     */
     1291    char chDrv = *pszNativePath;
     1292    if (chDrv == '/' || chDrv == '\\')
     1293        return makedev('U', 0);          /* U as in UNC */
     1294    LIBC_ASSERT(chDrv >= 'A' && chDrv <= 'Z');
     1295    return makedev('V', chDrv);      /* V as in Volume */
    13601296}
    13611297
     
    13781314
    13791315    /* Try come up with an accurate max estimate of a maximum result. */
    1380     char    achBuffer[sizeof(gGEA2ListUnixAttribs) + 7 * (sizeof(USHORT) * 2 + sizeof(BYTE)) + CCHMAXPATH + 6 * sizeof(uint32_t) + 0x30];
     1316    char    achBuffer[sizeof(EAOP2) + sizeof(FILEFINDBUF3) + sizeof(__libc_gFsUnixAttribsGEA2List) + 7 * (sizeof(USHORT) * 2 + sizeof(BYTE)) + CCHMAXPATH + 6 * sizeof(uint32_t) + 0x30];
    13811317    char   *pachBuffer = (char *)((uintptr_t)&achBuffer[3] & ~3);
    1382     EAOP2   EaOp2;
    1383     int     rc;
     1318    PEAOP2  pEaOp2 = (PEAOP2)pachBuffer;
     1319    int     rc = -1000;
    13841320
    13851321    /*
    13861322     * Issue the query.
    13871323     */
    1388     EaOp2.fpGEA2List = (PGEA2LIST)&gGEA2ListUnixAttribs;
    1389     EaOp2.fpFEA2List = (PFEA2LIST)pachBuffer;
    1390     EaOp2.oError     = 0;
    1391     EaOp2.fpFEA2List->cbList = sizeof(achBuffer) - 4;
    13921324    if (hFile >= 0)
    1393         rc = DosQueryFileInfo(hFile, FIL_QUERYEASFROMLIST, &EaOp2, sizeof(EaOp2));
    1394     else
    1395         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, &EaOp2, sizeof(EaOp2));
     1325    {
     1326        pEaOp2->fpGEA2List = (PGEA2LIST)&__libc_gFsUnixAttribsGEA2List;
     1327        pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1);
     1328        pEaOp2->oError     = 0;
     1329        pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2);
     1330        rc = DosQueryFileInfo(hFile, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2));
     1331    }
     1332    if (rc && pszNativePath)
     1333    {
     1334        pEaOp2->fpGEA2List = (PGEA2LIST)&__libc_gFsUnixAttribsGEA2List;
     1335        pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1);
     1336        pEaOp2->oError     = 0;
     1337        pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2);
     1338        rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, pEaOp2, sizeof(EAOP2));
     1339        if (rc == ERROR_SHARING_VIOLATION || rc == ERROR_ACCESS_DENIED || rc == ERROR_INVALID_ACCESS)
     1340        {
     1341            HDIR hDir = HDIR_CREATE;
     1342            ULONG cFiles = 1;
     1343            pEaOp2->fpGEA2List = (PGEA2LIST)&__libc_gFsUnixAttribsGEA2List;
     1344            pEaOp2->fpFEA2List = (PFEA2LIST)(pEaOp2 + 1);
     1345            pEaOp2->oError     = 0;
     1346            pEaOp2->fpFEA2List->cbList = sizeof(achBuffer) - 4 - sizeof(EAOP2);
     1347            rc = DosFindFirst((PCSZ)pszNativePath, &hDir, 0, pEaOp2, pEaOp2->fpFEA2List->cbList + sizeof(*pEaOp2), &cFiles, FIL_QUERYEASFROMLIST);
     1348            if (!rc)
     1349            {
     1350                DosFindClose(hDir);
     1351                pEaOp2->fpFEA2List = (PFEA2LIST)((char *)pEaOp2 + sizeof(EAOP2) + offsetof(FILEFINDBUF3, cchName));
     1352            }
     1353        }
     1354    }
    13961355    if (rc)
    13971356    {
    1398         LIBC_ASSERTM(rc == ERROR_ACCESS_DENIED, "Bogus EAs? rc=%d oError=%ld\n", rc, EaOp2.oError);
     1357        LIBC_ASSERTM(rc == ERROR_ACCESS_DENIED || rc == ERROR_SHARING_VIOLATION || rc == ERROR_EAS_NOT_SUPPORTED,
     1358                     "Bogus EAs? rc=%d oError=%ld\n", rc, pEaOp2->oError);
    13991359        rc = -__libc_native2errno(rc);
    14001360        LIBCLOG_ERROR_RETURN_INT(rc);
    14011361    }
    1402     if (EaOp2.fpFEA2List->cbList < LIBC_UNIX_EA_MIN)
     1362    if (pEaOp2->fpFEA2List->cbList < LIBC_UNIX_EA_MIN)
    14031363        LIBCLOG_RETURN_INT(0);
    14041364
     
    14061366     * Parse the result.
    14071367     */
    1408     PFEA2   pFea2 = &EaOp2.fpFEA2List->list[0];
     1368    PFEA2   pFea2 = &pEaOp2->fpFEA2List->list[0];
    14091369    for (;;)
    14101370    {
     
    14161376            else
    14171377            {
    1418                 PUSHORT pusType = (PUSHORT)((char *)pFea2 + pFea2->cbName);
    1419                 if (pusType[0] == EAT_BINARY && pusType[1] == sizeof(uint32_t))
     1378                PUSHORT pusType = (PUSHORT)&pFea2->szName[pFea2->cbName + 1];
     1379                if (*pusType == EAT_BINARY)
    14201380                {
    1421                     uint32_t u32 = *(uint32_t *)&pusType[2];
    1422                     if (COMPARE_EANAME(__libc_gszUidEA))
    1423                         pStat->st_uid  = u32;
    1424                     else if (COMPARE_EANAME(__libc_gszGidEA))
    1425                         pStat->st_gid  = u32;
    1426                     else if (COMPARE_EANAME(__libc_gszModeEA))
    1427                         pStat->st_mode = u32;
    1428                     else if (COMPARE_EANAME(__libc_gszInoEA))
    1429                         pStat->st_ino  = u32;
    1430                     else if (COMPARE_EANAME(__libc_gszRDevEA))
    1431                         pStat->st_rdev = u32;
    1432                     else if (COMPARE_EANAME(__libc_gszGenEA))
    1433                         /* pStat->st_gen  = u32 - not implemented */;
     1381                    pusType++;
     1382                    if (*pusType == sizeof(uint32_t))
     1383                    {
     1384                        uint32_t u32 = *(uint32_t *)++pusType;
     1385                        if (COMPARE_EANAME(__libc_gszUidEA))
     1386                            pStat->st_uid  = u32;
     1387                        else if (COMPARE_EANAME(__libc_gszGidEA))
     1388                            pStat->st_gid  = u32;
     1389                        else if (COMPARE_EANAME(__libc_gszModeEA))
     1390                            pStat->st_mode = u32;
     1391                        else if (COMPARE_EANAME(__libc_gszRDevEA))
     1392                            pStat->st_rdev = u32;
     1393                        else if (COMPARE_EANAME(__libc_gszGenEA))
     1394                            /* pStat->st_gen  = u32 - not implemented */;
     1395                        else if (COMPARE_EANAME(__libc_gszFlagsEA))
     1396                            /* pStat->st_flags = u32 - not implemented */;
     1397                        else
     1398                            LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d! u32=%#x (%d)\n", pFea2->szName, pFea2->cbName, u32, u32);
     1399                    }
     1400                    else if (*pusType == sizeof(uint64_t))
     1401                    {
     1402                        uint64_t u64 = *(uint64_t *)++pusType;
     1403                        if (COMPARE_EANAME(__libc_gszInoEA))
     1404                            pStat->st_ino = u64;
     1405                        else
     1406                            LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d! u64=%#llx (%lld)\n", pFea2->szName, pFea2->cbName, u64, u64);
     1407                    }
    14341408                    else
    1435                         LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d!\n", pFea2->szName, pFea2->cbName);
     1409                        LIBC_ASSERTM_FAILED("Invalid LIBC EA! '%s' len=%#x and len=4 or 8.\n", pFea2->szName, *pusType);
    14361410                }
    14371411                else
    1438                     LIBC_ASSERTM_FAILED("Invalid LIBC EA! %s type=%#x len=%#x, expected type=%#x and len=%#x.\n",
    1439                                         pFea2->szName, pusType[0], pusType[1], EAT_BINARY, sizeof(uint32_t));
     1412                    LIBC_ASSERTM_FAILED("Invalid LIBC EA! '%s' type=%#x len=%#x, expected type=%#x and len=4 or 8.\n",
     1413                                        pFea2->szName, pusType[0], pusType[1], EAT_BINARY);
    14401414            }
    14411415#undef COMPARE_EANAME
     
    16181592
    16191593
     1594#if 0
    16201595/* djb2:
    16211596  This algorithm (k=33) was first reported by dan bernstein many years ago in
     
    16351610    return hash;
    16361611}
     1612#endif
    16371613
    16381614/* sdbm:
  • trunk/src/emx/src/lib/sys/seterrno.c

    • Property cvs2svn:cvs-rev changed from 1.4 to 1.5
    r2312 r2313  
    6464  EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,  /* 270..274 */
    6565  EINVAL, EINVAL, EINVAL, EINVAL, EINVAL,  /* 275..279 */
    66   EINVAL, EINVAL, EINVAL, EINVAL, EEXIST,  /* 280..284 */
     66  EINVAL, EINVAL, ENOTSUP, EINVAL, EEXIST,  /* 280..284 */
    6767  EEXIST, EINVAL, EINVAL, EINVAL, EINVAL,  /* 285..289 */
    6868  ENOMEM, EMFILE, EINVAL, EINVAL, EINVAL,  /* 290..294 */
Note: See TracChangeset for help on using the changeset viewer.