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
);
1072 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1076 case 0x0a: /* BUFFERED INPUT */
1078 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1082 TRACE(int21
,"BUFFERED INPUT (size=%d)\n",buffer
[0]);
1084 TRACE(int21
,"Handle old chars in buffer!\n");
1085 res
=_lread16( 0, buffer
+2,buffer
[0]);
1087 if(buffer
[res
+1] == '\n')
1088 buffer
[res
+1] = '\r';
1092 case 0x2e: /* SET VERIFY FLAG */
1093 TRACE(int21
,"SET VERIFY FLAG ignored\n");
1094 /* we cannot change the behaviour anyway, so just ignore it */
1097 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1101 case 0x6b: /* NULL FUNCTION */
1102 AL_reg(context
) = 0;
1105 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1109 case 0x0d: /* DISK BUFFER FLUSH */
1110 TRACE(int21
,"DISK BUFFER FLUSH ignored\n");
1111 RESET_CFLAG(context
); /* dos 6+ only */
1114 case 0x0e: /* SELECT DEFAULT DRIVE */
1115 TRACE(int21
,"SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1116 DRIVE_SetCurrentDrive( DL_reg(context
) );
1117 AL_reg(context
) = MAX_DOS_DRIVES
;
1120 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1121 TRACE(int21
,"FIND FIRST MATCHING FILE USING FCB %p\n",
1122 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1123 if (!INT21_FindFirstFCB(context
))
1125 AL_reg(context
) = 0xff;
1128 /* else fall through */
1130 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1131 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1134 case 0x13: /* DELETE FILE USING FCB */
1135 DeleteFileFCB(context
);
1138 case 0x17: /* RENAME FILE USING FCB */
1139 RenameFileFCB(context
);
1142 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1143 AL_reg(context
) = DRIVE_GetCurrentDrive();
1146 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1148 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1149 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1150 TRACE(int21
, "Set DTA: %08lx\n", pTask
->dta
);
1154 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1155 DL_reg(context
) = 0;
1156 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1159 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1160 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1163 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1164 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1167 case 0x25: /* SET INTERRUPT VECTOR */
1168 INT_CtxSetHandler( context
, AL_reg(context
),
1169 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1173 case 0x2a: /* GET SYSTEM DATE */
1174 INT21_GetSystemDate(context
);
1177 case 0x2b: /* SET SYSTEM DATE */
1178 FIXME(int21
, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1179 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1180 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1183 case 0x2c: /* GET SYSTEM TIME */
1184 INT21_GetSystemTime(context
);
1187 case 0x2d: /* SET SYSTEM TIME */
1188 FIXME(int21
, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1189 CH_reg(context
), CL_reg(context
),
1190 DH_reg(context
), DL_reg(context
) );
1191 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1194 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1195 TRACE(int21
,"GET DISK TRANSFER AREA ADDRESS\n");
1197 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1198 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1199 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1203 case 0x30: /* GET DOS VERSION */
1204 TRACE(int21
,"GET DOS VERSION %s requested\n",
1205 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1206 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1207 (HIWORD(GetVersion16()) << 8);
1209 AH_reg(context
) = 0x7;
1210 AL_reg(context
) = 0xA;
1213 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1214 CX_reg(context
) = 0x0000;
1217 case 0x31: /* TERMINATE AND STAY RESIDENT */
1218 FIXME(int21
,"TERMINATE AND STAY RESIDENT stub\n");
1221 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1222 TRACE(int21
,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1223 INT21_DriveName( DL_reg(context
)));
1224 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1227 case 0x33: /* MULTIPLEXED */
1228 switch (AL_reg(context
))
1230 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1231 TRACE(int21
,"GET CURRENT EXTENDED BREAK STATE stub\n");
1232 DL_reg(context
) = 0;
1235 case 0x01: /* SET EXTENDED BREAK STATE */
1236 TRACE(int21
,"SET CURRENT EXTENDED BREAK STATE stub\n");
1239 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1240 TRACE(int21
,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1241 DL_reg(context
) = 0;
1244 case 0x05: /* GET BOOT DRIVE */
1245 TRACE(int21
,"GET BOOT DRIVE\n");
1246 DL_reg(context
) = 3;
1247 /* c: is Wine's bootdrive (a: is 1)*/
1250 case 0x06: /* GET TRUE VERSION NUMBER */
1251 TRACE(int21
,"GET TRUE VERSION NUMBER\n");
1252 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1253 (HIWORD(GetVersion16() << 8));
1254 DX_reg(context
) = 0x00;
1258 INT_BARF( context
, 0x21 );
1263 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1264 TRACE(int21
,"GET ADDRESS OF INDOS FLAG\n");
1265 if (!heap
) INT21_CreateHeap();
1266 ES_reg(context
) = DosHeapHandle
;
1267 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1270 case 0x35: /* GET INTERRUPT VECTOR */
1271 TRACE(int21
,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1273 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1274 ES_reg(context
) = SELECTOROF(addr
);
1275 BX_reg(context
) = OFFSETOF(addr
);
1279 case 0x36: /* GET FREE DISK SPACE */
1280 TRACE(int21
,"GET FREE DISK SPACE FOR DRIVE %s\n",
1281 INT21_DriveName( DL_reg(context
)));
1282 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1287 unsigned char switchchar
='/';
1288 switch (AL_reg(context
))
1290 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1291 TRACE(int21
,"SWITCHAR - GET SWITCH CHARACTER\n");
1292 AL_reg(context
) = 0x00; /* success*/
1293 DL_reg(context
) = switchchar
;
1295 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1296 TRACE(int21
,"SWITCHAR - SET SWITCH CHARACTER\n");
1297 switchchar
= DL_reg(context
);
1298 AL_reg(context
) = 0x00; /* success*/
1300 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1301 INT_BARF( context
, 0x21 );
1307 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1308 TRACE(int21
,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1310 AX_reg(context
) = 0x02; /* no country support available */
1314 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1315 TRACE(int21
,"MKDIR %s\n",
1316 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1317 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1318 DX_reg(context
) ), NULL
));
1321 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1322 TRACE(int21
,"RMDIR %s\n",
1323 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1324 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1325 DX_reg(context
) )));
1328 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1329 TRACE(int21
,"CHDIR %s\n",
1330 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1331 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1334 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1335 TRACE(int21
,"CREAT flag 0x%02x %s\n",CX_reg(context
),
1336 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1337 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1338 DX_reg(context
) ), CX_reg(context
) );
1339 bSetDOSExtendedError
= (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
1342 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1343 TRACE(int21
,"OPEN mode 0x%02x %s\n",AL_reg(context
),
1344 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1345 OpenExistingFile(context
);
1348 case 0x3e: /* "CLOSE" - CLOSE FILE */
1349 TRACE(int21
,"CLOSE handle %d\n",BX_reg(context
));
1350 if ((BX_reg(context
)<5)||
1351 /* FIXME: need to improve on those handle conversion macros */
1352 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE
)))||
1353 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE
)))||
1354 (BX_reg(context
)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE
)))) {
1355 /* hack to make sure stdio isn't closed */
1356 FIXME(int21
, "stdio handle closed, need proper conversion\n");
1357 DOS_ExtendedError
= 0x06;
1358 bSetDOSExtendedError
= TRUE
;
1360 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1363 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1364 TRACE(int21
,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1365 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1369 result
= _hread16( BX_reg(context
),
1370 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1374 result
= WIN16_hread( BX_reg(context
),
1375 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1378 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1379 else AX_reg(context
) = (WORD
)result
;
1383 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1384 TRACE(int21
,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1385 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1387 LONG result
= _hwrite16( BX_reg(context
),
1388 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1391 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1392 else AX_reg(context
) = (WORD
)result
;
1396 case 0x41: /* "UNLINK" - DELETE FILE */
1397 TRACE(int21
,"UNLINK%s\n",
1398 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1399 bSetDOSExtendedError
= (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1400 DX_reg(context
) )));
1403 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1404 TRACE(int21
,"LSEEK handle %d offset %ld from %s\n",
1405 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1406 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1407 "current file position":"end of file");
1409 LONG status
= _llseek16( BX_reg(context
),
1410 MAKELONG(DX_reg(context
),CX_reg(context
)),
1412 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1415 AX_reg(context
) = LOWORD(status
);
1416 DX_reg(context
) = HIWORD(status
);
1421 case 0x43: /* FILE ATTRIBUTES */
1422 switch (AL_reg(context
))
1425 TRACE(int21
,"GET FILE ATTRIBUTES for %s\n",
1426 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1427 AX_reg(context
) = (WORD
)GetFileAttributes32A(
1428 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1430 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1431 else CX_reg(context
) = AX_reg(context
);
1435 TRACE(int21
,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1436 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1437 bSetDOSExtendedError
=
1438 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1443 TRACE(int21
,"GET COMPRESSED FILE SIZE for %s stub\n",
1444 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1448 case 0x44: /* IOCTL */
1449 switch (AL_reg(context
))
1452 ioctlGetDeviceInfo(context
);
1459 file
= FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context
)));
1460 if (!strcasecmp(file
->unix_name
, "SCSIMGR$"))
1461 ASPI_DOS_HandleInt(context
);
1462 FILE_ReleaseFile( file
);
1465 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1466 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),DX_reg(context));*/
1467 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1469 FIXME(int21
,"program tried to write to block device control channel of drive %d:\n",drive
);
1470 /* for (i=0;i<CX_reg(context);i++)
1471 fprintf(stdnimp,"%02x ",dataptr[i]);
1472 fprintf(stdnimp,"\n");*/
1473 AX_reg(context
)=CX_reg(context
);
1476 case 0x08: /* Check if drive is removable. */
1477 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1478 INT21_DriveName( BL_reg(context
)));
1479 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1481 case DRIVE_CANNOTDETERMINE
:
1482 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1483 AX_reg(context
) = ER_InvalidDrive
;
1486 case DRIVE_REMOVABLE
:
1487 AX_reg(context
) = 0; /* removable */
1490 AX_reg(context
) = 1; /* not removable */
1495 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1496 TRACE(int21
,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1497 INT21_DriveName( BL_reg(context
)));
1498 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1500 case DRIVE_CANNOTDETERMINE
:
1501 DOS_ERROR( ER_InvalidDrive
, EC_NotFound
, SA_Abort
, EL_Disk
);
1502 AX_reg(context
) = ER_InvalidDrive
;
1506 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1509 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1514 case 0x0a: /* check if handle (BX) is remote */
1515 TRACE(int21
,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1516 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1519 DX_reg(context
) = 0;
1522 case 0x0b: /* SET SHARING RETRY COUNT */
1523 TRACE(int21
,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1524 CX_reg(context
), DX_reg(context
));
1525 if (!CX_reg(context
))
1527 AX_reg(context
) = 1;
1531 sharing_pause
= CX_reg(context
);
1532 if (!DX_reg(context
))
1533 sharing_retries
= DX_reg(context
);
1534 RESET_CFLAG(context
);
1538 TRACE(int21
,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1539 INT21_DriveName( BL_reg(context
)));
1540 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1543 case 0x0e: /* get logical drive mapping */
1544 TRACE(int21
,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1545 INT21_DriveName( BL_reg(context
)));
1546 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1549 case 0x0F: /* Set logical drive mapping */
1552 TRACE(int21
,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1553 INT21_DriveName( BL_reg(context
)));
1554 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1555 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1558 AX_reg(context
) = 0x000F; /* invalid drive */
1563 case 0xe0: /* Sun PC-NFS API */
1568 INT_BARF( context
, 0x21 );
1573 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1574 TRACE(int21
,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1575 bSetDOSExtendedError
= ((AX_reg(context
) = HFILE32_TO_HFILE16(FILE_Dup(HFILE16_TO_HFILE32(BX_reg(context
))))) == (WORD
)HFILE_ERROR16
);
1578 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1579 TRACE(int21
,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1580 BX_reg(context
),CX_reg(context
));
1581 bSetDOSExtendedError
= (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context
)), HFILE16_TO_HFILE32(CX_reg(context
)) ) == HFILE_ERROR32
);
1584 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1585 TRACE(int21
,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1586 INT21_DriveName( DL_reg(context
)));
1587 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1590 case 0x48: /* ALLOCATE MEMORY */
1591 TRACE(int21
,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1596 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1598 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1602 mem
= (LPVOID
)GlobalDOSAlloc(BX_reg(context
)<<4);
1604 AX_reg(context
) = (DWORD
)mem
&0xffff;
1609 AX_reg(context
) = 0x0008; /* insufficient memory */
1610 BX_reg(context
) = DOSMEM_Available(0)>>4;
1615 case 0x49: /* FREE MEMORY */
1616 TRACE(int21
,"FREE MEMORY segment %04lX\n", ES_reg(context
));
1620 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1623 ret
= !GlobalDOSFree(ES_reg(context
));
1624 /* If we don't reset ES_reg, we will fail in the relay code */
1625 ES_reg(context
)=ret
;
1629 TRACE(int21
,"FREE MEMORY failed\n");
1631 AX_reg(context
) = 0x0009; /* memory block address invalid */
1636 case 0x4a: /* RESIZE MEMORY BLOCK */
1637 TRACE(int21
,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1638 if (!ISV86(context
))
1639 FIXME(int21
,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1641 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1642 BX_reg(context
)<<4,NULL
);
1644 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1647 AX_reg(context
) = 0x0008; /* insufficient memory */
1648 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1653 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1654 TRACE(int21
,"EXEC %s\n",
1655 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
) ));
1656 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1659 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1662 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1663 TRACE(int21
,"EXIT with return code %d\n",AL_reg(context
));
1664 ExitProcess( AL_reg(context
) );
1667 case 0x4d: /* GET RETURN CODE */
1668 TRACE(int21
,"GET RETURN CODE (ERRORLEVEL)\n");
1669 AX_reg(context
) = 0; /* normal exit */
1672 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1673 TRACE(int21
,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1674 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1675 if (!INT21_FindFirst(context
)) break;
1678 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1679 TRACE(int21
,"FINDNEXT\n");
1680 if (!INT21_FindNext(context
))
1682 DOS_ERROR( ER_NoMoreFiles
, EC_MediaError
, SA_Abort
, EL_Disk
);
1683 AX_reg(context
) = ER_NoMoreFiles
;
1686 else AX_reg(context
) = 0; /* OK */
1688 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1689 TRACE(int21
, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1690 INT21_SetCurrentPSP(BX_reg(context
));
1692 case 0x51: /* GET PSP ADDRESS */
1693 TRACE(int21
,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1694 /* FIXME: should we return the original DOS PSP upon */
1695 /* Windows startup ? */
1696 BX_reg(context
) = INT21_GetCurrentPSP();
1698 case 0x62: /* GET PSP ADDRESS */
1699 TRACE(int21
,"GET CURRENT PSP ADDRESS\n");
1700 /* FIXME: should we return the original DOS PSP upon */
1701 /* Windows startup ? */
1702 BX_reg(context
) = INT21_GetCurrentPSP();
1705 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1706 TRACE(int21
,"SYSVARS - GET LIST OF LISTS\n");
1709 lol
= INT21_GetListOfLists();
1710 ES_reg(context
) = HIWORD(lol
);
1711 BX_reg(context
) = LOWORD(lol
);
1715 case 0x56: /* "RENAME" - RENAME FILE */
1716 TRACE(int21
,"RENAME %s to %s\n",
1717 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
1718 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),DI_reg(context
)));
1719 bSetDOSExtendedError
=
1720 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
1721 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),DI_reg(context
))));
1724 case 0x57: /* FILE DATE AND TIME */
1725 switch (AL_reg(context
))
1727 case 0x00: /* Get */
1730 TRACE(int21
,"GET FILE DATE AND TIME for handle %d\n",
1732 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context
)), NULL
, NULL
, &filetime
))
1733 bSetDOSExtendedError
= TRUE
;
1734 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1739 case 0x01: /* Set */
1742 TRACE(int21
,"SET FILE DATE AND TIME for handle %d\n",
1744 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1746 bSetDOSExtendedError
=
1747 (!SetFileTime( BX_reg(context
), NULL
, NULL
, &filetime
));
1753 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1754 TRACE(int21
,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1756 switch (AL_reg(context
))
1759 AX_reg(context
) = 1;
1762 AX_reg(context
) = 0;
1768 RESET_CFLAG(context
);
1771 case 0x5a: /* CREATE TEMPORARY FILE */
1772 TRACE(int21
,"CREATE TEMPORARY FILE\n");
1773 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1776 case 0x5b: /* CREATE NEW FILE */
1777 TRACE(int21
,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1778 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
1779 bSetDOSExtendedError
= ((AX_reg(context
) =
1780 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)), 0 )))
1781 == (WORD
)HFILE_ERROR16
);
1784 case 0x5d: /* NETWORK */
1785 FIXME(int21
,"Function 0x%04x not implemented.\n", AX_reg (context
));
1786 /* Fix the following while you're at it. */
1787 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1788 bSetDOSExtendedError
= TRUE
;
1792 bSetDOSExtendedError
= INT21_networkfunc (context
);
1795 case 0x5f: /* NETWORK */
1796 switch (AL_reg(context
))
1798 case 0x07: /* ENABLE DRIVE */
1799 TRACE(int21
,"ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1800 if (!DRIVE_Enable( DL_reg(context
) ))
1802 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1803 bSetDOSExtendedError
= TRUE
;
1807 case 0x08: /* DISABLE DRIVE */
1808 TRACE(int21
,"DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1809 if (!DRIVE_Disable( DL_reg(context
) ))
1811 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
1812 bSetDOSExtendedError
= TRUE
;
1817 /* network software not installed */
1818 TRACE(int21
,"NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1819 DOS_ERROR( ER_NoNetwork
, EC_NotFound
, SA_Abort
, EL_Network
);
1820 bSetDOSExtendedError
= TRUE
;
1825 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1826 TRACE(int21
,"TRUENAME %s\n",
1827 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),SI_reg(context
)));
1829 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1830 SI_reg(context
)), 128,
1831 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1832 DI_reg(context
)),NULL
))
1833 bSetDOSExtendedError
= TRUE
;
1834 else AX_reg(context
) = 0;
1838 case 0x61: /* UNUSED */
1839 case 0x63: /* UNUSED */
1840 case 0x64: /* OS/2 DOS BOX */
1841 INT_BARF( context
, 0x21 );
1845 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1846 extern WORD WINE_LanguageId
;
1847 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),DI_reg(context
));
1848 TRACE(int21
,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1849 BX_reg(context
), DX_reg(context
));
1850 switch (AL_reg(context
)) {
1852 TRACE(int21
,"\tget general internationalization info\n");
1854 *(WORD
*)(dataptr
+1) = 41;
1855 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
1856 *(WORD
*)(dataptr
+5) = CodePage
;
1857 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
1860 TRACE(int21
,"\tget pointer to collating sequence table\n");
1862 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1863 CX_reg(context
) = 258;/*FIXME: size of table?*/
1866 TRACE(int21
,"\tunimplemented function %d\n",AL_reg(context
));
1867 INT_BARF( context
, 0x21 );
1873 case 0x66: /* GLOBAL CODE PAGE TABLE */
1874 switch (AL_reg(context
))
1877 TRACE(int21
,"GET GLOBAL CODE PAGE TABLE\n");
1878 DX_reg(context
) = BX_reg(context
) = CodePage
;
1879 RESET_CFLAG(context
);
1882 TRACE(int21
,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1883 BX_reg(context
),DX_reg(context
));
1884 CodePage
= BX_reg(context
);
1885 RESET_CFLAG(context
);
1890 case 0x67: /* SET HANDLE COUNT */
1891 TRACE(int21
,"SET HANDLE COUNT to %d\n",BX_reg(context
) );
1892 SetHandleCount16( BX_reg(context
) );
1893 if (DOS_ExtendedError
) bSetDOSExtendedError
= TRUE
;
1896 case 0x68: /* "FFLUSH" - COMMIT FILE */
1897 case 0x6a: /* COMMIT FILE */
1898 TRACE(int21
,"FFLUSH/COMMIT handle %d\n",BX_reg(context
));
1899 bSetDOSExtendedError
= (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context
)) ));
1902 case 0x69: /* DISK SERIAL NUMBER */
1903 switch (AL_reg(context
))
1906 TRACE(int21
,"GET DISK SERIAL NUMBER for drive %s\n",
1907 INT21_DriveName(BL_reg(context
)));
1908 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1909 else AX_reg(context
) = 0;
1913 TRACE(int21
,"SET DISK SERIAL NUMBER for drive %s\n",
1914 INT21_DriveName(BL_reg(context
)));
1915 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
1916 else AX_reg(context
) = 1;
1921 case 0x6C: /* Extended Open/Create*/
1922 TRACE(int21
,"EXTENDED OPEN/CREATE %s\n",
1923 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DI_reg(context
)));
1924 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
1927 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1928 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
1929 /* not supported on anything but Win95 */
1930 TRACE(int21
,"LONG FILENAME functions supported only by win95\n");
1932 AL_reg(context
) = 0;
1934 switch(AL_reg(context
))
1936 case 0x39: /* Create directory */
1937 TRACE(int21
,"LONG FILENAME - MAKE DIRECTORY %s\n",
1938 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1939 bSetDOSExtendedError
= (!CreateDirectory32A(
1940 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1941 DX_reg(context
) ), NULL
));
1943 case 0x3a: /* Remove directory */
1944 TRACE(int21
,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1945 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1946 bSetDOSExtendedError
= (!RemoveDirectory32A(
1947 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1948 DX_reg(context
) )));
1950 case 0x43: /* Get/Set file attributes */
1951 TRACE(int21
,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1952 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1953 switch (BL_reg(context
))
1955 case 0x00: /* Get file attributes */
1956 TRACE(int21
,"\tretrieve attributes\n");
1957 CX_reg(context
) = (WORD
)GetFileAttributes32A(
1958 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1960 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1963 TRACE(int21
,"\tset attributes 0x%04x\n",CX_reg(context
));
1964 bSetDOSExtendedError
= (!SetFileAttributes32A(
1965 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1967 CX_reg(context
) ) );
1970 FIXME(int21
, "Unimplemented long file name function:\n");
1971 INT_BARF( context
, 0x21 );
1973 AL_reg(context
) = 0;
1977 case 0x47: /* Get current directory */
1978 TRACE(int21
," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1979 INT21_DriveName(DL_reg(context
)));
1980 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1983 case 0x4e: /* Find first file */
1984 TRACE(int21
," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1985 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
1986 /* FIXME: use attributes in CX */
1987 if ((AX_reg(context
) = FindFirstFile16(
1988 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)),
1989 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1991 == INVALID_HANDLE_VALUE16
)
1992 bSetDOSExtendedError
= TRUE
;
1994 case 0x4f: /* Find next file */
1995 TRACE(int21
,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1997 if (!FindNextFile16( BX_reg(context
),
1998 (WIN32_FIND_DATA32A
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2000 bSetDOSExtendedError
= TRUE
;
2002 case 0xa1: /* Find close */
2003 TRACE(int21
,"LONG FILENAME - FINDCLOSE for handle %d\n",
2005 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2008 TRACE(int21
,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2009 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),DX_reg(context
)));
2012 switch(CL_reg(context
))
2014 case 0x01: /*Get short filename or path */
2015 if (!GetShortPathName32A
2016 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2018 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2019 DI_reg(context
)), 67))
2020 bSetDOSExtendedError
= TRUE
;
2021 else AX_reg(context
) = 0;
2023 case 0x02: /*Get canonical long filename or path */
2024 if (!GetFullPathName32A
2025 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2026 SI_reg(context
)), 128,
2027 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2028 DI_reg(context
)),NULL
))
2029 bSetDOSExtendedError
= TRUE
;
2030 else AX_reg(context
) = 0;
2033 FIXME(int21
, "Unimplemented long file name function:\n");
2034 INT_BARF( context
, 0x21 );
2036 AL_reg(context
) = 0;
2040 case 0x6c: /* Create or open file */
2041 TRACE(int21
,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2042 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), SI_reg(context
)));
2043 /* translate Dos 7 action to Dos 6 action */
2044 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2047 case 0x3b: /* Change directory */
2048 TRACE(int21
,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2049 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
2050 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context
,
2056 AL_reg(context
) = DOS_ExtendedError
;
2059 case 0x41: /* Delete file */
2060 TRACE(int21
,"LONG FILENAME - DELETE FILE %s\n",
2061 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)));
2062 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context
,
2067 AL_reg(context
) = DOS_ExtendedError
;
2070 case 0x56: /* Move (rename) file */
2071 TRACE(int21
,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2072 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), DX_reg(context
)),
2073 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), DI_reg(context
)));
2075 FIXME(int21
, "Unimplemented long file name function:\n");
2076 INT_BARF( context
, 0x21 );
2078 AL_reg(context
) = 0;
2083 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2084 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2085 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2086 TRACE(int21
,"windows95 function AX %04x\n",
2088 WARN(int21
, " returning unimplemented\n");
2090 AL_reg(context
) = 0;
2093 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2094 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2098 INT_BARF( context
, 0x21 );
2101 } /* END OF SWITCH */
2103 if( bSetDOSExtendedError
) /* set general error condition */
2105 AX_reg(context
) = DOS_ExtendedError
;
2109 if ((EFL_reg(context
) & 0x0001))
2110 TRACE(int21
, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2111 DOS_ExtendedError
, DOS_ErrorClass
, DOS_ErrorAction
, DOS_ErrorLocus
);
2113 TRACE(int21
, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2114 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2115 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2116 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2117 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2121 FARPROC16 WINAPI
GetSetKernelDOSProc(FARPROC16 DosProc
)
2123 FIXME(int21
, "(DosProc=0x%08x): stub\n", (UINT32
)DosProc
);