2 * DOS interrupt 21h handler
10 # include <sys/file.h>
15 #include <sys/types.h>
21 #include "winuser.h" /* SW_NORMAL */
22 #include "wine/winbase16.h"
32 #include "dosexe.h" /* for the MZ_SUPPORTED define */
36 #if defined(__svr4__) || defined(_SCO_DS)
37 /* SVR4 DOESNT do locking the same way must implement properly */
44 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
46 /* Define the drive parameter block, as used by int21/1F
47 * and int21/32. This table can be accessed through the
48 * global 'dpb' pointer, which points into the local dos
53 BYTE drive_num
; /* 0=A, etc. */
54 BYTE unit_num
; /* Drive's unit number (?) */
55 WORD sector_size
; /* Sector size in bytes */
56 BYTE high_sector
; /* Highest sector in a cluster */
57 BYTE shift
; /* Shift count (?) */
58 WORD reserved
; /* Number of reserved sectors at start */
59 BYTE num_FAT
; /* Number of FATs */
60 WORD dir_entries
; /* Number of root dir entries */
61 WORD first_data
; /* First data sector */
62 WORD high_cluster
; /* Highest cluster number */
63 WORD sectors_in_FAT
; /* Number of sectors per FAT */
64 WORD start_dir
; /* Starting sector of first dir */
65 DWORD driver_head
; /* Address of device driver header (?) */
66 BYTE media_ID
; /* Media ID */
67 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
68 DWORD next
; /* Pointer to next DPB in list */
69 WORD free_search
; /* Free cluster search start */
70 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
81 BYTE DummyDBCSLeadTable
[6];
83 static struct DosHeap
*heap
;
84 static WORD DosHeapHandle
;
86 WORD sharing_retries
= 3; /* number of retries at sharing violation */
87 WORD sharing_pause
= 1; /* pause between retries */
89 extern char TempDirectory
[];
91 static BOOL
INT21_CreateHeap(void)
93 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
95 WARN(int21
, "Out of memory\n");
98 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
99 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
101 strcpy(heap
->biosdate
, "01/01/80");
102 memset(heap
->DummyDBCSLeadTable
, 0, 6);
106 static BYTE
*GetCurrentDTA( CONTEXT
*context
)
108 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
110 /* FIXME: This assumes DTA was set correctly! */
111 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
112 (DWORD
)OFFSETOF(pTask
->dta
) );
116 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
117 /* limited == TRUE is used with INT 0x21/0x440d */
122 setword(&data
[3], 0);
124 setword(&data
[6], 240);
125 setword(&data
[8], 64000);
127 setword(&data
[0x0b], 40);
128 setword(&data
[0x0d], 56);
129 setword(&data
[0x0f], 2);
130 setword(&data
[0x11], 0);
132 setword(&data
[0x1f], 800);
134 setword(&data
[0x22], 1);
136 } else { /* 1.44mb */
139 setword(&data
[3], 0);
141 setword(&data
[6], 240);
142 setword(&data
[8], 2880);
144 setword(&data
[0x0b], 6);
145 setword(&data
[0x0d], 18);
146 setword(&data
[0x0f], 2);
147 setword(&data
[0x11], 0);
149 setword(&data
[0x1f], 80);
151 setword(&data
[0x22], 2);
156 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
158 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
159 char root
[] = "A:\\";
161 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
162 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
163 &free_clusters
, &total_clusters
)) return 0;
164 AX_reg(context
) = cluster_sectors
;
165 BX_reg(context
) = free_clusters
;
166 CX_reg(context
) = sector_bytes
;
167 DX_reg(context
) = total_clusters
;
171 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
173 if (!INT21_GetFreeDiskSpace( context
)) return 0;
174 if (!heap
&& !INT21_CreateHeap()) return 0;
175 heap
->mediaID
= 0xf0;
176 DS_reg(context
) = DosHeapHandle
;
177 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
181 static void GetDrivePB( CONTEXT
*context
, int drive
)
183 if(!DRIVE_IsValid(drive
))
185 SetLastError( ERROR_INVALID_DRIVE
);
186 AX_reg(context
) = 0x00ff;
188 else if (heap
|| INT21_CreateHeap())
190 FIXME(int21
, "GetDrivePB not fully implemented.\n");
192 /* FIXME: I have no idea what a lot of this information should
193 * say or whether it even really matters since we're not allowing
194 * direct block access. However, some programs seem to depend on
195 * getting at least _something_ back from here. The 'next' pointer
196 * does worry me, though. Should we have a complete table of
197 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
199 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
200 heap
->dpb
.sector_size
= 512;
201 heap
->dpb
.high_sector
= 1;
202 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
203 heap
->dpb
.reserved
= 0;
204 heap
->dpb
.num_FAT
= 1;
205 heap
->dpb
.dir_entries
= 2;
206 heap
->dpb
.first_data
= 2;
207 heap
->dpb
.high_cluster
= 64000;
208 heap
->dpb
.sectors_in_FAT
= 1;
209 heap
->dpb
.start_dir
= 1;
210 heap
->dpb
.driver_head
= 0;
211 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
212 heap
->dpb
.access_flag
= 0;
214 heap
->dpb
.free_search
= 0;
215 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
217 AL_reg(context
) = 0x00;
218 DS_reg(context
) = SELECTOROF(dpbsegptr
);
219 BX_reg(context
) = OFFSETOF(dpbsegptr
);
224 static void ioctlGetDeviceInfo( CONTEXT
*context
)
227 const DOS_DEVICE
*dev
;
229 TRACE(int21
, "(%d)\n", BX_reg(context
));
231 RESET_CFLAG(context
);
234 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )))
236 DX_reg(context
) = dev
->flags
;
240 /* it seems to be a file */
241 curr_drive
= DRIVE_GetCurrentDrive();
242 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
244 /* bits 0-5 are current drive
245 * bit 6 - file has NOT been written..FIXME: correct?
246 * bit 8 - generate int24 if no diskspace on write/ read past end of file
247 * bit 11 - media not removable
248 * bit 14 - don't set file date/time on closing
249 * bit 15 - file is remote
253 static BOOL
ioctlGenericBlkDevReq( CONTEXT
*context
)
255 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
256 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
258 if (!DRIVE_IsValid(drive
))
260 SetLastError( ERROR_FILE_NOT_FOUND
);
264 if (CH_reg(context
) != 0x08)
266 INT_BARF( context
, 0x21 );
270 switch (CL_reg(context
))
272 case 0x4a: /* lock logical volume */
273 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
276 case 0x60: /* get device parameters */
277 /* used by w4wgrp's winfile */
278 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
280 dataptr
[6] = 0; /* media type */
283 dataptr
[1] = 0x05; /* fixed disk */
284 setword(&dataptr
[2], 0x01); /* non removable */
285 setword(&dataptr
[4], 0x300); /* # of cylinders */
289 dataptr
[1] = 0x07; /* block dev, floppy */
290 setword(&dataptr
[2], 0x02); /* removable */
291 setword(&dataptr
[4], 80); /* # of cylinders */
293 CreateBPB(drive
, &dataptr
[7], TRUE
);
294 RESET_CFLAG(context
);
297 case 0x41: /* write logical device track */
298 case 0x61: /* read logical device track */
300 BYTE drive
= BL_reg(context
) ?
301 BL_reg(context
) : DRIVE_GetCurrentDrive();
302 WORD head
= *(WORD
*)dataptr
+1;
303 WORD cyl
= *(WORD
*)dataptr
+3;
304 WORD sect
= *(WORD
*)dataptr
+5;
305 WORD nrsect
= *(WORD
*)dataptr
+7;
306 BYTE
*data
= (BYTE
*)dataptr
+9;
307 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
309 raw_func
= (CL_reg(context
) == 0x41) ?
310 DRIVE_RawWrite
: DRIVE_RawRead
;
312 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
313 RESET_CFLAG(context
);
316 AX_reg(context
) = 0x1e; /* read fault */
321 case 0x66:/* get disk serial number */
323 char label
[12],fsname
[9],path
[4];
326 strcpy(path
,"x:\\");path
[0]=drive
+'A';
327 GetVolumeInformationA(
328 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
331 memcpy(dataptr
+2,&serial
,4);
332 memcpy(dataptr
+6,label
,11);
333 memcpy(dataptr
+17,fsname
,8);
338 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
342 memset(dataptr
+1, '\0', dataptr
[0]-1);
343 dataptr
[1] = dataptr
[0];
344 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
345 dataptr
[3] = 0xFF; /* no physical drive */
349 /* Trail on error implementation */
350 AX_reg(context
) = GetDriveType16(BL_reg(context
)) == DRIVE_CANNOTDETERMINE
? 0x0f : 0x01;
351 SET_CFLAG(context
); /* Seems to be set all the time */
355 INT_BARF( context
, 0x21 );
360 static void INT21_ParseFileNameIntoFCB( CONTEXT
*context
)
363 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
365 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
366 char *buffer
, *s
, *d
;
368 AL_reg(context
) = 0xff; /* failed */
370 TRACE(int21
, "filename: '%s'\n", filename
);
372 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
378 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
385 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
387 TRACE(int21
, "FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
389 HeapFree( GetProcessHeap(), 0, buffer
);
392 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
394 /* point DS:SI to first unparsed character */
395 SI_reg(context
) += (int)s
- (int)filename
;
398 static void INT21_GetSystemDate( CONTEXT
*context
)
401 GetLocalTime( &systime
);
402 CX_reg(context
) = systime
.wYear
;
403 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
404 AX_reg(context
) = systime
.wDayOfWeek
;
407 static void INT21_GetSystemTime( CONTEXT
*context
)
410 GetLocalTime( &systime
);
411 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
412 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
415 /* Many calls translate a drive argument like this:
416 drive number (00h = default, 01h = A:, etc)
418 static char drivestring
[]="default";
420 char *INT21_DriveName(int drive
)
425 drivestring
[0]= (unsigned char)drive
+ '@';
431 static BOOL
INT21_CreateFile( CONTEXT
*context
)
433 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
434 EDX_reg(context
) ), CX_reg(context
) );
435 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
438 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
440 /* Mask off all flags not explicitly allowed by the doc */
441 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
442 return FILE_AllocDosHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
443 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
444 CREATE_NEW
, attr
, -1 ));
447 static void OpenExistingFile( CONTEXT
*context
)
449 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
451 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
453 AX_reg(context
) = GetLastError();
458 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
460 BOOL bExtendedError
= FALSE
;
461 BYTE action
= DL_reg(context
);
463 /* Shuffle arguments to call OpenExistingFile */
464 AL_reg(context
) = BL_reg(context
);
465 DX_reg(context
) = SI_reg(context
);
466 /* BX,CX and DX should be preserved */
467 OpenExistingFile(context
);
469 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
471 UINT16 uReturnCX
= 0;
473 /* Now decide what do do */
475 if ((action
& 0x07) == 0)
477 _lclose16( AX_reg(context
) );
478 AX_reg(context
) = 0x0050; /*File exists*/
480 WARN(int21
, "extended open/create: failed because file exists \n");
482 else if ((action
& 0x07) == 2)
484 /* Truncate it, but first check if opened for write */
485 if ((BL_reg(context
) & 0x0007)== 0)
487 _lclose16( AX_reg(context
) );
488 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
489 AX_reg(context
) = 0x000C; /*Access code invalid*/
494 TRACE(int21
, "extended open/create: Closing before truncate\n");
495 if (_lclose16( AX_reg(context
) ))
497 WARN(int21
, "extended open/create: close before trunc failed\n");
498 AX_reg(context
) = 0x0019; /*Seek Error*/
502 /* Shuffle arguments to call CreateFile */
504 TRACE(int21
, "extended open/create: Truncating\n");
505 AL_reg(context
) = BL_reg(context
);
506 /* CX is still the same */
507 DX_reg(context
) = SI_reg(context
);
508 bExtendedError
= INT21_CreateFile(context
);
510 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
512 WARN(int21
, "extended open/create: trunc failed\n");
513 return bExtendedError
;
518 else uReturnCX
= 0x1;
520 CX_reg(context
) = uReturnCX
;
522 else /* file does not exist */
524 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
525 if ((action
& 0xF0)== 0)
529 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
533 /* Shuffle arguments to call CreateFile */
534 TRACE(int21
, "extended open/create: Creating\n");
535 AL_reg(context
) = BL_reg(context
);
536 /* CX should still be the same */
537 DX_reg(context
) = SI_reg(context
);
538 bExtendedError
= INT21_CreateFile(context
);
539 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
541 WARN(int21
, "extended open/create: create failed\n");
542 return bExtendedError
;
548 return bExtendedError
;
552 static BOOL
INT21_ChangeDir( CONTEXT
*context
)
555 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
557 TRACE(int21
,"changedir %s\n", dirname
);
558 if (dirname
[0] && (dirname
[1] == ':'))
560 drive
= toupper(dirname
[0]) - 'A';
563 else drive
= DRIVE_GetCurrentDrive();
564 return DRIVE_Chdir( drive
, dirname
);
568 static int INT21_FindFirst( CONTEXT
*context
)
572 DOS_FULL_NAME full_name
;
573 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
575 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
576 dta
->unixPath
= NULL
;
577 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
579 AX_reg(context
) = GetLastError();
583 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
584 p
= strrchr( dta
->unixPath
, '/' );
587 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
588 * (doesn't matter as it is set below anyway)
590 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
592 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
593 dta
->unixPath
= NULL
;
594 SetLastError( ERROR_FILE_NOT_FOUND
);
595 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
599 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
600 : DRIVE_GetCurrentDrive();
602 dta
->search_attr
= CL_reg(context
);
607 static int INT21_FindNext( CONTEXT
*context
)
609 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
610 WIN32_FIND_DATAA entry
;
613 if (!dta
->unixPath
) return 0;
614 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
615 dta
->search_attr
, dta
->count
, &entry
)))
617 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
618 dta
->unixPath
= NULL
;
621 if ((int)dta
->count
+ count
> 0xffff)
623 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
624 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
625 dta
->unixPath
= NULL
;
629 dta
->fileattr
= entry
.dwFileAttributes
;
630 dta
->filesize
= entry
.nFileSizeLow
;
631 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
632 &dta
->filedate
, &dta
->filetime
);
633 strcpy( dta
->filename
, entry
.cAlternateFileName
);
634 if (!memchr(dta
->mask
,'?',11)) {
635 /* wildcardless search, release resources in case no findnext will
636 * be issued, and as a workaround in case file creation messes up
637 * findnext, as sometimes happens with pkunzip */
638 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
639 dta
->unixPath
= NULL
;
645 static BOOL
INT21_CreateTempFile( CONTEXT
*context
)
647 static int counter
= 0;
648 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
649 char *p
= name
+ strlen(name
);
651 /* despite what Ralf Brown says, some programs seem to call without
652 * ending backslash (DOS accepts that, so we accept it too) */
653 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
657 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
658 counter
= (counter
+ 1) % 1000;
660 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
662 TRACE(int21
, "created %s\n", name
);
665 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
670 static BOOL
INT21_GetCurrentDirectory( CONTEXT
*context
)
672 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
673 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
675 if (!DRIVE_IsValid(drive
))
677 SetLastError( ERROR_INVALID_DRIVE
);
680 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
681 AX_reg(context
) = 0x0100; /* success return code */
686 static void INT21_GetDBCSLeadTable( CONTEXT
*context
)
688 if (heap
|| INT21_CreateHeap())
689 { /* return an empty table just as DOS 4.0+ does */
690 DS_reg(context
) = DosHeapHandle
;
691 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
695 AX_reg(context
) = 0x1; /* error */
701 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
703 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
704 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
706 if (!DRIVE_IsValid(drive
))
708 SetLastError( ERROR_INVALID_DRIVE
);
712 *(WORD
*)dataptr
= 0;
713 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
714 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
715 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
720 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
722 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
723 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
725 if (!DRIVE_IsValid(drive
))
727 SetLastError( ERROR_INVALID_DRIVE
);
731 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
736 /* microsoft's programmers should be shot for using CP/M style int21
737 calls in Windows for Workgroup's winfile.exe */
739 static int INT21_FindFirstFCB( CONTEXT
*context
)
741 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
746 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
747 else pFCB
= (FINDFILE_FCB
*)fcb
;
748 drive
= DOS_GET_DRIVE( pFCB
->drive
);
749 if (!DRIVE_IsValid( drive
)) return 0;
750 root
= DRIVE_GetRoot( drive
);
751 cwd
= DRIVE_GetUnixCwd( drive
);
752 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
753 strlen(root
)+strlen(cwd
)+2 );
754 if (!pFCB
->unixPath
) return 0;
755 strcpy( pFCB
->unixPath
, root
);
756 strcat( pFCB
->unixPath
, "/" );
757 strcat( pFCB
->unixPath
, cwd
);
763 static int INT21_FindNextFCB( CONTEXT
*context
)
765 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
767 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
768 WIN32_FIND_DATAA entry
;
772 if (*fcb
== 0xff) /* extended FCB ? */
775 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
780 pFCB
= (FINDFILE_FCB
*)fcb
;
783 if (!pFCB
->unixPath
) return 0;
784 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
785 DOS_GET_DRIVE( pFCB
->drive
), attr
,
786 pFCB
->count
, &entry
)))
788 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
789 pFCB
->unixPath
= NULL
;
792 pFCB
->count
+= count
;
794 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
795 *(BYTE
*)pResult
= 0xff;
796 (BYTE
*)pResult
+=6; /* leave reserved field behind */
797 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
800 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
802 pResult
->fileattr
= entry
.dwFileAttributes
;
803 pResult
->cluster
= 0; /* what else? */
804 pResult
->filesize
= entry
.nFileSizeLow
;
805 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
806 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
807 &pResult
->filedate
, &pResult
->filetime
);
809 /* Convert file name to FCB format */
811 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
812 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
813 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
814 pResult
->filename
[0] = pResult
->filename
[1] = '.';
817 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
818 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
820 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
821 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
822 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
825 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
826 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
832 static void DeleteFileFCB( CONTEXT
*context
)
834 FIXME(int21
, "(%p): stub\n", context
);
837 static void RenameFileFCB( CONTEXT
*context
)
839 FIXME(int21
, "(%p): stub\n", context
);
844 static void fLock( CONTEXT
* context
)
847 switch ( AX_reg(context
) & 0xff )
849 case 0x00: /* LOCK */
850 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
852 MAKELONG(DX_reg(context
),CX_reg(context
)),
853 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
854 if (!LockFile(FILE_GetHandle(BX_reg(context
)),
855 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
856 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
857 AX_reg(context
) = GetLastError();
862 case 0x01: /* UNLOCK */
863 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
865 MAKELONG(DX_reg(context
),CX_reg(context
)),
866 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
867 if (!UnlockFile(FILE_GetHandle(BX_reg(context
)),
868 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
869 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
870 AX_reg(context
) = GetLastError();
875 AX_reg(context
) = 0x0001;
882 INT21_networkfunc (CONTEXT
*context
)
884 switch (AL_reg(context
)) {
885 case 0x00: /* Get machine name. */
887 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
888 TRACE(int21
, "getting machine name to %p\n", dst
);
889 if (gethostname (dst
, 15))
891 WARN(int21
,"failed!\n");
892 SetLastError( ER_NoNetwork
);
895 int len
= strlen (dst
);
899 CH_reg(context
) = 1; /* Valid */
900 CL_reg(context
) = 1; /* NETbios number??? */
901 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
907 SetLastError( ER_NoNetwork
);
912 static void INT21_SetCurrentPSP(WORD psp
)
915 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
916 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
918 GlobalUnlock16( GetCurrentTask() );
919 if (pModule
->lpDosTask
)
920 pModule
->lpDosTask
->psp_seg
= psp
;
923 ERR(int21
, "Cannot change PSP for non-DOS task!\n");
926 static WORD
INT21_GetCurrentPSP()
929 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
930 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
932 GlobalUnlock16( GetCurrentTask() );
933 if (pModule
->lpDosTask
)
934 return pModule
->lpDosTask
->psp_seg
;
937 return GetCurrentPDB16();
941 SEGPTR
INT21_GetListOfLists()
943 static DOS_LISTOFLISTS
*LOL
;
944 static SEGPTR seg_LOL
;
949 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
950 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
951 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
952 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
953 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
954 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
955 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
956 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
957 0133:00A0 D0 44 C8 FD D0 44 .D...D
960 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
962 LOL
->CX_Int21_5e01
= 0x0;
963 LOL
->LRU_count_FCB_cache
= 0x0;
964 LOL
->LRU_count_FCB_open
= 0x0;
965 LOL
->OEM_func_handler
= -1; /* not available */
966 LOL
->INT21_offset
= 0x0;
967 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
968 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
969 LOL
->ptr_disk_buf
= 0x0;
970 LOL
->offs_unread_CON
= 0x0;
971 LOL
->seg_first_MCB
= 0x0;
972 LOL
->ptr_first_DPB
= 0x0;
973 LOL
->ptr_first_SysFileTable
= 0x0;
974 LOL
->ptr_clock_dev_hdr
= 0x0;
975 LOL
->ptr_CON_dev_hdr
= 0x0;
976 LOL
->max_byte_per_sec
= 512;
977 LOL
->ptr_disk_buf_info
= 0x0;
978 LOL
->ptr_array_CDS
= 0x0;
979 LOL
->ptr_sys_FCB
= 0x0;
980 LOL
->nr_protect_FCB
= 0x0;
981 LOL
->nr_block_dev
= 0x0;
982 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
983 LOL
->nr_drives_JOINed
= 0x0;
984 LOL
->ptr_spec_prg_names
= 0x0;
985 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
986 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
987 LOL
->PSP_last_exec
= 0x0;
988 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
989 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
990 LOL
->boot_drive
= 3; /* C: */
991 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
992 LOL
->size_extended_mem
= 0xf000; /* very high value */
994 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
995 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
999 /***********************************************************************
1000 * INT21_GetExtendedError
1002 static void INT21_GetExtendedError( CONTEXT
*context
)
1004 BYTE
class, action
, locus
;
1005 WORD error
= GetLastError();
1010 class = action
= locus
= 0;
1012 case ERROR_DIR_NOT_EMPTY
:
1017 case ERROR_ACCESS_DENIED
:
1018 class = EC_AccessDenied
;
1022 case ERROR_CANNOT_MAKE
:
1023 class = EC_AccessDenied
;
1027 case ERROR_DISK_FULL
:
1028 case ERROR_HANDLE_DISK_FULL
:
1029 class = EC_MediaError
;
1033 case ERROR_FILE_EXISTS
:
1034 case ERROR_ALREADY_EXISTS
:
1039 case ERROR_FILE_NOT_FOUND
:
1040 class = EC_NotFound
;
1044 case ER_GeneralFailure
:
1045 class = EC_SystemFailure
;
1049 case ERROR_INVALID_DRIVE
:
1050 class = EC_MediaError
;
1054 case ERROR_INVALID_HANDLE
:
1055 class = EC_ProgramError
;
1059 case ERROR_LOCK_VIOLATION
:
1060 class = EC_AccessDenied
;
1064 case ERROR_NO_MORE_FILES
:
1065 class = EC_MediaError
;
1070 class = EC_NotFound
;
1074 case ERROR_NOT_ENOUGH_MEMORY
:
1075 class = EC_OutOfResource
;
1079 case ERROR_PATH_NOT_FOUND
:
1080 class = EC_NotFound
;
1085 class = EC_NotFound
;
1089 case ERROR_SHARING_VIOLATION
:
1090 class = EC_Temporary
;
1094 case ERROR_TOO_MANY_OPEN_FILES
:
1095 class = EC_ProgramError
;
1100 FIXME( int21
, "Unknown error %d\n", error
);
1101 class = EC_SystemFailure
;
1106 TRACE( int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1107 error
, class, action
, locus
);
1108 AX_reg(context
) = error
;
1109 BH_reg(context
) = class;
1110 BL_reg(context
) = action
;
1111 CH_reg(context
) = locus
;
1114 /***********************************************************************
1115 * DOS3Call (KERNEL.102)
1117 void WINAPI
DOS3Call( CONTEXT
*context
)
1119 BOOL bSetDOSExtendedError
= FALSE
;
1122 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
1123 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1124 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1125 SI_reg(context
), DI_reg(context
),
1126 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1130 if (AH_reg(context
) == 0x59) /* Get extended error info */
1132 INT21_GetExtendedError( context
);
1136 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1138 TRACE(int21
, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1139 /* no flush here yet */
1140 AH_reg(context
) = AL_reg(context
);
1143 if (AH_reg(context
)>=0x2f) {
1144 /* extended error is used by (at least) functions 0x2f to 0x62 */
1147 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1149 switch(AH_reg(context
))
1151 case 0x03: /* READ CHARACTER FROM STDAUX */
1152 case 0x04: /* WRITE CHARACTER TO STDAUX */
1153 case 0x05: /* WRITE CHARACTER TO PRINTER */
1154 case 0x0f: /* OPEN FILE USING FCB */
1155 case 0x10: /* CLOSE FILE USING FCB */
1156 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1157 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1158 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1159 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1160 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1161 case 0x23: /* GET FILE SIZE FOR FCB */
1162 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1163 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1164 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1165 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1166 INT_BARF( context
, 0x21 );
1169 case 0x00: /* TERMINATE PROGRAM */
1170 TRACE(int21
,"TERMINATE PROGRAM\n");
1174 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1175 TRACE(int21
,"DIRECT CHARACTER INPUT WITH ECHO\n");
1176 AL_reg(context
) = CONSOLE_GetCharacter();
1177 /* FIXME: no echo */
1180 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1181 TRACE(int21
, "Write Character to Standard Output\n");
1182 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1185 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1186 if (DL_reg(context
) == 0xff) {
1187 static char scan
= 0;
1188 TRACE(int21
, "Direct Console Input\n");
1190 /* return pending scancode */
1191 AL_reg(context
) = scan
;
1192 FL_reg(context
) &= ~0x40; /* clear ZF */
1196 if (CONSOLE_CheckForKeystroke(&scan
,&ascii
)) {
1197 CONSOLE_GetKeystroke(&scan
,&ascii
);
1198 /* return ASCII code */
1199 AL_reg(context
) = ascii
;
1200 FL_reg(context
) &= ~0x40; /* clear ZF */
1201 /* return scan code on next call only if ascii==0 */
1202 if (ascii
) scan
= 0;
1204 /* nothing pending, clear everything */
1205 AL_reg(context
) = 0;
1206 FL_reg(context
) |= 0x40; /* set ZF */
1207 scan
= 0; /* just in case */
1211 TRACE(int21
, "Direct Console Output\n");
1212 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1216 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1217 TRACE(int21
,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1218 AL_reg(context
) = CONSOLE_GetCharacter();
1221 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1222 TRACE(int21
,"CHARACTER INPUT WITHOUT ECHO\n");
1223 AL_reg(context
) = CONSOLE_GetCharacter();
1226 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1227 TRACE(int21
,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1228 DS_reg(context
),DX_reg(context
) );
1230 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1232 /* do NOT use strchr() to calculate the string length,
1233 as '\0' is valid string content, too !
1234 Maybe we should check for non-'$' strings, but DOS doesn't. */
1235 while (*p
!= '$') p
++;
1236 _hwrite16( 1, data
, (int)p
- (int)data
);
1237 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1241 case 0x0a: /* BUFFERED INPUT */
1243 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1244 EDX_reg(context
) ));
1247 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1249 TRACE(int21
,"Handle old chars in buffer!\n");
1250 res
=_lread16( 0, buffer
+2,buffer
[0]);
1252 if(buffer
[res
+1] == '\n')
1253 buffer
[res
+1] = '\r';
1257 case 0x0b: {/* GET STDIN STATUS */
1260 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1261 AL_reg(context
) = 0xff;
1263 AL_reg(context
) = 0;
1266 case 0x2e: /* SET VERIFY FLAG */
1267 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1268 /* we cannot change the behaviour anyway, so just ignore it */
1271 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1275 case 0x6b: /* NULL FUNCTION */
1276 AL_reg(context
) = 0;
1279 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1283 case 0x0d: /* DISK BUFFER FLUSH */
1284 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1285 RESET_CFLAG(context
); /* dos 6+ only */
1288 case 0x0e: /* SELECT DEFAULT DRIVE */
1289 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1290 DRIVE_SetCurrentDrive( DL_reg(context
) );
1291 AL_reg(context
) = MAX_DOS_DRIVES
;
1294 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1295 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1296 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1297 if (!INT21_FindFirstFCB(context
))
1299 AL_reg(context
) = 0xff;
1302 /* else fall through */
1304 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1305 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1308 case 0x13: /* DELETE FILE USING FCB */
1309 DeleteFileFCB(context
);
1312 case 0x17: /* RENAME FILE USING FCB */
1313 RenameFileFCB(context
);
1316 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1317 AL_reg(context
) = DRIVE_GetCurrentDrive();
1320 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1322 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1323 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1324 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1328 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1329 DL_reg(context
) = 0;
1330 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1333 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1334 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1337 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1338 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1341 case 0x25: /* SET INTERRUPT VECTOR */
1342 INT_CtxSetHandler( context
, AL_reg(context
),
1343 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1347 case 0x29: /* PARSE FILENAME INTO FCB */
1348 INT21_ParseFileNameIntoFCB(context
);
1351 case 0x2a: /* GET SYSTEM DATE */
1352 INT21_GetSystemDate(context
);
1355 case 0x2b: /* SET SYSTEM DATE */
1356 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1357 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1358 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1361 case 0x2c: /* GET SYSTEM TIME */
1362 INT21_GetSystemTime(context
);
1365 case 0x2d: /* SET SYSTEM TIME */
1366 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1367 CH_reg(context
), CL_reg(context
),
1368 DH_reg(context
), DL_reg(context
) );
1369 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1372 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1373 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1375 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1376 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1377 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1381 case 0x30: /* GET DOS VERSION */
1382 TRACE(int21
,"GET DOS VERSION %s requested\n",
1383 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1384 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1385 (HIWORD(GetVersion16()) << 8);
1387 AH_reg(context
) = 0x7;
1388 AL_reg(context
) = 0xA;
1391 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1392 CX_reg(context
) = 0x0000;
1395 case 0x31: /* TERMINATE AND STAY RESIDENT */
1396 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1399 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1400 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1401 INT21_DriveName( DL_reg(context
)));
1402 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1405 case 0x33: /* MULTIPLEXED */
1406 switch (AL_reg(context
))
1408 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1409 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE\n");
1410 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1413 case 0x01: /* SET EXTENDED BREAK STATE */
1414 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE\n");
1415 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1418 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1419 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1420 /* ugly coding in order to stay reentrant */
1421 if (DL_reg(context
))
1423 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1424 DOSCONF_config
.brk_flag
= 1;
1428 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1429 DOSCONF_config
.brk_flag
= 0;
1433 case 0x05: /* GET BOOT DRIVE */
1434 TRACE(int21
,"GET BOOT DRIVE\n");
1435 DL_reg(context
) = 3;
1436 /* c: is Wine's bootdrive (a: is 1)*/
1439 case 0x06: /* GET TRUE VERSION NUMBER */
1440 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1441 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1442 (HIWORD(GetVersion16() << 8));
1443 DX_reg(context
) = 0x00;
1447 INT_BARF( context
, 0x21 );
1452 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1453 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1454 if (!heap
) INT21_CreateHeap();
1455 ES_reg(context
) = DosHeapHandle
;
1456 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1459 case 0x35: /* GET INTERRUPT VECTOR */
1460 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1462 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1463 ES_reg(context
) = SELECTOROF(addr
);
1464 BX_reg(context
) = OFFSETOF(addr
);
1468 case 0x36: /* GET FREE DISK SPACE */
1469 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1470 INT21_DriveName( DL_reg(context
)));
1471 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1476 unsigned char switchchar
='/';
1477 switch (AL_reg(context
))
1479 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1480 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1481 AL_reg(context
) = 0x00; /* success*/
1482 DL_reg(context
) = switchchar
;
1484 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1485 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1486 switchchar
= DL_reg(context
);
1487 AL_reg(context
) = 0x00; /* success*/
1489 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1490 INT_BARF( context
, 0x21 );
1496 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1497 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1499 AX_reg(context
) = 0x02; /* no country support available */
1503 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1504 TRACE(int21
,"MKDIR %s\n",
1505 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1506 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1507 EDX_reg(context
) ), NULL
));
1508 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1509 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1510 * denied), while CreateDirectory return several ones. remap some of
1513 if (bSetDOSExtendedError
) {
1514 switch (GetLastError()) {
1515 case ERROR_ALREADY_EXISTS
:
1516 case ERROR_FILENAME_EXCED_RANGE
:
1517 case ERROR_DISK_FULL
:
1518 SetLastError(ERROR_ACCESS_DENIED
);
1525 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1526 TRACE(int21
,"RMDIR %s\n",
1527 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1528 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1529 EDX_reg(context
) )));
1532 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1533 TRACE(int21
,"CHDIR %s\n",
1534 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1535 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1538 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1539 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1540 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1541 bSetDOSExtendedError
= INT21_CreateFile( context
);
1544 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1545 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1546 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1547 OpenExistingFile(context
);
1550 case 0x3e: /* "CLOSE" - CLOSE FILE */
1551 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1552 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1555 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1556 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1557 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1561 result
= _hread16( BX_reg(context
),
1562 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1566 result
= WIN16_hread( BX_reg(context
),
1567 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1570 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1571 else AX_reg(context
) = (WORD
)result
;
1575 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1576 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1577 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1579 LONG result
= _hwrite16( BX_reg(context
),
1580 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1583 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1584 else AX_reg(context
) = (WORD
)result
;
1588 case 0x41: /* "UNLINK" - DELETE FILE */
1589 TRACE(int21
,"UNLINK%s\n",
1590 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1591 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1592 EDX_reg(context
) )));
1595 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1596 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1597 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1598 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1599 "current file position":"end of file");
1601 LONG status
= _llseek16( BX_reg(context
),
1602 MAKELONG(DX_reg(context
),CX_reg(context
)),
1604 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1607 AX_reg(context
) = LOWORD(status
);
1608 DX_reg(context
) = HIWORD(status
);
1613 case 0x43: /* FILE ATTRIBUTES */
1614 switch (AL_reg(context
))
1617 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1618 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1619 AX_reg(context
) = (WORD
)GetFileAttributesA(
1620 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1622 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1623 else CX_reg(context
) = AX_reg(context
);
1627 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1628 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1629 bSetDOSExtendedError
=
1630 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1635 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1636 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1640 case 0x44: /* IOCTL */
1641 switch (AL_reg(context
))
1644 ioctlGetDeviceInfo(context
);
1650 const DOS_DEVICE
*dev
;
1651 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )) &&
1652 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1654 ASPI_DOS_HandleInt(context
);
1658 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1659 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1660 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1662 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1663 /* for (i=0;i<CX_reg(context);i++)
1664 fprintf(stdnimp,"%02x ",dataptr[i]);
1665 fprintf(stdnimp,"\n");*/
1666 AX_reg(context
)=CX_reg(context
);
1669 case 0x08: /* Check if drive is removable. */
1670 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1671 INT21_DriveName( BL_reg(context
)));
1672 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1674 case DRIVE_CANNOTDETERMINE
:
1675 SetLastError( ERROR_INVALID_DRIVE
);
1676 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1679 case DRIVE_REMOVABLE
:
1680 AX_reg(context
) = 0; /* removable */
1683 AX_reg(context
) = 1; /* not removable */
1688 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1689 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1690 INT21_DriveName( BL_reg(context
)));
1691 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1693 case DRIVE_CANNOTDETERMINE
:
1694 SetLastError( ERROR_INVALID_DRIVE
);
1695 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1699 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1702 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1707 case 0x0a: /* check if handle (BX) is remote */
1708 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1709 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1712 DX_reg(context
) = 0;
1715 case 0x0b: /* SET SHARING RETRY COUNT */
1716 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1717 CX_reg(context
), DX_reg(context
));
1718 if (!CX_reg(context
))
1720 AX_reg(context
) = 1;
1724 sharing_pause
= CX_reg(context
);
1725 if (!DX_reg(context
))
1726 sharing_retries
= DX_reg(context
);
1727 RESET_CFLAG(context
);
1731 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1732 INT21_DriveName( BL_reg(context
)));
1733 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1736 case 0x0e: /* get logical drive mapping */
1737 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1738 INT21_DriveName( BL_reg(context
)));
1739 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1742 case 0x0F: /* Set logical drive mapping */
1745 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1746 INT21_DriveName( BL_reg(context
)));
1747 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1748 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1751 AX_reg(context
) = 0x000F; /* invalid drive */
1756 case 0xe0: /* Sun PC-NFS API */
1761 INT_BARF( context
, 0x21 );
1766 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1769 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1770 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1771 FILE_GetHandle(BX_reg(context
)),
1772 GetCurrentProcess(), &handle
,
1773 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1774 AX_reg(context
) = HFILE_ERROR16
;
1776 AX_reg(context
) = FILE_AllocDosHandle(handle
);
1780 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1781 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1782 BX_reg(context
),CX_reg(context
));
1783 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1786 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1787 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1788 INT21_DriveName( DL_reg(context
)));
1789 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1792 case 0x48: /* ALLOCATE MEMORY */
1793 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1798 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1800 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1804 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1806 AX_reg(context
) = (DWORD
)mem
&0xffff;
1811 AX_reg(context
) = 0x0008; /* insufficient memory */
1812 BX_reg(context
) = DOSMEM_Available(0)>>4;
1817 case 0x49: /* FREE MEMORY */
1818 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1822 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1825 ret
= !GlobalDOSFree16(ES_reg(context
));
1826 /* If we don't reset ES_reg, we will fail in the relay code */
1827 ES_reg(context
)=ret
;
1831 TRACE(int21
,"FREE MEMORY failed\n");
1833 AX_reg(context
) = 0x0009; /* memory block address invalid */
1838 case 0x4a: /* RESIZE MEMORY BLOCK */
1839 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1840 if (!ISV86(context
))
1841 FIXME(int21
,"RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1843 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1844 BX_reg(context
)<<4,NULL
);
1846 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1849 AX_reg(context
) = 0x0008; /* insufficient memory */
1850 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1855 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1856 TRACE(int21
,"EXEC %s\n",
1857 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1858 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1861 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1864 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1865 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1866 ExitProcess( AL_reg(context
) );
1869 case 0x4d: /* GET RETURN CODE */
1870 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1871 AX_reg(context
) = 0; /* normal exit */
1874 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1875 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1876 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1877 if (!INT21_FindFirst(context
)) break;
1880 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1881 TRACE(int21
,"FINDNEXT\n");
1882 if (!INT21_FindNext(context
))
1884 SetLastError( ERROR_NO_MORE_FILES
);
1885 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1888 else AX_reg(context
) = 0; /* OK */
1890 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1891 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1892 INT21_SetCurrentPSP(BX_reg(context
));
1894 case 0x51: /* GET PSP ADDRESS */
1895 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1896 /* FIXME: should we return the original DOS PSP upon */
1897 /* Windows startup ? */
1898 BX_reg(context
) = INT21_GetCurrentPSP();
1900 case 0x62: /* GET PSP ADDRESS */
1901 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1902 /* FIXME: should we return the original DOS PSP upon */
1903 /* Windows startup ? */
1904 BX_reg(context
) = INT21_GetCurrentPSP();
1907 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1908 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1911 lol
= INT21_GetListOfLists();
1912 ES_reg(context
) = HIWORD(lol
);
1913 BX_reg(context
) = LOWORD(lol
);
1917 case 0x54: /* Get Verify Flag */
1918 TRACE(int21
,"Get Verify Flag - Not Supported\n");
1919 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1922 case 0x56: /* "RENAME" - RENAME FILE */
1923 TRACE(int21
,"RENAME %s to %s\n",
1924 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1925 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1926 bSetDOSExtendedError
=
1927 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1928 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1931 case 0x57: /* FILE DATE AND TIME */
1932 switch (AL_reg(context
))
1934 case 0x00: /* Get */
1937 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1939 if (!GetFileTime( FILE_GetHandle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1940 bSetDOSExtendedError
= TRUE
;
1941 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1946 case 0x01: /* Set */
1949 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1951 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1953 bSetDOSExtendedError
=
1954 (!SetFileTime( FILE_GetHandle(BX_reg(context
)),
1955 NULL
, NULL
, &filetime
));
1961 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1962 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1964 switch (AL_reg(context
))
1967 AX_reg(context
) = 1;
1970 AX_reg(context
) = 0;
1976 RESET_CFLAG(context
);
1979 case 0x5a: /* CREATE TEMPORARY FILE */
1980 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1981 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1984 case 0x5b: /* CREATE NEW FILE */
1985 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1986 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1987 bSetDOSExtendedError
= ((AX_reg(context
) =
1988 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1989 CX_reg(context
) )) == (WORD
)HFILE_ERROR16
);
1992 case 0x5d: /* NETWORK */
1993 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1994 /* Fix the following while you're at it. */
1995 SetLastError( ER_NoNetwork
);
1996 bSetDOSExtendedError
= TRUE
;
2000 bSetDOSExtendedError
= INT21_networkfunc (context
);
2003 case 0x5f: /* NETWORK */
2004 switch (AL_reg(context
))
2006 case 0x07: /* ENABLE DRIVE */
2007 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
2008 if (!DRIVE_Enable( DL_reg(context
) ))
2010 SetLastError( ERROR_INVALID_DRIVE
);
2011 bSetDOSExtendedError
= TRUE
;
2015 case 0x08: /* DISABLE DRIVE */
2016 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
2017 if (!DRIVE_Disable( DL_reg(context
) ))
2019 SetLastError( ERROR_INVALID_DRIVE
);
2020 bSetDOSExtendedError
= TRUE
;
2025 /* network software not installed */
2026 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
2027 SetLastError( ER_NoNetwork
);
2028 bSetDOSExtendedError
= TRUE
;
2033 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
2034 TRACE(int21
,"TRUENAME %s\n",
2035 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
2037 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2038 ESI_reg(context
)), 128,
2039 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2040 EDI_reg(context
)),NULL
))
2041 bSetDOSExtendedError
= TRUE
;
2042 else AX_reg(context
) = 0;
2046 case 0x61: /* UNUSED */
2047 case 0x63: /* misc. language support */
2048 switch (AL_reg(context
)) {
2049 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
2050 INT21_GetDBCSLeadTable(context
);
2054 case 0x64: /* OS/2 DOS BOX */
2055 INT_BARF( context
, 0x21 );
2059 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2060 extern WORD WINE_LanguageId
;
2061 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
2062 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2063 BX_reg(context
), DX_reg(context
));
2064 switch (AL_reg(context
)) {
2066 TRACE(int21
,"\tget general internationalization info\n");
2068 *(WORD
*)(dataptr
+1) = 41;
2069 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
2070 *(WORD
*)(dataptr
+5) = CodePage
;
2071 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2074 TRACE(int21
,"\tget pointer to collating sequence table\n");
2076 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2077 CX_reg(context
) = 258;/*FIXME: size of table?*/
2080 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
2081 INT_BARF( context
, 0x21 );
2087 case 0x66: /* GLOBAL CODE PAGE TABLE */
2088 switch (AL_reg(context
))
2091 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
2092 DX_reg(context
) = BX_reg(context
) = CodePage
;
2093 RESET_CFLAG(context
);
2096 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2097 BX_reg(context
),DX_reg(context
));
2098 CodePage
= BX_reg(context
);
2099 RESET_CFLAG(context
);
2104 case 0x67: /* SET HANDLE COUNT */
2105 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
2106 SetHandleCount16( BX_reg(context
) );
2107 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2110 case 0x68: /* "FFLUSH" - COMMIT FILE */
2111 case 0x6a: /* COMMIT FILE */
2112 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2113 bSetDOSExtendedError
= (!FlushFileBuffers( FILE_GetHandle(BX_reg(context
)) ));
2116 case 0x69: /* DISK SERIAL NUMBER */
2117 switch (AL_reg(context
))
2120 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
2121 INT21_DriveName(BL_reg(context
)));
2122 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2123 else AX_reg(context
) = 0;
2127 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
2128 INT21_DriveName(BL_reg(context
)));
2129 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2130 else AX_reg(context
) = 1;
2135 case 0x6C: /* Extended Open/Create*/
2136 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
2137 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2138 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2141 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2142 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2143 /* not supported on anything but Win95 */
2144 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
2146 AL_reg(context
) = 0;
2148 switch(AL_reg(context
))
2150 case 0x39: /* Create directory */
2151 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
2152 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2153 bSetDOSExtendedError
= (!CreateDirectoryA(
2154 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2155 EDX_reg(context
) ), NULL
));
2157 case 0x3a: /* Remove directory */
2158 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2159 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2160 bSetDOSExtendedError
= (!RemoveDirectoryA(
2161 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2162 EDX_reg(context
) )));
2164 case 0x43: /* Get/Set file attributes */
2165 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2166 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2167 switch (BL_reg(context
))
2169 case 0x00: /* Get file attributes */
2170 TRACE(int21
,"\tretrieve attributes\n");
2171 CX_reg(context
) = (WORD
)GetFileAttributesA(
2172 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2174 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2177 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
2178 bSetDOSExtendedError
= (!SetFileAttributesA(
2179 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2181 CX_reg(context
) ) );
2184 FIXME(int21
, "Unimplemented long file name function:\n");
2185 INT_BARF( context
, 0x21 );
2187 AL_reg(context
) = 0;
2191 case 0x47: /* Get current directory */
2192 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2193 INT21_DriveName(DL_reg(context
)));
2194 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2197 case 0x4e: /* Find first file */
2198 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2199 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2200 /* FIXME: use attributes in CX */
2201 if ((AX_reg(context
) = FindFirstFile16(
2202 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2203 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2205 == INVALID_HANDLE_VALUE16
)
2206 bSetDOSExtendedError
= TRUE
;
2208 case 0x4f: /* Find next file */
2209 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2211 if (!FindNextFile16( BX_reg(context
),
2212 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2214 bSetDOSExtendedError
= TRUE
;
2216 case 0xa1: /* Find close */
2217 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2219 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2222 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2223 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2226 switch(CL_reg(context
))
2228 case 0x01: /*Get short filename or path */
2229 if (!GetShortPathNameA
2230 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2232 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2233 EDI_reg(context
)), 67))
2234 bSetDOSExtendedError
= TRUE
;
2235 else AX_reg(context
) = 0;
2237 case 0x02: /*Get canonical long filename or path */
2238 if (!GetFullPathNameA
2239 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2240 ESI_reg(context
)), 128,
2241 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2242 EDI_reg(context
)),NULL
))
2243 bSetDOSExtendedError
= TRUE
;
2244 else AX_reg(context
) = 0;
2247 FIXME(int21
, "Unimplemented long file name function:\n");
2248 INT_BARF( context
, 0x21 );
2250 AL_reg(context
) = 0;
2254 case 0x6c: /* Create or open file */
2255 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2256 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2257 /* translate Dos 7 action to Dos 6 action */
2258 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2261 case 0x3b: /* Change directory */
2262 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2263 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2264 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2270 AL_reg(context
) = GetLastError();
2273 case 0x41: /* Delete file */
2274 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2275 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2276 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2281 AL_reg(context
) = GetLastError();
2284 case 0x56: /* Move (rename) file */
2285 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2286 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2287 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2289 FIXME(int21
, "Unimplemented long file name function:\n");
2290 INT_BARF( context
, 0x21 );
2292 AL_reg(context
) = 0;
2297 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2298 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2299 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2300 TRACE(int21
,"windows95 function AX %04x\n",
2302 WARN(int21
, " returning unimplemented\n");
2304 AL_reg(context
) = 0;
2307 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2308 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2312 INT_BARF( context
, 0x21 );
2315 } /* END OF SWITCH */
2317 if( bSetDOSExtendedError
) /* set general error condition */
2319 AX_reg(context
) = GetLastError();
2323 if ((EFL_reg(context
) & 0x0001))
2324 TRACE(int21
, "failed, error 0x%04lx\n", GetLastError() );
2326 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2327 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2328 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2329 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2330 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2334 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2336 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT
)DosProc
);