2 * DOS interrupt 21h handler
11 #ifdef HAVE_SYS_FILE_H
12 # include <sys/file.h>
17 #include <sys/types.h>
23 #include "winuser.h" /* SW_NORMAL */
24 #include "wine/winbase16.h"
34 #include "dosexe.h" /* for the MZ_SUPPORTED define */
36 #include "debugtools.h"
39 DEFAULT_DEBUG_CHANNEL(int21
)
40 #if defined(__svr4__) || defined(_SCO_DS)
41 /* SVR4 DOESNT do locking the same way must implement properly */
48 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
50 /* Define the drive parameter block, as used by int21/1F
51 * and int21/32. This table can be accessed through the
52 * global 'dpb' pointer, which points into the local dos
57 BYTE drive_num
; /* 0=A, etc. */
58 BYTE unit_num
; /* Drive's unit number (?) */
59 WORD sector_size
; /* Sector size in bytes */
60 BYTE high_sector
; /* Highest sector in a cluster */
61 BYTE shift
; /* Shift count (?) */
62 WORD reserved
; /* Number of reserved sectors at start */
63 BYTE num_FAT
; /* Number of FATs */
64 WORD dir_entries
; /* Number of root dir entries */
65 WORD first_data
; /* First data sector */
66 WORD high_cluster
; /* Highest cluster number */
67 WORD sectors_in_FAT
; /* Number of sectors per FAT */
68 WORD start_dir
; /* Starting sector of first dir */
69 DWORD driver_head
; /* Address of device driver header (?) */
70 BYTE media_ID
; /* Media ID */
71 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
72 DWORD next
; /* Pointer to next DPB in list */
73 WORD free_search
; /* Free cluster search start */
74 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
85 BYTE DummyDBCSLeadTable
[6];
87 static struct DosHeap
*heap
;
88 static WORD DosHeapHandle
;
90 extern char TempDirectory
[];
92 static BOOL
INT21_CreateHeap(void)
94 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
96 WARN("Out of memory\n");
99 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
100 dpbsegptr
= PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
102 strcpy(heap
->biosdate
, "01/01/80");
103 memset(heap
->DummyDBCSLeadTable
, 0, 6);
107 static BYTE
*GetCurrentDTA( CONTEXT86
*context
)
109 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
111 /* FIXME: This assumes DTA was set correctly! */
112 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
113 (DWORD
)OFFSETOF(pTask
->dta
) );
117 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
118 /* limited == TRUE is used with INT 0x21/0x440d */
123 setword(&data
[3], 0);
125 setword(&data
[6], 240);
126 setword(&data
[8], 64000);
128 setword(&data
[0x0b], 40);
129 setword(&data
[0x0d], 56);
130 setword(&data
[0x0f], 2);
131 setword(&data
[0x11], 0);
133 setword(&data
[0x1f], 800);
135 setword(&data
[0x22], 1);
137 } else { /* 1.44mb */
140 setword(&data
[3], 0);
142 setword(&data
[6], 240);
143 setword(&data
[8], 2880);
145 setword(&data
[0x0b], 6);
146 setword(&data
[0x0d], 18);
147 setword(&data
[0x0f], 2);
148 setword(&data
[0x11], 0);
150 setword(&data
[0x1f], 80);
152 setword(&data
[0x22], 2);
157 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
159 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
160 char root
[] = "A:\\";
162 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
163 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
164 &free_clusters
, &total_clusters
)) return 0;
165 AX_reg(context
) = cluster_sectors
;
166 BX_reg(context
) = free_clusters
;
167 CX_reg(context
) = sector_bytes
;
168 DX_reg(context
) = total_clusters
;
172 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
)
174 if (!INT21_GetFreeDiskSpace( context
)) return 0;
175 if (!heap
&& !INT21_CreateHeap()) return 0;
176 heap
->mediaID
= 0xf0;
177 DS_reg(context
) = DosHeapHandle
;
178 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
182 static void GetDrivePB( CONTEXT86
*context
, int drive
)
184 if(!DRIVE_IsValid(drive
))
186 SetLastError( ERROR_INVALID_DRIVE
);
187 AX_reg(context
) = 0x00ff;
189 else if (heap
|| INT21_CreateHeap())
191 FIXME("GetDrivePB not fully implemented.\n");
193 /* FIXME: I have no idea what a lot of this information should
194 * say or whether it even really matters since we're not allowing
195 * direct block access. However, some programs seem to depend on
196 * getting at least _something_ back from here. The 'next' pointer
197 * does worry me, though. Should we have a complete table of
198 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
200 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
201 heap
->dpb
.sector_size
= 512;
202 heap
->dpb
.high_sector
= 1;
203 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
204 heap
->dpb
.reserved
= 0;
205 heap
->dpb
.num_FAT
= 1;
206 heap
->dpb
.dir_entries
= 2;
207 heap
->dpb
.first_data
= 2;
208 heap
->dpb
.high_cluster
= 64000;
209 heap
->dpb
.sectors_in_FAT
= 1;
210 heap
->dpb
.start_dir
= 1;
211 heap
->dpb
.driver_head
= 0;
212 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
213 heap
->dpb
.access_flag
= 0;
215 heap
->dpb
.free_search
= 0;
216 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
218 AL_reg(context
) = 0x00;
219 DS_reg(context
) = SELECTOROF(dpbsegptr
);
220 BX_reg(context
) = OFFSETOF(dpbsegptr
);
225 static void ioctlGetDeviceInfo( CONTEXT86
*context
)
228 const DOS_DEVICE
*dev
;
230 TRACE("(%d)\n", BX_reg(context
));
232 RESET_CFLAG(context
);
235 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )))
237 DX_reg(context
) = dev
->flags
;
241 /* it seems to be a file */
242 curr_drive
= DRIVE_GetCurrentDrive();
243 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
245 /* bits 0-5 are current drive
246 * bit 6 - file has NOT been written..FIXME: correct?
247 * bit 8 - generate int24 if no diskspace on write/ read past end of file
248 * bit 11 - media not removable
249 * bit 14 - don't set file date/time on closing
250 * bit 15 - file is remote
254 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
256 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
257 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
259 if (!DRIVE_IsValid(drive
))
261 SetLastError( ERROR_FILE_NOT_FOUND
);
265 if (CH_reg(context
) != 0x08)
267 INT_BARF( context
, 0x21 );
271 switch (CL_reg(context
))
273 case 0x4a: /* lock logical volume */
274 TRACE("lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
277 case 0x60: /* get device parameters */
278 /* used by w4wgrp's winfile */
279 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
281 dataptr
[6] = 0; /* media type */
284 dataptr
[1] = 0x05; /* fixed disk */
285 setword(&dataptr
[2], 0x01); /* non removable */
286 setword(&dataptr
[4], 0x300); /* # of cylinders */
290 dataptr
[1] = 0x07; /* block dev, floppy */
291 setword(&dataptr
[2], 0x02); /* removable */
292 setword(&dataptr
[4], 80); /* # of cylinders */
294 CreateBPB(drive
, &dataptr
[7], TRUE
);
295 RESET_CFLAG(context
);
298 case 0x41: /* write logical device track */
299 case 0x61: /* read logical device track */
301 BYTE drive
= BL_reg(context
) ?
302 BL_reg(context
) : DRIVE_GetCurrentDrive();
303 WORD head
= *(WORD
*)dataptr
+1;
304 WORD cyl
= *(WORD
*)dataptr
+3;
305 WORD sect
= *(WORD
*)dataptr
+5;
306 WORD nrsect
= *(WORD
*)dataptr
+7;
307 BYTE
*data
= (BYTE
*)dataptr
+9;
308 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
310 raw_func
= (CL_reg(context
) == 0x41) ?
311 DRIVE_RawWrite
: DRIVE_RawRead
;
313 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
314 RESET_CFLAG(context
);
317 AX_reg(context
) = 0x1e; /* read fault */
322 case 0x66:/* get disk serial number */
324 char label
[12],fsname
[9],path
[4];
327 strcpy(path
,"x:\\");path
[0]=drive
+'A';
328 GetVolumeInformationA(
329 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
332 memcpy(dataptr
+2,&serial
,4);
333 memcpy(dataptr
+6,label
,11);
334 memcpy(dataptr
+17,fsname
,8);
339 TRACE("logical volume %d unlocked.\n",drive
);
343 memset(dataptr
+1, '\0', dataptr
[0]-1);
344 dataptr
[1] = dataptr
[0];
345 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
346 dataptr
[3] = 0xFF; /* no physical drive */
350 /* Trail on error implementation */
351 AX_reg(context
) = GetDriveType16(BL_reg(context
)) == DRIVE_CANNOTDETERMINE
? 0x0f : 0x01;
352 SET_CFLAG(context
); /* Seems to be set all the time */
356 INT_BARF( context
, 0x21 );
361 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
364 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
366 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
) );
367 char *buffer
, *s
, *d
;
369 AL_reg(context
) = 0xff; /* failed */
371 TRACE("filename: '%s'\n", filename
);
373 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
379 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
386 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
388 TRACE("FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
390 HeapFree( GetProcessHeap(), 0, buffer
);
393 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
395 /* point DS:SI to first unparsed character */
396 SI_reg(context
) += (int)s
- (int)filename
;
399 static void INT21_GetSystemDate( CONTEXT86
*context
)
402 GetLocalTime( &systime
);
403 CX_reg(context
) = systime
.wYear
;
404 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
405 AX_reg(context
) = systime
.wDayOfWeek
;
408 static void INT21_GetSystemTime( CONTEXT86
*context
)
411 GetLocalTime( &systime
);
412 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
413 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
416 /* Many calls translate a drive argument like this:
417 drive number (00h = default, 01h = A:, etc)
419 static char drivestring
[]="default";
421 char *INT21_DriveName(int drive
)
426 drivestring
[0]= (unsigned char)drive
+ '@';
432 static BOOL
INT21_CreateFile( CONTEXT86
*context
)
434 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
435 EDX_reg(context
) ), CX_reg(context
) );
436 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
439 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
441 /* Mask off all flags not explicitly allowed by the doc */
442 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
443 return FILE_AllocDosHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
444 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
445 CREATE_NEW
, attr
, -1 ));
448 static void OpenExistingFile( CONTEXT86
*context
)
450 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
452 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
454 AX_reg(context
) = GetLastError();
459 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT86
*context
)
461 BOOL bExtendedError
= FALSE
;
462 BYTE action
= DL_reg(context
);
464 /* Shuffle arguments to call OpenExistingFile */
465 AL_reg(context
) = BL_reg(context
);
466 DX_reg(context
) = SI_reg(context
);
467 /* BX,CX and DX should be preserved */
468 OpenExistingFile(context
);
470 if ((EFL_reg(context
) & 0x0001) == 0) /* File exists */
472 UINT16 uReturnCX
= 0;
474 /* Now decide what do do */
476 if ((action
& 0x07) == 0)
478 _lclose16( AX_reg(context
) );
479 AX_reg(context
) = 0x0050; /*File exists*/
481 WARN("extended open/create: failed because file exists \n");
483 else if ((action
& 0x07) == 2)
485 /* Truncate it, but first check if opened for write */
486 if ((BL_reg(context
) & 0x0007)== 0)
488 _lclose16( AX_reg(context
) );
489 WARN("extended open/create: failed, trunc on ro file\n");
490 AX_reg(context
) = 0x000C; /*Access code invalid*/
495 TRACE("extended open/create: Closing before truncate\n");
496 if (_lclose16( AX_reg(context
) ))
498 WARN("extended open/create: close before trunc failed\n");
499 AX_reg(context
) = 0x0019; /*Seek Error*/
503 /* Shuffle arguments to call CreateFile */
505 TRACE("extended open/create: Truncating\n");
506 AL_reg(context
) = BL_reg(context
);
507 /* CX is still the same */
508 DX_reg(context
) = SI_reg(context
);
509 bExtendedError
= INT21_CreateFile(context
);
511 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
513 WARN("extended open/create: trunc failed\n");
514 return bExtendedError
;
519 else uReturnCX
= 0x1;
521 CX_reg(context
) = uReturnCX
;
523 else /* file does not exist */
525 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
526 if ((action
& 0xF0)== 0)
530 WARN("extended open/create: failed, file dosen't exist\n");
534 /* Shuffle arguments to call CreateFile */
535 TRACE("extended open/create: Creating\n");
536 AL_reg(context
) = BL_reg(context
);
537 /* CX should still be the same */
538 DX_reg(context
) = SI_reg(context
);
539 bExtendedError
= INT21_CreateFile(context
);
540 if (EFL_reg(context
) & 0x0001) /*no file open, flags set */
542 WARN("extended open/create: create failed\n");
543 return bExtendedError
;
549 return bExtendedError
;
553 static BOOL
INT21_ChangeDir( CONTEXT86
*context
)
556 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
));
558 TRACE("changedir %s\n", dirname
);
559 if (dirname
[0] && (dirname
[1] == ':'))
561 drive
= toupper(dirname
[0]) - 'A';
564 else drive
= DRIVE_GetCurrentDrive();
565 return DRIVE_Chdir( drive
, dirname
);
569 static int INT21_FindFirst( CONTEXT86
*context
)
573 DOS_FULL_NAME full_name
;
574 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
576 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
577 dta
->unixPath
= NULL
;
578 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
580 AX_reg(context
) = GetLastError();
584 dta
->unixPath
= HEAP_strdupA( GetProcessHeap(), 0, full_name
.long_name
);
585 p
= strrchr( dta
->unixPath
, '/' );
588 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
589 * (doesn't matter as it is set below anyway)
591 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
593 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
594 dta
->unixPath
= NULL
;
595 SetLastError( ERROR_FILE_NOT_FOUND
);
596 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
600 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
601 : DRIVE_GetCurrentDrive();
603 dta
->search_attr
= CL_reg(context
);
608 static int INT21_FindNext( CONTEXT86
*context
)
610 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
611 WIN32_FIND_DATAA entry
;
614 if (!dta
->unixPath
) return 0;
615 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
616 dta
->search_attr
, dta
->count
, &entry
)))
618 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
619 dta
->unixPath
= NULL
;
622 if ((int)dta
->count
+ count
> 0xffff)
624 WARN("Too many directory entries in %s\n", dta
->unixPath
);
625 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
626 dta
->unixPath
= NULL
;
630 dta
->fileattr
= entry
.dwFileAttributes
;
631 dta
->filesize
= entry
.nFileSizeLow
;
632 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
633 &dta
->filedate
, &dta
->filetime
);
634 strcpy( dta
->filename
, entry
.cAlternateFileName
);
635 if (!memchr(dta
->mask
,'?',11)) {
636 /* wildcardless search, release resources in case no findnext will
637 * be issued, and as a workaround in case file creation messes up
638 * findnext, as sometimes happens with pkunzip */
639 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
640 dta
->unixPath
= NULL
;
646 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
648 static int counter
= 0;
649 char *name
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
) );
650 char *p
= name
+ strlen(name
);
652 /* despite what Ralf Brown says, some programs seem to call without
653 * ending backslash (DOS accepts that, so we accept it too) */
654 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
658 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
659 counter
= (counter
+ 1) % 1000;
661 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
663 TRACE("created %s\n", name
);
666 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
671 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
)
673 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
674 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
) );
676 if (!DRIVE_IsValid(drive
))
678 SetLastError( ERROR_INVALID_DRIVE
);
681 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
682 AX_reg(context
) = 0x0100; /* success return code */
687 static void INT21_GetDBCSLeadTable( CONTEXT86
*context
)
689 if (heap
|| INT21_CreateHeap())
690 { /* return an empty table just as DOS 4.0+ does */
691 DS_reg(context
) = DosHeapHandle
;
692 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
696 AX_reg(context
) = 0x1; /* error */
702 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
704 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
705 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
707 if (!DRIVE_IsValid(drive
))
709 SetLastError( ERROR_INVALID_DRIVE
);
713 *(WORD
*)dataptr
= 0;
714 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
715 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
716 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
721 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
723 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
724 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
726 if (!DRIVE_IsValid(drive
))
728 SetLastError( ERROR_INVALID_DRIVE
);
732 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
737 /* microsoft's programmers should be shot for using CP/M style int21
738 calls in Windows for Workgroup's winfile.exe */
740 static int INT21_FindFirstFCB( CONTEXT86
*context
)
742 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
747 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
748 else pFCB
= (FINDFILE_FCB
*)fcb
;
749 drive
= DOS_GET_DRIVE( pFCB
->drive
);
750 if (!DRIVE_IsValid( drive
)) return 0;
751 root
= DRIVE_GetRoot( drive
);
752 cwd
= DRIVE_GetUnixCwd( drive
);
753 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
754 strlen(root
)+strlen(cwd
)+2 );
755 if (!pFCB
->unixPath
) return 0;
756 strcpy( pFCB
->unixPath
, root
);
757 strcat( pFCB
->unixPath
, "/" );
758 strcat( pFCB
->unixPath
, cwd
);
764 static int INT21_FindNextFCB( CONTEXT86
*context
)
766 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
));
768 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
769 WIN32_FIND_DATAA entry
;
773 if (*fcb
== 0xff) /* extended FCB ? */
776 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
781 pFCB
= (FINDFILE_FCB
*)fcb
;
784 if (!pFCB
->unixPath
) return 0;
785 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
786 DOS_GET_DRIVE( pFCB
->drive
), attr
,
787 pFCB
->count
, &entry
)))
789 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
790 pFCB
->unixPath
= NULL
;
793 pFCB
->count
+= count
;
795 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
796 *(BYTE
*)pResult
= 0xff;
797 (BYTE
*)pResult
+=6; /* leave reserved field behind */
798 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
801 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
803 pResult
->fileattr
= entry
.dwFileAttributes
;
804 pResult
->cluster
= 0; /* what else? */
805 pResult
->filesize
= entry
.nFileSizeLow
;
806 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
807 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
808 &pResult
->filedate
, &pResult
->filetime
);
810 /* Convert file name to FCB format */
812 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
813 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
814 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
815 pResult
->filename
[0] = pResult
->filename
[1] = '.';
818 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
819 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
821 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
822 MIN( (p
- entry
.cAlternateFileName
), 8 ) );
823 memcpy( pResult
->filename
+ 8, p
+ 1, MIN( strlen(p
), 3 ) );
826 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
827 MIN( strlen(entry
.cAlternateFileName
), 8 ) );
833 static void DeleteFileFCB( CONTEXT86
*context
)
835 FIXME("(%p): stub\n", context
);
838 static void RenameFileFCB( CONTEXT86
*context
)
840 FIXME("(%p): stub\n", context
);
845 static void fLock( CONTEXT86
* context
)
848 switch ( AX_reg(context
) & 0xff )
850 case 0x00: /* LOCK */
851 TRACE("lock handle %d offset %ld length %ld\n",
853 MAKELONG(DX_reg(context
),CX_reg(context
)),
854 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
855 if (!LockFile(FILE_GetHandle(BX_reg(context
)),
856 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
857 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
858 AX_reg(context
) = GetLastError();
863 case 0x01: /* UNLOCK */
864 TRACE("unlock handle %d offset %ld length %ld\n",
866 MAKELONG(DX_reg(context
),CX_reg(context
)),
867 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
868 if (!UnlockFile(FILE_GetHandle(BX_reg(context
)),
869 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
870 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
871 AX_reg(context
) = GetLastError();
876 AX_reg(context
) = 0x0001;
883 INT21_networkfunc (CONTEXT86
*context
)
885 switch (AL_reg(context
)) {
886 case 0x00: /* Get machine name. */
888 char *dst
= CTX_SEG_OFF_TO_LIN (context
,DS_reg(context
),EDX_reg(context
));
889 TRACE("getting machine name to %p\n", dst
);
890 if (gethostname (dst
, 15))
893 SetLastError( ER_NoNetwork
);
896 int len
= strlen (dst
);
900 CH_reg(context
) = 1; /* Valid */
901 CL_reg(context
) = 1; /* NETbios number??? */
902 TRACE("returning %s\n", debugstr_an (dst
, 16));
908 SetLastError( ER_NoNetwork
);
913 static void INT21_SetCurrentPSP(WORD psp
)
916 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
917 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
919 GlobalUnlock16( GetCurrentTask() );
920 if (pModule
->lpDosTask
)
921 pModule
->lpDosTask
->psp_seg
= psp
;
924 ERR("Cannot change PSP for non-DOS task!\n");
927 static WORD
INT21_GetCurrentPSP()
930 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
931 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
933 GlobalUnlock16( GetCurrentTask() );
934 if (pModule
->lpDosTask
)
935 return pModule
->lpDosTask
->psp_seg
;
938 return GetCurrentPDB16();
942 /***********************************************************************
943 * INT21_GetExtendedError
945 static void INT21_GetExtendedError( CONTEXT86
*context
)
947 BYTE
class, action
, locus
;
948 WORD error
= GetLastError();
953 class = action
= locus
= 0;
955 case ERROR_DIR_NOT_EMPTY
:
960 case ERROR_ACCESS_DENIED
:
961 class = EC_AccessDenied
;
965 case ERROR_CANNOT_MAKE
:
966 class = EC_AccessDenied
;
970 case ERROR_DISK_FULL
:
971 case ERROR_HANDLE_DISK_FULL
:
972 class = EC_MediaError
;
976 case ERROR_FILE_EXISTS
:
977 case ERROR_ALREADY_EXISTS
:
982 case ERROR_FILE_NOT_FOUND
:
987 case ER_GeneralFailure
:
988 class = EC_SystemFailure
;
992 case ERROR_INVALID_DRIVE
:
993 class = EC_MediaError
;
997 case ERROR_INVALID_HANDLE
:
998 class = EC_ProgramError
;
1002 case ERROR_LOCK_VIOLATION
:
1003 class = EC_AccessDenied
;
1007 case ERROR_NO_MORE_FILES
:
1008 class = EC_MediaError
;
1013 class = EC_NotFound
;
1017 case ERROR_NOT_ENOUGH_MEMORY
:
1018 class = EC_OutOfResource
;
1022 case ERROR_PATH_NOT_FOUND
:
1023 class = EC_NotFound
;
1028 class = EC_NotFound
;
1032 case ERROR_SHARING_VIOLATION
:
1033 class = EC_Temporary
;
1037 case ERROR_TOO_MANY_OPEN_FILES
:
1038 class = EC_ProgramError
;
1043 FIXME("Unknown error %d\n", error
);
1044 class = EC_SystemFailure
;
1049 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1050 error
, class, action
, locus
);
1051 AX_reg(context
) = error
;
1052 BH_reg(context
) = class;
1053 BL_reg(context
) = action
;
1054 CH_reg(context
) = locus
;
1057 /***********************************************************************
1058 * DOS3Call (KERNEL.102)
1060 void WINAPI
DOS3Call( CONTEXT86
*context
)
1062 BOOL bSetDOSExtendedError
= FALSE
;
1065 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1066 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1067 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1068 SI_reg(context
), DI_reg(context
),
1069 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
1073 if (AH_reg(context
) == 0x59) /* Get extended error info */
1075 INT21_GetExtendedError( context
);
1079 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1081 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1082 /* no flush here yet */
1083 AH_reg(context
) = AL_reg(context
);
1086 if (AH_reg(context
)>=0x2f) {
1087 /* extended error is used by (at least) functions 0x2f to 0x62 */
1090 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1092 switch(AH_reg(context
))
1094 case 0x03: /* READ CHARACTER FROM STDAUX */
1095 case 0x04: /* WRITE CHARACTER TO STDAUX */
1096 case 0x05: /* WRITE CHARACTER TO PRINTER */
1097 case 0x0f: /* OPEN FILE USING FCB */
1098 case 0x10: /* CLOSE FILE USING FCB */
1099 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1100 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1101 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1102 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1103 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1104 case 0x23: /* GET FILE SIZE FOR FCB */
1105 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1106 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1107 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1108 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1109 INT_BARF( context
, 0x21 );
1112 case 0x00: /* TERMINATE PROGRAM */
1113 TRACE("TERMINATE PROGRAM\n");
1117 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1118 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1119 AL_reg(context
) = CONSOLE_GetCharacter();
1120 /* FIXME: no echo */
1123 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1124 TRACE("Write Character to Standard Output\n");
1125 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1128 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1129 if (DL_reg(context
) == 0xff) {
1130 static char scan
= 0;
1131 TRACE("Direct Console Input\n");
1133 /* return pending scancode */
1134 AL_reg(context
) = scan
;
1135 EFL_reg(context
) &= ~0x40; /* clear ZF */
1139 if (CONSOLE_CheckForKeystroke(&scan
,&ascii
)) {
1140 CONSOLE_GetKeystroke(&scan
,&ascii
);
1141 /* return ASCII code */
1142 AL_reg(context
) = ascii
;
1143 EFL_reg(context
) &= ~0x40; /* clear ZF */
1144 /* return scan code on next call only if ascii==0 */
1145 if (ascii
) scan
= 0;
1147 /* nothing pending, clear everything */
1148 AL_reg(context
) = 0;
1149 EFL_reg(context
) |= 0x40; /* set ZF */
1150 scan
= 0; /* just in case */
1154 TRACE("Direct Console Output\n");
1155 CONSOLE_Write(DL_reg(context
), 0, 0, 0);
1159 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1160 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1161 AL_reg(context
) = CONSOLE_GetCharacter();
1164 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1165 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1166 AL_reg(context
) = CONSOLE_GetCharacter();
1169 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1170 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1171 DS_reg(context
),DX_reg(context
) );
1173 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
));
1175 /* do NOT use strchr() to calculate the string length,
1176 as '\0' is valid string content, too !
1177 Maybe we should check for non-'$' strings, but DOS doesn't. */
1178 while (*p
!= '$') p
++;
1179 _hwrite16( 1, data
, (int)p
- (int)data
);
1180 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1184 case 0x0a: /* BUFFERED INPUT */
1186 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1187 EDX_reg(context
) ));
1190 TRACE("BUFFERED INPUT (size=%d)\n",buffer
[0]);
1192 TRACE("Handle old chars in buffer!\n");
1193 res
=_lread16( 0, buffer
+2,buffer
[0]);
1195 if(buffer
[res
+1] == '\n')
1196 buffer
[res
+1] = '\r';
1200 case 0x0b: {/* GET STDIN STATUS */
1203 if (CONSOLE_CheckForKeystroke(&x1
,&x2
))
1204 AL_reg(context
) = 0xff;
1206 AL_reg(context
) = 0;
1209 case 0x2e: /* SET VERIFY FLAG */
1210 TRACE("SET VERIFY FLAG ignored\n");
1211 /* we cannot change the behaviour anyway, so just ignore it */
1214 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1218 case 0x6b: /* NULL FUNCTION */
1219 AL_reg(context
) = 0;
1222 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1226 case 0x0d: /* DISK BUFFER FLUSH */
1227 TRACE("DISK BUFFER FLUSH ignored\n");
1228 RESET_CFLAG(context
); /* dos 6+ only */
1231 case 0x0e: /* SELECT DEFAULT DRIVE */
1232 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1233 DRIVE_SetCurrentDrive( DL_reg(context
) );
1234 AL_reg(context
) = MAX_DOS_DRIVES
;
1237 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1238 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1239 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1240 if (!INT21_FindFirstFCB(context
))
1242 AL_reg(context
) = 0xff;
1245 /* else fall through */
1247 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1248 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1251 case 0x13: /* DELETE FILE USING FCB */
1252 DeleteFileFCB(context
);
1255 case 0x17: /* RENAME FILE USING FCB */
1256 RenameFileFCB(context
);
1259 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1260 AL_reg(context
) = DRIVE_GetCurrentDrive();
1263 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1265 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1266 pTask
->dta
= PTR_SEG_OFF_TO_SEGPTR(DS_reg(context
),DX_reg(context
));
1267 TRACE("Set DTA: %08lx\n", pTask
->dta
);
1271 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1272 DL_reg(context
) = 0;
1273 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1276 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1277 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1280 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1281 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1284 case 0x25: /* SET INTERRUPT VECTOR */
1285 INT_CtxSetHandler( context
, AL_reg(context
),
1286 (FARPROC16
)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1290 case 0x29: /* PARSE FILENAME INTO FCB */
1291 INT21_ParseFileNameIntoFCB(context
);
1294 case 0x2a: /* GET SYSTEM DATE */
1295 INT21_GetSystemDate(context
);
1298 case 0x2b: /* SET SYSTEM DATE */
1299 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1300 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1301 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1304 case 0x2c: /* GET SYSTEM TIME */
1305 INT21_GetSystemTime(context
);
1308 case 0x2d: /* SET SYSTEM TIME */
1309 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1310 CH_reg(context
), CL_reg(context
),
1311 DH_reg(context
), DL_reg(context
) );
1312 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1315 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1316 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1318 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
1319 ES_reg(context
) = SELECTOROF( pTask
->dta
);
1320 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1324 case 0x30: /* GET DOS VERSION */
1325 TRACE("GET DOS VERSION %s requested\n",
1326 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1327 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1328 (HIWORD(GetVersion16()) << 8);
1330 AH_reg(context
) = 0x7;
1331 AL_reg(context
) = 0xA;
1334 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1335 CX_reg(context
) = 0x0000;
1338 case 0x31: /* TERMINATE AND STAY RESIDENT */
1339 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1342 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1343 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1344 INT21_DriveName( DL_reg(context
)));
1345 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1348 case 0x33: /* MULTIPLEXED */
1349 switch (AL_reg(context
))
1351 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1352 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1353 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1356 case 0x01: /* SET EXTENDED BREAK STATE */
1357 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1358 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1361 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1362 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1363 /* ugly coding in order to stay reentrant */
1364 if (DL_reg(context
))
1366 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1367 DOSCONF_config
.brk_flag
= 1;
1371 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1372 DOSCONF_config
.brk_flag
= 0;
1376 case 0x05: /* GET BOOT DRIVE */
1377 TRACE("GET BOOT DRIVE\n");
1378 DL_reg(context
) = 3;
1379 /* c: is Wine's bootdrive (a: is 1)*/
1382 case 0x06: /* GET TRUE VERSION NUMBER */
1383 TRACE("GET TRUE VERSION NUMBER\n");
1384 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1385 (HIWORD(GetVersion16() << 8));
1386 DX_reg(context
) = 0x00;
1390 INT_BARF( context
, 0x21 );
1395 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1396 TRACE("GET ADDRESS OF INDOS FLAG\n");
1397 if (!heap
) INT21_CreateHeap();
1398 ES_reg(context
) = DosHeapHandle
;
1399 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1402 case 0x35: /* GET INTERRUPT VECTOR */
1403 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1405 FARPROC16 addr
= INT_CtxGetHandler( context
, AL_reg(context
) );
1406 ES_reg(context
) = SELECTOROF(addr
);
1407 BX_reg(context
) = OFFSETOF(addr
);
1411 case 0x36: /* GET FREE DISK SPACE */
1412 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1413 INT21_DriveName( DL_reg(context
)));
1414 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1419 unsigned char switchchar
='/';
1420 switch (AL_reg(context
))
1422 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1423 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1424 AL_reg(context
) = 0x00; /* success*/
1425 DL_reg(context
) = switchchar
;
1427 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1428 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1429 switchchar
= DL_reg(context
);
1430 AL_reg(context
) = 0x00; /* success*/
1432 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1433 INT_BARF( context
, 0x21 );
1439 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1440 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1442 AX_reg(context
) = 0x02; /* no country support available */
1446 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1448 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1449 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1450 EDX_reg(context
) ), NULL
));
1451 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1452 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1453 * denied), while CreateDirectory return several ones. remap some of
1456 if (bSetDOSExtendedError
) {
1457 switch (GetLastError()) {
1458 case ERROR_ALREADY_EXISTS
:
1459 case ERROR_FILENAME_EXCED_RANGE
:
1460 case ERROR_DISK_FULL
:
1461 SetLastError(ERROR_ACCESS_DENIED
);
1468 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1470 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1471 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1472 EDX_reg(context
) )));
1475 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1477 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1478 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1481 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1482 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context
),
1483 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1484 bSetDOSExtendedError
= INT21_CreateFile( context
);
1487 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1488 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context
),
1489 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1490 OpenExistingFile(context
);
1493 case 0x3e: /* "CLOSE" - CLOSE FILE */
1494 TRACE("CLOSE handle %d\n",BX_reg(context
));
1495 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1498 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1499 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1500 DS_reg(context
),DX_reg(context
),CX_reg(context
) );
1504 result
= _hread16( BX_reg(context
),
1505 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1509 result
= WIN16_hread( BX_reg(context
),
1510 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context
),
1513 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1514 else AX_reg(context
) = (WORD
)result
;
1518 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1519 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1520 DS_reg(context
),DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1522 LONG result
= _hwrite16( BX_reg(context
),
1523 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1526 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1527 else AX_reg(context
) = (WORD
)result
;
1531 case 0x41: /* "UNLINK" - DELETE FILE */
1533 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1534 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1535 EDX_reg(context
) )));
1538 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1539 TRACE("LSEEK handle %d offset %ld from %s\n",
1540 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1541 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1542 "current file position":"end of file");
1544 LONG status
= _llseek16( BX_reg(context
),
1545 MAKELONG(DX_reg(context
),CX_reg(context
)),
1547 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1550 AX_reg(context
) = LOWORD(status
);
1551 DX_reg(context
) = HIWORD(status
);
1556 case 0x43: /* FILE ATTRIBUTES */
1557 switch (AL_reg(context
))
1560 TRACE("GET FILE ATTRIBUTES for %s\n",
1561 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1562 AX_reg(context
) = (WORD
)GetFileAttributesA(
1563 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1565 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1566 else CX_reg(context
) = AX_reg(context
);
1570 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1571 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1572 bSetDOSExtendedError
=
1573 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1578 TRACE("GET COMPRESSED FILE SIZE for %s stub\n",
1579 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1583 case 0x44: /* IOCTL */
1584 switch (AL_reg(context
))
1587 ioctlGetDeviceInfo(context
);
1593 const DOS_DEVICE
*dev
;
1594 if ((dev
= DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context
)) )) &&
1595 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1597 ASPI_DOS_HandleInt(context
);
1601 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1602 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1603 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1605 FIXME("program tried to write to block device control channel of drive %d:\n",drive
);
1606 /* for (i=0;i<CX_reg(context);i++)
1607 fprintf(stdnimp,"%02x ",dataptr[i]);
1608 fprintf(stdnimp,"\n");*/
1609 AX_reg(context
)=CX_reg(context
);
1612 case 0x08: /* Check if drive is removable. */
1613 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1614 INT21_DriveName( BL_reg(context
)));
1615 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1617 case DRIVE_CANNOTDETERMINE
:
1618 SetLastError( ERROR_INVALID_DRIVE
);
1619 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1622 case DRIVE_REMOVABLE
:
1623 AX_reg(context
) = 0; /* removable */
1626 AX_reg(context
) = 1; /* not removable */
1631 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1632 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1633 INT21_DriveName( BL_reg(context
)));
1634 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1636 case DRIVE_CANNOTDETERMINE
:
1637 SetLastError( ERROR_INVALID_DRIVE
);
1638 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1642 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1645 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1650 case 0x0a: /* check if handle (BX) is remote */
1651 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1652 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1655 DX_reg(context
) = 0;
1658 case 0x0b: /* SET SHARING RETRY COUNT */
1659 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1660 CX_reg(context
), DX_reg(context
));
1661 if (!CX_reg(context
))
1663 AX_reg(context
) = 1;
1667 DOSMEM_LOL()->sharing_retry_delay
= CX_reg(context
);
1668 if (!DX_reg(context
))
1669 DOSMEM_LOL()->sharing_retry_count
= DX_reg(context
);
1670 RESET_CFLAG(context
);
1674 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1675 INT21_DriveName( BL_reg(context
)));
1676 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1679 case 0x0e: /* get logical drive mapping */
1680 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1681 INT21_DriveName( BL_reg(context
)));
1682 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1685 case 0x0F: /* Set logical drive mapping */
1688 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1689 INT21_DriveName( BL_reg(context
)));
1690 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1691 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1694 AX_reg(context
) = 0x000F; /* invalid drive */
1699 case 0xe0: /* Sun PC-NFS API */
1704 INT_BARF( context
, 0x21 );
1709 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1712 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1713 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1714 FILE_GetHandle(BX_reg(context
)),
1715 GetCurrentProcess(), &handle
,
1716 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1717 AX_reg(context
) = HFILE_ERROR16
;
1719 AX_reg(context
) = FILE_AllocDosHandle(handle
);
1723 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1724 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1725 BX_reg(context
),CX_reg(context
));
1726 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1729 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1730 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1731 INT21_DriveName( DL_reg(context
)));
1732 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1735 case 0x48: /* ALLOCATE MEMORY */
1736 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1741 mem
= DOSMEM_GetBlock(0,(DWORD
)BX_reg(context
)<<4,NULL
);
1743 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1747 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1749 AX_reg(context
) = (DWORD
)mem
&0xffff;
1754 AX_reg(context
) = 0x0008; /* insufficient memory */
1755 BX_reg(context
) = DOSMEM_Available(0)>>4;
1760 case 0x49: /* FREE MEMORY */
1761 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context
));
1765 ret
= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4));
1768 ret
= !GlobalDOSFree16(ES_reg(context
));
1769 /* If we don't reset ES_reg, we will fail in the relay code */
1770 ES_reg(context
)=ret
;
1774 TRACE("FREE MEMORY failed\n");
1776 AX_reg(context
) = 0x0009; /* memory block address invalid */
1781 case 0x4a: /* RESIZE MEMORY BLOCK */
1782 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context
), BX_reg(context
));
1783 if (!ISV86(context
))
1784 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1786 LPVOID
*mem
= DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context
)<<4),
1787 BX_reg(context
)<<4,NULL
);
1789 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1792 AX_reg(context
) = 0x0008; /* insufficient memory */
1793 BX_reg(context
) = DOSMEM_Available(0)>>4; /* not quite right */
1798 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1800 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
) ));
1801 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1804 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1807 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1808 TRACE("EXIT with return code %d\n",AL_reg(context
));
1809 ExitProcess( AL_reg(context
) );
1812 case 0x4d: /* GET RETURN CODE */
1813 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1814 AX_reg(context
) = 0; /* normal exit */
1817 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1818 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1819 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1820 if (!INT21_FindFirst(context
)) break;
1823 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1824 TRACE("FINDNEXT\n");
1825 if (!INT21_FindNext(context
))
1827 SetLastError( ERROR_NO_MORE_FILES
);
1828 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1831 else AX_reg(context
) = 0; /* OK */
1833 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1834 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1835 INT21_SetCurrentPSP(BX_reg(context
));
1837 case 0x51: /* GET PSP ADDRESS */
1838 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1839 /* FIXME: should we return the original DOS PSP upon */
1840 /* Windows startup ? */
1841 BX_reg(context
) = INT21_GetCurrentPSP();
1843 case 0x62: /* GET PSP ADDRESS */
1844 TRACE("GET CURRENT PSP ADDRESS\n");
1845 /* FIXME: should we return the original DOS PSP upon */
1846 /* Windows startup ? */
1847 BX_reg(context
) = INT21_GetCurrentPSP();
1850 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1851 TRACE("SYSVARS - GET LIST OF LISTS\n");
1853 ES_reg(context
) = ISV86(context
) ? HIWORD(DOS_LOLSeg
) : LOWORD(DOS_LOLSeg
);
1854 BX_reg(context
) = FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
);
1858 case 0x54: /* Get Verify Flag */
1859 TRACE("Get Verify Flag - Not Supported\n");
1860 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1863 case 0x56: /* "RENAME" - RENAME FILE */
1864 TRACE("RENAME %s to %s\n",
1865 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1866 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
)));
1867 bSetDOSExtendedError
=
1868 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1869 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
))));
1872 case 0x57: /* FILE DATE AND TIME */
1873 switch (AL_reg(context
))
1875 case 0x00: /* Get */
1878 TRACE("GET FILE DATE AND TIME for handle %d\n",
1880 if (!GetFileTime( FILE_GetHandle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1881 bSetDOSExtendedError
= TRUE
;
1882 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1887 case 0x01: /* Set */
1890 TRACE("SET FILE DATE AND TIME for handle %d\n",
1892 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1894 bSetDOSExtendedError
=
1895 (!SetFileTime( FILE_GetHandle(BX_reg(context
)),
1896 NULL
, NULL
, &filetime
));
1902 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1903 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1905 switch (AL_reg(context
))
1908 AX_reg(context
) = 1;
1911 AX_reg(context
) = 0;
1917 RESET_CFLAG(context
);
1920 case 0x5a: /* CREATE TEMPORARY FILE */
1921 TRACE("CREATE TEMPORARY FILE\n");
1922 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1925 case 0x5b: /* CREATE NEW FILE */
1926 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1927 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
1928 bSetDOSExtendedError
= ((AX_reg(context
) =
1929 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
1930 CX_reg(context
) )) == (WORD
)HFILE_ERROR16
);
1933 case 0x5d: /* NETWORK */
1934 FIXME("Function 0x%04x not implemented.\n", AX_reg (context
));
1935 /* Fix the following while you're at it. */
1936 SetLastError( ER_NoNetwork
);
1937 bSetDOSExtendedError
= TRUE
;
1941 bSetDOSExtendedError
= INT21_networkfunc (context
);
1944 case 0x5f: /* NETWORK */
1945 switch (AL_reg(context
))
1947 case 0x07: /* ENABLE DRIVE */
1948 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1949 if (!DRIVE_Enable( DL_reg(context
) ))
1951 SetLastError( ERROR_INVALID_DRIVE
);
1952 bSetDOSExtendedError
= TRUE
;
1956 case 0x08: /* DISABLE DRIVE */
1957 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1958 if (!DRIVE_Disable( DL_reg(context
) ))
1960 SetLastError( ERROR_INVALID_DRIVE
);
1961 bSetDOSExtendedError
= TRUE
;
1966 /* network software not installed */
1967 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1968 SetLastError( ER_NoNetwork
);
1969 bSetDOSExtendedError
= TRUE
;
1974 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1975 TRACE("TRUENAME %s\n",
1976 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),ESI_reg(context
)));
1978 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
1979 ESI_reg(context
)), 128,
1980 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
1981 EDI_reg(context
)),NULL
))
1982 bSetDOSExtendedError
= TRUE
;
1983 else AX_reg(context
) = 0;
1987 case 0x61: /* UNUSED */
1988 case 0x63: /* misc. language support */
1989 switch (AL_reg(context
)) {
1990 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1991 INT21_GetDBCSLeadTable(context
);
1995 case 0x64: /* OS/2 DOS BOX */
1996 INT_BARF( context
, 0x21 );
2000 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2001 extern WORD WINE_LanguageId
;
2002 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),EDI_reg(context
));
2003 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2004 BX_reg(context
), DX_reg(context
));
2005 switch (AL_reg(context
)) {
2007 TRACE("\tget general internationalization info\n");
2009 *(WORD
*)(dataptr
+1) = 41;
2010 *(WORD
*)(dataptr
+3) = WINE_LanguageId
;
2011 *(WORD
*)(dataptr
+5) = CodePage
;
2012 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2015 TRACE("\tget pointer to collating sequence table\n");
2017 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2018 CX_reg(context
) = 258;/*FIXME: size of table?*/
2021 TRACE("\tConvert char to uppercase\n");
2022 DL_reg(context
) = toupper(DL_reg(context
));
2025 TRACE("\tconvert string to uppercase with length\n");
2026 CharUpperBuffA( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
)),
2030 TRACE("\tConvert ASCIIZ string to uppercase\n");
2031 CharUpperA( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,DS_reg(context
),EDX_reg(context
)) );
2034 TRACE("\tunimplemented function %d\n",AL_reg(context
));
2035 INT_BARF( context
, 0x21 );
2041 case 0x66: /* GLOBAL CODE PAGE TABLE */
2042 switch (AL_reg(context
))
2045 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2046 DX_reg(context
) = BX_reg(context
) = CodePage
;
2047 RESET_CFLAG(context
);
2050 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2051 BX_reg(context
),DX_reg(context
));
2052 CodePage
= BX_reg(context
);
2053 RESET_CFLAG(context
);
2058 case 0x67: /* SET HANDLE COUNT */
2059 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context
) );
2060 SetHandleCount16( BX_reg(context
) );
2061 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2064 case 0x68: /* "FFLUSH" - COMMIT FILE */
2065 case 0x6a: /* COMMIT FILE */
2066 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2067 bSetDOSExtendedError
= (!FlushFileBuffers( FILE_GetHandle(BX_reg(context
)) ));
2070 case 0x69: /* DISK SERIAL NUMBER */
2071 switch (AL_reg(context
))
2074 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2075 INT21_DriveName(BL_reg(context
)));
2076 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2077 else AX_reg(context
) = 0;
2081 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2082 INT21_DriveName(BL_reg(context
)));
2083 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2084 else AX_reg(context
) = 1;
2089 case 0x6C: /* Extended Open/Create*/
2090 TRACE("EXTENDED OPEN/CREATE %s\n",
2091 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDI_reg(context
)));
2092 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2095 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2096 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2097 /* not supported on anything but Win95 */
2098 TRACE("LONG FILENAME functions supported only by win95\n");
2100 AL_reg(context
) = 0;
2102 switch(AL_reg(context
))
2104 case 0x39: /* Create directory */
2105 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2106 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2107 bSetDOSExtendedError
= (!CreateDirectoryA(
2108 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2109 EDX_reg(context
) ), NULL
));
2110 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2111 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2112 * denied), while CreateDirectory return several ones. remap some of
2115 if (bSetDOSExtendedError
) {
2116 switch (GetLastError()) {
2117 case ERROR_ALREADY_EXISTS
:
2118 case ERROR_FILENAME_EXCED_RANGE
:
2119 case ERROR_DISK_FULL
:
2120 SetLastError(ERROR_ACCESS_DENIED
);
2126 case 0x3a: /* Remove directory */
2127 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2128 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2129 bSetDOSExtendedError
= (!RemoveDirectoryA(
2130 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2131 EDX_reg(context
) )));
2133 case 0x43: /* Get/Set file attributes */
2134 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2135 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2136 switch (BL_reg(context
))
2138 case 0x00: /* Get file attributes */
2139 TRACE("\tretrieve attributes\n");
2140 CX_reg(context
) = (WORD
)GetFileAttributesA(
2141 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2143 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2146 TRACE("\tset attributes 0x%04x\n",CX_reg(context
));
2147 bSetDOSExtendedError
= (!SetFileAttributesA(
2148 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2150 CX_reg(context
) ) );
2153 FIXME("Unimplemented long file name function:\n");
2154 INT_BARF( context
, 0x21 );
2156 AL_reg(context
) = 0;
2160 case 0x47: /* Get current directory */
2161 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2162 INT21_DriveName(DL_reg(context
)));
2163 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2166 case 0x4e: /* Find first file */
2167 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2168 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2169 /* FIXME: use attributes in CX */
2170 if ((AX_reg(context
) = FindFirstFile16(
2171 CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)),
2172 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2174 == INVALID_HANDLE_VALUE16
)
2175 bSetDOSExtendedError
= TRUE
;
2177 case 0x4f: /* Find next file */
2178 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2180 if (!FindNextFile16( BX_reg(context
),
2181 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2183 bSetDOSExtendedError
= TRUE
;
2185 case 0xa1: /* Find close */
2186 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2188 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2191 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2192 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),EDX_reg(context
)));
2195 switch(CL_reg(context
))
2197 case 0x01: /*Get short filename or path */
2198 if (!GetShortPathNameA
2199 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2201 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2202 EDI_reg(context
)), 67))
2203 bSetDOSExtendedError
= TRUE
;
2204 else AX_reg(context
) = 0;
2206 case 0x02: /*Get canonical long filename or path */
2207 if (!GetFullPathNameA
2208 ( CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
),
2209 ESI_reg(context
)), 128,
2210 CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
),
2211 EDI_reg(context
)),NULL
))
2212 bSetDOSExtendedError
= TRUE
;
2213 else AX_reg(context
) = 0;
2216 FIXME("Unimplemented long file name function:\n");
2217 INT_BARF( context
, 0x21 );
2219 AL_reg(context
) = 0;
2223 case 0x6c: /* Create or open file */
2224 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2225 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), ESI_reg(context
)));
2226 /* translate Dos 7 action to Dos 6 action */
2227 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2230 case 0x3b: /* Change directory */
2231 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2232 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2233 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2239 AL_reg(context
) = GetLastError();
2242 case 0x41: /* Delete file */
2243 TRACE("LONG FILENAME - DELETE FILE %s\n",
2244 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)));
2245 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2250 AL_reg(context
) = GetLastError();
2253 case 0x56: /* Move (rename) file */
2254 TRACE("LONG FILENAME - RENAME FILE %s to %s stub\n",
2255 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, DS_reg(context
), EDX_reg(context
)),
2256 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EDI_reg(context
)));
2258 FIXME("Unimplemented long file name function:\n");
2259 INT_BARF( context
, 0x21 );
2261 AL_reg(context
) = 0;
2266 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2267 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2268 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2269 TRACE("windows95 function AX %04x\n",
2271 WARN(" returning unimplemented\n");
2273 AL_reg(context
) = 0;
2276 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2277 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2281 INT_BARF( context
, 0x21 );
2284 } /* END OF SWITCH */
2286 if( bSetDOSExtendedError
) /* set general error condition */
2288 AX_reg(context
) = GetLastError();
2292 if ((EFL_reg(context
) & 0x0001))
2293 TRACE("failed, error 0x%04lx\n", GetLastError() );
2295 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2296 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2297 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2298 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2299 (WORD
)DS_reg(context
), (WORD
)ES_reg(context
),
2303 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2305 FIXME("(DosProc=0x%08x): stub\n", (UINT
)DosProc
);