Changeset 1534


Ignore:
Timestamp:
Oct 1, 2004, 6:55:39 AM (21 years ago)
Author:
bird
Message:

Symlink stat'ing.

Location:
trunk/src/emx
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/emx/include/emx/syscalls.h

    • Property cvs2svn:cvs-rev changed from 1.11 to 1.12
    r1533 r1534  
    6161    /** File attributes. */
    6262    unsigned char   attr;
     63#if 0 /// @todo DT_LNK & d_ino
     64    /** Directory entry type. */
     65    unsigned char   dt_type;
     66#endif
    6367    /** File name */
    6468    char            szName[257];
  • trunk/src/emx/src/lib/io/lstat.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1533 r1534  
    1 /* lstat.c (libc) -- Copyright (c) 2003 knut st. osmundsen */
     1/* $Id$ *//* lstat.c (libc) -- Copyright (c) 2003 knut st. osmundsen */
     2/** @file
     3 *
     4 * lstat().
     5 *
     6 * Copyright (c) 2004 knut st. osmundsen <bird@innotek.de>
     7 *
     8 *
     9 * This file is part of InnoTek LIBC.
     10 *
     11 * InnoTek LIBC is free software; you can redistribute it and/or modify
     12 * it under the terms of the GNU Lesser General Public License as published
     13 * by the Free Software Foundation; either version 2 of the License, or
     14 * (at your option) any later version.
     15 *
     16 * InnoTek LIBC is distributed in the hope that it will be useful,
     17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 * GNU Lesser General Public License for more details.
     20 *
     21 * You should have received a copy of the GNU Lesser General Public License
     22 * along with InnoTek LIBC; if not, write to the Free Software
     23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     24 *
     25 */
    226
     27
     28/*******************************************************************************
     29*   Header Files                                                               *
     30*******************************************************************************/
    331#include "libc-alias.h"
     32#include <errno.h>
    433#include <sys/types.h>
    534#include <sys/stat.h>
    6 #include <emx/syscalls.h>
     35#include <emx/time.h>
     36#include <InnoTekLIBC/backend.h>
     37#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MISC
     38#include <InnoTekLIBC/logstrict.h>
    739
    8 int _STD(lstat) (const char *name, struct stat *buffer)
     40
     41int _STD(lstat)(const char *name, struct stat *buffer)
    942{
    10     return stat(name, buffer);
     43    LIBCLOG_ENTER("name=%p:{%s} buffer=%p\n", (void *)name, name, (void *)buffer);
     44    int rc = __libc_Back_fsSymlinkStat(name, buffer);
     45    if (!rc)
     46    {
     47        if (!_tzset_flag)
     48            tzset();
     49        _loc2gmt(&buffer->st_atime, -1);
     50        _loc2gmt(&buffer->st_mtime, -1);
     51        _loc2gmt(&buffer->st_ctime, -1);
     52    }
     53    else
     54    {
     55        errno = -rc;
     56        rc = -1;
     57    }
     58    LIBCLOG_RETURN_INT(rc);
    1159}
    1260
     61
  • trunk/src/emx/src/lib/io/stat.c

    • Property cvs2svn:cvs-rev changed from 1.6 to 1.7
    r1533 r1534  
    22
    33#include "libc-alias.h"
    4 #include <stdlib.h>
    5 #include <string.h>
    6 #include <time.h>
    7 #include <io.h>
    84#include <errno.h>
    95#include <sys/types.h>
    106#include <sys/stat.h>
    11 #include <emx/io.h>
    127#include <emx/time.h>
    13 #include <emx/syscalls.h>
    148#include <InnoTekLIBC/backend.h>
     9#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_MISC
     10#include <InnoTekLIBC/logstrict.h>
    1511
    1612int _STD(stat) (const char *name, struct stat *buffer)
    1713{
    18   int rc = __libc_Back_fsFileStat (name, buffer);
    19   if (rc == 0)
     14    LIBCLOG_ENTER("name=%p:{%s} buffer=%p\n", (void *)name, name, (void *)buffer);
     15    int rc = __libc_Back_fsFileStat (name, buffer);
     16    if (!rc)
    2017    {
    21       if (!_tzset_flag)
    22         tzset ();
    23       _loc2gmt (&buffer->st_atime, -1);
    24       _loc2gmt (&buffer->st_mtime, -1);
    25       _loc2gmt (&buffer->st_ctime, -1);
    26       if ((buffer->st_mode & (S_IFMT | ((S_IEXEC >> 6) * 0111))) == S_IFREG)
    27         {
    28           const char *tmp = _getext (name);
    29           if (tmp != NULL &&
    30               (stricmp (tmp, ".exe") == 0 ||
    31                stricmp (tmp, ".com") == 0 ||
    32                stricmp (tmp, ".cmd") == 0 ||
    33                stricmp (tmp, ".bat") == 0))
    34             buffer->st_mode |= (S_IEXEC >> 6) * 0111;
    35         }
     18        if (!_tzset_flag)
     19            tzset ();
     20        _loc2gmt (&buffer->st_atime, -1);
     21        _loc2gmt (&buffer->st_mtime, -1);
     22        _loc2gmt (&buffer->st_ctime, -1);
    3623    }
    37   else
     24    else
    3825    {
    39       errno = -rc;
    40       rc = -1;
     26        errno = -rc;
     27        rc = -1;
    4128    }
    42   return rc;
     29    LIBCLOG_RETURN_INT(rc);
    4330}
  • trunk/src/emx/src/lib/misc/symlink.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1533 r1534  
    5252    int rc = __libc_Back_fsSymlinkCreate(target, symlink);
    5353    if (!rc)
    54         LIBCLOG_RETURN_INT(!rc);
     54        LIBCLOG_RETURN_INT(0);
    5555    errno = -rc;
    5656    LIBCLOG_RETURN_INT(-1);
  • trunk/src/emx/src/lib/sys/b_fsDirCreate.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1533 r1534  
    7171    if (!rc)
    7272    {
    73         __libc_back_fsSetUnixAttribs(-1, &szNativePath[0], Mode);
     73        __libc_back_fsUnixAttribsSet(-1, &szNativePath[0], Mode);
    7474        LIBCLOG_RETURN_INT(0);
    7575    }
  • trunk/src/emx/src/lib/sys/b_fsFileStatFH.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1533 r1534  
    4242#include <limits.h>
    4343#include "syscalls.h"
     44#include <InnoTekLIBC/libc.h>
    4445#include <InnoTekLIBC/backend.h>
    4546#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_IO
     
    8990        }
    9091
    91         FS_VAR();
    92         FS_SAVE_LOAD();
    93         if (pStat->st_mode == S_IFREG)
    94         {
    95             union
    96             {
    97                 FILESTATUS3     fsts3;
    98                 FILESTATUS3L    fsts3L;
    99             } info;
    100 #if OFF_MAX > LONG_MAX
    101             int     fLarge = 0;
    102 #endif
    103 
    104             /*
    105              * Get file info.
    106              */
    107 #if OFF_MAX > LONG_MAX
    108             if (__libc_gpfnDosOpenL)
    109             {
    110                 rc = DosQueryFileInfo(fh, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    111                 fLarge = 1;
    112             }
    113             else
    114 #endif
    115                 rc = DosQueryFileInfo(fh, FIL_STANDARD, &info, sizeof(info.fsts3));
    116             if (rc)
    117             {
    118                 FS_RESTORE();
    119                 rc = -__libc_native2errno(rc);
    120                 LIBCLOG_RETURN_INT(rc);
    121             }
    122 
    123             /*
    124              * Format stats struct.
    125              *      We know the info struct layouts!
    126              *      Only cbFile, cbFileAlloc and attrFile need be accessed
    127              *      using the specific structure.
    128              */
    129             /* Times: FAT might not return create and access time. */
    130             pStat->st_mtime = _sys_p2t(info.fsts3.ftimeLastWrite, info.fsts3.fdateLastWrite);
    131             if (    FTIMEZEROP(info.fsts3.ftimeCreation)
    132                 &&  FDATEZEROP(info.fsts3.fdateCreation))
    133                 pStat->st_ctime = pStat->st_mtime;
    134             else
    135                 pStat->st_ctime = _sys_p2t(info.fsts3.ftimeCreation, info.fsts3.fdateCreation);
    136             if (    FTIMEZEROP(info.fsts3.ftimeLastAccess)
    137                 &&  FDATEZEROP(info.fsts3.fdateLastAccess))
    138                 pStat->st_atime = pStat->st_mtime;
    139             else
    140                 pStat->st_atime = _sys_p2t(info.fsts3.ftimeLastAccess, info.fsts3.fdateLastAccess);
    141 
    142 #if OFF_MAX > LONG_MAX
    143             if (fLarge)
    144             {
    145                 pStat->st_size = info.fsts3L.cbFile;
    146                 pStat->st_blocks = info.fsts3L.cbFileAlloc / S_BLKSIZE;
    147                 rc = info.fsts3L.attrFile;
    148             }
    149             else
    150 #endif
    151             {
    152                 pStat->st_size = info.fsts3.cbFile;
    153                 pStat->st_blocks = info.fsts3.cbFileAlloc / S_BLKSIZE;
    154                 rc = info.fsts3.attrFile;
    155             }
    156             pStat->st_attr = rc;
    157             if (rc & FILE_READONLY)
    158                 pStat->st_mode |= (S_IREAD >> 6) * 0111;
    159             else
    160                 pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
    161         }
    162         else
    163         {
    164             if ((pFH->fFlags & O_ACCMODE) == O_RDONLY)
    165                 pStat->st_mode |= (S_IREAD >> 6) * 0111;
    166             else
    167                 pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
    168         }
    169 
    170         /* default fake stuff */
    171         /** @todo read EAs containing this info! */
     92        /* fake unix stuff */
    17293        pStat->st_uid = 0;
    17394        pStat->st_gid = 0;
     
    179100        pStat->st_nlink = 1;
    180101        pStat->st_blksize = 4096*12; /* 48KB */
     102
     103        FS_VAR();
     104        FS_SAVE_LOAD();
     105        if (pStat->st_mode == S_IFREG)
     106        {
     107            union
     108            {
     109                FILESTATUS4     fsts4;
     110                FILESTATUS4L    fsts4L;
     111            } info;
     112#if OFF_MAX > LONG_MAX
     113            int     fLarge = 0;
     114#endif
     115
     116            /*
     117             * Get file info.
     118             */
     119#if OFF_MAX > LONG_MAX
     120            if (__libc_gpfnDosOpenL)
     121            {
     122                rc = DosQueryFileInfo(fh, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
     123                fLarge = 1;
     124            }
     125            else
     126#endif
     127                rc = DosQueryFileInfo(fh, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
     128            if (rc)
     129            {
     130                FS_RESTORE();
     131                rc = -__libc_native2errno(rc);
     132                LIBCLOG_RETURN_INT(rc);
     133            }
     134
     135            /*
     136             * Format stats struct.
     137             *      We know the info struct layouts!
     138             *      Only cbFile, cbFileAlloc and attrFile need be accessed
     139             *      using the specific structure.
     140             */
     141            /* Times: FAT might not return create and access time. */
     142            pStat->st_mtime = _sys_p2t(info.fsts4.ftimeLastWrite, info.fsts4.fdateLastWrite);
     143            if (    FTIMEZEROP(info.fsts4.ftimeCreation)
     144                &&  FDATEZEROP(info.fsts4.fdateCreation))
     145                pStat->st_ctime = pStat->st_mtime;
     146            else
     147                pStat->st_ctime = _sys_p2t(info.fsts4.ftimeCreation, info.fsts4.fdateCreation);
     148            if (    FTIMEZEROP(info.fsts4.ftimeLastAccess)
     149                &&  FDATEZEROP(info.fsts4.fdateLastAccess))
     150                pStat->st_atime = pStat->st_mtime;
     151            else
     152                pStat->st_atime = _sys_p2t(info.fsts4.ftimeLastAccess, info.fsts4.fdateLastAccess);
     153
     154#if OFF_MAX > LONG_MAX
     155            if (fLarge)
     156            {
     157                pStat->st_size = info.fsts4L.cbFile;
     158                pStat->st_blocks = info.fsts4L.cbFileAlloc / S_BLKSIZE;
     159                rc = info.fsts4L.attrFile;
     160            }
     161            else
     162#endif
     163            {
     164                pStat->st_size = info.fsts4.cbFile;
     165                pStat->st_blocks = info.fsts4.cbFileAlloc / S_BLKSIZE;
     166                rc = info.fsts4.attrFile;
     167            }
     168            pStat->st_attr = rc;
     169            if (rc & FILE_READONLY)
     170                pStat->st_mode |= (S_IREAD >> 6) * 0111;
     171            else
     172                pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     173
     174            /* If in unix mode we'll check the EAs (if any). */
     175            if (    !__libc_gfNoUnix
     176                && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
     177                __libc_back_fsUnixAttribsGet(fh, 0, pStat);
     178        }
     179        else
     180        {
     181            if ((pFH->fFlags & O_ACCMODE) == O_RDONLY)
     182                pStat->st_mode |= (S_IREAD >> 6) * 0111;
     183            else
     184                pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     185        }
     186
    181187        FS_RESTORE();
    182188    }
  • trunk/src/emx/src/lib/sys/b_fsNativeFileStat.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1533 r1534  
    3838#include <sys/types.h>
    3939#include <sys/stat.h>
     40#include <stdlib.h>
    4041#include <limits.h>
    4142#include "syscalls.h"
     43#include <InnoTekLIBC/libc.h>
    4244#include <InnoTekLIBC/pathrewrite.h>
    4345#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_FS
     
    5961    union
    6062    {
    61         FILESTATUS3     fsts3;
    62         FILESTATUS3L    fsts3L;
     63        FILESTATUS4     fsts4;
     64        FILESTATUS4L    fsts4L;
    6365    } info;
    6466#if OFF_MAX > LONG_MAX
     
    8890    if (__libc_gpfnDosOpenL)
    8991    {
    90         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARDL, &info, sizeof(info.fsts3L));
     92        rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZEL, &info, sizeof(info.fsts4L));
    9193        fLarge = 1;
    9294    }
    9395    else
    9496#endif
    95         rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_STANDARD, &info, sizeof(info.fsts3));
     97        rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASIZE, &info, sizeof(info.fsts4));
    9698    FS_RESTORE();
    9799    if (rc)
     
    108110     */
    109111    /* Times: FAT might not return create and access time. */
    110     pStat->st_mtime = _sys_p2t(info.fsts3.ftimeLastWrite, info.fsts3.fdateLastWrite);
    111     if (   FTIMEZEROP(info.fsts3.ftimeCreation)
    112         && FDATEZEROP(info.fsts3.fdateCreation))
     112    pStat->st_mtime = _sys_p2t(info.fsts4.ftimeLastWrite, info.fsts4.fdateLastWrite);
     113    if (   FTIMEZEROP(info.fsts4.ftimeCreation)
     114        && FDATEZEROP(info.fsts4.fdateCreation))
    113115        pStat->st_ctime = pStat->st_mtime;
    114116    else
    115         pStat->st_ctime = _sys_p2t(info.fsts3.ftimeCreation, info.fsts3.fdateCreation);
    116     if (   FTIMEZEROP(info.fsts3.ftimeLastAccess)
    117         && FDATEZEROP(info.fsts3.fdateLastAccess))
     117        pStat->st_ctime = _sys_p2t(info.fsts4.ftimeCreation, info.fsts4.fdateCreation);
     118    if (   FTIMEZEROP(info.fsts4.ftimeLastAccess)
     119        && FDATEZEROP(info.fsts4.fdateLastAccess))
    118120        pStat->st_atime = pStat->st_mtime;
    119121    else
    120         pStat->st_atime = _sys_p2t(info.fsts3.ftimeLastAccess, info.fsts3.fdateLastAccess);
     122        pStat->st_atime = _sys_p2t(info.fsts4.ftimeLastAccess, info.fsts4.fdateLastAccess);
    121123
    122124#if OFF_MAX > LONG_MAX
    123     ULONG fAttributtes = fLarge ? info.fsts3L.attrFile : info.fsts3.attrFile;
     125    ULONG fAttributtes = fLarge ? info.fsts4L.attrFile : info.fsts4.attrFile;
    124126#else
    125     ULONG fAttributtes = info.fsts3.attrFile;
     127    ULONG fAttributtes = info.fsts4.attrFile;
    126128#endif
    127129    pStat->st_attr = fAttributtes;
     
    138140        if (fLarge)
    139141        {
    140             pStat->st_size = info.fsts3L.cbFile;
    141             pStat->st_blocks = info.fsts3L.cbFileAlloc / S_BLKSIZE;
     142            pStat->st_size = info.fsts4L.cbFile;
     143            pStat->st_blocks = info.fsts4L.cbFileAlloc / S_BLKSIZE;
    142144        }
    143145        else
    144146#endif
    145147        {
    146             pStat->st_size = info.fsts3.cbFile;
    147             pStat->st_blocks = info.fsts3.cbFileAlloc / S_BLKSIZE;
     148            pStat->st_size = info.fsts4.cbFile;
     149            pStat->st_blocks = info.fsts4.cbFileAlloc / S_BLKSIZE;
    148150        }
    149151        pStat->st_mode = S_IFREG;
     
    152154        else
    153155            pStat->st_mode |= ((S_IREAD|S_IWRITE) >> 6) * 0111;
     156
     157        /* Mark .exe, .com, .cmd and .bat as executables. */
     158        if ((pStat->st_mode & (S_IFMT | ((S_IEXEC >> 6) * 0111))) == S_IFREG)
     159        {
     160            const char *pszExt = _getext(pszNativePath);
     161            if (   pszExt++
     162                && strstr("exeExeEXeEXEExEeXeeXEexEcomComCOmCOMCoMcOmcOMcoMbatBatBAtBATBaTbAtbATbaTcmdCmdCMdCMDCmDcMdcMDcmD",
     163                          pszExt))
     164                pStat->st_mode |= (S_IEXEC >> 6) * 0111;
     165        }
    154166    }
    155     /** @todo rewrite this to check for the LIBC.MODE, LIBC.GID,
    156      * LIBC.UID, LIBC.RDEV, LIBC.DEV and LIBC.INO EAs.
    157      */
    158     /* default fake stuff */
     167
     168    /* fake unix stuff */
    159169    pStat->st_uid = 0;
    160170    pStat->st_gid = 0;
     
    166176    pStat->st_nlink = 1;
    167177    pStat->st_blksize = 4096 * 12; /* 48kb */
     178    /* If in unix mode we'll check the EAs (if any). */
     179    if (    !__libc_gfNoUnix
     180        && (fLarge ? info.fsts4L.cbList : info.fsts4.cbList) >= LIBC_UNIX_EA_MIN)
     181        __libc_back_fsUnixAttribsGet(-1, pszNativePath, pStat);
    168182
    169183    LIBCLOG_MSG("st_dev:     %#x\n",  pStat->st_dev);
  • trunk/src/emx/src/lib/sys/b_ioFileOpen.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r1533 r1534  
    180180        if (   (ulAction == FILE_CREATED)
    181181            && !__libc_gfNoUnix)
    182             __libc_back_fsSetUnixAttribs(hFile, NULL, Mode);
     182            __libc_back_fsUnixAttribsSet(hFile, NULL, Mode);
    183183
    184184        /*
  • trunk/src/emx/src/lib/sys/filefind.c

    • Property cvs2svn:cvs-rev changed from 1.10 to 1.11
    r1533 r1534  
    4040}
    4141
    42 /* Build a `struct _find' structure from a FILEFINDBUF3 structure and
     42/* Build a `struct _find' structure from a FILEFINDBUF4 structure and
    4343   move to the next one. */
    4444
     
    5454    {
    5555        const char             *pch;
    56         const FILEFINDBUF3     *pFindbuf3;
    57         const FILEFINDBUF3L    *pFindbuf3L;
     56        const FILEFINDBUF4     *pFindbuf4;
     57        const FILEFINDBUF4L    *pFindbuf4L;
    5858    } u;
    5959    u.pch = pFD->pchNext;
     
    7676     *      cbFile, cbFileAlloc, attrFile, cchName, achName.
    7777     */
    78     fp->time = XUSHORT(u.pFindbuf3->ftimeLastWrite);
    79     fp->date = XUSHORT(u.pFindbuf3->fdateLastWrite);
     78    fp->time = XUSHORT(u.pFindbuf4->ftimeLastWrite);
     79    fp->date = XUSHORT(u.pFindbuf4->fdateLastWrite);
    8080#if OFF_MAX > LONG_MAX
    81     if (pFD->fType == FIL_STANDARDL)
    82     {
    83         fp->cbFile = u.pFindbuf3L->cbFile;
    84         fp->attr   = (unsigned char)u.pFindbuf3L->attrFile;
    85         strcpy(fp->szName, &u.pFindbuf3L->achName[0]);
     81    if (pFD->fType == FIL_QUERYEASIZEL)
     82    {
     83        fp->cbFile = u.pFindbuf4L->cbFile;
     84        fp->attr   = (unsigned char)u.pFindbuf4L->attrFile;
     85        strcpy(fp->szName, &u.pFindbuf4L->achName[0]);
     86#if 0 //@todo DT_LNK
     87        if (u.pFindbuf4L->cbList >= LIBC_UNIX_EA_MIN
     88            && find_is_symlink(u.pFindbuf4L->achName))
     89            fp->attr |= 0xf0;
     90#endif
    8691    }
    8792    else
    8893#endif
    8994    {
    90         fp->cbFile = u.pFindbuf3->cbFile;
    91         fp->attr   = (unsigned char)u.pFindbuf3->attrFile;
    92         strcpy(fp->szName, &u.pFindbuf3->achName[0]);
     95        fp->cbFile = u.pFindbuf4->cbFile;
     96        fp->attr   = (unsigned char)u.pFindbuf4->attrFile;
     97        strcpy(fp->szName, &u.pFindbuf4->achName[0]);
     98        if (u.pFindbuf4L->cbList >= LIBC_UNIX_EA_MIN)
     99        {
     100
     101        }
    93102    }
    94103
     
    96105     * Next entry.
    97106     */
    98     if (pFD->cFiles && u.pFindbuf3->oNextEntryOffset)
    99     {
    100         pFD->pchNext = u.pch + u.pFindbuf3->oNextEntryOffset;
     107    if (pFD->cFiles && u.pFindbuf4->oNextEntryOffset)
     108    {
     109        pFD->pchNext = u.pch + u.pFindbuf4->oNextEntryOffset;
    101110        pFD->cFiles--;
    102111    }
     
    124133    LIBCLOG_ENTER("pszName=%s attr=%#x fp=%p\n", pszName, attr, (void *)fp);
    125134    int                 rc;
    126     int                 cch;
     135    char                szNativePath[PATH_MAX];
    127136    struct find_data   *pFD = &__libc_threadCurrent()->b.sys.fd;
    128137    FS_VAR();
     
    131140     * Rewrite the specified file path.
    132141     */
    133     cch = __libc_PathRewrite(pszName, NULL, 0);
    134     if (cch > 0)
    135     {
    136         char *pszRewritten = alloca(cch);
    137         if (!pszRewritten)
    138         {
    139             errno = ENOMEM;
    140             LIBCLOG_RETURN_INT(-1);
    141         }
    142         cch = __libc_PathRewrite(pszName, pszRewritten, cch);
    143         if (cch > 0)
    144             pszName = pszRewritten;
    145         /* else happens when someone changes the rules between the two calls. */
    146         else if (cch < 0)
    147         {
    148             errno = EAGAIN;             /* non-standard, I'm sure. */
    149             LIBCLOG_RETURN_INT(-1);
    150         }
     142    rc = __libc_back_fsResolve(pszName, BACKFS_FLAGS_RESOLVE_FULL, &szNativePath[0], NULL);
     143    if (rc)
     144    {
     145        errno = -rc;
     146        return -1;
    151147    }
    152148
     
    171167    pFD->cFiles = sizeof(pFD->achBuffer) / 40;
    172168#if OFF_MAX > LONG_MAX
    173     pFD->fType = __libc_gpfnDosOpenL ? FIL_STANDARDL : FIL_STANDARD;
    174     if (pFD->fType == FIL_STANDARDL)  /* the L version is buggy!! Make sure there is enough space. */
    175         pFD->cFiles = sizeof(pFD->achBuffer) / sizeof(FILEFINDBUF3L);
     169    pFD->fType = __libc_gpfnDosOpenL ? FIL_QUERYEASIZEL : FIL_QUERYEASIZE;
     170    if (pFD->fType == FIL_QUERYEASIZEL)  /* the L version is buggy!! Make sure there is enough space. */
     171        pFD->cFiles = sizeof(pFD->achBuffer) / sizeof(FILEFINDBUF4L);
    176172#else
    177     pFD->fType = FIL_STANDARD;
     173    pFD->fType = FIL_QUERYEASIZE;
    178174#endif
    179175    FS_SAVE_LOAD();
     
    234230    {
    235231        pFD->cFiles = sizeof(pFD->achBuffer) / 40;
    236         if (pFD->fType == FIL_STANDARDL)  /* the L version is buggy!! Make sure there is enough space. */
    237             pFD->cFiles = sizeof(pFD->achBuffer) / sizeof(FILEFINDBUF3L);
     232        if (pFD->fType == FIL_QUERYEASIZEL)  /* the L version is buggy!! Make sure there is enough space. */
     233            pFD->cFiles = sizeof(pFD->achBuffer) / sizeof(FILEFINDBUF4L);
    238234        FS_SAVE_LOAD();
    239235        rc = DosFindNext(pFD->hdir, &pFD->achBuffer[0], sizeof(pFD->achBuffer), &pFD->cFiles);
  • trunk/src/emx/src/lib/sys/fs.c

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1533 r1534  
    4040#include <errno.h>
    4141#include <386/builtin.h>
     42#include <sys/stat.h>
    4243#include <sys/fmutex.h>
    4344#include <emx/startup.h>
     
    8485
    8586/** Symlink EA name. */
    86 #define EA_SYMLINK  "LIBC.SYMLINK"
    87 
    88 /** Symlink ea name. */
    89 const char __libc_gszSymlinkEA[] = EA_SYMLINK;
     87#define EA_SYMLINK          "LIBC.SYMLINK"
     88/** Symlink EA owner. */
     89#define EA_UID              "LIBC.UID"
     90/** Symlink EA group. */
     91#define EA_GID              "LIBC.GID"
     92/** Symlink EA mode. */
     93#define EA_MODE             "LIBC.MODE"
     94/** Symlink EA i-node number. */
     95#define EA_INO              "LIBC.INO"
     96/** Symlink EA rdev number. */
     97#define EA_RDEV             "LIBC.RDEV"
     98/** Symlink EA gen number. */
     99#define EA_GEN              "LIBC.GEN"
     100
     101/** Symlink EA name. */
     102static const char __libc_gszSymlinkEA[] = EA_SYMLINK;
     103/** UID EA name. */
     104static const char __libc_gszUidEA[]     = EA_UID;
     105/** GID EA name. */
     106static const char __libc_gszGidEA[]     = EA_GID;
     107/** Mode EA name. */
     108static const char __libc_gszModeEA[]    = EA_MODE;
     109/** Ino EA name. */
     110static const char __libc_gszInoEA[]     = EA_INO;
     111/** RDev EA name. */
     112static const char __libc_gszRDevEA[]    = EA_RDEV;
     113/** Gen(eration) EA name. */
     114static const char __libc_gszGenEA[]     = EA_GEN;
     115
    90116/* GEA2LIST Structure, just a bit more conveniently laid out.. */
    91117static const struct
     
    95121    BYTE    cbName;
    96122    CHAR    szName[sizeof(EA_SYMLINK)];
    97 } gSymlinkGEA2List =
    98 {
    99     sizeof(gSymlinkGEA2List),
     123} gGEA2ListSymlink =
     124{
     125    sizeof(gGEA2ListSymlink),
    100126    0,
    101127    sizeof(EA_SYMLINK) - 1,
    102128    EA_SYMLINK
     129};
     130
     131/* GEA2LIST Structures, just a bit more conveniently laid out.. */
     132static 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
    103173};
    104174
     
    316386    char   *pachBuffer = (char *)((uintptr_t)&_achBuffer[3] & ~3);
    317387    EAOP2   EaOp;
    318     EaOp.fpGEA2List = (PGEA2LIST)&gSymlinkGEA2List;
     388    EaOp.fpGEA2List = (PGEA2LIST)&gGEA2ListSymlink;
    319389    EaOp.fpFEA2List = (PFEA2LIST)pachBuffer;
    320390    EaOp.oError     = 0;
     
    749819         */
    750820        int cchTmp = __libc_PathRewrite(pszUserPath, szTmp, sizeof(szTmp));
    751         if (cchTmp)
     821        if (cchTmp > 0)
    752822        {
    753823            /*
     
    9681038            {
    9691039                EAOP2   EaOp;
    970                 EaOp.fpGEA2List = (PGEA2LIST)&gSymlinkGEA2List;
     1040                EaOp.fpGEA2List = (PGEA2LIST)&gGEA2ListSymlink;
    9711041                EaOp.fpFEA2List = (PFEA2LIST)pachBuffer;
    9721042                EaOp.oError     = 0;
     
    11401210 * @param   hFile           File handle to the newly created fs object. If no
    11411211 *                          handle handy, set to -1.
    1142  * @param   pszNativePath   Native path of the newly created fs object. If
     1212 * @param   pszNativePath   Native path to the newly created fs object. If
    11431213 *                          handle is give this will be ignored.
    11441214 * @param   mode            The specified file permission mode mask.
    11451215 */
    1146 int __libc_back_fsSetUnixAttribs(int hFile, const char *pszNativePath, mode_t mode)
     1216int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode)
    11471217{
    11481218    /* later */
     
    11501220}
    11511221
     1222/**
     1223 * Reads the unix EAs for a file which is being stat'ed.
     1224 *
     1225 * @returns 0 on success.
     1226 * @returns Negative errno on failure.
     1227 * @param   hFile           File handle to the fs object. If no handle handy, set to -1.
     1228 * @param   pszNativePath   Native path to the fs object. If handle is give this will be ignored.
     1229 * @param   pStat           Pointer to the stat buffer.
     1230 *                          The buffer is only updated if and with the EAs we find,
     1231 *                          so the caller must fill the fields with defaults before
     1232 *                          calling this function.
     1233 */
     1234int __libc_back_fsUnixAttribsGet(int hFile, const char *pszNativePath, struct stat *pStat)
     1235{
     1236    LIBCLOG_ENTER("hFile=%d pszNativePath=%p:{%s} pStat=%p\n", hFile, (void *)pszNativePath, pszNativePath, (void *)pStat);
     1237
     1238    /* Try come up with an accurate max estimate of a maximum result. */
     1239    char    achBuffer[sizeof(gGEA2ListUnixAttribs) + 7 * (sizeof(USHORT) * 2 + sizeof(BYTE)) + CCHMAXPATH + 6 * sizeof(uint32_t) + 0x30];
     1240    char   *pachBuffer = (char *)((uintptr_t)&achBuffer[3] & ~3);
     1241    EAOP2   EaOp2;
     1242    int     rc;
     1243
     1244    /*
     1245     * Issue the query.
     1246     */
     1247    EaOp2.fpGEA2List = (PGEA2LIST)&gGEA2ListUnixAttribs;
     1248    EaOp2.fpFEA2List = (PFEA2LIST)pachBuffer;
     1249    EaOp2.oError     = 0;
     1250    EaOp2.fpFEA2List->cbList = sizeof(achBuffer) - 4;
     1251    if (hFile >= 0)
     1252        rc = DosQueryFileInfo(hFile, FIL_QUERYEASFROMLIST, &EaOp2, sizeof(EaOp2));
     1253    else
     1254        rc = DosQueryPathInfo((PCSZ)pszNativePath, FIL_QUERYEASFROMLIST, &EaOp2, sizeof(EaOp2));
     1255    if (rc)
     1256    {
     1257        LIBC_ASSERTM_FAILED("Bogus EAs? rc=%d oError=%ld\n", rc, EaOp2.oError);
     1258        rc = -__libc_native2errno(rc);
     1259        LIBCLOG_RETURN_INT(rc);
     1260    }
     1261    if (EaOp2.fpFEA2List->cbList < LIBC_UNIX_EA_MIN)
     1262        LIBCLOG_RETURN_INT(rc);
     1263
     1264    /*
     1265     * Parse the result.
     1266     */
     1267    PFEA2   pFea2 = &EaOp2.fpFEA2List->list[0];
     1268    for (;;)
     1269    {
     1270        if (pFea2->cbValue > 0)
     1271        {
     1272#define COMPARE_EANAME(name) (pFea2->cbName == sizeof(name) - 1 && !memcmp(name, pFea2->szName, sizeof(name) - 1))
     1273            if (COMPARE_EANAME(__libc_gszSymlinkEA))
     1274                pStat->st_mode = (pStat->st_mode & ~S_IFMT) | S_IFLNK;
     1275            else
     1276            {
     1277                PUSHORT pusType = (PUSHORT)((char *)pFea2 + pFea2->cbName);
     1278                if (pusType[0] == EAT_BINARY && pusType[1] == sizeof(uint32_t))
     1279                {
     1280                    uint32_t u32 = *(uint32_t *)&pusType[2];
     1281                    if (COMPARE_EANAME(__libc_gszUidEA))
     1282                        pStat->st_uid  = u32;
     1283                    else if (COMPARE_EANAME(__libc_gszGidEA))
     1284                        pStat->st_gid  = u32;
     1285                    else if (COMPARE_EANAME(__libc_gszModeEA))
     1286                        pStat->st_mode = u32;
     1287                    else if (COMPARE_EANAME(__libc_gszInoEA))
     1288                        pStat->st_ino  = u32;
     1289                    else if (COMPARE_EANAME(__libc_gszRDevEA))
     1290                        pStat->st_rdev = u32;
     1291                    else if (COMPARE_EANAME(__libc_gszGenEA))
     1292                        /* pStat->st_gen  = u32 - not implemented */;
     1293                    else
     1294                        LIBC_ASSERTM_FAILED("Huh?!? got an ea named '%s', namelen=%d!\n", pFea2->szName, pFea2->cbName);
     1295                }
     1296                else
     1297                    LIBC_ASSERTM_FAILED("Invalid LIBC EA! %s type=%#x len=%#x, expected type=%#x and len=%#x.\n",
     1298                                        pFea2->szName, pusType[0], pusType[1], EAT_BINARY, sizeof(uint32_t));
     1299            }
     1300#undef COMPARE_EANAME
     1301        }
     1302
     1303        /* next */
     1304        if (pFea2->oNextEntryOffset <= sizeof(FEA2))
     1305            break;
     1306        pFea2 = (PFEA2)((uintptr_t)pFea2 + pFea2->oNextEntryOffset);
     1307    }
     1308
     1309    LIBCLOG_RETURN_INT(0);
     1310}
     1311
     1312
  • trunk/src/emx/src/lib/sys/fs.h

    • Property cvs2svn:cvs-rev changed from 1.2 to 1.3
    r1533 r1534  
    4646/** The current umask of the process. */
    4747extern mode_t __libc_gfsUMask;
     48
     49/** The minimum EA size of a file for it to possibly contain any LIBC Unix EAs. */
     50#define LIBC_UNIX_EA_MIN    (1 + 1 + 2 + sizeof("LIBC.???") + 2 + 2 + sizeof(uint32_t))
     51
    4852
    4953#ifdef _OS2EMX_H
     
    132136 * @param   mode            The specified file permission mode mask.
    133137 */
    134 int __libc_back_fsSetUnixAttribs(int hFile, const char *pszNativePath, mode_t mode);
     138int __libc_back_fsUnixAttribsSet(int hFile, const char *pszNativePath, mode_t mode);
     139
     140/**
     141 * Reads the unix EAs for a file which is being stat'ed.
     142 *
     143 * @returns 0 on success.
     144 * @returns Negative errno on failure.
     145 * @param   hFile           File handle to the fs object. If no handle handy, set to -1.
     146 * @param   pszNativePath   Native path to the fs object. If handle is give this will be ignored.
     147 * @param   pStat           Pointer to the stat buffer.
     148 *                          The buffer is only updated if and with the EAs we find,
     149 *                          so the caller must fill the fields with defaults before
     150 *                          calling this function.
     151 */
     152int __libc_back_fsUnixAttribsGet(int hFile, const char *pszNativePath, struct stat *pStat);
    135153
    136154
Note: See TracChangeset for help on using the changeset viewer.