2 * DOS interrupt 21h handler
4 * Copyright 1993, 1994 Erik Bos
5 * Copyright 1996 Alexandre Julliard
6 * Copyright 1997 Andreas Mohr
7 * Copyright 1998 Uwe Bonnes
8 * Copyright 1998, 1999 Ove Kaaven
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/port.h"
33 #ifdef HAVE_SYS_FILE_H
34 # include <sys/file.h>
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
40 #include <sys/types.h>
52 #include "winuser.h" /* SW_NORMAL */
53 #include "wine/winbase16.h"
61 #include "wine/unicode.h"
62 #include "wine/debug.h"
64 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
65 #if defined(__svr4__) || defined(_SCO_DS)
66 /* SVR4 DOESNT do locking the same way must implement properly */
73 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
75 /* Define the drive parameter block, as used by int21/1F
76 * and int21/32. This table can be accessed through the
77 * global 'dpb' pointer, which points into the local dos
82 BYTE drive_num
; /* 0=A, etc. */
83 BYTE unit_num
; /* Drive's unit number (?) */
84 WORD sector_size
; /* Sector size in bytes */
85 BYTE high_sector
; /* Highest sector in a cluster */
86 BYTE shift
; /* Shift count (?) */
87 WORD reserved
; /* Number of reserved sectors at start */
88 BYTE num_FAT
; /* Number of FATs */
89 WORD dir_entries
; /* Number of root dir entries */
90 WORD first_data
; /* First data sector */
91 WORD high_cluster
; /* Highest cluster number */
92 WORD sectors_in_FAT
; /* Number of sectors per FAT */
93 WORD start_dir
; /* Starting sector of first dir */
94 DWORD driver_head
; /* Address of device driver header (?) */
95 BYTE media_ID
; /* Media ID */
96 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
97 DWORD next
; /* Pointer to next DPB in list */
98 WORD free_search
; /* Free cluster search start */
99 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
102 struct EDPB
/* FAT32 extended Drive Parameter Block */
103 { /* from Ralf Brown's Interrupt List */
104 struct DPB dpb
; /* first 24 bytes = original DPB */
106 BYTE edpb_flags
; /* undocumented/unknown flags */
107 DWORD next_edpb
; /* pointer to next EDPB */
108 WORD free_cluster
; /* cluster to start search for free space on write, typically
109 the last cluster allocated */
110 WORD clusters_free
; /* number of free clusters on drive or FFFF = unknown */
111 WORD clusters_free_hi
; /* hiword of clusters_free */
112 WORD mirroring_flags
; /* mirroring flags: bit 7 set = do not mirror active FAT */
113 /* bits 0-3 = 0-based number of the active FAT */
114 WORD info_sector
; /* sector number of file system info sector, or FFFF for none */
115 WORD spare_boot_sector
; /* sector number of backup boot sector, or FFFF for none */
116 DWORD first_cluster
; /* sector number of the first cluster */
117 DWORD max_cluster
; /* sector number of the last cluster */
118 DWORD fat_clusters
; /* number of clusters occupied by FAT */
119 DWORD root_cluster
; /* cluster number of start of root directory */
120 DWORD free_cluster2
; /* same as free_cluster: cluster at which to start
121 search for free space when writing */
133 BYTE DummyDBCSLeadTable
[6];
135 static struct DosHeap
*heap
;
136 static WORD DosHeapHandle
;
138 extern char TempDirectory
[];
140 static void INT21_ReadConfigSys(void)
143 if (!done
) DOSCONF_ReadConfig();
147 static BOOL
INT21_CreateHeap(void)
149 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
151 WARN("Out of memory\n");
154 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
155 dpbsegptr
= MAKESEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
157 strcpy(heap
->biosdate
, "01/01/80");
158 memset(heap
->DummyDBCSLeadTable
, 0, 6);
162 static BYTE
*GetCurrentDTA( CONTEXT86
*context
)
164 TDB
*pTask
= TASK_GetCurrent();
166 /* FIXME: This assumes DTA was set correctly! */
167 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
168 (DWORD
)OFFSETOF(pTask
->dta
) );
172 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
173 /* limited == TRUE is used with INT 0x21/0x440d */
178 setword(&data
[3], 0);
180 setword(&data
[6], 240);
181 setword(&data
[8], 64000);
183 setword(&data
[0x0b], 40);
184 setword(&data
[0x0d], 56);
185 setword(&data
[0x0f], 2);
186 setword(&data
[0x11], 0);
188 setword(&data
[0x1f], 800);
190 setword(&data
[0x22], 1);
192 } else { /* 1.44mb */
195 setword(&data
[3], 0);
197 setword(&data
[6], 240);
198 setword(&data
[8], 2880);
200 setword(&data
[0x0b], 6);
201 setword(&data
[0x0d], 18);
202 setword(&data
[0x0f], 2);
203 setword(&data
[0x11], 0);
205 setword(&data
[0x1f], 80);
207 setword(&data
[0x22], 2);
212 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
214 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
215 char root
[] = "A:\\";
217 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
218 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
219 &free_clusters
, &total_clusters
)) return 0;
220 SET_AX( context
, cluster_sectors
);
221 SET_BX( context
, free_clusters
);
222 SET_CX( context
, sector_bytes
);
223 SET_DX( context
, total_clusters
);
227 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
)
229 if (!INT21_GetFreeDiskSpace( context
)) return 0;
230 if (!heap
&& !INT21_CreateHeap()) return 0;
231 heap
->mediaID
= 0xf0;
232 context
->SegDs
= DosHeapHandle
;
233 SET_BX( context
, (int)&heap
->mediaID
- (int)heap
);
237 static int FillInDrivePB( int drive
)
239 if(!DRIVE_IsValid(drive
))
241 SetLastError( ERROR_INVALID_DRIVE
);
244 else if (heap
|| INT21_CreateHeap())
246 /* FIXME: I have no idea what a lot of this information should
247 * say or whether it even really matters since we're not allowing
248 * direct block access. However, some programs seem to depend on
249 * getting at least _something_ back from here. The 'next' pointer
250 * does worry me, though. Should we have a complete table of
251 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
253 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
254 heap
->dpb
.sector_size
= 512;
255 heap
->dpb
.high_sector
= 1;
256 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
257 heap
->dpb
.reserved
= 0;
258 heap
->dpb
.num_FAT
= 1;
259 heap
->dpb
.dir_entries
= 2;
260 heap
->dpb
.first_data
= 2;
261 heap
->dpb
.high_cluster
= 64000;
262 heap
->dpb
.sectors_in_FAT
= 1;
263 heap
->dpb
.start_dir
= 1;
264 heap
->dpb
.driver_head
= 0;
265 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
266 heap
->dpb
.access_flag
= 0;
268 heap
->dpb
.free_search
= 0;
269 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
276 static void GetDrivePB( CONTEXT86
*context
, int drive
)
278 if (FillInDrivePB( drive
))
280 SET_AL( context
, 0x00 );
281 context
->SegDs
= SELECTOROF(dpbsegptr
);
282 SET_BX( context
, OFFSETOF(dpbsegptr
) );
286 SET_AX( context
, 0x00ff );
291 static void ioctlGetDeviceInfo( CONTEXT86
*context
)
294 const DOS_DEVICE
*dev
;
296 TRACE("(%d)\n", BX_reg(context
));
298 RESET_CFLAG(context
);
301 if ((dev
= DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context
)) )))
303 SET_DX( context
, dev
->flags
);
307 /* it seems to be a file */
308 curr_drive
= DRIVE_GetCurrentDrive();
309 SET_DX( context
, 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0) );
311 /* bits 0-5 are current drive
312 * bit 6 - file has NOT been written..FIXME: correct?
313 * bit 8 - generate int24 if no diskspace on write/ read past end of file
314 * bit 11 - media not removable
315 * bit 14 - don't set file date/time on closing
316 * bit 15 - file is remote
320 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
322 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
323 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
325 if (!DRIVE_IsValid(drive
))
327 SetLastError( ERROR_FILE_NOT_FOUND
);
331 if (CH_reg(context
) != 0x08)
333 INT_BARF( context
, 0x21 );
337 switch (CL_reg(context
))
339 case 0x4a: /* lock logical volume */
340 TRACE("lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
343 case 0x60: /* get device parameters */
344 /* used by w4wgrp's winfile */
345 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
347 dataptr
[6] = 0; /* media type */
350 dataptr
[1] = 0x05; /* fixed disk */
351 setword(&dataptr
[2], 0x01); /* non removable */
352 setword(&dataptr
[4], 0x300); /* # of cylinders */
356 dataptr
[1] = 0x07; /* block dev, floppy */
357 setword(&dataptr
[2], 0x02); /* removable */
358 setword(&dataptr
[4], 80); /* # of cylinders */
360 CreateBPB(drive
, &dataptr
[7], TRUE
);
361 RESET_CFLAG(context
);
364 case 0x41: /* write logical device track */
365 case 0x61: /* read logical device track */
367 BYTE drive
= BL_reg(context
) ?
368 BL_reg(context
) : DRIVE_GetCurrentDrive();
369 WORD head
= *(WORD
*)dataptr
+1;
370 WORD cyl
= *(WORD
*)dataptr
+3;
371 WORD sect
= *(WORD
*)dataptr
+5;
372 WORD nrsect
= *(WORD
*)dataptr
+7;
373 BYTE
*data
= (BYTE
*)dataptr
+9;
374 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
376 raw_func
= (CL_reg(context
) == 0x41) ?
377 DRIVE_RawWrite
: DRIVE_RawRead
;
379 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
380 RESET_CFLAG(context
);
383 SET_AX( context
, 0x1e ); /* read fault */
388 case 0x66:/* get disk serial number */
390 char label
[12],fsname
[9],path
[4];
393 strcpy(path
,"x:\\");path
[0]=drive
+'A';
394 GetVolumeInformationA(
395 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
398 memcpy(dataptr
+2,&serial
,4);
399 memcpy(dataptr
+6,label
,11);
400 memcpy(dataptr
+17,fsname
,8);
405 TRACE("logical volume %d unlocked.\n",drive
);
409 memset(dataptr
+1, '\0', dataptr
[0]-1);
410 dataptr
[1] = dataptr
[0];
411 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
412 dataptr
[3] = 0xFF; /* no physical drive */
416 /* Trail on error implementation */
417 SET_AX( context
, GetDriveType16(BL_reg(context
)) == DRIVE_UNKNOWN
? 0x0f : 0x01 );
418 SET_CFLAG(context
); /* Seems to be set all the time */
422 INT_BARF( context
, 0x21 );
427 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
430 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
432 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
438 SET_AL( context
, 0xff ); /* failed */
440 TRACE("filename: '%s'\n", filename
);
446 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
455 buffer_len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, NULL
, 0);
456 buffer
= HeapAlloc( GetProcessHeap(), 0, (buffer_len
+ 1) * sizeof(WCHAR
));
457 len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, buffer
, buffer_len
);
459 DOSFS_ToDosFCBFormat(buffer
, fcbW
);
460 HeapFree(GetProcessHeap(), 0, buffer
);
461 WideCharToMultiByte(CP_OEMCP
, 0, fcbW
, 12, fcb
+ 1, 12, NULL
, NULL
);
463 TRACE("FCB: '%s'\n", fcb
+ 1);
465 SET_AL( context
, ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0 );
467 /* point DS:SI to first unparsed character */
468 SET_SI( context
, context
->Esi
+ (int)s
- (int)filename
);
471 static void INT21_GetSystemDate( CONTEXT86
*context
)
474 GetLocalTime( &systime
);
475 SET_CX( context
, systime
.wYear
);
476 SET_DX( context
, (systime
.wMonth
<< 8) | systime
.wDay
);
477 SET_AX( context
, systime
.wDayOfWeek
);
480 static void INT21_GetSystemTime( CONTEXT86
*context
)
483 GetLocalTime( &systime
);
484 SET_CX( context
, (systime
.wHour
<< 8) | systime
.wMinute
);
485 SET_DX( context
, (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10) );
488 /* Many calls translate a drive argument like this:
489 drive number (00h = default, 01h = A:, etc)
491 static char drivestring
[]="default";
493 char *INT21_DriveName(int drive
)
498 drivestring
[0]= (unsigned char)drive
+ '@';
504 static BOOL
INT21_CreateFile( CONTEXT86
*context
)
506 SET_AX( context
, _lcreat16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
507 context
->Edx
), CX_reg(context
) ) );
508 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
511 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
513 /* Mask off all flags not explicitly allowed by the doc */
514 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
515 return Win32HandleToDosFileHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
516 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
517 CREATE_NEW
, attr
, 0 ));
520 static void OpenExistingFile( CONTEXT86
*context
)
522 SET_AX( context
, _lopen16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
524 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
526 SET_AX( context
, GetLastError() );
531 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT86
*context
)
533 BOOL bExtendedError
= FALSE
;
534 BYTE action
= DL_reg(context
);
536 /* Shuffle arguments to call OpenExistingFile */
537 SET_AL( context
, BL_reg(context
) );
538 SET_DX( context
, SI_reg(context
) );
539 /* BX,CX and DX should be preserved */
540 OpenExistingFile(context
);
542 if ((context
->EFlags
& 0x0001) == 0) /* File exists */
544 UINT16 uReturnCX
= 0;
546 /* Now decide what do do */
548 if ((action
& 0x07) == 0)
550 _lclose16( AX_reg(context
) );
551 SET_AX( context
, 0x0050 ); /*File exists*/
553 WARN("extended open/create: failed because file exists \n");
555 else if ((action
& 0x07) == 2)
557 /* Truncate it, but first check if opened for write */
558 if ((BL_reg(context
) & 0x0007)== 0)
560 _lclose16( AX_reg(context
) );
561 WARN("extended open/create: failed, trunc on ro file\n");
562 SET_AX( context
, 0x000C ); /*Access code invalid*/
567 TRACE("extended open/create: Closing before truncate\n");
568 if (_lclose16( AX_reg(context
) ))
570 WARN("extended open/create: close before trunc failed\n");
571 SET_AX( context
, 0x0019 ); /*Seek Error*/
572 SET_CX( context
, 0 );
575 /* Shuffle arguments to call CreateFile */
577 TRACE("extended open/create: Truncating\n");
578 SET_AL( context
, BL_reg(context
) );
579 /* CX is still the same */
580 SET_DX( context
, SI_reg(context
) );
581 bExtendedError
= INT21_CreateFile(context
);
583 if (context
->EFlags
& 0x0001) /*no file open, flags set */
585 WARN("extended open/create: trunc failed\n");
586 return bExtendedError
;
591 else uReturnCX
= 0x1;
593 SET_CX( context
, uReturnCX
);
595 else /* file does not exist */
597 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
598 if ((action
& 0xF0)== 0)
600 SET_CX( context
, 0 );
602 WARN("extended open/create: failed, file dosen't exist\n");
606 /* Shuffle arguments to call CreateFile */
607 TRACE("extended open/create: Creating\n");
608 SET_AL( context
, BL_reg(context
) );
609 /* CX should still be the same */
610 SET_DX( context
, SI_reg(context
) );
611 bExtendedError
= INT21_CreateFile(context
);
612 if (context
->EFlags
& 0x0001) /*no file open, flags set */
614 WARN("extended open/create: create failed\n");
615 return bExtendedError
;
617 SET_CX( context
, 2 );
621 return bExtendedError
;
625 static BOOL
INT21_ChangeDir( CONTEXT86
*context
)
628 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
629 WCHAR dirnameW
[MAX_PATH
];
631 TRACE("changedir %s\n", dirname
);
632 if (dirname
[0] && (dirname
[1] == ':'))
634 drive
= toupper(dirname
[0]) - 'A';
637 else drive
= DRIVE_GetCurrentDrive();
638 MultiByteToWideChar(CP_OEMCP
, 0, dirname
, -1, dirnameW
, MAX_PATH
);
639 return DRIVE_Chdir( drive
, dirnameW
);
643 static int INT21_FindFirst( CONTEXT86
*context
)
647 DOS_FULL_NAME full_name
;
648 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
649 WCHAR pathW
[MAX_PATH
];
652 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
653 MultiByteToWideChar(CP_OEMCP
, 0, path
, -1, pathW
, MAX_PATH
);
655 dta
->unixPath
= NULL
;
656 if (!DOSFS_GetFullName( pathW
, FALSE
, &full_name
))
658 SET_AX( context
, GetLastError() );
662 dta
->unixPath
= HeapAlloc( GetProcessHeap(), 0, strlen(full_name
.long_name
)+1 );
663 strcpy( dta
->unixPath
, full_name
.long_name
);
664 p
= strrchr( dta
->unixPath
, '/' );
667 MultiByteToWideChar(CP_OEMCP
, 0, p
+ 1, -1, pathW
, MAX_PATH
);
669 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
670 * (doesn't matter as it is set below anyway)
672 if (!DOSFS_ToDosFCBFormat( pathW
, maskW
))
674 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
675 dta
->unixPath
= NULL
;
676 SetLastError( ERROR_FILE_NOT_FOUND
);
677 SET_AX( context
, ERROR_FILE_NOT_FOUND
);
681 WideCharToMultiByte(CP_OEMCP
, 0, maskW
, 12, dta
->mask
, sizeof(dta
->mask
), NULL
, NULL
);
682 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
683 : DRIVE_GetCurrentDrive();
685 dta
->search_attr
= CL_reg(context
);
690 static int INT21_FindNext( CONTEXT86
*context
)
692 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
693 WIN32_FIND_DATAA entry
;
696 if (!dta
->unixPath
) return 0;
697 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
698 dta
->search_attr
, dta
->count
, &entry
)))
700 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
701 dta
->unixPath
= NULL
;
704 if ((int)dta
->count
+ count
> 0xffff)
706 WARN("Too many directory entries in %s\n", dta
->unixPath
);
707 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
708 dta
->unixPath
= NULL
;
712 dta
->fileattr
= entry
.dwFileAttributes
;
713 dta
->filesize
= entry
.nFileSizeLow
;
714 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
715 &dta
->filedate
, &dta
->filetime
);
716 strcpy( dta
->filename
, entry
.cAlternateFileName
);
717 if (!memchr(dta
->mask
,'?',11)) {
718 /* wildcardless search, release resources in case no findnext will
719 * be issued, and as a workaround in case file creation messes up
720 * findnext, as sometimes happens with pkunzip */
721 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
722 dta
->unixPath
= NULL
;
728 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
730 static int counter
= 0;
731 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
732 char *p
= name
+ strlen(name
);
734 /* despite what Ralf Brown says, some programs seem to call without
735 * ending backslash (DOS accepts that, so we accept it too) */
736 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
740 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
741 counter
= (counter
+ 1) % 1000;
743 if ((SET_AX( context
, _lcreat16_uniq( name
, 0 ))) != (WORD
)HFILE_ERROR16
)
745 TRACE("created %s\n", name
);
748 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
753 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
)
755 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
756 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
758 if (!DRIVE_IsValid(drive
))
760 SetLastError( ERROR_INVALID_DRIVE
);
763 WideCharToMultiByte(CP_OEMCP
, 0, DRIVE_GetDosCwd(drive
), -1, ptr
, 64, NULL
, NULL
);
764 ptr
[63] = 0; /* ensure 0 termination */
765 SET_AX( context
, 0x0100 ); /* success return code */
770 static void INT21_GetDBCSLeadTable( CONTEXT86
*context
)
772 if (heap
|| INT21_CreateHeap())
773 { /* return an empty table just as DOS 4.0+ does */
774 context
->SegDs
= DosHeapHandle
;
775 SET_SI( context
, (int)&heap
->DummyDBCSLeadTable
- (int)heap
);
779 SET_AX( context
, 0x1 ); /* error */
785 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
787 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
788 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
790 if (!DRIVE_IsValid(drive
))
792 SetLastError( ERROR_INVALID_DRIVE
);
796 *(WORD
*)dataptr
= 0;
797 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
798 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
799 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
804 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
806 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
807 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
809 if (!DRIVE_IsValid(drive
))
811 SetLastError( ERROR_INVALID_DRIVE
);
815 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
820 /* microsoft's programmers should be shot for using CP/M style int21
821 calls in Windows for Workgroup's winfile.exe */
823 static int INT21_FindFirstFCB( CONTEXT86
*context
)
825 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
830 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
831 else pFCB
= (FINDFILE_FCB
*)fcb
;
832 drive
= DOS_GET_DRIVE( pFCB
->drive
);
833 if (!DRIVE_IsValid( drive
)) return 0;
834 root
= DRIVE_GetRoot( drive
);
835 cwd
= DRIVE_GetUnixCwd( drive
);
836 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
837 strlen(root
)+strlen(cwd
)+2 );
838 if (!pFCB
->unixPath
) return 0;
839 strcpy( pFCB
->unixPath
, root
);
840 strcat( pFCB
->unixPath
, "/" );
841 strcat( pFCB
->unixPath
, cwd
);
847 static int INT21_FindNextFCB( CONTEXT86
*context
)
849 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
851 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
852 WIN32_FIND_DATAA entry
;
856 if (*fcb
== 0xff) /* extended FCB ? */
859 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
864 pFCB
= (FINDFILE_FCB
*)fcb
;
867 if (!pFCB
->unixPath
) return 0;
868 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
869 DOS_GET_DRIVE( pFCB
->drive
), attr
,
870 pFCB
->count
, &entry
)))
872 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
873 pFCB
->unixPath
= NULL
;
876 pFCB
->count
+= count
;
878 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
879 *(BYTE
*)pResult
= 0xff;
880 (BYTE
*)pResult
+=6; /* leave reserved field behind */
881 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
884 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
886 pResult
->fileattr
= entry
.dwFileAttributes
;
887 pResult
->cluster
= 0; /* what else? */
888 pResult
->filesize
= entry
.nFileSizeLow
;
889 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
890 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
891 &pResult
->filedate
, &pResult
->filetime
);
893 /* Convert file name to FCB format */
895 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
896 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
897 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
898 pResult
->filename
[0] = pResult
->filename
[1] = '.';
901 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
902 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
904 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
905 min( (p
- entry
.cAlternateFileName
), 8 ) );
906 memcpy( pResult
->filename
+ 8, p
+ 1, min( strlen(p
), 3 ) );
909 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
910 min( strlen(entry
.cAlternateFileName
), 8 ) );
916 static void DeleteFileFCB( CONTEXT86
*context
)
918 FIXME("(%p): stub\n", context
);
921 static void RenameFileFCB( CONTEXT86
*context
)
923 FIXME("(%p): stub\n", context
);
928 static void fLock( CONTEXT86
* context
)
931 switch ( AX_reg(context
) & 0xff )
933 case 0x00: /* LOCK */
934 TRACE("lock handle %d offset %ld length %ld\n",
936 MAKELONG(DX_reg(context
),CX_reg(context
)),
937 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
938 if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context
)),
939 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
940 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
941 SET_AX( context
, GetLastError() );
946 case 0x01: /* UNLOCK */
947 TRACE("unlock handle %d offset %ld length %ld\n",
949 MAKELONG(DX_reg(context
),CX_reg(context
)),
950 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
951 if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context
)),
952 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
953 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
954 SET_AX( context
, GetLastError() );
959 SET_AX( context
, 0x0001 );
966 INT21_networkfunc (CONTEXT86
*context
)
968 switch (AL_reg(context
)) {
969 case 0x00: /* Get machine name. */
971 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
972 TRACE("getting machine name to %p\n", dst
);
973 if (gethostname (dst
, 15))
976 SetLastError( ER_NoNetwork
);
979 int len
= strlen (dst
);
983 SET_CH( context
, 1 ); /* Valid */
984 SET_CL( context
, 1 ); /* NETbios number??? */
985 TRACE("returning %s\n", debugstr_an (dst
, 16));
991 SetLastError( ER_NoNetwork
);
997 static void ASPI_DOS_HandleInt( CONTEXT86
*context
)
999 if (!Dosvm
.ASPIHandler
&& !DPMI_LoadDosSystem())
1001 ERR("could not setup ASPI handler\n");
1004 Dosvm
.ASPIHandler( context
);
1007 /***********************************************************************
1008 * INT21_GetExtendedError
1010 static void INT21_GetExtendedError( CONTEXT86
*context
)
1012 BYTE
class, action
, locus
;
1013 WORD error
= GetLastError();
1018 class = action
= locus
= 0;
1020 case ERROR_DIR_NOT_EMPTY
:
1025 case ERROR_ACCESS_DENIED
:
1026 class = EC_AccessDenied
;
1030 case ERROR_CANNOT_MAKE
:
1031 class = EC_AccessDenied
;
1035 case ERROR_DISK_FULL
:
1036 case ERROR_HANDLE_DISK_FULL
:
1037 class = EC_MediaError
;
1041 case ERROR_FILE_EXISTS
:
1042 case ERROR_ALREADY_EXISTS
:
1047 case ERROR_FILE_NOT_FOUND
:
1048 class = EC_NotFound
;
1052 case ER_GeneralFailure
:
1053 class = EC_SystemFailure
;
1057 case ERROR_INVALID_DRIVE
:
1058 class = EC_MediaError
;
1062 case ERROR_INVALID_HANDLE
:
1063 class = EC_ProgramError
;
1067 case ERROR_LOCK_VIOLATION
:
1068 class = EC_AccessDenied
;
1072 case ERROR_NO_MORE_FILES
:
1073 class = EC_MediaError
;
1078 class = EC_NotFound
;
1082 case ERROR_NOT_ENOUGH_MEMORY
:
1083 class = EC_OutOfResource
;
1087 case ERROR_PATH_NOT_FOUND
:
1088 class = EC_NotFound
;
1093 class = EC_NotFound
;
1097 case ERROR_SHARING_VIOLATION
:
1098 class = EC_Temporary
;
1102 case ERROR_TOO_MANY_OPEN_FILES
:
1103 class = EC_ProgramError
;
1108 FIXME("Unknown error %d\n", error
);
1109 class = EC_SystemFailure
;
1114 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1115 error
, class, action
, locus
);
1116 SET_AX( context
, error
);
1117 SET_BH( context
, class );
1118 SET_BL( context
, action
);
1119 SET_CH( context
, locus
);
1122 /***********************************************************************
1123 * DOS3Call (KERNEL.102)
1124 * INT_Int21Handler (WPROCS.133)
1126 void WINAPI
DOS3Call( CONTEXT86
*context
)
1128 BOOL bSetDOSExtendedError
= FALSE
;
1131 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1132 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1133 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1134 SI_reg(context
), DI_reg(context
),
1135 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
1139 if (AH_reg(context
) == 0x59) /* Get extended error info */
1141 INT21_GetExtendedError( context
);
1145 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1147 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1148 /* no flush here yet */
1149 SET_AH( context
, AL_reg(context
) );
1152 if (AH_reg(context
)>=0x2f) {
1153 /* extended error is used by (at least) functions 0x2f to 0x62 */
1156 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1158 switch(AH_reg(context
))
1160 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1161 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1162 case 0x03: /* READ CHARACTER FROM STDAUX */
1163 case 0x04: /* WRITE CHARACTER TO STDAUX */
1164 case 0x05: /* WRITE CHARACTER TO PRINTER */
1165 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1166 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1167 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1168 case 0x0b: /* GET STDIN STATUS */
1169 case 0x0f: /* OPEN FILE USING FCB */
1170 case 0x10: /* CLOSE FILE USING FCB */
1171 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1172 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1173 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1174 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1175 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1176 case 0x23: /* GET FILE SIZE FOR FCB */
1177 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1178 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1179 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1180 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1181 case 0x4d: /* GET RETURN CODE */
1182 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1183 INT_BARF( context
, 0x21 );
1186 case 0x00: /* TERMINATE PROGRAM */
1187 TRACE("TERMINATE PROGRAM\n");
1191 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1192 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1193 context
->SegDs
,DX_reg(context
) );
1195 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
);
1197 /* do NOT use strchr() to calculate the string length,
1198 as '\0' is valid string content, too !
1199 Maybe we should check for non-'$' strings, but DOS doesn't. */
1200 while (*p
!= '$') p
++;
1201 _hwrite16( 1, data
, (int)p
- (int)data
);
1202 SET_AL( context
, '$' ); /* yes, '$' (0x24) gets returned in AL */
1206 case 0x0a: /* BUFFERED INPUT */
1208 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1212 TRACE("BUFFERED INPUT (size=%d)\n",buffer
[0]);
1214 TRACE("Handle old chars in buffer!\n");
1215 res
=_lread16( 0, buffer
+2,buffer
[0]);
1217 if(buffer
[res
+1] == '\n')
1218 buffer
[res
+1] = '\r';
1222 case 0x2e: /* SET VERIFY FLAG */
1223 TRACE("SET VERIFY FLAG ignored\n");
1224 /* we cannot change the behaviour anyway, so just ignore it */
1227 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1231 case 0x6b: /* NULL FUNCTION */
1232 SET_AL( context
, 0 );
1235 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1239 case 0x0d: /* DISK BUFFER FLUSH */
1240 TRACE("DISK BUFFER FLUSH ignored\n");
1241 RESET_CFLAG(context
); /* dos 6+ only */
1244 case 0x0e: /* SELECT DEFAULT DRIVE */
1245 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1246 DRIVE_SetCurrentDrive( DL_reg(context
) );
1247 SET_AL( context
, MAX_DOS_DRIVES
);
1250 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1251 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1252 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1253 if (!INT21_FindFirstFCB(context
))
1255 SET_AL( context
, 0xff );
1258 /* else fall through */
1260 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1261 SET_AL( context
, INT21_FindNextFCB(context
) ? 0x00 : 0xff );
1264 case 0x13: /* DELETE FILE USING FCB */
1265 DeleteFileFCB(context
);
1268 case 0x17: /* RENAME FILE USING FCB */
1269 RenameFileFCB(context
);
1272 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1273 SET_AL( context
, DRIVE_GetCurrentDrive() );
1276 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1278 TDB
*pTask
= TASK_GetCurrent();
1279 pTask
->dta
= MAKESEGPTR(context
->SegDs
,DX_reg(context
));
1280 TRACE("Set DTA: %08lx\n", pTask
->dta
);
1284 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1285 SET_DL( context
, 0 );
1286 if (!INT21_GetDriveAllocInfo(context
)) SET_AX( context
, 0xffff );
1289 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1290 if (!INT21_GetDriveAllocInfo(context
)) SET_AX( context
, 0xffff );
1293 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1294 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1297 case 0x25: /* SET INTERRUPT VECTOR */
1298 INT_SetPMHandler( AL_reg(context
), (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
)));
1301 case 0x29: /* PARSE FILENAME INTO FCB */
1302 INT21_ParseFileNameIntoFCB(context
);
1305 case 0x2a: /* GET SYSTEM DATE */
1306 INT21_GetSystemDate(context
);
1309 case 0x2b: /* SET SYSTEM DATE */
1310 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1311 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1312 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
1315 case 0x2c: /* GET SYSTEM TIME */
1316 INT21_GetSystemTime(context
);
1319 case 0x2d: /* SET SYSTEM TIME */
1320 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1321 CH_reg(context
), CL_reg(context
),
1322 DH_reg(context
), DL_reg(context
) );
1323 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
1326 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1327 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1329 TDB
*pTask
= TASK_GetCurrent();
1330 context
->SegEs
= SELECTOROF( pTask
->dta
);
1331 SET_BX( context
, OFFSETOF( pTask
->dta
) );
1335 case 0x30: /* GET DOS VERSION */
1336 TRACE("GET DOS VERSION %s requested\n",
1337 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1338 SET_AX( context
, (HIWORD(GetVersion16()) >> 8) | (HIWORD(GetVersion16()) << 8) );
1340 SET_AH( context
, 0x7 );
1341 SET_AL( context
, 0xA );
1344 SET_BX( context
, 0x00FF ); /* 0x123456 is Wine's serial # */
1345 SET_CX( context
, 0x0000 );
1348 case 0x31: /* TERMINATE AND STAY RESIDENT */
1349 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1352 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1353 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1354 INT21_DriveName( DL_reg(context
)));
1355 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1358 case 0x33: /* MULTIPLEXED */
1359 switch (AL_reg(context
))
1361 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1362 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1363 INT21_ReadConfigSys();
1364 SET_DL( context
, DOSCONF_config
.brk_flag
);
1367 case 0x01: /* SET EXTENDED BREAK STATE */
1368 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1369 INT21_ReadConfigSys();
1370 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1373 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1374 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1375 INT21_ReadConfigSys();
1376 /* ugly coding in order to stay reentrant */
1377 if (DL_reg(context
))
1379 SET_DL( context
, DOSCONF_config
.brk_flag
);
1380 DOSCONF_config
.brk_flag
= 1;
1384 SET_DL( context
, DOSCONF_config
.brk_flag
);
1385 DOSCONF_config
.brk_flag
= 0;
1389 case 0x05: /* GET BOOT DRIVE */
1390 TRACE("GET BOOT DRIVE\n");
1391 SET_DL( context
, 3 );
1392 /* c: is Wine's bootdrive (a: is 1)*/
1395 case 0x06: /* GET TRUE VERSION NUMBER */
1396 TRACE("GET TRUE VERSION NUMBER\n");
1397 SET_BX( context
, (HIWORD(GetVersion16() >> 8)) | (HIWORD(GetVersion16() << 8)) );
1398 SET_DX( context
, 0x00 );
1402 INT_BARF( context
, 0x21 );
1407 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1408 TRACE("GET ADDRESS OF INDOS FLAG\n");
1409 if (!heap
) INT21_CreateHeap();
1410 context
->SegEs
= DosHeapHandle
;
1411 SET_BX( context
, (int)&heap
->InDosFlag
- (int)heap
);
1414 case 0x35: /* GET INTERRUPT VECTOR */
1415 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1417 FARPROC16 addr
= INT_GetPMHandler( AL_reg(context
) );
1418 context
->SegEs
= SELECTOROF(addr
);
1419 SET_BX( context
, OFFSETOF(addr
) );
1423 case 0x36: /* GET FREE DISK SPACE */
1424 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1425 INT21_DriveName( DL_reg(context
)));
1426 if (!INT21_GetFreeDiskSpace(context
)) SET_AX( context
, 0xffff );
1431 unsigned char switchchar
='/';
1432 switch (AL_reg(context
))
1434 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1435 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1436 SET_AL( context
, 0x00 ); /* success*/
1437 SET_DL( context
, switchchar
);
1439 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1440 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1441 switchchar
= DL_reg(context
);
1442 SET_AL( context
, 0x00 ); /* success*/
1444 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1445 INT_BARF( context
, 0x21 );
1451 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1452 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1454 SET_AX( context
, 0x02 ); /* no country support available */
1458 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1460 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1461 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1462 context
->Edx
), NULL
));
1463 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1464 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1465 * denied), while CreateDirectory return several ones. remap some of
1468 if (bSetDOSExtendedError
) {
1469 switch (GetLastError()) {
1470 case ERROR_ALREADY_EXISTS
:
1471 case ERROR_FILENAME_EXCED_RANGE
:
1472 case ERROR_DISK_FULL
:
1473 SetLastError(ERROR_ACCESS_DENIED
);
1480 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1482 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1483 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1487 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1489 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1490 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1493 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1494 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context
),
1495 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1496 bSetDOSExtendedError
= INT21_CreateFile( context
);
1499 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1500 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context
),
1501 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1502 OpenExistingFile(context
);
1505 case 0x3e: /* "CLOSE" - CLOSE FILE */
1506 TRACE("CLOSE handle %d\n",BX_reg(context
));
1507 bSetDOSExtendedError
= ((SET_AX( context
, _lclose16( BX_reg(context
) )) != 0) );
1510 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1511 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1512 context
->SegDs
,DX_reg(context
),CX_reg(context
) );
1516 result
= _hread16( BX_reg(context
),
1517 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1521 result
= WIN16_hread( BX_reg(context
),
1522 MAKESEGPTR( context
->SegDs
, context
->Edx
),
1524 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1525 else SET_AX( context
, (WORD
)result
);
1529 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1530 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1531 context
->SegDs
,DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1533 LONG result
= _hwrite16( BX_reg(context
),
1534 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1537 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1538 else SET_AX( context
, (WORD
)result
);
1542 case 0x41: /* "UNLINK" - DELETE FILE */
1543 TRACE("UNLINK %s\n",
1544 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1545 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1549 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1550 TRACE("LSEEK handle %d offset %ld from %s\n",
1551 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1552 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1553 "current file position":"end of file");
1555 LONG status
= _llseek16( BX_reg(context
),
1556 MAKELONG(DX_reg(context
),CX_reg(context
)),
1558 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1561 SET_AX( context
, LOWORD(status
) );
1562 SET_DX( context
, HIWORD(status
) );
1567 case 0x43: /* FILE ATTRIBUTES */
1568 switch (AL_reg(context
))
1571 TRACE("GET FILE ATTRIBUTES for %s\n",
1572 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1573 SET_AX( context
, GetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1575 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1576 else SET_CX( context
, AX_reg(context
) );
1580 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1581 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1582 bSetDOSExtendedError
=
1583 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1588 FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1589 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1593 case 0x44: /* IOCTL */
1594 switch (AL_reg(context
))
1597 ioctlGetDeviceInfo(context
);
1603 const DOS_DEVICE
*dev
;
1604 static const WCHAR scsimgrW
[] = {'S','C','S','I','M','G','R','$',0};
1605 if ((dev
= DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context
)) )) &&
1606 !strcmpiW( dev
->name
, scsimgrW
))
1608 ASPI_DOS_HandleInt(context
);
1612 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1613 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
1614 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1616 FIXME("program tried to write to block device control channel of drive %d:\n",drive
);
1617 /* for (i=0;i<CX_reg(context);i++)
1618 fprintf(stdnimp,"%02x ",dataptr[i]);
1619 fprintf(stdnimp,"\n");*/
1620 SET_AX( context
, context
->Ecx
);
1623 case 0x08: /* Check if drive is removable. */
1624 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1625 INT21_DriveName( BL_reg(context
)));
1626 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1629 SetLastError( ERROR_INVALID_DRIVE
);
1630 SET_AX( context
, ERROR_INVALID_DRIVE
);
1633 case DRIVE_REMOVABLE
:
1634 SET_AX( context
, 0 ); /* removable */
1637 SET_AX( context
, 1 ); /* not removable */
1642 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1643 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1644 INT21_DriveName( BL_reg(context
)));
1645 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1648 SetLastError( ERROR_INVALID_DRIVE
);
1649 SET_AX( context
, ERROR_INVALID_DRIVE
);
1653 SET_DX( context
, (1<<9) | (1<<12) ); /* remote */
1656 SET_DX( context
, 0 ); /* FIXME: use driver attr here */
1661 case 0x0a: /* check if handle (BX) is remote */
1662 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1663 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1666 SET_DX( context
, 0 );
1670 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1671 INT21_DriveName( BL_reg(context
)));
1672 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1675 case 0x0e: /* get logical drive mapping */
1676 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1677 INT21_DriveName( BL_reg(context
)));
1678 SET_AL( context
, 0 ); /* drive has no mapping - FIXME: may be wrong*/
1681 case 0x0F: /* Set logical drive mapping */
1684 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1685 INT21_DriveName( BL_reg(context
)));
1686 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1687 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1690 SET_AX( context
, 0x000F ); /* invalid drive */
1695 case 0xe0: /* Sun PC-NFS API */
1699 case 0x52: /* DR-DOS version */
1700 /* This is not DR-DOS */
1702 TRACE("GET DR-DOS VERSION requested\n");
1704 SET_AX( context
, 0x0001 ); /* Invalid function */
1705 SET_CFLAG(context
); /* Error */
1706 SetLastError( ERROR_INVALID_FUNCTION
);
1710 INT_BARF( context
, 0x21 );
1715 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1718 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1719 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1720 DosFileHandleToWin32Handle(BX_reg(context
)),
1721 GetCurrentProcess(), &handle
,
1722 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1723 SET_AX( context
, HFILE_ERROR16
);
1725 SET_AX( context
, Win32HandleToDosFileHandle(handle
) );
1729 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1730 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1731 BX_reg(context
),CX_reg(context
));
1732 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1735 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1736 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1737 INT21_DriveName( DL_reg(context
)));
1738 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1741 case 0x48: /* ALLOCATE MEMORY */
1742 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1747 mem
= DOSMEM_GetBlock((DWORD
)BX_reg(context
)<<4,NULL
);
1749 SET_AX( context
, DOSMEM_MapLinearToDos(mem
)>>4 );
1753 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1755 SET_AX( context
, (DWORD
)mem
&0xffff );
1760 SET_AX( context
, 0x0008 ); /* insufficient memory */
1761 SET_BX( context
, DOSMEM_Available()>>4 );
1766 case 0x49: /* FREE MEMORY */
1767 TRACE("FREE MEMORY segment %04lX\n", context
->SegEs
);
1771 ret
= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(context
->SegEs
<<4));
1774 ret
= !GlobalDOSFree16(context
->SegEs
);
1775 /* If we don't reset ES_reg, we will fail in the relay code */
1780 TRACE("FREE MEMORY failed\n");
1782 SET_AX( context
, 0x0009 ); /* memory block address invalid */
1787 case 0x4a: /* RESIZE MEMORY BLOCK */
1788 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", context
->SegEs
, BX_reg(context
));
1789 if (!ISV86(context
))
1790 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1792 LPVOID
*mem
= DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(context
->SegEs
<<4),
1793 BX_reg(context
)<<4,NULL
);
1795 SET_AX( context
, DOSMEM_MapLinearToDos(mem
)>>4 );
1798 SET_AX( context
, 0x0008 ); /* insufficient memory */
1799 SET_BX( context
, DOSMEM_Available()>>4 ); /* not quite right */
1804 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1805 TRACE("EXEC %s\n", (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1806 SET_AX( context
, WinExec16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
),
1808 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1811 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1812 TRACE("EXIT with return code %d\n",AL_reg(context
));
1813 ExitThread( AL_reg(context
) );
1816 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1817 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1818 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1819 if (!INT21_FindFirst(context
)) break;
1822 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1823 TRACE("FINDNEXT\n");
1824 if (!INT21_FindNext(context
))
1826 SetLastError( ERROR_NO_MORE_FILES
);
1827 SET_AX( context
, ERROR_NO_MORE_FILES
);
1830 else SET_AX( context
, 0 ); /* OK */
1832 case 0x51: /* GET PSP ADDRESS */
1833 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1834 /* FIXME: should we return the original DOS PSP upon */
1835 /* Windows startup ? */
1836 SET_BX( context
, GetCurrentPDB16() );
1838 case 0x62: /* GET PSP ADDRESS */
1839 /* FIXME: should we return the original DOS PSP upon */
1840 /* Windows startup ? */
1841 SET_BX( context
, GetCurrentPDB16() );
1844 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1845 TRACE("SYSVARS - GET LIST OF LISTS\n");
1848 context
->SegEs
= LOWORD(DOS_LOLSeg
);
1849 SET_BX( context
, FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
) );
1852 FIXME("LOLSeg broken for now\n");
1854 SET_BX( context
, 0 );
1857 case 0x54: /* Get Verify Flag */
1858 TRACE("Get Verify Flag - Not Supported\n");
1859 SET_AL( context
, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
1862 case 0x56: /* "RENAME" - RENAME FILE */
1863 TRACE("RENAME %s to %s\n",
1864 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1865 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
));
1866 bSetDOSExtendedError
=
1867 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1868 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
)));
1871 case 0x57: /* FILE DATE AND TIME */
1872 switch (AL_reg(context
))
1874 case 0x00: /* Get */
1877 TRACE("GET FILE DATE AND TIME for handle %d\n",
1879 if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1880 bSetDOSExtendedError
= TRUE
;
1884 FileTimeToDosDateTime( &filetime
, &date
, &time
);
1885 SET_DX( context
, date
);
1886 SET_CX( context
, time
);
1891 case 0x01: /* Set */
1894 TRACE("SET FILE DATE AND TIME for handle %d\n",
1896 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1898 bSetDOSExtendedError
=
1899 (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context
)),
1900 NULL
, NULL
, &filetime
));
1906 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1907 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1909 switch (AL_reg(context
))
1912 SET_AX( context
, 1 );
1915 SET_AX( context
, 0 );
1921 RESET_CFLAG(context
);
1924 case 0x5a: /* CREATE TEMPORARY FILE */
1925 TRACE("CREATE TEMPORARY FILE\n");
1926 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1929 case 0x5b: /* CREATE NEW FILE */
1930 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1931 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1932 bSetDOSExtendedError
= ((SET_AX( context
,
1933 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1934 CX_reg(context
) ))) == (WORD
)HFILE_ERROR16
);
1937 case 0x5d: /* NETWORK */
1938 FIXME("Function 0x%04x not implemented.\n", AX_reg (context
));
1939 /* Fix the following while you're at it. */
1940 SetLastError( ER_NoNetwork
);
1941 bSetDOSExtendedError
= TRUE
;
1945 bSetDOSExtendedError
= INT21_networkfunc (context
);
1948 case 0x5f: /* NETWORK */
1949 switch (AL_reg(context
))
1951 case 0x07: /* ENABLE DRIVE */
1952 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1953 if (!DRIVE_Enable( DL_reg(context
) ))
1955 SetLastError( ERROR_INVALID_DRIVE
);
1956 bSetDOSExtendedError
= TRUE
;
1960 case 0x08: /* DISABLE DRIVE */
1961 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1962 if (!DRIVE_Disable( DL_reg(context
) ))
1964 SetLastError( ERROR_INVALID_DRIVE
);
1965 bSetDOSExtendedError
= TRUE
;
1970 /* network software not installed */
1971 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1972 SetLastError( ER_NoNetwork
);
1973 bSetDOSExtendedError
= TRUE
;
1978 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1979 TRACE("TRUENAME %s\n",
1980 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
1982 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1984 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
1985 context
->Edi
),NULL
))
1986 bSetDOSExtendedError
= TRUE
;
1987 else SET_AX( context
, 0 );
1991 case 0x61: /* UNUSED */
1992 case 0x63: /* misc. language support */
1993 switch (AL_reg(context
)) {
1994 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1995 INT21_GetDBCSLeadTable(context
);
1999 case 0x64: /* OS/2 DOS BOX */
2000 INT_BARF( context
, 0x21 );
2004 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2005 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
2006 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2007 BX_reg(context
), DX_reg(context
));
2008 switch (AL_reg(context
)) {
2010 TRACE("\tget general internationalization info\n");
2012 *(WORD
*)(dataptr
+1) = 41;
2013 *(WORD
*)(dataptr
+3) = GetSystemDefaultLangID();
2014 *(WORD
*)(dataptr
+5) = CodePage
;
2015 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
2018 TRACE("\tget pointer to collating sequence table\n");
2020 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
2021 SET_CX( context
, 258 );/*FIXME: size of table?*/
2024 TRACE("\tConvert char to uppercase\n");
2025 SET_DL( context
, toupper(DL_reg(context
)) );
2028 TRACE("\tconvert string to uppercase with length\n");
2030 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
);
2031 WORD len
= CX_reg(context
);
2032 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
2036 TRACE("\tConvert ASCIIZ string to uppercase\n");
2037 _strupr( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
) );
2040 TRACE("\tunimplemented function %d\n",AL_reg(context
));
2041 INT_BARF( context
, 0x21 );
2047 case 0x66: /* GLOBAL CODE PAGE TABLE */
2048 switch (AL_reg(context
))
2051 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2052 SET_BX( context
, CodePage
);
2053 SET_DX( context
, CodePage
);
2054 RESET_CFLAG(context
);
2057 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2058 BX_reg(context
),DX_reg(context
));
2059 CodePage
= BX_reg(context
);
2060 RESET_CFLAG(context
);
2065 case 0x67: /* SET HANDLE COUNT */
2066 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context
) );
2067 SetHandleCount16( BX_reg(context
) );
2068 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2071 case 0x68: /* "FFLUSH" - COMMIT FILE */
2072 case 0x6a: /* COMMIT FILE */
2073 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2074 bSetDOSExtendedError
= (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ));
2077 case 0x69: /* DISK SERIAL NUMBER */
2078 switch (AL_reg(context
))
2081 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2082 INT21_DriveName(BL_reg(context
)));
2083 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2084 else SET_AX( context
, 0 );
2088 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2089 INT21_DriveName(BL_reg(context
)));
2090 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2091 else SET_AX( context
, 1 );
2096 case 0x6C: /* Extended Open/Create*/
2097 TRACE("EXTENDED OPEN/CREATE %s\n",
2098 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edi
));
2099 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2102 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2103 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2104 /* not supported on anything but Win95 */
2105 TRACE("LONG FILENAME functions supported only by win95\n");
2107 SET_AL( context
, 0 );
2109 switch(AL_reg(context
))
2111 case 0x39: /* Create directory */
2112 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2113 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2114 bSetDOSExtendedError
= (!CreateDirectoryA(
2115 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2116 context
->Edx
), NULL
));
2117 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2118 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2119 * denied), while CreateDirectory return several ones. remap some of
2122 if (bSetDOSExtendedError
) {
2123 switch (GetLastError()) {
2124 case ERROR_ALREADY_EXISTS
:
2125 case ERROR_FILENAME_EXCED_RANGE
:
2126 case ERROR_DISK_FULL
:
2127 SetLastError(ERROR_ACCESS_DENIED
);
2133 case 0x3a: /* Remove directory */
2134 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2135 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2136 bSetDOSExtendedError
= (!RemoveDirectoryA(
2137 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2140 case 0x43: /* Get/Set file attributes */
2141 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2142 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2143 switch (BL_reg(context
))
2145 case 0x00: /* Get file attributes */
2146 TRACE("\tretrieve attributes\n");
2147 SET_CX( context
, GetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2149 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2152 TRACE("\tset attributes 0x%04x\n",CX_reg(context
));
2153 bSetDOSExtendedError
= (!SetFileAttributesA(
2154 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2156 CX_reg(context
) ) );
2159 FIXME("Unimplemented long file name function:\n");
2160 INT_BARF( context
, 0x21 );
2162 SET_AL( context
, 0 );
2166 case 0x47: /* Get current directory */
2167 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2168 INT21_DriveName(DL_reg(context
)));
2169 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2172 case 0x4e: /* Find first file */
2173 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2174 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2175 /* FIXME: use attributes in CX */
2176 if ((SET_AX( context
, FindFirstFile16(
2177 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
2178 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2180 == INVALID_HANDLE_VALUE16
)
2181 bSetDOSExtendedError
= TRUE
;
2183 case 0x4f: /* Find next file */
2184 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2186 if (!FindNextFile16( BX_reg(context
),
2187 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2189 bSetDOSExtendedError
= TRUE
;
2193 LPCSTR driveroot
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
2194 LPSTR buffer
= (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
2195 DWORD filename_len
, flags
;
2197 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot
);
2198 SET_AX( context
, 0 );
2199 if (!GetVolumeInformationA( driveroot
, NULL
, 0, NULL
, &filename_len
,
2200 &flags
, buffer
, 8 ))
2202 INT_BARF( context
, 0x21 );
2206 SET_BX( context
, flags
| 0x4000 ); /* support for LFN functions */
2207 SET_CX( context
, filename_len
);
2208 SET_DX( context
, MAX_PATH
); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2211 case 0xa1: /* Find close */
2212 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2214 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2217 switch(CL_reg(context
))
2219 case 0x01: /* Get short filename or path */
2220 if (!GetShortPathNameA
2221 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2223 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2225 bSetDOSExtendedError
= TRUE
;
2226 else SET_AX( context
, 0 );
2228 case 0x02: /* Get canonical long filename or path */
2229 if (!GetFullPathNameA
2230 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2232 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2233 context
->Edi
),NULL
))
2234 bSetDOSExtendedError
= TRUE
;
2235 else SET_AX( context
, 0 );
2238 FIXME("Unimplemented long file name function:\n");
2239 INT_BARF( context
, 0x21 );
2241 SET_AL( context
, 0 );
2245 case 0x6c: /* Create or open file */
2246 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2247 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
));
2248 /* translate Dos 7 action to Dos 6 action */
2249 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2252 case 0x3b: /* Change directory */
2253 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2254 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
2255 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2261 SET_AL( context
, GetLastError() );
2264 case 0x41: /* Delete file */
2265 TRACE("LONG FILENAME - DELETE FILE %s\n",
2266 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
2267 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2272 SET_AL( context
, GetLastError() );
2275 case 0x56: /* Move (rename) file */
2277 LPCSTR fn1
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2278 LPCSTR fn2
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
2279 TRACE("LONG FILENAME - RENAME FILE %s to %s\n", fn1
, fn2
);
2280 if (!MoveFileA(fn1
, fn2
))
2283 SET_AL( context
, GetLastError() );
2288 FIXME("Unimplemented long file name function:\n");
2289 INT_BARF( context
, 0x21 );
2291 SET_AL( context
, 0 );
2296 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2297 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2298 TRACE("windows95 function AX %04x\n",
2300 WARN(" returning unimplemented\n");
2302 SET_AL( context
, 0 );
2305 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2306 TRACE("windows95 function AX %04x\n",
2309 switch (AL_reg(context
))
2311 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
2312 /* ES:DI points to word with length of data (should be 0x3d) */
2316 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
2317 char root
[] = "A:\\";
2319 buffer
= (WORD
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
2321 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer
);
2323 /* validate passed-in buffer lengths */
2324 if ((*buffer
!= 0x3d) || (context
->Ecx
!= 0x3f))
2326 WARN("Get Extended DPB: buffer lengths incorrect\n");
2327 WARN("CX = %lx, buffer[0] = %x\n", context
->Ecx
, *buffer
);
2329 SET_AL( context
, 0x18 ); /* bad buffer length */
2332 /* buffer checks out */
2333 buffer
++; /* skip over length word now */
2334 if (FillInDrivePB( DX_reg(context
) ) )
2336 edpb
= (struct EDPB
*)buffer
;
2338 /* copy down the old-style DPB portion first */
2339 memcpy(&edpb
->dpb
, &heap
->dpb
, sizeof(struct DPB
));
2341 /* now fill in the extended entries */
2342 edpb
->edpb_flags
= 0;
2343 edpb
->next_edpb
= 0;
2344 edpb
->free_cluster
= edpb
->free_cluster2
= 0;
2346 /* determine free disk space */
2347 *root
+= DOS_GET_DRIVE( DX_reg(context
) );
2348 GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
2349 &free_clusters
, &total_clusters
);
2351 edpb
->clusters_free
= (free_clusters
&0xffff);
2353 edpb
->clusters_free_hi
= free_clusters
>> 16;
2354 edpb
->mirroring_flags
= 0;
2355 edpb
->info_sector
= 0xffff;
2356 edpb
->spare_boot_sector
= 0xffff;
2357 edpb
->first_cluster
= 0;
2358 edpb
->max_cluster
= total_clusters
;
2359 edpb
->fat_clusters
= 32; /* made-up value */
2360 edpb
->root_cluster
= 0;
2362 RESET_CFLAG(context
); /* clear carry */
2363 SET_AX( context
, 0 );
2367 SET_AX( context
, 0x00ff );
2373 case 0x03: /* Get Extended free space on drive */
2374 case 0x04: /* Set DPB for formatting */
2375 case 0x05: /* extended absolute disk read/write */
2376 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context
));
2378 SET_AL( context
, 0 );
2385 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2386 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2390 INT_BARF( context
, 0x21 );
2393 } /* END OF SWITCH */
2395 if( bSetDOSExtendedError
) /* set general error condition */
2397 SET_AX( context
, GetLastError() );
2401 if ((context
->EFlags
& 0x0001))
2402 TRACE("failed, error %ld\n", GetLastError() );
2404 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2405 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2406 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2407 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2408 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
2412 /***********************************************************************
2413 * GetSetKernelDOSProc (KERNEL.311)
2415 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2417 FIXME("(DosProc=0x%08x): stub\n", (UINT
)DosProc
);