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
);
295 "int21: read (%d, void *, 0x%x) = EBADF\n", BX
, CX
);
299 ptr
= PTR_SEG_OFF_TO_LIN (DS
,DX
);
306 "int21: read (%d, void *, 0x%x) = EOF\n", BX
, CX
);
309 size
= read(BX
, ptr
, CX
);
311 "int21: read (%d, void *, 0x%x) = 0x%x\n",
325 static void WriteFile(struct sigcontext_struct
*context
)
330 ptr
= PTR_SEG_OFF_TO_LIN (DS
,DX
);
333 Error (InvalidHandle
, EC_Unknown
, EL_Unknown
);
340 for (x
= 0;x
!= CX
;x
++) {
341 dprintf_int(stddeb
, "%c", *ptr
++);
349 size
= write(BX
, ptr
, CX
);
351 Error (WriteFault
, EC_Unknown
, EL_Unknown
);
368 static void SeekFile(struct sigcontext_struct
*context
)
370 off_t status
, fileoffset
;
373 case 1: fileoffset
= SEEK_CUR
;
375 case 2: fileoffset
= SEEK_END
;
378 case 0: fileoffset
= SEEK_SET
;
381 status
= lseek(BX
, (CX
<< 16) + DX
, fileoffset
);
383 dprintf_int (stddeb
, "int21: seek (%d, 0x%x, %d) = 0x%lx\n",
384 BX
, (CX
<< 16) + DX
, AL
, status
);
388 AL
= ExtendedError
; SetCflag
;
392 AX
= (status
& 0xffff);
393 DX
= ((status
>> 16) & 0xffff);
398 static void ioctlGetDeviceInfo(struct sigcontext_struct
*context
)
401 dprintf_int (stddeb
, "int21: ioctl (%d, GetDeviceInfo)\n", BX
);
407 DX
= 0x80d0 + (1 << BX
);
415 if (fstat(BX
, &sbuf
) < 0)
417 IntBarf(0x21, context
);
423 /* This isn't the right answer, but should be close enough. */
430 static void ioctlGenericBlkDevReq(struct sigcontext_struct
*context
)
432 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
436 drive
= DOS_GetDefaultDrive();
440 if (!DOS_ValidDrive(drive
)) {
447 IntBarf(0x21, context
);
451 case 0x60: /* get device parameters */
452 /* used by w4wgrp's winfile */
453 memset(dataptr
, 0, 0x26);
455 dataptr
[6] = 0; /* media type */
458 dataptr
[1] = 0x05; /* fixed disk */
459 setword(&dataptr
[2], 0x01); /* non removable */
460 setword(&dataptr
[4], 0x300); /* # of cylinders */
464 dataptr
[1] = 0x07; /* block dev, floppy */
465 setword(&dataptr
[2], 0x02); /* removable */
466 setword(&dataptr
[4], 80); /* # of cylinders */
468 CreateBPB(drive
, &dataptr
[7]);
472 IntBarf(0x21, context
);
476 static void GetSystemDate(struct sigcontext_struct
*context
)
482 now
= localtime(<ime
);
484 CX
= now
->tm_year
+ 1900 - 1980;
485 DX
= ((now
->tm_mon
+ 1) << 8) | now
->tm_mday
;
489 static void GetSystemTime(struct sigcontext_struct
*context
)
494 gettimeofday(&tv
,NULL
); /* Note use of gettimeofday(), instead of time() */
495 now
= localtime(&tv
.tv_sec
);
497 CX
= (now
->tm_hour
<<8) | now
->tm_min
;
498 DX
= (now
->tm_sec
<<8) | tv
.tv_usec
/10000;
499 /* Note hundredths of seconds */
502 static void GetExtendedErrorInfo(struct sigcontext_struct
*context
)
505 BX
= (ErrorClass
<< 8) | Action
;
506 CH
= ErrorLocus
<< 8;
509 static void CreateFile(struct sigcontext_struct
*context
)
513 if ((handle
= open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
)),
514 O_CREAT
| O_TRUNC
| O_RDWR
)) == -1) {
521 EAX
= (EAX
& 0xffff0000) | handle
;
525 void OpenExistingFile(struct sigcontext_struct
*context
)
546 if ((handle
= open(DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS
,DX
)),
549 if( Options
.allowReadOnly
)
550 handle
= open( DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS
,DX
)),
554 dprintf_int (stddeb
, "int21: open (%s, %d) = -1\n",
555 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS
,DX
)), mode
);
563 dprintf_int (stddeb
, "int21: open (%s, %d) = %d\n",
564 DOS_GetUnixFileName(PTR_SEG_OFF_TO_LIN(DS
,DX
)), mode
, handle
);
568 case 0x00: /* compatability mode */
569 case 0x40: /* DENYNONE */
573 case 0x30: /* DENYREAD */
575 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
576 (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
));
577 case 0x10: /* DENYALL */
581 case 0x20: /* DENYWRITE */
592 int result
,retries
=sharing_retries
;
594 result
= flock(handle
, lock
| LOCK_NB
);
595 if ( retries
&& (!result
) )
598 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
599 result
++; /* stop the optimizer */
600 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
604 while( (!result
) && (!(retries
--)) );
609 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
618 EAX
= (EAX
& 0xffff0000) | handle
;
622 static void CloseFile(struct sigcontext_struct
*context
)
624 dprintf_int (stddeb
, "int21: close (%d)\n", BX
);
626 if (close(BX
) == -1) {
637 static void RenameFile(struct sigcontext_struct
*context
)
639 char *newname
, *oldname
;
641 dprintf_int(stddeb
,"int21: renaming %s to %s\n",
642 (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
), (char *)PTR_SEG_OFF_TO_LIN(ES
,DI
) );
644 oldname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) );
645 newname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(ES
,DI
) );
647 rename( oldname
, newname
);
652 static void MakeDir(struct sigcontext_struct
*context
)
656 dprintf_int(stddeb
,"int21: makedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
) );
658 if ((dirname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) ))== NULL
) {
664 if (mkdir(dirname
,0) == -1) {
672 static void ChangeDir(struct sigcontext_struct
*context
)
675 char *dirname
= PTR_SEG_OFF_TO_LIN(DS
,DX
);
676 drive
= DOS_GetDefaultDrive();
677 dprintf_int(stddeb
,"int21: changedir %s\n", dirname
);
678 if (dirname
!= NULL
&& dirname
[1] == ':') {
679 drive
= toupper(dirname
[0]) - 'A';
682 if (!DOS_ChangeDir(drive
, dirname
))
689 static void RemoveDir(struct sigcontext_struct
*context
)
693 dprintf_int(stddeb
,"int21: removedir %s\n", (char *)PTR_SEG_OFF_TO_LIN(DS
,DX
) );
695 if ((dirname
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) ))== NULL
) {
702 if (strcmp(unixname,DosDrives[drive].CurrentDirectory)) {
703 AL = CanNotRemoveCwd;
707 if (rmdir(dirname
) == -1) {
714 static void ExecProgram(struct sigcontext_struct
*context
)
716 execl("wine", DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
)) );
719 static void FindNext(struct sigcontext_struct
*context
)
721 struct dosdirent
*dp
;
723 BYTE
*dta
= GetCurrentDTA();
725 memcpy(&dp
, dta
+0x11, sizeof(dp
));
728 if ((dp
= DOS_readdir(dp
)) == NULL
) {
729 Error(NoMoreFiles
, EC_MediaError
, EL_Disk
);
734 } /* while (*(dta + 0x0c) != dp->attribute);*/
735 while ( ( dp
->search_attribute
& dp
->attribute
) != dp
->attribute
);
737 *(dta
+ 0x15) = dp
->attribute
;
738 setword(&dta
[0x0d], dp
->entnum
);
740 t
= localtime(&(dp
->filetime
));
741 setword(&dta
[0x16], (t
->tm_hour
<< 11) + (t
->tm_min
<< 5) +
742 (t
->tm_sec
/ 2)); /* time */
743 setword(&dta
[0x18], ((t
->tm_year
- 80) << 9) + (t
->tm_mon
<< 5) +
744 (t
->tm_mday
)); /* date */
745 setdword(&dta
[0x1a], dp
->filesize
);
746 strncpy(dta
+ 0x1e, dp
->filename
, 13);
751 dprintf_int(stddeb
, "int21: FindNext -- (%s) index=%d size=%ld\n", dp
->filename
, dp
->entnum
, dp
->filesize
);
755 static void FindFirst(struct sigcontext_struct
*context
)
757 BYTE drive
, *path
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
758 struct dosdirent
*dp
;
760 BYTE
*dta
= GetCurrentDTA();
762 dprintf_int(stddeb
, "int21: FindFirst path = %s\n", path
);
764 if ((*path
)&&(path
[1] == ':')) {
765 drive
= (islower(*path
) ? toupper(*path
) : *path
) - 'A';
767 if (!DOS_ValidDrive(drive
)) {
768 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
774 drive
= DOS_GetDefaultDrive();
777 memset(dta
+ 1 , '?', 11);
778 *(dta
+ 0x0c) = ECX
& (FA_LABEL
| FA_DIREC
);
780 if (ECX
& FA_LABEL
) {
781 /* return volume label */
783 if (DOS_GetVolumeLabel(drive
) != NULL
)
784 strncpy(dta
+ 0x1e, DOS_GetVolumeLabel(drive
), 8);
791 if ((dp
= DOS_opendir(path
)) == NULL
) {
792 Error(PathNotFound
, EC_MediaError
, EL_Disk
);
798 dp
->search_attribute
= ECX
& (FA_LABEL
| FA_DIREC
);
799 memcpy(dta
+ 0x11, &dp
, sizeof(dp
));
803 static void GetFileDateTime(struct sigcontext_struct
*context
)
805 struct stat filestat
;
808 fstat( BX
, &filestat
);
809 now
= localtime (&filestat
.st_mtime
);
811 CX
= ((now
->tm_hour
* 0x2000) + (now
->tm_min
* 0x20) + now
->tm_sec
/2);
812 DX
= ((now
->tm_year
* 0x200) + (now
->tm_mon
* 0x20) + now
->tm_mday
);
817 static void SetFileDateTime(struct sigcontext_struct
*context
)
820 struct utimbuf filetime
;
822 /* FIXME: Argument isn't the name of the file in DS:DX,
823 but the file handle in BX */
824 filename
= DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) );
826 filetime
.actime
= 0L;
827 filetime
.modtime
= filetime
.actime
;
829 utime(filename
, &filetime
);
833 static void CreateTempFile(struct sigcontext_struct
*context
)
838 sprintf(temp
,"%s\\win%d.tmp",TempDirectory
,(int) getpid());
840 dprintf_int(stddeb
,"CreateTempFile %s\n",temp
);
842 handle
= open(DOS_GetUnixFileName(temp
), O_CREAT
| O_TRUNC
| O_RDWR
);
850 strcpy(PTR_SEG_OFF_TO_LIN(DS
,DX
), temp
);
856 static void CreateNewFile(struct sigcontext_struct
*context
)
860 if ((handle
= open(DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
) ), O_CREAT
| O_EXCL
| O_RDWR
)) == -1) {
870 static void GetCurrentDirectory(struct sigcontext_struct
*context
)
875 drive
= DOS_GetDefaultDrive();
879 if (!DOS_ValidDrive(drive
)) {
885 strcpy(PTR_SEG_OFF_TO_LIN(DS
,SI
), DOS_GetCurrentDir(drive
) );
889 static void GetDiskSerialNumber(struct sigcontext_struct
*context
)
892 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
896 drive
= DOS_GetDefaultDrive();
900 if (!DOS_ValidDrive(drive
)) {
906 DOS_GetSerialNumber(drive
, &serialnumber
);
909 setdword(&dataptr
[2], serialnumber
);
910 strncpy(dataptr
+ 6, DOS_GetVolumeLabel(drive
), 8);
911 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
917 static void SetDiskSerialNumber(struct sigcontext_struct
*context
)
920 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
924 drive
= DOS_GetDefaultDrive();
928 if (!DOS_ValidDrive(drive
)) {
934 serialnumber
= dataptr
[1] + (dataptr
[2] << 8) + (dataptr
[3] << 16) +
937 DOS_SetSerialNumber(drive
, serialnumber
);
942 static void DumpFCB(BYTE
*fcb
)
948 for (y
= 0; y
!=2 ; y
++) {
949 for (x
= 0; x
!=15;x
++)
950 dprintf_int(stddeb
, "%02x ", *fcb
++);
951 dprintf_int(stddeb
,"\n");
955 /* microsoft's programmers should be shot for using CP/M style int21
956 calls in Windows for Workgroup's winfile.exe */
958 static void FindFirstFCB(struct sigcontext_struct
*context
)
960 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
961 struct fcb
*standard_fcb
;
962 struct fcb
*output_fcb
;
966 BYTE
*dta
= GetCurrentDTA();
972 standard_fcb
= (struct fcb
*)(fcb
+ 7);
973 output_fcb
= (struct fcb
*)(dta
+ 7);
978 standard_fcb
= (struct fcb
*)fcb
;
979 output_fcb
= (struct fcb
*)dta
;
982 if (standard_fcb
->drive
)
984 drive
= standard_fcb
->drive
- 1;
985 if (!DOS_ValidDrive(drive
))
987 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
993 drive
= DOS_GetDefaultDrive();
995 output_fcb
->drive
= drive
;
999 if (*(fcb
+6) & FA_LABEL
) /* return volume label */
1001 *(dta
+6) = FA_LABEL
;
1002 memset(&output_fcb
->name
, ' ', 11);
1003 if (DOS_GetVolumeLabel(drive
) != NULL
)
1005 strncpy(output_fcb
->name
, DOS_GetVolumeLabel(drive
), 11);
1012 strncpy(output_fcb
->name
, standard_fcb
->name
, 11);
1014 *(dta
+6) = ( *(fcb
+6) & (!FA_DIREC
));
1016 sprintf(path
,"%c:*.*",drive
+'A');
1017 if ((output_fcb
->directory
= DOS_opendir(path
))==NULL
)
1019 Error (PathNotFound
, EC_MediaError
, EL_Disk
);
1027 static void DeleteFileFCB(struct sigcontext_struct
*context
)
1029 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
1031 struct dosdirent
*dp
;
1032 char temp
[256], *ptr
;
1039 drive
= DOS_GetDefaultDrive();
1041 strcpy(temp
, DOS_GetCurrentDir(drive
));
1043 strncat(temp
, fcb
+ 1, 8);
1044 ChopOffWhiteSpace(temp
);
1045 strncat(temp
, fcb
+ 9, 3);
1046 ChopOffWhiteSpace(temp
);
1048 if ((dp
= DOS_opendir(temp
)) == NULL
) {
1049 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1054 strcpy(temp
, DOS_GetCurrentDir(drive
) );
1057 ptr
= temp
+ strlen(temp
);
1059 while (DOS_readdir(dp
) != NULL
)
1061 strcpy(ptr
, dp
->filename
);
1062 dprintf_int(stddeb
, "int21: delete file %s\n", temp
);
1063 /* unlink(DOS_GetUnixFileName(temp)); */
1069 static void RenameFileFCB(struct sigcontext_struct
*context
)
1071 BYTE
*fcb
= PTR_SEG_OFF_TO_LIN(DS
, DX
);
1073 struct dosdirent
*dp
;
1074 char temp
[256], oldname
[256], newname
[256], *oldnameptr
, *newnameptr
;
1081 drive
= DOS_GetDefaultDrive();
1083 strcpy(temp
, DOS_GetCurrentDir(drive
));
1085 strncat(temp
, fcb
+ 1, 8);
1086 ChopOffWhiteSpace(temp
);
1087 strncat(temp
, fcb
+ 9, 3);
1088 ChopOffWhiteSpace(temp
);
1090 if ((dp
= DOS_opendir(temp
)) == NULL
) {
1091 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1096 strcpy(oldname
, DOS_GetCurrentDir(drive
) );
1097 strcat(oldname
, "\\");
1098 oldnameptr
= oldname
+ strlen(oldname
);
1100 strcpy(newname
, DOS_GetCurrentDir(drive
) );
1101 strcat(newname
, "\\");
1102 newnameptr
= newname
+ strlen(newname
);
1104 while (DOS_readdir(dp
) != NULL
)
1106 strcpy(oldnameptr
, dp
->filename
);
1107 strcpy(newnameptr
, fcb
+ 1);
1108 dprintf_int(stddeb
, "int21: renamefile %s -> %s\n",
1117 static void fLock (struct sigcontext_struct
* context
)
1120 int result
,retries
=sharing_retries
;
1122 f
.l_start
= MAKELONG(DX
,CX
);
1123 f
.l_len
= MAKELONG(DI
,SI
);
1127 switch ( AX
& 0xff )
1129 case 0x00: /* LOCK */
1133 case 0x01: /* UNLOCK */
1138 EAX
= (EAX
& 0xffff0000) | 0x0001;
1144 result
= fcntl(BX
,F_SETLK
,&f
);
1145 if ( retries
&& (!result
) )
1148 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1149 result
++; /* stop the optimizer */
1150 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
1154 while( (!result
) && (!(retries
--)) );
1159 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
1169 static void GetFileAttribute (struct sigcontext_struct
* context
)
1171 char *filename
= PTR_SEG_OFF_TO_LIN (DS
,DX
);
1175 res
= stat(DOS_GetUnixFileName(filename
), &s
);
1179 EAX
= (EAX
& 0xffffff00) | ExtendedError
;
1185 if (S_ISDIR(s
.st_mode
))
1187 if ((S_IWRITE
& s
.st_mode
) != S_IWRITE
)
1190 dprintf_int (stddeb
, "int21: GetFileAttributes (%s) = 0x%x\n",
1193 ECX
= (ECX
& 0xffff0000) | cx
;
1199 extern void LOCAL_PrintHeap (WORD ds
);
1201 /************************************************************************/
1203 int do_int21(struct sigcontext_struct
* context
)
1207 dprintf_int(stddeb
,"int21: AX %04x, BX %04x, CX %04x, DX %04x, "
1208 "SI %04x, DI %04x, DS %04x, ES %04x\n",
1209 AX
, BX
, CX
, DX
, SI
, DI
, DS
, ES
);
1213 GetExtendedErrorInfo(context
);
1221 case 0x00: /* TERMINATE PROGRAM */
1222 TASK_KillCurrentTask( 0 );
1225 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1226 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1227 case 0x03: /* READ CHARACTER FROM STDAUX */
1228 case 0x04: /* WRITE CHARACTER TO STDAUX */
1229 case 0x05: /* WRITE CHARACTER TO PRINTER */
1230 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1231 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
1232 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1233 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1234 case 0x0a: /* BUFFERED INPUT */
1235 case 0x0b: /* GET STDIN STATUS */
1236 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
1237 case 0x0f: /* OPEN FILE USING FCB */
1238 case 0x10: /* CLOSE FILE USING FCB */
1239 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1240 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1241 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1242 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1243 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1244 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1245 case 0x23: /* GET FILE SIZE FOR FCB */
1246 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1247 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1248 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1249 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1250 case 0x29: /* PARSE FILENAME INTO FCB */
1251 case 0x2e: /* SET VERIFY FLAG */
1252 IntBarf(0x21, context
);
1255 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1259 case 0x2b: /* SET SYSTEM DATE */
1260 case 0x2d: /* SET SYSTEM TIME */
1261 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1262 "SWITCHAR" - SET SWITCH CHARACTER
1263 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1264 case 0x54: /* GET VERIFY FLAG */
1265 case 0x6b: /* NULL FUNCTION */
1266 IntBarf(0x21, context
);
1270 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1274 case 0x0d: /* DISK BUFFER FLUSH */
1275 ResetCflag
; /* dos 6+ only */
1278 case 0x0e: /* SELECT DEFAULT DRIVE */
1279 if (!DOS_ValidDrive(DL
)) {
1280 Error (InvalidDrive
, EC_MediaError
, EL_Disk
);
1283 DOS_SetDefaultDrive(DL
);
1284 AX
= MAX_DOS_DRIVES
;
1289 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1290 FindFirstFCB(context
);
1293 case 0x13: /* DELETE FILE USING FCB */
1294 DeleteFileFCB(context
);
1297 case 0x17: /* RENAME FILE USING FCB */
1298 RenameFileFCB(context
);
1301 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1302 AL
= DOS_GetDefaultDrive();
1306 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1308 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1309 pTask
->dta
= MAKELONG( DX
, DS
);
1310 dprintf_int(stddeb
, "int21: Set DTA: %08lx\n", pTask
->dta
);
1314 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1315 GetDefDriveAllocInfo(context
);
1318 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1319 GetDriveAllocInfo(context
);
1322 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1323 GetDrivePB(context
, DOS_GetDefaultDrive());
1326 case 0x25: /* SET INTERRUPT VECTOR */
1327 INT_SetHandler( AL
, MAKELONG( DX
, DS
) );
1330 case 0x2a: /* GET SYSTEM DATE */
1331 GetSystemDate(context
);
1334 case 0x2c: /* GET SYSTEM TIME */
1335 GetSystemTime(context
);
1338 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1340 TDB
*pTask
= (TDB
*)GlobalLock( GetCurrentTask() );
1341 ES
= SELECTOROF( pTask
->dta
);
1342 BX
= OFFSETOF( pTask
->dta
);
1346 case 0x30: /* GET DOS VERSION */
1348 BX
= 0x0012; /* 0x123456 is Wine's serial # */
1352 case 0x31: /* TERMINATE AND STAY RESIDENT */
1353 IntBarf(0x21, context
);
1356 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1357 GetDrivePB(context
, (DL
== 0) ? (DOS_GetDefaultDrive()) : (DL
-1));
1360 case 0x33: /* MULTIPLEXED */
1362 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1367 case 0x01: /* SET EXTENDED BREAK STATE */
1370 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1374 case 0x05: /* GET BOOT DRIVE */
1376 /* c: is Wine's bootdrive */
1379 case 0x06: /* GET TRUE VERSION NUMBER */
1385 IntBarf(0x21, context
);
1390 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1392 BX
= (int)&heap
->InDosFlag
- (int)heap
;
1395 case 0x35: /* GET INTERRUPT VECTOR */
1397 SEGPTR addr
= INT_GetHandler( AL
);
1398 ES
= SELECTOROF(addr
);
1399 BX
= OFFSETOF(addr
);
1403 case 0x36: /* GET FREE DISK SPACE */
1404 GetFreeDiskSpace(context
);
1407 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1408 AX
= 0x02; /* no country support available */
1412 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1416 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1420 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1424 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1425 CreateFile(context
);
1428 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1429 OpenExistingFile(context
);
1432 case 0x3e: /* "CLOSE" - CLOSE FILE */
1436 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1440 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1444 case 0x41: /* "UNLINK" - DELETE FILE */
1445 if (unlink( DOS_GetUnixFileName( PTR_SEG_OFF_TO_LIN(DS
,DX
)) ) == -1) {
1455 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1459 case 0x43: /* FILE ATTRIBUTES */
1463 GetFileAttribute(context
);
1471 case 0x44: /* IOCTL */
1475 ioctlGetDeviceInfo(context
);
1478 case 0x08: /* Check if drive is removable. */
1479 drive
= BL
? (BL
- 1) : DOS_GetDefaultDrive();
1480 if(!DOS_ValidDrive(drive
))
1483 AX
= 0x000F; /* Bad drive number */
1488 EAX
= (EAX
& 0xFFFF0000) | 0x0001; /* not removable */
1490 EAX
= (EAX
& 0xFFFF0000); /* removable */
1495 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1496 drive
= BL
? (BL
- 1) : DOS_GetDefaultDrive();
1497 if(!DOS_ValidDrive(drive
))
1500 AX
= 0x000F; /* Bad drive number */
1504 EDX
= (EDX
& 0xffff0000) | (1<<9) | (1<<12) | (1<<15);
1509 case 0x0b: /* SET SHARING RETRY COUNT */
1512 EAX
= (EAX
& 0xffff0000) | 0x0001;
1518 sharing_retries
= DX
;
1523 ioctlGenericBlkDevReq(context
);
1526 case 0x0F: /* Set logical drive mapping */
1527 /* FIXME: Not implemented at the moment, always returns error
1529 EAX
= (EAX
& 0xFFFF0000) | 0x0001; /* invalid function */
1534 IntBarf(0x21, context
);
1539 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1540 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1545 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1546 GetCurrentDirectory(context
);
1548 /* intlist: many Microsoft products for Windows rely on this */
1551 case 0x48: /* ALLOCATE MEMORY */
1552 case 0x49: /* FREE MEMORY */
1553 case 0x4a: /* RESIZE MEMORY BLOCK */
1554 IntBarf(0x21, context
);
1557 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1558 ExecProgram(context
);
1561 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1562 TASK_KillCurrentTask( AL
);
1565 case 0x4d: /* GET RETURN CODE */
1566 AL
= NoError
; /* normal exit */
1569 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1573 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1577 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1580 IntBarf(0x21, context
);
1583 case 0x56: /* "RENAME" - RENAME FILE */
1584 RenameFile(context
);
1587 case 0x57: /* FILE DATE AND TIME */
1591 GetFileDateTime(context
);
1594 SetFileDateTime(context
);
1599 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1615 case 0x5a: /* CREATE TEMPORARY FILE */
1616 CreateTempFile(context
);
1619 case 0x5b: /* CREATE NEW FILE */
1620 CreateNewFile(context
);
1623 case 0x5d: /* NETWORK */
1625 /* network software not installed */
1630 case 0x5f: /* NETWORK */
1633 case 0x07: /* ENABLE DRIVE */
1634 if (!DOS_EnableDrive(DL
))
1636 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1646 case 0x08: /* DISABLE DRIVE */
1647 if (!DOS_DisableDrive(DL
))
1649 Error(InvalidDrive
, EC_MediaError
, EL_Disk
);
1660 /* network software not installed */
1667 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1668 strncpy(PTR_SEG_OFF_TO_LIN(ES
,DI
), PTR_SEG_OFF_TO_LIN(DS
,SI
), strlen(PTR_SEG_OFF_TO_LIN(DS
,SI
)) & 0x7f);
1672 case 0x61: /* UNUSED */
1673 case 0x62: /* GET CURRENT PSP ADDRESS */
1674 case 0x63: /* UNUSED */
1675 case 0x64: /* OS/2 DOS BOX */
1676 case 0x65: /* GET EXTENDED COUNTRY INFORMATION */
1677 IntBarf(0x21, context
);
1680 case 0x66: /* GLOBAL CODE PAGE TABLE */
1694 case 0x67: /* SET HANDLE COUNT */
1698 case 0x68: /* "FFLUSH" - COMMIT FILE */
1702 case 0x69: /* DISK SERIAL NUMBER */
1706 GetDiskSerialNumber(context
);
1709 SetDiskSerialNumber(context
);
1714 case 0x6a: /* COMMIT FILE */
1718 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1722 IntBarf(0x21, context
);
1726 dprintf_int(stddeb
,"ret21: AX %04x, BX %04x, CX %04x, DX %04x, "
1727 "SI %04x, DI %04x, DS %04x, ES %04x EFL %08lx\n",
1728 AX
, BX
, CX
, DX
, SI
, DI
, DS
, ES
, EFL
);
1734 /***********************************************************************
1735 * DOS3Call (KERNEL.102)
1737 void DOS3Call( struct sigcontext_struct context
)
1739 do_int21( &context
);
1742 void INT21_Init(void)
1744 if ((DosHeapHandle
= GlobalAlloc(GMEM_FIXED
,sizeof(struct DosHeap
))) == 0)
1746 fprintf( stderr
, "INT21_Init: Out of memory\n");
1749 heap
= (struct DosHeap
*) GlobalLock(DosHeapHandle
);
1752 dpbsegptr
= MAKELONG( (int)&heap
->dpb
- (int)heap
, DosHeapHandle
);
1753 heap
->InDosFlag
= 0;
1754 strcpy(heap
->biosdate
, "01/01/80");