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"
32 #ifdef HAVE_SYS_FILE_H
33 # include <sys/file.h>
36 #ifdef HAVE_SYS_TIME_H
37 # include <sys/time.h>
39 #include <sys/types.h>
51 #include "winuser.h" /* SW_NORMAL */
52 #include "wine/winbase16.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 */
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
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 */
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");
143 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
144 dpbsegptr
= MAKESEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
145 strcpy(heap
->biosdate
, "01/01/80");
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 */
165 setword(&data
[3], 0);
167 setword(&data
[6], 240);
168 setword(&data
[8], 64000);
170 setword(&data
[0x0b], 40);
171 setword(&data
[0x0d], 56);
172 setword(&data
[0x0f], 2);
173 setword(&data
[0x11], 0);
175 setword(&data
[0x1f], 800);
177 setword(&data
[0x22], 1);
179 } else { /* 1.44mb */
182 setword(&data
[3], 0);
184 setword(&data
[6], 240);
185 setword(&data
[8], 2880);
187 setword(&data
[0x0b], 6);
188 setword(&data
[0x0d], 18);
189 setword(&data
[0x0f], 2);
190 setword(&data
[0x11], 0);
192 setword(&data
[0x1f], 80);
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
, §or_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
);
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
);
224 static int FillInDrivePB( int drive
)
226 if(!DRIVE_IsValid(drive
))
228 SetLastError( ERROR_INVALID_DRIVE
);
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;
255 heap
->dpb
.free_search
= 0;
256 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
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
) );
273 SET_AX( context
, 0x00ff );
278 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
280 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
281 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
283 if (!DRIVE_IsValid(drive
))
285 SetLastError( ERROR_FILE_NOT_FOUND
);
289 if (CH_reg(context
) != 0x08)
291 INT_BARF( context
, 0x21 );
295 switch (CL_reg(context
))
297 case 0x60: /* get device parameters */
298 /* used by w4wgrp's winfile */
299 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
301 dataptr
[6] = 0; /* media type */
304 dataptr
[1] = 0x05; /* fixed disk */
305 setword(&dataptr
[2], 0x01); /* non removable */
306 setword(&dataptr
[4], 0x300); /* # of cylinders */
310 dataptr
[1] = 0x07; /* block dev, floppy */
311 setword(&dataptr
[2], 0x02); /* removable */
312 setword(&dataptr
[4], 80); /* # of cylinders */
314 CreateBPB(drive
, &dataptr
[7], TRUE
);
315 RESET_CFLAG(context
);
318 case 0x66:/* get disk serial number */
320 char label
[12],fsname
[9],path
[4];
323 strcpy(path
,"x:\\");path
[0]=drive
+'A';
324 GetVolumeInformationA(
325 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
328 memcpy(dataptr
+2,&serial
,4);
329 memcpy(dataptr
+6,label
,11);
330 memcpy(dataptr
+17,fsname
,8);
335 memset(dataptr
+1, '\0', dataptr
[0]-1);
336 dataptr
[1] = dataptr
[0];
337 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
338 dataptr
[3] = 0xFF; /* no physical drive */
342 /* Trail on error implementation */
343 SET_AX( context
, GetDriveType16(BL_reg(context
)) == DRIVE_UNKNOWN
? 0x0f : 0x01 );
344 SET_CFLAG(context
); /* Seems to be set all the time */
348 INT_BARF( context
, 0x21 );
353 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
356 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
358 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
364 SET_AL( context
, 0xff ); /* failed */
366 TRACE("filename: '%s'\n", filename
);
372 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
381 buffer_len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, NULL
, 0);
382 buffer
= HeapAlloc( GetProcessHeap(), 0, (buffer_len
+ 1) * sizeof(WCHAR
));
383 len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, buffer
, buffer_len
);
385 DOSFS_ToDosFCBFormat(buffer
, fcbW
);
386 HeapFree(GetProcessHeap(), 0, buffer
);
387 WideCharToMultiByte(CP_OEMCP
, 0, fcbW
, 12, fcb
+ 1, 12, NULL
, NULL
);
389 TRACE("FCB: '%s'\n", fcb
+ 1);
391 SET_AL( context
, ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0 );
393 /* point DS:SI to first unparsed character */
394 SET_SI( context
, context
->Esi
+ (int)s
- (int)filename
);
398 /* Many calls translate a drive argument like this:
399 drive number (00h = default, 01h = A:, etc)
401 static char drivestring
[]="default";
403 char *INT21_DriveName(int drive
)
408 drivestring
[0]= (unsigned char)drive
+ '@';
415 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
417 /* Mask off all flags not explicitly allowed by the doc */
418 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
419 return Win32HandleToDosFileHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
420 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
421 CREATE_NEW
, attr
, 0 ));
425 static int INT21_FindFirst( CONTEXT86
*context
)
429 DOS_FULL_NAME full_name
;
430 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
431 WCHAR pathW
[MAX_PATH
];
434 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
435 MultiByteToWideChar(CP_OEMCP
, 0, path
, -1, pathW
, MAX_PATH
);
437 dta
->unixPath
= NULL
;
438 if (!DOSFS_GetFullName( pathW
, FALSE
, &full_name
))
440 SET_AX( context
, GetLastError() );
444 dta
->unixPath
= HeapAlloc( GetProcessHeap(), 0, strlen(full_name
.long_name
)+1 );
445 strcpy( dta
->unixPath
, full_name
.long_name
);
446 p
= strrchr( dta
->unixPath
, '/' );
449 MultiByteToWideChar(CP_OEMCP
, 0, p
+ 1, -1, pathW
, MAX_PATH
);
451 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
452 * (doesn't matter as it is set below anyway)
454 if (!DOSFS_ToDosFCBFormat( pathW
, maskW
))
456 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
457 dta
->unixPath
= NULL
;
458 SetLastError( ERROR_FILE_NOT_FOUND
);
459 SET_AX( context
, ERROR_FILE_NOT_FOUND
);
463 WideCharToMultiByte(CP_OEMCP
, 0, maskW
, 12, dta
->mask
, sizeof(dta
->mask
), NULL
, NULL
);
464 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
465 : DRIVE_GetCurrentDrive();
467 dta
->search_attr
= CL_reg(context
);
472 static int INT21_FindNext( CONTEXT86
*context
)
474 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
475 WIN32_FIND_DATAA entry
;
478 if (!dta
->unixPath
) return 0;
479 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
480 dta
->search_attr
, dta
->count
, &entry
)))
482 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
483 dta
->unixPath
= NULL
;
486 if ((int)dta
->count
+ count
> 0xffff)
488 WARN("Too many directory entries in %s\n", dta
->unixPath
);
489 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
490 dta
->unixPath
= NULL
;
494 dta
->fileattr
= entry
.dwFileAttributes
;
495 dta
->filesize
= entry
.nFileSizeLow
;
496 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
497 &dta
->filedate
, &dta
->filetime
);
498 strcpy( dta
->filename
, entry
.cAlternateFileName
);
499 if (!memchr(dta
->mask
,'?',11)) {
500 /* wildcardless search, release resources in case no findnext will
501 * be issued, and as a workaround in case file creation messes up
502 * findnext, as sometimes happens with pkunzip */
503 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
504 dta
->unixPath
= NULL
;
510 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
512 static int counter
= 0;
513 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
514 char *p
= name
+ strlen(name
);
516 /* despite what Ralf Brown says, some programs seem to call without
517 * ending backslash (DOS accepts that, so we accept it too) */
518 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
522 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
523 counter
= (counter
+ 1) % 1000;
525 SET_AX( context
, _lcreat16_uniq( name
, 0 ) );
526 if (AX_reg(context
) != HFILE_ERROR16
)
528 TRACE("created %s\n", name
);
531 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
536 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
538 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
539 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
541 if (!DRIVE_IsValid(drive
))
543 SetLastError( ERROR_INVALID_DRIVE
);
547 *(WORD
*)dataptr
= 0;
548 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
549 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
550 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
555 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
557 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
558 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
560 if (!DRIVE_IsValid(drive
))
562 SetLastError( ERROR_INVALID_DRIVE
);
566 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
571 /* microsoft's programmers should be shot for using CP/M style int21
572 calls in Windows for Workgroup's winfile.exe */
574 static int INT21_FindFirstFCB( CONTEXT86
*context
)
576 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
581 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
582 else pFCB
= (FINDFILE_FCB
*)fcb
;
583 drive
= DOS_GET_DRIVE( pFCB
->drive
);
584 if (!DRIVE_IsValid( drive
)) return 0;
585 root
= DRIVE_GetRoot( drive
);
586 cwd
= DRIVE_GetUnixCwd( drive
);
587 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
588 strlen(root
)+strlen(cwd
)+2 );
589 if (!pFCB
->unixPath
) return 0;
590 strcpy( pFCB
->unixPath
, root
);
591 strcat( pFCB
->unixPath
, "/" );
592 strcat( pFCB
->unixPath
, cwd
);
598 static int INT21_FindNextFCB( CONTEXT86
*context
)
600 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
602 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
603 WIN32_FIND_DATAA entry
;
607 if (*fcb
== 0xff) /* extended FCB ? */
610 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
615 pFCB
= (FINDFILE_FCB
*)fcb
;
618 if (!pFCB
->unixPath
) return 0;
619 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
620 DOS_GET_DRIVE( pFCB
->drive
), attr
,
621 pFCB
->count
, &entry
)))
623 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
624 pFCB
->unixPath
= NULL
;
627 pFCB
->count
+= count
;
629 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
630 *(BYTE
*)pResult
= 0xff;
631 (BYTE
*)pResult
+=6; /* leave reserved field behind */
632 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
635 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
637 pResult
->fileattr
= entry
.dwFileAttributes
;
638 pResult
->cluster
= 0; /* what else? */
639 pResult
->filesize
= entry
.nFileSizeLow
;
640 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
641 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
642 &pResult
->filedate
, &pResult
->filetime
);
644 /* Convert file name to FCB format */
646 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
647 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
648 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
649 pResult
->filename
[0] = pResult
->filename
[1] = '.';
652 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
653 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
655 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
656 min( (p
- entry
.cAlternateFileName
), 8 ) );
657 memcpy( pResult
->filename
+ 8, p
+ 1, min( strlen(p
), 3 ) );
660 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
661 min( strlen(entry
.cAlternateFileName
), 8 ) );
668 INT21_networkfunc (CONTEXT86
*context
)
670 switch (AL_reg(context
)) {
671 case 0x00: /* Get machine name. */
673 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
674 TRACE("getting machine name to %p\n", dst
);
675 if (gethostname (dst
, 15))
678 SetLastError( ER_NoNetwork
);
681 int len
= strlen (dst
);
685 SET_CH( context
, 1 ); /* Valid */
686 SET_CL( context
, 1 ); /* NETbios number??? */
687 TRACE("returning %s\n", debugstr_an (dst
, 16));
693 SetLastError( ER_NoNetwork
);
699 /***********************************************************************
702 void WINAPI
INT_Int21Handler( CONTEXT86
*context
)
704 BOOL bSetDOSExtendedError
= FALSE
;
706 switch(AH_reg(context
))
708 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
709 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
710 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
711 if (!INT21_FindFirstFCB(context
))
713 SET_AL( context
, 0xff );
716 /* else fall through */
718 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
719 SET_AL( context
, INT21_FindNextFCB(context
) ? 0x00 : 0xff );
722 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
723 SET_DL( context
, 0 );
724 if (!INT21_GetDriveAllocInfo(context
)) SET_AX( context
, 0xffff );
727 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
728 if (!INT21_GetDriveAllocInfo(context
)) SET_AX( context
, 0xffff );
731 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
732 GetDrivePB(context
, DRIVE_GetCurrentDrive());
735 case 0x29: /* PARSE FILENAME INTO FCB */
736 INT21_ParseFileNameIntoFCB(context
);
739 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
740 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
741 INT21_DriveName( DL_reg(context
)));
742 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
745 case 0x36: /* GET FREE DISK SPACE */
746 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
747 INT21_DriveName( DL_reg(context
)));
748 if (!INT21_GetFreeDiskSpace(context
)) SET_AX( context
, 0xffff );
751 case 0x44: /* IOCTL */
752 switch (AL_reg(context
))
755 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
756 INT21_DriveName( BL_reg(context
)));
757 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
760 case 0x0F: /* Set logical drive mapping */
763 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
764 INT21_DriveName( BL_reg(context
)));
765 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
766 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
769 SET_AX( context
, 0x000F ); /* invalid drive */
776 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
777 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
778 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
779 if (!INT21_FindFirst(context
)) break;
782 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
784 if (!INT21_FindNext(context
))
786 SetLastError( ERROR_NO_MORE_FILES
);
787 SET_AX( context
, ERROR_NO_MORE_FILES
);
790 else SET_AX( context
, 0 ); /* OK */
793 case 0x5a: /* CREATE TEMPORARY FILE */
794 TRACE("CREATE TEMPORARY FILE\n");
795 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
799 bSetDOSExtendedError
= INT21_networkfunc (context
);
802 case 0x5f: /* NETWORK */
803 switch (AL_reg(context
))
805 case 0x07: /* ENABLE DRIVE */
806 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
807 if (!DRIVE_Enable( DL_reg(context
) ))
809 SetLastError( ERROR_INVALID_DRIVE
);
810 bSetDOSExtendedError
= TRUE
;
814 case 0x08: /* DISABLE DRIVE */
815 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
816 if (!DRIVE_Disable( DL_reg(context
) ))
818 SetLastError( ERROR_INVALID_DRIVE
);
819 bSetDOSExtendedError
= TRUE
;
824 /* network software not installed */
825 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
826 SetLastError( ER_NoNetwork
);
827 bSetDOSExtendedError
= TRUE
;
832 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
833 TRACE("TRUENAME %s\n",
834 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
836 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
838 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
840 bSetDOSExtendedError
= TRUE
;
841 else SET_AX( context
, 0 );
845 case 0x69: /* DISK SERIAL NUMBER */
846 switch (AL_reg(context
))
849 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
850 INT21_DriveName(BL_reg(context
)));
851 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
852 else SET_AX( context
, 0 );
856 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
857 INT21_DriveName(BL_reg(context
)));
858 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
859 else SET_AX( context
, 1 );
864 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
865 switch(AL_reg(context
))
867 case 0x4e: /* Find first file */
868 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
869 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
870 /* FIXME: use attributes in CX */
871 SET_AX( context
, FindFirstFile16(
872 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
873 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
875 if (AX_reg(context
) == INVALID_HANDLE_VALUE16
)
876 bSetDOSExtendedError
= TRUE
;
878 case 0x4f: /* Find next file */
879 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
881 if (!FindNextFile16( BX_reg(context
),
882 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
884 bSetDOSExtendedError
= TRUE
;
888 LPCSTR driveroot
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
889 LPSTR buffer
= (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
890 DWORD filename_len
, flags
;
892 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot
);
893 SET_AX( context
, 0 );
894 if (!GetVolumeInformationA( driveroot
, NULL
, 0, NULL
, &filename_len
,
897 INT_BARF( context
, 0x21 );
901 SET_BX( context
, flags
| 0x4000 ); /* support for LFN functions */
902 SET_CX( context
, filename_len
);
903 SET_DX( context
, MAX_PATH
); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
906 case 0xa1: /* Find close */
907 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
909 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
912 switch(CL_reg(context
))
914 case 0x01: /* Get short filename or path */
915 if (!GetShortPathNameA
916 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
918 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
920 bSetDOSExtendedError
= TRUE
;
921 else SET_AX( context
, 0 );
923 case 0x02: /* Get canonical long filename or path */
924 if (!GetFullPathNameA
925 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
927 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
929 bSetDOSExtendedError
= TRUE
;
930 else SET_AX( context
, 0 );
933 FIXME("Unimplemented long file name function:\n");
934 INT_BARF( context
, 0x21 );
936 SET_AL( context
, 0 );
942 FIXME("Unimplemented long file name function:\n");
943 INT_BARF( context
, 0x21 );
945 SET_AL( context
, 0 );
951 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
952 TRACE("windows95 function AX %04x\n",
955 switch (AL_reg(context
))
957 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
958 /* ES:DI points to word with length of data (should be 0x3d) */
962 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
963 char root
[] = "A:\\";
965 buffer
= (WORD
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
967 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer
);
969 /* validate passed-in buffer lengths */
970 if ((*buffer
!= 0x3d) || (context
->Ecx
!= 0x3f))
972 WARN("Get Extended DPB: buffer lengths incorrect\n");
973 WARN("CX = %lx, buffer[0] = %x\n", context
->Ecx
, *buffer
);
975 SET_AL( context
, 0x18 ); /* bad buffer length */
978 /* buffer checks out */
979 buffer
++; /* skip over length word now */
980 if (FillInDrivePB( DX_reg(context
) ) )
982 edpb
= (struct EDPB
*)buffer
;
984 /* copy down the old-style DPB portion first */
985 memcpy(&edpb
->dpb
, &heap
->dpb
, sizeof(struct DPB
));
987 /* now fill in the extended entries */
988 edpb
->edpb_flags
= 0;
990 edpb
->free_cluster
= edpb
->free_cluster2
= 0;
992 /* determine free disk space */
993 *root
+= DOS_GET_DRIVE( DX_reg(context
) );
994 GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
995 &free_clusters
, &total_clusters
);
997 edpb
->clusters_free
= (free_clusters
&0xffff);
999 edpb
->clusters_free_hi
= free_clusters
>> 16;
1000 edpb
->mirroring_flags
= 0;
1001 edpb
->info_sector
= 0xffff;
1002 edpb
->spare_boot_sector
= 0xffff;
1003 edpb
->first_cluster
= 0;
1004 edpb
->max_cluster
= total_clusters
;
1005 edpb
->fat_clusters
= 32; /* made-up value */
1006 edpb
->root_cluster
= 0;
1008 RESET_CFLAG(context
); /* clear carry */
1009 SET_AX( context
, 0 );
1013 SET_AX( context
, 0x00ff );
1019 case 0x03: /* Get Extended free space on drive */
1020 case 0x04: /* Set DPB for formatting */
1021 case 0x05: /* extended absolute disk read/write */
1022 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context
));
1024 SET_AL( context
, 0 );
1031 INT_BARF( context
, 0x21 );
1034 } /* END OF SWITCH */
1036 if( bSetDOSExtendedError
) /* set general error condition */
1038 SET_AX( context
, GetLastError() );