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