2 * DOS interrupt 21h handler
13 #include <sys/types.h>
28 #if defined(__svr4__) || defined(_SCO_DS)
29 /* SVR4 DOESNT do locking the same way must implement properly */
36 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
38 /* Define the drive parameter block, as used by int21/1F
39 * and int21/32. This table can be accessed through the
40 * global 'dpb' pointer, which points into the local dos
45 BYTE drive_num
; /* 0=A, etc. */
46 BYTE unit_num
; /* Drive's unit number (?) */
47 WORD sector_size
; /* Sector size in bytes */
48 BYTE high_sector
; /* Highest sector in a cluster */
49 BYTE shift
; /* Shift count (?) */
50 WORD reserved
; /* Number of reserved sectors at start */
51 BYTE num_FAT
; /* Number of FATs */
52 WORD dir_entries
; /* Number of root dir entries */
53 WORD first_data
; /* First data sector */
54 WORD high_cluster
; /* Highest cluster number */
55 WORD sectors_in_FAT
; /* Number of sectors per FAT */
56 WORD start_dir
; /* Starting sector of first dir */
57 DWORD driver_head
; /* Address of device driver header (?) */
58 BYTE media_ID
; /* Media ID */
59 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
60 DWORD next
; /* Pointer to next DPB in list */
61 WORD free_search
; /* Free cluster search start */
62 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
73 BYTE DummyDBCSLeadTable
[6];
75 static struct DosHeap
*heap
;
76 static WORD DosHeapHandle
;
78 WORD sharing_retries
= 3; /* number of retries at sharing violation */
79 WORD sharing_pause
= 1; /* pause between retries */
81 extern char TempDirectory
[];
83 static BOOL32
INT21_CreateHeap(void)
85 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
87 WARN(int21
, "Out of memory\n");
90 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
91 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
93 strcpy(heap
->biosdate
, "01/01/80");
94 memset(heap
->DummyDBCSLeadTable
, 0, 6);
98 static BYTE
*GetCurrentDTA( CONTEXT
*context
)
100 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
102 /* FIXME: This assumes DTA was set correctly! */
103 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
104 (DWORD
)OFFSETOF(pTask
->dta
) );
108 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
109 /* limited == TRUE is used with INT 0x21/0x440d */
114 setword(&data
[3], 0);
116 setword(&data
[6], 240);
117 setword(&data
[8], 64000);
119 setword(&data
[0x0b], 40);
120 setword(&data
[0x0d], 56);
121 setword(&data
[0x0f], 2);
122 setword(&data
[0x11], 0);
124 setword(&data
[0x1f], 800);
126 setword(&data
[0x22], 1);
128 } else { /* 1.44mb */
131 setword(&data
[3], 0);
133 setword(&data
[6], 240);
134 setword(&data
[8], 2880);
136 setword(&data
[0x0b], 6);
137 setword(&data
[0x0d], 18);
138 setword(&data
[0x0f], 2);
139 setword(&data
[0x11], 0);
141 setword(&data
[0x1f], 80);
143 setword(&data
[0x22], 2);
148 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
150 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
151 char root
[] = "A:\\";
153 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
154 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
155 &free_clusters
, &total_clusters
)) return 0;
156 AX_reg(context
) = cluster_sectors
;
157 BX_reg(context
) = free_clusters
;
158 CX_reg(context
) = sector_bytes
;
159 DX_reg(context
) = total_clusters
;
163 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
165 if (!INT21_GetFreeDiskSpace( context
)) return 0;
166 if (!heap
&& !INT21_CreateHeap()) return 0;
167 heap
->mediaID
= 0xf0;
168 DS_reg(context
) = DosHeapHandle
;
169 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
173 static void GetDrivePB( CONTEXT
*context
, int drive
)
175 if(!DRIVE_IsValid(drive
))
177 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
178 AX_reg(context
) = 0x00ff;
180 else if (heap
|| INT21_CreateHeap())
182 FIXME(int21
, "GetDrivePB not fully implemented.\n");
184 /* FIXME: I have no idea what a lot of this information should
185 * say or whether it even really matters since we're not allowing
186 * direct block access. However, some programs seem to depend on
187 * getting at least _something_ back from here. The 'next' pointer
188 * does worry me, though. Should we have a complete table of
189 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
191 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
192 heap
->dpb
.sector_size
= 512;
193 heap
->dpb
.high_sector
= 1;
194 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
195 heap
->dpb
.reserved
= 0;
196 heap
->dpb
.num_FAT
= 1;
197 heap
->dpb
.dir_entries
= 2;
198 heap
->dpb
.first_data
= 2;
199 heap
->dpb
.high_cluster
= 64000;
200 heap
->dpb
.sectors_in_FAT
= 1;
201 heap
->dpb
.start_dir
= 1;
202 heap
->dpb
.driver_head
= 0;
203 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
204 heap
->dpb
.access_flag
= 0;
206 heap
->dpb
.free_search
= 0;
207 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
209 AL_reg(context
) = 0x00;
210 DS_reg(context
) = SELECTOROF(dpbsegptr
);
211 BX_reg(context
) = OFFSETOF(dpbsegptr
);
216 static void ioctlGetDeviceInfo( CONTEXT
*context
)
221 TRACE(int21
, "(%d)\n", BX_reg(context
));
223 RESET_CFLAG(context
);
226 if ((file
= FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context
)) )))
228 const DOS_DEVICE
*dev
= DOSFS_GetDevice( file
->unix_name
);
229 FILE_ReleaseFile( file
);
232 DX_reg(context
) = dev
->flags
;
237 /* it seems to be a file */
238 curr_drive
= DRIVE_GetCurrentDrive();
239 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
241 /* bits 0-5 are current drive
242 * bit 6 - file has NOT been written..FIXME: correct?
243 * bit 8 - generate int24 if no diskspace on write/ read past end of file
244 * bit 11 - media not removable
245 * bit 14 - don't set file date/time on closing
246 * bit 15 - file is remote
250 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
252 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
253 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
255 if (!DRIVE_IsValid(drive
))
257 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
261 if (CH_reg(context
) != 0x08)
263 INT_BARF( context
, 0x21 );
267 switch (CL_reg(context
))
269 case 0x4a: /* lock logical volume */
270 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
273 case 0x60: /* get device parameters */
274 /* used by w4wgrp's winfile */
275 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
277 dataptr
[6] = 0; /* media type */
280 dataptr
[1] = 0x05; /* fixed disk */
281 setword(&dataptr
[2], 0x01); /* non removable */
282 setword(&dataptr
[4], 0x300); /* # of cylinders */
286 dataptr
[1] = 0x07; /* block dev, floppy */
287 setword(&dataptr
[2], 0x02); /* removable */
288 setword(&dataptr
[4], 80); /* # of cylinders */
290 CreateBPB(drive
, &dataptr
[7], TRUE
);
291 RESET_CFLAG(context
);
294 case 0x66:/* get disk serial number */
296 char label
[12],fsname
[9],path
[4];
299 strcpy(path
,"x:\\");path
[0]=drive
+'A';
300 GetVolumeInformation32A(
301 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
304 memcpy(dataptr
+2,&serial
,4);
305 memcpy(dataptr
+6,label
,11);
306 memcpy(dataptr
+17,fsname
,8);
311 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
315 memset(dataptr
+1, '\0', dataptr
[0]-1);
316 dataptr
[1] = dataptr
[0];
317 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
318 dataptr
[3] = 0xFF; /* no physical drive */
322 INT_BARF( context
, 0x21 );
327 static void INT21_ParseFileNameIntoFCB( CONTEXT
*context
)
330 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), SI_reg(context
) );
332 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), DI_reg(context
) );
333 char *buffer
, *s
, *d
;
335 AL_reg(context
) = 0xff; /* failed */
337 TRACE(int21
, "filename: '%s'\n", filename
);
339 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) );
345 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
352 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
354 TRACE(int21
, "FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
356 HeapFree( GetProcessHeap(), 0, buffer
);
359 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
361 /* point DS:SI to first unparsed character */
362 SI_reg(context
) += (int)s
- (int)filename
;
365 static void INT21_GetSystemDate( CONTEXT
*context
)
368 GetLocalTime( &systime
);
369 CX_reg(context
) = systime
.wYear
;
370 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
371 AX_reg(context
) = systime
.wDayOfWeek
;
374 static void INT21_GetSystemTime( CONTEXT
*context
)
377 GetLocalTime( &systime
);
378 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
379 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
382 /* Many calls translate a drive argument like this:
383 drive number (00h = default, 01h = A:, etc)
385 static char drivestring
[]="default";
387 char *INT21_DriveName(int drive
)
392 drivestring
[0]= (unsigned char)drive
+ '@';
398 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
400 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
401 EDX_reg(context
) ), CX_reg(context
) );
402 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
406 static void OpenExistingFile( CONTEXT
*context
)
408 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
410 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
412 AX_reg(context
) = DOS_ExtendedError
;
421 switch (AX_reg(context
) & 0x0070)
423 case 0x00: /* compatability mode */
424 case 0x40: /* DENYNONE */
428 case 0x30: /* DENYREAD */
429 TRACE(int21
, "(%s): DENYREAD changed to DENYALL\n",
430 (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
431 case 0x10: /* DENYALL */
435 case 0x20: /* DENYWRITE */
446 int result
,retries
=sharing_retries
;
448 #if defined(__svr4__) || defined(_SCO_DS)
449 ERR(int21
, "Should call flock and needs porting to lockf\n");
453 result
= flock(handle
, lock
| LOCK_NB
);
455 if ( retries
&& (!result
) )
458 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
459 result
++; /* stop the optimizer */
460 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
464 while( (!result
) && (!(retries
--)) );
469 AX_reg(context
) = DOS_ExtendedError
;
478 AX_reg(context
) = handle
;
479 RESET_CFLAG(context
);
484 static void CloseFile( CONTEXT
*context
)
486 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
488 AX_reg(context
) = DOS_ExtendedError
;
493 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
495 BOOL32 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 ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
506 UINT16 uReturnCX
= 0;
508 /* Now decide what do do */
510 if ((action
& 0x07) == 0)
512 BX_reg(context
) = AX_reg(context
);
514 AX_reg(context
) = 0x0050; /*File exists*/
516 WARN(int21
, "extended open/create: failed because file exists \n");
518 else if ((action
& 0x07) == 2)
520 /* Truncate it, but first check if opened for write */
521 if ((BL_reg(context
) & 0x0007)== 0)
523 BX_reg(context
) = AX_reg(context
);
525 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
526 AX_reg(context
) = 0x000C; /*Access code invalid*/
531 /* Shuffle arguments to call CloseFile while
532 * preserving BX and DX */
534 TRACE(int21
, "extended open/create: Closing before truncate\n");
535 BX_reg(context
) = AX_reg(context
);
537 if (EFL_reg(context
) & 0x0001)
539 WARN(int21
, "extended open/create: close before trunc failed\n");
540 AX_reg(context
) = 0x0019; /*Seek Error*/
544 /* Shuffle arguments to call CreateFile */
546 TRACE(int21
, "extended open/create: Truncating\n");
547 AL_reg(context
) = BL_reg(context
);
548 /* CX is still the same */
549 DX_reg(context
) = SI_reg(context
);
550 bExtendedError
= INT21_CreateFile(context
);
552 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
554 WARN(int21
, "extended open/create: trunc failed\n");
555 return bExtendedError
;
560 else uReturnCX
= 0x1;
562 CX_reg(context
) = uReturnCX
;
564 else /* file does not exist */
566 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
567 if ((action
& 0xF0)== 0)
571 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
575 /* Shuffle arguments to call CreateFile */
576 TRACE(int21
, "extended open/create: Creating\n");
577 AL_reg(context
) = BL_reg(context
);
578 /* CX should still be the same */
579 DX_reg(context
) = SI_reg(context
);
580 bExtendedError
= INT21_CreateFile(context
);
581 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
583 WARN(int21
, "extended open/create: create failed\n");
584 return bExtendedError
;
590 return bExtendedError
;
594 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
597 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
599 TRACE(int21
,"changedir %s\n", dirname
);
600 if (dirname
[0] && (dirname
[1] == ':'))
602 drive
= toupper(dirname
[0]) - 'A';
605 else drive
= DRIVE_GetCurrentDrive();
606 return DRIVE_Chdir( drive
, dirname
);
610 static int INT21_FindFirst( CONTEXT
*context
)
614 DOS_FULL_NAME full_name
;
615 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
617 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
618 dta
->unixPath
= NULL
;
619 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
621 AX_reg(context
) = DOS_ExtendedError
;
625 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
626 p
= strrchr( dta
->unixPath
, '/' );
629 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
630 * (doesn't matter as it is set below anyway)
632 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
634 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
635 dta
->unixPath
= NULL
;
636 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
637 AX_reg(context
) = ER_FileNotFound
;
641 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
642 : DRIVE_GetCurrentDrive();
644 dta
->search_attr
= CL_reg(context
);
649 static int INT21_FindNext( CONTEXT
*context
)
651 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
652 WIN32_FIND_DATA32A entry
;
655 if (!dta
->unixPath
) return 0;
656 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
657 dta
->search_attr
, dta
->count
, &entry
)))
659 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
660 dta
->unixPath
= NULL
;
663 if ((int)dta
->count
+ count
> 0xffff)
665 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
666 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
667 dta
->unixPath
= NULL
;
671 dta
->fileattr
= entry
.dwFileAttributes
;
672 dta
->filesize
= entry
.nFileSizeLow
;
673 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
674 &dta
->filedate
, &dta
->filetime
);
675 strcpy( dta
->filename
, entry
.cAlternateFileName
);
676 if (!memchr(dta
->mask
,'?',11)) {
677 /* wildcardless search, release resources in case no findnext will
678 * be issued, and as a workaround in case file creation messes up
679 * findnext, as sometimes happens with pkunzip */
680 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
681 dta
->unixPath
= NULL
;
687 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
689 static int counter
= 0;
690 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
691 char *p
= name
+ strlen(name
);
693 /* despite what Ralf Brown says, some programs seem to call without
694 * ending backslash (DOS accepts that, so we accept it too) */
695 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
699 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
700 counter
= (counter
+ 1) % 1000;
702 if ((AX_reg(context
) = HFILE32_TO_HFILE16(_lcreat_uniq( name
, 0 ))) != (WORD
)HFILE_ERROR16
)
704 TRACE(int21
, "created %s\n", name
);
707 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
712 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
714 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
715 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
717 if (!DRIVE_IsValid(drive
))
719 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
722 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
723 AX_reg(context
) = 0x0100; /* success return code */
728 static void INT21_GetDBCSLeadTable( CONTEXT
*context
)
730 if (heap
|| INT21_CreateHeap())
731 { /* return an empty table just as DOS 4.0+ does */
732 DS_reg(context
) = DosHeapHandle
;
733 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
737 AX_reg(context
) = 0x1; /* error */
743 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
745 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
746 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
748 if (!DRIVE_IsValid(drive
))
750 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
754 *(WORD
*)dataptr
= 0;
755 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
756 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
757 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
762 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
764 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
765 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
767 if (!DRIVE_IsValid(drive
))
769 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
773 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
778 /* microsoft's programmers should be shot for using CP/M style int21
779 calls in Windows for Workgroup's winfile.exe */
781 static int INT21_FindFirstFCB( CONTEXT
*context
)
783 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
788 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
789 else pFCB
= (FINDFILE_FCB
*)fcb
;
790 drive
= DOS_GET_DRIVE( pFCB
->drive
);
791 if (!DRIVE_IsValid( drive
)) return 0;
792 root
= DRIVE_GetRoot( drive
);
793 cwd
= DRIVE_GetUnixCwd( drive
);
794 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
795 strlen(root
)+strlen(cwd
)+2 );
796 if (!pFCB
->unixPath
) return 0;
797 strcpy( pFCB
->unixPath
, root
);
798 strcat( pFCB
->unixPath
, "/" );
799 strcat( pFCB
->unixPath
, cwd
);
805 static int INT21_FindNextFCB( CONTEXT
*context
)
807 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
809 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
810 WIN32_FIND_DATA32A entry
;
814 if (*fcb
== 0xff) /* extended FCB ? */
817 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
822 pFCB
= (FINDFILE_FCB
*)fcb
;
825 if (!pFCB
->unixPath
) return 0;
826 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
827 DOS_GET_DRIVE( pFCB
->drive
), attr
,
828 pFCB
->count
, &entry
)))
830 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
831 pFCB
->unixPath
= NULL
;
834 pFCB
->count
+= count
;
836 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
837 *(BYTE
*)pResult
= 0xff;
838 (BYTE
*)pResult
+=6; /* leave reserved field behind */
839 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
842 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
844 pResult
->fileattr
= entry
.dwFileAttributes
;
845 pResult
->cluster
= 0; /* what else? */
846 pResult
->filesize
= entry
.nFileSizeLow
;
847 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
848 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
849 &pResult
->filedate
, &pResult
->filetime
);
851 /* Convert file name to FCB format */
853 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
854 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
855 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
856 pResult
->filename
[0] = pResult
->filename
[1] = '.';
859 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
860 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
862 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
863 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
864 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
867 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
868 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
874 static void DeleteFileFCB( CONTEXT
*context
)
876 FIXME(int21
, "(%p): stub\n", context
);
879 static void RenameFileFCB( CONTEXT
*context
)
881 FIXME(int21
, "(%p): stub\n", context
);
886 static void fLock( CONTEXT
* context
)
889 switch ( AX_reg(context
) & 0xff )
891 case 0x00: /* LOCK */
892 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
894 MAKELONG(DX_reg(context
),CX_reg(context
)),
895 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
896 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context
)),
897 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
898 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
899 AX_reg(context
) = DOS_ExtendedError
;
904 case 0x01: /* UNLOCK */
905 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
907 MAKELONG(DX_reg(context
),CX_reg(context
)),
908 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
909 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context
)),
910 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
911 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
912 AX_reg(context
) = DOS_ExtendedError
;
917 AX_reg(context
) = 0x0001;
924 INT21_networkfunc (CONTEXT
*context
)
926 switch (AL_reg(context
)) {
927 case 0x00: /* Get machine name. */
929 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
930 TRACE(int21
, "getting machine name to %p\n", dst
);
931 if (gethostname (dst
, 15))
933 WARN(int21
,"failed!\n");
934 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
937 int len
= strlen (dst
);
941 CH_reg(context
) = 1; /* Valid */
942 CL_reg(context
) = 1; /* NETbios number??? */
943 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
949 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
954 static void INT21_SetCurrentPSP(WORD psp
)
957 TDB
*pTask
= hModule
? NULL
: (TDB
*)GlobalLock16( GetCurrentTask() );
958 NE_MODULE
*pModule
= (hModule
|| pTask
) ? NE_GetPtr( hModule
? hModule
: pTask
->hModule
) : NULL
;
960 GlobalUnlock16( GetCurrentTask() );
961 if (pModule
->lpDosTask
)
962 pModule
->lpDosTask
->psp_seg
= psp
;
965 ERR(int21
, "Cannot change PSP for non-DOS task!\n");
968 static WORD
INT21_GetCurrentPSP()
971 TDB
*pTask
= hModule
? NULL
: (TDB
*)GlobalLock16( GetCurrentTask() );
972 NE_MODULE
*pModule
= (hModule
|| pTask
) ? NE_GetPtr( hModule
? hModule
: pTask
->hModule
) : NULL
;
974 GlobalUnlock16( GetCurrentTask() );
975 if (pModule
->lpDosTask
)
976 return pModule
->lpDosTask
->psp_seg
;
979 return GetCurrentPDB();
983 SEGPTR
INT21_GetListOfLists()
985 static DOS_LISTOFLISTS
*LOL
;
986 static SEGPTR seg_LOL
;
991 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
992 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
993 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
994 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
995 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
996 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
997 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
998 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
999 0133:00A0 D0 44 C8 FD D0 44 .D...D
1002 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
1004 LOL
->CX_Int21_5e01
= 0x0;
1005 LOL
->LRU_count_FCB_cache
= 0x0;
1006 LOL
->LRU_count_FCB_open
= 0x0;
1007 LOL
->OEM_func_handler
= -1; /* not available */
1008 LOL
->INT21_offset
= 0x0;
1009 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
1010 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
1011 LOL
->ptr_disk_buf
= 0x0;
1012 LOL
->offs_unread_CON
= 0x0;
1013 LOL
->seg_first_MCB
= 0x0;
1014 LOL
->ptr_first_DPB
= 0x0;
1015 LOL
->ptr_first_SysFileTable
= 0x0;
1016 LOL
->ptr_clock_dev_hdr
= 0x0;
1017 LOL
->ptr_CON_dev_hdr
= 0x0;
1018 LOL
->max_byte_per_sec
= 512;
1019 LOL
->ptr_disk_buf_info
= 0x0;
1020 LOL
->ptr_array_CDS
= 0x0;
1021 LOL
->ptr_sys_FCB
= 0x0;
1022 LOL
->nr_protect_FCB
= 0x0;
1023 LOL
->nr_block_dev
= 0x0;
1024 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
1025 LOL
->nr_drives_JOINed
= 0x0;
1026 LOL
->ptr_spec_prg_names
= 0x0;
1027 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
1028 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
1029 LOL
->PSP_last_exec
= 0x0;
1030 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
1031 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
1032 LOL
->boot_drive
= 3; /* C: */
1033 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
1034 LOL
->size_extended_mem
= 0xf000; /* very high value */
1036 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
1037 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
1040 /***********************************************************************
1041 * DOS3Call (KERNEL.102)
1043 void WINAPI
DOS3Call( CONTEXT
*context
)
1045 BOOL32 bSetDOSExtendedError
= FALSE
;
1048 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
1049 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1050 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1051 SI_reg(context
), DI_reg(context
),
1052 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1056 if (AH_reg(context
) == 0x59) /* Get extended error info */
1058 TRACE(int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1059 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
1060 AX_reg(context
) = DOS_ExtendedError
;
1061 BH_reg(context
) = DOS_ErrorClass
;
1062 BL_reg(context
) = DOS_ErrorAction
;
1063 CH_reg(context
) = DOS_ErrorLocus
;
1067 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1069 TRACE(int21
, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1070 /* no flush here yet */
1071 AH_reg(context
) = AL_reg(context
);
1074 DOS_ERROR( 0, 0, 0, 0 );
1075 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1077 switch(AH_reg(context
))
1079 case 0x00: /* TERMINATE PROGRAM */
1080 TRACE(int21
,"TERMINATE PROGRAM\n");
1084 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1085 case 0x03: /* READ CHARACTER FROM STDAUX */
1086 case 0x04: /* WRITE CHARACTER TO STDAUX */
1087 case 0x05: /* WRITE CHARACTER TO PRINTER */
1088 case 0x0b: /* GET STDIN STATUS */
1089 case 0x0f: /* OPEN FILE USING FCB */
1090 case 0x10: /* CLOSE FILE USING FCB */
1091 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1092 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1093 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1094 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1095 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1096 case 0x23: /* GET FILE SIZE FOR FCB */
1097 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1098 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1099 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1100 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1101 case 0x54: /* GET VERIFY FLAG */
1102 INT_BARF( context
, 0x21 );
1105 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1106 TRACE(int21
, "Write Character to Standard Output\n");
1107 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1110 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1111 TRACE(int21
, "Direct Console Input/Output\n");
1112 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1115 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1116 TRACE(int21
,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1117 AL_reg(context
) = CONSOLE_GetCharacter();
1120 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1121 TRACE(int21
,"CHARACTER INPUT WITHOUT ECHO\n");
1122 AL_reg(context
) = CONSOLE_GetCharacter();
1125 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1126 TRACE(int21
,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1127 DS_reg(context
),DX_reg(context
) );
1129 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1130 LONG length
= strchr(data
,'$')-data
;
1131 _hwrite16( 1, data
, length
);
1132 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1136 case 0x0a: /* BUFFERED INPUT */
1138 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1139 EDX_reg(context
) ));
1142 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1144 TRACE(int21
,"Handle old chars in buffer!\n");
1145 res
=_lread16( 0, buffer
+2,buffer
[0]);
1147 if(buffer
[res
+1] == '\n')
1148 buffer
[res
+1] = '\r';
1152 case 0x2e: /* SET VERIFY FLAG */
1153 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1154 /* we cannot change the behaviour anyway, so just ignore it */
1157 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1161 case 0x6b: /* NULL FUNCTION */
1162 AL_reg(context
) = 0;
1165 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1169 case 0x0d: /* DISK BUFFER FLUSH */
1170 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1171 RESET_CFLAG(context
); /* dos 6+ only */
1174 case 0x0e: /* SELECT DEFAULT DRIVE */
1175 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1176 DRIVE_SetCurrentDrive( DL_reg(context
) );
1177 AL_reg(context
) = MAX_DOS_DRIVES
;
1180 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1181 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1182 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1183 if (!INT21_FindFirstFCB(context
))
1185 AL_reg(context
) = 0xff;
1188 /* else fall through */
1190 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1191 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1194 case 0x13: /* DELETE FILE USING FCB */
1195 DeleteFileFCB(context
);
1198 case 0x17: /* RENAME FILE USING FCB */
1199 RenameFileFCB(context
);
1202 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1203 AL_reg(context
) = DRIVE_GetCurrentDrive();
1206 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1208 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1209 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1210 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1214 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1215 DL_reg(context
) = 0;
1216 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1219 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1220 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1223 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1224 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1227 case 0x25: /* SET INTERRUPT VECTOR */
1228 INT_CtxSetHandler( context
, AL_reg(context
),
1229 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1233 case 0x29: /* PARSE FILENAME INTO FCB */
1234 INT21_ParseFileNameIntoFCB(context
);
1237 case 0x2a: /* GET SYSTEM DATE */
1238 INT21_GetSystemDate(context
);
1241 case 0x2b: /* SET SYSTEM DATE */
1242 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1243 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1244 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1247 case 0x2c: /* GET SYSTEM TIME */
1248 INT21_GetSystemTime(context
);
1251 case 0x2d: /* SET SYSTEM TIME */
1252 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1253 CH_reg(context
), CL_reg(context
),
1254 DH_reg(context
), DL_reg(context
) );
1255 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1258 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1259 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1261 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1262 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1263 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1267 case 0x30: /* GET DOS VERSION */
1268 TRACE(int21
,"GET DOS VERSION %s requested\n",
1269 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1270 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1271 (HIWORD(GetVersion16()) << 8);
1273 AH_reg(context
) = 0x7;
1274 AL_reg(context
) = 0xA;
1277 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1278 CX_reg(context
) = 0x0000;
1281 case 0x31: /* TERMINATE AND STAY RESIDENT */
1282 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1285 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1286 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1287 INT21_DriveName( DL_reg(context
)));
1288 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1291 case 0x33: /* MULTIPLEXED */
1292 switch (AL_reg(context
))
1294 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1295 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE stub\n");
1296 DL_reg(context
) = 0;
1299 case 0x01: /* SET EXTENDED BREAK STATE */
1300 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE stub\n");
1303 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1304 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1305 DL_reg(context
) = 0;
1308 case 0x05: /* GET BOOT DRIVE */
1309 TRACE(int21
,"GET BOOT DRIVE\n");
1310 DL_reg(context
) = 3;
1311 /* c: is Wine's bootdrive (a: is 1)*/
1314 case 0x06: /* GET TRUE VERSION NUMBER */
1315 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1316 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1317 (HIWORD(GetVersion16() << 8));
1318 DX_reg(context
) = 0x00;
1322 INT_BARF( context
, 0x21 );
1327 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1328 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1329 if (!heap
) INT21_CreateHeap();
1330 ES_reg(context
) = DosHeapHandle
;
1331 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1334 case 0x35: /* GET INTERRUPT VECTOR */
1335 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1337 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1338 ES_reg(context
) = SELECTOROF(addr
);
1339 BX_reg(context
) = OFFSETOF(addr
);
1343 case 0x36: /* GET FREE DISK SPACE */
1344 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1345 INT21_DriveName( DL_reg(context
)));
1346 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1351 unsigned char switchchar
='/';
1352 switch (AL_reg(context
))
1354 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1355 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1356 AL_reg(context
) = 0x00; /* success*/
1357 DL_reg(context
) = switchchar
;
1359 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1360 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1361 switchchar
= DL_reg(context
);
1362 AL_reg(context
) = 0x00; /* success*/
1364 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1365 INT_BARF( context
, 0x21 );
1371 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1372 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1374 AX_reg(context
) = 0x02; /* no country support available */
1378 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1379 TRACE(int21
,"MKDIR %s\n",
1380 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1381 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1382 EDX_reg(context
) ), NULL
));
1385 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1386 TRACE(int21
,"RMDIR %s\n",
1387 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1388 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1389 EDX_reg(context
) )));
1392 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1393 TRACE(int21
,"CHDIR %s\n",
1394 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1395 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1398 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1399 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1400 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1401 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1402 EDX_reg(context
) ), CX_reg(context
) );
1403 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1406 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1407 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1408 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1409 OpenExistingFile(context
);
1412 case 0x3e: /* "CLOSE" - CLOSE FILE */
1413 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1414 if ((BX_reg(context
)<5)||
1415 /* FIXME: need to improve on those handle conversion macros */
1416 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE
)))||
1417 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE
)))||
1418 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE
)))) {
1419 /* hack to make sure stdio isn't closed */
1420 FIXME(int21
, "stdio handle closed, need proper conversion\n");
1421 DOS_ExtendedError
= 0x06;
1422 bSetDOSExtendedError
= TRUE
;
1424 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1427 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1428 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1429 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1433 result
= _hread16( BX_reg(context
),
1434 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1438 result
= WIN16_hread( BX_reg(context
),
1439 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1442 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1443 else AX_reg(context
) = (WORD
)result
;
1447 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1448 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1449 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1451 LONG result
= _hwrite16( BX_reg(context
),
1452 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1455 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1456 else AX_reg(context
) = (WORD
)result
;
1460 case 0x41: /* "UNLINK" - DELETE FILE */
1461 TRACE(int21
,"UNLINK%s\n",
1462 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1463 bSetDOSExtendedError
= (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1464 EDX_reg(context
) )));
1467 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1468 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1469 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1470 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1471 "current file position":"end of file");
1473 LONG status
= _llseek16( BX_reg(context
),
1474 MAKELONG(DX_reg(context
),CX_reg(context
)),
1476 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1479 AX_reg(context
) = LOWORD(status
);
1480 DX_reg(context
) = HIWORD(status
);
1485 case 0x43: /* FILE ATTRIBUTES */
1486 switch (AL_reg(context
))
1489 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1490 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1491 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1492 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1494 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1495 else CX_reg(context
) = AX_reg(context
);
1499 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1500 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1501 bSetDOSExtendedError
=
1502 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1507 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1508 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1512 case 0x44: /* IOCTL */
1513 switch (AL_reg(context
))
1516 ioctlGetDeviceInfo(context
);
1523 file
= FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context
)));
1524 if (!strcasecmp(file
->unix_name
, "SCSIMGR$"))
1525 ASPI_DOS_HandleInt(context
);
1526 FILE_ReleaseFile( file
);
1529 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1530 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1531 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1533 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1534 /* for (i=0;i<CX_reg(context);i++)
1535 fprintf(stdnimp,"%02x ",dataptr[i]);
1536 fprintf(stdnimp,"\n");*/
1537 AX_reg(context
)=CX_reg(context
);
1540 case 0x08: /* Check if drive is removable. */
1541 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1542 INT21_DriveName( BL_reg(context
)));
1543 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1545 case DRIVE_CANNOTDETERMINE
:
1546 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1547 AX_reg(context
) = ER_InvalidDrive
;
1550 case DRIVE_REMOVABLE
:
1551 AX_reg(context
) = 0; /* removable */
1554 AX_reg(context
) = 1; /* not removable */
1559 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1560 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1561 INT21_DriveName( BL_reg(context
)));
1562 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1564 case DRIVE_CANNOTDETERMINE
:
1565 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1566 AX_reg(context
) = ER_InvalidDrive
;
1570 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1573 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1578 case 0x0a: /* check if handle (BX) is remote */
1579 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1580 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1583 DX_reg(context
) = 0;
1586 case 0x0b: /* SET SHARING RETRY COUNT */
1587 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1588 CX_reg(context
), DX_reg(context
));
1589 if (!CX_reg(context
))
1591 AX_reg(context
) = 1;
1595 sharing_pause
= CX_reg(context
);
1596 if (!DX_reg(context
))
1597 sharing_retries
= DX_reg(context
);
1598 RESET_CFLAG(context
);
1602 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1603 INT21_DriveName( BL_reg(context
)));
1604 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1607 case 0x0e: /* get logical drive mapping */
1608 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1609 INT21_DriveName( BL_reg(context
)));
1610 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1613 case 0x0F: /* Set logical drive mapping */
1616 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1617 INT21_DriveName( BL_reg(context
)));
1618 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1619 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1622 AX_reg(context
) = 0x000F; /* invalid drive */
1627 case 0xe0: /* Sun PC-NFS API */
1632 INT_BARF( context
, 0x21 );
1637 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1638 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1639 bSetDOSExtendedError
= ((AX_reg(context
) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context
))))) == (WORD
)HFILE_ERROR16
);
1642 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1643 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1644 BX_reg(context
),CX_reg(context
));
1645 bSetDOSExtendedError
= (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context
)), HFILE16_TO_HFILE32(CX_reg(context
)) ) == HFILE_ERROR32
);
1648 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1649 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1650 INT21_DriveName( DL_reg(context
)));
1651 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1654 case 0x48: /* ALLOCATE MEMORY */
1655 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1660 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1662 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1666 mem
= (LPVOID
)GlobalDOSAlloc(BX_reg(context
)<<4);
1668 AX_reg(context
) = (DWORD
)mem
&0xffff;
1673 AX_reg(context
) = 0x0008; /* insufficient memory */
1674 BX_reg(context
) = DOSMEM_Available(0)>>4;
1679 case 0x49: /* FREE MEMORY */
1680 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1684 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1687 ret
= !GlobalDOSFree(ES_reg(context
));
1688 /* If we don't reset ES_reg, we will fail in the relay code */
1689 ES_reg(context
)=ret
;
1693 TRACE(int21
,"FREE MEMORY failed\n");
1695 AX_reg(context
) = 0x0009; /* memory block address invalid */
1700 case 0x4a: /* RESIZE MEMORY BLOCK */
1701 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1702 if (!ISV86(context
))
1703 FIXME(int21
,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1705 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1706 BX_reg(context
)<<4,NULL
);
1708 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1711 AX_reg(context
) = 0x0008; /* insufficient memory */
1712 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1717 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1718 TRACE(int21
,"EXEC %s\n",
1719 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1720 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1723 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1726 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1727 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1728 ExitProcess( AL_reg(context
) );
1731 case 0x4d: /* GET RETURN CODE */
1732 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1733 AX_reg(context
) = 0; /* normal exit */
1736 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1737 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1738 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1739 if (!INT21_FindFirst(context
)) break;
1742 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1743 TRACE(int21
,"FINDNEXT\n");
1744 if (!INT21_FindNext(context
))
1746 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1747 AX_reg(context
) = ER_NoMoreFiles
;
1750 else AX_reg(context
) = 0; /* OK */
1752 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1753 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1754 INT21_SetCurrentPSP(BX_reg(context
));
1756 case 0x51: /* GET PSP ADDRESS */
1757 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1758 /* FIXME: should we return the original DOS PSP upon */
1759 /* Windows startup ? */
1760 BX_reg(context
) = INT21_GetCurrentPSP();
1762 case 0x62: /* GET PSP ADDRESS */
1763 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1764 /* FIXME: should we return the original DOS PSP upon */
1765 /* Windows startup ? */
1766 BX_reg(context
) = INT21_GetCurrentPSP();
1769 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1770 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1773 lol
= INT21_GetListOfLists();
1774 ES_reg(context
) = HIWORD(lol
);
1775 BX_reg(context
) = LOWORD(lol
);
1779 case 0x56: /* "RENAME" - RENAME FILE */
1780 TRACE(int21
,"RENAME %s to %s\n",
1781 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1782 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1783 bSetDOSExtendedError
=
1784 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1785 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1788 case 0x57: /* FILE DATE AND TIME */
1789 switch (AL_reg(context
))
1791 case 0x00: /* Get */
1794 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1796 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context
)), NULL
, NULL
, &filetime
))
1797 bSetDOSExtendedError
= TRUE
;
1798 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1803 case 0x01: /* Set */
1806 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1808 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1810 bSetDOSExtendedError
=
1811 (!SetFileTime( HFILE16_TO_HFILE32(BX_reg(context
)),
1812 NULL
, NULL
, &filetime
));
1818 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1819 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1821 switch (AL_reg(context
))
1824 AX_reg(context
) = 1;
1827 AX_reg(context
) = 0;
1833 RESET_CFLAG(context
);
1836 case 0x5a: /* CREATE TEMPORARY FILE */
1837 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1838 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1841 case 0x5b: /* CREATE NEW FILE */
1842 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1843 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1844 bSetDOSExtendedError
= ((AX_reg(context
) =
1845 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)), 0 )))
1846 == (WORD
)HFILE_ERROR16
);
1849 case 0x5d: /* NETWORK */
1850 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1851 /* Fix the following while you're at it. */
1852 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1853 bSetDOSExtendedError
= TRUE
;
1857 bSetDOSExtendedError
= INT21_networkfunc (context
);
1860 case 0x5f: /* NETWORK */
1861 switch (AL_reg(context
))
1863 case 0x07: /* ENABLE DRIVE */
1864 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1865 if (!DRIVE_Enable( DL_reg(context
) ))
1867 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1868 bSetDOSExtendedError
= TRUE
;
1872 case 0x08: /* DISABLE DRIVE */
1873 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1874 if (!DRIVE_Disable( DL_reg(context
) ))
1876 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1877 bSetDOSExtendedError
= TRUE
;
1882 /* network software not installed */
1883 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1884 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1885 bSetDOSExtendedError
= TRUE
;
1890 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1891 TRACE(int21
,"TRUENAME %s\n",
1892 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
1894 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1895 ESI_reg(context
)), 128,
1896 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1897 EDI_reg(context
)),NULL
))
1898 bSetDOSExtendedError
= TRUE
;
1899 else AX_reg(context
) = 0;
1903 case 0x61: /* UNUSED */
1904 case 0x63: /* misc. language support */
1905 switch (AL_reg(context
)) {
1906 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1907 INT21_GetDBCSLeadTable(context
);
1911 case 0x64: /* OS/2 DOS BOX */
1912 INT_BARF( context
, 0x21 );
1916 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1917 extern WORD WINE_LanguageId
;
1918 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
1919 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1920 BX_reg(context
), DX_reg(context
));
1921 switch (AL_reg(context
)) {
1923 TRACE(int21
,"\tget general internationalization info\n");
1925 *(WORD
*)(dataptr
+1) = 41;
1926 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1927 *(WORD
*)(dataptr
+5) = CodePage
;
1928 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
1931 TRACE(int21
,"\tget pointer to collating sequence table\n");
1933 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1934 CX_reg(context
) = 258;/*FIXME: size of table?*/
1937 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1938 INT_BARF( context
, 0x21 );
1944 case 0x66: /* GLOBAL CODE PAGE TABLE */
1945 switch (AL_reg(context
))
1948 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
1949 DX_reg(context
) = BX_reg(context
) = CodePage
;
1950 RESET_CFLAG(context
);
1953 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1954 BX_reg(context
),DX_reg(context
));
1955 CodePage
= BX_reg(context
);
1956 RESET_CFLAG(context
);
1961 case 0x67: /* SET HANDLE COUNT */
1962 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
1963 SetHandleCount16( BX_reg(context
) );
1964 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1967 case 0x68: /* "FFLUSH" - COMMIT FILE */
1968 case 0x6a: /* COMMIT FILE */
1969 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
1970 bSetDOSExtendedError
= (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context
)) ));
1973 case 0x69: /* DISK SERIAL NUMBER */
1974 switch (AL_reg(context
))
1977 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
1978 INT21_DriveName(BL_reg(context
)));
1979 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1980 else AX_reg(context
) = 0;
1984 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
1985 INT21_DriveName(BL_reg(context
)));
1986 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1987 else AX_reg(context
) = 1;
1992 case 0x6C: /* Extended Open/Create*/
1993 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
1994 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
1995 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1998 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1999 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
2000 /* not supported on anything but Win95 */
2001 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
2003 AL_reg(context
) = 0;
2005 switch(AL_reg(context
))
2007 case 0x39: /* Create directory */
2008 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
2009 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2010 bSetDOSExtendedError
= (!CreateDirectory32A(
2011 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2012 EDX_reg(context
) ), NULL
));
2014 case 0x3a: /* Remove directory */
2015 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2016 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2017 bSetDOSExtendedError
= (!RemoveDirectory32A(
2018 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2019 EDX_reg(context
) )));
2021 case 0x43: /* Get/Set file attributes */
2022 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2023 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2024 switch (BL_reg(context
))
2026 case 0x00: /* Get file attributes */
2027 TRACE(int21
,"\tretrieve attributes\n");
2028 CX_reg(context
) = (WORD
)GetFileAttributes32A(
2029 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2031 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2034 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
2035 bSetDOSExtendedError
= (!SetFileAttributes32A(
2036 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2038 CX_reg(context
) ) );
2041 FIXME(int21
, "Unimplemented long file name function:\n");
2042 INT_BARF( context
, 0x21 );
2044 AL_reg(context
) = 0;
2048 case 0x47: /* Get current directory */
2049 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2050 INT21_DriveName(DL_reg(context
)));
2051 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2054 case 0x4e: /* Find first file */
2055 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2056 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2057 /* FIXME: use attributes in CX */
2058 if ((AX_reg(context
) = FindFirstFile16(
2059 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2060 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2062 == INVALID_HANDLE_VALUE16
)
2063 bSetDOSExtendedError
= TRUE
;
2065 case 0x4f: /* Find next file */
2066 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2068 if (!FindNextFile16( BX_reg(context
),
2069 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2071 bSetDOSExtendedError
= TRUE
;
2073 case 0xa1: /* Find close */
2074 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2076 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2079 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2080 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2083 switch(CL_reg(context
))
2085 case 0x01: /*Get short filename or path */
2086 if (!GetShortPathName32A
2087 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2089 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2090 EDI_reg(context
)), 67))
2091 bSetDOSExtendedError
= TRUE
;
2092 else AX_reg(context
) = 0;
2094 case 0x02: /*Get canonical long filename or path */
2095 if (!GetFullPathName32A
2096 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2097 ESI_reg(context
)), 128,
2098 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2099 EDI_reg(context
)),NULL
))
2100 bSetDOSExtendedError
= TRUE
;
2101 else AX_reg(context
) = 0;
2104 FIXME(int21
, "Unimplemented long file name function:\n");
2105 INT_BARF( context
, 0x21 );
2107 AL_reg(context
) = 0;
2111 case 0x6c: /* Create or open file */
2112 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2113 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2114 /* translate Dos 7 action to Dos 6 action */
2115 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2118 case 0x3b: /* Change directory */
2119 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2120 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2121 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context
,
2127 AL_reg(context
) = DOS_ExtendedError
;
2130 case 0x41: /* Delete file */
2131 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2132 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2133 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context
,
2138 AL_reg(context
) = DOS_ExtendedError
;
2141 case 0x56: /* Move (rename) file */
2142 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2143 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2144 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2146 FIXME(int21
, "Unimplemented long file name function:\n");
2147 INT_BARF( context
, 0x21 );
2149 AL_reg(context
) = 0;
2154 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2155 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2156 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2157 TRACE(int21
,"windows95 function AX %04x\n",
2159 WARN(int21
, " returning unimplemented\n");
2161 AL_reg(context
) = 0;
2164 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2165 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2169 INT_BARF( context
, 0x21 );
2172 } /* END OF SWITCH */
2174 if( bSetDOSExtendedError
) /* set general error condition */
2176 AX_reg(context
) = DOS_ExtendedError
;
2180 if ((EFL_reg(context
) & 0x0001))
2181 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2182 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
2184 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2185 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2186 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2187 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2188 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2192 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
2194 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT32
)DosProc
);