Look up the printer's port in the registry if neither CreateDC or
[wine.git] / msdos / int21.c
blobfb2bfd8ca242a9fbcce67c5e988b5fb768d5db6c
1 /*
2 * DOS interrupt 21h handler
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
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.
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.
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
25 #include "config.h"
26 #include "wine/port.h"
28 #include <time.h>
29 #include <fcntl.h>
30 #include <stdlib.h>
31 #include <stdio.h>
32 #ifdef HAVE_SYS_FILE_H
33 # include <sys/file.h>
34 #endif
35 #include <string.h>
36 #ifdef HAVE_SYS_TIME_H
37 # include <sys/time.h>
38 #endif
39 #include <sys/types.h>
40 #ifdef HAVE_UNISTD_H
41 # include <unistd.h>
42 #endif
43 #ifdef HAVE_UTIME_H
44 # include <utime.h>
45 #endif
46 #include <ctype.h>
47 #include "windef.h"
48 #include "winbase.h"
49 #include "winternl.h"
50 #include "wingdi.h"
51 #include "winuser.h" /* SW_NORMAL */
52 #include "wine/winbase16.h"
53 #include "winerror.h"
54 #include "drive.h"
55 #include "file.h"
56 #include "callback.h"
57 #include "msdos.h"
58 #include "miscemu.h"
59 #include "task.h"
60 #include "wine/unicode.h"
61 #include "wine/debug.h"
63 WINE_DEFAULT_DEBUG_CHANNEL(int21);
64 #if defined(__svr4__) || defined(_SCO_DS)
65 /* SVR4 DOESNT do locking the same way must implement properly */
66 #define LOCK_EX 0
67 #define LOCK_SH 1
68 #define LOCK_NB 8
69 #endif
72 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
74 /* Define the drive parameter block, as used by int21/1F
75 * and int21/32. This table can be accessed through the
76 * global 'dpb' pointer, which points into the local dos
77 * heap.
79 struct DPB
81 BYTE drive_num; /* 0=A, etc. */
82 BYTE unit_num; /* Drive's unit number (?) */
83 WORD sector_size; /* Sector size in bytes */
84 BYTE high_sector; /* Highest sector in a cluster */
85 BYTE shift; /* Shift count (?) */
86 WORD reserved; /* Number of reserved sectors at start */
87 BYTE num_FAT; /* Number of FATs */
88 WORD dir_entries; /* Number of root dir entries */
89 WORD first_data; /* First data sector */
90 WORD high_cluster; /* Highest cluster number */
91 WORD sectors_in_FAT; /* Number of sectors per FAT */
92 WORD start_dir; /* Starting sector of first dir */
93 DWORD driver_head; /* Address of device driver header (?) */
94 BYTE media_ID; /* Media ID */
95 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
96 DWORD next; /* Pointer to next DPB in list */
97 WORD free_search; /* Free cluster search start */
98 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
101 struct EDPB /* FAT32 extended Drive Parameter Block */
102 { /* from Ralf Brown's Interrupt List */
103 struct DPB dpb; /* first 24 bytes = original DPB */
105 BYTE edpb_flags; /* undocumented/unknown flags */
106 DWORD next_edpb; /* pointer to next EDPB */
107 WORD free_cluster; /* cluster to start search for free space on write, typically
108 the last cluster allocated */
109 WORD clusters_free; /* number of free clusters on drive or FFFF = unknown */
110 WORD clusters_free_hi; /* hiword of clusters_free */
111 WORD mirroring_flags; /* mirroring flags: bit 7 set = do not mirror active FAT */
112 /* bits 0-3 = 0-based number of the active FAT */
113 WORD info_sector; /* sector number of file system info sector, or FFFF for none */
114 WORD spare_boot_sector; /* sector number of backup boot sector, or FFFF for none */
115 DWORD first_cluster; /* sector number of the first cluster */
116 DWORD max_cluster; /* sector number of the last cluster */
117 DWORD fat_clusters; /* number of clusters occupied by FAT */
118 DWORD root_cluster; /* cluster number of start of root directory */
119 DWORD free_cluster2; /* same as free_cluster: cluster at which to start
120 search for free space when writing */
124 DWORD dpbsegptr;
126 struct DosHeap {
127 BYTE mediaID;
128 BYTE biosdate[8];
129 struct DPB dpb;
131 static struct DosHeap *heap;
132 static WORD DosHeapHandle;
134 extern char TempDirectory[];
136 static BOOL INT21_CreateHeap(void)
138 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
140 WARN("Out of memory\n");
141 return FALSE;
143 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
144 dpbsegptr = MAKESEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
145 strcpy(heap->biosdate, "01/01/80");
146 return TRUE;
149 static BYTE *GetCurrentDTA( CONTEXT86 *context )
151 TDB *pTask = TASK_GetCurrent();
153 /* FIXME: This assumes DTA was set correctly! */
154 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
155 (DWORD)OFFSETOF(pTask->dta) );
159 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
160 /* limited == TRUE is used with INT 0x21/0x440d */
162 if (drive > 1) {
163 setword(data, 512);
164 data[2] = 2;
165 setword(&data[3], 0);
166 data[5] = 2;
167 setword(&data[6], 240);
168 setword(&data[8], 64000);
169 data[0x0a] = 0xf8;
170 setword(&data[0x0b], 40);
171 setword(&data[0x0d], 56);
172 setword(&data[0x0f], 2);
173 setword(&data[0x11], 0);
174 if (!limited) {
175 setword(&data[0x1f], 800);
176 data[0x21] = 5;
177 setword(&data[0x22], 1);
179 } else { /* 1.44mb */
180 setword(data, 512);
181 data[2] = 2;
182 setword(&data[3], 0);
183 data[5] = 2;
184 setword(&data[6], 240);
185 setword(&data[8], 2880);
186 data[0x0a] = 0xf8;
187 setword(&data[0x0b], 6);
188 setword(&data[0x0d], 18);
189 setword(&data[0x0f], 2);
190 setword(&data[0x11], 0);
191 if (!limited) {
192 setword(&data[0x1f], 80);
193 data[0x21] = 7;
194 setword(&data[0x22], 2);
199 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
201 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
202 char root[] = "A:\\";
204 *root += DOS_GET_DRIVE( DL_reg(context) );
205 if (!GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
206 &free_clusters, &total_clusters )) return 0;
207 SET_AX( context, cluster_sectors );
208 SET_BX( context, free_clusters );
209 SET_CX( context, sector_bytes );
210 SET_DX( context, total_clusters );
211 return 1;
214 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
216 if (!INT21_GetFreeDiskSpace( context )) return 0;
217 if (!heap && !INT21_CreateHeap()) return 0;
218 heap->mediaID = 0xf0;
219 context->SegDs = DosHeapHandle;
220 SET_BX( context, (int)&heap->mediaID - (int)heap );
221 return 1;
224 static int FillInDrivePB( int drive )
226 if(!DRIVE_IsValid(drive))
228 SetLastError( ERROR_INVALID_DRIVE );
229 return 0;
231 else if (heap || INT21_CreateHeap())
233 /* FIXME: I have no idea what a lot of this information should
234 * say or whether it even really matters since we're not allowing
235 * direct block access. However, some programs seem to depend on
236 * getting at least _something_ back from here. The 'next' pointer
237 * does worry me, though. Should we have a complete table of
238 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
240 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
241 heap->dpb.sector_size = 512;
242 heap->dpb.high_sector = 1;
243 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
244 heap->dpb.reserved = 0;
245 heap->dpb.num_FAT = 1;
246 heap->dpb.dir_entries = 2;
247 heap->dpb.first_data = 2;
248 heap->dpb.high_cluster = 64000;
249 heap->dpb.sectors_in_FAT = 1;
250 heap->dpb.start_dir = 1;
251 heap->dpb.driver_head = 0;
252 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
253 heap->dpb.access_flag = 0;
254 heap->dpb.next = 0;
255 heap->dpb.free_search = 0;
256 heap->dpb.free_clusters = 0xFFFF; /* unknown */
257 return 1;
260 return 0;
263 static void GetDrivePB( CONTEXT86 *context, int drive )
265 if (FillInDrivePB( drive ))
267 SET_AL( context, 0x00 );
268 context->SegDs = SELECTOROF(dpbsegptr);
269 SET_BX( context, OFFSETOF(dpbsegptr) );
271 else
273 SET_AX( context, 0x00ff );
278 static void ioctlGetDeviceInfo( CONTEXT86 *context )
280 int curr_drive;
281 const DOS_DEVICE *dev;
283 TRACE("(%d)\n", BX_reg(context));
285 RESET_CFLAG(context);
287 /* DOS device ? */
288 if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )))
290 SET_DX( context, dev->flags );
291 return;
294 /* it seems to be a file */
295 curr_drive = DRIVE_GetCurrentDrive();
296 SET_DX( context, 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0) );
297 /* no floppy */
298 /* bits 0-5 are current drive
299 * bit 6 - file has NOT been written..FIXME: correct?
300 * bit 8 - generate int24 if no diskspace on write/ read past end of file
301 * bit 11 - media not removable
302 * bit 14 - don't set file date/time on closing
303 * bit 15 - file is remote
307 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
309 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
310 int drive = DOS_GET_DRIVE( BL_reg(context) );
312 if (!DRIVE_IsValid(drive))
314 SetLastError( ERROR_FILE_NOT_FOUND );
315 return TRUE;
318 if (CH_reg(context) != 0x08)
320 INT_BARF( context, 0x21 );
321 return FALSE;
324 switch (CL_reg(context))
326 case 0x4a: /* lock logical volume */
327 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
328 break;
330 case 0x60: /* get device parameters */
331 /* used by w4wgrp's winfile */
332 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
333 dataptr[0] = 0x04;
334 dataptr[6] = 0; /* media type */
335 if (drive > 1)
337 dataptr[1] = 0x05; /* fixed disk */
338 setword(&dataptr[2], 0x01); /* non removable */
339 setword(&dataptr[4], 0x300); /* # of cylinders */
341 else
343 dataptr[1] = 0x07; /* block dev, floppy */
344 setword(&dataptr[2], 0x02); /* removable */
345 setword(&dataptr[4], 80); /* # of cylinders */
347 CreateBPB(drive, &dataptr[7], TRUE);
348 RESET_CFLAG(context);
349 break;
351 case 0x41: /* write logical device track */
352 case 0x61: /* read logical device track */
354 BYTE drive = BL_reg(context) ?
355 BL_reg(context) : DRIVE_GetCurrentDrive();
356 WORD head = *(WORD *)dataptr+1;
357 WORD cyl = *(WORD *)dataptr+3;
358 WORD sect = *(WORD *)dataptr+5;
359 WORD nrsect = *(WORD *)dataptr+7;
360 BYTE *data = (BYTE *)dataptr+9;
361 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
363 raw_func = (CL_reg(context) == 0x41) ?
364 DRIVE_RawWrite : DRIVE_RawRead;
366 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
367 RESET_CFLAG(context);
368 else
370 SET_AX( context, 0x1e ); /* read fault */
371 SET_CFLAG(context);
374 break;
375 case 0x66:/* get disk serial number */
377 char label[12],fsname[9],path[4];
378 DWORD serial;
380 strcpy(path,"x:\\");path[0]=drive+'A';
381 GetVolumeInformationA(
382 path,label,12,&serial,NULL,NULL,fsname,9
384 *(WORD*)dataptr = 0;
385 memcpy(dataptr+2,&serial,4);
386 memcpy(dataptr+6,label ,11);
387 memcpy(dataptr+17,fsname,8);
389 break;
391 case 0x6a:
392 TRACE("logical volume %d unlocked.\n",drive);
393 break;
395 case 0x6f:
396 memset(dataptr+1, '\0', dataptr[0]-1);
397 dataptr[1] = dataptr[0];
398 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
399 dataptr[3] = 0xFF; /* no physical drive */
400 break;
402 case 0x72:
403 /* Trail on error implementation */
404 SET_AX( context, GetDriveType16(BL_reg(context)) == DRIVE_UNKNOWN ? 0x0f : 0x01 );
405 SET_CFLAG(context); /* Seems to be set all the time */
406 break;
408 default:
409 INT_BARF( context, 0x21 );
411 return FALSE;
414 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
416 char *filename =
417 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
418 char *fcb =
419 CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi );
420 char *s;
421 WCHAR *buffer;
422 WCHAR fcbW[12];
423 INT buffer_len, len;
425 SET_AL( context, 0xff ); /* failed */
427 TRACE("filename: '%s'\n", filename);
429 s = filename;
430 len = 0;
431 while (*s)
433 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
435 s++;
436 len++;
438 else
439 break;
442 buffer_len = MultiByteToWideChar(CP_OEMCP, 0, filename, len, NULL, 0);
443 buffer = HeapAlloc( GetProcessHeap(), 0, (buffer_len + 1) * sizeof(WCHAR));
444 len = MultiByteToWideChar(CP_OEMCP, 0, filename, len, buffer, buffer_len);
445 buffer[len] = 0;
446 DOSFS_ToDosFCBFormat(buffer, fcbW);
447 HeapFree(GetProcessHeap(), 0, buffer);
448 WideCharToMultiByte(CP_OEMCP, 0, fcbW, 12, fcb + 1, 12, NULL, NULL);
449 *fcb = 0;
450 TRACE("FCB: '%s'\n", fcb + 1);
452 SET_AL( context, ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0 );
454 /* point DS:SI to first unparsed character */
455 SET_SI( context, context->Esi + (int)s - (int)filename );
459 /* Many calls translate a drive argument like this:
460 drive number (00h = default, 01h = A:, etc)
462 static char drivestring[]="default";
464 char *INT21_DriveName(int drive)
467 if(drive >0)
469 drivestring[0]= (unsigned char)drive + '@';
470 drivestring[1]=':';
471 drivestring[2]=0;
473 return drivestring;
475 static BOOL INT21_CreateFile( CONTEXT86 *context )
477 SET_AX( context, _lcreat16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
478 context->Edx ), CX_reg(context) ) );
479 return (AX_reg(context) == (WORD)HFILE_ERROR16);
482 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
484 /* Mask off all flags not explicitly allowed by the doc */
485 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
486 return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
487 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
488 CREATE_NEW, attr, 0 ));
491 static void OpenExistingFile( CONTEXT86 *context )
493 SET_AX( context, _lopen16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
494 AL_reg(context) ));
495 if (AX_reg(context) == (WORD)HFILE_ERROR16)
497 SET_AX( context, GetLastError() );
498 SET_CFLAG(context);
502 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
504 BOOL bExtendedError = FALSE;
505 BYTE action = DL_reg(context);
507 /* Shuffle arguments to call OpenExistingFile */
508 SET_AL( context, BL_reg(context) );
509 SET_DX( context, SI_reg(context) );
510 /* BX,CX and DX should be preserved */
511 OpenExistingFile(context);
513 if ((context->EFlags & 0x0001) == 0) /* File exists */
515 UINT16 uReturnCX = 0;
517 /* Now decide what do do */
519 if ((action & 0x07) == 0)
521 _lclose16( AX_reg(context) );
522 SET_AX( context, 0x0050 ); /*File exists*/
523 SET_CFLAG(context);
524 WARN("extended open/create: failed because file exists \n");
526 else if ((action & 0x07) == 2)
528 /* Truncate it, but first check if opened for write */
529 if ((BL_reg(context) & 0x0007)== 0)
531 _lclose16( AX_reg(context) );
532 WARN("extended open/create: failed, trunc on ro file\n");
533 SET_AX( context, 0x000C ); /*Access code invalid*/
534 SET_CFLAG(context);
536 else
538 TRACE("extended open/create: Closing before truncate\n");
539 if (_lclose16( AX_reg(context) ))
541 WARN("extended open/create: close before trunc failed\n");
542 SET_AX( context, 0x0019 ); /*Seek Error*/
543 SET_CX( context, 0 );
544 SET_CFLAG(context);
546 /* Shuffle arguments to call CreateFile */
548 TRACE("extended open/create: Truncating\n");
549 SET_AL( context, BL_reg(context) );
550 /* CX is still the same */
551 SET_DX( context, SI_reg(context) );
552 bExtendedError = INT21_CreateFile(context);
554 if (context->EFlags & 0x0001) /*no file open, flags set */
556 WARN("extended open/create: trunc failed\n");
557 return bExtendedError;
559 uReturnCX = 0x3;
562 else uReturnCX = 0x1;
564 SET_CX( context, uReturnCX );
566 else /* file does not exist */
568 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
569 if ((action & 0xF0)== 0)
571 SET_CX( context, 0 );
572 SET_CFLAG(context);
573 WARN("extended open/create: failed, file dosen't exist\n");
575 else
577 /* Shuffle arguments to call CreateFile */
578 TRACE("extended open/create: Creating\n");
579 SET_AL( context, BL_reg(context) );
580 /* CX should still be the same */
581 SET_DX( context, SI_reg(context) );
582 bExtendedError = INT21_CreateFile(context);
583 if (context->EFlags & 0x0001) /*no file open, flags set */
585 WARN("extended open/create: create failed\n");
586 return bExtendedError;
588 SET_CX( context, 2 );
592 return bExtendedError;
596 static BOOL INT21_ChangeDir( CONTEXT86 *context )
598 int drive;
599 char *dirname = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
600 WCHAR dirnameW[MAX_PATH];
602 TRACE("changedir %s\n", dirname);
603 if (dirname[0] && (dirname[1] == ':'))
605 drive = toupper(dirname[0]) - 'A';
606 dirname += 2;
608 else drive = DRIVE_GetCurrentDrive();
609 MultiByteToWideChar(CP_OEMCP, 0, dirname, -1, dirnameW, MAX_PATH);
610 return DRIVE_Chdir( drive, dirnameW );
614 static int INT21_FindFirst( CONTEXT86 *context )
616 char *p;
617 const char *path;
618 DOS_FULL_NAME full_name;
619 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
620 WCHAR pathW[MAX_PATH];
621 WCHAR maskW[12];
623 path = (const char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
624 MultiByteToWideChar(CP_OEMCP, 0, path, -1, pathW, MAX_PATH);
626 dta->unixPath = NULL;
627 if (!DOSFS_GetFullName( pathW, FALSE, &full_name ))
629 SET_AX( context, GetLastError() );
630 SET_CFLAG(context);
631 return 0;
633 dta->unixPath = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
634 strcpy( dta->unixPath, full_name.long_name );
635 p = strrchr( dta->unixPath, '/' );
636 *p = '\0';
638 MultiByteToWideChar(CP_OEMCP, 0, p + 1, -1, pathW, MAX_PATH);
640 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
641 * (doesn't matter as it is set below anyway)
643 if (!DOSFS_ToDosFCBFormat( pathW, maskW ))
645 HeapFree( GetProcessHeap(), 0, dta->unixPath );
646 dta->unixPath = NULL;
647 SetLastError( ERROR_FILE_NOT_FOUND );
648 SET_AX( context, ERROR_FILE_NOT_FOUND );
649 SET_CFLAG(context);
650 return 0;
652 WideCharToMultiByte(CP_OEMCP, 0, maskW, 12, dta->mask, sizeof(dta->mask), NULL, NULL);
653 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
654 : DRIVE_GetCurrentDrive();
655 dta->count = 0;
656 dta->search_attr = CL_reg(context);
657 return 1;
661 static int INT21_FindNext( CONTEXT86 *context )
663 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
664 WIN32_FIND_DATAA entry;
665 int count;
667 if (!dta->unixPath) return 0;
668 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
669 dta->search_attr, dta->count, &entry )))
671 HeapFree( GetProcessHeap(), 0, dta->unixPath );
672 dta->unixPath = NULL;
673 return 0;
675 if ((int)dta->count + count > 0xffff)
677 WARN("Too many directory entries in %s\n", dta->unixPath );
678 HeapFree( GetProcessHeap(), 0, dta->unixPath );
679 dta->unixPath = NULL;
680 return 0;
682 dta->count += count;
683 dta->fileattr = entry.dwFileAttributes;
684 dta->filesize = entry.nFileSizeLow;
685 FileTimeToDosDateTime( &entry.ftLastWriteTime,
686 &dta->filedate, &dta->filetime );
687 strcpy( dta->filename, entry.cAlternateFileName );
688 if (!memchr(dta->mask,'?',11)) {
689 /* wildcardless search, release resources in case no findnext will
690 * be issued, and as a workaround in case file creation messes up
691 * findnext, as sometimes happens with pkunzip */
692 HeapFree( GetProcessHeap(), 0, dta->unixPath );
693 dta->unixPath = NULL;
695 return 1;
699 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
701 static int counter = 0;
702 char *name = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx );
703 char *p = name + strlen(name);
705 /* despite what Ralf Brown says, some programs seem to call without
706 * ending backslash (DOS accepts that, so we accept it too) */
707 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
709 for (;;)
711 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
712 counter = (counter + 1) % 1000;
714 SET_AX( context, _lcreat16_uniq( name, 0 ) );
715 if (AX_reg(context) != HFILE_ERROR16)
717 TRACE("created %s\n", name );
718 return TRUE;
720 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
725 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
727 int drive = DOS_GET_DRIVE( DL_reg(context) );
728 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
730 if (!DRIVE_IsValid(drive))
732 SetLastError( ERROR_INVALID_DRIVE );
733 return FALSE;
735 WideCharToMultiByte(CP_OEMCP, 0, DRIVE_GetDosCwd(drive), -1, ptr, 64, NULL, NULL);
736 ptr[63] = 0; /* ensure 0 termination */
737 SET_AX( context, 0x0100 ); /* success return code */
738 return TRUE;
742 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
744 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
745 int drive = DOS_GET_DRIVE( BL_reg(context) );
747 if (!DRIVE_IsValid(drive))
749 SetLastError( ERROR_INVALID_DRIVE );
750 return 0;
753 *(WORD *)dataptr = 0;
754 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
755 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
756 strncpy(dataptr + 0x11, "FAT16 ", 8);
757 return 1;
761 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
763 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
764 int drive = DOS_GET_DRIVE( BL_reg(context) );
766 if (!DRIVE_IsValid(drive))
768 SetLastError( ERROR_INVALID_DRIVE );
769 return 0;
772 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
773 return 1;
777 /* microsoft's programmers should be shot for using CP/M style int21
778 calls in Windows for Workgroup's winfile.exe */
780 static int INT21_FindFirstFCB( CONTEXT86 *context )
782 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
783 FINDFILE_FCB *pFCB;
784 LPCSTR root, cwd;
785 int drive;
787 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
788 else pFCB = (FINDFILE_FCB *)fcb;
789 drive = DOS_GET_DRIVE( pFCB->drive );
790 if (!DRIVE_IsValid( drive )) return 0;
791 root = DRIVE_GetRoot( drive );
792 cwd = DRIVE_GetUnixCwd( drive );
793 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
794 strlen(root)+strlen(cwd)+2 );
795 if (!pFCB->unixPath) return 0;
796 strcpy( pFCB->unixPath, root );
797 strcat( pFCB->unixPath, "/" );
798 strcat( pFCB->unixPath, cwd );
799 pFCB->count = 0;
800 return 1;
804 static int INT21_FindNextFCB( CONTEXT86 *context )
806 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
807 FINDFILE_FCB *pFCB;
808 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
809 WIN32_FIND_DATAA entry;
810 BYTE attr;
811 int count;
813 if (*fcb == 0xff) /* extended FCB ? */
815 attr = fcb[6];
816 pFCB = (FINDFILE_FCB *)(fcb + 7);
818 else
820 attr = 0;
821 pFCB = (FINDFILE_FCB *)fcb;
824 if (!pFCB->unixPath) return 0;
825 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
826 DOS_GET_DRIVE( pFCB->drive ), attr,
827 pFCB->count, &entry )))
829 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
830 pFCB->unixPath = NULL;
831 return 0;
833 pFCB->count += count;
835 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
836 *(BYTE *)pResult = 0xff;
837 (BYTE *)pResult +=6; /* leave reserved field behind */
838 *(BYTE *)pResult = entry.dwFileAttributes;
839 ((BYTE *)pResult)++;
841 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
842 ((BYTE *)pResult)++;
843 pResult->fileattr = entry.dwFileAttributes;
844 pResult->cluster = 0; /* what else? */
845 pResult->filesize = entry.nFileSizeLow;
846 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
847 FileTimeToDosDateTime( &entry.ftLastWriteTime,
848 &pResult->filedate, &pResult->filetime );
850 /* Convert file name to FCB format */
852 memset( pResult->filename, ' ', sizeof(pResult->filename) );
853 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
854 else if (!strcmp( entry.cAlternateFileName, ".." ))
855 pResult->filename[0] = pResult->filename[1] = '.';
856 else
858 char *p = strrchr( entry.cAlternateFileName, '.' );
859 if (p && p[1] && (p != entry.cAlternateFileName))
861 memcpy( pResult->filename, entry.cAlternateFileName,
862 min( (p - entry.cAlternateFileName), 8 ) );
863 memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
865 else
866 memcpy( pResult->filename, entry.cAlternateFileName,
867 min( strlen(entry.cAlternateFileName), 8 ) );
869 return 1;
873 static BOOL
874 INT21_networkfunc (CONTEXT86 *context)
876 switch (AL_reg(context)) {
877 case 0x00: /* Get machine name. */
879 char *dst = CTX_SEG_OFF_TO_LIN (context,context->SegDs,context->Edx);
880 TRACE("getting machine name to %p\n", dst);
881 if (gethostname (dst, 15))
883 WARN("failed!\n");
884 SetLastError( ER_NoNetwork );
885 return TRUE;
886 } else {
887 int len = strlen (dst);
888 while (len < 15)
889 dst[len++] = ' ';
890 dst[15] = 0;
891 SET_CH( context, 1 ); /* Valid */
892 SET_CL( context, 1 ); /* NETbios number??? */
893 TRACE("returning %s\n", debugstr_an (dst, 16));
894 return FALSE;
898 default:
899 SetLastError( ER_NoNetwork );
900 return TRUE;
905 /***********************************************************************
906 * INT_Int21Handler
908 void WINAPI INT_Int21Handler( CONTEXT86 *context )
910 BOOL bSetDOSExtendedError = FALSE;
912 switch(AH_reg(context))
914 case 0x0e: /* SELECT DEFAULT DRIVE */
915 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
916 DRIVE_SetCurrentDrive( DL_reg(context) );
917 SET_AL( context, MAX_DOS_DRIVES );
918 break;
920 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
921 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
922 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
923 if (!INT21_FindFirstFCB(context))
925 SET_AL( context, 0xff );
926 break;
928 /* else fall through */
930 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
931 SET_AL( context, INT21_FindNextFCB(context) ? 0x00 : 0xff );
932 break;
934 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
935 SET_DL( context, 0 );
936 if (!INT21_GetDriveAllocInfo(context)) SET_AX( context, 0xffff );
937 break;
939 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
940 if (!INT21_GetDriveAllocInfo(context)) SET_AX( context, 0xffff );
941 break;
943 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
944 GetDrivePB(context, DRIVE_GetCurrentDrive());
945 break;
947 case 0x29: /* PARSE FILENAME INTO FCB */
948 INT21_ParseFileNameIntoFCB(context);
949 break;
951 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
952 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
953 INT21_DriveName( DL_reg(context)));
954 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
955 break;
957 case 0x36: /* GET FREE DISK SPACE */
958 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
959 INT21_DriveName( DL_reg(context)));
960 if (!INT21_GetFreeDiskSpace(context)) SET_AX( context, 0xffff );
961 break;
963 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
964 TRACE("CHDIR %s\n",
965 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
966 bSetDOSExtendedError = !INT21_ChangeDir(context);
967 break;
969 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
970 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
971 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
972 bSetDOSExtendedError = INT21_CreateFile( context );
973 break;
975 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
976 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
977 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
978 OpenExistingFile(context);
979 break;
981 case 0x44: /* IOCTL */
982 switch (AL_reg(context))
984 case 0x00:
985 ioctlGetDeviceInfo(context);
986 break;
988 case 0x01:
989 break;
991 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
992 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
993 int drive = DOS_GET_DRIVE(BL_reg(context));
995 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
996 /* for (i=0;i<CX_reg(context);i++)
997 fprintf(stdnimp,"%02x ",dataptr[i]);
998 fprintf(stdnimp,"\n");*/
999 SET_AX( context, context->Ecx );
1000 break;
1002 case 0x08: /* Check if drive is removable. */
1003 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1004 INT21_DriveName( BL_reg(context)));
1005 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1007 case DRIVE_UNKNOWN:
1008 SetLastError( ERROR_INVALID_DRIVE );
1009 SET_AX( context, ERROR_INVALID_DRIVE );
1010 SET_CFLAG(context);
1011 break;
1012 case DRIVE_REMOVABLE:
1013 SET_AX( context, 0 ); /* removable */
1014 break;
1015 default:
1016 SET_AX( context, 1 ); /* not removable */
1017 break;
1019 break;
1021 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1022 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1023 INT21_DriveName( BL_reg(context)));
1024 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1026 case DRIVE_UNKNOWN:
1027 SetLastError( ERROR_INVALID_DRIVE );
1028 SET_AX( context, ERROR_INVALID_DRIVE );
1029 SET_CFLAG(context);
1030 break;
1031 case DRIVE_REMOTE:
1032 SET_DX( context, (1<<9) | (1<<12) ); /* remote */
1033 break;
1034 default:
1035 SET_DX( context, 0 ); /* FIXME: use driver attr here */
1036 break;
1038 break;
1040 case 0x0a: /* check if handle (BX) is remote */
1041 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1042 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1043 * not set on close
1045 SET_DX( context, 0 );
1046 break;
1048 case 0x0d:
1049 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1050 INT21_DriveName( BL_reg(context)));
1051 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1052 break;
1054 case 0x0e: /* get logical drive mapping */
1055 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1056 INT21_DriveName( BL_reg(context)));
1057 SET_AL( context, 0 ); /* drive has no mapping - FIXME: may be wrong*/
1058 break;
1060 case 0x0F: /* Set logical drive mapping */
1062 int drive;
1063 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1064 INT21_DriveName( BL_reg(context)));
1065 drive = DOS_GET_DRIVE ( BL_reg(context) );
1066 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1068 SET_CFLAG(context);
1069 SET_AX( context, 0x000F ); /* invalid drive */
1071 break;
1074 default:
1075 INT_BARF( context, 0x21 );
1076 break;
1078 break;
1080 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1081 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1082 INT21_DriveName( DL_reg(context)));
1083 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1084 break;
1086 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1087 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1088 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1089 if (!INT21_FindFirst(context)) break;
1090 /* fall through */
1092 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1093 TRACE("FINDNEXT\n");
1094 if (!INT21_FindNext(context))
1096 SetLastError( ERROR_NO_MORE_FILES );
1097 SET_AX( context, ERROR_NO_MORE_FILES );
1098 SET_CFLAG(context);
1100 else SET_AX( context, 0 ); /* OK */
1101 break;
1103 case 0x5a: /* CREATE TEMPORARY FILE */
1104 TRACE("CREATE TEMPORARY FILE\n");
1105 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1106 break;
1108 case 0x5b: /* CREATE NEW FILE */
1109 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1110 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1111 SET_AX( context,
1112 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1113 CX_reg(context) ));
1114 bSetDOSExtendedError = (AX_reg(context) != 0);
1115 break;
1117 case 0x5e:
1118 bSetDOSExtendedError = INT21_networkfunc (context);
1119 break;
1121 case 0x5f: /* NETWORK */
1122 switch (AL_reg(context))
1124 case 0x07: /* ENABLE DRIVE */
1125 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1126 if (!DRIVE_Enable( DL_reg(context) ))
1128 SetLastError( ERROR_INVALID_DRIVE );
1129 bSetDOSExtendedError = TRUE;
1131 break;
1133 case 0x08: /* DISABLE DRIVE */
1134 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1135 if (!DRIVE_Disable( DL_reg(context) ))
1137 SetLastError( ERROR_INVALID_DRIVE );
1138 bSetDOSExtendedError = TRUE;
1140 break;
1142 default:
1143 /* network software not installed */
1144 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1145 SetLastError( ER_NoNetwork );
1146 bSetDOSExtendedError = TRUE;
1147 break;
1149 break;
1151 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1152 TRACE("TRUENAME %s\n",
1153 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Esi));
1155 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1156 context->Esi), 128,
1157 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1158 context->Edi),NULL))
1159 bSetDOSExtendedError = TRUE;
1160 else SET_AX( context, 0 );
1162 break;
1164 case 0x69: /* DISK SERIAL NUMBER */
1165 switch (AL_reg(context))
1167 case 0x00:
1168 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
1169 INT21_DriveName(BL_reg(context)));
1170 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1171 else SET_AX( context, 0 );
1172 break;
1174 case 0x01:
1175 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
1176 INT21_DriveName(BL_reg(context)));
1177 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1178 else SET_AX( context, 1 );
1179 break;
1181 break;
1183 case 0x6C: /* Extended Open/Create*/
1184 TRACE("EXTENDED OPEN/CREATE %s\n",
1185 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edi));
1186 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1187 break;
1189 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1190 switch(AL_reg(context))
1192 case 0x47: /* Get current directory */
1193 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1194 INT21_DriveName(DL_reg(context)));
1195 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1196 break;
1198 case 0x4e: /* Find first file */
1199 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1200 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
1201 /* FIXME: use attributes in CX */
1202 SET_AX( context, FindFirstFile16(
1203 CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1204 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1205 context->Edi)));
1206 if (AX_reg(context) == INVALID_HANDLE_VALUE16)
1207 bSetDOSExtendedError = TRUE;
1208 break;
1209 case 0x4f: /* Find next file */
1210 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1211 BX_reg(context));
1212 if (!FindNextFile16( BX_reg(context),
1213 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1214 context->Edi)))
1215 bSetDOSExtendedError = TRUE;
1216 break;
1217 case 0xa0:
1219 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
1220 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
1221 DWORD filename_len, flags;
1223 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
1224 SET_AX( context, 0 );
1225 if (!GetVolumeInformationA( driveroot, NULL, 0, NULL, &filename_len,
1226 &flags, buffer, 8 ))
1228 INT_BARF( context, 0x21 );
1229 SET_CFLAG(context);
1230 break;
1232 SET_BX( context, flags | 0x4000 ); /* support for LFN functions */
1233 SET_CX( context, filename_len );
1234 SET_DX( context, MAX_PATH ); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
1236 break;
1237 case 0xa1: /* Find close */
1238 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
1239 BX_reg(context));
1240 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1241 break;
1242 case 0x60:
1243 switch(CL_reg(context))
1245 case 0x01: /* Get short filename or path */
1246 if (!GetShortPathNameA
1247 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1248 context->Esi),
1249 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1250 context->Edi), 67))
1251 bSetDOSExtendedError = TRUE;
1252 else SET_AX( context, 0 );
1253 break;
1254 case 0x02: /* Get canonical long filename or path */
1255 if (!GetFullPathNameA
1256 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1257 context->Esi), 128,
1258 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1259 context->Edi),NULL))
1260 bSetDOSExtendedError = TRUE;
1261 else SET_AX( context, 0 );
1262 break;
1263 default:
1264 FIXME("Unimplemented long file name function:\n");
1265 INT_BARF( context, 0x21 );
1266 SET_CFLAG(context);
1267 SET_AL( context, 0 );
1268 break;
1270 break;
1271 case 0x6c: /* Create or open file */
1272 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
1273 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi));
1274 /* translate Dos 7 action to Dos 6 action */
1275 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1276 break;
1278 case 0x3b: /* Change directory */
1279 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
1280 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1281 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
1282 context->SegDs,
1283 context->Edx
1286 SET_CFLAG(context);
1287 SET_AL( context, GetLastError() );
1289 break;
1291 default:
1292 FIXME("Unimplemented long file name function:\n");
1293 INT_BARF( context, 0x21 );
1294 SET_CFLAG(context);
1295 SET_AL( context, 0 );
1296 break;
1298 break;
1301 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
1302 TRACE("windows95 function AX %04x\n",
1303 AX_reg(context));
1305 switch (AL_reg(context))
1307 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
1308 /* ES:DI points to word with length of data (should be 0x3d) */
1310 WORD *buffer;
1311 struct EDPB *edpb;
1312 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
1313 char root[] = "A:\\";
1315 buffer = (WORD *)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
1317 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer);
1319 /* validate passed-in buffer lengths */
1320 if ((*buffer != 0x3d) || (context->Ecx != 0x3f))
1322 WARN("Get Extended DPB: buffer lengths incorrect\n");
1323 WARN("CX = %lx, buffer[0] = %x\n", context->Ecx, *buffer);
1324 SET_CFLAG(context);
1325 SET_AL( context, 0x18 ); /* bad buffer length */
1328 /* buffer checks out */
1329 buffer++; /* skip over length word now */
1330 if (FillInDrivePB( DX_reg(context) ) )
1332 edpb = (struct EDPB *)buffer;
1334 /* copy down the old-style DPB portion first */
1335 memcpy(&edpb->dpb, &heap->dpb, sizeof(struct DPB));
1337 /* now fill in the extended entries */
1338 edpb->edpb_flags = 0;
1339 edpb->next_edpb = 0;
1340 edpb->free_cluster = edpb->free_cluster2 = 0;
1342 /* determine free disk space */
1343 *root += DOS_GET_DRIVE( DX_reg(context) );
1344 GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
1345 &free_clusters, &total_clusters );
1347 edpb->clusters_free = (free_clusters&0xffff);
1349 edpb->clusters_free_hi = free_clusters >> 16;
1350 edpb->mirroring_flags = 0;
1351 edpb->info_sector = 0xffff;
1352 edpb->spare_boot_sector = 0xffff;
1353 edpb->first_cluster = 0;
1354 edpb->max_cluster = total_clusters;
1355 edpb->fat_clusters = 32; /* made-up value */
1356 edpb->root_cluster = 0;
1358 RESET_CFLAG(context); /* clear carry */
1359 SET_AX( context, 0 );
1361 else
1363 SET_AX( context, 0x00ff );
1364 SET_CFLAG(context);
1367 break;
1369 case 0x03: /* Get Extended free space on drive */
1370 case 0x04: /* Set DPB for formatting */
1371 case 0x05: /* extended absolute disk read/write */
1372 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context));
1373 SET_CFLAG(context);
1374 SET_AL( context, 0 );
1375 break;
1378 break;
1380 default:
1381 INT_BARF( context, 0x21 );
1382 break;
1384 } /* END OF SWITCH */
1386 if( bSetDOSExtendedError ) /* set general error condition */
1388 SET_AX( context, GetLastError() );
1389 SET_CFLAG(context);