MSVC compatibility fixes.
[wine] / msdos / int21.c
1 /*
2  * DOS interrupt 21h handler
3  *
4  * Copyright 1993, 1994 Erik Bos
5  * Copyright 1996 Alexandre Julliard
6  * Copyright 1997 Andreas Mohr
7  * Copyright 1998 Uwe Bonnes
8  * Copyright 1998, 1999 Ove Kaaven
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23  */
24
25 #include "config.h"
26
27 #include <time.h>
28 #include <fcntl.h>
29 #include <errno.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #ifdef HAVE_SYS_FILE_H
33 # include <sys/file.h>
34 #endif
35 #include <string.h>
36 #ifdef HAVE_SYS_TIME_H
37 # include <sys/time.h>
38 #endif
39 #include <sys/types.h>
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 #ifdef HAVE_UTIME_H
44 # include <utime.h>
45 #endif
46 #include <ctype.h>
47 #include "windef.h"
48 #include "winbase.h"
49 #include "ntddk.h"
50 #include "wingdi.h"
51 #include "winuser.h" /* SW_NORMAL */
52 #include "wine/winbase16.h"
53 #include "winerror.h"
54 #include "drive.h"
55 #include "file.h"
56 #include "callback.h"
57 #include "msdos.h"
58 #include "miscemu.h"
59 #include "task.h"
60 #include "wine/debug.h"
61
62 WINE_DEFAULT_DEBUG_CHANNEL(int21);
63 #if defined(__svr4__) || defined(_SCO_DS)
64 /* SVR4 DOESNT do locking the same way must implement properly */
65 #define LOCK_EX 0
66 #define LOCK_SH  1
67 #define LOCK_NB  8
68 #endif
69
70
71 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
72
73 /* Define the drive parameter block, as used by int21/1F
74  * and int21/32.  This table can be accessed through the
75  * global 'dpb' pointer, which points into the local dos
76  * heap.
77  */
78 struct DPB
79 {
80     BYTE drive_num;         /* 0=A, etc. */
81     BYTE unit_num;          /* Drive's unit number (?) */
82     WORD sector_size;       /* Sector size in bytes */
83     BYTE high_sector;       /* Highest sector in a cluster */
84     BYTE shift;             /* Shift count (?) */
85     WORD reserved;          /* Number of reserved sectors at start */
86     BYTE num_FAT;           /* Number of FATs */
87     WORD dir_entries;       /* Number of root dir entries */
88     WORD first_data;        /* First data sector */
89     WORD high_cluster;      /* Highest cluster number */
90     WORD sectors_in_FAT;    /* Number of sectors per FAT */
91     WORD start_dir;         /* Starting sector of first dir */
92     DWORD driver_head;      /* Address of device driver header (?) */
93     BYTE media_ID;          /* Media ID */
94     BYTE access_flag;       /* Prev. accessed flag (0=yes,0xFF=no) */
95     DWORD next;             /* Pointer to next DPB in list */
96     WORD free_search;       /* Free cluster search start */
97     WORD free_clusters;     /* Number of free clusters (0xFFFF=unknown) */
98 };
99
100 struct EDPB                     /* FAT32 extended Drive Parameter Block */
101 {                               /* from Ralf Brown's Interrupt List */
102         struct DPB dpb;         /* first 24 bytes = original DPB */
103
104         BYTE edpb_flags;        /* undocumented/unknown flags */
105         DWORD next_edpb;        /* pointer to next EDPB */
106         WORD free_cluster;      /* cluster to start search for free space on write, typically
107                                    the last cluster allocated */
108         WORD clusters_free;     /* number of free clusters on drive or FFFF = unknown */
109         WORD clusters_free_hi;  /* hiword of clusters_free */
110         WORD mirroring_flags;   /* mirroring flags: bit 7 set = do not mirror active FAT */
111                                 /* bits 0-3 = 0-based number of the active FAT */
112         WORD info_sector;       /* sector number of file system info sector, or FFFF for none */
113         WORD spare_boot_sector; /* sector number of backup boot sector, or FFFF for none */
114         DWORD first_cluster;    /* sector number of the first cluster */
115         DWORD max_cluster;      /* sector number of the last cluster */
116         DWORD fat_clusters;     /* number of clusters occupied by FAT */
117         DWORD root_cluster;     /* cluster number of start of root directory */
118         DWORD free_cluster2;    /* same as free_cluster: cluster at which to start
119                                    search for free space when writing */
120
121 };
122
123 WORD CodePage = 437;
124 DWORD dpbsegptr;
125
126 struct DosHeap {
127         BYTE InDosFlag;
128         BYTE mediaID;
129         BYTE biosdate[8];
130         struct DPB dpb;
131         BYTE DummyDBCSLeadTable[6];
132 };
133 static struct DosHeap *heap;
134 static WORD DosHeapHandle;
135
136 extern char TempDirectory[];
137
138 static void INT21_ReadConfigSys(void)
139 {
140     static int done;
141     if (!done) DOSCONF_ReadConfig();
142     done = 1;
143 }
144
145 static BOOL INT21_CreateHeap(void)
146 {
147     if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
148     {
149         WARN("Out of memory\n");
150         return FALSE;
151     }
152     heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
153     dpbsegptr = MAKESEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
154     heap->InDosFlag = 0;
155     strcpy(heap->biosdate, "01/01/80");
156     memset(heap->DummyDBCSLeadTable, 0, 6);
157     return TRUE;
158 }
159
160 static BYTE *GetCurrentDTA( CONTEXT86 *context )
161 {
162     TDB *pTask = TASK_GetCurrent();
163
164     /* FIXME: This assumes DTA was set correctly! */
165     return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
166                                                 (DWORD)OFFSETOF(pTask->dta) );
167 }
168
169
170 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
171 /* limited == TRUE is used with INT 0x21/0x440d */
172 {
173         if (drive > 1) {
174                 setword(data, 512);
175                 data[2] = 2;
176                 setword(&data[3], 0);
177                 data[5] = 2;
178                 setword(&data[6], 240);
179                 setword(&data[8], 64000);
180                 data[0x0a] = 0xf8;
181                 setword(&data[0x0b], 40);
182                 setword(&data[0x0d], 56);
183                 setword(&data[0x0f], 2);
184                 setword(&data[0x11], 0);
185                 if (!limited) {
186                     setword(&data[0x1f], 800);
187                     data[0x21] = 5;
188                     setword(&data[0x22], 1);
189                 }
190         } else { /* 1.44mb */
191                 setword(data, 512);
192                 data[2] = 2;
193                 setword(&data[3], 0);
194                 data[5] = 2;
195                 setword(&data[6], 240);
196                 setword(&data[8], 2880);
197                 data[0x0a] = 0xf8;
198                 setword(&data[0x0b], 6);
199                 setword(&data[0x0d], 18);
200                 setword(&data[0x0f], 2);
201                 setword(&data[0x11], 0);
202                 if (!limited) {
203                     setword(&data[0x1f], 80);
204                     data[0x21] = 7;
205                     setword(&data[0x22], 2);
206                 }
207         }
208 }
209
210 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
211 {
212     DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
213     char root[] = "A:\\";
214
215     *root += DOS_GET_DRIVE( DL_reg(context) );
216     if (!GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
217                               &free_clusters, &total_clusters )) return 0;
218     AX_reg(context) = cluster_sectors;
219     BX_reg(context) = free_clusters;
220     CX_reg(context) = sector_bytes;
221     DX_reg(context) = total_clusters;
222     return 1;
223 }
224
225 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
226 {
227     if (!INT21_GetFreeDiskSpace( context )) return 0;
228     if (!heap && !INT21_CreateHeap()) return 0;
229     heap->mediaID = 0xf0;
230     context->SegDs = DosHeapHandle;
231     BX_reg(context) = (int)&heap->mediaID - (int)heap;
232     return 1;
233 }
234
235 static int FillInDrivePB( int drive )
236 {
237         if(!DRIVE_IsValid(drive))
238         {
239             SetLastError( ERROR_INVALID_DRIVE );
240                         return 0;
241         }
242         else if (heap || INT21_CreateHeap())
243         {
244                 /* FIXME: I have no idea what a lot of this information should
245                  * say or whether it even really matters since we're not allowing
246                  * direct block access.  However, some programs seem to depend on
247                  * getting at least _something_ back from here.  The 'next' pointer
248                  * does worry me, though.  Should we have a complete table of
249                  * separate DPBs per drive?  Probably, but I'm lazy. :-)  -CH
250                  */
251                 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
252                 heap->dpb.sector_size = 512;
253                 heap->dpb.high_sector = 1;
254                 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
255                 heap->dpb.reserved = 0;
256                 heap->dpb.num_FAT = 1;
257                 heap->dpb.dir_entries = 2;
258                 heap->dpb.first_data = 2;
259                 heap->dpb.high_cluster = 64000;
260                 heap->dpb.sectors_in_FAT = 1;
261                 heap->dpb.start_dir = 1;
262                 heap->dpb.driver_head = 0;
263                 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
264                 heap->dpb.access_flag = 0;
265                 heap->dpb.next = 0;
266                 heap->dpb.free_search = 0;
267                 heap->dpb.free_clusters = 0xFFFF;    /* unknown */
268                                 return 1;
269                 }
270
271                 return 0;
272 }
273
274 static void GetDrivePB( CONTEXT86 *context, int drive )
275 {
276         if (FillInDrivePB( drive ))
277         {
278                 AL_reg(context) = 0x00;
279                 context->SegDs = SELECTOROF(dpbsegptr);
280                 BX_reg(context) = OFFSETOF(dpbsegptr);
281         }
282         else
283         {
284         AX_reg(context) = 0x00ff;
285         }
286 }
287
288
289 static void ioctlGetDeviceInfo( CONTEXT86 *context )
290 {
291     int curr_drive;
292     const DOS_DEVICE *dev;
293
294     TRACE("(%d)\n", BX_reg(context));
295
296     RESET_CFLAG(context);
297
298     /* DOS device ? */
299     if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )))
300     {
301         DX_reg(context) = dev->flags;
302         return;
303     }
304
305     /* it seems to be a file */
306     curr_drive = DRIVE_GetCurrentDrive();
307     DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
308     /* no floppy */
309     /* bits 0-5 are current drive
310      * bit 6 - file has NOT been written..FIXME: correct?
311      * bit 8 - generate int24 if no diskspace on write/ read past end of file
312      * bit 11 - media not removable
313      * bit 14 - don't set file date/time on closing
314      * bit 15 - file is remote
315      */
316 }
317
318 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
319 {
320         BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
321         int drive = DOS_GET_DRIVE( BL_reg(context) );
322
323         if (!DRIVE_IsValid(drive))
324         {
325             SetLastError( ERROR_FILE_NOT_FOUND );
326             return TRUE;
327         }
328
329         if (CH_reg(context) != 0x08)
330         {
331             INT_BARF( context, 0x21 );
332             return FALSE;
333         }
334
335         switch (CL_reg(context))
336         {
337                 case 0x4a: /* lock logical volume */
338                         TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
339                         break;
340
341                 case 0x60: /* get device parameters */
342                            /* used by w4wgrp's winfile */
343                         memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
344                         dataptr[0] = 0x04;
345                         dataptr[6] = 0; /* media type */
346                         if (drive > 1)
347                         {
348                                 dataptr[1] = 0x05; /* fixed disk */
349                                 setword(&dataptr[2], 0x01); /* non removable */
350                                 setword(&dataptr[4], 0x300); /* # of cylinders */
351                         }
352                         else
353                         {
354                                 dataptr[1] = 0x07; /* block dev, floppy */
355                                 setword(&dataptr[2], 0x02); /* removable */
356                                 setword(&dataptr[4], 80); /* # of cylinders */
357                         }
358                         CreateBPB(drive, &dataptr[7], TRUE);
359                         RESET_CFLAG(context);
360                         break;
361
362                 case 0x41: /* write logical device track */
363                 case 0x61: /* read logical device track */
364                         {
365                                 BYTE drive = BL_reg(context) ?
366                                                 BL_reg(context) : DRIVE_GetCurrentDrive();
367                                 WORD head   = *(WORD *)dataptr+1;
368                                 WORD cyl    = *(WORD *)dataptr+3;
369                                 WORD sect   = *(WORD *)dataptr+5;
370                                 WORD nrsect = *(WORD *)dataptr+7;
371                                 BYTE *data  =  (BYTE *)dataptr+9;
372                                 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
373
374                                 raw_func = (CL_reg(context) == 0x41) ?
375                                                                 DRIVE_RawWrite : DRIVE_RawRead;
376
377                                 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
378                                         RESET_CFLAG(context);
379                                 else
380                                 {
381                                         AX_reg(context) = 0x1e; /* read fault */
382                                         SET_CFLAG(context);
383                                 }
384                         }
385                         break;
386                 case 0x66:/*  get disk serial number */
387                         {
388                                 char    label[12],fsname[9],path[4];
389                                 DWORD   serial;
390
391                                 strcpy(path,"x:\\");path[0]=drive+'A';
392                                 GetVolumeInformationA(
393                                         path,label,12,&serial,NULL,NULL,fsname,9
394                                 );
395                                 *(WORD*)dataptr         = 0;
396                                 memcpy(dataptr+2,&serial,4);
397                                 memcpy(dataptr+6,label  ,11);
398                                 memcpy(dataptr+17,fsname,8);
399                         }
400                         break;
401
402                 case 0x6a:
403                         TRACE("logical volume %d unlocked.\n",drive);
404                         break;
405
406                 case 0x6f:
407                         memset(dataptr+1, '\0', dataptr[0]-1);
408                         dataptr[1] = dataptr[0];
409                         dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
410                         dataptr[3] = 0xFF; /* no physical drive */
411                         break;
412
413                 case 0x72:
414                         /* Trail on error implementation */
415                         AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_UNKNOWN ? 0x0f : 0x01;
416                         SET_CFLAG(context);     /* Seems to be set all the time */
417                         break;
418
419                 default:
420                         INT_BARF( context, 0x21 );
421         }
422         return FALSE;
423 }
424
425 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
426 {
427     char *filename =
428         CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
429     char *fcb =
430         CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi );
431     char *buffer, *s, *d;
432
433     AL_reg(context) = 0xff; /* failed */
434
435     TRACE("filename: '%s'\n", filename);
436
437     buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
438
439     s = filename;
440     d = buffer;
441     while (*s)
442     {
443         if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
444             *d++ = *s++;
445         else
446             break;
447     }
448
449     *d = '\0';
450     DOSFS_ToDosFCBFormat(buffer, fcb + 1);
451     *fcb = 0;
452     TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
453
454     HeapFree( GetProcessHeap(), 0, buffer);
455
456     AL_reg(context) =
457         ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
458
459     /* point DS:SI to first unparsed character */
460     SI_reg(context) += (int)s - (int)filename;
461 }
462
463 static void INT21_GetSystemDate( CONTEXT86 *context )
464 {
465     SYSTEMTIME systime;
466     GetLocalTime( &systime );
467     CX_reg(context) = systime.wYear;
468     DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
469     AX_reg(context) = systime.wDayOfWeek;
470 }
471
472 static void INT21_GetSystemTime( CONTEXT86 *context )
473 {
474     SYSTEMTIME systime;
475     GetLocalTime( &systime );
476     CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
477     DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
478 }
479
480 /* Many calls translate a drive argument like this:
481    drive number (00h = default, 01h = A:, etc)
482    */
483 static char drivestring[]="default";
484
485 char *INT21_DriveName(int drive)
486 {
487
488     if(drive >0)
489       {
490         drivestring[0]= (unsigned char)drive + '@';
491         drivestring[1]=':';
492         drivestring[2]=0;
493       }
494     return drivestring;
495 }
496 static BOOL INT21_CreateFile( CONTEXT86 *context )
497 {
498     AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
499                                           context->Edx ), CX_reg(context) );
500     return (AX_reg(context) == (WORD)HFILE_ERROR16);
501 }
502
503 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
504 {
505     /* Mask off all flags not explicitly allowed by the doc */
506     attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
507     return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
508                                              FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
509                                              CREATE_NEW, attr, 0 ));
510 }
511
512 static void OpenExistingFile( CONTEXT86 *context )
513 {
514     AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
515                                AL_reg(context) );
516     if (AX_reg(context) == (WORD)HFILE_ERROR16)
517     {
518         AX_reg(context) = GetLastError();
519         SET_CFLAG(context);
520     }
521 }
522
523 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
524 {
525   BOOL bExtendedError = FALSE;
526   BYTE action = DL_reg(context);
527
528   /* Shuffle arguments to call OpenExistingFile */
529   AL_reg(context) = BL_reg(context);
530   DX_reg(context) = SI_reg(context);
531   /* BX,CX and DX should be preserved */
532   OpenExistingFile(context);
533
534   if ((context->EFlags & 0x0001) == 0) /* File exists */
535   {
536       UINT16    uReturnCX = 0;
537
538       /* Now decide what do do */
539
540       if ((action & 0x07) == 0)
541       {
542           _lclose16( AX_reg(context) );
543           AX_reg(context) = 0x0050;     /*File exists*/
544           SET_CFLAG(context);
545           WARN("extended open/create: failed because file exists \n");
546       }
547       else if ((action & 0x07) == 2)
548       {
549         /* Truncate it, but first check if opened for write */
550         if ((BL_reg(context) & 0x0007)== 0)
551         {
552             _lclose16( AX_reg(context) );
553             WARN("extended open/create: failed, trunc on ro file\n");
554             AX_reg(context) = 0x000C;   /*Access code invalid*/
555             SET_CFLAG(context);
556         }
557         else
558         {
559                 TRACE("extended open/create: Closing before truncate\n");
560                 if (_lclose16( AX_reg(context) ))
561                 {
562                    WARN("extended open/create: close before trunc failed\n");
563                    AX_reg(context) = 0x0019;    /*Seek Error*/
564                    CX_reg(context) = 0;
565                    SET_CFLAG(context);
566                 }
567                 /* Shuffle arguments to call CreateFile */
568
569                 TRACE("extended open/create: Truncating\n");
570                 AL_reg(context) = BL_reg(context);
571                 /* CX is still the same */
572                 DX_reg(context) = SI_reg(context);
573                 bExtendedError = INT21_CreateFile(context);
574
575                 if (context->EFlags & 0x0001)   /*no file open, flags set */
576                 {
577                     WARN("extended open/create: trunc failed\n");
578                     return bExtendedError;
579                 }
580                 uReturnCX = 0x3;
581         }
582       }
583       else uReturnCX = 0x1;
584
585       CX_reg(context) = uReturnCX;
586   }
587   else /* file does not exist */
588   {
589       RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
590       if ((action & 0xF0)== 0)
591       {
592         CX_reg(context) = 0;
593         SET_CFLAG(context);
594         WARN("extended open/create: failed, file dosen't exist\n");
595       }
596       else
597       {
598         /* Shuffle arguments to call CreateFile */
599         TRACE("extended open/create: Creating\n");
600         AL_reg(context) = BL_reg(context);
601         /* CX should still be the same */
602         DX_reg(context) = SI_reg(context);
603         bExtendedError = INT21_CreateFile(context);
604         if (context->EFlags & 0x0001)  /*no file open, flags set */
605         {
606             WARN("extended open/create: create failed\n");
607             return bExtendedError;
608         }
609         CX_reg(context) = 2;
610       }
611   }
612
613   return bExtendedError;
614 }
615
616
617 static BOOL INT21_ChangeDir( CONTEXT86 *context )
618 {
619     int drive;
620     char *dirname = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
621
622     TRACE("changedir %s\n", dirname);
623     if (dirname[0] && (dirname[1] == ':'))
624     {
625         drive = toupper(dirname[0]) - 'A';
626         dirname += 2;
627     }
628     else drive = DRIVE_GetCurrentDrive();
629     return DRIVE_Chdir( drive, dirname );
630 }
631
632
633 static int INT21_FindFirst( CONTEXT86 *context )
634 {
635     char *p;
636     const char *path;
637     DOS_FULL_NAME full_name;
638     FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
639
640     path = (const char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
641     dta->unixPath = NULL;
642     if (!DOSFS_GetFullName( path, FALSE, &full_name ))
643     {
644         AX_reg(context) = GetLastError();
645         SET_CFLAG(context);
646         return 0;
647     }
648     dta->unixPath = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
649     strcpy( dta->unixPath, full_name.long_name );
650     p = strrchr( dta->unixPath, '/' );
651     *p = '\0';
652
653     /* Note: terminating NULL in dta->mask overwrites dta->search_attr
654      *       (doesn't matter as it is set below anyway)
655      */
656     if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
657     {
658         HeapFree( GetProcessHeap(), 0, dta->unixPath );
659         dta->unixPath = NULL;
660         SetLastError( ERROR_FILE_NOT_FOUND );
661         AX_reg(context) = ERROR_FILE_NOT_FOUND;
662         SET_CFLAG(context);
663         return 0;
664     }
665     dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
666                                                : DRIVE_GetCurrentDrive();
667     dta->count = 0;
668     dta->search_attr = CL_reg(context);
669     return 1;
670 }
671
672
673 static int INT21_FindNext( CONTEXT86 *context )
674 {
675     FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
676     WIN32_FIND_DATAA entry;
677     int count;
678
679     if (!dta->unixPath) return 0;
680     if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
681                                   dta->search_attr, dta->count, &entry )))
682     {
683         HeapFree( GetProcessHeap(), 0, dta->unixPath );
684         dta->unixPath = NULL;
685         return 0;
686     }
687     if ((int)dta->count + count > 0xffff)
688     {
689         WARN("Too many directory entries in %s\n", dta->unixPath );
690         HeapFree( GetProcessHeap(), 0, dta->unixPath );
691         dta->unixPath = NULL;
692         return 0;
693     }
694     dta->count += count;
695     dta->fileattr = entry.dwFileAttributes;
696     dta->filesize = entry.nFileSizeLow;
697     FileTimeToDosDateTime( &entry.ftLastWriteTime,
698                            &dta->filedate, &dta->filetime );
699     strcpy( dta->filename, entry.cAlternateFileName );
700     if (!memchr(dta->mask,'?',11)) {
701         /* wildcardless search, release resources in case no findnext will
702          * be issued, and as a workaround in case file creation messes up
703          * findnext, as sometimes happens with pkunzip */
704         HeapFree( GetProcessHeap(), 0, dta->unixPath );
705         dta->unixPath = NULL;
706     }
707     return 1;
708 }
709
710
711 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
712 {
713     static int counter = 0;
714     char *name = CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx );
715     char *p = name + strlen(name);
716
717     /* despite what Ralf Brown says, some programs seem to call without
718      * ending backslash (DOS accepts that, so we accept it too) */
719     if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
720
721     for (;;)
722     {
723         sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
724         counter = (counter + 1) % 1000;
725
726         if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
727         {
728             TRACE("created %s\n", name );
729             return TRUE;
730         }
731         if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
732     }
733 }
734
735
736 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
737 {
738     int drive = DOS_GET_DRIVE( DL_reg(context) );
739     char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Esi );
740
741     if (!DRIVE_IsValid(drive))
742     {
743         SetLastError( ERROR_INVALID_DRIVE );
744         return FALSE;
745     }
746     lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
747     AX_reg(context) = 0x0100;                        /* success return code */
748     return TRUE;
749 }
750
751
752 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
753 {
754     if (heap || INT21_CreateHeap())
755     { /* return an empty table just as DOS 4.0+ does */
756         context->SegDs = DosHeapHandle;
757         SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
758     }
759     else
760     {
761         AX_reg(context) = 0x1; /* error */
762         SET_CFLAG(context);
763     }
764 }
765
766
767 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
768 {
769     BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
770     int drive = DOS_GET_DRIVE( BL_reg(context) );
771
772     if (!DRIVE_IsValid(drive))
773     {
774         SetLastError( ERROR_INVALID_DRIVE );
775         return 0;
776     }
777
778     *(WORD *)dataptr = 0;
779     *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
780     memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
781     strncpy(dataptr + 0x11, "FAT16   ", 8);
782     return 1;
783 }
784
785
786 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
787 {
788     BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
789     int drive = DOS_GET_DRIVE( BL_reg(context) );
790
791     if (!DRIVE_IsValid(drive))
792     {
793         SetLastError( ERROR_INVALID_DRIVE );
794         return 0;
795     }
796
797     DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
798     return 1;
799 }
800
801
802 /* microsoft's programmers should be shot for using CP/M style int21
803    calls in Windows for Workgroup's winfile.exe */
804
805 static int INT21_FindFirstFCB( CONTEXT86 *context )
806 {
807     BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
808     FINDFILE_FCB *pFCB;
809     LPCSTR root, cwd;
810     int drive;
811
812     if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
813     else pFCB = (FINDFILE_FCB *)fcb;
814     drive = DOS_GET_DRIVE( pFCB->drive );
815     if (!DRIVE_IsValid( drive )) return 0;
816     root = DRIVE_GetRoot( drive );
817     cwd  = DRIVE_GetUnixCwd( drive );
818     pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
819                                 strlen(root)+strlen(cwd)+2 );
820     if (!pFCB->unixPath) return 0;
821     strcpy( pFCB->unixPath, root );
822     strcat( pFCB->unixPath, "/" );
823     strcat( pFCB->unixPath, cwd );
824     pFCB->count = 0;
825     return 1;
826 }
827
828
829 static int INT21_FindNextFCB( CONTEXT86 *context )
830 {
831     BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
832     FINDFILE_FCB *pFCB;
833     DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
834     WIN32_FIND_DATAA entry;
835     BYTE attr;
836     int count;
837
838     if (*fcb == 0xff) /* extended FCB ? */
839     {
840         attr = fcb[6];
841         pFCB = (FINDFILE_FCB *)(fcb + 7);
842     }
843     else
844     {
845         attr = 0;
846         pFCB = (FINDFILE_FCB *)fcb;
847     }
848
849     if (!pFCB->unixPath) return 0;
850     if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
851                                   DOS_GET_DRIVE( pFCB->drive ), attr,
852                                   pFCB->count, &entry )))
853     {
854         HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
855         pFCB->unixPath = NULL;
856         return 0;
857     }
858     pFCB->count += count;
859
860     if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
861         *(BYTE *)pResult = 0xff;
862         (BYTE *)pResult +=6; /* leave reserved field behind */
863         *(BYTE *)pResult = entry.dwFileAttributes;
864         ((BYTE *)pResult)++;
865     }
866     *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
867     ((BYTE *)pResult)++;
868     pResult->fileattr = entry.dwFileAttributes;
869     pResult->cluster  = 0;  /* what else? */
870     pResult->filesize = entry.nFileSizeLow;
871     memset( pResult->reserved, 0, sizeof(pResult->reserved) );
872     FileTimeToDosDateTime( &entry.ftLastWriteTime,
873                            &pResult->filedate, &pResult->filetime );
874
875     /* Convert file name to FCB format */
876
877     memset( pResult->filename, ' ', sizeof(pResult->filename) );
878     if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
879     else if (!strcmp( entry.cAlternateFileName, ".." ))
880         pResult->filename[0] = pResult->filename[1] = '.';
881     else
882     {
883         char *p = strrchr( entry.cAlternateFileName, '.' );
884         if (p && p[1] && (p != entry.cAlternateFileName))
885         {
886             memcpy( pResult->filename, entry.cAlternateFileName,
887                     min( (p - entry.cAlternateFileName), 8 ) );
888             memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
889         }
890         else
891             memcpy( pResult->filename, entry.cAlternateFileName,
892                     min( strlen(entry.cAlternateFileName), 8 ) );
893     }
894     return 1;
895 }
896
897
898 static void DeleteFileFCB( CONTEXT86 *context )
899 {
900     FIXME("(%p): stub\n", context);
901 }
902
903 static void RenameFileFCB( CONTEXT86 *context )
904 {
905     FIXME("(%p): stub\n", context);
906 }
907
908
909
910 static void fLock( CONTEXT86 * context )
911 {
912
913     switch ( AX_reg(context) & 0xff )
914     {
915         case 0x00: /* LOCK */
916           TRACE("lock handle %d offset %ld length %ld\n",
917                 BX_reg(context),
918                 MAKELONG(DX_reg(context),CX_reg(context)),
919                 MAKELONG(DI_reg(context),SI_reg(context))) ;
920           if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context)),
921                         MAKELONG(DX_reg(context),CX_reg(context)), 0,
922                         MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
923             AX_reg(context) = GetLastError();
924             SET_CFLAG(context);
925           }
926           break;
927
928         case 0x01: /* UNLOCK */
929           TRACE("unlock handle %d offset %ld length %ld\n",
930                 BX_reg(context),
931                 MAKELONG(DX_reg(context),CX_reg(context)),
932                 MAKELONG(DI_reg(context),SI_reg(context))) ;
933           if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context)),
934                           MAKELONG(DX_reg(context),CX_reg(context)), 0,
935                           MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
936             AX_reg(context) = GetLastError();
937             SET_CFLAG(context);
938           }
939           return;
940         default:
941           AX_reg(context) = 0x0001;
942           SET_CFLAG(context);
943           return;
944      }
945 }
946
947 static BOOL
948 INT21_networkfunc (CONTEXT86 *context)
949 {
950      switch (AL_reg(context)) {
951      case 0x00: /* Get machine name. */
952      {
953           char *dst = CTX_SEG_OFF_TO_LIN (context,context->SegDs,context->Edx);
954           TRACE("getting machine name to %p\n", dst);
955           if (gethostname (dst, 15))
956           {
957                WARN("failed!\n");
958                SetLastError( ER_NoNetwork );
959                return TRUE;
960           } else {
961                int len = strlen (dst);
962                while (len < 15)
963                     dst[len++] = ' ';
964                dst[15] = 0;
965                CH_reg(context) = 1; /* Valid */
966                CL_reg(context) = 1; /* NETbios number??? */
967                TRACE("returning %s\n", debugstr_an (dst, 16));
968                return FALSE;
969           }
970      }
971
972      default:
973           SetLastError( ER_NoNetwork );
974           return TRUE;
975      }
976 }
977
978
979 static void ASPI_DOS_HandleInt( CONTEXT86 *context )
980 {
981     if (!Dosvm.ASPIHandler && !DPMI_LoadDosSystem())
982     {
983         ERR("could not setup ASPI handler\n");
984         return;
985     }
986     Dosvm.ASPIHandler( context );
987 }
988
989 /***********************************************************************
990  *           INT21_GetExtendedError
991  */
992 static void INT21_GetExtendedError( CONTEXT86 *context )
993 {
994     BYTE class, action, locus;
995     WORD error = GetLastError();
996
997     switch(error)
998     {
999     case ERROR_SUCCESS:
1000         class = action = locus = 0;
1001         break;
1002     case ERROR_DIR_NOT_EMPTY:
1003         class  = EC_Exists;
1004         action = SA_Ignore;
1005         locus  = EL_Disk;
1006         break;
1007     case ERROR_ACCESS_DENIED:
1008         class  = EC_AccessDenied;
1009         action = SA_Abort;
1010         locus  = EL_Disk;
1011         break;
1012     case ERROR_CANNOT_MAKE:
1013         class  = EC_AccessDenied;
1014         action = SA_Abort;
1015         locus  = EL_Unknown;
1016         break;
1017     case ERROR_DISK_FULL:
1018     case ERROR_HANDLE_DISK_FULL:
1019         class  = EC_MediaError;
1020         action = SA_Abort;
1021         locus  = EL_Disk;
1022         break;
1023     case ERROR_FILE_EXISTS:
1024     case ERROR_ALREADY_EXISTS:
1025         class  = EC_Exists;
1026         action = SA_Abort;
1027         locus  = EL_Disk;
1028         break;
1029     case ERROR_FILE_NOT_FOUND:
1030         class  = EC_NotFound;
1031         action = SA_Abort;
1032         locus  = EL_Disk;
1033         break;
1034     case ER_GeneralFailure:
1035         class  = EC_SystemFailure;
1036         action = SA_Abort;
1037         locus  = EL_Unknown;
1038         break;
1039     case ERROR_INVALID_DRIVE:
1040         class  = EC_MediaError;
1041         action = SA_Abort;
1042         locus  = EL_Disk;
1043         break;
1044     case ERROR_INVALID_HANDLE:
1045         class  = EC_ProgramError;
1046         action = SA_Abort;
1047         locus  = EL_Disk;
1048         break;
1049     case ERROR_LOCK_VIOLATION:
1050         class  = EC_AccessDenied;
1051         action = SA_Abort;
1052         locus  = EL_Disk;
1053         break;
1054     case ERROR_NO_MORE_FILES:
1055         class  = EC_MediaError;
1056         action = SA_Abort;
1057         locus  = EL_Disk;
1058         break;
1059     case ER_NoNetwork:
1060         class  = EC_NotFound;
1061         action = SA_Abort;
1062         locus  = EL_Network;
1063         break;
1064     case ERROR_NOT_ENOUGH_MEMORY:
1065         class  = EC_OutOfResource;
1066         action = SA_Abort;
1067         locus  = EL_Memory;
1068         break;
1069     case ERROR_PATH_NOT_FOUND:
1070         class  = EC_NotFound;
1071         action = SA_Abort;
1072         locus  = EL_Disk;
1073         break;
1074     case ERROR_SEEK:
1075         class  = EC_NotFound;
1076         action = SA_Ignore;
1077         locus  = EL_Disk;
1078         break;
1079     case ERROR_SHARING_VIOLATION:
1080         class  = EC_Temporary;
1081         action = SA_Retry;
1082         locus  = EL_Disk;
1083         break;
1084     case ERROR_TOO_MANY_OPEN_FILES:
1085         class  = EC_ProgramError;
1086         action = SA_Abort;
1087         locus  = EL_Disk;
1088         break;
1089     default:
1090         FIXME("Unknown error %d\n", error );
1091         class  = EC_SystemFailure;
1092         action = SA_Abort;
1093         locus  = EL_Unknown;
1094         break;
1095     }
1096     TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1097            error, class, action, locus );
1098     AX_reg(context) = error;
1099     BH_reg(context) = class;
1100     BL_reg(context) = action;
1101     CH_reg(context) = locus;
1102 }
1103
1104 /***********************************************************************
1105  *           DOS3Call         (KERNEL.102)
1106  *           INT_Int21Handler (WPROCS.133)
1107  */
1108 void WINAPI DOS3Call( CONTEXT86 *context )
1109 {
1110     BOOL        bSetDOSExtendedError = FALSE;
1111
1112
1113     TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1114           "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1115           AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1116           SI_reg(context), DI_reg(context),
1117           (WORD)context->SegDs, (WORD)context->SegEs,
1118           context->EFlags );
1119
1120
1121     if (AH_reg(context) == 0x59)  /* Get extended error info */
1122     {
1123         INT21_GetExtendedError( context );
1124         return;
1125     }
1126
1127     if (AH_reg(context) == 0x0C)  /* Flush buffer and read standard input */
1128     {
1129         TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1130         /* no flush here yet */
1131         AH_reg(context) = AL_reg(context);
1132     }
1133
1134     if (AH_reg(context)>=0x2f) {
1135         /* extended error is used by (at least) functions 0x2f to 0x62 */
1136         SetLastError(0);
1137     }
1138     RESET_CFLAG(context);  /* Not sure if this is a good idea */
1139
1140     switch(AH_reg(context))
1141     {
1142     case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1143     case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1144     case 0x03: /* READ CHARACTER FROM STDAUX  */
1145     case 0x04: /* WRITE CHARACTER TO STDAUX */
1146     case 0x05: /* WRITE CHARACTER TO PRINTER */
1147     case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1148     case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1149     case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1150     case 0x0b: /* GET STDIN STATUS */
1151     case 0x0f: /* OPEN FILE USING FCB */
1152     case 0x10: /* CLOSE FILE USING FCB */
1153     case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1154     case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1155     case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1156     case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1157     case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1158     case 0x23: /* GET FILE SIZE FOR FCB */
1159     case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1160     case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1161     case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1162     case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1163     case 0x4d: /* GET RETURN CODE */
1164     case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1165         INT_BARF( context, 0x21 );
1166         break;
1167
1168     case 0x00: /* TERMINATE PROGRAM */
1169         TRACE("TERMINATE PROGRAM\n");
1170         ExitThread( 0 );
1171         break;
1172
1173     case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1174         TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1175               context->SegDs,DX_reg(context) );
1176         {
1177             LPSTR data = CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx);
1178             LPSTR p = data;
1179             /* do NOT use strchr() to calculate the string length,
1180             as '\0' is valid string content, too !
1181             Maybe we should check for non-'$' strings, but DOS doesn't. */
1182             while (*p != '$') p++;
1183             _hwrite16( 1, data, (int)p - (int)data);
1184             AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1185         }
1186         break;
1187
1188     case 0x0a: /* BUFFERED INPUT */
1189       {
1190         char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
1191                                                    context->Edx ));
1192         int res;
1193
1194         TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1195         if (buffer[1])
1196           TRACE("Handle old chars in buffer!\n");
1197         res=_lread16( 0, buffer+2,buffer[0]);
1198         buffer[1]=res;
1199         if(buffer[res+1] == '\n')
1200           buffer[res+1] = '\r';
1201         break;
1202       }
1203
1204     case 0x2e: /* SET VERIFY FLAG */
1205         TRACE("SET VERIFY FLAG ignored\n");
1206         /* we cannot change the behaviour anyway, so just ignore it */
1207         break;
1208
1209     case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1210     case 0x1d:
1211     case 0x1e:
1212     case 0x20:
1213     case 0x6b: /* NULL FUNCTION */
1214         AL_reg(context) = 0;
1215         break;
1216
1217     case 0x5c: /* "FLOCK" - RECORD LOCKING */
1218         fLock(context);
1219         break;
1220
1221     case 0x0d: /* DISK BUFFER FLUSH */
1222         TRACE("DISK BUFFER FLUSH ignored\n");
1223         RESET_CFLAG(context); /* dos 6+ only */
1224         break;
1225
1226     case 0x0e: /* SELECT DEFAULT DRIVE */
1227         TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1228         DRIVE_SetCurrentDrive( DL_reg(context) );
1229         AL_reg(context) = MAX_DOS_DRIVES;
1230         break;
1231
1232     case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1233         TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1234               CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1235         if (!INT21_FindFirstFCB(context))
1236         {
1237             AL_reg(context) = 0xff;
1238             break;
1239         }
1240         /* else fall through */
1241
1242     case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1243         AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1244         break;
1245
1246     case 0x13: /* DELETE FILE USING FCB */
1247         DeleteFileFCB(context);
1248         break;
1249
1250     case 0x17: /* RENAME FILE USING FCB */
1251         RenameFileFCB(context);
1252         break;
1253
1254     case 0x19: /* GET CURRENT DEFAULT DRIVE */
1255         AL_reg(context) = DRIVE_GetCurrentDrive();
1256         break;
1257
1258     case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1259         {
1260             TDB *pTask = TASK_GetCurrent();
1261             pTask->dta = MAKESEGPTR(context->SegDs,DX_reg(context));
1262             TRACE("Set DTA: %08lx\n", pTask->dta);
1263         }
1264         break;
1265
1266     case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1267         DL_reg(context) = 0;
1268         if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1269         break;
1270
1271     case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1272         if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1273         break;
1274
1275     case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1276         GetDrivePB(context, DRIVE_GetCurrentDrive());
1277         break;
1278
1279     case 0x25: /* SET INTERRUPT VECTOR */
1280         INT_SetPMHandler( AL_reg(context), (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
1281         break;
1282
1283     case 0x29: /* PARSE FILENAME INTO FCB */
1284         INT21_ParseFileNameIntoFCB(context);
1285         break;
1286
1287     case 0x2a: /* GET SYSTEM DATE */
1288         INT21_GetSystemDate(context);
1289         break;
1290
1291     case 0x2b: /* SET SYSTEM DATE */
1292         FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1293               DL_reg(context), DH_reg(context), CX_reg(context) );
1294         AL_reg(context) = 0;  /* Let's pretend we succeeded */
1295         break;
1296
1297     case 0x2c: /* GET SYSTEM TIME */
1298         INT21_GetSystemTime(context);
1299         break;
1300
1301     case 0x2d: /* SET SYSTEM TIME */
1302         FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1303               CH_reg(context), CL_reg(context),
1304               DH_reg(context), DL_reg(context) );
1305         AL_reg(context) = 0;  /* Let's pretend we succeeded */
1306         break;
1307
1308     case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1309         TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1310         {
1311             TDB *pTask = TASK_GetCurrent();
1312             context->SegEs = SELECTOROF( pTask->dta );
1313             BX_reg(context) = OFFSETOF( pTask->dta );
1314         }
1315         break;
1316
1317     case 0x30: /* GET DOS VERSION */
1318         TRACE("GET DOS VERSION %s requested\n",
1319               (AL_reg(context) == 0x00)?"OEM number":"version flag");
1320         AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1321                           (HIWORD(GetVersion16()) << 8);
1322 #if 0
1323         AH_reg(context) = 0x7;
1324         AL_reg(context) = 0xA;
1325 #endif
1326
1327         BX_reg(context) = 0x00FF;     /* 0x123456 is Wine's serial # */
1328         CX_reg(context) = 0x0000;
1329         break;
1330
1331     case 0x31: /* TERMINATE AND STAY RESIDENT */
1332         FIXME("TERMINATE AND STAY RESIDENT stub\n");
1333         break;
1334
1335     case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1336         TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1337               INT21_DriveName( DL_reg(context)));
1338         GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1339         break;
1340
1341     case 0x33: /* MULTIPLEXED */
1342         switch (AL_reg(context))
1343         {
1344               case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1345                 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1346                 INT21_ReadConfigSys();
1347                 DL_reg(context) = DOSCONF_config.brk_flag;
1348                 break;
1349
1350               case 0x01: /* SET EXTENDED BREAK STATE */
1351                 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1352                 INT21_ReadConfigSys();
1353                 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1354                 break;
1355
1356               case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1357                 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1358                 INT21_ReadConfigSys();
1359                 /* ugly coding in order to stay reentrant */
1360                 if (DL_reg(context))
1361                 {
1362                     DL_reg(context) = DOSCONF_config.brk_flag;
1363                     DOSCONF_config.brk_flag = 1;
1364                 }
1365                 else
1366                 {
1367                     DL_reg(context) = DOSCONF_config.brk_flag;
1368                     DOSCONF_config.brk_flag = 0;
1369                 }
1370                 break;
1371
1372               case 0x05: /* GET BOOT DRIVE */
1373                 TRACE("GET BOOT DRIVE\n");
1374                 DL_reg(context) = 3;
1375                 /* c: is Wine's bootdrive (a: is 1)*/
1376                 break;
1377
1378               case 0x06: /* GET TRUE VERSION NUMBER */
1379                 TRACE("GET TRUE VERSION NUMBER\n");
1380                 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1381                                   (HIWORD(GetVersion16() << 8));
1382                 DX_reg(context) = 0x00;
1383                 break;
1384
1385               default:
1386                 INT_BARF( context, 0x21 );
1387                 break;
1388         }
1389         break;
1390
1391     case 0x34: /* GET ADDRESS OF INDOS FLAG */
1392         TRACE("GET ADDRESS OF INDOS FLAG\n");
1393         if (!heap) INT21_CreateHeap();
1394         context->SegEs = DosHeapHandle;
1395         BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1396         break;
1397
1398     case 0x35: /* GET INTERRUPT VECTOR */
1399         TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1400         {
1401             FARPROC16 addr = INT_GetPMHandler( AL_reg(context) );
1402             context->SegEs = SELECTOROF(addr);
1403             BX_reg(context) = OFFSETOF(addr);
1404         }
1405         break;
1406
1407     case 0x36: /* GET FREE DISK SPACE */
1408         TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1409               INT21_DriveName( DL_reg(context)));
1410         if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1411         break;
1412
1413     case 0x37:
1414       {
1415         unsigned char switchchar='/';
1416         switch (AL_reg(context))
1417         {
1418         case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1419           TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1420           AL_reg(context) = 0x00; /* success*/
1421           DL_reg(context) = switchchar;
1422           break;
1423         case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1424           TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1425           switchchar = DL_reg(context);
1426           AL_reg(context) = 0x00; /* success*/
1427           break;
1428         default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1429           INT_BARF( context, 0x21 );
1430           break;
1431         }
1432         break;
1433       }
1434
1435     case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1436         TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1437               AL_reg(context));
1438         AX_reg(context) = 0x02; /* no country support available */
1439         SET_CFLAG(context);
1440         break;
1441
1442     case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1443         TRACE("MKDIR %s\n",
1444               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1445         bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
1446                                                            context->Edx ), NULL));
1447         /* FIXME: CreateDirectory's LastErrors will clash with the ones
1448          * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1449          * denied), while CreateDirectory return several ones. remap some of
1450          * them. -Marcus
1451          */
1452         if (bSetDOSExtendedError) {
1453                 switch (GetLastError()) {
1454                 case ERROR_ALREADY_EXISTS:
1455                 case ERROR_FILENAME_EXCED_RANGE:
1456                 case ERROR_DISK_FULL:
1457                         SetLastError(ERROR_ACCESS_DENIED);
1458                         break;
1459                 default: break;
1460                 }
1461         }
1462         break;
1463
1464     case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1465         TRACE("RMDIR %s\n",
1466               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1467         bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
1468                                                                  context->Edx )));
1469         break;
1470
1471     case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1472         TRACE("CHDIR %s\n",
1473               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1474         bSetDOSExtendedError = !INT21_ChangeDir(context);
1475         break;
1476
1477     case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1478         TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1479               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1480         bSetDOSExtendedError = INT21_CreateFile( context );
1481         break;
1482
1483     case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1484         TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1485               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1486         OpenExistingFile(context);
1487         break;
1488
1489     case 0x3e: /* "CLOSE" - CLOSE FILE */
1490         TRACE("CLOSE handle %d\n",BX_reg(context));
1491         bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1492         break;
1493
1494     case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1495         TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1496               context->SegDs,DX_reg(context),CX_reg(context) );
1497         {
1498             LONG result;
1499             if (ISV86(context))
1500                 result = _hread16( BX_reg(context),
1501                                    CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1502                                                                context->Edx ),
1503                                    CX_reg(context) );
1504             else
1505                 result = WIN16_hread( BX_reg(context),
1506                                       MAKESEGPTR( context->SegDs, context->Edx ),
1507                                       CX_reg(context) );
1508             if (result == -1) bSetDOSExtendedError = TRUE;
1509             else AX_reg(context) = (WORD)result;
1510         }
1511         break;
1512
1513     case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1514         TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1515               context->SegDs,DX_reg(context),BX_reg(context),CX_reg(context) );
1516         {
1517             LONG result = _hwrite16( BX_reg(context),
1518                                      CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
1519                                                          context->Edx ),
1520                                      CX_reg(context) );
1521             if (result == -1) bSetDOSExtendedError = TRUE;
1522             else AX_reg(context) = (WORD)result;
1523         }
1524         break;
1525
1526     case 0x41: /* "UNLINK" - DELETE FILE */
1527         TRACE("UNLINK %s\n",
1528               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1529         bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
1530                                                              context->Edx )));
1531         break;
1532
1533     case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1534         TRACE("LSEEK handle %d offset %ld from %s\n",
1535               BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1536               (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1537               "current file position":"end of file");
1538         {
1539             LONG status = _llseek16( BX_reg(context),
1540                                      MAKELONG(DX_reg(context),CX_reg(context)),
1541                                      AL_reg(context) );
1542             if (status == -1) bSetDOSExtendedError = TRUE;
1543             else
1544             {
1545                 AX_reg(context) = LOWORD(status);
1546                 DX_reg(context) = HIWORD(status);
1547             }
1548         }
1549         break;
1550
1551     case 0x43: /* FILE ATTRIBUTES */
1552         switch (AL_reg(context))
1553         {
1554         case 0x00:
1555             TRACE("GET FILE ATTRIBUTES for %s\n",
1556                   (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1557             AX_reg(context) = (WORD)GetFileAttributesA(
1558                                           CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1559                                                              context->Edx));
1560             if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1561             else CX_reg(context) = AX_reg(context);
1562             break;
1563
1564         case 0x01:
1565             TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1566                   (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1567             bSetDOSExtendedError =
1568                 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1569                                                            context->Edx),
1570                                                            CX_reg(context) ));
1571             break;
1572         case 0x02:
1573             FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1574                   (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1575         }
1576         break;
1577
1578     case 0x44: /* IOCTL */
1579         switch (AL_reg(context))
1580         {
1581         case 0x00:
1582             ioctlGetDeviceInfo(context);
1583             break;
1584
1585         case 0x01:
1586             break;
1587         case 0x02:{
1588             const DOS_DEVICE *dev;
1589             if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )) &&
1590                 !strcasecmp( dev->name, "SCSIMGR$" ))
1591             {
1592                 ASPI_DOS_HandleInt(context);
1593             }
1594             break;
1595        }
1596         case 0x05:{     /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1597             /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
1598             int drive = DOS_GET_DRIVE(BL_reg(context));
1599
1600             FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1601             /* for (i=0;i<CX_reg(context);i++)
1602                 fprintf(stdnimp,"%02x ",dataptr[i]);
1603             fprintf(stdnimp,"\n");*/
1604             AX_reg(context)=CX_reg(context);
1605             break;
1606         }
1607         case 0x08:   /* Check if drive is removable. */
1608             TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1609                  INT21_DriveName( BL_reg(context)));
1610             switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1611             {
1612             case DRIVE_UNKNOWN:
1613                 SetLastError( ERROR_INVALID_DRIVE );
1614                 AX_reg(context) = ERROR_INVALID_DRIVE;
1615                 SET_CFLAG(context);
1616                 break;
1617             case DRIVE_REMOVABLE:
1618                 AX_reg(context) = 0;      /* removable */
1619                 break;
1620             default:
1621                 AX_reg(context) = 1;   /* not removable */
1622                 break;
1623             }
1624             break;
1625
1626         case 0x09:   /* CHECK IF BLOCK DEVICE REMOTE */
1627             TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1628                  INT21_DriveName( BL_reg(context)));
1629             switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1630             {
1631             case DRIVE_UNKNOWN:
1632                 SetLastError( ERROR_INVALID_DRIVE );
1633                 AX_reg(context) = ERROR_INVALID_DRIVE;
1634                 SET_CFLAG(context);
1635                 break;
1636             case DRIVE_REMOTE:
1637                 DX_reg(context) = (1<<9) | (1<<12);  /* remote */
1638                 break;
1639             default:
1640                 DX_reg(context) = 0;  /* FIXME: use driver attr here */
1641                 break;
1642             }
1643             break;
1644
1645         case 0x0a: /* check if handle (BX) is remote */
1646             TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1647             /* returns DX, bit 15 set if remote, bit 14 set if date/time
1648              * not set on close
1649              */
1650             DX_reg(context) = 0;
1651             break;
1652
1653         case 0x0d:
1654             TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1655                   INT21_DriveName( BL_reg(context)));
1656             bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1657             break;
1658
1659         case 0x0e: /* get logical drive mapping */
1660             TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1661                   INT21_DriveName( BL_reg(context)));
1662             AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1663             break;
1664
1665         case 0x0F:   /* Set logical drive mapping */
1666             {
1667             int drive;
1668             TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1669                   INT21_DriveName( BL_reg(context)));
1670             drive = DOS_GET_DRIVE ( BL_reg(context) );
1671             if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1672             {
1673                 SET_CFLAG(context);
1674                 AX_reg(context) = 0x000F;  /* invalid drive */
1675             }
1676             break;
1677             }
1678
1679         case 0xe0:  /* Sun PC-NFS API */
1680             /* not installed */
1681             break;
1682
1683         case 0x52:  /* DR-DOS version */
1684             /* This is not DR-DOS */
1685
1686             TRACE("GET DR-DOS VERSION requested\n");
1687
1688             AX_reg(context) = 0x0001; /* Invalid function */
1689             SET_CFLAG(context);       /* Error */
1690             SetLastError( ERROR_INVALID_FUNCTION );
1691             break;
1692
1693         default:
1694             INT_BARF( context, 0x21 );
1695             break;
1696         }
1697         break;
1698
1699     case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1700         {
1701             HANDLE handle;
1702             TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1703             if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1704                                                           DosFileHandleToWin32Handle(BX_reg(context)),
1705                                                           GetCurrentProcess(), &handle,
1706                                                           0, TRUE, DUPLICATE_SAME_ACCESS )))
1707                 AX_reg(context) = HFILE_ERROR16;
1708             else
1709                 AX_reg(context) = Win32HandleToDosFileHandle(handle);
1710             break;
1711         }
1712
1713     case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1714         TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1715               BX_reg(context),CX_reg(context));
1716         bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1717         break;
1718
1719     case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1720         TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1721               INT21_DriveName( DL_reg(context)));
1722         bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1723         break;
1724
1725     case 0x48: /* ALLOCATE MEMORY */
1726         TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1727         {
1728             LPVOID *mem;
1729             if (ISV86(context))
1730               {
1731                 mem= DOSMEM_GetBlock((DWORD)BX_reg(context)<<4,NULL);
1732             if (mem)
1733                 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1734               }
1735             else
1736               {
1737                 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1738                 if (mem)
1739                   AX_reg(context) = (DWORD)mem&0xffff;
1740               }
1741             if (!mem)
1742               {
1743                 SET_CFLAG(context);
1744                 AX_reg(context) = 0x0008; /* insufficient memory */
1745                 BX_reg(context) = DOSMEM_Available()>>4;
1746             }
1747         }
1748         break;
1749
1750     case 0x49: /* FREE MEMORY */
1751         TRACE("FREE MEMORY segment %04lX\n", context->SegEs);
1752         {
1753           BOOL ret;
1754           if (ISV86(context))
1755             ret= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(context->SegEs<<4));
1756           else
1757             {
1758               ret = !GlobalDOSFree16(context->SegEs);
1759               /* If we don't reset ES_reg, we will fail in the relay code */
1760               context->SegEs=ret;
1761             }
1762           if (!ret)
1763             {
1764               TRACE("FREE MEMORY failed\n");
1765             SET_CFLAG(context);
1766             AX_reg(context) = 0x0009; /* memory block address invalid */
1767         }
1768         }
1769         break;
1770
1771     case 0x4a: /* RESIZE MEMORY BLOCK */
1772         TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", context->SegEs, BX_reg(context));
1773         if (!ISV86(context))
1774           FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1775         {
1776             LPVOID *mem = DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(context->SegEs<<4),
1777                                              BX_reg(context)<<4,NULL);
1778             if (mem)
1779                 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1780             else {
1781                 SET_CFLAG(context);
1782                 AX_reg(context) = 0x0008; /* insufficient memory */
1783                 BX_reg(context) = DOSMEM_Available()>>4; /* not quite right */
1784             }
1785         }
1786         break;
1787
1788     case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1789         TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
1790         AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx ),
1791                                      SW_NORMAL );
1792         if (AX_reg(context) < 32) SET_CFLAG(context);
1793         break;
1794
1795     case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1796         TRACE("EXIT with return code %d\n",AL_reg(context));
1797         ExitThread( AL_reg(context) );
1798         break;
1799
1800     case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1801         TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1802               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1803         if (!INT21_FindFirst(context)) break;
1804         /* fall through */
1805
1806     case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1807         TRACE("FINDNEXT\n");
1808         if (!INT21_FindNext(context))
1809         {
1810             SetLastError( ERROR_NO_MORE_FILES );
1811             AX_reg(context) = ERROR_NO_MORE_FILES;
1812             SET_CFLAG(context);
1813         }
1814         else AX_reg(context) = 0;  /* OK */
1815         break;
1816     case 0x51: /* GET PSP ADDRESS */
1817         TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1818         /* FIXME: should we return the original DOS PSP upon */
1819         /*        Windows startup ? */
1820         BX_reg(context) = GetCurrentPDB16();
1821         break;
1822     case 0x62: /* GET PSP ADDRESS */
1823         /* FIXME: should we return the original DOS PSP upon */
1824         /*        Windows startup ? */
1825         BX_reg(context) = GetCurrentPDB16();
1826         break;
1827
1828     case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1829         TRACE("SYSVARS - GET LIST OF LISTS\n");
1830         {
1831             context->SegEs = LOWORD(DOS_LOLSeg);
1832             BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1833         }
1834         break;
1835
1836     case 0x54: /* Get Verify Flag */
1837         TRACE("Get Verify Flag - Not Supported\n");
1838         AL_reg(context) = 0x00;  /* pretend we can tell. 00h = off 01h = on */
1839         break;
1840
1841     case 0x56: /* "RENAME" - RENAME FILE */
1842         TRACE("RENAME %s to %s\n",
1843               (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1844               (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi));
1845         bSetDOSExtendedError =
1846                 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1847                                CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi)));
1848         break;
1849
1850     case 0x57: /* FILE DATE AND TIME */
1851         switch (AL_reg(context))
1852         {
1853         case 0x00:  /* Get */
1854             {
1855                 FILETIME filetime;
1856                 TRACE("GET FILE DATE AND TIME for handle %d\n",
1857                       BX_reg(context));
1858                 if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context)), NULL, NULL, &filetime ))
1859                      bSetDOSExtendedError = TRUE;
1860                 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1861                                             &CX_reg(context) );
1862             }
1863             break;
1864
1865         case 0x01:  /* Set */
1866             {
1867                 FILETIME filetime;
1868                 TRACE("SET FILE DATE AND TIME for handle %d\n",
1869                       BX_reg(context));
1870                 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1871                                        &filetime );
1872                 bSetDOSExtendedError =
1873                         (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context)),
1874                                       NULL, NULL, &filetime ));
1875             }
1876             break;
1877         }
1878         break;
1879
1880     case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1881         TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1882               AL_reg(context));
1883         switch (AL_reg(context))
1884         {
1885         case 0x00:
1886             AX_reg(context) = 1;
1887             break;
1888         case 0x02:
1889             AX_reg(context) = 0;
1890             break;
1891         case 0x01:
1892         case 0x03:
1893             break;
1894         }
1895         RESET_CFLAG(context);
1896         break;
1897
1898     case 0x5a: /* CREATE TEMPORARY FILE */
1899         TRACE("CREATE TEMPORARY FILE\n");
1900         bSetDOSExtendedError = !INT21_CreateTempFile(context);
1901         break;
1902
1903     case 0x5b: /* CREATE NEW FILE */
1904         TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1905               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
1906         bSetDOSExtendedError = ((AX_reg(context) =
1907                _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1908                                CX_reg(context) )) == (WORD)HFILE_ERROR16);
1909         break;
1910
1911     case 0x5d: /* NETWORK */
1912         FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1913         /* Fix the following while you're at it.  */
1914         SetLastError( ER_NoNetwork );
1915         bSetDOSExtendedError = TRUE;
1916         break;
1917
1918     case 0x5e:
1919         bSetDOSExtendedError = INT21_networkfunc (context);
1920         break;
1921
1922     case 0x5f: /* NETWORK */
1923         switch (AL_reg(context))
1924         {
1925         case 0x07: /* ENABLE DRIVE */
1926             TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1927             if (!DRIVE_Enable( DL_reg(context) ))
1928             {
1929                 SetLastError( ERROR_INVALID_DRIVE );
1930                 bSetDOSExtendedError = TRUE;
1931             }
1932             break;
1933
1934         case 0x08: /* DISABLE DRIVE */
1935             TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1936             if (!DRIVE_Disable( DL_reg(context) ))
1937             {
1938                 SetLastError( ERROR_INVALID_DRIVE );
1939                 bSetDOSExtendedError = TRUE;
1940             }
1941             break;
1942
1943         default:
1944             /* network software not installed */
1945             TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1946             SetLastError( ER_NoNetwork );
1947             bSetDOSExtendedError = TRUE;
1948             break;
1949         }
1950         break;
1951
1952     case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1953         TRACE("TRUENAME %s\n",
1954               (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Esi));
1955         {
1956             if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1957                                                         context->Esi), 128,
1958                                      CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1959                                                         context->Edi),NULL))
1960                 bSetDOSExtendedError = TRUE;
1961             else AX_reg(context) = 0;
1962         }
1963         break;
1964
1965     case 0x61: /* UNUSED */
1966     case 0x63: /* misc. language support */
1967         switch (AL_reg(context)) {
1968         case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1969             INT21_GetDBCSLeadTable(context);
1970             break;
1971         }
1972         break;
1973     case 0x64: /* OS/2 DOS BOX */
1974         INT_BARF( context, 0x21 );
1975         SET_CFLAG(context);
1976         break;
1977
1978     case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1979         BYTE    *dataptr=CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
1980         TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1981               BX_reg(context), DX_reg(context));
1982         switch (AL_reg(context)) {
1983         case 0x01:
1984             TRACE("\tget general internationalization info\n");
1985             dataptr[0] = 0x1;
1986             *(WORD*)(dataptr+1) = 41;
1987             *(WORD*)(dataptr+3) = GetSystemDefaultLangID();
1988             *(WORD*)(dataptr+5) = CodePage;
1989             *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1990             break;
1991         case 0x06:
1992             TRACE("\tget pointer to collating sequence table\n");
1993             dataptr[0] = 0x06;
1994             *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1995             CX_reg(context)         = 258;/*FIXME: size of table?*/
1996             break;
1997         case 0x20:
1998             TRACE("\tConvert char to uppercase\n");
1999             DL_reg(context) = toupper(DL_reg(context));
2000             break;
2001         case 0x21:
2002             TRACE("\tconvert string to uppercase with length\n");
2003             {
2004                 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx);
2005                 WORD len = CX_reg(context);
2006                 while (len--) { *ptr = toupper(*ptr); ptr++; }
2007             }
2008             break;
2009         case 0x22:
2010             TRACE("\tConvert ASCIIZ string to uppercase\n");
2011             _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx) );
2012             break;
2013         default:
2014             TRACE("\tunimplemented function %d\n",AL_reg(context));
2015             INT_BARF( context, 0x21 );
2016             SET_CFLAG(context);
2017             break;
2018         }
2019         break;
2020     }
2021     case 0x66: /* GLOBAL CODE PAGE TABLE */
2022         switch (AL_reg(context))
2023         {
2024         case 0x01:
2025             TRACE("GET GLOBAL CODE PAGE TABLE\n");
2026             DX_reg(context) = BX_reg(context) = CodePage;
2027             RESET_CFLAG(context);
2028             break;
2029         case 0x02:
2030             TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2031                   BX_reg(context),DX_reg(context));
2032             CodePage = BX_reg(context);
2033             RESET_CFLAG(context);
2034             break;
2035         }
2036         break;
2037
2038     case 0x67: /* SET HANDLE COUNT */
2039         TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2040         SetHandleCount16( BX_reg(context) );
2041         if (GetLastError()) bSetDOSExtendedError = TRUE;
2042         break;
2043
2044     case 0x68: /* "FFLUSH" - COMMIT FILE */
2045     case 0x6a: /* COMMIT FILE */
2046         TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2047         bSetDOSExtendedError = (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ));
2048         break;
2049
2050     case 0x69: /* DISK SERIAL NUMBER */
2051         switch (AL_reg(context))
2052         {
2053         case 0x00:
2054             TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2055                   INT21_DriveName(BL_reg(context)));
2056             if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2057             else AX_reg(context) = 0;
2058             break;
2059
2060         case 0x01:
2061             TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2062                   INT21_DriveName(BL_reg(context)));
2063             if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2064             else AX_reg(context) = 1;
2065             break;
2066         }
2067         break;
2068
2069     case 0x6C: /* Extended Open/Create*/
2070         TRACE("EXTENDED OPEN/CREATE %s\n",
2071               (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edi));
2072         bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2073         break;
2074
2075     case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2076         if ((GetVersion()&0xC0000004)!=0xC0000004) {
2077             /* not supported on anything but Win95 */
2078             TRACE("LONG FILENAME functions supported only by win95\n");
2079             SET_CFLAG(context);
2080             AL_reg(context) = 0;
2081         } else
2082         switch(AL_reg(context))
2083         {
2084         case 0x39:  /* Create directory */
2085             TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2086                   (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs,context->Edx));
2087             bSetDOSExtendedError = (!CreateDirectoryA(
2088                                         CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
2089                                                   context->Edx ), NULL));
2090             /* FIXME: CreateDirectory's LastErrors will clash with the ones
2091              * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2092              * denied), while CreateDirectory return several ones. remap some of
2093              * them. -Marcus
2094              */
2095             if (bSetDOSExtendedError) {
2096                     switch (GetLastError()) {
2097                     case ERROR_ALREADY_EXISTS:
2098                     case ERROR_FILENAME_EXCED_RANGE:
2099                     case ERROR_DISK_FULL:
2100                             SetLastError(ERROR_ACCESS_DENIED);
2101                             break;
2102                     default: break;
2103                     }
2104             }
2105             break;
2106         case 0x3a:  /* Remove directory */
2107             TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2108                   (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs,context->Edx));
2109             bSetDOSExtendedError = (!RemoveDirectoryA(
2110                                         CTX_SEG_OFF_TO_LIN(context,  context->SegDs,
2111                                                         context->Edx )));
2112             break;
2113         case 0x43:  /* Get/Set file attributes */
2114           TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2115                 (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs,context->Edx));
2116         switch (BL_reg(context))
2117         {
2118         case 0x00: /* Get file attributes */
2119             TRACE("\tretrieve attributes\n");
2120             CX_reg(context) = (WORD)GetFileAttributesA(
2121                                           CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2122                                                              context->Edx));
2123             if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2124             break;
2125         case 0x01:
2126             TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2127             bSetDOSExtendedError = (!SetFileAttributesA(
2128                                         CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2129                                                            context->Edx),
2130                                         CX_reg(context)  ) );
2131             break;
2132         default:
2133           FIXME("Unimplemented long file name function:\n");
2134           INT_BARF( context, 0x21 );
2135           SET_CFLAG(context);
2136           AL_reg(context) = 0;
2137           break;
2138         }
2139         break;
2140         case 0x47:  /* Get current directory */
2141             TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2142                   INT21_DriveName(DL_reg(context)));
2143             bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2144             break;
2145
2146         case 0x4e:  /* Find first file */
2147             TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2148                   (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2149             /* FIXME: use attributes in CX */
2150             if ((AX_reg(context) = FindFirstFile16(
2151                    CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
2152                    (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2153                                                             context->Edi)))
2154                 == INVALID_HANDLE_VALUE16)
2155                 bSetDOSExtendedError = TRUE;
2156             break;
2157         case 0x4f:  /* Find next file */
2158             TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2159                   BX_reg(context));
2160             if (!FindNextFile16( BX_reg(context),
2161                     (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2162                                                              context->Edi)))
2163                 bSetDOSExtendedError = TRUE;
2164             break;
2165         case 0xa0:
2166             {
2167                 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs,context->Edx);
2168                 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegEs,context->Edi);
2169                 DWORD filename_len, flags;
2170
2171                 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
2172                 AX_reg(context) = 0;
2173                 if (!GetVolumeInformationA( driveroot, NULL, 0, NULL, &filename_len,
2174                                             &flags, buffer, 8 ))
2175                 {
2176                     INT_BARF( context, 0x21 );
2177                     SET_CFLAG(context);
2178                     break;
2179                 }
2180                 BX_reg(context) = flags | 0x4000; /* support for LFN functions */
2181                 CX_reg(context) = filename_len;
2182                 DX_reg(context) = MAX_PATH; /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2183             }
2184             break;
2185         case 0xa1:  /* Find close */
2186             TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2187                   BX_reg(context));
2188             bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2189             break;
2190         case 0x60:
2191           switch(CL_reg(context))
2192           {
2193             case 0x01:  /* Get short filename or path */
2194               if (!GetShortPathNameA
2195                   ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2196                                        context->Esi),
2197                     CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2198                                        context->Edi), 67))
2199                 bSetDOSExtendedError = TRUE;
2200               else AX_reg(context) = 0;
2201               break;
2202             case 0x02:  /* Get canonical long filename or path */
2203               if (!GetFullPathNameA
2204                   ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2205                                        context->Esi), 128,
2206                     CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2207                                        context->Edi),NULL))
2208                 bSetDOSExtendedError = TRUE;
2209               else AX_reg(context) = 0;
2210               break;
2211             default:
2212               FIXME("Unimplemented long file name function:\n");
2213               INT_BARF( context, 0x21 );
2214               SET_CFLAG(context);
2215               AL_reg(context) = 0;
2216               break;
2217           }
2218           break;
2219         case 0x6c:  /* Create or open file */
2220             TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2221                  (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Esi));
2222           /* translate Dos 7 action to Dos 6 action */
2223             bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2224             break;
2225
2226         case 0x3b:  /* Change directory */
2227             TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2228                  (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
2229             if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2230                                                 context->SegDs,
2231                                                 context->Edx
2232                                         ))
2233             ) {
2234                 SET_CFLAG(context);
2235                 AL_reg(context) = GetLastError();
2236             }
2237             break;
2238         case 0x41:  /* Delete file */
2239             TRACE("LONG FILENAME - DELETE FILE %s\n",
2240                  (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx));
2241             if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2242                                         context->SegDs,
2243                                         context->Edx)
2244             )) {
2245                 SET_CFLAG(context);
2246                 AL_reg(context) = GetLastError();
2247             }
2248             break;
2249         case 0x56:  /* Move (rename) file */
2250             {
2251                 LPCSTR fn1 = (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegDs, context->Edx);
2252                 LPCSTR fn2 = (LPCSTR)CTX_SEG_OFF_TO_LIN(context,  context->SegEs, context->Edi);
2253                 TRACE("LONG FILENAME - RENAME FILE %s to %s\n", fn1, fn2);
2254                 if (!MoveFileA(fn1, fn2))
2255                 {
2256                     SET_CFLAG(context);
2257                     AL_reg(context) = GetLastError();
2258                 }
2259             }
2260             break;
2261         default:
2262             FIXME("Unimplemented long file name function:\n");
2263             INT_BARF( context, 0x21 );
2264             SET_CFLAG(context);
2265             AL_reg(context) = 0;
2266             break;
2267         }
2268         break;
2269
2270     case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2271     case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2272         TRACE("windows95 function AX %04x\n",
2273                     AX_reg(context));
2274         WARN("        returning unimplemented\n");
2275         SET_CFLAG(context);
2276         AL_reg(context) = 0;
2277         break;
2278
2279     case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2280         TRACE("windows95 function AX %04x\n",
2281                     AX_reg(context));
2282
2283         switch (AL_reg(context))
2284                 {
2285                 case 0x02:      /* Get Extended Drive Parameter Block for specific drive */
2286                                 /* ES:DI points to word with length of data (should be 0x3d) */
2287                         {
2288                                 WORD *buffer;
2289                                 struct EDPB *edpb;
2290                             DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
2291                             char root[] = "A:\\";
2292
2293                                 buffer = (WORD *)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
2294
2295                                 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer);
2296
2297                                 /* validate passed-in buffer lengths */
2298                                 if ((*buffer != 0x3d) || (context->Ecx != 0x3f))
2299                                 {
2300                                         WARN("Get Extended DPB: buffer lengths incorrect\n");
2301                                         WARN("CX = %lx, buffer[0] = %x\n", context->Ecx, *buffer);
2302                                         SET_CFLAG(context);
2303                                         AL_reg(context) = 0x18;         /* bad buffer length */
2304                                 }
2305
2306                                 /* buffer checks out */
2307                                 buffer++;               /* skip over length word now */
2308                                 if (FillInDrivePB( DX_reg(context) ) )
2309                                 {
2310                                         edpb = (struct EDPB *)buffer;
2311
2312                                         /* copy down the old-style DPB portion first */
2313                                         memcpy(&edpb->dpb, &heap->dpb, sizeof(struct DPB));
2314
2315                                         /* now fill in the extended entries */
2316                                         edpb->edpb_flags = 0;
2317                                         edpb->next_edpb = 0;
2318                                         edpb->free_cluster = edpb->free_cluster2 = 0;
2319
2320                                         /* determine free disk space */
2321                                     *root += DOS_GET_DRIVE( DX_reg(context) );
2322                                     GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
2323                               &free_clusters, &total_clusters );
2324
2325                                         edpb->clusters_free = (free_clusters&0xffff);
2326
2327                                         edpb->clusters_free_hi = free_clusters >> 16;
2328                                         edpb->mirroring_flags = 0;
2329                                         edpb->info_sector = 0xffff;
2330                                         edpb->spare_boot_sector = 0xffff;
2331                                         edpb->first_cluster = 0;
2332                                         edpb->max_cluster = total_clusters;
2333                                         edpb->fat_clusters = 32;        /* made-up value */
2334                                         edpb->root_cluster = 0;
2335
2336                                         RESET_CFLAG(context);   /* clear carry */
2337                                         AX_reg(context) = 0;
2338                                 }
2339                                 else
2340                                 {
2341                                 AX_reg(context) = 0x00ff;
2342                                         SET_CFLAG(context);
2343                                 }
2344                         }
2345                         break;
2346
2347                 case 0x03:      /* Get Extended free space on drive */
2348                 case 0x04:  /* Set DPB for formatting */
2349                 case 0x05:  /* extended absolute disk read/write */
2350                         FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context));
2351                         SET_CFLAG(context);
2352                         AL_reg(context) = 0;
2353                         break;
2354                 }
2355
2356                 break;
2357
2358
2359     case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2360     case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2361         break;
2362
2363     default:
2364         INT_BARF( context, 0x21 );
2365         break;
2366
2367     } /* END OF SWITCH */
2368
2369     if( bSetDOSExtendedError )          /* set general error condition */
2370     {
2371         AX_reg(context) = GetLastError();
2372         SET_CFLAG(context);
2373     }
2374
2375     if ((context->EFlags & 0x0001))
2376         TRACE("failed, error %ld\n", GetLastError() );
2377
2378     TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2379                  "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2380                  AX_reg(context), BX_reg(context), CX_reg(context),
2381                  DX_reg(context), SI_reg(context), DI_reg(context),
2382                  (WORD)context->SegDs, (WORD)context->SegEs,
2383                  context->EFlags);
2384 }
2385
2386 /***********************************************************************
2387  *              GetSetKernelDOSProc (KERNEL.311)
2388  */
2389 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2390 {
2391         FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);
2392         return NULL;
2393 }