secur32: Don't try to use ntlm_auth --use-cred-cache.
[wine] / dlls / mountmgr.sys / device.c
1 /*
2  * Dynamic devices support
3  *
4  * Copyright 2006 Alexandre Julliard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <assert.h>
25 #include <errno.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <sys/time.h>
29
30 #include "mountmgr.h"
31 #include "winreg.h"
32 #include "winuser.h"
33 #include "dbt.h"
34
35 #include "wine/library.h"
36 #include "wine/list.h"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
39
40 WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
41
42 #define MAX_DOS_DRIVES 26
43
44 static const WCHAR drive_types[][8] =
45 {
46     { 0 },                           /* DEVICE_UNKNOWN */
47     { 0 },                           /* DEVICE_HARDDISK */
48     {'h','d',0},                     /* DEVICE_HARDDISK_VOL */
49     {'f','l','o','p','p','y',0},     /* DEVICE_FLOPPY */
50     {'c','d','r','o','m',0},         /* DEVICE_CDROM */
51     {'n','e','t','w','o','r','k',0}, /* DEVICE_NETWORK */
52     {'r','a','m','d','i','s','k',0}  /* DEVICE_RAMDISK */
53 };
54
55 static const WCHAR drives_keyW[] = {'S','o','f','t','w','a','r','e','\\',
56                                     'W','i','n','e','\\','D','r','i','v','e','s',0};
57
58 struct dos_drive
59 {
60     struct list           entry;       /* entry in drives list */
61     char                 *udi;         /* unique identifier for dynamic drives */
62     int                   drive;       /* drive letter (0 = A: etc.) */
63     enum device_type      type;        /* drive type */
64     DEVICE_OBJECT        *device;      /* disk device allocated for this drive */
65     UNICODE_STRING        name;        /* device name */
66     UNICODE_STRING        symlink;     /* device symlink if any */
67     STORAGE_DEVICE_NUMBER devnum;      /* device number info */
68     struct mount_point   *dosdev;      /* DosDevices mount point */
69     struct mount_point   *volume;      /* Volume{xxx} mount point */
70     char                 *unix_device; /* unix device path */
71     char                 *unix_mount;  /* unix mount point path */
72 };
73
74 static struct list drives_list = LIST_INIT(drives_list);
75
76 static DRIVER_OBJECT *harddisk_driver;
77
78 static char *get_dosdevices_path( char **drive )
79 {
80     const char *config_dir = wine_get_config_dir();
81     size_t len = strlen(config_dir) + sizeof("/dosdevices/a::");
82     char *path = HeapAlloc( GetProcessHeap(), 0, len );
83     if (path)
84     {
85         strcpy( path, config_dir );
86         strcat( path, "/dosdevices/a::" );
87         *drive = path + len - 4;
88     }
89     return path;
90 }
91
92 static char *strdupA( const char *str )
93 {
94     char *ret;
95
96     if (!str) return NULL;
97     if ((ret = RtlAllocateHeap( GetProcessHeap(), 0, strlen(str) + 1 ))) strcpy( ret, str );
98     return ret;
99 }
100
101 /* read a Unix symlink; returned buffer must be freed by caller */
102 static char *read_symlink( const char *path )
103 {
104     char *buffer;
105     int ret, size = 128;
106
107     for (;;)
108     {
109         if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, size )))
110         {
111             SetLastError( ERROR_NOT_ENOUGH_MEMORY );
112             return 0;
113         }
114         ret = readlink( path, buffer, size );
115         if (ret == -1)
116         {
117             RtlFreeHeap( GetProcessHeap(), 0, buffer );
118             return 0;
119         }
120         if (ret != size)
121         {
122             buffer[ret] = 0;
123             return buffer;
124         }
125         RtlFreeHeap( GetProcessHeap(), 0, buffer );
126         size *= 2;
127     }
128 }
129
130 /* send notification about a change to a given drive */
131 static void send_notify( int drive, int code )
132 {
133     DWORD_PTR result;
134     DEV_BROADCAST_VOLUME info;
135
136     info.dbcv_size       = sizeof(info);
137     info.dbcv_devicetype = DBT_DEVTYP_VOLUME;
138     info.dbcv_reserved   = 0;
139     info.dbcv_unitmask   = 1 << drive;
140     info.dbcv_flags      = DBTF_MEDIA;
141     result = BroadcastSystemMessageW( BSF_FORCEIFHUNG|BSF_QUERY, NULL,
142                                       WM_DEVICECHANGE, code, (LPARAM)&info );
143 }
144
145 /* create the disk device for a given drive */
146 static NTSTATUS create_disk_device( const char *udi, enum device_type type, struct dos_drive **drive_ret )
147 {
148     static const WCHAR harddiskvolW[] = {'\\','D','e','v','i','c','e',
149                                          '\\','H','a','r','d','d','i','s','k','V','o','l','u','m','e','%','u',0};
150     static const WCHAR harddiskW[] = {'\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','%','u',0};
151     static const WCHAR cdromW[] = {'\\','D','e','v','i','c','e','\\','C','d','R','o','m','%','u',0};
152     static const WCHAR floppyW[] = {'\\','D','e','v','i','c','e','\\','F','l','o','p','p','y','%','u',0};
153     static const WCHAR ramdiskW[] = {'\\','D','e','v','i','c','e','\\','R','a','m','d','i','s','k','%','u',0};
154     static const WCHAR physdriveW[] = {'\\','?','?','\\','P','h','y','s','i','c','a','l','D','r','i','v','e','%','u',0};
155
156     UINT i, first = 0;
157     NTSTATUS status = 0;
158     const WCHAR *format = NULL;
159     UNICODE_STRING name;
160     DEVICE_OBJECT *dev_obj;
161     struct dos_drive *drive;
162
163     switch(type)
164     {
165     case DEVICE_UNKNOWN:
166     case DEVICE_HARDDISK:
167     case DEVICE_NETWORK:  /* FIXME */
168         format = harddiskW;
169         break;
170     case DEVICE_HARDDISK_VOL:
171         format = harddiskvolW;
172         first = 1;  /* harddisk volumes start counting from 1 */
173         break;
174     case DEVICE_FLOPPY:
175         format = floppyW;
176         break;
177     case DEVICE_CDROM:
178         format = cdromW;
179         break;
180     case DEVICE_RAMDISK:
181         format = ramdiskW;
182         break;
183     }
184
185     name.MaximumLength = (strlenW(format) + 10) * sizeof(WCHAR);
186     name.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, name.MaximumLength );
187     for (i = first; i < 32; i++)
188     {
189         sprintfW( name.Buffer, format, i );
190         name.Length = strlenW(name.Buffer) * sizeof(WCHAR);
191         status = IoCreateDevice( harddisk_driver, sizeof(*drive), &name, 0, 0, FALSE, &dev_obj );
192         if (status != STATUS_OBJECT_NAME_COLLISION) break;
193     }
194     if (!status)
195     {
196         drive = dev_obj->DeviceExtension;
197         drive->drive  = -1;
198         drive->device = dev_obj;
199         drive->name   = name;
200         drive->type   = type;
201         drive->dosdev = NULL;
202         drive->volume = NULL;
203         drive->unix_device = NULL;
204         drive->unix_mount  = NULL;
205         drive->symlink.Buffer = NULL;
206         if (udi)
207         {
208             if (!(drive->udi = HeapAlloc( GetProcessHeap(), 0, strlen(udi)+1 )))
209             {
210                 RtlFreeUnicodeString( &name );
211                 IoDeleteDevice( drive->device );
212                 return STATUS_NO_MEMORY;
213             }
214             strcpy( drive->udi, udi );
215         }
216         switch (type)
217         {
218         case DEVICE_FLOPPY:
219         case DEVICE_RAMDISK:
220             drive->devnum.DeviceType = FILE_DEVICE_DISK;
221             drive->devnum.DeviceNumber = i;
222             drive->devnum.PartitionNumber = ~0u;
223             break;
224         case DEVICE_CDROM:
225             drive->devnum.DeviceType = FILE_DEVICE_CD_ROM;
226             drive->devnum.DeviceNumber = i;
227             drive->devnum.PartitionNumber = ~0u;
228             break;
229         case DEVICE_UNKNOWN:
230         case DEVICE_HARDDISK:
231         case DEVICE_NETWORK:  /* FIXME */
232             {
233                 UNICODE_STRING symlink;
234
235                 symlink.MaximumLength = sizeof(physdriveW) + 10 * sizeof(WCHAR);
236                 if ((symlink.Buffer = RtlAllocateHeap( GetProcessHeap(), 0, symlink.MaximumLength)))
237                 {
238                     sprintfW( symlink.Buffer, physdriveW, i );
239                     symlink.Length = strlenW(symlink.Buffer) * sizeof(WCHAR);
240                     if (!IoCreateSymbolicLink( &symlink, &name )) drive->symlink = symlink;
241                 }
242                 drive->devnum.DeviceType = FILE_DEVICE_DISK;
243                 drive->devnum.DeviceNumber = i;
244                 drive->devnum.PartitionNumber = 0;
245             }
246             break;
247         case DEVICE_HARDDISK_VOL:
248             drive->devnum.DeviceType = FILE_DEVICE_DISK;
249             drive->devnum.DeviceNumber = 0;
250             drive->devnum.PartitionNumber = i;
251             break;
252         }
253         list_add_tail( &drives_list, &drive->entry );
254         *drive_ret = drive;
255         TRACE( "created device %s\n", debugstr_w(name.Buffer) );
256     }
257     else
258     {
259         FIXME( "IoCreateDevice %s got %x\n", debugstr_w(name.Buffer), status );
260         RtlFreeUnicodeString( &name );
261     }
262     return status;
263 }
264
265 /* delete the disk device for a given drive */
266 static void delete_disk_device( struct dos_drive *drive )
267 {
268     TRACE( "deleting device %s\n", debugstr_w(drive->name.Buffer) );
269     list_remove( &drive->entry );
270     if (drive->dosdev) delete_mount_point( drive->dosdev );
271     if (drive->volume) delete_mount_point( drive->volume );
272     if (drive->symlink.Buffer)
273     {
274         IoDeleteSymbolicLink( &drive->symlink );
275         RtlFreeUnicodeString( &drive->symlink );
276     }
277     RtlFreeHeap( GetProcessHeap(), 0, drive->unix_device );
278     RtlFreeHeap( GetProcessHeap(), 0, drive->unix_mount );
279     RtlFreeHeap( GetProcessHeap(), 0, drive->udi );
280     RtlFreeUnicodeString( &drive->name );
281     IoDeleteDevice( drive->device );
282 }
283
284 /* set or change the drive letter for an existing drive */
285 static void set_drive_letter( struct dos_drive *drive, int letter )
286 {
287     void *id = NULL;
288     unsigned int id_len = 0;
289
290     if (drive->drive == letter) return;
291     if (drive->dosdev) delete_mount_point( drive->dosdev );
292     if (drive->volume) delete_mount_point( drive->volume );
293     drive->drive = letter;
294     if (letter == -1) return;
295     if (drive->unix_mount)
296     {
297         id = drive->unix_mount;
298         id_len = strlen( drive->unix_mount ) + 1;
299     }
300     drive->dosdev = add_dosdev_mount_point( drive->device, &drive->name, letter, id, id_len );
301     drive->volume = add_volume_mount_point( drive->device, &drive->name, letter, id, id_len );
302 }
303
304 static inline int is_valid_device( struct stat *st )
305 {
306 #if defined(linux) || defined(__sun__)
307     return S_ISBLK( st->st_mode );
308 #else
309     /* disks are char devices on *BSD */
310     return S_ISCHR( st->st_mode );
311 #endif
312 }
313
314 /* find or create a DOS drive for the corresponding device */
315 static int add_drive( const char *device, enum device_type type )
316 {
317     char *path, *p;
318     char in_use[26];
319     struct stat dev_st, drive_st;
320     int drive, first, last, avail = 0;
321
322     if (stat( device, &dev_st ) == -1 || !is_valid_device( &dev_st )) return -1;
323
324     if (!(path = get_dosdevices_path( &p ))) return -1;
325
326     memset( in_use, 0, sizeof(in_use) );
327
328     switch (type)
329     {
330     case DEVICE_FLOPPY:
331         first = 0;
332         last = 2;
333         break;
334     case DEVICE_CDROM:
335         first = 3;
336         last = 26;
337         break;
338     default:
339         first = 2;
340         last = 26;
341         break;
342     }
343
344     while (avail != -1)
345     {
346         avail = -1;
347         for (drive = first; drive < last; drive++)
348         {
349             if (in_use[drive]) continue;  /* already checked */
350             *p = 'a' + drive;
351             if (stat( path, &drive_st ) == -1)
352             {
353                 if (lstat( path, &drive_st ) == -1 && errno == ENOENT)  /* this is a candidate */
354                 {
355                     if (avail == -1)
356                     {
357                         p[2] = 0;
358                         /* if mount point symlink doesn't exist either, it's available */
359                         if (lstat( path, &drive_st ) == -1 && errno == ENOENT) avail = drive;
360                         p[2] = ':';
361                     }
362                 }
363                 else in_use[drive] = 1;
364             }
365             else
366             {
367                 in_use[drive] = 1;
368                 if (!is_valid_device( &drive_st )) continue;
369                 if (dev_st.st_rdev == drive_st.st_rdev) goto done;
370             }
371         }
372         if (avail != -1)
373         {
374             /* try to use the one we found */
375             drive = avail;
376             *p = 'a' + drive;
377             if (symlink( device, path ) != -1) goto done;
378             /* failed, retry the search */
379         }
380     }
381     drive = -1;
382
383 done:
384     HeapFree( GetProcessHeap(), 0, path );
385     return drive;
386 }
387
388 static BOOL set_unix_mount_point( struct dos_drive *drive, const char *mount_point )
389 {
390     char *path, *p;
391     BOOL modified = FALSE;
392
393     if (!(path = get_dosdevices_path( &p ))) return FALSE;
394     p[0] = 'a' + drive->drive;
395     p[2] = 0;
396
397     if (mount_point && mount_point[0])
398     {
399         /* try to avoid unlinking if already set correctly */
400         if (!drive->unix_mount || strcmp( drive->unix_mount, mount_point ))
401         {
402             unlink( path );
403             symlink( mount_point, path );
404             modified = TRUE;
405         }
406         RtlFreeHeap( GetProcessHeap(), 0, drive->unix_mount );
407         drive->unix_mount = strdupA( mount_point );
408         if (drive->dosdev) set_mount_point_id( drive->dosdev, mount_point, strlen(mount_point) + 1 );
409         if (drive->volume) set_mount_point_id( drive->volume, mount_point, strlen(mount_point) + 1 );
410     }
411     else
412     {
413         if (unlink( path ) != -1) modified = TRUE;
414         RtlFreeHeap( GetProcessHeap(), 0, drive->unix_mount );
415         drive->unix_mount = NULL;
416         if (drive->dosdev) set_mount_point_id( drive->dosdev, NULL, 0 );
417         if (drive->volume) set_mount_point_id( drive->volume, NULL, 0 );
418     }
419
420     HeapFree( GetProcessHeap(), 0, path );
421     return modified;
422 }
423
424 /* create devices for mapped drives */
425 static void create_drive_devices(void)
426 {
427     char *path, *p, *link, *device;
428     struct dos_drive *drive;
429     unsigned int i;
430     HKEY drives_key;
431     enum device_type drive_type;
432     WCHAR driveW[] = {'a',':',0};
433
434     if (!(path = get_dosdevices_path( &p ))) return;
435     if (RegOpenKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &drives_key )) drives_key = 0;
436
437     for (i = 0; i < MAX_DOS_DRIVES; i++)
438     {
439         p[0] = 'a' + i;
440         p[2] = 0;
441         if (!(link = read_symlink( path ))) continue;
442         p[2] = ':';
443         device = read_symlink( path );
444
445         drive_type = i < 2 ? DEVICE_FLOPPY : DEVICE_HARDDISK_VOL;
446         if (drives_key)
447         {
448             WCHAR buffer[32];
449             DWORD j, type, size = sizeof(buffer);
450
451             driveW[0] = 'a' + i;
452             if (!RegQueryValueExW( drives_key, driveW, NULL, &type, (BYTE *)buffer, &size ) &&
453                 type == REG_SZ)
454             {
455                 for (j = 0; j < sizeof(drive_types)/sizeof(drive_types[0]); j++)
456                     if (drive_types[j][0] && !strcmpiW( buffer, drive_types[j] ))
457                     {
458                         drive_type = j;
459                         break;
460                     }
461                 if (drive_type == DEVICE_FLOPPY && i >= 2) drive_type = DEVICE_HARDDISK;
462             }
463         }
464
465         if (!create_disk_device( NULL, drive_type, &drive ))
466         {
467             drive->unix_mount = link;
468             drive->unix_device = device;
469             set_drive_letter( drive, i );
470         }
471         else
472         {
473             RtlFreeHeap( GetProcessHeap(), 0, link );
474             RtlFreeHeap( GetProcessHeap(), 0, device );
475         }
476     }
477     RegCloseKey( drives_key );
478     RtlFreeHeap( GetProcessHeap(), 0, path );
479 }
480
481 /* create a new dos drive */
482 NTSTATUS add_dos_device( int letter, const char *udi, const char *device,
483                          const char *mount_point, enum device_type type )
484 {
485     struct dos_drive *drive, *next;
486
487     if (letter == -1)  /* auto-assign a letter */
488     {
489         letter = add_drive( device, type );
490         if (letter == -1) return STATUS_OBJECT_NAME_COLLISION;
491     }
492     else  /* simply reset the device symlink */
493     {
494         char *path, *p;
495
496         if (!(path = get_dosdevices_path( &p ))) return STATUS_NO_MEMORY;
497         *p = 'a' + letter;
498         unlink( path );
499         if (device) symlink( device, path );
500     }
501
502     LIST_FOR_EACH_ENTRY_SAFE( drive, next, &drives_list, struct dos_drive, entry )
503     {
504         if (udi && drive->udi && !strcmp( udi, drive->udi ))
505         {
506             if (type == drive->type) goto found;
507             delete_disk_device( drive );
508             continue;
509         }
510         if (drive->drive == letter) delete_disk_device( drive );
511     }
512
513     if (create_disk_device( udi, type, &drive )) return STATUS_NO_MEMORY;
514
515 found:
516     RtlFreeHeap( GetProcessHeap(), 0, drive->unix_device );
517     drive->unix_device = strdupA( device );
518     set_drive_letter( drive, letter );
519     set_unix_mount_point( drive, mount_point );
520
521     if (drive->drive != -1)
522     {
523         HKEY hkey;
524
525         TRACE( "added device %c: udi %s for %s on %s type %u\n",
526                     'a' + drive->drive, wine_dbgstr_a(udi), wine_dbgstr_a(device),
527                     wine_dbgstr_a(mount_point), type );
528
529         /* hack: force the drive type in the registry */
530         if (!RegCreateKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &hkey ))
531         {
532             const WCHAR *type_name = drive_types[type];
533             WCHAR name[3] = {'a',':',0};
534
535             name[0] += drive->drive;
536             if (!type_name[0] && type == DEVICE_HARDDISK) type_name = drive_types[DEVICE_FLOPPY];
537             if (type_name[0])
538                 RegSetValueExW( hkey, name, 0, REG_SZ, (const BYTE *)type_name,
539                                 (strlenW(type_name) + 1) * sizeof(WCHAR) );
540             else
541                 RegDeleteValueW( hkey, name );
542             RegCloseKey( hkey );
543         }
544
545         if (udi) send_notify( drive->drive, DBT_DEVICEARRIVAL );
546     }
547     return STATUS_SUCCESS;
548 }
549
550 /* remove an existing dos drive, by letter or udi */
551 NTSTATUS remove_dos_device( int letter, const char *udi )
552 {
553     HKEY hkey;
554     struct dos_drive *drive;
555
556     LIST_FOR_EACH_ENTRY( drive, &drives_list, struct dos_drive, entry )
557     {
558         if (letter != -1 && drive->drive != letter) continue;
559         if (udi)
560         {
561             if (!drive->udi) continue;
562             if (strcmp( udi, drive->udi )) continue;
563         }
564
565         if (drive->drive != -1)
566         {
567             BOOL modified = set_unix_mount_point( drive, NULL );
568
569             /* clear the registry key too */
570             if (!RegOpenKeyW( HKEY_LOCAL_MACHINE, drives_keyW, &hkey ))
571             {
572                 WCHAR name[3] = {'a',':',0};
573                 name[0] += drive->drive;
574                 RegDeleteValueW( hkey, name );
575                 RegCloseKey( hkey );
576             }
577
578             if (modified && udi) send_notify( drive->drive, DBT_DEVICEREMOVECOMPLETE );
579         }
580         delete_disk_device( drive );
581         return STATUS_SUCCESS;
582     }
583     return STATUS_NO_SUCH_DEVICE;
584 }
585
586 /* query information about an existing dos drive, by letter or udi */
587 NTSTATUS query_dos_device( int letter, enum device_type *type,
588                            const char **device, const char **mount_point )
589 {
590     struct dos_drive *drive;
591
592     LIST_FOR_EACH_ENTRY( drive, &drives_list, struct dos_drive, entry )
593     {
594         if (drive->drive != letter) continue;
595         if (type) *type = drive->type;
596         if (device) *device = drive->unix_device;
597         if (mount_point) *mount_point = drive->unix_mount;
598         return STATUS_SUCCESS;
599     }
600     return STATUS_NO_SUCH_DEVICE;
601 }
602
603 /* handler for ioctls on the harddisk device */
604 static NTSTATUS WINAPI harddisk_ioctl( DEVICE_OBJECT *device, IRP *irp )
605 {
606     IO_STACK_LOCATION *irpsp = irp->Tail.Overlay.s.u.CurrentStackLocation;
607     struct dos_drive *drive = device->DeviceExtension;
608
609     TRACE( "ioctl %x insize %u outsize %u\n",
610            irpsp->Parameters.DeviceIoControl.IoControlCode,
611            irpsp->Parameters.DeviceIoControl.InputBufferLength,
612            irpsp->Parameters.DeviceIoControl.OutputBufferLength );
613
614     switch(irpsp->Parameters.DeviceIoControl.IoControlCode)
615     {
616     case IOCTL_DISK_GET_DRIVE_GEOMETRY:
617     {
618         DISK_GEOMETRY info;
619         DWORD len = min( sizeof(info), irpsp->Parameters.DeviceIoControl.OutputBufferLength );
620
621         info.Cylinders.QuadPart = 10000;
622         info.MediaType = (drive->devnum.DeviceType == FILE_DEVICE_DISK) ? FixedMedia : RemovableMedia;
623         info.TracksPerCylinder = 255;
624         info.SectorsPerTrack = 63;
625         info.BytesPerSector = 512;
626         memcpy( irp->MdlAddress->StartVa, &info, len );
627         irp->IoStatus.Information = len;
628         irp->IoStatus.u.Status = STATUS_SUCCESS;
629         break;
630     }
631     case IOCTL_STORAGE_GET_DEVICE_NUMBER:
632     {
633         DWORD len = min( sizeof(drive->devnum), irpsp->Parameters.DeviceIoControl.OutputBufferLength );
634
635         memcpy( irp->MdlAddress->StartVa, &drive->devnum, len );
636         irp->IoStatus.Information = len;
637         irp->IoStatus.u.Status = STATUS_SUCCESS;
638         break;
639     }
640     case IOCTL_CDROM_READ_TOC:
641         irp->IoStatus.u.Status = STATUS_INVALID_DEVICE_REQUEST;
642         break;
643     default:
644         FIXME( "unsupported ioctl %x\n", irpsp->Parameters.DeviceIoControl.IoControlCode );
645         irp->IoStatus.u.Status = STATUS_NOT_SUPPORTED;
646         break;
647     }
648     return irp->IoStatus.u.Status;
649 }
650
651 /* driver entry point for the harddisk driver */
652 NTSTATUS WINAPI harddisk_driver_entry( DRIVER_OBJECT *driver, UNICODE_STRING *path )
653 {
654     struct dos_drive *drive;
655
656     harddisk_driver = driver;
657     driver->MajorFunction[IRP_MJ_DEVICE_CONTROL] = harddisk_ioctl;
658
659     /* create a harddisk0 device that isn't assigned to any drive */
660     create_disk_device( "harddisk0 placeholder", DEVICE_HARDDISK, &drive );
661
662     create_drive_devices();
663
664     return STATUS_SUCCESS;
665 }