2 * DOS interrupt 21h handler
4 * Copyright 1993, 1994 Erik Bos
5 * Copyright 1996 Alexandre Julliard
6 * Copyright 1997 Andreas Mohr
7 * Copyright 1998 Uwe Bonnes
8 * Copyright 1998, 1999 Ove Kaaven
9 * Copyright 2003 Thomas Mertes
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/port.h"
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
42 #include "wine/winbase16.h"
46 #include "wine/unicode.h"
47 #include "wine/server.h"
48 #include "wine/debug.h"
49 #include "wine/exception.h"
51 BOOL WINAPI
VerifyConsoleIoHandle(HANDLE
);
54 * - Most of the file related functions are wrong. NT's kernel32
55 * doesn't maintain a per drive current directory, while DOS does.
56 * We should in fact keep track in here of those per drive
57 * directories, and use this info while dealing with partial paths
58 * (drive defined, but only relative paths). This could even be
59 * created as an array of CDS (there should be an entry for that in
64 * Forward declarations.
66 static BOOL
INT21_RenameFile( CONTEXT86
*context
);
68 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
74 * Extended Drive Parameter Block.
75 * This structure is compatible with standard DOS4+ DPB and
78 typedef struct _INT21_DPB
{
79 BYTE drive
; /* 00 drive number (0=A, ...) */
80 BYTE unit
; /* 01 unit number within device driver */
81 WORD sector_bytes
; /* 02 bytes per sector */
82 BYTE cluster_sectors
; /* 04 highest sector number within a cluster */
83 BYTE shift
; /* 05 shift count to convert clusters into sectors */
84 WORD num_reserved
; /* 06 reserved sectors at beginning of drive */
85 BYTE num_FAT
; /* 08 number of FATs */
86 WORD num_root_entries
; /* 09 number of root directory entries */
87 WORD first_data_sector
; /* 0b number of first sector containing user data */
88 WORD num_clusters1
; /* 0d highest cluster number (number of data clusters + 1) */
89 WORD sectors_per_FAT
; /* 0f number of sectors per FAT */
90 WORD first_dir_sector
; /* 11 sector number of first directory sector */
91 SEGPTR driver_header
; /* 13 address of device driver header */
92 BYTE media_ID
; /* 17 media ID byte */
93 BYTE access_flag
; /* 18 0x00 if disk accessed, 0xff if not */
94 SEGPTR next
; /* 19 pointer to next DPB */
95 WORD search_cluster1
; /* 1d cluster at which to start search for free space */
96 WORD free_clusters_lo
; /* 1f number of free clusters on drive or 0xffff if unknown */
97 WORD free_clusters_hi
; /* 21 hiword of clusters_free */
98 WORD mirroring_flags
; /* 23 active FAT/mirroring flags */
99 WORD info_sector
; /* 25 sector number of file system info sector or 0xffff for none */
100 WORD spare_boot_sector
; /* 27 sector number of backup boot sector or 0xffff for none */
101 DWORD first_cluster_sector
; /* 29 sector number of the first cluster */
102 DWORD num_clusters2
; /* 2d maximum cluster number */
103 DWORD fat_clusters
; /* 31 number of clusters occupied by FAT */
104 DWORD root_cluster
; /* 35 cluster number of start of root directory */
105 DWORD search_cluster2
; /* 39 cluster at which to start searching for free space */
110 * Structure for DOS data that can be accessed directly from applications.
111 * Real and protected mode pointers will be returned to this structure so
112 * the structure must be correctly packed.
114 typedef struct _INT21_HEAP
{
115 WORD uppercase_size
; /* Size of the following table in bytes */
116 BYTE uppercase_table
[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
118 WORD lowercase_size
; /* Size of the following table in bytes */
119 BYTE lowercase_table
[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
121 WORD collating_size
; /* Size of the following table in bytes */
122 BYTE collating_table
[256]; /* Values used to sort characters from 0x00 to 0xff. */
124 WORD filename_size
; /* Size of the following filename data in bytes */
125 BYTE filename_reserved1
; /* 0x01 for MS-DOS 3.30-6.00 */
126 BYTE filename_lowest
; /* Lowest permissible character value for filename */
127 BYTE filename_highest
; /* Highest permissible character value for filename */
128 BYTE filename_reserved2
; /* 0x00 for MS-DOS 3.30-6.00 */
129 BYTE filename_exclude_first
; /* First illegal character in permissible range */
130 BYTE filename_exclude_last
; /* Last illegal character in permissible range */
131 BYTE filename_reserved3
; /* 0x02 for MS-DOS 3.30-6.00 */
132 BYTE filename_illegal_size
; /* Number of terminators in the following table */
133 BYTE filename_illegal_table
[16]; /* Characters which terminate a filename */
135 WORD dbcs_size
; /* Number of valid ranges in the following table */
136 BYTE dbcs_table
[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
138 BYTE misc_indos
; /* Interrupt 21 nesting flag */
139 WORD misc_segment
; /* Real mode segment for INT21_HEAP */
140 WORD misc_selector
; /* Protected mode selector for INT21_HEAP */
141 INT21_DPB misc_dpb_list
[MAX_DOS_DRIVES
]; /* Drive parameter blocks for all drives */
149 CHAR file_extension
[3];
150 WORD current_block_number
;
151 WORD logical_record_size
;
153 WORD date_of_last_write
;
154 WORD time_of_last_write
;
157 WORD starting_cluster
;
158 WORD sequence_number
;
159 BYTE file_attributes
;
161 BYTE record_within_current_block
;
162 BYTE random_access_record_number
[4];
169 BYTE xfcb_file_attribute
;
173 /* DTA layout for FindFirst/FindNext */
176 BYTE drive
; /* 00 drive letter */
177 char mask
[11]; /* 01 search template */
178 BYTE search_attr
; /* 0c search attributes */
179 WORD count
; /* 0d entry count within directory */
180 WORD cluster
; /* 0f cluster of parent directory */
181 WCHAR
*fullPath
; /* 11 full path (was: reserved) */
182 BYTE fileattr
; /* 15 file attributes */
183 WORD filetime
; /* 16 file time */
184 WORD filedate
; /* 18 file date */
185 DWORD filesize
; /* 1a file size */
186 char filename
[13]; /* 1e file name + extension */
189 /* FCB layout for FindFirstFCB/FindNextFCB */
192 BYTE drive
; /* 00 drive letter */
193 char filename
[11]; /* 01 filename 8+3 format */
194 int count
; /* 0c entry count (was: reserved) */
195 WCHAR
*fullPath
; /* 10 full path (was: reserved) */
198 /* DOS directory entry for FindFirstFCB/FindNextFCB */
201 char filename
[11]; /* 00 filename 8+3 format */
202 BYTE fileattr
; /* 0b file attributes */
203 BYTE reserved
[10]; /* 0c reserved */
204 WORD filetime
; /* 16 file time */
205 WORD filedate
; /* 18 file date */
206 WORD cluster
; /* 1a file first cluster */
207 DWORD filesize
; /* 1c file size */
208 } DOS_DIRENTRY_LAYOUT
;
212 /* dos file attributes */
213 #define FA_NORMAL 0x00 /* Normal file, no attributes */
214 #define FA_RDONLY 0x01 /* Read only attribute */
215 #define FA_HIDDEN 0x02 /* Hidden file */
216 #define FA_SYSTEM 0x04 /* System file */
217 #define FA_LABEL 0x08 /* Volume label */
218 #define FA_DIRECTORY 0x10 /* Directory */
219 #define FA_ARCHIVE 0x20 /* Archive */
220 #define FA_UNUSED 0x40 /* Unused */
223 #define ER_NoNetwork 0x49
226 #define EC_OutOfResource 0x01
227 #define EC_Temporary 0x02
228 #define EC_AccessDenied 0x03
229 #define EC_InternalError 0x04
230 #define EC_HardwareFailure 0x05
231 #define EC_SystemFailure 0x06
232 #define EC_ProgramError 0x07
233 #define EC_NotFound 0x08
234 #define EC_MediaError 0x0b
235 #define EC_Exists 0x0c
236 #define EC_Unknown 0x0d
238 /* Suggested actions */
239 #define SA_Retry 0x01
240 #define SA_DelayedRetry 0x02
241 #define SA_Abort 0x04
242 #define SA_Ignore 0x06
243 #define SA_Ask4Retry 0x07
246 #define EL_Unknown 0x01
248 #define EL_Network 0x03
249 #define EL_Serial 0x04
250 #define EL_Memory 0x05
252 /* BIOS Keyboard Scancodes */
253 #define KEY_LEFT 0x4B
254 #define KEY_RIGHT 0x4D
256 #define KEY_DOWN 0x50
257 #define KEY_IC 0x52 /* insert char */
258 #define KEY_DC 0x53 /* delete char */
259 #define KEY_BACKSPACE 0x0E
260 #define KEY_HOME 0x47
262 #define KEY_NPAGE 0x49
263 #define KEY_PPAGE 0x51
272 void (*ioctl_handler
)(CONTEXT86
*);
275 static void INT21_IoctlScsiMgrHandler( CONTEXT86
* );
276 static void INT21_IoctlEMSHandler( CONTEXT86
* );
277 static void INT21_IoctlHPScanHandler( CONTEXT86
* );
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, INT21_IoctlEMSHandler
},
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
[3] = {'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
[3] = {'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
, CONTEXT86
*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 )
413 * FIXME: Determine country code. We should probably use
414 * DOSCONF structure for that.
416 return GetSystemDefaultLangID();
420 /***********************************************************************
421 * INT21_FillCountryInformation
423 * Fill 34-byte buffer with country information data using
424 * default system locale.
426 static void INT21_FillCountryInformation( BYTE
*buffer
)
428 /* 00 - WORD: date format
433 *(WORD
*)(buffer
+ 0) = 0; /* FIXME: Get from locale */
435 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
436 buffer
[2] = '$'; /* FIXME: Get from locale */
439 /* 07 - BYTE[2]: ASCIIZ thousands separator */
440 buffer
[7] = 0; /* FIXME: Get from locale */
443 /* 09 - BYTE[2]: ASCIIZ decimal separator */
444 buffer
[9] = '.'; /* FIXME: Get from locale */
447 /* 11 - BYTE[2]: ASCIIZ date separator */
448 buffer
[11] = '/'; /* FIXME: Get from locale */
451 /* 13 - BYTE[2]: ASCIIZ time separator */
452 buffer
[13] = ':'; /* FIXME: Get from locale */
455 /* 15 - BYTE: Currency format
456 * bit 2 = set if currency symbol replaces decimal point
457 * bit 1 = number of spaces between value and currency symbol
458 * bit 0 = 0 if currency symbol precedes value
459 * 1 if currency symbol follows value
461 buffer
[15] = 0; /* FIXME: Get from locale */
463 /* 16 - BYTE: Number of digits after decimal in currency */
464 buffer
[16] = 0; /* FIXME: Get from locale */
466 /* 17 - BYTE: Time format
467 * bit 0 = 0 if 12-hour clock
470 buffer
[17] = 1; /* FIXME: Get from locale */
472 /* 18 - DWORD: Address of case map routine */
473 *(DWORD
*)(buffer
+ 18) = 0; /* FIXME: ptr to case map routine */
475 /* 22 - BYTE[2]: ASCIIZ data-list separator */
476 buffer
[22] = ','; /* FIXME: Get from locale */
479 /* 24 - BYTE[10]: Reserved */
480 memset( buffer
+ 24, 0, 10 );
484 /***********************************************************************
487 * Initialize DOS heap.
489 * Filename Terminator Table of w2k DE NTVDM:
490 * 16 00 01 00 FF 00 00 20-02 0E 2E 22 2F 5C 5B 5D ....... ..."/\[]
491 * 3A 7C 3C 3E 2B 3D 3B 2C-00 :|<>+=;,
493 static void INT21_FillHeap( INT21_HEAP
*heap
)
495 static const char terminators
[] = ".\"/\\[]:|<>+=;,";
501 heap
->uppercase_size
= 128;
502 for (i
= 0; i
< 128; i
++)
503 heap
->uppercase_table
[i
] = toupper( 128 + i
);
508 heap
->lowercase_size
= 256;
509 for (i
= 0; i
< 256; i
++)
510 heap
->lowercase_table
[i
] = tolower( i
);
515 heap
->collating_size
= 256;
516 for (i
= 0; i
< 256; i
++)
517 heap
->collating_table
[i
] = i
;
522 heap
->filename_size
= 8 + strlen(terminators
);
523 heap
->filename_illegal_size
= strlen(terminators
);
524 strcpy( heap
->filename_illegal_table
, terminators
);
526 heap
->filename_reserved1
= 0x01;
527 heap
->filename_lowest
= 0x00;
528 heap
->filename_highest
= 0xff;
529 heap
->filename_reserved2
= 0x00;
530 heap
->filename_exclude_first
= 0x00;
531 heap
->filename_exclude_last
= 0x20;
532 heap
->filename_reserved3
= 0x02;
535 * DBCS lead byte table. This table is empty.
538 memset( heap
->dbcs_table
, 0, sizeof(heap
->dbcs_table
) );
541 * Initialize InDos flag.
543 heap
->misc_indos
= 0;
546 * FIXME: Should drive parameter blocks (DPB) be
547 * initialized here and linked to DOS LOL?
552 /***********************************************************************
553 * INT21_GetHeapPointer
555 * Get pointer for DOS heap (INT21_HEAP).
556 * Creates and initializes heap on first call.
558 static INT21_HEAP
*INT21_GetHeapPointer( void )
560 static INT21_HEAP
*heap_pointer
= NULL
;
567 heap_pointer
= DOSVM_AllocDataUMB( sizeof(INT21_HEAP
),
571 heap_pointer
->misc_segment
= heap_segment
;
572 heap_pointer
->misc_selector
= heap_selector
;
573 INT21_FillHeap( heap_pointer
);
580 /***********************************************************************
581 * INT21_GetHeapSelector
583 * Get segment/selector for DOS heap (INT21_HEAP).
584 * Creates and initializes heap on first call.
586 static WORD
INT21_GetHeapSelector( CONTEXT86
*context
)
588 INT21_HEAP
*heap
= INT21_GetHeapPointer();
590 if (!ISV86(context
) && DOSVM_IsWin16())
591 return heap
->misc_selector
;
593 return heap
->misc_segment
;
597 /***********************************************************************
600 * Fill DOS heap drive parameter block for the specified drive.
601 * Return TRUE if drive was valid and there were
602 * no errors while reading drive information.
604 static BOOL
INT21_FillDrivePB( BYTE drive
)
606 WCHAR drivespec
[3] = {'A', ':', 0};
607 INT21_HEAP
*heap
= INT21_GetHeapPointer();
610 DWORD cluster_sectors
;
613 DWORD total_clusters
;
615 if (drive
>= MAX_DOS_DRIVES
)
618 dpb
= &heap
->misc_dpb_list
[drive
];
619 drivespec
[0] += drive
;
620 drivetype
= GetDriveTypeW( drivespec
);
623 * FIXME: Does this check work correctly with floppy/cdrom drives?
625 if (drivetype
== DRIVE_NO_ROOT_DIR
|| drivetype
== DRIVE_UNKNOWN
)
629 * FIXME: Does this check work correctly with floppy/cdrom drives?
631 if (!GetDiskFreeSpaceW( drivespec
, &cluster_sectors
, §or_bytes
,
632 &free_clusters
, &total_clusters
))
636 * FIXME: Most of the values listed below are incorrect.
637 * All values should be validated.
642 dpb
->sector_bytes
= sector_bytes
;
643 dpb
->cluster_sectors
= cluster_sectors
- 1;
646 while (cluster_sectors
> 1)
648 cluster_sectors
/= 2;
652 dpb
->num_reserved
= 0;
654 dpb
->num_root_entries
= 2;
655 dpb
->first_data_sector
= 2;
656 dpb
->num_clusters1
= total_clusters
;
657 dpb
->sectors_per_FAT
= 1;
658 dpb
->first_dir_sector
= 1;
659 dpb
->driver_header
= 0;
660 dpb
->media_ID
= (drivetype
== DRIVE_FIXED
) ? 0xF8 : 0xF0;
661 dpb
->access_flag
= 0;
663 dpb
->search_cluster1
= 0;
664 dpb
->free_clusters_lo
= LOWORD(free_clusters
);
665 dpb
->free_clusters_hi
= HIWORD(free_clusters
);
666 dpb
->mirroring_flags
= 0;
667 dpb
->info_sector
= 0xffff;
668 dpb
->spare_boot_sector
= 0xffff;
669 dpb
->first_cluster_sector
= 0;
670 dpb
->num_clusters2
= total_clusters
;
671 dpb
->fat_clusters
= 32;
672 dpb
->root_cluster
= 0;
673 dpb
->search_cluster2
= 0;
679 /***********************************************************************
680 * INT21_GetCurrentDirectory
684 * - subfunction 0x47 of function 0x71
686 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
, BOOL islong
)
688 char *buffer
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
689 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
690 WCHAR pathW
[MAX_PATH
];
691 char pathA
[MAX_PATH
];
694 TRACE( "drive %d\n", DL_reg(context
) );
696 if (drive
== MAX_DOS_DRIVES
)
698 SetLastError(ERROR_INVALID_DRIVE
);
703 * Grab current directory.
706 if (!GetCurrentDirectoryW( MAX_PATH
, pathW
)) return FALSE
;
708 if (toupperW(pathW
[0]) - 'A' != drive
|| pathW
[1] != ':')
710 /* cwd is not on the requested drive, get the environment string instead */
715 env_var
[1] = 'A' + drive
;
718 if (!GetEnvironmentVariableW( env_var
, pathW
, MAX_PATH
))
720 /* return empty path */
727 * Convert into short format.
732 DWORD result
= GetShortPathNameW( pathW
, pathW
, MAX_PATH
);
735 if (result
> MAX_PATH
)
737 WARN( "Short path too long!\n" );
738 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
744 * The returned pathname does not include
745 * the drive letter, colon or leading backslash.
751 * FIXME: We should probably just strip host part from name...
753 FIXME( "UNC names are not supported.\n" );
754 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
757 else if (!ptr
[0] || ptr
[1] != ':' || ptr
[2] != '\\')
759 WARN( "Path is neither UNC nor DOS path: %s\n",
760 wine_dbgstr_w(ptr
) );
761 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
766 /* Remove drive letter, colon and leading backslash. */
771 * Convert into OEM string.
774 if (!WideCharToMultiByte(CP_OEMCP
, 0, ptr
, -1, pathA
,
775 MAX_PATH
, NULL
, NULL
))
777 WARN( "Cannot convert path!\n" );
778 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
788 /* Undocumented success code. */
789 SET_AX( context
, 0x0100 );
791 /* Truncate buffer to 64 bytes. */
795 TRACE( "%c:=%s\n", 'A' + drive
, pathA
);
797 strcpy( buffer
, pathA
);
802 /***********************************************************************
803 * INT21_SetCurrentDirectory
807 * - subfunction 0x3b of function 0x71
809 static BOOL
INT21_SetCurrentDirectory( CONTEXT86
*context
)
811 WCHAR dirW
[MAX_PATH
];
814 char *dirA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
815 BYTE drive
= INT21_GetCurrentDrive();
818 TRACE( "SET CURRENT DIRECTORY %s\n", dirA
);
820 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
821 if (!GetFullPathNameW( dirW
, MAX_PATH
, dirW
, NULL
)) return FALSE
;
823 attr
= GetFileAttributesW( dirW
);
824 if (attr
== INVALID_FILE_ATTRIBUTES
|| !(attr
& FILE_ATTRIBUTE_DIRECTORY
))
826 SetLastError( ERROR_PATH_NOT_FOUND
);
831 env_var
[1] = dirW
[0];
834 result
= SetEnvironmentVariableW( env_var
, dirW
);
836 /* only set current directory if on the current drive */
837 if (result
&& (toupperW(dirW
[0]) - 'A' == drive
)) result
= SetCurrentDirectoryW( dirW
);
842 /***********************************************************************
843 * INT21_CreateMagicDeviceHandle
845 * Create a dummy file handle for a "magic" device.
847 static HANDLE
INT21_CreateMagicDeviceHandle( LPCWSTR name
)
849 const char *dir
= wine_get_server_dir();
853 OBJECT_ATTRIBUTES attr
;
854 UNICODE_STRING nameW
;
857 len
= MultiByteToWideChar( CP_UNIXCP
, 0, dir
, -1, NULL
, 0 );
858 nameW
.Length
= (len
+ 1 + strlenW( name
)) * sizeof(WCHAR
);
859 nameW
.MaximumLength
= nameW
.Length
+ sizeof(WCHAR
);
860 if (!(nameW
.Buffer
= HeapAlloc( GetProcessHeap(), 0, nameW
.Length
)))
862 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
865 MultiByteToWideChar( CP_UNIXCP
, 0, dir
, -1, nameW
.Buffer
, len
);
866 nameW
.Buffer
[len
-1] = '/';
867 strcpyW( nameW
.Buffer
+ len
, name
);
869 attr
.Length
= sizeof(attr
);
870 attr
.RootDirectory
= 0;
872 attr
.ObjectName
= &nameW
;
873 attr
.SecurityDescriptor
= NULL
;
874 attr
.SecurityQualityOfService
= NULL
;
876 status
= NtCreateFile( &ret
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &io
, NULL
, 0,
877 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
,
878 FILE_SYNCHRONOUS_IO_ALERT
, NULL
, 0 );
882 SetLastError( RtlNtStatusToDosError(status
) );
884 RtlFreeUnicodeString( &nameW
);
889 /***********************************************************************
890 * INT21_OpenMagicDevice
892 * Open a file handle for "magic" devices like EMMXXXX0.
894 static HANDLE
INT21_OpenMagicDevice( LPCWSTR name
, DWORD access
)
900 if (name
[0] && (name
[1] == ':')) name
+= 2;
901 if ((p
= strrchrW( name
, '/' ))) name
= p
+ 1;
902 if ((p
= strrchrW( name
, '\\' ))) name
= p
+ 1;
904 for (i
= 0; i
< NB_MAGIC_DEVICES
; i
++)
906 int len
= strlenW( magic_devices
[i
].name
);
907 if (!strncmpiW( magic_devices
[i
].name
, name
, len
) &&
908 (!name
[len
] || name
[len
] == '.' || name
[len
] == ':')) break;
910 if (i
== NB_MAGIC_DEVICES
) return 0;
912 if (!magic_devices
[i
].handle
) /* need to open it */
917 if (!(handle
= INT21_CreateMagicDeviceHandle( magic_devices
[i
].name
))) return 0;
918 wine_server_handle_to_fd( handle
, 0, &fd
, NULL
);
920 wine_server_release_fd( handle
, fd
);
921 magic_devices
[i
].dev
= st
.st_dev
;
922 magic_devices
[i
].ino
= st
.st_ino
;
923 magic_devices
[i
].handle
= handle
;
925 if (!DuplicateHandle( GetCurrentProcess(), magic_devices
[i
].handle
,
926 GetCurrentProcess(), &handle
, access
, FALSE
, 0 )) handle
= 0;
931 /***********************************************************************
939 * - subfunction 0x6c of function 0x71
941 static BOOL
INT21_CreateFile( CONTEXT86
*context
,
948 char *pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, pathSegOff
);
949 WCHAR pathW
[MAX_PATH
];
956 TRACE( "CreateFile called: function=%02x, action=%02x, access/share=%04x, "
957 "create flags=%04x, file=%s.\n",
958 AH_reg(context
), dosAction
, dosAccessShare
, CX_reg(context
), pathA
);
961 * Application tried to create/open a file whose name
962 * ends with a backslash. This is not allowed.
964 * FIXME: This needs to be validated, especially the return value.
966 if (pathA
[strlen(pathA
) - 1] == '/')
968 SetLastError( ERROR_FILE_NOT_FOUND
);
973 * Convert DOS action flags into Win32 creation disposition parameter.
978 winMode
= OPEN_EXISTING
;
981 winMode
= TRUNCATE_EXISTING
;
984 winMode
= CREATE_NEW
;
987 winMode
= OPEN_ALWAYS
;
990 winMode
= CREATE_ALWAYS
;
993 SetLastError( ERROR_INVALID_PARAMETER
);
998 * Convert DOS access/share flags into Win32 desired access parameter.
1000 switch(dosAccessShare
& 0x07)
1003 winAccess
= GENERIC_READ
;
1006 winAccess
= GENERIC_WRITE
;
1009 winAccess
= GENERIC_READ
| GENERIC_WRITE
;
1013 * Read-only, do not modify file's last-access time (DOS7).
1015 * FIXME: How to prevent modification of last-access time?
1017 winAccess
= GENERIC_READ
;
1024 * Convert DOS access/share flags into Win32 share mode parameter.
1026 switch(dosAccessShare
& 0x70)
1028 case OF_SHARE_EXCLUSIVE
:
1031 case OF_SHARE_DENY_WRITE
:
1032 winSharing
= FILE_SHARE_READ
;
1034 case OF_SHARE_DENY_READ
:
1035 winSharing
= FILE_SHARE_WRITE
;
1037 case OF_SHARE_DENY_NONE
:
1038 case OF_SHARE_COMPAT
:
1040 winSharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1044 * FIXME: Bit (dosAccessShare & 0x80) represents inheritance.
1045 * What to do with this bit?
1046 * FIXME: Bits in the high byte of dosAccessShare are not supported.
1047 * See both function 0x6c and subfunction 0x6c of function 0x71 for
1048 * definition of these bits.
1052 * Convert DOS create attributes into Win32 flags and attributes parameter.
1054 if (winMode
== OPEN_EXISTING
|| winMode
== TRUNCATE_EXISTING
)
1060 WORD dosAttributes
= CX_reg(context
);
1062 if (dosAttributes
& FA_LABEL
)
1065 * Application tried to create volume label entry.
1066 * This is difficult to support so we do not allow it.
1068 * FIXME: If volume does not already have a label,
1069 * this function is supposed to succeed.
1071 SetLastError( ERROR_ACCESS_DENIED
);
1075 winAttributes
= dosAttributes
&
1076 (FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
|
1077 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
);
1083 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
1085 if ((winHandle
= INT21_OpenMagicDevice( pathW
, winAccess
)))
1091 winHandle
= CreateFileW( pathW
, winAccess
, winSharing
, NULL
,
1092 winMode
, winAttributes
, 0 );
1094 if (winHandle
== INVALID_HANDLE_VALUE
)
1098 * Determine DOS file status.
1109 case TRUNCATE_EXISTING
:
1116 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 1 : 2;
1119 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 3 : 2;
1127 * Return DOS file handle and DOS status.
1129 SET_AX( context
, Win32HandleToDosFileHandle(winHandle
) );
1132 SET_CX( context
, dosStatus
);
1134 TRACE( "CreateFile finished: handle=%d, status=%d.\n",
1135 AX_reg(context
), dosStatus
);
1141 /***********************************************************************
1142 * INT21_BufferedInput
1144 * Handler for function 0x0a and reading from console using
1147 * Reads a string of characters from standard input until
1148 * enter key is pressed. Returns either number of characters
1149 * read from console including terminating CR or
1150 * zero if capacity was zero.
1152 static WORD
INT21_BufferedInput( CONTEXT86
*context
, BYTE
*ptr
, WORD capacity
)
1157 * Return immediately if capacity is zero.
1167 DOSVM_Int16ReadChar( &ascii
, &scan
, context
);
1169 if (ascii
== '\r' || ascii
== '\n')
1176 * DOS handles only backspace and KEY_LEFT
1177 * perhaps we should do more
1179 if (ascii
== '\b' || scan
== KEY_LEFT
)
1181 if (length
==0) continue;
1182 DOSVM_PutChar( '\b' );
1188 * If the buffer becomes filled to within one byte of
1189 * capacity, DOS rejects all further characters up to,
1190 * but not including, the terminating carriage return.
1192 if (ascii
!= 0 && length
< capacity
-1)
1194 DOSVM_PutChar( ascii
);
1195 ptr
[length
] = ascii
;
1202 /***********************************************************************
1203 * INT21_GetCurrentDTA
1205 static BYTE
*INT21_GetCurrentDTA( CONTEXT86
*context
)
1207 TDB
*pTask
= GlobalLock16(GetCurrentTask());
1209 /* FIXME: This assumes DTA was set correctly! */
1210 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
1211 (DWORD
)OFFSETOF(pTask
->dta
) );
1215 /***********************************************************************
1216 * INT21_OpenFileUsingFCB
1218 * Handler for function 0x0f.
1221 * DX:DX [I/O] File control block (FCB or XFCB) of unopened file
1228 * Opens a FCB file for read/write in compatibility mode. Upon calling
1229 * the FCB must have the drive_number, file_name, and file_extension
1230 * fields filled and all other bytes cleared.
1232 static void INT21_OpenFileUsingFCB( CONTEXT86
*context
)
1240 BY_HANDLE_FILE_INFORMATION info
;
1243 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1244 if (fcb
->drive_number
== 0xff) {
1245 xfcb
= (struct XFCB
*) fcb
;
1246 fcb
= (struct FCB
*) xfcb
->fcb
;
1250 file_path
[0] = 'A' + INT21_MapDrive( fcb
->drive_number
);
1252 if (AL_result
== 0) {
1254 pos
= &file_path
[2];
1255 memcpy(pos
, fcb
->file_name
, 8);
1258 pos
= strchr(pos
, ' ');
1261 memcpy(pos
, fcb
->file_extension
, 3);
1264 pos
= strchr(pos
, ' ');
1267 handle
= (HANDLE
) _lopen(file_path
, OF_READWRITE
);
1268 if (handle
== INVALID_HANDLE_VALUE
) {
1269 TRACE("_lopen(\"%s\") failed: INVALID_HANDLE_VALUE\n", file_path
);
1270 AL_result
= 0xff; /* failed */
1272 hfile16
= Win32HandleToDosFileHandle(handle
);
1273 if (hfile16
== HFILE_ERROR16
) {
1274 TRACE("Win32HandleToDosFileHandle(%p) failed: HFILE_ERROR\n", handle
);
1275 CloseHandle(handle
);
1276 AL_result
= 0xff; /* failed */
1277 } else if (hfile16
> 255) {
1278 TRACE("hfile16 (=%d) larger than 255 for \"%s\"\n", hfile16
, file_path
);
1280 AL_result
= 0xff; /* failed */
1282 if (!GetFileInformationByHandle(handle
, &info
)) {
1283 TRACE("GetFileInformationByHandle(%d, %p) for \"%s\" failed\n",
1284 hfile16
, handle
, file_path
);
1286 AL_result
= 0xff; /* failed */
1288 fcb
->drive_number
= file_path
[0] - 'A' + 1;
1289 fcb
->current_block_number
= 0;
1290 fcb
->logical_record_size
= 128;
1291 fcb
->file_size
= info
.nFileSizeLow
;
1292 FileTimeToDosDateTime(&info
.ftLastWriteTime
,
1293 &fcb
->date_of_last_write
, &fcb
->time_of_last_write
);
1294 fcb
->file_number
= hfile16
;
1295 fcb
->attributes
= 0xc2;
1296 fcb
->starting_cluster
= 0; /* don't know correct init value */
1297 fcb
->sequence_number
= 0; /* don't know correct init value */
1298 fcb
->file_attributes
= info
.dwFileAttributes
;
1299 /* The following fields are not initialized */
1300 /* by the native function: */
1302 /* record_within_current_block */
1303 /* random_access_record_number */
1305 TRACE("successful opened file \"%s\" as %d (handle %p)\n",
1306 file_path
, hfile16
, handle
);
1307 AL_result
= 0x00; /* successful */
1312 SET_AL(context
, AL_result
);
1316 /***********************************************************************
1317 * INT21_CloseFileUsingFCB
1319 * Handler for function 0x10.
1322 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1329 * Closes a FCB file.
1331 static void INT21_CloseFileUsingFCB( CONTEXT86
*context
)
1337 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1338 if (fcb
->drive_number
== 0xff) {
1339 xfcb
= (struct XFCB
*) fcb
;
1340 fcb
= (struct FCB
*) xfcb
->fcb
;
1343 if (_lclose16((HFILE16
) fcb
->file_number
) != 0) {
1344 TRACE("_lclose16(%d) failed\n", fcb
->file_number
);
1345 AL_result
= 0xff; /* failed */
1347 TRACE("successful closed file %d\n", fcb
->file_number
);
1348 AL_result
= 0x00; /* successful */
1350 SET_AL(context
, AL_result
);
1354 /***********************************************************************
1355 * INT21_SequentialReadFromFCB
1357 * Handler for function 0x14.
1360 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1364 * 1: end of file, no data read
1365 * 2: segment wrap in DTA, no data read (not returned now)
1366 * 3: end of file, partial record read
1369 * Reads a record with the size FCB->logical_record_size from the FCB
1370 * to the disk transfer area. The position of the record is specified
1371 * with FCB->current_block_number and FCB->record_within_current_block.
1372 * Then FCB->current_block_number and FCB->record_within_current_block
1373 * are updated to point to the next record. If a partial record is
1374 * read, it is filled with zeros up to the FCB->logical_record_size.
1376 static void INT21_SequentialReadFromFCB( CONTEXT86
*context
)
1381 DWORD record_number
;
1383 BYTE
*disk_transfer_area
;
1387 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1388 if (fcb
->drive_number
== 0xff) {
1389 xfcb
= (struct XFCB
*) fcb
;
1390 fcb
= (struct FCB
*) xfcb
->fcb
;
1393 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1394 if (handle
== INVALID_HANDLE_VALUE
) {
1395 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1397 AL_result
= 0x01; /* end of file, no data read */
1399 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1400 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1401 if (position
!= record_number
* fcb
->logical_record_size
) {
1402 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1403 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1404 AL_result
= 0x01; /* end of file, no data read */
1406 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1407 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1408 if (bytes_read
!= fcb
->logical_record_size
) {
1409 TRACE("_lread(%d, %p, %d) failed with %d\n",
1410 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1411 if (bytes_read
== 0) {
1412 AL_result
= 0x01; /* end of file, no data read */
1414 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1415 AL_result
= 0x03; /* end of file, partial record read */
1418 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1419 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1420 AL_result
= 0x00; /* successful */
1424 if (AL_result
== 0x00 || AL_result
== 0x03) {
1425 if (fcb
->record_within_current_block
== 127) {
1426 fcb
->record_within_current_block
= 0;
1427 fcb
->current_block_number
++;
1429 fcb
->record_within_current_block
++;
1432 SET_AL(context
, AL_result
);
1436 /***********************************************************************
1437 * INT21_SequentialWriteToFCB
1439 * Handler for function 0x15.
1442 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1447 * 2: segment wrap in DTA (not returned now)
1450 * Writes a record with the size FCB->logical_record_size from the disk
1451 * transfer area to the FCB. The position of the record is specified
1452 * with FCB->current_block_number and FCB->record_within_current_block.
1453 * Then FCB->current_block_number and FCB->record_within_current_block
1454 * are updated to point to the next record.
1456 static void INT21_SequentialWriteToFCB( CONTEXT86
*context
)
1461 DWORD record_number
;
1463 BYTE
*disk_transfer_area
;
1467 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1468 if (fcb
->drive_number
== 0xff) {
1469 xfcb
= (struct XFCB
*) fcb
;
1470 fcb
= (struct FCB
*) xfcb
->fcb
;
1473 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1474 if (handle
== INVALID_HANDLE_VALUE
) {
1475 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1477 AL_result
= 0x01; /* disk full */
1479 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1480 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1481 if (position
!= record_number
* fcb
->logical_record_size
) {
1482 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1483 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1484 AL_result
= 0x01; /* disk full */
1486 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1487 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1488 if (bytes_written
!= fcb
->logical_record_size
) {
1489 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1490 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1491 AL_result
= 0x01; /* disk full */
1493 TRACE("successful written %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1494 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1495 AL_result
= 0x00; /* successful */
1499 if (AL_result
== 0x00) {
1500 if (fcb
->record_within_current_block
== 127) {
1501 fcb
->record_within_current_block
= 0;
1502 fcb
->current_block_number
++;
1504 fcb
->record_within_current_block
++;
1507 SET_AL(context
, AL_result
);
1511 /***********************************************************************
1512 * INT21_ReadRandomRecordFromFCB
1514 * Handler for function 0x21.
1517 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1521 * 1: end of file, no data read
1522 * 2: segment wrap in DTA, no data read (not returned now)
1523 * 3: end of file, partial record read
1526 * Reads a record with the size FCB->logical_record_size from
1527 * the FCB to the disk transfer area. The position of the record
1528 * is specified with FCB->random_access_record_number. The
1529 * FCB->random_access_record_number is not updated. If a partial record
1530 * is read, it is filled with zeros up to the FCB->logical_record_size.
1532 static void INT21_ReadRandomRecordFromFCB( CONTEXT86
*context
)
1537 DWORD record_number
;
1539 BYTE
*disk_transfer_area
;
1543 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1544 if (fcb
->drive_number
== 0xff) {
1545 xfcb
= (struct XFCB
*) fcb
;
1546 fcb
= (struct FCB
*) xfcb
->fcb
;
1549 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1550 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1551 if (handle
== INVALID_HANDLE_VALUE
) {
1552 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1554 AL_result
= 0x01; /* end of file, no data read */
1556 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1557 if (position
!= record_number
* fcb
->logical_record_size
) {
1558 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1559 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1560 AL_result
= 0x01; /* end of file, no data read */
1562 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1563 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1564 if (bytes_read
!= fcb
->logical_record_size
) {
1565 TRACE("_lread(%d, %p, %d) failed with %d\n",
1566 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1567 if (bytes_read
== 0) {
1568 AL_result
= 0x01; /* end of file, no data read */
1570 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1571 AL_result
= 0x03; /* end of file, partial record read */
1574 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1575 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1576 AL_result
= 0x00; /* successful */
1580 fcb
->current_block_number
= record_number
/ 128;
1581 fcb
->record_within_current_block
= record_number
% 128;
1582 SET_AL(context
, AL_result
);
1586 /***********************************************************************
1587 * INT21_WriteRandomRecordToFCB
1589 * Handler for function 0x22.
1592 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1597 * 2: segment wrap in DTA (not returned now)
1600 * Writes a record with the size FCB->logical_record_size from
1601 * the disk transfer area to the FCB. The position of the record
1602 * is specified with FCB->random_access_record_number. The
1603 * FCB->random_access_record_number is not updated.
1605 static void INT21_WriteRandomRecordToFCB( CONTEXT86
*context
)
1610 DWORD record_number
;
1612 BYTE
*disk_transfer_area
;
1616 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1617 if (fcb
->drive_number
== 0xff) {
1618 xfcb
= (struct XFCB
*) fcb
;
1619 fcb
= (struct FCB
*) xfcb
->fcb
;
1622 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1623 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1624 if (handle
== INVALID_HANDLE_VALUE
) {
1625 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1627 AL_result
= 0x01; /* disk full */
1629 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1630 if (position
!= record_number
* fcb
->logical_record_size
) {
1631 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1632 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1633 AL_result
= 0x01; /* disk full */
1635 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1636 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1637 if (bytes_written
!= fcb
->logical_record_size
) {
1638 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1639 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1640 AL_result
= 0x01; /* disk full */
1642 TRACE("successful written %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1643 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1644 AL_result
= 0x00; /* successful */
1648 fcb
->current_block_number
= record_number
/ 128;
1649 fcb
->record_within_current_block
= record_number
% 128;
1650 SET_AL(context
, AL_result
);
1654 /***********************************************************************
1655 * INT21_RandomBlockReadFromFCB
1657 * Handler for function 0x27.
1660 * CX [I/O] Number of records to read
1661 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1665 * 1: end of file, no data read
1666 * 2: segment wrap in DTA, no data read (not returned now)
1667 * 3: end of file, partial record read
1670 * Reads several records with the size FCB->logical_record_size from
1671 * the FCB to the disk transfer area. The number of records to be
1672 * read is specified in the CX register. The position of the first
1673 * record is specified with FCB->random_access_record_number. The
1674 * FCB->random_access_record_number, the FCB->current_block_number
1675 * and FCB->record_within_current_block are updated to point to the
1676 * next record after the records read. If a partial record is read,
1677 * it is filled with zeros up to the FCB->logical_record_size. The
1678 * CX register is set to the number of successfully read records.
1680 static void INT21_RandomBlockReadFromFCB( CONTEXT86
*context
)
1685 DWORD record_number
;
1687 BYTE
*disk_transfer_area
;
1688 UINT records_requested
;
1689 UINT bytes_requested
;
1694 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1695 if (fcb
->drive_number
== 0xff) {
1696 xfcb
= (struct XFCB
*) fcb
;
1697 fcb
= (struct FCB
*) xfcb
->fcb
;
1700 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1701 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1702 if (handle
== INVALID_HANDLE_VALUE
) {
1703 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1706 AL_result
= 0x01; /* end of file, no data read */
1708 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1709 if (position
!= record_number
* fcb
->logical_record_size
) {
1710 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1711 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1713 AL_result
= 0x01; /* end of file, no data read */
1715 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1716 records_requested
= CX_reg(context
);
1717 bytes_requested
= (UINT
) records_requested
* fcb
->logical_record_size
;
1718 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1719 if (bytes_read
!= bytes_requested
) {
1720 TRACE("_lread(%d, %p, %d) failed with %d\n",
1721 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_read
);
1722 records_read
= bytes_read
/ fcb
->logical_record_size
;
1723 if (bytes_read
% fcb
->logical_record_size
== 0) {
1724 AL_result
= 0x01; /* end of file, no data read */
1727 memset(&disk_transfer_area
[bytes_read
], 0, records_read
* fcb
->logical_record_size
- bytes_read
);
1728 AL_result
= 0x03; /* end of file, partial record read */
1731 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1732 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1733 records_read
= records_requested
;
1734 AL_result
= 0x00; /* successful */
1738 record_number
+= records_read
;
1739 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1740 fcb
->current_block_number
= record_number
/ 128;
1741 fcb
->record_within_current_block
= record_number
% 128;
1742 SET_CX(context
, records_read
);
1743 SET_AL(context
, AL_result
);
1747 /***********************************************************************
1748 * INT21_RandomBlockWriteToFCB
1750 * Handler for function 0x28.
1753 * CX [I/O] Number of records to write
1754 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1759 * 2: segment wrap in DTA (not returned now)
1762 * Writes several records with the size FCB->logical_record_size from
1763 * the disk transfer area to the FCB. The number of records to be
1764 * written is specified in the CX register. The position of the first
1765 * record is specified with FCB->random_access_record_number. The
1766 * FCB->random_access_record_number, the FCB->current_block_number
1767 * and FCB->record_within_current_block are updated to point to the
1768 * next record after the records written. The CX register is set to
1769 * the number of successfully written records.
1771 static void INT21_RandomBlockWriteToFCB( CONTEXT86
*context
)
1776 DWORD record_number
;
1778 BYTE
*disk_transfer_area
;
1779 UINT records_requested
;
1780 UINT bytes_requested
;
1782 UINT records_written
;
1785 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1786 if (fcb
->drive_number
== 0xff) {
1787 xfcb
= (struct XFCB
*) fcb
;
1788 fcb
= (struct FCB
*) xfcb
->fcb
;
1791 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1792 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1793 if (handle
== INVALID_HANDLE_VALUE
) {
1794 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1796 records_written
= 0;
1797 AL_result
= 0x01; /* disk full */
1799 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1800 if (position
!= record_number
* fcb
->logical_record_size
) {
1801 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1802 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1803 records_written
= 0;
1804 AL_result
= 0x01; /* disk full */
1806 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1807 records_requested
= CX_reg(context
);
1808 bytes_requested
= (UINT
) records_requested
* fcb
->logical_record_size
;
1809 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1810 if (bytes_written
!= bytes_requested
) {
1811 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1812 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_written
);
1813 records_written
= bytes_written
/ fcb
->logical_record_size
;
1814 AL_result
= 0x01; /* disk full */
1816 TRACE("successful write %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1817 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1818 records_written
= records_requested
;
1819 AL_result
= 0x00; /* successful */
1823 record_number
+= records_written
;
1824 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1825 fcb
->current_block_number
= record_number
/ 128;
1826 fcb
->record_within_current_block
= record_number
% 128;
1827 SET_CX(context
, records_written
);
1828 SET_AL(context
, AL_result
);
1832 /***********************************************************************
1833 * INT21_CreateDirectory
1837 * - subfunction 0x39 of function 0x71
1838 * - subfunction 0xff of function 0x43 (CL == 0x39)
1840 static BOOL
INT21_CreateDirectory( CONTEXT86
*context
)
1842 WCHAR dirW
[MAX_PATH
];
1843 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
1847 TRACE( "CREATE DIRECTORY %s\n", dirA
);
1849 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
1851 if (CreateDirectoryW(dirW
, NULL
))
1855 * FIXME: CreateDirectory's LastErrors will clash with the ones
1856 * used by DOS. AH=39 only returns 3 (path not found) and
1857 * 5 (access denied), while CreateDirectory return several
1858 * ones. Remap some of them. -Marcus
1860 switch (GetLastError())
1862 case ERROR_ALREADY_EXISTS
:
1863 case ERROR_FILENAME_EXCED_RANGE
:
1864 case ERROR_DISK_FULL
:
1865 SetLastError(ERROR_ACCESS_DENIED
);
1875 /***********************************************************************
1876 * INT21_ExtendedCountryInformation
1878 * Handler for function 0x65.
1880 static void INT21_ExtendedCountryInformation( CONTEXT86
*context
)
1882 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN( context
, context
->SegEs
, context
->Edi
);
1883 BYTE buffsize
= CX_reg (context
);
1885 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
1889 * Check subfunctions that are passed country and code page.
1891 if (AL_reg(context
) >= 0x01 && AL_reg(context
) <= 0x07)
1893 WORD country
= DX_reg(context
);
1894 WORD codepage
= BX_reg(context
);
1896 if (country
!= 0xffff && country
!= INT21_GetSystemCountryCode())
1897 FIXME( "Requested info on non-default country %04x\n", country
);
1899 if (codepage
!= 0xffff && codepage
!= GetOEMCP())
1900 FIXME( "Requested info on non-default code page %04x\n", codepage
);
1903 switch (AL_reg(context
)) {
1904 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
1905 INT_BARF( context
, 0x21 );
1906 SET_CFLAG( context
);
1909 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
1910 TRACE( "Get general internationalization info\n" );
1911 dataptr
[0] = 0x01; /* Info ID */
1912 *(WORD
*)(dataptr
+1) = 38; /* Size of the following info */
1913 *(WORD
*)(dataptr
+3) = INT21_GetSystemCountryCode(); /* Country ID */
1914 *(WORD
*)(dataptr
+5) = GetOEMCP(); /* Code page */
1915 /* FIXME: fill buffer partially up to buffsize bytes*/
1916 if (buffsize
>= 0x29){
1917 INT21_FillCountryInformation( dataptr
+ 7 );
1918 SET_CX( context
, 0x29 ); /* Size of returned info */
1920 SET_CX( context
, 0x07 ); /* Size of returned info */
1924 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
1925 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
1926 TRACE( "Get pointer to uppercase table\n" );
1927 dataptr
[0] = AL_reg(context
); /* Info ID */
1928 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1929 offsetof(INT21_HEAP
, uppercase_size
) );
1930 SET_CX( context
, 5 ); /* Size of returned info */
1933 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
1934 TRACE( "Get pointer to lowercase table\n" );
1935 dataptr
[0] = 0x03; /* Info ID */
1936 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1937 offsetof(INT21_HEAP
, lowercase_size
) );
1938 SET_CX( context
, 5 ); /* Size of returned info */
1941 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
1942 TRACE("Get pointer to filename terminator table\n");
1943 dataptr
[0] = 0x05; /* Info ID */
1944 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1945 offsetof(INT21_HEAP
, filename_size
) );
1946 SET_CX( context
, 5 ); /* Size of returned info */
1949 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
1950 TRACE("Get pointer to collating sequence table\n");
1951 dataptr
[0] = 0x06; /* Info ID */
1952 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1953 offsetof(INT21_HEAP
, collating_size
) );
1954 SET_CX( context
, 5 ); /* Size of returned info */
1957 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
1958 TRACE("Get pointer to DBCS lead byte table\n");
1959 dataptr
[0] = 0x07; /* Info ID */
1960 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1961 offsetof(INT21_HEAP
, dbcs_size
) );
1962 SET_CX( context
, 5 ); /* Size of returned info */
1965 case 0x20: /* CAPITALIZE CHARACTER */
1966 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
1967 TRACE("Convert char to uppercase\n");
1968 SET_DL( context
, toupper(DL_reg(context
)) );
1971 case 0x21: /* CAPITALIZE STRING */
1972 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
1973 TRACE("Convert string to uppercase with length\n");
1975 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN( context
,
1978 WORD len
= CX_reg(context
);
1979 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
1983 case 0x22: /* CAPITALIZE ASCIIZ STRING */
1984 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
1985 TRACE("Convert ASCIIZ string to uppercase\n");
1986 _strupr( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
) );
1989 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
1990 INT_BARF( context
, 0x21 );
1991 SET_CFLAG( context
);
1995 INT_BARF( context
, 0x21 );
2002 /***********************************************************************
2003 * INT21_FileAttributes
2007 * - subfunction 0x43 of function 0x71
2009 static BOOL
INT21_FileAttributes( CONTEXT86
*context
,
2013 WCHAR fileW
[MAX_PATH
];
2014 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
2023 switch (subfunction
)
2025 case 0x00: /* GET FILE ATTRIBUTES */
2026 TRACE( "GET FILE ATTRIBUTES for %s\n", fileA
);
2027 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2029 result
= GetFileAttributesW( fileW
);
2030 if (result
== INVALID_FILE_ATTRIBUTES
)
2034 SET_CX( context
, (WORD
)result
);
2036 SET_AX( context
, (WORD
)result
); /* DR DOS */
2040 case 0x01: /* SET FILE ATTRIBUTES */
2041 TRACE( "SET FILE ATTRIBUTES 0x%02x for %s\n",
2042 CX_reg(context
), fileA
);
2043 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2045 if (!SetFileAttributesW( fileW
, CX_reg(context
) ))
2049 case 0x02: /* GET COMPRESSED FILE SIZE */
2050 TRACE( "GET COMPRESSED FILE SIZE for %s\n", fileA
);
2051 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2053 result
= GetCompressedFileSizeW( fileW
, NULL
);
2054 if (result
== INVALID_FILE_SIZE
)
2058 SET_AX( context
, LOWORD(result
) );
2059 SET_DX( context
, HIWORD(result
) );
2063 case 0x03: /* SET FILE LAST-WRITTEN DATE AND TIME */
2065 INT_BARF( context
, 0x21 );
2068 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
2069 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2071 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2072 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2073 NULL
, OPEN_EXISTING
, 0, 0 );
2074 if (handle
== INVALID_HANDLE_VALUE
)
2077 DosDateTimeToFileTime( DI_reg(context
),
2080 status
= SetFileTime( handle
, NULL
, NULL
, &filetime
);
2082 CloseHandle( handle
);
2087 case 0x04: /* GET FILE LAST-WRITTEN DATE AND TIME */
2089 INT_BARF( context
, 0x21 );
2092 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
2093 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2095 handle
= CreateFileW( fileW
, GENERIC_READ
,
2096 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2097 NULL
, OPEN_EXISTING
, 0, 0 );
2098 if (handle
== INVALID_HANDLE_VALUE
)
2101 status
= GetFileTime( handle
, NULL
, NULL
, &filetime
);
2104 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2105 SET_DI( context
, date
);
2106 SET_CX( context
, time
);
2109 CloseHandle( handle
);
2114 case 0x05: /* SET FILE LAST ACCESS DATE */
2116 INT_BARF( context
, 0x21 );
2119 TRACE( "SET FILE LAST ACCESS DATE, file %s\n", fileA
);
2120 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2122 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2123 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2124 NULL
, OPEN_EXISTING
, 0, 0 );
2125 if (handle
== INVALID_HANDLE_VALUE
)
2128 DosDateTimeToFileTime( DI_reg(context
),
2131 status
= SetFileTime( handle
, NULL
, &filetime
, NULL
);
2133 CloseHandle( handle
);
2138 case 0x06: /* GET FILE LAST ACCESS DATE */
2140 INT_BARF( context
, 0x21 );
2143 TRACE( "GET FILE LAST ACCESS DATE, file %s\n", fileA
);
2144 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2146 handle
= CreateFileW( fileW
, GENERIC_READ
,
2147 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2148 NULL
, OPEN_EXISTING
, 0, 0 );
2149 if (handle
== INVALID_HANDLE_VALUE
)
2152 status
= GetFileTime( handle
, NULL
, &filetime
, NULL
);
2155 FileTimeToDosDateTime( &filetime
, &date
, NULL
);
2156 SET_DI( context
, date
);
2159 CloseHandle( handle
);
2164 case 0x07: /* SET FILE CREATION DATE AND TIME */
2166 INT_BARF( context
, 0x21 );
2169 TRACE( "SET FILE CREATION DATE AND TIME, file %s\n", fileA
);
2171 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2172 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2173 NULL
, OPEN_EXISTING
, 0, 0 );
2174 if (handle
== INVALID_HANDLE_VALUE
)
2178 * FIXME: SI has number of 10-millisecond units past time in CX.
2180 DosDateTimeToFileTime( DI_reg(context
),
2183 status
= SetFileTime( handle
, &filetime
, NULL
, NULL
);
2185 CloseHandle( handle
);
2190 case 0x08: /* GET FILE CREATION DATE AND TIME */
2192 INT_BARF( context
, 0x21 );
2195 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2198 handle
= CreateFileW( fileW
, GENERIC_READ
,
2199 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2200 NULL
, OPEN_EXISTING
, 0, 0 );
2201 if (handle
== INVALID_HANDLE_VALUE
)
2204 status
= GetFileTime( handle
, &filetime
, NULL
, NULL
);
2207 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2208 SET_DI( context
, date
);
2209 SET_CX( context
, time
);
2211 * FIXME: SI has number of 10-millisecond units past
2214 SET_SI( context
, 0 );
2217 CloseHandle(handle
);
2222 case 0xff: /* EXTENDED-LENGTH FILENAME OPERATIONS */
2223 if (islong
|| context
->Ebp
!= 0x5053)
2224 INT_BARF( context
, 0x21 );
2227 switch(CL_reg(context
))
2230 if (!INT21_CreateDirectory( context
))
2235 if (!INT21_RenameFile( context
))
2240 INT_BARF( context
, 0x21 );
2246 INT_BARF( context
, 0x21 );
2253 /***********************************************************************
2254 * INT21_FileDateTime
2256 * Handler for function 0x57.
2258 static BOOL
INT21_FileDateTime( CONTEXT86
*context
)
2260 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2264 switch (AL_reg(context
)) {
2265 case 0x00: /* Get last-written stamp */
2266 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2269 if (!GetFileTime( handle
, NULL
, NULL
, &filetime
))
2271 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2272 SET_DX( context
, date
);
2273 SET_CX( context
, time
);
2277 case 0x01: /* Set last-written stamp */
2278 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2281 DosDateTimeToFileTime( DX_reg(context
),
2284 if (!SetFileTime( handle
, NULL
, NULL
, &filetime
))
2289 case 0x04: /* Get last access stamp, DOS 7 */
2290 TRACE( "GET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2293 if (!GetFileTime( handle
, NULL
, &filetime
, NULL
))
2295 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2296 SET_DX( context
, date
);
2297 SET_CX( context
, time
);
2301 case 0x05: /* Set last access stamp, DOS 7 */
2302 TRACE( "SET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2305 DosDateTimeToFileTime( DX_reg(context
),
2308 if (!SetFileTime( handle
, NULL
, &filetime
, NULL
))
2313 case 0x06: /* Get creation stamp, DOS 7 */
2314 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2317 if (!GetFileTime( handle
, &filetime
, NULL
, NULL
))
2319 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2320 SET_DX( context
, date
);
2321 SET_CX( context
, time
);
2323 * FIXME: SI has number of 10-millisecond units past time in CX.
2325 SET_SI( context
, 0 );
2329 case 0x07: /* Set creation stamp, DOS 7 */
2330 TRACE( "SET FILE CREATION DATE AND TIME, handle %d\n",
2334 * FIXME: SI has number of 10-millisecond units past time in CX.
2336 DosDateTimeToFileTime( DX_reg(context
),
2339 if (!SetFileTime( handle
, &filetime
, NULL
, NULL
))
2345 INT_BARF( context
, 0x21 );
2353 /***********************************************************************
2356 * Handler for functions 0x51 and 0x62.
2358 static void INT21_GetPSP( CONTEXT86
*context
)
2360 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context
) );
2363 * FIXME: should we return the original DOS PSP upon
2366 if (!ISV86(context
) && DOSVM_IsWin16())
2367 SET_BX( context
, LOWORD(GetCurrentPDB16()) );
2369 SET_BX( context
, DOSVM_psp
);
2372 static inline void setword( BYTE
*ptr
, WORD w
)
2375 ptr
[1] = (BYTE
)(w
>> 8);
2378 static void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
2379 /* limited == TRUE is used with INT 0x21/0x440d */
2381 /* FIXME: we're forcing some values without checking that those are valid */
2386 setword(&data
[3], 0);
2388 setword(&data
[6], 240);
2389 setword(&data
[8], 64000);
2391 setword(&data
[0x0b], 40);
2392 setword(&data
[0x0d], 56);
2393 setword(&data
[0x0f], 2);
2394 setword(&data
[0x11], 0);
2397 setword(&data
[0x1f], 800);
2399 setword(&data
[0x22], 1);
2406 setword(&data
[3], 0);
2408 setword(&data
[6], 240);
2409 setword(&data
[8], 2880);
2411 setword(&data
[0x0b], 6);
2412 setword(&data
[0x0d], 18);
2413 setword(&data
[0x0f], 2);
2414 setword(&data
[0x11], 0);
2417 setword(&data
[0x1f], 80);
2419 setword(&data
[0x22], 2);
2424 inline DWORD
INT21_Ioctl_CylHeadSect2Lin(DWORD cyl
, WORD head
, WORD sec
, WORD cyl_cnt
, WORD head_cnt
, WORD sec_cnt
)
2426 DWORD res
= (cyl
* head_cnt
*sec_cnt
+ head
* sec_cnt
+ sec
);
2430 /***********************************************************************
2433 * Handler for block device IOCTLs.
2435 static void INT21_Ioctl_Block( CONTEXT86
*context
)
2438 BYTE drive
= INT21_MapDrive( BL_reg(context
) );
2439 WCHAR drivespec
[4] = {'A', ':', '\\', 0};
2442 drivespec
[0] += drive
;
2443 drivetype
= GetDriveTypeW( drivespec
);
2445 RESET_CFLAG(context
);
2446 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
2448 TRACE( "IOCTL - SUBFUNCTION %d - INVALID DRIVE %c:\n",
2449 AL_reg(context
), 'A' + drive
);
2450 SetLastError( ERROR_INVALID_DRIVE
);
2451 SET_AX( context
, ERROR_INVALID_DRIVE
);
2452 SET_CFLAG( context
);
2456 switch (AL_reg(context
))
2458 case 0x04: /* READ FROM BLOCK DEVICE CONTROL CHANNEL */
2459 case 0x05: /* WRITE TO BLOCK DEVICE CONTROL CHANNEL */
2460 INT_BARF( context
, 0x21 );
2463 case 0x08: /* CHECK IF BLOCK DEVICE REMOVABLE */
2464 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOVABLE - %c:\n",
2467 if (drivetype
== DRIVE_REMOVABLE
)
2468 SET_AX( context
, 0 ); /* removable */
2470 SET_AX( context
, 1 ); /* not removable */
2473 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
2474 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOTE - %c:\n",
2477 if (drivetype
== DRIVE_REMOTE
)
2478 SET_DX( context
, (1<<9) | (1<<12) ); /* remote + no direct IO */
2480 SET_DX( context
, 0 ); /* FIXME: use driver attr here */
2483 case 0x0d: /* GENERIC BLOCK DEVICE REQUEST */
2484 /* Get pointer to IOCTL parameter block */
2485 dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2487 switch (CX_reg(context
))
2489 case 0x0841: /* write logical device track */
2490 TRACE( "GENERIC IOCTL - Write logical device track - %c:\n",
2493 WORD head
= *(WORD
*)(dataptr
+1);
2494 WORD cyl
= *(WORD
*)(dataptr
+3);
2495 WORD sect
= *(WORD
*)(dataptr
+5);
2496 WORD nrsect
= *(WORD
*)(dataptr
+7);
2497 BYTE
*data
= CTX_SEG_OFF_TO_LIN(context
, *(WORD
*)(dataptr
+11), *(WORD
*)(dataptr
+9));
2498 WORD cyl_cnt
, head_cnt
, sec_cnt
;
2500 /* FIXME: we're faking some values here */
2506 SET_AX( context
, ERROR_WRITE_FAULT
);
2517 if (!DOSVM_RawWrite(drive
, INT21_Ioctl_CylHeadSect2Lin(cyl
, head
, sect
, cyl_cnt
, head_cnt
, sec_cnt
), nrsect
, data
, FALSE
))
2519 SET_AX( context
, ERROR_WRITE_FAULT
);
2525 case 0x084a: /* lock logical volume */
2526 TRACE( "GENERIC IOCTL - Lock logical volume, level %d mode %d - %c:\n",
2527 BH_reg(context
), DX_reg(context
), 'A' + drive
);
2530 case 0x0860: /* get device parameters */
2531 /* FIXME: we're faking some values here */
2532 /* used by w4wgrp's winfile */
2533 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
2535 dataptr
[6] = 0; /* media type */
2538 dataptr
[1] = 0x05; /* fixed disk */
2539 setword(&dataptr
[2], 0x01); /* non removable */
2540 setword(&dataptr
[4], 0x300); /* # of cylinders */
2544 dataptr
[1] = 0x07; /* block dev, floppy */
2545 setword(&dataptr
[2], 0x02); /* removable */
2546 setword(&dataptr
[4], 80); /* # of cylinders */
2548 CreateBPB(drive
, &dataptr
[7], TRUE
);
2549 RESET_CFLAG(context
);
2552 case 0x0861: /* read logical device track */
2553 TRACE( "GENERIC IOCTL - Read logical device track - %c:\n",
2556 WORD head
= *(WORD
*)(dataptr
+1);
2557 WORD cyl
= *(WORD
*)(dataptr
+3);
2558 WORD sect
= *(WORD
*)(dataptr
+5);
2559 WORD nrsect
= *(WORD
*)(dataptr
+7);
2560 BYTE
*data
= CTX_SEG_OFF_TO_LIN(context
, *(WORD
*)(dataptr
+11), *(WORD
*)(dataptr
+9));
2561 WORD cyl_cnt
, head_cnt
, sec_cnt
;
2563 /* FIXME: we're faking some values here */
2577 if (!DOSVM_RawRead(drive
, INT21_Ioctl_CylHeadSect2Lin(cyl
, head
, sect
, cyl_cnt
, head_cnt
, sec_cnt
), nrsect
, data
, FALSE
))
2579 SET_AX( context
, ERROR_READ_FAULT
);
2585 case 0x0866: /* get volume serial number */
2587 WCHAR label
[12],fsname
[9];
2590 drivespec
[0] += drive
;
2591 GetVolumeInformationW(drivespec
, label
, 12, &serial
, NULL
, NULL
, fsname
, 9);
2592 *(WORD
*)dataptr
= 0;
2593 memcpy(dataptr
+2,&serial
,4);
2594 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, dataptr
+ 6, 11, NULL
, NULL
);
2595 WideCharToMultiByte(CP_OEMCP
, 0, fsname
, 8, dataptr
+ 17, 8, NULL
, NULL
);
2599 case 0x086a: /* unlock logical volume */
2600 TRACE( "GENERIC IOCTL - Logical volume unlocked - %c:\n",
2604 case 0x086f: /* get drive map information */
2605 memset(dataptr
+1, '\0', dataptr
[0]-1);
2606 dataptr
[1] = dataptr
[0];
2607 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
2608 dataptr
[3] = 0xFF; /* no physical drive */
2612 /* Trial and error implementation */
2613 SET_AX( context
, drivetype
== DRIVE_UNKNOWN
? 0x0f : 0x01 );
2614 SET_CFLAG(context
); /* Seems to be set all the time */
2618 INT_BARF( context
, 0x21 );
2622 case 0x0e: /* GET LOGICAL DRIVE MAP */
2623 TRACE( "IOCTL - GET LOGICAL DRIVE MAP - %c:\n",
2625 /* FIXME: this is not correct if drive has mappings */
2626 SET_AL( context
, 0 ); /* drive has no mapping */
2629 case 0x0f: /* SET LOGICAL DRIVE MAP */
2631 WCHAR dev
[3], tgt
[4];
2633 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
2634 INT21_DriveName( BL_reg(context
)));
2635 dev
[0] = 'A' + drive
; dev
[1] = ':'; dev
[2] = 0;
2636 tgt
[0] = 'A' + drive
+ 1; tgt
[1] = ':'; tgt
[2] = '\\'; tgt
[3] = 0;
2637 if (!DefineDosDeviceW(DDD_RAW_TARGET_PATH
, dev
, tgt
))
2640 SET_AX( context
, 0x000F ); /* invalid drive */
2645 case 0x11: /* QUERY GENERIC IOCTL CAPABILITY */
2647 INT_BARF( context
, 0x21 );
2652 /***********************************************************************
2653 * INT21_IoctlScsiMgrHandler
2655 * IOCTL handler for the SCSIMGR device.
2657 static void INT21_IoctlScsiMgrHandler( CONTEXT86
*context
)
2659 switch (AL_reg(context
))
2661 case 0x00: /* GET DEVICE INFORMATION */
2662 SET_DX( context
, 0xc0c0 );
2665 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2666 DOSVM_ASPIHandler(context
);
2669 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2670 SET_DX( context
, 0 );
2673 case 0x01: /* SET DEVICE INFORMATION */
2674 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2675 case 0x06: /* GET INPUT STATUS */
2676 case 0x07: /* GET OUTPUT STATUS */
2677 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2678 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2680 INT_BARF( context
, 0x21 );
2686 /***********************************************************************
2687 * INT21_IoctlEMSHandler
2689 * IOCTL handler for the EMXXXX0 device.
2691 static void INT21_IoctlEMSHandler( CONTEXT86
*context
)
2693 EMS_Ioctl_Handler(context
);
2697 /***********************************************************************
2698 * INT21_IoctlHPScanHandler
2700 * IOCTL handler for the HPSCAN device.
2702 static void INT21_IoctlHPScanHandler( CONTEXT86
*context
)
2704 switch (AL_reg(context
))
2706 case 0x00: /* GET DEVICE INFORMATION */
2707 SET_DX( context
, 0xc0c0 );
2710 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2711 SET_DX( context
, 0 );
2714 case 0x01: /* SET DEVICE INFORMATION */
2715 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2716 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2717 case 0x06: /* GET INPUT STATUS */
2718 case 0x07: /* GET OUTPUT STATUS */
2719 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2720 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2722 INT_BARF( context
, 0x21 );
2728 /***********************************************************************
2731 * Handler for character device IOCTLs.
2733 static void INT21_Ioctl_Char( CONTEXT86
*context
)
2737 int IsConsoleIOHandle
= 0;
2738 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2740 status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
);
2743 if( VerifyConsoleIoHandle( handle
))
2744 IsConsoleIOHandle
= 1;
2746 SET_AX( context
, RtlNtStatusToDosError(status
) );
2747 SET_CFLAG( context
);
2752 IsConsoleIOHandle
= isatty( fd
);
2753 wine_server_release_fd( handle
, fd
);
2754 for (i
= 0; i
< NB_MAGIC_DEVICES
; i
++)
2756 if (!magic_devices
[i
].handle
) continue;
2757 if (magic_devices
[i
].dev
== st
.st_dev
&&
2758 magic_devices
[i
].ino
== st
.st_ino
)
2761 magic_devices
[i
].ioctl_handler( context
);
2767 /* no magic device found, do default handling */
2769 switch (AL_reg(context
))
2771 case 0x00: /* GET DEVICE INFORMATION */
2772 TRACE( "IOCTL - GET DEVICE INFORMATION - %d\n", BX_reg(context
) );
2773 if (IsConsoleIOHandle
|| S_ISCHR(st
.st_mode
))
2776 * Returns attribute word in DX:
2777 * Bit 14 - Device driver can process IOCTL requests.
2778 * Bit 13 - Output until busy supported.
2779 * Bit 11 - Driver supports OPEN/CLOSE calls.
2781 * Bit 7 - Set (indicates device).
2782 * Bit 6 - EOF on input.
2783 * Bit 5 - Raw (binary) mode.
2784 * Bit 4 - Device is special (uses int29).
2785 * Bit 3 - Clock device.
2786 * Bit 2 - NUL device.
2787 * Bit 1 - Console output device.
2788 * Bit 0 - Console input device.
2790 SET_DX( context
, IsConsoleIOHandle
? 0x80c3 : 0x80c0 /* FIXME */ );
2795 * Returns attribute word in DX:
2796 * Bit 15 - File is remote.
2797 * Bit 14 - Don't set file date/time on closing.
2798 * Bit 11 - Media not removable.
2799 * Bit 8 - Generate int24 if no disk space on write
2800 * or read past end of file
2801 * Bit 7 - Clear (indicates file).
2802 * Bit 6 - File has not been written.
2803 * Bit 5..0 - Drive number (0=A:,...)
2805 * FIXME: Should check if file is on remote or removable drive.
2806 * FIXME: Should use drive file is located on (and not current).
2808 SET_DX( context
, 0x0140 + INT21_GetCurrentDrive() );
2812 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2813 TRACE( "IOCTL - CHECK IF HANDLE IS REMOTE - %d\n", BX_reg(context
) );
2815 * Returns attribute word in DX:
2816 * Bit 15 - Set if remote.
2817 * Bit 14 - Set if date/time not set on close.
2819 * FIXME: Should check if file is on remote drive.
2821 SET_DX( context
, 0 );
2824 case 0x01: /* SET DEVICE INFORMATION */
2825 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2826 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2827 case 0x06: /* GET INPUT STATUS */
2828 case 0x07: /* GET OUTPUT STATUS */
2829 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2830 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2832 INT_BARF( context
, 0x21 );
2838 /***********************************************************************
2841 * Handler for function 0x44.
2843 static void INT21_Ioctl( CONTEXT86
*context
)
2845 switch (AL_reg(context
))
2851 INT21_Ioctl_Char( context
);
2856 INT21_Ioctl_Block( context
);
2861 INT21_Ioctl_Char( context
);
2866 INT21_Ioctl_Block( context
);
2870 INT21_Ioctl_Char( context
);
2873 case 0x0b: /* SET SHARING RETRY COUNT */
2874 TRACE( "SET SHARING RETRY COUNT: Pause %d, retries %d.\n",
2875 CX_reg(context
), DX_reg(context
) );
2876 if (!CX_reg(context
))
2878 SET_AX( context
, 1 );
2879 SET_CFLAG( context
);
2883 DOSDEV_SetSharingRetry( CX_reg(context
), DX_reg(context
) );
2884 RESET_CFLAG( context
);
2889 INT21_Ioctl_Char( context
);
2895 INT21_Ioctl_Block( context
);
2899 INT21_Ioctl_Char( context
);
2903 INT21_Ioctl_Block( context
);
2906 case 0x12: /* DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION) */
2907 TRACE( "DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION)\n" );
2908 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2909 SET_AX( context
, 0x0001 ); /* Invalid function */
2912 case 0x52: /* DR DOS - DETERMINE DOS TYPE */
2913 TRACE( "DR DOS - DETERMINE DOS TYPE\n" );
2914 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2915 SET_AX( context
, 0x0001 ); /* Invalid function */
2918 case 0xe0: /* Sun PC-NFS API */
2919 TRACE( "Sun PC-NFS API\n" );
2924 INT_BARF( context
, 0x21 );
2929 /***********************************************************************
2932 * Handler for function 0x73.
2934 static BOOL
INT21_Fat32( CONTEXT86
*context
)
2936 switch (AL_reg(context
))
2938 case 0x02: /* FAT32 - GET EXTENDED DPB */
2940 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
2941 WORD
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
2942 context
->SegEs
, context
->Edi
);
2943 INT21_DPB
*target
= (INT21_DPB
*)(ptr
+ 1);
2946 TRACE( "FAT32 - GET EXTENDED DPB %d\n", DL_reg(context
) );
2948 if ( CX_reg(context
) < sizeof(INT21_DPB
) + 2 || *ptr
< sizeof(INT21_DPB
) )
2950 SetLastError( ERROR_BAD_LENGTH
);
2954 if ( !INT21_FillDrivePB( drive
) )
2956 SetLastError( ERROR_INVALID_DRIVE
);
2960 source
= &INT21_GetHeapPointer()->misc_dpb_list
[drive
];
2962 *ptr
= sizeof(INT21_DPB
);
2963 memcpy( target
, source
, sizeof(INT21_DPB
));
2965 if (LOWORD(context
->Esi
) != 0xF1A6)
2967 target
->driver_header
= 0;
2972 FIXME( "Caller requested driver and next DPB pointers!\n" );
2977 case 0x03: /* FAT32 - GET EXTENDED FREE SPACE ON DRIVE */
2979 WCHAR dirW
[MAX_PATH
];
2980 char *dirA
= CTX_SEG_OFF_TO_LIN( context
,
2981 context
->SegDs
, context
->Edx
);
2982 BYTE
*data
= CTX_SEG_OFF_TO_LIN( context
,
2983 context
->SegEs
, context
->Edi
);
2984 DWORD cluster_sectors
;
2986 DWORD free_clusters
;
2987 DWORD total_clusters
;
2989 TRACE( "FAT32 - GET EXTENDED FREE SPACE ON DRIVE %s\n", dirA
);
2990 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
2992 if (CX_reg(context
) < 44)
2994 SetLastError( ERROR_BAD_LENGTH
);
2998 if (!GetDiskFreeSpaceW( dirW
, &cluster_sectors
, §or_bytes
,
2999 &free_clusters
, &total_clusters
))
3002 *(WORD
*) (data
+ 0) = 44; /* size of structure */
3003 *(WORD
*) (data
+ 2) = 0; /* version */
3004 *(DWORD
*)(data
+ 4) = cluster_sectors
;
3005 *(DWORD
*)(data
+ 8) = sector_bytes
;
3006 *(DWORD
*)(data
+ 12) = free_clusters
;
3007 *(DWORD
*)(data
+ 16) = total_clusters
;
3010 * Below we have free/total sectors and
3011 * free/total allocation units without adjustment
3012 * for compression. We fake both using cluster information.
3014 *(DWORD
*)(data
+ 20) = free_clusters
* cluster_sectors
;
3015 *(DWORD
*)(data
+ 24) = total_clusters
* cluster_sectors
;
3016 *(DWORD
*)(data
+ 28) = free_clusters
;
3017 *(DWORD
*)(data
+ 32) = total_clusters
;
3020 * Between (data + 36) and (data + 43) there
3021 * are eight reserved bytes.
3027 INT_BARF( context
, 0x21 );
3033 static void INT21_ConvertFindDataWtoA(WIN32_FIND_DATAA
*dataA
,
3034 const WIN32_FIND_DATAW
*dataW
)
3036 dataA
->dwFileAttributes
= dataW
->dwFileAttributes
;
3037 dataA
->ftCreationTime
= dataW
->ftCreationTime
;
3038 dataA
->ftLastAccessTime
= dataW
->ftLastAccessTime
;
3039 dataA
->ftLastWriteTime
= dataW
->ftLastWriteTime
;
3040 dataA
->nFileSizeHigh
= dataW
->nFileSizeHigh
;
3041 dataA
->nFileSizeLow
= dataW
->nFileSizeLow
;
3042 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cFileName
, -1,
3043 dataA
->cFileName
, sizeof(dataA
->cFileName
), NULL
, NULL
);
3044 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cAlternateFileName
, -1,
3045 dataA
->cAlternateFileName
, sizeof(dataA
->cAlternateFileName
), NULL
, NULL
);
3048 /***********************************************************************
3049 * INT21_LongFilename
3051 * Handler for function 0x71.
3053 static void INT21_LongFilename( CONTEXT86
*context
)
3055 BOOL bSetDOSExtendedError
= FALSE
;
3056 WCHAR pathW
[MAX_PATH
];
3059 if (HIBYTE(HIWORD(GetVersion16())) < 0x07)
3061 TRACE( "LONG FILENAME - functions supported only under DOS7\n" );
3062 SET_CFLAG( context
);
3063 SET_AL( context
, 0 );
3067 switch (AL_reg(context
))
3069 case 0x0d: /* RESET DRIVE */
3070 INT_BARF( context
, 0x21 );
3073 case 0x39: /* LONG FILENAME - MAKE DIRECTORY */
3074 if (!INT21_CreateDirectory( context
))
3075 bSetDOSExtendedError
= TRUE
;
3078 case 0x3a: /* LONG FILENAME - REMOVE DIRECTORY */
3079 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3081 TRACE( "LONG FILENAME - REMOVE DIRECTORY %s\n", pathA
);
3082 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3083 if (!RemoveDirectoryW( pathW
)) bSetDOSExtendedError
= TRUE
;
3086 case 0x3b: /* LONG FILENAME - CHANGE DIRECTORY */
3087 if (!INT21_SetCurrentDirectory( context
))
3088 bSetDOSExtendedError
= TRUE
;
3091 case 0x41: /* LONG FILENAME - DELETE FILE */
3092 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3094 TRACE( "LONG FILENAME - DELETE FILE %s\n", pathA
);
3095 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3097 if (!DeleteFileW( pathW
)) bSetDOSExtendedError
= TRUE
;
3100 case 0x43: /* LONG FILENAME - EXTENDED GET/SET FILE ATTRIBUTES */
3101 if (!INT21_FileAttributes( context
, BL_reg(context
), TRUE
))
3102 bSetDOSExtendedError
= TRUE
;
3105 case 0x47: /* LONG FILENAME - GET CURRENT DIRECTORY */
3106 if (!INT21_GetCurrentDirectory( context
, TRUE
))
3107 bSetDOSExtendedError
= TRUE
;
3110 case 0x4e: /* LONG FILENAME - FIND FIRST MATCHING FILE */
3114 WIN32_FIND_DATAW dataW
;
3115 WIN32_FIND_DATAA
* dataA
;
3117 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
3118 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n", pathA
);
3120 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3121 handle
= FindFirstFileW(pathW
, &dataW
);
3123 dataA
= (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
3125 if (handle
!= INVALID_HANDLE_VALUE
&&
3126 (h16
= GlobalAlloc16(GMEM_MOVEABLE
, sizeof(handle
))))
3128 HANDLE
* ptr
= GlobalLock16( h16
);
3130 GlobalUnlock16( h16
);
3131 SET_AX( context
, h16
);
3132 INT21_ConvertFindDataWtoA(dataA
, &dataW
);
3136 if (handle
!= INVALID_HANDLE_VALUE
) FindClose(handle
);
3137 SET_AX( context
, INVALID_HANDLE_VALUE16
);
3138 bSetDOSExtendedError
= TRUE
;
3143 case 0x4f: /* LONG FILENAME - FIND NEXT MATCHING FILE */
3145 HGLOBAL16 h16
= BX_reg(context
);
3147 WIN32_FIND_DATAW dataW
;
3148 WIN32_FIND_DATAA
* dataA
;
3150 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
3153 dataA
= (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
3156 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
3158 if (!FindNextFileW(*ptr
, &dataW
)) bSetDOSExtendedError
= TRUE
;
3159 else INT21_ConvertFindDataWtoA(dataA
, &dataW
);
3160 GlobalUnlock16( h16
);
3164 SetLastError( ERROR_INVALID_HANDLE
);
3165 bSetDOSExtendedError
= TRUE
;
3170 case 0x56: /* LONG FILENAME - RENAME FILE */
3171 if (!INT21_RenameFile(context
))
3172 bSetDOSExtendedError
= TRUE
;
3175 case 0x60: /* LONG FILENAME - CONVERT PATH */
3177 WCHAR res
[MAX_PATH
];
3179 switch (CL_reg(context
))
3181 case 0x00: /* "truename" - Canonicalize path */
3183 * FIXME: This is not 100% equal to 0x01 case,
3184 * if you fix this, fix int21 subfunction 0x60, too.
3187 case 0x01: /* Get short filename or path */
3188 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
3189 if (!GetShortPathNameW(pathW
, res
, 67))
3190 bSetDOSExtendedError
= TRUE
;
3193 SET_AX( context
, 0 );
3194 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
3195 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3200 case 0x02: /* Get canonical long filename or path */
3201 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
3202 if (!GetFullPathNameW(pathW
, 128, res
, NULL
))
3203 bSetDOSExtendedError
= TRUE
;
3206 SET_AX( context
, 0 );
3207 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
3208 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3213 FIXME("Unimplemented long file name function:\n");
3214 INT_BARF( context
, 0x21 );
3216 SET_AL( context
, 0 );
3222 case 0x6c: /* LONG FILENAME - CREATE OR OPEN FILE */
3223 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
3224 BX_reg(context
), DL_reg(context
) ))
3225 bSetDOSExtendedError
= TRUE
;
3228 case 0xa0: /* LONG FILENAME - GET VOLUME INFORMATION */
3230 DWORD filename_len
, flags
;
3233 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
3235 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", pathA
);
3236 SET_AX( context
, 0 );
3237 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3238 if (!GetVolumeInformationW( pathW
, NULL
, 0, NULL
, &filename_len
,
3241 INT_BARF( context
, 0x21 );
3245 SET_BX( context
, flags
| 0x4000 ); /* support for LFN functions */
3246 SET_CX( context
, filename_len
);
3247 SET_DX( context
, MAX_PATH
); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
3248 WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1,
3249 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3254 case 0xa1: /* LONG FILENAME - "FindClose" - TERMINATE DIRECTORY SEARCH */
3256 HGLOBAL16 h16
= BX_reg(context
);
3259 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
3261 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
3263 if (!FindClose( *ptr
)) bSetDOSExtendedError
= TRUE
;
3264 GlobalUnlock16( h16
);
3265 GlobalFree16( h16
);
3269 SetLastError( ERROR_INVALID_HANDLE
);
3270 bSetDOSExtendedError
= TRUE
;
3275 case 0xa6: /* LONG FILENAME - GET FILE INFO BY HANDLE */
3277 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
3278 BY_HANDLE_FILE_INFORMATION
*info
=
3279 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3281 TRACE( "LONG FILENAME - GET FILE INFO BY HANDLE\n" );
3283 if (!GetFileInformationByHandle(handle
, info
))
3284 bSetDOSExtendedError
= TRUE
;
3288 case 0xa7: /* LONG FILENAME - CONVERT TIME */
3289 switch (BL_reg(context
))
3291 case 0x00: /* FILE TIME TO DOS TIME */
3294 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3298 TRACE( "LONG FILENAME - FILE TIME TO DOS TIME\n" );
3300 FileTimeToDosDateTime( filetime
, &date
, &time
);
3302 SET_DX( context
, date
);
3303 SET_CX( context
, time
);
3306 * FIXME: BH has number of 10-millisecond units
3309 SET_BH( context
, 0 );
3313 case 0x01: /* DOS TIME TO FILE TIME */
3315 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3319 TRACE( "LONG FILENAME - DOS TIME TO FILE TIME\n" );
3322 * FIXME: BH has number of 10-millisecond units
3325 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
3331 INT_BARF( context
, 0x21 );
3336 case 0xa8: /* LONG FILENAME - GENERATE SHORT FILENAME */
3337 case 0xa9: /* LONG FILENAME - SERVER CREATE OR OPEN FILE */
3338 case 0xaa: /* LONG FILENAME - SUBST */
3340 FIXME("Unimplemented long file name function:\n");
3341 INT_BARF( context
, 0x21 );
3343 SET_AL( context
, 0 );
3347 if (bSetDOSExtendedError
)
3349 SET_AX( context
, GetLastError() );
3350 SET_CFLAG( context
);
3355 /***********************************************************************
3360 * - subfunction 0x56 of function 0x71
3361 * - subfunction 0xff of function 0x43 (CL == 0x56)
3363 static BOOL
INT21_RenameFile( CONTEXT86
*context
)
3365 WCHAR fromW
[MAX_PATH
];
3366 WCHAR toW
[MAX_PATH
];
3367 char *fromA
= CTX_SEG_OFF_TO_LIN(context
,
3368 context
->SegDs
,context
->Edx
);
3369 char *toA
= CTX_SEG_OFF_TO_LIN(context
,
3370 context
->SegEs
,context
->Edi
);
3372 TRACE( "RENAME FILE %s to %s\n", fromA
, toA
);
3373 MultiByteToWideChar(CP_OEMCP
, 0, fromA
, -1, fromW
, MAX_PATH
);
3374 MultiByteToWideChar(CP_OEMCP
, 0, toA
, -1, toW
, MAX_PATH
);
3376 return MoveFileW( fromW
, toW
);
3380 /***********************************************************************
3386 static BOOL
INT21_NetworkFunc (CONTEXT86
*context
)
3388 switch (AL_reg(context
))
3390 case 0x00: /* Get machine name. */
3392 WCHAR dstW
[MAX_COMPUTERNAME_LENGTH
+ 1];
3393 DWORD s
= sizeof(dstW
) / sizeof(WCHAR
);
3396 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
3397 TRACE("getting machine name to %p\n", dst
);
3398 if (!GetComputerNameW(dstW
, &s
) ||
3399 !WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1, dst
, 16, NULL
, NULL
))
3402 SetLastError( ER_NoNetwork
);
3405 for (len
= strlen(dst
); len
< 15; len
++) dst
[len
] = ' ';
3407 SET_CH( context
, 1 ); /* Valid */
3408 SET_CL( context
, 1 ); /* NETbios number??? */
3409 TRACE("returning %s\n", debugstr_an(dst
, 16));
3414 SetLastError( ER_NoNetwork
);
3419 /******************************************************************
3420 * INT21_GetDiskSerialNumber
3423 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
3425 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3426 WCHAR path
[] = {'A',':',0}, label
[11];
3429 path
[0] += INT21_MapDrive(BL_reg(context
));
3430 if (!GetVolumeInformationW( path
, label
, 11, &serial
, NULL
, NULL
, NULL
, 0))
3432 SetLastError( ERROR_INVALID_DRIVE
);
3436 *(WORD
*)dataptr
= 0;
3437 memcpy(dataptr
+ 2, &serial
, sizeof(DWORD
));
3438 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, dataptr
+ 6, 11, NULL
, NULL
);
3439 memcpy(dataptr
+ 17, "FAT16 ", 8);
3444 /******************************************************************
3445 * INT21_SetDiskSerialNumber
3448 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
3451 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3452 int drive
= INT21_MapDrive(BL_reg(context
));
3454 if (!is_valid_drive(drive
))
3456 SetLastError( ERROR_INVALID_DRIVE
);
3460 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
3463 FIXME("Setting drive serial number is no longer supported\n");
3464 SetLastError( ERROR_NOT_SUPPORTED
);
3470 /******************************************************************
3471 * INT21_GetFreeDiskSpace
3474 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
3476 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
3477 WCHAR root
[] = {'A',':','\\',0};
3479 root
[0] += INT21_MapDrive(DL_reg(context
));
3480 if (!GetDiskFreeSpaceW( root
, &cluster_sectors
, §or_bytes
,
3481 &free_clusters
, &total_clusters
)) return 0;
3482 /* make sure that the number of clusters fits in a 16 bits value */
3483 while( total_clusters
& 0xffff0000) {
3484 cluster_sectors
<<= 1;
3485 free_clusters
>>= 1;
3486 total_clusters
>>= 1;
3488 SET_AX( context
, cluster_sectors
);
3489 SET_BX( context
, free_clusters
);
3490 SET_CX( context
, sector_bytes
);
3491 SET_DX( context
, total_clusters
);
3495 /******************************************************************
3496 * INT21_GetDriveAllocInfo
3499 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
, BYTE drive
)
3503 drive
= INT21_MapDrive( drive
);
3504 if (!INT21_FillDrivePB( drive
)) return 0;
3505 dpb
= &(INT21_GetHeapPointer()->misc_dpb_list
[drive
]);
3506 SET_AL( context
, dpb
->cluster_sectors
+ 1 );
3507 SET_CX( context
, dpb
->sector_bytes
);
3508 SET_DX( context
, dpb
->num_clusters1
);
3510 context
->SegDs
= INT21_GetHeapSelector( context
);
3511 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
].media_ID
) );
3515 /***********************************************************************
3516 * INT21_GetExtendedError
3518 static void INT21_GetExtendedError( CONTEXT86
*context
)
3520 BYTE
class, action
, locus
;
3521 WORD error
= GetLastError();
3526 class = action
= locus
= 0;
3528 case ERROR_DIR_NOT_EMPTY
:
3533 case ERROR_ACCESS_DENIED
:
3534 class = EC_AccessDenied
;
3538 case ERROR_CANNOT_MAKE
:
3539 class = EC_AccessDenied
;
3543 case ERROR_DISK_FULL
:
3544 case ERROR_HANDLE_DISK_FULL
:
3545 class = EC_MediaError
;
3549 case ERROR_FILE_EXISTS
:
3550 case ERROR_ALREADY_EXISTS
:
3555 case ERROR_FILE_NOT_FOUND
:
3556 class = EC_NotFound
;
3560 case ERROR_GEN_FAILURE
:
3561 class = EC_SystemFailure
;
3565 case ERROR_INVALID_DRIVE
:
3566 class = EC_MediaError
;
3570 case ERROR_INVALID_HANDLE
:
3571 class = EC_ProgramError
;
3575 case ERROR_LOCK_VIOLATION
:
3576 class = EC_AccessDenied
;
3580 case ERROR_NO_MORE_FILES
:
3581 class = EC_MediaError
;
3586 class = EC_NotFound
;
3590 case ERROR_NOT_ENOUGH_MEMORY
:
3591 class = EC_OutOfResource
;
3595 case ERROR_PATH_NOT_FOUND
:
3596 class = EC_NotFound
;
3601 class = EC_NotFound
;
3605 case ERROR_SHARING_VIOLATION
:
3606 class = EC_Temporary
;
3610 case ERROR_TOO_MANY_OPEN_FILES
:
3611 class = EC_ProgramError
;
3616 FIXME("Unknown error %d\n", error
);
3617 class = EC_SystemFailure
;
3622 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
3623 error
, class, action
, locus
);
3624 SET_AX( context
, error
);
3625 SET_BH( context
, class );
3626 SET_BL( context
, action
);
3627 SET_CH( context
, locus
);
3630 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
3632 static int counter
= 0;
3633 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3634 char *p
= name
+ strlen(name
);
3636 /* despite what Ralf Brown says, some programs seem to call without
3637 * ending backslash (DOS accepts that, so we accept it too) */
3638 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
3642 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
3643 counter
= (counter
+ 1) % 1000;
3646 Win32HandleToDosFileHandle(
3647 CreateFileA( name
, GENERIC_READ
| GENERIC_WRITE
,
3648 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
3649 CREATE_NEW
, 0, 0 ) ) );
3650 if (AX_reg(context
) != HFILE_ERROR16
)
3652 TRACE("created %s\n", name
);
3655 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
3659 /***********************************************************************
3660 * DOSFS_ToDosFCBFormat
3662 * Convert a file name to DOS FCB format (8+3 chars, padded with blanks),
3663 * expanding wild cards and converting to upper-case in the process.
3664 * File name can be terminated by '\0', '\\' or '/'.
3665 * Return FALSE if the name is not a valid DOS name.
3666 * 'buffer' must be at least 12 characters long.
3668 /* Chars we don't want to see in DOS file names */
3669 static BOOL
INT21_ToDosFCBFormat( LPCWSTR name
, LPWSTR buffer
)
3671 static const WCHAR invalid_chars
[] = {'*','?','<','>','|','\\','"','+','=',',',';','[',']',' ','\345',0};
3675 /* Check for "." and ".." */
3680 for(i
= 1; i
< 11; i
++) buffer
[i
] = ' ';
3687 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3690 for (i
= 0; i
< 8; i
++)
3707 if (strchrW( invalid_chars
, *p
)) return FALSE
;
3708 buffer
[i
] = toupperW(*p
);
3716 /* Skip all chars after wildcard up to first dot */
3717 while (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) p
++;
3721 /* Check if name too long */
3722 if (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) return FALSE
;
3724 if (*p
== '.') p
++; /* Skip dot */
3726 for (i
= 8; i
< 11; i
++)
3736 return FALSE
; /* Second extension not allowed */
3744 if (strchrW( invalid_chars
, *p
)) return FALSE
;
3745 buffer
[i
] = toupperW(*p
);
3752 /* at most 3 character of the extension are processed
3753 * is something behind this ?
3755 while (*p
== '*' || *p
== ' ') p
++; /* skip wildcards and spaces */
3756 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3759 static HANDLE INT21_FindHandle
;
3760 static const WCHAR
*INT21_FindPath
; /* will point to current dta->fullPath search */
3762 /******************************************************************
3765 static int INT21_FindFirst( CONTEXT86
*context
)
3769 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3770 WCHAR maskW
[12], pathW
[MAX_PATH
];
3771 static const WCHAR wildcardW
[] = {'*','.','*',0};
3773 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3774 MultiByteToWideChar(CP_OEMCP
, 0, path
, -1, pathW
, MAX_PATH
);
3776 p
= strrchrW( pathW
, '\\');
3777 q
= strrchrW( pathW
, '/');
3781 if (pathW
[0] && pathW
[1] == ':') p
= pathW
+ 2;
3786 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
3787 * (doesn't matter as it is set below anyway)
3789 if (!INT21_ToDosFCBFormat( p
, maskW
))
3791 SetLastError( ERROR_FILE_NOT_FOUND
);
3792 SET_AX( context
, ERROR_FILE_NOT_FOUND
);
3796 WideCharToMultiByte(CP_OEMCP
, 0, maskW
, 12, dta
->mask
, sizeof(dta
->mask
), NULL
, NULL
);
3798 dta
->fullPath
= HeapAlloc( GetProcessHeap(), 0, sizeof(wildcardW
) + (p
- pathW
)*sizeof(WCHAR
) );
3799 memcpy( dta
->fullPath
, pathW
, (p
- pathW
) * sizeof(WCHAR
) );
3800 memcpy( dta
->fullPath
+ (p
- pathW
), wildcardW
, sizeof(wildcardW
) );
3801 /* we must have a fully qualified file name in dta->fullPath
3802 * (we could have a UNC path, but this would lead to some errors later on)
3804 dta
->drive
= toupperW(dta
->fullPath
[0]) - 'A';
3806 dta
->search_attr
= CL_reg(context
);
3810 /******************************************************************
3813 * Check is a short path name (DTA unicode) matches a mask (FCB ansi)
3815 static BOOL
match_short(LPCWSTR shortW
, LPCSTR maskA
)
3817 WCHAR mask
[11], file
[12];
3820 if (!INT21_ToDosFCBFormat( shortW
, file
)) return FALSE
;
3821 MultiByteToWideChar(CP_OEMCP
, 0, maskA
, 11, mask
, 11);
3822 for (i
= 0; i
< 11; i
++)
3823 if (mask
[i
] != '?' && mask
[i
] != file
[i
]) return FALSE
;
3827 static unsigned INT21_FindHelper(LPCWSTR fullPath
, unsigned drive
, unsigned count
,
3828 LPCSTR mask
, unsigned search_attr
,
3829 WIN32_FIND_DATAW
* entry
)
3833 if ((search_attr
& ~(FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
)) == FA_LABEL
)
3835 WCHAR path
[] = {' ',':',0};
3837 if (count
) return 0;
3838 path
[0] = drive
+ 'A';
3839 if (!GetVolumeInformationW(path
, entry
->cAlternateFileName
, 13, NULL
, NULL
, NULL
, NULL
, 0)) return 0;
3840 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftCreationTime
);
3841 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftLastAccessTime
);
3842 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftLastWriteTime
);
3843 entry
->dwFileAttributes
= FA_LABEL
;
3844 entry
->nFileSizeHigh
= entry
->nFileSizeLow
= 0;
3845 TRACE("returning %s as label\n", debugstr_w(entry
->cAlternateFileName
));
3849 if (!INT21_FindHandle
|| INT21_FindPath
!= fullPath
|| count
== 0)
3851 if (INT21_FindHandle
) FindClose(INT21_FindHandle
);
3852 INT21_FindHandle
= FindFirstFileW(fullPath
, entry
);
3853 if (INT21_FindHandle
== INVALID_HANDLE_VALUE
)
3855 INT21_FindHandle
= 0;
3858 INT21_FindPath
= fullPath
;
3859 /* we need to resync search */
3864 while (ncalls
-- != 0)
3866 if (!FindNextFileW(INT21_FindHandle
, entry
))
3868 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3872 while (count
< 0xffff)
3875 /* Check the file attributes, and path */
3876 if (!(entry
->dwFileAttributes
& ~search_attr
) &&
3877 match_short(entry
->cAlternateFileName
[0] ? entry
->cAlternateFileName
: entry
->cFileName
,
3882 if (!FindNextFileW(INT21_FindHandle
, entry
))
3884 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3888 WARN("Too many directory entries in %s\n", debugstr_w(fullPath
) );
3892 /******************************************************************
3895 static int INT21_FindNext( CONTEXT86
*context
)
3897 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3898 DWORD attr
= dta
->search_attr
| FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
;
3899 WIN32_FIND_DATAW entry
;
3902 if (!dta
->fullPath
) return 0;
3904 n
= INT21_FindHelper(dta
->fullPath
, dta
->drive
, dta
->count
,
3905 dta
->mask
, attr
, &entry
);
3908 dta
->fileattr
= entry
.dwFileAttributes
;
3909 dta
->filesize
= entry
.nFileSizeLow
;
3910 FileTimeToDosDateTime( &entry
.ftLastWriteTime
, &dta
->filedate
, &dta
->filetime
);
3911 if (entry
.cAlternateFileName
[0])
3912 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cAlternateFileName
, -1,
3913 dta
->filename
, 13, NULL
, NULL
);
3915 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cFileName
, -1, dta
->filename
, 13, NULL
, NULL
);
3917 if (!memchr(dta
->mask
,'?',11))
3919 /* wildcardless search, release resources in case no findnext will
3920 * be issued, and as a workaround in case file creation messes up
3921 * findnext, as sometimes happens with pkunzip
3923 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3924 INT21_FindPath
= dta
->fullPath
= NULL
;
3929 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3930 INT21_FindPath
= dta
->fullPath
= NULL
;
3934 /* microsoft's programmers should be shot for using CP/M style int21
3935 calls in Windows for Workgroup's winfile.exe */
3937 /******************************************************************
3938 * INT21_FindFirstFCB
3941 static int INT21_FindFirstFCB( CONTEXT86
*context
)
3943 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3946 WCHAR p
[] = {' ',':',};
3948 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3949 else pFCB
= (FINDFILE_FCB
*)fcb
;
3950 drive
= INT21_MapDrive( pFCB
->drive
);
3951 if (drive
== MAX_DOS_DRIVES
) return 0;
3954 pFCB
->fullPath
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
3955 if (!pFCB
->fullPath
) return 0;
3956 GetLongPathNameW(p
, pFCB
->fullPath
, MAX_PATH
);
3961 /******************************************************************
3965 static int INT21_FindNextFCB( CONTEXT86
*context
)
3967 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3969 LPBYTE pResult
= INT21_GetCurrentDTA(context
);
3970 DOS_DIRENTRY_LAYOUT
*ddl
;
3971 WIN32_FIND_DATAW entry
;
3976 if (*fcb
== 0xff) /* extended FCB ? */
3979 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3984 pFCB
= (FINDFILE_FCB
*)fcb
;
3987 if (!pFCB
->fullPath
) return 0;
3988 n
= INT21_FindHelper(pFCB
->fullPath
, INT21_MapDrive( pFCB
->drive
),
3989 pFCB
->count
, pFCB
->filename
, attr
, &entry
);
3992 HeapFree( GetProcessHeap(), 0, pFCB
->fullPath
);
3993 INT21_FindPath
= pFCB
->fullPath
= NULL
;
4000 /* place extended FCB header before pResult if called with extended FCB */
4002 pResult
+= 6; /* leave reserved field behind */
4003 *pResult
++ = entry
.dwFileAttributes
;
4005 *pResult
++ = INT21_MapDrive( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
4006 ddl
= (DOS_DIRENTRY_LAYOUT
*)pResult
;
4007 ddl
->fileattr
= entry
.dwFileAttributes
;
4008 ddl
->cluster
= 0; /* what else? */
4009 ddl
->filesize
= entry
.nFileSizeLow
;
4010 memset( ddl
->reserved
, 0, sizeof(ddl
->reserved
) );
4011 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
4012 &ddl
->filedate
, &ddl
->filetime
);
4014 /* Convert file name to FCB format */
4015 if (entry
.cAlternateFileName
[0])
4016 INT21_ToDosFCBFormat( entry
.cAlternateFileName
, nameW
);
4018 INT21_ToDosFCBFormat( entry
.cFileName
, nameW
);
4019 WideCharToMultiByte(CP_OEMCP
, 0, nameW
, 11, ddl
->filename
, 11, NULL
, NULL
);
4024 /******************************************************************
4025 * INT21_ParseFileNameIntoFCB
4028 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
4031 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
4033 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
4037 INT buffer_len
, len
;
4039 SET_AL( context
, 0xff ); /* failed */
4041 TRACE("filename: '%s'\n", filename
);
4044 while (*s
&& (*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
4048 buffer_len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, NULL
, 0);
4049 buffer
= HeapAlloc( GetProcessHeap(), 0, (buffer_len
+ 1) * sizeof(WCHAR
));
4050 len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, buffer
, buffer_len
);
4052 INT21_ToDosFCBFormat(buffer
, fcbW
);
4053 HeapFree(GetProcessHeap(), 0, buffer
);
4054 WideCharToMultiByte(CP_OEMCP
, 0, fcbW
, 12, fcb
+ 1, 12, NULL
, NULL
);
4056 TRACE("FCB: '%s'\n", fcb
+ 1);
4058 SET_AL( context
, ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0 );
4060 /* point DS:SI to first unparsed character */
4061 SET_SI( context
, context
->Esi
+ (int)s
- (int)filename
);
4064 static BOOL
INT21_Dup2(HFILE16 hFile1
, HFILE16 hFile2
)
4066 HFILE16 res
= HFILE_ERROR16
;
4067 HANDLE handle
, new_handle
;
4068 #define DOS_TABLE_SIZE 256
4069 DWORD map
[DOS_TABLE_SIZE
/ 32];
4072 handle
= DosFileHandleToWin32Handle(hFile1
);
4073 if (handle
== INVALID_HANDLE_VALUE
)
4077 /* now loop to allocate the same one... */
4078 memset(map
, 0, sizeof(map
));
4079 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++)
4081 if (!DuplicateHandle(GetCurrentProcess(), handle
,
4082 GetCurrentProcess(), &new_handle
,
4083 0, FALSE
, DUPLICATE_SAME_ACCESS
))
4085 res
= HFILE_ERROR16
;
4088 res
= Win32HandleToDosFileHandle(new_handle
);
4089 if (res
== HFILE_ERROR16
|| res
== hFile2
) break;
4090 map
[res
/ 32] |= 1 << (res
% 32);
4092 /* clean up the allocated slots */
4093 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++)
4095 if (map
[i
/ 32] & (1 << (i
% 32)))
4096 _lclose16((HFILE16
)i
);
4098 return res
== hFile2
;
4102 /***********************************************************************
4103 * DOSVM_Int21Handler
4105 * Interrupt 0x21 handler.
4107 void WINAPI
DOSVM_Int21Handler( CONTEXT86
*context
)
4109 BOOL bSetDOSExtendedError
= FALSE
;
4111 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
4112 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
4113 AX_reg(context
), BX_reg(context
),
4114 CX_reg(context
), DX_reg(context
),
4115 SI_reg(context
), DI_reg(context
),
4116 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
4120 * Extended error is used by (at least) functions 0x2f to 0x62.
4121 * Function 0x59 returns extended error and error should not
4122 * be cleared before handling the function.
4124 if (AH_reg(context
) >= 0x2f && AH_reg(context
) != 0x59)
4127 RESET_CFLAG(context
); /* Not sure if this is a good idea. */
4129 switch(AH_reg(context
))
4131 case 0x00: /* TERMINATE PROGRAM */
4132 TRACE("TERMINATE PROGRAM\n");
4133 if (DOSVM_IsWin16())
4135 else if(ISV86(context
))
4136 MZ_Exit( context
, FALSE
, 0 );
4138 ERR( "Called from DOS protected mode\n" );
4141 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
4144 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
4145 INT21_ReadChar( &ascii
, context
);
4146 SET_AL( context
, ascii
);
4148 * FIXME: What to echo when extended keycodes are read?
4150 DOSVM_PutChar(AL_reg(context
));
4154 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
4155 TRACE("Write Character to Standard Output\n");
4156 DOSVM_PutChar(DL_reg(context
));
4159 case 0x03: /* READ CHARACTER FROM STDAUX */
4160 case 0x04: /* WRITE CHARACTER TO STDAUX */
4161 case 0x05: /* WRITE CHARACTER TO PRINTER */
4162 INT_BARF( context
, 0x21 );
4165 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
4166 if (DL_reg(context
) == 0xff)
4168 TRACE("Direct Console Input\n");
4170 if (INT21_ReadChar( NULL
, NULL
))
4173 INT21_ReadChar( &ascii
, context
);
4174 SET_AL( context
, ascii
);
4175 RESET_ZFLAG( context
);
4179 /* no character available */
4180 SET_AL( context
, 0 );
4181 SET_ZFLAG( context
);
4186 TRACE("Direct Console Output\n");
4187 DOSVM_PutChar(DL_reg(context
));
4189 * At least DOS versions 2.1-7.0 return character
4190 * that was written in AL register.
4192 SET_AL( context
, DL_reg(context
) );
4196 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
4199 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
4200 INT21_ReadChar( &ascii
, context
);
4201 SET_AL( context
, ascii
);
4205 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
4208 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
4209 INT21_ReadChar( &ascii
, context
);
4210 SET_AL( context
, ascii
);
4214 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
4215 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
4216 context
->SegDs
, DX_reg(context
) );
4218 LPSTR data
= CTX_SEG_OFF_TO_LIN( context
,
4219 context
->SegDs
, context
->Edx
);
4223 * Do NOT use strchr() to calculate the string length,
4224 * as '\0' is valid string content, too!
4225 * Maybe we should check for non-'$' strings, but DOS doesn't.
4227 while (*p
!= '$') p
++;
4229 if (DOSVM_IsWin16())
4230 WriteFile( DosFileHandleToWin32Handle(1),
4231 data
, p
- data
, &w
, NULL
);
4233 for(; data
!= p
; data
++)
4234 DOSVM_PutChar( *data
);
4236 SET_AL( context
, '$' ); /* yes, '$' (0x24) gets returned in AL */
4240 case 0x0a: /* BUFFERED INPUT */
4242 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
4247 TRACE( "BUFFERED INPUT (size=%d)\n", ptr
[0] );
4250 * FIXME: Some documents state that
4251 * ptr[1] holds number of chars from last input which
4252 * may be recalled on entry, other documents do not mention
4256 TRACE( "Handle old chars in buffer!\n" );
4259 * ptr[0] - capacity (includes terminating CR)
4260 * ptr[1] - characters read (excludes terminating CR)
4262 result
= INT21_BufferedInput( context
, ptr
+ 2, ptr
[0] );
4264 ptr
[1] = (BYTE
)result
- 1;
4270 case 0x0b: /* GET STDIN STATUS */
4271 TRACE( "GET STDIN STATUS\n" );
4273 if (INT21_ReadChar( NULL
, NULL
))
4274 SET_AL( context
, 0xff ); /* character available */
4276 SET_AL( context
, 0 ); /* no character available */
4280 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
4282 BYTE al
= AL_reg(context
); /* Input function to execute after flush. */
4284 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al
);
4286 /* FIXME: buffers are not flushed */
4289 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
4290 * int21 function identified by AL will be called.
4292 if(al
== 0x01 || al
== 0x06 || al
== 0x07 || al
== 0x08 || al
== 0x0a)
4294 SET_AH( context
, al
);
4295 DOSVM_Int21Handler( context
);
4300 case 0x0d: /* DISK BUFFER FLUSH */
4301 TRACE("DISK BUFFER FLUSH ignored\n");
4304 case 0x0e: /* SELECT DEFAULT DRIVE */
4305 TRACE( "SELECT DEFAULT DRIVE - %c:\n", 'A' + DL_reg(context
) );
4306 INT21_SetCurrentDrive( DL_reg(context
) );
4307 SET_AL( context
, MAX_DOS_DRIVES
);
4310 case 0x0f: /* OPEN FILE USING FCB */
4311 INT21_OpenFileUsingFCB( context
);
4314 case 0x10: /* CLOSE FILE USING FCB */
4315 INT21_CloseFileUsingFCB( context
);
4318 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
4319 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
4320 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
4321 if (!INT21_FindFirstFCB(context
))
4323 SET_AL( context
, 0xff );
4326 /* else fall through */
4328 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
4329 SET_AL( context
, INT21_FindNextFCB(context
) ? 0x00 : 0xff );
4332 case 0x13: /* DELETE FILE USING FCB */
4333 INT_BARF( context
, 0x21 );
4336 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
4337 INT21_SequentialReadFromFCB( context
);
4340 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
4341 INT21_SequentialWriteToFCB( context
);
4344 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
4345 case 0x17: /* RENAME FILE USING FCB */
4346 INT_BARF( context
, 0x21 );
4349 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4350 SET_AL( context
, 0 );
4353 case 0x19: /* GET CURRENT DEFAULT DRIVE */
4354 SET_AL( context
, INT21_GetCurrentDrive() );
4355 TRACE( "GET CURRENT DRIVE -> %c:\n", 'A' + AL_reg( context
) );
4358 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
4359 TRACE( "SET DISK TRANSFER AREA ADDRESS %04lX:%04X\n",
4360 context
->SegDs
, DX_reg(context
) );
4362 TDB
*task
= GlobalLock16( GetCurrentTask() );
4363 task
->dta
= MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4367 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
4368 if (!INT21_GetDriveAllocInfo(context
, 0))
4369 SET_AX( context
, 0xffff );
4372 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
4373 if (!INT21_GetDriveAllocInfo(context
, DL_reg(context
)))
4374 SET_AX( context
, 0xffff );
4377 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4378 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4379 SET_AL( context
, 0 );
4382 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
4384 BYTE drive
= INT21_MapDrive( 0 );
4385 TRACE( "GET DPB FOR DEFAULT DRIVE\n" );
4387 if (INT21_FillDrivePB( drive
))
4389 SET_AL( context
, 0x00 ); /* success */
4390 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4391 context
->SegDs
= INT21_GetHeapSelector( context
);
4395 SET_AL( context
, 0xff ); /* invalid or network drive */
4400 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4401 SET_AL( context
, 0 );
4404 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
4405 INT21_ReadRandomRecordFromFCB( context
);
4408 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
4409 INT21_WriteRandomRecordToFCB( context
);
4412 case 0x23: /* GET FILE SIZE FOR FCB */
4413 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
4414 INT_BARF( context
, 0x21 );
4417 case 0x25: /* SET INTERRUPT VECTOR */
4418 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4420 FARPROC16 ptr
= (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4421 if (!ISV86(context
) && DOSVM_IsWin16())
4422 DOSVM_SetPMHandler16( AL_reg(context
), ptr
);
4424 DOSVM_SetRMHandler( AL_reg(context
), ptr
);
4428 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
4429 INT_BARF( context
, 0x21 );
4432 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
4433 INT21_RandomBlockReadFromFCB( context
);
4436 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
4437 INT21_RandomBlockWriteToFCB( context
);
4440 case 0x29: /* PARSE FILENAME INTO FCB */
4441 INT21_ParseFileNameIntoFCB(context
);
4444 case 0x2a: /* GET SYSTEM DATE */
4445 TRACE( "GET SYSTEM DATE\n" );
4448 GetLocalTime( &systime
);
4449 SET_CX( context
, systime
.wYear
);
4450 SET_DH( context
, systime
.wMonth
);
4451 SET_DL( context
, systime
.wDay
);
4452 SET_AL( context
, systime
.wDayOfWeek
);
4456 case 0x2b: /* SET SYSTEM DATE */
4457 TRACE( "SET SYSTEM DATE\n" );
4459 WORD year
= CX_reg(context
);
4460 BYTE month
= DH_reg(context
);
4461 BYTE day
= DL_reg(context
);
4463 if (year
>= 1980 && year
<= 2099 &&
4464 month
>= 1 && month
<= 12 &&
4465 day
>= 1 && day
<= 31)
4467 FIXME( "SetSystemDate(%02d/%02d/%04d): not allowed\n",
4469 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4473 SET_AL( context
, 0xff ); /* invalid date */
4474 TRACE( "SetSystemDate(%02d/%02d/%04d): invalid date\n",
4480 case 0x2c: /* GET SYSTEM TIME */
4481 TRACE( "GET SYSTEM TIME\n" );
4484 GetLocalTime( &systime
);
4485 SET_CH( context
, systime
.wHour
);
4486 SET_CL( context
, systime
.wMinute
);
4487 SET_DH( context
, systime
.wSecond
);
4488 SET_DL( context
, systime
.wMilliseconds
/ 10 );
4492 case 0x2d: /* SET SYSTEM TIME */
4493 if( CH_reg(context
) >= 24 || CL_reg(context
) >= 60 || DH_reg(context
) >= 60 || DL_reg(context
) >= 100 ) {
4494 TRACE("SetSystemTime(%02d:%02d:%02d.%02d): wrong time\n",
4495 CH_reg(context
), CL_reg(context
),
4496 DH_reg(context
), DL_reg(context
) );
4497 SET_AL( context
, 0xFF );
4501 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
4502 CH_reg(context
), CL_reg(context
),
4503 DH_reg(context
), DL_reg(context
) );
4504 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4508 case 0x2e: /* SET VERIFY FLAG */
4509 TRACE("SET VERIFY FLAG ignored\n");
4510 /* we cannot change the behaviour anyway, so just ignore it */
4513 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
4514 TRACE( "GET DISK TRANSFER AREA ADDRESS\n" );
4516 TDB
*task
= GlobalLock16( GetCurrentTask() );
4517 context
->SegEs
= SELECTOROF( task
->dta
);
4518 SET_BX( context
, OFFSETOF( task
->dta
) );
4522 case 0x30: /* GET DOS VERSION */
4523 TRACE( "GET DOS VERSION - %s requested\n",
4524 (AL_reg(context
) == 0x00) ? "OEM number" : "version flag" );
4526 if (AL_reg(context
) == 0x00)
4527 SET_BH( context
, 0xff ); /* OEM number => undefined */
4529 SET_BH( context
, 0x08 ); /* version flag => DOS is in ROM */
4531 SET_AL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
4532 SET_AH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
4534 SET_BL( context
, 0x12 ); /* 0x123456 is 24-bit Wine's serial # */
4535 SET_CX( context
, 0x3456 );
4538 case 0x31: /* TERMINATE AND STAY RESIDENT */
4539 FIXME("TERMINATE AND STAY RESIDENT stub\n");
4542 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
4544 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
4545 TRACE( "GET DPB FOR SPECIFIC DRIVE %d\n", DL_reg(context
) );
4547 if (INT21_FillDrivePB( drive
))
4549 SET_AL( context
, 0x00 ); /* success */
4550 SET_DX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4551 context
->SegDs
= INT21_GetHeapSelector( context
);
4555 SET_AL( context
, 0xff ); /* invalid or network drive */
4560 case 0x33: /* MULTIPLEXED */
4561 switch (AL_reg(context
))
4563 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
4564 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
4565 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4568 case 0x01: /* SET EXTENDED BREAK STATE */
4569 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
4570 DOSCONF_GetConfig()->brk_flag
= (DL_reg(context
) > 0) ? 1 : 0;
4573 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
4574 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
4575 /* ugly coding in order to stay reentrant */
4576 if (DL_reg(context
))
4578 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4579 DOSCONF_GetConfig()->brk_flag
= 1;
4583 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4584 DOSCONF_GetConfig()->brk_flag
= 0;
4588 case 0x05: /* GET BOOT DRIVE */
4589 TRACE("GET BOOT DRIVE\n");
4590 SET_DL( context
, 3 );
4591 /* c: is Wine's bootdrive (a: is 1)*/
4594 case 0x06: /* GET TRUE VERSION NUMBER */
4595 TRACE("GET TRUE VERSION NUMBER\n");
4596 SET_BL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major */
4597 SET_BH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor */
4598 SET_DL( context
, 0x00 ); /* revision */
4599 SET_DH( context
, 0x08 ); /* DOS is in ROM */
4603 INT_BARF( context
, 0x21 );
4608 case 0x34: /* GET ADDRESS OF INDOS FLAG */
4609 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
4610 context
->SegEs
= INT21_GetHeapSelector( context
);
4611 SET_BX( context
, offsetof(INT21_HEAP
, misc_indos
) );
4614 case 0x35: /* GET INTERRUPT VECTOR */
4615 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4618 if (!ISV86(context
) && DOSVM_IsWin16())
4619 addr
= DOSVM_GetPMHandler16( AL_reg(context
) );
4621 addr
= DOSVM_GetRMHandler( AL_reg(context
) );
4622 context
->SegEs
= SELECTOROF(addr
);
4623 SET_BX( context
, OFFSETOF(addr
) );
4627 case 0x36: /* GET FREE DISK SPACE */
4628 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
4629 INT21_DriveName( DL_reg(context
) ));
4630 if (!INT21_GetFreeDiskSpace(context
)) SET_AX( context
, 0xffff );
4633 case 0x37: /* SWITCHAR */
4635 switch (AL_reg(context
))
4637 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
4638 TRACE( "SWITCHAR - GET SWITCH CHARACTER\n" );
4639 SET_AL( context
, 0x00 ); /* success*/
4640 SET_DL( context
, '/' );
4642 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
4643 FIXME( "SWITCHAR - SET SWITCH CHARACTER: %c\n",
4645 SET_AL( context
, 0x00 ); /* success*/
4648 INT_BARF( context
, 0x21 );
4654 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
4655 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
4656 if (AL_reg(context
))
4658 WORD country
= AL_reg(context
);
4659 if (country
== 0xff)
4660 country
= BX_reg(context
);
4661 if (country
!= INT21_GetSystemCountryCode()) {
4662 FIXME( "Requested info on non-default country %04x\n", country
);
4667 if(AX_reg(context
) != 2 )
4669 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context
,
4672 SET_AX( context
, INT21_GetSystemCountryCode() );
4673 SET_BX( context
, INT21_GetSystemCountryCode() );
4674 RESET_CFLAG(context
);
4678 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
4679 if (!INT21_CreateDirectory( context
))
4680 bSetDOSExtendedError
= TRUE
;
4682 RESET_CFLAG(context
);
4685 case 0x3a: /* "RMDIR" - REMOVE DIRECTORY */
4687 WCHAR dirW
[MAX_PATH
];
4688 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
4689 context
->SegDs
, context
->Edx
);
4691 TRACE( "REMOVE DIRECTORY %s\n", dirA
);
4693 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
4695 if (!RemoveDirectoryW( dirW
))
4696 bSetDOSExtendedError
= TRUE
;
4698 RESET_CFLAG(context
);
4702 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
4703 if (!INT21_SetCurrentDirectory( context
))
4704 bSetDOSExtendedError
= TRUE
;
4706 RESET_CFLAG(context
);
4709 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
4710 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4711 OF_READWRITE
| OF_SHARE_COMPAT
, 0x12 ))
4712 bSetDOSExtendedError
= TRUE
;
4714 RESET_CFLAG(context
);
4717 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
4718 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4719 AL_reg(context
), 0x01 ))
4720 bSetDOSExtendedError
= TRUE
;
4722 RESET_CFLAG(context
);
4725 case 0x3e: /* "CLOSE" - CLOSE FILE */
4726 TRACE( "CLOSE handle %d\n", BX_reg(context
) );
4727 if (_lclose16( BX_reg(context
) ) == HFILE_ERROR16
)
4728 bSetDOSExtendedError
= TRUE
;
4730 RESET_CFLAG(context
);
4733 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
4734 TRACE( "READ from %d to %04lX:%04X for %d bytes\n",
4741 WORD count
= CX_reg(context
);
4742 BYTE
*buffer
= CTX_SEG_OFF_TO_LIN( context
,
4746 /* Some programs pass a count larger than the allocated buffer */
4747 if (DOSVM_IsWin16())
4749 WORD maxcount
= GetSelectorLimit16( context
->SegDs
)
4750 - DX_reg(context
) + 1;
4751 if (count
> maxcount
)
4756 * FIXME: Reading from console (BX=1) in DOS mode
4757 * does not work as it is supposed to work.
4760 RESET_CFLAG(context
); /* set if error */
4761 if (!DOSVM_IsWin16() && BX_reg(context
) == 0)
4763 result
= INT21_BufferedInput( context
, buffer
, count
);
4764 SET_AX( context
, (WORD
)result
);
4766 else if (ReadFile( DosFileHandleToWin32Handle(BX_reg(context
)),
4767 buffer
, count
, &result
, NULL
))
4768 SET_AX( context
, (WORD
)result
);
4770 bSetDOSExtendedError
= TRUE
;
4774 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
4775 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
4776 context
->SegDs
, DX_reg(context
),
4777 BX_reg(context
), CX_reg(context
) );
4779 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4781 if (!DOSVM_IsWin16() &&
4782 (BX_reg(context
) == 1 || BX_reg(context
) == 2))
4785 for(i
=0; i
<CX_reg(context
); i
++)
4786 DOSVM_PutChar(ptr
[i
]);
4787 SET_AX(context
, CX_reg(context
));
4788 RESET_CFLAG(context
);
4792 HFILE handle
= (HFILE
)DosFileHandleToWin32Handle(BX_reg(context
));
4793 LONG result
= _hwrite( handle
, ptr
, CX_reg(context
) );
4794 if (result
== HFILE_ERROR
)
4795 bSetDOSExtendedError
= TRUE
;
4798 SET_AX( context
, (WORD
)result
);
4799 RESET_CFLAG(context
);
4805 case 0x41: /* "UNLINK" - DELETE FILE */
4807 WCHAR fileW
[MAX_PATH
];
4808 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
4812 TRACE( "UNLINK %s\n", fileA
);
4813 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
4815 if (!DeleteFileW( fileW
))
4816 bSetDOSExtendedError
= TRUE
;
4818 RESET_CFLAG(context
);
4822 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
4823 TRACE( "LSEEK handle %d offset %ld from %s\n",
4825 MAKELONG( DX_reg(context
), CX_reg(context
) ),
4826 (AL_reg(context
) == 0) ?
4827 "start of file" : ((AL_reg(context
) == 1) ?
4828 "current file position" : "end of file") );
4830 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
4831 LONG offset
= MAKELONG( DX_reg(context
), CX_reg(context
) );
4832 DWORD status
= SetFilePointer( handle
, offset
,
4833 NULL
, AL_reg(context
) );
4834 if (status
== INVALID_SET_FILE_POINTER
)
4835 bSetDOSExtendedError
= TRUE
;
4838 SET_AX( context
, LOWORD(status
) );
4839 SET_DX( context
, HIWORD(status
) );
4840 RESET_CFLAG(context
);
4845 case 0x43: /* FILE ATTRIBUTES */
4846 if (!INT21_FileAttributes( context
, AL_reg(context
), FALSE
))
4847 bSetDOSExtendedError
= TRUE
;
4849 RESET_CFLAG(context
);
4852 case 0x44: /* IOCTL */
4853 INT21_Ioctl( context
);
4856 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
4857 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context
) );
4860 HFILE handle16
= HFILE_ERROR
;
4862 if (DuplicateHandle( GetCurrentProcess(),
4863 DosFileHandleToWin32Handle(BX_reg(context
)),
4864 GetCurrentProcess(),
4866 0, TRUE
, DUPLICATE_SAME_ACCESS
))
4867 handle16
= Win32HandleToDosFileHandle(handle32
);
4869 if (handle16
== HFILE_ERROR
)
4870 bSetDOSExtendedError
= TRUE
;
4873 SET_AX( context
, handle16
);
4874 RESET_CFLAG(context
);
4879 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
4880 TRACE( "FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
4881 BX_reg(context
), CX_reg(context
) );
4882 if (!INT21_Dup2(BX_reg(context
), CX_reg(context
)))
4883 bSetDOSExtendedError
= TRUE
;
4885 RESET_CFLAG(context
);
4888 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
4889 if (!INT21_GetCurrentDirectory( context
, FALSE
))
4890 bSetDOSExtendedError
= TRUE
;
4892 RESET_CFLAG(context
);
4895 case 0x48: /* ALLOCATE MEMORY */
4896 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
) );
4899 DWORD bytes
= (DWORD
)BX_reg(context
) << 4;
4901 if (!ISV86(context
) && DOSVM_IsWin16())
4903 DWORD rv
= GlobalDOSAlloc16( bytes
);
4904 selector
= LOWORD( rv
);
4907 DOSMEM_AllocBlock( bytes
, &selector
);
4911 SET_AX( context
, selector
);
4912 RESET_CFLAG(context
);
4917 SET_AX( context
, 0x0008 ); /* insufficient memory */
4918 SET_BX( context
, DOSMEM_Available() >> 4 );
4923 case 0x49: /* FREE MEMORY */
4924 TRACE( "FREE MEMORY segment %04lX\n", context
->SegEs
);
4928 if (!ISV86(context
) && DOSVM_IsWin16())
4930 ok
= !GlobalDOSFree16( context
->SegEs
);
4932 /* If we don't reset ES_reg, we will fail in the relay code */
4937 ok
= DOSMEM_FreeBlock( PTR_REAL_TO_LIN(context
->SegEs
, 0) );
4941 TRACE("FREE MEMORY failed\n");
4943 SET_AX( context
, 0x0009 ); /* memory block address invalid */
4948 case 0x4a: /* RESIZE MEMORY BLOCK */
4949 TRACE( "RESIZE MEMORY segment %04lX to %d paragraphs\n",
4950 context
->SegEs
, BX_reg(context
) );
4952 DWORD newsize
= (DWORD
)BX_reg(context
) << 4;
4954 if (!ISV86(context
) && DOSVM_IsWin16())
4956 FIXME( "Resize memory block - unsupported under Win16\n" );
4961 LPVOID address
= (void*)((DWORD
)context
->SegEs
<< 4);
4962 UINT blocksize
= DOSMEM_ResizeBlock( address
, newsize
, FALSE
);
4964 RESET_CFLAG(context
);
4965 if (blocksize
== (UINT
)-1)
4967 SET_CFLAG( context
);
4968 SET_AX( context
, 0x0009 ); /* illegal address */
4970 else if(blocksize
!= newsize
)
4972 SET_CFLAG( context
);
4973 SET_AX( context
, 0x0008 ); /* insufficient memory */
4974 SET_BX( context
, blocksize
>> 4 ); /* new block size */
4980 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
4982 BYTE
*program
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4983 BYTE
*paramblk
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
4985 TRACE( "EXEC %s\n", program
);
4987 RESET_CFLAG(context
);
4988 if (DOSVM_IsWin16())
4990 HINSTANCE16 instance
= WinExec16( program
, SW_NORMAL
);
4993 SET_CFLAG( context
);
4994 SET_AX( context
, instance
);
4999 if (!MZ_Exec( context
, program
, AL_reg(context
), paramblk
))
5000 bSetDOSExtendedError
= TRUE
;
5005 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
5006 TRACE( "EXIT with return code %d\n", AL_reg(context
) );
5007 if (DOSVM_IsWin16())
5008 ExitThread( AL_reg(context
) );
5009 else if(ISV86(context
))
5010 MZ_Exit( context
, FALSE
, AL_reg(context
) );
5016 DWORD rv
= AL_reg(context
);
5017 RaiseException( EXCEPTION_VM86_INTx
, 0, 1, &rv
);
5021 case 0x4d: /* GET RETURN CODE */
5022 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
5023 SET_AX( context
, DOSVM_retval
);
5027 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
5028 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
5029 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
5030 if (!INT21_FindFirst(context
)) break;
5033 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
5034 TRACE("FINDNEXT\n");
5035 if (!INT21_FindNext(context
))
5037 SetLastError( ERROR_NO_MORE_FILES
);
5038 SET_AX( context
, ERROR_NO_MORE_FILES
);
5041 else SET_AX( context
, 0 ); /* OK */
5044 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
5045 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
5046 DOSVM_psp
= BX_reg(context
);
5049 case 0x51: /* GET PSP ADDRESS */
5050 INT21_GetPSP( context
);
5053 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
5055 SEGPTR ptr
= DOSDEV_GetLOL( ISV86(context
) || !DOSVM_IsWin16() );
5056 context
->SegEs
= SELECTOROF(ptr
);
5057 SET_BX( context
, OFFSETOF(ptr
) );
5061 case 0x54: /* Get Verify Flag */
5062 TRACE("Get Verify Flag - Not Supported\n");
5063 SET_AL( context
, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
5066 case 0x56: /* "RENAME" - RENAME FILE */
5067 if (!INT21_RenameFile( context
))
5068 bSetDOSExtendedError
= TRUE
;
5070 RESET_CFLAG(context
);
5073 case 0x57: /* FILE DATE AND TIME */
5074 if (!INT21_FileDateTime( context
))
5075 bSetDOSExtendedError
= TRUE
;
5077 RESET_CFLAG(context
);
5080 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
5081 switch (AL_reg(context
))
5083 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
5084 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
5085 SET_AX( context
, 0 ); /* low memory first fit */
5088 case 0x01: /* SET ALLOCATION STRATEGY */
5089 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
5093 case 0x02: /* GET UMB LINK STATE */
5094 TRACE( "GET UMB LINK STATE\n" );
5095 SET_AL( context
, 0 ); /* UMBs not part of DOS memory chain */
5098 case 0x03: /* SET UMB LINK STATE */
5099 TRACE( "SET UMB LINK STATE to %d - ignored\n",
5104 INT_BARF( context
, 0x21 );
5108 case 0x59: /* GET EXTENDED ERROR INFO */
5109 INT21_GetExtendedError( context
);
5112 case 0x5a: /* CREATE TEMPORARY FILE */
5113 TRACE("CREATE TEMPORARY FILE\n");
5114 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
5117 case 0x5b: /* CREATE NEW FILE */
5118 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
5119 OF_READWRITE
| OF_SHARE_COMPAT
, 0x10 ))
5120 bSetDOSExtendedError
= TRUE
;
5122 RESET_CFLAG(context
);
5125 case 0x5c: /* "FLOCK" - RECORD LOCKING */
5127 DWORD offset
= MAKELONG(DX_reg(context
), CX_reg(context
));
5128 DWORD length
= MAKELONG(DI_reg(context
), SI_reg(context
));
5129 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
5131 RESET_CFLAG(context
);
5132 switch (AL_reg(context
))
5134 case 0x00: /* LOCK */
5135 TRACE( "lock handle %d offset %ld length %ld\n",
5136 BX_reg(context
), offset
, length
);
5137 if (!LockFile( handle
, offset
, 0, length
, 0 ))
5138 bSetDOSExtendedError
= TRUE
;
5141 case 0x01: /* UNLOCK */
5142 TRACE( "unlock handle %d offset %ld length %ld\n",
5143 BX_reg(context
), offset
, length
);
5144 if (!UnlockFile( handle
, offset
, 0, length
, 0 ))
5145 bSetDOSExtendedError
= TRUE
;
5149 INT_BARF( context
, 0x21 );
5154 case 0x5d: /* NETWORK 5D */
5155 FIXME( "Network function 5D not implemented.\n" );
5156 SetLastError( ER_NoNetwork
);
5157 bSetDOSExtendedError
= TRUE
;
5160 case 0x5e: /* NETWORK 5E */
5161 bSetDOSExtendedError
= INT21_NetworkFunc( context
);
5164 case 0x5f: /* NETWORK 5F */
5165 /* FIXME: supporting this would need to 1:
5166 * - implement per drive current directory (as kernel32 doesn't)
5167 * - assign enabled/disabled flag on a per drive basis
5169 /* network software not installed */
5170 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
5171 SetLastError( ER_NoNetwork
);
5172 bSetDOSExtendedError
= TRUE
;
5175 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
5177 WCHAR pathW
[MAX_PATH
], res
[MAX_PATH
];
5178 /* FIXME: likely to be broken */
5180 TRACE("TRUENAME %s\n",
5181 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
5182 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
5183 if (!GetFullPathNameW( pathW
, 128, res
, NULL
))
5184 bSetDOSExtendedError
= TRUE
;
5187 SET_AX( context
, 0 );
5188 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
5189 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
5195 case 0x61: /* UNUSED */
5196 SET_AL( context
, 0 );
5199 case 0x62: /* GET PSP ADDRESS */
5200 INT21_GetPSP( context
);
5203 case 0x63: /* MISC. LANGUAGE SUPPORT */
5204 switch (AL_reg(context
)) {
5205 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
5206 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
5207 context
->SegDs
= INT21_GetHeapSelector( context
);
5208 SET_SI( context
, offsetof(INT21_HEAP
, dbcs_table
) );
5209 SET_AL( context
, 0 ); /* success */
5214 case 0x64: /* OS/2 DOS BOX */
5215 INT_BARF( context
, 0x21 );
5219 case 0x65: /* EXTENDED COUNTRY INFORMATION */
5220 INT21_ExtendedCountryInformation( context
);
5223 case 0x66: /* GLOBAL CODE PAGE TABLE */
5224 switch (AL_reg(context
))
5227 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
5228 SET_BX( context
, GetOEMCP() );
5229 SET_DX( context
, GetOEMCP() );
5232 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
5233 BX_reg(context
), DX_reg(context
) );
5238 case 0x67: /* SET HANDLE COUNT */
5239 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context
) );
5240 if (SetHandleCount( BX_reg(context
) ) < BX_reg(context
) )
5241 bSetDOSExtendedError
= TRUE
;
5244 case 0x68: /* "FFLUSH" - COMMIT FILE */
5245 TRACE( "FFLUSH - handle %d\n", BX_reg(context
) );
5246 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
5247 bSetDOSExtendedError
= TRUE
;
5250 case 0x69: /* DISK SERIAL NUMBER */
5251 switch (AL_reg(context
))
5254 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
5255 INT21_DriveName(BL_reg(context
)));
5256 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
5257 else SET_AX( context
, 0 );
5261 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
5262 INT21_DriveName(BL_reg(context
)));
5263 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
5264 else SET_AX( context
, 1 );
5269 case 0x6a: /* COMMIT FILE */
5270 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context
) );
5271 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
5272 bSetDOSExtendedError
= TRUE
;
5275 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
5276 SET_AL( context
, 0 );
5279 case 0x6c: /* EXTENDED OPEN/CREATE */
5280 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
5281 BX_reg(context
), DL_reg(context
) ))
5282 bSetDOSExtendedError
= TRUE
;
5285 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
5286 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
5287 SET_CFLAG( context
);
5288 SET_AL( context
, 0 );
5291 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
5292 INT21_LongFilename( context
);
5295 case 0x73: /* MSDOS7 - FAT32 */
5296 RESET_CFLAG( context
);
5297 if (!INT21_Fat32( context
))
5298 bSetDOSExtendedError
= TRUE
;
5301 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
5302 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
5305 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
5306 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
5309 case 0xff: /* DOS32 EXTENDER (DOS/4GW) - API */
5310 /* we don't implement a DOS32 extender */
5311 TRACE( "DOS32 EXTENDER API - ignored\n" );
5315 INT_BARF( context
, 0x21 );
5318 } /* END OF SWITCH */
5320 /* Set general error condition. */
5321 if (bSetDOSExtendedError
)
5323 SET_AX( context
, GetLastError() );
5324 SET_CFLAG( context
);
5327 /* Print error code if carry flag is set. */
5328 if (context
->EFlags
& 0x0001)
5329 TRACE("failed, error %ld\n", GetLastError() );
5331 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
5332 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
5333 AX_reg(context
), BX_reg(context
),
5334 CX_reg(context
), DX_reg(context
),
5335 SI_reg(context
), DI_reg(context
),
5336 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,