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"
40 #include "wine/winbase16.h"
44 #include "wine/unicode.h"
45 #include "wine/server.h"
46 #include "wine/debug.h"
47 #include "wine/exception.h"
51 * - Most of the file related functions are wrong. NT's kernel32
52 * doesn't maintain a per drive current directory, while DOS does.
53 * We should in fact keep track in here of those per driver
54 * directories, and use this infro while dealing with partial paths
55 * (drive defined, but only relative paths). This could even be
56 * created as an array of CDS (there should be an entry for that in
61 * Forward declarations.
63 static BOOL
INT21_RenameFile( CONTEXT86
*context
);
65 WINE_DEFAULT_DEBUG_CHANNEL(int21
);
71 * Extended Drive Parameter Block.
72 * This structure is compatible with standard DOS4+ DPB and
75 typedef struct _INT21_DPB
{
76 BYTE drive
; /* 00 drive number (0=A, ...) */
77 BYTE unit
; /* 01 unit number within device driver */
78 WORD sector_bytes
; /* 02 bytes per sector */
79 BYTE cluster_sectors
; /* 04 highest sector number within a cluster */
80 BYTE shift
; /* 05 shift count to convert clusters into sectors */
81 WORD num_reserved
; /* 06 reserved sectors at beginning of drive */
82 BYTE num_FAT
; /* 08 number of FATs */
83 WORD num_root_entries
; /* 09 number of root directory entries */
84 WORD first_data_sector
; /* 0b number of first sector containing user data */
85 WORD num_clusters1
; /* 0d highest cluster number (number of data clusters + 1) */
86 WORD sectors_per_FAT
; /* 0f number of sectors per FAT */
87 WORD first_dir_sector
; /* 11 sector number of first directory sector */
88 SEGPTR driver_header
; /* 13 address of device driver header */
89 BYTE media_ID
; /* 17 media ID byte */
90 BYTE access_flag
; /* 18 0x00 if disk accessed, 0xff if not */
91 SEGPTR next
; /* 19 pointer to next DPB */
92 WORD search_cluster1
; /* 1d cluster at which to start search for free space */
93 WORD free_clusters_lo
; /* 1f number of free clusters on drive or 0xffff if unknown */
94 WORD free_clusters_hi
; /* 21 hiword of clusters_free */
95 WORD mirroring_flags
; /* 23 active FAT/mirroring flags */
96 WORD info_sector
; /* 25 sector number of file system info sector or 0xffff for none */
97 WORD spare_boot_sector
; /* 27 sector number of backup boot sector or 0xffff for none */
98 DWORD first_cluster_sector
; /* 29 sector number of the first cluster */
99 DWORD num_clusters2
; /* 2d maximum cluster number */
100 DWORD fat_clusters
; /* 31 number of clusters occupied by FAT */
101 DWORD root_cluster
; /* 35 cluster number of start of root directory */
102 DWORD search_cluster2
; /* 39 cluster at which to start searching for free space */
107 * Structure for DOS data that can be accessed directly from applications.
108 * Real and protected mode pointers will be returned to this structure so
109 * the structure must be correctly packed.
111 typedef struct _INT21_HEAP
{
112 WORD uppercase_size
; /* Size of the following table in bytes */
113 BYTE uppercase_table
[128]; /* Uppercase equivalents of chars from 0x80 to 0xff. */
115 WORD lowercase_size
; /* Size of the following table in bytes */
116 BYTE lowercase_table
[256]; /* Lowercase equivalents of chars from 0x00 to 0xff. */
118 WORD collating_size
; /* Size of the following table in bytes */
119 BYTE collating_table
[256]; /* Values used to sort characters from 0x00 to 0xff. */
121 WORD filename_size
; /* Size of the following filename data in bytes */
122 BYTE filename_reserved1
; /* 0x01 for MS-DOS 3.30-6.00 */
123 BYTE filename_lowest
; /* Lowest permissible character value for filename */
124 BYTE filename_highest
; /* Highest permissible character value for filename */
125 BYTE filename_reserved2
; /* 0x00 for MS-DOS 3.30-6.00 */
126 BYTE filename_exclude_first
; /* First illegal character in permissible range */
127 BYTE filename_exclude_last
; /* Last illegal character in permissible range */
128 BYTE filename_reserved3
; /* 0x02 for MS-DOS 3.30-6.00 */
129 BYTE filename_illegal_size
; /* Number of terminators in the following table */
130 BYTE filename_illegal_table
[16]; /* Characters which terminate a filename */
132 WORD dbcs_size
; /* Number of valid ranges in the following table */
133 BYTE dbcs_table
[16]; /* Start/end bytes for N ranges and 00/00 as terminator */
135 BYTE misc_indos
; /* Interrupt 21 nesting flag */
136 WORD misc_segment
; /* Real mode segment for INT21_HEAP */
137 WORD misc_selector
; /* Protected mode selector for INT21_HEAP */
138 INT21_DPB misc_dpb_list
[MAX_DOS_DRIVES
]; /* Drive parameter blocks for all drives */
146 CHAR file_extension
[3];
147 WORD current_block_number
;
148 WORD logical_record_size
;
150 WORD date_of_last_write
;
151 WORD time_of_last_write
;
154 WORD starting_cluster
;
155 WORD sequence_number
;
156 BYTE file_attributes
;
158 BYTE record_within_current_block
;
159 BYTE random_access_record_number
[4];
166 BYTE xfcb_file_attribute
;
170 /* DTA layout for FindFirst/FindNext */
173 BYTE drive
; /* 00 drive letter */
174 char mask
[11]; /* 01 search template */
175 BYTE search_attr
; /* 0c search attributes */
176 WORD count
; /* 0d entry count within directory */
177 WORD cluster
; /* 0f cluster of parent directory */
178 WCHAR
*fullPath
; /* 11 full path (was: reserved) */
179 BYTE fileattr
; /* 15 file attributes */
180 WORD filetime
; /* 16 file time */
181 WORD filedate
; /* 18 file date */
182 DWORD filesize
; /* 1a file size */
183 char filename
[13]; /* 1e file name + extension */
186 /* FCB layout for FindFirstFCB/FindNextFCB */
189 BYTE drive
; /* 00 drive letter */
190 char filename
[11]; /* 01 filename 8+3 format */
191 int count
; /* 0c entry count (was: reserved) */
192 WCHAR
*fullPath
; /* 10 full path (was: reserved) */
195 /* DOS directory entry for FindFirstFCB/FindNextFCB */
198 char filename
[11]; /* 00 filename 8+3 format */
199 BYTE fileattr
; /* 0b file attributes */
200 BYTE reserved
[10]; /* 0c reserved */
201 WORD filetime
; /* 16 file time */
202 WORD filedate
; /* 18 file date */
203 WORD cluster
; /* 1a file first cluster */
204 DWORD filesize
; /* 1c file size */
205 } DOS_DIRENTRY_LAYOUT
;
209 /* dos file attributes */
210 #define FA_NORMAL 0x00 /* Normal file, no attributes */
211 #define FA_RDONLY 0x01 /* Read only attribute */
212 #define FA_HIDDEN 0x02 /* Hidden file */
213 #define FA_SYSTEM 0x04 /* System file */
214 #define FA_LABEL 0x08 /* Volume label */
215 #define FA_DIRECTORY 0x10 /* Directory */
216 #define FA_ARCHIVE 0x20 /* Archive */
217 #define FA_UNUSED 0x40 /* Unused */
220 #define ER_NoNetwork 0x49
223 #define EC_OutOfResource 0x01
224 #define EC_Temporary 0x02
225 #define EC_AccessDenied 0x03
226 #define EC_InternalError 0x04
227 #define EC_HardwareFailure 0x05
228 #define EC_SystemFailure 0x06
229 #define EC_ProgramError 0x07
230 #define EC_NotFound 0x08
231 #define EC_MediaError 0x0b
232 #define EC_Exists 0x0c
233 #define EC_Unknown 0x0d
235 /* Suggested actions */
236 #define SA_Retry 0x01
237 #define SA_DelayedRetry 0x02
238 #define SA_Abort 0x04
239 #define SA_Ignore 0x06
240 #define SA_Ask4Retry 0x07
243 #define EL_Unknown 0x01
245 #define EL_Network 0x03
246 #define EL_Serial 0x04
247 #define EL_Memory 0x05
249 /* BIOS Keyboard Scancodes */
250 #define KEY_LEFT 0x4B
251 #define KEY_RIGHT 0x4D
253 #define KEY_DOWN 0x50
254 #define KEY_IC 0x52 /* insert char */
255 #define KEY_DC 0x53 /* delete char */
256 #define KEY_BACKSPACE 0x0E
257 #define KEY_HOME 0x47
259 #define KEY_NPAGE 0x49
260 #define KEY_PPAGE 0x51
269 void (*ioctl_handler
)(CONTEXT86
*);
272 static void INT21_IoctlScsiMgrHandler( CONTEXT86
* );
273 static void INT21_IoctlEMSHandler( CONTEXT86
* );
274 static void INT21_IoctlHPScanHandler( CONTEXT86
* );
276 static struct magic_device magic_devices
[] =
278 { {'s','c','s','i','m','g','r','$',0}, NULL
, 0, 0, INT21_IoctlScsiMgrHandler
},
279 { {'e','m','m','x','x','x','x','0',0}, NULL
, 0, 0, INT21_IoctlEMSHandler
},
280 { {'h','p','s','c','a','n',0}, NULL
, 0, 0, INT21_IoctlHPScanHandler
},
283 #define NB_MAGIC_DEVICES (sizeof(magic_devices)/sizeof(magic_devices[0]))
286 /* Many calls translate a drive argument like this:
287 drive number (00h = default, 01h = A:, etc)
289 /******************************************************************
292 * Many calls translate a drive argument like this:
293 * drive number (00h = default, 01h = A:, etc)
295 static const char *INT21_DriveName(int drive
)
299 if (drive
<= 26) return wine_dbg_sprintf("%c:", 'A' + drive
- 1);
300 else return wine_dbg_sprintf( "<Bad drive: %d>", drive
);
305 /***********************************************************************
306 * INT21_GetCurrentDrive
308 * Return current drive using scheme (0=A:, 1=B:, 2=C:, ...) or
309 * MAX_DOS_DRIVES on error.
311 static BYTE
INT21_GetCurrentDrive(void)
313 WCHAR current_directory
[MAX_PATH
];
315 if (!GetCurrentDirectoryW( MAX_PATH
, current_directory
) ||
316 current_directory
[1] != ':')
318 TRACE( "Failed to get current drive.\n" );
319 return MAX_DOS_DRIVES
;
322 return toupperW( current_directory
[0] ) - 'A';
326 /***********************************************************************
329 * Convert drive number from scheme (0=default, 1=A:, 2=B:, ...) into
330 * scheme (0=A:, 1=B:, 2=C:, ...) or MAX_DOS_DRIVES on error.
332 static BYTE
INT21_MapDrive( BYTE drive
)
336 WCHAR drivespec
[3] = {'A', ':', 0};
339 drivespec
[0] += drive
- 1;
340 drivetype
= GetDriveTypeW( drivespec
);
342 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
343 return MAX_DOS_DRIVES
;
348 return INT21_GetCurrentDrive();
352 /***********************************************************************
353 * INT21_SetCurrentDrive
355 * Set current drive. Uses scheme (0=A:, 1=B:, 2=C:, ...).
357 static void INT21_SetCurrentDrive( BYTE drive
)
359 WCHAR drivespec
[3] = {'A', ':', 0};
361 drivespec
[0] += drive
;
363 if (!SetCurrentDirectoryW( drivespec
))
364 TRACE( "Failed to set current drive.\n" );
368 /***********************************************************************
371 * Reads a character from the standard input.
372 * Extended keycodes will be returned as two separate characters.
374 static BOOL
INT21_ReadChar( BYTE
*input
, CONTEXT86
*waitctx
)
376 static BYTE pending_scan
= 0;
381 *input
= pending_scan
;
390 if (!DOSVM_Int16ReadChar( &ascii
, &scan
, waitctx
))
395 if (waitctx
&& !ascii
)
402 /***********************************************************************
403 * INT21_GetSystemCountryCode
405 * Return DOS country code for default system locale.
407 static WORD
INT21_GetSystemCountryCode( void )
410 * FIXME: Determine country code. We should probably use
411 * DOSCONF structure for that.
413 return GetSystemDefaultLangID();
417 /***********************************************************************
418 * INT21_FillCountryInformation
420 * Fill 34-byte buffer with country information data using
421 * default system locale.
423 static void INT21_FillCountryInformation( BYTE
*buffer
)
425 /* 00 - WORD: date format
430 *(WORD
*)(buffer
+ 0) = 0; /* FIXME: Get from locale */
432 /* 02 - BYTE[5]: ASCIIZ currency symbol string */
433 buffer
[2] = '$'; /* FIXME: Get from locale */
436 /* 07 - BYTE[2]: ASCIIZ thousands separator */
437 buffer
[7] = 0; /* FIXME: Get from locale */
440 /* 09 - BYTE[2]: ASCIIZ decimal separator */
441 buffer
[9] = '.'; /* FIXME: Get from locale */
444 /* 11 - BYTE[2]: ASCIIZ date separator */
445 buffer
[11] = '/'; /* FIXME: Get from locale */
448 /* 13 - BYTE[2]: ASCIIZ time separator */
449 buffer
[13] = ':'; /* FIXME: Get from locale */
452 /* 15 - BYTE: Currency format
453 * bit 2 = set if currency symbol replaces decimal point
454 * bit 1 = number of spaces between value and currency symbol
455 * bit 0 = 0 if currency symbol precedes value
456 * 1 if currency symbol follows value
458 buffer
[15] = 0; /* FIXME: Get from locale */
460 /* 16 - BYTE: Number of digits after decimal in currency */
461 buffer
[16] = 0; /* FIXME: Get from locale */
463 /* 17 - BYTE: Time format
464 * bit 0 = 0 if 12-hour clock
467 buffer
[17] = 1; /* FIXME: Get from locale */
469 /* 18 - DWORD: Address of case map routine */
470 *(DWORD
*)(buffer
+ 18) = 0; /* FIXME: ptr to case map routine */
472 /* 22 - BYTE[2]: ASCIIZ data-list separator */
473 buffer
[22] = ','; /* FIXME: Get from locale */
476 /* 24 - BYTE[10]: Reserved */
477 memset( buffer
+ 24, 0, 10 );
481 /***********************************************************************
484 * Initialize DOS heap.
486 * Filename Terminator Table of w2k DE NTVDM:
487 * 16 00 01 00 FF 00 00 20-02 0E 2E 22 2F 5C 5B 5D ....... ..."/\[]
488 * 3A 7C 3C 3E 2B 3D 3B 2C-00 :|<>+=;,
490 static void INT21_FillHeap( INT21_HEAP
*heap
)
492 static const char terminators
[] = ".\"/\\[]:|<>+=;,";
498 heap
->uppercase_size
= 128;
499 for (i
= 0; i
< 128; i
++)
500 heap
->uppercase_table
[i
] = toupper( 128 + i
);
505 heap
->lowercase_size
= 256;
506 for (i
= 0; i
< 256; i
++)
507 heap
->lowercase_table
[i
] = tolower( i
);
512 heap
->collating_size
= 256;
513 for (i
= 0; i
< 256; i
++)
514 heap
->collating_table
[i
] = i
;
519 heap
->filename_size
= 8 + strlen(terminators
);
520 heap
->filename_illegal_size
= strlen(terminators
);
521 strcpy( heap
->filename_illegal_table
, terminators
);
523 heap
->filename_reserved1
= 0x01;
524 heap
->filename_lowest
= 0x00;
525 heap
->filename_highest
= 0xff;
526 heap
->filename_reserved2
= 0x00;
527 heap
->filename_exclude_first
= 0x00;
528 heap
->filename_exclude_last
= 0x20;
529 heap
->filename_reserved3
= 0x02;
532 * DBCS lead byte table. This table is empty.
535 memset( heap
->dbcs_table
, 0, sizeof(heap
->dbcs_table
) );
538 * Initialize InDos flag.
540 heap
->misc_indos
= 0;
543 * FIXME: Should drive parameter blocks (DPB) be
544 * initialized here and linked to DOS LOL?
549 /***********************************************************************
550 * INT21_GetHeapPointer
552 * Get pointer for DOS heap (INT21_HEAP).
553 * Creates and initializes heap on first call.
555 static INT21_HEAP
*INT21_GetHeapPointer( void )
557 static INT21_HEAP
*heap_pointer
= NULL
;
564 heap_pointer
= DOSVM_AllocDataUMB( sizeof(INT21_HEAP
),
568 heap_pointer
->misc_segment
= heap_segment
;
569 heap_pointer
->misc_selector
= heap_selector
;
570 INT21_FillHeap( heap_pointer
);
577 /***********************************************************************
578 * INT21_GetHeapSelector
580 * Get segment/selector for DOS heap (INT21_HEAP).
581 * Creates and initializes heap on first call.
583 static WORD
INT21_GetHeapSelector( CONTEXT86
*context
)
585 INT21_HEAP
*heap
= INT21_GetHeapPointer();
587 if (!ISV86(context
) && DOSVM_IsWin16())
588 return heap
->misc_selector
;
590 return heap
->misc_segment
;
594 /***********************************************************************
597 * Fill DOS heap drive parameter block for the specified drive.
598 * Return TRUE if drive was valid and there were
599 * no errors while reading drive information.
601 static BOOL
INT21_FillDrivePB( BYTE drive
)
603 WCHAR drivespec
[3] = {'A', ':', 0};
604 INT21_HEAP
*heap
= INT21_GetHeapPointer();
607 DWORD cluster_sectors
;
610 DWORD total_clusters
;
612 if (drive
>= MAX_DOS_DRIVES
)
615 dpb
= &heap
->misc_dpb_list
[drive
];
616 drivespec
[0] += drive
;
617 drivetype
= GetDriveTypeW( drivespec
);
620 * FIXME: Does this check work correctly with floppy/cdrom drives?
622 if (drivetype
== DRIVE_NO_ROOT_DIR
|| drivetype
== DRIVE_UNKNOWN
)
626 * FIXME: Does this check work correctly with floppy/cdrom drives?
628 if (!GetDiskFreeSpaceW( drivespec
, &cluster_sectors
, §or_bytes
,
629 &free_clusters
, &total_clusters
))
633 * FIXME: Most of the values listed below are incorrect.
634 * All values should be validated.
639 dpb
->sector_bytes
= sector_bytes
;
640 dpb
->cluster_sectors
= cluster_sectors
- 1;
643 while (cluster_sectors
> 1)
645 cluster_sectors
/= 2;
649 dpb
->num_reserved
= 0;
651 dpb
->num_root_entries
= 2;
652 dpb
->first_data_sector
= 2;
653 dpb
->num_clusters1
= total_clusters
;
654 dpb
->sectors_per_FAT
= 1;
655 dpb
->first_dir_sector
= 1;
656 dpb
->driver_header
= 0;
657 dpb
->media_ID
= (drivetype
== DRIVE_FIXED
) ? 0xF8 : 0xF0;
658 dpb
->access_flag
= 0;
660 dpb
->search_cluster1
= 0;
661 dpb
->free_clusters_lo
= LOWORD(free_clusters
);
662 dpb
->free_clusters_hi
= HIWORD(free_clusters
);
663 dpb
->mirroring_flags
= 0;
664 dpb
->info_sector
= 0xffff;
665 dpb
->spare_boot_sector
= 0xffff;
666 dpb
->first_cluster_sector
= 0;
667 dpb
->num_clusters2
= total_clusters
;
668 dpb
->fat_clusters
= 32;
669 dpb
->root_cluster
= 0;
670 dpb
->search_cluster2
= 0;
676 /***********************************************************************
677 * INT21_GetCurrentDirectory
681 * - subfunction 0x47 of function 0x71
683 static BOOL
INT21_GetCurrentDirectory( CONTEXT86
*context
, BOOL islong
)
685 char *buffer
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
686 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
687 WCHAR pathW
[MAX_PATH
];
688 char pathA
[MAX_PATH
];
691 TRACE( "drive %d\n", DL_reg(context
) );
693 if (drive
== MAX_DOS_DRIVES
)
695 SetLastError(ERROR_INVALID_DRIVE
);
700 * Grab current directory.
703 if (!GetCurrentDirectoryW( MAX_PATH
, pathW
)) return FALSE
;
705 if (toupperW(pathW
[0]) - 'A' != drive
|| pathW
[1] != ':')
707 /* cwd is not on the requested drive, get the environment string instead */
712 env_var
[1] = 'A' + drive
;
715 if (!GetEnvironmentVariableW( env_var
, pathW
, MAX_PATH
))
717 /* return empty path */
724 * Convert into short format.
729 DWORD result
= GetShortPathNameW( pathW
, pathW
, MAX_PATH
);
732 if (result
> MAX_PATH
)
734 WARN( "Short path too long!\n" );
735 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
741 * The returned pathname does not include
742 * the drive letter, colon or leading backslash.
748 * FIXME: We should probably just strip host part from name...
750 FIXME( "UNC names are not supported.\n" );
751 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
754 else if (!ptr
[0] || ptr
[1] != ':' || ptr
[2] != '\\')
756 WARN( "Path is neither UNC nor DOS path: %s\n",
757 wine_dbgstr_w(ptr
) );
758 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
763 /* Remove drive letter, colon and leading backslash. */
768 * Convert into OEM string.
771 if (!WideCharToMultiByte(CP_OEMCP
, 0, ptr
, -1, pathA
,
772 MAX_PATH
, NULL
, NULL
))
774 WARN( "Cannot convert path!\n" );
775 SetLastError(ERROR_NETWORK_BUSY
); /* Internal Wine error. */
785 /* Undocumented success code. */
786 SET_AX( context
, 0x0100 );
788 /* Truncate buffer to 64 bytes. */
792 TRACE( "%c:=%s\n", 'A' + drive
, pathA
);
794 strcpy( buffer
, pathA
);
799 /***********************************************************************
800 * INT21_SetCurrentDirectory
804 * - subfunction 0x3b of function 0x71
806 static BOOL
INT21_SetCurrentDirectory( CONTEXT86
*context
)
808 WCHAR dirW
[MAX_PATH
];
811 char *dirA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
812 BYTE drive
= INT21_GetCurrentDrive();
815 TRACE( "SET CURRENT DIRECTORY %s\n", dirA
);
817 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
818 if (!GetFullPathNameW( dirW
, MAX_PATH
, dirW
, NULL
)) return FALSE
;
820 attr
= GetFileAttributesW( dirW
);
821 if (attr
== INVALID_FILE_ATTRIBUTES
|| !(attr
& FILE_ATTRIBUTE_DIRECTORY
))
823 SetLastError( ERROR_PATH_NOT_FOUND
);
828 env_var
[1] = dirW
[0];
831 result
= SetEnvironmentVariableW( env_var
, dirW
);
833 /* only set current directory if on the current drive */
834 if (result
&& (toupperW(dirW
[0]) - 'A' == drive
)) result
= SetCurrentDirectoryW( dirW
);
839 /***********************************************************************
840 * INT21_CreateMagicDeviceHandle
842 * Create a dummy file handle for a "magic" device.
844 static HANDLE
INT21_CreateMagicDeviceHandle( LPCWSTR name
)
846 const char *dir
= wine_get_server_dir();
850 OBJECT_ATTRIBUTES attr
;
851 UNICODE_STRING nameW
;
854 len
= MultiByteToWideChar( CP_UNIXCP
, 0, dir
, -1, NULL
, 0 );
855 nameW
.Length
= (len
+ 1 + strlenW( name
)) * sizeof(WCHAR
);
856 nameW
.MaximumLength
= nameW
.Length
+ sizeof(WCHAR
);
857 if (!(nameW
.Buffer
= HeapAlloc( GetProcessHeap(), 0, nameW
.Length
)))
859 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
862 MultiByteToWideChar( CP_UNIXCP
, 0, dir
, -1, nameW
.Buffer
, len
);
863 nameW
.Buffer
[len
-1] = '/';
864 strcpyW( nameW
.Buffer
+ len
, name
);
866 attr
.Length
= sizeof(attr
);
867 attr
.RootDirectory
= 0;
869 attr
.ObjectName
= &nameW
;
870 attr
.SecurityDescriptor
= NULL
;
871 attr
.SecurityQualityOfService
= NULL
;
873 status
= NtCreateFile( &ret
, GENERIC_READ
|GENERIC_WRITE
, &attr
, &io
, NULL
, 0,
874 FILE_SHARE_READ
|FILE_SHARE_WRITE
, FILE_OPEN_IF
,
875 FILE_SYNCHRONOUS_IO_ALERT
, NULL
, 0 );
879 SetLastError( RtlNtStatusToDosError(status
) );
881 RtlFreeUnicodeString( &nameW
);
886 /***********************************************************************
887 * INT21_OpenMagicDevice
889 * Open a file handle for "magic" devices like EMMXXXX0.
891 static HANDLE
INT21_OpenMagicDevice( LPCWSTR name
, DWORD access
)
897 if (name
[0] && (name
[1] == ':')) name
+= 2;
898 if ((p
= strrchrW( name
, '/' ))) name
= p
+ 1;
899 if ((p
= strrchrW( name
, '\\' ))) name
= p
+ 1;
901 for (i
= 0; i
< NB_MAGIC_DEVICES
; i
++)
903 int len
= strlenW( magic_devices
[i
].name
);
904 if (!strncmpiW( magic_devices
[i
].name
, name
, len
) &&
905 (!name
[len
] || name
[len
] == '.' || name
[len
] == ':')) break;
907 if (i
== NB_MAGIC_DEVICES
) return 0;
909 if (!magic_devices
[i
].handle
) /* need to open it */
914 if (!(handle
= INT21_CreateMagicDeviceHandle( magic_devices
[i
].name
))) return 0;
915 wine_server_handle_to_fd( handle
, 0, &fd
, NULL
);
917 wine_server_release_fd( handle
, fd
);
918 magic_devices
[i
].dev
= st
.st_dev
;
919 magic_devices
[i
].ino
= st
.st_ino
;
920 magic_devices
[i
].handle
= handle
;
922 if (!DuplicateHandle( GetCurrentProcess(), magic_devices
[i
].handle
,
923 GetCurrentProcess(), &handle
, access
, FALSE
, 0 )) handle
= 0;
928 /***********************************************************************
936 * - subfunction 0x6c of function 0x71
938 static BOOL
INT21_CreateFile( CONTEXT86
*context
,
945 char *pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, pathSegOff
);
946 WCHAR pathW
[MAX_PATH
];
953 TRACE( "CreateFile called: function=%02x, action=%02x, access/share=%04x, "
954 "create flags=%04x, file=%s.\n",
955 AH_reg(context
), dosAction
, dosAccessShare
, CX_reg(context
), pathA
);
958 * Application tried to create/open a file whose name
959 * ends with a backslash. This is not allowed.
961 * FIXME: This needs to be validated, especially the return value.
963 if (pathA
[strlen(pathA
) - 1] == '/')
965 SetLastError( ERROR_FILE_NOT_FOUND
);
970 * Convert DOS action flags into Win32 creation disposition parameter.
975 winMode
= OPEN_EXISTING
;
978 winMode
= TRUNCATE_EXISTING
;
981 winMode
= CREATE_NEW
;
984 winMode
= OPEN_ALWAYS
;
987 winMode
= CREATE_ALWAYS
;
990 SetLastError( ERROR_INVALID_PARAMETER
);
995 * Convert DOS access/share flags into Win32 desired access parameter.
997 switch(dosAccessShare
& 0x07)
1000 winAccess
= GENERIC_READ
;
1003 winAccess
= GENERIC_WRITE
;
1006 winAccess
= GENERIC_READ
| GENERIC_WRITE
;
1010 * Read-only, do not modify file's last-access time (DOS7).
1012 * FIXME: How to prevent modification of last-access time?
1014 winAccess
= GENERIC_READ
;
1021 * Convert DOS access/share flags into Win32 share mode parameter.
1023 switch(dosAccessShare
& 0x70)
1025 case OF_SHARE_EXCLUSIVE
:
1028 case OF_SHARE_DENY_WRITE
:
1029 winSharing
= FILE_SHARE_READ
;
1031 case OF_SHARE_DENY_READ
:
1032 winSharing
= FILE_SHARE_WRITE
;
1034 case OF_SHARE_DENY_NONE
:
1035 case OF_SHARE_COMPAT
:
1037 winSharing
= FILE_SHARE_READ
| FILE_SHARE_WRITE
;
1041 * FIXME: Bit (dosAccessShare & 0x80) represents inheritance.
1042 * What to do with this bit?
1043 * FIXME: Bits in the high byte of dosAccessShare are not supported.
1044 * See both function 0x6c and subfunction 0x6c of function 0x71 for
1045 * definition of these bits.
1049 * Convert DOS create attributes into Win32 flags and attributes parameter.
1051 if (winMode
== OPEN_EXISTING
|| winMode
== TRUNCATE_EXISTING
)
1057 WORD dosAttributes
= CX_reg(context
);
1059 if (dosAttributes
& FA_LABEL
)
1062 * Application tried to create volume label entry.
1063 * This is difficult to support so we do not allow it.
1065 * FIXME: If volume does not already have a label,
1066 * this function is supposed to succeed.
1068 SetLastError( ERROR_ACCESS_DENIED
);
1072 winAttributes
= dosAttributes
&
1073 (FILE_ATTRIBUTE_READONLY
| FILE_ATTRIBUTE_HIDDEN
|
1074 FILE_ATTRIBUTE_SYSTEM
| FILE_ATTRIBUTE_ARCHIVE
);
1080 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
1082 if ((winHandle
= INT21_OpenMagicDevice( pathW
, winAccess
)))
1088 winHandle
= CreateFileW( pathW
, winAccess
, winSharing
, NULL
,
1089 winMode
, winAttributes
, 0 );
1091 if (winHandle
== INVALID_HANDLE_VALUE
)
1095 * Determine DOS file status.
1106 case TRUNCATE_EXISTING
:
1113 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 1 : 2;
1116 dosStatus
= (GetLastError() == ERROR_ALREADY_EXISTS
) ? 3 : 2;
1124 * Return DOS file handle and DOS status.
1126 SET_AX( context
, Win32HandleToDosFileHandle(winHandle
) );
1129 SET_CX( context
, dosStatus
);
1131 TRACE( "CreateFile finished: handle=%d, status=%d.\n",
1132 AX_reg(context
), dosStatus
);
1138 /***********************************************************************
1139 * INT21_BufferedInput
1141 * Handler for function 0x0a and reading from console using
1144 * Reads a string of characters from standard input until
1145 * enter key is pressed. Returns either number of characters
1146 * read from console including terminating CR or
1147 * zero if capacity was zero.
1149 static WORD
INT21_BufferedInput( CONTEXT86
*context
, BYTE
*ptr
, WORD capacity
)
1154 * Return immediately if capacity is zero.
1164 DOSVM_Int16ReadChar( &ascii
, &scan
, context
);
1166 if (ascii
== '\r' || ascii
== '\n')
1173 * DOS handles only backspace and KEY_LEFT
1174 * perhaps we should do more
1176 if (ascii
== '\b' || scan
== KEY_LEFT
)
1178 if (length
==0) continue;
1179 DOSVM_PutChar( '\b' );
1185 * If the buffer becomes filled to within one byte of
1186 * capacity, DOS rejects all further characters up to,
1187 * but not including, the terminating carriage return.
1189 if (ascii
!= 0 && length
< capacity
-1)
1191 DOSVM_PutChar( ascii
);
1192 ptr
[length
] = ascii
;
1199 /***********************************************************************
1200 * INT21_GetCurrentDTA
1202 static BYTE
*INT21_GetCurrentDTA( CONTEXT86
*context
)
1204 TDB
*pTask
= GlobalLock16(GetCurrentTask());
1206 /* FIXME: This assumes DTA was set correctly! */
1207 return (BYTE
*)CTX_SEG_OFF_TO_LIN( context
, SELECTOROF(pTask
->dta
),
1208 (DWORD
)OFFSETOF(pTask
->dta
) );
1212 /***********************************************************************
1213 * INT21_OpenFileUsingFCB
1215 * Handler for function 0x0f.
1218 * DX:DX [I/O] File control block (FCB or XFCB) of unopened file
1225 * Opens a FCB file for read/write in compatibility mode. Upon calling
1226 * the FCB must have the drive_number, file_name, and file_extension
1227 * fields filled and all other bytes cleared.
1229 static void INT21_OpenFileUsingFCB( CONTEXT86
*context
)
1237 BY_HANDLE_FILE_INFORMATION info
;
1240 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1241 if (fcb
->drive_number
== 0xff) {
1242 xfcb
= (struct XFCB
*) fcb
;
1243 fcb
= (struct FCB
*) xfcb
->fcb
;
1247 file_path
[0] = 'A' + INT21_MapDrive( fcb
->drive_number
);
1249 if (AL_result
== 0) {
1251 pos
= &file_path
[2];
1252 memcpy(pos
, fcb
->file_name
, 8);
1255 pos
= strchr(pos
, ' ');
1258 memcpy(pos
, fcb
->file_extension
, 3);
1261 pos
= strchr(pos
, ' ');
1264 handle
= (HANDLE
) _lopen(file_path
, OF_READWRITE
);
1265 if (handle
== INVALID_HANDLE_VALUE
) {
1266 TRACE("_lopen(\"%s\") failed: INVALID_HANDLE_VALUE\n", file_path
);
1267 AL_result
= 0xff; /* failed */
1269 hfile16
= Win32HandleToDosFileHandle(handle
);
1270 if (hfile16
== HFILE_ERROR16
) {
1271 TRACE("Win32HandleToDosFileHandle(%p) failed: HFILE_ERROR\n", handle
);
1272 CloseHandle(handle
);
1273 AL_result
= 0xff; /* failed */
1274 } else if (hfile16
> 255) {
1275 TRACE("hfile16 (=%d) larger than 255 for \"%s\"\n", hfile16
, file_path
);
1277 AL_result
= 0xff; /* failed */
1279 if (!GetFileInformationByHandle(handle
, &info
)) {
1280 TRACE("GetFileInformationByHandle(%d, %p) for \"%s\" failed\n",
1281 hfile16
, handle
, file_path
);
1283 AL_result
= 0xff; /* failed */
1285 fcb
->drive_number
= file_path
[0] - 'A' + 1;
1286 fcb
->current_block_number
= 0;
1287 fcb
->logical_record_size
= 128;
1288 fcb
->file_size
= info
.nFileSizeLow
;
1289 FileTimeToDosDateTime(&info
.ftLastWriteTime
,
1290 &fcb
->date_of_last_write
, &fcb
->time_of_last_write
);
1291 fcb
->file_number
= hfile16
;
1292 fcb
->attributes
= 0xc2;
1293 fcb
->starting_cluster
= 0; /* don't know correct init value */
1294 fcb
->sequence_number
= 0; /* don't know correct init value */
1295 fcb
->file_attributes
= info
.dwFileAttributes
;
1296 /* The following fields are not initialized */
1297 /* by the native function: */
1299 /* record_within_current_block */
1300 /* random_access_record_number */
1302 TRACE("successful opened file \"%s\" as %d (handle %p)\n",
1303 file_path
, hfile16
, handle
);
1304 AL_result
= 0x00; /* successful */
1309 SET_AL(context
, AL_result
);
1313 /***********************************************************************
1314 * INT21_CloseFileUsingFCB
1316 * Handler for function 0x10.
1319 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1326 * Closes a FCB file.
1328 static void INT21_CloseFileUsingFCB( CONTEXT86
*context
)
1334 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1335 if (fcb
->drive_number
== 0xff) {
1336 xfcb
= (struct XFCB
*) fcb
;
1337 fcb
= (struct FCB
*) xfcb
->fcb
;
1340 if (_lclose16((HFILE16
) fcb
->file_number
) != 0) {
1341 TRACE("_lclose16(%d) failed\n", fcb
->file_number
);
1342 AL_result
= 0xff; /* failed */
1344 TRACE("successful closed file %d\n", fcb
->file_number
);
1345 AL_result
= 0x00; /* successful */
1347 SET_AL(context
, AL_result
);
1351 /***********************************************************************
1352 * INT21_SequentialReadFromFCB
1354 * Handler for function 0x14.
1357 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1361 * 1: end of file, no data read
1362 * 2: segment wrap in DTA, no data read (not returned now)
1363 * 3: end of file, partial record read
1366 * Reads a record with the size FCB->logical_record_size from the FCB
1367 * to the disk transfer area. The position of the record is specified
1368 * with FCB->current_block_number and FCB->record_within_current_block.
1369 * Then FCB->current_block_number and FCB->record_within_current_block
1370 * are updated to point to the next record. If a partial record is
1371 * read, it is filled with zeros up to the FCB->logical_record_size.
1373 static void INT21_SequentialReadFromFCB( CONTEXT86
*context
)
1378 DWORD record_number
;
1380 BYTE
*disk_transfer_area
;
1384 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1385 if (fcb
->drive_number
== 0xff) {
1386 xfcb
= (struct XFCB
*) fcb
;
1387 fcb
= (struct FCB
*) xfcb
->fcb
;
1390 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1391 if (handle
== INVALID_HANDLE_VALUE
) {
1392 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1394 AL_result
= 0x01; /* end of file, no data read */
1396 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1397 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1398 if (position
!= record_number
* fcb
->logical_record_size
) {
1399 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1400 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1401 AL_result
= 0x01; /* end of file, no data read */
1403 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1404 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1405 if (bytes_read
!= fcb
->logical_record_size
) {
1406 TRACE("_lread(%d, %p, %d) failed with %d\n",
1407 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1408 if (bytes_read
== 0) {
1409 AL_result
= 0x01; /* end of file, no data read */
1411 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1412 AL_result
= 0x03; /* end of file, partial record read */
1415 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1416 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1417 AL_result
= 0x00; /* successful */
1421 if (AL_result
== 0x00 || AL_result
== 0x03) {
1422 if (fcb
->record_within_current_block
== 127) {
1423 fcb
->record_within_current_block
= 0;
1424 fcb
->current_block_number
++;
1426 fcb
->record_within_current_block
++;
1429 SET_AL(context
, AL_result
);
1433 /***********************************************************************
1434 * INT21_SequentialWriteToFCB
1436 * Handler for function 0x15.
1439 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1444 * 2: segment wrap in DTA (not returned now)
1447 * Writes a record with the size FCB->logical_record_size from the disk
1448 * transfer area to the FCB. The position of the record is specified
1449 * with FCB->current_block_number and FCB->record_within_current_block.
1450 * Then FCB->current_block_number and FCB->record_within_current_block
1451 * are updated to point to the next record.
1453 static void INT21_SequentialWriteToFCB( CONTEXT86
*context
)
1458 DWORD record_number
;
1460 BYTE
*disk_transfer_area
;
1464 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1465 if (fcb
->drive_number
== 0xff) {
1466 xfcb
= (struct XFCB
*) fcb
;
1467 fcb
= (struct FCB
*) xfcb
->fcb
;
1470 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1471 if (handle
== INVALID_HANDLE_VALUE
) {
1472 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1474 AL_result
= 0x01; /* disk full */
1476 record_number
= 128 * fcb
->current_block_number
+ fcb
->record_within_current_block
;
1477 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1478 if (position
!= record_number
* fcb
->logical_record_size
) {
1479 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1480 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1481 AL_result
= 0x01; /* disk full */
1483 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1484 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1485 if (bytes_written
!= fcb
->logical_record_size
) {
1486 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1487 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1488 AL_result
= 0x01; /* disk full */
1490 TRACE("successful written %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1491 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1492 AL_result
= 0x00; /* successful */
1496 if (AL_result
== 0x00) {
1497 if (fcb
->record_within_current_block
== 127) {
1498 fcb
->record_within_current_block
= 0;
1499 fcb
->current_block_number
++;
1501 fcb
->record_within_current_block
++;
1504 SET_AL(context
, AL_result
);
1508 /***********************************************************************
1509 * INT21_ReadRandomRecordFromFCB
1511 * Handler for function 0x21.
1514 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1518 * 1: end of file, no data read
1519 * 2: segment wrap in DTA, no data read (not returned now)
1520 * 3: end of file, partial record read
1523 * Reads a record with the size FCB->logical_record_size from
1524 * the FCB to the disk transfer area. The position of the record
1525 * is specified with FCB->random_access_record_number. The
1526 * FCB->random_access_record_number is not updated. If a partial record
1527 * is read, it is filled with zeros up to the FCB->logical_record_size.
1529 static void INT21_ReadRandomRecordFromFCB( CONTEXT86
*context
)
1534 DWORD record_number
;
1536 BYTE
*disk_transfer_area
;
1540 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1541 if (fcb
->drive_number
== 0xff) {
1542 xfcb
= (struct XFCB
*) fcb
;
1543 fcb
= (struct FCB
*) xfcb
->fcb
;
1546 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1547 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1548 if (handle
== INVALID_HANDLE_VALUE
) {
1549 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1551 AL_result
= 0x01; /* end of file, no data read */
1553 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1554 if (position
!= record_number
* fcb
->logical_record_size
) {
1555 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1556 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1557 AL_result
= 0x01; /* end of file, no data read */
1559 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1560 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1561 if (bytes_read
!= fcb
->logical_record_size
) {
1562 TRACE("_lread(%d, %p, %d) failed with %d\n",
1563 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_read
);
1564 if (bytes_read
== 0) {
1565 AL_result
= 0x01; /* end of file, no data read */
1567 memset(&disk_transfer_area
[bytes_read
], 0, fcb
->logical_record_size
- bytes_read
);
1568 AL_result
= 0x03; /* end of file, partial record read */
1571 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1572 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1573 AL_result
= 0x00; /* successful */
1577 fcb
->current_block_number
= record_number
/ 128;
1578 fcb
->record_within_current_block
= record_number
% 128;
1579 SET_AL(context
, AL_result
);
1583 /***********************************************************************
1584 * INT21_WriteRandomRecordToFCB
1586 * Handler for function 0x22.
1589 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1594 * 2: segment wrap in DTA (not returned now)
1597 * Writes a record with the size FCB->logical_record_size from
1598 * the disk transfer area to the FCB. The position of the record
1599 * is specified with FCB->random_access_record_number. The
1600 * FCB->random_access_record_number is not updated.
1602 static void INT21_WriteRandomRecordToFCB( CONTEXT86
*context
)
1607 DWORD record_number
;
1609 BYTE
*disk_transfer_area
;
1613 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1614 if (fcb
->drive_number
== 0xff) {
1615 xfcb
= (struct XFCB
*) fcb
;
1616 fcb
= (struct FCB
*) xfcb
->fcb
;
1619 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1620 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1621 if (handle
== INVALID_HANDLE_VALUE
) {
1622 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1624 AL_result
= 0x01; /* disk full */
1626 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1627 if (position
!= record_number
* fcb
->logical_record_size
) {
1628 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1629 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1630 AL_result
= 0x01; /* disk full */
1632 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1633 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, fcb
->logical_record_size
);
1634 if (bytes_written
!= fcb
->logical_record_size
) {
1635 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1636 fcb
->file_number
, disk_transfer_area
, fcb
->logical_record_size
, bytes_written
);
1637 AL_result
= 0x01; /* disk full */
1639 TRACE("successful written %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1640 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1641 AL_result
= 0x00; /* successful */
1645 fcb
->current_block_number
= record_number
/ 128;
1646 fcb
->record_within_current_block
= record_number
% 128;
1647 SET_AL(context
, AL_result
);
1651 /***********************************************************************
1652 * INT21_RandomBlockReadFromFCB
1654 * Handler for function 0x27.
1657 * CX [I/O] Number of records to read
1658 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1662 * 1: end of file, no data read
1663 * 2: segment wrap in DTA, no data read (not returned now)
1664 * 3: end of file, partial record read
1667 * Reads several records with the size FCB->logical_record_size from
1668 * the FCB to the disk transfer area. The number of records to be
1669 * read is specified in the CX register. The position of the first
1670 * record is specified with FCB->random_access_record_number. The
1671 * FCB->random_access_record_number, the FCB->current_block_number
1672 * and FCB->record_within_current_block are updated to point to the
1673 * next record after the records read. If a partial record is read,
1674 * it is filled with zeros up to the FCB->logical_record_size. The
1675 * CX register is set to the number of successfully read records.
1677 static void INT21_RandomBlockReadFromFCB( CONTEXT86
*context
)
1682 DWORD record_number
;
1684 BYTE
*disk_transfer_area
;
1685 UINT records_requested
;
1686 UINT bytes_requested
;
1691 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1692 if (fcb
->drive_number
== 0xff) {
1693 xfcb
= (struct XFCB
*) fcb
;
1694 fcb
= (struct FCB
*) xfcb
->fcb
;
1697 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1698 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1699 if (handle
== INVALID_HANDLE_VALUE
) {
1700 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1703 AL_result
= 0x01; /* end of file, no data read */
1705 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1706 if (position
!= record_number
* fcb
->logical_record_size
) {
1707 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1708 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1710 AL_result
= 0x01; /* end of file, no data read */
1712 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1713 records_requested
= CX_reg(context
);
1714 bytes_requested
= (UINT
) records_requested
* fcb
->logical_record_size
;
1715 bytes_read
= _lread((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1716 if (bytes_read
!= bytes_requested
) {
1717 TRACE("_lread(%d, %p, %d) failed with %d\n",
1718 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_read
);
1719 records_read
= bytes_read
/ fcb
->logical_record_size
;
1720 if (bytes_read
% fcb
->logical_record_size
== 0) {
1721 AL_result
= 0x01; /* end of file, no data read */
1724 memset(&disk_transfer_area
[bytes_read
], 0, records_read
* fcb
->logical_record_size
- bytes_read
);
1725 AL_result
= 0x03; /* end of file, partial record read */
1728 TRACE("successful read %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1729 bytes_read
, record_number
, position
, fcb
->file_number
, handle
);
1730 records_read
= records_requested
;
1731 AL_result
= 0x00; /* successful */
1735 record_number
+= records_read
;
1736 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1737 fcb
->current_block_number
= record_number
/ 128;
1738 fcb
->record_within_current_block
= record_number
% 128;
1739 SET_CX(context
, records_read
);
1740 SET_AL(context
, AL_result
);
1744 /***********************************************************************
1745 * INT21_RandomBlockWriteToFCB
1747 * Handler for function 0x28.
1750 * CX [I/O] Number of records to write
1751 * DX:DX [I/O] File control block (FCB or XFCB) of open file
1756 * 2: segment wrap in DTA (not returned now)
1759 * Writes several records with the size FCB->logical_record_size from
1760 * the disk transfer area to the FCB. The number of records to be
1761 * written is specified in the CX register. The position of the first
1762 * record is specified with FCB->random_access_record_number. The
1763 * FCB->random_access_record_number, the FCB->current_block_number
1764 * and FCB->record_within_current_block are updated to point to the
1765 * next record after the records written. The CX register is set to
1766 * the number of successfully written records.
1768 static void INT21_RandomBlockWriteToFCB( CONTEXT86
*context
)
1773 DWORD record_number
;
1775 BYTE
*disk_transfer_area
;
1776 UINT records_requested
;
1777 UINT bytes_requested
;
1779 UINT records_written
;
1782 fcb
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
1783 if (fcb
->drive_number
== 0xff) {
1784 xfcb
= (struct XFCB
*) fcb
;
1785 fcb
= (struct FCB
*) xfcb
->fcb
;
1788 memcpy(&record_number
, fcb
->random_access_record_number
, 4);
1789 handle
= DosFileHandleToWin32Handle((HFILE16
) fcb
->file_number
);
1790 if (handle
== INVALID_HANDLE_VALUE
) {
1791 TRACE("DosFileHandleToWin32Handle(%d) failed: INVALID_HANDLE_VALUE\n",
1793 records_written
= 0;
1794 AL_result
= 0x01; /* disk full */
1796 position
= SetFilePointer(handle
, record_number
* fcb
->logical_record_size
, NULL
, 0);
1797 if (position
!= record_number
* fcb
->logical_record_size
) {
1798 TRACE("seek(%d, %ld, 0) failed with %ld\n",
1799 fcb
->file_number
, record_number
* fcb
->logical_record_size
, position
);
1800 records_written
= 0;
1801 AL_result
= 0x01; /* disk full */
1803 disk_transfer_area
= INT21_GetCurrentDTA(context
);
1804 records_requested
= CX_reg(context
);
1805 bytes_requested
= (UINT
) records_requested
* fcb
->logical_record_size
;
1806 bytes_written
= _lwrite((HFILE
) handle
, disk_transfer_area
, bytes_requested
);
1807 if (bytes_written
!= bytes_requested
) {
1808 TRACE("_lwrite(%d, %p, %d) failed with %d\n",
1809 fcb
->file_number
, disk_transfer_area
, bytes_requested
, bytes_written
);
1810 records_written
= bytes_written
/ fcb
->logical_record_size
;
1811 AL_result
= 0x01; /* disk full */
1813 TRACE("successful write %d bytes from record %ld (position %ld) of file %d (handle %p)\n",
1814 bytes_written
, record_number
, position
, fcb
->file_number
, handle
);
1815 records_written
= records_requested
;
1816 AL_result
= 0x00; /* successful */
1820 record_number
+= records_written
;
1821 memcpy(fcb
->random_access_record_number
, &record_number
, 4);
1822 fcb
->current_block_number
= record_number
/ 128;
1823 fcb
->record_within_current_block
= record_number
% 128;
1824 SET_CX(context
, records_written
);
1825 SET_AL(context
, AL_result
);
1829 /***********************************************************************
1830 * INT21_CreateDirectory
1834 * - subfunction 0x39 of function 0x71
1835 * - subfunction 0xff of function 0x43 (CL == 0x39)
1837 static BOOL
INT21_CreateDirectory( CONTEXT86
*context
)
1839 WCHAR dirW
[MAX_PATH
];
1840 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
1844 TRACE( "CREATE DIRECTORY %s\n", dirA
);
1846 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
1848 if (CreateDirectoryW(dirW
, NULL
))
1852 * FIXME: CreateDirectory's LastErrors will clash with the ones
1853 * used by DOS. AH=39 only returns 3 (path not found) and
1854 * 5 (access denied), while CreateDirectory return several
1855 * ones. Remap some of them. -Marcus
1857 switch (GetLastError())
1859 case ERROR_ALREADY_EXISTS
:
1860 case ERROR_FILENAME_EXCED_RANGE
:
1861 case ERROR_DISK_FULL
:
1862 SetLastError(ERROR_ACCESS_DENIED
);
1872 /***********************************************************************
1873 * INT21_ExtendedCountryInformation
1875 * Handler for function 0x65.
1877 static void INT21_ExtendedCountryInformation( CONTEXT86
*context
)
1879 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN( context
, context
->SegEs
, context
->Edi
);
1881 TRACE( "GET EXTENDED COUNTRY INFORMATION, subfunction %02x\n",
1885 * Check subfunctions that are passed country and code page.
1887 if (AL_reg(context
) >= 0x01 && AL_reg(context
) <= 0x07)
1889 WORD country
= DX_reg(context
);
1890 WORD codepage
= BX_reg(context
);
1892 if (country
!= 0xffff && country
!= INT21_GetSystemCountryCode())
1893 FIXME( "Requested info on non-default country %04x\n", country
);
1895 if (codepage
!= 0xffff && codepage
!= GetOEMCP())
1896 FIXME( "Requested info on non-default code page %04x\n", codepage
);
1899 switch (AL_reg(context
)) {
1900 case 0x00: /* SET GENERAL INTERNATIONALIZATION INFO */
1901 INT_BARF( context
, 0x21 );
1902 SET_CFLAG( context
);
1905 case 0x01: /* GET GENERAL INTERNATIONALIZATION INFO */
1906 TRACE( "Get general internationalization info\n" );
1907 dataptr
[0] = 0x01; /* Info ID */
1908 *(WORD
*)(dataptr
+1) = 38; /* Size of the following info */
1909 *(WORD
*)(dataptr
+3) = INT21_GetSystemCountryCode(); /* Country ID */
1910 *(WORD
*)(dataptr
+5) = GetOEMCP(); /* Code page */
1911 INT21_FillCountryInformation( dataptr
+ 7 );
1912 SET_CX( context
, 41 ); /* Size of returned info */
1915 case 0x02: /* GET POINTER TO UPPERCASE TABLE */
1916 case 0x04: /* GET POINTER TO FILENAME UPPERCASE TABLE */
1917 TRACE( "Get pointer to uppercase table\n" );
1918 dataptr
[0] = AL_reg(context
); /* Info ID */
1919 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1920 offsetof(INT21_HEAP
, uppercase_size
) );
1921 SET_CX( context
, 5 ); /* Size of returned info */
1924 case 0x03: /* GET POINTER TO LOWERCASE TABLE */
1925 TRACE( "Get pointer to lowercase table\n" );
1926 dataptr
[0] = 0x03; /* Info ID */
1927 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1928 offsetof(INT21_HEAP
, lowercase_size
) );
1929 SET_CX( context
, 5 ); /* Size of returned info */
1932 case 0x05: /* GET POINTER TO FILENAME TERMINATOR TABLE */
1933 TRACE("Get pointer to filename terminator table\n");
1934 dataptr
[0] = 0x05; /* Info ID */
1935 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1936 offsetof(INT21_HEAP
, filename_size
) );
1937 SET_CX( context
, 5 ); /* Size of returned info */
1940 case 0x06: /* GET POINTER TO COLLATING SEQUENCE TABLE */
1941 TRACE("Get pointer to collating sequence table\n");
1942 dataptr
[0] = 0x06; /* Info ID */
1943 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1944 offsetof(INT21_HEAP
, collating_size
) );
1945 SET_CX( context
, 5 ); /* Size of returned info */
1948 case 0x07: /* GET POINTER TO DBCS LEAD BYTE TABLE */
1949 TRACE("Get pointer to DBCS lead byte table\n");
1950 dataptr
[0] = 0x07; /* Info ID */
1951 *(DWORD
*)(dataptr
+1) = MAKESEGPTR( INT21_GetHeapSelector( context
),
1952 offsetof(INT21_HEAP
, dbcs_size
) );
1953 SET_CX( context
, 5 ); /* Size of returned info */
1956 case 0x20: /* CAPITALIZE CHARACTER */
1957 case 0xa0: /* CAPITALIZE FILENAME CHARACTER */
1958 TRACE("Convert char to uppercase\n");
1959 SET_DL( context
, toupper(DL_reg(context
)) );
1962 case 0x21: /* CAPITALIZE STRING */
1963 case 0xa1: /* CAPITALIZE COUNTED FILENAME STRING */
1964 TRACE("Convert string to uppercase with length\n");
1966 char *ptr
= (char *)CTX_SEG_OFF_TO_LIN( context
,
1969 WORD len
= CX_reg(context
);
1970 while (len
--) { *ptr
= toupper(*ptr
); ptr
++; }
1974 case 0x22: /* CAPITALIZE ASCIIZ STRING */
1975 case 0xa2: /* CAPITALIZE ASCIIZ FILENAME */
1976 TRACE("Convert ASCIIZ string to uppercase\n");
1977 _strupr( (LPSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
) );
1980 case 0x23: /* DETERMINE IF CHARACTER REPRESENTS YES/NO RESPONSE */
1981 INT_BARF( context
, 0x21 );
1982 SET_CFLAG( context
);
1986 INT_BARF( context
, 0x21 );
1993 /***********************************************************************
1994 * INT21_FileAttributes
1998 * - subfunction 0x43 of function 0x71
2000 static BOOL
INT21_FileAttributes( CONTEXT86
*context
,
2004 WCHAR fileW
[MAX_PATH
];
2005 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
2014 switch (subfunction
)
2016 case 0x00: /* GET FILE ATTRIBUTES */
2017 TRACE( "GET FILE ATTRIBUTES for %s\n", fileA
);
2018 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2020 result
= GetFileAttributesW( fileW
);
2021 if (result
== INVALID_FILE_ATTRIBUTES
)
2025 SET_CX( context
, (WORD
)result
);
2027 SET_AX( context
, (WORD
)result
); /* DR DOS */
2031 case 0x01: /* SET FILE ATTRIBUTES */
2032 TRACE( "SET FILE ATTRIBUTES 0x%02x for %s\n",
2033 CX_reg(context
), fileA
);
2034 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2036 if (!SetFileAttributesW( fileW
, CX_reg(context
) ))
2040 case 0x02: /* GET COMPRESSED FILE SIZE */
2041 TRACE( "GET COMPRESSED FILE SIZE for %s\n", fileA
);
2042 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2044 result
= GetCompressedFileSizeW( fileW
, NULL
);
2045 if (result
== INVALID_FILE_SIZE
)
2049 SET_AX( context
, LOWORD(result
) );
2050 SET_DX( context
, HIWORD(result
) );
2054 case 0x03: /* SET FILE LAST-WRITTEN DATE AND TIME */
2056 INT_BARF( context
, 0x21 );
2059 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
2060 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2062 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2063 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2064 NULL
, OPEN_EXISTING
, 0, 0 );
2065 if (handle
== INVALID_HANDLE_VALUE
)
2068 DosDateTimeToFileTime( DI_reg(context
),
2071 status
= SetFileTime( handle
, NULL
, NULL
, &filetime
);
2073 CloseHandle( handle
);
2078 case 0x04: /* GET FILE LAST-WRITTEN DATE AND TIME */
2080 INT_BARF( context
, 0x21 );
2083 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, file %s\n", fileA
);
2084 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2086 handle
= CreateFileW( fileW
, GENERIC_READ
,
2087 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2088 NULL
, OPEN_EXISTING
, 0, 0 );
2089 if (handle
== INVALID_HANDLE_VALUE
)
2092 status
= GetFileTime( handle
, NULL
, NULL
, &filetime
);
2095 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2096 SET_DI( context
, date
);
2097 SET_CX( context
, time
);
2100 CloseHandle( handle
);
2105 case 0x05: /* SET FILE LAST ACCESS DATE */
2107 INT_BARF( context
, 0x21 );
2110 TRACE( "SET FILE LAST ACCESS DATE, file %s\n", fileA
);
2111 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2113 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2114 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2115 NULL
, OPEN_EXISTING
, 0, 0 );
2116 if (handle
== INVALID_HANDLE_VALUE
)
2119 DosDateTimeToFileTime( DI_reg(context
),
2122 status
= SetFileTime( handle
, NULL
, &filetime
, NULL
);
2124 CloseHandle( handle
);
2129 case 0x06: /* GET FILE LAST ACCESS DATE */
2131 INT_BARF( context
, 0x21 );
2134 TRACE( "GET FILE LAST ACCESS DATE, file %s\n", fileA
);
2135 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
2137 handle
= CreateFileW( fileW
, GENERIC_READ
,
2138 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2139 NULL
, OPEN_EXISTING
, 0, 0 );
2140 if (handle
== INVALID_HANDLE_VALUE
)
2143 status
= GetFileTime( handle
, NULL
, &filetime
, NULL
);
2146 FileTimeToDosDateTime( &filetime
, &date
, NULL
);
2147 SET_DI( context
, date
);
2150 CloseHandle( handle
);
2155 case 0x07: /* SET FILE CREATION DATE AND TIME */
2157 INT_BARF( context
, 0x21 );
2160 TRACE( "SET FILE CREATION DATE AND TIME, file %s\n", fileA
);
2162 handle
= CreateFileW( fileW
, GENERIC_WRITE
,
2163 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2164 NULL
, OPEN_EXISTING
, 0, 0 );
2165 if (handle
== INVALID_HANDLE_VALUE
)
2169 * FIXME: SI has number of 10-millisecond units past time in CX.
2171 DosDateTimeToFileTime( DI_reg(context
),
2174 status
= SetFileTime( handle
, &filetime
, NULL
, NULL
);
2176 CloseHandle( handle
);
2181 case 0x08: /* GET FILE CREATION DATE AND TIME */
2183 INT_BARF( context
, 0x21 );
2186 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2189 handle
= CreateFileW( fileW
, GENERIC_READ
,
2190 FILE_SHARE_READ
| FILE_SHARE_WRITE
,
2191 NULL
, OPEN_EXISTING
, 0, 0 );
2192 if (handle
== INVALID_HANDLE_VALUE
)
2195 status
= GetFileTime( handle
, &filetime
, NULL
, NULL
);
2198 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2199 SET_DI( context
, date
);
2200 SET_CX( context
, time
);
2202 * FIXME: SI has number of 10-millisecond units past
2205 SET_SI( context
, 0 );
2208 CloseHandle(handle
);
2213 case 0xff: /* EXTENDED-LENGTH FILENAME OPERATIONS */
2214 if (islong
|| context
->Ebp
!= 0x5053)
2215 INT_BARF( context
, 0x21 );
2218 switch(CL_reg(context
))
2221 if (!INT21_CreateDirectory( context
))
2226 if (!INT21_RenameFile( context
))
2231 INT_BARF( context
, 0x21 );
2237 INT_BARF( context
, 0x21 );
2244 /***********************************************************************
2245 * INT21_FileDateTime
2247 * Handler for function 0x57.
2249 static BOOL
INT21_FileDateTime( CONTEXT86
*context
)
2251 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2255 switch (AL_reg(context
)) {
2256 case 0x00: /* Get last-written stamp */
2257 TRACE( "GET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2260 if (!GetFileTime( handle
, NULL
, NULL
, &filetime
))
2262 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2263 SET_DX( context
, date
);
2264 SET_CX( context
, time
);
2268 case 0x01: /* Set last-written stamp */
2269 TRACE( "SET FILE LAST-WRITTEN DATE AND TIME, handle %d\n",
2272 DosDateTimeToFileTime( DX_reg(context
),
2275 if (!SetFileTime( handle
, NULL
, NULL
, &filetime
))
2280 case 0x04: /* Get last access stamp, DOS 7 */
2281 TRACE( "GET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2284 if (!GetFileTime( handle
, NULL
, &filetime
, NULL
))
2286 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2287 SET_DX( context
, date
);
2288 SET_CX( context
, time
);
2292 case 0x05: /* Set last access stamp, DOS 7 */
2293 TRACE( "SET FILE LAST ACCESS DATE AND TIME, handle %d\n",
2296 DosDateTimeToFileTime( DX_reg(context
),
2299 if (!SetFileTime( handle
, NULL
, &filetime
, NULL
))
2304 case 0x06: /* Get creation stamp, DOS 7 */
2305 TRACE( "GET FILE CREATION DATE AND TIME, handle %d\n",
2308 if (!GetFileTime( handle
, &filetime
, NULL
, NULL
))
2310 FileTimeToDosDateTime( &filetime
, &date
, &time
);
2311 SET_DX( context
, date
);
2312 SET_CX( context
, time
);
2314 * FIXME: SI has number of 10-millisecond units past time in CX.
2316 SET_SI( context
, 0 );
2320 case 0x07: /* Set creation stamp, DOS 7 */
2321 TRACE( "SET FILE CREATION DATE AND TIME, handle %d\n",
2325 * FIXME: SI has number of 10-millisecond units past time in CX.
2327 DosDateTimeToFileTime( DX_reg(context
),
2330 if (!SetFileTime( handle
, &filetime
, NULL
, NULL
))
2336 INT_BARF( context
, 0x21 );
2344 /***********************************************************************
2347 * Handler for functions 0x51 and 0x62.
2349 static void INT21_GetPSP( CONTEXT86
*context
)
2351 TRACE( "GET CURRENT PSP ADDRESS (%02x)\n", AH_reg(context
) );
2354 * FIXME: should we return the original DOS PSP upon
2357 if (!ISV86(context
) && DOSVM_IsWin16())
2358 SET_BX( context
, LOWORD(GetCurrentPDB16()) );
2360 SET_BX( context
, DOSVM_psp
);
2363 static inline void setword( BYTE
*ptr
, WORD w
)
2366 ptr
[1] = (BYTE
)(w
>> 8);
2369 static void CreateBPB(int drive
, BYTE
*data
, BOOL16 limited
)
2370 /* limited == TRUE is used with INT 0x21/0x440d */
2372 /* FIXME: we're forcing some values without checking that those are valid */
2377 setword(&data
[3], 0);
2379 setword(&data
[6], 240);
2380 setword(&data
[8], 64000);
2382 setword(&data
[0x0b], 40);
2383 setword(&data
[0x0d], 56);
2384 setword(&data
[0x0f], 2);
2385 setword(&data
[0x11], 0);
2388 setword(&data
[0x1f], 800);
2390 setword(&data
[0x22], 1);
2397 setword(&data
[3], 0);
2399 setword(&data
[6], 240);
2400 setword(&data
[8], 2880);
2402 setword(&data
[0x0b], 6);
2403 setword(&data
[0x0d], 18);
2404 setword(&data
[0x0f], 2);
2405 setword(&data
[0x11], 0);
2408 setword(&data
[0x1f], 80);
2410 setword(&data
[0x22], 2);
2415 inline DWORD
INT21_Ioctl_CylHeadSect2Lin(DWORD cyl
, WORD head
, WORD sec
, WORD cyl_cnt
, WORD head_cnt
, WORD sec_cnt
)
2417 DWORD res
= (cyl
* head_cnt
*sec_cnt
+ head
* sec_cnt
+ sec
);
2421 /***********************************************************************
2424 * Handler for block device IOCTLs.
2426 static void INT21_Ioctl_Block( CONTEXT86
*context
)
2429 BYTE drive
= INT21_MapDrive( BL_reg(context
) );
2430 WCHAR drivespec
[4] = {'A', ':', '\\', 0};
2433 drivespec
[0] += drive
;
2434 drivetype
= GetDriveTypeW( drivespec
);
2436 RESET_CFLAG(context
);
2437 if (drivetype
== DRIVE_UNKNOWN
|| drivetype
== DRIVE_NO_ROOT_DIR
)
2439 TRACE( "IOCTL - SUBFUNCTION %d - INVALID DRIVE %c:\n",
2440 AL_reg(context
), 'A' + drive
);
2441 SetLastError( ERROR_INVALID_DRIVE
);
2442 SET_AX( context
, ERROR_INVALID_DRIVE
);
2443 SET_CFLAG( context
);
2447 switch (AL_reg(context
))
2449 case 0x04: /* READ FROM BLOCK DEVICE CONTROL CHANNEL */
2450 case 0x05: /* WRITE TO BLOCK DEVICE CONTROL CHANNEL */
2451 INT_BARF( context
, 0x21 );
2454 case 0x08: /* CHECK IF BLOCK DEVICE REMOVABLE */
2455 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOVABLE - %c:\n",
2458 if (drivetype
== DRIVE_REMOVABLE
)
2459 SET_AX( context
, 0 ); /* removable */
2461 SET_AX( context
, 1 ); /* not removable */
2464 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
2465 TRACE( "IOCTL - CHECK IF BLOCK DEVICE REMOTE - %c:\n",
2468 if (drivetype
== DRIVE_REMOTE
)
2469 SET_DX( context
, (1<<9) | (1<<12) ); /* remote + no direct IO */
2471 SET_DX( context
, 0 ); /* FIXME: use driver attr here */
2474 case 0x0d: /* GENERIC BLOCK DEVICE REQUEST */
2475 /* Get pointer to IOCTL parameter block */
2476 dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
2478 switch (CX_reg(context
))
2480 case 0x0841: /* write logical device track */
2481 TRACE( "GENERIC IOCTL - Write logical device track - %c:\n",
2484 WORD head
= *(WORD
*)(dataptr
+1);
2485 WORD cyl
= *(WORD
*)(dataptr
+3);
2486 WORD sect
= *(WORD
*)(dataptr
+5);
2487 WORD nrsect
= *(WORD
*)(dataptr
+7);
2488 BYTE
*data
= CTX_SEG_OFF_TO_LIN(context
, *(WORD
*)(dataptr
+11), *(WORD
*)(dataptr
+9));
2489 WORD cyl_cnt
, head_cnt
, sec_cnt
;
2491 /* FIXME: we're faking some values here */
2497 SET_AX( context
, ERROR_WRITE_FAULT
);
2508 if (!DOSVM_RawWrite(drive
, INT21_Ioctl_CylHeadSect2Lin(cyl
, head
, sect
, cyl_cnt
, head_cnt
, sec_cnt
), nrsect
, data
, FALSE
))
2510 SET_AX( context
, ERROR_WRITE_FAULT
);
2516 case 0x084a: /* lock logical volume */
2517 TRACE( "GENERIC IOCTL - Lock logical volume, level %d mode %d - %c:\n",
2518 BH_reg(context
), DX_reg(context
), 'A' + drive
);
2521 case 0x0860: /* get device parameters */
2522 /* FIXME: we're faking some values here */
2523 /* used by w4wgrp's winfile */
2524 memset(dataptr
, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
2526 dataptr
[6] = 0; /* media type */
2529 dataptr
[1] = 0x05; /* fixed disk */
2530 setword(&dataptr
[2], 0x01); /* non removable */
2531 setword(&dataptr
[4], 0x300); /* # of cylinders */
2535 dataptr
[1] = 0x07; /* block dev, floppy */
2536 setword(&dataptr
[2], 0x02); /* removable */
2537 setword(&dataptr
[4], 80); /* # of cylinders */
2539 CreateBPB(drive
, &dataptr
[7], TRUE
);
2540 RESET_CFLAG(context
);
2543 case 0x0861: /* read logical device track */
2544 TRACE( "GENERIC IOCTL - Read logical device track - %c:\n",
2547 WORD head
= *(WORD
*)(dataptr
+1);
2548 WORD cyl
= *(WORD
*)(dataptr
+3);
2549 WORD sect
= *(WORD
*)(dataptr
+5);
2550 WORD nrsect
= *(WORD
*)(dataptr
+7);
2551 BYTE
*data
= CTX_SEG_OFF_TO_LIN(context
, *(WORD
*)(dataptr
+11), *(WORD
*)(dataptr
+9));
2552 WORD cyl_cnt
, head_cnt
, sec_cnt
;
2554 /* FIXME: we're faking some values here */
2568 if (!DOSVM_RawRead(drive
, INT21_Ioctl_CylHeadSect2Lin(cyl
, head
, sect
, cyl_cnt
, head_cnt
, sec_cnt
), nrsect
, data
, FALSE
))
2570 SET_AX( context
, ERROR_READ_FAULT
);
2576 case 0x0866: /* get volume serial number */
2578 WCHAR label
[12],fsname
[9];
2581 drivespec
[0] += drive
;
2582 GetVolumeInformationW(drivespec
, label
, 12, &serial
, NULL
, NULL
, fsname
, 9);
2583 *(WORD
*)dataptr
= 0;
2584 memcpy(dataptr
+2,&serial
,4);
2585 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, dataptr
+ 6, 11, NULL
, NULL
);
2586 WideCharToMultiByte(CP_OEMCP
, 0, fsname
, 8, dataptr
+ 17, 8, NULL
, NULL
);
2590 case 0x086a: /* unlock logical volume */
2591 TRACE( "GENERIC IOCTL - Logical volume unlocked - %c:\n",
2595 case 0x086f: /* get drive map information */
2596 memset(dataptr
+1, '\0', dataptr
[0]-1);
2597 dataptr
[1] = dataptr
[0];
2598 dataptr
[2] = 0x07; /* protected mode driver; no eject; no notification */
2599 dataptr
[3] = 0xFF; /* no physical drive */
2603 /* Trial and error implementation */
2604 SET_AX( context
, drivetype
== DRIVE_UNKNOWN
? 0x0f : 0x01 );
2605 SET_CFLAG(context
); /* Seems to be set all the time */
2609 INT_BARF( context
, 0x21 );
2613 case 0x0e: /* GET LOGICAL DRIVE MAP */
2614 TRACE( "IOCTL - GET LOGICAL DRIVE MAP - %c:\n",
2616 /* FIXME: this is not correct if drive has mappings */
2617 SET_AL( context
, 0 ); /* drive has no mapping */
2620 case 0x0f: /* SET LOGICAL DRIVE MAP */
2622 WCHAR dev
[3], tgt
[4];
2624 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
2625 INT21_DriveName( BL_reg(context
)));
2626 dev
[0] = 'A' + drive
; dev
[1] = ':'; dev
[2] = 0;
2627 tgt
[0] = 'A' + drive
+ 1; dev
[1] = ':'; dev
[2] = '\\'; dev
[3] = 0;
2628 if (!DefineDosDeviceW(DDD_RAW_TARGET_PATH
, dev
, tgt
))
2631 SET_AX( context
, 0x000F ); /* invalid drive */
2636 case 0x11: /* QUERY GENERIC IOCTL CAPABILITY */
2638 INT_BARF( context
, 0x21 );
2643 /***********************************************************************
2644 * INT21_IoctlScsiMgrHandler
2646 * IOCTL handler for the SCSIMGR device.
2648 static void INT21_IoctlScsiMgrHandler( CONTEXT86
*context
)
2650 switch (AL_reg(context
))
2652 case 0x00: /* GET DEVICE INFORMATION */
2653 SET_DX( context
, 0xc0c0 );
2656 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2657 DOSVM_ASPIHandler(context
);
2660 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2661 SET_DX( context
, 0 );
2664 case 0x01: /* SET DEVICE INFORMATION */
2665 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2666 case 0x06: /* GET INPUT STATUS */
2667 case 0x07: /* GET OUTPUT STATUS */
2668 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2669 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2671 INT_BARF( context
, 0x21 );
2677 /***********************************************************************
2678 * INT21_IoctlEMSHandler
2680 * IOCTL handler for the EMXXXX0 device.
2682 static void INT21_IoctlEMSHandler( CONTEXT86
*context
)
2684 EMS_Ioctl_Handler(context
);
2688 /***********************************************************************
2689 * INT21_IoctlHPScanHandler
2691 * IOCTL handler for the HPSCAN device.
2693 static void INT21_IoctlHPScanHandler( CONTEXT86
*context
)
2695 switch (AL_reg(context
))
2697 case 0x00: /* GET DEVICE INFORMATION */
2698 SET_DX( context
, 0xc0c0 );
2701 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2702 SET_DX( context
, 0 );
2705 case 0x01: /* SET DEVICE INFORMATION */
2706 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2707 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2708 case 0x06: /* GET INPUT STATUS */
2709 case 0x07: /* GET OUTPUT STATUS */
2710 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2711 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2713 INT_BARF( context
, 0x21 );
2719 /***********************************************************************
2722 * Handler for character device IOCTLs.
2724 static void INT21_Ioctl_Char( CONTEXT86
*context
)
2728 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
2730 status
= wine_server_handle_to_fd( handle
, 0, &fd
, NULL
);
2733 SET_AX( context
, RtlNtStatusToDosError(status
) );
2734 SET_CFLAG( context
);
2738 wine_server_release_fd( handle
, fd
);
2740 for (i
= 0; i
< NB_MAGIC_DEVICES
; i
++)
2742 if (!magic_devices
[i
].handle
) continue;
2743 if (magic_devices
[i
].dev
== st
.st_dev
&& magic_devices
[i
].ino
== st
.st_ino
)
2746 magic_devices
[i
].ioctl_handler( context
);
2751 /* no magic device found, do default handling */
2753 switch (AL_reg(context
))
2755 case 0x00: /* GET DEVICE INFORMATION */
2756 TRACE( "IOCTL - GET DEVICE INFORMATION - %d\n", BX_reg(context
) );
2757 if (S_ISCHR(st
.st_mode
))
2760 * Returns attribute word in DX:
2761 * Bit 14 - Device driver can process IOCTL requests.
2762 * Bit 13 - Output until busy supported.
2763 * Bit 11 - Driver supports OPEN/CLOSE calls.
2765 * Bit 7 - Set (indicates device).
2766 * Bit 6 - EOF on input.
2767 * Bit 5 - Raw (binary) mode.
2768 * Bit 4 - Device is special (uses int29).
2769 * Bit 3 - Clock device.
2770 * Bit 2 - NUL device.
2771 * Bit 1 - Standard output.
2772 * Bit 0 - Standard input.
2774 SET_DX( context
, 0x80c0 /* FIXME */ );
2779 * Returns attribute word in DX:
2780 * Bit 15 - File is remote.
2781 * Bit 14 - Don't set file date/time on closing.
2782 * Bit 11 - Media not removable.
2783 * Bit 8 - Generate int24 if no disk space on write
2784 * or read past end of file
2785 * Bit 7 - Clear (indicates file).
2786 * Bit 6 - File has not been written.
2787 * Bit 5..0 - Drive number (0=A:,...)
2789 * FIXME: Should check if file is on remote or removable drive.
2790 * FIXME: Should use drive file is located on (and not current).
2792 SET_DX( context
, 0x0140 + INT21_GetCurrentDrive() );
2796 case 0x0a: /* CHECK IF HANDLE IS REMOTE */
2797 TRACE( "IOCTL - CHECK IF HANDLE IS REMOTE - %d\n", BX_reg(context
) );
2799 * Returns attribute word in DX:
2800 * Bit 15 - Set if remote.
2801 * Bit 14 - Set if date/time not set on close.
2803 * FIXME: Should check if file is on remote drive.
2805 SET_DX( context
, 0 );
2808 case 0x01: /* SET DEVICE INFORMATION */
2809 case 0x02: /* READ FROM CHARACTER DEVICE CONTROL CHANNEL */
2810 case 0x03: /* WRITE TO CHARACTER DEVICE CONTROL CHANNEL */
2811 case 0x06: /* GET INPUT STATUS */
2812 case 0x07: /* GET OUTPUT STATUS */
2813 case 0x0c: /* GENERIC CHARACTER DEVICE REQUEST */
2814 case 0x10: /* QUERY GENERIC IOCTL CAPABILITY */
2816 INT_BARF( context
, 0x21 );
2822 /***********************************************************************
2825 * Handler for function 0x44.
2827 static void INT21_Ioctl( CONTEXT86
*context
)
2829 switch (AL_reg(context
))
2835 INT21_Ioctl_Char( context
);
2840 INT21_Ioctl_Block( context
);
2845 INT21_Ioctl_Char( context
);
2850 INT21_Ioctl_Block( context
);
2854 INT21_Ioctl_Char( context
);
2857 case 0x0b: /* SET SHARING RETRY COUNT */
2858 TRACE( "SET SHARING RETRY COUNT: Pause %d, retries %d.\n",
2859 CX_reg(context
), DX_reg(context
) );
2860 if (!CX_reg(context
))
2862 SET_AX( context
, 1 );
2863 SET_CFLAG( context
);
2867 DOSDEV_SetSharingRetry( CX_reg(context
), DX_reg(context
) );
2868 RESET_CFLAG( context
);
2873 INT21_Ioctl_Char( context
);
2879 INT21_Ioctl_Block( context
);
2883 INT21_Ioctl_Char( context
);
2887 INT21_Ioctl_Block( context
);
2890 case 0x12: /* DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION) */
2891 TRACE( "DR DOS - DETERMINE DOS TYPE (OBSOLETE FUNCTION)\n" );
2892 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2893 SET_AX( context
, 0x0001 ); /* Invalid function */
2896 case 0x52: /* DR DOS - DETERMINE DOS TYPE */
2897 TRACE( "DR DOS - DETERMINE DOS TYPE\n" );
2898 SET_CFLAG(context
); /* Error / This is not DR DOS. */
2899 SET_AX( context
, 0x0001 ); /* Invalid function */
2902 case 0xe0: /* Sun PC-NFS API */
2903 TRACE( "Sun PC-NFS API\n" );
2908 INT_BARF( context
, 0x21 );
2913 /***********************************************************************
2916 * Handler for function 0x73.
2918 static BOOL
INT21_Fat32( CONTEXT86
*context
)
2920 switch (AL_reg(context
))
2922 case 0x02: /* FAT32 - GET EXTENDED DPB */
2924 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
2925 WORD
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
2926 context
->SegEs
, context
->Edi
);
2927 INT21_DPB
*target
= (INT21_DPB
*)(ptr
+ 1);
2930 TRACE( "FAT32 - GET EXTENDED DPB %d\n", DL_reg(context
) );
2932 if ( CX_reg(context
) < sizeof(INT21_DPB
) + 2 || *ptr
< sizeof(INT21_DPB
) )
2934 SetLastError( ERROR_BAD_LENGTH
);
2938 if ( !INT21_FillDrivePB( drive
) )
2940 SetLastError( ERROR_INVALID_DRIVE
);
2944 source
= &INT21_GetHeapPointer()->misc_dpb_list
[drive
];
2946 *ptr
= sizeof(INT21_DPB
);
2947 memcpy( target
, source
, sizeof(INT21_DPB
));
2949 if (LOWORD(context
->Esi
) != 0xF1A6)
2951 target
->driver_header
= 0;
2956 FIXME( "Caller requested driver and next DPB pointers!\n" );
2961 case 0x03: /* FAT32 - GET EXTENDED FREE SPACE ON DRIVE */
2963 WCHAR dirW
[MAX_PATH
];
2964 char *dirA
= CTX_SEG_OFF_TO_LIN( context
,
2965 context
->SegDs
, context
->Edx
);
2966 BYTE
*data
= CTX_SEG_OFF_TO_LIN( context
,
2967 context
->SegEs
, context
->Edi
);
2968 DWORD cluster_sectors
;
2970 DWORD free_clusters
;
2971 DWORD total_clusters
;
2973 TRACE( "FAT32 - GET EXTENDED FREE SPACE ON DRIVE %s\n", dirA
);
2974 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
2976 if (CX_reg(context
) < 44)
2978 SetLastError( ERROR_BAD_LENGTH
);
2982 if (!GetDiskFreeSpaceW( dirW
, &cluster_sectors
, §or_bytes
,
2983 &free_clusters
, &total_clusters
))
2986 *(WORD
*) (data
+ 0) = 44; /* size of structure */
2987 *(WORD
*) (data
+ 2) = 0; /* version */
2988 *(DWORD
*)(data
+ 4) = cluster_sectors
;
2989 *(DWORD
*)(data
+ 8) = sector_bytes
;
2990 *(DWORD
*)(data
+ 12) = free_clusters
;
2991 *(DWORD
*)(data
+ 16) = total_clusters
;
2994 * Below we have free/total sectors and
2995 * free/total allocation units without adjustment
2996 * for compression. We fake both using cluster information.
2998 *(DWORD
*)(data
+ 20) = free_clusters
* cluster_sectors
;
2999 *(DWORD
*)(data
+ 24) = total_clusters
* cluster_sectors
;
3000 *(DWORD
*)(data
+ 28) = free_clusters
;
3001 *(DWORD
*)(data
+ 32) = total_clusters
;
3004 * Between (data + 36) and (data + 43) there
3005 * are eight reserved bytes.
3011 INT_BARF( context
, 0x21 );
3017 static void INT21_ConvertFindDataWtoA(WIN32_FIND_DATAA
*dataA
,
3018 const WIN32_FIND_DATAW
*dataW
)
3020 dataA
->dwFileAttributes
= dataW
->dwFileAttributes
;
3021 dataA
->ftCreationTime
= dataW
->ftCreationTime
;
3022 dataA
->ftLastAccessTime
= dataW
->ftLastAccessTime
;
3023 dataA
->ftLastWriteTime
= dataW
->ftLastWriteTime
;
3024 dataA
->nFileSizeHigh
= dataW
->nFileSizeHigh
;
3025 dataA
->nFileSizeLow
= dataW
->nFileSizeLow
;
3026 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cFileName
, -1,
3027 dataA
->cFileName
, sizeof(dataA
->cFileName
), NULL
, NULL
);
3028 WideCharToMultiByte( CP_OEMCP
, 0, dataW
->cAlternateFileName
, -1,
3029 dataA
->cAlternateFileName
, sizeof(dataA
->cAlternateFileName
), NULL
, NULL
);
3032 /***********************************************************************
3033 * INT21_LongFilename
3035 * Handler for function 0x71.
3037 static void INT21_LongFilename( CONTEXT86
*context
)
3039 BOOL bSetDOSExtendedError
= FALSE
;
3040 WCHAR pathW
[MAX_PATH
];
3043 if (HIBYTE(HIWORD(GetVersion16())) < 0x07)
3045 TRACE( "LONG FILENAME - functions supported only under DOS7\n" );
3046 SET_CFLAG( context
);
3047 SET_AL( context
, 0 );
3051 switch (AL_reg(context
))
3053 case 0x0d: /* RESET DRIVE */
3054 INT_BARF( context
, 0x21 );
3057 case 0x39: /* LONG FILENAME - MAKE DIRECTORY */
3058 if (!INT21_CreateDirectory( context
))
3059 bSetDOSExtendedError
= TRUE
;
3062 case 0x3a: /* LONG FILENAME - REMOVE DIRECTORY */
3063 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3065 TRACE( "LONG FILENAME - REMOVE DIRECTORY %s\n", pathA
);
3066 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3067 if (!RemoveDirectoryW( pathW
)) bSetDOSExtendedError
= TRUE
;
3070 case 0x3b: /* LONG FILENAME - CHANGE DIRECTORY */
3071 if (!INT21_SetCurrentDirectory( context
))
3072 bSetDOSExtendedError
= TRUE
;
3075 case 0x41: /* LONG FILENAME - DELETE FILE */
3076 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3078 TRACE( "LONG FILENAME - DELETE FILE %s\n", pathA
);
3079 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3081 if (!DeleteFileW( pathW
)) bSetDOSExtendedError
= TRUE
;
3084 case 0x43: /* LONG FILENAME - EXTENDED GET/SET FILE ATTRIBUTES */
3085 if (!INT21_FileAttributes( context
, BL_reg(context
), TRUE
))
3086 bSetDOSExtendedError
= TRUE
;
3089 case 0x47: /* LONG FILENAME - GET CURRENT DIRECTORY */
3090 if (!INT21_GetCurrentDirectory( context
, TRUE
))
3091 bSetDOSExtendedError
= TRUE
;
3094 case 0x4e: /* LONG FILENAME - FIND FIRST MATCHING FILE */
3098 WIN32_FIND_DATAW dataW
;
3099 WIN32_FIND_DATAA
* dataA
;
3101 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
3102 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n", pathA
);
3104 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3105 handle
= FindFirstFileW(pathW
, &dataW
);
3107 dataA
= (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
3109 if (handle
!= INVALID_HANDLE_VALUE
&&
3110 (h16
= GlobalAlloc16(GMEM_MOVEABLE
, sizeof(handle
))))
3112 HANDLE
* ptr
= GlobalLock16( h16
);
3114 GlobalUnlock16( h16
);
3115 SET_AX( context
, h16
);
3116 INT21_ConvertFindDataWtoA(dataA
, &dataW
);
3120 if (handle
!= INVALID_HANDLE_VALUE
) FindClose(handle
);
3121 SET_AX( context
, INVALID_HANDLE_VALUE16
);
3122 bSetDOSExtendedError
= TRUE
;
3127 case 0x4f: /* LONG FILENAME - FIND NEXT MATCHING FILE */
3129 HGLOBAL16 h16
= BX_reg(context
);
3131 WIN32_FIND_DATAW dataW
;
3132 WIN32_FIND_DATAA
* dataA
;
3134 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
3137 dataA
= (WIN32_FIND_DATAA
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
,
3140 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
3142 if (!FindNextFileW(*ptr
, &dataW
)) bSetDOSExtendedError
= TRUE
;
3143 else INT21_ConvertFindDataWtoA(dataA
, &dataW
);
3144 GlobalUnlock16( h16
);
3148 SetLastError( ERROR_INVALID_HANDLE
);
3149 bSetDOSExtendedError
= TRUE
;
3154 case 0x56: /* LONG FILENAME - RENAME FILE */
3155 if (!INT21_RenameFile(context
))
3156 bSetDOSExtendedError
= TRUE
;
3159 case 0x60: /* LONG FILENAME - CONVERT PATH */
3161 WCHAR res
[MAX_PATH
];
3163 switch (CL_reg(context
))
3165 case 0x00: /* "truename" - Canonicalize path */
3167 * FIXME: This is not 100% equal to 0x01 case,
3168 * if you fix this, fix int21 subfunction 0x60, too.
3171 case 0x01: /* Get short filename or path */
3172 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
3173 if (!GetShortPathNameW(pathW
, res
, 67))
3174 bSetDOSExtendedError
= TRUE
;
3177 SET_AX( context
, 0 );
3178 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
3179 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3184 case 0x02: /* Get canonical long filename or path */
3185 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
3186 if (!GetFullPathNameW(pathW
, 128, res
, NULL
))
3187 bSetDOSExtendedError
= TRUE
;
3190 SET_AX( context
, 0 );
3191 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
3192 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3197 FIXME("Unimplemented long file name function:\n");
3198 INT_BARF( context
, 0x21 );
3200 SET_AL( context
, 0 );
3206 case 0x6c: /* LONG FILENAME - CREATE OR OPEN FILE */
3207 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
3208 BX_reg(context
), DL_reg(context
) ))
3209 bSetDOSExtendedError
= TRUE
;
3212 case 0xa0: /* LONG FILENAME - GET VOLUME INFORMATION */
3214 DWORD filename_len
, flags
;
3217 pathA
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Edx
);
3219 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", pathA
);
3220 SET_AX( context
, 0 );
3221 MultiByteToWideChar(CP_OEMCP
, 0, pathA
, -1, pathW
, MAX_PATH
);
3222 if (!GetVolumeInformationW( pathW
, NULL
, 0, NULL
, &filename_len
,
3225 INT_BARF( context
, 0x21 );
3229 SET_BX( context
, flags
| 0x4000 ); /* support for LFN functions */
3230 SET_CX( context
, filename_len
);
3231 SET_DX( context
, MAX_PATH
); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
3232 WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1,
3233 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
3238 case 0xa1: /* LONG FILENAME - "FindClose" - TERMINATE DIRECTORY SEARCH */
3240 HGLOBAL16 h16
= BX_reg(context
);
3243 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
3245 if (h16
!= INVALID_HANDLE_VALUE16
&& (ptr
= GlobalLock16( h16
)))
3247 if (!FindClose( *ptr
)) bSetDOSExtendedError
= TRUE
;
3248 GlobalUnlock16( h16
);
3249 GlobalFree16( h16
);
3253 SetLastError( ERROR_INVALID_HANDLE
);
3254 bSetDOSExtendedError
= TRUE
;
3259 case 0xa6: /* LONG FILENAME - GET FILE INFO BY HANDLE */
3261 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
3262 BY_HANDLE_FILE_INFORMATION
*info
=
3263 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3265 TRACE( "LONG FILENAME - GET FILE INFO BY HANDLE\n" );
3267 if (!GetFileInformationByHandle(handle
, info
))
3268 bSetDOSExtendedError
= TRUE
;
3272 case 0xa7: /* LONG FILENAME - CONVERT TIME */
3273 switch (BL_reg(context
))
3275 case 0x00: /* FILE TIME TO DOS TIME */
3278 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3282 TRACE( "LONG FILENAME - FILE TIME TO DOS TIME\n" );
3284 FileTimeToDosDateTime( filetime
, &date
, &time
);
3286 SET_DX( context
, date
);
3287 SET_CX( context
, time
);
3290 * FIXME: BH has number of 10-millisecond units
3293 SET_BH( context
, 0 );
3297 case 0x01: /* DOS TIME TO FILE TIME */
3299 FILETIME
*filetime
= CTX_SEG_OFF_TO_LIN(context
,
3303 TRACE( "LONG FILENAME - DOS TIME TO FILE TIME\n" );
3306 * FIXME: BH has number of 10-millisecond units
3309 DosDateTimeToFileTime( DX_reg(context
), CX_reg(context
),
3315 INT_BARF( context
, 0x21 );
3320 case 0xa8: /* LONG FILENAME - GENERATE SHORT FILENAME */
3321 case 0xa9: /* LONG FILENAME - SERVER CREATE OR OPEN FILE */
3322 case 0xaa: /* LONG FILENAME - SUBST */
3324 FIXME("Unimplemented long file name function:\n");
3325 INT_BARF( context
, 0x21 );
3327 SET_AL( context
, 0 );
3331 if (bSetDOSExtendedError
)
3333 SET_AX( context
, GetLastError() );
3334 SET_CFLAG( context
);
3339 /***********************************************************************
3344 * - subfunction 0x56 of function 0x71
3345 * - subfunction 0xff of function 0x43 (CL == 0x56)
3347 static BOOL
INT21_RenameFile( CONTEXT86
*context
)
3349 WCHAR fromW
[MAX_PATH
];
3350 WCHAR toW
[MAX_PATH
];
3351 char *fromA
= CTX_SEG_OFF_TO_LIN(context
,
3352 context
->SegDs
,context
->Edx
);
3353 char *toA
= CTX_SEG_OFF_TO_LIN(context
,
3354 context
->SegEs
,context
->Edi
);
3356 TRACE( "RENAME FILE %s to %s\n", fromA
, toA
);
3357 MultiByteToWideChar(CP_OEMCP
, 0, fromA
, -1, fromW
, MAX_PATH
);
3358 MultiByteToWideChar(CP_OEMCP
, 0, toA
, -1, toW
, MAX_PATH
);
3360 return MoveFileW( fromW
, toW
);
3364 /***********************************************************************
3370 static BOOL
INT21_NetworkFunc (CONTEXT86
*context
)
3372 switch (AL_reg(context
))
3374 case 0x00: /* Get machine name. */
3376 WCHAR dstW
[MAX_COMPUTERNAME_LENGTH
+ 1];
3377 DWORD s
= sizeof(dstW
) / sizeof(WCHAR
);
3380 char *dst
= CTX_SEG_OFF_TO_LIN (context
,context
->SegDs
,context
->Edx
);
3381 TRACE("getting machine name to %p\n", dst
);
3382 if (!GetComputerNameW(dstW
, &s
) ||
3383 !WideCharToMultiByte(CP_OEMCP
, 0, dstW
, -1, dst
, 16, NULL
, NULL
))
3386 SetLastError( ER_NoNetwork
);
3389 for (len
= strlen(dst
); len
< 15; len
++) dst
[len
] = ' ';
3391 SET_CH( context
, 1 ); /* Valid */
3392 SET_CL( context
, 1 ); /* NETbios number??? */
3393 TRACE("returning %s\n", debugstr_an(dst
, 16));
3398 SetLastError( ER_NoNetwork
);
3403 /******************************************************************
3404 * INT21_GetDiskSerialNumber
3407 static int INT21_GetDiskSerialNumber( CONTEXT86
*context
)
3409 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3410 WCHAR path
[] = {'A',':',0}, label
[11];
3413 path
[0] += INT21_MapDrive(BL_reg(context
));
3414 if (!GetVolumeInformationW( path
, label
, 11, &serial
, NULL
, NULL
, NULL
, 0))
3416 SetLastError( ERROR_INVALID_DRIVE
);
3420 *(WORD
*)dataptr
= 0;
3421 memcpy(dataptr
+ 2, &serial
, sizeof(DWORD
));
3422 WideCharToMultiByte(CP_OEMCP
, 0, label
, 11, dataptr
+ 6, 11, NULL
, NULL
);
3423 strncpy(dataptr
+ 17, "FAT16 ", 8);
3428 /******************************************************************
3429 * INT21_SetDiskSerialNumber
3432 static int INT21_SetDiskSerialNumber( CONTEXT86
*context
)
3435 BYTE
*dataptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3436 int drive
= INT21_MapDrive(BL_reg(context
));
3438 if (!is_valid_drive(drive
))
3440 SetLastError( ERROR_INVALID_DRIVE
);
3444 DRIVE_SetSerialNumber( drive
, *(DWORD
*)(dataptr
+ 2) );
3447 FIXME("Setting drive serial number is no longer supported\n");
3448 SetLastError( ERROR_NOT_SUPPORTED
);
3454 /******************************************************************
3455 * INT21_GetFreeDiskSpace
3458 static int INT21_GetFreeDiskSpace( CONTEXT86
*context
)
3460 DWORD cluster_sectors
, sector_bytes
, free_clusters
, total_clusters
;
3461 WCHAR root
[] = {'A',':','\\',0};
3463 root
[0] += INT21_MapDrive(DL_reg(context
));
3464 if (!GetDiskFreeSpaceW( root
, &cluster_sectors
, §or_bytes
,
3465 &free_clusters
, &total_clusters
)) return 0;
3466 /* make sure that the number of clusters fits in a 16 bits value */
3467 while( total_clusters
& 0xffff0000) {
3468 cluster_sectors
<<= 1;
3469 free_clusters
>>= 1;
3470 total_clusters
>>= 1;
3472 SET_AX( context
, cluster_sectors
);
3473 SET_BX( context
, free_clusters
);
3474 SET_CX( context
, sector_bytes
);
3475 SET_DX( context
, total_clusters
);
3479 /******************************************************************
3480 * INT21_GetDriveAllocInfo
3483 static int INT21_GetDriveAllocInfo( CONTEXT86
*context
, BYTE drive
)
3487 drive
= INT21_MapDrive( drive
);
3488 if (!INT21_FillDrivePB( drive
)) return 0;
3489 dpb
= &(INT21_GetHeapPointer()->misc_dpb_list
[drive
]);
3490 SET_AL( context
, dpb
->cluster_sectors
+ 1 );
3491 SET_CX( context
, dpb
->sector_bytes
);
3492 SET_DX( context
, dpb
->num_clusters1
);
3494 context
->SegDs
= INT21_GetHeapSelector( context
);
3495 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
].media_ID
) );
3499 /***********************************************************************
3500 * INT21_GetExtendedError
3502 static void INT21_GetExtendedError( CONTEXT86
*context
)
3504 BYTE
class, action
, locus
;
3505 WORD error
= GetLastError();
3510 class = action
= locus
= 0;
3512 case ERROR_DIR_NOT_EMPTY
:
3517 case ERROR_ACCESS_DENIED
:
3518 class = EC_AccessDenied
;
3522 case ERROR_CANNOT_MAKE
:
3523 class = EC_AccessDenied
;
3527 case ERROR_DISK_FULL
:
3528 case ERROR_HANDLE_DISK_FULL
:
3529 class = EC_MediaError
;
3533 case ERROR_FILE_EXISTS
:
3534 case ERROR_ALREADY_EXISTS
:
3539 case ERROR_FILE_NOT_FOUND
:
3540 class = EC_NotFound
;
3544 case ERROR_GEN_FAILURE
:
3545 class = EC_SystemFailure
;
3549 case ERROR_INVALID_DRIVE
:
3550 class = EC_MediaError
;
3554 case ERROR_INVALID_HANDLE
:
3555 class = EC_ProgramError
;
3559 case ERROR_LOCK_VIOLATION
:
3560 class = EC_AccessDenied
;
3564 case ERROR_NO_MORE_FILES
:
3565 class = EC_MediaError
;
3570 class = EC_NotFound
;
3574 case ERROR_NOT_ENOUGH_MEMORY
:
3575 class = EC_OutOfResource
;
3579 case ERROR_PATH_NOT_FOUND
:
3580 class = EC_NotFound
;
3585 class = EC_NotFound
;
3589 case ERROR_SHARING_VIOLATION
:
3590 class = EC_Temporary
;
3594 case ERROR_TOO_MANY_OPEN_FILES
:
3595 class = EC_ProgramError
;
3600 FIXME("Unknown error %d\n", error
);
3601 class = EC_SystemFailure
;
3606 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
3607 error
, class, action
, locus
);
3608 SET_AX( context
, error
);
3609 SET_BH( context
, class );
3610 SET_BL( context
, action
);
3611 SET_CH( context
, locus
);
3614 static BOOL
INT21_CreateTempFile( CONTEXT86
*context
)
3616 static int counter
= 0;
3617 char *name
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3618 char *p
= name
+ strlen(name
);
3620 /* despite what Ralf Brown says, some programs seem to call without
3621 * ending backslash (DOS accepts that, so we accept it too) */
3622 if ((p
== name
) || (p
[-1] != '\\')) *p
++ = '\\';
3626 sprintf( p
, "wine%04x.%03d", (int)getpid(), counter
);
3627 counter
= (counter
+ 1) % 1000;
3630 Win32HandleToDosFileHandle(
3631 CreateFileA( name
, GENERIC_READ
| GENERIC_WRITE
,
3632 FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
3633 CREATE_NEW
, 0, 0 ) ) );
3634 if (AX_reg(context
) != HFILE_ERROR16
)
3636 TRACE("created %s\n", name
);
3639 if (GetLastError() != ERROR_FILE_EXISTS
) return FALSE
;
3643 /***********************************************************************
3644 * DOSFS_ToDosFCBFormat
3646 * Convert a file name to DOS FCB format (8+3 chars, padded with blanks),
3647 * expanding wild cards and converting to upper-case in the process.
3648 * File name can be terminated by '\0', '\\' or '/'.
3649 * Return FALSE if the name is not a valid DOS name.
3650 * 'buffer' must be at least 12 characters long.
3652 /* Chars we don't want to see in DOS file names */
3653 static BOOL
INT21_ToDosFCBFormat( LPCWSTR name
, LPWSTR buffer
)
3655 static const WCHAR invalid_chars
[] = {'*','?','<','>','|','\\','"','+','=',',',';','[',']',' ','\345',0};
3659 /* Check for "." and ".." */
3664 for(i
= 1; i
< 11; i
++) buffer
[i
] = ' ';
3671 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3674 for (i
= 0; i
< 8; i
++)
3691 if (strchrW( invalid_chars
, *p
)) return FALSE
;
3692 buffer
[i
] = toupperW(*p
);
3700 /* Skip all chars after wildcard up to first dot */
3701 while (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) p
++;
3705 /* Check if name too long */
3706 if (*p
&& (*p
!= '/') && (*p
!= '\\') && (*p
!= '.')) return FALSE
;
3708 if (*p
== '.') p
++; /* Skip dot */
3710 for (i
= 8; i
< 11; i
++)
3720 return FALSE
; /* Second extension not allowed */
3728 if (strchrW( invalid_chars
, *p
)) return FALSE
;
3729 buffer
[i
] = toupperW(*p
);
3736 /* at most 3 character of the extension are processed
3737 * is something behind this ?
3739 while (*p
== '*' || *p
== ' ') p
++; /* skip wildcards and spaces */
3740 return (!*p
|| (*p
== '/') || (*p
== '\\'));
3743 static HANDLE INT21_FindHandle
;
3744 static const WCHAR
*INT21_FindPath
; /* will point to current dta->fullPath search */
3746 /******************************************************************
3749 static int INT21_FindFirst( CONTEXT86
*context
)
3753 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3754 WCHAR maskW
[12], pathW
[MAX_PATH
];
3755 static const WCHAR wildcardW
[] = {'*','.','*',0};
3757 path
= (const char *)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3758 MultiByteToWideChar(CP_OEMCP
, 0, path
, -1, pathW
, MAX_PATH
);
3760 p
= strrchrW( pathW
, '\\');
3761 q
= strrchrW( pathW
, '/');
3765 if (pathW
[0] && pathW
[1] == ':') p
= pathW
+ 2;
3770 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
3771 * (doesn't matter as it is set below anyway)
3773 if (!INT21_ToDosFCBFormat( p
, maskW
))
3775 SetLastError( ERROR_FILE_NOT_FOUND
);
3776 SET_AX( context
, ERROR_FILE_NOT_FOUND
);
3780 WideCharToMultiByte(CP_OEMCP
, 0, maskW
, 12, dta
->mask
, sizeof(dta
->mask
), NULL
, NULL
);
3782 dta
->fullPath
= HeapAlloc( GetProcessHeap(), 0, sizeof(wildcardW
) + (p
- pathW
)*sizeof(WCHAR
) );
3783 memcpy( dta
->fullPath
, pathW
, (p
- pathW
) * sizeof(WCHAR
) );
3784 memcpy( dta
->fullPath
+ (p
- pathW
), wildcardW
, sizeof(wildcardW
) );
3785 /* we must have a fully qualified file name in dta->fullPath
3786 * (we could have a UNC path, but this would lead to some errors later on)
3788 dta
->drive
= toupperW(dta
->fullPath
[0]) - 'A';
3790 dta
->search_attr
= CL_reg(context
);
3794 /******************************************************************
3797 * Check is a short path name (DTA unicode) matches a mask (FCB ansi)
3799 static BOOL
match_short(LPCWSTR shortW
, LPCSTR maskA
)
3801 WCHAR mask
[11], file
[12];
3804 if (!INT21_ToDosFCBFormat( shortW
, file
)) return FALSE
;
3805 MultiByteToWideChar(CP_OEMCP
, 0, maskA
, 11, mask
, 11);
3806 for (i
= 0; i
< 11; i
++)
3807 if (mask
[i
] != '?' && mask
[i
] != file
[i
]) return FALSE
;
3811 static unsigned INT21_FindHelper(LPCWSTR fullPath
, unsigned drive
, unsigned count
,
3812 LPCSTR mask
, unsigned search_attr
,
3813 WIN32_FIND_DATAW
* entry
)
3817 if ((search_attr
& ~(FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
)) == FA_LABEL
)
3819 WCHAR path
[] = {' ',':',0};
3821 if (count
) return 0;
3822 path
[0] = drive
+ 'A';
3823 if (!GetVolumeInformationW(path
, entry
->cAlternateFileName
, 13, NULL
, NULL
, NULL
, NULL
, 0)) return 0;
3824 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftCreationTime
);
3825 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftLastAccessTime
);
3826 RtlSecondsSince1970ToTime( (time_t)0, (LARGE_INTEGER
*)&entry
->ftLastWriteTime
);
3827 entry
->dwFileAttributes
= FA_LABEL
;
3828 entry
->nFileSizeHigh
= entry
->nFileSizeLow
= 0;
3829 TRACE("returning %s as label\n", debugstr_w(entry
->cAlternateFileName
));
3833 if (!INT21_FindHandle
|| INT21_FindPath
!= fullPath
|| count
== 0)
3835 if (INT21_FindHandle
) FindClose(INT21_FindHandle
);
3836 INT21_FindHandle
= FindFirstFileW(fullPath
, entry
);
3837 if (INT21_FindHandle
== INVALID_HANDLE_VALUE
)
3839 INT21_FindHandle
= 0;
3842 INT21_FindPath
= fullPath
;
3843 /* we need to resync search */
3848 while (ncalls
-- != 0)
3850 if (!FindNextFileW(INT21_FindHandle
, entry
))
3852 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3856 while (count
< 0xffff)
3859 /* Check the file attributes, and path */
3860 if (!(entry
->dwFileAttributes
& ~search_attr
) &&
3861 match_short(entry
->cAlternateFileName
[0] ? entry
->cAlternateFileName
: entry
->cFileName
,
3866 if (!FindNextFileW(INT21_FindHandle
, entry
))
3868 FindClose(INT21_FindHandle
); INT21_FindHandle
= 0;
3872 WARN("Too many directory entries in %s\n", debugstr_w(fullPath
) );
3876 /******************************************************************
3879 static int INT21_FindNext( CONTEXT86
*context
)
3881 FINDFILE_DTA
*dta
= (FINDFILE_DTA
*)INT21_GetCurrentDTA(context
);
3882 DWORD attr
= dta
->search_attr
| FA_UNUSED
| FA_ARCHIVE
| FA_RDONLY
;
3883 WIN32_FIND_DATAW entry
;
3886 if (!dta
->fullPath
) return 0;
3888 n
= INT21_FindHelper(dta
->fullPath
, dta
->drive
, dta
->count
,
3889 dta
->mask
, attr
, &entry
);
3892 dta
->fileattr
= entry
.dwFileAttributes
;
3893 dta
->filesize
= entry
.nFileSizeLow
;
3894 FileTimeToDosDateTime( &entry
.ftLastWriteTime
, &dta
->filedate
, &dta
->filetime
);
3895 if (entry
.cAlternateFileName
[0])
3896 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cAlternateFileName
, -1,
3897 dta
->filename
, 13, NULL
, NULL
);
3899 WideCharToMultiByte(CP_OEMCP
, 0, entry
.cFileName
, -1, dta
->filename
, 13, NULL
, NULL
);
3901 if (!memchr(dta
->mask
,'?',11))
3903 /* wildcardless search, release resources in case no findnext will
3904 * be issued, and as a workaround in case file creation messes up
3905 * findnext, as sometimes happens with pkunzip
3907 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3908 INT21_FindPath
= dta
->fullPath
= NULL
;
3913 HeapFree( GetProcessHeap(), 0, dta
->fullPath
);
3914 INT21_FindPath
= dta
->fullPath
= NULL
;
3918 /* microsoft's programmers should be shot for using CP/M style int21
3919 calls in Windows for Workgroup's winfile.exe */
3921 /******************************************************************
3922 * INT21_FindFirstFCB
3925 static int INT21_FindFirstFCB( CONTEXT86
*context
)
3927 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3930 WCHAR p
[] = {' ',':',};
3932 if (*fcb
== 0xff) pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3933 else pFCB
= (FINDFILE_FCB
*)fcb
;
3934 drive
= INT21_MapDrive( pFCB
->drive
);
3935 if (drive
== MAX_DOS_DRIVES
) return 0;
3938 pFCB
->fullPath
= HeapAlloc(GetProcessHeap(), 0, MAX_PATH
* sizeof(WCHAR
));
3939 if (!pFCB
->fullPath
) return 0;
3940 GetLongPathNameW(p
, pFCB
->fullPath
, MAX_PATH
);
3945 /******************************************************************
3949 static int INT21_FindNextFCB( CONTEXT86
*context
)
3951 BYTE
*fcb
= (BYTE
*)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
3953 LPBYTE pResult
= INT21_GetCurrentDTA(context
);
3954 DOS_DIRENTRY_LAYOUT
*ddl
;
3955 WIN32_FIND_DATAW entry
;
3960 if (*fcb
== 0xff) /* extended FCB ? */
3963 pFCB
= (FINDFILE_FCB
*)(fcb
+ 7);
3968 pFCB
= (FINDFILE_FCB
*)fcb
;
3971 if (!pFCB
->fullPath
) return 0;
3972 n
= INT21_FindHelper(pFCB
->fullPath
, INT21_MapDrive( pFCB
->drive
),
3973 pFCB
->count
, pFCB
->filename
, attr
, &entry
);
3976 HeapFree( GetProcessHeap(), 0, pFCB
->fullPath
);
3977 INT21_FindPath
= pFCB
->fullPath
= NULL
;
3984 /* place extended FCB header before pResult if called with extended FCB */
3986 pResult
+= 6; /* leave reserved field behind */
3987 *pResult
++ = entry
.dwFileAttributes
;
3989 *pResult
++ = INT21_MapDrive( pFCB
->drive
); /* DOS_DIRENTRY_LAYOUT after current drive number */
3990 ddl
= (DOS_DIRENTRY_LAYOUT
*)pResult
;
3991 ddl
->fileattr
= entry
.dwFileAttributes
;
3992 ddl
->cluster
= 0; /* what else? */
3993 ddl
->filesize
= entry
.nFileSizeLow
;
3994 memset( ddl
->reserved
, 0, sizeof(ddl
->reserved
) );
3995 FileTimeToDosDateTime( &entry
.ftLastWriteTime
,
3996 &ddl
->filedate
, &ddl
->filetime
);
3998 /* Convert file name to FCB format */
3999 if (entry
.cAlternateFileName
[0])
4000 INT21_ToDosFCBFormat( entry
.cAlternateFileName
, nameW
);
4002 INT21_ToDosFCBFormat( entry
.cFileName
, nameW
);
4003 WideCharToMultiByte(CP_OEMCP
, 0, nameW
, 11, ddl
->filename
, 11, NULL
, NULL
);
4008 /******************************************************************
4009 * INT21_ParseFileNameIntoFCB
4012 static void INT21_ParseFileNameIntoFCB( CONTEXT86
*context
)
4015 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
);
4017 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
);
4021 INT buffer_len
, len
;
4023 SET_AL( context
, 0xff ); /* failed */
4025 TRACE("filename: '%s'\n", filename
);
4028 while (*s
&& (*s
!= ' ') && (*s
!= '\r') && (*s
!= '\n'))
4032 buffer_len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, NULL
, 0);
4033 buffer
= HeapAlloc( GetProcessHeap(), 0, (buffer_len
+ 1) * sizeof(WCHAR
));
4034 len
= MultiByteToWideChar(CP_OEMCP
, 0, filename
, len
, buffer
, buffer_len
);
4036 INT21_ToDosFCBFormat(buffer
, fcbW
);
4037 HeapFree(GetProcessHeap(), 0, buffer
);
4038 WideCharToMultiByte(CP_OEMCP
, 0, fcbW
, 12, fcb
+ 1, 12, NULL
, NULL
);
4040 TRACE("FCB: '%s'\n", fcb
+ 1);
4042 SET_AL( context
, ((strchr(filename
, '*')) || (strchr(filename
, '$'))) != 0 );
4044 /* point DS:SI to first unparsed character */
4045 SET_SI( context
, context
->Esi
+ (int)s
- (int)filename
);
4048 static BOOL
INT21_Dup2(HFILE16 hFile1
, HFILE16 hFile2
)
4050 HFILE16 res
= HFILE_ERROR16
;
4051 HANDLE handle
, new_handle
;
4052 #define DOS_TABLE_SIZE 256
4053 DWORD map
[DOS_TABLE_SIZE
/ 32];
4056 handle
= DosFileHandleToWin32Handle(hFile1
);
4057 if (handle
== INVALID_HANDLE_VALUE
)
4061 /* now loop to allocate the same one... */
4062 memset(map
, 0, sizeof(map
));
4063 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++)
4065 if (!DuplicateHandle(GetCurrentProcess(), handle
,
4066 GetCurrentProcess(), &new_handle
,
4067 0, FALSE
, DUPLICATE_SAME_ACCESS
))
4069 res
= HFILE_ERROR16
;
4072 res
= Win32HandleToDosFileHandle(new_handle
);
4073 if (res
== HFILE_ERROR16
|| res
== hFile2
) break;
4074 map
[res
/ 32] |= 1 << (res
% 32);
4076 /* clean up the allocated slots */
4077 for (i
= 0; i
< DOS_TABLE_SIZE
; i
++)
4079 if (map
[i
/ 32] & (1 << (i
% 32)))
4080 _lclose16((HFILE16
)i
);
4082 return res
== hFile2
;
4086 /***********************************************************************
4087 * DOSVM_Int21Handler
4089 * Interrupt 0x21 handler.
4091 void WINAPI
DOSVM_Int21Handler( CONTEXT86
*context
)
4093 BOOL bSetDOSExtendedError
= FALSE
;
4095 TRACE( "AX=%04x BX=%04x CX=%04x DX=%04x "
4096 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
4097 AX_reg(context
), BX_reg(context
),
4098 CX_reg(context
), DX_reg(context
),
4099 SI_reg(context
), DI_reg(context
),
4100 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,
4104 * Extended error is used by (at least) functions 0x2f to 0x62.
4105 * Function 0x59 returns extended error and error should not
4106 * be cleared before handling the function.
4108 if (AH_reg(context
) >= 0x2f && AH_reg(context
) != 0x59)
4111 RESET_CFLAG(context
); /* Not sure if this is a good idea. */
4113 switch(AH_reg(context
))
4115 case 0x00: /* TERMINATE PROGRAM */
4116 TRACE("TERMINATE PROGRAM\n");
4117 if (DOSVM_IsWin16())
4119 else if(ISV86(context
))
4120 MZ_Exit( context
, FALSE
, 0 );
4122 ERR( "Called from DOS protected mode\n" );
4125 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
4128 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
4129 INT21_ReadChar( &ascii
, context
);
4130 SET_AL( context
, ascii
);
4132 * FIXME: What to echo when extended keycodes are read?
4134 DOSVM_PutChar(AL_reg(context
));
4138 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
4139 TRACE("Write Character to Standard Output\n");
4140 DOSVM_PutChar(DL_reg(context
));
4143 case 0x03: /* READ CHARACTER FROM STDAUX */
4144 case 0x04: /* WRITE CHARACTER TO STDAUX */
4145 case 0x05: /* WRITE CHARACTER TO PRINTER */
4146 INT_BARF( context
, 0x21 );
4149 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
4150 if (DL_reg(context
) == 0xff)
4152 TRACE("Direct Console Input\n");
4154 if (INT21_ReadChar( NULL
, NULL
))
4157 INT21_ReadChar( &ascii
, context
);
4158 SET_AL( context
, ascii
);
4159 RESET_ZFLAG( context
);
4163 /* no character available */
4164 SET_AL( context
, 0 );
4165 SET_ZFLAG( context
);
4170 TRACE("Direct Console Output\n");
4171 DOSVM_PutChar(DL_reg(context
));
4173 * At least DOS versions 2.1-7.0 return character
4174 * that was written in AL register.
4176 SET_AL( context
, DL_reg(context
) );
4180 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
4183 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
4184 INT21_ReadChar( &ascii
, context
);
4185 SET_AL( context
, ascii
);
4189 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
4192 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
4193 INT21_ReadChar( &ascii
, context
);
4194 SET_AL( context
, ascii
);
4198 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
4199 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
4200 context
->SegDs
, DX_reg(context
) );
4202 LPSTR data
= CTX_SEG_OFF_TO_LIN( context
,
4203 context
->SegDs
, context
->Edx
);
4207 * Do NOT use strchr() to calculate the string length,
4208 * as '\0' is valid string content, too!
4209 * Maybe we should check for non-'$' strings, but DOS doesn't.
4211 while (*p
!= '$') p
++;
4213 if (DOSVM_IsWin16())
4214 WriteFile( DosFileHandleToWin32Handle(1),
4215 data
, p
- data
, 0, 0 );
4217 for(; data
!= p
; data
++)
4218 DOSVM_PutChar( *data
);
4220 SET_AL( context
, '$' ); /* yes, '$' (0x24) gets returned in AL */
4224 case 0x0a: /* BUFFERED INPUT */
4226 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
,
4231 TRACE( "BUFFERED INPUT (size=%d)\n", ptr
[0] );
4234 * FIXME: Some documents state that
4235 * ptr[1] holds number of chars from last input which
4236 * may be recalled on entry, other documents do not mention
4240 TRACE( "Handle old chars in buffer!\n" );
4243 * ptr[0] - capacity (includes terminating CR)
4244 * ptr[1] - characters read (excludes terminating CR)
4246 result
= INT21_BufferedInput( context
, ptr
+ 2, ptr
[0] );
4248 ptr
[1] = (BYTE
)result
- 1;
4254 case 0x0b: /* GET STDIN STATUS */
4255 TRACE( "GET STDIN STATUS\n" );
4257 if (INT21_ReadChar( NULL
, NULL
))
4258 SET_AL( context
, 0xff ); /* character available */
4260 SET_AL( context
, 0 ); /* no character available */
4264 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
4266 BYTE al
= AL_reg(context
); /* Input function to execute after flush. */
4268 TRACE( "FLUSH BUFFER AND READ STANDARD INPUT - 0x%02x\n", al
);
4270 /* FIXME: buffers are not flushed */
4273 * If AL is one of 0x01, 0x06, 0x07, 0x08, or 0x0a,
4274 * int21 function identified by AL will be called.
4276 if(al
== 0x01 || al
== 0x06 || al
== 0x07 || al
== 0x08 || al
== 0x0a)
4278 SET_AH( context
, al
);
4279 DOSVM_Int21Handler( context
);
4284 case 0x0d: /* DISK BUFFER FLUSH */
4285 TRACE("DISK BUFFER FLUSH ignored\n");
4288 case 0x0e: /* SELECT DEFAULT DRIVE */
4289 TRACE( "SELECT DEFAULT DRIVE - %c:\n", 'A' + DL_reg(context
) );
4290 INT21_SetCurrentDrive( DL_reg(context
) );
4291 SET_AL( context
, MAX_DOS_DRIVES
);
4294 case 0x0f: /* OPEN FILE USING FCB */
4295 INT21_OpenFileUsingFCB( context
);
4298 case 0x10: /* CLOSE FILE USING FCB */
4299 INT21_CloseFileUsingFCB( context
);
4302 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
4303 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
4304 CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
4305 if (!INT21_FindFirstFCB(context
))
4307 SET_AL( context
, 0xff );
4310 /* else fall through */
4312 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
4313 SET_AL( context
, INT21_FindNextFCB(context
) ? 0x00 : 0xff );
4316 case 0x13: /* DELETE FILE USING FCB */
4317 INT_BARF( context
, 0x21 );
4320 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
4321 INT21_SequentialReadFromFCB( context
);
4324 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
4325 INT21_SequentialWriteToFCB( context
);
4328 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
4329 case 0x17: /* RENAME FILE USING FCB */
4330 INT_BARF( context
, 0x21 );
4333 case 0x18: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4334 SET_AL( context
, 0 );
4337 case 0x19: /* GET CURRENT DEFAULT DRIVE */
4338 SET_AL( context
, INT21_GetCurrentDrive() );
4339 TRACE( "GET CURRENT DRIVE -> %c:\n", 'A' + AL_reg( context
) );
4342 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
4343 TRACE( "SET DISK TRANSFER AREA ADDRESS %04lX:%04X\n",
4344 context
->SegDs
, DX_reg(context
) );
4346 TDB
*task
= GlobalLock16( GetCurrentTask() );
4347 task
->dta
= MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4351 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
4352 if (!INT21_GetDriveAllocInfo(context
, 0))
4353 SET_AX( context
, 0xffff );
4356 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
4357 if (!INT21_GetDriveAllocInfo(context
, DL_reg(context
)))
4358 SET_AX( context
, 0xffff );
4361 case 0x1d: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4362 case 0x1e: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4363 SET_AL( context
, 0 );
4366 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
4368 BYTE drive
= INT21_MapDrive( 0 );
4369 TRACE( "GET DPB FOR DEFAULT DRIVE\n" );
4371 if (INT21_FillDrivePB( drive
))
4373 SET_AL( context
, 0x00 ); /* success */
4374 SET_BX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4375 context
->SegDs
= INT21_GetHeapSelector( context
);
4379 SET_AL( context
, 0xff ); /* invalid or network drive */
4384 case 0x20: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
4385 SET_AL( context
, 0 );
4388 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
4389 INT21_ReadRandomRecordFromFCB( context
);
4392 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
4393 INT21_WriteRandomRecordToFCB( context
);
4396 case 0x23: /* GET FILE SIZE FOR FCB */
4397 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
4398 INT_BARF( context
, 0x21 );
4401 case 0x25: /* SET INTERRUPT VECTOR */
4402 TRACE("SET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4404 FARPROC16 ptr
= (FARPROC16
)MAKESEGPTR( context
->SegDs
, DX_reg(context
) );
4405 if (!ISV86(context
) && DOSVM_IsWin16())
4406 DOSVM_SetPMHandler16( AL_reg(context
), ptr
);
4408 DOSVM_SetRMHandler( AL_reg(context
), ptr
);
4412 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
4413 INT_BARF( context
, 0x21 );
4416 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
4417 INT21_RandomBlockReadFromFCB( context
);
4420 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
4421 INT21_RandomBlockWriteToFCB( context
);
4424 case 0x29: /* PARSE FILENAME INTO FCB */
4425 INT21_ParseFileNameIntoFCB(context
);
4428 case 0x2a: /* GET SYSTEM DATE */
4429 TRACE( "GET SYSTEM DATE\n" );
4432 GetLocalTime( &systime
);
4433 SET_CX( context
, systime
.wYear
);
4434 SET_DH( context
, systime
.wMonth
);
4435 SET_DL( context
, systime
.wDay
);
4436 SET_AL( context
, systime
.wDayOfWeek
);
4440 case 0x2b: /* SET SYSTEM DATE */
4441 TRACE( "SET SYSTEM DATE\n" );
4443 WORD year
= CX_reg(context
);
4444 BYTE month
= DH_reg(context
);
4445 BYTE day
= DL_reg(context
);
4447 if (year
>= 1980 && year
<= 2099 &&
4448 month
>= 1 && month
<= 12 &&
4449 day
>= 1 && day
<= 31)
4451 FIXME( "SetSystemDate(%02d/%02d/%04d): not allowed\n",
4453 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4457 SET_AL( context
, 0xff ); /* invalid date */
4458 TRACE( "SetSystemDate(%02d/%02d/%04d): invalid date\n",
4464 case 0x2c: /* GET SYSTEM TIME */
4465 TRACE( "GET SYSTEM TIME\n" );
4468 GetLocalTime( &systime
);
4469 SET_CH( context
, systime
.wHour
);
4470 SET_CL( context
, systime
.wMinute
);
4471 SET_DH( context
, systime
.wSecond
);
4472 SET_DL( context
, systime
.wMilliseconds
/ 10 );
4476 case 0x2d: /* SET SYSTEM TIME */
4477 if( CH_reg(context
) >= 24 || CL_reg(context
) >= 60 || DH_reg(context
) >= 60 || DL_reg(context
) >= 100 ) {
4478 TRACE("SetSystemTime(%02d:%02d:%02d.%02d): wrong time\n",
4479 CH_reg(context
), CL_reg(context
),
4480 DH_reg(context
), DL_reg(context
) );
4481 SET_AL( context
, 0xFF );
4485 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
4486 CH_reg(context
), CL_reg(context
),
4487 DH_reg(context
), DL_reg(context
) );
4488 SET_AL( context
, 0 ); /* Let's pretend we succeeded */
4492 case 0x2e: /* SET VERIFY FLAG */
4493 TRACE("SET VERIFY FLAG ignored\n");
4494 /* we cannot change the behaviour anyway, so just ignore it */
4497 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
4498 TRACE( "GET DISK TRANSFER AREA ADDRESS\n" );
4500 TDB
*task
= GlobalLock16( GetCurrentTask() );
4501 context
->SegEs
= SELECTOROF( task
->dta
);
4502 SET_BX( context
, OFFSETOF( task
->dta
) );
4506 case 0x30: /* GET DOS VERSION */
4507 TRACE( "GET DOS VERSION - %s requested\n",
4508 (AL_reg(context
) == 0x00) ? "OEM number" : "version flag" );
4510 if (AL_reg(context
) == 0x00)
4511 SET_BH( context
, 0xff ); /* OEM number => undefined */
4513 SET_BH( context
, 0x08 ); /* version flag => DOS is in ROM */
4515 SET_AL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major version */
4516 SET_AH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor version */
4518 SET_BL( context
, 0x12 ); /* 0x123456 is 24-bit Wine's serial # */
4519 SET_CX( context
, 0x3456 );
4522 case 0x31: /* TERMINATE AND STAY RESIDENT */
4523 FIXME("TERMINATE AND STAY RESIDENT stub\n");
4526 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
4528 BYTE drive
= INT21_MapDrive( DL_reg(context
) );
4529 TRACE( "GET DPB FOR SPECIFIC DRIVE %d\n", DL_reg(context
) );
4531 if (INT21_FillDrivePB( drive
))
4533 SET_AL( context
, 0x00 ); /* success */
4534 SET_DX( context
, offsetof( INT21_HEAP
, misc_dpb_list
[drive
] ) );
4535 context
->SegDs
= INT21_GetHeapSelector( context
);
4539 SET_AL( context
, 0xff ); /* invalid or network drive */
4544 case 0x33: /* MULTIPLEXED */
4545 switch (AL_reg(context
))
4547 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
4548 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
4549 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4552 case 0x01: /* SET EXTENDED BREAK STATE */
4553 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
4554 DOSCONF_GetConfig()->brk_flag
= (DL_reg(context
) > 0) ? 1 : 0;
4557 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
4558 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
4559 /* ugly coding in order to stay reentrant */
4560 if (DL_reg(context
))
4562 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4563 DOSCONF_GetConfig()->brk_flag
= 1;
4567 SET_DL( context
, DOSCONF_GetConfig()->brk_flag
);
4568 DOSCONF_GetConfig()->brk_flag
= 0;
4572 case 0x05: /* GET BOOT DRIVE */
4573 TRACE("GET BOOT DRIVE\n");
4574 SET_DL( context
, 3 );
4575 /* c: is Wine's bootdrive (a: is 1)*/
4578 case 0x06: /* GET TRUE VERSION NUMBER */
4579 TRACE("GET TRUE VERSION NUMBER\n");
4580 SET_BL( context
, HIBYTE(HIWORD(GetVersion16())) ); /* major */
4581 SET_BH( context
, LOBYTE(HIWORD(GetVersion16())) ); /* minor */
4582 SET_DL( context
, 0x00 ); /* revision */
4583 SET_DH( context
, 0x08 ); /* DOS is in ROM */
4587 INT_BARF( context
, 0x21 );
4592 case 0x34: /* GET ADDRESS OF INDOS FLAG */
4593 TRACE( "GET ADDRESS OF INDOS FLAG\n" );
4594 context
->SegEs
= INT21_GetHeapSelector( context
);
4595 SET_BX( context
, offsetof(INT21_HEAP
, misc_indos
) );
4598 case 0x35: /* GET INTERRUPT VECTOR */
4599 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context
));
4602 if (!ISV86(context
) && DOSVM_IsWin16())
4603 addr
= DOSVM_GetPMHandler16( AL_reg(context
) );
4605 addr
= DOSVM_GetRMHandler( AL_reg(context
) );
4606 context
->SegEs
= SELECTOROF(addr
);
4607 SET_BX( context
, OFFSETOF(addr
) );
4611 case 0x36: /* GET FREE DISK SPACE */
4612 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
4613 INT21_DriveName( DL_reg(context
) ));
4614 if (!INT21_GetFreeDiskSpace(context
)) SET_AX( context
, 0xffff );
4617 case 0x37: /* SWITCHAR */
4619 switch (AL_reg(context
))
4621 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
4622 TRACE( "SWITCHAR - GET SWITCH CHARACTER\n" );
4623 SET_AL( context
, 0x00 ); /* success*/
4624 SET_DL( context
, '/' );
4626 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
4627 FIXME( "SWITCHAR - SET SWITCH CHARACTER: %c\n",
4629 SET_AL( context
, 0x00 ); /* success*/
4632 INT_BARF( context
, 0x21 );
4638 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
4639 TRACE( "GET COUNTRY-SPECIFIC INFORMATION\n" );
4640 if (AL_reg(context
))
4642 WORD country
= AL_reg(context
);
4643 if (country
== 0xff)
4644 country
= BX_reg(context
);
4645 if (country
!= INT21_GetSystemCountryCode()) {
4646 FIXME( "Requested info on non-default country %04x\n", country
);
4651 if(AX_reg(context
) != 2 )
4653 INT21_FillCountryInformation( CTX_SEG_OFF_TO_LIN(context
,
4656 SET_AX( context
, INT21_GetSystemCountryCode() );
4657 SET_BX( context
, INT21_GetSystemCountryCode() );
4658 RESET_CFLAG(context
);
4662 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
4663 if (!INT21_CreateDirectory( context
))
4664 bSetDOSExtendedError
= TRUE
;
4666 RESET_CFLAG(context
);
4669 case 0x3a: /* "RMDIR" - REMOVE DIRECTORY */
4671 WCHAR dirW
[MAX_PATH
];
4672 char *dirA
= CTX_SEG_OFF_TO_LIN(context
,
4673 context
->SegDs
, context
->Edx
);
4675 TRACE( "REMOVE DIRECTORY %s\n", dirA
);
4677 MultiByteToWideChar(CP_OEMCP
, 0, dirA
, -1, dirW
, MAX_PATH
);
4679 if (!RemoveDirectoryW( dirW
))
4680 bSetDOSExtendedError
= TRUE
;
4682 RESET_CFLAG(context
);
4686 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
4687 if (!INT21_SetCurrentDirectory( context
))
4688 bSetDOSExtendedError
= TRUE
;
4690 RESET_CFLAG(context
);
4693 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
4694 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4695 OF_READWRITE
| OF_SHARE_COMPAT
, 0x12 ))
4696 bSetDOSExtendedError
= TRUE
;
4698 RESET_CFLAG(context
);
4701 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
4702 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
4703 AL_reg(context
), 0x01 ))
4704 bSetDOSExtendedError
= TRUE
;
4706 RESET_CFLAG(context
);
4709 case 0x3e: /* "CLOSE" - CLOSE FILE */
4710 TRACE( "CLOSE handle %d\n", BX_reg(context
) );
4711 if (_lclose16( BX_reg(context
) ) == HFILE_ERROR16
)
4712 bSetDOSExtendedError
= TRUE
;
4714 RESET_CFLAG(context
);
4717 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
4718 TRACE( "READ from %d to %04lX:%04X for %d bytes\n",
4725 WORD count
= CX_reg(context
);
4726 BYTE
*buffer
= CTX_SEG_OFF_TO_LIN( context
,
4730 /* Some programs pass a count larger than the allocated buffer */
4731 if (DOSVM_IsWin16())
4733 WORD maxcount
= GetSelectorLimit16( context
->SegDs
)
4734 - DX_reg(context
) + 1;
4735 if (count
> maxcount
)
4740 * FIXME: Reading from console (BX=1) in DOS mode
4741 * does not work as it is supposed to work.
4744 RESET_CFLAG(context
); /* set if error */
4745 if (!DOSVM_IsWin16() && BX_reg(context
) == 0)
4747 result
= INT21_BufferedInput( context
, buffer
, count
);
4748 SET_AX( context
, (WORD
)result
);
4750 else if (ReadFile( DosFileHandleToWin32Handle(BX_reg(context
)),
4751 buffer
, count
, &result
, NULL
))
4752 SET_AX( context
, (WORD
)result
);
4754 bSetDOSExtendedError
= TRUE
;
4758 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
4759 TRACE( "WRITE from %04lX:%04X to handle %d for %d byte\n",
4760 context
->SegDs
, DX_reg(context
),
4761 BX_reg(context
), CX_reg(context
) );
4763 BYTE
*ptr
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4765 if (!DOSVM_IsWin16() &&
4766 (BX_reg(context
) == 1 || BX_reg(context
) == 2))
4769 for(i
=0; i
<CX_reg(context
); i
++)
4770 DOSVM_PutChar(ptr
[i
]);
4771 SET_AX(context
, CX_reg(context
));
4772 RESET_CFLAG(context
);
4776 HFILE handle
= (HFILE
)DosFileHandleToWin32Handle(BX_reg(context
));
4777 LONG result
= _hwrite( handle
, ptr
, CX_reg(context
) );
4778 if (result
== HFILE_ERROR
)
4779 bSetDOSExtendedError
= TRUE
;
4782 SET_AX( context
, (WORD
)result
);
4783 RESET_CFLAG(context
);
4789 case 0x41: /* "UNLINK" - DELETE FILE */
4791 WCHAR fileW
[MAX_PATH
];
4792 char *fileA
= CTX_SEG_OFF_TO_LIN(context
,
4796 TRACE( "UNLINK %s\n", fileA
);
4797 MultiByteToWideChar(CP_OEMCP
, 0, fileA
, -1, fileW
, MAX_PATH
);
4799 if (!DeleteFileW( fileW
))
4800 bSetDOSExtendedError
= TRUE
;
4802 RESET_CFLAG(context
);
4806 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
4807 TRACE( "LSEEK handle %d offset %ld from %s\n",
4809 MAKELONG( DX_reg(context
), CX_reg(context
) ),
4810 (AL_reg(context
) == 0) ?
4811 "start of file" : ((AL_reg(context
) == 1) ?
4812 "current file position" : "end of file") );
4814 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
4815 LONG offset
= MAKELONG( DX_reg(context
), CX_reg(context
) );
4816 DWORD status
= SetFilePointer( handle
, offset
,
4817 NULL
, AL_reg(context
) );
4818 if (status
== INVALID_SET_FILE_POINTER
)
4819 bSetDOSExtendedError
= TRUE
;
4822 SET_AX( context
, LOWORD(status
) );
4823 SET_DX( context
, HIWORD(status
) );
4824 RESET_CFLAG(context
);
4829 case 0x43: /* FILE ATTRIBUTES */
4830 if (!INT21_FileAttributes( context
, AL_reg(context
), FALSE
))
4831 bSetDOSExtendedError
= TRUE
;
4833 RESET_CFLAG(context
);
4836 case 0x44: /* IOCTL */
4837 INT21_Ioctl( context
);
4840 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
4841 TRACE( "DUPLICATE FILE HANDLE %d\n", BX_reg(context
) );
4844 HFILE handle16
= HFILE_ERROR
;
4846 if (DuplicateHandle( GetCurrentProcess(),
4847 DosFileHandleToWin32Handle(BX_reg(context
)),
4848 GetCurrentProcess(),
4850 0, TRUE
, DUPLICATE_SAME_ACCESS
))
4851 handle16
= Win32HandleToDosFileHandle(handle32
);
4853 if (handle16
== HFILE_ERROR
)
4854 bSetDOSExtendedError
= TRUE
;
4857 SET_AX( context
, handle16
);
4858 RESET_CFLAG(context
);
4863 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
4864 TRACE( "FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
4865 BX_reg(context
), CX_reg(context
) );
4866 if (!INT21_Dup2(BX_reg(context
), CX_reg(context
)))
4867 bSetDOSExtendedError
= TRUE
;
4869 RESET_CFLAG(context
);
4872 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
4873 if (!INT21_GetCurrentDirectory( context
, FALSE
))
4874 bSetDOSExtendedError
= TRUE
;
4876 RESET_CFLAG(context
);
4879 case 0x48: /* ALLOCATE MEMORY */
4880 TRACE( "ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context
) );
4883 DWORD bytes
= (DWORD
)BX_reg(context
) << 4;
4885 if (!ISV86(context
) && DOSVM_IsWin16())
4887 DWORD rv
= GlobalDOSAlloc16( bytes
);
4888 selector
= LOWORD( rv
);
4891 DOSMEM_GetBlock( bytes
, &selector
);
4895 SET_AX( context
, selector
);
4896 RESET_CFLAG(context
);
4901 SET_AX( context
, 0x0008 ); /* insufficient memory */
4902 SET_BX( context
, DOSMEM_Available() >> 4 );
4907 case 0x49: /* FREE MEMORY */
4908 TRACE( "FREE MEMORY segment %04lX\n", context
->SegEs
);
4912 if (!ISV86(context
) && DOSVM_IsWin16())
4914 ok
= !GlobalDOSFree16( context
->SegEs
);
4916 /* If we don't reset ES_reg, we will fail in the relay code */
4921 ok
= DOSMEM_FreeBlock( (void*)((DWORD
)context
->SegEs
<< 4) );
4925 TRACE("FREE MEMORY failed\n");
4927 SET_AX( context
, 0x0009 ); /* memory block address invalid */
4932 case 0x4a: /* RESIZE MEMORY BLOCK */
4933 TRACE( "RESIZE MEMORY segment %04lX to %d paragraphs\n",
4934 context
->SegEs
, BX_reg(context
) );
4936 DWORD newsize
= (DWORD
)BX_reg(context
) << 4;
4938 if (!ISV86(context
) && DOSVM_IsWin16())
4940 FIXME( "Resize memory block - unsupported under Win16\n" );
4945 LPVOID address
= (void*)((DWORD
)context
->SegEs
<< 4);
4946 UINT blocksize
= DOSMEM_ResizeBlock( address
, newsize
, FALSE
);
4948 RESET_CFLAG(context
);
4949 if (blocksize
== (UINT
)-1)
4951 SET_CFLAG( context
);
4952 SET_AX( context
, 0x0009 ); /* illegal address */
4954 else if(blocksize
!= newsize
)
4956 SET_CFLAG( context
);
4957 SET_AX( context
, 0x0008 ); /* insufficient memory */
4958 SET_BX( context
, blocksize
>> 4 ); /* new block size */
4964 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
4966 BYTE
*program
= CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
);
4967 BYTE
*paramblk
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
4969 TRACE( "EXEC %s\n", program
);
4971 RESET_CFLAG(context
);
4972 if (DOSVM_IsWin16())
4974 HINSTANCE16 instance
= WinExec16( program
, SW_NORMAL
);
4977 SET_CFLAG( context
);
4978 SET_AX( context
, instance
);
4983 if (!MZ_Exec( context
, program
, AL_reg(context
), paramblk
))
4984 bSetDOSExtendedError
= TRUE
;
4989 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
4990 TRACE( "EXIT with return code %d\n", AL_reg(context
) );
4991 if (DOSVM_IsWin16())
4992 ExitThread( AL_reg(context
) );
4993 else if(ISV86(context
))
4994 MZ_Exit( context
, FALSE
, AL_reg(context
) );
5000 DWORD rv
= AL_reg(context
);
5001 RaiseException( EXCEPTION_VM86_INTx
, 0, 1, &rv
);
5005 case 0x4d: /* GET RETURN CODE */
5006 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
5007 SET_AX( context
, DOSVM_retval
);
5011 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
5012 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context
),
5013 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Edx
));
5014 if (!INT21_FindFirst(context
)) break;
5017 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
5018 TRACE("FINDNEXT\n");
5019 if (!INT21_FindNext(context
))
5021 SetLastError( ERROR_NO_MORE_FILES
);
5022 SET_AX( context
, ERROR_NO_MORE_FILES
);
5025 else SET_AX( context
, 0 ); /* OK */
5028 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
5029 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
5030 DOSVM_psp
= BX_reg(context
);
5033 case 0x51: /* GET PSP ADDRESS */
5034 INT21_GetPSP( context
);
5037 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
5039 SEGPTR ptr
= DOSDEV_GetLOL( ISV86(context
) || !DOSVM_IsWin16() );
5040 context
->SegEs
= SELECTOROF(ptr
);
5041 SET_BX( context
, OFFSETOF(ptr
) );
5045 case 0x54: /* Get Verify Flag */
5046 TRACE("Get Verify Flag - Not Supported\n");
5047 SET_AL( context
, 0x00 ); /* pretend we can tell. 00h = off 01h = on */
5050 case 0x56: /* "RENAME" - RENAME FILE */
5051 if (!INT21_RenameFile( context
))
5052 bSetDOSExtendedError
= TRUE
;
5054 RESET_CFLAG(context
);
5057 case 0x57: /* FILE DATE AND TIME */
5058 if (!INT21_FileDateTime( context
))
5059 bSetDOSExtendedError
= TRUE
;
5061 RESET_CFLAG(context
);
5064 case 0x58: /* GET OR SET MEMORY ALLOCATION STRATEGY */
5065 switch (AL_reg(context
))
5067 case 0x00: /* GET MEMORY ALLOCATION STRATEGY */
5068 TRACE( "GET MEMORY ALLOCATION STRATEGY\n" );
5069 SET_AX( context
, 0 ); /* low memory first fit */
5072 case 0x01: /* SET ALLOCATION STRATEGY */
5073 TRACE( "SET MEMORY ALLOCATION STRATEGY to %d - ignored\n",
5077 case 0x02: /* GET UMB LINK STATE */
5078 TRACE( "GET UMB LINK STATE\n" );
5079 SET_AL( context
, 0 ); /* UMBs not part of DOS memory chain */
5082 case 0x03: /* SET UMB LINK STATE */
5083 TRACE( "SET UMB LINK STATE to %d - ignored\n",
5088 INT_BARF( context
, 0x21 );
5092 case 0x59: /* GET EXTENDED ERROR INFO */
5093 INT21_GetExtendedError( context
);
5096 case 0x5a: /* CREATE TEMPORARY FILE */
5097 TRACE("CREATE TEMPORARY FILE\n");
5098 bSetDOSExtendedError
= !INT21_CreateTempFile(context
);
5101 case 0x5b: /* CREATE NEW FILE */
5102 if (!INT21_CreateFile( context
, context
->Edx
, FALSE
,
5103 OF_READWRITE
| OF_SHARE_COMPAT
, 0x10 ))
5104 bSetDOSExtendedError
= TRUE
;
5106 RESET_CFLAG(context
);
5109 case 0x5c: /* "FLOCK" - RECORD LOCKING */
5111 DWORD offset
= MAKELONG(DX_reg(context
), CX_reg(context
));
5112 DWORD length
= MAKELONG(DI_reg(context
), SI_reg(context
));
5113 HANDLE handle
= DosFileHandleToWin32Handle(BX_reg(context
));
5115 RESET_CFLAG(context
);
5116 switch (AL_reg(context
))
5118 case 0x00: /* LOCK */
5119 TRACE( "lock handle %d offset %ld length %ld\n",
5120 BX_reg(context
), offset
, length
);
5121 if (!LockFile( handle
, offset
, 0, length
, 0 ))
5122 bSetDOSExtendedError
= TRUE
;
5125 case 0x01: /* UNLOCK */
5126 TRACE( "unlock handle %d offset %ld length %ld\n",
5127 BX_reg(context
), offset
, length
);
5128 if (!UnlockFile( handle
, offset
, 0, length
, 0 ))
5129 bSetDOSExtendedError
= TRUE
;
5133 INT_BARF( context
, 0x21 );
5138 case 0x5d: /* NETWORK 5D */
5139 FIXME( "Network function 5D not implemented.\n" );
5140 SetLastError( ER_NoNetwork
);
5141 bSetDOSExtendedError
= TRUE
;
5144 case 0x5e: /* NETWORK 5E */
5145 bSetDOSExtendedError
= INT21_NetworkFunc( context
);
5148 case 0x5f: /* NETWORK 5F */
5149 /* FIXME: supporting this would need to 1:
5150 * - implement per drive current directory (as kernel32 doesn't)
5151 * - assign enabled/disabled flag on a per drive basis
5153 /* network software not installed */
5154 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context
));
5155 SetLastError( ER_NoNetwork
);
5156 bSetDOSExtendedError
= TRUE
;
5159 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
5161 WCHAR pathW
[MAX_PATH
], res
[MAX_PATH
];
5162 /* FIXME: likely to be broken */
5164 TRACE("TRUENAME %s\n",
5165 (LPCSTR
)CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
,context
->Esi
));
5166 MultiByteToWideChar(CP_OEMCP
, 0, CTX_SEG_OFF_TO_LIN(context
, context
->SegDs
, context
->Esi
), -1, pathW
, MAX_PATH
);
5167 if (!GetFullPathNameW( pathW
, 128, res
, NULL
))
5168 bSetDOSExtendedError
= TRUE
;
5171 SET_AX( context
, 0 );
5172 WideCharToMultiByte(CP_OEMCP
, 0, res
, -1,
5173 CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Edi
),
5179 case 0x61: /* UNUSED */
5180 SET_AL( context
, 0 );
5183 case 0x62: /* GET PSP ADDRESS */
5184 INT21_GetPSP( context
);
5187 case 0x63: /* MISC. LANGUAGE SUPPORT */
5188 switch (AL_reg(context
)) {
5189 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
5190 TRACE( "GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE\n" );
5191 context
->SegDs
= INT21_GetHeapSelector( context
);
5192 SET_SI( context
, offsetof(INT21_HEAP
, dbcs_table
) );
5193 SET_AL( context
, 0 ); /* success */
5198 case 0x64: /* OS/2 DOS BOX */
5199 INT_BARF( context
, 0x21 );
5203 case 0x65: /* EXTENDED COUNTRY INFORMATION */
5204 INT21_ExtendedCountryInformation( context
);
5207 case 0x66: /* GLOBAL CODE PAGE TABLE */
5208 switch (AL_reg(context
))
5211 TRACE( "GET GLOBAL CODE PAGE TABLE\n" );
5212 SET_BX( context
, GetOEMCP() );
5213 SET_DX( context
, GetOEMCP() );
5216 FIXME( "SET GLOBAL CODE PAGE TABLE, active %d, system %d - ignored\n",
5217 BX_reg(context
), DX_reg(context
) );
5222 case 0x67: /* SET HANDLE COUNT */
5223 TRACE( "SET HANDLE COUNT to %d\n", BX_reg(context
) );
5224 if (SetHandleCount( BX_reg(context
) ) < BX_reg(context
) )
5225 bSetDOSExtendedError
= TRUE
;
5228 case 0x68: /* "FFLUSH" - COMMIT FILE */
5229 TRACE( "FFLUSH - handle %d\n", BX_reg(context
) );
5230 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
5231 bSetDOSExtendedError
= TRUE
;
5234 case 0x69: /* DISK SERIAL NUMBER */
5235 switch (AL_reg(context
))
5238 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
5239 INT21_DriveName(BL_reg(context
)));
5240 if (!INT21_GetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
5241 else SET_AX( context
, 0 );
5245 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
5246 INT21_DriveName(BL_reg(context
)));
5247 if (!INT21_SetDiskSerialNumber(context
)) bSetDOSExtendedError
= TRUE
;
5248 else SET_AX( context
, 1 );
5253 case 0x6a: /* COMMIT FILE */
5254 TRACE( "COMMIT FILE - handle %d\n", BX_reg(context
) );
5255 if (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context
)) ))
5256 bSetDOSExtendedError
= TRUE
;
5259 case 0x6b: /* NULL FUNCTION FOR CP/M COMPATIBILITY */
5260 SET_AL( context
, 0 );
5263 case 0x6c: /* EXTENDED OPEN/CREATE */
5264 if (!INT21_CreateFile( context
, context
->Esi
, TRUE
,
5265 BX_reg(context
), DL_reg(context
) ))
5266 bSetDOSExtendedError
= TRUE
;
5269 case 0x70: /* MSDOS 7 - GET/SET INTERNATIONALIZATION INFORMATION */
5270 FIXME( "MS-DOS 7 - GET/SET INTERNATIONALIZATION INFORMATION\n" );
5271 SET_CFLAG( context
);
5272 SET_AL( context
, 0 );
5275 case 0x71: /* MSDOS 7 - LONG FILENAME FUNCTIONS */
5276 INT21_LongFilename( context
);
5279 case 0x73: /* MSDOS7 - FAT32 */
5280 RESET_CFLAG( context
);
5281 if (!INT21_Fat32( context
))
5282 bSetDOSExtendedError
= TRUE
;
5285 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
5286 TRACE( "CONNECTION SERVICES - GET CONNECTION NUMBER - ignored\n" );
5289 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
5290 TRACE( "NOVELL NETWARE - RETURN SHELL VERSION - ignored\n" );
5293 case 0xff: /* DOS32 EXTENDER (DOS/4GW) - API */
5294 /* we don't implement a DOS32 extender */
5295 TRACE( "DOS32 EXTENDER API - ignored\n" );
5299 INT_BARF( context
, 0x21 );
5302 } /* END OF SWITCH */
5304 /* Set general error condition. */
5305 if (bSetDOSExtendedError
)
5307 SET_AX( context
, GetLastError() );
5308 SET_CFLAG( context
);
5311 /* Print error code if carry flag is set. */
5312 if (context
->EFlags
& 0x0001)
5313 TRACE("failed, error %ld\n", GetLastError() );
5315 TRACE( "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
5316 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
5317 AX_reg(context
), BX_reg(context
),
5318 CX_reg(context
), DX_reg(context
),
5319 SI_reg(context
), DI_reg(context
),
5320 (WORD
)context
->SegDs
, (WORD
)context
->SegEs
,