2 * DOS interrupt 21h handler
11 #ifdef HAVE_SYS_FILE_H
12 # include <sys/file.h>
17 #include <sys/types.h>
25 #include "winuser.h" /* SW_NORMAL */
26 #include "wine/winbase16.h"
36 #include "dosexe.h" /* for the MZ_SUPPORTED define */
38 #include "debugtools.h"
41 DEFAULT_DEBUG_CHANNEL(int21
)
42 #if defined(__svr4__) || defined(_SCO_DS)
43 /* SVR4 DOESNT do locking the same way must implement properly */
50 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
52 /* Define the drive parameter block, as used by int21/1F
53 * and int21/32. This table can be accessed through the
54 * global 'dpb' pointer, which points into the local dos
59 BYTE drive_num
; /* 0=A, etc. */
60 BYTE unit_num
; /* Drive's unit number (?) */
61 WORD sector_size
; /* Sector size in bytes */
62 BYTE high_sector
; /* Highest sector in a cluster */
63 BYTE shift
; /* Shift count (?) */
64 WORD reserved
; /* Number of reserved sectors at start */
65 BYTE num_FAT
; /* Number of FATs */
66 WORD dir_entries
; /* Number of root dir entries */
67 WORD first_data
; /* First data sector */
68 WORD high_cluster
; /* Highest cluster number */
69 WORD sectors_in_FAT
; /* Number of sectors per FAT */
70 WORD start_dir
; /* Starting sector of first dir */
71 DWORD driver_head
; /* Address of device driver header (?) */
72 BYTE media_ID
; /* Media ID */
73 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
74 DWORD next
; /* Pointer to next DPB in list */
75 WORD free_search
; /* Free cluster search start */
76 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
87 BYTE DummyDBCSLeadTable
[6];
89 static struct DosHeap
*heap
;
90 static WORD DosHeapHandle
;
92 extern char TempDirectory
[];
94 static BOOL
INT21_CreateHeap(void)
96 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
98 WARN("Out of memory\n");
101 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
102 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
104 strcpy(heap
->biosdate
, "01/01/80");
105 memset(heap
->DummyDBCSLeadTable
, 0, 6);
109 static BYTE
*GetCurrentDTA( CONTEXT86
*context
)
111 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
113 /* FIXME: This assumes DTA was set correctly! */
114 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
115 (DWORD
)OFFSETOF(pTask
->dta
) );
119 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
120 /* limited == TRUE is used with INT 0x21/0x440d */
125 setword(&data
[3], 0);
127 setword(&data
[6], 240);
128 setword(&data
[8], 64000);
130 setword(&data
[0x0b], 40);
131 setword(&data
[0x0d], 56);
132 setword(&data
[0x0f], 2);
133 setword(&data
[0x11], 0);
135 setword(&data
[0x1f], 800);
137 setword(&data
[0x22], 1);
139 } else { /* 1.44mb */
142 setword(&data
[3], 0);
144 setword(&data
[6], 240);
145 setword(&data
[8], 2880);
147 setword(&data
[0x0b], 6);
148 setword(&data
[0x0d], 18);
149 setword(&data
[0x0f], 2);
150 setword(&data
[0x11], 0);
152 setword(&data
[0x1f], 80);
154 setword(&data
[0x22], 2);
159 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
161 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
162 char root
[] = "A:\\";
164 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
165 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
166 &free_clusters
, &total_clusters
)) return 0;
167 AX_reg(context
) = cluster_sectors
;
168 BX_reg(context
) = free_clusters
;
169 CX_reg(context
) = sector_bytes
;
170 DX_reg(context
) = total_clusters
;
174 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
)
176 if (!INT21_GetFreeDiskSpace( context
)) return 0;
177 if (!heap
&& !INT21_CreateHeap()) return 0;
178 heap
->mediaID
= 0xf0;
179 DS_reg(context
) = DosHeapHandle
;
180 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
184 static void GetDrivePB( CONTEXT86
*context
, int drive
)
186 if(!DRIVE_IsValid(drive
))
188 SetLastError( ERROR_INVALID_DRIVE
);
189 AX_reg(context
) = 0x00ff;
191 else if (heap
|| INT21_CreateHeap())
193 FIXME("GetDrivePB not fully implemented.\n");
195 /* FIXME: I have no idea what a lot of this information should
196 * say or whether it even really matters since we're not allowing
197 * direct block access. However, some programs seem to depend on
198 * getting at least _something_ back from here. The 'next' pointer
199 * does worry me, though. Should we have a complete table of
200 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
202 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
203 heap
->dpb
.sector_size
= 512;
204 heap
->dpb
.high_sector
= 1;
205 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
206 heap
->dpb
.reserved
= 0;
207 heap
->dpb
.num_FAT
= 1;
208 heap
->dpb
.dir_entries
= 2;
209 heap
->dpb
.first_data
= 2;
210 heap
->dpb
.high_cluster
= 64000;
211 heap
->dpb
.sectors_in_FAT
= 1;
212 heap
->dpb
.start_dir
= 1;
213 heap
->dpb
.driver_head
= 0;
214 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
215 heap
->dpb
.access_flag
= 0;
217 heap
->dpb
.free_search
= 0;
218 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
220 AL_reg(context
) = 0x00;
221 DS_reg(context
) = SELECTOROF(dpbsegptr
);
222 BX_reg(context
) = OFFSETOF(dpbsegptr
);
227 static void ioctlGetDeviceInfo( CONTEXT86
*context
)
230 const DOS_DEVICE
*dev
;
232 TRACE("(%d)\n", BX_reg(context
));
234 RESET_CFLAG(context
);
237 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )))
239 DX_reg(context
) = dev
->flags
;
243 /* it seems to be a file */
244 curr_drive
= DRIVE_GetCurrentDrive();
245 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
247 /* bits 0-5 are current drive
248 * bit 6 - file has NOT been written..FIXME: correct?
249 * bit 8 - generate int24 if no diskspace on write/ read past end of file
250 * bit 11 - media not removable
251 * bit 14 - don't set file date/time on closing
252 * bit 15 - file is remote
256 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
258 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
259 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
261 if (!DRIVE_IsValid(drive
))
263 SetLastError( ERROR_FILE_NOT_FOUND
);
267 if (CH_reg(context
) != 0x08)
269 INT_BARF( context
, 0x21 );
273 switch (CL_reg(context
))
275 case 0x4a: /* lock logical volume */
276 TRACE("lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
279 case 0x60: /* get device parameters */
280 /* used by w4wgrp's winfile */
281 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
283 dataptr
[6] = 0; /* media type */
286 dataptr
[1] = 0x05; /* fixed disk */
287 setword(&dataptr
[2], 0x01); /* non removable */
288 setword(&dataptr
[4], 0x300); /* # of cylinders */
292 dataptr
[1] = 0x07; /* block dev, floppy */
293 setword(&dataptr
[2], 0x02); /* removable */
294 setword(&dataptr
[4], 80); /* # of cylinders */
296 CreateBPB(drive
, &dataptr
[7], TRUE
);
297 RESET_CFLAG(context
);
300 case 0x41: /* write logical device track */
301 case 0x61: /* read logical device track */
303 BYTE drive
= BL_reg(context
) ?
304 BL_reg(context
) : DRIVE_GetCurrentDrive();
305 WORD head
= *(WORD
*)dataptr
+1;
306 WORD cyl
= *(WORD
*)dataptr
+3;
307 WORD sect
= *(WORD
*)dataptr
+5;
308 WORD nrsect
= *(WORD
*)dataptr
+7;
309 BYTE
*data
= (BYTE
*)dataptr
+9;
310 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
312 raw_func
= (CL_reg(context
) == 0x41) ?
313 DRIVE_RawWrite
: DRIVE_RawRead
;
315 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
316 RESET_CFLAG(context
);
319 AX_reg(context
) = 0x1e; /* read fault */
324 case 0x66:/* get disk serial number */
326 char label
[12],fsname
[9],path
[4];
329 strcpy(path
,"x:\\");path
[0]=drive
+'A';
330 GetVolumeInformationA(
331 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
334 memcpy(dataptr
+2,&serial
,4);
335 memcpy(dataptr
+6,label
,11);
336 memcpy(dataptr
+17,fsname
,8);
341 TRACE("logical volume %d unlocked.\n",drive
);
345 memset(dataptr
+1, '\0', dataptr
[0]-1);
346 dataptr
[1] = dataptr
[0];
347 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
348 dataptr
[3] = 0xFF; /* no physical drive */
352 /* Trail on error implementation */
353 AX_reg(context
) = GetDriveType16(BL_reg(context
)) == DRIVE_CANNOTDETERMINE
? 0x0f : 0x01;
354 SET_CFLAG(context
); /* Seems to be set all the time */
358 INT_BARF( context
, 0x21 );
363 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
366 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
368 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
369 char *buffer
, *s
, *d
;
371 AL_reg(context
) = 0xff; /* failed */
373 TRACE("filename: '%s'\n", filename
);
375 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
381 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
388 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
390 TRACE("FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
392 HeapFree( GetProcessHeap(), 0, buffer
);
395 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
397 /* point DS:SI to first unparsed character */
398 SI_reg(context
) += (int)s
- (int)filename
;
401 static void INT21_GetSystemDate( CONTEXT86
*context
)
404 GetLocalTime( &systime
);
405 CX_reg(context
) = systime
.wYear
;
406 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
407 AX_reg(context
) = systime
.wDayOfWeek
;
410 static void INT21_GetSystemTime( CONTEXT86
*context
)
413 GetLocalTime( &systime
);
414 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
415 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
418 /* Many calls translate a drive argument like this:
419 drive number (00h = default, 01h = A:, etc)
421 static char drivestring
[]="default";
423 char *INT21_DriveName(int drive
)
428 drivestring
[0]= (unsigned char)drive
+ '@';
434 static BOOL
INT21_CreateFile( CONTEXT86
*context
)
436 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
437 EDX_reg(context
) ), CX_reg(context
) );
438 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
441 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
443 /* Mask off all flags not explicitly allowed by the doc */
444 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
445 return FILE_AllocDosHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
446 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
447 CREATE_NEW
, attr
, -1 ));
450 static void OpenExistingFile( CONTEXT86
*context
)
452 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
454 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
456 AX_reg(context
) = GetLastError();
461 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT86
*context
)
463 BOOL bExtendedError
= FALSE
;
464 BYTE action
= DL_reg(context
);
466 /* Shuffle arguments to call OpenExistingFile */
467 AL_reg(context
) = BL_reg(context
);
468 DX_reg(context
) = SI_reg(context
);
469 /* BX,CX and DX should be preserved */
470 OpenExistingFile(context
);
472 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
474 UINT16 uReturnCX
= 0;
476 /* Now decide what do do */
478 if ((action
& 0x07) == 0)
480 _lclose16( AX_reg(context
) );
481 AX_reg(context
) = 0x0050; /*File exists*/
483 WARN("extended open/create: failed because file exists \n");
485 else if ((action
& 0x07) == 2)
487 /* Truncate it, but first check if opened for write */
488 if ((BL_reg(context
) & 0x0007)== 0)
490 _lclose16( AX_reg(context
) );
491 WARN("extended open/create: failed, trunc on ro file\n");
492 AX_reg(context
) = 0x000C; /*Access code invalid*/
497 TRACE("extended open/create: Closing before truncate\n");
498 if (_lclose16( AX_reg(context
) ))
500 WARN("extended open/create: close before trunc failed\n");
501 AX_reg(context
) = 0x0019; /*Seek Error*/
505 /* Shuffle arguments to call CreateFile */
507 TRACE("extended open/create: Truncating\n");
508 AL_reg(context
) = BL_reg(context
);
509 /* CX is still the same */
510 DX_reg(context
) = SI_reg(context
);
511 bExtendedError
= INT21_CreateFile(context
);
513 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
515 WARN("extended open/create: trunc failed\n");
516 return bExtendedError
;
521 else uReturnCX
= 0x1;
523 CX_reg(context
) = uReturnCX
;
525 else /* file does not exist */
527 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
528 if ((action
& 0xF0)== 0)
532 WARN("extended open/create: failed, file dosen't exist\n");
536 /* Shuffle arguments to call CreateFile */
537 TRACE("extended open/create: Creating\n");
538 AL_reg(context
) = BL_reg(context
);
539 /* CX should still be the same */
540 DX_reg(context
) = SI_reg(context
);
541 bExtendedError
= INT21_CreateFile(context
);
542 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
544 WARN("extended open/create: create failed\n");
545 return bExtendedError
;
551 return bExtendedError
;
555 static BOOL
INT21_ChangeDir( CONTEXT86
*context
)
558 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
560 TRACE("changedir %s\n", dirname
);
561 if (dirname
[0] && (dirname
[1] == ':'))
563 drive
= toupper(dirname
[0]) - 'A';
566 else drive
= DRIVE_GetCurrentDrive();
567 return DRIVE_Chdir( drive
, dirname
);
571 static int INT21_FindFirst( CONTEXT86
*context
)
575 DOS_FULL_NAME full_name
;
576 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
578 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
579 dta
->unixPath
= NULL
;
580 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
582 AX_reg(context
) = GetLastError();
586 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
587 p
= strrchr( dta
->unixPath
, '/' );
590 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
591 * (doesn't matter as it is set below anyway)
593 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
595 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
596 dta
->unixPath
= NULL
;
597 SetLastError( ERROR_FILE_NOT_FOUND
);
598 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
602 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
603 : DRIVE_GetCurrentDrive();
605 dta
->search_attr
= CL_reg(context
);
610 static int INT21_FindNext( CONTEXT86
*context
)
612 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
613 WIN32_FIND_DATAA entry
;
616 if (!dta
->unixPath
) return 0;
617 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
618 dta
->search_attr
, dta
->count
, &entry
)))
620 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
621 dta
->unixPath
= NULL
;
624 if ((int)dta
->count
+ count
> 0xffff)
626 WARN("Too many directory entries in %s\n", dta
->unixPath
);
627 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
628 dta
->unixPath
= NULL
;
632 dta
->fileattr
= entry
.dwFileAttributes
;
633 dta
->filesize
= entry
.nFileSizeLow
;
634 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
635 &dta
->filedate
, &dta
->filetime
);
636 strcpy( dta
->filename
, entry
.cAlternateFileName
);
637 if (!memchr(dta
->mask
,'?',11)) {
638 /* wildcardless search, release resources in case no findnext will
639 * be issued, and as a workaround in case file creation messes up
640 * findnext, as sometimes happens with pkunzip */
641 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
642 dta
->unixPath
= NULL
;
648 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
650 static int counter
= 0;
651 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
652 char *p
= name
+ strlen(name
);
654 /* despite what Ralf Brown says, some programs seem to call without
655 * ending backslash (DOS accepts that, so we accept it too) */
656 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
660 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
661 counter
= (counter
+ 1) % 1000;
663 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
665 TRACE("created %s\n", name
);
668 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
673 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
)
675 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
676 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
678 if (!DRIVE_IsValid(drive
))
680 SetLastError( ERROR_INVALID_DRIVE
);
683 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
684 AX_reg(context
) = 0x0100; /* success return code */
689 static void INT21_GetDBCSLeadTable( CONTEXT86
*context
)
691 if (heap
|| INT21_CreateHeap())
692 { /* return an empty table just as DOS 4.0+ does */
693 DS_reg(context
) = DosHeapHandle
;
694 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
698 AX_reg(context
) = 0x1; /* error */
704 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
706 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
707 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
709 if (!DRIVE_IsValid(drive
))
711 SetLastError( ERROR_INVALID_DRIVE
);
715 *(WORD
*)dataptr
= 0;
716 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
717 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
718 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
723 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
725 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
726 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
728 if (!DRIVE_IsValid(drive
))
730 SetLastError( ERROR_INVALID_DRIVE
);
734 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
739 /* microsoft's programmers should be shot for using CP/M style int21
740 calls in Windows for Workgroup's winfile.exe */
742 static int INT21_FindFirstFCB( CONTEXT86
*context
)
744 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
749 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
750 else pFCB
= (FINDFILE_FCB
*)fcb
;
751 drive
= DOS_GET_DRIVE( pFCB
->drive
);
752 if (!DRIVE_IsValid( drive
)) return 0;
753 root
= DRIVE_GetRoot( drive
);
754 cwd
= DRIVE_GetUnixCwd( drive
);
755 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
756 strlen(root
)+strlen(cwd
)+2 );
757 if (!pFCB
->unixPath
) return 0;
758 strcpy( pFCB
->unixPath
, root
);
759 strcat( pFCB
->unixPath
, "/" );
760 strcat( pFCB
->unixPath
, cwd
);
766 static int INT21_FindNextFCB( CONTEXT86
*context
)
768 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
770 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
771 WIN32_FIND_DATAA entry
;
775 if (*fcb
== 0xff) /* extended FCB ? */
778 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
783 pFCB
= (FINDFILE_FCB
*)fcb
;
786 if (!pFCB
->unixPath
) return 0;
787 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
788 DOS_GET_DRIVE( pFCB
->drive
), attr
,
789 pFCB
->count
, &entry
)))
791 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
792 pFCB
->unixPath
= NULL
;
795 pFCB
->count
+= count
;
797 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
798 *(BYTE
*)pResult
= 0xff;
799 (BYTE
*)pResult
+=6; /* leave reserved field behind */
800 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
803 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
805 pResult
->fileattr
= entry
.dwFileAttributes
;
806 pResult
->cluster
= 0; /* what else? */
807 pResult
->filesize
= entry
.nFileSizeLow
;
808 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
809 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
810 &pResult
->filedate
, &pResult
->filetime
);
812 /* Convert file name to FCB format */
814 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
815 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
816 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
817 pResult
->filename
[0] = pResult
->filename
[1] = '.';
820 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
821 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
823 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
824 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
825 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
828 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
829 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
835 static void DeleteFileFCB( CONTEXT86
*context
)
837 FIXME("(%p): stub\n", context
);
840 static void RenameFileFCB( CONTEXT86
*context
)
842 FIXME("(%p): stub\n", context
);
847 static void fLock( CONTEXT86
* context
)
850 switch ( AX_reg(context
) & 0xff )
852 case 0x00: /* LOCK */
853 TRACE("lock handle %d offset %ld length %ld\n",
855 MAKELONG(DX_reg(context
),CX_reg(context
)),
856 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
857 if (!LockFile(FILE_GetHandle(BX_reg(context
)),
858 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
859 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
860 AX_reg(context
) = GetLastError();
865 case 0x01: /* UNLOCK */
866 TRACE("unlock handle %d offset %ld length %ld\n",
868 MAKELONG(DX_reg(context
),CX_reg(context
)),
869 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
870 if (!UnlockFile(FILE_GetHandle(BX_reg(context
)),
871 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
872 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
873 AX_reg(context
) = GetLastError();
878 AX_reg(context
) = 0x0001;
885 INT21_networkfunc (CONTEXT86
*context
)
887 switch (AL_reg(context
)) {
888 case 0x00: /* Get machine name. */
890 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
891 TRACE("getting machine name to %p\n", dst
);
892 if (gethostname (dst
, 15))
895 SetLastError( ER_NoNetwork
);
898 int len
= strlen (dst
);
902 CH_reg(context
) = 1; /* Valid */
903 CL_reg(context
) = 1; /* NETbios number??? */
904 TRACE("returning %s\n", debugstr_an (dst
, 16));
910 SetLastError( ER_NoNetwork
);
915 static void INT21_SetCurrentPSP(WORD psp
)
918 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
919 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
921 GlobalUnlock16( GetCurrentTask() );
922 if (pModule
->lpDosTask
)
923 pModule
->lpDosTask
->psp_seg
= psp
;
926 ERR("Cannot change PSP for non-DOS task!\n");
929 static WORD
INT21_GetCurrentPSP()
932 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
933 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
935 GlobalUnlock16( GetCurrentTask() );
936 if (pModule
->lpDosTask
)
937 return pModule
->lpDosTask
->psp_seg
;
940 return GetCurrentPDB16();
944 /***********************************************************************
945 * INT21_GetExtendedError
947 static void INT21_GetExtendedError( CONTEXT86
*context
)
949 BYTE
class, action
, locus
;
950 WORD error
= GetLastError();
955 class = action
= locus
= 0;
957 case ERROR_DIR_NOT_EMPTY
:
962 case ERROR_ACCESS_DENIED
:
963 class = EC_AccessDenied
;
967 case ERROR_CANNOT_MAKE
:
968 class = EC_AccessDenied
;
972 case ERROR_DISK_FULL
:
973 case ERROR_HANDLE_DISK_FULL
:
974 class = EC_MediaError
;
978 case ERROR_FILE_EXISTS
:
979 case ERROR_ALREADY_EXISTS
:
984 case ERROR_FILE_NOT_FOUND
:
989 case ER_GeneralFailure
:
990 class = EC_SystemFailure
;
994 case ERROR_INVALID_DRIVE
:
995 class = EC_MediaError
;
999 case ERROR_INVALID_HANDLE
:
1000 class = EC_ProgramError
;
1004 case ERROR_LOCK_VIOLATION
:
1005 class = EC_AccessDenied
;
1009 case ERROR_NO_MORE_FILES
:
1010 class = EC_MediaError
;
1015 class = EC_NotFound
;
1019 case ERROR_NOT_ENOUGH_MEMORY
:
1020 class = EC_OutOfResource
;
1024 case ERROR_PATH_NOT_FOUND
:
1025 class = EC_NotFound
;
1030 class = EC_NotFound
;
1034 case ERROR_SHARING_VIOLATION
:
1035 class = EC_Temporary
;
1039 case ERROR_TOO_MANY_OPEN_FILES
:
1040 class = EC_ProgramError
;
1045 FIXME("Unknown error %d\n", error
);
1046 class = EC_SystemFailure
;
1051 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1052 error
, class, action
, locus
);
1053 AX_reg(context
) = error
;
1054 BH_reg(context
) = class;
1055 BL_reg(context
) = action
;
1056 CH_reg(context
) = locus
;
1059 /***********************************************************************
1060 * DOS3Call (KERNEL.102)
1062 void WINAPI
DOS3Call( CONTEXT86
*context
)
1064 BOOL bSetDOSExtendedError
= FALSE
;
1067 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1068 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1069 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1070 SI_reg(context
), DI_reg(context
),
1071 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1075 if (AH_reg(context
) == 0x59) /* Get extended error info */
1077 INT21_GetExtendedError( context
);
1081 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1083 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1084 /* no flush here yet */
1085 AH_reg(context
) = AL_reg(context
);
1088 if (AH_reg(context
)>=0x2f) {
1089 /* extended error is used by (at least) functions 0x2f to 0x62 */
1092 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1094 switch(AH_reg(context
))
1096 case 0x03: /* READ CHARACTER FROM STDAUX */
1097 case 0x04: /* WRITE CHARACTER TO STDAUX */
1098 case 0x05: /* WRITE CHARACTER TO PRINTER */
1099 case 0x0f: /* OPEN FILE USING FCB */
1100 case 0x10: /* CLOSE FILE USING FCB */
1101 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1102 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1103 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1104 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1105 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1106 case 0x23: /* GET FILE SIZE FOR FCB */
1107 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1108 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1109 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1110 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1111 INT_BARF( context
, 0x21 );
1114 case 0x00: /* TERMINATE PROGRAM */
1115 TRACE("TERMINATE PROGRAM\n");
1119 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1120 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1121 AL_reg(context
) = CONSOLE_GetCharacter();
1122 /* FIXME: no echo */
1125 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1126 TRACE("Write Character to Standard Output\n");
1127 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1130 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1131 if (DL_reg(context
) == 0xff) {
1132 static char scan
= 0;
1133 TRACE("Direct Console Input\n");
1135 /* return pending scancode */
1136 AL_reg(context
) = scan
;
1137 EFL_reg(context
) &= ~0x40; /* clear ZF */
1141 if (CONSOLE_CheckForKeystroke(&scan
,&ascii
)) {
1142 CONSOLE_GetKeystroke(&scan
,&ascii
);
1143 /* return ASCII code */
1144 AL_reg(context
) = ascii
;
1145 EFL_reg(context
) &= ~0x40; /* clear ZF */
1146 /* return scan code on next call only if ascii==0 */
1147 if (ascii
) scan
= 0;
1149 /* nothing pending, clear everything */
1150 AL_reg(context
) = 0;
1151 EFL_reg(context
) |= 0x40; /* set ZF */
1152 scan
= 0; /* just in case */
1156 TRACE("Direct Console Output\n");
1157 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1161 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1162 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1163 AL_reg(context
) = CONSOLE_GetCharacter();
1166 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1167 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1168 AL_reg(context
) = CONSOLE_GetCharacter();
1171 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1172 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1173 DS_reg(context
),DX_reg(context
) );
1175 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1177 /* do NOT use strchr() to calculate the string length,
1178 as '\0' is valid string content, too !
1179 Maybe we should check for non-'$' strings, but DOS doesn't. */
1180 while (*p
!= '$') p
++;
1181 _hwrite16( 1, data
, (int)p
- (int)data
);
1182 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1186 case 0x0a: /* BUFFERED INPUT */
1188 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1189 EDX_reg(context
) ));
1192 TRACE("BUFFERED INPUT (size=%d)\n",buffer
[0]);
1194 TRACE("Handle old chars in buffer!\n");
1195 res
=_lread16( 0, buffer
+2,buffer
[0]);
1197 if(buffer
[res
+1] == '\n')
1198 buffer
[res
+1] = '\r';
1202 case 0x0b: {/* GET STDIN STATUS */
1205 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1206 AL_reg(context
) = 0xff;
1208 AL_reg(context
) = 0;
1211 case 0x2e: /* SET VERIFY FLAG */
1212 TRACE("SET VERIFY FLAG ignored\n");
1213 /* we cannot change the behaviour anyway, so just ignore it */
1216 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1220 case 0x6b: /* NULL FUNCTION */
1221 AL_reg(context
) = 0;
1224 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1228 case 0x0d: /* DISK BUFFER FLUSH */
1229 TRACE("DISK BUFFER FLUSH ignored\n");
1230 RESET_CFLAG(context
); /* dos 6+ only */
1233 case 0x0e: /* SELECT DEFAULT DRIVE */
1234 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1235 DRIVE_SetCurrentDrive( DL_reg(context
) );
1236 AL_reg(context
) = MAX_DOS_DRIVES
;
1239 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1240 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1241 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1242 if (!INT21_FindFirstFCB(context
))
1244 AL_reg(context
) = 0xff;
1247 /* else fall through */
1249 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1250 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1253 case 0x13: /* DELETE FILE USING FCB */
1254 DeleteFileFCB(context
);
1257 case 0x17: /* RENAME FILE USING FCB */
1258 RenameFileFCB(context
);
1261 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1262 AL_reg(context
) = DRIVE_GetCurrentDrive();
1265 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1267 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1268 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1269 TRACE("Set DTA: %08lx\n", pTask
->dta
);
1273 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1274 DL_reg(context
) = 0;
1275 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1278 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1279 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1282 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1283 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1286 case 0x25: /* SET INTERRUPT VECTOR */
1287 INT_CtxSetHandler( context
, AL_reg(context
),
1288 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1292 case 0x29: /* PARSE FILENAME INTO FCB */
1293 INT21_ParseFileNameIntoFCB(context
);
1296 case 0x2a: /* GET SYSTEM DATE */
1297 INT21_GetSystemDate(context
);
1300 case 0x2b: /* SET SYSTEM DATE */
1301 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1302 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1303 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1306 case 0x2c: /* GET SYSTEM TIME */
1307 INT21_GetSystemTime(context
);
1310 case 0x2d: /* SET SYSTEM TIME */
1311 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1312 CH_reg(context
), CL_reg(context
),
1313 DH_reg(context
), DL_reg(context
) );
1314 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1317 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1318 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1320 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1321 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1322 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1326 case 0x30: /* GET DOS VERSION */
1327 TRACE("GET DOS VERSION %s requested\n",
1328 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1329 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1330 (HIWORD(GetVersion16()) << 8);
1332 AH_reg(context
) = 0x7;
1333 AL_reg(context
) = 0xA;
1336 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1337 CX_reg(context
) = 0x0000;
1340 case 0x31: /* TERMINATE AND STAY RESIDENT */
1341 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1344 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1345 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1346 INT21_DriveName( DL_reg(context
)));
1347 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1350 case 0x33: /* MULTIPLEXED */
1351 switch (AL_reg(context
))
1353 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1354 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1355 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1358 case 0x01: /* SET EXTENDED BREAK STATE */
1359 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1360 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1363 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1364 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1365 /* ugly coding in order to stay reentrant */
1366 if (DL_reg(context
))
1368 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1369 DOSCONF_config
.brk_flag
= 1;
1373 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1374 DOSCONF_config
.brk_flag
= 0;
1378 case 0x05: /* GET BOOT DRIVE */
1379 TRACE("GET BOOT DRIVE\n");
1380 DL_reg(context
) = 3;
1381 /* c: is Wine's bootdrive (a: is 1)*/
1384 case 0x06: /* GET TRUE VERSION NUMBER */
1385 TRACE("GET TRUE VERSION NUMBER\n");
1386 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1387 (HIWORD(GetVersion16() << 8));
1388 DX_reg(context
) = 0x00;
1392 INT_BARF( context
, 0x21 );
1397 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1398 TRACE("GET ADDRESS OF INDOS FLAG\n");
1399 if (!heap
) INT21_CreateHeap();
1400 ES_reg(context
) = DosHeapHandle
;
1401 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1404 case 0x35: /* GET INTERRUPT VECTOR */
1405 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1407 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1408 ES_reg(context
) = SELECTOROF(addr
);
1409 BX_reg(context
) = OFFSETOF(addr
);
1413 case 0x36: /* GET FREE DISK SPACE */
1414 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1415 INT21_DriveName( DL_reg(context
)));
1416 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1421 unsigned char switchchar
='/';
1422 switch (AL_reg(context
))
1424 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1425 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1426 AL_reg(context
) = 0x00; /* success*/
1427 DL_reg(context
) = switchchar
;
1429 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1430 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1431 switchchar
= DL_reg(context
);
1432 AL_reg(context
) = 0x00; /* success*/
1434 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1435 INT_BARF( context
, 0x21 );
1441 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1442 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1444 AX_reg(context
) = 0x02; /* no country support available */
1448 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1450 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1451 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1452 EDX_reg(context
) ), NULL
));
1453 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1454 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1455 * denied), while CreateDirectory return several ones. remap some of
1458 if (bSetDOSExtendedError
) {
1459 switch (GetLastError()) {
1460 case ERROR_ALREADY_EXISTS
:
1461 case ERROR_FILENAME_EXCED_RANGE
:
1462 case ERROR_DISK_FULL
:
1463 SetLastError(ERROR_ACCESS_DENIED
);
1470 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1472 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1473 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1474 EDX_reg(context
) )));
1477 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1479 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1480 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1483 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1484 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context
),
1485 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1486 bSetDOSExtendedError
= INT21_CreateFile( context
);
1489 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1490 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context
),
1491 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1492 OpenExistingFile(context
);
1495 case 0x3e: /* "CLOSE" - CLOSE FILE */
1496 TRACE("CLOSE handle %d\n",BX_reg(context
));
1497 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1500 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1501 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1502 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1506 result
= _hread16( BX_reg(context
),
1507 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1511 result
= WIN16_hread( BX_reg(context
),
1512 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1515 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1516 else AX_reg(context
) = (WORD
)result
;
1520 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1521 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1522 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1524 LONG result
= _hwrite16( BX_reg(context
),
1525 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1528 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1529 else AX_reg(context
) = (WORD
)result
;
1533 case 0x41: /* "UNLINK" - DELETE FILE */
1535 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1536 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1537 EDX_reg(context
) )));
1540 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1541 TRACE("LSEEK handle %d offset %ld from %s\n",
1542 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1543 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1544 "current file position":"end of file");
1546 LONG status
= _llseek16( BX_reg(context
),
1547 MAKELONG(DX_reg(context
),CX_reg(context
)),
1549 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1552 AX_reg(context
) = LOWORD(status
);
1553 DX_reg(context
) = HIWORD(status
);
1558 case 0x43: /* FILE ATTRIBUTES */
1559 switch (AL_reg(context
))
1562 TRACE("GET FILE ATTRIBUTES for %s\n",
1563 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1564 AX_reg(context
) = (WORD
)GetFileAttributesA(
1565 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1567 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1568 else CX_reg(context
) = AX_reg(context
);
1572 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1573 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1574 bSetDOSExtendedError
=
1575 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1580 TRACE("GET COMPRESSED FILE SIZE for %s stub\n",
1581 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1585 case 0x44: /* IOCTL */
1586 switch (AL_reg(context
))
1589 ioctlGetDeviceInfo(context
);
1595 const DOS_DEVICE
*dev
;
1596 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )) &&
1597 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1599 ASPI_DOS_HandleInt(context
);
1603 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1604 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1605 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1607 FIXME("program tried to write to block device control channel of drive %d:\n",drive
);
1608 /* for (i=0;i<CX_reg(context);i++)
1609 fprintf(stdnimp,"%02x ",dataptr[i]);
1610 fprintf(stdnimp,"\n");*/
1611 AX_reg(context
)=CX_reg(context
);
1614 case 0x08: /* Check if drive is removable. */
1615 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1616 INT21_DriveName( BL_reg(context
)));
1617 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1619 case DRIVE_CANNOTDETERMINE
:
1620 SetLastError( ERROR_INVALID_DRIVE
);
1621 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1624 case DRIVE_REMOVABLE
:
1625 AX_reg(context
) = 0; /* removable */
1628 AX_reg(context
) = 1; /* not removable */
1633 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1634 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1635 INT21_DriveName( BL_reg(context
)));
1636 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1638 case DRIVE_CANNOTDETERMINE
:
1639 SetLastError( ERROR_INVALID_DRIVE
);
1640 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1644 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1647 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1652 case 0x0a: /* check if handle (BX) is remote */
1653 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1654 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1657 DX_reg(context
) = 0;
1660 case 0x0b: /* SET SHARING RETRY COUNT */
1661 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1662 CX_reg(context
), DX_reg(context
));
1663 if (!CX_reg(context
))
1665 AX_reg(context
) = 1;
1669 DOSMEM_LOL()->sharing_retry_delay
= CX_reg(context
);
1670 if (!DX_reg(context
))
1671 DOSMEM_LOL()->sharing_retry_count
= DX_reg(context
);
1672 RESET_CFLAG(context
);
1676 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1677 INT21_DriveName( BL_reg(context
)));
1678 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1681 case 0x0e: /* get logical drive mapping */
1682 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1683 INT21_DriveName( BL_reg(context
)));
1684 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1687 case 0x0F: /* Set logical drive mapping */
1690 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1691 INT21_DriveName( BL_reg(context
)));
1692 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1693 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1696 AX_reg(context
) = 0x000F; /* invalid drive */
1701 case 0xe0: /* Sun PC-NFS API */
1706 INT_BARF( context
, 0x21 );
1711 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1714 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1715 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1716 FILE_GetHandle(BX_reg(context
)),
1717 GetCurrentProcess(), &handle
,
1718 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1719 AX_reg(context
) = HFILE_ERROR16
;
1721 AX_reg(context
) = FILE_AllocDosHandle(handle
);
1725 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1726 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1727 BX_reg(context
),CX_reg(context
));
1728 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1731 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1732 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1733 INT21_DriveName( DL_reg(context
)));
1734 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1737 case 0x48: /* ALLOCATE MEMORY */
1738 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1743 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1745 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1749 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1751 AX_reg(context
) = (DWORD
)mem
&0xffff;
1756 AX_reg(context
) = 0x0008; /* insufficient memory */
1757 BX_reg(context
) = DOSMEM_Available(0)>>4;
1762 case 0x49: /* FREE MEMORY */
1763 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context
));
1767 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1770 ret
= !GlobalDOSFree16(ES_reg(context
));
1771 /* If we don't reset ES_reg, we will fail in the relay code */
1772 ES_reg(context
)=ret
;
1776 TRACE("FREE MEMORY failed\n");
1778 AX_reg(context
) = 0x0009; /* memory block address invalid */
1783 case 0x4a: /* RESIZE MEMORY BLOCK */
1784 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1785 if (!ISV86(context
))
1786 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1788 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1789 BX_reg(context
)<<4,NULL
);
1791 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1794 AX_reg(context
) = 0x0008; /* insufficient memory */
1795 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1800 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1802 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1803 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1806 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1809 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1810 TRACE("EXIT with return code %d\n",AL_reg(context
));
1811 ExitProcess( AL_reg(context
) );
1814 case 0x4d: /* GET RETURN CODE */
1815 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1816 AX_reg(context
) = 0; /* normal exit */
1819 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1820 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1821 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1822 if (!INT21_FindFirst(context
)) break;
1825 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1826 TRACE("FINDNEXT\n");
1827 if (!INT21_FindNext(context
))
1829 SetLastError( ERROR_NO_MORE_FILES
);
1830 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1833 else AX_reg(context
) = 0; /* OK */
1835 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1836 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1837 INT21_SetCurrentPSP(BX_reg(context
));
1839 case 0x51: /* GET PSP ADDRESS */
1840 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1841 /* FIXME: should we return the original DOS PSP upon */
1842 /* Windows startup ? */
1843 BX_reg(context
) = INT21_GetCurrentPSP();
1845 case 0x62: /* GET PSP ADDRESS */
1846 TRACE("GET CURRENT PSP ADDRESS\n");
1847 /* FIXME: should we return the original DOS PSP upon */
1848 /* Windows startup ? */
1849 BX_reg(context
) = INT21_GetCurrentPSP();
1852 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1853 TRACE("SYSVARS - GET LIST OF LISTS\n");
1855 ES_reg(context
) = ISV86(context
) ? HIWORD(DOS_LOLSeg
) : LOWORD(DOS_LOLSeg
);
1856 BX_reg(context
) = FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
);
1860 case 0x54: /* Get Verify Flag */
1861 TRACE("Get Verify Flag - Not Supported\n");
1862 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1865 case 0x56: /* "RENAME" - RENAME FILE */
1866 TRACE("RENAME %s to %s\n",
1867 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1868 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1869 bSetDOSExtendedError
=
1870 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1871 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1874 case 0x57: /* FILE DATE AND TIME */
1875 switch (AL_reg(context
))
1877 case 0x00: /* Get */
1880 TRACE("GET FILE DATE AND TIME for handle %d\n",
1882 if (!GetFileTime( FILE_GetHandle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1883 bSetDOSExtendedError
= TRUE
;
1884 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1889 case 0x01: /* Set */
1892 TRACE("SET FILE DATE AND TIME for handle %d\n",
1894 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1896 bSetDOSExtendedError
=
1897 (!SetFileTime( FILE_GetHandle(BX_reg(context
)),
1898 NULL
, NULL
, &filetime
));
1904 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1905 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1907 switch (AL_reg(context
))
1910 AX_reg(context
) = 1;
1913 AX_reg(context
) = 0;
1919 RESET_CFLAG(context
);
1922 case 0x5a: /* CREATE TEMPORARY FILE */
1923 TRACE("CREATE TEMPORARY FILE\n");
1924 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1927 case 0x5b: /* CREATE NEW FILE */
1928 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1929 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1930 bSetDOSExtendedError
= ((AX_reg(context
) =
1931 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1932 CX_reg(context
) )) == (WORD
)HFILE_ERROR16
);
1935 case 0x5d: /* NETWORK */
1936 FIXME("Function 0x%04x not implemented.\n", AX_reg (context
));
1937 /* Fix the following while you're at it. */
1938 SetLastError( ER_NoNetwork
);
1939 bSetDOSExtendedError
= TRUE
;
1943 bSetDOSExtendedError
= INT21_networkfunc (context
);
1946 case 0x5f: /* NETWORK */
1947 switch (AL_reg(context
))
1949 case 0x07: /* ENABLE DRIVE */
1950 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1951 if (!DRIVE_Enable( DL_reg(context
) ))
1953 SetLastError( ERROR_INVALID_DRIVE
);
1954 bSetDOSExtendedError
= TRUE
;
1958 case 0x08: /* DISABLE DRIVE */
1959 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1960 if (!DRIVE_Disable( DL_reg(context
) ))
1962 SetLastError( ERROR_INVALID_DRIVE
);
1963 bSetDOSExtendedError
= TRUE
;
1968 /* network software not installed */
1969 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1970 SetLastError( ER_NoNetwork
);
1971 bSetDOSExtendedError
= TRUE
;
1976 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1977 TRACE("TRUENAME %s\n",
1978 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
1980 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1981 ESI_reg(context
)), 128,
1982 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1983 EDI_reg(context
)),NULL
))
1984 bSetDOSExtendedError
= TRUE
;
1985 else AX_reg(context
) = 0;
1989 case 0x61: /* UNUSED */
1990 case 0x63: /* misc. language support */
1991 switch (AL_reg(context
)) {
1992 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1993 INT21_GetDBCSLeadTable(context
);
1997 case 0x64: /* OS/2 DOS BOX */
1998 INT_BARF( context
, 0x21 );
2002 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2003 extern WORD WINE_LanguageId
;
2004 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
2005 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2006 BX_reg(context
), DX_reg(context
));
2007 switch (AL_reg(context
)) {
2009 TRACE("\tget general internationalization info\n");
2011 *(WORD
*)(dataptr
+1) = 41;
2012 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
2013 *(WORD
*)(dataptr
+5) = CodePage
;
2014 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2017 TRACE("\tget pointer to collating sequence table\n");
2019 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2020 CX_reg(context
) = 258;/*FIXME: size of table?*/
2023 TRACE("\tConvert char to uppercase\n");
2024 DL_reg(context
) = toupper(DL_reg(context
));
2027 TRACE("\tconvert string to uppercase with length\n");
2028 CharUpperBuffA( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
)),
2032 TRACE("\tConvert ASCIIZ string to uppercase\n");
2033 CharUpperA( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
)) );
2036 TRACE("\tunimplemented function %d\n",AL_reg(context
));
2037 INT_BARF( context
, 0x21 );
2043 case 0x66: /* GLOBAL CODE PAGE TABLE */
2044 switch (AL_reg(context
))
2047 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2048 DX_reg(context
) = BX_reg(context
) = CodePage
;
2049 RESET_CFLAG(context
);
2052 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2053 BX_reg(context
),DX_reg(context
));
2054 CodePage
= BX_reg(context
);
2055 RESET_CFLAG(context
);
2060 case 0x67: /* SET HANDLE COUNT */
2061 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context
) );
2062 SetHandleCount16( BX_reg(context
) );
2063 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2066 case 0x68: /* "FFLUSH" - COMMIT FILE */
2067 case 0x6a: /* COMMIT FILE */
2068 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2069 bSetDOSExtendedError
= (!FlushFileBuffers( FILE_GetHandle(BX_reg(context
)) ));
2072 case 0x69: /* DISK SERIAL NUMBER */
2073 switch (AL_reg(context
))
2076 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2077 INT21_DriveName(BL_reg(context
)));
2078 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2079 else AX_reg(context
) = 0;
2083 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2084 INT21_DriveName(BL_reg(context
)));
2085 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2086 else AX_reg(context
) = 1;
2091 case 0x6C: /* Extended Open/Create*/
2092 TRACE("EXTENDED OPEN/CREATE %s\n",
2093 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2094 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2097 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2098 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2099 /* not supported on anything but Win95 */
2100 TRACE("LONG FILENAME functions supported only by win95\n");
2102 AL_reg(context
) = 0;
2104 switch(AL_reg(context
))
2106 case 0x39: /* Create directory */
2107 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2108 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2109 bSetDOSExtendedError
= (!CreateDirectoryA(
2110 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2111 EDX_reg(context
) ), NULL
));
2112 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2113 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2114 * denied), while CreateDirectory return several ones. remap some of
2117 if (bSetDOSExtendedError
) {
2118 switch (GetLastError()) {
2119 case ERROR_ALREADY_EXISTS
:
2120 case ERROR_FILENAME_EXCED_RANGE
:
2121 case ERROR_DISK_FULL
:
2122 SetLastError(ERROR_ACCESS_DENIED
);
2128 case 0x3a: /* Remove directory */
2129 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2130 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2131 bSetDOSExtendedError
= (!RemoveDirectoryA(
2132 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2133 EDX_reg(context
) )));
2135 case 0x43: /* Get/Set file attributes */
2136 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2137 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2138 switch (BL_reg(context
))
2140 case 0x00: /* Get file attributes */
2141 TRACE("\tretrieve attributes\n");
2142 CX_reg(context
) = (WORD
)GetFileAttributesA(
2143 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2145 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2148 TRACE("\tset attributes 0x%04x\n",CX_reg(context
));
2149 bSetDOSExtendedError
= (!SetFileAttributesA(
2150 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2152 CX_reg(context
) ) );
2155 FIXME("Unimplemented long file name function:\n");
2156 INT_BARF( context
, 0x21 );
2158 AL_reg(context
) = 0;
2162 case 0x47: /* Get current directory */
2163 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2164 INT21_DriveName(DL_reg(context
)));
2165 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2168 case 0x4e: /* Find first file */
2169 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2170 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2171 /* FIXME: use attributes in CX */
2172 if ((AX_reg(context
) = FindFirstFile16(
2173 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2174 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2176 == INVALID_HANDLE_VALUE16
)
2177 bSetDOSExtendedError
= TRUE
;
2179 case 0x4f: /* Find next file */
2180 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2182 if (!FindNextFile16( BX_reg(context
),
2183 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2185 bSetDOSExtendedError
= TRUE
;
2187 case 0xa1: /* Find close */
2188 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2190 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2193 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2194 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2197 switch(CL_reg(context
))
2199 case 0x01: /*Get short filename or path */
2200 if (!GetShortPathNameA
2201 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2203 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2204 EDI_reg(context
)), 67))
2205 bSetDOSExtendedError
= TRUE
;
2206 else AX_reg(context
) = 0;
2208 case 0x02: /*Get canonical long filename or path */
2209 if (!GetFullPathNameA
2210 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2211 ESI_reg(context
)), 128,
2212 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2213 EDI_reg(context
)),NULL
))
2214 bSetDOSExtendedError
= TRUE
;
2215 else AX_reg(context
) = 0;
2218 FIXME("Unimplemented long file name function:\n");
2219 INT_BARF( context
, 0x21 );
2221 AL_reg(context
) = 0;
2225 case 0x6c: /* Create or open file */
2226 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2227 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2228 /* translate Dos 7 action to Dos 6 action */
2229 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2232 case 0x3b: /* Change directory */
2233 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2234 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2235 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2241 AL_reg(context
) = GetLastError();
2244 case 0x41: /* Delete file */
2245 TRACE("LONG FILENAME - DELETE FILE %s\n",
2246 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2247 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2252 AL_reg(context
) = GetLastError();
2255 case 0x56: /* Move (rename) file */
2256 TRACE("LONG FILENAME - RENAME FILE %s to %s stub\n",
2257 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2258 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2260 FIXME("Unimplemented long file name function:\n");
2261 INT_BARF( context
, 0x21 );
2263 AL_reg(context
) = 0;
2268 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2269 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2270 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2271 TRACE("windows95 function AX %04x\n",
2273 WARN(" returning unimplemented\n");
2275 AL_reg(context
) = 0;
2278 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2279 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2283 INT_BARF( context
, 0x21 );
2286 } /* END OF SWITCH */
2288 if( bSetDOSExtendedError
) /* set general error condition */
2290 AX_reg(context
) = GetLastError();
2294 if ((EFL_reg(context
) & 0x0001))
2295 TRACE("failed, error 0x%04lx\n", GetLastError() );
2297 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2298 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2299 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2300 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2301 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2305 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2307 FIXME("(DosProc=0x%08x): stub\n", (UINT
)DosProc
);