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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/port.h"
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
42 #include "wine/winbase16.h"
43 #include "kernel16_private.h"
47 #include "wine/unicode.h"
48 #include "wine/server.h"
49 #include "wine/debug.h"
50 #include "wine/exception.h"
52 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE
);
55 * - Most of the file related functions are wrong. NT's kernel32
56 * doesn't maintain a per drive current directory, while DOS does.
57 * We should in fact keep track in here of those per drive
58 * directories, and use this info while dealing with partial paths
59 * (drive defined, but only relative paths). This could even be
60 * created as an array of CDS (there should be an entry for that in
65 * Forward declarations.
67 static BOOL
INT21_RenameFile( CONTEXT
*context
);
69 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
75 * Extended Drive Parameter Block.
76 * This structure is compatible with standard DOS4+ DPB and
79 typedef struct _INT21_DPB
{
80 BYTE drive
; /* 00 drive number (0=A, ...) */
81 BYTE unit
; /* 01 unit number within device driver */
82 WORD sector_bytes
; /* 02 bytes per sector */
83 BYTE cluster_sectors
; /* 04 highest sector number within a cluster */
84 BYTE shift
; /* 05 shift count to convert clusters into sectors */
85 WORD num_reserved
; /* 06 reserved sectors at beginning of drive */
86 BYTE num_FAT
; /* 08 number of FATs */
87 WORD num_root_entries
; /* 09 number of root directory entries */
88 WORD first_data_sector
; /* 0b number of first sector containing user data */
89 WORD num_clusters1
; /* 0d highest cluster number (number of data clusters + 1) */
90 WORD sectors_per_FAT
; /* 0f number of sectors per FAT */
91 WORD first_dir_sector
; /* 11 sector number of first directory sector */
92 SEGPTR driver_header
; /* 13 address of device driver header */
93 BYTE media_ID
; /* 17 media ID byte */
94 BYTE access_flag
; /* 18 0x00 if disk accessed, 0xff if not */
95 SEGPTR next
; /* 19 pointer to next DPB */
96 WORD search_cluster1
; /* 1d cluster at which to start search for free space */
97 WORD free_clusters_lo
; /* 1f number of free clusters on drive or 0xffff if unknown */
98 WORD free_clusters_hi
; /* 21 hiword of clusters_free */
99 WORD mirroring_flags
; /* 23 active FAT/mirroring flags */
100 WORD info_sector
; /* 25 sector number of file system info sector or 0xffff for none */
101 WORD spare_boot_sector
; /* 27 sector number of backup boot sector or 0xffff for none */
102 DWORD first_cluster_sector
; /* 29 sector number of the first cluster */
103 DWORD num_clusters2
; /* 2d maximum cluster number */
104 DWORD fat_clusters
; /* 31 number of clusters occupied by FAT */
105 DWORD root_cluster
; /* 35 cluster number of start of root directory */
106 DWORD search_cluster2
; /* 39 cluster at which to start searching for free space */
111 * Structure for DOS data that can be accessed directly from applications.
112 * Real and protected mode pointers will be returned to this structure so
113 * the structure must be correctly packed.
115 typedef struct _INT21_HEAP
{
116 WORD uppercase_size
; /* Size of the following table in bytes */
117 BYTE uppercase_table
[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
119 WORD lowercase_size
; /* Size of the following table in bytes */
120 BYTE lowercase_table
[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
122 WORD collating_size
; /* Size of the following table in bytes */
123 BYTE collating_table
[256]; /* Values used to sort characters from 0x00 to 0xff. */
125 WORD filename_size
; /* Size of the following filename data in bytes */
126 BYTE filename_reserved1
; /* 0x01 for MS-DOS 3.30-6.00 */
127 BYTE filename_lowest
; /* Lowest permissible character value for filename */
128 BYTE filename_highest
; /* Highest permissible character value for filename */
129 BYTE filename_reserved2
; /* 0x00 for MS-DOS 3.30-6.00 */
130 BYTE filename_exclude_first
; /* First illegal character in permissible range */
131 BYTE filename_exclude_last
; /* Last illegal character in permissible range */
132 BYTE filename_reserved3
; /* 0x02 for MS-DOS 3.30-6.00 */
133 BYTE filename_illegal_size
; /* Number of terminators in the following table */
134 BYTE filename_illegal_table
[16]; /* Characters which terminate a filename */
136 WORD dbcs_size
; /* Number of valid ranges in the following table */
137 BYTE dbcs_table
[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
139 BYTE misc_indos
; /* Interrupt 21 nesting flag */
140 WORD misc_segment
; /* Real mode segment for INT21_HEAP */
141 WORD misc_selector
; /* Protected mode selector for INT21_HEAP */
142 INT21_DPB misc_dpb_list
[MAX_DOS_DRIVES
]; /* Drive parameter blocks for all drives */
150 CHAR file_extension
[3];
151 WORD current_block_number
;
152 WORD logical_record_size
;
154 WORD date_of_last_write
;
155 WORD time_of_last_write
;
158 WORD starting_cluster
;
159 WORD sequence_number
;
160 BYTE file_attributes
;
162 BYTE record_within_current_block
;
163 BYTE random_access_record_number
[4];
170 BYTE xfcb_file_attribute
;
174 /* DTA layout for FindFirst/FindNext */
177 BYTE drive
; /* 00 drive letter */
178 char mask
[11]; /* 01 search template */
179 BYTE search_attr
; /* 0c search attributes */
180 WORD count
; /* 0d entry count within directory */
181 WORD cluster
; /* 0f cluster of parent directory */
182 WCHAR
*fullPath
; /* 11 full path (was: reserved) */
183 BYTE fileattr
; /* 15 file attributes */
184 WORD filetime
; /* 16 file time */
185 WORD filedate
; /* 18 file date */
186 DWORD filesize
; /* 1a file size */
187 char filename
[13]; /* 1e file name + extension */
190 /* FCB layout for FindFirstFCB/FindNextFCB */
193 BYTE drive
; /* 00 drive letter */
194 char filename
[11]; /* 01 filename 8+3 format */
195 int count
; /* 0c entry count (was: reserved) */
196 WCHAR
*fullPath
; /* 10 full path (was: reserved) */
199 /* DOS directory entry for FindFirstFCB/FindNextFCB */
202 char filename
[11]; /* 00 filename 8+3 format */
203 BYTE fileattr
; /* 0b file attributes */
204 BYTE reserved
[10]; /* 0c reserved */
205 WORD filetime
; /* 16 file time */
206 WORD filedate
; /* 18 file date */
207 WORD cluster
; /* 1a file first cluster */
208 DWORD filesize
; /* 1c file size */
209 } DOS_DIRENTRY_LAYOUT
;
213 /* dos file attributes */
214 #define FA_NORMAL 0x00 /* Normal file, no attributes */
215 #define FA_RDONLY 0x01 /* Read only attribute */
216 #define FA_HIDDEN 0x02 /* Hidden file */
217 #define FA_SYSTEM 0x04 /* System file */
218 #define FA_LABEL 0x08 /* Volume label */
219 #define FA_DIRECTORY 0x10 /* Directory */
220 #define FA_ARCHIVE 0x20 /* Archive */
221 #define FA_UNUSED 0x40 /* Unused */
224 #define ER_NoNetwork 0x49
227 #define EC_OutOfResource 0x01
228 #define EC_Temporary 0x02
229 #define EC_AccessDenied 0x03
230 #define EC_InternalError 0x04
231 #define EC_HardwareFailure 0x05
232 #define EC_SystemFailure 0x06
233 #define EC_ProgramError 0x07
234 #define EC_NotFound 0x08
235 #define EC_MediaError 0x0b
236 #define EC_Exists 0x0c
237 #define EC_Unknown 0x0d
239 /* Suggested actions */
240 #define SA_Retry 0x01
241 #define SA_DelayedRetry 0x02
242 #define SA_Abort 0x04
243 #define SA_Ignore 0x06
244 #define SA_Ask4Retry 0x07
247 #define EL_Unknown 0x01
249 #define EL_Network 0x03
250 #define EL_Serial 0x04
251 #define EL_Memory 0x05
253 /* BIOS Keyboard Scancodes */
254 #define KEY_LEFT 0x4B
255 #define KEY_RIGHT 0x4D
257 #define KEY_DOWN 0x50
258 #define KEY_IC 0x52 /* insert char */
259 #define KEY_DC 0x53 /* delete char */
260 #define KEY_BACKSPACE 0x0E
261 #define KEY_HOME 0x47
263 #define KEY_NPAGE 0x49
264 #define KEY_PPAGE 0x51
273 void (*ioctl_handler
)(CONTEXT
*);
276 static void INT21_IoctlScsiMgrHandler( CONTEXT
* );
277 static void INT21_IoctlHPScanHandler( CONTEXT
* );
279 static struct magic_device magic_devices
[] =
281 { {'s','c','s','i','m','g','r','$',0}, NULL
, { { 0, 0 } }, INT21_IoctlScsiMgrHandler
},
282 { {'e','m','m','x','x','x','x','0',0}, NULL
, { { 0, 0 } }, EMS_Ioctl_Handler
},
283 { {'h','p','s','c','a','n',0}, NULL
, { { 0, 0 } }, INT21_IoctlHPScanHandler
},
286 #define NB_MAGIC_DEVICES (sizeof(magic_devices)/sizeof(magic_devices[0]))
289 /* Many calls translate a drive argument like this:
290 drive number (00h = default, 01h = A:, etc)
292 /******************************************************************
295 * Many calls translate a drive argument like this:
296 * drive number (00h = default, 01h = A:, etc)
298 static const char *INT21_DriveName(int drive
)
302 if (drive
<= 26) return wine_dbg_sprintf("%c:", 'A' + drive
- 1);
303 else return wine_dbg_sprintf( "<Bad drive: %d>", drive
);
308 /***********************************************************************
309 * INT21_GetCurrentDrive
311 * Return current drive using scheme (0=A:, 1=B:, 2=C:, ...) or
312 * MAX_DOS_DRIVES on error.
314 static BYTE
INT21_GetCurrentDrive(void)
316 WCHAR current_directory
[MAX_PATH
];
318 if (!GetCurrentDirectoryW( MAX_PATH
, current_directory
) ||
319 current_directory
[1] != ':')
321 TRACE( "Failed to get current drive.\n" );
322 return MAX_DOS_DRIVES
;
325 return toupperW( current_directory
[0] ) - 'A';
329 /***********************************************************************
332 * Convert drive number from scheme (0=default, 1=A:, 2=B:, ...) into
333 * scheme (0=A:, 1=B:, 2=C:, ...) or MAX_DOS_DRIVES on error.
335 static BYTE
INT21_MapDrive( BYTE drive
)
339 WCHAR drivespec
[] = {'A', ':', 0};
342 drivespec
[0] += drive
- 1;
343 drivetype
= GetDriveTypeW( drivespec
);
345 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
346 return MAX_DOS_DRIVES
;
351 return INT21_GetCurrentDrive();
355 /***********************************************************************
356 * INT21_SetCurrentDrive
358 * Set current drive. Uses scheme (0=A:, 1=B:, 2=C:, ...).
360 static void INT21_SetCurrentDrive( BYTE drive
)
362 WCHAR drivespec
[] = {'A', ':', 0};
364 drivespec
[0] += drive
;
366 if (!SetCurrentDirectoryW( drivespec
))
367 TRACE( "Failed to set current drive.\n" );
371 /***********************************************************************
374 * Reads a character from the standard input.
375 * Extended keycodes will be returned as two separate characters.
377 static BOOL
INT21_ReadChar( BYTE
*input
, CONTEXT
*waitctx
)
379 static BYTE pending_scan
= 0;
384 *input
= pending_scan
;
393 if (!DOSVM_Int16ReadChar( &ascii
, &scan
, waitctx
))
398 if (waitctx
&& !ascii
)
405 /***********************************************************************
406 * INT21_GetSystemCountryCode
408 * Return DOS country code for default system locale.
410 static WORD
INT21_GetSystemCountryCode( void )
412 return GetSystemDefaultLangID();
416 /***********************************************************************
417 * INT21_FillCountryInformation
419 * Fill 34-byte buffer with country information data using
420 * default system locale.
422 static void INT21_FillCountryInformation( BYTE
*buffer
)
424 /* 00 - WORD: date format
429 *(WORD
*)(buffer
+ 0) = 0; /* FIXME: Get from locale */
431 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
432 buffer
[2] = '$'; /* FIXME: Get from locale */
435 /* 07 - BYTE[2]: ASCIIZ thousands separator */
436 buffer
[7] = 0; /* FIXME: Get from locale */
439 /* 09 - BYTE[2]: ASCIIZ decimal separator */
440 buffer
[9] = '.'; /* FIXME: Get from locale */
443 /* 11 - BYTE[2]: ASCIIZ date separator */
444 buffer
[11] = '/'; /* FIXME: Get from locale */
447 /* 13 - BYTE[2]: ASCIIZ time separator */
448 buffer
[13] = ':'; /* FIXME: Get from locale */
451 /* 15 - BYTE: Currency format
452 * bit 2 = set if currency symbol replaces decimal point
453 * bit 1 = number of spaces between value and currency symbol
454 * bit 0 = 0 if currency symbol precedes value
455 * 1 if currency symbol follows value
457 buffer
[15] = 0; /* FIXME: Get from locale */
459 /* 16 - BYTE: Number of digits after decimal in currency */
460 buffer
[16] = 0; /* FIXME: Get from locale */
462 /* 17 - BYTE: Time format
463 * bit 0 = 0 if 12-hour clock
466 buffer
[17] = 1; /* FIXME: Get from locale */
468 /* 18 - DWORD: Address of case map routine */
469 *(DWORD
*)(buffer
+ 18) = 0; /* FIXME: ptr to case map routine */
471 /* 22 - BYTE[2]: ASCIIZ data-list separator */
472 buffer
[22] = ','; /* FIXME: Get from locale */
475 /* 24 - BYTE[10]: Reserved */
476 memset( buffer
+ 24, 0, 10 );
480 /***********************************************************************
483 * Initialize DOS heap.
485 * Filename Terminator Table of w2k DE NTVDM:
486 * 16 00 01 00 FF 00 00 20-02 0E 2E 22 2F 5C 5B 5D ....... ..."/\[]
487 * 3A 7C 3C 3E 2B 3D 3B 2C-00 :|<>+=;,
489 static void INT21_FillHeap( INT21_HEAP
*heap
)
491 static const char terminators
[] = ".\"/\\[]:|<>+=;,";
497 heap
->uppercase_size
= 128;
498 for (i
= 0; i
< 128; i
++)
499 heap
->uppercase_table
[i
] = toupper( 128 + i
);
504 heap
->lowercase_size
= 256;
505 for (i
= 0; i
< 256; i
++)
506 heap
->lowercase_table
[i
] = tolower( i
);
511 heap
->collating_size
= 256;
512 for (i
= 0; i
< 256; i
++)
513 heap
->collating_table
[i
] = i
;
518 heap
->filename_size
= 8 + strlen(terminators
);
519 heap
->filename_illegal_size
= strlen(terminators
);
520 memcpy( heap
->filename_illegal_table
, terminators
, heap
->filename_illegal_size
);
522 heap
->filename_reserved1
= 0x01;
523 heap
->filename_lowest
= 0x00;
524 heap
->filename_highest
= 0xff;
525 heap
->filename_reserved2
= 0x00;
526 heap
->filename_exclude_first
= 0x00;
527 heap
->filename_exclude_last
= 0x20;
528 heap
->filename_reserved3
= 0x02;
531 * DBCS lead byte table. This table is empty.
534 memset( heap
->dbcs_table
, 0, sizeof(heap
->dbcs_table
) );
537 * Initialize InDos flag.
539 heap
->misc_indos
= 0;
542 * FIXME: Should drive parameter blocks (DPB) be
543 * initialized here and linked to DOS LOL?
548 /***********************************************************************
549 * INT21_GetHeapPointer
551 * Get pointer for DOS heap (INT21_HEAP).
552 * Creates and initializes heap on first call.
554 static INT21_HEAP
*INT21_GetHeapPointer( void )
556 static INT21_HEAP
*heap_pointer
= NULL
;
563 heap_pointer
= DOSVM_AllocDataUMB( sizeof(INT21_HEAP
),
567 heap_pointer
->misc_segment
= heap_segment
;
568 heap_pointer
->misc_selector
= heap_selector
;
569 INT21_FillHeap( heap_pointer
);
576 /***********************************************************************
577 * INT21_GetHeapSelector
579 * Get segment/selector for DOS heap (INT21_HEAP).
580 * Creates and initializes heap on first call.
582 static WORD
INT21_GetHeapSelector( CONTEXT
*context
)
584 INT21_HEAP
*heap
= INT21_GetHeapPointer();
586 if (!ISV86(context
) && DOSVM_IsWin16())
587 return heap
->misc_selector
;
589 return heap
->misc_segment
;
593 /***********************************************************************
596 * Fill DOS heap drive parameter block for the specified drive.
597 * Return TRUE if drive was valid and there were
598 * no errors while reading drive information.
600 static BOOL
INT21_FillDrivePB( BYTE drive
)
602 WCHAR drivespec
[] = {'A', ':', 0};
603 INT21_HEAP
*heap
= INT21_GetHeapPointer();
606 DWORD cluster_sectors
;
609 DWORD total_clusters
;
611 if (drive
>= MAX_DOS_DRIVES
)
614 dpb
= &heap
->misc_dpb_list
[drive
];
615 drivespec
[0] += drive
;
616 drivetype
= GetDriveTypeW( drivespec
);
619 * FIXME: Does this check work correctly with floppy/cdrom drives?
621 if (drivetype
== DRIVE_NO_ROOT_DIR
|| drivetype
== DRIVE_UNKNOWN
)
625 * FIXME: Does this check work correctly with floppy/cdrom drives?
627 if (!GetDiskFreeSpaceW( drivespec
, &cluster_sectors
, §or_bytes
,
628 &free_clusters
, &total_clusters
))
632 * FIXME: Most of the values listed below are incorrect.
633 * All values should be validated.
638 dpb
->sector_bytes
= sector_bytes
;
639 dpb
->cluster_sectors
= cluster_sectors
- 1;
642 while (cluster_sectors
> 1)
644 cluster_sectors
/= 2;
648 dpb
->num_reserved
= 0;
650 dpb
->num_root_entries
= 2;
651 dpb
->first_data_sector
= 2;
652 dpb
->num_clusters1
= total_clusters
;
653 dpb
->sectors_per_FAT
= 1;
654 dpb
->first_dir_sector
= 1;
655 dpb
->driver_header
= 0;
656 dpb
->media_ID
= (drivetype
== DRIVE_FIXED
) ? 0xF8 : 0xF0;
657 dpb
->access_flag
= 0;
659 dpb
->search_cluster1
= 0;
660 dpb
->free_clusters_lo
= LOWORD(free_clusters
);
661 dpb
->free_clusters_hi
= HIWORD(free_clusters
);
662 dpb
->mirroring_flags
= 0;
663 dpb
->info_sector
= 0xffff;
664 dpb
->spare_boot_sector
= 0xffff;
665 dpb
->first_cluster_sector
= 0;
666 dpb
->num_clusters2
= total_clusters
;
667 dpb
->fat_clusters
= 32;
668 dpb
->root_cluster
= 0;
669 dpb
->search_cluster2
= 0;
675 /***********************************************************************
676 * INT21_GetCurrentDirectory
680 * - subfunction 0x47 of function 0x71
682 static BOOL
INT21_GetCurrentDirectory( CONTEXT
*context
, BOOL islong
)
684 char *buffer
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
685 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
686 WCHAR pathW
[MAX_PATH
];
687 char pathA
[MAX_PATH
];
690 TRACE( "drive %d\n", DL_reg(context
) );
692 if (drive
== MAX_DOS_DRIVES
)
694 SetLastError(ERROR_INVALID_DRIVE
);
699 * Grab current directory.
702 if (!GetCurrentDirectoryW( MAX_PATH
, pathW
)) return FALSE
;
704 if (toupperW(pathW
[0]) - 'A' != drive
|| pathW
[1] != ':')
706 /* cwd is not on the requested drive, get the environment string instead */
711 env_var
[1] = 'A' + drive
;
714 if (!GetEnvironmentVariableW( env_var
, pathW
, MAX_PATH
))
716 /* return empty path */
723 * Convert into short format.
728 DWORD result
= GetShortPathNameW( pathW
, pathW
, MAX_PATH
);
731 if (result
> MAX_PATH
)
733 WARN( "Short path too long!\n" );
734 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
740 * The returned pathname does not include
741 * the drive letter, colon or leading backslash.
747 * FIXME: We should probably just strip host part from name...
749 FIXME( "UNC names are not supported.\n" );
750 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
753 else if (!ptr
[0] || ptr
[1] != ':' || ptr
[2] != '\\')
755 WARN( "Path is neither UNC nor DOS path: %s\n",
756 wine_dbgstr_w(ptr
) );
757 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
762 /* Remove drive letter, colon and leading backslash. */
767 * Convert into OEM string.
770 if (!WideCharToMultiByte(CP_OEMCP
, 0, ptr
, -1, pathA
,
771 MAX_PATH
, NULL
, NULL
))
773 WARN( "Cannot convert path!\n" );
774 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
784 /* Undocumented success code. */
785 SET_AX( context
, 0x0100 );
787 /* Truncate buffer to 64 bytes. */
791 TRACE( "%c:=%s\n", 'A' + drive
, pathA
);
793 strcpy( buffer
, pathA
);
798 /***********************************************************************
799 * INT21_SetCurrentDirectory
803 * - subfunction 0x3b of function 0x71
805 static BOOL
INT21_SetCurrentDirectory( CONTEXT
*context
)
807 WCHAR dirW
[MAX_PATH
];
810 char *dirA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
811 BYTE drive
= INT21_GetCurrentDrive();
814 TRACE( "SET CURRENT DIRECTORY %s\n", dirA
);
816 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
817 if (!GetFullPathNameW( dirW
, MAX_PATH
, dirW
, NULL
)) return FALSE
;
819 attr
= GetFileAttributesW( dirW
);
820 if (attr
== INVALID_FILE_ATTRIBUTES
|| !(attr
& FILE_ATTRIBUTE_DIRECTORY
))
822 SetLastError( ERROR_PATH_NOT_FOUND
);
827 env_var
[1] = dirW
[0];
830 result
= SetEnvironmentVariableW( env_var
, dirW
);
832 /* only set current directory if on the current drive */
833 if (result
&& (toupperW(dirW
[0]) - 'A' == drive
)) result
= SetCurrentDirectoryW( dirW
);
838 /***********************************************************************
839 * INT21_CreateMagicDeviceHandle
841 * Create a dummy file handle for a "magic" device.
843 static HANDLE
INT21_CreateMagicDeviceHandle( LPCWSTR name
)
845 static const WCHAR prefixW
[] = {'\\','?','?','\\','u','n','i','x'};
846 const char *dir
= wine_get_server_dir();
850 OBJECT_ATTRIBUTES attr
;
851 UNICODE_STRING nameW
;
854 len
= MultiByteToWideChar( CP_UNIXCP
, 0, dir
, -1, NULL
, 0 );
855 nameW
.Length
= sizeof(prefixW
) + (len
+ strlenW( name
)) * sizeof(WCHAR
);
856 nameW
.MaximumLength
= nameW
.Length
+ sizeof(WCHAR
);
857 if (!(nameW
.Buffer
= HeapAlloc( GetProcessHeap(), 0, nameW
.MaximumLength
)))
859 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
862 memcpy( nameW
.Buffer
, prefixW
, sizeof(prefixW
) );
863 MultiByteToWideChar( CP_UNIXCP
, 0, dir
, -1, nameW
.Buffer
+ sizeof(prefixW
)/sizeof(WCHAR
), len
);
864 len
+= sizeof(prefixW
) / sizeof(WCHAR
);
865 nameW
.Buffer
[len
-1] = '/';
866 strcpyW( nameW
.Buffer
+ len
, name
);
868 attr
.Length
= sizeof(attr
);
869 attr
.RootDirectory
= 0;
871 attr
.ObjectName
= &nameW
;
872 attr
.SecurityDescriptor
= NULL
;
873 attr
.SecurityQualityOfService
= NULL
;
875 status
= NtCreateFile( &ret
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &io
, NULL
, 0,
876 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
,
877 FILE_SYNCHRONOUS_IO_ALERT
, NULL
, 0 );
881 SetLastError( RtlNtStatusToDosError(status
) );
883 RtlFreeUnicodeString( &nameW
);
888 /***********************************************************************
889 * INT21_OpenMagicDevice
891 * Open a file handle for "magic" devices like EMMXXXX0.
893 static HANDLE
INT21_OpenMagicDevice( LPCWSTR name
, DWORD access
)
899 if (name
[0] && (name
[1] == ':')) name
+= 2;
900 if ((p
= strrchrW( name
, '/' ))) name
= p
+ 1;
901 if ((p
= strrchrW( name
, '\\' ))) name
= p
+ 1;
903 for (i
= 0; i
< NB_MAGIC_DEVICES
; i
++)
905 int len
= strlenW( magic_devices
[i
].name
);
906 if (!strncmpiW( magic_devices
[i
].name
, name
, len
) &&
907 (!name
[len
] || name
[len
] == '.' || name
[len
] == ':')) break;
909 if (i
== NB_MAGIC_DEVICES
) return 0;
911 if (!magic_devices
[i
].handle
) /* need to open it */
914 FILE_INTERNAL_INFORMATION info
;
916 if (!(handle
= INT21_CreateMagicDeviceHandle( magic_devices
[i
].name
))) return 0;
918 NtQueryInformationFile( handle
, &io
, &info
, sizeof(info
), FileInternalInformation
);
919 magic_devices
[i
].index
= info
.IndexNumber
;
920 magic_devices
[i
].handle
= handle
;
922 if (!DuplicateHandle( GetCurrentProcess(), magic_devices
[i
].handle
,
923 GetCurrentProcess(), &handle
, access
, FALSE
, 0 )) handle
= 0;
928 /***********************************************************************
936 * - subfunction 0x6c of function 0x71
938 static BOOL
INT21_CreateFile( CONTEXT
*context
,
945 char *pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, pathSegOff
);
946 WCHAR pathW
[MAX_PATH
];
953 TRACE( "CreateFile called: function=%02x, action=%02x, access/share=%04x, "
954 "create flags=%04x, file=%s.\n",
955 AH_reg(context
), dosAction
, dosAccessShare
, CX_reg(context
), pathA
);
958 * Application tried to create/open a file whose name
959 * ends with a backslash. This is not allowed.
961 * FIXME: This needs to be validated, especially the return value.
963 if (pathA
[strlen(pathA
) - 1] == '/')
965 SetLastError( ERROR_FILE_NOT_FOUND
);
970 * Convert DOS action flags into Win32 creation disposition parameter.
975 winMode
= OPEN_EXISTING
;
978 winMode
= TRUNCATE_EXISTING
;
981 winMode
= CREATE_NEW
;
984 winMode
= OPEN_ALWAYS
;
987 winMode
= CREATE_ALWAYS
;
990 SetLastError( ERROR_INVALID_PARAMETER
);
995 * Convert DOS access/share flags into Win32 desired access parameter.
997 switch(dosAccessShare
& 0x07)
1000 winAccess
= GENERIC_READ
;
1003 winAccess
= GENERIC_WRITE
;
1006 winAccess
= GENERIC_READ
| GENERIC_WRITE
;
1010 * Read-only, do not modify file's last-access time (DOS7).
1012 * FIXME: How to prevent modification of last-access time?
1014 winAccess
= GENERIC_READ
;
1021 * Convert DOS access/share flags into Win32 share mode parameter.
1023 switch(dosAccessShare
& 0x70)
1025 case OF_SHARE_EXCLUSIVE
:
1028 case OF_SHARE_DENY_WRITE
:
1029 winSharing
= FILE_SHARE_READ
;
1031 case OF_SHARE_DENY_READ
:
1032 winSharing
= FILE_SHARE_WRITE
;
1034 case OF_SHARE_DENY_NONE
:
1035 case OF_SHARE_COMPAT
:
1037 winSharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1041 * FIXME: Bit (dosAccessShare & 0x80) represents inheritance.
1042 * What to do with this bit?
1043 * FIXME: Bits in the high byte of dosAccessShare are not supported.
1044 * See both function 0x6c and subfunction 0x6c of function 0x71 for
1045 * definition of these bits.
1049 * Convert DOS create attributes into Win32 flags and attributes parameter.
1051 if (winMode
== OPEN_EXISTING
|| winMode
== TRUNCATE_EXISTING
)
1057 WORD dosAttributes
= CX_reg(context
);
1059 if (dosAttributes
& FA_LABEL
)
1062 * Application tried to create volume label entry.
1063 * This is difficult to support so we do not allow it.
1065 * FIXME: If volume does not already have a label,
1066 * this function is supposed to succeed.
1068 SetLastError( ERROR_ACCESS_DENIED
);
1072 winAttributes
= dosAttributes
&
1073 (FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
|
1074 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
);
1080 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
1082 if ((winHandle
= INT21_OpenMagicDevice( pathW
, winAccess
)))
1088 winHandle
= CreateFileW( pathW
, winAccess
, winSharing
, NULL
,
1089 winMode
, winAttributes
, 0 );
1090 /* DOS allows opening files on a CDROM R/W */
1091 if( winHandle
== INVALID_HANDLE_VALUE
&&
1092 (GetLastError() == ERROR_WRITE_PROTECT
||
1093 GetLastError() == ERROR_ACCESS_DENIED
)) {
1094 winHandle
= CreateFileW( pathW
, winAccess
& ~GENERIC_WRITE
,
1095 winSharing
, NULL
, winMode
, winAttributes
, 0 );
1098 if (winHandle
== INVALID_HANDLE_VALUE
)
1102 * Determine DOS file status.
1113 case TRUNCATE_EXISTING
:
1120 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 1 : 2;
1123 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 3 : 2;
1131 * Return DOS file handle and DOS status.
1133 SET_AX( context
, Win32HandleToDosFileHandle(winHandle
) );
1136 SET_CX( context
, dosStatus
);
1138 TRACE( "CreateFile finished: handle=%d, status=%d.\n",
1139 AX_reg(context
), dosStatus
);
1145 /***********************************************************************
1146 * INT21_BufferedInput
1148 * Handler for function 0x0a and reading from console using
1151 * Reads a string of characters from standard input until
1152 * enter key is pressed. Returns either number of characters
1153 * read from console including terminating CR or
1154 * zero if capacity was zero.
1156 static WORD
INT21_BufferedInput( CONTEXT
*context
, BYTE
*ptr
, WORD capacity
)
1161 * Return immediately if capacity is zero.
1171 DOSVM_Int16ReadChar( &ascii
, &scan
, context
);
1173 if (ascii
== '\r' || ascii
== '\n')
1180 * DOS handles only backspace and KEY_LEFT
1181 * perhaps we should do more
1183 if (ascii
== '\b' || scan
== KEY_LEFT
)
1185 if (length
==0) continue;
1186 DOSVM_PutChar( '\b' );
1192 * If the buffer becomes filled to within one byte of
1193 * capacity, DOS rejects all further characters up to,
1194 * but not including, the terminating carriage return.
1196 if (ascii
!= 0 && length
< capacity
-1)
1198 DOSVM_PutChar( ascii
);
1199 ptr
[length
] = ascii
;
1206 /***********************************************************************
1207 * INT21_GetCurrentDTA
1209 static BYTE
*INT21_GetCurrentDTA( CONTEXT
*context
)
1211 TDB
*pTask
= GlobalLock16(GetCurrentTask());
1213 /* FIXME: This assumes DTA was set correctly! */
1214 return CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
1215 OFFSETOF(pTask
->dta
) );
1219 /***********************************************************************
1220 * INT21_OpenFileUsingFCB
1222 * Handler for function 0x0f.
1225 * DX:DX [I/O] File control block (FCB or XFCB) of unopened file
1232 * Opens a FCB file for read/write in compatibility mode. Upon calling
1233 * the FCB must have the drive_number, file_name, and file_extension
1234 * fields filled and all other bytes cleared.
1236 static void INT21_OpenFileUsingFCB( CONTEXT
*context
)
1244 BY_HANDLE_FILE_INFORMATION info
;
1247 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1248 if (fcb
->drive_number
== 0xff) {
1249 xfcb
= (struct XFCB
*) fcb
;
1250 fcb
= (struct FCB
*) xfcb
->fcb
;
1254 file_path
[0] = 'A' + INT21_MapDrive( fcb
->drive_number
);
1256 if (AL_result
== 0) {
1258 pos
= &file_path
[2];
1259 memcpy(pos
, fcb
->file_name
, 8);
1262 pos
= strchr(pos
, ' ');
1265 memcpy(pos
, fcb
->file_extension
, 3);
1268 pos
= strchr(pos
, ' ');
1271 handle
= (HANDLE
) _lopen(file_path
, OF_READWRITE
);
1272 if (handle
== INVALID_HANDLE_VALUE
) {
1273 TRACE("_lopen(\"%s\") failed: INVALID_HANDLE_VALUE\n", file_path
);
1274 AL_result
= 0xff; /* failed */
1276 hfile16
= Win32HandleToDosFileHandle(handle
);
1277 if (hfile16
== HFILE_ERROR16
) {
1278 TRACE("Win32HandleToDosFileHandle(%p) failed: HFILE_ERROR\n", handle
);
1279 CloseHandle(handle
);
1280 AL_result
= 0xff; /* failed */
1281 } else if (hfile16
> 255) {
1282 TRACE("hfile16 (=%d) larger than 255 for \"%s\"\n", hfile16
, file_path
);
1284 AL_result
= 0xff; /* failed */
1286 if (!GetFileInformationByHandle(handle
, &info
)) {
1287 TRACE("GetFileInformationByHandle(%d, %p) for \"%s\" failed\n",
1288 hfile16
, handle
, file_path
);
1290 AL_result
= 0xff; /* failed */
1292 fcb
->drive_number
= file_path
[0] - 'A' + 1;
1293 fcb
->current_block_number
= 0;
1294 fcb
->logical_record_size
= 128;
1295 fcb
->file_size
= info
.nFileSizeLow
;
1296 FileTimeToDosDateTime(&info
.ftLastWriteTime
,
1297 &fcb
->date_of_last_write
, &fcb
->time_of_last_write
);
1298 fcb
->file_number
= hfile16
;
1299 fcb
->attributes
= 0xc2;
1300 fcb
->starting_cluster
= 0; /* don't know correct init value */
1301 fcb
->sequence_number
= 0; /* don't know correct init value */
1302 fcb
->file_attributes
= info
.dwFileAttributes
;
1303 /* The following fields are not initialized */
1304 /* by the native function: */
1306 /* record_within_current_block */
1307 /* random_access_record_number */
1309 TRACE("successful opened file \"%s\" as %d (handle %p)\n",
1310 file_path
, hfile16
, handle
);
1311 AL_result
= 0x00; /* successful */
1316 SET_AL(context
, AL_result
);
1320 /***********************************************************************
1321 * INT21_CloseFileUsingFCB
1323 * Handler for function 0x10.
1326 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1333 * Closes a FCB file.
1335 static void INT21_CloseFileUsingFCB( CONTEXT
*context
)
1341 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1342 if (fcb
->drive_number
== 0xff) {
1343 xfcb
= (struct XFCB
*) fcb
;
1344 fcb
= (struct FCB
*) xfcb
->fcb
;
1347 if (_lclose16((HFILE16
) fcb
->file_number
) != 0) {
1348 TRACE("_lclose16(%d) failed\n", fcb
->file_number
);
1349 AL_result
= 0xff; /* failed */
1351 TRACE("successful closed file %d\n", fcb
->file_number
);
1352 AL_result
= 0x00; /* successful */
1354 SET_AL(context
, AL_result
);
1358 /***********************************************************************
1359 * INT21_SequentialReadFromFCB
1361 * Handler for function 0x14.
1364 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1368 * 1: end of file, no data read
1369 * 2: segment wrap in DTA, no data read (not returned now)
1370 * 3: end of file, partial record read
1373 * Reads a record with the size FCB->logical_record_size from the FCB
1374 * to the disk transfer area. The position of the record is specified
1375 * with FCB->current_block_number and FCB->record_within_current_block.
1376 * Then FCB->current_block_number and FCB->record_within_current_block
1377 * are updated to point to the next record. If a partial record is
1378 * read, it is filled with zeros up to the FCB->logical_record_size.
1380 static void INT21_SequentialReadFromFCB( CONTEXT
*context
)
1385 DWORD record_number
;
1387 BYTE
*disk_transfer_area
;
1391 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1392 if (fcb
->drive_number
== 0xff) {
1393 xfcb
= (struct XFCB
*) fcb
;
1394 fcb
= (struct FCB
*) xfcb
->fcb
;
1397 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1398 if (handle
== INVALID_HANDLE_VALUE
) {
1399 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1401 AL_result
= 0x01; /* end of file, no data read */
1403 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1404 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1405 if (position
!= record_number
* fcb
->logical_record_size
) {
1406 TRACE("seek(%d, %d, 0) failed with %u\n",
1407 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1408 AL_result
= 0x01; /* end of file, no data read */
1410 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1411 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1412 if (bytes_read
!= fcb
->logical_record_size
) {
1413 TRACE("_lread(%d, %p, %d) failed with %d\n",
1414 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1415 if (bytes_read
== 0) {
1416 AL_result
= 0x01; /* end of file, no data read */
1418 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1419 AL_result
= 0x03; /* end of file, partial record read */
1422 TRACE("successful read %d bytes from record %d (position %u) of file %d (handle %p)\n",
1423 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1424 AL_result
= 0x00; /* successful */
1428 if (AL_result
== 0x00 || AL_result
== 0x03) {
1429 if (fcb
->record_within_current_block
== 127) {
1430 fcb
->record_within_current_block
= 0;
1431 fcb
->current_block_number
++;
1433 fcb
->record_within_current_block
++;
1436 SET_AL(context
, AL_result
);
1440 /***********************************************************************
1441 * INT21_SequentialWriteToFCB
1443 * Handler for function 0x15.
1446 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1451 * 2: segment wrap in DTA (not returned now)
1454 * Writes a record with the size FCB->logical_record_size from the disk
1455 * transfer area to the FCB. The position of the record is specified
1456 * with FCB->current_block_number and FCB->record_within_current_block.
1457 * Then FCB->current_block_number and FCB->record_within_current_block
1458 * are updated to point to the next record.
1460 static void INT21_SequentialWriteToFCB( CONTEXT
*context
)
1465 DWORD record_number
;
1467 BYTE
*disk_transfer_area
;
1471 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1472 if (fcb
->drive_number
== 0xff) {
1473 xfcb
= (struct XFCB
*) fcb
;
1474 fcb
= (struct FCB
*) xfcb
->fcb
;
1477 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1478 if (handle
== INVALID_HANDLE_VALUE
) {
1479 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1481 AL_result
= 0x01; /* disk full */
1483 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1484 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1485 if (position
!= record_number
* fcb
->logical_record_size
) {
1486 TRACE("seek(%d, %d, 0) failed with %u\n",
1487 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1488 AL_result
= 0x01; /* disk full */
1490 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1491 bytes_written
= _lwrite((HFILE
) handle
, (LPCSTR
)disk_transfer_area
, fcb
->logical_record_size
);
1492 if (bytes_written
!= fcb
->logical_record_size
) {
1493 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1494 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1495 AL_result
= 0x01; /* disk full */
1497 TRACE("successful written %d bytes from record %d (position %u) of file %d (handle %p)\n",
1498 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1499 AL_result
= 0x00; /* successful */
1503 if (AL_result
== 0x00) {
1504 if (fcb
->record_within_current_block
== 127) {
1505 fcb
->record_within_current_block
= 0;
1506 fcb
->current_block_number
++;
1508 fcb
->record_within_current_block
++;
1511 SET_AL(context
, AL_result
);
1515 /***********************************************************************
1516 * INT21_ReadRandomRecordFromFCB
1518 * Handler for function 0x21.
1521 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1525 * 1: end of file, no data read
1526 * 2: segment wrap in DTA, no data read (not returned now)
1527 * 3: end of file, partial record read
1530 * Reads a record with the size FCB->logical_record_size from
1531 * the FCB to the disk transfer area. The position of the record
1532 * is specified with FCB->random_access_record_number. The
1533 * FCB->random_access_record_number is not updated. If a partial record
1534 * is read, it is filled with zeros up to the FCB->logical_record_size.
1536 static void INT21_ReadRandomRecordFromFCB( CONTEXT
*context
)
1541 DWORD record_number
;
1543 BYTE
*disk_transfer_area
;
1547 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1548 if (fcb
->drive_number
== 0xff) {
1549 xfcb
= (struct XFCB
*) fcb
;
1550 fcb
= (struct FCB
*) xfcb
->fcb
;
1553 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1554 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1555 if (handle
== INVALID_HANDLE_VALUE
) {
1556 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1558 AL_result
= 0x01; /* end of file, no data read */
1560 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1561 if (position
!= record_number
* fcb
->logical_record_size
) {
1562 TRACE("seek(%d, %d, 0) failed with %u\n",
1563 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1564 AL_result
= 0x01; /* end of file, no data read */
1566 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1567 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1568 if (bytes_read
!= fcb
->logical_record_size
) {
1569 TRACE("_lread(%d, %p, %d) failed with %d\n",
1570 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1571 if (bytes_read
== 0) {
1572 AL_result
= 0x01; /* end of file, no data read */
1574 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1575 AL_result
= 0x03; /* end of file, partial record read */
1578 TRACE("successful read %d bytes from record %d (position %u) of file %d (handle %p)\n",
1579 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1580 AL_result
= 0x00; /* successful */
1584 fcb
->current_block_number
= record_number
/ 128;
1585 fcb
->record_within_current_block
= record_number
% 128;
1586 SET_AL(context
, AL_result
);
1590 /***********************************************************************
1591 * INT21_WriteRandomRecordToFCB
1593 * Handler for function 0x22.
1596 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1601 * 2: segment wrap in DTA (not returned now)
1604 * Writes a record with the size FCB->logical_record_size from
1605 * the disk transfer area to the FCB. The position of the record
1606 * is specified with FCB->random_access_record_number. The
1607 * FCB->random_access_record_number is not updated.
1609 static void INT21_WriteRandomRecordToFCB( CONTEXT
*context
)
1614 DWORD record_number
;
1616 BYTE
*disk_transfer_area
;
1620 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1621 if (fcb
->drive_number
== 0xff) {
1622 xfcb
= (struct XFCB
*) fcb
;
1623 fcb
= (struct FCB
*) xfcb
->fcb
;
1626 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1627 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1628 if (handle
== INVALID_HANDLE_VALUE
) {
1629 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1631 AL_result
= 0x01; /* disk full */
1633 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1634 if (position
!= record_number
* fcb
->logical_record_size
) {
1635 TRACE("seek(%d, %d, 0) failed with %u\n",
1636 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1637 AL_result
= 0x01; /* disk full */
1639 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1640 bytes_written
= _lwrite((HFILE
) handle
, (LPCSTR
)disk_transfer_area
, fcb
->logical_record_size
);
1641 if (bytes_written
!= fcb
->logical_record_size
) {
1642 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1643 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1644 AL_result
= 0x01; /* disk full */
1646 TRACE("successful written %d bytes from record %d (position %u) of file %d (handle %p)\n",
1647 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1648 AL_result
= 0x00; /* successful */
1652 fcb
->current_block_number
= record_number
/ 128;
1653 fcb
->record_within_current_block
= record_number
% 128;
1654 SET_AL(context
, AL_result
);
1658 /***********************************************************************
1659 * INT21_RandomBlockReadFromFCB
1661 * Handler for function 0x27.
1664 * CX [I/O] Number of records to read
1665 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1669 * 1: end of file, no data read
1670 * 2: segment wrap in DTA, no data read (not returned now)
1671 * 3: end of file, partial record read
1674 * Reads several records with the size FCB->logical_record_size from
1675 * the FCB to the disk transfer area. The number of records to be
1676 * read is specified in the CX register. The position of the first
1677 * record is specified with FCB->random_access_record_number. The
1678 * FCB->random_access_record_number, the FCB->current_block_number
1679 * and FCB->record_within_current_block are updated to point to the
1680 * next record after the records read. If a partial record is read,
1681 * it is filled with zeros up to the FCB->logical_record_size. The
1682 * CX register is set to the number of successfully read records.
1684 static void INT21_RandomBlockReadFromFCB( CONTEXT
*context
)
1689 DWORD record_number
;
1691 BYTE
*disk_transfer_area
;
1692 UINT records_requested
;
1693 UINT bytes_requested
;
1698 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1699 if (fcb
->drive_number
== 0xff) {
1700 xfcb
= (struct XFCB
*) fcb
;
1701 fcb
= (struct FCB
*) xfcb
->fcb
;
1704 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1705 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1706 if (handle
== INVALID_HANDLE_VALUE
) {
1707 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1710 AL_result
= 0x01; /* end of file, no data read */
1712 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1713 if (position
!= record_number
* fcb
->logical_record_size
) {
1714 TRACE("seek(%d, %d, 0) failed with %u\n",
1715 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1717 AL_result
= 0x01; /* end of file, no data read */
1719 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1720 records_requested
= CX_reg(context
);
1721 bytes_requested
= records_requested
* fcb
->logical_record_size
;
1722 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1723 if (bytes_read
!= bytes_requested
) {
1724 TRACE("_lread(%d, %p, %d) failed with %d\n",
1725 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_read
);
1726 records_read
= bytes_read
/ fcb
->logical_record_size
;
1727 if (bytes_read
% fcb
->logical_record_size
== 0) {
1728 AL_result
= 0x01; /* end of file, no data read */
1731 memset(&disk_transfer_area
[bytes_read
], 0, records_read
* fcb
->logical_record_size
- bytes_read
);
1732 AL_result
= 0x03; /* end of file, partial record read */
1735 TRACE("successful read %d bytes from record %d (position %u) of file %d (handle %p)\n",
1736 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1737 records_read
= records_requested
;
1738 AL_result
= 0x00; /* successful */
1742 record_number
+= records_read
;
1743 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1744 fcb
->current_block_number
= record_number
/ 128;
1745 fcb
->record_within_current_block
= record_number
% 128;
1746 SET_CX(context
, records_read
);
1747 SET_AL(context
, AL_result
);
1751 /***********************************************************************
1752 * INT21_RandomBlockWriteToFCB
1754 * Handler for function 0x28.
1757 * CX [I/O] Number of records to write
1758 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1763 * 2: segment wrap in DTA (not returned now)
1766 * Writes several records with the size FCB->logical_record_size from
1767 * the disk transfer area to the FCB. The number of records to be
1768 * written is specified in the CX register. The position of the first
1769 * record is specified with FCB->random_access_record_number. The
1770 * FCB->random_access_record_number, the FCB->current_block_number
1771 * and FCB->record_within_current_block are updated to point to the
1772 * next record after the records written. The CX register is set to
1773 * the number of successfully written records.
1775 static void INT21_RandomBlockWriteToFCB( CONTEXT
*context
)
1780 DWORD record_number
;
1782 BYTE
*disk_transfer_area
;
1783 UINT records_requested
;
1784 UINT bytes_requested
;
1786 UINT records_written
;
1789 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1790 if (fcb
->drive_number
== 0xff) {
1791 xfcb
= (struct XFCB
*) fcb
;
1792 fcb
= (struct FCB
*) xfcb
->fcb
;
1795 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1796 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1797 if (handle
== INVALID_HANDLE_VALUE
) {
1798 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1800 records_written
= 0;
1801 AL_result
= 0x01; /* disk full */
1803 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1804 if (position
!= record_number
* fcb
->logical_record_size
) {
1805 TRACE("seek(%d, %d, 0) failed with %u\n",
1806 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1807 records_written
= 0;
1808 AL_result
= 0x01; /* disk full */
1810 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1811 records_requested
= CX_reg(context
);
1812 bytes_requested
= records_requested
* fcb
->logical_record_size
;
1813 bytes_written
= _lwrite((HFILE
) handle
, (LPCSTR
)disk_transfer_area
, bytes_requested
);
1814 if (bytes_written
!= bytes_requested
) {
1815 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1816 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_written
);
1817 records_written
= bytes_written
/ fcb
->logical_record_size
;
1818 AL_result
= 0x01; /* disk full */
1820 TRACE("successful write %d bytes from record %d (position %u) of file %d (handle %p)\n",
1821 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1822 records_written
= records_requested
;
1823 AL_result
= 0x00; /* successful */
1827 record_number
+= records_written
;
1828 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1829 fcb
->current_block_number
= record_number
/ 128;
1830 fcb
->record_within_current_block
= record_number
% 128;
1831 SET_CX(context
, records_written
);
1832 SET_AL(context
, AL_result
);
1836 /***********************************************************************
1837 * INT21_CreateDirectory
1841 * - subfunction 0x39 of function 0x71
1842 * - subfunction 0xff of function 0x43 (CL == 0x39)
1844 static BOOL
INT21_CreateDirectory( CONTEXT
*context
)
1846 WCHAR dirW
[MAX_PATH
];
1847 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
1851 TRACE( "CREATE DIRECTORY %s\n", dirA
);
1853 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
1855 if (CreateDirectoryW(dirW
, NULL
))
1859 * FIXME: CreateDirectory's LastErrors will clash with the ones
1860 * used by DOS. AH=39 only returns 3 (path not found) and
1861 * 5 (access denied), while CreateDirectory return several
1862 * ones. Remap some of them. -Marcus
1864 switch (GetLastError())
1866 case ERROR_ALREADY_EXISTS
:
1867 case ERROR_FILENAME_EXCED_RANGE
:
1868 case ERROR_DISK_FULL
:
1869 SetLastError(ERROR_ACCESS_DENIED
);
1879 /***********************************************************************
1880 * INT21_ExtendedCountryInformation
1882 * Handler for function 0x65.
1884 static void INT21_ExtendedCountryInformation( CONTEXT
*context
)
1886 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN( context
, context
->SegEs
, context
->Edi
);
1887 BYTE buffsize
= CX_reg (context
);
1889 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
1893 * Check subfunctions that are passed country and code page.
1895 if (AL_reg(context
) >= 0x01 && AL_reg(context
) <= 0x07)
1897 WORD country
= DX_reg(context
);
1898 WORD codepage
= BX_reg(context
);
1900 if (country
!= 0xffff && country
!= INT21_GetSystemCountryCode())
1901 FIXME( "Requested info on non-default country %04x\n", country
);
1903 if (codepage
!= 0xffff && codepage
!= GetOEMCP())
1904 FIXME( "Requested info on non-default code page %04x\n", codepage
);
1907 switch (AL_reg(context
)) {
1908 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
1909 INT_BARF( context
, 0x21 );
1910 SET_CFLAG( context
);
1913 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
1914 TRACE( "Get general internationalization info\n" );
1915 dataptr
[0] = 0x01; /* Info ID */
1916 *(WORD
*)(dataptr
+1) = 38; /* Size of the following info */
1917 *(WORD
*)(dataptr
+3) = INT21_GetSystemCountryCode(); /* Country ID */
1918 *(WORD
*)(dataptr
+5) = GetOEMCP(); /* Code page */
1919 /* FIXME: fill buffer partially up to buffsize bytes*/
1920 if (buffsize
>= 0x29){
1921 INT21_FillCountryInformation( dataptr
+ 7 );
1922 SET_CX( context
, 0x29 ); /* Size of returned info */
1924 SET_CX( context
, 0x07 ); /* Size of returned info */
1928 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
1929 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
1930 TRACE( "Get pointer to uppercase table\n" );
1931 dataptr
[0] = AL_reg(context
); /* Info ID */
1932 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1933 offsetof(INT21_HEAP
, uppercase_size
) );
1934 SET_CX( context
, 5 ); /* Size of returned info */
1937 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
1938 TRACE( "Get pointer to lowercase table\n" );
1939 dataptr
[0] = 0x03; /* Info ID */
1940 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1941 offsetof(INT21_HEAP
, lowercase_size
) );
1942 SET_CX( context
, 5 ); /* Size of returned info */
1945 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
1946 TRACE("Get pointer to filename terminator table\n");
1947 dataptr
[0] = 0x05; /* Info ID */
1948 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1949 offsetof(INT21_HEAP
, filename_size
) );
1950 SET_CX( context
, 5 ); /* Size of returned info */
1953 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
1954 TRACE("Get pointer to collating sequence table\n");
1955 dataptr
[0] = 0x06; /* Info ID */
1956 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1957 offsetof(INT21_HEAP
, collating_size
) );
1958 SET_CX( context
, 5 ); /* Size of returned info */
1961 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
1962 TRACE("Get pointer to DBCS lead byte table\n");
1963 dataptr
[0] = 0x07; /* Info ID */
1964 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1965 offsetof(INT21_HEAP
, dbcs_size
) );
1966 SET_CX( context
, 5 ); /* Size of returned info */
1969 case 0x20: /* CAPITALIZE CHARACTER */
1970 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
1971 TRACE("Convert char to uppercase\n");
1972 SET_DL( context
, toupper(DL_reg(context
)) );
1975 case 0x21: /* CAPITALIZE STRING */
1976 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
1977 TRACE("Convert string to uppercase with length\n");
1979 char *ptr
= CTX_SEG_OFF_TO_LIN( context
, context
->SegDs
,
1981 WORD len
= CX_reg(context
);
1982 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
1986 case 0x22: /* CAPITALIZE ASCIIZ STRING */
1987 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
1988 TRACE("Convert ASCIIZ string to uppercase\n");
1990 char *p
= CTX_SEG_OFF_TO_LIN( context
, context
->SegDs
, context
->Edx
);
1991 for ( ; *p
; p
++) *p
= toupper(*p
);
1995 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
1996 INT_BARF( context
, 0x21 );
1997 SET_CFLAG( context
);
2001 INT_BARF( context
, 0x21 );
2008 /***********************************************************************
2009 * INT21_FileAttributes
2013 * - subfunction 0x43 of function 0x71
2015 static BOOL
INT21_FileAttributes( CONTEXT
*context
,
2019 WCHAR fileW
[MAX_PATH
];
2020 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
2030 switch (subfunction
)
2032 case 0x00: /* GET FILE ATTRIBUTES */
2033 TRACE( "GET FILE ATTRIBUTES for %s\n", fileA
);
2034 len
= MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2036 /* Winbench 96 Disk Test fails if we don't complain
2037 * about a filename that ends in \
2039 if (!len
|| (fileW
[len
-1] == '/') || (fileW
[len
-1] == '\\'))
2042 result
= GetFileAttributesW( fileW
);
2043 if (result
== INVALID_FILE_ATTRIBUTES
)
2047 SET_CX( context
, (WORD
)result
);
2049 SET_AX( context
, (WORD
)result
); /* DR DOS */
2053 case 0x01: /* SET FILE ATTRIBUTES */
2054 TRACE( "SET FILE ATTRIBUTES 0x%02x for %s\n",
2055 CX_reg(context
), fileA
);
2056 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2058 if (!SetFileAttributesW( fileW
, CX_reg(context
) ))
2062 case 0x02: /* GET COMPRESSED FILE SIZE */
2063 TRACE( "GET COMPRESSED FILE SIZE for %s\n", fileA
);
2064 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2066 result
= GetCompressedFileSizeW( fileW
, NULL
);
2067 if (result
== INVALID_FILE_SIZE
)
2071 SET_AX( context
, LOWORD(result
) );
2072 SET_DX( context
, HIWORD(result
) );
2076 case 0x03: /* SET FILE LAST-WRITTEN DATE AND TIME */
2078 INT_BARF( context
, 0x21 );
2081 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
2082 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2084 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2085 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2086 NULL
, OPEN_EXISTING
, 0, 0 );
2087 if (handle
== INVALID_HANDLE_VALUE
)
2090 DosDateTimeToFileTime( DI_reg(context
),
2093 status
= SetFileTime( handle
, NULL
, NULL
, &filetime
);
2095 CloseHandle( handle
);
2100 case 0x04: /* GET FILE LAST-WRITTEN DATE AND TIME */
2102 INT_BARF( context
, 0x21 );
2105 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
2106 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2108 handle
= CreateFileW( fileW
, GENERIC_READ
,
2109 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2110 NULL
, OPEN_EXISTING
, 0, 0 );
2111 if (handle
== INVALID_HANDLE_VALUE
)
2114 status
= GetFileTime( handle
, NULL
, NULL
, &filetime
);
2117 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2118 SET_DI( context
, date
);
2119 SET_CX( context
, time
);
2122 CloseHandle( handle
);
2127 case 0x05: /* SET FILE LAST ACCESS DATE */
2129 INT_BARF( context
, 0x21 );
2132 TRACE( "SET FILE LAST ACCESS DATE, file %s\n", fileA
);
2133 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2135 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2136 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2137 NULL
, OPEN_EXISTING
, 0, 0 );
2138 if (handle
== INVALID_HANDLE_VALUE
)
2141 DosDateTimeToFileTime( DI_reg(context
),
2144 status
= SetFileTime( handle
, NULL
, &filetime
, NULL
);
2146 CloseHandle( handle
);
2151 case 0x06: /* GET FILE LAST ACCESS DATE */
2153 INT_BARF( context
, 0x21 );
2156 TRACE( "GET FILE LAST ACCESS DATE, file %s\n", fileA
);
2157 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2159 handle
= CreateFileW( fileW
, GENERIC_READ
,
2160 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2161 NULL
, OPEN_EXISTING
, 0, 0 );
2162 if (handle
== INVALID_HANDLE_VALUE
)
2165 status
= GetFileTime( handle
, NULL
, &filetime
, NULL
);
2168 FileTimeToDosDateTime( &filetime
, &date
, NULL
);
2169 SET_DI( context
, date
);
2172 CloseHandle( handle
);
2177 case 0x07: /* SET FILE CREATION DATE AND TIME */
2179 INT_BARF( context
, 0x21 );
2182 TRACE( "SET FILE CREATION DATE AND TIME, file %s\n", fileA
);
2183 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2185 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2186 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2187 NULL
, OPEN_EXISTING
, 0, 0 );
2188 if (handle
== INVALID_HANDLE_VALUE
)
2192 * FIXME: SI has number of 10-millisecond units past time in CX.
2194 DosDateTimeToFileTime( DI_reg(context
),
2197 status
= SetFileTime( handle
, &filetime
, NULL
, NULL
);
2199 CloseHandle( handle
);
2204 case 0x08: /* GET FILE CREATION DATE AND TIME */
2206 INT_BARF( context
, 0x21 );
2209 TRACE( "GET FILE CREATION DATE AND TIME, file %s\n", fileA
);
2210 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2212 handle
= CreateFileW( fileW
, GENERIC_READ
,
2213 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2214 NULL
, OPEN_EXISTING
, 0, 0 );
2215 if (handle
== INVALID_HANDLE_VALUE
)
2218 status
= GetFileTime( handle
, &filetime
, NULL
, NULL
);
2221 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2222 SET_DI( context
, date
);
2223 SET_CX( context
, time
);
2225 * FIXME: SI has number of 10-millisecond units past
2228 SET_SI( context
, 0 );
2231 CloseHandle(handle
);
2236 case 0xff: /* EXTENDED-LENGTH FILENAME OPERATIONS */
2237 if (islong
|| context
->Ebp
!= 0x5053)
2238 INT_BARF( context
, 0x21 );
2241 switch(CL_reg(context
))
2244 if (!INT21_CreateDirectory( context
))
2249 if (!INT21_RenameFile( context
))
2254 INT_BARF( context
, 0x21 );
2260 INT_BARF( context
, 0x21 );
2267 /***********************************************************************
2268 * INT21_FileDateTime
2270 * Handler for function 0x57.
2272 static BOOL
INT21_FileDateTime( CONTEXT
*context
)
2274 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2278 switch (AL_reg(context
)) {
2279 case 0x00: /* Get last-written stamp */
2280 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2283 if (!GetFileTime( handle
, NULL
, NULL
, &filetime
))
2285 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2286 SET_DX( context
, date
);
2287 SET_CX( context
, time
);
2291 case 0x01: /* Set last-written stamp */
2292 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2295 DosDateTimeToFileTime( DX_reg(context
),
2298 if (!SetFileTime( handle
, NULL
, NULL
, &filetime
))
2303 case 0x04: /* Get last access stamp, DOS 7 */
2304 TRACE( "GET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2307 if (!GetFileTime( handle
, NULL
, &filetime
, NULL
))
2309 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2310 SET_DX( context
, date
);
2311 SET_CX( context
, time
);
2315 case 0x05: /* Set last access stamp, DOS 7 */
2316 TRACE( "SET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2319 DosDateTimeToFileTime( DX_reg(context
),
2322 if (!SetFileTime( handle
, NULL
, &filetime
, NULL
))
2327 case 0x06: /* Get creation stamp, DOS 7 */
2328 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2331 if (!GetFileTime( handle
, &filetime
, NULL
, NULL
))
2333 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2334 SET_DX( context
, date
);
2335 SET_CX( context
, time
);
2337 * FIXME: SI has number of 10-millisecond units past time in CX.
2339 SET_SI( context
, 0 );
2343 case 0x07: /* Set creation stamp, DOS 7 */
2344 TRACE( "SET FILE CREATION DATE AND TIME, handle %d\n",
2348 * FIXME: SI has number of 10-millisecond units past time in CX.
2350 DosDateTimeToFileTime( DX_reg(context
),
2353 if (!SetFileTime( handle
, &filetime
, NULL
, NULL
))
2359 INT_BARF( context
, 0x21 );
2367 /***********************************************************************
2370 * Handler for functions 0x51 and 0x62.
2372 static void INT21_GetPSP( CONTEXT
*context
)
2374 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context
) );
2377 * FIXME: should we return the original DOS PSP upon
2380 if (!ISV86(context
) && DOSVM_IsWin16())
2381 SET_BX( context
, LOWORD(GetCurrentPDB16()) );
2383 SET_BX( context
, DOSVM_psp
);
2386 static inline void setword( BYTE
*ptr
, WORD w
)
2389 ptr
[1] = (BYTE
)(w
>> 8);
2392 static void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
2393 /* limited == TRUE is used with INT 0x21/0x440d */
2395 /* FIXME: we're forcing some values without checking that those are valid */
2400 setword(&data
[3], 0);
2402 setword(&data
[6], 240);
2403 setword(&data
[8], 64000);
2405 setword(&data
[0x0b], 40);
2406 setword(&data
[0x0d], 56);
2407 setword(&data
[0x0f], 2);
2408 setword(&data
[0x11], 0);
2411 setword(&data
[0x1f], 800);
2413 setword(&data
[0x22], 1);
2420 setword(&data
[3], 0);
2422 setword(&data
[6], 240);
2423 setword(&data
[8], 2880);
2425 setword(&data
[0x0b], 6);
2426 setword(&data
[0x0d], 18);
2427 setword(&data
[0x0f], 2);
2428 setword(&data
[0x11], 0);
2431 setword(&data
[0x1f], 80);
2433 setword(&data
[0x22], 2);
2438 static inline DWORD
INT21_Ioctl_CylHeadSect2Lin(DWORD cyl
, WORD head
, WORD sec
, WORD cyl_cnt
,
2439 WORD head_cnt
, WORD sec_cnt
)
2441 DWORD res
= (cyl
* head_cnt
*sec_cnt
+ head
* sec_cnt
+ sec
);
2445 /***********************************************************************
2448 * Handler for block device IOCTLs.
2450 static void INT21_Ioctl_Block( CONTEXT
*context
)
2453 BYTE drive
= INT21_MapDrive( BL_reg(context
) );
2454 WCHAR drivespec
[] = {'A', ':', '\\', 0};
2457 drivespec
[0] += drive
;
2458 drivetype
= GetDriveTypeW( drivespec
);
2460 RESET_CFLAG(context
);
2461 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
2463 TRACE( "IOCTL - SUBFUNCTION %d - INVALID DRIVE %c:\n",
2464 AL_reg(context
), 'A' + drive
);
2465 SetLastError( ERROR_INVALID_DRIVE
);
2466 SET_AX( context
, ERROR_INVALID_DRIVE
);
2467 SET_CFLAG( context
);
2471 switch (AL_reg(context
))
2473 case 0x04: /* READ FROM BLOCK DEVICE CONTROL CHANNEL */
2474 case 0x05: /* WRITE TO BLOCK DEVICE CONTROL CHANNEL */
2475 INT_BARF( context
, 0x21 );
2478 case 0x08: /* CHECK IF BLOCK DEVICE REMOVABLE */
2479 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOVABLE - %c:\n",
2482 if (drivetype
== DRIVE_REMOVABLE
)
2483 SET_AX( context
, 0 ); /* removable */
2485 SET_AX( context
, 1 ); /* not removable */
2488 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
2489 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOTE - %c:\n",
2492 if (drivetype
== DRIVE_REMOTE
)
2493 SET_DX( context
, (1<<9) | (1<<12) ); /* remote + no direct IO */
2494 else if (drivetype
== DRIVE_CDROM
)
2495 /* CDROM should be set to remote. If it set the app will
2496 * call int2f to check if it cdrom or remote drive. */
2497 SET_DX( context
, (1<<12) );
2498 else if (drivetype
== DRIVE_FIXED
)
2499 /* This should define if drive support 0x0d, 0x0f and 0x08
2500 * requests. The local fixed drive should do. */
2501 SET_DX( context
, (1<<11) );
2503 SET_DX( context
, 0 ); /* FIXME: use driver attr here */
2506 case 0x0d: /* GENERIC BLOCK DEVICE REQUEST */
2507 /* Get pointer to IOCTL parameter block */
2508 dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2510 switch (CX_reg(context
))
2512 case 0x0841: /* write logical device track */
2513 TRACE( "GENERIC IOCTL - Write logical device track - %c:\n",
2516 WORD head
= *(WORD
*)(dataptr
+1);
2517 WORD cyl
= *(WORD
*)(dataptr
+3);
2518 WORD sect
= *(WORD
*)(dataptr
+5);
2519 WORD nrsect
= *(WORD
*)(dataptr
+7);
2520 BYTE
*data
= CTX_SEG_OFF_TO_LIN(context
, *(WORD
*)(dataptr
+11), *(WORD
*)(dataptr
+9));
2521 WORD cyl_cnt
, head_cnt
, sec_cnt
;
2523 /* FIXME: we're faking some values here */
2529 SET_AX( context
, ERROR_WRITE_FAULT
);
2540 if (!DOSVM_RawWrite(drive
, INT21_Ioctl_CylHeadSect2Lin(cyl
, head
, sect
, cyl_cnt
, head_cnt
, sec_cnt
), nrsect
, data
, FALSE
))
2542 SET_AX( context
, ERROR_WRITE_FAULT
);
2548 case 0x084a: /* lock logical volume */
2549 TRACE( "GENERIC IOCTL - Lock logical volume, level %d mode %d - %c:\n",
2550 BH_reg(context
), DX_reg(context
), 'A' + drive
);
2553 case 0x0860: /* get device parameters */
2554 /* FIXME: we're faking some values here */
2555 /* used by w4wgrp's winfile */
2556 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
2558 dataptr
[6] = 0; /* media type */
2561 dataptr
[1] = 0x05; /* fixed disk */
2562 setword(&dataptr
[2], 0x01); /* non removable */
2563 setword(&dataptr
[4], 0x300); /* # of cylinders */
2567 dataptr
[1] = 0x07; /* block dev, floppy */
2568 setword(&dataptr
[2], 0x02); /* removable */
2569 setword(&dataptr
[4], 80); /* # of cylinders */
2571 CreateBPB(drive
, &dataptr
[7], TRUE
);
2572 RESET_CFLAG(context
);
2575 case 0x0861: /* read logical device track */
2576 TRACE( "GENERIC IOCTL - Read logical device track - %c:\n",
2579 WORD head
= *(WORD
*)(dataptr
+1);
2580 WORD cyl
= *(WORD
*)(dataptr
+3);
2581 WORD sect
= *(WORD
*)(dataptr
+5);
2582 WORD nrsect
= *(WORD
*)(dataptr
+7);
2583 BYTE
*data
= CTX_SEG_OFF_TO_LIN(context
, *(WORD
*)(dataptr
+11), *(WORD
*)(dataptr
+9));
2584 WORD cyl_cnt
, head_cnt
, sec_cnt
;
2586 /* FIXME: we're faking some values here */
2600 if (!DOSVM_RawRead(drive
, INT21_Ioctl_CylHeadSect2Lin(cyl
, head
, sect
, cyl_cnt
, head_cnt
, sec_cnt
), nrsect
, data
, FALSE
))
2602 SET_AX( context
, ERROR_READ_FAULT
);
2608 case 0x0866: /* get volume serial number */
2610 WCHAR label
[12],fsname
[9];
2613 drivespec
[0] += drive
;
2614 GetVolumeInformationW(drivespec
, label
, 12, &serial
, NULL
, NULL
, fsname
, 9);
2615 *(WORD
*)dataptr
= 0;
2616 memcpy(dataptr
+2,&serial
,4);
2617 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, (LPSTR
)dataptr
+ 6, 11, NULL
, NULL
);
2618 WideCharToMultiByte(CP_OEMCP
, 0, fsname
, 8, (LPSTR
)dataptr
+ 17, 8, NULL
, NULL
);
2622 case 0x086a: /* unlock logical volume */
2623 TRACE( "GENERIC IOCTL - Logical volume unlocked - %c:\n",
2627 case 0x086f: /* get drive map information */
2628 memset(dataptr
+1, '\0', dataptr
[0]-1);
2629 dataptr
[1] = dataptr
[0];
2630 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
2631 dataptr
[3] = 0xFF; /* no physical drive */
2635 /* Trial and error implementation */
2636 SET_AX( context
, drivetype
== DRIVE_UNKNOWN
? 0x0f : 0x01 );
2637 SET_CFLAG(context
); /* Seems to be set all the time */
2641 INT_BARF( context
, 0x21 );
2645 case 0x0e: /* GET LOGICAL DRIVE MAP */
2646 TRACE( "IOCTL - GET LOGICAL DRIVE MAP - %c:\n",
2648 /* FIXME: this is not correct if drive has mappings */
2649 SET_AL( context
, 0 ); /* drive has no mapping */
2652 case 0x0f: /* SET LOGICAL DRIVE MAP */
2653 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
2654 INT21_DriveName( BL_reg(context
)));
2655 /* FIXME: as of today, we don't support logical drive mapping... */
2656 SET_AL( context
, 0 );
2659 case 0x11: /* QUERY GENERIC IOCTL CAPABILITY */
2661 INT_BARF( context
, 0x21 );
2666 /***********************************************************************
2667 * INT21_IoctlScsiMgrHandler
2669 * IOCTL handler for the SCSIMGR device.
2671 static void INT21_IoctlScsiMgrHandler( CONTEXT
*context
)
2673 switch (AL_reg(context
))
2675 case 0x00: /* GET DEVICE INFORMATION */
2676 SET_DX( context
, 0xc0c0 );
2679 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2680 DOSVM_ASPIHandler(context
);
2683 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2684 SET_DX( context
, 0 );
2687 case 0x01: /* SET DEVICE INFORMATION */
2688 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2689 case 0x06: /* GET INPUT STATUS */
2690 case 0x07: /* GET OUTPUT STATUS */
2691 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2692 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2694 INT_BARF( context
, 0x21 );
2700 /***********************************************************************
2701 * INT21_IoctlHPScanHandler
2703 * IOCTL handler for the HPSCAN device.
2705 static void INT21_IoctlHPScanHandler( CONTEXT
*context
)
2707 switch (AL_reg(context
))
2709 case 0x00: /* GET DEVICE INFORMATION */
2710 SET_DX( context
, 0xc0c0 );
2713 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2714 SET_DX( context
, 0 );
2717 case 0x01: /* SET DEVICE INFORMATION */
2718 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2719 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2720 case 0x06: /* GET INPUT STATUS */
2721 case 0x07: /* GET OUTPUT STATUS */
2722 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2723 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2725 INT_BARF( context
, 0x21 );
2731 /***********************************************************************
2734 * Handler for character device IOCTLs.
2736 static void INT21_Ioctl_Char( CONTEXT
*context
)
2739 int IsConsoleIOHandle
= 0;
2741 FILE_INTERNAL_INFORMATION info
;
2742 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2744 status
= NtQueryInformationFile( handle
, &io
, &info
, sizeof(info
), FileInternalInformation
);
2747 if( VerifyConsoleIoHandle( handle
))
2748 IsConsoleIOHandle
= 1;
2750 SET_AX( context
, RtlNtStatusToDosError(status
) );
2751 SET_CFLAG( context
);
2756 for (i
= 0; i
< NB_MAGIC_DEVICES
; i
++)
2758 if (!magic_devices
[i
].handle
) continue;
2759 if (magic_devices
[i
].index
.QuadPart
== info
.IndexNumber
.QuadPart
)
2762 magic_devices
[i
].ioctl_handler( context
);
2768 /* no magic device found, do default handling */
2770 switch (AL_reg(context
))
2772 case 0x00: /* GET DEVICE INFORMATION */
2773 TRACE( "IOCTL - GET DEVICE INFORMATION - %d\n", BX_reg(context
) );
2774 if (IsConsoleIOHandle
|| GetFileType(handle
) == FILE_TYPE_CHAR
)
2777 * Returns attribute word in DX:
2778 * Bit 14 - Device driver can process IOCTL requests.
2779 * Bit 13 - Output until busy supported.
2780 * Bit 11 - Driver supports OPEN/CLOSE calls.
2782 * Bit 7 - Set (indicates device).
2783 * Bit 6 - EOF on input.
2784 * Bit 5 - Raw (binary) mode.
2785 * Bit 4 - Device is special (uses int29).
2786 * Bit 3 - Clock device.
2787 * Bit 2 - NUL device.
2788 * Bit 1 - Console output device.
2789 * Bit 0 - Console input device.
2791 SET_DX( context
, IsConsoleIOHandle
? 0x80c3 : 0x80c0 /* FIXME */ );
2796 * Returns attribute word in DX:
2797 * Bit 15 - File is remote.
2798 * Bit 14 - Don't set file date/time on closing.
2799 * Bit 11 - Media not removable.
2800 * Bit 8 - Generate int24 if no disk space on write
2801 * or read past end of file
2802 * Bit 7 - Clear (indicates file).
2803 * Bit 6 - File has not been written.
2804 * Bit 5..0 - Drive number (0=A:,...)
2806 * FIXME: Should check if file is on remote or removable drive.
2807 * FIXME: Should use drive file is located on (and not current).
2809 SET_DX( context
, 0x0140 + INT21_GetCurrentDrive() );
2813 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2814 TRACE( "IOCTL - CHECK IF HANDLE IS REMOTE - %d\n", BX_reg(context
) );
2816 * Returns attribute word in DX:
2817 * Bit 15 - Set if remote.
2818 * Bit 14 - Set if date/time not set on close.
2820 * FIXME: Should check if file is on remote drive.
2822 SET_DX( context
, 0 );
2825 case 0x01: /* SET DEVICE INFORMATION */
2826 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2827 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2828 case 0x06: /* GET INPUT STATUS */
2829 case 0x07: /* GET OUTPUT STATUS */
2830 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2831 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2833 INT_BARF( context
, 0x21 );
2839 /***********************************************************************
2842 * Handler for function 0x44.
2844 static void INT21_Ioctl( CONTEXT
*context
)
2846 switch (AL_reg(context
))
2852 INT21_Ioctl_Char( context
);
2857 INT21_Ioctl_Block( context
);
2862 INT21_Ioctl_Char( context
);
2867 INT21_Ioctl_Block( context
);
2871 INT21_Ioctl_Char( context
);
2874 case 0x0b: /* SET SHARING RETRY COUNT */
2875 TRACE( "SET SHARING RETRY COUNT: Pause %d, retries %d.\n",
2876 CX_reg(context
), DX_reg(context
) );
2877 if (!CX_reg(context
))
2879 SET_AX( context
, 1 );
2880 SET_CFLAG( context
);
2884 DOSDEV_SetSharingRetry( CX_reg(context
), DX_reg(context
) );
2885 RESET_CFLAG( context
);
2890 INT21_Ioctl_Char( context
);
2896 INT21_Ioctl_Block( context
);
2900 INT21_Ioctl_Char( context
);
2904 INT21_Ioctl_Block( context
);
2907 case 0x12: /* DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION) */
2908 TRACE( "DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION)\n" );
2909 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2910 SET_AX( context
, 0x0001 ); /* Invalid function */
2913 case 0x52: /* DR DOS - DETERMINE DOS TYPE */
2914 TRACE( "DR DOS - DETERMINE DOS TYPE\n" );
2915 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2916 SET_AX( context
, 0x0001 ); /* Invalid function */
2919 case 0xe0: /* Sun PC-NFS API */
2920 TRACE( "Sun PC-NFS API\n" );
2925 INT_BARF( context
, 0x21 );
2930 /***********************************************************************
2933 * Handler for function 0x73.
2935 static BOOL
INT21_Fat32( CONTEXT
*context
)
2937 switch (AL_reg(context
))
2939 case 0x02: /* FAT32 - GET EXTENDED DPB */
2941 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
2942 WORD
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
2943 context
->SegEs
, context
->Edi
);
2944 INT21_DPB
*target
= (INT21_DPB
*)(ptr
+ 1);
2947 TRACE( "FAT32 - GET EXTENDED DPB %d\n", DL_reg(context
) );
2949 if ( CX_reg(context
) < sizeof(INT21_DPB
) + 2 || *ptr
< sizeof(INT21_DPB
) )
2951 SetLastError( ERROR_BAD_LENGTH
);
2955 if ( !INT21_FillDrivePB( drive
) )
2957 SetLastError( ERROR_INVALID_DRIVE
);
2961 source
= &INT21_GetHeapPointer()->misc_dpb_list
[drive
];
2963 *ptr
= sizeof(INT21_DPB
);
2966 if (LOWORD(context
->Esi
) != 0xF1A6)
2968 target
->driver_header
= 0;
2973 FIXME( "Caller requested driver and next DPB pointers!\n" );
2978 case 0x03: /* FAT32 - GET EXTENDED FREE SPACE ON DRIVE */
2980 WCHAR dirW
[MAX_PATH
];
2981 char *dirA
= CTX_SEG_OFF_TO_LIN( context
,
2982 context
->SegDs
, context
->Edx
);
2983 BYTE
*data
= CTX_SEG_OFF_TO_LIN( context
,
2984 context
->SegEs
, context
->Edi
);
2985 DWORD cluster_sectors
;
2987 DWORD free_clusters
;
2988 DWORD total_clusters
;
2990 TRACE( "FAT32 - GET EXTENDED FREE SPACE ON DRIVE %s\n", dirA
);
2991 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
2993 if (CX_reg(context
) < 44)
2995 SetLastError( ERROR_BAD_LENGTH
);
2999 if (!GetDiskFreeSpaceW( dirW
, &cluster_sectors
, §or_bytes
,
3000 &free_clusters
, &total_clusters
))
3003 *(WORD
*) (data
+ 0) = 44; /* size of structure */
3004 *(WORD
*) (data
+ 2) = 0; /* version */
3005 *(DWORD
*)(data
+ 4) = cluster_sectors
;
3006 *(DWORD
*)(data
+ 8) = sector_bytes
;
3007 *(DWORD
*)(data
+ 12) = free_clusters
;
3008 *(DWORD
*)(data
+ 16) = total_clusters
;
3011 * Below we have free/total sectors and
3012 * free/total allocation units without adjustment
3013 * for compression. We fake both using cluster information.
3015 *(DWORD
*)(data
+ 20) = free_clusters
* cluster_sectors
;
3016 *(DWORD
*)(data
+ 24) = total_clusters
* cluster_sectors
;
3017 *(DWORD
*)(data
+ 28) = free_clusters
;
3018 *(DWORD
*)(data
+ 32) = total_clusters
;
3021 * Between (data + 36) and (data + 43) there
3022 * are eight reserved bytes.
3028 INT_BARF( context
, 0x21 );
3034 static void INT21_ConvertFindDataWtoA(WIN32_FIND_DATAA
*dataA
,
3035 const WIN32_FIND_DATAW
*dataW
)
3037 dataA
->dwFileAttributes
= dataW
->dwFileAttributes
;
3038 dataA
->ftCreationTime
= dataW
->ftCreationTime
;
3039 dataA
->ftLastAccessTime
= dataW
->ftLastAccessTime
;
3040 dataA
->ftLastWriteTime
= dataW
->ftLastWriteTime
;
3041 dataA
->nFileSizeHigh
= dataW
->nFileSizeHigh
;
3042 dataA
->nFileSizeLow
= dataW
->nFileSizeLow
;
3043 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cFileName
, -1,
3044 dataA
->cFileName
, sizeof(dataA
->cFileName
), NULL
, NULL
);
3045 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cAlternateFileName
, -1,
3046 dataA
->cAlternateFileName
, sizeof(dataA
->cAlternateFileName
), NULL
, NULL
);
3049 /***********************************************************************
3050 * INT21_LongFilename
3052 * Handler for function 0x71.
3054 static void INT21_LongFilename( CONTEXT
*context
)
3056 BOOL bSetDOSExtendedError
= FALSE
;
3057 WCHAR pathW
[MAX_PATH
];
3060 switch (AL_reg(context
))
3062 case 0x0d: /* RESET DRIVE */
3063 INT_BARF( context
, 0x21 );
3066 case 0x39: /* LONG FILENAME - MAKE DIRECTORY */
3067 if (!INT21_CreateDirectory( context
))
3068 bSetDOSExtendedError
= TRUE
;
3071 case 0x3a: /* LONG FILENAME - REMOVE DIRECTORY */
3072 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3074 TRACE( "LONG FILENAME - REMOVE DIRECTORY %s\n", pathA
);
3075 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3076 if (!RemoveDirectoryW( pathW
)) bSetDOSExtendedError
= TRUE
;
3079 case 0x3b: /* LONG FILENAME - CHANGE DIRECTORY */
3080 if (!INT21_SetCurrentDirectory( context
))
3081 bSetDOSExtendedError
= TRUE
;
3084 case 0x41: /* LONG FILENAME - DELETE FILE */
3085 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3087 TRACE( "LONG FILENAME - DELETE FILE %s\n", pathA
);
3088 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3090 if (!DeleteFileW( pathW
)) bSetDOSExtendedError
= TRUE
;
3093 case 0x43: /* LONG FILENAME - EXTENDED GET/SET FILE ATTRIBUTES */
3094 if (!INT21_FileAttributes( context
, BL_reg(context
), TRUE
))
3095 bSetDOSExtendedError
= TRUE
;
3098 case 0x47: /* LONG FILENAME - GET CURRENT DIRECTORY */
3099 if (!INT21_GetCurrentDirectory( context
, TRUE
))
3100 bSetDOSExtendedError
= TRUE
;
3103 case 0x4e: /* LONG FILENAME - FIND FIRST MATCHING FILE */
3107 WIN32_FIND_DATAW dataW
;
3108 WIN32_FIND_DATAA
* dataA
;
3110 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
3111 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n", pathA
);
3113 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3114 handle
= FindFirstFileW(pathW
, &dataW
);
3116 dataA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
3117 if (handle
!= INVALID_HANDLE_VALUE
&&
3118 (h16
= GlobalAlloc16(GMEM_MOVEABLE
, sizeof(handle
))))
3120 HANDLE
* ptr
= GlobalLock16( h16
);
3122 GlobalUnlock16( h16
);
3123 SET_AX( context
, h16
);
3124 INT21_ConvertFindDataWtoA(dataA
, &dataW
);
3128 if (handle
!= INVALID_HANDLE_VALUE
) FindClose(handle
);
3129 SET_AX( context
, INVALID_HANDLE_VALUE16
);
3130 bSetDOSExtendedError
= TRUE
;
3135 case 0x4f: /* LONG FILENAME - FIND NEXT MATCHING FILE */
3137 HGLOBAL16 h16
= BX_reg(context
);
3139 WIN32_FIND_DATAW dataW
;
3140 WIN32_FIND_DATAA
* dataA
;
3142 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
3145 dataA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
3147 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
3149 if (!FindNextFileW(*ptr
, &dataW
)) bSetDOSExtendedError
= TRUE
;
3150 else INT21_ConvertFindDataWtoA(dataA
, &dataW
);
3151 GlobalUnlock16( h16
);
3155 SetLastError( ERROR_INVALID_HANDLE
);
3156 bSetDOSExtendedError
= TRUE
;
3161 case 0x56: /* LONG FILENAME - RENAME FILE */
3162 if (!INT21_RenameFile(context
))
3163 bSetDOSExtendedError
= TRUE
;
3166 case 0x60: /* LONG FILENAME - CONVERT PATH */
3168 WCHAR res
[MAX_PATH
];
3170 switch (CL_reg(context
))
3172 case 0x00: /* "truename" - Canonicalize path */
3174 * FIXME: This is not 100% equal to 0x01 case,
3175 * if you fix this, fix int21 subfunction 0x60, too.
3178 case 0x01: /* Get short filename or path */
3179 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
3180 if (!GetShortPathNameW(pathW
, res
, 67))
3181 bSetDOSExtendedError
= TRUE
;
3184 SET_AX( context
, 0 );
3185 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
3186 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3191 case 0x02: /* Get canonical long filename or path */
3192 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
3193 if (!GetFullPathNameW(pathW
, 128, res
, NULL
))
3194 bSetDOSExtendedError
= TRUE
;
3197 SET_AX( context
, 0 );
3198 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
3199 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3204 FIXME("Unimplemented long file name function:\n");
3205 INT_BARF( context
, 0x21 );
3207 SET_AL( context
, 0 );
3213 case 0x6c: /* LONG FILENAME - CREATE OR OPEN FILE */
3214 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
3215 BX_reg(context
), DL_reg(context
) ))
3216 bSetDOSExtendedError
= TRUE
;
3219 case 0xa0: /* LONG FILENAME - GET VOLUME INFORMATION */
3221 DWORD filename_len
, flags
;
3224 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
3226 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", pathA
);
3227 SET_AX( context
, 0 );
3228 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3229 if (!GetVolumeInformationW( pathW
, NULL
, 0, NULL
, &filename_len
,
3232 INT_BARF( context
, 0x21 );
3236 SET_BX( context
, flags
| 0x4000 ); /* support for LFN functions */
3237 SET_CX( context
, filename_len
);
3238 SET_DX( context
, MAX_PATH
); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
3239 WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1,
3240 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3245 case 0xa1: /* LONG FILENAME - "FindClose" - TERMINATE DIRECTORY SEARCH */
3247 HGLOBAL16 h16
= BX_reg(context
);
3250 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
3252 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
3254 if (!FindClose( *ptr
)) bSetDOSExtendedError
= TRUE
;
3255 GlobalUnlock16( h16
);
3256 GlobalFree16( h16
);
3260 SetLastError( ERROR_INVALID_HANDLE
);
3261 bSetDOSExtendedError
= TRUE
;
3266 case 0xa6: /* LONG FILENAME - GET FILE INFO BY HANDLE */
3268 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
3269 BY_HANDLE_FILE_INFORMATION
*info
=
3270 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3272 TRACE( "LONG FILENAME - GET FILE INFO BY HANDLE\n" );
3274 if (!GetFileInformationByHandle(handle
, info
))
3275 bSetDOSExtendedError
= TRUE
;
3279 case 0xa7: /* LONG FILENAME - CONVERT TIME */
3280 switch (BL_reg(context
))
3282 case 0x00: /* FILE TIME TO DOS TIME */
3285 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3289 TRACE( "LONG FILENAME - FILE TIME TO DOS TIME\n" );
3291 FileTimeToDosDateTime( filetime
, &date
, &time
);
3293 SET_DX( context
, date
);
3294 SET_CX( context
, time
);
3297 * FIXME: BH has number of 10-millisecond units
3300 SET_BH( context
, 0 );
3304 case 0x01: /* DOS TIME TO FILE TIME */
3306 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3310 TRACE( "LONG FILENAME - DOS TIME TO FILE TIME\n" );
3313 * FIXME: BH has number of 10-millisecond units
3316 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
3322 INT_BARF( context
, 0x21 );
3327 case 0xa8: /* LONG FILENAME - GENERATE SHORT FILENAME */
3328 case 0xa9: /* LONG FILENAME - SERVER CREATE OR OPEN FILE */
3329 case 0xaa: /* LONG FILENAME - SUBST */
3331 FIXME("Unimplemented long file name function:\n");
3332 INT_BARF( context
, 0x21 );
3334 SET_AL( context
, 0 );
3338 if (bSetDOSExtendedError
)
3340 SET_AX( context
, GetLastError() );
3341 SET_CFLAG( context
);
3346 /***********************************************************************
3351 * - subfunction 0x56 of function 0x71
3352 * - subfunction 0xff of function 0x43 (CL == 0x56)
3354 static BOOL
INT21_RenameFile( CONTEXT
*context
)
3356 WCHAR fromW
[MAX_PATH
];
3357 WCHAR toW
[MAX_PATH
];
3358 char *fromA
= CTX_SEG_OFF_TO_LIN(context
,
3359 context
->SegDs
,context
->Edx
);
3360 char *toA
= CTX_SEG_OFF_TO_LIN(context
,
3361 context
->SegEs
,context
->Edi
);
3363 TRACE( "RENAME FILE %s to %s\n", fromA
, toA
);
3364 MultiByteToWideChar(CP_OEMCP
, 0, fromA
, -1, fromW
, MAX_PATH
);
3365 MultiByteToWideChar(CP_OEMCP
, 0, toA
, -1, toW
, MAX_PATH
);
3367 return MoveFileW( fromW
, toW
);
3371 /***********************************************************************
3377 static BOOL
INT21_NetworkFunc (CONTEXT
*context
)
3379 switch (AL_reg(context
))
3381 case 0x00: /* Get machine name. */
3383 WCHAR dstW
[MAX_COMPUTERNAME_LENGTH
+ 1];
3384 DWORD s
= sizeof(dstW
) / sizeof(WCHAR
);
3387 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
3388 TRACE("getting machine name to %p\n", dst
);
3389 if (!GetComputerNameW(dstW
, &s
) ||
3390 !WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1, dst
, 16, NULL
, NULL
))
3393 SetLastError( ER_NoNetwork
);
3396 for (len
= strlen(dst
); len
< 15; len
++) dst
[len
] = ' ';
3398 SET_CH( context
, 1 ); /* Valid */
3399 SET_CL( context
, 1 ); /* NETbios number??? */
3400 TRACE("returning %s\n", debugstr_an(dst
, 16));
3405 SetLastError( ER_NoNetwork
);
3410 /******************************************************************
3411 * INT21_GetDiskSerialNumber
3414 static int INT21_GetDiskSerialNumber( CONTEXT
*context
)
3416 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3417 WCHAR path
[] = {'A',':','\\',0}, label
[11];
3420 path
[0] += INT21_MapDrive(BL_reg(context
));
3421 if (!GetVolumeInformationW( path
, label
, 11, &serial
, NULL
, NULL
, NULL
, 0))
3423 SetLastError( ERROR_INVALID_DRIVE
);
3427 *(WORD
*)dataptr
= 0;
3428 memcpy(dataptr
+ 2, &serial
, sizeof(DWORD
));
3429 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, (LPSTR
)dataptr
+ 6, 11, NULL
, NULL
);
3430 memcpy(dataptr
+ 17, "FAT16 ", 8);
3435 /******************************************************************
3436 * INT21_SetDiskSerialNumber
3439 static int INT21_SetDiskSerialNumber( CONTEXT
*context
)
3442 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3443 int drive
= INT21_MapDrive(BL_reg(context
));
3445 if (!is_valid_drive(drive
))
3447 SetLastError( ERROR_INVALID_DRIVE
);
3451 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
3454 FIXME("Setting drive serial number is no longer supported\n");
3455 SetLastError( ERROR_NOT_SUPPORTED
);
3461 /******************************************************************
3462 * INT21_GetFreeDiskSpace
3465 static int INT21_GetFreeDiskSpace( CONTEXT
*context
)
3467 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
3468 WCHAR root
[] = {'A',':','\\',0};
3469 const DWORD max_clusters
= 0x3d83;
3470 const DWORD max_sectors_per_cluster
= 0x7f;
3471 const DWORD max_bytes_per_sector
= 0x200;
3473 root
[0] += INT21_MapDrive(DL_reg(context
));
3474 if (!GetDiskFreeSpaceW( root
, &cluster_sectors
, §or_bytes
,
3475 &free_clusters
, &total_clusters
)) return 0;
3477 /* Some old win31 apps (Lotus SmartSuite 5.1) crap out if there's too
3478 * much disk space, so Windows XP seems to apply the following limits:
3479 * cluster_sectors <= 0x7f
3480 * sector size <= 0x200
3481 * clusters <= 0x3D83
3482 * This means total reported space is limited to about 1GB.
3485 /* Make sure bytes-per-sector is in [, max] */
3486 while (sector_bytes
> max_bytes_per_sector
) {
3488 free_clusters
<<= 1;
3489 total_clusters
<<= 1;
3491 /* Then make sure sectors-per-cluster is in [max/2, max]. */
3492 while (cluster_sectors
<= max_sectors_per_cluster
/2) {
3493 cluster_sectors
<<= 1;
3494 free_clusters
>>= 1;
3495 total_clusters
>>= 1;
3497 while (cluster_sectors
> max_sectors_per_cluster
) {
3498 cluster_sectors
>>= 1;
3499 free_clusters
<<= 1;
3500 total_clusters
<<= 1;
3503 /* scale up sectors_per_cluster to exactly max_sectors_per_cluster.
3504 * We could skip this, but that would impose an artificially low
3505 * limit on reported disk space.
3506 * To avoid overflow, first apply a preliminary cap on sector count;
3507 * this will not affect the correctness of the final result,
3508 * because if the preliminary cap hits, the final one will, too.
3510 if (total_clusters
> 4 * max_clusters
)
3511 total_clusters
= 4 * max_clusters
;
3512 if (free_clusters
> 4 * max_clusters
)
3513 free_clusters
= 4 * max_clusters
;
3514 if (cluster_sectors
< max_sectors_per_cluster
) {
3515 free_clusters
*= cluster_sectors
;
3516 free_clusters
/= max_sectors_per_cluster
;
3517 total_clusters
*= cluster_sectors
;
3518 total_clusters
/= max_sectors_per_cluster
;
3519 cluster_sectors
= max_sectors_per_cluster
;
3522 /* Finally, apply real cluster count cap. */
3523 if (total_clusters
> max_clusters
)
3524 total_clusters
= max_clusters
;
3525 if (free_clusters
> max_clusters
)
3526 free_clusters
= max_clusters
;
3528 SET_AX( context
, cluster_sectors
);
3529 SET_BX( context
, free_clusters
);
3530 SET_CX( context
, sector_bytes
);
3531 SET_DX( context
, total_clusters
);
3535 /******************************************************************
3536 * INT21_GetDriveAllocInfo
3539 static int INT21_GetDriveAllocInfo( CONTEXT
*context
, BYTE drive
)
3543 drive
= INT21_MapDrive( drive
);
3544 if (!INT21_FillDrivePB( drive
)) return 0;
3545 dpb
= &(INT21_GetHeapPointer()->misc_dpb_list
[drive
]);
3546 SET_AL( context
, dpb
->cluster_sectors
+ 1 );
3547 SET_CX( context
, dpb
->sector_bytes
);
3548 SET_DX( context
, dpb
->num_clusters1
);
3550 context
->SegDs
= INT21_GetHeapSelector( context
);
3551 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
].media_ID
) );
3555 /***********************************************************************
3556 * INT21_GetExtendedError
3558 static void INT21_GetExtendedError( CONTEXT
*context
)
3560 BYTE
class, action
, locus
;
3561 WORD error
= GetLastError();
3566 class = action
= locus
= 0;
3568 case ERROR_DIR_NOT_EMPTY
:
3573 case ERROR_ACCESS_DENIED
:
3574 class = EC_AccessDenied
;
3578 case ERROR_CANNOT_MAKE
:
3579 class = EC_AccessDenied
;
3583 case ERROR_DISK_FULL
:
3584 case ERROR_HANDLE_DISK_FULL
:
3585 class = EC_MediaError
;
3589 case ERROR_FILE_EXISTS
:
3590 case ERROR_ALREADY_EXISTS
:
3595 case ERROR_FILE_NOT_FOUND
:
3596 case ERROR_PATH_NOT_FOUND
:
3597 case ERROR_INVALID_NAME
:
3598 class = EC_NotFound
;
3602 case ERROR_GEN_FAILURE
:
3603 class = EC_SystemFailure
;
3607 case ERROR_INVALID_DRIVE
:
3608 class = EC_MediaError
;
3612 case ERROR_INVALID_HANDLE
:
3613 class = EC_ProgramError
;
3617 case ERROR_LOCK_VIOLATION
:
3618 class = EC_AccessDenied
;
3622 case ERROR_NO_MORE_FILES
:
3623 class = EC_MediaError
;
3628 class = EC_NotFound
;
3632 case ERROR_NOT_ENOUGH_MEMORY
:
3633 class = EC_OutOfResource
;
3638 class = EC_NotFound
;
3642 case ERROR_SHARING_VIOLATION
:
3643 class = EC_Temporary
;
3647 case ERROR_TOO_MANY_OPEN_FILES
:
3648 class = EC_ProgramError
;
3653 FIXME("Unknown error %d\n", error
);
3654 class = EC_SystemFailure
;
3659 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
3660 error
, class, action
, locus
);
3661 SET_AX( context
, error
);
3662 SET_BH( context
, class );
3663 SET_BL( context
, action
);
3664 SET_CH( context
, locus
);
3667 static BOOL
INT21_CreateTempFile( CONTEXT
*context
)
3669 static int counter
= 0;
3670 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3671 char *p
= name
+ strlen(name
);
3673 /* despite what Ralf Brown says, some programs seem to call without
3674 * ending backslash (DOS accepts that, so we accept it too) */
3675 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
3679 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
3680 counter
= (counter
+ 1) % 1000;
3683 Win32HandleToDosFileHandle(
3684 CreateFileA( name
, GENERIC_READ
| GENERIC_WRITE
,
3685 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
3686 CREATE_NEW
, 0, 0 ) ) );
3687 if (AX_reg(context
) != HFILE_ERROR16
)
3689 TRACE("created %s\n", name
);
3692 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
3696 /***********************************************************************
3697 * DOSFS_ToDosFCBFormat
3699 * Convert a file name to DOS FCB format (8+3 chars, padded with blanks),
3700 * expanding wild cards and converting to upper-case in the process.
3701 * File name can be terminated by '\0', '\\' or '/'.
3702 * Return FALSE if the name is not a valid DOS name.
3703 * 'buffer' must be at least 12 characters long.
3705 /* Chars we don't want to see in DOS file names */
3706 static BOOL
INT21_ToDosFCBFormat( LPCWSTR name
, LPWSTR buffer
)
3708 static const WCHAR invalid_chars
[] = {'*','?','<','>','|','\\','"','+','=',',',';','[',']',' ','\345',0};
3712 /* Check for "." and ".." */
3717 for(i
= 1; i
< 11; i
++) buffer
[i
] = ' ';
3724 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3727 for (i
= 0; i
< 8; i
++)
3744 if (strchrW( invalid_chars
, *p
)) return FALSE
;
3745 buffer
[i
] = toupperW(*p
);
3753 /* Skip all chars after wildcard up to first dot */
3754 while (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) p
++;
3758 /* Check if name too long */
3759 if (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) return FALSE
;
3761 if (*p
== '.') p
++; /* Skip dot */
3763 for (i
= 8; i
< 11; i
++)
3773 return FALSE
; /* Second extension not allowed */
3781 if (strchrW( invalid_chars
, *p
)) return FALSE
;
3782 buffer
[i
] = toupperW(*p
);
3789 /* at most 3 character of the extension are processed
3790 * is something behind this ?
3792 while (*p
== '*' || *p
== ' ') p
++; /* skip wildcards and spaces */
3793 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3796 static HANDLE INT21_FindHandle
;
3797 static const WCHAR
*INT21_FindPath
; /* will point to current dta->fullPath search */
3799 /******************************************************************
3802 static int INT21_FindFirst( CONTEXT
*context
)
3806 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3807 WCHAR maskW
[12], pathW
[MAX_PATH
];
3808 static const WCHAR wildcardW
[] = {'*','.','*',0};
3810 path
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3811 MultiByteToWideChar(CP_OEMCP
, 0, path
, -1, pathW
, MAX_PATH
);
3813 p
= strrchrW( pathW
, '\\');
3814 q
= strrchrW( pathW
, '/');
3818 if (pathW
[0] && pathW
[1] == ':') p
= pathW
+ 2;
3823 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
3824 * (doesn't matter as it is set below anyway)
3826 if (!INT21_ToDosFCBFormat( p
, maskW
))
3828 SetLastError( ERROR_FILE_NOT_FOUND
);
3829 SET_AX( context
, ERROR_FILE_NOT_FOUND
);
3833 WideCharToMultiByte(CP_OEMCP
, 0, maskW
, 12, dta
->mask
, sizeof(dta
->mask
), NULL
, NULL
);
3835 dta
->fullPath
= HeapAlloc( GetProcessHeap(), 0, sizeof(wildcardW
) + (p
- pathW
)*sizeof(WCHAR
) );
3836 memcpy( dta
->fullPath
, pathW
, (p
- pathW
) * sizeof(WCHAR
) );
3837 memcpy( dta
->fullPath
+ (p
- pathW
), wildcardW
, sizeof(wildcardW
) );
3838 /* we must have a fully qualified file name in dta->fullPath
3839 * (we could have a UNC path, but this would lead to some errors later on)
3841 dta
->drive
= toupperW(dta
->fullPath
[0]) - 'A';
3843 dta
->search_attr
= CL_reg(context
);
3847 /******************************************************************
3850 * Check is a short path name (DTA unicode) matches a mask (FCB ansi)
3852 static BOOL
match_short(LPCWSTR shortW
, LPCSTR maskA
)
3854 WCHAR mask
[11], file
[12];
3857 if (!INT21_ToDosFCBFormat( shortW
, file
)) return FALSE
;
3858 MultiByteToWideChar(CP_OEMCP
, 0, maskA
, 11, mask
, 11);
3859 for (i
= 0; i
< 11; i
++)
3860 if (mask
[i
] != '?' && mask
[i
] != file
[i
]) return FALSE
;
3864 static unsigned INT21_FindHelper(LPCWSTR fullPath
, unsigned drive
, unsigned count
,
3865 LPCSTR mask
, unsigned search_attr
,
3866 WIN32_FIND_DATAW
* entry
)
3870 if ((search_attr
& ~(FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
)) == FA_LABEL
)
3872 WCHAR path
[] = {' ',':','\\',0};
3874 if (count
) return 0;
3875 path
[0] = drive
+ 'A';
3876 if (!GetVolumeInformationW(path
, entry
->cAlternateFileName
, 13, NULL
, NULL
, NULL
, NULL
, 0)) return 0;
3877 RtlSecondsSince1970ToTime( 0, (LARGE_INTEGER
*)&entry
->ftCreationTime
);
3878 RtlSecondsSince1970ToTime( 0, (LARGE_INTEGER
*)&entry
->ftLastAccessTime
);
3879 RtlSecondsSince1970ToTime( 0, (LARGE_INTEGER
*)&entry
->ftLastWriteTime
);
3880 entry
->dwFileAttributes
= FA_LABEL
;
3881 entry
->nFileSizeHigh
= entry
->nFileSizeLow
= 0;
3882 TRACE("returning %s as label\n", debugstr_w(entry
->cAlternateFileName
));
3886 if (!INT21_FindHandle
|| INT21_FindPath
!= fullPath
|| count
== 0)
3888 if (INT21_FindHandle
) FindClose(INT21_FindHandle
);
3889 INT21_FindHandle
= FindFirstFileW(fullPath
, entry
);
3890 if (INT21_FindHandle
== INVALID_HANDLE_VALUE
)
3892 INT21_FindHandle
= 0;
3895 INT21_FindPath
= fullPath
;
3896 /* we need to resync search */
3901 while (ncalls
-- != 0)
3903 if (!FindNextFileW(INT21_FindHandle
, entry
))
3905 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3909 while (count
< 0xffff)
3912 /* Check the file attributes, and path */
3913 if (!(entry
->dwFileAttributes
& ~search_attr
) &&
3914 match_short(entry
->cAlternateFileName
[0] ? entry
->cAlternateFileName
: entry
->cFileName
,
3919 if (!FindNextFileW(INT21_FindHandle
, entry
))
3921 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3925 WARN("Too many directory entries in %s\n", debugstr_w(fullPath
) );
3929 /******************************************************************
3932 static int INT21_FindNext( CONTEXT
*context
)
3934 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3935 DWORD attr
= dta
->search_attr
| FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
;
3936 WIN32_FIND_DATAW entry
;
3939 if (!dta
->fullPath
) return 0;
3941 n
= INT21_FindHelper(dta
->fullPath
, dta
->drive
, dta
->count
,
3942 dta
->mask
, attr
, &entry
);
3945 dta
->fileattr
= entry
.dwFileAttributes
;
3946 dta
->filesize
= entry
.nFileSizeLow
;
3947 FileTimeToDosDateTime( &entry
.ftLastWriteTime
, &dta
->filedate
, &dta
->filetime
);
3948 if (entry
.cAlternateFileName
[0])
3949 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cAlternateFileName
, -1,
3950 dta
->filename
, 13, NULL
, NULL
);
3952 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cFileName
, -1, dta
->filename
, 13, NULL
, NULL
);
3954 if (!memchr(dta
->mask
,'?',11))
3956 /* wildcardless search, release resources in case no findnext will
3957 * be issued, and as a workaround in case file creation messes up
3958 * findnext, as sometimes happens with pkunzip
3960 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3961 INT21_FindPath
= dta
->fullPath
= NULL
;
3966 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3967 INT21_FindPath
= dta
->fullPath
= NULL
;
3971 /* microsoft's programmers should be shot for using CP/M style int21
3972 calls in Windows for Workgroup's winfile.exe */
3974 /******************************************************************
3975 * INT21_FindFirstFCB
3978 static int INT21_FindFirstFCB( CONTEXT
*context
)
3980 BYTE
*fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3983 WCHAR p
[] = {' ',':',};
3985 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3986 else pFCB
= (FINDFILE_FCB
*)fcb
;
3987 drive
= INT21_MapDrive( pFCB
->drive
);
3988 if (drive
== MAX_DOS_DRIVES
) return 0;
3991 pFCB
->fullPath
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
3992 if (!pFCB
->fullPath
) return 0;
3993 GetLongPathNameW(p
, pFCB
->fullPath
, MAX_PATH
);
3998 /******************************************************************
4002 static int INT21_FindNextFCB( CONTEXT
*context
)
4004 BYTE
*fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4006 LPBYTE pResult
= INT21_GetCurrentDTA(context
);
4007 DOS_DIRENTRY_LAYOUT
*ddl
;
4008 WIN32_FIND_DATAW entry
;
4013 if (*fcb
== 0xff) /* extended FCB ? */
4016 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
4021 pFCB
= (FINDFILE_FCB
*)fcb
;
4024 if (!pFCB
->fullPath
) return 0;
4025 n
= INT21_FindHelper(pFCB
->fullPath
, INT21_MapDrive( pFCB
->drive
),
4026 pFCB
->count
, pFCB
->filename
, attr
, &entry
);
4029 HeapFree( GetProcessHeap(), 0, pFCB
->fullPath
);
4030 INT21_FindPath
= pFCB
->fullPath
= NULL
;
4037 /* place extended FCB header before pResult if called with extended FCB */
4039 pResult
+= 6; /* leave reserved field behind */
4040 *pResult
++ = entry
.dwFileAttributes
;
4042 *pResult
++ = INT21_MapDrive( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
4043 ddl
= (DOS_DIRENTRY_LAYOUT
*)pResult
;
4044 ddl
->fileattr
= entry
.dwFileAttributes
;
4045 ddl
->cluster
= 0; /* what else? */
4046 ddl
->filesize
= entry
.nFileSizeLow
;
4047 memset( ddl
->reserved
, 0, sizeof(ddl
->reserved
) );
4048 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
4049 &ddl
->filedate
, &ddl
->filetime
);
4051 /* Convert file name to FCB format */
4052 if (entry
.cAlternateFileName
[0])
4053 INT21_ToDosFCBFormat( entry
.cAlternateFileName
, nameW
);
4055 INT21_ToDosFCBFormat( entry
.cFileName
, nameW
);
4056 WideCharToMultiByte(CP_OEMCP
, 0, nameW
, 11, ddl
->filename
, 11, NULL
, NULL
);
4061 /******************************************************************
4062 * INT21_ParseFileNameIntoFCB
4065 static void INT21_ParseFileNameIntoFCB( CONTEXT
*context
)
4068 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
4070 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
4074 INT buffer_len
, len
;
4076 SET_AL( context
, 0xff ); /* failed */
4078 TRACE("filename: '%s'\n", filename
);
4081 while (*s
&& (*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
4085 buffer_len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, NULL
, 0);
4086 buffer
= HeapAlloc( GetProcessHeap(), 0, (buffer_len
+ 1) * sizeof(WCHAR
));
4087 len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, buffer
, buffer_len
);
4089 INT21_ToDosFCBFormat(buffer
, fcbW
);
4090 HeapFree(GetProcessHeap(), 0, buffer
);
4091 WideCharToMultiByte(CP_OEMCP
, 0, fcbW
, 12, fcb
+ 1, 12, NULL
, NULL
);
4093 TRACE("FCB: '%s'\n", fcb
+ 1);
4095 SET_AL( context
, ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0 );
4097 /* point DS:SI to first unparsed character */
4098 SET_SI( context
, context
->Esi
+ (int)s
- (int)filename
);
4101 static BOOL
INT21_Dup2(HFILE16 hFile1
, HFILE16 hFile2
)
4103 HFILE16 res
= HFILE_ERROR16
;
4104 HANDLE handle
, new_handle
;
4105 #define DOS_TABLE_SIZE 256
4106 DWORD map
[DOS_TABLE_SIZE
/ 32];
4109 handle
= DosFileHandleToWin32Handle(hFile1
);
4110 if (handle
== INVALID_HANDLE_VALUE
)
4114 /* now loop to allocate the same one... */
4115 memset(map
, 0, sizeof(map
));
4116 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++)
4118 if (!DuplicateHandle(GetCurrentProcess(), handle
,
4119 GetCurrentProcess(), &new_handle
,
4120 0, FALSE
, DUPLICATE_SAME_ACCESS
))
4122 res
= HFILE_ERROR16
;
4125 res
= Win32HandleToDosFileHandle(new_handle
);
4126 if (res
== HFILE_ERROR16
|| res
== hFile2
) break;
4127 map
[res
/ 32] |= 1 << (res
% 32);
4129 /* clean up the allocated slots */
4130 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++)
4132 if (map
[i
/ 32] & (1 << (i
% 32)))
4133 _lclose16((HFILE16
)i
);
4135 return res
== hFile2
;
4139 /***********************************************************************
4140 * DOSVM_Int21Handler
4142 * Interrupt 0x21 handler.
4144 void WINAPI
DOSVM_Int21Handler( CONTEXT
*context
)
4146 BOOL bSetDOSExtendedError
= FALSE
;
4148 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
4149 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08x\n",
4150 AX_reg(context
), BX_reg(context
),
4151 CX_reg(context
), DX_reg(context
),
4152 SI_reg(context
), DI_reg(context
),
4153 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
4157 * Extended error is used by (at least) functions 0x2f to 0x62.
4158 * Function 0x59 returns extended error and error should not
4159 * be cleared before handling the function.
4161 if (AH_reg(context
) >= 0x2f && AH_reg(context
) != 0x59)
4164 RESET_CFLAG(context
); /* Not sure if this is a good idea. */
4166 switch(AH_reg(context
))
4168 case 0x00: /* TERMINATE PROGRAM */
4169 TRACE("TERMINATE PROGRAM\n");
4170 if (DOSVM_IsWin16())
4172 else if(ISV86(context
))
4173 MZ_Exit( context
, FALSE
, 0 );
4175 ERR( "Called from DOS protected mode\n" );
4178 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
4181 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
4182 INT21_ReadChar( &ascii
, context
);
4183 SET_AL( context
, ascii
);
4185 * FIXME: What to echo when extended keycodes are read?
4187 DOSVM_PutChar(AL_reg(context
));
4191 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
4192 TRACE("Write Character to Standard Output\n");
4193 DOSVM_PutChar(DL_reg(context
));
4196 case 0x03: /* READ CHARACTER FROM STDAUX */
4197 case 0x04: /* WRITE CHARACTER TO STDAUX */
4198 case 0x05: /* WRITE CHARACTER TO PRINTER */
4199 INT_BARF( context
, 0x21 );
4202 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
4203 if (DL_reg(context
) == 0xff)
4205 TRACE("Direct Console Input\n");
4207 if (INT21_ReadChar( NULL
, NULL
))
4210 INT21_ReadChar( &ascii
, context
);
4211 SET_AL( context
, ascii
);
4212 RESET_ZFLAG( context
);
4216 /* no character available */
4217 SET_AL( context
, 0 );
4218 SET_ZFLAG( context
);
4223 TRACE("Direct Console Output\n");
4224 DOSVM_PutChar(DL_reg(context
));
4226 * At least DOS versions 2.1-7.0 return character
4227 * that was written in AL register.
4229 SET_AL( context
, DL_reg(context
) );
4233 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
4236 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
4237 INT21_ReadChar( &ascii
, context
);
4238 SET_AL( context
, ascii
);
4242 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
4245 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
4246 INT21_ReadChar( &ascii
, context
);
4247 SET_AL( context
, ascii
);
4251 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
4252 TRACE("WRITE '$'-terminated string from %04X:%04X to stdout\n",
4253 context
->SegDs
, DX_reg(context
) );
4255 LPSTR data
= CTX_SEG_OFF_TO_LIN( context
,
4256 context
->SegDs
, context
->Edx
);
4260 * Do NOT use strchr() to calculate the string length,
4261 * as '\0' is valid string content, too!
4262 * Maybe we should check for non-'$' strings, but DOS doesn't.
4264 while (*p
!= '$') p
++;
4266 if (DOSVM_IsWin16())
4267 WriteFile( DosFileHandleToWin32Handle(1),
4268 data
, p
- data
, &w
, NULL
);
4270 for(; data
!= p
; data
++)
4271 DOSVM_PutChar( *data
);
4273 SET_AL( context
, '$' ); /* yes, '$' (0x24) gets returned in AL */
4277 case 0x0a: /* BUFFERED INPUT */
4279 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
4284 TRACE( "BUFFERED INPUT (size=%d)\n", ptr
[0] );
4287 * FIXME: Some documents state that
4288 * ptr[1] holds number of chars from last input which
4289 * may be recalled on entry, other documents do not mention
4293 TRACE( "Handle old chars in buffer!\n" );
4296 * ptr[0] - capacity (includes terminating CR)
4297 * ptr[1] - characters read (excludes terminating CR)
4299 result
= INT21_BufferedInput( context
, ptr
+ 2, ptr
[0] );
4301 ptr
[1] = (BYTE
)result
- 1;
4307 case 0x0b: /* GET STDIN STATUS */
4308 TRACE( "GET STDIN STATUS\n" );
4310 if (INT21_ReadChar( NULL
, NULL
))
4311 SET_AL( context
, 0xff ); /* character available */
4313 SET_AL( context
, 0 ); /* no character available */
4317 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
4319 BYTE al
= AL_reg(context
); /* Input function to execute after flush. */
4321 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al
);
4323 /* FIXME: buffers are not flushed */
4326 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
4327 * int21 function identified by AL will be called.
4329 if(al
== 0x01 || al
== 0x06 || al
== 0x07 || al
== 0x08 || al
== 0x0a)
4331 SET_AH( context
, al
);
4332 DOSVM_Int21Handler( context
);
4337 case 0x0d: /* DISK BUFFER FLUSH */
4338 TRACE("DISK BUFFER FLUSH ignored\n");
4341 case 0x0e: /* SELECT DEFAULT DRIVE */
4342 TRACE( "SELECT DEFAULT DRIVE - %c:\n", 'A' + DL_reg(context
) );
4343 INT21_SetCurrentDrive( DL_reg(context
) );
4344 SET_AL( context
, MAX_DOS_DRIVES
);
4347 case 0x0f: /* OPEN FILE USING FCB */
4348 INT21_OpenFileUsingFCB( context
);
4351 case 0x10: /* CLOSE FILE USING FCB */
4352 INT21_CloseFileUsingFCB( context
);
4355 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
4356 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
4357 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
4358 if (!INT21_FindFirstFCB(context
))
4360 SET_AL( context
, 0xff );
4363 /* else fall through */
4365 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
4366 SET_AL( context
, INT21_FindNextFCB(context
) ? 0x00 : 0xff );
4369 case 0x13: /* DELETE FILE USING FCB */
4370 INT_BARF( context
, 0x21 );
4373 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
4374 INT21_SequentialReadFromFCB( context
);
4377 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
4378 INT21_SequentialWriteToFCB( context
);
4381 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
4382 case 0x17: /* RENAME FILE USING FCB */
4383 INT_BARF( context
, 0x21 );
4386 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4387 SET_AL( context
, 0 );
4390 case 0x19: /* GET CURRENT DEFAULT DRIVE */
4391 SET_AL( context
, INT21_GetCurrentDrive() );
4392 TRACE( "GET CURRENT DRIVE -> %c:\n", 'A' + AL_reg( context
) );
4395 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
4396 TRACE( "SET DISK TRANSFER AREA ADDRESS %04X:%04X\n",
4397 context
->SegDs
, DX_reg(context
) );
4399 TDB
*task
= GlobalLock16( GetCurrentTask() );
4400 task
->dta
= MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4404 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
4405 if (!INT21_GetDriveAllocInfo(context
, 0))
4406 SET_AX( context
, 0xffff );
4409 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
4410 if (!INT21_GetDriveAllocInfo(context
, DL_reg(context
)))
4411 SET_AX( context
, 0xffff );
4414 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4415 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4416 SET_AL( context
, 0 );
4419 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
4421 BYTE drive
= INT21_MapDrive( 0 );
4422 TRACE( "GET DPB FOR DEFAULT DRIVE\n" );
4424 if (INT21_FillDrivePB( drive
))
4426 SET_AL( context
, 0x00 ); /* success */
4427 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4428 context
->SegDs
= INT21_GetHeapSelector( context
);
4432 SET_AL( context
, 0xff ); /* invalid or network drive */
4437 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4438 SET_AL( context
, 0 );
4441 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
4442 INT21_ReadRandomRecordFromFCB( context
);
4445 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
4446 INT21_WriteRandomRecordToFCB( context
);
4449 case 0x23: /* GET FILE SIZE FOR FCB */
4450 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
4451 INT_BARF( context
, 0x21 );
4454 case 0x25: /* SET INTERRUPT VECTOR */
4455 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4457 FARPROC16 ptr
= (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4458 if (!ISV86(context
) && DOSVM_IsWin16())
4459 DOSVM_SetPMHandler16( AL_reg(context
), ptr
);
4461 DOSVM_SetRMHandler( AL_reg(context
), ptr
);
4465 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
4466 INT_BARF( context
, 0x21 );
4469 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
4470 INT21_RandomBlockReadFromFCB( context
);
4473 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
4474 INT21_RandomBlockWriteToFCB( context
);
4477 case 0x29: /* PARSE FILENAME INTO FCB */
4478 INT21_ParseFileNameIntoFCB(context
);
4481 case 0x2a: /* GET SYSTEM DATE */
4482 TRACE( "GET SYSTEM DATE\n" );
4485 GetLocalTime( &systime
);
4486 SET_CX( context
, systime
.wYear
);
4487 SET_DH( context
, systime
.wMonth
);
4488 SET_DL( context
, systime
.wDay
);
4489 SET_AL( context
, systime
.wDayOfWeek
);
4493 case 0x2b: /* SET SYSTEM DATE */
4494 TRACE( "SET SYSTEM DATE\n" );
4496 WORD year
= CX_reg(context
);
4497 BYTE month
= DH_reg(context
);
4498 BYTE day
= DL_reg(context
);
4500 if (year
>= 1980 && year
<= 2099 &&
4501 month
>= 1 && month
<= 12 &&
4502 day
>= 1 && day
<= 31)
4504 FIXME( "SetSystemDate(%02d/%02d/%04d): not allowed\n",
4506 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4510 SET_AL( context
, 0xff ); /* invalid date */
4511 TRACE( "SetSystemDate(%02d/%02d/%04d): invalid date\n",
4517 case 0x2c: /* GET SYSTEM TIME */
4518 TRACE( "GET SYSTEM TIME\n" );
4521 GetLocalTime( &systime
);
4522 SET_CH( context
, systime
.wHour
);
4523 SET_CL( context
, systime
.wMinute
);
4524 SET_DH( context
, systime
.wSecond
);
4525 SET_DL( context
, systime
.wMilliseconds
/ 10 );
4529 case 0x2d: /* SET SYSTEM TIME */
4530 if( CH_reg(context
) >= 24 || CL_reg(context
) >= 60 || DH_reg(context
) >= 60 || DL_reg(context
) >= 100 ) {
4531 TRACE("SetSystemTime(%02d:%02d:%02d.%02d): wrong time\n",
4532 CH_reg(context
), CL_reg(context
),
4533 DH_reg(context
), DL_reg(context
) );
4534 SET_AL( context
, 0xFF );
4538 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
4539 CH_reg(context
), CL_reg(context
),
4540 DH_reg(context
), DL_reg(context
) );
4541 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4545 case 0x2e: /* SET VERIFY FLAG */
4546 TRACE("SET VERIFY FLAG ignored\n");
4547 /* we cannot change the behaviour anyway, so just ignore it */
4550 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
4551 TRACE( "GET DISK TRANSFER AREA ADDRESS\n" );
4553 TDB
*task
= GlobalLock16( GetCurrentTask() );
4554 context
->SegEs
= SELECTOROF( task
->dta
);
4555 SET_BX( context
, OFFSETOF( task
->dta
) );
4559 case 0x30: /* GET DOS VERSION */
4560 TRACE( "GET DOS VERSION - %s requested\n",
4561 (AL_reg(context
) == 0x00) ? "OEM number" : "version flag" );
4563 if (AL_reg(context
) == 0x00)
4564 SET_BH( context
, 0xff ); /* OEM number => undefined */
4566 SET_BH( context
, 0x08 ); /* version flag => DOS is in ROM */
4568 SET_AL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
4569 SET_AH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
4571 SET_BL( context
, 0x12 ); /* 0x123456 is 24-bit Wine's serial # */
4572 SET_CX( context
, 0x3456 );
4575 case 0x31: /* TERMINATE AND STAY RESIDENT */
4576 FIXME("TERMINATE AND STAY RESIDENT stub\n");
4579 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
4581 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
4582 TRACE( "GET DPB FOR SPECIFIC DRIVE %d\n", DL_reg(context
) );
4584 if (INT21_FillDrivePB( drive
))
4586 SET_AL( context
, 0x00 ); /* success */
4587 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4588 context
->SegDs
= INT21_GetHeapSelector( context
);
4592 SET_AL( context
, 0xff ); /* invalid or network drive */
4597 case 0x33: /* MULTIPLEXED */
4598 switch (AL_reg(context
))
4600 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
4601 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
4602 SET_DL( context
, brk_flag
);
4605 case 0x01: /* SET EXTENDED BREAK STATE */
4606 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
4607 brk_flag
= (DL_reg(context
) > 0) ? 1 : 0;
4610 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
4611 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
4612 /* ugly coding in order to stay reentrant */
4613 if (DL_reg(context
))
4615 SET_DL( context
, brk_flag
);
4620 SET_DL( context
, brk_flag
);
4625 case 0x05: /* GET BOOT DRIVE */
4626 TRACE("GET BOOT DRIVE\n");
4627 SET_DL( context
, 3 );
4628 /* c: is Wine's bootdrive (a: is 1)*/
4631 case 0x06: /* GET TRUE VERSION NUMBER */
4632 TRACE("GET TRUE VERSION NUMBER\n");
4633 SET_BL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major */
4634 SET_BH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor */
4635 SET_DL( context
, 0x00 ); /* revision */
4636 SET_DH( context
, 0x08 ); /* DOS is in ROM */
4640 INT_BARF( context
, 0x21 );
4645 case 0x34: /* GET ADDRESS OF INDOS FLAG */
4646 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
4647 context
->SegEs
= INT21_GetHeapSelector( context
);
4648 SET_BX( context
, offsetof(INT21_HEAP
, misc_indos
) );
4651 case 0x35: /* GET INTERRUPT VECTOR */
4652 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4655 if (!ISV86(context
) && DOSVM_IsWin16())
4656 addr
= DOSVM_GetPMHandler16( AL_reg(context
) );
4658 addr
= DOSVM_GetRMHandler( AL_reg(context
) );
4659 context
->SegEs
= SELECTOROF(addr
);
4660 SET_BX( context
, OFFSETOF(addr
) );
4664 case 0x36: /* GET FREE DISK SPACE */
4665 TRACE("GET FREE DISK SPACE FOR DRIVE %s (limited to about 1GB)\n",
4666 INT21_DriveName( DL_reg(context
) ));
4667 if (!INT21_GetFreeDiskSpace(context
)) SET_AX( context
, 0xffff );
4670 case 0x37: /* SWITCHAR */
4672 switch (AL_reg(context
))
4674 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
4675 TRACE( "SWITCHAR - GET SWITCH CHARACTER\n" );
4676 SET_AL( context
, 0x00 ); /* success*/
4677 SET_DL( context
, '/' );
4679 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
4680 FIXME( "SWITCHAR - SET SWITCH CHARACTER: %c\n",
4682 SET_AL( context
, 0x00 ); /* success*/
4685 INT_BARF( context
, 0x21 );
4691 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
4692 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
4693 if (AL_reg(context
))
4695 WORD country
= AL_reg(context
);
4696 if (country
== 0xff)
4697 country
= BX_reg(context
);
4698 if (country
!= INT21_GetSystemCountryCode()) {
4699 FIXME( "Requested info on non-default country %04x\n", country
);
4704 if(AX_reg(context
) != 2 )
4706 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context
,
4709 SET_AX( context
, INT21_GetSystemCountryCode() );
4710 SET_BX( context
, INT21_GetSystemCountryCode() );
4711 RESET_CFLAG(context
);
4715 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
4716 if (!INT21_CreateDirectory( context
))
4717 bSetDOSExtendedError
= TRUE
;
4719 RESET_CFLAG(context
);
4722 case 0x3a: /* "RMDIR" - REMOVE DIRECTORY */
4724 WCHAR dirW
[MAX_PATH
];
4725 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
4726 context
->SegDs
, context
->Edx
);
4728 TRACE( "REMOVE DIRECTORY %s\n", dirA
);
4730 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
4732 if (!RemoveDirectoryW( dirW
))
4733 bSetDOSExtendedError
= TRUE
;
4735 RESET_CFLAG(context
);
4739 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
4740 if (!INT21_SetCurrentDirectory( context
))
4741 bSetDOSExtendedError
= TRUE
;
4743 RESET_CFLAG(context
);
4746 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
4747 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4748 OF_READWRITE
| OF_SHARE_COMPAT
, 0x12 ))
4749 bSetDOSExtendedError
= TRUE
;
4751 RESET_CFLAG(context
);
4754 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
4755 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4756 AL_reg(context
), 0x01 ))
4757 bSetDOSExtendedError
= TRUE
;
4759 RESET_CFLAG(context
);
4762 case 0x3e: /* "CLOSE" - CLOSE FILE */
4763 TRACE( "CLOSE handle %d\n", BX_reg(context
) );
4764 if (_lclose16( BX_reg(context
) ) == HFILE_ERROR16
)
4765 bSetDOSExtendedError
= TRUE
;
4767 RESET_CFLAG(context
);
4770 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
4771 TRACE( "READ from %d to %04X:%04X for %d bytes\n",
4778 WORD count
= CX_reg(context
);
4779 BYTE
*buffer
= CTX_SEG_OFF_TO_LIN( context
,
4783 /* Some programs pass a count larger than the allocated buffer */
4784 if (DOSVM_IsWin16())
4786 DWORD maxcount
= GetSelectorLimit16( context
->SegDs
)
4787 - DX_reg(context
) + 1;
4788 if (count
> maxcount
)
4793 * FIXME: Reading from console (BX=1) in DOS mode
4794 * does not work as it is supposed to work.
4797 RESET_CFLAG(context
); /* set if error */
4798 if (!DOSVM_IsWin16() && BX_reg(context
) == 0)
4800 result
= INT21_BufferedInput( context
, buffer
, count
);
4801 SET_AX( context
, (WORD
)result
);
4803 else if (ReadFile( DosFileHandleToWin32Handle(BX_reg(context
)),
4804 buffer
, count
, &result
, NULL
))
4805 SET_AX( context
, (WORD
)result
);
4807 bSetDOSExtendedError
= TRUE
;
4811 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
4812 TRACE( "WRITE from %04X:%04X to handle %d for %d byte\n",
4813 context
->SegDs
, DX_reg(context
),
4814 BX_reg(context
), CX_reg(context
) );
4816 char *ptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4818 if (!DOSVM_IsWin16() &&
4819 (BX_reg(context
) == 1 || BX_reg(context
) == 2))
4822 for(i
=0; i
<CX_reg(context
); i
++)
4823 DOSVM_PutChar(ptr
[i
]);
4824 SET_AX(context
, CX_reg(context
));
4825 RESET_CFLAG(context
);
4829 HFILE handle
= (HFILE
)DosFileHandleToWin32Handle(BX_reg(context
));
4830 LONG result
= _hwrite( handle
, ptr
, CX_reg(context
) );
4831 if (result
== HFILE_ERROR
)
4832 bSetDOSExtendedError
= TRUE
;
4835 SET_AX( context
, (WORD
)result
);
4836 RESET_CFLAG(context
);
4842 case 0x41: /* "UNLINK" - DELETE FILE */
4844 WCHAR fileW
[MAX_PATH
];
4845 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
4849 TRACE( "UNLINK %s\n", fileA
);
4850 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
4852 if (!DeleteFileW( fileW
))
4853 bSetDOSExtendedError
= TRUE
;
4855 RESET_CFLAG(context
);
4859 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
4860 TRACE( "LSEEK handle %d offset %d from %s\n",
4862 MAKELONG( DX_reg(context
), CX_reg(context
) ),
4863 (AL_reg(context
) == 0) ?
4864 "start of file" : ((AL_reg(context
) == 1) ?
4865 "current file position" : "end of file") );
4867 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
4868 LONG offset
= MAKELONG( DX_reg(context
), CX_reg(context
) );
4869 DWORD status
= SetFilePointer( handle
, offset
,
4870 NULL
, AL_reg(context
) );
4871 if (status
== INVALID_SET_FILE_POINTER
)
4872 bSetDOSExtendedError
= TRUE
;
4875 SET_AX( context
, LOWORD(status
) );
4876 SET_DX( context
, HIWORD(status
) );
4877 RESET_CFLAG(context
);
4882 case 0x43: /* FILE ATTRIBUTES */
4883 if (!INT21_FileAttributes( context
, AL_reg(context
), FALSE
))
4884 bSetDOSExtendedError
= TRUE
;
4886 RESET_CFLAG(context
);
4889 case 0x44: /* IOCTL */
4890 INT21_Ioctl( context
);
4893 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
4894 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context
) );
4897 HFILE handle16
= HFILE_ERROR
;
4899 if (DuplicateHandle( GetCurrentProcess(),
4900 DosFileHandleToWin32Handle(BX_reg(context
)),
4901 GetCurrentProcess(),
4903 0, TRUE
, DUPLICATE_SAME_ACCESS
))
4904 handle16
= Win32HandleToDosFileHandle(handle32
);
4906 if (handle16
== HFILE_ERROR
)
4907 bSetDOSExtendedError
= TRUE
;
4910 SET_AX( context
, handle16
);
4911 RESET_CFLAG(context
);
4916 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
4917 TRACE( "FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
4918 BX_reg(context
), CX_reg(context
) );
4919 if (!INT21_Dup2(BX_reg(context
), CX_reg(context
)))
4920 bSetDOSExtendedError
= TRUE
;
4922 RESET_CFLAG(context
);
4925 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
4926 if (!INT21_GetCurrentDirectory( context
, FALSE
))
4927 bSetDOSExtendedError
= TRUE
;
4929 RESET_CFLAG(context
);
4932 case 0x48: /* ALLOCATE MEMORY */
4933 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
) );
4936 DWORD bytes
= (DWORD
)BX_reg(context
) << 4;
4938 if (!ISV86(context
) && DOSVM_IsWin16())
4940 DWORD rv
= GlobalDOSAlloc16( bytes
);
4941 selector
= LOWORD( rv
);
4944 DOSMEM_AllocBlock( bytes
, &selector
);
4948 SET_AX( context
, selector
);
4949 RESET_CFLAG(context
);
4954 SET_AX( context
, 0x0008 ); /* insufficient memory */
4955 SET_BX( context
, DOSMEM_Available() >> 4 );
4960 case 0x49: /* FREE MEMORY */
4961 TRACE( "FREE MEMORY segment %04X\n", context
->SegEs
);
4965 if (!ISV86(context
) && DOSVM_IsWin16())
4967 ok
= !GlobalDOSFree16( context
->SegEs
);
4969 /* If we don't reset ES_reg, we will fail in the relay code */
4974 ok
= DOSMEM_FreeBlock( PTR_REAL_TO_LIN(context
->SegEs
, 0) );
4978 TRACE("FREE MEMORY failed\n");
4980 SET_AX( context
, 0x0009 ); /* memory block address invalid */
4985 case 0x4a: /* RESIZE MEMORY BLOCK */
4986 TRACE( "RESIZE MEMORY segment %04X to %d paragraphs\n",
4987 context
->SegEs
, BX_reg(context
) );
4989 DWORD newsize
= (DWORD
)BX_reg(context
) << 4;
4991 if (!ISV86(context
) && DOSVM_IsWin16())
4993 FIXME( "Resize memory block - unsupported under Win16\n" );
4998 LPVOID address
= (void*)(context
->SegEs
<< 4);
4999 UINT blocksize
= DOSMEM_ResizeBlock( address
, newsize
, FALSE
);
5001 RESET_CFLAG(context
);
5002 if (blocksize
== (UINT
)-1)
5004 SET_CFLAG( context
);
5005 SET_AX( context
, 0x0009 ); /* illegal address */
5007 else if(blocksize
!= newsize
)
5009 SET_CFLAG( context
);
5010 SET_AX( context
, 0x0008 ); /* insufficient memory */
5011 SET_BX( context
, blocksize
>> 4 ); /* new block size */
5017 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
5019 char *program
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
5020 BYTE
*paramblk
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
5022 TRACE( "EXEC %s\n", program
);
5024 RESET_CFLAG(context
);
5025 if (DOSVM_IsWin16())
5027 HINSTANCE16 instance
= WinExec16( program
, SW_NORMAL
);
5030 SET_CFLAG( context
);
5031 SET_AX( context
, instance
);
5036 if (!MZ_Exec( context
, program
, AL_reg(context
), paramblk
))
5037 bSetDOSExtendedError
= TRUE
;
5042 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
5043 TRACE( "EXIT with return code %d\n", AL_reg(context
) );
5044 if (DOSVM_IsWin16())
5045 DOSVM_Exit( AL_reg(context
) );
5046 else if(ISV86(context
))
5047 MZ_Exit( context
, FALSE
, AL_reg(context
) );
5053 ULONG_PTR rv
= AL_reg(context
);
5054 RaiseException( EXCEPTION_VM86_INTx
, 0, 1, &rv
);
5058 case 0x4d: /* GET RETURN CODE */
5059 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
5060 SET_AX( context
, DOSVM_retval
);
5064 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
5065 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
5066 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
5067 if (!INT21_FindFirst(context
)) break;
5070 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
5071 TRACE("FINDNEXT\n");
5072 if (!INT21_FindNext(context
))
5074 SetLastError( ERROR_NO_MORE_FILES
);
5075 SET_AX( context
, ERROR_NO_MORE_FILES
);
5078 else SET_AX( context
, 0 ); /* OK */
5081 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
5082 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
5083 DOSVM_psp
= BX_reg(context
);
5086 case 0x51: /* GET PSP ADDRESS */
5087 INT21_GetPSP( context
);
5090 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
5092 SEGPTR ptr
= DOSDEV_GetLOL( ISV86(context
) || !DOSVM_IsWin16() );
5093 context
->SegEs
= SELECTOROF(ptr
);
5094 SET_BX( context
, OFFSETOF(ptr
) );
5098 case 0x54: /* Get Verify Flag */
5099 TRACE("Get Verify Flag - Not Supported\n");
5100 SET_AL( context
, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
5103 case 0x56: /* "RENAME" - RENAME FILE */
5104 if (!INT21_RenameFile( context
))
5105 bSetDOSExtendedError
= TRUE
;
5107 RESET_CFLAG(context
);
5110 case 0x57: /* FILE DATE AND TIME */
5111 if (!INT21_FileDateTime( context
))
5112 bSetDOSExtendedError
= TRUE
;
5114 RESET_CFLAG(context
);
5117 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
5118 switch (AL_reg(context
))
5120 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
5121 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
5122 SET_AX( context
, 0 ); /* low memory first fit */
5125 case 0x01: /* SET ALLOCATION STRATEGY */
5126 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
5130 case 0x02: /* GET UMB LINK STATE */
5131 TRACE( "GET UMB LINK STATE\n" );
5132 SET_AL( context
, 0 ); /* UMBs not part of DOS memory chain */
5135 case 0x03: /* SET UMB LINK STATE */
5136 TRACE( "SET UMB LINK STATE to %d - ignored\n",
5141 INT_BARF( context
, 0x21 );
5145 case 0x59: /* GET EXTENDED ERROR INFO */
5146 INT21_GetExtendedError( context
);
5149 case 0x5a: /* CREATE TEMPORARY FILE */
5150 TRACE("CREATE TEMPORARY FILE\n");
5151 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
5154 case 0x5b: /* CREATE NEW FILE */
5155 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
5156 OF_READWRITE
| OF_SHARE_COMPAT
, 0x10 ))
5157 bSetDOSExtendedError
= TRUE
;
5159 RESET_CFLAG(context
);
5162 case 0x5c: /* "FLOCK" - RECORD LOCKING */
5164 DWORD offset
= MAKELONG(DX_reg(context
), CX_reg(context
));
5165 DWORD length
= MAKELONG(DI_reg(context
), SI_reg(context
));
5166 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
5168 RESET_CFLAG(context
);
5169 switch (AL_reg(context
))
5171 case 0x00: /* LOCK */
5172 TRACE( "lock handle %d offset %d length %d\n",
5173 BX_reg(context
), offset
, length
);
5174 if (!LockFile( handle
, offset
, 0, length
, 0 ))
5175 bSetDOSExtendedError
= TRUE
;
5178 case 0x01: /* UNLOCK */
5179 TRACE( "unlock handle %d offset %d length %d\n",
5180 BX_reg(context
), offset
, length
);
5181 if (!UnlockFile( handle
, offset
, 0, length
, 0 ))
5182 bSetDOSExtendedError
= TRUE
;
5186 INT_BARF( context
, 0x21 );
5191 case 0x5d: /* NETWORK 5D */
5192 FIXME( "Network function 5D not implemented.\n" );
5193 SetLastError( ER_NoNetwork
);
5194 bSetDOSExtendedError
= TRUE
;
5197 case 0x5e: /* NETWORK 5E */
5198 bSetDOSExtendedError
= INT21_NetworkFunc( context
);
5201 case 0x5f: /* NETWORK 5F */
5202 /* FIXME: supporting this would need to 1:
5203 * - implement per drive current directory (as kernel32 doesn't)
5204 * - assign enabled/disabled flag on a per drive basis
5206 /* network software not installed */
5207 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
5208 SetLastError( ER_NoNetwork
);
5209 bSetDOSExtendedError
= TRUE
;
5212 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
5214 WCHAR pathW
[MAX_PATH
], res
[MAX_PATH
];
5215 /* FIXME: likely to be broken */
5217 TRACE("TRUENAME %s\n",
5218 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
5219 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
5220 if (!GetFullPathNameW( pathW
, 128, res
, NULL
))
5221 bSetDOSExtendedError
= TRUE
;
5224 SET_AX( context
, 0 );
5225 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
5226 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
5232 case 0x61: /* UNUSED */
5233 SET_AL( context
, 0 );
5236 case 0x62: /* GET PSP ADDRESS */
5237 INT21_GetPSP( context
);
5240 case 0x63: /* MISC. LANGUAGE SUPPORT */
5241 switch (AL_reg(context
)) {
5242 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
5243 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
5244 context
->SegDs
= INT21_GetHeapSelector( context
);
5245 SET_SI( context
, offsetof(INT21_HEAP
, dbcs_table
) );
5246 SET_AL( context
, 0 ); /* success */
5251 case 0x64: /* OS/2 DOS BOX */
5252 INT_BARF( context
, 0x21 );
5256 case 0x65: /* EXTENDED COUNTRY INFORMATION */
5257 INT21_ExtendedCountryInformation( context
);
5260 case 0x66: /* GLOBAL CODE PAGE TABLE */
5261 switch (AL_reg(context
))
5264 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
5265 SET_BX( context
, GetOEMCP() );
5266 SET_DX( context
, GetOEMCP() );
5269 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
5270 BX_reg(context
), DX_reg(context
) );
5275 case 0x67: /* SET HANDLE COUNT */
5276 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context
) );
5277 if (SetHandleCount( BX_reg(context
) ) < BX_reg(context
) )
5278 bSetDOSExtendedError
= TRUE
;
5281 case 0x68: /* "FFLUSH" - COMMIT FILE */
5282 TRACE( "FFLUSH - handle %d\n", BX_reg(context
) );
5283 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
5284 bSetDOSExtendedError
= TRUE
;
5287 case 0x69: /* DISK SERIAL NUMBER */
5288 switch (AL_reg(context
))
5291 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
5292 INT21_DriveName(BL_reg(context
)));
5293 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
5294 else SET_AX( context
, 0 );
5298 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
5299 INT21_DriveName(BL_reg(context
)));
5300 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
5301 else SET_AX( context
, 1 );
5306 case 0x6a: /* COMMIT FILE */
5307 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context
) );
5308 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
5309 bSetDOSExtendedError
= TRUE
;
5312 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
5313 SET_AL( context
, 0 );
5316 case 0x6c: /* EXTENDED OPEN/CREATE */
5317 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
5318 BX_reg(context
), DL_reg(context
) ))
5319 bSetDOSExtendedError
= TRUE
;
5322 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
5323 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
5324 SET_CFLAG( context
);
5325 SET_AL( context
, 0 );
5328 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
5329 INT21_LongFilename( context
);
5332 case 0x73: /* MSDOS7 - FAT32 */
5333 RESET_CFLAG( context
);
5334 if (!INT21_Fat32( context
))
5335 bSetDOSExtendedError
= TRUE
;
5338 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
5339 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
5342 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
5343 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
5346 case 0xff: /* DOS32 EXTENDER (DOS/4GW) - API */
5347 /* we don't implement a DOS32 extender */
5348 TRACE( "DOS32 EXTENDER API - ignored\n" );
5352 INT_BARF( context
, 0x21 );
5355 } /* END OF SWITCH */
5357 /* Set general error condition. */
5358 if (bSetDOSExtendedError
)
5360 SET_AX( context
, GetLastError() );
5361 SET_CFLAG( context
);
5364 /* Print error code if carry flag is set. */
5365 if (context
->EFlags
& 0x0001)
5366 TRACE("failed, error %d\n", GetLastError() );
5368 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
5369 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08x\n",
5370 AX_reg(context
), BX_reg(context
),
5371 CX_reg(context
), DX_reg(context
),
5372 SI_reg(context
), DI_reg(context
),
5373 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,