[9663] | 1 | /* $Id: dosdevice.cpp,v 1.2 2003-01-12 16:19:36 sandervl Exp $
|
---|
[7480] | 2 | *
|
---|
| 3 | * Win32 Kernel Symbolic Link Subsystem for OS/2
|
---|
| 4 | *
|
---|
| 5 | * 2001/11/29 Patrick Haller <patrick.haller@innotek.de>
|
---|
| 6 | *
|
---|
[9663] | 7 | *
|
---|
| 8 | * QueryDosDeviceA/W borrowed from Rewind (pre-LGPL Wine)
|
---|
| 9 | * Copyright 1993 Erik Bos
|
---|
| 10 | * Copyright 1996 Alexandre Julliard
|
---|
[21916] | 11 | *
|
---|
[7480] | 12 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 13 | *
|
---|
| 14 | */
|
---|
| 15 |
|
---|
| 16 | /* To Do:
|
---|
| 17 | * - implement both APIs using the HandleNames symbolic link resolver
|
---|
| 18 | */
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | /*****************************************************************************
|
---|
| 22 | * Includes *
|
---|
| 23 | *****************************************************************************/
|
---|
| 24 | #include <os2win.h>
|
---|
[9663] | 25 | #include <stdio.h>
|
---|
[21916] | 26 | #include <string.h>
|
---|
[7480] | 27 | #include <winnls.h>
|
---|
| 28 | #include "unicode.h"
|
---|
| 29 | #include "handlemanager.h"
|
---|
| 30 | #include "handlenames.h"
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | /*****************************************************************************
|
---|
| 34 | * Defines *
|
---|
| 35 | *****************************************************************************/
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | // For DefineDosDevice
|
---|
| 39 |
|
---|
| 40 | #define DDD_RAW_TARGET_PATH 0x00000001
|
---|
| 41 | #define DDD_REMOVE_DEFINITION 0x00000002
|
---|
| 42 | #define DDD_EXACT_MATCH_ON_REMOVE 0x00000004
|
---|
| 43 | #define DDD_NO_BROADCAST_SYSTEM 0x00000008
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 | /*****************************************************************************
|
---|
| 48 | * Name : BOOL WIN32API DefineDosDeviceA
|
---|
| 49 | * Purpose : The DefineDosDeviceA function lets an application define,
|
---|
| 50 | * redefine, or delete MS-DOS device names.
|
---|
| 51 | * MS-DOS device names are stored as symbolic links in the object
|
---|
| 52 | * name space in 32-bit versions of Windows. The code that converts
|
---|
| 53 | * an MS-DOS path into a corresponding path in 32-bit versions of
|
---|
| 54 | * Windows uses these symbolic links to map MS-DOS devices and drive
|
---|
| 55 | * letters. The DefineDosDevice function provides a mechanism
|
---|
| 56 | * whereby a Win32-based application can modify the symbolic links
|
---|
| 57 | * used to implement the MS-DOS device name space.
|
---|
| 58 | * Parameters: DWORD dwFlags flags specifying aspects of device definition
|
---|
| 59 | * LPCSTR lpDeviceName pointer to MS-DOS device name string
|
---|
| 60 | * LPCSTR lpTargetPath pointer to MS-DOS or path string for
|
---|
| 61 | * 32-bit Windows
|
---|
| 62 | * Variables :
|
---|
| 63 | * Result : If the function succeeds, the return value is nonzero.
|
---|
| 64 | * If the function fails, the return value is zero
|
---|
| 65 | * Remark :
|
---|
| 66 | * Status : UNTESTED STUB
|
---|
| 67 | *
|
---|
| 68 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
| 69 | *****************************************************************************/
|
---|
| 70 |
|
---|
| 71 | BOOL WIN32API DefineDosDeviceA( DWORD dwFlags, LPCSTR lpDeviceName,
|
---|
| 72 | LPCSTR lpTargetPath )
|
---|
| 73 | {
|
---|
| 74 |
|
---|
| 75 | dprintf(("KERNEL32: DefineDosDeviceA(%08x,%08x,%08x) not implemented\n",
|
---|
| 76 | dwFlags, lpDeviceName, lpTargetPath
|
---|
| 77 | ));
|
---|
| 78 |
|
---|
[9663] | 79 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
[7480] | 80 | return (FALSE);
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /*****************************************************************************
|
---|
| 84 | * Name : BOOL WIN32API DefineDosDeviceW
|
---|
| 85 | * Purpose : UNICODE version of DefineDosDeviceA
|
---|
| 86 | * Parameters: DWORD dwFlags flags specifying aspects of device definition
|
---|
| 87 | * LPCSTR lpDeviceName pointer to MS-DOS device name string
|
---|
| 88 | * LPCSTR lpTargetPath pointer to MS-DOS or path string for
|
---|
| 89 | * 32-bit Windows
|
---|
| 90 | * Variables :
|
---|
| 91 | * Result : If the function succeeds, the return value is nonzero.
|
---|
| 92 | * If the function fails, the return value is zero
|
---|
| 93 | * Remark :
|
---|
| 94 | * Status : UNTESTED STUB
|
---|
| 95 | *
|
---|
| 96 | * Author : Markus Montkowski [Tha, 1998/05/21 17:46]
|
---|
| 97 | *****************************************************************************/
|
---|
| 98 |
|
---|
| 99 | BOOL WIN32API DefineDosDeviceW( DWORD dwFlags, LPCWSTR lpDeviceName,
|
---|
| 100 | LPCWSTR lpTargetPath )
|
---|
| 101 | {
|
---|
| 102 |
|
---|
| 103 | dprintf(("KERNEL32: DefineDosDeviceW(%08x,%08x,%08x) not implemented\n",
|
---|
| 104 | dwFlags, lpDeviceName, lpTargetPath
|
---|
| 105 | ));
|
---|
| 106 |
|
---|
[9663] | 107 | SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
---|
[7480] | 108 | return (FALSE);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
[9663] | 112 | /***********************************************************************
|
---|
| 113 | * QueryDosDeviceA (KERNEL32.@)
|
---|
[7480] | 114 | *
|
---|
[9663] | 115 | * returns array of strings terminated by \0, terminated by \0
|
---|
| 116 | */
|
---|
| 117 | DWORD WINAPI QueryDosDeviceA(LPCSTR devname,LPSTR target,DWORD bufsize)
|
---|
[7480] | 118 | {
|
---|
[9663] | 119 | LPSTR s;
|
---|
| 120 | char buffer[200];
|
---|
[7480] | 121 |
|
---|
[9663] | 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;
|
---|
[21916] | 152 |
|
---|
[9663] | 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);
|
---|
[21355] | 171 | if ((s=strchr(buffer,':')) != NULL) *s='\0';
|
---|
[9663] | 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);
|
---|
[21916] | 178 | if(ret != DRIVE_UNKNOWN)
|
---|
[9663] | 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 | }
|
---|
[7480] | 197 | }
|
---|
| 198 |
|
---|
| 199 |
|
---|
[9663] | 200 | /***********************************************************************
|
---|
| 201 | * QueryDosDeviceW (KERNEL32.@)
|
---|
[7480] | 202 | *
|
---|
[9663] | 203 | * returns array of strings terminated by \0, terminated by \0
|
---|
| 204 | */
|
---|
| 205 | DWORD WINAPI QueryDosDeviceW(LPCWSTR devname,LPWSTR target,DWORD bufsize)
|
---|
[7480] | 206 | {
|
---|
[9663] | 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);
|
---|
[7480] | 210 |
|
---|
[9663] | 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;
|
---|
[7480] | 215 | }
|
---|