2 * DOS interrupt 21h handler
11 #ifdef HAVE_SYS_FILE_H
12 # include <sys/file.h>
17 #include <sys/types.h>
24 #include "winuser.h" /* SW_NORMAL */
25 #include "wine/winbase16.h"
35 #include "dosexe.h" /* for the MZ_SUPPORTED define */
37 #include "debugtools.h"
40 DEFAULT_DEBUG_CHANNEL(int21
)
41 #if defined(__svr4__) || defined(_SCO_DS)
42 /* SVR4 DOESNT do locking the same way must implement properly */
49 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
51 /* Define the drive parameter block, as used by int21/1F
52 * and int21/32. This table can be accessed through the
53 * global 'dpb' pointer, which points into the local dos
58 BYTE drive_num
; /* 0=A, etc. */
59 BYTE unit_num
; /* Drive's unit number (?) */
60 WORD sector_size
; /* Sector size in bytes */
61 BYTE high_sector
; /* Highest sector in a cluster */
62 BYTE shift
; /* Shift count (?) */
63 WORD reserved
; /* Number of reserved sectors at start */
64 BYTE num_FAT
; /* Number of FATs */
65 WORD dir_entries
; /* Number of root dir entries */
66 WORD first_data
; /* First data sector */
67 WORD high_cluster
; /* Highest cluster number */
68 WORD sectors_in_FAT
; /* Number of sectors per FAT */
69 WORD start_dir
; /* Starting sector of first dir */
70 DWORD driver_head
; /* Address of device driver header (?) */
71 BYTE media_ID
; /* Media ID */
72 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
73 DWORD next
; /* Pointer to next DPB in list */
74 WORD free_search
; /* Free cluster search start */
75 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
86 BYTE DummyDBCSLeadTable
[6];
88 static struct DosHeap
*heap
;
89 static WORD DosHeapHandle
;
91 extern char TempDirectory
[];
93 static BOOL
INT21_CreateHeap(void)
95 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
97 WARN("Out of memory\n");
100 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
101 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
103 strcpy(heap
->biosdate
, "01/01/80");
104 memset(heap
->DummyDBCSLeadTable
, 0, 6);
108 static BYTE
*GetCurrentDTA( CONTEXT86
*context
)
110 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
112 /* FIXME: This assumes DTA was set correctly! */
113 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
114 (DWORD
)OFFSETOF(pTask
->dta
) );
118 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
119 /* limited == TRUE is used with INT 0x21/0x440d */
124 setword(&data
[3], 0);
126 setword(&data
[6], 240);
127 setword(&data
[8], 64000);
129 setword(&data
[0x0b], 40);
130 setword(&data
[0x0d], 56);
131 setword(&data
[0x0f], 2);
132 setword(&data
[0x11], 0);
134 setword(&data
[0x1f], 800);
136 setword(&data
[0x22], 1);
138 } else { /* 1.44mb */
141 setword(&data
[3], 0);
143 setword(&data
[6], 240);
144 setword(&data
[8], 2880);
146 setword(&data
[0x0b], 6);
147 setword(&data
[0x0d], 18);
148 setword(&data
[0x0f], 2);
149 setword(&data
[0x11], 0);
151 setword(&data
[0x1f], 80);
153 setword(&data
[0x22], 2);
158 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
160 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
161 char root
[] = "A:\\";
163 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
164 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
165 &free_clusters
, &total_clusters
)) return 0;
166 AX_reg(context
) = cluster_sectors
;
167 BX_reg(context
) = free_clusters
;
168 CX_reg(context
) = sector_bytes
;
169 DX_reg(context
) = total_clusters
;
173 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
)
175 if (!INT21_GetFreeDiskSpace( context
)) return 0;
176 if (!heap
&& !INT21_CreateHeap()) return 0;
177 heap
->mediaID
= 0xf0;
178 DS_reg(context
) = DosHeapHandle
;
179 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
183 static void GetDrivePB( CONTEXT86
*context
, int drive
)
185 if(!DRIVE_IsValid(drive
))
187 SetLastError( ERROR_INVALID_DRIVE
);
188 AX_reg(context
) = 0x00ff;
190 else if (heap
|| INT21_CreateHeap())
192 FIXME("GetDrivePB not fully implemented.\n");
194 /* FIXME: I have no idea what a lot of this information should
195 * say or whether it even really matters since we're not allowing
196 * direct block access. However, some programs seem to depend on
197 * getting at least _something_ back from here. The 'next' pointer
198 * does worry me, though. Should we have a complete table of
199 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
201 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
202 heap
->dpb
.sector_size
= 512;
203 heap
->dpb
.high_sector
= 1;
204 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
205 heap
->dpb
.reserved
= 0;
206 heap
->dpb
.num_FAT
= 1;
207 heap
->dpb
.dir_entries
= 2;
208 heap
->dpb
.first_data
= 2;
209 heap
->dpb
.high_cluster
= 64000;
210 heap
->dpb
.sectors_in_FAT
= 1;
211 heap
->dpb
.start_dir
= 1;
212 heap
->dpb
.driver_head
= 0;
213 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
214 heap
->dpb
.access_flag
= 0;
216 heap
->dpb
.free_search
= 0;
217 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
219 AL_reg(context
) = 0x00;
220 DS_reg(context
) = SELECTOROF(dpbsegptr
);
221 BX_reg(context
) = OFFSETOF(dpbsegptr
);
226 static void ioctlGetDeviceInfo( CONTEXT86
*context
)
229 const DOS_DEVICE
*dev
;
231 TRACE("(%d)\n", BX_reg(context
));
233 RESET_CFLAG(context
);
236 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )))
238 DX_reg(context
) = dev
->flags
;
242 /* it seems to be a file */
243 curr_drive
= DRIVE_GetCurrentDrive();
244 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
246 /* bits 0-5 are current drive
247 * bit 6 - file has NOT been written..FIXME: correct?
248 * bit 8 - generate int24 if no diskspace on write/ read past end of file
249 * bit 11 - media not removable
250 * bit 14 - don't set file date/time on closing
251 * bit 15 - file is remote
255 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
257 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
258 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
260 if (!DRIVE_IsValid(drive
))
262 SetLastError( ERROR_FILE_NOT_FOUND
);
266 if (CH_reg(context
) != 0x08)
268 INT_BARF( context
, 0x21 );
272 switch (CL_reg(context
))
274 case 0x4a: /* lock logical volume */
275 TRACE("lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
278 case 0x60: /* get device parameters */
279 /* used by w4wgrp's winfile */
280 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
282 dataptr
[6] = 0; /* media type */
285 dataptr
[1] = 0x05; /* fixed disk */
286 setword(&dataptr
[2], 0x01); /* non removable */
287 setword(&dataptr
[4], 0x300); /* # of cylinders */
291 dataptr
[1] = 0x07; /* block dev, floppy */
292 setword(&dataptr
[2], 0x02); /* removable */
293 setword(&dataptr
[4], 80); /* # of cylinders */
295 CreateBPB(drive
, &dataptr
[7], TRUE
);
296 RESET_CFLAG(context
);
299 case 0x41: /* write logical device track */
300 case 0x61: /* read logical device track */
302 BYTE drive
= BL_reg(context
) ?
303 BL_reg(context
) : DRIVE_GetCurrentDrive();
304 WORD head
= *(WORD
*)dataptr
+1;
305 WORD cyl
= *(WORD
*)dataptr
+3;
306 WORD sect
= *(WORD
*)dataptr
+5;
307 WORD nrsect
= *(WORD
*)dataptr
+7;
308 BYTE
*data
= (BYTE
*)dataptr
+9;
309 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
311 raw_func
= (CL_reg(context
) == 0x41) ?
312 DRIVE_RawWrite
: DRIVE_RawRead
;
314 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
315 RESET_CFLAG(context
);
318 AX_reg(context
) = 0x1e; /* read fault */
323 case 0x66:/* get disk serial number */
325 char label
[12],fsname
[9],path
[4];
328 strcpy(path
,"x:\\");path
[0]=drive
+'A';
329 GetVolumeInformationA(
330 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
333 memcpy(dataptr
+2,&serial
,4);
334 memcpy(dataptr
+6,label
,11);
335 memcpy(dataptr
+17,fsname
,8);
340 TRACE("logical volume %d unlocked.\n",drive
);
344 memset(dataptr
+1, '\0', dataptr
[0]-1);
345 dataptr
[1] = dataptr
[0];
346 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
347 dataptr
[3] = 0xFF; /* no physical drive */
351 /* Trail on error implementation */
352 AX_reg(context
) = GetDriveType16(BL_reg(context
)) == DRIVE_CANNOTDETERMINE
? 0x0f : 0x01;
353 SET_CFLAG(context
); /* Seems to be set all the time */
357 INT_BARF( context
, 0x21 );
362 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
365 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
367 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
368 char *buffer
, *s
, *d
;
370 AL_reg(context
) = 0xff; /* failed */
372 TRACE("filename: '%s'\n", filename
);
374 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
380 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
387 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
389 TRACE("FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
391 HeapFree( GetProcessHeap(), 0, buffer
);
394 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
396 /* point DS:SI to first unparsed character */
397 SI_reg(context
) += (int)s
- (int)filename
;
400 static void INT21_GetSystemDate( CONTEXT86
*context
)
403 GetLocalTime( &systime
);
404 CX_reg(context
) = systime
.wYear
;
405 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
406 AX_reg(context
) = systime
.wDayOfWeek
;
409 static void INT21_GetSystemTime( CONTEXT86
*context
)
412 GetLocalTime( &systime
);
413 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
414 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
417 /* Many calls translate a drive argument like this:
418 drive number (00h = default, 01h = A:, etc)
420 static char drivestring
[]="default";
422 char *INT21_DriveName(int drive
)
427 drivestring
[0]= (unsigned char)drive
+ '@';
433 static BOOL
INT21_CreateFile( CONTEXT86
*context
)
435 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
436 EDX_reg(context
) ), CX_reg(context
) );
437 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
440 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
442 /* Mask off all flags not explicitly allowed by the doc */
443 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
444 return FILE_AllocDosHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
445 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
446 CREATE_NEW
, attr
, -1 ));
449 static void OpenExistingFile( CONTEXT86
*context
)
451 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
453 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
455 AX_reg(context
) = GetLastError();
460 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT86
*context
)
462 BOOL bExtendedError
= FALSE
;
463 BYTE action
= DL_reg(context
);
465 /* Shuffle arguments to call OpenExistingFile */
466 AL_reg(context
) = BL_reg(context
);
467 DX_reg(context
) = SI_reg(context
);
468 /* BX,CX and DX should be preserved */
469 OpenExistingFile(context
);
471 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
473 UINT16 uReturnCX
= 0;
475 /* Now decide what do do */
477 if ((action
& 0x07) == 0)
479 _lclose16( AX_reg(context
) );
480 AX_reg(context
) = 0x0050; /*File exists*/
482 WARN("extended open/create: failed because file exists \n");
484 else if ((action
& 0x07) == 2)
486 /* Truncate it, but first check if opened for write */
487 if ((BL_reg(context
) & 0x0007)== 0)
489 _lclose16( AX_reg(context
) );
490 WARN("extended open/create: failed, trunc on ro file\n");
491 AX_reg(context
) = 0x000C; /*Access code invalid*/
496 TRACE("extended open/create: Closing before truncate\n");
497 if (_lclose16( AX_reg(context
) ))
499 WARN("extended open/create: close before trunc failed\n");
500 AX_reg(context
) = 0x0019; /*Seek Error*/
504 /* Shuffle arguments to call CreateFile */
506 TRACE("extended open/create: Truncating\n");
507 AL_reg(context
) = BL_reg(context
);
508 /* CX is still the same */
509 DX_reg(context
) = SI_reg(context
);
510 bExtendedError
= INT21_CreateFile(context
);
512 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
514 WARN("extended open/create: trunc failed\n");
515 return bExtendedError
;
520 else uReturnCX
= 0x1;
522 CX_reg(context
) = uReturnCX
;
524 else /* file does not exist */
526 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
527 if ((action
& 0xF0)== 0)
531 WARN("extended open/create: failed, file dosen't exist\n");
535 /* Shuffle arguments to call CreateFile */
536 TRACE("extended open/create: Creating\n");
537 AL_reg(context
) = BL_reg(context
);
538 /* CX should still be the same */
539 DX_reg(context
) = SI_reg(context
);
540 bExtendedError
= INT21_CreateFile(context
);
541 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
543 WARN("extended open/create: create failed\n");
544 return bExtendedError
;
550 return bExtendedError
;
554 static BOOL
INT21_ChangeDir( CONTEXT86
*context
)
557 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
559 TRACE("changedir %s\n", dirname
);
560 if (dirname
[0] && (dirname
[1] == ':'))
562 drive
= toupper(dirname
[0]) - 'A';
565 else drive
= DRIVE_GetCurrentDrive();
566 return DRIVE_Chdir( drive
, dirname
);
570 static int INT21_FindFirst( CONTEXT86
*context
)
574 DOS_FULL_NAME full_name
;
575 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
577 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
578 dta
->unixPath
= NULL
;
579 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
581 AX_reg(context
) = GetLastError();
585 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
586 p
= strrchr( dta
->unixPath
, '/' );
589 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
590 * (doesn't matter as it is set below anyway)
592 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
594 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
595 dta
->unixPath
= NULL
;
596 SetLastError( ERROR_FILE_NOT_FOUND
);
597 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
601 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
602 : DRIVE_GetCurrentDrive();
604 dta
->search_attr
= CL_reg(context
);
609 static int INT21_FindNext( CONTEXT86
*context
)
611 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
612 WIN32_FIND_DATAA entry
;
615 if (!dta
->unixPath
) return 0;
616 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
617 dta
->search_attr
, dta
->count
, &entry
)))
619 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
620 dta
->unixPath
= NULL
;
623 if ((int)dta
->count
+ count
> 0xffff)
625 WARN("Too many directory entries in %s\n", dta
->unixPath
);
626 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
627 dta
->unixPath
= NULL
;
631 dta
->fileattr
= entry
.dwFileAttributes
;
632 dta
->filesize
= entry
.nFileSizeLow
;
633 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
634 &dta
->filedate
, &dta
->filetime
);
635 strcpy( dta
->filename
, entry
.cAlternateFileName
);
636 if (!memchr(dta
->mask
,'?',11)) {
637 /* wildcardless search, release resources in case no findnext will
638 * be issued, and as a workaround in case file creation messes up
639 * findnext, as sometimes happens with pkunzip */
640 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
641 dta
->unixPath
= NULL
;
647 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
649 static int counter
= 0;
650 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
651 char *p
= name
+ strlen(name
);
653 /* despite what Ralf Brown says, some programs seem to call without
654 * ending backslash (DOS accepts that, so we accept it too) */
655 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
659 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
660 counter
= (counter
+ 1) % 1000;
662 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
664 TRACE("created %s\n", name
);
667 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
672 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
)
674 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
675 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
677 if (!DRIVE_IsValid(drive
))
679 SetLastError( ERROR_INVALID_DRIVE
);
682 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
683 AX_reg(context
) = 0x0100; /* success return code */
688 static void INT21_GetDBCSLeadTable( CONTEXT86
*context
)
690 if (heap
|| INT21_CreateHeap())
691 { /* return an empty table just as DOS 4.0+ does */
692 DS_reg(context
) = DosHeapHandle
;
693 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
697 AX_reg(context
) = 0x1; /* error */
703 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
705 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
706 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
708 if (!DRIVE_IsValid(drive
))
710 SetLastError( ERROR_INVALID_DRIVE
);
714 *(WORD
*)dataptr
= 0;
715 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
716 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
717 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
722 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
724 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
725 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
727 if (!DRIVE_IsValid(drive
))
729 SetLastError( ERROR_INVALID_DRIVE
);
733 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
738 /* microsoft's programmers should be shot for using CP/M style int21
739 calls in Windows for Workgroup's winfile.exe */
741 static int INT21_FindFirstFCB( CONTEXT86
*context
)
743 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
748 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
749 else pFCB
= (FINDFILE_FCB
*)fcb
;
750 drive
= DOS_GET_DRIVE( pFCB
->drive
);
751 if (!DRIVE_IsValid( drive
)) return 0;
752 root
= DRIVE_GetRoot( drive
);
753 cwd
= DRIVE_GetUnixCwd( drive
);
754 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
755 strlen(root
)+strlen(cwd
)+2 );
756 if (!pFCB
->unixPath
) return 0;
757 strcpy( pFCB
->unixPath
, root
);
758 strcat( pFCB
->unixPath
, "/" );
759 strcat( pFCB
->unixPath
, cwd
);
765 static int INT21_FindNextFCB( CONTEXT86
*context
)
767 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
769 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
770 WIN32_FIND_DATAA entry
;
774 if (*fcb
== 0xff) /* extended FCB ? */
777 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
782 pFCB
= (FINDFILE_FCB
*)fcb
;
785 if (!pFCB
->unixPath
) return 0;
786 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
787 DOS_GET_DRIVE( pFCB
->drive
), attr
,
788 pFCB
->count
, &entry
)))
790 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
791 pFCB
->unixPath
= NULL
;
794 pFCB
->count
+= count
;
796 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
797 *(BYTE
*)pResult
= 0xff;
798 (BYTE
*)pResult
+=6; /* leave reserved field behind */
799 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
802 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
804 pResult
->fileattr
= entry
.dwFileAttributes
;
805 pResult
->cluster
= 0; /* what else? */
806 pResult
->filesize
= entry
.nFileSizeLow
;
807 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
808 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
809 &pResult
->filedate
, &pResult
->filetime
);
811 /* Convert file name to FCB format */
813 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
814 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
815 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
816 pResult
->filename
[0] = pResult
->filename
[1] = '.';
819 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
820 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
822 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
823 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
824 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
827 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
828 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
834 static void DeleteFileFCB( CONTEXT86
*context
)
836 FIXME("(%p): stub\n", context
);
839 static void RenameFileFCB( CONTEXT86
*context
)
841 FIXME("(%p): stub\n", context
);
846 static void fLock( CONTEXT86
* context
)
849 switch ( AX_reg(context
) & 0xff )
851 case 0x00: /* LOCK */
852 TRACE("lock handle %d offset %ld length %ld\n",
854 MAKELONG(DX_reg(context
),CX_reg(context
)),
855 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
856 if (!LockFile(FILE_GetHandle(BX_reg(context
)),
857 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
858 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
859 AX_reg(context
) = GetLastError();
864 case 0x01: /* UNLOCK */
865 TRACE("unlock handle %d offset %ld length %ld\n",
867 MAKELONG(DX_reg(context
),CX_reg(context
)),
868 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
869 if (!UnlockFile(FILE_GetHandle(BX_reg(context
)),
870 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
871 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
872 AX_reg(context
) = GetLastError();
877 AX_reg(context
) = 0x0001;
884 INT21_networkfunc (CONTEXT86
*context
)
886 switch (AL_reg(context
)) {
887 case 0x00: /* Get machine name. */
889 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
890 TRACE("getting machine name to %p\n", dst
);
891 if (gethostname (dst
, 15))
894 SetLastError( ER_NoNetwork
);
897 int len
= strlen (dst
);
901 CH_reg(context
) = 1; /* Valid */
902 CL_reg(context
) = 1; /* NETbios number??? */
903 TRACE("returning %s\n", debugstr_an (dst
, 16));
909 SetLastError( ER_NoNetwork
);
914 static void INT21_SetCurrentPSP(WORD psp
)
917 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
918 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
920 GlobalUnlock16( GetCurrentTask() );
921 if (pModule
->lpDosTask
)
922 pModule
->lpDosTask
->psp_seg
= psp
;
925 ERR("Cannot change PSP for non-DOS task!\n");
928 static WORD
INT21_GetCurrentPSP()
931 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
932 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
934 GlobalUnlock16( GetCurrentTask() );
935 if (pModule
->lpDosTask
)
936 return pModule
->lpDosTask
->psp_seg
;
939 return GetCurrentPDB16();
943 /***********************************************************************
944 * INT21_GetExtendedError
946 static void INT21_GetExtendedError( CONTEXT86
*context
)
948 BYTE
class, action
, locus
;
949 WORD error
= GetLastError();
954 class = action
= locus
= 0;
956 case ERROR_DIR_NOT_EMPTY
:
961 case ERROR_ACCESS_DENIED
:
962 class = EC_AccessDenied
;
966 case ERROR_CANNOT_MAKE
:
967 class = EC_AccessDenied
;
971 case ERROR_DISK_FULL
:
972 case ERROR_HANDLE_DISK_FULL
:
973 class = EC_MediaError
;
977 case ERROR_FILE_EXISTS
:
978 case ERROR_ALREADY_EXISTS
:
983 case ERROR_FILE_NOT_FOUND
:
988 case ER_GeneralFailure
:
989 class = EC_SystemFailure
;
993 case ERROR_INVALID_DRIVE
:
994 class = EC_MediaError
;
998 case ERROR_INVALID_HANDLE
:
999 class = EC_ProgramError
;
1003 case ERROR_LOCK_VIOLATION
:
1004 class = EC_AccessDenied
;
1008 case ERROR_NO_MORE_FILES
:
1009 class = EC_MediaError
;
1014 class = EC_NotFound
;
1018 case ERROR_NOT_ENOUGH_MEMORY
:
1019 class = EC_OutOfResource
;
1023 case ERROR_PATH_NOT_FOUND
:
1024 class = EC_NotFound
;
1029 class = EC_NotFound
;
1033 case ERROR_SHARING_VIOLATION
:
1034 class = EC_Temporary
;
1038 case ERROR_TOO_MANY_OPEN_FILES
:
1039 class = EC_ProgramError
;
1044 FIXME("Unknown error %d\n", error
);
1045 class = EC_SystemFailure
;
1050 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1051 error
, class, action
, locus
);
1052 AX_reg(context
) = error
;
1053 BH_reg(context
) = class;
1054 BL_reg(context
) = action
;
1055 CH_reg(context
) = locus
;
1058 /***********************************************************************
1059 * DOS3Call (KERNEL.102)
1061 void WINAPI
DOS3Call( CONTEXT86
*context
)
1063 BOOL bSetDOSExtendedError
= FALSE
;
1066 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1067 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1068 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1069 SI_reg(context
), DI_reg(context
),
1070 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1074 if (AH_reg(context
) == 0x59) /* Get extended error info */
1076 INT21_GetExtendedError( context
);
1080 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1082 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1083 /* no flush here yet */
1084 AH_reg(context
) = AL_reg(context
);
1087 if (AH_reg(context
)>=0x2f) {
1088 /* extended error is used by (at least) functions 0x2f to 0x62 */
1091 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1093 switch(AH_reg(context
))
1095 case 0x03: /* READ CHARACTER FROM STDAUX */
1096 case 0x04: /* WRITE CHARACTER TO STDAUX */
1097 case 0x05: /* WRITE CHARACTER TO PRINTER */
1098 case 0x0f: /* OPEN FILE USING FCB */
1099 case 0x10: /* CLOSE FILE USING FCB */
1100 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1101 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1102 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1103 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1104 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1105 case 0x23: /* GET FILE SIZE FOR FCB */
1106 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1107 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1108 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1109 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1110 INT_BARF( context
, 0x21 );
1113 case 0x00: /* TERMINATE PROGRAM */
1114 TRACE("TERMINATE PROGRAM\n");
1118 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1119 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1120 AL_reg(context
) = CONSOLE_GetCharacter();
1121 /* FIXME: no echo */
1124 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1125 TRACE("Write Character to Standard Output\n");
1126 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1129 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1130 if (DL_reg(context
) == 0xff) {
1131 static char scan
= 0;
1132 TRACE("Direct Console Input\n");
1134 /* return pending scancode */
1135 AL_reg(context
) = scan
;
1136 EFL_reg(context
) &= ~0x40; /* clear ZF */
1140 if (CONSOLE_CheckForKeystroke(&scan
,&ascii
)) {
1141 CONSOLE_GetKeystroke(&scan
,&ascii
);
1142 /* return ASCII code */
1143 AL_reg(context
) = ascii
;
1144 EFL_reg(context
) &= ~0x40; /* clear ZF */
1145 /* return scan code on next call only if ascii==0 */
1146 if (ascii
) scan
= 0;
1148 /* nothing pending, clear everything */
1149 AL_reg(context
) = 0;
1150 EFL_reg(context
) |= 0x40; /* set ZF */
1151 scan
= 0; /* just in case */
1155 TRACE("Direct Console Output\n");
1156 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1160 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1161 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1162 AL_reg(context
) = CONSOLE_GetCharacter();
1165 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1166 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1167 AL_reg(context
) = CONSOLE_GetCharacter();
1170 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1171 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1172 DS_reg(context
),DX_reg(context
) );
1174 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1176 /* do NOT use strchr() to calculate the string length,
1177 as '\0' is valid string content, too !
1178 Maybe we should check for non-'$' strings, but DOS doesn't. */
1179 while (*p
!= '$') p
++;
1180 _hwrite16( 1, data
, (int)p
- (int)data
);
1181 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1185 case 0x0a: /* BUFFERED INPUT */
1187 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1188 EDX_reg(context
) ));
1191 TRACE("BUFFERED INPUT (size=%d)\n",buffer
[0]);
1193 TRACE("Handle old chars in buffer!\n");
1194 res
=_lread16( 0, buffer
+2,buffer
[0]);
1196 if(buffer
[res
+1] == '\n')
1197 buffer
[res
+1] = '\r';
1201 case 0x0b: {/* GET STDIN STATUS */
1204 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1205 AL_reg(context
) = 0xff;
1207 AL_reg(context
) = 0;
1210 case 0x2e: /* SET VERIFY FLAG */
1211 TRACE("SET VERIFY FLAG ignored\n");
1212 /* we cannot change the behaviour anyway, so just ignore it */
1215 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1219 case 0x6b: /* NULL FUNCTION */
1220 AL_reg(context
) = 0;
1223 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1227 case 0x0d: /* DISK BUFFER FLUSH */
1228 TRACE("DISK BUFFER FLUSH ignored\n");
1229 RESET_CFLAG(context
); /* dos 6+ only */
1232 case 0x0e: /* SELECT DEFAULT DRIVE */
1233 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1234 DRIVE_SetCurrentDrive( DL_reg(context
) );
1235 AL_reg(context
) = MAX_DOS_DRIVES
;
1238 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1239 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1240 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1241 if (!INT21_FindFirstFCB(context
))
1243 AL_reg(context
) = 0xff;
1246 /* else fall through */
1248 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1249 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1252 case 0x13: /* DELETE FILE USING FCB */
1253 DeleteFileFCB(context
);
1256 case 0x17: /* RENAME FILE USING FCB */
1257 RenameFileFCB(context
);
1260 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1261 AL_reg(context
) = DRIVE_GetCurrentDrive();
1264 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1266 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1267 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1268 TRACE("Set DTA: %08lx\n", pTask
->dta
);
1272 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1273 DL_reg(context
) = 0;
1274 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1277 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1278 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1281 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1282 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1285 case 0x25: /* SET INTERRUPT VECTOR */
1286 INT_CtxSetHandler( context
, AL_reg(context
),
1287 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1291 case 0x29: /* PARSE FILENAME INTO FCB */
1292 INT21_ParseFileNameIntoFCB(context
);
1295 case 0x2a: /* GET SYSTEM DATE */
1296 INT21_GetSystemDate(context
);
1299 case 0x2b: /* SET SYSTEM DATE */
1300 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1301 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1302 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1305 case 0x2c: /* GET SYSTEM TIME */
1306 INT21_GetSystemTime(context
);
1309 case 0x2d: /* SET SYSTEM TIME */
1310 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1311 CH_reg(context
), CL_reg(context
),
1312 DH_reg(context
), DL_reg(context
) );
1313 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1316 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1317 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1319 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1320 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1321 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1325 case 0x30: /* GET DOS VERSION */
1326 TRACE("GET DOS VERSION %s requested\n",
1327 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1328 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1329 (HIWORD(GetVersion16()) << 8);
1331 AH_reg(context
) = 0x7;
1332 AL_reg(context
) = 0xA;
1335 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1336 CX_reg(context
) = 0x0000;
1339 case 0x31: /* TERMINATE AND STAY RESIDENT */
1340 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1343 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1344 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1345 INT21_DriveName( DL_reg(context
)));
1346 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1349 case 0x33: /* MULTIPLEXED */
1350 switch (AL_reg(context
))
1352 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1353 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1354 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1357 case 0x01: /* SET EXTENDED BREAK STATE */
1358 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1359 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1362 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1363 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1364 /* ugly coding in order to stay reentrant */
1365 if (DL_reg(context
))
1367 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1368 DOSCONF_config
.brk_flag
= 1;
1372 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1373 DOSCONF_config
.brk_flag
= 0;
1377 case 0x05: /* GET BOOT DRIVE */
1378 TRACE("GET BOOT DRIVE\n");
1379 DL_reg(context
) = 3;
1380 /* c: is Wine's bootdrive (a: is 1)*/
1383 case 0x06: /* GET TRUE VERSION NUMBER */
1384 TRACE("GET TRUE VERSION NUMBER\n");
1385 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1386 (HIWORD(GetVersion16() << 8));
1387 DX_reg(context
) = 0x00;
1391 INT_BARF( context
, 0x21 );
1396 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1397 TRACE("GET ADDRESS OF INDOS FLAG\n");
1398 if (!heap
) INT21_CreateHeap();
1399 ES_reg(context
) = DosHeapHandle
;
1400 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1403 case 0x35: /* GET INTERRUPT VECTOR */
1404 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1406 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1407 ES_reg(context
) = SELECTOROF(addr
);
1408 BX_reg(context
) = OFFSETOF(addr
);
1412 case 0x36: /* GET FREE DISK SPACE */
1413 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1414 INT21_DriveName( DL_reg(context
)));
1415 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1420 unsigned char switchchar
='/';
1421 switch (AL_reg(context
))
1423 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1424 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1425 AL_reg(context
) = 0x00; /* success*/
1426 DL_reg(context
) = switchchar
;
1428 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1429 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1430 switchchar
= DL_reg(context
);
1431 AL_reg(context
) = 0x00; /* success*/
1433 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1434 INT_BARF( context
, 0x21 );
1440 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1441 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1443 AX_reg(context
) = 0x02; /* no country support available */
1447 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1449 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1450 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1451 EDX_reg(context
) ), NULL
));
1452 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1453 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1454 * denied), while CreateDirectory return several ones. remap some of
1457 if (bSetDOSExtendedError
) {
1458 switch (GetLastError()) {
1459 case ERROR_ALREADY_EXISTS
:
1460 case ERROR_FILENAME_EXCED_RANGE
:
1461 case ERROR_DISK_FULL
:
1462 SetLastError(ERROR_ACCESS_DENIED
);
1469 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1471 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1472 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1473 EDX_reg(context
) )));
1476 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1478 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1479 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1482 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1483 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context
),
1484 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1485 bSetDOSExtendedError
= INT21_CreateFile( context
);
1488 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1489 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context
),
1490 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1491 OpenExistingFile(context
);
1494 case 0x3e: /* "CLOSE" - CLOSE FILE */
1495 TRACE("CLOSE handle %d\n",BX_reg(context
));
1496 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1499 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1500 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1501 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1505 result
= _hread16( BX_reg(context
),
1506 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1510 result
= WIN16_hread( BX_reg(context
),
1511 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1514 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1515 else AX_reg(context
) = (WORD
)result
;
1519 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1520 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1521 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1523 LONG result
= _hwrite16( BX_reg(context
),
1524 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1527 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1528 else AX_reg(context
) = (WORD
)result
;
1532 case 0x41: /* "UNLINK" - DELETE FILE */
1534 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1535 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1536 EDX_reg(context
) )));
1539 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1540 TRACE("LSEEK handle %d offset %ld from %s\n",
1541 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1542 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1543 "current file position":"end of file");
1545 LONG status
= _llseek16( BX_reg(context
),
1546 MAKELONG(DX_reg(context
),CX_reg(context
)),
1548 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1551 AX_reg(context
) = LOWORD(status
);
1552 DX_reg(context
) = HIWORD(status
);
1557 case 0x43: /* FILE ATTRIBUTES */
1558 switch (AL_reg(context
))
1561 TRACE("GET FILE ATTRIBUTES for %s\n",
1562 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1563 AX_reg(context
) = (WORD
)GetFileAttributesA(
1564 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1566 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1567 else CX_reg(context
) = AX_reg(context
);
1571 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1572 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1573 bSetDOSExtendedError
=
1574 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1579 TRACE("GET COMPRESSED FILE SIZE for %s stub\n",
1580 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1584 case 0x44: /* IOCTL */
1585 switch (AL_reg(context
))
1588 ioctlGetDeviceInfo(context
);
1594 const DOS_DEVICE
*dev
;
1595 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )) &&
1596 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1598 ASPI_DOS_HandleInt(context
);
1602 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1603 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1604 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1606 FIXME("program tried to write to block device control channel of drive %d:\n",drive
);
1607 /* for (i=0;i<CX_reg(context);i++)
1608 fprintf(stdnimp,"%02x ",dataptr[i]);
1609 fprintf(stdnimp,"\n");*/
1610 AX_reg(context
)=CX_reg(context
);
1613 case 0x08: /* Check if drive is removable. */
1614 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1615 INT21_DriveName( BL_reg(context
)));
1616 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1618 case DRIVE_CANNOTDETERMINE
:
1619 SetLastError( ERROR_INVALID_DRIVE
);
1620 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1623 case DRIVE_REMOVABLE
:
1624 AX_reg(context
) = 0; /* removable */
1627 AX_reg(context
) = 1; /* not removable */
1632 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1633 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1634 INT21_DriveName( BL_reg(context
)));
1635 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1637 case DRIVE_CANNOTDETERMINE
:
1638 SetLastError( ERROR_INVALID_DRIVE
);
1639 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1643 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1646 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1651 case 0x0a: /* check if handle (BX) is remote */
1652 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1653 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1656 DX_reg(context
) = 0;
1659 case 0x0b: /* SET SHARING RETRY COUNT */
1660 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1661 CX_reg(context
), DX_reg(context
));
1662 if (!CX_reg(context
))
1664 AX_reg(context
) = 1;
1668 DOSMEM_LOL()->sharing_retry_delay
= CX_reg(context
);
1669 if (!DX_reg(context
))
1670 DOSMEM_LOL()->sharing_retry_count
= DX_reg(context
);
1671 RESET_CFLAG(context
);
1675 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1676 INT21_DriveName( BL_reg(context
)));
1677 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1680 case 0x0e: /* get logical drive mapping */
1681 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1682 INT21_DriveName( BL_reg(context
)));
1683 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1686 case 0x0F: /* Set logical drive mapping */
1689 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1690 INT21_DriveName( BL_reg(context
)));
1691 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1692 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1695 AX_reg(context
) = 0x000F; /* invalid drive */
1700 case 0xe0: /* Sun PC-NFS API */
1705 INT_BARF( context
, 0x21 );
1710 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1713 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1714 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1715 FILE_GetHandle(BX_reg(context
)),
1716 GetCurrentProcess(), &handle
,
1717 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1718 AX_reg(context
) = HFILE_ERROR16
;
1720 AX_reg(context
) = FILE_AllocDosHandle(handle
);
1724 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1725 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1726 BX_reg(context
),CX_reg(context
));
1727 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1730 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1731 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1732 INT21_DriveName( DL_reg(context
)));
1733 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1736 case 0x48: /* ALLOCATE MEMORY */
1737 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1742 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1744 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1748 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1750 AX_reg(context
) = (DWORD
)mem
&0xffff;
1755 AX_reg(context
) = 0x0008; /* insufficient memory */
1756 BX_reg(context
) = DOSMEM_Available(0)>>4;
1761 case 0x49: /* FREE MEMORY */
1762 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context
));
1766 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1769 ret
= !GlobalDOSFree16(ES_reg(context
));
1770 /* If we don't reset ES_reg, we will fail in the relay code */
1771 ES_reg(context
)=ret
;
1775 TRACE("FREE MEMORY failed\n");
1777 AX_reg(context
) = 0x0009; /* memory block address invalid */
1782 case 0x4a: /* RESIZE MEMORY BLOCK */
1783 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1784 if (!ISV86(context
))
1785 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1787 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1788 BX_reg(context
)<<4,NULL
);
1790 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1793 AX_reg(context
) = 0x0008; /* insufficient memory */
1794 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1799 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1801 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1802 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1805 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1808 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1809 TRACE("EXIT with return code %d\n",AL_reg(context
));
1810 ExitProcess( AL_reg(context
) );
1813 case 0x4d: /* GET RETURN CODE */
1814 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1815 AX_reg(context
) = 0; /* normal exit */
1818 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1819 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1820 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1821 if (!INT21_FindFirst(context
)) break;
1824 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1825 TRACE("FINDNEXT\n");
1826 if (!INT21_FindNext(context
))
1828 SetLastError( ERROR_NO_MORE_FILES
);
1829 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1832 else AX_reg(context
) = 0; /* OK */
1834 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1835 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1836 INT21_SetCurrentPSP(BX_reg(context
));
1838 case 0x51: /* GET PSP ADDRESS */
1839 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1840 /* FIXME: should we return the original DOS PSP upon */
1841 /* Windows startup ? */
1842 BX_reg(context
) = INT21_GetCurrentPSP();
1844 case 0x62: /* GET PSP ADDRESS */
1845 TRACE("GET CURRENT PSP ADDRESS\n");
1846 /* FIXME: should we return the original DOS PSP upon */
1847 /* Windows startup ? */
1848 BX_reg(context
) = INT21_GetCurrentPSP();
1851 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1852 TRACE("SYSVARS - GET LIST OF LISTS\n");
1854 ES_reg(context
) = ISV86(context
) ? HIWORD(DOS_LOLSeg
) : LOWORD(DOS_LOLSeg
);
1855 BX_reg(context
) = FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
);
1859 case 0x54: /* Get Verify Flag */
1860 TRACE("Get Verify Flag - Not Supported\n");
1861 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1864 case 0x56: /* "RENAME" - RENAME FILE */
1865 TRACE("RENAME %s to %s\n",
1866 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1867 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1868 bSetDOSExtendedError
=
1869 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1870 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1873 case 0x57: /* FILE DATE AND TIME */
1874 switch (AL_reg(context
))
1876 case 0x00: /* Get */
1879 TRACE("GET FILE DATE AND TIME for handle %d\n",
1881 if (!GetFileTime( FILE_GetHandle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1882 bSetDOSExtendedError
= TRUE
;
1883 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1888 case 0x01: /* Set */
1891 TRACE("SET FILE DATE AND TIME for handle %d\n",
1893 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1895 bSetDOSExtendedError
=
1896 (!SetFileTime( FILE_GetHandle(BX_reg(context
)),
1897 NULL
, NULL
, &filetime
));
1903 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1904 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1906 switch (AL_reg(context
))
1909 AX_reg(context
) = 1;
1912 AX_reg(context
) = 0;
1918 RESET_CFLAG(context
);
1921 case 0x5a: /* CREATE TEMPORARY FILE */
1922 TRACE("CREATE TEMPORARY FILE\n");
1923 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1926 case 0x5b: /* CREATE NEW FILE */
1927 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1928 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1929 bSetDOSExtendedError
= ((AX_reg(context
) =
1930 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1931 CX_reg(context
) )) == (WORD
)HFILE_ERROR16
);
1934 case 0x5d: /* NETWORK */
1935 FIXME("Function 0x%04x not implemented.\n", AX_reg (context
));
1936 /* Fix the following while you're at it. */
1937 SetLastError( ER_NoNetwork
);
1938 bSetDOSExtendedError
= TRUE
;
1942 bSetDOSExtendedError
= INT21_networkfunc (context
);
1945 case 0x5f: /* NETWORK */
1946 switch (AL_reg(context
))
1948 case 0x07: /* ENABLE DRIVE */
1949 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1950 if (!DRIVE_Enable( DL_reg(context
) ))
1952 SetLastError( ERROR_INVALID_DRIVE
);
1953 bSetDOSExtendedError
= TRUE
;
1957 case 0x08: /* DISABLE DRIVE */
1958 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1959 if (!DRIVE_Disable( DL_reg(context
) ))
1961 SetLastError( ERROR_INVALID_DRIVE
);
1962 bSetDOSExtendedError
= TRUE
;
1967 /* network software not installed */
1968 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1969 SetLastError( ER_NoNetwork
);
1970 bSetDOSExtendedError
= TRUE
;
1975 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1976 TRACE("TRUENAME %s\n",
1977 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
1979 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1980 ESI_reg(context
)), 128,
1981 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1982 EDI_reg(context
)),NULL
))
1983 bSetDOSExtendedError
= TRUE
;
1984 else AX_reg(context
) = 0;
1988 case 0x61: /* UNUSED */
1989 case 0x63: /* misc. language support */
1990 switch (AL_reg(context
)) {
1991 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1992 INT21_GetDBCSLeadTable(context
);
1996 case 0x64: /* OS/2 DOS BOX */
1997 INT_BARF( context
, 0x21 );
2001 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2002 extern WORD WINE_LanguageId
;
2003 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
2004 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2005 BX_reg(context
), DX_reg(context
));
2006 switch (AL_reg(context
)) {
2008 TRACE("\tget general internationalization info\n");
2010 *(WORD
*)(dataptr
+1) = 41;
2011 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
2012 *(WORD
*)(dataptr
+5) = CodePage
;
2013 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2016 TRACE("\tget pointer to collating sequence table\n");
2018 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2019 CX_reg(context
) = 258;/*FIXME: size of table?*/
2022 TRACE("\tConvert char to uppercase\n");
2023 DL_reg(context
) = toupper(DL_reg(context
));
2026 TRACE("\tconvert string to uppercase with length\n");
2027 CharUpperBuffA( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
)),
2031 TRACE("\tConvert ASCIIZ string to uppercase\n");
2032 CharUpperA( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
)) );
2035 TRACE("\tunimplemented function %d\n",AL_reg(context
));
2036 INT_BARF( context
, 0x21 );
2042 case 0x66: /* GLOBAL CODE PAGE TABLE */
2043 switch (AL_reg(context
))
2046 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2047 DX_reg(context
) = BX_reg(context
) = CodePage
;
2048 RESET_CFLAG(context
);
2051 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2052 BX_reg(context
),DX_reg(context
));
2053 CodePage
= BX_reg(context
);
2054 RESET_CFLAG(context
);
2059 case 0x67: /* SET HANDLE COUNT */
2060 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context
) );
2061 SetHandleCount16( BX_reg(context
) );
2062 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2065 case 0x68: /* "FFLUSH" - COMMIT FILE */
2066 case 0x6a: /* COMMIT FILE */
2067 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2068 bSetDOSExtendedError
= (!FlushFileBuffers( FILE_GetHandle(BX_reg(context
)) ));
2071 case 0x69: /* DISK SERIAL NUMBER */
2072 switch (AL_reg(context
))
2075 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2076 INT21_DriveName(BL_reg(context
)));
2077 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2078 else AX_reg(context
) = 0;
2082 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2083 INT21_DriveName(BL_reg(context
)));
2084 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2085 else AX_reg(context
) = 1;
2090 case 0x6C: /* Extended Open/Create*/
2091 TRACE("EXTENDED OPEN/CREATE %s\n",
2092 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2093 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2096 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2097 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2098 /* not supported on anything but Win95 */
2099 TRACE("LONG FILENAME functions supported only by win95\n");
2101 AL_reg(context
) = 0;
2103 switch(AL_reg(context
))
2105 case 0x39: /* Create directory */
2106 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2107 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2108 bSetDOSExtendedError
= (!CreateDirectoryA(
2109 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2110 EDX_reg(context
) ), NULL
));
2111 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2112 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2113 * denied), while CreateDirectory return several ones. remap some of
2116 if (bSetDOSExtendedError
) {
2117 switch (GetLastError()) {
2118 case ERROR_ALREADY_EXISTS
:
2119 case ERROR_FILENAME_EXCED_RANGE
:
2120 case ERROR_DISK_FULL
:
2121 SetLastError(ERROR_ACCESS_DENIED
);
2127 case 0x3a: /* Remove directory */
2128 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2129 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2130 bSetDOSExtendedError
= (!RemoveDirectoryA(
2131 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2132 EDX_reg(context
) )));
2134 case 0x43: /* Get/Set file attributes */
2135 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2136 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2137 switch (BL_reg(context
))
2139 case 0x00: /* Get file attributes */
2140 TRACE("\tretrieve attributes\n");
2141 CX_reg(context
) = (WORD
)GetFileAttributesA(
2142 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2144 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2147 TRACE("\tset attributes 0x%04x\n",CX_reg(context
));
2148 bSetDOSExtendedError
= (!SetFileAttributesA(
2149 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2151 CX_reg(context
) ) );
2154 FIXME("Unimplemented long file name function:\n");
2155 INT_BARF( context
, 0x21 );
2157 AL_reg(context
) = 0;
2161 case 0x47: /* Get current directory */
2162 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2163 INT21_DriveName(DL_reg(context
)));
2164 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2167 case 0x4e: /* Find first file */
2168 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2169 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2170 /* FIXME: use attributes in CX */
2171 if ((AX_reg(context
) = FindFirstFile16(
2172 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2173 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2175 == INVALID_HANDLE_VALUE16
)
2176 bSetDOSExtendedError
= TRUE
;
2178 case 0x4f: /* Find next file */
2179 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2181 if (!FindNextFile16( BX_reg(context
),
2182 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2184 bSetDOSExtendedError
= TRUE
;
2186 case 0xa1: /* Find close */
2187 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2189 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2192 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2193 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2196 switch(CL_reg(context
))
2198 case 0x01: /*Get short filename or path */
2199 if (!GetShortPathNameA
2200 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2202 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2203 EDI_reg(context
)), 67))
2204 bSetDOSExtendedError
= TRUE
;
2205 else AX_reg(context
) = 0;
2207 case 0x02: /*Get canonical long filename or path */
2208 if (!GetFullPathNameA
2209 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2210 ESI_reg(context
)), 128,
2211 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2212 EDI_reg(context
)),NULL
))
2213 bSetDOSExtendedError
= TRUE
;
2214 else AX_reg(context
) = 0;
2217 FIXME("Unimplemented long file name function:\n");
2218 INT_BARF( context
, 0x21 );
2220 AL_reg(context
) = 0;
2224 case 0x6c: /* Create or open file */
2225 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2226 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2227 /* translate Dos 7 action to Dos 6 action */
2228 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2231 case 0x3b: /* Change directory */
2232 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2233 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2234 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2240 AL_reg(context
) = GetLastError();
2243 case 0x41: /* Delete file */
2244 TRACE("LONG FILENAME - DELETE FILE %s\n",
2245 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2246 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2251 AL_reg(context
) = GetLastError();
2254 case 0x56: /* Move (rename) file */
2255 TRACE("LONG FILENAME - RENAME FILE %s to %s stub\n",
2256 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2257 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2259 FIXME("Unimplemented long file name function:\n");
2260 INT_BARF( context
, 0x21 );
2262 AL_reg(context
) = 0;
2267 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2268 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2269 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2270 TRACE("windows95 function AX %04x\n",
2272 WARN(" returning unimplemented\n");
2274 AL_reg(context
) = 0;
2277 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2278 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2282 INT_BARF( context
, 0x21 );
2285 } /* END OF SWITCH */
2287 if( bSetDOSExtendedError
) /* set general error condition */
2289 AX_reg(context
) = GetLastError();
2293 if ((EFL_reg(context
) & 0x0001))
2294 TRACE("failed, error 0x%04lx\n", GetLastError() );
2296 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2297 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2298 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2299 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2300 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2304 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2306 FIXME("(DosProc=0x%08x): stub\n", (UINT
)DosProc
);