2 * DOS interrupt 21h handler
14 #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) */
74 static struct DosHeap
*heap
;
75 static WORD DosHeapHandle
;
77 WORD sharing_retries
= 3; /* number of retries at sharing violation */
78 WORD sharing_pause
= 1; /* pause between retries */
80 extern char TempDirectory
[];
82 static BOOL32
INT21_CreateHeap(void)
84 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
86 WARN(int21
, "Out of memory\n");
89 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
90 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
92 strcpy(heap
->biosdate
, "01/01/80");
96 static BYTE
*GetCurrentDTA(void)
98 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
99 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
103 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
104 /* limited == TRUE is used with INT 0x21/0x440d */
109 setword(&data
[3], 0);
111 setword(&data
[6], 240);
112 setword(&data
[8], 64000);
114 setword(&data
[0x0b], 40);
115 setword(&data
[0x0d], 56);
116 setword(&data
[0x0f], 2);
117 setword(&data
[0x11], 0);
119 setword(&data
[0x1f], 800);
121 setword(&data
[0x22], 1);
123 } else { /* 1.44mb */
126 setword(&data
[3], 0);
128 setword(&data
[6], 240);
129 setword(&data
[8], 2880);
131 setword(&data
[0x0b], 6);
132 setword(&data
[0x0d], 18);
133 setword(&data
[0x0f], 2);
134 setword(&data
[0x11], 0);
136 setword(&data
[0x1f], 80);
138 setword(&data
[0x22], 2);
143 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
145 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
146 char root
[] = "A:\\";
148 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
149 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
150 &free_clusters
, &total_clusters
)) return 0;
151 AX_reg(context
) = cluster_sectors
;
152 BX_reg(context
) = free_clusters
;
153 CX_reg(context
) = sector_bytes
;
154 DX_reg(context
) = total_clusters
;
158 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
160 if (!INT21_GetFreeDiskSpace( context
)) return 0;
161 if (!heap
&& !INT21_CreateHeap()) return 0;
162 heap
->mediaID
= 0xf0;
163 DS_reg(context
) = DosHeapHandle
;
164 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
168 static void GetDrivePB( CONTEXT
*context
, int drive
)
170 if(!DRIVE_IsValid(drive
))
172 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
173 AX_reg(context
) = 0x00ff;
175 else if (heap
|| INT21_CreateHeap())
177 FIXME(int21
, "GetDrivePB not fully implemented.\n");
179 /* FIXME: I have no idea what a lot of this information should
180 * say or whether it even really matters since we're not allowing
181 * direct block access. However, some programs seem to depend on
182 * getting at least _something_ back from here. The 'next' pointer
183 * does worry me, though. Should we have a complete table of
184 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
186 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
187 heap
->dpb
.sector_size
= 512;
188 heap
->dpb
.high_sector
= 1;
189 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
190 heap
->dpb
.reserved
= 0;
191 heap
->dpb
.num_FAT
= 1;
192 heap
->dpb
.dir_entries
= 2;
193 heap
->dpb
.first_data
= 2;
194 heap
->dpb
.high_cluster
= 64000;
195 heap
->dpb
.sectors_in_FAT
= 1;
196 heap
->dpb
.start_dir
= 1;
197 heap
->dpb
.driver_head
= 0;
198 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
199 heap
->dpb
.access_flag
= 0;
201 heap
->dpb
.free_search
= 0;
202 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
204 AL_reg(context
) = 0x00;
205 DS_reg(context
) = SELECTOROF(dpbsegptr
);
206 BX_reg(context
) = OFFSETOF(dpbsegptr
);
211 static void ioctlGetDeviceInfo( CONTEXT
*context
)
214 TRACE(int21
, "(%d)\n", BX_reg(context
));
216 curr_drive
= DRIVE_GetCurrentDrive();
217 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
219 /* bits 0-5 are current drive
220 * bit 6 - file has NOT been written..FIXME: correct?
221 * bit 8 - generate int24 if no diskspace on write/ read past end of file
222 * bit 11 - media not removable
223 * bit 14 - don't set file date/time on closing
224 * bit 15 - file is remote
226 RESET_CFLAG(context
);
229 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
231 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
232 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
234 if (!DRIVE_IsValid(drive
))
236 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
240 if (CH_reg(context
) != 0x08)
242 INT_BARF( context
, 0x21 );
246 switch (CL_reg(context
))
248 case 0x4a: /* lock logical volume */
249 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
252 case 0x60: /* get device parameters */
253 /* used by w4wgrp's winfile */
254 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
256 dataptr
[6] = 0; /* media type */
259 dataptr
[1] = 0x05; /* fixed disk */
260 setword(&dataptr
[2], 0x01); /* non removable */
261 setword(&dataptr
[4], 0x300); /* # of cylinders */
265 dataptr
[1] = 0x07; /* block dev, floppy */
266 setword(&dataptr
[2], 0x02); /* removable */
267 setword(&dataptr
[4], 80); /* # of cylinders */
269 CreateBPB(drive
, &dataptr
[7], TRUE
);
270 RESET_CFLAG(context
);
273 case 0x66:/* get disk serial number */
275 char label
[12],fsname
[9],path
[4];
278 strcpy(path
,"x:\\");path
[0]=drive
+'A';
279 GetVolumeInformation32A(
280 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
283 memcpy(dataptr
+2,&serial
,4);
284 memcpy(dataptr
+6,label
,11);
285 memcpy(dataptr
+17,fsname
,8);
290 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
294 INT_BARF( context
, 0x21 );
299 static void INT21_GetSystemDate( CONTEXT
*context
)
302 GetLocalTime( &systime
);
303 CX_reg(context
) = systime
.wYear
;
304 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
305 AX_reg(context
) = systime
.wDayOfWeek
;
308 static void INT21_GetSystemTime( CONTEXT
*context
)
311 GetLocalTime( &systime
);
312 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
313 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
316 /* Many calls translate a drive argument like this:
317 drive number (00h = default, 01h = A:, etc)
319 static char drivestring
[]="default";
321 char *INT21_DriveName(int drive
)
326 drivestring
[0]= (unsigned char)drive
+ '@';
332 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
334 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
335 DX_reg(context
) ), CX_reg(context
) );
336 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
340 static void OpenExistingFile( CONTEXT
*context
)
342 AX_reg(context
) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
344 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
346 AX_reg(context
) = DOS_ExtendedError
;
355 switch (AX_reg(context
) & 0x0070)
357 case 0x00: /* compatability mode */
358 case 0x40: /* DENYNONE */
362 case 0x30: /* DENYREAD */
363 TRACE(int21
, "(%s): DENYREAD changed to DENYALL\n",
364 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
365 case 0x10: /* DENYALL */
369 case 0x20: /* DENYWRITE */
380 int result
,retries
=sharing_retries
;
382 #if defined(__svr4__) || defined(_SCO_DS)
383 ERR(int21
, "Should call flock and needs porting to lockf\n");
387 result
= flock(handle
, lock
| LOCK_NB
);
389 if ( retries
&& (!result
) )
392 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
393 result
++; /* stop the optimizer */
394 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
398 while( (!result
) && (!(retries
--)) );
403 AX_reg(context
) = DOS_ExtendedError
;
412 AX_reg(context
) = handle
;
413 RESET_CFLAG(context
);
418 static void CloseFile( CONTEXT
*context
)
420 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
422 AX_reg(context
) = DOS_ExtendedError
;
427 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
429 BOOL32 bExtendedError
= FALSE
;
430 BYTE action
= DL_reg(context
);
432 /* Shuffle arguments to call OpenExistingFile */
433 AL_reg(context
) = BL_reg(context
);
434 DX_reg(context
) = SI_reg(context
);
435 /* BX,CX and DX should be preserved */
436 OpenExistingFile(context
);
438 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
440 UINT16 uReturnCX
= 0;
442 /* Now decide what do do */
444 if ((action
& 0x07) == 0)
446 BX_reg(context
) = AX_reg(context
);
448 AX_reg(context
) = 0x0050; /*File exists*/
450 WARN(int21
, "extended open/create: failed because file exists \n");
452 else if ((action
& 0x07) == 2)
454 /* Truncate it, but first check if opened for write */
455 if ((BL_reg(context
) & 0x0007)== 0)
457 BX_reg(context
) = AX_reg(context
);
459 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
460 AX_reg(context
) = 0x000C; /*Access code invalid*/
465 /* Shuffle arguments to call CloseFile while
466 * preserving BX and DX */
468 TRACE(int21
, "extended open/create: Closing before truncate\n");
469 BX_reg(context
) = AX_reg(context
);
471 if (EFL_reg(context
) & 0x0001)
473 WARN(int21
, "extended open/create: close before trunc failed\n");
474 AX_reg(context
) = 0x0019; /*Seek Error*/
478 /* Shuffle arguments to call CreateFile */
480 TRACE(int21
, "extended open/create: Truncating\n");
481 AL_reg(context
) = BL_reg(context
);
482 /* CX is still the same */
483 DX_reg(context
) = SI_reg(context
);
484 bExtendedError
= INT21_CreateFile(context
);
486 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
488 WARN(int21
, "extended open/create: trunc failed\n");
489 return bExtendedError
;
494 else uReturnCX
= 0x1;
496 CX_reg(context
) = uReturnCX
;
498 else /* file does not exist */
500 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
501 if ((action
& 0xF0)== 0)
505 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
509 /* Shuffle arguments to call CreateFile */
510 TRACE(int21
, "extended open/create: Creating\n");
511 AL_reg(context
) = BL_reg(context
);
512 /* CX should still be the same */
513 DX_reg(context
) = SI_reg(context
);
514 bExtendedError
= INT21_CreateFile(context
);
515 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
517 WARN(int21
, "extended open/create: create failed\n");
518 return bExtendedError
;
524 return bExtendedError
;
528 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
531 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
533 TRACE(int21
,"changedir %s\n", dirname
);
534 if (dirname
[0] && (dirname
[1] == ':'))
536 drive
= toupper(dirname
[0]) - 'A';
539 else drive
= DRIVE_GetCurrentDrive();
540 return DRIVE_Chdir( drive
, dirname
);
544 static int INT21_FindFirst( CONTEXT
*context
)
548 DOS_FULL_NAME full_name
;
549 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
551 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
552 dta
->unixPath
= NULL
;
553 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
555 AX_reg(context
) = DOS_ExtendedError
;
559 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
560 p
= strrchr( dta
->unixPath
, '/' );
563 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
564 * (doesn't matter as it is set below anyway)
566 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
568 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
569 dta
->unixPath
= NULL
;
570 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
571 AX_reg(context
) = ER_FileNotFound
;
575 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
576 : DRIVE_GetCurrentDrive();
578 dta
->search_attr
= CL_reg(context
);
583 static int INT21_FindNext( CONTEXT
*context
)
585 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
586 WIN32_FIND_DATA32A entry
;
589 if (!dta
->unixPath
) return 0;
590 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
591 dta
->search_attr
, dta
->count
, &entry
)))
593 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
594 dta
->unixPath
= NULL
;
597 if ((int)dta
->count
+ count
> 0xffff)
599 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
600 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
601 dta
->unixPath
= NULL
;
605 dta
->fileattr
= entry
.dwFileAttributes
;
606 dta
->filesize
= entry
.nFileSizeLow
;
607 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
608 &dta
->filedate
, &dta
->filetime
);
609 strcpy( dta
->filename
, entry
.cAlternateFileName
);
614 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
616 static int counter
= 0;
617 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
618 char *p
= name
+ strlen(name
);
620 /* despite what Ralf Brown says, some programs seem to call without
621 * ending backslash (DOS accepts that, so we accept it too) */
622 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
626 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
627 counter
= (counter
+ 1) % 1000;
629 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
631 TRACE(int21
, "created %s\n", name
);
634 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
639 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
641 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
642 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
644 if (!DRIVE_IsValid(drive
))
646 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
649 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
650 AX_reg(context
) = 0x0100; /* success return code */
655 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
657 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
658 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
660 if (!DRIVE_IsValid(drive
))
662 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
666 *(WORD
*)dataptr
= 0;
667 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
668 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
669 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
674 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
676 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
677 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
679 if (!DRIVE_IsValid(drive
))
681 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
685 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
690 /* microsoft's programmers should be shot for using CP/M style int21
691 calls in Windows for Workgroup's winfile.exe */
693 static int INT21_FindFirstFCB( CONTEXT
*context
)
695 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
700 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
701 else pFCB
= (FINDFILE_FCB
*)fcb
;
702 drive
= DOS_GET_DRIVE( pFCB
->drive
);
703 root
= DRIVE_GetRoot( drive
);
704 cwd
= DRIVE_GetUnixCwd( drive
);
705 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
706 strlen(root
)+strlen(cwd
)+2 );
707 if (!pFCB
->unixPath
) return 0;
708 strcpy( pFCB
->unixPath
, root
);
709 strcat( pFCB
->unixPath
, "/" );
710 strcat( pFCB
->unixPath
, cwd
);
716 static int INT21_FindNextFCB( CONTEXT
*context
)
718 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
720 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
721 WIN32_FIND_DATA32A entry
;
725 if (*fcb
== 0xff) /* extended FCB ? */
728 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
733 pFCB
= (FINDFILE_FCB
*)fcb
;
736 if (!pFCB
->unixPath
) return 0;
737 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
738 DOS_GET_DRIVE( pFCB
->drive
), attr
,
739 pFCB
->count
, &entry
)))
741 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
742 pFCB
->unixPath
= NULL
;
745 pFCB
->count
+= count
;
747 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
748 *(BYTE
*)pResult
= 0xff;
749 (BYTE
*)pResult
+=6; /* leave reserved field behind */
750 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
753 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
755 pResult
->fileattr
= entry
.dwFileAttributes
;
756 pResult
->cluster
= 0; /* what else? */
757 pResult
->filesize
= entry
.nFileSizeLow
;
758 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
759 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
760 &pResult
->filedate
, &pResult
->filetime
);
762 /* Convert file name to FCB format */
764 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
765 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
766 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
767 pResult
->filename
[0] = pResult
->filename
[1] = '.';
770 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
771 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
773 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
774 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
775 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
778 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
779 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
785 static void DeleteFileFCB( CONTEXT
*context
)
787 FIXME(int21
, "(%p): not implemented yet\n", context
);
790 static void RenameFileFCB( CONTEXT
*context
)
792 FIXME(int21
, "(%p): not implemented yet\n", context
);
797 static void fLock( CONTEXT
* context
)
800 switch ( AX_reg(context
) & 0xff )
802 case 0x00: /* LOCK */
803 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
805 MAKELONG(DX_reg(context
),CX_reg(context
)),
806 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
807 if (!LockFile(BX_reg(context
),
808 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
809 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
810 AX_reg(context
) = DOS_ExtendedError
;
815 case 0x01: /* UNLOCK */
816 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
818 MAKELONG(DX_reg(context
),CX_reg(context
)),
819 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
820 if (!UnlockFile(BX_reg(context
),
821 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
822 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
823 AX_reg(context
) = DOS_ExtendedError
;
828 AX_reg(context
) = 0x0001;
835 INT21_networkfunc (CONTEXT
*context
)
837 switch (AL_reg(context
)) {
838 case 0x00: /* Get machine name. */
840 char *dst
= PTR_SEG_OFF_TO_LIN (DS_reg(context
),DX_reg(context
));
841 TRACE(int21
, "getting machine name to %p\n", dst
);
842 if (gethostname (dst
, 15))
844 WARN(int21
,"failed!\n");
845 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
848 int len
= strlen (dst
);
852 CH_reg(context
) = 1; /* Valid */
853 CL_reg(context
) = 1; /* NETbios number??? */
854 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
860 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
866 SEGPTR
INT21_GetListOfLists()
868 static DOS_LISTOFLISTS
*LOL
;
869 static SEGPTR seg_LOL
;
874 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
875 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
876 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
877 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
878 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
879 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
880 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
881 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
882 0133:00A0 D0 44 C8 FD D0 44 .D...D
885 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
887 LOL
->CX_Int21_5e01
= 0x0;
888 LOL
->LRU_count_FCB_cache
= 0x0;
889 LOL
->LRU_count_FCB_open
= 0x0;
890 LOL
->OEM_func_handler
= -1; /* not available */
891 LOL
->INT21_offset
= 0x0;
892 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
893 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
894 LOL
->ptr_disk_buf
= 0x0;
895 LOL
->offs_unread_CON
= 0x0;
896 LOL
->seg_first_MCB
= 0x0;
897 LOL
->ptr_first_DPB
= 0x0;
898 LOL
->ptr_first_SysFileTable
= 0x0;
899 LOL
->ptr_clock_dev_hdr
= 0x0;
900 LOL
->ptr_CON_dev_hdr
= 0x0;
901 LOL
->max_byte_per_sec
= 512;
902 LOL
->ptr_disk_buf_info
= 0x0;
903 LOL
->ptr_array_CDS
= 0x0;
904 LOL
->ptr_sys_FCB
= 0x0;
905 LOL
->nr_protect_FCB
= 0x0;
906 LOL
->nr_block_dev
= 0x0;
907 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
908 LOL
->nr_drives_JOINed
= 0x0;
909 LOL
->ptr_spec_prg_names
= 0x0;
910 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
911 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
912 LOL
->PSP_last_exec
= 0x0;
913 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
914 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
915 LOL
->boot_drive
= 3; /* C: */
916 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
917 LOL
->size_extended_mem
= 0xf000; /* very high value */
919 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
920 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
924 extern void LOCAL_PrintHeap (WORD ds
);
926 /***********************************************************************
927 * DOS3Call (KERNEL.102)
929 void WINAPI
DOS3Call( CONTEXT
*context
)
931 BOOL32 bSetDOSExtendedError
= FALSE
;
934 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
935 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
936 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
937 SI_reg(context
), DI_reg(context
),
938 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
942 if (AH_reg(context
) == 0x59) /* Get extended error info */
944 TRACE(int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
945 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
946 AX_reg(context
) = DOS_ExtendedError
;
947 BH_reg(context
) = DOS_ErrorClass
;
948 BL_reg(context
) = DOS_ErrorAction
;
949 CH_reg(context
) = DOS_ErrorLocus
;
953 DOS_ERROR( 0, 0, 0, 0 );
954 RESET_CFLAG(context
); /* Not sure if this is a good idea */
956 switch(AH_reg(context
))
958 case 0x00: /* TERMINATE PROGRAM */
959 TRACE(int21
,"TERMINATE PROGRAM\n");
960 TASK_KillCurrentTask( 0 );
963 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
964 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
965 case 0x03: /* READ CHARACTER FROM STDAUX */
966 case 0x04: /* WRITE CHARACTER TO STDAUX */
967 case 0x05: /* WRITE CHARACTER TO PRINTER */
968 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
969 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
970 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
971 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
972 case 0x0a: /* BUFFERED INPUT */
973 case 0x0b: /* GET STDIN STATUS */
974 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
975 case 0x0f: /* OPEN FILE USING FCB */
976 case 0x10: /* CLOSE FILE USING FCB */
977 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
978 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
979 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
980 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
981 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
982 case 0x23: /* GET FILE SIZE FOR FCB */
983 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
984 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
985 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
986 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
987 case 0x29: /* PARSE FILENAME INTO FCB */
988 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
989 "SWITCHAR" - SET SWITCH CHARACTER
990 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
991 case 0x54: /* GET VERIFY FLAG */
992 case 0x48: /* ALLOCATE MEMORY */
993 case 0x49: /* FREE MEMORY */
994 case 0x4a: /* RESIZE MEMORY BLOCK */
995 INT_BARF( context
, 0x21 );
997 case 0x2e: /* SET VERIFY FLAG */
998 TRACE(int21
,"SET VERIFY FLAG ignored\n");
999 /* we cannot change the behaviour anyway, so just ignore it */
1002 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1006 case 0x6b: /* NULL FUNCTION */
1007 AL_reg(context
) = 0;
1010 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1014 case 0x0d: /* DISK BUFFER FLUSH */
1015 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1016 RESET_CFLAG(context
); /* dos 6+ only */
1019 case 0x0e: /* SELECT DEFAULT DRIVE */
1020 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1021 DRIVE_SetCurrentDrive( DL_reg(context
) );
1022 AL_reg(context
) = MAX_DOS_DRIVES
;
1025 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1026 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1027 PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
)));
1028 if (!INT21_FindFirstFCB(context
))
1030 AL_reg(context
) = 0xff;
1033 /* else fall through */
1035 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1036 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1039 case 0x13: /* DELETE FILE USING FCB */
1040 DeleteFileFCB(context
);
1043 case 0x17: /* RENAME FILE USING FCB */
1044 RenameFileFCB(context
);
1047 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1048 AL_reg(context
) = DRIVE_GetCurrentDrive();
1051 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1053 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1054 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1055 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1059 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1060 DL_reg(context
) = 0;
1061 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1064 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1065 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1068 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1069 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1072 case 0x25: /* SET INTERRUPT VECTOR */
1073 INT_SetHandler( AL_reg(context
),
1074 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1078 case 0x2a: /* GET SYSTEM DATE */
1079 INT21_GetSystemDate(context
);
1082 case 0x2b: /* SET SYSTEM DATE */
1083 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1084 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1085 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1088 case 0x2c: /* GET SYSTEM TIME */
1089 INT21_GetSystemTime(context
);
1092 case 0x2d: /* SET SYSTEM TIME */
1093 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1094 CH_reg(context
), CL_reg(context
),
1095 DH_reg(context
), DL_reg(context
) );
1096 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1099 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1100 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1102 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1103 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1104 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1108 case 0x30: /* GET DOS VERSION */
1109 TRACE(int21
,"GET DOS VERSION %s requested\n",
1110 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1111 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1112 (HIWORD(GetVersion16()) << 8);
1113 BX_reg(context
) = 0x0012; /* 0x123456 is Wine's serial # */
1114 CX_reg(context
) = 0x3456;
1117 case 0x31: /* TERMINATE AND STAY RESIDENT */
1118 TRACE(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1119 INT_BARF( context
, 0x21 );
1122 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1123 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1124 INT21_DriveName( DL_reg(context
)));
1125 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1128 case 0x33: /* MULTIPLEXED */
1129 switch (AL_reg(context
))
1131 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1132 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE stub\n");
1133 DL_reg(context
) = 0;
1136 case 0x01: /* SET EXTENDED BREAK STATE */
1137 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE stub\n");
1140 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1141 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1142 DL_reg(context
) = 0;
1145 case 0x05: /* GET BOOT DRIVE */
1146 TRACE(int21
,"GET BOOT DRIVE\n");
1147 DL_reg(context
) = 3;
1148 /* c: is Wine's bootdrive (a: is 1)*/
1151 case 0x06: /* GET TRUE VERSION NUMBER */
1152 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1153 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1154 (HIWORD(GetVersion16() << 8));
1155 DX_reg(context
) = 0x00;
1159 INT_BARF( context
, 0x21 );
1164 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1165 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1166 if (!heap
) INT21_CreateHeap();
1167 ES_reg(context
) = DosHeapHandle
;
1168 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1171 case 0x35: /* GET INTERRUPT VECTOR */
1172 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1174 FARPROC16 addr
= INT_GetHandler( AL_reg(context
) );
1175 ES_reg(context
) = SELECTOROF(addr
);
1176 BX_reg(context
) = OFFSETOF(addr
);
1180 case 0x36: /* GET FREE DISK SPACE */
1181 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1182 INT21_DriveName( DL_reg(context
)));
1183 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1186 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1187 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1189 AX_reg(context
) = 0x02; /* no country support available */
1193 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1194 TRACE(int21
,"MKDIR %s\n",
1195 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1196 bSetDOSExtendedError
= (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1197 DX_reg(context
) ), NULL
));
1200 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1201 TRACE(int21
,"RMDIR %s\n",
1202 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1203 bSetDOSExtendedError
= (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1204 DX_reg(context
) )));
1207 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1208 TRACE(int21
,"CHDIR %s\n",
1209 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1210 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1213 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1214 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1215 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1216 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1217 DX_reg(context
) ), CX_reg(context
) );
1218 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1221 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1222 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1223 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1224 OpenExistingFile(context
);
1227 case 0x3e: /* "CLOSE" - CLOSE FILE */
1228 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1229 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1232 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1233 TRACE(int21
,"READ from %d to %ld for %d byte\n",BX_reg(context
),
1234 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),DX_reg(context
)),CX_reg(context
) );
1236 LONG result
= WIN16_hread( BX_reg(context
),
1237 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1240 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1241 else AX_reg(context
) = (WORD
)result
;
1245 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1246 TRACE(int21
,"WRITE from %ld to handle %d for %d byte\n",
1247 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),DX_reg(context
)),
1248 BX_reg(context
),CX_reg(context
) );
1250 LONG result
= _hwrite16( BX_reg(context
),
1251 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1254 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1255 else AX_reg(context
) = (WORD
)result
;
1259 case 0x41: /* "UNLINK" - DELETE FILE */
1260 TRACE(int21
,"UNLINK%s\n",
1261 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1262 bSetDOSExtendedError
= (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1263 DX_reg(context
) )));
1266 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1267 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1268 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1269 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1270 "current file position":"end of file");
1272 LONG status
= _llseek16( BX_reg(context
),
1273 MAKELONG(DX_reg(context
),CX_reg(context
)),
1275 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1278 AX_reg(context
) = LOWORD(status
);
1279 DX_reg(context
) = HIWORD(status
);
1284 case 0x43: /* FILE ATTRIBUTES */
1285 switch (AL_reg(context
))
1288 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1289 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1290 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1291 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1293 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1294 else CX_reg(context
) = AX_reg(context
);
1298 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1299 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1300 bSetDOSExtendedError
=
1301 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1306 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1307 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1311 case 0x44: /* IOCTL */
1312 switch (AL_reg(context
))
1315 ioctlGetDeviceInfo(context
);
1320 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1321 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
1322 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1324 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1325 /* for (i=0;i<CX_reg(context);i++)
1326 fprintf(stdnimp,"%02x ",dataptr[i]);
1327 fprintf(stdnimp,"\n");*/
1328 AX_reg(context
)=CX_reg(context
);
1331 case 0x08: /* Check if drive is removable. */
1332 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1333 INT21_DriveName( BL_reg(context
)));
1334 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1336 case DRIVE_CANNOTDETERMINE
:
1337 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1338 AX_reg(context
) = ER_InvalidDrive
;
1341 case DRIVE_REMOVABLE
:
1342 AX_reg(context
) = 0; /* removable */
1345 AX_reg(context
) = 1; /* not removable */
1350 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1351 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1352 INT21_DriveName( BL_reg(context
)));
1353 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1355 case DRIVE_CANNOTDETERMINE
:
1356 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1357 AX_reg(context
) = ER_InvalidDrive
;
1361 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1364 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1369 case 0x0a: /* check if handle (BX) is remote */
1370 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1371 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1374 DX_reg(context
) = 0;
1377 case 0x0b: /* SET SHARING RETRY COUNT */
1378 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1379 CX_reg(context
), DX_reg(context
));
1380 if (!CX_reg(context
))
1382 AX_reg(context
) = 1;
1386 sharing_pause
= CX_reg(context
);
1387 if (!DX_reg(context
))
1388 sharing_retries
= DX_reg(context
);
1389 RESET_CFLAG(context
);
1393 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1394 INT21_DriveName( BL_reg(context
)));
1395 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1398 case 0x0e: /* get logical drive mapping */
1399 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1400 INT21_DriveName( BL_reg(context
)));
1401 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1404 case 0x0F: /* Set logical drive mapping */
1407 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1408 INT21_DriveName( BL_reg(context
)));
1409 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1410 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1413 AX_reg(context
) = 0x000F; /* invalid drive */
1419 INT_BARF( context
, 0x21 );
1424 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1425 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1426 bSetDOSExtendedError
= ((AX_reg(context
) = FILE_Dup(BX_reg(context
))) == (WORD
)HFILE_ERROR16
);
1429 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1430 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1431 BX_reg(context
),CX_reg(context
));
1432 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR32
);
1435 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1436 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1437 INT21_DriveName( DL_reg(context
)));
1438 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1441 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1442 TRACE(int21
,"EXEC %s\n",
1443 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
) ));
1444 AX_reg(context
) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1447 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1450 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1451 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1452 TASK_KillCurrentTask( AL_reg(context
) );
1455 case 0x4d: /* GET RETURN CODE */
1456 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1457 AX_reg(context
) = 0; /* normal exit */
1460 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1461 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1462 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1463 if (!INT21_FindFirst(context
)) break;
1466 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1467 TRACE(int21
,"FINDNEXT\n");
1468 if (!INT21_FindNext(context
))
1470 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1471 AX_reg(context
) = ER_NoMoreFiles
;
1474 else AX_reg(context
) = 0; /* OK */
1477 case 0x51: /* GET PSP ADDRESS */
1478 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1479 /* FIXME: should we return the original DOS PSP upon */
1480 /* Windows startup ? */
1481 BX_reg(context
) = GetCurrentPDB();
1483 case 0x62: /* GET PSP ADDRESS */
1484 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1485 /* FIXME: should we return the original DOS PSP upon */
1486 /* Windows startup ? */
1487 BX_reg(context
) = GetCurrentPDB();
1490 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1491 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1494 lol
= INT21_GetListOfLists();
1495 ES_reg(context
) = HIWORD(lol
);
1496 BX_reg(context
) = LOWORD(lol
);
1500 case 0x56: /* "RENAME" - RENAME FILE */
1501 TRACE(int21
,"RENAME %s to %s\n",
1502 (LPCSTR
)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1503 (LPCSTR
)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
)));
1504 bSetDOSExtendedError
=
1505 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1506 PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
))));
1509 case 0x57: /* FILE DATE AND TIME */
1510 switch (AL_reg(context
))
1512 case 0x00: /* Get */
1515 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1517 if (!GetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
))
1518 bSetDOSExtendedError
= TRUE
;
1519 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1524 case 0x01: /* Set */
1527 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1529 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1531 bSetDOSExtendedError
=
1532 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1538 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1539 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1541 switch (AL_reg(context
))
1544 AX_reg(context
) = 1;
1547 AX_reg(context
) = 0;
1553 RESET_CFLAG(context
);
1556 case 0x5a: /* CREATE TEMPORARY FILE */
1557 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1558 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1561 case 0x5b: /* CREATE NEW FILE */
1562 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1563 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1564 bSetDOSExtendedError
= ((AX_reg(context
) =
1565 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), 0 ))
1566 == (WORD
)HFILE_ERROR16
);
1569 case 0x5d: /* NETWORK */
1570 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1571 /* Fix the following while you're at it. */
1572 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1573 bSetDOSExtendedError
= TRUE
;
1577 bSetDOSExtendedError
= INT21_networkfunc (context
);
1580 case 0x5f: /* NETWORK */
1581 switch (AL_reg(context
))
1583 case 0x07: /* ENABLE DRIVE */
1584 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1585 if (!DRIVE_Enable( DL_reg(context
) ))
1587 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1588 bSetDOSExtendedError
= TRUE
;
1592 case 0x08: /* DISABLE DRIVE */
1593 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1594 if (!DRIVE_Disable( DL_reg(context
) ))
1596 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1597 bSetDOSExtendedError
= TRUE
;
1602 /* network software not installed */
1603 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1604 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1605 bSetDOSExtendedError
= TRUE
;
1610 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1611 TRACE(int21
,"TRUENAME %s\n",
1612 (LPCSTR
)PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)));
1614 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1615 SI_reg(context
)), 128,
1616 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1617 DI_reg(context
)),NULL
))
1618 bSetDOSExtendedError
= TRUE
;
1619 else AX_reg(context
) = 0;
1623 case 0x61: /* UNUSED */
1624 case 0x63: /* UNUSED */
1625 case 0x64: /* OS/2 DOS BOX */
1626 INT_BARF( context
, 0x21 );
1630 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1631 extern WORD WINE_LanguageId
;
1632 BYTE
*dataptr
=PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
1633 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1634 BX_reg(context
), DX_reg(context
));
1635 switch (AL_reg(context
)) {
1637 TRACE(int21
,"\tget general internationalization info\n");
1639 *(WORD
*)(dataptr
+1) = 41;
1640 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1641 *(WORD
*)(dataptr
+5) = CodePage
;
1642 *(DWORD
*)(dataptr
+0x19) = NULL
; /* FIXME: ptr to case map routine */
1645 TRACE(int21
,"\tget pointer to collating sequence table\n");
1647 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1648 CX_reg(context
) = 258;/*FIXME: size of table?*/
1651 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1652 INT_BARF( context
, 0x21 );
1658 case 0x66: /* GLOBAL CODE PAGE TABLE */
1659 switch (AL_reg(context
))
1662 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
1663 DX_reg(context
) = BX_reg(context
) = CodePage
;
1664 RESET_CFLAG(context
);
1667 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1668 BX_reg(context
),DX_reg(context
));
1669 CodePage
= BX_reg(context
);
1670 RESET_CFLAG(context
);
1675 case 0x67: /* SET HANDLE COUNT */
1676 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
1677 SetHandleCount16( BX_reg(context
) );
1678 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1681 case 0x68: /* "FFLUSH" - COMMIT FILE */
1682 case 0x6a: /* COMMIT FILE */
1683 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
1684 bSetDOSExtendedError
= (!FlushFileBuffers( BX_reg(context
) ));
1687 case 0x69: /* DISK SERIAL NUMBER */
1688 switch (AL_reg(context
))
1691 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
1692 INT21_DriveName(BL_reg(context
)));
1693 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1694 else AX_reg(context
) = 0;
1698 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
1699 INT21_DriveName(BL_reg(context
)));
1700 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1701 else AX_reg(context
) = 1;
1706 case 0x6C: /* Extended Open/Create*/
1707 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
1708 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DI_reg(context
)));
1709 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1712 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1713 switch(AL_reg(context
))
1715 case 0x39: /* Create directory */
1716 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
1717 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1718 bSetDOSExtendedError
= (!CreateDirectory32A(
1719 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1720 DX_reg(context
) ), NULL
));
1722 case 0x3a: /* Remove directory */
1723 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1724 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1725 bSetDOSExtendedError
= (!RemoveDirectory32A(
1726 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1727 DX_reg(context
) )));
1729 case 0x43: /* Get/Set file attributes */
1730 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1731 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1732 switch (BL_reg(context
))
1734 case 0x00: /* Get file attributes */
1735 TRACE(int21
,"\tretrieve attributes\n");
1736 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1737 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1739 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1742 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
1743 bSetDOSExtendedError
= (!SetFileAttributes32A(
1744 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1746 CX_reg(context
) ) );
1749 FIXME(int21
, "Unimplemented long file name function:\n");
1750 INT_BARF( context
, 0x21 );
1752 AL_reg(context
) = 0;
1756 case 0x47: /* Get current directory */
1757 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1758 INT21_DriveName(DL_reg(context
)));
1759 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1762 case 0x4e: /* Find first file */
1763 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1764 (LPCSTR
)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
1765 /* FIXME: use attributes in CX */
1766 if ((AX_reg(context
) = FindFirstFile16(
1767 PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1768 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1770 == INVALID_HANDLE_VALUE16
)
1771 bSetDOSExtendedError
= TRUE
;
1773 case 0x4f: /* Find next file */
1774 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1776 if (!FindNextFile16( BX_reg(context
),
1777 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1779 bSetDOSExtendedError
= TRUE
;
1781 case 0xa1: /* Find close */
1782 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
1784 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
1787 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
1788 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1791 switch(CL_reg(context
))
1793 case 0x02: /*Get canonical long filename or path */
1794 if (!GetFullPathName32A
1795 ( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1796 SI_reg(context
)), 128,
1797 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1798 DI_reg(context
)),NULL
))
1799 bSetDOSExtendedError
= TRUE
;
1800 else AX_reg(context
) = 0;
1803 FIXME(int21
, "Unimplemented long file name function:\n");
1804 INT_BARF( context
, 0x21 );
1806 AL_reg(context
) = 0;
1810 case 0x6c: /* Create or open file */
1811 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
1812 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
)));
1813 /* translate Dos 7 action to Dos 6 action */
1814 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1817 case 0x3b: /* Change directory */
1818 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
1819 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1820 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1826 AL_reg(context
) = DOS_ExtendedError
;
1829 case 0x41: /* Delete file */
1830 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
1831 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1832 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1837 AL_reg(context
) = DOS_ExtendedError
;
1840 case 0x56: /* Move (rename) file */
1841 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
1842 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)),
1843 (LPCSTR
)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
)));
1845 FIXME(int21
, "Unimplemented long file name function:\n");
1846 INT_BARF( context
, 0x21 );
1848 AL_reg(context
) = 0;
1853 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1854 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1855 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1856 TRACE(int21
,"windows95 function AX %04x\n",
1858 WARN(int21
, " returning unimplemented\n");
1860 AL_reg(context
) = 0;
1863 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1864 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1868 INT_BARF( context
, 0x21 );
1871 } /* END OF SWITCH */
1873 if( bSetDOSExtendedError
) /* set general error condition */
1875 AX_reg(context
) = DOS_ExtendedError
;
1879 if ((EFL_reg(context
) & 0x0001))
1880 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1881 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
1883 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1884 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1885 AX_reg(context
), BX_reg(context
), CX_reg(context
),
1886 DX_reg(context
), SI_reg(context
), DI_reg(context
),
1887 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1891 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
1893 FIXME(int21
, "(DosProc=%08x);\n", (UINT32
)DosProc
);