Changeset 2922


Ignore:
Timestamp:
Dec 29, 2006, 7:57:21 PM (19 years ago)
Author:
bird
Message:

cleanup in progress (party time)

Location:
trunk/libc
Files:
1 added
1 deleted
7 edited
1 copied
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/libc/include/klibc/backend.h

    r2920 r2922  
    653653
    654654/**
     655 * I/O Control operation.
     656 *
     657 * @returns 0 on success.
     658 * @returns Negated errno on failure.
     659 * @param   fh          The file handle.
     660 * @param   ulIOControl Which I/O control operation to perform.
     661 * @param   va          Argument which content is specific to each operation.
     662 * @param   prc         Where to store the value which upon success is
     663 *                      returned to the caller.
     664 */
     665int __libc_Back_ioControl(int fh, unsigned long ulIOControl, va_list va, int *prc);
     666
     667/**
    655668 * Try resolve a filehandle to a path.
    656669 *
  • trunk/libc/include/klibc/io.h

    r2920 r2922  
    180180     *                      returned to the caller.
    181181     */
    182     int (*pfnFileControl)(struct __libc_FileHandle *pFH, int iRequest, int iArg, int *prc);
     182    int (*pfnFileControl)(struct __libc_FileHandle *pFH, int iRequest, intptr_t iArg, int *prc);
    183183
    184184    /**
     
    188188     * @returns Negated errno on failure.
    189189     * @param   pFH         Pointer to the handle structure to operate on.
    190      * @param   iIOControl  Which I/O control operation to perform.
    191      * @param   iArg        Argument which content is specific to each
    192      *                      iIOControl operation.
     190     * @param   ulIOControl Which I/O control operation to perform.
     191     * @param   va          Argument vector which content is specific to each operation.
    193192     * @param   prc         Where to store the value which upon success is
    194193     *                      returned to the caller.
    195194     */
    196     int (*pfnIOControl)(struct __libc_FileHandle *pFH, int iIOControl, int iArg, int *prc);
     195    int (*pfnIOControl)(struct __libc_FileHandle *pFH, unsigned long ulIOControl, va_list va, int *prc);
    197196
    198197    /**
  • trunk/libc/src/kNIX/Makefile.kmk

    r2920 r2922  
    4848    $(PATH_LIBC_SRC)/kNIX/b_fsUMask.c \
    4949    $(PATH_LIBC_SRC)/kNIX/b_ioClose.c \
     50    $(PATH_LIBC_SRC)/kNIX/b_ioControl.c \
    5051    $(PATH_LIBC_SRC)/kNIX/b_ioDirGetEntries.c \
    5152    $(PATH_LIBC_SRC)/kNIX/b_ioDuplicate.c \
     53    $(PATH_LIBC_SRC)/kNIX/b_ioFileControl.c \
    5254    $(PATH_LIBC_SRC)/kNIX/b_ioFileSizeSet.c \
    5355    $(PATH_LIBC_SRC)/kNIX/b_ioFHToPath.c \
     
    9294    $(PATH_LIBC_SRC)/kNIX/os2/b_fsSync.c \
    9395    $(PATH_LIBC_SRC)/kNIX/os2/b_fsUnlink.c \
    94     $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileControl.c \
     96    $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileControlStandard.c \
    9597    $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileOpen.c \
    9698    $(PATH_LIBC_SRC)/kNIX/os2/b_ioPipe.c \
  • trunk/libc/src/kNIX/b_ioFileControl.c

    r2916 r2922  
    22/** @file
    33 *
    4  * kNIX - File Control.
     4 * kNIX - fcntl().
    55 *
    66 * Copyright (c) 2003-2006 knut st. osmundsen <bird-src-spam@innotek.de>
     
    2525 */
    2626
    27 /*******************************************************************************
    28 *   Header Files                                                               *
    29 *******************************************************************************/
    3027#include "kNIX.h"
    3128#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
    3229#include <klibc/logstrict.h>
    33 
    34 
    35 /*******************************************************************************
    36 *   Internal Functions                                                         *
    37 *******************************************************************************/
    38 static int __fcntl_getfd(__LIBC_PFH pFH, int fh, int *pfFlags);
    39 static int __fcntl_setfd(__LIBC_PFH pFH, int fh, int iArg);
    40 static int __fcntl_locking(int fh, int iRequest, struct flock *pFlock);
    4130
    4231
     
    6655    if (!rc)
    6756    {
     57        /*
     58         * Initialize *prc and call the file handle operation.
     59         */
    6860        *prc = 0;
    69         if (!pFH->pOps)
    70         {
    71             /*
    72              * Standard OS/2 handle.
    73              */
    74             rc = __libc_Back_ioFileControlStandard(pFH, iRequest, iArg, prc);
    75         }
    76         else
    77         {
    78             /*
    79              * Non-standard fh - call registered method.
    80              */
    81             rc = pFH->pOps->pfnFileControl(pFH, iRequest, (int)iArg, prc); /** @todo fix iArg */
    82         }
     61        rc = pFH->pOps->pfnFileControl(pFH, iRequest, iArg, prc); /** @todo fix iArg */
    8362        __libc_FHPut(pFH);
    8463        if (!rc)
    85             LIBCLOG_RETURN_INT(rc);
     64            LIBCLOG_RETURN_MSG(0, "ret 0 - *prc=%d\n", *prc);
    8665    }
    8766
    8867    /* failure! */
    89     if (rc > 0)
    90         rc = -__libc_back_native2errno(rc);
    9168    *prc = -1;
    9269    LIBCLOG_ERROR_RETURN_INT(rc);
    9370}
    9471
    95 
    96 /**
    97  * File Control operation - OS/2 standard handle.
    98  *
    99  * @returns 0 on success.
    100  * @returns OS/2 error code or negated errno on failure.
    101  *
    102  * @param   pFH         Pointer to the handle structure to operate on.
    103  * @param   iRequest    Which file file descriptior request to perform.
    104  * @param   iArg        Argument which content is specific to each
    105  *                      iRequest operation.
    106  * @param   prc         Where to store the value which upon success is
    107  *                      returned to the caller.
    108  */
    109 int __libc_Back_ioFileControlStandard(__LIBC_PFH pFH, int iRequest, intptr_t iArg, int *prc)
    110 {
    111     LIBCLOG_ENTER("pFH=%p iRequest=%#x iArg=%#x prc=%p\n", (void *)pFH, iRequest, iArg, (void *)prc);
    112 
    113     switch (iRequest)
    114     {
    115         /*
    116          * Get file status flags and access modes.
    117          */
    118         case F_GETFL:
    119         {
    120             const unsigned fFlags = pFH->fFlags & __LIBC_FH_GETFL_MASK;
    121             *prc = fFlags;
    122             LIBCLOG_RETURN_INT(0);
    123         }
    124 
    125         /*
    126          * Set file status flags.
    127          */
    128         case F_SETFL:
    129         {
    130             *prc = 0;
    131             unsigned fFlags = pFH->fFlags & ~__LIBC_FH_SETFL_MASK;
    132             fFlags |= ((int)iArg & __LIBC_FH_SETFL_MASK);
    133             int rc = __libc_FHSetFlags(pFH, fFlags);
    134             LIBCLOG_MIX0_RETURN_INT(rc);
    135         }
    136 
    137         /*
    138          * Get file descriptor flags.
    139          */
    140         case F_GETFD:
    141         {
    142             int rc = __fcntl_getfd(pFH, pFH->fh, prc);
    143             LIBCLOG_MIX0_RETURN_INT(rc);
    144         }
    145 
    146         /*
    147          * Set file descriptor flags.
    148          */
    149         case F_SETFD:
    150         {
    151             *prc = 0;
    152             int rc = __fcntl_setfd(pFH, pFH->fh, (int)iArg);
    153             LIBCLOG_MIX0_RETURN_INT(rc);
    154         }
    155 
    156         /*
    157          * File locking.
    158          */
    159         case F_GETLK:   /* get record locking information */
    160         case F_SETLK:   /* set record locking information */
    161         case F_SETLKW:  /* F_SETLK; wait if blocked */
    162         {
    163             *prc = 0;
    164             int rc = __fcntl_locking(pFH->fh, iRequest, (struct flock*)iArg);
    165             LIBCLOG_MIX0_RETURN_INT(rc);
    166         }
    167 
    168         default:
    169             LIBCLOG_ERROR_RETURN(-EINVAL, "ret -EINVAL - Invalid iRequest %#x\n", iRequest);
    170     }
    171 }
    172 
    173 
    174 /**
    175  * F_GETFD operation on standard OS/2 fh.
    176  * Gets file descriptor flags, which at the moment is limited to FD_CLOEXEC.
    177  *
    178  * @returns 0 on success.
    179  * @returns OS/2 error code or negated errno on failure.
    180  * @param   pFH     File handler structure.
    181  * @param   fh   File fh.
    182  * @param   pfFlags Where to store the flags on success.
    183  */
    184 static int __fcntl_getfd(__LIBC_PFH pFH, int fh, int *pfFlags)
    185 {
    186     LIBCLOG_ENTER("pFH=%p fh=%d\n", (void *)pFH, fh);
    187 
    188     FS_VAR_SAVE_LOAD();
    189     ULONG   fulState;
    190     int rc = DosQueryFHState(fh, &fulState);
    191     FS_RESTORE();
    192     if (!rc)
    193     {
    194         unsigned fFlags = pFH->fFlags;
    195         /* flags out of sync? */
    196         if (    ( (fulState & OPEN_FLAGS_NOINHERIT) != 0 )
    197             !=  (   (fFlags & (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)))
    198                  == (O_NOINHERIT | (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)) ) )
    199         {
    200             LIBC_ASSERTM_FAILED("Inherit flags are out of sync for file fh %d (%#x)! fulState=%08lx fFlags=%08x\n",
    201                                 fh, fh, fulState, fFlags);
    202             if (fulState & OPEN_FLAGS_NOINHERIT)
    203                 fFlags |= O_NOINHERIT | FD_CLOEXEC;
    204             else
    205                 fFlags &= ~(O_NOINHERIT | FD_CLOEXEC);
    206             __atomic_xchg(&pFH->fFlags, fFlags);
    207         }
    208 
    209         *pfFlags = fFlags >> __LIBC_FH_FDFLAGS_SHIFT;
    210         LIBCLOG_RETURN_INT(0);
    211     }
    212     LIBC_ASSERTM_FAILED("DosQueryFHState(%d,) failed rc=%d! was handle closed?\n", fh, rc);
    213     LIBCLOG_ERROR_RETURN_INT(rc);
    214 }
    215 
    216 
    217 /**
    218  * F_SETFD operation on standard OS/2 fh.
    219  * Sets file descriptor flags, which at the moment is limited to FD_CLOEXEC.
    220  *
    221  * @returns 0 on success.
    222  * @returns OS/2 error code or negated errno on failure.
    223  * @param   pFH     File handler structure.
    224  * @param   fh      File fh.
    225  * @param   iArg    New file descriptor flags.
    226  */
    227 static int __fcntl_setfd(__LIBC_PFH pFH, int fh, int iArg)
    228 {
    229     LIBCLOG_ENTER("pFH=%p fh=%d iArg=%#x\n", (void *)pFH, fh, iArg);
    230 
    231     /*
    232      * Calc new flags.
    233      */
    234     unsigned fFlags = pFH->fFlags;
    235     fFlags = (fFlags & ~__LIBC_FH_FDFLAGS_MASK) | (iArg << __LIBC_FH_FDFLAGS_SHIFT);
    236     if (iArg & FD_CLOEXEC)
    237         fFlags |= O_NOINHERIT;
    238     else
    239         fFlags &= ~O_NOINHERIT;
    240 
    241     /*
    242      * Update the flags.
    243      */
    244     int rc = __libc_FHSetFlags(pFH, fFlags);
    245     LIBCLOG_MIX0_RETURN_INT(rc);
    246 }
    247 
    248 
    249 /**
    250  * Handle locking requests.
    251  *
    252  * @returns 0 on success.
    253  * @returns OS/2 error code or negated errno on failure.
    254  * @param   fh       File fh.
    255  * @param   iRequest     Lock iRequest.
    256  * @param   pFlock      Pointer to flock structure.
    257  */
    258 static int __fcntl_locking(int fh, int iRequest, struct flock *pFlock)
    259 {
    260     LIBCLOG_ENTER("fh=%d iRequest=%d pFlock=%p\n", fh, iRequest, (void *)pFlock);
    261 
    262     /*
    263      * Check input.
    264      */
    265     /** @todo: Implement F_GETLK */
    266     if (iRequest == F_GETLK)
    267         LIBCLOG_ERROR_RETURN_MSG(-EINVAL, "ret -EINVAL - F_GETLK is not implemented!\n");
    268     if (!pFlock)
    269         LIBCLOG_ERROR_RETURN_INT(-EINVAL);
    270 
    271     /*
    272      * Check fh & get filesize.
    273      */
    274     union
    275     {
    276         FILESTATUS3     fsts3;
    277         FILESTATUS3L    fsts3L;
    278     }       info;
    279     int rc;
    280     FS_VAR_SAVE_LOAD();
    281 #if OFF_MAX > LONG_MAX
    282     int  fLarge = 0;
    283     if (__libc_gpfnDosOpenL)
    284     {
    285         rc = DosQueryFileInfo(fh, FIL_STANDARDL, &info, sizeof(info.fsts3L));
    286         fLarge = 1;
    287     }
    288     else
    289 #endif
    290         rc = DosQueryFileInfo(fh, FIL_STANDARD, &info, sizeof(info.fsts3));
    291     FS_RESTORE();
    292     if (!rc)
    293     {
    294         ULONG       fAccess;
    295         int         fLock;
    296         ULONG       ulTimeout;
    297         off_t       cbFile;
    298         off_t       offStart;
    299         off_t       cbRange;
    300 #if OFF_MAX > LONG_MAX
    301         if (fLarge)
    302             cbFile = info.fsts3L.cbFile;
    303         else
    304 #endif
    305             cbFile = info.fsts3.cbFile;
    306 
    307         /* range */
    308         cbRange = pFlock->l_len ? pFlock->l_len : OFF_MAX;
    309 
    310         /* offset */
    311         switch (pFlock->l_whence)
    312         {
    313             case SEEK_SET:  offStart = pFlock->l_start; break;
    314             case SEEK_CUR:  offStart = tell(fh) + pFlock->l_start; break;
    315             case SEEK_END:  offStart = cbFile - pFlock->l_start; break;
    316             default:
    317                 LIBCLOG_ERROR_RETURN_MSG(-EINVAL, "ret -EINVAL - Invalid l_whence=%d\n", pFlock->l_whence);
    318         }
    319         if (    offStart < 0
    320             ||  cbRange + offStart < 0)
    321             LIBCLOG_ERROR_RETURN_MSG(-EINVAL, "ret -EINVAL - Invalid offStart=%llx cbRange=%llx\n", offStart, cbRange);
    322 
    323         /* flags and order */
    324         fAccess = 0; /* exclusive */
    325         switch (pFlock->l_type)
    326         {
    327             case F_UNLCK:
    328                 fLock = 0;
    329                 break;
    330 
    331             case F_RDLCK:
    332                 fAccess = 1; /* shared */
    333             case F_WRLCK:
    334                 fLock = 1;
    335                 break;
    336 
    337             default:
    338                 LIBCLOG_ERROR_RETURN_MSG(-EINVAL, "ret -EINVAL - Invalid l_type=%d\n", pFlock->l_type);
    339         }
    340 
    341         /* timeout */
    342         if (iRequest == F_SETLKW)
    343             ulTimeout = SEM_INDEFINITE_WAIT;
    344         else
    345             ulTimeout = SEM_IMMEDIATE_RETURN;
    346 
    347         /* Do work. */
    348 #if OFF_MAX > LONG_MAX
    349         rc = ERROR_INVALID_PARAMETER;
    350         if (__libc_gpfnDosSetFileLocksL)
    351         {
    352             FILELOCKL   aflock[2];
    353             bzero(&aflock[(fLock + 1) & 1], sizeof(aflock[0]));
    354             aflock[fLock].lOffset = offStart;
    355             aflock[fLock].lRange  = cbRange;
    356             FS_SAVE_LOAD();
    357             rc = __libc_gpfnDosSetFileLocksL(fh, &aflock[0], &aflock[1], ulTimeout, fAccess);
    358             FS_RESTORE();
    359         }
    360         /*
    361          * There is/was a bug in the large API which make it fail on non JFS
    362          * disks with ERROR_INVALID_PARAMETER. We need to work around this.
    363          */
    364         if (rc == ERROR_INVALID_PARAMETER)
    365 #endif
    366         {
    367             FILELOCK    aflock[2];
    368 #if OFF_MAX > LONG_MAX
    369             if (    offStart > LONG_MAX
    370                 ||  (   cbRange != OFF_MAX
    371                      && (   cbRange > LONG_MAX
    372                          || offStart + cbRange > LONG_MAX)
    373                     )
    374                )
    375                 LIBCLOG_ERROR_RETURN_MSG(-EOVERFLOW, "ret -EOVERFLOW\n");
    376 #endif
    377             bzero(&aflock[(fLock + 1) & 1], sizeof(aflock[0]));
    378             aflock[fLock].lOffset = offStart;
    379             aflock[fLock].lRange  = cbRange;
    380             FS_SAVE_LOAD();
    381             rc = DosSetFileLocks(fh, &aflock[0], &aflock[1], ulTimeout, fAccess);
    382             FS_RESTORE();
    383         }
    384     }
    385 
    386     LIBCLOG_MIX0_RETURN_INT(rc);
    387 }
    388 
  • trunk/libc/src/kNIX/kNIX.h

    r2917 r2922  
    5555#include <sys/fcntl.h>
    5656#include <sys/filio.h>
     57#include <sys/ioctl.h>
    5758#include <sys/mman.h>
    5859#include <sys/mount.h>
     
    239240 */
    240241int __libc_FHImportFile(uintptr_t hNative, int fh, __LIBC_PFH *ppFH);
     242/** Get the low word of the ioctl request number.
     243 * Used to support ioctl request numbers from old and new _IOC macros.
     244 */
     245#define __IOCLW(a) ((unsigned short)(a))
    241246/** @} */
    242247
  • trunk/libc/src/kNIX/os2/b_ioFileControlStandard.c

    r2916 r2922  
    3939static int __fcntl_setfd(__LIBC_PFH pFH, int fh, int iArg);
    4040static int __fcntl_locking(int fh, int iRequest, struct flock *pFlock);
    41 
    42 
    43 /**
    44  * File Control.
    45  *
    46  * Deals with file descriptor flags, file descriptor duplication and locking.
    47  *
    48  * @returns 0 on success and *piRet set.
    49  * @returns Negated errno on failure and *piRet set to -1.
    50  * @param   fh          File handle (descriptor).
    51  * @param   iRequest    Which file file descriptior request to perform.
    52  * @param   iArg        Argument which content is specific to each
    53  *                      iRequest operation.
    54  * @param   prc         Where to store the value which upon success is
    55  *                      returned to the caller.
    56  */
    57 int __libc_Back_ioFileControl(int fh, int iRequest, intptr_t iArg, int *prc)
    58 {
    59     LIBCLOG_ENTER("fh=%d iRequest=%#x iArg=%#x prc=%p\n", fh, iRequest, iArg, (void *)prc);
    60 
    61     /*
    62      * Get the file fh data.
    63      */
    64     __LIBC_PFH  pFH;
    65     int rc = __libc_FHGet(fh, &pFH);
    66     if (!rc)
    67     {
    68         *prc = 0;
    69         if (!pFH->pOps)
    70         {
    71             /*
    72              * Standard OS/2 handle.
    73              */
    74             rc = __libc_Back_ioFileControlStandard(pFH, iRequest, iArg, prc);
    75         }
    76         else
    77         {
    78             /*
    79              * Non-standard fh - call registered method.
    80              */
    81             rc = pFH->pOps->pfnFileControl(pFH, iRequest, (int)iArg, prc); /** @todo fix iArg */
    82         }
    83         __libc_FHPut(pFH);
    84         if (!rc)
    85             LIBCLOG_RETURN_INT(rc);
    86     }
    87 
    88     /* failure! */
    89     if (rc > 0)
    90         rc = -__libc_back_native2errno(rc);
    91     *prc = -1;
    92     LIBCLOG_ERROR_RETURN_INT(rc);
    93 }
    9441
    9542
  • trunk/libc/src/kNIX/os2/b_ioPipe.c

    r2920 r2922  
    6868         * Allocates the handles.
    6969         */
    70         if (fBinaryText == -1)
    71             fBinaryText = !!_fmode_bin;
    7270        const unsigned fFlags = !fBinaryText ? O_TEXT | F_PIPE : O_BINARY | F_PIPE;
    7371        __LIBC_PFH pFHRead;
    74         rc = __libc_FHAllocate(sizeof(__LIBC_FH), &__libc_back_gFileOps, hRead, hRead, fFlags | O_RDONLY, pFHRead);
     72        rc = __libc_FHAllocate(sizeof(__LIBC_FH), &__libc_back_gFileOps, hRead, hRead, fFlags | O_RDONLY, &pFHRead);
    7573        if (!rc)
    7674        {
    7775            __LIBC_PFH pFHWrite;
    78             rc = __libc_FHAllocate(sizeof(__LIBC_FH), &__libc_back_gFileOps, hWrite, hWrite, fFlags | O_WRONLY, pFHWrite);
     76            rc = __libc_FHAllocate(sizeof(__LIBC_FH), &__libc_back_gFileOps, hWrite, hWrite, fFlags | O_WRONLY, &pFHWrite);
    7977            if (!rc)
    8078            {
    81                 __libc_FHPut(pfhRead);
    82                 __libc_FHPut(pfhWrite);
     79                __libc_FHPut(pFHRead);
     80                __libc_FHPut(pFHWrite);
    8381
    8482                *pfhRead = hRead;
  • trunk/libc/src/kNIX/os2/fhOS2File.c

    r2920 r2922  
    476476
    477477
    478 /** File Control operation.
    479  * @returns 0 on success.
    480  * @returns Negated errno on failure.
    481  * @param   pFH         Pointer to the handle structure to operate on.
    482  * @param   iRequest    Which file file descriptior request to perform.
    483  * @param   iArg        Argument which content is specific to each
    484  *                      iRequest operation.
    485  * @param   prc         Where to store the value which upon success is
    486  *                      returned to the caller.
    487  */
     478/** @copydoc __LIBC_FHOPS::pfnFileControl */
    488479static int fhOs2FileFileControl(__LIBC_PFH pFH, int iRequest, int iArg, int *prc)
    489480{
    490     return -ENOSYS;
    491 }
    492 
    493 /** I/O Control operation.
    494  * @returns 0 on success.
    495  * @returns Negated errno on failure.
    496  * @param   pFH         Pointer to the handle structure to operate on.
    497  * @param   iIOControl  Which I/O control operation to perform.
    498  * @param   iArg        Argument which content is specific to each
    499  *                      iIOControl operation.
    500  * @param   prc         Where to store the value which upon success is
    501  *                      returned to the caller.
    502  */
    503 static int fhOs2FileIOControl(__LIBC_PFH pFH, int iIOControl, int iArg, int *prc)
    504 {
    505     return -ENOSYS;
    506 }
     481    return __libc_Back_ioFileControlStandard(pFH, iRequest, iArg, prc);
     482}
     483
     484
     485/** @copydoc __LIBC_FHOPS::pfnIOControl */
     486static int fhOs2FileIOControl(__LIBC_PFH pFH, unsigned long ulIOControl, va_list va, int *prc)
     487{
     488    LIBCLOG_ENTER("pFH=%p:{.fh=%d} ulIOControl=%#lx (%lu) prc=%p\n", (void *)pFH, pFH->fh, ulIOControl, ulIOControl, (void *)prc);
     489
     490    int rc;
     491    switch (__IOCLW(ulIOControl))
     492    {
     493        case __IOCLW(FGETHTYPE):
     494        {
     495            FS_VAR_SAVE_LOAD();
     496            ULONG fulType, fulFlags;
     497            rc = DosQueryHType(pFH->fh, &fulType, &fulFlags);
     498            FS_RESTORE();
     499            if (rc)
     500                break;
     501
     502            int *piHandleType = va_arg(va, int *);
     503            switch (fulType & 0xff)
     504            {
     505                case 0:                 /* File */
     506                    *piHandleType = HT_FILE;
     507                    break;
     508                case 1:                 /* Character device */
     509                    if (fulFlags & 3)
     510                        *piHandleType = HT_DEV_CON;
     511                    else if (fulFlags & 4)
     512                        *piHandleType = HT_DEV_NUL;
     513                    else if (fulFlags & 8)
     514                        *piHandleType = HT_DEV_CLK;
     515                    else
     516                        *piHandleType = HT_DEV_OTHER;
     517                    break;
     518                case 2:                 /* Pipe */
     519                    FS_SAVE_LOAD();
     520                    rc = DosQueryNPHState(pFH->fh, &fulFlags);
     521                    FS_RESTORE();
     522                    if (    rc == NO_ERROR
     523                        ||  rc == ERROR_PIPE_NOT_CONNECTED)
     524                        *piHandleType = HT_NPIPE;
     525                    else
     526                        *piHandleType = HT_UPIPE;
     527                    rc = 0;
     528                    break;
     529                default:
     530                    rc = -EINVAL;
     531                    break;
     532            }
     533            break;
     534        }
     535
     536/** @todo lots of FIO* things to go!! */
     537#if 0
     538
     539#define FIOCLEX          _IO('f', 1)            /* set close on exec on fd */
     540#define FIONCLEX         _IO('f', 2)            /* remove close on exec */
     541#define FIONREAD        _IOR('f', 127, int)     /* get # bytes to read */
     542#define FIONBIO         _IOW('f', 126, int)     /* set/clear non-blocking i/o */
     543#define FIOASYNC        _IOW('f', 125, int)     /* set/clear async i/o */
     544#define FIOSETOWN       _IOW('f', 124, int)     /* set owner */
     545#define FIOGETOWN       _IOR('f', 123, int)     /* get owner */
     546#define FIODTYPE        _IOR('f', 122, int)     /* get d_flags type part */
     547#define FIOGETLBA       _IOR('f', 121, int)     /* get start blk # */
     548
     549#endif
     550
     551        default:
     552            rc = -EINVAL;
     553            break;
     554    }
     555
     556    if (rc > 0)
     557        rc = -__libc_back_native2errno(rc);
     558    else if (!rc)
     559        LIBCLOG_RETURN_MSG(0, "ret 0 - *prc=%d (%#x)\n", *prc, *prc);
     560    LIBCLOG_ERROR_RETURN_INT(rc);
     561}
     562
    507563
    508564/** Select operation.
  • trunk/libc/src/libc/io/ioctl.c

    r2739 r2922  
     1#if 1
     2/* $Id: $ */
     3/** @file
     4 *
     5 * kLIBC - ioctl().
     6 *
     7 * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
     8 *
     9 *
     10 * This file is part of kLIBC.
     11 *
     12 * kLIBC is free software; you can redistribute it and/or modify
     13 * it under the terms of the GNU Lesser General Public License as published
     14 * by the Free Software Foundation; either version 2 of the License, or
     15 * (at your option) any later version.
     16 *
     17 * kLIBC is distributed in the hope that it will be useful,
     18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20 * GNU Lesser General Public License for more details.
     21 *
     22 * You should have received a copy of the GNU Lesser General Public License
     23 * along with kLIBC; if not, write to the Free Software
     24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     25 *
     26 */
     27
     28#include "libc-alias.h"
     29#include <sys/ioccom.h>
     30#include <io.h>
     31#include <stdarg.h>
     32#include <errno.h>
     33#include <sys/ioctl.h>
     34#include <klibc/backend.h>
     35#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
     36#include <klibc/logstrict.h>
     37
     38
     39int _STD(ioctl)(int fh, unsigned long ulIOControl, ...)
     40{
     41    LIBCLOG_ENTER("fh=%d ulIOControl=%#lx (%ul)\n", fh, ulIOControl, ulIOControl);
     42
     43    va_list va;
     44    va_start(va, ulIOControl);
     45    int rc2 = -1;
     46    int rc = __libc_Back_ioControl(fh, ulIOControl, va, &rc2);
     47    va_end(va);
     48
     49    if (!rc)
     50        LIBCLOG_RETURN_INT(rc2);
     51    errno = -rc;
     52    LIBCLOG_RETURN_INT(rc2);
     53}
     54
     55#else /** @todo make sure the extra massaging of stuff here is really moved to the backend. */
     56
    157/* ioctl.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes
    258                     -- Copyright (c) 2003 by Knut St. Osmunden */
     
    1672 */
    1773#define __IOCLW(a) ((unsigned short)(a))
    18 
     74#endif
    1975
    2076int _STD(ioctl) (int handle, unsigned long request, ...)
     
    95151    __libc_FHPut(pFH);
    96152    return rc;
     153#endif
    97154}
Note: See TracChangeset for help on using the changeset viewer.