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( CONTEXT
*context
)
97 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
99 /* FIXME: This assumes DTA was set correctly! */
100 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
101 OFFSETOF(pTask
->dta
) );
105 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
106 /* limited == TRUE is used with INT 0x21/0x440d */
111 setword(&data
[3], 0);
113 setword(&data
[6], 240);
114 setword(&data
[8], 64000);
116 setword(&data
[0x0b], 40);
117 setword(&data
[0x0d], 56);
118 setword(&data
[0x0f], 2);
119 setword(&data
[0x11], 0);
121 setword(&data
[0x1f], 800);
123 setword(&data
[0x22], 1);
125 } else { /* 1.44mb */
128 setword(&data
[3], 0);
130 setword(&data
[6], 240);
131 setword(&data
[8], 2880);
133 setword(&data
[0x0b], 6);
134 setword(&data
[0x0d], 18);
135 setword(&data
[0x0f], 2);
136 setword(&data
[0x11], 0);
138 setword(&data
[0x1f], 80);
140 setword(&data
[0x22], 2);
145 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
147 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
148 char root
[] = "A:\\";
150 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
151 if (!GetDiskFreeSpace32A( root
, &cluster_sectors
, §or_bytes
,
152 &free_clusters
, &total_clusters
)) return 0;
153 AX_reg(context
) = cluster_sectors
;
154 BX_reg(context
) = free_clusters
;
155 CX_reg(context
) = sector_bytes
;
156 DX_reg(context
) = total_clusters
;
160 static int INT21_GetDriveAllocInfo( CONTEXT
*context
)
162 if (!INT21_GetFreeDiskSpace( context
)) return 0;
163 if (!heap
&& !INT21_CreateHeap()) return 0;
164 heap
->mediaID
= 0xf0;
165 DS_reg(context
) = DosHeapHandle
;
166 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
170 static void GetDrivePB( CONTEXT
*context
, int drive
)
172 if(!DRIVE_IsValid(drive
))
174 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
175 AX_reg(context
) = 0x00ff;
177 else if (heap
|| INT21_CreateHeap())
179 FIXME(int21
, "GetDrivePB not fully implemented.\n");
181 /* FIXME: I have no idea what a lot of this information should
182 * say or whether it even really matters since we're not allowing
183 * direct block access. However, some programs seem to depend on
184 * getting at least _something_ back from here. The 'next' pointer
185 * does worry me, though. Should we have a complete table of
186 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
188 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
189 heap
->dpb
.sector_size
= 512;
190 heap
->dpb
.high_sector
= 1;
191 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
192 heap
->dpb
.reserved
= 0;
193 heap
->dpb
.num_FAT
= 1;
194 heap
->dpb
.dir_entries
= 2;
195 heap
->dpb
.first_data
= 2;
196 heap
->dpb
.high_cluster
= 64000;
197 heap
->dpb
.sectors_in_FAT
= 1;
198 heap
->dpb
.start_dir
= 1;
199 heap
->dpb
.driver_head
= 0;
200 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
201 heap
->dpb
.access_flag
= 0;
203 heap
->dpb
.free_search
= 0;
204 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
206 AL_reg(context
) = 0x00;
207 DS_reg(context
) = SELECTOROF(dpbsegptr
);
208 BX_reg(context
) = OFFSETOF(dpbsegptr
);
213 static void ioctlGetDeviceInfo( CONTEXT
*context
)
218 TRACE(int21
, "(%d)\n", BX_reg(context
));
220 RESET_CFLAG(context
);
223 if ((file
= FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context
)) )))
225 const DOS_DEVICE
*dev
= DOSFS_GetDevice( file
->unix_name
);
226 FILE_ReleaseFile( file
);
229 DX_reg(context
) = dev
->flags
;
234 /* it seems to be a file */
235 curr_drive
= DRIVE_GetCurrentDrive();
236 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
238 /* bits 0-5 are current drive
239 * bit 6 - file has NOT been written..FIXME: correct?
240 * bit 8 - generate int24 if no diskspace on write/ read past end of file
241 * bit 11 - media not removable
242 * bit 14 - don't set file date/time on closing
243 * bit 15 - file is remote
247 static BOOL32
ioctlGenericBlkDevReq( CONTEXT
*context
)
249 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
));
250 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
252 if (!DRIVE_IsValid(drive
))
254 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
258 if (CH_reg(context
) != 0x08)
260 INT_BARF( context
, 0x21 );
264 switch (CL_reg(context
))
266 case 0x4a: /* lock logical volume */
267 TRACE(int21
,"lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
270 case 0x60: /* get device parameters */
271 /* used by w4wgrp's winfile */
272 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
274 dataptr
[6] = 0; /* media type */
277 dataptr
[1] = 0x05; /* fixed disk */
278 setword(&dataptr
[2], 0x01); /* non removable */
279 setword(&dataptr
[4], 0x300); /* # of cylinders */
283 dataptr
[1] = 0x07; /* block dev, floppy */
284 setword(&dataptr
[2], 0x02); /* removable */
285 setword(&dataptr
[4], 80); /* # of cylinders */
287 CreateBPB(drive
, &dataptr
[7], TRUE
);
288 RESET_CFLAG(context
);
291 case 0x66:/* get disk serial number */
293 char label
[12],fsname
[9],path
[4];
296 strcpy(path
,"x:\\");path
[0]=drive
+'A';
297 GetVolumeInformation32A(
298 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
301 memcpy(dataptr
+2,&serial
,4);
302 memcpy(dataptr
+6,label
,11);
303 memcpy(dataptr
+17,fsname
,8);
308 TRACE(int21
,"logical volume %d unlocked.\n",drive
);
312 memset(dataptr
+1, '\0', dataptr
[0]-1);
313 dataptr
[1] = dataptr
[0];
314 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
315 dataptr
[3] = 0xFF; /* no physical drive */
319 INT_BARF( context
, 0x21 );
324 static void INT21_GetSystemDate( CONTEXT
*context
)
327 GetLocalTime( &systime
);
328 CX_reg(context
) = systime
.wYear
;
329 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
330 AX_reg(context
) = systime
.wDayOfWeek
;
333 static void INT21_GetSystemTime( CONTEXT
*context
)
336 GetLocalTime( &systime
);
337 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
338 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
341 /* Many calls translate a drive argument like this:
342 drive number (00h = default, 01h = A:, etc)
344 static char drivestring
[]="default";
346 char *INT21_DriveName(int drive
)
351 drivestring
[0]= (unsigned char)drive
+ '@';
357 static BOOL32
INT21_CreateFile( CONTEXT
*context
)
359 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
360 DX_reg(context
) ), CX_reg(context
) );
361 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
365 static void OpenExistingFile( CONTEXT
*context
)
367 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
369 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
371 AX_reg(context
) = DOS_ExtendedError
;
380 switch (AX_reg(context
) & 0x0070)
382 case 0x00: /* compatability mode */
383 case 0x40: /* DENYNONE */
387 case 0x30: /* DENYREAD */
388 TRACE(int21
, "(%s): DENYREAD changed to DENYALL\n",
389 (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
390 case 0x10: /* DENYALL */
394 case 0x20: /* DENYWRITE */
405 int result
,retries
=sharing_retries
;
407 #if defined(__svr4__) || defined(_SCO_DS)
408 ERR(int21
, "Should call flock and needs porting to lockf\n");
412 result
= flock(handle
, lock
| LOCK_NB
);
414 if ( retries
&& (!result
) )
417 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
418 result
++; /* stop the optimizer */
419 for(i
=0;i
<32768*((int)sharing_pause
);i
++)
423 while( (!result
) && (!(retries
--)) );
428 AX_reg(context
) = DOS_ExtendedError
;
437 AX_reg(context
) = handle
;
438 RESET_CFLAG(context
);
443 static void CloseFile( CONTEXT
*context
)
445 if ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0)
447 AX_reg(context
) = DOS_ExtendedError
;
452 static BOOL32
INT21_ExtendedOpenCreateFile(CONTEXT
*context
)
454 BOOL32 bExtendedError
= FALSE
;
455 BYTE action
= DL_reg(context
);
457 /* Shuffle arguments to call OpenExistingFile */
458 AL_reg(context
) = BL_reg(context
);
459 DX_reg(context
) = SI_reg(context
);
460 /* BX,CX and DX should be preserved */
461 OpenExistingFile(context
);
463 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
465 UINT16 uReturnCX
= 0;
467 /* Now decide what do do */
469 if ((action
& 0x07) == 0)
471 BX_reg(context
) = AX_reg(context
);
473 AX_reg(context
) = 0x0050; /*File exists*/
475 WARN(int21
, "extended open/create: failed because file exists \n");
477 else if ((action
& 0x07) == 2)
479 /* Truncate it, but first check if opened for write */
480 if ((BL_reg(context
) & 0x0007)== 0)
482 BX_reg(context
) = AX_reg(context
);
484 WARN(int21
, "extended open/create: failed, trunc on ro file\n");
485 AX_reg(context
) = 0x000C; /*Access code invalid*/
490 /* Shuffle arguments to call CloseFile while
491 * preserving BX and DX */
493 TRACE(int21
, "extended open/create: Closing before truncate\n");
494 BX_reg(context
) = AX_reg(context
);
496 if (EFL_reg(context
) & 0x0001)
498 WARN(int21
, "extended open/create: close before trunc failed\n");
499 AX_reg(context
) = 0x0019; /*Seek Error*/
503 /* Shuffle arguments to call CreateFile */
505 TRACE(int21
, "extended open/create: Truncating\n");
506 AL_reg(context
) = BL_reg(context
);
507 /* CX is still the same */
508 DX_reg(context
) = SI_reg(context
);
509 bExtendedError
= INT21_CreateFile(context
);
511 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
513 WARN(int21
, "extended open/create: trunc failed\n");
514 return bExtendedError
;
519 else uReturnCX
= 0x1;
521 CX_reg(context
) = uReturnCX
;
523 else /* file does not exist */
525 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
526 if ((action
& 0xF0)== 0)
530 WARN(int21
, "extended open/create: failed, file dosen't exist\n");
534 /* Shuffle arguments to call CreateFile */
535 TRACE(int21
, "extended open/create: Creating\n");
536 AL_reg(context
) = BL_reg(context
);
537 /* CX should still be the same */
538 DX_reg(context
) = SI_reg(context
);
539 bExtendedError
= INT21_CreateFile(context
);
540 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
542 WARN(int21
, "extended open/create: create failed\n");
543 return bExtendedError
;
549 return bExtendedError
;
553 static BOOL32
INT21_ChangeDir( CONTEXT
*context
)
556 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
));
558 TRACE(int21
,"changedir %s\n", dirname
);
559 if (dirname
[0] && (dirname
[1] == ':'))
561 drive
= toupper(dirname
[0]) - 'A';
564 else drive
= DRIVE_GetCurrentDrive();
565 return DRIVE_Chdir( drive
, dirname
);
569 static int INT21_FindFirst( CONTEXT
*context
)
573 DOS_FULL_NAME full_name
;
574 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
576 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
));
577 dta
->unixPath
= NULL
;
578 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
580 AX_reg(context
) = DOS_ExtendedError
;
584 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
585 p
= strrchr( dta
->unixPath
, '/' );
588 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
589 * (doesn't matter as it is set below anyway)
591 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
593 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
594 dta
->unixPath
= NULL
;
595 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
596 AX_reg(context
) = ER_FileNotFound
;
600 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
601 : DRIVE_GetCurrentDrive();
603 dta
->search_attr
= CL_reg(context
);
608 static int INT21_FindNext( CONTEXT
*context
)
610 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
611 WIN32_FIND_DATA32A entry
;
614 if (!dta
->unixPath
) return 0;
615 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
616 dta
->search_attr
, dta
->count
, &entry
)))
618 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
619 dta
->unixPath
= NULL
;
622 if ((int)dta
->count
+ count
> 0xffff)
624 WARN(int21
, "Too many directory entries in %s\n", dta
->unixPath
);
625 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
626 dta
->unixPath
= NULL
;
630 dta
->fileattr
= entry
.dwFileAttributes
;
631 dta
->filesize
= entry
.nFileSizeLow
;
632 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
633 &dta
->filedate
, &dta
->filetime
);
634 strcpy( dta
->filename
, entry
.cAlternateFileName
);
635 if (!memchr(dta
->mask
,'?',11)) {
636 /* wildcardless search, release resources in case no findnext will
637 * be issued, and as a workaround in case file creation messes up
638 * findnext, as sometimes happens with pkunzip */
639 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
640 dta
->unixPath
= NULL
;
646 static BOOL32
INT21_CreateTempFile( CONTEXT
*context
)
648 static int counter
= 0;
649 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
) );
650 char *p
= name
+ strlen(name
);
652 /* despite what Ralf Brown says, some programs seem to call without
653 * ending backslash (DOS accepts that, so we accept it too) */
654 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
658 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
659 counter
= (counter
+ 1) % 1000;
661 if ((AX_reg(context
) = HFILE32_TO_HFILE16(_lcreat_uniq( name
, 0 ))) != (WORD
)HFILE_ERROR16
)
663 TRACE(int21
, "created %s\n", name
);
666 if (DOS_ExtendedError
!= ER_FileExists
) return FALSE
;
671 static BOOL32
INT21_GetCurrentDirectory( CONTEXT
*context
)
673 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
674 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), SI_reg(context
) );
676 if (!DRIVE_IsValid(drive
))
678 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
681 lstrcpyn32A( ptr
, DRIVE_GetDosCwd(drive
), 64 );
682 AX_reg(context
) = 0x0100; /* success return code */
687 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
689 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
));
690 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
692 if (!DRIVE_IsValid(drive
))
694 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
698 *(WORD
*)dataptr
= 0;
699 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
700 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
701 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
706 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
708 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
));
709 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
711 if (!DRIVE_IsValid(drive
))
713 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
717 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
722 /* microsoft's programmers should be shot for using CP/M style int21
723 calls in Windows for Workgroup's winfile.exe */
725 static int INT21_FindFirstFCB( CONTEXT
*context
)
727 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
));
732 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
733 else pFCB
= (FINDFILE_FCB
*)fcb
;
734 drive
= DOS_GET_DRIVE( pFCB
->drive
);
735 if (!DRIVE_IsValid( drive
)) return 0;
736 root
= DRIVE_GetRoot( drive
);
737 cwd
= DRIVE_GetUnixCwd( drive
);
738 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
739 strlen(root
)+strlen(cwd
)+2 );
740 if (!pFCB
->unixPath
) return 0;
741 strcpy( pFCB
->unixPath
, root
);
742 strcat( pFCB
->unixPath
, "/" );
743 strcat( pFCB
->unixPath
, cwd
);
749 static int INT21_FindNextFCB( CONTEXT
*context
)
751 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
));
753 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
754 WIN32_FIND_DATA32A entry
;
758 if (*fcb
== 0xff) /* extended FCB ? */
761 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
766 pFCB
= (FINDFILE_FCB
*)fcb
;
769 if (!pFCB
->unixPath
) return 0;
770 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
771 DOS_GET_DRIVE( pFCB
->drive
), attr
,
772 pFCB
->count
, &entry
)))
774 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
775 pFCB
->unixPath
= NULL
;
778 pFCB
->count
+= count
;
780 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
781 *(BYTE
*)pResult
= 0xff;
782 (BYTE
*)pResult
+=6; /* leave reserved field behind */
783 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
786 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
788 pResult
->fileattr
= entry
.dwFileAttributes
;
789 pResult
->cluster
= 0; /* what else? */
790 pResult
->filesize
= entry
.nFileSizeLow
;
791 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
792 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
793 &pResult
->filedate
, &pResult
->filetime
);
795 /* Convert file name to FCB format */
797 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
798 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
799 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
800 pResult
->filename
[0] = pResult
->filename
[1] = '.';
803 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
804 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
806 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
807 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
808 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
811 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
812 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
818 static void DeleteFileFCB( CONTEXT
*context
)
820 FIXME(int21
, "(%p): stub\n", context
);
823 static void RenameFileFCB( CONTEXT
*context
)
825 FIXME(int21
, "(%p): stub\n", context
);
830 static void fLock( CONTEXT
* context
)
833 switch ( AX_reg(context
) & 0xff )
835 case 0x00: /* LOCK */
836 TRACE(int21
,"lock handle %d offset %ld length %ld\n",
838 MAKELONG(DX_reg(context
),CX_reg(context
)),
839 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
840 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context
)),
841 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
842 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
843 AX_reg(context
) = DOS_ExtendedError
;
848 case 0x01: /* UNLOCK */
849 TRACE(int21
,"unlock handle %d offset %ld length %ld\n",
851 MAKELONG(DX_reg(context
),CX_reg(context
)),
852 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
853 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context
)),
854 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
855 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
856 AX_reg(context
) = DOS_ExtendedError
;
861 AX_reg(context
) = 0x0001;
868 INT21_networkfunc (CONTEXT
*context
)
870 switch (AL_reg(context
)) {
871 case 0x00: /* Get machine name. */
873 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),DX_reg(context
));
874 TRACE(int21
, "getting machine name to %p\n", dst
);
875 if (gethostname (dst
, 15))
877 WARN(int21
,"failed!\n");
878 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
881 int len
= strlen (dst
);
885 CH_reg(context
) = 1; /* Valid */
886 CL_reg(context
) = 1; /* NETbios number??? */
887 TRACE(int21
, "returning %s\n", debugstr_an (dst
, 16));
893 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
898 static void INT21_SetCurrentPSP(WORD psp
)
901 TDB
*pTask
= hModule
? NULL
: (TDB
*)GlobalLock16( GetCurrentTask() );
902 NE_MODULE
*pModule
= (hModule
|| pTask
) ? NE_GetPtr( hModule
? hModule
: pTask
->hModule
) : NULL
;
904 GlobalUnlock16( GetCurrentTask() );
905 if (pModule
->lpDosTask
)
906 pModule
->lpDosTask
->psp_seg
= psp
;
909 ERR(int21
, "Cannot change PSP for non-DOS task!\n");
912 static WORD
INT21_GetCurrentPSP()
915 TDB
*pTask
= hModule
? NULL
: (TDB
*)GlobalLock16( GetCurrentTask() );
916 NE_MODULE
*pModule
= (hModule
|| pTask
) ? NE_GetPtr( hModule
? hModule
: pTask
->hModule
) : NULL
;
918 GlobalUnlock16( GetCurrentTask() );
919 if (pModule
->lpDosTask
)
920 return pModule
->lpDosTask
->psp_seg
;
923 return GetCurrentPDB();
927 SEGPTR
INT21_GetListOfLists()
929 static DOS_LISTOFLISTS
*LOL
;
930 static SEGPTR seg_LOL
;
935 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
936 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
937 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
938 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
939 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
940 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
941 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
942 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
943 0133:00A0 D0 44 C8 FD D0 44 .D...D
946 LOL
= SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS
));
948 LOL
->CX_Int21_5e01
= 0x0;
949 LOL
->LRU_count_FCB_cache
= 0x0;
950 LOL
->LRU_count_FCB_open
= 0x0;
951 LOL
->OEM_func_handler
= -1; /* not available */
952 LOL
->INT21_offset
= 0x0;
953 LOL
->sharing_retry_count
= sharing_retries
; /* default value: 3 */
954 LOL
->sharing_retry_delay
= sharing_pause
; /* default value: 1 */
955 LOL
->ptr_disk_buf
= 0x0;
956 LOL
->offs_unread_CON
= 0x0;
957 LOL
->seg_first_MCB
= 0x0;
958 LOL
->ptr_first_DPB
= 0x0;
959 LOL
->ptr_first_SysFileTable
= 0x0;
960 LOL
->ptr_clock_dev_hdr
= 0x0;
961 LOL
->ptr_CON_dev_hdr
= 0x0;
962 LOL
->max_byte_per_sec
= 512;
963 LOL
->ptr_disk_buf_info
= 0x0;
964 LOL
->ptr_array_CDS
= 0x0;
965 LOL
->ptr_sys_FCB
= 0x0;
966 LOL
->nr_protect_FCB
= 0x0;
967 LOL
->nr_block_dev
= 0x0;
968 LOL
->nr_avail_drive_letters
= 26; /* A - Z */
969 LOL
->nr_drives_JOINed
= 0x0;
970 LOL
->ptr_spec_prg_names
= 0x0;
971 LOL
->ptr_SETVER_prg_list
= 0x0; /* no SETVER list */
972 LOL
->DOS_HIGH_A20_func_offs
= 0x0;
973 LOL
->PSP_last_exec
= 0x0;
974 LOL
->BUFFERS_val
= 99; /* maximum: 99 */
975 LOL
->BUFFERS_nr_lookahead
= 8; /* maximum: 8 */
976 LOL
->boot_drive
= 3; /* C: */
977 LOL
->flag_DWORD_moves
= 0x01; /* i386+ */
978 LOL
->size_extended_mem
= 0xf000; /* very high value */
980 if (!seg_LOL
) seg_LOL
= SEGPTR_GET(LOL
);
981 return seg_LOL
+(WORD
)&((DOS_LISTOFLISTS
*)0)->ptr_first_DPB
;
984 /***********************************************************************
985 * DOS3Call (KERNEL.102)
987 void WINAPI
DOS3Call( CONTEXT
*context
)
989 BOOL32 bSetDOSExtendedError
= FALSE
;
992 TRACE(int21
, "AX=%04x BX=%04x CX=%04x DX=%04x "
993 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
994 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
995 SI_reg(context
), DI_reg(context
),
996 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1000 if (AH_reg(context
) == 0x59) /* Get extended error info */
1002 TRACE(int21
, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1003 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
1004 AX_reg(context
) = DOS_ExtendedError
;
1005 BH_reg(context
) = DOS_ErrorClass
;
1006 BL_reg(context
) = DOS_ErrorAction
;
1007 CH_reg(context
) = DOS_ErrorLocus
;
1011 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1013 TRACE(int21
, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1014 /* no flush here yet */
1015 AH_reg(context
) = AL_reg(context
);
1018 DOS_ERROR( 0, 0, 0, 0 );
1019 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1021 switch(AH_reg(context
))
1023 case 0x00: /* TERMINATE PROGRAM */
1024 TRACE(int21
,"TERMINATE PROGRAM\n");
1028 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1029 case 0x03: /* READ CHARACTER FROM STDAUX */
1030 case 0x04: /* WRITE CHARACTER TO STDAUX */
1031 case 0x05: /* WRITE CHARACTER TO PRINTER */
1032 case 0x0b: /* GET STDIN STATUS */
1033 case 0x0f: /* OPEN FILE USING FCB */
1034 case 0x10: /* CLOSE FILE USING FCB */
1035 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1036 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1037 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1038 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1039 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1040 case 0x23: /* GET FILE SIZE FOR FCB */
1041 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1042 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1043 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1044 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1045 case 0x29: /* PARSE FILENAME INTO FCB */
1046 case 0x54: /* GET VERIFY FLAG */
1047 INT_BARF( context
, 0x21 );
1050 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1051 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1052 _lwrite16( 1, &DL_reg(context
), 1);
1055 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1056 TRACE(int21
,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1057 _lread16( 0, &AL_reg(context
), 1);
1060 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1061 TRACE(int21
,"CHARACTER INPUT WITHOUT ECHO\n");
1062 _lread16( 0, &AL_reg(context
), 1);
1065 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1066 TRACE(int21
,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1067 DS_reg(context
),DX_reg(context
) );
1069 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),DX_reg(context
));
1070 LONG length
= strchr(data
,'$')-data
;
1071 _hwrite16( 1, data
, length
);
1075 case 0x0a: /* BUFFERED INPUT */
1077 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1081 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1083 TRACE(int21
,"Handle old chars in buffer!\n");
1084 res
=_lread16( 0, buffer
+2,buffer
[0]);
1086 if(buffer
[res
+1] == '\n')
1087 buffer
[res
+1] = '\r';
1091 case 0x2e: /* SET VERIFY FLAG */
1092 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1093 /* we cannot change the behaviour anyway, so just ignore it */
1096 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1100 case 0x6b: /* NULL FUNCTION */
1101 AL_reg(context
) = 0;
1104 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1108 case 0x0d: /* DISK BUFFER FLUSH */
1109 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1110 RESET_CFLAG(context
); /* dos 6+ only */
1113 case 0x0e: /* SELECT DEFAULT DRIVE */
1114 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1115 DRIVE_SetCurrentDrive( DL_reg(context
) );
1116 AL_reg(context
) = MAX_DOS_DRIVES
;
1119 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1120 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1121 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1122 if (!INT21_FindFirstFCB(context
))
1124 AL_reg(context
) = 0xff;
1127 /* else fall through */
1129 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1130 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1133 case 0x13: /* DELETE FILE USING FCB */
1134 DeleteFileFCB(context
);
1137 case 0x17: /* RENAME FILE USING FCB */
1138 RenameFileFCB(context
);
1141 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1142 AL_reg(context
) = DRIVE_GetCurrentDrive();
1145 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1147 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1148 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1149 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1153 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1154 DL_reg(context
) = 0;
1155 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1158 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1159 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1162 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1163 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1166 case 0x25: /* SET INTERRUPT VECTOR */
1167 INT_CtxSetHandler( context
, AL_reg(context
),
1168 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1172 case 0x2a: /* GET SYSTEM DATE */
1173 INT21_GetSystemDate(context
);
1176 case 0x2b: /* SET SYSTEM DATE */
1177 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1178 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1179 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1182 case 0x2c: /* GET SYSTEM TIME */
1183 INT21_GetSystemTime(context
);
1186 case 0x2d: /* SET SYSTEM TIME */
1187 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1188 CH_reg(context
), CL_reg(context
),
1189 DH_reg(context
), DL_reg(context
) );
1190 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1193 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1194 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1196 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1197 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1198 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1202 case 0x30: /* GET DOS VERSION */
1203 TRACE(int21
,"GET DOS VERSION %s requested\n",
1204 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1205 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1206 (HIWORD(GetVersion16()) << 8);
1208 AH_reg(context
) = 0x7;
1209 AL_reg(context
) = 0xA;
1212 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1213 CX_reg(context
) = 0x0000;
1216 case 0x31: /* TERMINATE AND STAY RESIDENT */
1217 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1220 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1221 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1222 INT21_DriveName( DL_reg(context
)));
1223 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1226 case 0x33: /* MULTIPLEXED */
1227 switch (AL_reg(context
))
1229 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1230 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE stub\n");
1231 DL_reg(context
) = 0;
1234 case 0x01: /* SET EXTENDED BREAK STATE */
1235 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE stub\n");
1238 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1239 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1240 DL_reg(context
) = 0;
1243 case 0x05: /* GET BOOT DRIVE */
1244 TRACE(int21
,"GET BOOT DRIVE\n");
1245 DL_reg(context
) = 3;
1246 /* c: is Wine's bootdrive (a: is 1)*/
1249 case 0x06: /* GET TRUE VERSION NUMBER */
1250 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1251 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1252 (HIWORD(GetVersion16() << 8));
1253 DX_reg(context
) = 0x00;
1257 INT_BARF( context
, 0x21 );
1262 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1263 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1264 if (!heap
) INT21_CreateHeap();
1265 ES_reg(context
) = DosHeapHandle
;
1266 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1269 case 0x35: /* GET INTERRUPT VECTOR */
1270 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1272 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1273 ES_reg(context
) = SELECTOROF(addr
);
1274 BX_reg(context
) = OFFSETOF(addr
);
1278 case 0x36: /* GET FREE DISK SPACE */
1279 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1280 INT21_DriveName( DL_reg(context
)));
1281 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1286 unsigned char switchchar
='/';
1287 switch (AL_reg(context
))
1289 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1290 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1291 AL_reg(context
) = 0x00; /* success*/
1292 DL_reg(context
) = switchchar
;
1294 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1295 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1296 switchchar
= DL_reg(context
);
1297 AL_reg(context
) = 0x00; /* success*/
1299 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1300 INT_BARF( context
, 0x21 );
1306 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1307 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1309 AX_reg(context
) = 0x02; /* no country support available */
1313 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1314 TRACE(int21
,"MKDIR %s\n",
1315 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1316 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1317 DX_reg(context
) ), NULL
));
1320 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1321 TRACE(int21
,"RMDIR %s\n",
1322 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1323 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1324 DX_reg(context
) )));
1327 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1328 TRACE(int21
,"CHDIR %s\n",
1329 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1330 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1333 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1334 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1335 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1336 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1337 DX_reg(context
) ), CX_reg(context
) );
1338 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1341 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1342 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1343 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1344 OpenExistingFile(context
);
1347 case 0x3e: /* "CLOSE" - CLOSE FILE */
1348 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1349 if ((BX_reg(context
)<5)||
1350 /* FIXME: need to improve on those handle conversion macros */
1351 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE
)))||
1352 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE
)))||
1353 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE
)))) {
1354 /* hack to make sure stdio isn't closed */
1355 FIXME(int21
, "stdio handle closed, need proper conversion\n");
1356 DOS_ExtendedError
= 0x06;
1357 bSetDOSExtendedError
= TRUE
;
1359 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1362 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1363 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1364 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1368 result
= _hread16( BX_reg(context
),
1369 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1373 result
= WIN16_hread( BX_reg(context
),
1374 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1377 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1378 else AX_reg(context
) = (WORD
)result
;
1382 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1383 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1384 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1386 LONG result
= _hwrite16( BX_reg(context
),
1387 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1390 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1391 else AX_reg(context
) = (WORD
)result
;
1395 case 0x41: /* "UNLINK" - DELETE FILE */
1396 TRACE(int21
,"UNLINK%s\n",
1397 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1398 bSetDOSExtendedError
= (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1399 DX_reg(context
) )));
1402 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1403 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1404 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1405 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1406 "current file position":"end of file");
1408 LONG status
= _llseek16( BX_reg(context
),
1409 MAKELONG(DX_reg(context
),CX_reg(context
)),
1411 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1414 AX_reg(context
) = LOWORD(status
);
1415 DX_reg(context
) = HIWORD(status
);
1420 case 0x43: /* FILE ATTRIBUTES */
1421 switch (AL_reg(context
))
1424 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1425 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1426 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1427 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1429 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1430 else CX_reg(context
) = AX_reg(context
);
1434 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1435 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1436 bSetDOSExtendedError
=
1437 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1442 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1443 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1447 case 0x44: /* IOCTL */
1448 switch (AL_reg(context
))
1451 ioctlGetDeviceInfo(context
);
1458 file
= FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context
)));
1459 if (!strcasecmp(file
->unix_name
, "SCSIMGR$"))
1460 ASPI_DOS_HandleInt(context
);
1461 FILE_ReleaseFile( file
);
1464 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1465 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));*/
1466 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1468 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1469 /* for (i=0;i<CX_reg(context);i++)
1470 fprintf(stdnimp,"%02x ",dataptr[i]);
1471 fprintf(stdnimp,"\n");*/
1472 AX_reg(context
)=CX_reg(context
);
1475 case 0x08: /* Check if drive is removable. */
1476 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1477 INT21_DriveName( BL_reg(context
)));
1478 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1480 case DRIVE_CANNOTDETERMINE
:
1481 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1482 AX_reg(context
) = ER_InvalidDrive
;
1485 case DRIVE_REMOVABLE
:
1486 AX_reg(context
) = 0; /* removable */
1489 AX_reg(context
) = 1; /* not removable */
1494 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1495 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1496 INT21_DriveName( BL_reg(context
)));
1497 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1499 case DRIVE_CANNOTDETERMINE
:
1500 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1501 AX_reg(context
) = ER_InvalidDrive
;
1505 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1508 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1513 case 0x0a: /* check if handle (BX) is remote */
1514 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1515 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1518 DX_reg(context
) = 0;
1521 case 0x0b: /* SET SHARING RETRY COUNT */
1522 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1523 CX_reg(context
), DX_reg(context
));
1524 if (!CX_reg(context
))
1526 AX_reg(context
) = 1;
1530 sharing_pause
= CX_reg(context
);
1531 if (!DX_reg(context
))
1532 sharing_retries
= DX_reg(context
);
1533 RESET_CFLAG(context
);
1537 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1538 INT21_DriveName( BL_reg(context
)));
1539 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1542 case 0x0e: /* get logical drive mapping */
1543 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1544 INT21_DriveName( BL_reg(context
)));
1545 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1548 case 0x0F: /* Set logical drive mapping */
1551 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1552 INT21_DriveName( BL_reg(context
)));
1553 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1554 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1557 AX_reg(context
) = 0x000F; /* invalid drive */
1562 case 0xe0: /* Sun PC-NFS API */
1567 INT_BARF( context
, 0x21 );
1572 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1573 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1574 bSetDOSExtendedError
= ((AX_reg(context
) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context
))))) == (WORD
)HFILE_ERROR16
);
1577 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1578 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1579 BX_reg(context
),CX_reg(context
));
1580 bSetDOSExtendedError
= (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context
)), HFILE16_TO_HFILE32(CX_reg(context
)) ) == HFILE_ERROR32
);
1583 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1584 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1585 INT21_DriveName( DL_reg(context
)));
1586 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1589 case 0x48: /* ALLOCATE MEMORY */
1590 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1595 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1597 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1601 mem
= (LPVOID
)GlobalDOSAlloc(BX_reg(context
)<<4);
1603 AX_reg(context
) = (DWORD
)mem
&0xffff;
1608 AX_reg(context
) = 0x0008; /* insufficient memory */
1609 BX_reg(context
) = DOSMEM_Available(0)>>4;
1614 case 0x49: /* FREE MEMORY */
1615 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1619 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1622 ret
= !GlobalDOSFree(ES_reg(context
));
1623 /* If we don't reset ES_reg, we will fail in the relay code */
1624 ES_reg(context
)=ret
;
1628 TRACE(int21
,"FREE MEMORY failed\n");
1630 AX_reg(context
) = 0x0009; /* memory block address invalid */
1635 case 0x4a: /* RESIZE MEMORY BLOCK */
1636 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1637 if (!ISV86(context
))
1638 FIXME(int21
,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1640 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1641 BX_reg(context
)<<4,NULL
);
1643 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1646 AX_reg(context
) = 0x0008; /* insufficient memory */
1647 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1652 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1653 TRACE(int21
,"EXEC %s\n",
1654 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
) ));
1655 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1658 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1661 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1662 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1663 ExitProcess( AL_reg(context
) );
1666 case 0x4d: /* GET RETURN CODE */
1667 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1668 AX_reg(context
) = 0; /* normal exit */
1671 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1672 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1673 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1674 if (!INT21_FindFirst(context
)) break;
1677 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1678 TRACE(int21
,"FINDNEXT\n");
1679 if (!INT21_FindNext(context
))
1681 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1682 AX_reg(context
) = ER_NoMoreFiles
;
1685 else AX_reg(context
) = 0; /* OK */
1687 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1688 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1689 INT21_SetCurrentPSP(BX_reg(context
));
1691 case 0x51: /* GET PSP ADDRESS */
1692 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1693 /* FIXME: should we return the original DOS PSP upon */
1694 /* Windows startup ? */
1695 BX_reg(context
) = INT21_GetCurrentPSP();
1697 case 0x62: /* GET PSP ADDRESS */
1698 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1699 /* FIXME: should we return the original DOS PSP upon */
1700 /* Windows startup ? */
1701 BX_reg(context
) = INT21_GetCurrentPSP();
1704 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1705 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1708 lol
= INT21_GetListOfLists();
1709 ES_reg(context
) = HIWORD(lol
);
1710 BX_reg(context
) = LOWORD(lol
);
1714 case 0x56: /* "RENAME" - RENAME FILE */
1715 TRACE(int21
,"RENAME %s to %s\n",
1716 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
1717 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),DI_reg(context
)));
1718 bSetDOSExtendedError
=
1719 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
1720 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),DI_reg(context
))));
1723 case 0x57: /* FILE DATE AND TIME */
1724 switch (AL_reg(context
))
1726 case 0x00: /* Get */
1729 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1731 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context
)), NULL
, NULL
, &filetime
))
1732 bSetDOSExtendedError
= TRUE
;
1733 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1738 case 0x01: /* Set */
1741 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1743 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1745 bSetDOSExtendedError
=
1746 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1752 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1753 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1755 switch (AL_reg(context
))
1758 AX_reg(context
) = 1;
1761 AX_reg(context
) = 0;
1767 RESET_CFLAG(context
);
1770 case 0x5a: /* CREATE TEMPORARY FILE */
1771 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1772 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1775 case 0x5b: /* CREATE NEW FILE */
1776 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1777 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1778 bSetDOSExtendedError
= ((AX_reg(context
) =
1779 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)), 0 )))
1780 == (WORD
)HFILE_ERROR16
);
1783 case 0x5d: /* NETWORK */
1784 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1785 /* Fix the following while you're at it. */
1786 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1787 bSetDOSExtendedError
= TRUE
;
1791 bSetDOSExtendedError
= INT21_networkfunc (context
);
1794 case 0x5f: /* NETWORK */
1795 switch (AL_reg(context
))
1797 case 0x07: /* ENABLE DRIVE */
1798 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1799 if (!DRIVE_Enable( DL_reg(context
) ))
1801 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1802 bSetDOSExtendedError
= TRUE
;
1806 case 0x08: /* DISABLE DRIVE */
1807 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1808 if (!DRIVE_Disable( DL_reg(context
) ))
1810 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1811 bSetDOSExtendedError
= TRUE
;
1816 /* network software not installed */
1817 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1818 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1819 bSetDOSExtendedError
= TRUE
;
1824 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1825 TRACE(int21
,"TRUENAME %s\n",
1826 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),SI_reg(context
)));
1828 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1829 SI_reg(context
)), 128,
1830 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1831 DI_reg(context
)),NULL
))
1832 bSetDOSExtendedError
= TRUE
;
1833 else AX_reg(context
) = 0;
1837 case 0x61: /* UNUSED */
1838 case 0x63: /* UNUSED */
1839 case 0x64: /* OS/2 DOS BOX */
1840 INT_BARF( context
, 0x21 );
1844 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1845 extern WORD WINE_LanguageId
;
1846 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),DI_reg(context
));
1847 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1848 BX_reg(context
), DX_reg(context
));
1849 switch (AL_reg(context
)) {
1851 TRACE(int21
,"\tget general internationalization info\n");
1853 *(WORD
*)(dataptr
+1) = 41;
1854 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1855 *(WORD
*)(dataptr
+5) = CodePage
;
1856 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
1859 TRACE(int21
,"\tget pointer to collating sequence table\n");
1861 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1862 CX_reg(context
) = 258;/*FIXME: size of table?*/
1865 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1866 INT_BARF( context
, 0x21 );
1872 case 0x66: /* GLOBAL CODE PAGE TABLE */
1873 switch (AL_reg(context
))
1876 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
1877 DX_reg(context
) = BX_reg(context
) = CodePage
;
1878 RESET_CFLAG(context
);
1881 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1882 BX_reg(context
),DX_reg(context
));
1883 CodePage
= BX_reg(context
);
1884 RESET_CFLAG(context
);
1889 case 0x67: /* SET HANDLE COUNT */
1890 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
1891 SetHandleCount16( BX_reg(context
) );
1892 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1895 case 0x68: /* "FFLUSH" - COMMIT FILE */
1896 case 0x6a: /* COMMIT FILE */
1897 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
1898 bSetDOSExtendedError
= (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context
)) ));
1901 case 0x69: /* DISK SERIAL NUMBER */
1902 switch (AL_reg(context
))
1905 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
1906 INT21_DriveName(BL_reg(context
)));
1907 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1908 else AX_reg(context
) = 0;
1912 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
1913 INT21_DriveName(BL_reg(context
)));
1914 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1915 else AX_reg(context
) = 1;
1920 case 0x6C: /* Extended Open/Create*/
1921 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
1922 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DI_reg(context
)));
1923 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1926 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1927 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
1928 /* not supported on anything but Win95 */
1929 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
1931 AL_reg(context
) = 0;
1933 switch(AL_reg(context
))
1935 case 0x39: /* Create directory */
1936 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
1937 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1938 bSetDOSExtendedError
= (!CreateDirectory32A(
1939 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1940 DX_reg(context
) ), NULL
));
1942 case 0x3a: /* Remove directory */
1943 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1944 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1945 bSetDOSExtendedError
= (!RemoveDirectory32A(
1946 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1947 DX_reg(context
) )));
1949 case 0x43: /* Get/Set file attributes */
1950 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1951 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1952 switch (BL_reg(context
))
1954 case 0x00: /* Get file attributes */
1955 TRACE(int21
,"\tretrieve attributes\n");
1956 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1957 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1959 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1962 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
1963 bSetDOSExtendedError
= (!SetFileAttributes32A(
1964 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1966 CX_reg(context
) ) );
1969 FIXME(int21
, "Unimplemented long file name function:\n");
1970 INT_BARF( context
, 0x21 );
1972 AL_reg(context
) = 0;
1976 case 0x47: /* Get current directory */
1977 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1978 INT21_DriveName(DL_reg(context
)));
1979 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1982 case 0x4e: /* Find first file */
1983 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1984 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1985 /* FIXME: use attributes in CX */
1986 if ((AX_reg(context
) = FindFirstFile16(
1987 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
1988 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1990 == INVALID_HANDLE_VALUE16
)
1991 bSetDOSExtendedError
= TRUE
;
1993 case 0x4f: /* Find next file */
1994 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1996 if (!FindNextFile16( BX_reg(context
),
1997 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1999 bSetDOSExtendedError
= TRUE
;
2001 case 0xa1: /* Find close */
2002 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2004 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2007 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2008 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
2011 switch(CL_reg(context
))
2013 case 0x01: /*Get short filename or path */
2014 if (!GetShortPathName32A
2015 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2017 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2018 DI_reg(context
)), 67))
2019 bSetDOSExtendedError
= TRUE
;
2020 else AX_reg(context
) = 0;
2022 case 0x02: /*Get canonical long filename or path */
2023 if (!GetFullPathName32A
2024 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2025 SI_reg(context
)), 128,
2026 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2027 DI_reg(context
)),NULL
))
2028 bSetDOSExtendedError
= TRUE
;
2029 else AX_reg(context
) = 0;
2032 FIXME(int21
, "Unimplemented long file name function:\n");
2033 INT_BARF( context
, 0x21 );
2035 AL_reg(context
) = 0;
2039 case 0x6c: /* Create or open file */
2040 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2041 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), SI_reg(context
)));
2042 /* translate Dos 7 action to Dos 6 action */
2043 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2046 case 0x3b: /* Change directory */
2047 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2048 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
2049 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context
,
2055 AL_reg(context
) = DOS_ExtendedError
;
2058 case 0x41: /* Delete file */
2059 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2060 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
2061 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context
,
2066 AL_reg(context
) = DOS_ExtendedError
;
2069 case 0x56: /* Move (rename) file */
2070 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2071 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)),
2072 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), DI_reg(context
)));
2074 FIXME(int21
, "Unimplemented long file name function:\n");
2075 INT_BARF( context
, 0x21 );
2077 AL_reg(context
) = 0;
2082 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2083 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2084 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2085 TRACE(int21
,"windows95 function AX %04x\n",
2087 WARN(int21
, " returning unimplemented\n");
2089 AL_reg(context
) = 0;
2092 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2093 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2097 INT_BARF( context
, 0x21 );
2100 } /* END OF SWITCH */
2102 if( bSetDOSExtendedError
) /* set general error condition */
2104 AX_reg(context
) = DOS_ExtendedError
;
2108 if ((EFL_reg(context
) & 0x0001))
2109 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2110 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
2112 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2113 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2114 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2115 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2116 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2120 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
2122 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT32
)DosProc
);