2 * DOS interrupt 21h handler
11 #ifdef HAVE_SYS_FILE_H
12 # include <sys/file.h>
16 #include <sys/types.h>
24 #include "winuser.h" /* SW_NORMAL */
25 #include "wine/winbase16.h"
36 #include "debugtools.h"
39 DEFAULT_DEBUG_CHANNEL(int21
);
40 #if defined(__svr4__) || defined(_SCO_DS)
41 /* SVR4 DOESNT do locking the same way must implement properly */
48 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
50 /* Define the drive parameter block, as used by int21/1F
51 * and int21/32. This table can be accessed through the
52 * global 'dpb' pointer, which points into the local dos
57 BYTE drive_num
; /* 0=A, etc. */
58 BYTE unit_num
; /* Drive's unit number (?) */
59 WORD sector_size
; /* Sector size in bytes */
60 BYTE high_sector
; /* Highest sector in a cluster */
61 BYTE shift
; /* Shift count (?) */
62 WORD reserved
; /* Number of reserved sectors at start */
63 BYTE num_FAT
; /* Number of FATs */
64 WORD dir_entries
; /* Number of root dir entries */
65 WORD first_data
; /* First data sector */
66 WORD high_cluster
; /* Highest cluster number */
67 WORD sectors_in_FAT
; /* Number of sectors per FAT */
68 WORD start_dir
; /* Starting sector of first dir */
69 DWORD driver_head
; /* Address of device driver header (?) */
70 BYTE media_ID
; /* Media ID */
71 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
72 DWORD next
; /* Pointer to next DPB in list */
73 WORD free_search
; /* Free cluster search start */
74 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
77 struct EDPB
/* FAT32 extended Drive Parameter Block */
78 { /* from Ralf Brown's Interrupt List */
79 struct DPB dpb
; /* first 24 bytes = original DPB */
81 BYTE edpb_flags
; /* undocumented/unknown flags */
82 DWORD next_edpb
; /* pointer to next EDPB */
83 WORD free_cluster
; /* cluster to start search for free space on write, typically
84 the last cluster allocated */
85 WORD clusters_free
; /* number of free clusters on drive or FFFF = unknown */
86 WORD clusters_free_hi
; /* hiword of clusters_free */
87 WORD mirroring_flags
; /* mirroring flags: bit 7 set = do not mirror active FAT */
88 /* bits 0-3 = 0-based number of the active FAT */
89 WORD info_sector
; /* sector number of file system info sector, or FFFF for none */
90 WORD spare_boot_sector
; /* sector number of backup boot sector, or FFFF for none */
91 DWORD first_cluster
; /* sector number of the first cluster */
92 DWORD max_cluster
; /* sector number of the last cluster */
93 DWORD fat_clusters
; /* number of clusters occupied by FAT */
94 DWORD root_cluster
; /* cluster number of start of root directory */
95 DWORD free_cluster2
; /* same as free_cluster: cluster at which to start
96 search for free space when writing */
108 BYTE DummyDBCSLeadTable
[6];
110 static struct DosHeap
*heap
;
111 static WORD DosHeapHandle
;
113 extern char TempDirectory
[];
115 static BOOL
INT21_CreateHeap(void)
117 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
119 WARN("Out of memory\n");
122 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
123 dpbsegptr
= MAKESEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
125 strcpy(heap
->biosdate
, "01/01/80");
126 memset(heap
->DummyDBCSLeadTable
, 0, 6);
130 static BYTE
*GetCurrentDTA( CONTEXT86
*context
)
132 TDB
*pTask
= TASK_GetCurrent();
134 /* FIXME: This assumes DTA was set correctly! */
135 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
136 (DWORD
)OFFSETOF(pTask
->dta
) );
140 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
141 /* limited == TRUE is used with INT 0x21/0x440d */
146 setword(&data
[3], 0);
148 setword(&data
[6], 240);
149 setword(&data
[8], 64000);
151 setword(&data
[0x0b], 40);
152 setword(&data
[0x0d], 56);
153 setword(&data
[0x0f], 2);
154 setword(&data
[0x11], 0);
156 setword(&data
[0x1f], 800);
158 setword(&data
[0x22], 1);
160 } else { /* 1.44mb */
163 setword(&data
[3], 0);
165 setword(&data
[6], 240);
166 setword(&data
[8], 2880);
168 setword(&data
[0x0b], 6);
169 setword(&data
[0x0d], 18);
170 setword(&data
[0x0f], 2);
171 setword(&data
[0x11], 0);
173 setword(&data
[0x1f], 80);
175 setword(&data
[0x22], 2);
180 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
182 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
183 char root
[] = "A:\\";
185 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
186 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
187 &free_clusters
, &total_clusters
)) return 0;
188 AX_reg(context
) = cluster_sectors
;
189 BX_reg(context
) = free_clusters
;
190 CX_reg(context
) = sector_bytes
;
191 DX_reg(context
) = total_clusters
;
195 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
)
197 if (!INT21_GetFreeDiskSpace( context
)) return 0;
198 if (!heap
&& !INT21_CreateHeap()) return 0;
199 heap
->mediaID
= 0xf0;
200 context
->SegDs
= DosHeapHandle
;
201 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
205 static int FillInDrivePB( int drive
)
207 if(!DRIVE_IsValid(drive
))
209 SetLastError( ERROR_INVALID_DRIVE
);
212 else if (heap
|| INT21_CreateHeap())
214 /* FIXME: I have no idea what a lot of this information should
215 * say or whether it even really matters since we're not allowing
216 * direct block access. However, some programs seem to depend on
217 * getting at least _something_ back from here. The 'next' pointer
218 * does worry me, though. Should we have a complete table of
219 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
221 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
222 heap
->dpb
.sector_size
= 512;
223 heap
->dpb
.high_sector
= 1;
224 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
225 heap
->dpb
.reserved
= 0;
226 heap
->dpb
.num_FAT
= 1;
227 heap
->dpb
.dir_entries
= 2;
228 heap
->dpb
.first_data
= 2;
229 heap
->dpb
.high_cluster
= 64000;
230 heap
->dpb
.sectors_in_FAT
= 1;
231 heap
->dpb
.start_dir
= 1;
232 heap
->dpb
.driver_head
= 0;
233 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
234 heap
->dpb
.access_flag
= 0;
236 heap
->dpb
.free_search
= 0;
237 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
244 static void GetDrivePB( CONTEXT86
*context
, int drive
)
246 if (FillInDrivePB( drive
))
248 AL_reg(context
) = 0x00;
249 context
->SegDs
= SELECTOROF(dpbsegptr
);
250 BX_reg(context
) = OFFSETOF(dpbsegptr
);
254 AX_reg(context
) = 0x00ff;
259 static void ioctlGetDeviceInfo( CONTEXT86
*context
)
262 const DOS_DEVICE
*dev
;
264 TRACE("(%d)\n", BX_reg(context
));
266 RESET_CFLAG(context
);
269 if ((dev
= DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context
)) )))
271 DX_reg(context
) = dev
->flags
;
275 /* it seems to be a file */
276 curr_drive
= DRIVE_GetCurrentDrive();
277 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
279 /* bits 0-5 are current drive
280 * bit 6 - file has NOT been written..FIXME: correct?
281 * bit 8 - generate int24 if no diskspace on write/ read past end of file
282 * bit 11 - media not removable
283 * bit 14 - don't set file date/time on closing
284 * bit 15 - file is remote
288 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
290 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
291 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
293 if (!DRIVE_IsValid(drive
))
295 SetLastError( ERROR_FILE_NOT_FOUND
);
299 if (CH_reg(context
) != 0x08)
301 INT_BARF( context
, 0x21 );
305 switch (CL_reg(context
))
307 case 0x4a: /* lock logical volume */
308 TRACE("lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
311 case 0x60: /* get device parameters */
312 /* used by w4wgrp's winfile */
313 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
315 dataptr
[6] = 0; /* media type */
318 dataptr
[1] = 0x05; /* fixed disk */
319 setword(&dataptr
[2], 0x01); /* non removable */
320 setword(&dataptr
[4], 0x300); /* # of cylinders */
324 dataptr
[1] = 0x07; /* block dev, floppy */
325 setword(&dataptr
[2], 0x02); /* removable */
326 setword(&dataptr
[4], 80); /* # of cylinders */
328 CreateBPB(drive
, &dataptr
[7], TRUE
);
329 RESET_CFLAG(context
);
332 case 0x41: /* write logical device track */
333 case 0x61: /* read logical device track */
335 BYTE drive
= BL_reg(context
) ?
336 BL_reg(context
) : DRIVE_GetCurrentDrive();
337 WORD head
= *(WORD
*)dataptr
+1;
338 WORD cyl
= *(WORD
*)dataptr
+3;
339 WORD sect
= *(WORD
*)dataptr
+5;
340 WORD nrsect
= *(WORD
*)dataptr
+7;
341 BYTE
*data
= (BYTE
*)dataptr
+9;
342 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
344 raw_func
= (CL_reg(context
) == 0x41) ?
345 DRIVE_RawWrite
: DRIVE_RawRead
;
347 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
348 RESET_CFLAG(context
);
351 AX_reg(context
) = 0x1e; /* read fault */
356 case 0x66:/* get disk serial number */
358 char label
[12],fsname
[9],path
[4];
361 strcpy(path
,"x:\\");path
[0]=drive
+'A';
362 GetVolumeInformationA(
363 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
366 memcpy(dataptr
+2,&serial
,4);
367 memcpy(dataptr
+6,label
,11);
368 memcpy(dataptr
+17,fsname
,8);
373 TRACE("logical volume %d unlocked.\n",drive
);
377 memset(dataptr
+1, '\0', dataptr
[0]-1);
378 dataptr
[1] = dataptr
[0];
379 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
380 dataptr
[3] = 0xFF; /* no physical drive */
384 /* Trail on error implementation */
385 AX_reg(context
) = GetDriveType16(BL_reg(context
)) == DRIVE_UNKNOWN
? 0x0f : 0x01;
386 SET_CFLAG(context
); /* Seems to be set all the time */
390 INT_BARF( context
, 0x21 );
395 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
398 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
400 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
401 char *buffer
, *s
, *d
;
403 AL_reg(context
) = 0xff; /* failed */
405 TRACE("filename: '%s'\n", filename
);
407 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
413 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
420 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
422 TRACE("FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
424 HeapFree( GetProcessHeap(), 0, buffer
);
427 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
429 /* point DS:SI to first unparsed character */
430 SI_reg(context
) += (int)s
- (int)filename
;
433 static void INT21_GetSystemDate( CONTEXT86
*context
)
436 GetLocalTime( &systime
);
437 CX_reg(context
) = systime
.wYear
;
438 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
439 AX_reg(context
) = systime
.wDayOfWeek
;
442 static void INT21_GetSystemTime( CONTEXT86
*context
)
445 GetLocalTime( &systime
);
446 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
447 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
450 /* Many calls translate a drive argument like this:
451 drive number (00h = default, 01h = A:, etc)
453 static char drivestring
[]="default";
455 char *INT21_DriveName(int drive
)
460 drivestring
[0]= (unsigned char)drive
+ '@';
466 static BOOL
INT21_CreateFile( CONTEXT86
*context
)
468 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
469 context
->Edx
), CX_reg(context
) );
470 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
473 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
475 /* Mask off all flags not explicitly allowed by the doc */
476 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
477 return Win32HandleToDosFileHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
478 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
479 CREATE_NEW
, attr
, 0 ));
482 static void OpenExistingFile( CONTEXT86
*context
)
484 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
486 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
488 AX_reg(context
) = GetLastError();
493 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT86
*context
)
495 BOOL bExtendedError
= FALSE
;
496 BYTE action
= DL_reg(context
);
498 /* Shuffle arguments to call OpenExistingFile */
499 AL_reg(context
) = BL_reg(context
);
500 DX_reg(context
) = SI_reg(context
);
501 /* BX,CX and DX should be preserved */
502 OpenExistingFile(context
);
504 if ((context
->EFlags
& 0x0001) == 0) /* File exists */
506 UINT16 uReturnCX
= 0;
508 /* Now decide what do do */
510 if ((action
& 0x07) == 0)
512 _lclose16( AX_reg(context
) );
513 AX_reg(context
) = 0x0050; /*File exists*/
515 WARN("extended open/create: failed because file exists \n");
517 else if ((action
& 0x07) == 2)
519 /* Truncate it, but first check if opened for write */
520 if ((BL_reg(context
) & 0x0007)== 0)
522 _lclose16( AX_reg(context
) );
523 WARN("extended open/create: failed, trunc on ro file\n");
524 AX_reg(context
) = 0x000C; /*Access code invalid*/
529 TRACE("extended open/create: Closing before truncate\n");
530 if (_lclose16( AX_reg(context
) ))
532 WARN("extended open/create: close before trunc failed\n");
533 AX_reg(context
) = 0x0019; /*Seek Error*/
537 /* Shuffle arguments to call CreateFile */
539 TRACE("extended open/create: Truncating\n");
540 AL_reg(context
) = BL_reg(context
);
541 /* CX is still the same */
542 DX_reg(context
) = SI_reg(context
);
543 bExtendedError
= INT21_CreateFile(context
);
545 if (context
->EFlags
& 0x0001) /*no file open, flags set */
547 WARN("extended open/create: trunc failed\n");
548 return bExtendedError
;
553 else uReturnCX
= 0x1;
555 CX_reg(context
) = uReturnCX
;
557 else /* file does not exist */
559 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
560 if ((action
& 0xF0)== 0)
564 WARN("extended open/create: failed, file dosen't exist\n");
568 /* Shuffle arguments to call CreateFile */
569 TRACE("extended open/create: Creating\n");
570 AL_reg(context
) = BL_reg(context
);
571 /* CX should still be the same */
572 DX_reg(context
) = SI_reg(context
);
573 bExtendedError
= INT21_CreateFile(context
);
574 if (context
->EFlags
& 0x0001) /*no file open, flags set */
576 WARN("extended open/create: create failed\n");
577 return bExtendedError
;
583 return bExtendedError
;
587 static BOOL
INT21_ChangeDir( CONTEXT86
*context
)
590 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
592 TRACE("changedir %s\n", dirname
);
593 if (dirname
[0] && (dirname
[1] == ':'))
595 drive
= toupper(dirname
[0]) - 'A';
598 else drive
= DRIVE_GetCurrentDrive();
599 return DRIVE_Chdir( drive
, dirname
);
603 static int INT21_FindFirst( CONTEXT86
*context
)
607 DOS_FULL_NAME full_name
;
608 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
610 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
611 dta
->unixPath
= NULL
;
612 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
614 AX_reg(context
) = GetLastError();
618 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
619 p
= strrchr( dta
->unixPath
, '/' );
622 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
623 * (doesn't matter as it is set below anyway)
625 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
627 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
628 dta
->unixPath
= NULL
;
629 SetLastError( ERROR_FILE_NOT_FOUND
);
630 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
634 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
635 : DRIVE_GetCurrentDrive();
637 dta
->search_attr
= CL_reg(context
);
642 static int INT21_FindNext( CONTEXT86
*context
)
644 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
645 WIN32_FIND_DATAA entry
;
648 if (!dta
->unixPath
) return 0;
649 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
650 dta
->search_attr
, dta
->count
, &entry
)))
652 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
653 dta
->unixPath
= NULL
;
656 if ((int)dta
->count
+ count
> 0xffff)
658 WARN("Too many directory entries in %s\n", dta
->unixPath
);
659 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
660 dta
->unixPath
= NULL
;
664 dta
->fileattr
= entry
.dwFileAttributes
;
665 dta
->filesize
= entry
.nFileSizeLow
;
666 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
667 &dta
->filedate
, &dta
->filetime
);
668 strcpy( dta
->filename
, entry
.cAlternateFileName
);
669 if (!memchr(dta
->mask
,'?',11)) {
670 /* wildcardless search, release resources in case no findnext will
671 * be issued, and as a workaround in case file creation messes up
672 * findnext, as sometimes happens with pkunzip */
673 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
674 dta
->unixPath
= NULL
;
680 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
682 static int counter
= 0;
683 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
684 char *p
= name
+ strlen(name
);
686 /* despite what Ralf Brown says, some programs seem to call without
687 * ending backslash (DOS accepts that, so we accept it too) */
688 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
692 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
693 counter
= (counter
+ 1) % 1000;
695 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
697 TRACE("created %s\n", name
);
700 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
705 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
)
707 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
708 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
710 if (!DRIVE_IsValid(drive
))
712 SetLastError( ERROR_INVALID_DRIVE
);
715 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
716 AX_reg(context
) = 0x0100; /* success return code */
721 static void INT21_GetDBCSLeadTable( CONTEXT86
*context
)
723 if (heap
|| INT21_CreateHeap())
724 { /* return an empty table just as DOS 4.0+ does */
725 context
->SegDs
= DosHeapHandle
;
726 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
730 AX_reg(context
) = 0x1; /* error */
736 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
738 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
739 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
741 if (!DRIVE_IsValid(drive
))
743 SetLastError( ERROR_INVALID_DRIVE
);
747 *(WORD
*)dataptr
= 0;
748 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
749 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
750 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
755 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
757 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
758 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
760 if (!DRIVE_IsValid(drive
))
762 SetLastError( ERROR_INVALID_DRIVE
);
766 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
771 /* microsoft's programmers should be shot for using CP/M style int21
772 calls in Windows for Workgroup's winfile.exe */
774 static int INT21_FindFirstFCB( CONTEXT86
*context
)
776 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
781 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
782 else pFCB
= (FINDFILE_FCB
*)fcb
;
783 drive
= DOS_GET_DRIVE( pFCB
->drive
);
784 if (!DRIVE_IsValid( drive
)) return 0;
785 root
= DRIVE_GetRoot( drive
);
786 cwd
= DRIVE_GetUnixCwd( drive
);
787 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
788 strlen(root
)+strlen(cwd
)+2 );
789 if (!pFCB
->unixPath
) return 0;
790 strcpy( pFCB
->unixPath
, root
);
791 strcat( pFCB
->unixPath
, "/" );
792 strcat( pFCB
->unixPath
, cwd
);
798 static int INT21_FindNextFCB( CONTEXT86
*context
)
800 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
802 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
803 WIN32_FIND_DATAA entry
;
807 if (*fcb
== 0xff) /* extended FCB ? */
810 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
815 pFCB
= (FINDFILE_FCB
*)fcb
;
818 if (!pFCB
->unixPath
) return 0;
819 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
820 DOS_GET_DRIVE( pFCB
->drive
), attr
,
821 pFCB
->count
, &entry
)))
823 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
824 pFCB
->unixPath
= NULL
;
827 pFCB
->count
+= count
;
829 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
830 *(BYTE
*)pResult
= 0xff;
831 (BYTE
*)pResult
+=6; /* leave reserved field behind */
832 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
835 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
837 pResult
->fileattr
= entry
.dwFileAttributes
;
838 pResult
->cluster
= 0; /* what else? */
839 pResult
->filesize
= entry
.nFileSizeLow
;
840 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
841 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
842 &pResult
->filedate
, &pResult
->filetime
);
844 /* Convert file name to FCB format */
846 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
847 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
848 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
849 pResult
->filename
[0] = pResult
->filename
[1] = '.';
852 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
853 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
855 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
856 min( (p
- entry
.cAlternateFileName
), 8 ) );
857 memcpy( pResult
->filename
+ 8, p
+ 1, min( strlen(p
), 3 ) );
860 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
861 min( strlen(entry
.cAlternateFileName
), 8 ) );
867 static void DeleteFileFCB( CONTEXT86
*context
)
869 FIXME("(%p): stub\n", context
);
872 static void RenameFileFCB( CONTEXT86
*context
)
874 FIXME("(%p): stub\n", context
);
879 static void fLock( CONTEXT86
* context
)
882 switch ( AX_reg(context
) & 0xff )
884 case 0x00: /* LOCK */
885 TRACE("lock handle %d offset %ld length %ld\n",
887 MAKELONG(DX_reg(context
),CX_reg(context
)),
888 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
889 if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context
)),
890 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
891 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
892 AX_reg(context
) = GetLastError();
897 case 0x01: /* UNLOCK */
898 TRACE("unlock handle %d offset %ld length %ld\n",
900 MAKELONG(DX_reg(context
),CX_reg(context
)),
901 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
902 if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context
)),
903 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
904 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
905 AX_reg(context
) = GetLastError();
910 AX_reg(context
) = 0x0001;
917 INT21_networkfunc (CONTEXT86
*context
)
919 switch (AL_reg(context
)) {
920 case 0x00: /* Get machine name. */
922 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
923 TRACE("getting machine name to %p\n", dst
);
924 if (gethostname (dst
, 15))
927 SetLastError( ER_NoNetwork
);
930 int len
= strlen (dst
);
934 CH_reg(context
) = 1; /* Valid */
935 CL_reg(context
) = 1; /* NETbios number??? */
936 TRACE("returning %s\n", debugstr_an (dst
, 16));
942 SetLastError( ER_NoNetwork
);
947 static void INT21_SetCurrentPSP(WORD psp
)
949 LPDOSTASK lpDosTask
= Dosvm
.Current();
951 lpDosTask
->psp_seg
= psp
;
953 ERR("Cannot change PSP for non-DOS task!\n");
956 static WORD
INT21_GetCurrentPSP(void)
958 LPDOSTASK lpDosTask
= Dosvm
.Current();
960 return lpDosTask
->psp_seg
;
962 return GetCurrentPDB16();
965 static WORD
INT21_GetReturnCode(void)
967 LPDOSTASK lpDosTask
= Dosvm
.Current();
969 WORD ret
= lpDosTask
->retval
;
970 lpDosTask
->retval
= 0;
975 /***********************************************************************
976 * INT21_GetExtendedError
978 static void INT21_GetExtendedError( CONTEXT86
*context
)
980 BYTE
class, action
, locus
;
981 WORD error
= GetLastError();
986 class = action
= locus
= 0;
988 case ERROR_DIR_NOT_EMPTY
:
993 case ERROR_ACCESS_DENIED
:
994 class = EC_AccessDenied
;
998 case ERROR_CANNOT_MAKE
:
999 class = EC_AccessDenied
;
1003 case ERROR_DISK_FULL
:
1004 case ERROR_HANDLE_DISK_FULL
:
1005 class = EC_MediaError
;
1009 case ERROR_FILE_EXISTS
:
1010 case ERROR_ALREADY_EXISTS
:
1015 case ERROR_FILE_NOT_FOUND
:
1016 class = EC_NotFound
;
1020 case ER_GeneralFailure
:
1021 class = EC_SystemFailure
;
1025 case ERROR_INVALID_DRIVE
:
1026 class = EC_MediaError
;
1030 case ERROR_INVALID_HANDLE
:
1031 class = EC_ProgramError
;
1035 case ERROR_LOCK_VIOLATION
:
1036 class = EC_AccessDenied
;
1040 case ERROR_NO_MORE_FILES
:
1041 class = EC_MediaError
;
1046 class = EC_NotFound
;
1050 case ERROR_NOT_ENOUGH_MEMORY
:
1051 class = EC_OutOfResource
;
1055 case ERROR_PATH_NOT_FOUND
:
1056 class = EC_NotFound
;
1061 class = EC_NotFound
;
1065 case ERROR_SHARING_VIOLATION
:
1066 class = EC_Temporary
;
1070 case ERROR_TOO_MANY_OPEN_FILES
:
1071 class = EC_ProgramError
;
1076 FIXME("Unknown error %d\n", error
);
1077 class = EC_SystemFailure
;
1082 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1083 error
, class, action
, locus
);
1084 AX_reg(context
) = error
;
1085 BH_reg(context
) = class;
1086 BL_reg(context
) = action
;
1087 CH_reg(context
) = locus
;
1090 /***********************************************************************
1091 * DOS3Call (KERNEL.102)
1093 void WINAPI
DOS3Call( CONTEXT86
*context
)
1095 BOOL bSetDOSExtendedError
= FALSE
;
1098 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1099 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1100 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1101 SI_reg(context
), DI_reg(context
),
1102 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
1106 if (AH_reg(context
) == 0x59) /* Get extended error info */
1108 INT21_GetExtendedError( context
);
1112 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1114 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1115 /* no flush here yet */
1116 AH_reg(context
) = AL_reg(context
);
1119 if (AH_reg(context
)>=0x2f) {
1120 /* extended error is used by (at least) functions 0x2f to 0x62 */
1123 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1125 switch(AH_reg(context
))
1127 case 0x03: /* READ CHARACTER FROM STDAUX */
1128 case 0x04: /* WRITE CHARACTER TO STDAUX */
1129 case 0x05: /* WRITE CHARACTER TO PRINTER */
1130 case 0x0f: /* OPEN FILE USING FCB */
1131 case 0x10: /* CLOSE FILE USING FCB */
1132 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1133 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1134 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1135 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1136 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1137 case 0x23: /* GET FILE SIZE FOR FCB */
1138 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1139 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1140 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1141 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1142 INT_BARF( context
, 0x21 );
1145 case 0x00: /* TERMINATE PROGRAM */
1146 TRACE("TERMINATE PROGRAM\n");
1147 if (Dosvm
.Exit
) Dosvm
.Exit( context
, FALSE
, 0 );
1148 else ExitThread( 0 );
1151 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1152 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1153 AL_reg(context
) = CONSOLE_GetCharacter();
1154 /* FIXME: no echo */
1157 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1158 TRACE("Write Character to Standard Output\n");
1159 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1162 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1163 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
1164 if (DL_reg(context
) == 0xff) {
1165 static char scan
= 0;
1166 TRACE("Direct Console Input\n");
1168 /* return pending scancode */
1169 AL_reg(context
) = scan
;
1170 RESET_ZFLAG(context
);
1174 if (INT_Int16ReadChar(&ascii
,&scan
,TRUE
)) {
1175 INT_Int16ReadChar(&ascii
,&scan
,FALSE
);
1176 /* return ASCII code */
1177 AL_reg(context
) = ascii
;
1178 RESET_ZFLAG(context
);
1179 /* return scan code on next call only if ascii==0 */
1180 if (ascii
) scan
= 0;
1182 /* nothing pending, clear everything */
1183 AL_reg(context
) = 0;
1185 scan
= 0; /* just in case */
1189 TRACE("Direct Console Output\n");
1190 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1194 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1195 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
1196 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1197 INT_Int16ReadChar(&AL_reg(context
), NULL
, FALSE
);
1200 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1201 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
1202 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1203 INT_Int16ReadChar(&AL_reg(context
), NULL
, FALSE
);
1206 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1207 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1208 context
->SegDs
,DX_reg(context
) );
1210 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
);
1212 /* do NOT use strchr() to calculate the string length,
1213 as '\0' is valid string content, too !
1214 Maybe we should check for non-'$' strings, but DOS doesn't. */
1215 while (*p
!= '$') p
++;
1216 _hwrite16( 1, data
, (int)p
- (int)data
);
1217 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1221 case 0x0a: /* BUFFERED INPUT */
1223 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1227 TRACE("BUFFERED INPUT (size=%d)\n",buffer
[0]);
1229 TRACE("Handle old chars in buffer!\n");
1230 res
=_lread16( 0, buffer
+2,buffer
[0]);
1232 if(buffer
[res
+1] == '\n')
1233 buffer
[res
+1] = '\r';
1237 case 0x0b: {/* GET STDIN STATUS */
1240 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1241 AL_reg(context
) = 0xff;
1243 AL_reg(context
) = 0;
1246 case 0x2e: /* SET VERIFY FLAG */
1247 TRACE("SET VERIFY FLAG ignored\n");
1248 /* we cannot change the behaviour anyway, so just ignore it */
1251 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1255 case 0x6b: /* NULL FUNCTION */
1256 AL_reg(context
) = 0;
1259 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1263 case 0x0d: /* DISK BUFFER FLUSH */
1264 TRACE("DISK BUFFER FLUSH ignored\n");
1265 RESET_CFLAG(context
); /* dos 6+ only */
1268 case 0x0e: /* SELECT DEFAULT DRIVE */
1269 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1270 DRIVE_SetCurrentDrive( DL_reg(context
) );
1271 AL_reg(context
) = MAX_DOS_DRIVES
;
1274 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1275 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1276 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1277 if (!INT21_FindFirstFCB(context
))
1279 AL_reg(context
) = 0xff;
1282 /* else fall through */
1284 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1285 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1288 case 0x13: /* DELETE FILE USING FCB */
1289 DeleteFileFCB(context
);
1292 case 0x17: /* RENAME FILE USING FCB */
1293 RenameFileFCB(context
);
1296 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1297 AL_reg(context
) = DRIVE_GetCurrentDrive();
1300 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1302 TDB
*pTask
= TASK_GetCurrent();
1303 pTask
->dta
= MAKESEGPTR(context
->SegDs
,DX_reg(context
));
1304 TRACE("Set DTA: %08lx\n", pTask
->dta
);
1308 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1309 DL_reg(context
) = 0;
1310 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1313 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1314 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1317 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1318 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1321 case 0x25: /* SET INTERRUPT VECTOR */
1322 INT_CtxSetHandler( context
, AL_reg(context
),
1323 (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
)));
1326 case 0x29: /* PARSE FILENAME INTO FCB */
1327 INT21_ParseFileNameIntoFCB(context
);
1330 case 0x2a: /* GET SYSTEM DATE */
1331 INT21_GetSystemDate(context
);
1334 case 0x2b: /* SET SYSTEM DATE */
1335 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1336 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1337 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1340 case 0x2c: /* GET SYSTEM TIME */
1341 INT21_GetSystemTime(context
);
1344 case 0x2d: /* SET SYSTEM TIME */
1345 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1346 CH_reg(context
), CL_reg(context
),
1347 DH_reg(context
), DL_reg(context
) );
1348 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1351 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1352 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1354 TDB
*pTask
= TASK_GetCurrent();
1355 context
->SegEs
= SELECTOROF( pTask
->dta
);
1356 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1360 case 0x30: /* GET DOS VERSION */
1361 TRACE("GET DOS VERSION %s requested\n",
1362 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1363 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1364 (HIWORD(GetVersion16()) << 8);
1366 AH_reg(context
) = 0x7;
1367 AL_reg(context
) = 0xA;
1370 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1371 CX_reg(context
) = 0x0000;
1374 case 0x31: /* TERMINATE AND STAY RESIDENT */
1375 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1378 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1379 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1380 INT21_DriveName( DL_reg(context
)));
1381 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1384 case 0x33: /* MULTIPLEXED */
1385 switch (AL_reg(context
))
1387 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1388 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1389 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1392 case 0x01: /* SET EXTENDED BREAK STATE */
1393 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1394 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1397 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1398 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1399 /* ugly coding in order to stay reentrant */
1400 if (DL_reg(context
))
1402 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1403 DOSCONF_config
.brk_flag
= 1;
1407 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1408 DOSCONF_config
.brk_flag
= 0;
1412 case 0x05: /* GET BOOT DRIVE */
1413 TRACE("GET BOOT DRIVE\n");
1414 DL_reg(context
) = 3;
1415 /* c: is Wine's bootdrive (a: is 1)*/
1418 case 0x06: /* GET TRUE VERSION NUMBER */
1419 TRACE("GET TRUE VERSION NUMBER\n");
1420 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1421 (HIWORD(GetVersion16() << 8));
1422 DX_reg(context
) = 0x00;
1426 INT_BARF( context
, 0x21 );
1431 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1432 TRACE("GET ADDRESS OF INDOS FLAG\n");
1433 if (!heap
) INT21_CreateHeap();
1434 context
->SegEs
= DosHeapHandle
;
1435 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1438 case 0x35: /* GET INTERRUPT VECTOR */
1439 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1441 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1442 context
->SegEs
= SELECTOROF(addr
);
1443 BX_reg(context
) = OFFSETOF(addr
);
1447 case 0x36: /* GET FREE DISK SPACE */
1448 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1449 INT21_DriveName( DL_reg(context
)));
1450 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1455 unsigned char switchchar
='/';
1456 switch (AL_reg(context
))
1458 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1459 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1460 AL_reg(context
) = 0x00; /* success*/
1461 DL_reg(context
) = switchchar
;
1463 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1464 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1465 switchchar
= DL_reg(context
);
1466 AL_reg(context
) = 0x00; /* success*/
1468 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1469 INT_BARF( context
, 0x21 );
1475 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1476 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1478 AX_reg(context
) = 0x02; /* no country support available */
1482 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1484 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1485 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1486 context
->Edx
), NULL
));
1487 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1488 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1489 * denied), while CreateDirectory return several ones. remap some of
1492 if (bSetDOSExtendedError
) {
1493 switch (GetLastError()) {
1494 case ERROR_ALREADY_EXISTS
:
1495 case ERROR_FILENAME_EXCED_RANGE
:
1496 case ERROR_DISK_FULL
:
1497 SetLastError(ERROR_ACCESS_DENIED
);
1504 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1506 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1507 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1511 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1513 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1514 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1517 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1518 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context
),
1519 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1520 bSetDOSExtendedError
= INT21_CreateFile( context
);
1523 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1524 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context
),
1525 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1526 OpenExistingFile(context
);
1529 case 0x3e: /* "CLOSE" - CLOSE FILE */
1530 TRACE("CLOSE handle %d\n",BX_reg(context
));
1531 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1534 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1535 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1536 context
->SegDs
,DX_reg(context
),CX_reg(context
) );
1540 result
= _hread16( BX_reg(context
),
1541 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1545 result
= WIN16_hread( BX_reg(context
),
1546 MAKESEGPTR( context
->SegDs
, context
->Edx
),
1548 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1549 else AX_reg(context
) = (WORD
)result
;
1553 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1554 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1555 context
->SegDs
,DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1557 LONG result
= _hwrite16( BX_reg(context
),
1558 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1561 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1562 else AX_reg(context
) = (WORD
)result
;
1566 case 0x41: /* "UNLINK" - DELETE FILE */
1567 TRACE("UNLINK %s\n",
1568 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1569 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1573 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1574 TRACE("LSEEK handle %d offset %ld from %s\n",
1575 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1576 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1577 "current file position":"end of file");
1579 LONG status
= _llseek16( BX_reg(context
),
1580 MAKELONG(DX_reg(context
),CX_reg(context
)),
1582 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1585 AX_reg(context
) = LOWORD(status
);
1586 DX_reg(context
) = HIWORD(status
);
1591 case 0x43: /* FILE ATTRIBUTES */
1592 switch (AL_reg(context
))
1595 TRACE("GET FILE ATTRIBUTES for %s\n",
1596 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1597 AX_reg(context
) = (WORD
)GetFileAttributesA(
1598 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1600 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1601 else CX_reg(context
) = AX_reg(context
);
1605 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1606 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1607 bSetDOSExtendedError
=
1608 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1613 FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1614 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1618 case 0x44: /* IOCTL */
1619 switch (AL_reg(context
))
1622 ioctlGetDeviceInfo(context
);
1628 const DOS_DEVICE
*dev
;
1629 if ((dev
= DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context
)) )) &&
1630 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1632 ASPI_DOS_HandleInt(context
);
1636 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1637 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
1638 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1640 FIXME("program tried to write to block device control channel of drive %d:\n",drive
);
1641 /* for (i=0;i<CX_reg(context);i++)
1642 fprintf(stdnimp,"%02x ",dataptr[i]);
1643 fprintf(stdnimp,"\n");*/
1644 AX_reg(context
)=CX_reg(context
);
1647 case 0x08: /* Check if drive is removable. */
1648 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1649 INT21_DriveName( BL_reg(context
)));
1650 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1653 SetLastError( ERROR_INVALID_DRIVE
);
1654 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1657 case DRIVE_REMOVABLE
:
1658 AX_reg(context
) = 0; /* removable */
1661 AX_reg(context
) = 1; /* not removable */
1666 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1667 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1668 INT21_DriveName( BL_reg(context
)));
1669 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1672 SetLastError( ERROR_INVALID_DRIVE
);
1673 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1677 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1680 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1685 case 0x0a: /* check if handle (BX) is remote */
1686 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1687 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1690 DX_reg(context
) = 0;
1693 case 0x0b: /* SET SHARING RETRY COUNT */
1694 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1695 CX_reg(context
), DX_reg(context
));
1696 if (!CX_reg(context
))
1698 AX_reg(context
) = 1;
1702 DOSMEM_LOL()->sharing_retry_delay
= CX_reg(context
);
1703 if (!DX_reg(context
))
1704 DOSMEM_LOL()->sharing_retry_count
= DX_reg(context
);
1705 RESET_CFLAG(context
);
1709 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1710 INT21_DriveName( BL_reg(context
)));
1711 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1714 case 0x0e: /* get logical drive mapping */
1715 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1716 INT21_DriveName( BL_reg(context
)));
1717 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1720 case 0x0F: /* Set logical drive mapping */
1723 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1724 INT21_DriveName( BL_reg(context
)));
1725 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1726 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1729 AX_reg(context
) = 0x000F; /* invalid drive */
1734 case 0xe0: /* Sun PC-NFS API */
1738 case 0x52: /* DR-DOS version */
1739 /* This is not DR-DOS */
1741 TRACE("GET DR-DOS VERSION requested\n");
1743 AX_reg(context
) = 0x0001; /* Invalid function */
1744 SET_CFLAG(context
); /* Error */
1745 SetLastError( ERROR_INVALID_FUNCTION
);
1749 INT_BARF( context
, 0x21 );
1754 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1757 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1758 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1759 DosFileHandleToWin32Handle(BX_reg(context
)),
1760 GetCurrentProcess(), &handle
,
1761 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1762 AX_reg(context
) = HFILE_ERROR16
;
1764 AX_reg(context
) = Win32HandleToDosFileHandle(handle
);
1768 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1769 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1770 BX_reg(context
),CX_reg(context
));
1771 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1774 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1775 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1776 INT21_DriveName( DL_reg(context
)));
1777 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1780 case 0x48: /* ALLOCATE MEMORY */
1781 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1786 mem
= DOSMEM_GetBlock((DWORD
)BX_reg(context
)<<4,NULL
);
1788 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1792 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1794 AX_reg(context
) = (DWORD
)mem
&0xffff;
1799 AX_reg(context
) = 0x0008; /* insufficient memory */
1800 BX_reg(context
) = DOSMEM_Available()>>4;
1805 case 0x49: /* FREE MEMORY */
1806 TRACE("FREE MEMORY segment %04lX\n", context
->SegEs
);
1810 ret
= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(context
->SegEs
<<4));
1813 ret
= !GlobalDOSFree16(context
->SegEs
);
1814 /* If we don't reset ES_reg, we will fail in the relay code */
1819 TRACE("FREE MEMORY failed\n");
1821 AX_reg(context
) = 0x0009; /* memory block address invalid */
1826 case 0x4a: /* RESIZE MEMORY BLOCK */
1827 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", context
->SegEs
, BX_reg(context
));
1828 if (!ISV86(context
))
1829 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1831 LPVOID
*mem
= DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(context
->SegEs
<<4),
1832 BX_reg(context
)<<4,NULL
);
1834 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1837 AX_reg(context
) = 0x0008; /* insufficient memory */
1838 BX_reg(context
) = DOSMEM_Available()>>4; /* not quite right */
1843 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1845 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1846 if (ISV86(context
)) {
1847 if (!Dosvm
.Exec( context
, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
),
1848 AL_reg(context
), CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
) ))
1849 bSetDOSExtendedError
= TRUE
;
1851 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1854 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1858 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1859 TRACE("EXIT with return code %d\n",AL_reg(context
));
1860 if (Dosvm
.Exit
) Dosvm
.Exit( context
, FALSE
, AL_reg(context
) );
1861 else ExitThread( AL_reg(context
) );
1864 case 0x4d: /* GET RETURN CODE */
1865 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1866 AX_reg(context
) = INT21_GetReturnCode();
1869 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1870 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1871 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1872 if (!INT21_FindFirst(context
)) break;
1875 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1876 TRACE("FINDNEXT\n");
1877 if (!INT21_FindNext(context
))
1879 SetLastError( ERROR_NO_MORE_FILES
);
1880 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1883 else AX_reg(context
) = 0; /* OK */
1885 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1886 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1887 INT21_SetCurrentPSP(BX_reg(context
));
1889 case 0x51: /* GET PSP ADDRESS */
1890 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1891 /* FIXME: should we return the original DOS PSP upon */
1892 /* Windows startup ? */
1893 BX_reg(context
) = INT21_GetCurrentPSP();
1895 case 0x62: /* GET PSP ADDRESS */
1896 TRACE("GET CURRENT PSP ADDRESS\n");
1897 /* FIXME: should we return the original DOS PSP upon */
1898 /* Windows startup ? */
1899 BX_reg(context
) = INT21_GetCurrentPSP();
1902 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1903 TRACE("SYSVARS - GET LIST OF LISTS\n");
1905 context
->SegEs
= ISV86(context
) ? HIWORD(DOS_LOLSeg
) : LOWORD(DOS_LOLSeg
);
1906 BX_reg(context
) = FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
);
1910 case 0x54: /* Get Verify Flag */
1911 TRACE("Get Verify Flag - Not Supported\n");
1912 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1915 case 0x56: /* "RENAME" - RENAME FILE */
1916 TRACE("RENAME %s to %s\n",
1917 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1918 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
));
1919 bSetDOSExtendedError
=
1920 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1921 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
)));
1924 case 0x57: /* FILE DATE AND TIME */
1925 switch (AL_reg(context
))
1927 case 0x00: /* Get */
1930 TRACE("GET FILE DATE AND TIME for handle %d\n",
1932 if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1933 bSetDOSExtendedError
= TRUE
;
1934 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1939 case 0x01: /* Set */
1942 TRACE("SET FILE DATE AND TIME for handle %d\n",
1944 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1946 bSetDOSExtendedError
=
1947 (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context
)),
1948 NULL
, NULL
, &filetime
));
1954 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1955 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1957 switch (AL_reg(context
))
1960 AX_reg(context
) = 1;
1963 AX_reg(context
) = 0;
1969 RESET_CFLAG(context
);
1972 case 0x5a: /* CREATE TEMPORARY FILE */
1973 TRACE("CREATE TEMPORARY FILE\n");
1974 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1977 case 0x5b: /* CREATE NEW FILE */
1978 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1979 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1980 bSetDOSExtendedError
= ((AX_reg(context
) =
1981 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1982 CX_reg(context
) )) == (WORD
)HFILE_ERROR16
);
1985 case 0x5d: /* NETWORK */
1986 FIXME("Function 0x%04x not implemented.\n", AX_reg (context
));
1987 /* Fix the following while you're at it. */
1988 SetLastError( ER_NoNetwork
);
1989 bSetDOSExtendedError
= TRUE
;
1993 bSetDOSExtendedError
= INT21_networkfunc (context
);
1996 case 0x5f: /* NETWORK */
1997 switch (AL_reg(context
))
1999 case 0x07: /* ENABLE DRIVE */
2000 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
2001 if (!DRIVE_Enable( DL_reg(context
) ))
2003 SetLastError( ERROR_INVALID_DRIVE
);
2004 bSetDOSExtendedError
= TRUE
;
2008 case 0x08: /* DISABLE DRIVE */
2009 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
2010 if (!DRIVE_Disable( DL_reg(context
) ))
2012 SetLastError( ERROR_INVALID_DRIVE
);
2013 bSetDOSExtendedError
= TRUE
;
2018 /* network software not installed */
2019 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
2020 SetLastError( ER_NoNetwork
);
2021 bSetDOSExtendedError
= TRUE
;
2026 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
2027 TRACE("TRUENAME %s\n",
2028 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
2030 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2032 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2033 context
->Edi
),NULL
))
2034 bSetDOSExtendedError
= TRUE
;
2035 else AX_reg(context
) = 0;
2039 case 0x61: /* UNUSED */
2040 case 0x63: /* misc. language support */
2041 switch (AL_reg(context
)) {
2042 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
2043 INT21_GetDBCSLeadTable(context
);
2047 case 0x64: /* OS/2 DOS BOX */
2048 INT_BARF( context
, 0x21 );
2052 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2053 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
2054 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2055 BX_reg(context
), DX_reg(context
));
2056 switch (AL_reg(context
)) {
2058 TRACE("\tget general internationalization info\n");
2060 *(WORD
*)(dataptr
+1) = 41;
2061 *(WORD
*)(dataptr
+3) = GetSystemDefaultLangID();
2062 *(WORD
*)(dataptr
+5) = CodePage
;
2063 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2066 TRACE("\tget pointer to collating sequence table\n");
2068 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2069 CX_reg(context
) = 258;/*FIXME: size of table?*/
2072 TRACE("\tConvert char to uppercase\n");
2073 DL_reg(context
) = toupper(DL_reg(context
));
2076 TRACE("\tconvert string to uppercase with length\n");
2078 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
);
2079 WORD len
= CX_reg(context
);
2080 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
2084 TRACE("\tConvert ASCIIZ string to uppercase\n");
2085 _strupr( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
) );
2088 TRACE("\tunimplemented function %d\n",AL_reg(context
));
2089 INT_BARF( context
, 0x21 );
2095 case 0x66: /* GLOBAL CODE PAGE TABLE */
2096 switch (AL_reg(context
))
2099 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2100 DX_reg(context
) = BX_reg(context
) = CodePage
;
2101 RESET_CFLAG(context
);
2104 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2105 BX_reg(context
),DX_reg(context
));
2106 CodePage
= BX_reg(context
);
2107 RESET_CFLAG(context
);
2112 case 0x67: /* SET HANDLE COUNT */
2113 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context
) );
2114 SetHandleCount16( BX_reg(context
) );
2115 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2118 case 0x68: /* "FFLUSH" - COMMIT FILE */
2119 case 0x6a: /* COMMIT FILE */
2120 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2121 bSetDOSExtendedError
= (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ));
2124 case 0x69: /* DISK SERIAL NUMBER */
2125 switch (AL_reg(context
))
2128 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2129 INT21_DriveName(BL_reg(context
)));
2130 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2131 else AX_reg(context
) = 0;
2135 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2136 INT21_DriveName(BL_reg(context
)));
2137 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2138 else AX_reg(context
) = 1;
2143 case 0x6C: /* Extended Open/Create*/
2144 TRACE("EXTENDED OPEN/CREATE %s\n",
2145 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edi
));
2146 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2149 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2150 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2151 /* not supported on anything but Win95 */
2152 TRACE("LONG FILENAME functions supported only by win95\n");
2154 AL_reg(context
) = 0;
2156 switch(AL_reg(context
))
2158 case 0x39: /* Create directory */
2159 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2160 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2161 bSetDOSExtendedError
= (!CreateDirectoryA(
2162 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2163 context
->Edx
), NULL
));
2164 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2165 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2166 * denied), while CreateDirectory return several ones. remap some of
2169 if (bSetDOSExtendedError
) {
2170 switch (GetLastError()) {
2171 case ERROR_ALREADY_EXISTS
:
2172 case ERROR_FILENAME_EXCED_RANGE
:
2173 case ERROR_DISK_FULL
:
2174 SetLastError(ERROR_ACCESS_DENIED
);
2180 case 0x3a: /* Remove directory */
2181 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2182 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2183 bSetDOSExtendedError
= (!RemoveDirectoryA(
2184 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2187 case 0x43: /* Get/Set file attributes */
2188 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2189 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2190 switch (BL_reg(context
))
2192 case 0x00: /* Get file attributes */
2193 TRACE("\tretrieve attributes\n");
2194 CX_reg(context
) = (WORD
)GetFileAttributesA(
2195 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2197 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2200 TRACE("\tset attributes 0x%04x\n",CX_reg(context
));
2201 bSetDOSExtendedError
= (!SetFileAttributesA(
2202 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2204 CX_reg(context
) ) );
2207 FIXME("Unimplemented long file name function:\n");
2208 INT_BARF( context
, 0x21 );
2210 AL_reg(context
) = 0;
2214 case 0x47: /* Get current directory */
2215 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2216 INT21_DriveName(DL_reg(context
)));
2217 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2220 case 0x4e: /* Find first file */
2221 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2222 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2223 /* FIXME: use attributes in CX */
2224 if ((AX_reg(context
) = FindFirstFile16(
2225 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
2226 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2228 == INVALID_HANDLE_VALUE16
)
2229 bSetDOSExtendedError
= TRUE
;
2231 case 0x4f: /* Find next file */
2232 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2234 if (!FindNextFile16( BX_reg(context
),
2235 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2237 bSetDOSExtendedError
= TRUE
;
2241 LPCSTR driveroot
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
2242 LPSTR buffer
= (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
2243 DWORD filename_len
, flags
;
2245 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot
);
2246 AX_reg(context
) = 0;
2247 if (!GetVolumeInformationA( driveroot
, NULL
, 0, NULL
, &filename_len
,
2248 &flags
, buffer
, 8 ))
2250 INT_BARF( context
, 0x21 );
2254 BX_reg(context
) = flags
| 0x4000; /* support for LFN functions */
2255 CX_reg(context
) = filename_len
;
2256 DX_reg(context
) = MAX_PATH
; /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2259 case 0xa1: /* Find close */
2260 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2262 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2265 switch(CL_reg(context
))
2267 case 0x01: /* Get short filename or path */
2268 if (!GetShortPathNameA
2269 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2271 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2273 bSetDOSExtendedError
= TRUE
;
2274 else AX_reg(context
) = 0;
2276 case 0x02: /* Get canonical long filename or path */
2277 if (!GetFullPathNameA
2278 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2280 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2281 context
->Edi
),NULL
))
2282 bSetDOSExtendedError
= TRUE
;
2283 else AX_reg(context
) = 0;
2286 FIXME("Unimplemented long file name function:\n");
2287 INT_BARF( context
, 0x21 );
2289 AL_reg(context
) = 0;
2293 case 0x6c: /* Create or open file */
2294 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2295 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
));
2296 /* translate Dos 7 action to Dos 6 action */
2297 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2300 case 0x3b: /* Change directory */
2301 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2302 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
2303 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2309 AL_reg(context
) = GetLastError();
2312 case 0x41: /* Delete file */
2313 TRACE("LONG FILENAME - DELETE FILE %s\n",
2314 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
2315 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2320 AL_reg(context
) = GetLastError();
2323 case 0x56: /* Move (rename) file */
2325 LPCSTR fn1
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2326 LPCSTR fn2
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
2327 TRACE("LONG FILENAME - RENAME FILE %s to %s\n", fn1
, fn2
);
2328 if (!MoveFileA(fn1
, fn2
))
2331 AL_reg(context
) = GetLastError();
2336 FIXME("Unimplemented long file name function:\n");
2337 INT_BARF( context
, 0x21 );
2339 AL_reg(context
) = 0;
2344 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2345 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2346 TRACE("windows95 function AX %04x\n",
2348 WARN(" returning unimplemented\n");
2350 AL_reg(context
) = 0;
2353 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2354 TRACE("windows95 function AX %04x\n",
2357 switch (AL_reg(context
))
2359 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
2360 /* ES:DI points to word with length of data (should be 0x3d) */
2364 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
2365 char root
[] = "A:\\";
2367 buffer
= (WORD
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
2369 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer
);
2371 /* validate passed-in buffer lengths */
2372 if ((*buffer
!= 0x3d) || (context
->Ecx
!= 0x3f))
2374 WARN("Get Extended DPB: buffer lengths incorrect\n");
2375 WARN("CX = %lx, buffer[0] = %x\n", context
->Ecx
, *buffer
);
2377 AL_reg(context
) = 0x18; /* bad buffer length */
2380 /* buffer checks out */
2381 buffer
++; /* skip over length word now */
2382 if (FillInDrivePB( DX_reg(context
) ) )
2384 edpb
= (struct EDPB
*)buffer
;
2386 /* copy down the old-style DPB portion first */
2387 memcpy(&edpb
->dpb
, &heap
->dpb
, sizeof(struct DPB
));
2389 /* now fill in the extended entries */
2390 edpb
->edpb_flags
= 0;
2391 edpb
->next_edpb
= 0;
2392 edpb
->free_cluster
= edpb
->free_cluster2
= 0;
2394 /* determine free disk space */
2395 *root
+= DOS_GET_DRIVE( DX_reg(context
) );
2396 GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
2397 &free_clusters
, &total_clusters
);
2399 edpb
->clusters_free
= (free_clusters
&0xffff);
2401 edpb
->clusters_free_hi
= free_clusters
>> 16;
2402 edpb
->mirroring_flags
= 0;
2403 edpb
->info_sector
= 0xffff;
2404 edpb
->spare_boot_sector
= 0xffff;
2405 edpb
->first_cluster
= 0;
2406 edpb
->max_cluster
= total_clusters
;
2407 edpb
->fat_clusters
= 32; /* made-up value */
2408 edpb
->root_cluster
= 0;
2410 RESET_CFLAG(context
); /* clear carry */
2411 AX_reg(context
) = 0;
2415 AX_reg(context
) = 0x00ff;
2421 case 0x03: /* Get Extended free space on drive */
2422 case 0x04: /* Set DPB for formatting */
2423 case 0x05: /* extended absolute disk read/write */
2424 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context
));
2426 AL_reg(context
) = 0;
2433 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2434 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2438 INT_BARF( context
, 0x21 );
2441 } /* END OF SWITCH */
2443 if( bSetDOSExtendedError
) /* set general error condition */
2445 AX_reg(context
) = GetLastError();
2449 if ((context
->EFlags
& 0x0001))
2450 TRACE("failed, error 0x%04lx\n", GetLastError() );
2452 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2453 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2454 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2455 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2456 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
2460 /***********************************************************************
2461 * GetSetKernelDOSProc
2463 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2465 FIXME("(DosProc=0x%08x): stub\n", (UINT
)DosProc
);