2 * DOS interrupt 21h handler
13 #include <sys/types.h>
27 #if defined(__svr4__) || defined(_SCO_DS)
28 /* SVR4 DOESNT do locking the same way must implement properly */
35 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
37 /* Define the drive parameter block, as used by int21/1F
38 * and int21/32. This table can be accessed through the
39 * global 'dpb' pointer, which points into the local dos
44 BYTE drive_num
; /* 0=A, etc. */
45 BYTE unit_num
; /* Drive's unit number (?) */
46 WORD sector_size
; /* Sector size in bytes */
47 BYTE high_sector
; /* Highest sector in a cluster */
48 BYTE shift
; /* Shift count (?) */
49 WORD reserved
; /* Number of reserved sectors at start */
50 BYTE num_FAT
; /* Number of FATs */
51 WORD dir_entries
; /* Number of root dir entries */
52 WORD first_data
; /* First data sector */
53 WORD high_cluster
; /* Highest cluster number */
54 WORD sectors_in_FAT
; /* Number of sectors per FAT */
55 WORD start_dir
; /* Starting sector of first dir */
56 DWORD driver_head
; /* Address of device driver header (?) */
57 BYTE media_ID
; /* Media ID */
58 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
59 DWORD next
; /* Pointer to next DPB in list */
60 WORD free_search
; /* Free cluster search start */
61 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
73 static struct DosHeap
*heap
;
74 static WORD DosHeapHandle
;
76 WORD sharing_retries
= 3; /* number of retries at sharing violation */
77 WORD sharing_pause
= 1; /* pause between retries */
79 extern char TempDirectory
[];
81 static BOOL32
INT21_CreateHeap(void)
83 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
85 WARN(int21
, "Out of memory\n");
88 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
89 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
91 strcpy(heap
->biosdate
, "01/01/80");
95 static BYTE
*GetCurrentDTA(void)
97 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
98 return (BYTE
*)PTR_SEG_TO_LIN( pTask
->dta
);
102 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
103 /* limited == TRUE is used with INT 0x21/0x440d */
108 setword(&data
[3], 0);
110 setword(&data
[6], 240);
111 setword(&data
[8], 64000);
113 setword(&data
[0x0b], 40);
114 setword(&data
[0x0d], 56);
115 setword(&data
[0x0f], 2);
116 setword(&data
[0x11], 0);
118 setword(&data
[0x1f], 800);
120 setword(&data
[0x22], 1);
122 } else { /* 1.44mb */
125 setword(&data
[3], 0);
127 setword(&data
[6], 240);
128 setword(&data
[8], 2880);
130 setword(&data
[0x0b], 6);
131 setword(&data
[0x0d], 18);
132 setword(&data
[0x0f], 2);
133 setword(&data
[0x11], 0);
135 setword(&data
[0x1f], 80);
137 setword(&data
[0x22], 2);
142 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
144 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
145 char root
[] = "A:\\";
147 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
148 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
149 &free_clusters
, &total_clusters
)) return 0;
150 AX_reg(context
) = cluster_sectors
;
151 BX_reg(context
) = free_clusters
;
152 CX_reg(context
) = sector_bytes
;
153 DX_reg(context
) = total_clusters
;
157 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
159 if (!INT21_GetFreeDiskSpace( context
)) return 0;
160 if (!heap
&& !INT21_CreateHeap()) return 0;
161 heap
->mediaID
= 0xf0;
162 DS_reg(context
) = DosHeapHandle
;
163 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
167 static void GetDrivePB( CONTEXT
*context
, int drive
)
169 if(!DRIVE_IsValid(drive
))
171 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
172 AX_reg(context
) = 0x00ff;
174 else if (heap
|| INT21_CreateHeap())
176 FIXME(int21
, "GetDrivePB not fully implemented.\n");
178 /* FIXME: I have no idea what a lot of this information should
179 * say or whether it even really matters since we're not allowing
180 * direct block access. However, some programs seem to depend on
181 * getting at least _something_ back from here. The 'next' pointer
182 * does worry me, though. Should we have a complete table of
183 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
185 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
186 heap
->dpb
.sector_size
= 512;
187 heap
->dpb
.high_sector
= 1;
188 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
189 heap
->dpb
.reserved
= 0;
190 heap
->dpb
.num_FAT
= 1;
191 heap
->dpb
.dir_entries
= 2;
192 heap
->dpb
.first_data
= 2;
193 heap
->dpb
.high_cluster
= 64000;
194 heap
->dpb
.sectors_in_FAT
= 1;
195 heap
->dpb
.start_dir
= 1;
196 heap
->dpb
.driver_head
= 0;
197 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
198 heap
->dpb
.access_flag
= 0;
200 heap
->dpb
.free_search
= 0;
201 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
203 AL_reg(context
) = 0x00;
204 DS_reg(context
) = SELECTOROF(dpbsegptr
);
205 BX_reg(context
) = OFFSETOF(dpbsegptr
);
210 static void ioctlGetDeviceInfo( CONTEXT
*context
)
213 TRACE(int21
, "(%d)\n", BX_reg(context
));
215 curr_drive
= DRIVE_GetCurrentDrive();
216 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
218 /* bits 0-5 are current drive
219 * bit 6 - file has NOT been written..FIXME: correct?
220 * bit 8 - generate int24 if no diskspace on write/ read past end of file
221 * bit 11 - media not removable
222 * bit 14 - don't set file date/time on closing
223 * bit 15 - file is remote
225 RESET_CFLAG(context
);
228 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
230 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
231 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
233 if (!DRIVE_IsValid(drive
))
235 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
239 if (CH_reg(context
) != 0x08)
241 INT_BARF( context
, 0x21 );
245 switch (CL_reg(context
))
247 case 0x4a: /* lock logical volume */
248 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
251 case 0x60: /* get device parameters */
252 /* used by w4wgrp's winfile */
253 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
255 dataptr
[6] = 0; /* media type */
258 dataptr
[1] = 0x05; /* fixed disk */
259 setword(&dataptr
[2], 0x01); /* non removable */
260 setword(&dataptr
[4], 0x300); /* # of cylinders */
264 dataptr
[1] = 0x07; /* block dev, floppy */
265 setword(&dataptr
[2], 0x02); /* removable */
266 setword(&dataptr
[4], 80); /* # of cylinders */
268 CreateBPB(drive
, &dataptr
[7], TRUE
);
269 RESET_CFLAG(context
);
272 case 0x66:/* get disk serial number */
274 char label
[12],fsname
[9],path
[4];
277 strcpy(path
,"x:\\");path
[0]=drive
+'A';
278 GetVolumeInformation32A(
279 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
282 memcpy(dataptr
+2,&serial
,4);
283 memcpy(dataptr
+6,label
,11);
284 memcpy(dataptr
+17,fsname
,8);
289 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
293 INT_BARF( context
, 0x21 );
298 static void INT21_GetSystemDate( CONTEXT
*context
)
301 GetLocalTime( &systime
);
302 CX_reg(context
) = systime
.wYear
;
303 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
304 AX_reg(context
) = systime
.wDayOfWeek
;
307 static void INT21_GetSystemTime( CONTEXT
*context
)
310 GetLocalTime( &systime
);
311 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
312 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
315 /* Many calls translate a drive argument like this:
316 drive number (00h = default, 01h = A:, etc)
318 static char drivestring
[]="default";
320 char *INT21_DriveName(int drive
)
325 drivestring
[0]= (unsigned char)drive
+ '@';
331 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
333 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
334 DX_reg(context
) ), CX_reg(context
) );
335 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
339 static void OpenExistingFile( CONTEXT
*context
)
341 AX_reg(context
) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
343 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
345 AX_reg(context
) = DOS_ExtendedError
;
354 switch (AX_reg(context
) & 0x0070)
356 case 0x00: /* compatability mode */
357 case 0x40: /* DENYNONE */
361 case 0x30: /* DENYREAD */
362 TRACE(int21
, "(%s): DENYREAD changed to DENYALL\n",
363 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
364 case 0x10: /* DENYALL */
368 case 0x20: /* DENYWRITE */
379 int result
,retries
=sharing_retries
;
381 #if defined(__svr4__) || defined(_SCO_DS)
382 ERR(int21
, "Should call flock and needs porting to lockf\n");
386 result
= flock(handle
, lock
| LOCK_NB
);
388 if ( retries
&& (!result
) )
391 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
392 result
++; /* stop the optimizer */
393 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
397 while( (!result
) && (!(retries
--)) );
402 AX_reg(context
) = DOS_ExtendedError
;
411 AX_reg(context
) = handle
;
412 RESET_CFLAG(context
);
417 static void CloseFile( CONTEXT
*context
)
419 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
421 AX_reg(context
) = DOS_ExtendedError
;
426 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
428 BOOL32 bExtendedError
= FALSE
;
429 BYTE action
= DL_reg(context
);
431 /* Shuffle arguments to call OpenExistingFile */
432 AL_reg(context
) = BL_reg(context
);
433 DX_reg(context
) = SI_reg(context
);
434 /* BX,CX and DX should be preserved */
435 OpenExistingFile(context
);
437 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
439 UINT16 uReturnCX
= 0;
441 /* Now decide what do do */
443 if ((action
& 0x07) == 0)
445 BX_reg(context
) = AX_reg(context
);
447 AX_reg(context
) = 0x0050; /*File exists*/
449 WARN(int21
, "extended open/create: failed because file exists \n");
451 else if ((action
& 0x07) == 2)
453 /* Truncate it, but first check if opened for write */
454 if ((BL_reg(context
) & 0x0007)== 0)
456 BX_reg(context
) = AX_reg(context
);
458 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
459 AX_reg(context
) = 0x000C; /*Access code invalid*/
464 /* Shuffle arguments to call CloseFile while
465 * preserving BX and DX */
467 TRACE(int21
, "extended open/create: Closing before truncate\n");
468 BX_reg(context
) = AX_reg(context
);
470 if (EFL_reg(context
) & 0x0001)
472 WARN(int21
, "extended open/create: close before trunc failed\n");
473 AX_reg(context
) = 0x0019; /*Seek Error*/
477 /* Shuffle arguments to call CreateFile */
479 TRACE(int21
, "extended open/create: Truncating\n");
480 AL_reg(context
) = BL_reg(context
);
481 /* CX is still the same */
482 DX_reg(context
) = SI_reg(context
);
483 bExtendedError
= INT21_CreateFile(context
);
485 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
487 WARN(int21
, "extended open/create: trunc failed\n");
488 return bExtendedError
;
493 else uReturnCX
= 0x1;
495 CX_reg(context
) = uReturnCX
;
497 else /* file does not exist */
499 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
500 if ((action
& 0xF0)== 0)
504 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
508 /* Shuffle arguments to call CreateFile */
509 TRACE(int21
, "extended open/create: Creating\n");
510 AL_reg(context
) = BL_reg(context
);
511 /* CX should still be the same */
512 DX_reg(context
) = SI_reg(context
);
513 bExtendedError
= INT21_CreateFile(context
);
514 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
516 WARN(int21
, "extended open/create: create failed\n");
517 return bExtendedError
;
523 return bExtendedError
;
527 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
530 char *dirname
= PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
));
532 TRACE(int21
,"changedir %s\n", dirname
);
533 if (dirname
[0] && (dirname
[1] == ':'))
535 drive
= toupper(dirname
[0]) - 'A';
538 else drive
= DRIVE_GetCurrentDrive();
539 return DRIVE_Chdir( drive
, dirname
);
543 static int INT21_FindFirst( CONTEXT
*context
)
547 DOS_FULL_NAME full_name
;
548 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
550 path
= (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
551 dta
->unixPath
= NULL
;
552 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
554 AX_reg(context
) = DOS_ExtendedError
;
558 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
559 p
= strrchr( dta
->unixPath
, '/' );
562 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
563 * (doesn't matter as it is set below anyway)
565 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
567 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
568 dta
->unixPath
= NULL
;
569 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
570 AX_reg(context
) = ER_FileNotFound
;
574 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
575 : DRIVE_GetCurrentDrive();
577 dta
->search_attr
= CL_reg(context
);
582 static int INT21_FindNext( CONTEXT
*context
)
584 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA();
585 WIN32_FIND_DATA32A entry
;
588 if (!dta
->unixPath
) return 0;
589 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
590 dta
->search_attr
, dta
->count
, &entry
)))
592 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
593 dta
->unixPath
= NULL
;
596 if ((int)dta
->count
+ count
> 0xffff)
598 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
599 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
600 dta
->unixPath
= NULL
;
604 dta
->fileattr
= entry
.dwFileAttributes
;
605 dta
->filesize
= entry
.nFileSizeLow
;
606 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
607 &dta
->filedate
, &dta
->filetime
);
608 strcpy( dta
->filename
, entry
.cAlternateFileName
);
613 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
615 static int counter
= 0;
616 char *name
= PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
) );
617 char *p
= name
+ strlen(name
);
619 /* despite what Ralf Brown says, some programs seem to call without
620 * ending backslash (DOS accepts that, so we accept it too) */
621 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
625 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
626 counter
= (counter
+ 1) % 1000;
628 if ((AX_reg(context
) = _lcreat_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
630 TRACE(int21
, "created %s\n", name
);
633 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
638 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
640 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
641 char *ptr
= (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
) );
643 if (!DRIVE_IsValid(drive
))
645 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
648 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
649 AX_reg(context
) = 0x0100; /* success return code */
654 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
656 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
657 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
659 if (!DRIVE_IsValid(drive
))
661 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
665 *(WORD
*)dataptr
= 0;
666 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
667 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
668 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
673 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
675 BYTE
*dataptr
= PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
676 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
678 if (!DRIVE_IsValid(drive
))
680 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
684 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
689 /* microsoft's programmers should be shot for using CP/M style int21
690 calls in Windows for Workgroup's winfile.exe */
692 static int INT21_FindFirstFCB( CONTEXT
*context
)
694 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
699 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
700 else pFCB
= (FINDFILE_FCB
*)fcb
;
701 drive
= DOS_GET_DRIVE( pFCB
->drive
);
702 root
= DRIVE_GetRoot( drive
);
703 cwd
= DRIVE_GetUnixCwd( drive
);
704 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
705 strlen(root
)+strlen(cwd
)+2 );
706 if (!pFCB
->unixPath
) return 0;
707 strcpy( pFCB
->unixPath
, root
);
708 strcat( pFCB
->unixPath
, "/" );
709 strcat( pFCB
->unixPath
, cwd
);
715 static int INT21_FindNextFCB( CONTEXT
*context
)
717 BYTE
*fcb
= (BYTE
*)PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
));
719 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA();
720 WIN32_FIND_DATA32A entry
;
724 if (*fcb
== 0xff) /* extended FCB ? */
727 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
732 pFCB
= (FINDFILE_FCB
*)fcb
;
735 if (!pFCB
->unixPath
) return 0;
736 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
737 DOS_GET_DRIVE( pFCB
->drive
), attr
,
738 pFCB
->count
, &entry
)))
740 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
741 pFCB
->unixPath
= NULL
;
744 pFCB
->count
+= count
;
746 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
747 *(BYTE
*)pResult
= 0xff;
748 (BYTE
*)pResult
+=6; /* leave reserved field behind */
749 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
752 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
754 pResult
->fileattr
= entry
.dwFileAttributes
;
755 pResult
->cluster
= 0; /* what else? */
756 pResult
->filesize
= entry
.nFileSizeLow
;
757 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
758 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
759 &pResult
->filedate
, &pResult
->filetime
);
761 /* Convert file name to FCB format */
763 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
764 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
765 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
766 pResult
->filename
[0] = pResult
->filename
[1] = '.';
769 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
770 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
772 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
773 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
774 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
777 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
778 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
784 static void DeleteFileFCB( CONTEXT
*context
)
786 FIXME(int21
, "(%p): not implemented yet\n", context
);
789 static void RenameFileFCB( CONTEXT
*context
)
791 FIXME(int21
, "(%p): not implemented yet\n", context
);
796 static void fLock( CONTEXT
* context
)
799 switch ( AX_reg(context
) & 0xff )
801 case 0x00: /* LOCK */
802 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
804 MAKELONG(DX_reg(context
),CX_reg(context
)),
805 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
806 if (!LockFile(BX_reg(context
),
807 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
808 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
809 AX_reg(context
) = DOS_ExtendedError
;
814 case 0x01: /* UNLOCK */
815 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
817 MAKELONG(DX_reg(context
),CX_reg(context
)),
818 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
819 if (!UnlockFile(BX_reg(context
),
820 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
821 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
822 AX_reg(context
) = DOS_ExtendedError
;
827 AX_reg(context
) = 0x0001;
834 INT21_networkfunc (CONTEXT
*context
)
836 switch (AL_reg(context
)) {
837 case 0x00: /* Get machine name. */
839 char *dst
= PTR_SEG_OFF_TO_LIN (DS_reg(context
),DX_reg(context
));
840 TRACE(int21
, "getting machine name to %p\n", dst
);
841 if (gethostname (dst
, 15))
843 WARN(int21
,"failed!\n");
844 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
847 int len
= strlen (dst
);
851 CH_reg(context
) = 1; /* Valid */
852 CL_reg(context
) = 1; /* NETbios number??? */
853 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
859 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
865 SEGPTR
INT21_GetListOfLists()
867 static DOS_LISTOFLISTS
*LOL
;
868 static SEGPTR seg_LOL
;
873 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
874 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
875 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
876 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
877 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
878 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
879 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
880 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
881 0133:00A0 D0 44 C8 FD D0 44 .D...D
884 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
886 LOL
->CX_Int21_5e01
= 0x0;
887 LOL
->LRU_count_FCB_cache
= 0x0;
888 LOL
->LRU_count_FCB_open
= 0x0;
889 LOL
->OEM_func_handler
= -1; /* not available */
890 LOL
->INT21_offset
= 0x0;
891 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
892 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
893 LOL
->ptr_disk_buf
= 0x0;
894 LOL
->offs_unread_CON
= 0x0;
895 LOL
->seg_first_MCB
= 0x0;
896 LOL
->ptr_first_DPB
= 0x0;
897 LOL
->ptr_first_SysFileTable
= 0x0;
898 LOL
->ptr_clock_dev_hdr
= 0x0;
899 LOL
->ptr_CON_dev_hdr
= 0x0;
900 LOL
->max_byte_per_sec
= 512;
901 LOL
->ptr_disk_buf_info
= 0x0;
902 LOL
->ptr_array_CDS
= 0x0;
903 LOL
->ptr_sys_FCB
= 0x0;
904 LOL
->nr_protect_FCB
= 0x0;
905 LOL
->nr_block_dev
= 0x0;
906 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
907 LOL
->nr_drives_JOINed
= 0x0;
908 LOL
->ptr_spec_prg_names
= 0x0;
909 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
910 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
911 LOL
->PSP_last_exec
= 0x0;
912 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
913 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
914 LOL
->boot_drive
= 3; /* C: */
915 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
916 LOL
->size_extended_mem
= 0xf000; /* very high value */
918 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
919 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
922 /***********************************************************************
923 * DOS3Call (KERNEL.102)
925 void WINAPI
DOS3Call( CONTEXT
*context
)
927 BOOL32 bSetDOSExtendedError
= FALSE
;
930 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
931 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
932 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
933 SI_reg(context
), DI_reg(context
),
934 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
938 if (AH_reg(context
) == 0x59) /* Get extended error info */
940 TRACE(int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
941 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
942 AX_reg(context
) = DOS_ExtendedError
;
943 BH_reg(context
) = DOS_ErrorClass
;
944 BL_reg(context
) = DOS_ErrorAction
;
945 CH_reg(context
) = DOS_ErrorLocus
;
949 DOS_ERROR( 0, 0, 0, 0 );
950 RESET_CFLAG(context
); /* Not sure if this is a good idea */
952 switch(AH_reg(context
))
954 case 0x00: /* TERMINATE PROGRAM */
955 TRACE(int21
,"TERMINATE PROGRAM\n");
956 TASK_KillCurrentTask( 0 );
959 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
960 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
961 case 0x03: /* READ CHARACTER FROM STDAUX */
962 case 0x04: /* WRITE CHARACTER TO STDAUX */
963 case 0x05: /* WRITE CHARACTER TO PRINTER */
964 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
965 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
966 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
967 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
968 case 0x0a: /* BUFFERED INPUT */
969 case 0x0b: /* GET STDIN STATUS */
970 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
971 case 0x0f: /* OPEN FILE USING FCB */
972 case 0x10: /* CLOSE FILE USING FCB */
973 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
974 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
975 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
976 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
977 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
978 case 0x23: /* GET FILE SIZE FOR FCB */
979 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
980 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
981 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
982 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
983 case 0x29: /* PARSE FILENAME INTO FCB */
984 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
985 "SWITCHAR" - SET SWITCH CHARACTER
986 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
987 case 0x54: /* GET VERIFY FLAG */
988 case 0x48: /* ALLOCATE MEMORY */
989 case 0x49: /* FREE MEMORY */
990 case 0x4a: /* RESIZE MEMORY BLOCK */
991 INT_BARF( context
, 0x21 );
993 case 0x2e: /* SET VERIFY FLAG */
994 TRACE(int21
,"SET VERIFY FLAG ignored\n");
995 /* we cannot change the behaviour anyway, so just ignore it */
998 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1002 case 0x6b: /* NULL FUNCTION */
1003 AL_reg(context
) = 0;
1006 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1010 case 0x0d: /* DISK BUFFER FLUSH */
1011 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1012 RESET_CFLAG(context
); /* dos 6+ only */
1015 case 0x0e: /* SELECT DEFAULT DRIVE */
1016 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1017 DRIVE_SetCurrentDrive( DL_reg(context
) );
1018 AL_reg(context
) = MAX_DOS_DRIVES
;
1021 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1022 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1023 PTR_SEG_OFF_TO_LIN(DS_reg(context
), DX_reg(context
)));
1024 if (!INT21_FindFirstFCB(context
))
1026 AL_reg(context
) = 0xff;
1029 /* else fall through */
1031 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1032 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1035 case 0x13: /* DELETE FILE USING FCB */
1036 DeleteFileFCB(context
);
1039 case 0x17: /* RENAME FILE USING FCB */
1040 RenameFileFCB(context
);
1043 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1044 AL_reg(context
) = DRIVE_GetCurrentDrive();
1047 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1049 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1050 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1051 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1055 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1056 DL_reg(context
) = 0;
1057 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1060 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1061 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1064 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1065 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1068 case 0x25: /* SET INTERRUPT VECTOR */
1069 INT_SetHandler( AL_reg(context
),
1070 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1074 case 0x2a: /* GET SYSTEM DATE */
1075 INT21_GetSystemDate(context
);
1078 case 0x2b: /* SET SYSTEM DATE */
1079 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1080 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1081 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1084 case 0x2c: /* GET SYSTEM TIME */
1085 INT21_GetSystemTime(context
);
1088 case 0x2d: /* SET SYSTEM TIME */
1089 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1090 CH_reg(context
), CL_reg(context
),
1091 DH_reg(context
), DL_reg(context
) );
1092 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1095 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1096 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1098 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1099 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1100 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1104 case 0x30: /* GET DOS VERSION */
1105 TRACE(int21
,"GET DOS VERSION %s requested\n",
1106 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1107 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1108 (HIWORD(GetVersion16()) << 8);
1109 BX_reg(context
) = 0x0012; /* 0x123456 is Wine's serial # */
1110 CX_reg(context
) = 0x3456;
1113 case 0x31: /* TERMINATE AND STAY RESIDENT */
1114 TRACE(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1115 INT_BARF( context
, 0x21 );
1118 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1119 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1120 INT21_DriveName( DL_reg(context
)));
1121 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1124 case 0x33: /* MULTIPLEXED */
1125 switch (AL_reg(context
))
1127 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1128 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE stub\n");
1129 DL_reg(context
) = 0;
1132 case 0x01: /* SET EXTENDED BREAK STATE */
1133 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE stub\n");
1136 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1137 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1138 DL_reg(context
) = 0;
1141 case 0x05: /* GET BOOT DRIVE */
1142 TRACE(int21
,"GET BOOT DRIVE\n");
1143 DL_reg(context
) = 3;
1144 /* c: is Wine's bootdrive (a: is 1)*/
1147 case 0x06: /* GET TRUE VERSION NUMBER */
1148 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1149 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1150 (HIWORD(GetVersion16() << 8));
1151 DX_reg(context
) = 0x00;
1155 INT_BARF( context
, 0x21 );
1160 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1161 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1162 if (!heap
) INT21_CreateHeap();
1163 ES_reg(context
) = DosHeapHandle
;
1164 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1167 case 0x35: /* GET INTERRUPT VECTOR */
1168 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1170 FARPROC16 addr
= INT_GetHandler( AL_reg(context
) );
1171 ES_reg(context
) = SELECTOROF(addr
);
1172 BX_reg(context
) = OFFSETOF(addr
);
1176 case 0x36: /* GET FREE DISK SPACE */
1177 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1178 INT21_DriveName( DL_reg(context
)));
1179 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1182 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1183 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1185 AX_reg(context
) = 0x02; /* no country support available */
1189 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1190 TRACE(int21
,"MKDIR %s\n",
1191 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1192 bSetDOSExtendedError
= (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1193 DX_reg(context
) ), NULL
));
1196 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1197 TRACE(int21
,"RMDIR %s\n",
1198 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1199 bSetDOSExtendedError
= (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1200 DX_reg(context
) )));
1203 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1204 TRACE(int21
,"CHDIR %s\n",
1205 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1206 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1209 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1210 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1211 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1212 AX_reg(context
) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1213 DX_reg(context
) ), CX_reg(context
) );
1214 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1217 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1218 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1219 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1220 OpenExistingFile(context
);
1223 case 0x3e: /* "CLOSE" - CLOSE FILE */
1224 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1225 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1228 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1229 TRACE(int21
,"READ from %d to %ld for %d byte\n",BX_reg(context
),
1230 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),DX_reg(context
)),CX_reg(context
) );
1232 LONG result
= WIN16_hread( BX_reg(context
),
1233 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1236 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1237 else AX_reg(context
) = (WORD
)result
;
1241 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1242 TRACE(int21
,"WRITE from %ld to handle %d for %d byte\n",
1243 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),DX_reg(context
)),
1244 BX_reg(context
),CX_reg(context
) );
1246 LONG result
= _hwrite16( BX_reg(context
),
1247 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1250 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1251 else AX_reg(context
) = (WORD
)result
;
1255 case 0x41: /* "UNLINK" - DELETE FILE */
1256 TRACE(int21
,"UNLINK%s\n",
1257 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1258 bSetDOSExtendedError
= (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1259 DX_reg(context
) )));
1262 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1263 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1264 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1265 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1266 "current file position":"end of file");
1268 LONG status
= _llseek16( BX_reg(context
),
1269 MAKELONG(DX_reg(context
),CX_reg(context
)),
1271 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1274 AX_reg(context
) = LOWORD(status
);
1275 DX_reg(context
) = HIWORD(status
);
1280 case 0x43: /* FILE ATTRIBUTES */
1281 switch (AL_reg(context
))
1284 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1285 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1286 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1287 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1289 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1290 else CX_reg(context
) = AX_reg(context
);
1294 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1295 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1296 bSetDOSExtendedError
=
1297 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1302 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1303 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1307 case 0x44: /* IOCTL */
1308 switch (AL_reg(context
))
1311 ioctlGetDeviceInfo(context
);
1316 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1317 /*BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));*/
1318 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1320 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1321 /* for (i=0;i<CX_reg(context);i++)
1322 fprintf(stdnimp,"%02x ",dataptr[i]);
1323 fprintf(stdnimp,"\n");*/
1324 AX_reg(context
)=CX_reg(context
);
1327 case 0x08: /* Check if drive is removable. */
1328 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1329 INT21_DriveName( BL_reg(context
)));
1330 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1332 case DRIVE_CANNOTDETERMINE
:
1333 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1334 AX_reg(context
) = ER_InvalidDrive
;
1337 case DRIVE_REMOVABLE
:
1338 AX_reg(context
) = 0; /* removable */
1341 AX_reg(context
) = 1; /* not removable */
1346 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1347 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1348 INT21_DriveName( BL_reg(context
)));
1349 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1351 case DRIVE_CANNOTDETERMINE
:
1352 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1353 AX_reg(context
) = ER_InvalidDrive
;
1357 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1360 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1365 case 0x0a: /* check if handle (BX) is remote */
1366 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1367 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1370 DX_reg(context
) = 0;
1373 case 0x0b: /* SET SHARING RETRY COUNT */
1374 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1375 CX_reg(context
), DX_reg(context
));
1376 if (!CX_reg(context
))
1378 AX_reg(context
) = 1;
1382 sharing_pause
= CX_reg(context
);
1383 if (!DX_reg(context
))
1384 sharing_retries
= DX_reg(context
);
1385 RESET_CFLAG(context
);
1389 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1390 INT21_DriveName( BL_reg(context
)));
1391 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1394 case 0x0e: /* get logical drive mapping */
1395 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1396 INT21_DriveName( BL_reg(context
)));
1397 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1400 case 0x0F: /* Set logical drive mapping */
1403 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1404 INT21_DriveName( BL_reg(context
)));
1405 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1406 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1409 AX_reg(context
) = 0x000F; /* invalid drive */
1415 INT_BARF( context
, 0x21 );
1420 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1421 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1422 bSetDOSExtendedError
= ((AX_reg(context
) = FILE_Dup(BX_reg(context
))) == (WORD
)HFILE_ERROR16
);
1425 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1426 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1427 BX_reg(context
),CX_reg(context
));
1428 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR32
);
1431 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1432 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1433 INT21_DriveName( DL_reg(context
)));
1434 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1437 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1438 TRACE(int21
,"EXEC %s\n",
1439 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
) ));
1440 AX_reg(context
) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1443 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1446 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1447 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1448 TASK_KillCurrentTask( AL_reg(context
) );
1451 case 0x4d: /* GET RETURN CODE */
1452 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1453 AX_reg(context
) = 0; /* normal exit */
1456 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1457 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1458 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1459 if (!INT21_FindFirst(context
)) break;
1462 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1463 TRACE(int21
,"FINDNEXT\n");
1464 if (!INT21_FindNext(context
))
1466 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1467 AX_reg(context
) = ER_NoMoreFiles
;
1470 else AX_reg(context
) = 0; /* OK */
1473 case 0x51: /* GET PSP ADDRESS */
1474 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1475 /* FIXME: should we return the original DOS PSP upon */
1476 /* Windows startup ? */
1477 BX_reg(context
) = GetCurrentPDB();
1479 case 0x62: /* GET PSP ADDRESS */
1480 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1481 /* FIXME: should we return the original DOS PSP upon */
1482 /* Windows startup ? */
1483 BX_reg(context
) = GetCurrentPDB();
1486 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1487 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1490 lol
= INT21_GetListOfLists();
1491 ES_reg(context
) = HIWORD(lol
);
1492 BX_reg(context
) = LOWORD(lol
);
1496 case 0x56: /* "RENAME" - RENAME FILE */
1497 TRACE(int21
,"RENAME %s to %s\n",
1498 (LPCSTR
)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1499 (LPCSTR
)PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
)));
1500 bSetDOSExtendedError
=
1501 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1502 PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
))));
1505 case 0x57: /* FILE DATE AND TIME */
1506 switch (AL_reg(context
))
1508 case 0x00: /* Get */
1511 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1513 if (!GetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
))
1514 bSetDOSExtendedError
= TRUE
;
1515 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1520 case 0x01: /* Set */
1523 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1525 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1527 bSetDOSExtendedError
=
1528 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1534 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1535 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1537 switch (AL_reg(context
))
1540 AX_reg(context
) = 1;
1543 AX_reg(context
) = 0;
1549 RESET_CFLAG(context
);
1552 case 0x5a: /* CREATE TEMPORARY FILE */
1553 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1554 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1557 case 0x5b: /* CREATE NEW FILE */
1558 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1559 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1560 bSetDOSExtendedError
= ((AX_reg(context
) =
1561 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)), 0 ))
1562 == (WORD
)HFILE_ERROR16
);
1565 case 0x5d: /* NETWORK */
1566 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1567 /* Fix the following while you're at it. */
1568 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1569 bSetDOSExtendedError
= TRUE
;
1573 bSetDOSExtendedError
= INT21_networkfunc (context
);
1576 case 0x5f: /* NETWORK */
1577 switch (AL_reg(context
))
1579 case 0x07: /* ENABLE DRIVE */
1580 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1581 if (!DRIVE_Enable( DL_reg(context
) ))
1583 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1584 bSetDOSExtendedError
= TRUE
;
1588 case 0x08: /* DISABLE DRIVE */
1589 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1590 if (!DRIVE_Disable( DL_reg(context
) ))
1592 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1593 bSetDOSExtendedError
= TRUE
;
1598 /* network software not installed */
1599 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1600 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1601 bSetDOSExtendedError
= TRUE
;
1606 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1607 TRACE(int21
,"TRUENAME %s\n",
1608 (LPCSTR
)PTR_SEG_OFF_TO_LIN(DS_reg(context
),SI_reg(context
)));
1610 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1611 SI_reg(context
)), 128,
1612 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1613 DI_reg(context
)),NULL
))
1614 bSetDOSExtendedError
= TRUE
;
1615 else AX_reg(context
) = 0;
1619 case 0x61: /* UNUSED */
1620 case 0x63: /* UNUSED */
1621 case 0x64: /* OS/2 DOS BOX */
1622 INT_BARF( context
, 0x21 );
1626 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1627 extern WORD WINE_LanguageId
;
1628 BYTE
*dataptr
=PTR_SEG_OFF_TO_LIN(ES_reg(context
),DI_reg(context
));
1629 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1630 BX_reg(context
), DX_reg(context
));
1631 switch (AL_reg(context
)) {
1633 TRACE(int21
,"\tget general internationalization info\n");
1635 *(WORD
*)(dataptr
+1) = 41;
1636 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1637 *(WORD
*)(dataptr
+5) = CodePage
;
1638 *(DWORD
*)(dataptr
+0x19) = NULL
; /* FIXME: ptr to case map routine */
1641 TRACE(int21
,"\tget pointer to collating sequence table\n");
1643 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1644 CX_reg(context
) = 258;/*FIXME: size of table?*/
1647 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1648 INT_BARF( context
, 0x21 );
1654 case 0x66: /* GLOBAL CODE PAGE TABLE */
1655 switch (AL_reg(context
))
1658 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
1659 DX_reg(context
) = BX_reg(context
) = CodePage
;
1660 RESET_CFLAG(context
);
1663 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1664 BX_reg(context
),DX_reg(context
));
1665 CodePage
= BX_reg(context
);
1666 RESET_CFLAG(context
);
1671 case 0x67: /* SET HANDLE COUNT */
1672 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
1673 SetHandleCount16( BX_reg(context
) );
1674 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1677 case 0x68: /* "FFLUSH" - COMMIT FILE */
1678 case 0x6a: /* COMMIT FILE */
1679 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
1680 bSetDOSExtendedError
= (!FlushFileBuffers( BX_reg(context
) ));
1683 case 0x69: /* DISK SERIAL NUMBER */
1684 switch (AL_reg(context
))
1687 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
1688 INT21_DriveName(BL_reg(context
)));
1689 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1690 else AX_reg(context
) = 0;
1694 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
1695 INT21_DriveName(BL_reg(context
)));
1696 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1697 else AX_reg(context
) = 1;
1702 case 0x6C: /* Extended Open/Create*/
1703 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
1704 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DI_reg(context
)));
1705 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1708 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1709 switch(AL_reg(context
))
1711 case 0x39: /* Create directory */
1712 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
1713 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1714 bSetDOSExtendedError
= (!CreateDirectory32A(
1715 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1716 DX_reg(context
) ), NULL
));
1718 case 0x3a: /* Remove directory */
1719 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1720 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1721 bSetDOSExtendedError
= (!RemoveDirectory32A(
1722 PTR_SEG_OFF_TO_LIN( DS_reg(context
),
1723 DX_reg(context
) )));
1725 case 0x43: /* Get/Set file attributes */
1726 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1727 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1728 switch (BL_reg(context
))
1730 case 0x00: /* Get file attributes */
1731 TRACE(int21
,"\tretrieve attributes\n");
1732 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1733 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1735 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1738 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
1739 bSetDOSExtendedError
= (!SetFileAttributes32A(
1740 PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1742 CX_reg(context
) ) );
1745 FIXME(int21
, "Unimplemented long file name function:\n");
1746 INT_BARF( context
, 0x21 );
1748 AL_reg(context
) = 0;
1752 case 0x47: /* Get current directory */
1753 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1754 INT21_DriveName(DL_reg(context
)));
1755 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1758 case 0x4e: /* Find first file */
1759 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1760 (LPCSTR
)PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)));
1761 /* FIXME: use attributes in CX */
1762 if ((AX_reg(context
) = FindFirstFile16(
1763 PTR_SEG_OFF_TO_LIN(DS_reg(context
),DX_reg(context
)),
1764 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1766 == INVALID_HANDLE_VALUE16
)
1767 bSetDOSExtendedError
= TRUE
;
1769 case 0x4f: /* Find next file */
1770 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1772 if (!FindNextFile16( BX_reg(context
),
1773 (WIN32_FIND_DATA32A
*)PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1775 bSetDOSExtendedError
= TRUE
;
1777 case 0xa1: /* Find close */
1778 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
1780 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
1783 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
1784 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
),DX_reg(context
)));
1787 switch(CL_reg(context
))
1789 case 0x02: /*Get canonical long filename or path */
1790 if (!GetFullPathName32A
1791 ( PTR_SEG_OFF_TO_LIN(DS_reg(context
),
1792 SI_reg(context
)), 128,
1793 PTR_SEG_OFF_TO_LIN(ES_reg(context
),
1794 DI_reg(context
)),NULL
))
1795 bSetDOSExtendedError
= TRUE
;
1796 else AX_reg(context
) = 0;
1799 FIXME(int21
, "Unimplemented long file name function:\n");
1800 INT_BARF( context
, 0x21 );
1802 AL_reg(context
) = 0;
1806 case 0x6c: /* Create or open file */
1807 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
1808 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), SI_reg(context
)));
1809 /* translate Dos 7 action to Dos 6 action */
1810 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1813 case 0x3b: /* Change directory */
1814 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
1815 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1816 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1822 AL_reg(context
) = DOS_ExtendedError
;
1825 case 0x41: /* Delete file */
1826 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
1827 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)));
1828 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1833 AL_reg(context
) = DOS_ExtendedError
;
1836 case 0x56: /* Move (rename) file */
1837 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
1838 (LPCSTR
)PTR_SEG_OFF_TO_LIN( DS_reg(context
), DX_reg(context
)),
1839 (LPCSTR
)PTR_SEG_OFF_TO_LIN( ES_reg(context
), DI_reg(context
)));
1841 FIXME(int21
, "Unimplemented long file name function:\n");
1842 INT_BARF( context
, 0x21 );
1844 AL_reg(context
) = 0;
1849 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1850 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1851 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1852 TRACE(int21
,"windows95 function AX %04x\n",
1854 WARN(int21
, " returning unimplemented\n");
1856 AL_reg(context
) = 0;
1859 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1860 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1864 INT_BARF( context
, 0x21 );
1867 } /* END OF SWITCH */
1869 if( bSetDOSExtendedError
) /* set general error condition */
1871 AX_reg(context
) = DOS_ExtendedError
;
1875 if ((EFL_reg(context
) & 0x0001))
1876 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1877 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
1879 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1880 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1881 AX_reg(context
), BX_reg(context
), CX_reg(context
),
1882 DX_reg(context
), SI_reg(context
), DI_reg(context
),
1883 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1887 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
1889 FIXME(int21
, "(DosProc=%08x);\n", (UINT32
)DosProc
);