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
32 #ifdef HAVE_SYS_FILE_H
33 # include <sys/file.h>
37 #include <sys/types.h>
45 #include "winuser.h" /* SW_NORMAL */
46 #include "wine/winbase16.h"
55 #include "wine/debug.h"
57 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
58 #if defined(__svr4__) || defined(_SCO_DS)
59 /* SVR4 DOESNT do locking the same way must implement properly */
66 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
68 /* Define the drive parameter block, as used by int21/1F
69 * and int21/32. This table can be accessed through the
70 * global 'dpb' pointer, which points into the local dos
75 BYTE drive_num
; /* 0=A, etc. */
76 BYTE unit_num
; /* Drive's unit number (?) */
77 WORD sector_size
; /* Sector size in bytes */
78 BYTE high_sector
; /* Highest sector in a cluster */
79 BYTE shift
; /* Shift count (?) */
80 WORD reserved
; /* Number of reserved sectors at start */
81 BYTE num_FAT
; /* Number of FATs */
82 WORD dir_entries
; /* Number of root dir entries */
83 WORD first_data
; /* First data sector */
84 WORD high_cluster
; /* Highest cluster number */
85 WORD sectors_in_FAT
; /* Number of sectors per FAT */
86 WORD start_dir
; /* Starting sector of first dir */
87 DWORD driver_head
; /* Address of device driver header (?) */
88 BYTE media_ID
; /* Media ID */
89 BYTE access_flag
; /* Prev. accessed flag (0=yes,0xFF=no) */
90 DWORD next
; /* Pointer to next DPB in list */
91 WORD free_search
; /* Free cluster search start */
92 WORD free_clusters
; /* Number of free clusters (0xFFFF=unknown) */
95 struct EDPB
/* FAT32 extended Drive Parameter Block */
96 { /* from Ralf Brown's Interrupt List */
97 struct DPB dpb
; /* first 24 bytes = original DPB */
99 BYTE edpb_flags
; /* undocumented/unknown flags */
100 DWORD next_edpb
; /* pointer to next EDPB */
101 WORD free_cluster
; /* cluster to start search for free space on write, typically
102 the last cluster allocated */
103 WORD clusters_free
; /* number of free clusters on drive or FFFF = unknown */
104 WORD clusters_free_hi
; /* hiword of clusters_free */
105 WORD mirroring_flags
; /* mirroring flags: bit 7 set = do not mirror active FAT */
106 /* bits 0-3 = 0-based number of the active FAT */
107 WORD info_sector
; /* sector number of file system info sector, or FFFF for none */
108 WORD spare_boot_sector
; /* sector number of backup boot sector, or FFFF for none */
109 DWORD first_cluster
; /* sector number of the first cluster */
110 DWORD max_cluster
; /* sector number of the last cluster */
111 DWORD fat_clusters
; /* number of clusters occupied by FAT */
112 DWORD root_cluster
; /* cluster number of start of root directory */
113 DWORD free_cluster2
; /* same as free_cluster: cluster at which to start
114 search for free space when writing */
126 BYTE DummyDBCSLeadTable
[6];
128 static struct DosHeap
*heap
;
129 static WORD DosHeapHandle
;
131 extern char TempDirectory
[];
133 static void INT21_ReadConfigSys(void)
136 if (!done
) DOSCONF_ReadConfig();
140 static BOOL
INT21_CreateHeap(void)
142 if (!(DosHeapHandle
= GlobalAlloc16(GMEM_FIXED
,sizeof(struct DosHeap
))))
144 WARN("Out of memory\n");
147 heap
= (struct DosHeap
*) GlobalLock16(DosHeapHandle
);
148 dpbsegptr
= MAKESEGPTR(DosHeapHandle
,(int)&heap
->dpb
-(int)heap
);
150 strcpy(heap
->biosdate
, "01/01/80");
151 memset(heap
->DummyDBCSLeadTable
, 0, 6);
155 static BYTE
*GetCurrentDTA( CONTEXT86
*context
)
157 TDB
*pTask
= TASK_GetCurrent();
159 /* FIXME: This assumes DTA was set correctly! */
160 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
161 (DWORD
)OFFSETOF(pTask
->dta
) );
165 void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
166 /* limited == TRUE is used with INT 0x21/0x440d */
171 setword(&data
[3], 0);
173 setword(&data
[6], 240);
174 setword(&data
[8], 64000);
176 setword(&data
[0x0b], 40);
177 setword(&data
[0x0d], 56);
178 setword(&data
[0x0f], 2);
179 setword(&data
[0x11], 0);
181 setword(&data
[0x1f], 800);
183 setword(&data
[0x22], 1);
185 } else { /* 1.44mb */
188 setword(&data
[3], 0);
190 setword(&data
[6], 240);
191 setword(&data
[8], 2880);
193 setword(&data
[0x0b], 6);
194 setword(&data
[0x0d], 18);
195 setword(&data
[0x0f], 2);
196 setword(&data
[0x11], 0);
198 setword(&data
[0x1f], 80);
200 setword(&data
[0x22], 2);
205 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
207 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
208 char root
[] = "A:\\";
210 *root
+= DOS_GET_DRIVE( DL_reg(context
) );
211 if (!GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
212 &free_clusters
, &total_clusters
)) return 0;
213 AX_reg(context
) = cluster_sectors
;
214 BX_reg(context
) = free_clusters
;
215 CX_reg(context
) = sector_bytes
;
216 DX_reg(context
) = total_clusters
;
220 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
)
222 if (!INT21_GetFreeDiskSpace( context
)) return 0;
223 if (!heap
&& !INT21_CreateHeap()) return 0;
224 heap
->mediaID
= 0xf0;
225 context
->SegDs
= DosHeapHandle
;
226 BX_reg(context
) = (int)&heap
->mediaID
- (int)heap
;
230 static int FillInDrivePB( int drive
)
232 if(!DRIVE_IsValid(drive
))
234 SetLastError( ERROR_INVALID_DRIVE
);
237 else if (heap
|| INT21_CreateHeap())
239 /* FIXME: I have no idea what a lot of this information should
240 * say or whether it even really matters since we're not allowing
241 * direct block access. However, some programs seem to depend on
242 * getting at least _something_ back from here. The 'next' pointer
243 * does worry me, though. Should we have a complete table of
244 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
246 heap
->dpb
.drive_num
= heap
->dpb
.unit_num
= drive
; /*The same?*/
247 heap
->dpb
.sector_size
= 512;
248 heap
->dpb
.high_sector
= 1;
249 heap
->dpb
.shift
= drive
< 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
250 heap
->dpb
.reserved
= 0;
251 heap
->dpb
.num_FAT
= 1;
252 heap
->dpb
.dir_entries
= 2;
253 heap
->dpb
.first_data
= 2;
254 heap
->dpb
.high_cluster
= 64000;
255 heap
->dpb
.sectors_in_FAT
= 1;
256 heap
->dpb
.start_dir
= 1;
257 heap
->dpb
.driver_head
= 0;
258 heap
->dpb
.media_ID
= (drive
> 1) ? 0xF8 : 0xF0;
259 heap
->dpb
.access_flag
= 0;
261 heap
->dpb
.free_search
= 0;
262 heap
->dpb
.free_clusters
= 0xFFFF; /* unknown */
269 static void GetDrivePB( CONTEXT86
*context
, int drive
)
271 if (FillInDrivePB( drive
))
273 AL_reg(context
) = 0x00;
274 context
->SegDs
= SELECTOROF(dpbsegptr
);
275 BX_reg(context
) = OFFSETOF(dpbsegptr
);
279 AX_reg(context
) = 0x00ff;
284 static void ioctlGetDeviceInfo( CONTEXT86
*context
)
287 const DOS_DEVICE
*dev
;
289 TRACE("(%d)\n", BX_reg(context
));
291 RESET_CFLAG(context
);
294 if ((dev
= DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context
)) )))
296 DX_reg(context
) = dev
->flags
;
300 /* it seems to be a file */
301 curr_drive
= DRIVE_GetCurrentDrive();
302 DX_reg(context
) = 0x0140 + curr_drive
+ ((curr_drive
> 1) ? 0x0800 : 0);
304 /* bits 0-5 are current drive
305 * bit 6 - file has NOT been written..FIXME: correct?
306 * bit 8 - generate int24 if no diskspace on write/ read past end of file
307 * bit 11 - media not removable
308 * bit 14 - don't set file date/time on closing
309 * bit 15 - file is remote
313 static BOOL
ioctlGenericBlkDevReq( CONTEXT86
*context
)
315 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
316 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
318 if (!DRIVE_IsValid(drive
))
320 SetLastError( ERROR_FILE_NOT_FOUND
);
324 if (CH_reg(context
) != 0x08)
326 INT_BARF( context
, 0x21 );
330 switch (CL_reg(context
))
332 case 0x4a: /* lock logical volume */
333 TRACE("lock logical volume (%d) level %d mode %d\n",drive
,BH_reg(context
),DX_reg(context
));
336 case 0x60: /* get device parameters */
337 /* used by w4wgrp's winfile */
338 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
340 dataptr
[6] = 0; /* media type */
343 dataptr
[1] = 0x05; /* fixed disk */
344 setword(&dataptr
[2], 0x01); /* non removable */
345 setword(&dataptr
[4], 0x300); /* # of cylinders */
349 dataptr
[1] = 0x07; /* block dev, floppy */
350 setword(&dataptr
[2], 0x02); /* removable */
351 setword(&dataptr
[4], 80); /* # of cylinders */
353 CreateBPB(drive
, &dataptr
[7], TRUE
);
354 RESET_CFLAG(context
);
357 case 0x41: /* write logical device track */
358 case 0x61: /* read logical device track */
360 BYTE drive
= BL_reg(context
) ?
361 BL_reg(context
) : DRIVE_GetCurrentDrive();
362 WORD head
= *(WORD
*)dataptr
+1;
363 WORD cyl
= *(WORD
*)dataptr
+3;
364 WORD sect
= *(WORD
*)dataptr
+5;
365 WORD nrsect
= *(WORD
*)dataptr
+7;
366 BYTE
*data
= (BYTE
*)dataptr
+9;
367 int (*raw_func
)(BYTE
, DWORD
, DWORD
, BYTE
*, BOOL
);
369 raw_func
= (CL_reg(context
) == 0x41) ?
370 DRIVE_RawWrite
: DRIVE_RawRead
;
372 if (raw_func(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
373 RESET_CFLAG(context
);
376 AX_reg(context
) = 0x1e; /* read fault */
381 case 0x66:/* get disk serial number */
383 char label
[12],fsname
[9],path
[4];
386 strcpy(path
,"x:\\");path
[0]=drive
+'A';
387 GetVolumeInformationA(
388 path
,label
,12,&serial
,NULL
,NULL
,fsname
,9
391 memcpy(dataptr
+2,&serial
,4);
392 memcpy(dataptr
+6,label
,11);
393 memcpy(dataptr
+17,fsname
,8);
398 TRACE("logical volume %d unlocked.\n",drive
);
402 memset(dataptr
+1, '\0', dataptr
[0]-1);
403 dataptr
[1] = dataptr
[0];
404 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
405 dataptr
[3] = 0xFF; /* no physical drive */
409 /* Trail on error implementation */
410 AX_reg(context
) = GetDriveType16(BL_reg(context
)) == DRIVE_UNKNOWN
? 0x0f : 0x01;
411 SET_CFLAG(context
); /* Seems to be set all the time */
415 INT_BARF( context
, 0x21 );
420 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
423 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
425 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
426 char *buffer
, *s
, *d
;
428 AL_reg(context
) = 0xff; /* failed */
430 TRACE("filename: '%s'\n", filename
);
432 buffer
= HeapAlloc( GetProcessHeap(), 0, strlen(filename
) + 1);
438 if ((*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
445 DOSFS_ToDosFCBFormat(buffer
, fcb
+ 1);
447 TRACE("FCB: '%s'\n", ((CHAR
*)fcb
+ 1));
449 HeapFree( GetProcessHeap(), 0, buffer
);
452 ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0;
454 /* point DS:SI to first unparsed character */
455 SI_reg(context
) += (int)s
- (int)filename
;
458 static void INT21_GetSystemDate( CONTEXT86
*context
)
461 GetLocalTime( &systime
);
462 CX_reg(context
) = systime
.wYear
;
463 DX_reg(context
) = (systime
.wMonth
<< 8) | systime
.wDay
;
464 AX_reg(context
) = systime
.wDayOfWeek
;
467 static void INT21_GetSystemTime( CONTEXT86
*context
)
470 GetLocalTime( &systime
);
471 CX_reg(context
) = (systime
.wHour
<< 8) | systime
.wMinute
;
472 DX_reg(context
) = (systime
.wSecond
<< 8) | (systime
.wMilliseconds
/ 10);
475 /* Many calls translate a drive argument like this:
476 drive number (00h = default, 01h = A:, etc)
478 static char drivestring
[]="default";
480 char *INT21_DriveName(int drive
)
485 drivestring
[0]= (unsigned char)drive
+ '@';
491 static BOOL
INT21_CreateFile( CONTEXT86
*context
)
493 AX_reg(context
) = _lcreat16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
494 context
->Edx
), CX_reg(context
) );
495 return (AX_reg(context
) == (WORD
)HFILE_ERROR16
);
498 static HFILE16
_lcreat16_uniq( LPCSTR path
, INT attr
)
500 /* Mask off all flags not explicitly allowed by the doc */
501 attr
&= FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
;
502 return Win32HandleToDosFileHandle( CreateFileA( path
, GENERIC_READ
| GENERIC_WRITE
,
503 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
504 CREATE_NEW
, attr
, 0 ));
507 static void OpenExistingFile( CONTEXT86
*context
)
509 AX_reg(context
) = _lopen16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
511 if (AX_reg(context
) == (WORD
)HFILE_ERROR16
)
513 AX_reg(context
) = GetLastError();
518 static BOOL
INT21_ExtendedOpenCreateFile(CONTEXT86
*context
)
520 BOOL bExtendedError
= FALSE
;
521 BYTE action
= DL_reg(context
);
523 /* Shuffle arguments to call OpenExistingFile */
524 AL_reg(context
) = BL_reg(context
);
525 DX_reg(context
) = SI_reg(context
);
526 /* BX,CX and DX should be preserved */
527 OpenExistingFile(context
);
529 if ((context
->EFlags
& 0x0001) == 0) /* File exists */
531 UINT16 uReturnCX
= 0;
533 /* Now decide what do do */
535 if ((action
& 0x07) == 0)
537 _lclose16( AX_reg(context
) );
538 AX_reg(context
) = 0x0050; /*File exists*/
540 WARN("extended open/create: failed because file exists \n");
542 else if ((action
& 0x07) == 2)
544 /* Truncate it, but first check if opened for write */
545 if ((BL_reg(context
) & 0x0007)== 0)
547 _lclose16( AX_reg(context
) );
548 WARN("extended open/create: failed, trunc on ro file\n");
549 AX_reg(context
) = 0x000C; /*Access code invalid*/
554 TRACE("extended open/create: Closing before truncate\n");
555 if (_lclose16( AX_reg(context
) ))
557 WARN("extended open/create: close before trunc failed\n");
558 AX_reg(context
) = 0x0019; /*Seek Error*/
562 /* Shuffle arguments to call CreateFile */
564 TRACE("extended open/create: Truncating\n");
565 AL_reg(context
) = BL_reg(context
);
566 /* CX is still the same */
567 DX_reg(context
) = SI_reg(context
);
568 bExtendedError
= INT21_CreateFile(context
);
570 if (context
->EFlags
& 0x0001) /*no file open, flags set */
572 WARN("extended open/create: trunc failed\n");
573 return bExtendedError
;
578 else uReturnCX
= 0x1;
580 CX_reg(context
) = uReturnCX
;
582 else /* file does not exist */
584 RESET_CFLAG(context
); /* was set by OpenExistingFile(context) */
585 if ((action
& 0xF0)== 0)
589 WARN("extended open/create: failed, file dosen't exist\n");
593 /* Shuffle arguments to call CreateFile */
594 TRACE("extended open/create: Creating\n");
595 AL_reg(context
) = BL_reg(context
);
596 /* CX should still be the same */
597 DX_reg(context
) = SI_reg(context
);
598 bExtendedError
= INT21_CreateFile(context
);
599 if (context
->EFlags
& 0x0001) /*no file open, flags set */
601 WARN("extended open/create: create failed\n");
602 return bExtendedError
;
608 return bExtendedError
;
612 static BOOL
INT21_ChangeDir( CONTEXT86
*context
)
615 char *dirname
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
617 TRACE("changedir %s\n", dirname
);
618 if (dirname
[0] && (dirname
[1] == ':'))
620 drive
= toupper(dirname
[0]) - 'A';
623 else drive
= DRIVE_GetCurrentDrive();
624 return DRIVE_Chdir( drive
, dirname
);
628 static int INT21_FindFirst( CONTEXT86
*context
)
632 DOS_FULL_NAME full_name
;
633 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
635 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
636 dta
->unixPath
= NULL
;
637 if (!DOSFS_GetFullName( path
, FALSE
, &full_name
))
639 AX_reg(context
) = GetLastError();
643 dta
->unixPath
= HeapAlloc( GetProcessHeap(), 0, strlen(full_name
.long_name
)+1 );
644 strcpy( dta
->unixPath
, full_name
.long_name
);
645 p
= strrchr( dta
->unixPath
, '/' );
648 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
649 * (doesn't matter as it is set below anyway)
651 if (!DOSFS_ToDosFCBFormat( p
+ 1, dta
->mask
))
653 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
654 dta
->unixPath
= NULL
;
655 SetLastError( ERROR_FILE_NOT_FOUND
);
656 AX_reg(context
) = ERROR_FILE_NOT_FOUND
;
660 dta
->drive
= (path
[0] && (path
[1] == ':')) ? toupper(path
[0]) - 'A'
661 : DRIVE_GetCurrentDrive();
663 dta
->search_attr
= CL_reg(context
);
668 static int INT21_FindNext( CONTEXT86
*context
)
670 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)GetCurrentDTA(context
);
671 WIN32_FIND_DATAA entry
;
674 if (!dta
->unixPath
) return 0;
675 if (!(count
= DOSFS_FindNext( dta
->unixPath
, dta
->mask
, NULL
, dta
->drive
,
676 dta
->search_attr
, dta
->count
, &entry
)))
678 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
679 dta
->unixPath
= NULL
;
682 if ((int)dta
->count
+ count
> 0xffff)
684 WARN("Too many directory entries in %s\n", dta
->unixPath
);
685 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
686 dta
->unixPath
= NULL
;
690 dta
->fileattr
= entry
.dwFileAttributes
;
691 dta
->filesize
= entry
.nFileSizeLow
;
692 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
693 &dta
->filedate
, &dta
->filetime
);
694 strcpy( dta
->filename
, entry
.cAlternateFileName
);
695 if (!memchr(dta
->mask
,'?',11)) {
696 /* wildcardless search, release resources in case no findnext will
697 * be issued, and as a workaround in case file creation messes up
698 * findnext, as sometimes happens with pkunzip */
699 HeapFree( GetProcessHeap(), 0, dta
->unixPath
);
700 dta
->unixPath
= NULL
;
706 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
708 static int counter
= 0;
709 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
710 char *p
= name
+ strlen(name
);
712 /* despite what Ralf Brown says, some programs seem to call without
713 * ending backslash (DOS accepts that, so we accept it too) */
714 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
718 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
719 counter
= (counter
+ 1) % 1000;
721 if ((AX_reg(context
) = _lcreat16_uniq( name
, 0 )) != (WORD
)HFILE_ERROR16
)
723 TRACE("created %s\n", name
);
726 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
731 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
)
733 int drive
= DOS_GET_DRIVE( DL_reg(context
) );
734 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
736 if (!DRIVE_IsValid(drive
))
738 SetLastError( ERROR_INVALID_DRIVE
);
741 lstrcpynA( ptr
, DRIVE_GetDosCwd(drive
), 64 );
742 AX_reg(context
) = 0x0100; /* success return code */
747 static void INT21_GetDBCSLeadTable( CONTEXT86
*context
)
749 if (heap
|| INT21_CreateHeap())
750 { /* return an empty table just as DOS 4.0+ does */
751 context
->SegDs
= DosHeapHandle
;
752 SI_reg(context
) = (int)&heap
->DummyDBCSLeadTable
- (int)heap
;
756 AX_reg(context
) = 0x1; /* error */
762 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
764 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
765 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
767 if (!DRIVE_IsValid(drive
))
769 SetLastError( ERROR_INVALID_DRIVE
);
773 *(WORD
*)dataptr
= 0;
774 *(DWORD
*)(dataptr
+ 2) = DRIVE_GetSerialNumber( drive
);
775 memcpy( dataptr
+ 6, DRIVE_GetLabel( drive
), 11 );
776 strncpy(dataptr
+ 0x11, "FAT16 ", 8);
781 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
783 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
784 int drive
= DOS_GET_DRIVE( BL_reg(context
) );
786 if (!DRIVE_IsValid(drive
))
788 SetLastError( ERROR_INVALID_DRIVE
);
792 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
797 /* microsoft's programmers should be shot for using CP/M style int21
798 calls in Windows for Workgroup's winfile.exe */
800 static int INT21_FindFirstFCB( CONTEXT86
*context
)
802 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
807 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
808 else pFCB
= (FINDFILE_FCB
*)fcb
;
809 drive
= DOS_GET_DRIVE( pFCB
->drive
);
810 if (!DRIVE_IsValid( drive
)) return 0;
811 root
= DRIVE_GetRoot( drive
);
812 cwd
= DRIVE_GetUnixCwd( drive
);
813 pFCB
->unixPath
= HeapAlloc( GetProcessHeap(), 0,
814 strlen(root
)+strlen(cwd
)+2 );
815 if (!pFCB
->unixPath
) return 0;
816 strcpy( pFCB
->unixPath
, root
);
817 strcat( pFCB
->unixPath
, "/" );
818 strcat( pFCB
->unixPath
, cwd
);
824 static int INT21_FindNextFCB( CONTEXT86
*context
)
826 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
828 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)GetCurrentDTA(context
);
829 WIN32_FIND_DATAA entry
;
833 if (*fcb
== 0xff) /* extended FCB ? */
836 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
841 pFCB
= (FINDFILE_FCB
*)fcb
;
844 if (!pFCB
->unixPath
) return 0;
845 if (!(count
= DOSFS_FindNext( pFCB
->unixPath
, pFCB
->filename
, NULL
,
846 DOS_GET_DRIVE( pFCB
->drive
), attr
,
847 pFCB
->count
, &entry
)))
849 HeapFree( GetProcessHeap(), 0, pFCB
->unixPath
);
850 pFCB
->unixPath
= NULL
;
853 pFCB
->count
+= count
;
855 if (*fcb
== 0xff) { /* place extended FCB header before pResult if called with extended FCB */
856 *(BYTE
*)pResult
= 0xff;
857 (BYTE
*)pResult
+=6; /* leave reserved field behind */
858 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
861 *(BYTE
*)pResult
= DOS_GET_DRIVE( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
863 pResult
->fileattr
= entry
.dwFileAttributes
;
864 pResult
->cluster
= 0; /* what else? */
865 pResult
->filesize
= entry
.nFileSizeLow
;
866 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
867 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
868 &pResult
->filedate
, &pResult
->filetime
);
870 /* Convert file name to FCB format */
872 memset( pResult
->filename
, ' ', sizeof(pResult
->filename
) );
873 if (!strcmp( entry
.cAlternateFileName
, "." )) pResult
->filename
[0] = '.';
874 else if (!strcmp( entry
.cAlternateFileName
, ".." ))
875 pResult
->filename
[0] = pResult
->filename
[1] = '.';
878 char *p
= strrchr( entry
.cAlternateFileName
, '.' );
879 if (p
&& p
[1] && (p
!= entry
.cAlternateFileName
))
881 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
882 min( (p
- entry
.cAlternateFileName
), 8 ) );
883 memcpy( pResult
->filename
+ 8, p
+ 1, min( strlen(p
), 3 ) );
886 memcpy( pResult
->filename
, entry
.cAlternateFileName
,
887 min( strlen(entry
.cAlternateFileName
), 8 ) );
893 static void DeleteFileFCB( CONTEXT86
*context
)
895 FIXME("(%p): stub\n", context
);
898 static void RenameFileFCB( CONTEXT86
*context
)
900 FIXME("(%p): stub\n", context
);
905 static void fLock( CONTEXT86
* context
)
908 switch ( AX_reg(context
) & 0xff )
910 case 0x00: /* LOCK */
911 TRACE("lock handle %d offset %ld length %ld\n",
913 MAKELONG(DX_reg(context
),CX_reg(context
)),
914 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
915 if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context
)),
916 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
917 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
918 AX_reg(context
) = GetLastError();
923 case 0x01: /* UNLOCK */
924 TRACE("unlock handle %d offset %ld length %ld\n",
926 MAKELONG(DX_reg(context
),CX_reg(context
)),
927 MAKELONG(DI_reg(context
),SI_reg(context
))) ;
928 if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context
)),
929 MAKELONG(DX_reg(context
),CX_reg(context
)), 0,
930 MAKELONG(DI_reg(context
),SI_reg(context
)), 0)) {
931 AX_reg(context
) = GetLastError();
936 AX_reg(context
) = 0x0001;
943 INT21_networkfunc (CONTEXT86
*context
)
945 switch (AL_reg(context
)) {
946 case 0x00: /* Get machine name. */
948 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
949 TRACE("getting machine name to %p\n", dst
);
950 if (gethostname (dst
, 15))
953 SetLastError( ER_NoNetwork
);
956 int len
= strlen (dst
);
960 CH_reg(context
) = 1; /* Valid */
961 CL_reg(context
) = 1; /* NETbios number??? */
962 TRACE("returning %s\n", debugstr_an (dst
, 16));
968 SetLastError( ER_NoNetwork
);
974 static void ASPI_DOS_HandleInt( CONTEXT86
*context
)
976 if (!Dosvm
.ASPIHandler
&& !DPMI_LoadDosSystem())
978 ERR("could not setup ASPI handler\n");
981 Dosvm
.ASPIHandler( context
);
984 /***********************************************************************
985 * INT21_GetExtendedError
987 static void INT21_GetExtendedError( CONTEXT86
*context
)
989 BYTE
class, action
, locus
;
990 WORD error
= GetLastError();
995 class = action
= locus
= 0;
997 case ERROR_DIR_NOT_EMPTY
:
1002 case ERROR_ACCESS_DENIED
:
1003 class = EC_AccessDenied
;
1007 case ERROR_CANNOT_MAKE
:
1008 class = EC_AccessDenied
;
1012 case ERROR_DISK_FULL
:
1013 case ERROR_HANDLE_DISK_FULL
:
1014 class = EC_MediaError
;
1018 case ERROR_FILE_EXISTS
:
1019 case ERROR_ALREADY_EXISTS
:
1024 case ERROR_FILE_NOT_FOUND
:
1025 class = EC_NotFound
;
1029 case ER_GeneralFailure
:
1030 class = EC_SystemFailure
;
1034 case ERROR_INVALID_DRIVE
:
1035 class = EC_MediaError
;
1039 case ERROR_INVALID_HANDLE
:
1040 class = EC_ProgramError
;
1044 case ERROR_LOCK_VIOLATION
:
1045 class = EC_AccessDenied
;
1049 case ERROR_NO_MORE_FILES
:
1050 class = EC_MediaError
;
1055 class = EC_NotFound
;
1059 case ERROR_NOT_ENOUGH_MEMORY
:
1060 class = EC_OutOfResource
;
1064 case ERROR_PATH_NOT_FOUND
:
1065 class = EC_NotFound
;
1070 class = EC_NotFound
;
1074 case ERROR_SHARING_VIOLATION
:
1075 class = EC_Temporary
;
1079 case ERROR_TOO_MANY_OPEN_FILES
:
1080 class = EC_ProgramError
;
1085 FIXME("Unknown error %d\n", error
);
1086 class = EC_SystemFailure
;
1091 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1092 error
, class, action
, locus
);
1093 AX_reg(context
) = error
;
1094 BH_reg(context
) = class;
1095 BL_reg(context
) = action
;
1096 CH_reg(context
) = locus
;
1099 /***********************************************************************
1100 * DOS3Call (KERNEL.102)
1101 * INT_Int21Handler (WPROCS.133)
1103 void WINAPI
DOS3Call( CONTEXT86
*context
)
1105 BOOL bSetDOSExtendedError
= FALSE
;
1108 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1109 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1110 AX_reg(context
), BX_reg(context
), CX_reg(context
), DX_reg(context
),
1111 SI_reg(context
), DI_reg(context
),
1112 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
1116 if (AH_reg(context
) == 0x59) /* Get extended error info */
1118 INT21_GetExtendedError( context
);
1122 if (AH_reg(context
) == 0x0C) /* Flush buffer and read standard input */
1124 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1125 /* no flush here yet */
1126 AH_reg(context
) = AL_reg(context
);
1129 if (AH_reg(context
)>=0x2f) {
1130 /* extended error is used by (at least) functions 0x2f to 0x62 */
1133 RESET_CFLAG(context
); /* Not sure if this is a good idea */
1135 switch(AH_reg(context
))
1137 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1138 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1139 case 0x03: /* READ CHARACTER FROM STDAUX */
1140 case 0x04: /* WRITE CHARACTER TO STDAUX */
1141 case 0x05: /* WRITE CHARACTER TO PRINTER */
1142 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1143 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1144 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1145 case 0x0b: /* GET STDIN STATUS */
1146 case 0x0f: /* OPEN FILE USING FCB */
1147 case 0x10: /* CLOSE FILE USING FCB */
1148 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1149 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1150 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1151 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1152 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1153 case 0x23: /* GET FILE SIZE FOR FCB */
1154 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1155 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1156 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1157 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1158 case 0x4d: /* GET RETURN CODE */
1159 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1160 INT_BARF( context
, 0x21 );
1163 case 0x00: /* TERMINATE PROGRAM */
1164 TRACE("TERMINATE PROGRAM\n");
1168 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1169 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1170 context
->SegDs
,DX_reg(context
) );
1172 LPSTR data
= CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
);
1174 /* do NOT use strchr() to calculate the string length,
1175 as '\0' is valid string content, too !
1176 Maybe we should check for non-'$' strings, but DOS doesn't. */
1177 while (*p
!= '$') p
++;
1178 _hwrite16( 1, data
, (int)p
- (int)data
);
1179 AL_reg(context
) = '$'; /* yes, '$' (0x24) gets returned in AL */
1183 case 0x0a: /* BUFFERED INPUT */
1185 char *buffer
= ((char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1189 TRACE("BUFFERED INPUT (size=%d)\n",buffer
[0]);
1191 TRACE("Handle old chars in buffer!\n");
1192 res
=_lread16( 0, buffer
+2,buffer
[0]);
1194 if(buffer
[res
+1] == '\n')
1195 buffer
[res
+1] = '\r';
1199 case 0x2e: /* SET VERIFY FLAG */
1200 TRACE("SET VERIFY FLAG ignored\n");
1201 /* we cannot change the behaviour anyway, so just ignore it */
1204 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1208 case 0x6b: /* NULL FUNCTION */
1209 AL_reg(context
) = 0;
1212 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1216 case 0x0d: /* DISK BUFFER FLUSH */
1217 TRACE("DISK BUFFER FLUSH ignored\n");
1218 RESET_CFLAG(context
); /* dos 6+ only */
1221 case 0x0e: /* SELECT DEFAULT DRIVE */
1222 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context
));
1223 DRIVE_SetCurrentDrive( DL_reg(context
) );
1224 AL_reg(context
) = MAX_DOS_DRIVES
;
1227 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1228 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1229 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1230 if (!INT21_FindFirstFCB(context
))
1232 AL_reg(context
) = 0xff;
1235 /* else fall through */
1237 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1238 AL_reg(context
) = INT21_FindNextFCB(context
) ? 0x00 : 0xff;
1241 case 0x13: /* DELETE FILE USING FCB */
1242 DeleteFileFCB(context
);
1245 case 0x17: /* RENAME FILE USING FCB */
1246 RenameFileFCB(context
);
1249 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1250 AL_reg(context
) = DRIVE_GetCurrentDrive();
1253 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1255 TDB
*pTask
= TASK_GetCurrent();
1256 pTask
->dta
= MAKESEGPTR(context
->SegDs
,DX_reg(context
));
1257 TRACE("Set DTA: %08lx\n", pTask
->dta
);
1261 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1262 DL_reg(context
) = 0;
1263 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1266 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1267 if (!INT21_GetDriveAllocInfo(context
)) AX_reg(context
) = 0xffff;
1270 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1271 GetDrivePB(context
, DRIVE_GetCurrentDrive());
1274 case 0x25: /* SET INTERRUPT VECTOR */
1275 INT_SetPMHandler( AL_reg(context
), (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
)));
1278 case 0x29: /* PARSE FILENAME INTO FCB */
1279 INT21_ParseFileNameIntoFCB(context
);
1282 case 0x2a: /* GET SYSTEM DATE */
1283 INT21_GetSystemDate(context
);
1286 case 0x2b: /* SET SYSTEM DATE */
1287 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1288 DL_reg(context
), DH_reg(context
), CX_reg(context
) );
1289 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1292 case 0x2c: /* GET SYSTEM TIME */
1293 INT21_GetSystemTime(context
);
1296 case 0x2d: /* SET SYSTEM TIME */
1297 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1298 CH_reg(context
), CL_reg(context
),
1299 DH_reg(context
), DL_reg(context
) );
1300 AL_reg(context
) = 0; /* Let's pretend we succeeded */
1303 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1304 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1306 TDB
*pTask
= TASK_GetCurrent();
1307 context
->SegEs
= SELECTOROF( pTask
->dta
);
1308 BX_reg(context
) = OFFSETOF( pTask
->dta
);
1312 case 0x30: /* GET DOS VERSION */
1313 TRACE("GET DOS VERSION %s requested\n",
1314 (AL_reg(context
) == 0x00)?"OEM number":"version flag");
1315 AX_reg(context
) = (HIWORD(GetVersion16()) >> 8) |
1316 (HIWORD(GetVersion16()) << 8);
1318 AH_reg(context
) = 0x7;
1319 AL_reg(context
) = 0xA;
1322 BX_reg(context
) = 0x00FF; /* 0x123456 is Wine's serial # */
1323 CX_reg(context
) = 0x0000;
1326 case 0x31: /* TERMINATE AND STAY RESIDENT */
1327 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1330 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1331 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1332 INT21_DriveName( DL_reg(context
)));
1333 GetDrivePB(context
, DOS_GET_DRIVE( DL_reg(context
) ) );
1336 case 0x33: /* MULTIPLEXED */
1337 switch (AL_reg(context
))
1339 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1340 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1341 INT21_ReadConfigSys();
1342 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1345 case 0x01: /* SET EXTENDED BREAK STATE */
1346 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1347 INT21_ReadConfigSys();
1348 DOSCONF_config
.brk_flag
= (DL_reg(context
) > 0);
1351 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1352 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1353 INT21_ReadConfigSys();
1354 /* ugly coding in order to stay reentrant */
1355 if (DL_reg(context
))
1357 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1358 DOSCONF_config
.brk_flag
= 1;
1362 DL_reg(context
) = DOSCONF_config
.brk_flag
;
1363 DOSCONF_config
.brk_flag
= 0;
1367 case 0x05: /* GET BOOT DRIVE */
1368 TRACE("GET BOOT DRIVE\n");
1369 DL_reg(context
) = 3;
1370 /* c: is Wine's bootdrive (a: is 1)*/
1373 case 0x06: /* GET TRUE VERSION NUMBER */
1374 TRACE("GET TRUE VERSION NUMBER\n");
1375 BX_reg(context
) = (HIWORD(GetVersion16() >> 8)) |
1376 (HIWORD(GetVersion16() << 8));
1377 DX_reg(context
) = 0x00;
1381 INT_BARF( context
, 0x21 );
1386 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1387 TRACE("GET ADDRESS OF INDOS FLAG\n");
1388 if (!heap
) INT21_CreateHeap();
1389 context
->SegEs
= DosHeapHandle
;
1390 BX_reg(context
) = (int)&heap
->InDosFlag
- (int)heap
;
1393 case 0x35: /* GET INTERRUPT VECTOR */
1394 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
1396 FARPROC16 addr
= INT_GetPMHandler( AL_reg(context
) );
1397 context
->SegEs
= SELECTOROF(addr
);
1398 BX_reg(context
) = OFFSETOF(addr
);
1402 case 0x36: /* GET FREE DISK SPACE */
1403 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1404 INT21_DriveName( DL_reg(context
)));
1405 if (!INT21_GetFreeDiskSpace(context
)) AX_reg(context
) = 0xffff;
1410 unsigned char switchchar
='/';
1411 switch (AL_reg(context
))
1413 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1414 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1415 AL_reg(context
) = 0x00; /* success*/
1416 DL_reg(context
) = switchchar
;
1418 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1419 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1420 switchchar
= DL_reg(context
);
1421 AL_reg(context
) = 0x00; /* success*/
1423 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1424 INT_BARF( context
, 0x21 );
1430 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1431 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1433 AX_reg(context
) = 0x02; /* no country support available */
1437 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1439 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1440 bSetDOSExtendedError
= (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1441 context
->Edx
), NULL
));
1442 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1443 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1444 * denied), while CreateDirectory return several ones. remap some of
1447 if (bSetDOSExtendedError
) {
1448 switch (GetLastError()) {
1449 case ERROR_ALREADY_EXISTS
:
1450 case ERROR_FILENAME_EXCED_RANGE
:
1451 case ERROR_DISK_FULL
:
1452 SetLastError(ERROR_ACCESS_DENIED
);
1459 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1461 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1462 bSetDOSExtendedError
= (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1466 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1468 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1469 bSetDOSExtendedError
= !INT21_ChangeDir(context
);
1472 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1473 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context
),
1474 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1475 bSetDOSExtendedError
= INT21_CreateFile( context
);
1478 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1479 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context
),
1480 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1481 OpenExistingFile(context
);
1484 case 0x3e: /* "CLOSE" - CLOSE FILE */
1485 TRACE("CLOSE handle %d\n",BX_reg(context
));
1486 bSetDOSExtendedError
= ((AX_reg(context
) = _lclose16( BX_reg(context
) )) != 0);
1489 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1490 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context
),
1491 context
->SegDs
,DX_reg(context
),CX_reg(context
) );
1495 result
= _hread16( BX_reg(context
),
1496 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1500 result
= WIN16_hread( BX_reg(context
),
1501 MAKESEGPTR( context
->SegDs
, context
->Edx
),
1503 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1504 else AX_reg(context
) = (WORD
)result
;
1508 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1509 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1510 context
->SegDs
,DX_reg(context
),BX_reg(context
),CX_reg(context
) );
1512 LONG result
= _hwrite16( BX_reg(context
),
1513 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1516 if (result
== -1) bSetDOSExtendedError
= TRUE
;
1517 else AX_reg(context
) = (WORD
)result
;
1521 case 0x41: /* "UNLINK" - DELETE FILE */
1522 TRACE("UNLINK %s\n",
1523 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1524 bSetDOSExtendedError
= (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1528 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1529 TRACE("LSEEK handle %d offset %ld from %s\n",
1530 BX_reg(context
), MAKELONG(DX_reg(context
),CX_reg(context
)),
1531 (AL_reg(context
)==0)?"start of file":(AL_reg(context
)==1)?
1532 "current file position":"end of file");
1534 LONG status
= _llseek16( BX_reg(context
),
1535 MAKELONG(DX_reg(context
),CX_reg(context
)),
1537 if (status
== -1) bSetDOSExtendedError
= TRUE
;
1540 AX_reg(context
) = LOWORD(status
);
1541 DX_reg(context
) = HIWORD(status
);
1546 case 0x43: /* FILE ATTRIBUTES */
1547 switch (AL_reg(context
))
1550 TRACE("GET FILE ATTRIBUTES for %s\n",
1551 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1552 AX_reg(context
) = (WORD
)GetFileAttributesA(
1553 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1555 if (AX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
1556 else CX_reg(context
) = AX_reg(context
);
1560 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context
),
1561 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1562 bSetDOSExtendedError
=
1563 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1568 FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1569 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1573 case 0x44: /* IOCTL */
1574 switch (AL_reg(context
))
1577 ioctlGetDeviceInfo(context
);
1583 const DOS_DEVICE
*dev
;
1584 if ((dev
= DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context
)) )) &&
1585 !strcasecmp( dev
->name
, "SCSIMGR$" ))
1587 ASPI_DOS_HandleInt(context
);
1591 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1592 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
1593 int drive
= DOS_GET_DRIVE(BL_reg(context
));
1595 FIXME("program tried to write to block device control channel of drive %d:\n",drive
);
1596 /* for (i=0;i<CX_reg(context);i++)
1597 fprintf(stdnimp,"%02x ",dataptr[i]);
1598 fprintf(stdnimp,"\n");*/
1599 AX_reg(context
)=CX_reg(context
);
1602 case 0x08: /* Check if drive is removable. */
1603 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1604 INT21_DriveName( BL_reg(context
)));
1605 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1608 SetLastError( ERROR_INVALID_DRIVE
);
1609 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1612 case DRIVE_REMOVABLE
:
1613 AX_reg(context
) = 0; /* removable */
1616 AX_reg(context
) = 1; /* not removable */
1621 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1622 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1623 INT21_DriveName( BL_reg(context
)));
1624 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context
) )))
1627 SetLastError( ERROR_INVALID_DRIVE
);
1628 AX_reg(context
) = ERROR_INVALID_DRIVE
;
1632 DX_reg(context
) = (1<<9) | (1<<12); /* remote */
1635 DX_reg(context
) = 0; /* FIXME: use driver attr here */
1640 case 0x0a: /* check if handle (BX) is remote */
1641 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context
));
1642 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1645 DX_reg(context
) = 0;
1649 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1650 INT21_DriveName( BL_reg(context
)));
1651 bSetDOSExtendedError
= ioctlGenericBlkDevReq(context
);
1654 case 0x0e: /* get logical drive mapping */
1655 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1656 INT21_DriveName( BL_reg(context
)));
1657 AL_reg(context
) = 0; /* drive has no mapping - FIXME: may be wrong*/
1660 case 0x0F: /* Set logical drive mapping */
1663 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1664 INT21_DriveName( BL_reg(context
)));
1665 drive
= DOS_GET_DRIVE ( BL_reg(context
) );
1666 if ( ! DRIVE_SetLogicalMapping ( drive
, drive
+1 ) )
1669 AX_reg(context
) = 0x000F; /* invalid drive */
1674 case 0xe0: /* Sun PC-NFS API */
1678 case 0x52: /* DR-DOS version */
1679 /* This is not DR-DOS */
1681 TRACE("GET DR-DOS VERSION requested\n");
1683 AX_reg(context
) = 0x0001; /* Invalid function */
1684 SET_CFLAG(context
); /* Error */
1685 SetLastError( ERROR_INVALID_FUNCTION
);
1689 INT_BARF( context
, 0x21 );
1694 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1697 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context
));
1698 if ((bSetDOSExtendedError
= !DuplicateHandle( GetCurrentProcess(),
1699 DosFileHandleToWin32Handle(BX_reg(context
)),
1700 GetCurrentProcess(), &handle
,
1701 0, TRUE
, DUPLICATE_SAME_ACCESS
)))
1702 AX_reg(context
) = HFILE_ERROR16
;
1704 AX_reg(context
) = Win32HandleToDosFileHandle(handle
);
1708 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1709 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1710 BX_reg(context
),CX_reg(context
));
1711 bSetDOSExtendedError
= (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
);
1714 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1715 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1716 INT21_DriveName( DL_reg(context
)));
1717 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
1720 case 0x48: /* ALLOCATE MEMORY */
1721 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
));
1726 mem
= DOSMEM_GetBlock((DWORD
)BX_reg(context
)<<4,NULL
);
1728 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1732 mem
= (LPVOID
)GlobalDOSAlloc16(BX_reg(context
)<<4);
1734 AX_reg(context
) = (DWORD
)mem
&0xffff;
1739 AX_reg(context
) = 0x0008; /* insufficient memory */
1740 BX_reg(context
) = DOSMEM_Available()>>4;
1745 case 0x49: /* FREE MEMORY */
1746 TRACE("FREE MEMORY segment %04lX\n", context
->SegEs
);
1750 ret
= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(context
->SegEs
<<4));
1753 ret
= !GlobalDOSFree16(context
->SegEs
);
1754 /* If we don't reset ES_reg, we will fail in the relay code */
1759 TRACE("FREE MEMORY failed\n");
1761 AX_reg(context
) = 0x0009; /* memory block address invalid */
1766 case 0x4a: /* RESIZE MEMORY BLOCK */
1767 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", context
->SegEs
, BX_reg(context
));
1768 if (!ISV86(context
))
1769 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1771 LPVOID
*mem
= DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(context
->SegEs
<<4),
1772 BX_reg(context
)<<4,NULL
);
1774 AX_reg(context
) = DOSMEM_MapLinearToDos(mem
)>>4;
1777 AX_reg(context
) = 0x0008; /* insufficient memory */
1778 BX_reg(context
) = DOSMEM_Available()>>4; /* not quite right */
1783 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1784 TRACE("EXEC %s\n", (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1785 AX_reg(context
) = WinExec16( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
),
1787 if (AX_reg(context
) < 32) SET_CFLAG(context
);
1790 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1791 TRACE("EXIT with return code %d\n",AL_reg(context
));
1792 ExitThread( AL_reg(context
) );
1795 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1796 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
1797 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1798 if (!INT21_FindFirst(context
)) break;
1801 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1802 TRACE("FINDNEXT\n");
1803 if (!INT21_FindNext(context
))
1805 SetLastError( ERROR_NO_MORE_FILES
);
1806 AX_reg(context
) = ERROR_NO_MORE_FILES
;
1809 else AX_reg(context
) = 0; /* OK */
1811 case 0x51: /* GET PSP ADDRESS */
1812 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1813 /* FIXME: should we return the original DOS PSP upon */
1814 /* Windows startup ? */
1815 BX_reg(context
) = GetCurrentPDB16();
1817 case 0x62: /* GET PSP ADDRESS */
1818 /* FIXME: should we return the original DOS PSP upon */
1819 /* Windows startup ? */
1820 BX_reg(context
) = GetCurrentPDB16();
1823 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1824 TRACE("SYSVARS - GET LIST OF LISTS\n");
1826 context
->SegEs
= LOWORD(DOS_LOLSeg
);
1827 BX_reg(context
) = FIELD_OFFSET(DOS_LISTOFLISTS
, ptr_first_DPB
);
1831 case 0x54: /* Get Verify Flag */
1832 TRACE("Get Verify Flag - Not Supported\n");
1833 AL_reg(context
) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1836 case 0x56: /* "RENAME" - RENAME FILE */
1837 TRACE("RENAME %s to %s\n",
1838 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1839 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
));
1840 bSetDOSExtendedError
=
1841 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1842 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
)));
1845 case 0x57: /* FILE DATE AND TIME */
1846 switch (AL_reg(context
))
1848 case 0x00: /* Get */
1851 TRACE("GET FILE DATE AND TIME for handle %d\n",
1853 if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context
)), NULL
, NULL
, &filetime
))
1854 bSetDOSExtendedError
= TRUE
;
1855 else FileTimeToDosDateTime( &filetime
, &DX_reg(context
),
1860 case 0x01: /* Set */
1863 TRACE("SET FILE DATE AND TIME for handle %d\n",
1865 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
1867 bSetDOSExtendedError
=
1868 (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context
)),
1869 NULL
, NULL
, &filetime
));
1875 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1876 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1878 switch (AL_reg(context
))
1881 AX_reg(context
) = 1;
1884 AX_reg(context
) = 0;
1890 RESET_CFLAG(context
);
1893 case 0x5a: /* CREATE TEMPORARY FILE */
1894 TRACE("CREATE TEMPORARY FILE\n");
1895 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
1898 case 0x5b: /* CREATE NEW FILE */
1899 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context
),
1900 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
1901 bSetDOSExtendedError
= ((AX_reg(context
) =
1902 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
1903 CX_reg(context
) )) == (WORD
)HFILE_ERROR16
);
1906 case 0x5d: /* NETWORK */
1907 FIXME("Function 0x%04x not implemented.\n", AX_reg (context
));
1908 /* Fix the following while you're at it. */
1909 SetLastError( ER_NoNetwork
);
1910 bSetDOSExtendedError
= TRUE
;
1914 bSetDOSExtendedError
= INT21_networkfunc (context
);
1917 case 0x5f: /* NETWORK */
1918 switch (AL_reg(context
))
1920 case 0x07: /* ENABLE DRIVE */
1921 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1922 if (!DRIVE_Enable( DL_reg(context
) ))
1924 SetLastError( ERROR_INVALID_DRIVE
);
1925 bSetDOSExtendedError
= TRUE
;
1929 case 0x08: /* DISABLE DRIVE */
1930 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context
)+'A'));
1931 if (!DRIVE_Disable( DL_reg(context
) ))
1933 SetLastError( ERROR_INVALID_DRIVE
);
1934 bSetDOSExtendedError
= TRUE
;
1939 /* network software not installed */
1940 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
1941 SetLastError( ER_NoNetwork
);
1942 bSetDOSExtendedError
= TRUE
;
1947 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1948 TRACE("TRUENAME %s\n",
1949 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
1951 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
1953 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
1954 context
->Edi
),NULL
))
1955 bSetDOSExtendedError
= TRUE
;
1956 else AX_reg(context
) = 0;
1960 case 0x61: /* UNUSED */
1961 case 0x63: /* misc. language support */
1962 switch (AL_reg(context
)) {
1963 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1964 INT21_GetDBCSLeadTable(context
);
1968 case 0x64: /* OS/2 DOS BOX */
1969 INT_BARF( context
, 0x21 );
1973 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1974 BYTE
*dataptr
=CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
1975 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1976 BX_reg(context
), DX_reg(context
));
1977 switch (AL_reg(context
)) {
1979 TRACE("\tget general internationalization info\n");
1981 *(WORD
*)(dataptr
+1) = 41;
1982 *(WORD
*)(dataptr
+3) = GetSystemDefaultLangID();
1983 *(WORD
*)(dataptr
+5) = CodePage
;
1984 *(DWORD
*)(dataptr
+0x19) = 0; /* FIXME: ptr to case map routine */
1987 TRACE("\tget pointer to collating sequence table\n");
1989 *(DWORD
*)(dataptr
+1) = MAKELONG(DOSMEM_CollateTable
& 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable
>>16));
1990 CX_reg(context
) = 258;/*FIXME: size of table?*/
1993 TRACE("\tConvert char to uppercase\n");
1994 DL_reg(context
) = toupper(DL_reg(context
));
1997 TRACE("\tconvert string to uppercase with length\n");
1999 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
);
2000 WORD len
= CX_reg(context
);
2001 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
2005 TRACE("\tConvert ASCIIZ string to uppercase\n");
2006 _strupr( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
,context
->SegDs
,context
->Edx
) );
2009 TRACE("\tunimplemented function %d\n",AL_reg(context
));
2010 INT_BARF( context
, 0x21 );
2016 case 0x66: /* GLOBAL CODE PAGE TABLE */
2017 switch (AL_reg(context
))
2020 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2021 DX_reg(context
) = BX_reg(context
) = CodePage
;
2022 RESET_CFLAG(context
);
2025 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2026 BX_reg(context
),DX_reg(context
));
2027 CodePage
= BX_reg(context
);
2028 RESET_CFLAG(context
);
2033 case 0x67: /* SET HANDLE COUNT */
2034 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context
) );
2035 SetHandleCount16( BX_reg(context
) );
2036 if (GetLastError()) bSetDOSExtendedError
= TRUE
;
2039 case 0x68: /* "FFLUSH" - COMMIT FILE */
2040 case 0x6a: /* COMMIT FILE */
2041 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context
));
2042 bSetDOSExtendedError
= (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ));
2045 case 0x69: /* DISK SERIAL NUMBER */
2046 switch (AL_reg(context
))
2049 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2050 INT21_DriveName(BL_reg(context
)));
2051 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2052 else AX_reg(context
) = 0;
2056 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2057 INT21_DriveName(BL_reg(context
)));
2058 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
2059 else AX_reg(context
) = 1;
2064 case 0x6C: /* Extended Open/Create*/
2065 TRACE("EXTENDED OPEN/CREATE %s\n",
2066 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edi
));
2067 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2070 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2071 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2072 /* not supported on anything but Win95 */
2073 TRACE("LONG FILENAME functions supported only by win95\n");
2075 AL_reg(context
) = 0;
2077 switch(AL_reg(context
))
2079 case 0x39: /* Create directory */
2080 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2081 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2082 bSetDOSExtendedError
= (!CreateDirectoryA(
2083 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2084 context
->Edx
), NULL
));
2085 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2086 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2087 * denied), while CreateDirectory return several ones. remap some of
2090 if (bSetDOSExtendedError
) {
2091 switch (GetLastError()) {
2092 case ERROR_ALREADY_EXISTS
:
2093 case ERROR_FILENAME_EXCED_RANGE
:
2094 case ERROR_DISK_FULL
:
2095 SetLastError(ERROR_ACCESS_DENIED
);
2101 case 0x3a: /* Remove directory */
2102 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2103 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2104 bSetDOSExtendedError
= (!RemoveDirectoryA(
2105 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2108 case 0x43: /* Get/Set file attributes */
2109 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2110 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2111 switch (BL_reg(context
))
2113 case 0x00: /* Get file attributes */
2114 TRACE("\tretrieve attributes\n");
2115 CX_reg(context
) = (WORD
)GetFileAttributesA(
2116 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2118 if (CX_reg(context
) == 0xffff) bSetDOSExtendedError
= TRUE
;
2121 TRACE("\tset attributes 0x%04x\n",CX_reg(context
));
2122 bSetDOSExtendedError
= (!SetFileAttributesA(
2123 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2125 CX_reg(context
) ) );
2128 FIXME("Unimplemented long file name function:\n");
2129 INT_BARF( context
, 0x21 );
2131 AL_reg(context
) = 0;
2135 case 0x47: /* Get current directory */
2136 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2137 INT21_DriveName(DL_reg(context
)));
2138 bSetDOSExtendedError
= !INT21_GetCurrentDirectory(context
);
2141 case 0x4e: /* Find first file */
2142 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2143 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
));
2144 /* FIXME: use attributes in CX */
2145 if ((AX_reg(context
) = FindFirstFile16(
2146 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
),
2147 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2149 == INVALID_HANDLE_VALUE16
)
2150 bSetDOSExtendedError
= TRUE
;
2152 case 0x4f: /* Find next file */
2153 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2155 if (!FindNextFile16( BX_reg(context
),
2156 (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2158 bSetDOSExtendedError
= TRUE
;
2162 LPCSTR driveroot
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
2163 LPSTR buffer
= (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,context
->Edi
);
2164 DWORD filename_len
, flags
;
2166 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot
);
2167 AX_reg(context
) = 0;
2168 if (!GetVolumeInformationA( driveroot
, NULL
, 0, NULL
, &filename_len
,
2169 &flags
, buffer
, 8 ))
2171 INT_BARF( context
, 0x21 );
2175 BX_reg(context
) = flags
| 0x4000; /* support for LFN functions */
2176 CX_reg(context
) = filename_len
;
2177 DX_reg(context
) = MAX_PATH
; /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2180 case 0xa1: /* Find close */
2181 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2183 bSetDOSExtendedError
= (!FindClose16( BX_reg(context
) ));
2186 switch(CL_reg(context
))
2188 case 0x01: /* Get short filename or path */
2189 if (!GetShortPathNameA
2190 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2192 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2194 bSetDOSExtendedError
= TRUE
;
2195 else AX_reg(context
) = 0;
2197 case 0x02: /* Get canonical long filename or path */
2198 if (!GetFullPathNameA
2199 ( CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,
2201 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2202 context
->Edi
),NULL
))
2203 bSetDOSExtendedError
= TRUE
;
2204 else AX_reg(context
) = 0;
2207 FIXME("Unimplemented long file name function:\n");
2208 INT_BARF( context
, 0x21 );
2210 AL_reg(context
) = 0;
2214 case 0x6c: /* Create or open file */
2215 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2216 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
));
2217 /* translate Dos 7 action to Dos 6 action */
2218 bSetDOSExtendedError
= INT21_ExtendedOpenCreateFile(context
);
2221 case 0x3b: /* Change directory */
2222 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2223 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
2224 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context
,
2230 AL_reg(context
) = GetLastError();
2233 case 0x41: /* Delete file */
2234 TRACE("LONG FILENAME - DELETE FILE %s\n",
2235 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
2236 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context
,
2241 AL_reg(context
) = GetLastError();
2244 case 0x56: /* Move (rename) file */
2246 LPCSTR fn1
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2247 LPCSTR fn2
= (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
2248 TRACE("LONG FILENAME - RENAME FILE %s to %s\n", fn1
, fn2
);
2249 if (!MoveFileA(fn1
, fn2
))
2252 AL_reg(context
) = GetLastError();
2257 FIXME("Unimplemented long file name function:\n");
2258 INT_BARF( context
, 0x21 );
2260 AL_reg(context
) = 0;
2265 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2266 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2267 TRACE("windows95 function AX %04x\n",
2269 WARN(" returning unimplemented\n");
2271 AL_reg(context
) = 0;
2274 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2275 TRACE("windows95 function AX %04x\n",
2278 switch (AL_reg(context
))
2280 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
2281 /* ES:DI points to word with length of data (should be 0x3d) */
2285 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
2286 char root
[] = "A:\\";
2288 buffer
= (WORD
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
2290 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer
);
2292 /* validate passed-in buffer lengths */
2293 if ((*buffer
!= 0x3d) || (context
->Ecx
!= 0x3f))
2295 WARN("Get Extended DPB: buffer lengths incorrect\n");
2296 WARN("CX = %lx, buffer[0] = %x\n", context
->Ecx
, *buffer
);
2298 AL_reg(context
) = 0x18; /* bad buffer length */
2301 /* buffer checks out */
2302 buffer
++; /* skip over length word now */
2303 if (FillInDrivePB( DX_reg(context
) ) )
2305 edpb
= (struct EDPB
*)buffer
;
2307 /* copy down the old-style DPB portion first */
2308 memcpy(&edpb
->dpb
, &heap
->dpb
, sizeof(struct DPB
));
2310 /* now fill in the extended entries */
2311 edpb
->edpb_flags
= 0;
2312 edpb
->next_edpb
= 0;
2313 edpb
->free_cluster
= edpb
->free_cluster2
= 0;
2315 /* determine free disk space */
2316 *root
+= DOS_GET_DRIVE( DX_reg(context
) );
2317 GetDiskFreeSpaceA( root
, &cluster_sectors
, §or_bytes
,
2318 &free_clusters
, &total_clusters
);
2320 edpb
->clusters_free
= (free_clusters
&0xffff);
2322 edpb
->clusters_free_hi
= free_clusters
>> 16;
2323 edpb
->mirroring_flags
= 0;
2324 edpb
->info_sector
= 0xffff;
2325 edpb
->spare_boot_sector
= 0xffff;
2326 edpb
->first_cluster
= 0;
2327 edpb
->max_cluster
= total_clusters
;
2328 edpb
->fat_clusters
= 32; /* made-up value */
2329 edpb
->root_cluster
= 0;
2331 RESET_CFLAG(context
); /* clear carry */
2332 AX_reg(context
) = 0;
2336 AX_reg(context
) = 0x00ff;
2342 case 0x03: /* Get Extended free space on drive */
2343 case 0x04: /* Set DPB for formatting */
2344 case 0x05: /* extended absolute disk read/write */
2345 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context
));
2347 AL_reg(context
) = 0;
2354 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2355 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2359 INT_BARF( context
, 0x21 );
2362 } /* END OF SWITCH */
2364 if( bSetDOSExtendedError
) /* set general error condition */
2366 AX_reg(context
) = GetLastError();
2370 if ((context
->EFlags
& 0x0001))
2371 TRACE("failed, error %ld\n", GetLastError() );
2373 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2374 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2375 AX_reg(context
), BX_reg(context
), CX_reg(context
),
2376 DX_reg(context
), SI_reg(context
), DI_reg(context
),
2377 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
2381 /***********************************************************************
2382 * GetSetKernelDOSProc (KERNEL.311)
2384 FARPROC16 WINAPI
GetSetKernelDOSProc16(FARPROC16 DosProc
)
2386 FIXME("(DosProc=0x%08x): stub\n", (UINT
)DosProc
);