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
9 * Copyright 2003 Thomas Mertes
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/port.h"
39 #include "wine/winbase16.h"
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
46 #include "wine/exception.h"
50 * - Most of the file related functions are wrong. NT's kernel32
51 * doesn't maintain a per drive current directory, while DOS does.
52 * We should in fact keep track in here of those per driver
53 * directories, and use this infro while dealing with partial paths
54 * (drive defined, but only relative paths). This could even be
55 * created as an array of CDS (there should be an entry for that in
60 * Forward declarations.
62 static BOOL
INT21_RenameFile( CONTEXT86
*context
);
64 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
70 * Extended Drive Parameter Block.
71 * This structure is compatible with standard DOS4+ DPB and
74 typedef struct _INT21_DPB
{
75 BYTE drive
; /* 00 drive number (0=A, ...) */
76 BYTE unit
; /* 01 unit number within device driver */
77 WORD sector_bytes
; /* 02 bytes per sector */
78 BYTE cluster_sectors
; /* 04 highest sector number within a cluster */
79 BYTE shift
; /* 05 shift count to convert clusters into sectors */
80 WORD num_reserved
; /* 06 reserved sectors at beginning of drive */
81 BYTE num_FAT
; /* 08 number of FATs */
82 WORD num_root_entries
; /* 09 number of root directory entries */
83 WORD first_data_sector
; /* 0b number of first sector containing user data */
84 WORD num_clusters1
; /* 0d highest cluster number (number of data clusters + 1) */
85 WORD sectors_per_FAT
; /* 0f number of sectors per FAT */
86 WORD first_dir_sector
; /* 11 sector number of first directory sector */
87 SEGPTR driver_header
; /* 13 address of device driver header */
88 BYTE media_ID
; /* 17 media ID byte */
89 BYTE access_flag
; /* 18 0x00 if disk accessed, 0xff if not */
90 SEGPTR next
; /* 19 pointer to next DPB */
91 WORD search_cluster1
; /* 1d cluster at which to start search for free space */
92 WORD free_clusters_lo
; /* 1f number of free clusters on drive or 0xffff if unknown */
93 WORD free_clusters_hi
; /* 21 hiword of clusters_free */
94 WORD mirroring_flags
; /* 23 active FAT/mirroring flags */
95 WORD info_sector
; /* 25 sector number of file system info sector or 0xffff for none */
96 WORD spare_boot_sector
; /* 27 sector number of backup boot sector or 0xffff for none */
97 DWORD first_cluster_sector
; /* 29 sector number of the first cluster */
98 DWORD num_clusters2
; /* 2d maximum cluster number */
99 DWORD fat_clusters
; /* 31 number of clusters occupied by FAT */
100 DWORD root_cluster
; /* 35 cluster number of start of root directory */
101 DWORD search_cluster2
; /* 39 cluster at which to start searching for free space */
106 * Structure for DOS data that can be accessed directly from applications.
107 * Real and protected mode pointers will be returned to this structure so
108 * the structure must be correctly packed.
110 typedef struct _INT21_HEAP
{
111 WORD uppercase_size
; /* Size of the following table in bytes */
112 BYTE uppercase_table
[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
114 WORD lowercase_size
; /* Size of the following table in bytes */
115 BYTE lowercase_table
[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
117 WORD collating_size
; /* Size of the following table in bytes */
118 BYTE collating_table
[256]; /* Values used to sort characters from 0x00 to 0xff. */
120 WORD filename_size
; /* Size of the following filename data in bytes */
121 BYTE filename_reserved1
; /* 0x01 for MS-DOS 3.30-6.00 */
122 BYTE filename_lowest
; /* Lowest permissible character value for filename */
123 BYTE filename_highest
; /* Highest permissible character value for filename */
124 BYTE filename_reserved2
; /* 0x00 for MS-DOS 3.30-6.00 */
125 BYTE filename_exclude_first
; /* First illegal character in permissible range */
126 BYTE filename_exclude_last
; /* Last illegal character in permissible range */
127 BYTE filename_reserved3
; /* 0x02 for MS-DOS 3.30-6.00 */
128 BYTE filename_illegal_size
; /* Number of terminators in the following table */
129 BYTE filename_illegal_table
[16]; /* Characters which terminate a filename */
131 WORD dbcs_size
; /* Number of valid ranges in the following table */
132 BYTE dbcs_table
[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
134 BYTE misc_indos
; /* Interrupt 21 nesting flag */
135 WORD misc_segment
; /* Real mode segment for INT21_HEAP */
136 WORD misc_selector
; /* Protected mode selector for INT21_HEAP */
137 INT21_DPB misc_dpb_list
[MAX_DOS_DRIVES
]; /* Drive parameter blocks for all drives */
145 CHAR file_extension
[3];
146 WORD current_block_number
;
147 WORD logical_record_size
;
149 WORD date_of_last_write
;
150 WORD time_of_last_write
;
153 WORD starting_cluster
;
154 WORD sequence_number
;
155 BYTE file_attributes
;
157 BYTE record_within_current_block
;
158 BYTE random_access_record_number
[4];
165 BYTE xfcb_file_attribute
;
169 /* DTA layout for FindFirst/FindNext */
172 BYTE drive
; /* 00 drive letter */
173 char mask
[11]; /* 01 search template */
174 BYTE search_attr
; /* 0c search attributes */
175 WORD count
; /* 0d entry count within directory */
176 WORD cluster
; /* 0f cluster of parent directory */
177 WCHAR
*fullPath
; /* 11 full path (was: reserved) */
178 BYTE fileattr
; /* 15 file attributes */
179 WORD filetime
; /* 16 file time */
180 WORD filedate
; /* 18 file date */
181 DWORD filesize
; /* 1a file size */
182 char filename
[13]; /* 1e file name + extension */
185 /* FCB layout for FindFirstFCB/FindNextFCB */
188 BYTE drive
; /* 00 drive letter */
189 char filename
[11]; /* 01 filename 8+3 format */
190 int count
; /* 0c entry count (was: reserved) */
191 WCHAR
*fullPath
; /* 10 full path (was: reserved) */
194 /* DOS directory entry for FindFirstFCB/FindNextFCB */
197 char filename
[11]; /* 00 filename 8+3 format */
198 BYTE fileattr
; /* 0b file attributes */
199 BYTE reserved
[10]; /* 0c reserved */
200 WORD filetime
; /* 16 file time */
201 WORD filedate
; /* 18 file date */
202 WORD cluster
; /* 1a file first cluster */
203 DWORD filesize
; /* 1c file size */
204 } DOS_DIRENTRY_LAYOUT
;
208 /* dos file attributes */
209 #define FA_NORMAL 0x00 /* Normal file, no attributes */
210 #define FA_RDONLY 0x01 /* Read only attribute */
211 #define FA_HIDDEN 0x02 /* Hidden file */
212 #define FA_SYSTEM 0x04 /* System file */
213 #define FA_LABEL 0x08 /* Volume label */
214 #define FA_DIRECTORY 0x10 /* Directory */
215 #define FA_ARCHIVE 0x20 /* Archive */
216 #define FA_UNUSED 0x40 /* Unused */
219 #define ER_NoNetwork 0x49
222 #define EC_OutOfResource 0x01
223 #define EC_Temporary 0x02
224 #define EC_AccessDenied 0x03
225 #define EC_InternalError 0x04
226 #define EC_HardwareFailure 0x05
227 #define EC_SystemFailure 0x06
228 #define EC_ProgramError 0x07
229 #define EC_NotFound 0x08
230 #define EC_MediaError 0x0b
231 #define EC_Exists 0x0c
232 #define EC_Unknown 0x0d
234 /* Suggested actions */
235 #define SA_Retry 0x01
236 #define SA_DelayedRetry 0x02
237 #define SA_Abort 0x04
238 #define SA_Ignore 0x06
239 #define SA_Ask4Retry 0x07
242 #define EL_Unknown 0x01
244 #define EL_Network 0x03
245 #define EL_Serial 0x04
246 #define EL_Memory 0x05
249 /* Many calls translate a drive argument like this:
250 drive number (00h = default, 01h = A:, etc)
252 /******************************************************************
255 * Many calls translate a drive argument like this:
256 * drive number (00h = default, 01h = A:, etc)
258 static const char *INT21_DriveName(int drive
)
262 if (drive
<= 26) return wine_dbg_sprintf("%c:", 'A' + drive
- 1);
263 else return wine_dbg_sprintf( "<Bad drive: %d>", drive
);
268 /***********************************************************************
269 * INT21_GetCurrentDrive
271 * Return current drive using scheme (0=A:, 1=B:, 2=C:, ...) or
272 * MAX_DOS_DRIVES on error.
274 static BYTE
INT21_GetCurrentDrive(void)
276 WCHAR current_directory
[MAX_PATH
];
278 if (!GetCurrentDirectoryW( MAX_PATH
, current_directory
) ||
279 current_directory
[1] != ':')
281 TRACE( "Failed to get current drive.\n" );
282 return MAX_DOS_DRIVES
;
285 return toupperW( current_directory
[0] ) - 'A';
289 /***********************************************************************
292 * Convert drive number from scheme (0=default, 1=A:, 2=B:, ...) into
293 * scheme (0=A:, 1=B:, 2=C:, ...) or MAX_DOS_DRIVES on error.
295 static BYTE
INT21_MapDrive( BYTE drive
)
299 WCHAR drivespec
[3] = {'A', ':', 0};
302 drivespec
[0] += drive
- 1;
303 drivetype
= GetDriveTypeW( drivespec
);
305 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
306 return MAX_DOS_DRIVES
;
311 return INT21_GetCurrentDrive();
315 /***********************************************************************
316 * INT21_SetCurrentDrive
318 * Set current drive. Uses scheme (0=A:, 1=B:, 2=C:, ...).
320 static void INT21_SetCurrentDrive( BYTE drive
)
322 WCHAR drivespec
[3] = {'A', ':', 0};
324 drivespec
[0] += drive
;
326 if (!SetCurrentDirectoryW( drivespec
))
327 TRACE( "Failed to set current drive.\n" );
331 /***********************************************************************
334 * Reads a character from the standard input.
335 * Extended keycodes will be returned as two separate characters.
337 static BOOL
INT21_ReadChar( BYTE
*input
, CONTEXT86
*waitctx
)
339 static BYTE pending_scan
= 0;
344 *input
= pending_scan
;
353 if (!DOSVM_Int16ReadChar( &ascii
, &scan
, waitctx
))
358 if (waitctx
&& !ascii
)
365 /***********************************************************************
366 * INT21_GetSystemCountryCode
368 * Return DOS country code for default system locale.
370 static WORD
INT21_GetSystemCountryCode( void )
373 * FIXME: Determine country code. We should probably use
374 * DOSCONF structure for that.
376 return GetSystemDefaultLangID();
380 /***********************************************************************
381 * INT21_FillCountryInformation
383 * Fill 34-byte buffer with country information data using
384 * default system locale.
386 static void INT21_FillCountryInformation( BYTE
*buffer
)
388 /* 00 - WORD: date format
393 *(WORD
*)(buffer
+ 0) = 0; /* FIXME: Get from locale */
395 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
396 buffer
[2] = '$'; /* FIXME: Get from locale */
399 /* 07 - BYTE[2]: ASCIIZ thousands separator */
400 buffer
[7] = 0; /* FIXME: Get from locale */
403 /* 09 - BYTE[2]: ASCIIZ decimal separator */
404 buffer
[9] = '.'; /* FIXME: Get from locale */
407 /* 11 - BYTE[2]: ASCIIZ date separator */
408 buffer
[11] = '/'; /* FIXME: Get from locale */
411 /* 13 - BYTE[2]: ASCIIZ time separator */
412 buffer
[13] = ':'; /* FIXME: Get from locale */
415 /* 15 - BYTE: Currency format
416 * bit 2 = set if currency symbol replaces decimal point
417 * bit 1 = number of spaces between value and currency symbol
418 * bit 0 = 0 if currency symbol precedes value
419 * 1 if currency symbol follows value
421 buffer
[15] = 0; /* FIXME: Get from locale */
423 /* 16 - BYTE: Number of digits after decimal in currency */
424 buffer
[16] = 0; /* FIXME: Get from locale */
426 /* 17 - BYTE: Time format
427 * bit 0 = 0 if 12-hour clock
430 buffer
[17] = 1; /* FIXME: Get from locale */
432 /* 18 - DWORD: Address of case map routine */
433 *(DWORD
*)(buffer
+ 18) = 0; /* FIXME: ptr to case map routine */
435 /* 22 - BYTE[2]: ASCIIZ data-list separator */
436 buffer
[22] = ','; /* FIXME: Get from locale */
439 /* 24 - BYTE[10]: Reserved */
440 memset( buffer
+ 24, 0, 10 );
444 /***********************************************************************
447 * Initialize DOS heap.
449 static void INT21_FillHeap( INT21_HEAP
*heap
)
451 static const char terminators
[] = "\"\\./[]:|<>+=;,";
457 heap
->uppercase_size
= 128;
458 for (i
= 0; i
< 128; i
++)
459 heap
->uppercase_table
[i
] = toupper( 128 + i
);
464 heap
->lowercase_size
= 256;
465 for (i
= 0; i
< 256; i
++)
466 heap
->lowercase_table
[i
] = tolower( i
);
471 heap
->collating_size
= 256;
472 for (i
= 0; i
< 256; i
++)
473 heap
->collating_table
[i
] = i
;
478 heap
->filename_size
= 8 + strlen(terminators
);
479 heap
->filename_illegal_size
= strlen(terminators
);
480 strcpy( heap
->filename_illegal_table
, terminators
);
482 heap
->filename_reserved1
= 0x01;
483 heap
->filename_lowest
= 0; /* FIXME: correct value? */
484 heap
->filename_highest
= 0xff; /* FIXME: correct value? */
485 heap
->filename_reserved2
= 0x00;
486 heap
->filename_exclude_first
= 0x00; /* FIXME: correct value? */
487 heap
->filename_exclude_last
= 0x00; /* FIXME: correct value? */
488 heap
->filename_reserved3
= 0x02;
491 * DBCS lead byte table. This table is empty.
494 memset( heap
->dbcs_table
, 0, sizeof(heap
->dbcs_table
) );
497 * Initialize InDos flag.
499 heap
->misc_indos
= 0;
502 * FIXME: Should drive parameter blocks (DPB) be
503 * initialized here and linked to DOS LOL?
508 /***********************************************************************
509 * INT21_GetHeapPointer
511 * Get pointer for DOS heap (INT21_HEAP).
512 * Creates and initializes heap on first call.
514 static INT21_HEAP
*INT21_GetHeapPointer( void )
516 static INT21_HEAP
*heap_pointer
= NULL
;
523 heap_pointer
= DOSVM_AllocDataUMB( sizeof(INT21_HEAP
),
527 heap_pointer
->misc_segment
= heap_segment
;
528 heap_pointer
->misc_selector
= heap_selector
;
529 INT21_FillHeap( heap_pointer
);
536 /***********************************************************************
537 * INT21_GetHeapSelector
539 * Get segment/selector for DOS heap (INT21_HEAP).
540 * Creates and initializes heap on first call.
542 static WORD
INT21_GetHeapSelector( CONTEXT86
*context
)
544 INT21_HEAP
*heap
= INT21_GetHeapPointer();
546 if (!ISV86(context
) && DOSVM_IsWin16())
547 return heap
->misc_selector
;
549 return heap
->misc_segment
;
553 /***********************************************************************
556 * Fill DOS heap drive parameter block for the specified drive.
557 * Return TRUE if drive was valid and there were
558 * no errors while reading drive information.
560 static BOOL
INT21_FillDrivePB( BYTE drive
)
562 WCHAR drivespec
[3] = {'A', ':', 0};
563 INT21_HEAP
*heap
= INT21_GetHeapPointer();
566 DWORD cluster_sectors
;
569 DWORD total_clusters
;
571 if (drive
>= MAX_DOS_DRIVES
)
574 dpb
= &heap
->misc_dpb_list
[drive
];
575 drivespec
[0] += drive
;
576 drivetype
= GetDriveTypeW( drivespec
);
579 * FIXME: Does this check work correctly with floppy/cdrom drives?
581 if (drivetype
== DRIVE_NO_ROOT_DIR
|| drivetype
== DRIVE_UNKNOWN
)
585 * FIXME: Does this check work correctly with floppy/cdrom drives?
587 if (!GetDiskFreeSpaceW( drivespec
, &cluster_sectors
, §or_bytes
,
588 &free_clusters
, &total_clusters
))
592 * FIXME: Most of the values listed below are incorrect.
593 * All values should be validated.
598 dpb
->sector_bytes
= sector_bytes
;
599 dpb
->cluster_sectors
= cluster_sectors
- 1;
602 while (cluster_sectors
> 1)
604 cluster_sectors
/= 2;
608 dpb
->num_reserved
= 0;
610 dpb
->num_root_entries
= 2;
611 dpb
->first_data_sector
= 2;
612 dpb
->num_clusters1
= total_clusters
;
613 dpb
->sectors_per_FAT
= 1;
614 dpb
->first_dir_sector
= 1;
615 dpb
->driver_header
= 0;
616 dpb
->media_ID
= (drivetype
== DRIVE_FIXED
) ? 0xF8 : 0xF0;
617 dpb
->access_flag
= 0;
619 dpb
->search_cluster1
= 0;
620 dpb
->free_clusters_lo
= LOWORD(free_clusters
);
621 dpb
->free_clusters_hi
= HIWORD(free_clusters
);
622 dpb
->mirroring_flags
= 0;
623 dpb
->info_sector
= 0xffff;
624 dpb
->spare_boot_sector
= 0xffff;
625 dpb
->first_cluster_sector
= 0;
626 dpb
->num_clusters2
= total_clusters
;
627 dpb
->fat_clusters
= 32;
628 dpb
->root_cluster
= 0;
629 dpb
->search_cluster2
= 0;
635 /***********************************************************************
636 * INT21_GetCurrentDirectory
640 * - subfunction 0x47 of function 0x71
642 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
, BOOL islong
)
644 char *buffer
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
645 BYTE new_drive
= INT21_MapDrive( DL_reg(context
) );
646 BYTE old_drive
= INT21_GetCurrentDrive();
647 WCHAR pathW
[MAX_PATH
];
648 char pathA
[MAX_PATH
];
651 TRACE( "drive %d\n", DL_reg(context
) );
653 if (new_drive
== MAX_DOS_DRIVES
)
655 SetLastError(ERROR_INVALID_DRIVE
);
660 * Grab current directory.
663 INT21_SetCurrentDrive( new_drive
);
664 if (!GetCurrentDirectoryW( MAX_PATH
, pathW
))
666 INT21_SetCurrentDrive( old_drive
);
669 INT21_SetCurrentDrive( old_drive
);
672 * Convert into short format.
677 DWORD result
= GetShortPathNameW( pathW
, pathW
, MAX_PATH
);
680 if (result
> MAX_PATH
)
682 WARN( "Short path too long!\n" );
683 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
689 * The returned pathname does not include
690 * the drive letter, colon or leading backslash.
696 * FIXME: We should probably just strip host part from name...
698 FIXME( "UNC names are not supported.\n" );
699 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
702 else if (!ptr
[0] || ptr
[1] != ':' || ptr
[2] != '\\')
704 WARN( "Path is neither UNC nor DOS path: %s\n",
705 wine_dbgstr_w(ptr
) );
706 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
711 /* Remove drive letter, colon and leading backslash. */
716 * Convert into OEM string.
719 if (!WideCharToMultiByte(CP_OEMCP
, 0, ptr
, -1, pathA
,
720 MAX_PATH
, NULL
, NULL
))
722 WARN( "Cannot convert path!\n" );
723 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
733 /* Undocumented success code. */
734 SET_AX( context
, 0x0100 );
736 /* Truncate buffer to 64 bytes. */
740 TRACE( "%c:=%s\n", 'A' + new_drive
, pathA
);
742 strcpy( buffer
, pathA
);
747 /***********************************************************************
748 * INT21_SetCurrentDirectory
752 * - subfunction 0x3b of function 0x71
754 static BOOL
INT21_SetCurrentDirectory( CONTEXT86
*context
)
756 WCHAR dirW
[MAX_PATH
];
757 char *dirA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
758 BYTE drive
= INT21_GetCurrentDrive();
761 TRACE( "SET CURRENT DIRECTORY %s\n", dirA
);
763 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
764 result
= SetCurrentDirectoryW( dirW
);
766 /* This function must not change current drive. */
767 INT21_SetCurrentDrive( drive
);
773 /***********************************************************************
781 * - subfunction 0x6c of function 0x71
783 static BOOL
INT21_CreateFile( CONTEXT86
*context
,
790 char *pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, pathSegOff
);
791 WCHAR pathW
[MAX_PATH
];
798 TRACE( "CreateFile called: function=%02x, action=%02x, access/share=%04x, "
799 "create flags=%04x, file=%s.\n",
800 AH_reg(context
), dosAction
, dosAccessShare
, CX_reg(context
), pathA
);
803 * Application tried to create/open a file whose name
804 * ends with a backslash. This is not allowed.
806 * FIXME: This needs to be validated, especially the return value.
808 if (pathA
[strlen(pathA
) - 1] == '/')
810 SetLastError( ERROR_FILE_NOT_FOUND
);
815 * Convert DOS action flags into Win32 creation disposition parameter.
820 winMode
= OPEN_EXISTING
;
823 winMode
= TRUNCATE_EXISTING
;
826 winMode
= CREATE_NEW
;
829 winMode
= OPEN_ALWAYS
;
832 winMode
= CREATE_ALWAYS
;
835 SetLastError( ERROR_INVALID_PARAMETER
);
840 * Convert DOS access/share flags into Win32 desired access parameter.
842 switch(dosAccessShare
& 0x07)
845 winAccess
= GENERIC_READ
;
848 winAccess
= GENERIC_WRITE
;
851 winAccess
= GENERIC_READ
| GENERIC_WRITE
;
855 * Read-only, do not modify file's last-access time (DOS7).
857 * FIXME: How to prevent modification of last-access time?
859 winAccess
= GENERIC_READ
;
866 * Convert DOS access/share flags into Win32 share mode parameter.
868 switch(dosAccessShare
& 0x70)
870 case OF_SHARE_EXCLUSIVE
:
873 case OF_SHARE_DENY_WRITE
:
874 winSharing
= FILE_SHARE_READ
;
876 case OF_SHARE_DENY_READ
:
877 winSharing
= FILE_SHARE_WRITE
;
879 case OF_SHARE_DENY_NONE
:
880 case OF_SHARE_COMPAT
:
882 winSharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
886 * FIXME: Bit (dosAccessShare & 0x80) represents inheritance.
887 * What to do with this bit?
888 * FIXME: Bits in the high byte of dosAccessShare are not supported.
889 * See both function 0x6c and subfunction 0x6c of function 0x71 for
890 * definition of these bits.
894 * Convert DOS create attributes into Win32 flags and attributes parameter.
896 if (winMode
== OPEN_EXISTING
|| winMode
== TRUNCATE_EXISTING
)
902 WORD dosAttributes
= CX_reg(context
);
904 if (dosAttributes
& FILE_ATTRIBUTE_LABEL
)
907 * Application tried to create volume label entry.
908 * This is difficult to support so we do not allow it.
910 * FIXME: If volume does not already have a label,
911 * this function is supposed to succeed.
913 SetLastError( ERROR_ACCESS_DENIED
);
917 winAttributes
= dosAttributes
&
918 (FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
|
919 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
);
925 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
927 winHandle
= CreateFileW( pathW
, winAccess
, winSharing
, NULL
,
928 winMode
, winAttributes
, 0 );
930 if (winHandle
== INVALID_HANDLE_VALUE
)
934 * Determine DOS file status.
945 case TRUNCATE_EXISTING
:
952 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 1 : 2;
955 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 3 : 2;
962 * Return DOS file handle and DOS status.
964 SET_AX( context
, Win32HandleToDosFileHandle(winHandle
) );
967 SET_CX( context
, dosStatus
);
969 TRACE( "CreateFile finished: handle=%d, status=%d.\n",
970 AX_reg(context
), dosStatus
);
976 /***********************************************************************
977 * INT21_BufferedInput
979 * Handler for function 0x0a and reading from console using
982 * Reads a string of characters from standard input until
983 * enter key is pressed. Returns either number of characters
984 * read from console including terminating CR or
985 * zero if capacity was zero.
987 static WORD
INT21_BufferedInput( CONTEXT86
*context
, BYTE
*ptr
, WORD capacity
)
992 * Return immediately if capacity is zero.
1002 DOSVM_Int16ReadChar( &ascii
, &scan
, context
);
1004 if (ascii
== '\r' || ascii
== '\n')
1007 * FIXME: What should be echoed here?
1009 DOSVM_PutChar( '\r' );
1010 DOSVM_PutChar( '\n' );
1016 * FIXME: This function is supposed to support
1017 * DOS editing keys...
1021 * If the buffer becomes filled to within one byte of
1022 * capacity, DOS rejects all further characters up to,
1023 * but not including, the terminating carriage return.
1025 if (ascii
!= 0 && length
< capacity
-1)
1027 DOSVM_PutChar( ascii
);
1028 ptr
[length
] = ascii
;
1035 /***********************************************************************
1036 * INT21_GetCurrentDTA
1038 static BYTE
*INT21_GetCurrentDTA( CONTEXT86
*context
)
1040 TDB
*pTask
= GlobalLock16(GetCurrentTask());
1042 /* FIXME: This assumes DTA was set correctly! */
1043 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
1044 (DWORD
)OFFSETOF(pTask
->dta
) );
1048 /***********************************************************************
1049 * INT21_OpenFileUsingFCB
1051 * Handler for function 0x0f.
1054 * DX:DX [I/O] File control block (FCB or XFCB) of unopened file
1061 * Opens a FCB file for read/write in compatibility mode. Upon calling
1062 * the FCB must have the drive_number, file_name, and file_extension
1063 * fields filled and all other bytes cleared.
1065 static void INT21_OpenFileUsingFCB( CONTEXT86
*context
)
1073 BY_HANDLE_FILE_INFORMATION info
;
1076 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1077 if (fcb
->drive_number
== 0xff) {
1078 xfcb
= (struct XFCB
*) fcb
;
1079 fcb
= (struct FCB
*) xfcb
->fcb
;
1083 file_path
[0] = 'A' + INT21_MapDrive( fcb
->drive_number
);
1085 if (AL_result
== 0) {
1087 pos
= &file_path
[2];
1088 memcpy(pos
, fcb
->file_name
, 8);
1091 pos
= strchr(pos
, ' ');
1094 memcpy(pos
, fcb
->file_extension
, 3);
1097 pos
= strchr(pos
, ' ');
1100 handle
= (HANDLE
) _lopen(file_path
, OF_READWRITE
);
1101 if (handle
== INVALID_HANDLE_VALUE
) {
1102 TRACE("_lopen(\"%s\") failed: INVALID_HANDLE_VALUE\n", file_path
);
1103 AL_result
= 0xff; /* failed */
1105 hfile16
= Win32HandleToDosFileHandle(handle
);
1106 if (hfile16
== HFILE_ERROR16
) {
1107 TRACE("Win32HandleToDosFileHandle(%p) failed: HFILE_ERROR\n", handle
);
1108 CloseHandle(handle
);
1109 AL_result
= 0xff; /* failed */
1110 } else if (hfile16
> 255) {
1111 TRACE("hfile16 (=%d) larger than 255 for \"%s\"\n", hfile16
, file_path
);
1113 AL_result
= 0xff; /* failed */
1115 if (!GetFileInformationByHandle(handle
, &info
)) {
1116 TRACE("GetFileInformationByHandle(%d, %p) for \"%s\" failed\n",
1117 hfile16
, handle
, file_path
);
1119 AL_result
= 0xff; /* failed */
1121 fcb
->drive_number
= file_path
[0] - 'A' + 1;
1122 fcb
->current_block_number
= 0;
1123 fcb
->logical_record_size
= 128;
1124 fcb
->file_size
= info
.nFileSizeLow
;
1125 FileTimeToDosDateTime(&info
.ftLastWriteTime
,
1126 &fcb
->date_of_last_write
, &fcb
->time_of_last_write
);
1127 fcb
->file_number
= hfile16
;
1128 fcb
->attributes
= 0xc2;
1129 fcb
->starting_cluster
= 0; /* don't know correct init value */
1130 fcb
->sequence_number
= 0; /* don't know correct init value */
1131 fcb
->file_attributes
= info
.dwFileAttributes
;
1132 /* The following fields are not initialized */
1133 /* by the native function: */
1135 /* record_within_current_block */
1136 /* random_access_record_number */
1138 TRACE("successful opened file \"%s\" as %d (handle %p)\n",
1139 file_path
, hfile16
, handle
);
1140 AL_result
= 0x00; /* successful */
1145 SET_AL(context
, AL_result
);
1149 /***********************************************************************
1150 * INT21_CloseFileUsingFCB
1152 * Handler for function 0x10.
1155 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1162 * Closes a FCB file.
1164 static void INT21_CloseFileUsingFCB( CONTEXT86
*context
)
1170 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1171 if (fcb
->drive_number
== 0xff) {
1172 xfcb
= (struct XFCB
*) fcb
;
1173 fcb
= (struct FCB
*) xfcb
->fcb
;
1176 if (_lclose16((HFILE16
) fcb
->file_number
) != 0) {
1177 TRACE("_lclose16(%d) failed\n", fcb
->file_number
);
1178 AL_result
= 0xff; /* failed */
1180 TRACE("successful closed file %d\n", fcb
->file_number
);
1181 AL_result
= 0x00; /* successful */
1183 SET_AL(context
, AL_result
);
1187 /***********************************************************************
1188 * INT21_SequentialReadFromFCB
1190 * Handler for function 0x14.
1193 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1197 * 1: end of file, no data read
1198 * 2: segment wrap in DTA, no data read (not returned now)
1199 * 3: end of file, partial record read
1202 * Reads a record with the size FCB->logical_record_size from the FCB
1203 * to the disk transfer area. The position of the record is specified
1204 * with FCB->current_block_number and FCB->record_within_current_block.
1205 * Then FCB->current_block_number and FCB->record_within_current_block
1206 * are updated to point to the next record. If a partial record is
1207 * read, it is filled with zeros up to the FCB->logical_record_size.
1209 static void INT21_SequentialReadFromFCB( CONTEXT86
*context
)
1214 DWORD record_number
;
1216 BYTE
*disk_transfer_area
;
1220 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1221 if (fcb
->drive_number
== 0xff) {
1222 xfcb
= (struct XFCB
*) fcb
;
1223 fcb
= (struct FCB
*) xfcb
->fcb
;
1226 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1227 if (handle
== INVALID_HANDLE_VALUE
) {
1228 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1230 AL_result
= 0x01; /* end of file, no data read */
1232 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1233 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1234 if (position
!= record_number
* fcb
->logical_record_size
) {
1235 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1236 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1237 AL_result
= 0x01; /* end of file, no data read */
1239 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1240 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1241 if (bytes_read
!= fcb
->logical_record_size
) {
1242 TRACE("_lread(%d, %p, %d) failed with %d\n",
1243 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1244 if (bytes_read
== 0) {
1245 AL_result
= 0x01; /* end of file, no data read */
1247 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1248 AL_result
= 0x03; /* end of file, partial record read */
1251 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1252 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1253 AL_result
= 0x00; /* successful */
1257 if (AL_result
== 0x00 || AL_result
== 0x03) {
1258 if (fcb
->record_within_current_block
== 127) {
1259 fcb
->record_within_current_block
= 0;
1260 fcb
->current_block_number
++;
1262 fcb
->record_within_current_block
++;
1265 SET_AL(context
, AL_result
);
1269 /***********************************************************************
1270 * INT21_SequentialWriteToFCB
1272 * Handler for function 0x15.
1275 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1280 * 2: segment wrap in DTA (not returned now)
1283 * Writes a record with the size FCB->logical_record_size from the disk
1284 * transfer area to the FCB. The position of the record is specified
1285 * with FCB->current_block_number and FCB->record_within_current_block.
1286 * Then FCB->current_block_number and FCB->record_within_current_block
1287 * are updated to point to the next record.
1289 static void INT21_SequentialWriteToFCB( CONTEXT86
*context
)
1294 DWORD record_number
;
1296 BYTE
*disk_transfer_area
;
1300 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1301 if (fcb
->drive_number
== 0xff) {
1302 xfcb
= (struct XFCB
*) fcb
;
1303 fcb
= (struct FCB
*) xfcb
->fcb
;
1306 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1307 if (handle
== INVALID_HANDLE_VALUE
) {
1308 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1310 AL_result
= 0x01; /* disk full */
1312 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1313 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1314 if (position
!= record_number
* fcb
->logical_record_size
) {
1315 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1316 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1317 AL_result
= 0x01; /* disk full */
1319 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1320 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1321 if (bytes_written
!= fcb
->logical_record_size
) {
1322 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1323 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1324 AL_result
= 0x01; /* disk full */
1326 TRACE("successful written %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1327 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1328 AL_result
= 0x00; /* successful */
1332 if (AL_result
== 0x00) {
1333 if (fcb
->record_within_current_block
== 127) {
1334 fcb
->record_within_current_block
= 0;
1335 fcb
->current_block_number
++;
1337 fcb
->record_within_current_block
++;
1340 SET_AL(context
, AL_result
);
1344 /***********************************************************************
1345 * INT21_ReadRandomRecordFromFCB
1347 * Handler for function 0x21.
1350 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1354 * 1: end of file, no data read
1355 * 2: segment wrap in DTA, no data read (not returned now)
1356 * 3: end of file, partial record read
1359 * Reads a record with the size FCB->logical_record_size from
1360 * the FCB to the disk transfer area. The position of the record
1361 * is specified with FCB->random_access_record_number. The
1362 * FCB->random_access_record_number is not updated. If a partial record
1363 * is read, it is filled with zeros up to the FCB->logical_record_size.
1365 static void INT21_ReadRandomRecordFromFCB( CONTEXT86
*context
)
1370 DWORD record_number
;
1372 BYTE
*disk_transfer_area
;
1376 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1377 if (fcb
->drive_number
== 0xff) {
1378 xfcb
= (struct XFCB
*) fcb
;
1379 fcb
= (struct FCB
*) xfcb
->fcb
;
1382 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1383 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1384 if (handle
== INVALID_HANDLE_VALUE
) {
1385 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1387 AL_result
= 0x01; /* end of file, no data read */
1389 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1390 if (position
!= record_number
* fcb
->logical_record_size
) {
1391 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1392 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1393 AL_result
= 0x01; /* end of file, no data read */
1395 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1396 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1397 if (bytes_read
!= fcb
->logical_record_size
) {
1398 TRACE("_lread(%d, %p, %d) failed with %d\n",
1399 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1400 if (bytes_read
== 0) {
1401 AL_result
= 0x01; /* end of file, no data read */
1403 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1404 AL_result
= 0x03; /* end of file, partial record read */
1407 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1408 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1409 AL_result
= 0x00; /* successful */
1413 fcb
->current_block_number
= record_number
/ 128;
1414 fcb
->record_within_current_block
= record_number
% 128;
1415 SET_AL(context
, AL_result
);
1419 /***********************************************************************
1420 * INT21_WriteRandomRecordToFCB
1422 * Handler for function 0x22.
1425 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1430 * 2: segment wrap in DTA (not returned now)
1433 * Writes a record with the size FCB->logical_record_size from
1434 * the disk transfer area to the FCB. The position of the record
1435 * is specified with FCB->random_access_record_number. The
1436 * FCB->random_access_record_number is not updated.
1438 static void INT21_WriteRandomRecordToFCB( CONTEXT86
*context
)
1443 DWORD record_number
;
1445 BYTE
*disk_transfer_area
;
1449 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1450 if (fcb
->drive_number
== 0xff) {
1451 xfcb
= (struct XFCB
*) fcb
;
1452 fcb
= (struct FCB
*) xfcb
->fcb
;
1455 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1456 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1457 if (handle
== INVALID_HANDLE_VALUE
) {
1458 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1460 AL_result
= 0x01; /* disk full */
1462 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1463 if (position
!= record_number
* fcb
->logical_record_size
) {
1464 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1465 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1466 AL_result
= 0x01; /* disk full */
1468 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1469 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1470 if (bytes_written
!= fcb
->logical_record_size
) {
1471 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1472 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1473 AL_result
= 0x01; /* disk full */
1475 TRACE("successful written %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1476 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1477 AL_result
= 0x00; /* successful */
1481 fcb
->current_block_number
= record_number
/ 128;
1482 fcb
->record_within_current_block
= record_number
% 128;
1483 SET_AL(context
, AL_result
);
1487 /***********************************************************************
1488 * INT21_RandomBlockReadFromFCB
1490 * Handler for function 0x27.
1493 * CX [I/O] Number of records to read
1494 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1498 * 1: end of file, no data read
1499 * 2: segment wrap in DTA, no data read (not returned now)
1500 * 3: end of file, partial record read
1503 * Reads several records with the size FCB->logical_record_size from
1504 * the FCB to the disk transfer area. The number of records to be
1505 * read is specified in the CX register. The position of the first
1506 * record is specified with FCB->random_access_record_number. The
1507 * FCB->random_access_record_number, the FCB->current_block_number
1508 * and FCB->record_within_current_block are updated to point to the
1509 * next record after the records read. If a partial record is read,
1510 * it is filled with zeros up to the FCB->logical_record_size. The
1511 * CX register is set to the number of successfully read records.
1513 static void INT21_RandomBlockReadFromFCB( CONTEXT86
*context
)
1518 DWORD record_number
;
1520 BYTE
*disk_transfer_area
;
1521 UINT records_requested
;
1522 UINT bytes_requested
;
1527 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1528 if (fcb
->drive_number
== 0xff) {
1529 xfcb
= (struct XFCB
*) fcb
;
1530 fcb
= (struct FCB
*) xfcb
->fcb
;
1533 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1534 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1535 if (handle
== INVALID_HANDLE_VALUE
) {
1536 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1539 AL_result
= 0x01; /* end of file, no data read */
1541 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1542 if (position
!= record_number
* fcb
->logical_record_size
) {
1543 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1544 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1546 AL_result
= 0x01; /* end of file, no data read */
1548 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1549 records_requested
= CX_reg(context
);
1550 bytes_requested
= (UINT
) records_requested
* fcb
->logical_record_size
;
1551 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1552 if (bytes_read
!= bytes_requested
) {
1553 TRACE("_lread(%d, %p, %d) failed with %d\n",
1554 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_read
);
1555 records_read
= bytes_read
/ fcb
->logical_record_size
;
1556 if (bytes_read
% fcb
->logical_record_size
== 0) {
1557 AL_result
= 0x01; /* end of file, no data read */
1560 memset(&disk_transfer_area
[bytes_read
], 0, records_read
* fcb
->logical_record_size
- bytes_read
);
1561 AL_result
= 0x03; /* end of file, partial record read */
1564 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1565 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1566 records_read
= records_requested
;
1567 AL_result
= 0x00; /* successful */
1571 record_number
+= records_read
;
1572 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1573 fcb
->current_block_number
= record_number
/ 128;
1574 fcb
->record_within_current_block
= record_number
% 128;
1575 SET_CX(context
, records_read
);
1576 SET_AL(context
, AL_result
);
1580 /***********************************************************************
1581 * INT21_RandomBlockWriteToFCB
1583 * Handler for function 0x28.
1586 * CX [I/O] Number of records to write
1587 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1592 * 2: segment wrap in DTA (not returned now)
1595 * Writes several records with the size FCB->logical_record_size from
1596 * the disk transfer area to the FCB. The number of records to be
1597 * written is specified in the CX register. The position of the first
1598 * record is specified with FCB->random_access_record_number. The
1599 * FCB->random_access_record_number, the FCB->current_block_number
1600 * and FCB->record_within_current_block are updated to point to the
1601 * next record after the records written. The CX register is set to
1602 * the number of successfully written records.
1604 static void INT21_RandomBlockWriteToFCB( CONTEXT86
*context
)
1609 DWORD record_number
;
1611 BYTE
*disk_transfer_area
;
1612 UINT records_requested
;
1613 UINT bytes_requested
;
1615 UINT records_written
;
1618 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1619 if (fcb
->drive_number
== 0xff) {
1620 xfcb
= (struct XFCB
*) fcb
;
1621 fcb
= (struct FCB
*) xfcb
->fcb
;
1624 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1625 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1626 if (handle
== INVALID_HANDLE_VALUE
) {
1627 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1629 records_written
= 0;
1630 AL_result
= 0x01; /* disk full */
1632 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1633 if (position
!= record_number
* fcb
->logical_record_size
) {
1634 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1635 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1636 records_written
= 0;
1637 AL_result
= 0x01; /* disk full */
1639 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1640 records_requested
= CX_reg(context
);
1641 bytes_requested
= (UINT
) records_requested
* fcb
->logical_record_size
;
1642 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1643 if (bytes_written
!= bytes_requested
) {
1644 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1645 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_written
);
1646 records_written
= bytes_written
/ fcb
->logical_record_size
;
1647 AL_result
= 0x01; /* disk full */
1649 TRACE("successful write %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1650 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1651 records_written
= records_requested
;
1652 AL_result
= 0x00; /* successful */
1656 record_number
+= records_written
;
1657 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1658 fcb
->current_block_number
= record_number
/ 128;
1659 fcb
->record_within_current_block
= record_number
% 128;
1660 SET_CX(context
, records_written
);
1661 SET_AL(context
, AL_result
);
1665 /***********************************************************************
1666 * INT21_CreateDirectory
1670 * - subfunction 0x39 of function 0x71
1671 * - subfunction 0xff of function 0x43 (CL == 0x39)
1673 static BOOL
INT21_CreateDirectory( CONTEXT86
*context
)
1675 WCHAR dirW
[MAX_PATH
];
1676 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
1680 TRACE( "CREATE DIRECTORY %s\n", dirA
);
1682 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
1684 if (CreateDirectoryW(dirW
, NULL
))
1688 * FIXME: CreateDirectory's LastErrors will clash with the ones
1689 * used by DOS. AH=39 only returns 3 (path not found) and
1690 * 5 (access denied), while CreateDirectory return several
1691 * ones. Remap some of them. -Marcus
1693 switch (GetLastError())
1695 case ERROR_ALREADY_EXISTS
:
1696 case ERROR_FILENAME_EXCED_RANGE
:
1697 case ERROR_DISK_FULL
:
1698 SetLastError(ERROR_ACCESS_DENIED
);
1708 /***********************************************************************
1709 * INT21_ExtendedCountryInformation
1711 * Handler for function 0x65.
1713 static void INT21_ExtendedCountryInformation( CONTEXT86
*context
)
1715 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN( context
, context
->SegEs
, context
->Edi
);
1717 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
1721 * Check subfunctions that are passed country and code page.
1723 if (AL_reg(context
) >= 0x01 && AL_reg(context
) <= 0x07)
1725 WORD country
= DX_reg(context
);
1726 WORD codepage
= BX_reg(context
);
1728 if (country
!= 0xffff && country
!= INT21_GetSystemCountryCode())
1729 FIXME( "Requested info on non-default country %04x\n", country
);
1731 if (codepage
!= 0xffff && codepage
!= GetOEMCP())
1732 FIXME( "Requested info on non-default code page %04x\n", codepage
);
1735 switch (AL_reg(context
)) {
1736 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
1737 INT_BARF( context
, 0x21 );
1738 SET_CFLAG( context
);
1741 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
1742 TRACE( "Get general internationalization info\n" );
1743 dataptr
[0] = 0x01; /* Info ID */
1744 *(WORD
*)(dataptr
+1) = 38; /* Size of the following info */
1745 *(WORD
*)(dataptr
+3) = INT21_GetSystemCountryCode(); /* Country ID */
1746 *(WORD
*)(dataptr
+5) = GetOEMCP(); /* Code page */
1747 INT21_FillCountryInformation( dataptr
+ 7 );
1748 SET_CX( context
, 41 ); /* Size of returned info */
1751 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
1752 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
1753 TRACE( "Get pointer to uppercase table\n" );
1754 dataptr
[0] = AL_reg(context
); /* Info ID */
1755 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1756 offsetof(INT21_HEAP
, uppercase_size
) );
1757 SET_CX( context
, 5 ); /* Size of returned info */
1760 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
1761 TRACE( "Get pointer to lowercase table\n" );
1762 dataptr
[0] = 0x03; /* Info ID */
1763 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1764 offsetof(INT21_HEAP
, lowercase_size
) );
1765 SET_CX( context
, 5 ); /* Size of returned info */
1768 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
1769 TRACE("Get pointer to filename terminator table\n");
1770 dataptr
[0] = 0x05; /* Info ID */
1771 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1772 offsetof(INT21_HEAP
, filename_size
) );
1773 SET_CX( context
, 5 ); /* Size of returned info */
1776 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
1777 TRACE("Get pointer to collating sequence table\n");
1778 dataptr
[0] = 0x06; /* Info ID */
1779 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1780 offsetof(INT21_HEAP
, collating_size
) );
1781 SET_CX( context
, 5 ); /* Size of returned info */
1784 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
1785 TRACE("Get pointer to DBCS lead byte table\n");
1786 dataptr
[0] = 0x07; /* Info ID */
1787 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1788 offsetof(INT21_HEAP
, dbcs_size
) );
1789 SET_CX( context
, 5 ); /* Size of returned info */
1792 case 0x20: /* CAPITALIZE CHARACTER */
1793 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
1794 TRACE("Convert char to uppercase\n");
1795 SET_DL( context
, toupper(DL_reg(context
)) );
1798 case 0x21: /* CAPITALIZE STRING */
1799 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
1800 TRACE("Convert string to uppercase with length\n");
1802 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN( context
,
1805 WORD len
= CX_reg(context
);
1806 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
1810 case 0x22: /* CAPITALIZE ASCIIZ STRING */
1811 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
1812 TRACE("Convert ASCIIZ string to uppercase\n");
1813 _strupr( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
) );
1816 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
1817 INT_BARF( context
, 0x21 );
1818 SET_CFLAG( context
);
1822 INT_BARF( context
, 0x21 );
1829 /***********************************************************************
1830 * INT21_FileAttributes
1834 * - subfunction 0x43 of function 0x71
1836 static BOOL
INT21_FileAttributes( CONTEXT86
*context
,
1840 WCHAR fileW
[MAX_PATH
];
1841 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
1850 switch (subfunction
)
1852 case 0x00: /* GET FILE ATTRIBUTES */
1853 TRACE( "GET FILE ATTRIBUTES for %s\n", fileA
);
1854 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1856 result
= GetFileAttributesW( fileW
);
1857 if (result
== INVALID_FILE_ATTRIBUTES
)
1861 SET_CX( context
, (WORD
)result
);
1863 SET_AX( context
, (WORD
)result
); /* DR DOS */
1867 case 0x01: /* SET FILE ATTRIBUTES */
1868 TRACE( "SET FILE ATTRIBUTES 0x%02x for %s\n",
1869 CX_reg(context
), fileA
);
1870 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1872 if (!SetFileAttributesW( fileW
, CX_reg(context
) ))
1876 case 0x02: /* GET COMPRESSED FILE SIZE */
1877 TRACE( "GET COMPRESSED FILE SIZE for %s\n", fileA
);
1878 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1880 result
= GetCompressedFileSizeW( fileW
, NULL
);
1881 if (result
== INVALID_FILE_SIZE
)
1885 SET_AX( context
, LOWORD(result
) );
1886 SET_DX( context
, HIWORD(result
) );
1890 case 0x03: /* SET FILE LAST-WRITTEN DATE AND TIME */
1892 INT_BARF( context
, 0x21 );
1895 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
1896 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1898 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
1899 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1900 NULL
, OPEN_EXISTING
, 0, 0 );
1901 if (handle
== INVALID_HANDLE_VALUE
)
1904 DosDateTimeToFileTime( DI_reg(context
),
1907 status
= SetFileTime( handle
, NULL
, NULL
, &filetime
);
1909 CloseHandle( handle
);
1914 case 0x04: /* GET FILE LAST-WRITTEN DATE AND TIME */
1916 INT_BARF( context
, 0x21 );
1919 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
1920 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1922 handle
= CreateFileW( fileW
, GENERIC_READ
,
1923 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1924 NULL
, OPEN_EXISTING
, 0, 0 );
1925 if (handle
== INVALID_HANDLE_VALUE
)
1928 status
= GetFileTime( handle
, NULL
, NULL
, &filetime
);
1931 FileTimeToDosDateTime( &filetime
, &date
, &time
);
1932 SET_DI( context
, date
);
1933 SET_CX( context
, time
);
1936 CloseHandle( handle
);
1941 case 0x05: /* SET FILE LAST ACCESS DATE */
1943 INT_BARF( context
, 0x21 );
1946 TRACE( "SET FILE LAST ACCESS DATE, file %s\n", fileA
);
1947 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1949 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
1950 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1951 NULL
, OPEN_EXISTING
, 0, 0 );
1952 if (handle
== INVALID_HANDLE_VALUE
)
1955 DosDateTimeToFileTime( DI_reg(context
),
1958 status
= SetFileTime( handle
, NULL
, &filetime
, NULL
);
1960 CloseHandle( handle
);
1965 case 0x06: /* GET FILE LAST ACCESS DATE */
1967 INT_BARF( context
, 0x21 );
1970 TRACE( "GET FILE LAST ACCESS DATE, file %s\n", fileA
);
1971 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
1973 handle
= CreateFileW( fileW
, GENERIC_READ
,
1974 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
1975 NULL
, OPEN_EXISTING
, 0, 0 );
1976 if (handle
== INVALID_HANDLE_VALUE
)
1979 status
= GetFileTime( handle
, NULL
, &filetime
, NULL
);
1982 FileTimeToDosDateTime( &filetime
, &date
, NULL
);
1983 SET_DI( context
, date
);
1986 CloseHandle( handle
);
1991 case 0x07: /* SET FILE CREATION DATE AND TIME */
1993 INT_BARF( context
, 0x21 );
1996 TRACE( "SET FILE CREATION DATE AND TIME, file %s\n", fileA
);
1998 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
1999 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2000 NULL
, OPEN_EXISTING
, 0, 0 );
2001 if (handle
== INVALID_HANDLE_VALUE
)
2005 * FIXME: SI has number of 10-millisecond units past time in CX.
2007 DosDateTimeToFileTime( DI_reg(context
),
2010 status
= SetFileTime( handle
, &filetime
, NULL
, NULL
);
2012 CloseHandle( handle
);
2017 case 0x08: /* GET FILE CREATION DATE AND TIME */
2019 INT_BARF( context
, 0x21 );
2022 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2025 handle
= CreateFileW( fileW
, GENERIC_READ
,
2026 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2027 NULL
, OPEN_EXISTING
, 0, 0 );
2028 if (handle
== INVALID_HANDLE_VALUE
)
2031 status
= GetFileTime( handle
, &filetime
, NULL
, NULL
);
2034 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2035 SET_DI( context
, date
);
2036 SET_CX( context
, time
);
2038 * FIXME: SI has number of 10-millisecond units past
2041 SET_SI( context
, 0 );
2044 CloseHandle(handle
);
2049 case 0xff: /* EXTENDED-LENGTH FILENAME OPERATIONS */
2050 if (islong
|| context
->Ebp
!= 0x5053)
2051 INT_BARF( context
, 0x21 );
2054 switch(CL_reg(context
))
2057 if (!INT21_CreateDirectory( context
))
2062 if (!INT21_RenameFile( context
))
2067 INT_BARF( context
, 0x21 );
2073 INT_BARF( context
, 0x21 );
2080 /***********************************************************************
2081 * INT21_FileDateTime
2083 * Handler for function 0x57.
2085 static BOOL
INT21_FileDateTime( CONTEXT86
*context
)
2087 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2091 switch (AL_reg(context
)) {
2092 case 0x00: /* Get last-written stamp */
2093 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2096 if (!GetFileTime( handle
, NULL
, NULL
, &filetime
))
2098 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2099 SET_DX( context
, date
);
2100 SET_CX( context
, time
);
2104 case 0x01: /* Set last-written stamp */
2105 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2108 DosDateTimeToFileTime( DX_reg(context
),
2111 if (!SetFileTime( handle
, NULL
, NULL
, &filetime
))
2116 case 0x04: /* Get last access stamp, DOS 7 */
2117 TRACE( "GET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2120 if (!GetFileTime( handle
, NULL
, &filetime
, NULL
))
2122 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2123 SET_DX( context
, date
);
2124 SET_CX( context
, time
);
2128 case 0x05: /* Set last access stamp, DOS 7 */
2129 TRACE( "SET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2132 DosDateTimeToFileTime( DX_reg(context
),
2135 if (!SetFileTime( handle
, NULL
, &filetime
, NULL
))
2140 case 0x06: /* Get creation stamp, DOS 7 */
2141 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2144 if (!GetFileTime( handle
, &filetime
, NULL
, NULL
))
2146 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2147 SET_DX( context
, date
);
2148 SET_CX( context
, time
);
2150 * FIXME: SI has number of 10-millisecond units past time in CX.
2152 SET_SI( context
, 0 );
2156 case 0x07: /* Set creation stamp, DOS 7 */
2157 TRACE( "SET FILE CREATION DATE AND TIME, handle %d\n",
2161 * FIXME: SI has number of 10-millisecond units past time in CX.
2163 DosDateTimeToFileTime( DX_reg(context
),
2166 if (!SetFileTime( handle
, &filetime
, NULL
, NULL
))
2172 INT_BARF( context
, 0x21 );
2180 /***********************************************************************
2183 * Handler for functions 0x51 and 0x62.
2185 static void INT21_GetPSP( CONTEXT86
*context
)
2187 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context
) );
2190 * FIXME: should we return the original DOS PSP upon
2193 if (!ISV86(context
) && DOSVM_IsWin16())
2194 SET_BX( context
, LOWORD(GetCurrentPDB16()) );
2196 SET_BX( context
, DOSVM_psp
);
2199 static inline void setword( BYTE
*ptr
, WORD w
)
2202 ptr
[1] = (BYTE
)(w
>> 8);
2205 static void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
2206 /* limited == TRUE is used with INT 0x21/0x440d */
2208 /* FIXME: we're forcing some values without checking that those are valid */
2213 setword(&data
[3], 0);
2215 setword(&data
[6], 240);
2216 setword(&data
[8], 64000);
2218 setword(&data
[0x0b], 40);
2219 setword(&data
[0x0d], 56);
2220 setword(&data
[0x0f], 2);
2221 setword(&data
[0x11], 0);
2224 setword(&data
[0x1f], 800);
2226 setword(&data
[0x22], 1);
2233 setword(&data
[3], 0);
2235 setword(&data
[6], 240);
2236 setword(&data
[8], 2880);
2238 setword(&data
[0x0b], 6);
2239 setword(&data
[0x0d], 18);
2240 setword(&data
[0x0f], 2);
2241 setword(&data
[0x11], 0);
2244 setword(&data
[0x1f], 80);
2246 setword(&data
[0x22], 2);
2251 /***********************************************************************
2254 * Handler for block device IOCTLs.
2256 static void INT21_Ioctl_Block( CONTEXT86
*context
)
2259 BYTE drive
= INT21_MapDrive( BL_reg(context
) );
2260 WCHAR drivespec
[4] = {'A', ':', '\\', 0};
2263 drivespec
[0] += drive
;
2264 drivetype
= GetDriveTypeW( drivespec
);
2266 RESET_CFLAG(context
);
2267 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
2269 TRACE( "IOCTL - SUBFUNCTION %d - INVALID DRIVE %c:\n",
2270 AL_reg(context
), 'A' + drive
);
2271 SetLastError( ERROR_INVALID_DRIVE
);
2272 SET_AX( context
, ERROR_INVALID_DRIVE
);
2273 SET_CFLAG( context
);
2277 switch (AL_reg(context
))
2279 case 0x04: /* READ FROM BLOCK DEVICE CONTROL CHANNEL */
2280 case 0x05: /* WRITE TO BLOCK DEVICE CONTROL CHANNEL */
2281 INT_BARF( context
, 0x21 );
2284 case 0x08: /* CHECK IF BLOCK DEVICE REMOVABLE */
2285 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOVABLE - %c:\n",
2288 if (drivetype
== DRIVE_REMOVABLE
)
2289 SET_AX( context
, 0 ); /* removable */
2291 SET_AX( context
, 1 ); /* not removable */
2294 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
2295 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOTE - %c:\n",
2298 if (drivetype
== DRIVE_REMOTE
)
2299 SET_DX( context
, (1<<9) | (1<<12) ); /* remote + no direct IO */
2301 SET_DX( context
, 0 ); /* FIXME: use driver attr here */
2304 case 0x0d: /* GENERIC BLOCK DEVICE REQUEST */
2305 /* Get pointer to IOCTL parameter block. */
2306 dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2308 switch (CX_reg(context
))
2310 case 0x0841: /* write logical device track */
2311 TRACE( "GENERIC IOCTL - Write logical device track - %c:\n",
2314 WORD head
= *(WORD
*)dataptr
+1;
2315 WORD cyl
= *(WORD
*)dataptr
+3;
2316 WORD sect
= *(WORD
*)dataptr
+5;
2317 WORD nrsect
= *(WORD
*)dataptr
+7;
2318 BYTE
*data
= (BYTE
*)dataptr
+9; /* FIXME: is this correct? */
2320 if (!DOSVM_RawWrite(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
2322 SET_AX( context
, ERROR_WRITE_FAULT
);
2328 case 0x084a: /* lock logical volume */
2329 TRACE( "GENERIC IOCTL - Lock logical volume, level %d mode %d - %c:\n",
2330 BH_reg(context
), DX_reg(context
), 'A' + drive
);
2333 case 0x0860: /* get device parameters */
2334 /* FIXME: we're faking some values here */
2335 /* used by w4wgrp's winfile */
2336 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
2338 dataptr
[6] = 0; /* media type */
2341 dataptr
[1] = 0x05; /* fixed disk */
2342 setword(&dataptr
[2], 0x01); /* non removable */
2343 setword(&dataptr
[4], 0x300); /* # of cylinders */
2347 dataptr
[1] = 0x07; /* block dev, floppy */
2348 setword(&dataptr
[2], 0x02); /* removable */
2349 setword(&dataptr
[4], 80); /* # of cylinders */
2351 CreateBPB(drive
, &dataptr
[7], TRUE
);
2352 RESET_CFLAG(context
);
2355 case 0x0861: /* read logical device track */
2356 TRACE( "GENERIC IOCTL - Read logical device track - %c:\n",
2359 WORD head
= *(WORD
*)dataptr
+1;
2360 WORD cyl
= *(WORD
*)dataptr
+3;
2361 WORD sect
= *(WORD
*)dataptr
+5;
2362 WORD nrsect
= *(WORD
*)dataptr
+7;
2363 BYTE
*data
= (BYTE
*)dataptr
+9; /* FIXME: is this correct? */
2365 if (!DOSVM_RawRead(drive
, head
*cyl
*sect
, nrsect
, data
, FALSE
))
2367 SET_AX( context
, ERROR_READ_FAULT
);
2373 case 0x0866: /* get volume serial number */
2375 WCHAR label
[12],fsname
[9];
2378 drivespec
[0] += drive
;
2379 GetVolumeInformationW(drivespec
, label
, 12, &serial
, NULL
, NULL
, fsname
, 9);
2380 *(WORD
*)dataptr
= 0;
2381 memcpy(dataptr
+2,&serial
,4);
2382 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, dataptr
+ 6, 11, NULL
, NULL
);
2383 WideCharToMultiByte(CP_OEMCP
, 0, fsname
, 8, dataptr
+ 17, 8, NULL
, NULL
);
2387 case 0x086a: /* unlock logical volume */
2388 TRACE( "GENERIC IOCTL - Logical volume unlocked - %c:\n",
2392 case 0x086f: /* get drive map information */
2393 memset(dataptr
+1, '\0', dataptr
[0]-1);
2394 dataptr
[1] = dataptr
[0];
2395 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
2396 dataptr
[3] = 0xFF; /* no physical drive */
2400 /* Trail on error implementation */
2401 SET_AX( context
, drivetype
== DRIVE_UNKNOWN
? 0x0f : 0x01 );
2402 SET_CFLAG(context
); /* Seems to be set all the time */
2406 INT_BARF( context
, 0x21 );
2410 case 0x0e: /* GET LOGICAL DRIVE MAP */
2411 TRACE( "IOCTL - GET LOGICAL DRIVE MAP - %c:\n",
2413 /* FIXME: this is not correct if drive has mappings */
2414 SET_AL( context
, 0 ); /* drive has no mapping */
2417 case 0x0f: /* SET LOGICAL DRIVE MAP */
2419 WCHAR dev
[3], tgt
[4];
2421 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
2422 INT21_DriveName( BL_reg(context
)));
2423 dev
[0] = 'A' + drive
; dev
[1] = ':'; dev
[2] = 0;
2424 tgt
[0] = 'A' + drive
+ 1; dev
[1] = ':'; dev
[2] = '\\'; dev
[3] = 0;
2425 if (!DefineDosDeviceW(DDD_RAW_TARGET_PATH
, dev
, tgt
))
2428 SET_AX( context
, 0x000F ); /* invalid drive */
2433 case 0x11: /* QUERY GENERIC IOCTL CAPABILITY */
2435 INT_BARF( context
, 0x21 );
2440 /***********************************************************************
2443 * Handler for character device IOCTLs.
2445 static void INT21_Ioctl_Char( CONTEXT86
*context
)
2447 static const WCHAR emmxxxx0W
[] = {'E','M','M','X','X','X','X','0',0};
2448 static const WCHAR scsimgrW
[] = {'S','C','S','I','M','G','R','$',0};
2450 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2451 const DOS_DEVICE
*dev
= DOSFS_GetDeviceByHandle(handle
);
2453 if (dev
&& !strcmpiW( dev
->name
, emmxxxx0W
))
2455 EMS_Ioctl_Handler(context
);
2459 if (dev
&& !strcmpiW( dev
->name
, scsimgrW
) && AL_reg(context
) == 2)
2461 DOSVM_ASPIHandler(context
);
2465 switch (AL_reg(context
))
2467 case 0x00: /* GET DEVICE INFORMATION */
2468 TRACE( "IOCTL - GET DEVICE INFORMATION - %d\n", BX_reg(context
) );
2472 * Returns attribute word in DX:
2473 * Bit 14 - Device driver can process IOCTL requests.
2474 * Bit 13 - Output until busy supported.
2475 * Bit 11 - Driver supports OPEN/CLOSE calls.
2477 * Bit 7 - Set (indicates device).
2478 * Bit 6 - EOF on input.
2479 * Bit 5 - Raw (binary) mode.
2480 * Bit 4 - Device is special (uses int29).
2481 * Bit 3 - Clock device.
2482 * Bit 2 - NUL device.
2483 * Bit 1 - Standard output.
2484 * Bit 0 - Standard input.
2486 SET_DX( context
, dev
->flags
);
2491 * Returns attribute word in DX:
2492 * Bit 15 - File is remote.
2493 * Bit 14 - Don't set file date/time on closing.
2494 * Bit 11 - Media not removable.
2495 * Bit 8 - Generate int24 if no disk space on write
2496 * or read past end of file
2497 * Bit 7 - Clear (indicates file).
2498 * Bit 6 - File has not been written.
2499 * Bit 5..0 - Drive number (0=A:,...)
2501 * FIXME: Should check if file is on remote or removable drive.
2502 * FIXME: Should use drive file is located on (and not current).
2504 SET_DX( context
, 0x0140 + INT21_GetCurrentDrive() );
2508 case 0x01: /* SET DEVICE INFORMATION */
2509 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2510 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2511 case 0x06: /* GET INPUT STATUS */
2512 case 0x07: /* GET OUTPUT STATUS */
2513 INT_BARF( context
, 0x21 );
2516 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2517 TRACE( "IOCTL - CHECK IF HANDLE IS REMOTE - %d\n", BX_reg(context
) );
2519 * Returns attribute word in DX:
2520 * Bit 15 - Set if remote.
2521 * Bit 14 - Set if date/time not set on close.
2523 * FIXME: Should check if file is on remote drive.
2525 SET_DX( context
, 0 );
2528 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2529 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2531 INT_BARF( context
, 0x21 );
2536 /***********************************************************************
2539 * Handler for function 0x44.
2541 static void INT21_Ioctl( CONTEXT86
*context
)
2543 switch (AL_reg(context
))
2549 INT21_Ioctl_Char( context
);
2554 INT21_Ioctl_Block( context
);
2559 INT21_Ioctl_Char( context
);
2564 INT21_Ioctl_Block( context
);
2568 INT21_Ioctl_Char( context
);
2571 case 0x0b: /* SET SHARING RETRY COUNT */
2572 TRACE( "SET SHARING RETRY COUNT: Pause %d, retries %d.\n",
2573 CX_reg(context
), DX_reg(context
) );
2574 if (!CX_reg(context
))
2576 SET_AX( context
, 1 );
2577 SET_CFLAG( context
);
2581 DOSDEV_SetSharingRetry( CX_reg(context
), DX_reg(context
) );
2582 RESET_CFLAG( context
);
2587 INT21_Ioctl_Char( context
);
2593 INT21_Ioctl_Block( context
);
2597 INT21_Ioctl_Char( context
);
2601 INT21_Ioctl_Block( context
);
2604 case 0x12: /* DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION) */
2605 TRACE( "DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION)\n" );
2606 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2607 SET_AX( context
, 0x0001 ); /* Invalid function */
2610 case 0x52: /* DR DOS - DETERMINE DOS TYPE */
2611 TRACE( "DR DOS - DETERMINE DOS TYPE\n" );
2612 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2613 SET_AX( context
, 0x0001 ); /* Invalid function */
2616 case 0xe0: /* Sun PC-NFS API */
2617 TRACE( "Sun PC-NFS API\n" );
2622 INT_BARF( context
, 0x21 );
2627 /***********************************************************************
2630 * Handler for function 0x73.
2632 static BOOL
INT21_Fat32( CONTEXT86
*context
)
2634 switch (AL_reg(context
))
2636 case 0x02: /* FAT32 - GET EXTENDED DPB */
2638 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
2639 WORD
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
2640 context
->SegEs
, context
->Edi
);
2641 INT21_DPB
*target
= (INT21_DPB
*)(ptr
+ 1);
2644 TRACE( "FAT32 - GET EXTENDED DPB %d\n", DL_reg(context
) );
2646 if ( CX_reg(context
) < sizeof(INT21_DPB
) + 2 || *ptr
< sizeof(INT21_DPB
) )
2648 SetLastError( ERROR_BAD_LENGTH
);
2652 if ( !INT21_FillDrivePB( drive
) )
2654 SetLastError( ERROR_INVALID_DRIVE
);
2658 source
= &INT21_GetHeapPointer()->misc_dpb_list
[drive
];
2660 *ptr
= sizeof(INT21_DPB
);
2661 memcpy( target
, source
, sizeof(INT21_DPB
));
2663 if (LOWORD(context
->Esi
) != 0xF1A6)
2665 target
->driver_header
= 0;
2670 FIXME( "Caller requested driver and next DPB pointers!\n" );
2675 case 0x03: /* FAT32 - GET EXTENDED FREE SPACE ON DRIVE */
2677 WCHAR dirW
[MAX_PATH
];
2678 char *dirA
= CTX_SEG_OFF_TO_LIN( context
,
2679 context
->SegDs
, context
->Edx
);
2680 BYTE
*data
= CTX_SEG_OFF_TO_LIN( context
,
2681 context
->SegEs
, context
->Edi
);
2682 DWORD cluster_sectors
;
2684 DWORD free_clusters
;
2685 DWORD total_clusters
;
2687 TRACE( "FAT32 - GET EXTENDED FREE SPACE ON DRIVE %s\n", dirA
);
2688 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
2690 if (CX_reg(context
) < 44)
2692 SetLastError( ERROR_BAD_LENGTH
);
2696 if (!GetDiskFreeSpaceW( dirW
, &cluster_sectors
, §or_bytes
,
2697 &free_clusters
, &total_clusters
))
2700 *(WORD
*) (data
+ 0) = 44; /* size of structure */
2701 *(WORD
*) (data
+ 2) = 0; /* version */
2702 *(DWORD
*)(data
+ 4) = cluster_sectors
;
2703 *(DWORD
*)(data
+ 8) = sector_bytes
;
2704 *(DWORD
*)(data
+ 12) = free_clusters
;
2705 *(DWORD
*)(data
+ 16) = total_clusters
;
2708 * Below we have free/total sectors and
2709 * free/total allocation units without adjustment
2710 * for compression. We fake both using cluster information.
2712 *(DWORD
*)(data
+ 20) = free_clusters
* cluster_sectors
;
2713 *(DWORD
*)(data
+ 24) = total_clusters
* cluster_sectors
;
2714 *(DWORD
*)(data
+ 28) = free_clusters
;
2715 *(DWORD
*)(data
+ 32) = total_clusters
;
2718 * Between (data + 36) and (data + 43) there
2719 * are eight reserved bytes.
2725 INT_BARF( context
, 0x21 );
2731 static void INT21_ConvertFindDataWtoA(WIN32_FIND_DATAA
*dataA
,
2732 const WIN32_FIND_DATAW
*dataW
)
2734 dataA
->dwFileAttributes
= dataW
->dwFileAttributes
;
2735 dataA
->ftCreationTime
= dataW
->ftCreationTime
;
2736 dataA
->ftLastAccessTime
= dataW
->ftLastAccessTime
;
2737 dataA
->ftLastWriteTime
= dataW
->ftLastWriteTime
;
2738 dataA
->nFileSizeHigh
= dataW
->nFileSizeHigh
;
2739 dataA
->nFileSizeLow
= dataW
->nFileSizeLow
;
2740 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cFileName
, -1,
2741 dataA
->cFileName
, sizeof(dataA
->cFileName
), NULL
, NULL
);
2742 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cAlternateFileName
, -1,
2743 dataA
->cAlternateFileName
, sizeof(dataA
->cAlternateFileName
), NULL
, NULL
);
2746 /***********************************************************************
2747 * INT21_LongFilename
2749 * Handler for function 0x71.
2751 static void INT21_LongFilename( CONTEXT86
*context
)
2753 BOOL bSetDOSExtendedError
= FALSE
;
2754 WCHAR pathW
[MAX_PATH
];
2757 if (HIBYTE(HIWORD(GetVersion16())) < 0x07)
2759 TRACE( "LONG FILENAME - functions supported only under DOS7\n" );
2760 SET_CFLAG( context
);
2761 SET_AL( context
, 0 );
2765 switch (AL_reg(context
))
2767 case 0x0d: /* RESET DRIVE */
2768 INT_BARF( context
, 0x21 );
2771 case 0x39: /* LONG FILENAME - MAKE DIRECTORY */
2772 if (!INT21_CreateDirectory( context
))
2773 bSetDOSExtendedError
= TRUE
;
2776 case 0x3a: /* LONG FILENAME - REMOVE DIRECTORY */
2777 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2779 TRACE( "LONG FILENAME - REMOVE DIRECTORY %s\n", pathA
);
2780 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
2781 if (!RemoveDirectoryW( pathW
)) bSetDOSExtendedError
= TRUE
;
2784 case 0x3b: /* LONG FILENAME - CHANGE DIRECTORY */
2785 if (!INT21_SetCurrentDirectory( context
))
2786 bSetDOSExtendedError
= TRUE
;
2789 case 0x41: /* LONG FILENAME - DELETE FILE */
2790 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2792 TRACE( "LONG FILENAME - DELETE FILE %s\n", pathA
);
2793 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
2795 if (!DeleteFileW( pathW
)) bSetDOSExtendedError
= TRUE
;
2798 case 0x43: /* LONG FILENAME - EXTENDED GET/SET FILE ATTRIBUTES */
2799 if (!INT21_FileAttributes( context
, BL_reg(context
), TRUE
))
2800 bSetDOSExtendedError
= TRUE
;
2803 case 0x47: /* LONG FILENAME - GET CURRENT DIRECTORY */
2804 if (!INT21_GetCurrentDirectory( context
, TRUE
))
2805 bSetDOSExtendedError
= TRUE
;
2808 case 0x4e: /* LONG FILENAME - FIND FIRST MATCHING FILE */
2812 WIN32_FIND_DATAW dataW
;
2813 WIN32_FIND_DATAA
* dataA
;
2815 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
2816 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n", pathA
);
2818 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
2819 handle
= FindFirstFileW(pathW
, &dataW
);
2821 dataA
= (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2823 if (handle
!= INVALID_HANDLE_VALUE
&&
2824 (h16
= GlobalAlloc16(GMEM_MOVEABLE
, sizeof(handle
))))
2826 HANDLE
* ptr
= GlobalLock16( h16
);
2828 GlobalUnlock16( h16
);
2829 SET_AX( context
, h16
);
2830 INT21_ConvertFindDataWtoA(dataA
, &dataW
);
2834 if (handle
!= INVALID_HANDLE_VALUE
) FindClose(handle
);
2835 SET_AX( context
, INVALID_HANDLE_VALUE16
);
2836 bSetDOSExtendedError
= TRUE
;
2841 case 0x4f: /* LONG FILENAME - FIND NEXT MATCHING FILE */
2843 HGLOBAL16 h16
= BX_reg(context
);
2845 WIN32_FIND_DATAW dataW
;
2846 WIN32_FIND_DATAA
* dataA
;
2848 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2851 dataA
= (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
2854 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
2856 if (!FindNextFileW(*ptr
, &dataW
)) bSetDOSExtendedError
= TRUE
;
2857 else INT21_ConvertFindDataWtoA(dataA
, &dataW
);
2858 GlobalUnlock16( h16
);
2862 SetLastError( ERROR_INVALID_HANDLE
);
2863 bSetDOSExtendedError
= TRUE
;
2868 case 0x56: /* LONG FILENAME - RENAME FILE */
2869 if (!INT21_RenameFile(context
))
2870 bSetDOSExtendedError
= TRUE
;
2873 case 0x60: /* LONG FILENAME - CONVERT PATH */
2875 WCHAR res
[MAX_PATH
];
2877 switch (CL_reg(context
))
2879 case 0x01: /* Get short filename or path */
2880 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
2881 if (!GetShortPathNameW(pathW
, res
, 67))
2882 bSetDOSExtendedError
= TRUE
;
2885 SET_AX( context
, 0 );
2886 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
2887 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
2892 case 0x02: /* Get canonical long filename or path */
2893 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
2894 if (!GetFullPathNameW(pathW
, 128, res
, NULL
))
2895 bSetDOSExtendedError
= TRUE
;
2898 SET_AX( context
, 0 );
2899 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
2900 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
2905 FIXME("Unimplemented long file name function:\n");
2906 INT_BARF( context
, 0x21 );
2908 SET_AL( context
, 0 );
2914 case 0x6c: /* LONG FILENAME - CREATE OR OPEN FILE */
2915 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
2916 BX_reg(context
), DL_reg(context
) ))
2917 bSetDOSExtendedError
= TRUE
;
2920 case 0xa0: /* LONG FILENAME - GET VOLUME INFORMATION */
2922 DWORD filename_len
, flags
;
2925 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
2927 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", pathA
);
2928 SET_AX( context
, 0 );
2929 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
2930 if (!GetVolumeInformationW( pathW
, NULL
, 0, NULL
, &filename_len
,
2933 INT_BARF( context
, 0x21 );
2937 SET_BX( context
, flags
| 0x4000 ); /* support for LFN functions */
2938 SET_CX( context
, filename_len
);
2939 SET_DX( context
, MAX_PATH
); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2940 WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1,
2941 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
2946 case 0xa1: /* LONG FILENAME - "FindClose" - TERMINATE DIRECTORY SEARCH */
2948 HGLOBAL16 h16
= BX_reg(context
);
2951 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2953 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
2955 if (!FindClose( *ptr
)) bSetDOSExtendedError
= TRUE
;
2956 GlobalUnlock16( h16
);
2957 GlobalFree16( h16
);
2961 SetLastError( ERROR_INVALID_HANDLE
);
2962 bSetDOSExtendedError
= TRUE
;
2967 case 0xa6: /* LONG FILENAME - GET FILE INFO BY HANDLE */
2969 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2970 BY_HANDLE_FILE_INFORMATION
*info
=
2971 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2973 TRACE( "LONG FILENAME - GET FILE INFO BY HANDLE\n" );
2975 if (!GetFileInformationByHandle(handle
, info
))
2976 bSetDOSExtendedError
= TRUE
;
2980 case 0xa7: /* LONG FILENAME - CONVERT TIME */
2981 switch (BL_reg(context
))
2983 case 0x00: /* FILE TIME TO DOS TIME */
2986 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
2990 TRACE( "LONG FILENAME - FILE TIME TO DOS TIME\n" );
2992 FileTimeToDosDateTime( filetime
, &date
, &time
);
2994 SET_DX( context
, date
);
2995 SET_CX( context
, time
);
2998 * FIXME: BH has number of 10-millisecond units
3001 SET_BH( context
, 0 );
3005 case 0x01: /* DOS TIME TO FILE TIME */
3007 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3011 TRACE( "LONG FILENAME - DOS TIME TO FILE TIME\n" );
3014 * FIXME: BH has number of 10-millisecond units
3017 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
3023 INT_BARF( context
, 0x21 );
3028 case 0xa8: /* LONG FILENAME - GENERATE SHORT FILENAME */
3029 case 0xa9: /* LONG FILENAME - SERVER CREATE OR OPEN FILE */
3030 case 0xaa: /* LONG FILENAME - SUBST */
3032 FIXME("Unimplemented long file name function:\n");
3033 INT_BARF( context
, 0x21 );
3035 SET_AL( context
, 0 );
3039 if (bSetDOSExtendedError
)
3041 SET_AX( context
, GetLastError() );
3042 SET_CFLAG( context
);
3047 /***********************************************************************
3052 * - subfunction 0x56 of function 0x71
3053 * - subfunction 0xff of function 0x43 (CL == 0x56)
3055 static BOOL
INT21_RenameFile( CONTEXT86
*context
)
3057 WCHAR fromW
[MAX_PATH
];
3058 WCHAR toW
[MAX_PATH
];
3059 char *fromA
= CTX_SEG_OFF_TO_LIN(context
,
3060 context
->SegDs
,context
->Edx
);
3061 char *toA
= CTX_SEG_OFF_TO_LIN(context
,
3062 context
->SegEs
,context
->Edi
);
3064 TRACE( "RENAME FILE %s to %s\n", fromA
, toA
);
3065 MultiByteToWideChar(CP_OEMCP
, 0, fromA
, -1, fromW
, MAX_PATH
);
3066 MultiByteToWideChar(CP_OEMCP
, 0, toA
, -1, toW
, MAX_PATH
);
3068 return MoveFileW( fromW
, toW
);
3072 /***********************************************************************
3078 static BOOL
INT21_NetworkFunc (CONTEXT86
*context
)
3080 switch (AL_reg(context
))
3082 case 0x00: /* Get machine name. */
3084 WCHAR dstW
[MAX_COMPUTERNAME_LENGTH
+ 1];
3085 DWORD s
= sizeof(dstW
) / sizeof(WCHAR
);
3088 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
3089 TRACE("getting machine name to %p\n", dst
);
3090 if (!GetComputerNameW(dstW
, &s
) ||
3091 !WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1, dst
, 16, NULL
, NULL
))
3094 SetLastError( ER_NoNetwork
);
3097 for (len
= strlen(dst
); len
< 15; len
++) dst
[len
] = ' ';
3099 SET_CH( context
, 1 ); /* Valid */
3100 SET_CL( context
, 1 ); /* NETbios number??? */
3101 TRACE("returning %s\n", debugstr_an(dst
, 16));
3106 SetLastError( ER_NoNetwork
);
3111 /******************************************************************
3112 * INT21_GetDiskSerialNumber
3115 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
3117 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3118 WCHAR path
[] = {'A',':',0}, label
[11];
3121 path
[0] += INT21_MapDrive(BL_reg(context
));
3122 if (!GetVolumeInformationW( path
, label
, 11, &serial
, NULL
, NULL
, NULL
, 0))
3124 SetLastError( ERROR_INVALID_DRIVE
);
3128 *(WORD
*)dataptr
= 0;
3129 memcpy(dataptr
+ 2, &serial
, sizeof(DWORD
));
3130 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, dataptr
+ 6, 11, NULL
, NULL
);
3131 strncpy(dataptr
+ 17, "FAT16 ", 8);
3136 /******************************************************************
3137 * INT21_SetDiskSerialNumber
3140 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
3143 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3144 int drive
= INT21_MapDrive(BL_reg(context
));
3146 if (!is_valid_drive(drive
))
3148 SetLastError( ERROR_INVALID_DRIVE
);
3152 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
3155 FIXME("Setting drive serial number is no longer supported\n");
3156 SetLastError( ERROR_NOT_SUPPORTED
);
3162 /******************************************************************
3163 * INT21_GetFreeDiskSpace
3166 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
3168 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
3169 WCHAR root
[] = {'A',':','\\',0};
3171 root
[0] += INT21_MapDrive(DL_reg(context
));
3172 if (!GetDiskFreeSpaceW( root
, &cluster_sectors
, §or_bytes
,
3173 &free_clusters
, &total_clusters
)) return 0;
3174 SET_AX( context
, cluster_sectors
);
3175 SET_BX( context
, free_clusters
);
3176 SET_CX( context
, sector_bytes
);
3177 SET_DX( context
, total_clusters
);
3181 /******************************************************************
3182 * INT21_GetDriveAllocInfo
3185 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
, int drive
)
3189 if (!INT21_FillDrivePB( drive
)) return 0;
3190 dpb
= &(INT21_GetHeapPointer()->misc_dpb_list
[drive
]);
3191 SET_AL( context
, dpb
->cluster_sectors
+ 1 );
3192 SET_CX( context
, dpb
->sector_bytes
);
3193 SET_DX( context
, dpb
->num_clusters1
);
3195 context
->SegDs
= INT21_GetHeapSelector( context
);
3196 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
].media_ID
) );
3200 /***********************************************************************
3201 * INT21_GetExtendedError
3203 static void INT21_GetExtendedError( CONTEXT86
*context
)
3205 BYTE
class, action
, locus
;
3206 WORD error
= GetLastError();
3211 class = action
= locus
= 0;
3213 case ERROR_DIR_NOT_EMPTY
:
3218 case ERROR_ACCESS_DENIED
:
3219 class = EC_AccessDenied
;
3223 case ERROR_CANNOT_MAKE
:
3224 class = EC_AccessDenied
;
3228 case ERROR_DISK_FULL
:
3229 case ERROR_HANDLE_DISK_FULL
:
3230 class = EC_MediaError
;
3234 case ERROR_FILE_EXISTS
:
3235 case ERROR_ALREADY_EXISTS
:
3240 case ERROR_FILE_NOT_FOUND
:
3241 class = EC_NotFound
;
3245 case ERROR_GEN_FAILURE
:
3246 class = EC_SystemFailure
;
3250 case ERROR_INVALID_DRIVE
:
3251 class = EC_MediaError
;
3255 case ERROR_INVALID_HANDLE
:
3256 class = EC_ProgramError
;
3260 case ERROR_LOCK_VIOLATION
:
3261 class = EC_AccessDenied
;
3265 case ERROR_NO_MORE_FILES
:
3266 class = EC_MediaError
;
3271 class = EC_NotFound
;
3275 case ERROR_NOT_ENOUGH_MEMORY
:
3276 class = EC_OutOfResource
;
3280 case ERROR_PATH_NOT_FOUND
:
3281 class = EC_NotFound
;
3286 class = EC_NotFound
;
3290 case ERROR_SHARING_VIOLATION
:
3291 class = EC_Temporary
;
3295 case ERROR_TOO_MANY_OPEN_FILES
:
3296 class = EC_ProgramError
;
3301 FIXME("Unknown error %d\n", error
);
3302 class = EC_SystemFailure
;
3307 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
3308 error
, class, action
, locus
);
3309 SET_AX( context
, error
);
3310 SET_BH( context
, class );
3311 SET_BL( context
, action
);
3312 SET_CH( context
, locus
);
3315 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
3317 static int counter
= 0;
3318 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3319 char *p
= name
+ strlen(name
);
3321 /* despite what Ralf Brown says, some programs seem to call without
3322 * ending backslash (DOS accepts that, so we accept it too) */
3323 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
3327 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
3328 counter
= (counter
+ 1) % 1000;
3331 Win32HandleToDosFileHandle(
3332 CreateFileA( name
, GENERIC_READ
| GENERIC_WRITE
,
3333 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
3334 CREATE_NEW
, 0, 0 ) ) );
3335 if (AX_reg(context
) != HFILE_ERROR16
)
3337 TRACE("created %s\n", name
);
3340 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
3344 /***********************************************************************
3345 * DOSFS_ToDosFCBFormat
3347 * Convert a file name to DOS FCB format (8+3 chars, padded with blanks),
3348 * expanding wild cards and converting to upper-case in the process.
3349 * File name can be terminated by '\0', '\\' or '/'.
3350 * Return FALSE if the name is not a valid DOS name.
3351 * 'buffer' must be at least 12 characters long.
3353 /* Chars we don't want to see in DOS file names */
3354 #define INVALID_DOS_CHARS "*?<>|\"+=,;[] \345"
3355 static BOOL
INT21_ToDosFCBFormat( LPCWSTR name
, LPWSTR buffer
)
3357 static const char invalid_chars
[] = INVALID_DOS_CHARS
;
3361 /* Check for "." and ".." */
3366 for(i
= 1; i
< 11; i
++) buffer
[i
] = ' ';
3373 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3376 for (i
= 0; i
< 8; i
++)
3393 if (*p
< 256 && strchr( invalid_chars
, (char)*p
)) return FALSE
;
3394 buffer
[i
] = toupperW(*p
);
3402 /* Skip all chars after wildcard up to first dot */
3403 while (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) p
++;
3407 /* Check if name too long */
3408 if (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) return FALSE
;
3410 if (*p
== '.') p
++; /* Skip dot */
3412 for (i
= 8; i
< 11; i
++)
3422 return FALSE
; /* Second extension not allowed */
3430 if (*p
< 256 && strchr( invalid_chars
, (char)*p
)) return FALSE
;
3431 buffer
[i
] = toupperW(*p
);
3438 /* at most 3 character of the extension are processed
3439 * is something behind this ?
3441 while (*p
== '*' || *p
== ' ') p
++; /* skip wildcards and spaces */
3442 return IS_END_OF_NAME(*p
);
3445 static HANDLE INT21_FindHandle
;
3446 static const WCHAR
*INT21_FindPath
; /* will point to current dta->fullPath search */
3448 /******************************************************************
3451 static int INT21_FindFirst( CONTEXT86
*context
)
3455 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3456 WCHAR maskW
[12], pathW
[MAX_PATH
];
3457 static const WCHAR wildcardW
[] = {'*','.','*',0};
3459 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3460 MultiByteToWideChar(CP_OEMCP
, 0, path
, -1, pathW
, MAX_PATH
);
3462 p
= strrchrW( pathW
, '\\');
3465 if (pathW
[0] && pathW
[1] == ':') p
= pathW
+ 2;
3470 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
3471 * (doesn't matter as it is set below anyway)
3473 if (!INT21_ToDosFCBFormat( p
, maskW
))
3475 SetLastError( ERROR_FILE_NOT_FOUND
);
3476 SET_AX( context
, ERROR_FILE_NOT_FOUND
);
3480 WideCharToMultiByte(CP_OEMCP
, 0, maskW
, 12, dta
->mask
, sizeof(dta
->mask
), NULL
, NULL
);
3482 dta
->fullPath
= HeapAlloc( GetProcessHeap(), 0, sizeof(wildcardW
) + (p
- pathW
)*sizeof(WCHAR
) );
3483 memcpy( dta
->fullPath
, pathW
, (p
- pathW
) * sizeof(WCHAR
) );
3484 memcpy( dta
->fullPath
+ (p
- pathW
), wildcardW
, sizeof(wildcardW
) );
3485 /* we must have a fully qualified file name in dta->fullPath
3486 * (we could have a UNC path, but this would lead to some errors later on)
3488 dta
->drive
= toupperW(dta
->fullPath
[0]) - 'A';
3490 dta
->search_attr
= CL_reg(context
);
3494 /******************************************************************
3497 * Check is a short path name (DTA unicode) matches a mask (FCB ansi)
3499 static BOOL
match_short(LPCWSTR shortW
, LPCSTR maskA
)
3501 WCHAR mask
[11], file
[12];
3504 if (!INT21_ToDosFCBFormat( shortW
, file
)) return FALSE
;
3505 MultiByteToWideChar(CP_OEMCP
, 0, maskA
, 11, mask
, 11);
3506 for (i
= 0; i
< 11; i
++)
3507 if (mask
[i
] != '?' && mask
[i
] != file
[i
]) return FALSE
;
3511 static unsigned INT21_FindHelper(LPCWSTR fullPath
, unsigned drive
, unsigned count
,
3512 LPCSTR mask
, unsigned search_attr
,
3513 WIN32_FIND_DATAW
* entry
)
3517 if ((search_attr
& ~(FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
)) == FA_LABEL
)
3519 WCHAR path
[] = {' ',':',0};
3521 if (count
) return 0;
3522 path
[0] = drive
+ 'A';
3523 if (!GetVolumeInformationW(path
, entry
->cAlternateFileName
, 13, NULL
, NULL
, NULL
, NULL
, 0)) return 0;
3524 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftCreationTime
);
3525 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftLastAccessTime
);
3526 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftLastWriteTime
);
3527 entry
->dwFileAttributes
= FILE_ATTRIBUTE_LABEL
;
3528 entry
->nFileSizeHigh
= entry
->nFileSizeLow
= 0;
3529 TRACE("returning %s as label\n", debugstr_w(entry
->cAlternateFileName
));
3533 if (!INT21_FindHandle
|| INT21_FindPath
!= fullPath
|| count
== 0)
3535 if (INT21_FindHandle
) FindClose(INT21_FindHandle
);
3536 INT21_FindHandle
= FindFirstFileW(fullPath
, entry
);
3537 if (INT21_FindHandle
== INVALID_HANDLE_VALUE
)
3539 INT21_FindHandle
= 0;
3542 INT21_FindPath
= fullPath
;
3543 /* we need to resync search */
3548 while (ncalls
-- != 0)
3550 if (!FindNextFileW(INT21_FindHandle
, entry
))
3552 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3556 while (count
< 0xffff)
3559 /* Check the file attributes, and path */
3560 if (!(entry
->dwFileAttributes
& ~search_attr
) &&
3561 match_short(entry
->cAlternateFileName
, mask
))
3565 if (!FindNextFileW(INT21_FindHandle
, entry
))
3567 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3571 WARN("Too many directory entries in %s\n", debugstr_w(fullPath
) );
3575 /******************************************************************
3578 static int INT21_FindNext( CONTEXT86
*context
)
3580 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3581 DWORD attr
= dta
->search_attr
| FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
;
3582 WIN32_FIND_DATAW entry
;
3585 if (!dta
->fullPath
) return 0;
3587 n
= INT21_FindHelper(dta
->fullPath
, dta
->drive
, dta
->count
,
3588 dta
->mask
, attr
, &entry
);
3591 dta
->fileattr
= entry
.dwFileAttributes
;
3592 dta
->filesize
= entry
.nFileSizeLow
;
3593 FileTimeToDosDateTime( &entry
.ftLastWriteTime
, &dta
->filedate
, &dta
->filetime
);
3594 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cAlternateFileName
, -1,
3595 dta
->filename
, 13, NULL
, NULL
);
3596 if (!memchr(dta
->mask
,'?',11))
3598 /* wildcardless search, release resources in case no findnext will
3599 * be issued, and as a workaround in case file creation messes up
3600 * findnext, as sometimes happens with pkunzip
3602 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3603 INT21_FindPath
= dta
->fullPath
= NULL
;
3608 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3609 INT21_FindPath
= dta
->fullPath
= NULL
;
3613 /* microsoft's programmers should be shot for using CP/M style int21
3614 calls in Windows for Workgroup's winfile.exe */
3616 /******************************************************************
3617 * INT21_FindFirstFCB
3620 static int INT21_FindFirstFCB( CONTEXT86
*context
)
3622 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3625 WCHAR p
[] = {' ',':',};
3627 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3628 else pFCB
= (FINDFILE_FCB
*)fcb
;
3629 drive
= INT21_MapDrive( pFCB
->drive
);
3630 if (drive
== MAX_DOS_DRIVES
) return 0;
3633 pFCB
->fullPath
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
3634 if (!pFCB
->fullPath
) return 0;
3635 GetLongPathNameW(p
, pFCB
->fullPath
, MAX_PATH
);
3640 /******************************************************************
3644 static int INT21_FindNextFCB( CONTEXT86
*context
)
3646 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3648 DOS_DIRENTRY_LAYOUT
*pResult
= (DOS_DIRENTRY_LAYOUT
*)INT21_GetCurrentDTA(context
);
3649 WIN32_FIND_DATAW entry
;
3654 if (*fcb
== 0xff) /* extended FCB ? */
3657 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3662 pFCB
= (FINDFILE_FCB
*)fcb
;
3665 if (!pFCB
->fullPath
) return 0;
3666 n
= INT21_FindHelper(pFCB
->fullPath
, INT21_MapDrive( pFCB
->drive
),
3667 pFCB
->count
, pFCB
->filename
, attr
, &entry
);
3670 HeapFree( GetProcessHeap(), 0, pFCB
->fullPath
);
3671 INT21_FindPath
= pFCB
->fullPath
= NULL
;
3678 /* place extended FCB header before pResult if called with extended FCB */
3679 *(BYTE
*)pResult
= 0xff;
3680 (BYTE
*)pResult
+=6; /* leave reserved field behind */
3681 *(BYTE
*)pResult
= entry
.dwFileAttributes
;
3682 ((BYTE
*)pResult
)++;
3684 *(BYTE
*)pResult
= INT21_MapDrive( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
3685 ((BYTE
*)pResult
)++;
3686 pResult
->fileattr
= entry
.dwFileAttributes
;
3687 pResult
->cluster
= 0; /* what else? */
3688 pResult
->filesize
= entry
.nFileSizeLow
;
3689 memset( pResult
->reserved
, 0, sizeof(pResult
->reserved
) );
3690 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
3691 &pResult
->filedate
, &pResult
->filetime
);
3693 /* Convert file name to FCB format */
3694 INT21_ToDosFCBFormat( entry
.cAlternateFileName
, nameW
);
3695 WideCharToMultiByte(CP_OEMCP
, 0, nameW
, 11, pResult
->filename
, 11, NULL
, NULL
);
3700 /******************************************************************
3701 * INT21_ParseFileNameIntoFCB
3704 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
3707 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
3709 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
3713 INT buffer_len
, len
;
3715 SET_AL( context
, 0xff ); /* failed */
3717 TRACE("filename: '%s'\n", filename
);
3720 while (*s
&& (*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
3724 buffer_len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, NULL
, 0);
3725 buffer
= HeapAlloc( GetProcessHeap(), 0, (buffer_len
+ 1) * sizeof(WCHAR
));
3726 len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, buffer
, buffer_len
);
3728 INT21_ToDosFCBFormat(buffer
, fcbW
);
3729 HeapFree(GetProcessHeap(), 0, buffer
);
3730 WideCharToMultiByte(CP_OEMCP
, 0, fcbW
, 12, fcb
+ 1, 12, NULL
, NULL
);
3732 TRACE("FCB: '%s'\n", fcb
+ 1);
3734 SET_AL( context
, ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0 );
3736 /* point DS:SI to first unparsed character */
3737 SET_SI( context
, context
->Esi
+ (int)s
- (int)filename
);
3740 /***********************************************************************
3741 * DOSVM_Int21Handler
3743 * Interrupt 0x21 handler.
3745 void WINAPI
DOSVM_Int21Handler( CONTEXT86
*context
)
3747 BOOL bSetDOSExtendedError
= FALSE
;
3749 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
3750 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
3751 AX_reg(context
), BX_reg(context
),
3752 CX_reg(context
), DX_reg(context
),
3753 SI_reg(context
), DI_reg(context
),
3754 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
3758 * Extended error is used by (at least) functions 0x2f to 0x62.
3759 * Function 0x59 returns extended error and error should not
3760 * be cleared before handling the function.
3762 if (AH_reg(context
) >= 0x2f && AH_reg(context
) != 0x59)
3765 RESET_CFLAG(context
); /* Not sure if this is a good idea. */
3767 switch(AH_reg(context
))
3769 case 0x00: /* TERMINATE PROGRAM */
3770 TRACE("TERMINATE PROGRAM\n");
3771 if (DOSVM_IsWin16())
3773 else if(ISV86(context
))
3774 MZ_Exit( context
, FALSE
, 0 );
3776 ERR( "Called from DOS protected mode\n" );
3779 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
3782 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
3783 INT21_ReadChar( &ascii
, context
);
3784 SET_AL( context
, ascii
);
3786 * FIXME: What to echo when extended keycodes are read?
3788 DOSVM_PutChar(AL_reg(context
));
3792 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
3793 TRACE("Write Character to Standard Output\n");
3794 DOSVM_PutChar(DL_reg(context
));
3797 case 0x03: /* READ CHARACTER FROM STDAUX */
3798 case 0x04: /* WRITE CHARACTER TO STDAUX */
3799 case 0x05: /* WRITE CHARACTER TO PRINTER */
3800 INT_BARF( context
, 0x21 );
3803 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
3804 if (DL_reg(context
) == 0xff)
3806 TRACE("Direct Console Input\n");
3808 if (INT21_ReadChar( NULL
, NULL
))
3811 INT21_ReadChar( &ascii
, context
);
3812 SET_AL( context
, ascii
);
3813 RESET_ZFLAG( context
);
3817 /* no character available */
3818 SET_AL( context
, 0 );
3819 SET_ZFLAG( context
);
3824 TRACE("Direct Console Output\n");
3825 DOSVM_PutChar(DL_reg(context
));
3827 * At least DOS versions 2.1-7.0 return character
3828 * that was written in AL register.
3830 SET_AL( context
, DL_reg(context
) );
3834 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
3837 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
3838 INT21_ReadChar( &ascii
, context
);
3839 SET_AL( context
, ascii
);
3843 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
3846 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
3847 INT21_ReadChar( &ascii
, context
);
3848 SET_AL( context
, ascii
);
3852 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
3853 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
3854 context
->SegDs
, DX_reg(context
) );
3856 LPSTR data
= CTX_SEG_OFF_TO_LIN( context
,
3857 context
->SegDs
, context
->Edx
);
3861 * Do NOT use strchr() to calculate the string length,
3862 * as '\0' is valid string content, too!
3863 * Maybe we should check for non-'$' strings, but DOS doesn't.
3865 while (*p
!= '$') p
++;
3867 if (DOSVM_IsWin16())
3868 WriteFile( DosFileHandleToWin32Handle(1),
3869 data
, p
- data
, 0, 0 );
3871 for(; data
!= p
; data
++)
3872 DOSVM_PutChar( *data
);
3874 SET_AL( context
, '$' ); /* yes, '$' (0x24) gets returned in AL */
3878 case 0x0a: /* BUFFERED INPUT */
3880 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
3885 TRACE( "BUFFERED INPUT (size=%d)\n", ptr
[0] );
3888 * FIXME: Some documents state that
3889 * ptr[1] holds number of chars from last input which
3890 * may be recalled on entry, other documents do not mention
3894 TRACE( "Handle old chars in buffer!\n" );
3897 * ptr[0] - capacity (includes terminating CR)
3898 * ptr[1] - characters read (excludes terminating CR)
3900 result
= INT21_BufferedInput( context
, ptr
+ 2, ptr
[0] );
3902 ptr
[1] = (BYTE
)result
- 1;
3908 case 0x0b: /* GET STDIN STATUS */
3909 TRACE( "GET STDIN STATUS\n" );
3911 if (INT21_ReadChar( NULL
, NULL
))
3912 SET_AL( context
, 0xff ); /* character available */
3914 SET_AL( context
, 0 ); /* no character available */
3918 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
3920 BYTE al
= AL_reg(context
); /* Input function to execute after flush. */
3922 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al
);
3924 /* FIXME: buffers are not flushed */
3927 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
3928 * int21 function identified by AL will be called.
3930 if(al
== 0x01 || al
== 0x06 || al
== 0x07 || al
== 0x08 || al
== 0x0a)
3932 SET_AH( context
, al
);
3933 DOSVM_Int21Handler( context
);
3938 case 0x0d: /* DISK BUFFER FLUSH */
3939 TRACE("DISK BUFFER FLUSH ignored\n");
3942 case 0x0e: /* SELECT DEFAULT DRIVE */
3943 TRACE( "SELECT DEFAULT DRIVE - %c:\n", 'A' + DL_reg(context
) );
3944 INT21_SetCurrentDrive( DL_reg(context
) );
3945 SET_AL( context
, MAX_DOS_DRIVES
);
3948 case 0x0f: /* OPEN FILE USING FCB */
3949 INT21_OpenFileUsingFCB( context
);
3952 case 0x10: /* CLOSE FILE USING FCB */
3953 INT21_CloseFileUsingFCB( context
);
3956 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
3957 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
3958 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
3959 if (!INT21_FindFirstFCB(context
))
3961 SET_AL( context
, 0xff );
3964 /* else fall through */
3966 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
3967 SET_AL( context
, INT21_FindNextFCB(context
) ? 0x00 : 0xff );
3970 case 0x13: /* DELETE FILE USING FCB */
3971 INT_BARF( context
, 0x21 );
3974 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
3975 INT21_SequentialReadFromFCB( context
);
3978 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
3979 INT21_SequentialWriteToFCB( context
);
3982 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
3983 case 0x17: /* RENAME FILE USING FCB */
3984 INT_BARF( context
, 0x21 );
3987 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
3988 SET_AL( context
, 0 );
3991 case 0x19: /* GET CURRENT DEFAULT DRIVE */
3992 SET_AL( context
, INT21_GetCurrentDrive() );
3993 TRACE( "GET CURRENT DRIVE -> %c:\n", 'A' + AL_reg( context
) );
3996 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
3997 TRACE( "SET DISK TRANSFER AREA ADDRESS %04lX:%04X\n",
3998 context
->SegDs
, DX_reg(context
) );
4000 TDB
*task
= GlobalLock16( GetCurrentTask() );
4001 task
->dta
= MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4005 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
4006 if (!INT21_GetDriveAllocInfo(context
, 0))
4007 SET_AX( context
, 0xffff );
4010 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
4011 if (!INT21_GetDriveAllocInfo(context
, DL_reg(context
)))
4012 SET_AX( context
, 0xffff );
4015 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4016 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4017 SET_AL( context
, 0 );
4020 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
4022 BYTE drive
= INT21_MapDrive( 0 );
4023 TRACE( "GET DPB FOR DEFAULT DRIVE\n" );
4025 if (INT21_FillDrivePB( drive
))
4027 SET_AL( context
, 0x00 ); /* success */
4028 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4029 context
->SegDs
= INT21_GetHeapSelector( context
);
4033 SET_AL( context
, 0xff ); /* invalid or network drive */
4038 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4039 SET_AL( context
, 0 );
4042 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
4043 INT21_ReadRandomRecordFromFCB( context
);
4046 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
4047 INT21_WriteRandomRecordToFCB( context
);
4050 case 0x23: /* GET FILE SIZE FOR FCB */
4051 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
4052 INT_BARF( context
, 0x21 );
4055 case 0x25: /* SET INTERRUPT VECTOR */
4056 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4058 FARPROC16 ptr
= (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4059 if (!ISV86(context
) && DOSVM_IsWin16())
4060 DOSVM_SetPMHandler16( AL_reg(context
), ptr
);
4062 DOSVM_SetRMHandler( AL_reg(context
), ptr
);
4066 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
4067 INT_BARF( context
, 0x21 );
4070 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
4071 INT21_RandomBlockReadFromFCB( context
);
4074 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
4075 INT21_RandomBlockWriteToFCB( context
);
4078 case 0x29: /* PARSE FILENAME INTO FCB */
4079 INT21_ParseFileNameIntoFCB(context
);
4082 case 0x2a: /* GET SYSTEM DATE */
4083 TRACE( "GET SYSTEM DATE\n" );
4086 GetLocalTime( &systime
);
4087 SET_CX( context
, systime
.wYear
);
4088 SET_DH( context
, systime
.wMonth
);
4089 SET_DL( context
, systime
.wDay
);
4090 SET_AL( context
, systime
.wDayOfWeek
);
4094 case 0x2b: /* SET SYSTEM DATE */
4095 TRACE( "SET SYSTEM DATE\n" );
4097 WORD year
= CX_reg(context
);
4098 BYTE month
= DH_reg(context
);
4099 BYTE day
= DL_reg(context
);
4101 if (year
>= 1980 && year
<= 2099 &&
4102 month
>= 1 && month
<= 12 &&
4103 day
>= 1 && day
<= 31)
4105 FIXME( "SetSystemDate(%02d/%02d/%04d): not allowed\n",
4107 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4111 SET_AL( context
, 0xff ); /* invalid date */
4112 TRACE( "SetSystemDate(%02d/%02d/%04d): invalid date\n",
4118 case 0x2c: /* GET SYSTEM TIME */
4119 TRACE( "GET SYSTEM TIME\n" );
4122 GetLocalTime( &systime
);
4123 SET_CH( context
, systime
.wHour
);
4124 SET_CL( context
, systime
.wMinute
);
4125 SET_DH( context
, systime
.wSecond
);
4126 SET_DL( context
, systime
.wMilliseconds
/ 10 );
4130 case 0x2d: /* SET SYSTEM TIME */
4131 if( CH_reg(context
) >= 24 || CL_reg(context
) >= 60 || DH_reg(context
) >= 60 || DL_reg(context
) >= 100 ) {
4132 TRACE("SetSystemTime(%02d:%02d:%02d.%02d): wrong time\n",
4133 CH_reg(context
), CL_reg(context
),
4134 DH_reg(context
), DL_reg(context
) );
4135 SET_AL( context
, 0xFF );
4139 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
4140 CH_reg(context
), CL_reg(context
),
4141 DH_reg(context
), DL_reg(context
) );
4142 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4146 case 0x2e: /* SET VERIFY FLAG */
4147 TRACE("SET VERIFY FLAG ignored\n");
4148 /* we cannot change the behaviour anyway, so just ignore it */
4151 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
4152 TRACE( "GET DISK TRANSFER AREA ADDRESS\n" );
4154 TDB
*task
= GlobalLock16( GetCurrentTask() );
4155 context
->SegEs
= SELECTOROF( task
->dta
);
4156 SET_BX( context
, OFFSETOF( task
->dta
) );
4160 case 0x30: /* GET DOS VERSION */
4161 TRACE( "GET DOS VERSION - %s requested\n",
4162 (AL_reg(context
) == 0x00) ? "OEM number" : "version flag" );
4164 if (AL_reg(context
) == 0x00)
4165 SET_BH( context
, 0xff ); /* OEM number => undefined */
4167 SET_BH( context
, 0x08 ); /* version flag => DOS is in ROM */
4169 SET_AL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
4170 SET_AH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
4172 SET_BL( context
, 0x12 ); /* 0x123456 is 24-bit Wine's serial # */
4173 SET_CX( context
, 0x3456 );
4176 case 0x31: /* TERMINATE AND STAY RESIDENT */
4177 FIXME("TERMINATE AND STAY RESIDENT stub\n");
4180 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
4182 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
4183 TRACE( "GET DPB FOR SPECIFIC DRIVE %d\n", DL_reg(context
) );
4185 if (INT21_FillDrivePB( drive
))
4187 SET_AL( context
, 0x00 ); /* success */
4188 SET_DX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4189 context
->SegDs
= INT21_GetHeapSelector( context
);
4193 SET_AL( context
, 0xff ); /* invalid or network drive */
4198 case 0x33: /* MULTIPLEXED */
4199 switch (AL_reg(context
))
4201 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
4202 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
4203 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4206 case 0x01: /* SET EXTENDED BREAK STATE */
4207 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
4208 DOSCONF_GetConfig()->brk_flag
= (DL_reg(context
) > 0) ? 1 : 0;
4211 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
4212 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
4213 /* ugly coding in order to stay reentrant */
4214 if (DL_reg(context
))
4216 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4217 DOSCONF_GetConfig()->brk_flag
= 1;
4221 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4222 DOSCONF_GetConfig()->brk_flag
= 0;
4226 case 0x05: /* GET BOOT DRIVE */
4227 TRACE("GET BOOT DRIVE\n");
4228 SET_DL( context
, 3 );
4229 /* c: is Wine's bootdrive (a: is 1)*/
4232 case 0x06: /* GET TRUE VERSION NUMBER */
4233 TRACE("GET TRUE VERSION NUMBER\n");
4234 SET_BL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major */
4235 SET_BH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor */
4236 SET_DL( context
, 0x00 ); /* revision */
4237 SET_DH( context
, 0x08 ); /* DOS is in ROM */
4241 INT_BARF( context
, 0x21 );
4246 case 0x34: /* GET ADDRESS OF INDOS FLAG */
4247 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
4248 context
->SegEs
= INT21_GetHeapSelector( context
);
4249 SET_BX( context
, offsetof(INT21_HEAP
, misc_indos
) );
4252 case 0x35: /* GET INTERRUPT VECTOR */
4253 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4256 if (!ISV86(context
) && DOSVM_IsWin16())
4257 addr
= DOSVM_GetPMHandler16( AL_reg(context
) );
4259 addr
= DOSVM_GetRMHandler( AL_reg(context
) );
4260 context
->SegEs
= SELECTOROF(addr
);
4261 SET_BX( context
, OFFSETOF(addr
) );
4265 case 0x36: /* GET FREE DISK SPACE */
4266 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
4267 INT21_DriveName( DL_reg(context
) ));
4268 if (!INT21_GetFreeDiskSpace(context
)) SET_AX( context
, 0xffff );
4271 case 0x37: /* SWITCHAR */
4273 switch (AL_reg(context
))
4275 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
4276 TRACE( "SWITCHAR - GET SWITCH CHARACTER\n" );
4277 SET_AL( context
, 0x00 ); /* success*/
4278 SET_DL( context
, '/' );
4280 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
4281 FIXME( "SWITCHAR - SET SWITCH CHARACTER: %c\n",
4283 SET_AL( context
, 0x00 ); /* success*/
4286 INT_BARF( context
, 0x21 );
4292 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
4293 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
4294 if (AL_reg(context
))
4296 WORD country
= AL_reg(context
);
4297 if (country
== 0xff)
4298 country
= BX_reg(context
);
4299 if (country
!= INT21_GetSystemCountryCode()) {
4300 FIXME( "Requested info on non-default country %04x\n", country
);
4305 if(AX_reg(context
) != 2 )
4307 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context
,
4310 SET_AX( context
, INT21_GetSystemCountryCode() );
4311 SET_BX( context
, INT21_GetSystemCountryCode() );
4312 RESET_CFLAG(context
);
4316 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
4317 if (!INT21_CreateDirectory( context
))
4318 bSetDOSExtendedError
= TRUE
;
4320 RESET_CFLAG(context
);
4323 case 0x3a: /* "RMDIR" - REMOVE DIRECTORY */
4325 WCHAR dirW
[MAX_PATH
];
4326 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
4327 context
->SegDs
, context
->Edx
);
4329 TRACE( "REMOVE DIRECTORY %s\n", dirA
);
4331 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
4333 if (!RemoveDirectoryW( dirW
))
4334 bSetDOSExtendedError
= TRUE
;
4336 RESET_CFLAG(context
);
4340 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
4341 if (!INT21_SetCurrentDirectory( context
))
4342 bSetDOSExtendedError
= TRUE
;
4344 RESET_CFLAG(context
);
4347 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
4348 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4349 OF_READWRITE
| OF_SHARE_COMPAT
, 0x12 ))
4350 bSetDOSExtendedError
= TRUE
;
4352 RESET_CFLAG(context
);
4355 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
4356 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4357 AL_reg(context
), 0x01 ))
4358 bSetDOSExtendedError
= TRUE
;
4360 RESET_CFLAG(context
);
4363 case 0x3e: /* "CLOSE" - CLOSE FILE */
4364 TRACE( "CLOSE handle %d\n", BX_reg(context
) );
4365 if (_lclose16( BX_reg(context
) ) == HFILE_ERROR16
)
4366 bSetDOSExtendedError
= TRUE
;
4368 RESET_CFLAG(context
);
4371 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
4372 TRACE( "READ from %d to %04lX:%04X for %d bytes\n",
4379 WORD count
= CX_reg(context
);
4380 BYTE
*buffer
= CTX_SEG_OFF_TO_LIN( context
,
4384 /* Some programs pass a count larger than the allocated buffer */
4385 if (DOSVM_IsWin16())
4387 WORD maxcount
= GetSelectorLimit16( context
->SegDs
)
4388 - DX_reg(context
) + 1;
4389 if (count
> maxcount
)
4394 * FIXME: Reading from console (BX=1) in DOS mode
4395 * does not work as it is supposed to work.
4398 RESET_CFLAG(context
); /* set if error */
4399 if (!DOSVM_IsWin16() && BX_reg(context
) == 0)
4401 result
= INT21_BufferedInput( context
, buffer
, count
);
4402 SET_AX( context
, (WORD
)result
);
4404 else if (ReadFile( DosFileHandleToWin32Handle(BX_reg(context
)),
4405 buffer
, count
, &result
, NULL
))
4406 SET_AX( context
, (WORD
)result
);
4408 bSetDOSExtendedError
= TRUE
;
4412 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
4413 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
4414 context
->SegDs
, DX_reg(context
),
4415 BX_reg(context
), CX_reg(context
) );
4417 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4419 if (!DOSVM_IsWin16() &&
4420 (BX_reg(context
) == 1 || BX_reg(context
) == 2))
4423 for(i
=0; i
<CX_reg(context
); i
++)
4424 DOSVM_PutChar(ptr
[i
]);
4425 SET_AX(context
, CX_reg(context
));
4426 RESET_CFLAG(context
);
4430 HFILE handle
= (HFILE
)DosFileHandleToWin32Handle(BX_reg(context
));
4431 LONG result
= _hwrite( handle
, ptr
, CX_reg(context
) );
4432 if (result
== HFILE_ERROR
)
4433 bSetDOSExtendedError
= TRUE
;
4436 SET_AX( context
, (WORD
)result
);
4437 RESET_CFLAG(context
);
4443 case 0x41: /* "UNLINK" - DELETE FILE */
4445 WCHAR fileW
[MAX_PATH
];
4446 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
4450 TRACE( "UNLINK %s\n", fileA
);
4451 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
4453 if (!DeleteFileW( fileW
))
4454 bSetDOSExtendedError
= TRUE
;
4456 RESET_CFLAG(context
);
4460 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
4461 TRACE( "LSEEK handle %d offset %ld from %s\n",
4463 MAKELONG( DX_reg(context
), CX_reg(context
) ),
4464 (AL_reg(context
) == 0) ?
4465 "start of file" : ((AL_reg(context
) == 1) ?
4466 "current file position" : "end of file") );
4468 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
4469 LONG offset
= MAKELONG( DX_reg(context
), CX_reg(context
) );
4470 DWORD status
= SetFilePointer( handle
, offset
,
4471 NULL
, AL_reg(context
) );
4472 if (status
== INVALID_SET_FILE_POINTER
)
4473 bSetDOSExtendedError
= TRUE
;
4476 SET_AX( context
, LOWORD(status
) );
4477 SET_DX( context
, HIWORD(status
) );
4478 RESET_CFLAG(context
);
4483 case 0x43: /* FILE ATTRIBUTES */
4484 if (!INT21_FileAttributes( context
, AL_reg(context
), FALSE
))
4485 bSetDOSExtendedError
= TRUE
;
4487 RESET_CFLAG(context
);
4490 case 0x44: /* IOCTL */
4491 INT21_Ioctl( context
);
4494 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
4495 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context
) );
4498 HFILE handle16
= HFILE_ERROR
;
4500 if (DuplicateHandle( GetCurrentProcess(),
4501 DosFileHandleToWin32Handle(BX_reg(context
)),
4502 GetCurrentProcess(),
4504 0, TRUE
, DUPLICATE_SAME_ACCESS
))
4505 handle16
= Win32HandleToDosFileHandle(handle32
);
4507 if (handle16
== HFILE_ERROR
)
4508 bSetDOSExtendedError
= TRUE
;
4511 SET_AX( context
, handle16
);
4512 RESET_CFLAG(context
);
4517 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
4518 TRACE( "FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
4519 BX_reg(context
), CX_reg(context
) );
4521 if (FILE_Dup2( BX_reg(context
), CX_reg(context
) ) == HFILE_ERROR16
)
4522 bSetDOSExtendedError
= TRUE
;
4524 RESET_CFLAG(context
);
4527 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
4528 if (!INT21_GetCurrentDirectory( context
, FALSE
))
4529 bSetDOSExtendedError
= TRUE
;
4531 RESET_CFLAG(context
);
4534 case 0x48: /* ALLOCATE MEMORY */
4535 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
) );
4538 DWORD bytes
= (DWORD
)BX_reg(context
) << 4;
4540 if (!ISV86(context
) && DOSVM_IsWin16())
4542 DWORD rv
= GlobalDOSAlloc16( bytes
);
4543 selector
= LOWORD( rv
);
4546 DOSMEM_GetBlock( bytes
, &selector
);
4550 SET_AX( context
, selector
);
4551 RESET_CFLAG(context
);
4556 SET_AX( context
, 0x0008 ); /* insufficient memory */
4557 SET_BX( context
, DOSMEM_Available() >> 4 );
4562 case 0x49: /* FREE MEMORY */
4563 TRACE( "FREE MEMORY segment %04lX\n", context
->SegEs
);
4567 if (!ISV86(context
) && DOSVM_IsWin16())
4569 ok
= !GlobalDOSFree16( context
->SegEs
);
4571 /* If we don't reset ES_reg, we will fail in the relay code */
4576 ok
= DOSMEM_FreeBlock( (void*)((DWORD
)context
->SegEs
<< 4) );
4580 TRACE("FREE MEMORY failed\n");
4582 SET_AX( context
, 0x0009 ); /* memory block address invalid */
4587 case 0x4a: /* RESIZE MEMORY BLOCK */
4588 TRACE( "RESIZE MEMORY segment %04lX to %d paragraphs\n",
4589 context
->SegEs
, BX_reg(context
) );
4591 DWORD newsize
= (DWORD
)BX_reg(context
) << 4;
4593 if (!ISV86(context
) && DOSVM_IsWin16())
4595 FIXME( "Resize memory block - unsupported under Win16\n" );
4600 LPVOID address
= (void*)((DWORD
)context
->SegEs
<< 4);
4601 UINT blocksize
= DOSMEM_ResizeBlock( address
, newsize
, FALSE
);
4603 RESET_CFLAG(context
);
4604 if (blocksize
== (UINT
)-1)
4606 SET_CFLAG( context
);
4607 SET_AX( context
, 0x0009 ); /* illegal address */
4609 else if(blocksize
!= newsize
)
4611 SET_CFLAG( context
);
4612 SET_AX( context
, 0x0008 ); /* insufficient memory */
4613 SET_BX( context
, blocksize
>> 4 ); /* new block size */
4619 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
4621 BYTE
*program
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4622 BYTE
*paramblk
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
4624 TRACE( "EXEC %s\n", program
);
4626 RESET_CFLAG(context
);
4627 if (DOSVM_IsWin16())
4629 HINSTANCE16 instance
= WinExec16( program
, SW_NORMAL
);
4632 SET_CFLAG( context
);
4633 SET_AX( context
, instance
);
4638 if (!MZ_Exec( context
, program
, AL_reg(context
), paramblk
))
4639 bSetDOSExtendedError
= TRUE
;
4644 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
4645 TRACE( "EXIT with return code %d\n", AL_reg(context
) );
4646 if (DOSVM_IsWin16())
4647 ExitThread( AL_reg(context
) );
4648 else if(ISV86(context
))
4649 MZ_Exit( context
, FALSE
, AL_reg(context
) );
4655 DWORD rv
= AL_reg(context
);
4656 RaiseException( EXCEPTION_VM86_INTx
, 0, 1, &rv
);
4660 case 0x4d: /* GET RETURN CODE */
4661 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
4662 SET_AX( context
, DOSVM_retval
);
4666 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
4667 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
4668 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
4669 if (!INT21_FindFirst(context
)) break;
4672 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
4673 TRACE("FINDNEXT\n");
4674 if (!INT21_FindNext(context
))
4676 SetLastError( ERROR_NO_MORE_FILES
);
4677 SET_AX( context
, ERROR_NO_MORE_FILES
);
4680 else SET_AX( context
, 0 ); /* OK */
4683 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
4684 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
4685 DOSVM_psp
= BX_reg(context
);
4688 case 0x51: /* GET PSP ADDRESS */
4689 INT21_GetPSP( context
);
4692 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
4694 SEGPTR ptr
= DOSDEV_GetLOL( ISV86(context
) || !DOSVM_IsWin16() );
4695 context
->SegEs
= SELECTOROF(ptr
);
4696 SET_BX( context
, OFFSETOF(ptr
) );
4700 case 0x54: /* Get Verify Flag */
4701 TRACE("Get Verify Flag - Not Supported\n");
4702 SET_AL( context
, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
4705 case 0x56: /* "RENAME" - RENAME FILE */
4706 if (!INT21_RenameFile( context
))
4707 bSetDOSExtendedError
= TRUE
;
4709 RESET_CFLAG(context
);
4712 case 0x57: /* FILE DATE AND TIME */
4713 if (!INT21_FileDateTime( context
))
4714 bSetDOSExtendedError
= TRUE
;
4716 RESET_CFLAG(context
);
4719 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
4720 switch (AL_reg(context
))
4722 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
4723 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
4724 SET_AX( context
, 0 ); /* low memory first fit */
4727 case 0x01: /* SET ALLOCATION STRATEGY */
4728 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
4732 case 0x02: /* GET UMB LINK STATE */
4733 TRACE( "GET UMB LINK STATE\n" );
4734 SET_AL( context
, 0 ); /* UMBs not part of DOS memory chain */
4737 case 0x03: /* SET UMB LINK STATE */
4738 TRACE( "SET UMB LINK STATE to %d - ignored\n",
4743 INT_BARF( context
, 0x21 );
4747 case 0x59: /* GET EXTENDED ERROR INFO */
4748 INT21_GetExtendedError( context
);
4751 case 0x5a: /* CREATE TEMPORARY FILE */
4752 TRACE("CREATE TEMPORARY FILE\n");
4753 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
4756 case 0x5b: /* CREATE NEW FILE */
4757 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4758 OF_READWRITE
| OF_SHARE_COMPAT
, 0x10 ))
4759 bSetDOSExtendedError
= TRUE
;
4761 RESET_CFLAG(context
);
4764 case 0x5c: /* "FLOCK" - RECORD LOCKING */
4766 DWORD offset
= MAKELONG(DX_reg(context
), CX_reg(context
));
4767 DWORD length
= MAKELONG(DI_reg(context
), SI_reg(context
));
4768 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
4770 RESET_CFLAG(context
);
4771 switch (AL_reg(context
))
4773 case 0x00: /* LOCK */
4774 TRACE( "lock handle %d offset %ld length %ld\n",
4775 BX_reg(context
), offset
, length
);
4776 if (!LockFile( handle
, offset
, 0, length
, 0 ))
4777 bSetDOSExtendedError
= TRUE
;
4780 case 0x01: /* UNLOCK */
4781 TRACE( "unlock handle %d offset %ld length %ld\n",
4782 BX_reg(context
), offset
, length
);
4783 if (!UnlockFile( handle
, offset
, 0, length
, 0 ))
4784 bSetDOSExtendedError
= TRUE
;
4788 INT_BARF( context
, 0x21 );
4793 case 0x5d: /* NETWORK 5D */
4794 FIXME( "Network function 5D not implemented.\n" );
4795 SetLastError( ER_NoNetwork
);
4796 bSetDOSExtendedError
= TRUE
;
4799 case 0x5e: /* NETWORK 5E */
4800 bSetDOSExtendedError
= INT21_NetworkFunc( context
);
4803 case 0x5f: /* NETWORK 5F */
4804 /* FIXME: supporting this would need to 1:
4805 * - implement per drive current directory (as kernel32 doesn't)
4806 * - assign enabled/disabled flag on a per drive basis
4808 /* network software not installed */
4809 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
4810 SetLastError( ER_NoNetwork
);
4811 bSetDOSExtendedError
= TRUE
;
4814 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
4816 WCHAR pathW
[MAX_PATH
], res
[MAX_PATH
];
4817 /* FIXME: likely to be broken */
4819 TRACE("TRUENAME %s\n",
4820 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
4821 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
4822 if (!GetFullPathNameW( pathW
, 128, res
, NULL
))
4823 bSetDOSExtendedError
= TRUE
;
4826 SET_AX( context
, 0 );
4827 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
4828 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
4834 case 0x61: /* UNUSED */
4835 SET_AL( context
, 0 );
4838 case 0x62: /* GET PSP ADDRESS */
4839 INT21_GetPSP( context
);
4842 case 0x63: /* MISC. LANGUAGE SUPPORT */
4843 switch (AL_reg(context
)) {
4844 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
4845 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
4846 context
->SegDs
= INT21_GetHeapSelector( context
);
4847 SET_SI( context
, offsetof(INT21_HEAP
, dbcs_table
) );
4848 SET_AL( context
, 0 ); /* success */
4853 case 0x64: /* OS/2 DOS BOX */
4854 INT_BARF( context
, 0x21 );
4858 case 0x65: /* EXTENDED COUNTRY INFORMATION */
4859 INT21_ExtendedCountryInformation( context
);
4862 case 0x66: /* GLOBAL CODE PAGE TABLE */
4863 switch (AL_reg(context
))
4866 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
4867 SET_BX( context
, GetOEMCP() );
4868 SET_DX( context
, GetOEMCP() );
4871 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
4872 BX_reg(context
), DX_reg(context
) );
4877 case 0x67: /* SET HANDLE COUNT */
4878 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context
) );
4879 if (SetHandleCount( BX_reg(context
) ) < BX_reg(context
) )
4880 bSetDOSExtendedError
= TRUE
;
4883 case 0x68: /* "FFLUSH" - COMMIT FILE */
4884 TRACE( "FFLUSH - handle %d\n", BX_reg(context
) );
4885 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
4886 bSetDOSExtendedError
= TRUE
;
4889 case 0x69: /* DISK SERIAL NUMBER */
4890 switch (AL_reg(context
))
4893 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
4894 INT21_DriveName(BL_reg(context
)));
4895 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
4896 else SET_AX( context
, 0 );
4900 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
4901 INT21_DriveName(BL_reg(context
)));
4902 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
4903 else SET_AX( context
, 1 );
4908 case 0x6a: /* COMMIT FILE */
4909 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context
) );
4910 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
4911 bSetDOSExtendedError
= TRUE
;
4914 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4915 SET_AL( context
, 0 );
4918 case 0x6c: /* EXTENDED OPEN/CREATE */
4919 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
4920 BX_reg(context
), DL_reg(context
) ))
4921 bSetDOSExtendedError
= TRUE
;
4924 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
4925 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
4926 SET_CFLAG( context
);
4927 SET_AL( context
, 0 );
4930 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
4931 INT21_LongFilename( context
);
4934 case 0x73: /* MSDOS7 - FAT32 */
4935 RESET_CFLAG( context
);
4936 if (!INT21_Fat32( context
))
4937 bSetDOSExtendedError
= TRUE
;
4940 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
4941 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
4944 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
4945 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
4948 case 0xff: /* DOS32 EXTENDER (DOS/4GW) - API */
4949 /* we don't implement a DOS32 extender */
4950 TRACE( "DOS32 EXTENDER API - ignored\n" );
4954 INT_BARF( context
, 0x21 );
4957 } /* END OF SWITCH */
4959 /* Set general error condition. */
4960 if (bSetDOSExtendedError
)
4962 SET_AX( context
, GetLastError() );
4963 SET_CFLAG( context
);
4966 /* Print error code if carry flag is set. */
4967 if (context
->EFlags
& 0x0001)
4968 TRACE("failed, error %ld\n", GetLastError() );
4970 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
4971 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
4972 AX_reg(context
), BX_reg(context
),
4973 CX_reg(context
), DX_reg(context
),
4974 SI_reg(context
), DI_reg(context
),
4975 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,