Ignore:
Timestamp:
Jan 12, 2003, 5:19:37 PM (23 years ago)
Author:
sandervl
Message:

Ported & extended QueryDosDeviceA/W; implemented IOCTL_SCSI_GET_CAPABILITIES; don't fail CDIO init if media not present

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/dosdevice.cpp

    r7480 r9663  
    1 /* $Id: dosdevice.cpp,v 1.1 2001-11-29 10:31:07 phaller Exp $
     1/* $Id: dosdevice.cpp,v 1.2 2003-01-12 16:19:36 sandervl Exp $
    22 *
    33 * Win32 Kernel Symbolic Link Subsystem for OS/2
     
    55 * 2001/11/29 Patrick Haller <patrick.haller@innotek.de>
    66 *
     7 *
     8 * QueryDosDeviceA/W borrowed from Rewind (pre-LGPL Wine)
     9 * Copyright 1993 Erik Bos
     10 * Copyright 1996 Alexandre Julliard
     11 *
    712 * Project Odin Software License can be found in LICENSE.TXT
    813 *
     
    1823 *****************************************************************************/
    1924#include <os2win.h>
     25#include <stdio.h>
    2026#include <winnls.h>
    2127#include "unicode.h"
     
    7177          ));
    7278
     79  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    7380  return (FALSE);
    7481}
     
    98105          ));
    99106
     107  SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
    100108  return (FALSE);
    101109}
    102110
    103111
    104 /*****************************************************************************
    105  * Name      : DWORD QueryDosDeviceA
    106  * Purpose   : The QueryDosDevice function lets an application obtain information
    107  *             about MS-DOS device names. The function can obtain the current
    108  *             mapping for a particular MS-DOS device name. The function can also
    109  *             obtain a list of all existing MS-DOS device names.
    110  *             MS-DOS device names are stored as symbolic links in the Windows NT
    111  *             object name space. The code that converts an MS-DOS path into a
    112  *             corresponding Windows NT path uses these symbolic links to map
    113  *             MS-DOS devices and drive letters. The QueryDosDevice function
    114  *             provides a mechanism whereby a Win32-based application can query
    115  *             the names of the symbolic links used to implement the MS-DOS device
    116  *             namespace as well as the value of each specific symbolic link.
    117  * Parameters: LPCTSTR lpDeviceName address of MS-DOS device name string
    118  *             LPTSTR  lpTargetPath ddress of buffer for storing query results
    119  *             DWORD   ucchMax       maximum storage capacity of buffer
    120  * Variables :
    121  * Result    : pointer to lpTargetPath
    122  * Remark    :
    123  * Status    : UNTESTED STUB
    124  *
    125  * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    126  *****************************************************************************/
    127 
    128 DWORD WIN32API QueryDosDeviceA(LPCTSTR lpDeviceName,
    129                                LPTSTR  lpTargetPath,
    130                                DWORD   ucchMax)
    131 {
    132   dprintf(("Kernel32: QueryDosDeviceA(%s,%08xh,%08xh) not implemented.\n",
    133            lpDeviceName,
    134            lpTargetPath,
    135            ucchMax));
    136 
    137   return (0);
    138 }
    139 
    140 
    141 /*****************************************************************************
    142  * Name      : DWORD QueryDosDeviceW
    143  * Purpose   : The QueryDosDevice function lets an application obtain information
    144  *             about MS-DOS device names. The function can obtain the current
    145  *             mapping for a particular MS-DOS device name. The function can also
    146  *             obtain a list of all existing MS-DOS device names.
    147  *             MS-DOS device names are stored as symbolic links in the Windows NT
    148  *             object name space. The code that converts an MS-DOS path into a
    149  *             corresponding Windows NT path uses these symbolic links to map
    150  *             MS-DOS devices and drive letters. The QueryDosDevice function
    151  *             provides a mechanism whereby a Win32-based application can query
    152  *             the names of the symbolic links used to implement the MS-DOS device
    153  *             namespace as well as the value of each specific symbolic link.
    154  * Parameters: LPCTSTR lpDeviceName address of MS-DOS device name string
    155  *             LPTSTR  lpTargetPath ddress of buffer for storing query results
    156  *             DWORD   ucchMax       maximum storage capacity of buffer
    157  * Variables :
    158  * Result    : pointer to lpTargetPath
    159  * Remark    :
    160  * Status    : UNTESTED STUB
    161  *
    162  * Author    : Patrick Haller [Mon, 1998/06/15 08:00]
    163  *****************************************************************************/
    164 
    165 DWORD WIN32API QueryDosDeviceW(LPCWSTR lpDeviceName,
    166                                LPWSTR  lpTargetPath,
    167                                DWORD   ucchMax)
    168 {
    169   dprintf(("Kernel32: QueryDosDeviceW(%s,%08xh,%08xh) not implemented.\n",
    170            lpDeviceName,
    171            lpTargetPath,
    172            ucchMax));
    173 
    174   return (0);
    175 }
     112/***********************************************************************
     113 *           QueryDosDeviceA   (KERNEL32.@)
     114 *
     115 * returns array of strings terminated by \0, terminated by \0
     116 */
     117DWORD WINAPI QueryDosDeviceA(LPCSTR devname,LPSTR target,DWORD bufsize)
     118{
     119    LPSTR s;
     120    char  buffer[200];
     121
     122    dprintf(("(%s,...)\n", devname ? devname : "<null>"));
     123    if (!devname) {
     124        /* return known MSDOS devices */
     125#ifdef __WIN32OS2__
     126        static const char devices[24] = "CON\0COM1\0COM2\0LPT1\0NUL\0";
     127        if(bufsize < 128 + sizeof(devices)) {
     128            SetLastError(ERROR_INSUFFICIENT_BUFFER);
     129            return 0;
     130        }
     131
     132        memcpy( target, devices, sizeof(devices) );
     133
     134        //Add all valid drive letters
     135        int drivemask = GetLogicalDrives();
     136        ULONG mask = 1;
     137        int i, len = 0;
     138        char *ptr = target+sizeof(devices)-1;
     139
     140        for(i=0;i<26;i++)
     141        {
     142            if(drivemask & mask)
     143            {
     144                len += 3;
     145                *ptr++ = (char)('A' + i);
     146                *ptr++ = ':';
     147                *ptr++ = 0;
     148            }
     149            mask <<= 1;
     150        }
     151        *ptr = 0;
     152       
     153        SetLastError(ERROR_SUCCESS);
     154        return sizeof(devices)+len;
     155#else
     156        static const char devices[24] = "CON\0COM1\0COM2\0LPT1\0NUL\0\0";
     157        memcpy( target, devices, min(bufsize,sizeof(devices)) );
     158        return min(bufsize,sizeof(devices));
     159#endif
     160    }
     161    /* In theory all that are possible and have been defined.
     162     * Now just those below, since mirc uses it to check for special files.
     163     *
     164     * (It is more complex, and supports netmounted stuff, and \\.\ stuff,
     165     *  but currently we just ignore that.)
     166     */
     167#define CHECK(x) (strstr(devname,#x)==devname)
     168    if (CHECK(con) || CHECK(com) || CHECK(lpt) || CHECK(nul)) {
     169        strcpy(buffer,"\\DEV\\");
     170        strcat(buffer,devname);
     171        if ((s=strchr(buffer,':'))) *s='\0';
     172        lstrcpynA(target,buffer,bufsize);
     173        return strlen(buffer)+1;
     174    } else {
     175#ifdef __WIN32OS2__
     176        if(devname[1] == ':' && devname[2] == 0) {
     177            int ret = GetDriveTypeA(devname);
     178            if(ret != DRIVE_UNKNOWN)
     179            {
     180                if(bufsize < 16) {
     181                    SetLastError(ERROR_INSUFFICIENT_BUFFER);
     182                    return 0;
     183                }
     184                sprintf(target, "\\\\.\\%s", devname);
     185                SetLastError(ERROR_SUCCESS);
     186                return strlen(target)+1;
     187            }
     188        }
     189#endif
     190        if (strchr(devname,':') || devname[0]=='\\') {
     191            /* This might be a DOS device we do not handle yet ... */
     192            dprintf(("(%s) not detected as DOS device!\n",devname));
     193        }
     194        SetLastError(ERROR_DEV_NOT_EXIST);
     195        return 0;
     196    }
     197}
     198
     199
     200/***********************************************************************
     201 *           QueryDosDeviceW   (KERNEL32.@)
     202 *
     203 * returns array of strings terminated by \0, terminated by \0
     204 */
     205DWORD WINAPI QueryDosDeviceW(LPCWSTR devname,LPWSTR target,DWORD bufsize)
     206{
     207    LPSTR devnameA = devname?HEAP_strdupWtoA(GetProcessHeap(),0,devname):NULL;
     208    LPSTR targetA = (LPSTR)HeapAlloc(GetProcessHeap(),0,bufsize);
     209    DWORD ret = QueryDosDeviceA(devnameA,targetA,bufsize);
     210
     211    ret = MultiByteToWideChar( CP_ACP, 0, targetA, ret, target, bufsize );
     212    if (devnameA) HeapFree(GetProcessHeap(),0,devnameA);
     213    if (targetA) HeapFree(GetProcessHeap(),0,targetA);
     214    return ret;
     215}
Note: See TracChangeset for help on using the changeset viewer.