source: trunk/src/kernel32/dosdevice.cpp@ 21916

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 7.4 KB
Line 
1/* $Id: dosdevice.cpp,v 1.2 2003-01-12 16:19:36 sandervl Exp $
2 *
3 * Win32 Kernel Symbolic Link Subsystem for OS/2
4 *
5 * 2001/11/29 Patrick Haller <patrick.haller@innotek.de>
6 *
7 *
8 * QueryDosDeviceA/W borrowed from Rewind (pre-LGPL Wine)
9 * Copyright 1993 Erik Bos
10 * Copyright 1996 Alexandre Julliard
11 *
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>
25#include <stdio.h>
26#include <string.h>
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
71BOOL 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
79 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
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
99BOOL 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
107 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
108 return (FALSE);
109}
110
111
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,':')) != NULL) *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 TracBrowser for help on using the repository browser.