2 * (c) 1993, 1994 Erik Bos
14 #include <sys/types.h>
21 #include "registers.h"
27 /* #define DEBUG_INT */
30 /* Define the drive parameter block, as used by int21/1F
31 * and int21/32. This table can be accessed through the
32 * global 'dpb' pointer, which points into the local dos
37 BYTE drive_num
; /* 0=A, etc. */
38 BYTE unit_num
; /* Drive's unit number (?) */
39 WORD sector_size
; /* Sector size in bytes */
40 BYTE high_sector
; /* Highest sector in a cluster */
41 BYTE shift
; /* Shift count (?) */
42 WORD reserved
; /* Number of reserved sectors at start */
43 BYTE num_FAT
; /* Number of FATs */
44 WORD dir_entries
; /* Number of root dir entries */
45 WORD first_data
; /* First data sector */
46 WORD high_cluster
; /* Highest cluster number */
47 WORD sectors_in_FAT
; /* Number of sectors per FAT */
48 WORD start_dir
; /* Starting sector of first dir */
49 DWORD driver_head
; /* Address of device driver header (?) */
50 BYTE media_ID
; /* Media ID */
51 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
52 DWORD next
; /* Pointer to next DPB in list */
53 WORD free_search
; /* Free cluster search start */
54 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
57 WORD ExtendedError
, CodePage
= 437;
58 BYTE ErrorClass
, Action
, ErrorLocus
;
68 static struct DosHeap
*heap
;
69 static WORD DosHeapHandle
;
71 WORD sharing_retries
= 3; /* number of retries at sharing violation */
72 WORD sharing_pause
= 1; /* pause between retries */
74 extern char TempDirectory
[];
76 static int Error(int e
, int class, int el
)
79 Action
= SA_Ask4Retry
;
86 void errno_to_doserr(void)
90 Error (ShareViolation
, EC_Temporary
, EL_Unknown
);
93 Error (InvalidHandle
, EC_AppError
, EL_Unknown
);
96 Error (DiskFull
, EC_MediaError
, EL_Disk
);
101 Error (WriteProtected
, EC_AccessDenied
, EL_Unknown
);
104 Error (LockViolation
, EC_AccessDenied
, EL_Unknown
);
107 Error (FileNotFound
, EC_NotFound
, EL_Unknown
);
110 Error (CanNotMakeDir
, EC_AccessDenied
, EL_Unknown
);
114 Error (NoMoreFiles
, EC_MediaError
, EL_Unknown
);
117 Error (FileExists
, EC_Exists
, EL_Disk
);
120 dprintf_int(stddeb
, "int21: unknown errno %d!\n", errno
);
121 Error (GeneralFailure
, EC_SystemFailure
, EL_Unknown
);
126 BYTE
*GetCurrentDTA(void)
128 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
129 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
133 void ChopOffWhiteSpace(char *string
)
137 for (length
= strlen(string
) ; length
; length
--)
138 if (string
[length
] == ' ')
139 string
[length
] = '\0';
142 static void CreateBPB(int drive
, BYTE
*data
)
147 setword(&data
[3], 0);
149 setword(&data
[6], 240);
150 setword(&data
[8], 64000);
152 setword(&data
[0x0b], 40);
153 setword(&data
[0x0d], 56);
154 setword(&data
[0x0f], 2);
155 setword(&data
[0x11], 0);
156 setword(&data
[0x1f], 800);
158 setword(&data
[0x22], 1);
159 } else { /* 1.44mb */
162 setword(&data
[3], 0);
164 setword(&data
[6], 240);
165 setword(&data
[8], 2880);
167 setword(&data
[0x0b], 6);
168 setword(&data
[0x0d], 18);
169 setword(&data
[0x0f], 2);
170 setword(&data
[0x11], 0);
171 setword(&data
[0x1f], 80);
173 setword(&data
[0x22], 2);
177 static void GetFreeDiskSpace(struct sigcontext_struct
*context
)
183 drive
= DOS_GetDefaultDrive();
187 if (!DOS_ValidDrive(drive
)) {
188 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
193 if (!DOS_GetFreeSpace(drive
, &size
, &available
)) {
194 Error(GeneralFailure
, EC_MediaError
, EL_Disk
);
202 BX
= (available
/ (CX
* AX
));
203 DX
= (size
/ (CX
* AX
));
207 static void GetDriveAllocInfo(struct sigcontext_struct
*context
)
209 long size
, available
;
211 if (!DOS_ValidDrive(DL
)) {
215 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
219 if (!DOS_GetFreeSpace(DL
, &size
, &available
)) {
220 Error(GeneralFailure
, EC_MediaError
, EL_Disk
);
227 EDX
= (size
/ (CX
* AX
));
229 heap
->mediaID
= 0xf0;
232 BX
= (int)&heap
->mediaID
- (int)heap
;
236 static void GetDefDriveAllocInfo(struct sigcontext_struct
*context
)
238 DX
= DOS_GetDefaultDrive();
239 GetDriveAllocInfo(context
);
242 static void GetDrivePB(struct sigcontext_struct
*context
, int drive
)
244 if(!DOS_ValidDrive(drive
))
246 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
251 dprintf_int(stddeb
, "int21: GetDrivePB not fully implemented.\n");
253 /* FIXME: I have no idea what a lot of this information should
254 * say or whether it even really matters since we're not allowing
255 * direct block access. However, some programs seem to depend on
256 * getting at least _something_ back from here. The 'next' pointer
257 * does worry me, though. Should we have a complete table of
258 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
260 dpb
->drive_num
= dpb
->unit_num
= drive
; /* The same? */
261 dpb
->sector_size
= 512;
262 dpb
->high_sector
= 1;
266 dpb
->dir_entries
= 2;
268 dpb
->high_cluster
= 1023;
269 dpb
->sectors_in_FAT
= 1;
271 dpb
->driver_head
= 0;
272 dpb
->media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
273 dpb
->access_flag
= 0;
275 dpb
->free_search
= 0;
276 dpb
->free_clusters
= 0xFFFF; /* unknown */
279 DS
= SELECTOROF(dpbsegptr
);
280 BX
= OFFSETOF(dpbsegptr
);
284 static void ReadFile(struct sigcontext_struct
*context
)
289 /* can't read from stdout / stderr */
290 if ((BX
== 1) || (BX
== 2)) {
291 Error (InvalidHandle
, EL_Unknown
, EC_Unknown
);
297 ptr
= PTR_SEG_OFF_TO_LIN (DS
,DX
);
305 size
= read(BX
, ptr
, CX
);
318 static void WriteFile(struct sigcontext_struct
*context
)
323 ptr
= PTR_SEG_OFF_TO_LIN (DS
,DX
);
326 Error (InvalidHandle
, EC_Unknown
, EL_Unknown
);
333 for (x
= 0;x
!= CX
;x
++) {
334 dprintf_int(stddeb
, "%c", *ptr
++);
342 size
= write(BX
, ptr
, CX
);
344 Error (WriteFault
, EC_Unknown
, EL_Unknown
);
361 static void SeekFile(struct sigcontext_struct
*context
)
363 off_t status
, fileoffset
;
366 case 1: fileoffset
= SEEK_CUR
;
368 case 2: fileoffset
= SEEK_END
;
371 case 0: fileoffset
= SEEK_SET
;
374 status
= lseek(BX
, (CX
<< 16) + DX
, fileoffset
);
377 AL
= ExtendedError
; SetCflag
;
381 AX
= (status
& 0xffff);
382 DX
= ((status
>> 16) & 0xffff);
387 static void ioctlGetDeviceInfo(struct sigcontext_struct
*context
)
393 DX
= 0x80d0 + (1 << BX
);
401 if (fstat(BX
, &sbuf
) < 0)
403 IntBarf(0x21, context
);
409 /* This isn't the right answer, but should be close enough. */
416 static void ioctlGenericBlkDevReq(struct sigcontext_struct
*context
)
418 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
422 drive
= DOS_GetDefaultDrive();
426 if (!DOS_ValidDrive(drive
)) {
433 IntBarf(0x21, context
);
437 case 0x60: /* get device parameters */
438 /* used by w4wgrp's winfile */
439 memset(dataptr
, 0, 0x26);
441 dataptr
[6] = 0; /* media type */
444 dataptr
[1] = 0x05; /* fixed disk */
445 setword(&dataptr
[2], 0x01); /* non removable */
446 setword(&dataptr
[4], 0x300); /* # of cylinders */
450 dataptr
[1] = 0x07; /* block dev, floppy */
451 setword(&dataptr
[2], 0x02); /* removable */
452 setword(&dataptr
[4], 80); /* # of cylinders */
454 CreateBPB(drive
, &dataptr
[7]);
458 IntBarf(0x21, context
);
462 static void GetSystemDate(struct sigcontext_struct
*context
)
468 now
= localtime(<ime
);
470 CX
= now
->tm_year
+ 1900;
471 DX
= ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
475 static void GetSystemTime(struct sigcontext_struct
*context
)
480 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
481 now
= localtime(&tv
.tv_sec
);
483 CX
= (now
->tm_hour
<<8) | now
->tm_min
;
484 DX
= (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
485 /* Note hundredths of seconds */
488 static void GetExtendedErrorInfo(struct sigcontext_struct
*context
)
491 BX
= (ErrorClass
<< 8) | Action
;
492 CH
= ErrorLocus
<< 8;
495 static void CreateFile(struct sigcontext_struct
*context
)
499 if ((handle
= open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
)),
500 O_CREAT
| O_TRUNC
| O_RDWR
)) == -1) {
507 EAX
= (EAX
& 0xffff0000) | handle
;
511 void OpenExistingFile(struct sigcontext_struct
*context
)
532 if ((handle
= open(DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS
,DX
)),
535 if( Options
.allowReadOnly
)
536 handle
= open( DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS
,DX
)),
549 case 0x00: /* compatability mode */
550 case 0x40: /* DENYNONE */
554 case 0x30: /* DENYREAD */
556 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
557 (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
));
558 case 0x10: /* DENYALL */
562 case 0x20: /* DENYWRITE */
573 int result
,retries
=sharing_retries
;
575 result
= flock(handle
, lock
| LOCK_NB
);
576 if ( retries
&& (!result
) )
579 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
580 result
++; /* stop the optimizer */
581 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
585 while( (!result
) && (!(retries
--)) );
590 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
599 EAX
= (EAX
& 0xffff0000) | handle
;
603 static void CloseFile(struct sigcontext_struct
*context
)
605 if (close(BX
) == -1) {
616 static void RenameFile(struct sigcontext_struct
*context
)
618 char *newname
, *oldname
;
620 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
621 (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
), (char *)PTR_SEG_OFF_TO_LIN(ES
,DI
) );
623 oldname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) );
624 newname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES
,DI
) );
626 rename( oldname
, newname
);
631 static void MakeDir(struct sigcontext_struct
*context
)
635 dprintf_int(stddeb
,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
) );
637 if ((dirname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) ))== NULL
) {
643 if (mkdir(dirname
,0) == -1) {
651 static void ChangeDir(struct sigcontext_struct
*context
)
654 char *dirname
= PTR_SEG_OFF_TO_LIN(DS
,DX
);
655 drive
= DOS_GetDefaultDrive();
656 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
657 if (dirname
!= NULL
&& dirname
[1] == ':') {
658 drive
= toupper(dirname
[0]) - 'A';
661 if (!DOS_ChangeDir(drive
, dirname
))
668 static void RemoveDir(struct sigcontext_struct
*context
)
672 dprintf_int(stddeb
,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
) );
674 if ((dirname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) ))== NULL
) {
681 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
682 AL = CanNotRemoveCwd;
686 if (rmdir(dirname
) == -1) {
693 static void ExecProgram(struct sigcontext_struct
*context
)
695 execl("wine", DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
)) );
698 static void FindNext(struct sigcontext_struct
*context
)
700 struct dosdirent
*dp
;
702 BYTE
*dta
= GetCurrentDTA();
704 memcpy(&dp
, dta
+0x11, sizeof(dp
));
707 if ((dp
= DOS_readdir(dp
)) == NULL
) {
708 Error(NoMoreFiles
, EC_MediaError
, EL_Disk
);
713 } /* while (*(dta + 0x0c) != dp->attribute);*/
714 while ( ( dp
->search_attribute
& dp
->attribute
) != dp
->attribute
);
716 *(dta
+ 0x15) = dp
->attribute
;
717 setword(&dta
[0x0d], dp
->entnum
);
719 t
= localtime(&(dp
->filetime
));
720 setword(&dta
[0x16], (t
->tm_hour
<< 11) + (t
->tm_min
<< 5) +
721 (t
->tm_sec
/ 2)); /* time */
722 setword(&dta
[0x18], ((t
->tm_year
- 80) << 9) + (t
->tm_mon
<< 5) +
723 (t
->tm_mday
)); /* date */
724 setdword(&dta
[0x1a], dp
->filesize
);
725 strncpy(dta
+ 0x1e, dp
->filename
, 13);
730 dprintf_int(stddeb
, "int21: FindNext -- (%s) index=%d size=%ld\n", dp
->filename
, dp
->entnum
, dp
->filesize
);
734 static void FindFirst(struct sigcontext_struct
*context
)
736 BYTE drive
, *path
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
737 struct dosdirent
*dp
;
739 BYTE
*dta
= GetCurrentDTA();
741 dprintf_int(stddeb
, "int21: FindFirst path = %s\n", path
);
743 if ((*path
)&&(path
[1] == ':')) {
744 drive
= (islower(*path
) ? toupper(*path
) : *path
) - 'A';
746 if (!DOS_ValidDrive(drive
)) {
747 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
753 drive
= DOS_GetDefaultDrive();
756 memset(dta
+ 1 , '?', 11);
757 *(dta
+ 0x0c) = ECX
& (FA_LABEL
| FA_DIREC
);
759 if (ECX
& FA_LABEL
) {
760 /* return volume label */
762 if (DOS_GetVolumeLabel(drive
) != NULL
)
763 strncpy(dta
+ 0x1e, DOS_GetVolumeLabel(drive
), 8);
770 if ((dp
= DOS_opendir(path
)) == NULL
) {
771 Error(PathNotFound
, EC_MediaError
, EL_Disk
);
777 dp
->search_attribute
= ECX
& (FA_LABEL
| FA_DIREC
);
778 memcpy(dta
+ 0x11, &dp
, sizeof(dp
));
782 static void GetFileDateTime(struct sigcontext_struct
*context
)
784 struct stat filestat
;
787 fstat( BX
, &filestat
);
788 now
= localtime (&filestat
.st_mtime
);
790 CX
= ((now
->tm_hour
* 0x2000) + (now
->tm_min
* 0x20) + now
->tm_sec
/2);
791 DX
= ((now
->tm_year
* 0x200) + (now
->tm_mon
* 0x20) + now
->tm_mday
);
796 static void SetFileDateTime(struct sigcontext_struct
*context
)
799 struct utimbuf filetime
;
801 /* FIXME: Argument isn't the name of the file in DS:DX,
802 but the file handle in BX */
803 filename
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) );
805 filetime
.actime
= 0L;
806 filetime
.modtime
= filetime
.actime
;
808 utime(filename
, &filetime
);
812 static void CreateTempFile(struct sigcontext_struct
*context
)
817 sprintf(temp
,"%s\\win%d.tmp",TempDirectory
,(int) getpid());
819 dprintf_int(stddeb
,"CreateTempFile %s\n",temp
);
821 handle
= open(DOS_GetUnixFileName(temp
), O_CREAT
| O_TRUNC
| O_RDWR
);
829 strcpy(PTR_SEG_OFF_TO_LIN(DS
,DX
), temp
);
835 static void CreateNewFile(struct sigcontext_struct
*context
)
839 if ((handle
= open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) ), O_CREAT
| O_EXCL
| O_RDWR
)) == -1) {
849 static void GetCurrentDirectory(struct sigcontext_struct
*context
)
854 drive
= DOS_GetDefaultDrive();
858 if (!DOS_ValidDrive(drive
)) {
864 strcpy(PTR_SEG_OFF_TO_LIN(DS
,SI
), DOS_GetCurrentDir(drive
) );
868 static void GetDiskSerialNumber(struct sigcontext_struct
*context
)
871 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
875 drive
= DOS_GetDefaultDrive();
879 if (!DOS_ValidDrive(drive
)) {
885 DOS_GetSerialNumber(drive
, &serialnumber
);
888 setdword(&dataptr
[2], serialnumber
);
889 strncpy(dataptr
+ 6, DOS_GetVolumeLabel(drive
), 8);
890 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
896 static void SetDiskSerialNumber(struct sigcontext_struct
*context
)
899 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
903 drive
= DOS_GetDefaultDrive();
907 if (!DOS_ValidDrive(drive
)) {
913 serialnumber
= dataptr
[1] + (dataptr
[2] << 8) + (dataptr
[3] << 16) +
916 DOS_SetSerialNumber(drive
, serialnumber
);
921 static void DumpFCB(BYTE
*fcb
)
927 for (y
= 0; y
!=2 ; y
++) {
928 for (x
= 0; x
!=15;x
++)
929 dprintf_int(stddeb
, "%02x ", *fcb
++);
930 dprintf_int(stddeb
,"\n");
934 /* microsoft's programmers should be shot for using CP/M style int21
935 calls in Windows for Workgroup's winfile.exe */
937 static void FindFirstFCB(struct sigcontext_struct
*context
)
939 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
940 struct fcb
*standard_fcb
;
941 struct fcb
*output_fcb
;
945 BYTE
*dta
= GetCurrentDTA();
951 standard_fcb
= (struct fcb
*)(fcb
+ 7);
952 output_fcb
= (struct fcb
*)(dta
+ 7);
957 standard_fcb
= (struct fcb
*)fcb
;
958 output_fcb
= (struct fcb
*)dta
;
961 if (standard_fcb
->drive
)
963 drive
= standard_fcb
->drive
- 1;
964 if (!DOS_ValidDrive(drive
))
966 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
972 drive
= DOS_GetDefaultDrive();
974 output_fcb
->drive
= drive
;
978 if (*(fcb
+6) & FA_LABEL
) /* return volume label */
981 memset(&output_fcb
->name
, ' ', 11);
982 if (DOS_GetVolumeLabel(drive
) != NULL
)
984 strncpy(output_fcb
->name
, DOS_GetVolumeLabel(drive
), 11);
991 strncpy(output_fcb
->name
, standard_fcb
->name
, 11);
993 *(dta
+6) = ( *(fcb
+6) & (!FA_DIREC
));
995 sprintf(path
,"%c:*.*",drive
+'A');
996 if ((output_fcb
->directory
= DOS_opendir(path
))==NULL
)
998 Error (PathNotFound
, EC_MediaError
, EL_Disk
);
1006 static void DeleteFileFCB(struct sigcontext_struct
*context
)
1008 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
1010 struct dosdirent
*dp
;
1011 char temp
[256], *ptr
;
1018 drive
= DOS_GetDefaultDrive();
1020 strcpy(temp
, DOS_GetCurrentDir(drive
));
1022 strncat(temp
, fcb
+ 1, 8);
1023 ChopOffWhiteSpace(temp
);
1024 strncat(temp
, fcb
+ 9, 3);
1025 ChopOffWhiteSpace(temp
);
1027 if ((dp
= DOS_opendir(temp
)) == NULL
) {
1028 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1033 strcpy(temp
, DOS_GetCurrentDir(drive
) );
1036 ptr
= temp
+ strlen(temp
);
1038 while (DOS_readdir(dp
) != NULL
)
1040 strcpy(ptr
, dp
->filename
);
1041 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
1042 /* unlink(DOS_GetUnixFileName(temp)); */
1048 static void RenameFileFCB(struct sigcontext_struct
*context
)
1050 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
1052 struct dosdirent
*dp
;
1053 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
1060 drive
= DOS_GetDefaultDrive();
1062 strcpy(temp
, DOS_GetCurrentDir(drive
));
1064 strncat(temp
, fcb
+ 1, 8);
1065 ChopOffWhiteSpace(temp
);
1066 strncat(temp
, fcb
+ 9, 3);
1067 ChopOffWhiteSpace(temp
);
1069 if ((dp
= DOS_opendir(temp
)) == NULL
) {
1070 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1075 strcpy(oldname
, DOS_GetCurrentDir(drive
) );
1076 strcat(oldname
, "\\");
1077 oldnameptr
= oldname
+ strlen(oldname
);
1079 strcpy(newname
, DOS_GetCurrentDir(drive
) );
1080 strcat(newname
, "\\");
1081 newnameptr
= newname
+ strlen(newname
);
1083 while (DOS_readdir(dp
) != NULL
)
1085 strcpy(oldnameptr
, dp
->filename
);
1086 strcpy(newnameptr
, fcb
+ 1);
1087 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
1096 static void fLock (struct sigcontext_struct
* context
)
1099 int result
,retries
=sharing_retries
;
1101 f
.l_start
= MAKELONG(DX
,CX
);
1102 f
.l_len
= MAKELONG(DI
,SI
);
1106 switch ( AX
& 0xff )
1108 case 0x00: /* LOCK */
1112 case 0x01: /* UNLOCK */
1117 EAX
= (EAX
& 0xffff0000) | 0x0001;
1123 result
= fcntl(BX
,F_SETLK
,&f
);
1124 if ( retries
&& (!result
) )
1127 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1128 result
++; /* stop the optimizer */
1129 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1133 while( (!result
) && (!(retries
--)) );
1138 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
1148 static void GetFileAttribute (struct sigcontext_struct
* context
)
1150 char *filename
= PTR_SEG_OFF_TO_LIN (DS
,DX
);
1154 res
= stat(DOS_GetUnixFileName(filename
), &s
);
1158 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
1164 if (S_ISDIR(s
.st_mode
))
1166 if ((S_IWRITE
& s
.st_mode
) != S_IWRITE
)
1169 ECX
= (ECX
& 0xffff0000) | cx
;
1176 /************************************************************************/
1178 int do_int21(struct sigcontext_struct
* context
)
1182 dprintf_int(stddeb
,"int21: AX %04x, BX %04x, CX %04x, DX %04x, "
1183 "SI %04x, DI %04x, DS %04x, ES %04x\n",
1184 AX
, BX
, CX
, DX
, SI
, DI
, DS
, ES
);
1188 GetExtendedErrorInfo(context
);
1196 case 0x00: /* TERMINATE PROGRAM */
1197 TASK_KillCurrentTask( 0 );
1200 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1201 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1202 case 0x03: /* READ CHARACTER FROM STDAUX */
1203 case 0x04: /* WRITE CHARACTER TO STDAUX */
1204 case 0x05: /* WRITE CHARACTER TO PRINTER */
1205 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1206 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1207 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1208 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1209 case 0x0a: /* BUFFERED INPUT */
1210 case 0x0b: /* GET STDIN STATUS */
1211 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1212 case 0x0f: /* OPEN FILE USING FCB */
1213 case 0x10: /* CLOSE FILE USING FCB */
1214 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1215 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1216 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1217 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1218 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1219 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1220 case 0x23: /* GET FILE SIZE FOR FCB */
1221 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1222 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1223 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1224 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1225 case 0x29: /* PARSE FILENAME INTO FCB */
1226 case 0x2e: /* SET VERIFY FLAG */
1227 IntBarf(0x21, context
);
1230 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1234 case 0x2b: /* SET SYSTEM DATE */
1235 case 0x2d: /* SET SYSTEM TIME */
1236 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1237 "SWITCHAR" - SET SWITCH CHARACTER
1238 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1239 case 0x54: /* GET VERIFY FLAG */
1240 case 0x6b: /* NULL FUNCTION */
1241 IntBarf(0x21, context
);
1245 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1249 case 0x0d: /* DISK BUFFER FLUSH */
1250 ResetCflag
; /* dos 6+ only */
1253 case 0x0e: /* SELECT DEFAULT DRIVE */
1254 if (!DOS_ValidDrive(DL
)) {
1255 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
1258 DOS_SetDefaultDrive(DL
);
1259 AX
= MAX_DOS_DRIVES
;
1264 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1265 FindFirstFCB(context
);
1268 case 0x13: /* DELETE FILE USING FCB */
1269 DeleteFileFCB(context
);
1272 case 0x17: /* RENAME FILE USING FCB */
1273 RenameFileFCB(context
);
1276 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1277 AL
= DOS_GetDefaultDrive();
1281 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1283 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1284 pTask
->dta
= MAKELONG( DX
, DS
);
1288 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1289 GetDefDriveAllocInfo(context
);
1292 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1293 GetDriveAllocInfo(context
);
1296 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1297 GetDrivePB(context
, DOS_GetDefaultDrive());
1300 case 0x25: /* SET INTERRUPT VECTOR */
1301 /* Ignore any attempt to set a segment vector */
1303 "int21: set interrupt vector %2x (%04x:%04x)\n",
1307 case 0x2a: /* GET SYSTEM DATE */
1308 GetSystemDate(context
);
1311 case 0x2c: /* GET SYSTEM TIME */
1312 GetSystemTime(context
);
1315 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1317 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1318 ES
= SELECTOROF( pTask
->dta
);
1319 BX
= OFFSETOF( pTask
->dta
);
1323 case 0x30: /* GET DOS VERSION */
1325 BX
= 0x0012; /* 0x123456 is Wine's serial # */
1329 case 0x31: /* TERMINATE AND STAY RESIDENT */
1330 IntBarf(0x21, context
);
1333 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1334 GetDrivePB(context
, (DL
== 0) ? (DOS_GetDefaultDrive()) : (DL
-1));
1337 case 0x33: /* MULTIPLEXED */
1339 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1344 case 0x01: /* SET EXTENDED BREAK STATE */
1347 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1351 case 0x05: /* GET BOOT DRIVE */
1353 /* c: is Wine's bootdrive */
1356 case 0x06: /* GET TRUE VERSION NUMBER */
1362 IntBarf(0x21, context
);
1367 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1369 BX
= (int)&heap
->InDosFlag
- (int)heap
;
1372 case 0x35: /* GET INTERRUPT VECTOR */
1373 /* Return a NULL segment selector - this will bomb,
1374 if anyone ever tries to use it */
1375 dprintf_int(stddeb
, "int21: get interrupt vector %2x\n",
1381 case 0x36: /* GET FREE DISK SPACE */
1382 GetFreeDiskSpace(context
);
1385 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1386 AX
= 0x02; /* no country support available */
1390 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1394 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1398 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1402 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1403 CreateFile(context
);
1406 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1407 OpenExistingFile(context
);
1410 case 0x3e: /* "CLOSE" - CLOSE FILE */
1414 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1418 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1422 case 0x41: /* "UNLINK" - DELETE FILE */
1423 if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
)) ) == -1) {
1433 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1437 case 0x43: /* FILE ATTRIBUTES */
1441 GetFileAttribute(context
);
1449 case 0x44: /* IOCTL */
1453 ioctlGetDeviceInfo(context
);
1456 case 0x08: /* Check if drive is removable. */
1457 drive
= BL
? (BL
- 1) : DOS_GetDefaultDrive();
1458 if(!DOS_ValidDrive(drive
))
1461 AX
= 0x000F; /* Bad drive number */
1466 EAX
= (EAX
& 0xFFFF0000) | 0x0001; /* not removable */
1468 EAX
= (EAX
& 0xFFFF0000); /* removable */
1473 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1474 drive
= BL
? (BL
- 1) : DOS_GetDefaultDrive();
1475 if(!DOS_ValidDrive(drive
))
1478 AX
= 0x000F; /* Bad drive number */
1482 EDX
= (EDX
& 0xffff0000) | (1<<9) | (1<<12) | (1<<15);
1487 case 0x0b: /* SET SHARING RETRY COUNT */
1490 EAX
= (EAX
& 0xffff0000) | 0x0001;
1496 sharing_retries
= DX
;
1501 ioctlGenericBlkDevReq(context
);
1504 case 0x0F: /* Set logical drive mapping */
1505 /* FIXME: Not implemented at the moment, always returns error
1507 EAX
= (EAX
& 0xFFFF0000) | 0x0001; /* invalid function */
1512 IntBarf(0x21, context
);
1517 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1518 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1523 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1524 GetCurrentDirectory(context
);
1526 /* intlist: many Microsoft products for Windows rely on this */
1529 case 0x48: /* ALLOCATE MEMORY */
1530 case 0x49: /* FREE MEMORY */
1531 case 0x4a: /* RESIZE MEMORY BLOCK */
1532 IntBarf(0x21, context
);
1535 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1536 ExecProgram(context
);
1539 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1540 TASK_KillCurrentTask( AL
);
1543 case 0x4d: /* GET RETURN CODE */
1544 AL
= NoError
; /* normal exit */
1547 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1551 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1555 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1558 IntBarf(0x21, context
);
1561 case 0x56: /* "RENAME" - RENAME FILE */
1562 RenameFile(context
);
1565 case 0x57: /* FILE DATE AND TIME */
1569 GetFileDateTime(context
);
1572 SetFileDateTime(context
);
1577 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1593 case 0x5a: /* CREATE TEMPORARY FILE */
1594 CreateTempFile(context
);
1597 case 0x5b: /* CREATE NEW FILE */
1598 CreateNewFile(context
);
1601 case 0x5d: /* NETWORK */
1603 /* network software not installed */
1608 case 0x5f: /* NETWORK */
1611 case 0x07: /* ENABLE DRIVE */
1612 if (!DOS_EnableDrive(DL
))
1614 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1624 case 0x08: /* DISABLE DRIVE */
1625 if (!DOS_DisableDrive(DL
))
1627 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1638 /* network software not installed */
1645 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1646 strncpy(PTR_SEG_OFF_TO_LIN(ES
,DI
), PTR_SEG_OFF_TO_LIN(DS
,SI
), strlen(PTR_SEG_OFF_TO_LIN(DS
,SI
)) & 0x7f);
1650 case 0x61: /* UNUSED */
1651 case 0x62: /* GET CURRENT PSP ADDRESS */
1652 case 0x63: /* UNUSED */
1653 case 0x64: /* OS/2 DOS BOX */
1654 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1655 IntBarf(0x21, context
);
1658 case 0x66: /* GLOBAL CODE PAGE TABLE */
1672 case 0x67: /* SET HANDLE COUNT */
1676 case 0x68: /* "FFLUSH" - COMMIT FILE */
1680 case 0x69: /* DISK SERIAL NUMBER */
1684 GetDiskSerialNumber(context
);
1687 SetDiskSerialNumber(context
);
1692 case 0x6a: /* COMMIT FILE */
1696 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1700 IntBarf(0x21, context
);
1707 /**********************************************************************
1710 void DOS3Call( struct sigcontext_struct context
)
1712 do_int21( &context
);
1715 void INT21_Init(void)
1717 if ((DosHeapHandle
= GlobalAlloc(GMEM_FIXED
,sizeof(struct DosHeap
))) == 0)
1719 fprintf( stderr
, "INT21_Init: Out of memory\n");
1722 heap
= (struct DosHeap
*) GlobalLock(DosHeapHandle
);
1725 dpbsegptr
= MAKELONG( (int)&heap
->dpb
- (int)heap
, DosHeapHandle
);
1726 heap
->InDosFlag
= 0;
1727 strcpy(heap
->biosdate
, "01/01/80");