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
26 #include "wine/port.h"
33 #ifdef HAVE_SYS_FILE_H
34 # include <sys/file.h>
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
40 #include <sys/types.h>
53 #include "winuser.h" /* SW_NORMAL */
54 #include "wine/winbase16.h"
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(int21);
66 #if defined(__svr4__) || defined(_SCO_DS)
67 /* SVR4 DOESNT do locking the same way must implement properly */
74 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
76 /* Define the drive parameter block, as used by int21/1F
77 * and int21/32. This table can be accessed through the
78 * global 'dpb' pointer, which points into the local dos
83 BYTE drive_num; /* 0=A, etc. */
84 BYTE unit_num; /* Drive's unit number (?) */
85 WORD sector_size; /* Sector size in bytes */
86 BYTE high_sector; /* Highest sector in a cluster */
87 BYTE shift; /* Shift count (?) */
88 WORD reserved; /* Number of reserved sectors at start */
89 BYTE num_FAT; /* Number of FATs */
90 WORD dir_entries; /* Number of root dir entries */
91 WORD first_data; /* First data sector */
92 WORD high_cluster; /* Highest cluster number */
93 WORD sectors_in_FAT; /* Number of sectors per FAT */
94 WORD start_dir; /* Starting sector of first dir */
95 DWORD driver_head; /* Address of device driver header (?) */
96 BYTE media_ID; /* Media ID */
97 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
98 DWORD next; /* Pointer to next DPB in list */
99 WORD free_search; /* Free cluster search start */
100 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
103 struct EDPB /* FAT32 extended Drive Parameter Block */
104 { /* from Ralf Brown's Interrupt List */
105 struct DPB dpb; /* first 24 bytes = original DPB */
107 BYTE edpb_flags; /* undocumented/unknown flags */
108 DWORD next_edpb; /* pointer to next EDPB */
109 WORD free_cluster; /* cluster to start search for free space on write, typically
110 the last cluster allocated */
111 WORD clusters_free; /* number of free clusters on drive or FFFF = unknown */
112 WORD clusters_free_hi; /* hiword of clusters_free */
113 WORD mirroring_flags; /* mirroring flags: bit 7 set = do not mirror active FAT */
114 /* bits 0-3 = 0-based number of the active FAT */
115 WORD info_sector; /* sector number of file system info sector, or FFFF for none */
116 WORD spare_boot_sector; /* sector number of backup boot sector, or FFFF for none */
117 DWORD first_cluster; /* sector number of the first cluster */
118 DWORD max_cluster; /* sector number of the last cluster */
119 DWORD fat_clusters; /* number of clusters occupied by FAT */
120 DWORD root_cluster; /* cluster number of start of root directory */
121 DWORD free_cluster2; /* same as free_cluster: cluster at which to start
122 search for free space when writing */
133 static struct DosHeap *heap;
134 static WORD DosHeapHandle;
136 extern char TempDirectory[];
138 static BOOL INT21_CreateHeap(void)
140 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
142 WARN("Out of memory\n");
145 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
146 dpbsegptr = MAKESEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
147 strcpy(heap->biosdate, "01/01/80");
151 static BYTE *GetCurrentDTA( CONTEXT86 *context )
153 TDB *pTask = GlobalLock16(GetCurrentTask());
155 /* FIXME: This assumes DTA was set correctly! */
156 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
157 (DWORD)OFFSETOF(pTask->dta) );
161 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
162 /* limited == TRUE is used with INT 0x21/0x440d */
167 setword(&data[3], 0);
169 setword(&data[6], 240);
170 setword(&data[8], 64000);
172 setword(&data[0x0b], 40);
173 setword(&data[0x0d], 56);
174 setword(&data[0x0f], 2);
175 setword(&data[0x11], 0);
177 setword(&data[0x1f], 800);
179 setword(&data[0x22], 1);
181 } else { /* 1.44mb */
184 setword(&data[3], 0);
186 setword(&data[6], 240);
187 setword(&data[8], 2880);
189 setword(&data[0x0b], 6);
190 setword(&data[0x0d], 18);
191 setword(&data[0x0f], 2);
192 setword(&data[0x11], 0);
194 setword(&data[0x1f], 80);
196 setword(&data[0x22], 2);
201 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
203 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
204 char root[] = "A:\\";
206 *root += DOS_GET_DRIVE( DL_reg(context) );
207 if (!GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
208 &free_clusters, &total_clusters )) return 0;
209 SET_AX( context, cluster_sectors );
210 SET_BX( context, free_clusters );
211 SET_CX( context, sector_bytes );
212 SET_DX( context, total_clusters );
216 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
218 if (!INT21_GetFreeDiskSpace( context )) return 0;
219 if (!heap && !INT21_CreateHeap()) return 0;
220 heap->mediaID = 0xf0;
221 context->SegDs = DosHeapHandle;
222 SET_BX( context, (int)&heap->mediaID - (int)heap );
226 static int FillInDrivePB( int drive )
228 if(!DRIVE_IsValid(drive))
230 SetLastError( ERROR_INVALID_DRIVE );
233 else if (heap || INT21_CreateHeap())
235 /* FIXME: I have no idea what a lot of this information should
236 * say or whether it even really matters since we're not allowing
237 * direct block access. However, some programs seem to depend on
238 * getting at least _something_ back from here. The 'next' pointer
239 * does worry me, though. Should we have a complete table of
240 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
242 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
243 heap->dpb.sector_size = 512;
244 heap->dpb.high_sector = 1;
245 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
246 heap->dpb.reserved = 0;
247 heap->dpb.num_FAT = 1;
248 heap->dpb.dir_entries = 2;
249 heap->dpb.first_data = 2;
250 heap->dpb.high_cluster = 64000;
251 heap->dpb.sectors_in_FAT = 1;
252 heap->dpb.start_dir = 1;
253 heap->dpb.driver_head = 0;
254 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
255 heap->dpb.access_flag = 0;
257 heap->dpb.free_search = 0;
258 heap->dpb.free_clusters = 0xFFFF; /* unknown */
265 static void GetDrivePB( CONTEXT86 *context, int drive )
267 if (FillInDrivePB( drive ))
269 SET_AL( context, 0x00 );
270 context->SegDs = SELECTOROF(dpbsegptr);
271 SET_BX( context, OFFSETOF(dpbsegptr) );
275 SET_AX( context, 0x00ff );
280 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
282 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
283 int drive = DOS_GET_DRIVE( BL_reg(context) );
285 if (!DRIVE_IsValid(drive))
287 SetLastError( ERROR_FILE_NOT_FOUND );
291 if (CH_reg(context) != 0x08)
293 INT_BARF( context, 0x21 );
297 switch (CL_reg(context))
299 case 0x60: /* get device parameters */
300 /* used by w4wgrp's winfile */
301 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
303 dataptr[6] = 0; /* media type */
306 dataptr[1] = 0x05; /* fixed disk */
307 setword(&dataptr[2], 0x01); /* non removable */
308 setword(&dataptr[4], 0x300); /* # of cylinders */
312 dataptr[1] = 0x07; /* block dev, floppy */
313 setword(&dataptr[2], 0x02); /* removable */
314 setword(&dataptr[4], 80); /* # of cylinders */
316 CreateBPB(drive, &dataptr[7], TRUE);
317 RESET_CFLAG(context);
320 case 0x66:/* get disk serial number */
322 char label[12],fsname[9],path[4];
325 strcpy(path,"x:\\");path[0]=drive+'A';
326 GetVolumeInformationA(
327 path,label,12,&serial,NULL,NULL,fsname,9
330 memcpy(dataptr+2,&serial,4);
331 memcpy(dataptr+6,label ,11);
332 memcpy(dataptr+17,fsname,8);
337 memset(dataptr+1, '\0', dataptr[0]-1);
338 dataptr[1] = dataptr[0];
339 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
340 dataptr[3] = 0xFF; /* no physical drive */
344 /* Trail on error implementation */
345 SET_AX( context, GetDriveType16(BL_reg(context)) == DRIVE_UNKNOWN ? 0x0f : 0x01 );
346 SET_CFLAG(context); /* Seems to be set all the time */
350 INT_BARF( context, 0x21 );
355 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
358 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
360 CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi );
366 SET_AL( context, 0xff ); /* failed */
368 TRACE("filename: '%s'\n", filename);
374 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
383 buffer_len = MultiByteToWideChar(CP_OEMCP, 0, filename, len, NULL, 0);
384 buffer = HeapAlloc( GetProcessHeap(), 0, (buffer_len + 1) * sizeof(WCHAR));
385 len = MultiByteToWideChar(CP_OEMCP, 0, filename, len, buffer, buffer_len);
387 DOSFS_ToDosFCBFormat(buffer, fcbW);
388 HeapFree(GetProcessHeap(), 0, buffer);
389 WideCharToMultiByte(CP_OEMCP, 0, fcbW, 12, fcb + 1, 12, NULL, NULL);
391 TRACE("FCB: '%s'\n", fcb + 1);
393 SET_AL( context, ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0 );
395 /* point DS:SI to first unparsed character */
396 SET_SI( context, context->Esi + (int)s - (int)filename );
400 /* Many calls translate a drive argument like this:
401 drive number (00h = default, 01h = A:, etc)
403 static char drivestring[]="default";
405 char *INT21_DriveName(int drive)
410 drivestring[0]= (unsigned char)drive + '@';
417 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
419 /* Mask off all flags not explicitly allowed by the doc */
420 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
421 return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
422 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
423 CREATE_NEW, attr, 0 ));
427 static int INT21_FindFirst( CONTEXT86 *context )
431 DOS_FULL_NAME full_name;
432 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
433 WCHAR pathW[MAX_PATH];
436 path = (const char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
437 MultiByteToWideChar(CP_OEMCP, 0, path, -1, pathW, MAX_PATH);
439 dta->unixPath = NULL;
440 if (!DOSFS_GetFullName( pathW, FALSE, &full_name ))
442 SET_AX( context, GetLastError() );
446 dta->unixPath = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
447 strcpy( dta->unixPath, full_name.long_name );
448 p = strrchr( dta->unixPath, '/' );
451 MultiByteToWideChar(CP_OEMCP, 0, p + 1, -1, pathW, MAX_PATH);
453 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
454 * (doesn't matter as it is set below anyway)
456 if (!DOSFS_ToDosFCBFormat( pathW, maskW ))
458 HeapFree( GetProcessHeap(), 0, dta->unixPath );
459 dta->unixPath = NULL;
460 SetLastError( ERROR_FILE_NOT_FOUND );
461 SET_AX( context, ERROR_FILE_NOT_FOUND );
465 WideCharToMultiByte(CP_OEMCP, 0, maskW, 12, dta->mask, sizeof(dta->mask), NULL, NULL);
466 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
467 : DRIVE_GetCurrentDrive();
469 dta->search_attr = CL_reg(context);
474 static int INT21_FindNext( CONTEXT86 *context )
476 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
477 WIN32_FIND_DATAA entry;
480 if (!dta->unixPath) return 0;
481 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
482 dta->search_attr, dta->count, &entry )))
484 HeapFree( GetProcessHeap(), 0, dta->unixPath );
485 dta->unixPath = NULL;
488 if ((int)dta->count + count > 0xffff)
490 WARN("Too many directory entries in %s\n", dta->unixPath );
491 HeapFree( GetProcessHeap(), 0, dta->unixPath );
492 dta->unixPath = NULL;
496 dta->fileattr = entry.dwFileAttributes;
497 dta->filesize = entry.nFileSizeLow;
498 FileTimeToDosDateTime( &entry.ftLastWriteTime,
499 &dta->filedate, &dta->filetime );
500 strcpy( dta->filename, entry.cAlternateFileName );
501 if (!memchr(dta->mask,'?',11)) {
502 /* wildcardless search, release resources in case no findnext will
503 * be issued, and as a workaround in case file creation messes up
504 * findnext, as sometimes happens with pkunzip */
505 HeapFree( GetProcessHeap(), 0, dta->unixPath );
506 dta->unixPath = NULL;
512 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
514 static int counter = 0;
515 char *name = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx );
516 char *p = name + strlen(name);
518 /* despite what Ralf Brown says, some programs seem to call without
519 * ending backslash (DOS accepts that, so we accept it too) */
520 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
524 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
525 counter = (counter + 1) % 1000;
527 SET_AX( context, _lcreat16_uniq( name, 0 ) );
528 if (AX_reg(context) != HFILE_ERROR16)
530 TRACE("created %s\n", name );
533 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
538 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
540 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
541 int drive = DOS_GET_DRIVE( BL_reg(context) );
543 if (!DRIVE_IsValid(drive))
545 SetLastError( ERROR_INVALID_DRIVE );
549 *(WORD *)dataptr = 0;
550 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
551 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
552 strncpy(dataptr + 0x11, "FAT16 ", 8);
557 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
559 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
560 int drive = DOS_GET_DRIVE( BL_reg(context) );
562 if (!DRIVE_IsValid(drive))
564 SetLastError( ERROR_INVALID_DRIVE );
568 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
573 /* microsoft's programmers should be shot for using CP/M style int21
574 calls in Windows for Workgroup's winfile.exe */
576 static int INT21_FindFirstFCB( CONTEXT86 *context )
578 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
583 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
584 else pFCB = (FINDFILE_FCB *)fcb;
585 drive = DOS_GET_DRIVE( pFCB->drive );
586 if (!DRIVE_IsValid( drive )) return 0;
587 root = DRIVE_GetRoot( drive );
588 cwd = DRIVE_GetUnixCwd( drive );
589 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
590 strlen(root)+strlen(cwd)+2 );
591 if (!pFCB->unixPath) return 0;
592 strcpy( pFCB->unixPath, root );
593 strcat( pFCB->unixPath, "/" );
594 strcat( pFCB->unixPath, cwd );
600 static int INT21_FindNextFCB( CONTEXT86 *context )
602 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
604 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
605 WIN32_FIND_DATAA entry;
609 if (*fcb == 0xff) /* extended FCB ? */
612 pFCB = (FINDFILE_FCB *)(fcb + 7);
617 pFCB = (FINDFILE_FCB *)fcb;
620 if (!pFCB->unixPath) return 0;
621 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
622 DOS_GET_DRIVE( pFCB->drive ), attr,
623 pFCB->count, &entry )))
625 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
626 pFCB->unixPath = NULL;
629 pFCB->count += count;
631 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
632 *(BYTE *)pResult = 0xff;
633 (BYTE *)pResult +=6; /* leave reserved field behind */
634 *(BYTE *)pResult = entry.dwFileAttributes;
637 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
639 pResult->fileattr = entry.dwFileAttributes;
640 pResult->cluster = 0; /* what else? */
641 pResult->filesize = entry.nFileSizeLow;
642 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
643 FileTimeToDosDateTime( &entry.ftLastWriteTime,
644 &pResult->filedate, &pResult->filetime );
646 /* Convert file name to FCB format */
648 memset( pResult->filename, ' ', sizeof(pResult->filename) );
649 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
650 else if (!strcmp( entry.cAlternateFileName, ".." ))
651 pResult->filename[0] = pResult->filename[1] = '.';
654 char *p = strrchr( entry.cAlternateFileName, '.' );
655 if (p && p[1] && (p != entry.cAlternateFileName))
657 memcpy( pResult->filename, entry.cAlternateFileName,
658 min( (p - entry.cAlternateFileName), 8 ) );
659 memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
662 memcpy( pResult->filename, entry.cAlternateFileName,
663 min( strlen(entry.cAlternateFileName), 8 ) );
670 INT21_networkfunc (CONTEXT86 *context)
672 switch (AL_reg(context)) {
673 case 0x00: /* Get machine name. */
675 char *dst = CTX_SEG_OFF_TO_LIN (context,context->SegDs,context->Edx);
676 TRACE("getting machine name to %p\n", dst);
677 if (gethostname (dst, 15))
680 SetLastError( ER_NoNetwork );
683 int len = strlen (dst);
687 SET_CH( context, 1 ); /* Valid */
688 SET_CL( context, 1 ); /* NETbios number??? */
689 TRACE("returning %s\n", debugstr_an (dst, 16));
695 SetLastError( ER_NoNetwork );
701 /***********************************************************************
704 void WINAPI INT_Int21Handler( CONTEXT86 *context )
706 BOOL bSetDOSExtendedError = FALSE;
708 switch(AH_reg(context))
710 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
711 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
712 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
713 if (!INT21_FindFirstFCB(context))
715 SET_AL( context, 0xff );
718 /* else fall through */
720 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
721 SET_AL( context, INT21_FindNextFCB(context) ? 0x00 : 0xff );
724 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
725 SET_DL( context, 0 );
726 if (!INT21_GetDriveAllocInfo(context)) SET_AX( context, 0xffff );
729 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
730 if (!INT21_GetDriveAllocInfo(context)) SET_AX( context, 0xffff );
733 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
734 GetDrivePB(context, DRIVE_GetCurrentDrive());
737 case 0x29: /* PARSE FILENAME INTO FCB */
738 INT21_ParseFileNameIntoFCB(context);
741 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
742 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
743 INT21_DriveName( DL_reg(context)));
744 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
747 case 0x36: /* GET FREE DISK SPACE */
748 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
749 INT21_DriveName( DL_reg(context)));
750 if (!INT21_GetFreeDiskSpace(context)) SET_AX( context, 0xffff );
753 case 0x44: /* IOCTL */
754 switch (AL_reg(context))
757 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
758 INT21_DriveName( BL_reg(context)));
759 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
762 case 0x0F: /* Set logical drive mapping */
765 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
766 INT21_DriveName( BL_reg(context)));
767 drive = DOS_GET_DRIVE ( BL_reg(context) );
768 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
771 SET_AX( context, 0x000F ); /* invalid drive */
778 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
779 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
780 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
781 if (!INT21_FindFirst(context)) break;
784 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
786 if (!INT21_FindNext(context))
788 SetLastError( ERROR_NO_MORE_FILES );
789 SET_AX( context, ERROR_NO_MORE_FILES );
792 else SET_AX( context, 0 ); /* OK */
795 case 0x5a: /* CREATE TEMPORARY FILE */
796 TRACE("CREATE TEMPORARY FILE\n");
797 bSetDOSExtendedError = !INT21_CreateTempFile(context);
801 bSetDOSExtendedError = INT21_networkfunc (context);
804 case 0x5f: /* NETWORK */
805 switch (AL_reg(context))
807 case 0x07: /* ENABLE DRIVE */
808 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
809 if (!DRIVE_Enable( DL_reg(context) ))
811 SetLastError( ERROR_INVALID_DRIVE );
812 bSetDOSExtendedError = TRUE;
816 case 0x08: /* DISABLE DRIVE */
817 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
818 if (!DRIVE_Disable( DL_reg(context) ))
820 SetLastError( ERROR_INVALID_DRIVE );
821 bSetDOSExtendedError = TRUE;
826 /* network software not installed */
827 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
828 SetLastError( ER_NoNetwork );
829 bSetDOSExtendedError = TRUE;
834 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
835 TRACE("TRUENAME %s\n",
836 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Esi));
838 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
840 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
842 bSetDOSExtendedError = TRUE;
843 else SET_AX( context, 0 );
847 case 0x69: /* DISK SERIAL NUMBER */
848 switch (AL_reg(context))
851 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
852 INT21_DriveName(BL_reg(context)));
853 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
854 else SET_AX( context, 0 );
858 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
859 INT21_DriveName(BL_reg(context)));
860 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
861 else SET_AX( context, 1 );
866 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
867 switch(AL_reg(context))
869 case 0x4e: /* Find first file */
870 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
871 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
872 /* FIXME: use attributes in CX */
873 SET_AX( context, FindFirstFile16(
874 CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
875 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
877 if (AX_reg(context) == INVALID_HANDLE_VALUE16)
878 bSetDOSExtendedError = TRUE;
880 case 0x4f: /* Find next file */
881 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
883 if (!FindNextFile16( BX_reg(context),
884 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
886 bSetDOSExtendedError = TRUE;
890 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
891 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
892 DWORD filename_len, flags;
894 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
895 SET_AX( context, 0 );
896 if (!GetVolumeInformationA( driveroot, NULL, 0, NULL, &filename_len,
899 INT_BARF( context, 0x21 );
903 SET_BX( context, flags | 0x4000 ); /* support for LFN functions */
904 SET_CX( context, filename_len );
905 SET_DX( context, MAX_PATH ); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
908 case 0xa1: /* Find close */
909 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
911 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
914 switch(CL_reg(context))
916 case 0x01: /* Get short filename or path */
917 if (!GetShortPathNameA
918 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
920 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
922 bSetDOSExtendedError = TRUE;
923 else SET_AX( context, 0 );
925 case 0x02: /* Get canonical long filename or path */
926 if (!GetFullPathNameA
927 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
929 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
931 bSetDOSExtendedError = TRUE;
932 else SET_AX( context, 0 );
935 FIXME("Unimplemented long file name function:\n");
936 INT_BARF( context, 0x21 );
938 SET_AL( context, 0 );
944 FIXME("Unimplemented long file name function:\n");
945 INT_BARF( context, 0x21 );
947 SET_AL( context, 0 );
953 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
954 TRACE("windows95 function AX %04x\n",
957 switch (AL_reg(context))
959 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
960 /* ES:DI points to word with length of data (should be 0x3d) */
964 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
965 char root[] = "A:\\";
967 buffer = (WORD *)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
969 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer);
971 /* validate passed-in buffer lengths */
972 if ((*buffer != 0x3d) || (context->Ecx != 0x3f))
974 WARN("Get Extended DPB: buffer lengths incorrect\n");
975 WARN("CX = %lx, buffer[0] = %x\n", context->Ecx, *buffer);
977 SET_AL( context, 0x18 ); /* bad buffer length */
980 /* buffer checks out */
981 buffer++; /* skip over length word now */
982 if (FillInDrivePB( DX_reg(context) ) )
984 edpb = (struct EDPB *)buffer;
986 /* copy down the old-style DPB portion first */
987 memcpy(&edpb->dpb, &heap->dpb, sizeof(struct DPB));
989 /* now fill in the extended entries */
990 edpb->edpb_flags = 0;
992 edpb->free_cluster = edpb->free_cluster2 = 0;
994 /* determine free disk space */
995 *root += DOS_GET_DRIVE( DX_reg(context) );
996 GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
997 &free_clusters, &total_clusters );
999 edpb->clusters_free = (free_clusters&0xffff);
1001 edpb->clusters_free_hi = free_clusters >> 16;
1002 edpb->mirroring_flags = 0;
1003 edpb->info_sector = 0xffff;
1004 edpb->spare_boot_sector = 0xffff;
1005 edpb->first_cluster = 0;
1006 edpb->max_cluster = total_clusters;
1007 edpb->fat_clusters = 32; /* made-up value */
1008 edpb->root_cluster = 0;
1010 RESET_CFLAG(context); /* clear carry */
1011 SET_AX( context, 0 );
1015 SET_AX( context, 0x00ff );
1021 case 0x03: /* Get Extended free space on drive */
1022 case 0x04: /* Set DPB for formatting */
1023 case 0x05: /* extended absolute disk read/write */
1024 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context));
1026 SET_AL( context, 0 );
1033 INT_BARF( context, 0x21 );
1036 } /* END OF SWITCH */
1038 if( bSetDOSExtendedError ) /* set general error condition */
1040 SET_AX( context, GetLastError() );