2 * DOS interrupt 21h handler
4 * Copyright 1993, 1994 Erik Bos
5 * Copyright 1996 Alexandre Julliard
6 * Copyright 1997 Andreas Mohr
7 * Copyright 1998 Uwe Bonnes
8 * Copyright 1998, 1999 Ove Kaaven
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #ifdef HAVE_SYS_FILE_H
33 # include <sys/file.h>
37 #include <sys/types.h>
45 #include "winuser.h" /* SW_NORMAL */
46 #include "wine/winbase16.h"
54 #include "wine/debug.h"
56 WINE_DEFAULT_DEBUG_CHANNEL(int21);
57 #if defined(__svr4__) || defined(_SCO_DS)
58 /* SVR4 DOESNT do locking the same way must implement properly */
65 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
67 /* Define the drive parameter block, as used by int21/1F
68 * and int21/32. This table can be accessed through the
69 * global 'dpb' pointer, which points into the local dos
74 BYTE drive_num; /* 0=A, etc. */
75 BYTE unit_num; /* Drive's unit number (?) */
76 WORD sector_size; /* Sector size in bytes */
77 BYTE high_sector; /* Highest sector in a cluster */
78 BYTE shift; /* Shift count (?) */
79 WORD reserved; /* Number of reserved sectors at start */
80 BYTE num_FAT; /* Number of FATs */
81 WORD dir_entries; /* Number of root dir entries */
82 WORD first_data; /* First data sector */
83 WORD high_cluster; /* Highest cluster number */
84 WORD sectors_in_FAT; /* Number of sectors per FAT */
85 WORD start_dir; /* Starting sector of first dir */
86 DWORD driver_head; /* Address of device driver header (?) */
87 BYTE media_ID; /* Media ID */
88 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
89 DWORD next; /* Pointer to next DPB in list */
90 WORD free_search; /* Free cluster search start */
91 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
94 struct EDPB /* FAT32 extended Drive Parameter Block */
95 { /* from Ralf Brown's Interrupt List */
96 struct DPB dpb; /* first 24 bytes = original DPB */
98 BYTE edpb_flags; /* undocumented/unknown flags */
99 DWORD next_edpb; /* pointer to next EDPB */
100 WORD free_cluster; /* cluster to start search for free space on write, typically
101 the last cluster allocated */
102 WORD clusters_free; /* number of free clusters on drive or FFFF = unknown */
103 WORD clusters_free_hi; /* hiword of clusters_free */
104 WORD mirroring_flags; /* mirroring flags: bit 7 set = do not mirror active FAT */
105 /* bits 0-3 = 0-based number of the active FAT */
106 WORD info_sector; /* sector number of file system info sector, or FFFF for none */
107 WORD spare_boot_sector; /* sector number of backup boot sector, or FFFF for none */
108 DWORD first_cluster; /* sector number of the first cluster */
109 DWORD max_cluster; /* sector number of the last cluster */
110 DWORD fat_clusters; /* number of clusters occupied by FAT */
111 DWORD root_cluster; /* cluster number of start of root directory */
112 DWORD free_cluster2; /* same as free_cluster: cluster at which to start
113 search for free space when writing */
125 BYTE DummyDBCSLeadTable[6];
127 static struct DosHeap *heap;
128 static WORD DosHeapHandle;
130 extern char TempDirectory[];
132 static void INT21_ReadConfigSys(void)
135 if (!done) DOSCONF_ReadConfig();
139 static BOOL INT21_CreateHeap(void)
141 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
143 WARN("Out of memory\n");
146 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
147 dpbsegptr = MAKESEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
149 strcpy(heap->biosdate, "01/01/80");
150 memset(heap->DummyDBCSLeadTable, 0, 6);
154 static BYTE *GetCurrentDTA( CONTEXT86 *context )
156 TDB *pTask = TASK_GetCurrent();
158 /* FIXME: This assumes DTA was set correctly! */
159 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
160 (DWORD)OFFSETOF(pTask->dta) );
164 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
165 /* limited == TRUE is used with INT 0x21/0x440d */
170 setword(&data[3], 0);
172 setword(&data[6], 240);
173 setword(&data[8], 64000);
175 setword(&data[0x0b], 40);
176 setword(&data[0x0d], 56);
177 setword(&data[0x0f], 2);
178 setword(&data[0x11], 0);
180 setword(&data[0x1f], 800);
182 setword(&data[0x22], 1);
184 } else { /* 1.44mb */
187 setword(&data[3], 0);
189 setword(&data[6], 240);
190 setword(&data[8], 2880);
192 setword(&data[0x0b], 6);
193 setword(&data[0x0d], 18);
194 setword(&data[0x0f], 2);
195 setword(&data[0x11], 0);
197 setword(&data[0x1f], 80);
199 setword(&data[0x22], 2);
204 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
206 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
207 char root[] = "A:\\";
209 *root += DOS_GET_DRIVE( DL_reg(context) );
210 if (!GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
211 &free_clusters, &total_clusters )) return 0;
212 AX_reg(context) = cluster_sectors;
213 BX_reg(context) = free_clusters;
214 CX_reg(context) = sector_bytes;
215 DX_reg(context) = total_clusters;
219 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
221 if (!INT21_GetFreeDiskSpace( context )) return 0;
222 if (!heap && !INT21_CreateHeap()) return 0;
223 heap->mediaID = 0xf0;
224 context->SegDs = DosHeapHandle;
225 BX_reg(context) = (int)&heap->mediaID - (int)heap;
229 static int FillInDrivePB( int drive )
231 if(!DRIVE_IsValid(drive))
233 SetLastError( ERROR_INVALID_DRIVE );
236 else if (heap || INT21_CreateHeap())
238 /* FIXME: I have no idea what a lot of this information should
239 * say or whether it even really matters since we're not allowing
240 * direct block access. However, some programs seem to depend on
241 * getting at least _something_ back from here. The 'next' pointer
242 * does worry me, though. Should we have a complete table of
243 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
245 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
246 heap->dpb.sector_size = 512;
247 heap->dpb.high_sector = 1;
248 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
249 heap->dpb.reserved = 0;
250 heap->dpb.num_FAT = 1;
251 heap->dpb.dir_entries = 2;
252 heap->dpb.first_data = 2;
253 heap->dpb.high_cluster = 64000;
254 heap->dpb.sectors_in_FAT = 1;
255 heap->dpb.start_dir = 1;
256 heap->dpb.driver_head = 0;
257 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
258 heap->dpb.access_flag = 0;
260 heap->dpb.free_search = 0;
261 heap->dpb.free_clusters = 0xFFFF; /* unknown */
268 static void GetDrivePB( CONTEXT86 *context, int drive )
270 if (FillInDrivePB( drive ))
272 AL_reg(context) = 0x00;
273 context->SegDs = SELECTOROF(dpbsegptr);
274 BX_reg(context) = OFFSETOF(dpbsegptr);
278 AX_reg(context) = 0x00ff;
283 static void ioctlGetDeviceInfo( CONTEXT86 *context )
286 const DOS_DEVICE *dev;
288 TRACE("(%d)\n", BX_reg(context));
290 RESET_CFLAG(context);
293 if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )))
295 DX_reg(context) = dev->flags;
299 /* it seems to be a file */
300 curr_drive = DRIVE_GetCurrentDrive();
301 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
303 /* bits 0-5 are current drive
304 * bit 6 - file has NOT been written..FIXME: correct?
305 * bit 8 - generate int24 if no diskspace on write/ read past end of file
306 * bit 11 - media not removable
307 * bit 14 - don't set file date/time on closing
308 * bit 15 - file is remote
312 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
314 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
315 int drive = DOS_GET_DRIVE( BL_reg(context) );
317 if (!DRIVE_IsValid(drive))
319 SetLastError( ERROR_FILE_NOT_FOUND );
323 if (CH_reg(context) != 0x08)
325 INT_BARF( context, 0x21 );
329 switch (CL_reg(context))
331 case 0x4a: /* lock logical volume */
332 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
335 case 0x60: /* get device parameters */
336 /* used by w4wgrp's winfile */
337 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
339 dataptr[6] = 0; /* media type */
342 dataptr[1] = 0x05; /* fixed disk */
343 setword(&dataptr[2], 0x01); /* non removable */
344 setword(&dataptr[4], 0x300); /* # of cylinders */
348 dataptr[1] = 0x07; /* block dev, floppy */
349 setword(&dataptr[2], 0x02); /* removable */
350 setword(&dataptr[4], 80); /* # of cylinders */
352 CreateBPB(drive, &dataptr[7], TRUE);
353 RESET_CFLAG(context);
356 case 0x41: /* write logical device track */
357 case 0x61: /* read logical device track */
359 BYTE drive = BL_reg(context) ?
360 BL_reg(context) : DRIVE_GetCurrentDrive();
361 WORD head = *(WORD *)dataptr+1;
362 WORD cyl = *(WORD *)dataptr+3;
363 WORD sect = *(WORD *)dataptr+5;
364 WORD nrsect = *(WORD *)dataptr+7;
365 BYTE *data = (BYTE *)dataptr+9;
366 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
368 raw_func = (CL_reg(context) == 0x41) ?
369 DRIVE_RawWrite : DRIVE_RawRead;
371 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
372 RESET_CFLAG(context);
375 AX_reg(context) = 0x1e; /* read fault */
380 case 0x66:/* get disk serial number */
382 char label[12],fsname[9],path[4];
385 strcpy(path,"x:\\");path[0]=drive+'A';
386 GetVolumeInformationA(
387 path,label,12,&serial,NULL,NULL,fsname,9
390 memcpy(dataptr+2,&serial,4);
391 memcpy(dataptr+6,label ,11);
392 memcpy(dataptr+17,fsname,8);
397 TRACE("logical volume %d unlocked.\n",drive);
401 memset(dataptr+1, '\0', dataptr[0]-1);
402 dataptr[1] = dataptr[0];
403 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
404 dataptr[3] = 0xFF; /* no physical drive */
408 /* Trail on error implementation */
409 AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_UNKNOWN ? 0x0f : 0x01;
410 SET_CFLAG(context); /* Seems to be set all the time */
414 INT_BARF( context, 0x21 );
419 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
422 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
424 CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi );
425 char *buffer, *s, *d;
427 AL_reg(context) = 0xff; /* failed */
429 TRACE("filename: '%s'\n", filename);
431 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
437 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
444 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
446 TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
448 HeapFree( GetProcessHeap(), 0, buffer);
451 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
453 /* point DS:SI to first unparsed character */
454 SI_reg(context) += (int)s - (int)filename;
457 static void INT21_GetSystemDate( CONTEXT86 *context )
460 GetLocalTime( &systime );
461 CX_reg(context) = systime.wYear;
462 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
463 AX_reg(context) = systime.wDayOfWeek;
466 static void INT21_GetSystemTime( CONTEXT86 *context )
469 GetLocalTime( &systime );
470 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
471 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
474 /* Many calls translate a drive argument like this:
475 drive number (00h = default, 01h = A:, etc)
477 static char drivestring[]="default";
479 char *INT21_DriveName(int drive)
484 drivestring[0]= (unsigned char)drive + '@';
490 static BOOL INT21_CreateFile( CONTEXT86 *context )
492 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
493 context->Edx ), CX_reg(context) );
494 return (AX_reg(context) == (WORD)HFILE_ERROR16);
497 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
499 /* Mask off all flags not explicitly allowed by the doc */
500 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
501 return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
502 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
503 CREATE_NEW, attr, 0 ));
506 static void OpenExistingFile( CONTEXT86 *context )
508 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
510 if (AX_reg(context) == (WORD)HFILE_ERROR16)
512 AX_reg(context) = GetLastError();
517 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
519 BOOL bExtendedError = FALSE;
520 BYTE action = DL_reg(context);
522 /* Shuffle arguments to call OpenExistingFile */
523 AL_reg(context) = BL_reg(context);
524 DX_reg(context) = SI_reg(context);
525 /* BX,CX and DX should be preserved */
526 OpenExistingFile(context);
528 if ((context->EFlags & 0x0001) == 0) /* File exists */
530 UINT16 uReturnCX = 0;
532 /* Now decide what do do */
534 if ((action & 0x07) == 0)
536 _lclose16( AX_reg(context) );
537 AX_reg(context) = 0x0050; /*File exists*/
539 WARN("extended open/create: failed because file exists \n");
541 else if ((action & 0x07) == 2)
543 /* Truncate it, but first check if opened for write */
544 if ((BL_reg(context) & 0x0007)== 0)
546 _lclose16( AX_reg(context) );
547 WARN("extended open/create: failed, trunc on ro file\n");
548 AX_reg(context) = 0x000C; /*Access code invalid*/
553 TRACE("extended open/create: Closing before truncate\n");
554 if (_lclose16( AX_reg(context) ))
556 WARN("extended open/create: close before trunc failed\n");
557 AX_reg(context) = 0x0019; /*Seek Error*/
561 /* Shuffle arguments to call CreateFile */
563 TRACE("extended open/create: Truncating\n");
564 AL_reg(context) = BL_reg(context);
565 /* CX is still the same */
566 DX_reg(context) = SI_reg(context);
567 bExtendedError = INT21_CreateFile(context);
569 if (context->EFlags & 0x0001) /*no file open, flags set */
571 WARN("extended open/create: trunc failed\n");
572 return bExtendedError;
577 else uReturnCX = 0x1;
579 CX_reg(context) = uReturnCX;
581 else /* file does not exist */
583 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
584 if ((action & 0xF0)== 0)
588 WARN("extended open/create: failed, file dosen't exist\n");
592 /* Shuffle arguments to call CreateFile */
593 TRACE("extended open/create: Creating\n");
594 AL_reg(context) = BL_reg(context);
595 /* CX should still be the same */
596 DX_reg(context) = SI_reg(context);
597 bExtendedError = INT21_CreateFile(context);
598 if (context->EFlags & 0x0001) /*no file open, flags set */
600 WARN("extended open/create: create failed\n");
601 return bExtendedError;
607 return bExtendedError;
611 static BOOL INT21_ChangeDir( CONTEXT86 *context )
614 char *dirname = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
616 TRACE("changedir %s\n", dirname);
617 if (dirname[0] && (dirname[1] == ':'))
619 drive = toupper(dirname[0]) - 'A';
622 else drive = DRIVE_GetCurrentDrive();
623 return DRIVE_Chdir( drive, dirname );
627 static int INT21_FindFirst( CONTEXT86 *context )
631 DOS_FULL_NAME full_name;
632 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
634 path = (const char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
635 dta->unixPath = NULL;
636 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
638 AX_reg(context) = GetLastError();
642 dta->unixPath = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
643 strcpy( dta->unixPath, full_name.long_name );
644 p = strrchr( dta->unixPath, '/' );
647 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
648 * (doesn't matter as it is set below anyway)
650 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
652 HeapFree( GetProcessHeap(), 0, dta->unixPath );
653 dta->unixPath = NULL;
654 SetLastError( ERROR_FILE_NOT_FOUND );
655 AX_reg(context) = ERROR_FILE_NOT_FOUND;
659 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
660 : DRIVE_GetCurrentDrive();
662 dta->search_attr = CL_reg(context);
667 static int INT21_FindNext( CONTEXT86 *context )
669 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
670 WIN32_FIND_DATAA entry;
673 if (!dta->unixPath) return 0;
674 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
675 dta->search_attr, dta->count, &entry )))
677 HeapFree( GetProcessHeap(), 0, dta->unixPath );
678 dta->unixPath = NULL;
681 if ((int)dta->count + count > 0xffff)
683 WARN("Too many directory entries in %s\n", dta->unixPath );
684 HeapFree( GetProcessHeap(), 0, dta->unixPath );
685 dta->unixPath = NULL;
689 dta->fileattr = entry.dwFileAttributes;
690 dta->filesize = entry.nFileSizeLow;
691 FileTimeToDosDateTime( &entry.ftLastWriteTime,
692 &dta->filedate, &dta->filetime );
693 strcpy( dta->filename, entry.cAlternateFileName );
694 if (!memchr(dta->mask,'?',11)) {
695 /* wildcardless search, release resources in case no findnext will
696 * be issued, and as a workaround in case file creation messes up
697 * findnext, as sometimes happens with pkunzip */
698 HeapFree( GetProcessHeap(), 0, dta->unixPath );
699 dta->unixPath = NULL;
705 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
707 static int counter = 0;
708 char *name = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx );
709 char *p = name + strlen(name);
711 /* despite what Ralf Brown says, some programs seem to call without
712 * ending backslash (DOS accepts that, so we accept it too) */
713 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
717 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
718 counter = (counter + 1) % 1000;
720 if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
722 TRACE("created %s\n", name );
725 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
730 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
732 int drive = DOS_GET_DRIVE( DL_reg(context) );
733 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
735 if (!DRIVE_IsValid(drive))
737 SetLastError( ERROR_INVALID_DRIVE );
740 lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
741 AX_reg(context) = 0x0100; /* success return code */
746 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
748 if (heap || INT21_CreateHeap())
749 { /* return an empty table just as DOS 4.0+ does */
750 context->SegDs = DosHeapHandle;
751 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
755 AX_reg(context) = 0x1; /* error */
761 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
763 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
764 int drive = DOS_GET_DRIVE( BL_reg(context) );
766 if (!DRIVE_IsValid(drive))
768 SetLastError( ERROR_INVALID_DRIVE );
772 *(WORD *)dataptr = 0;
773 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
774 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
775 strncpy(dataptr + 0x11, "FAT16 ", 8);
780 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
782 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
783 int drive = DOS_GET_DRIVE( BL_reg(context) );
785 if (!DRIVE_IsValid(drive))
787 SetLastError( ERROR_INVALID_DRIVE );
791 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
796 /* microsoft's programmers should be shot for using CP/M style int21
797 calls in Windows for Workgroup's winfile.exe */
799 static int INT21_FindFirstFCB( CONTEXT86 *context )
801 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
806 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
807 else pFCB = (FINDFILE_FCB *)fcb;
808 drive = DOS_GET_DRIVE( pFCB->drive );
809 if (!DRIVE_IsValid( drive )) return 0;
810 root = DRIVE_GetRoot( drive );
811 cwd = DRIVE_GetUnixCwd( drive );
812 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
813 strlen(root)+strlen(cwd)+2 );
814 if (!pFCB->unixPath) return 0;
815 strcpy( pFCB->unixPath, root );
816 strcat( pFCB->unixPath, "/" );
817 strcat( pFCB->unixPath, cwd );
823 static int INT21_FindNextFCB( CONTEXT86 *context )
825 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
827 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
828 WIN32_FIND_DATAA entry;
832 if (*fcb == 0xff) /* extended FCB ? */
835 pFCB = (FINDFILE_FCB *)(fcb + 7);
840 pFCB = (FINDFILE_FCB *)fcb;
843 if (!pFCB->unixPath) return 0;
844 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
845 DOS_GET_DRIVE( pFCB->drive ), attr,
846 pFCB->count, &entry )))
848 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
849 pFCB->unixPath = NULL;
852 pFCB->count += count;
854 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
855 *(BYTE *)pResult = 0xff;
856 (BYTE *)pResult +=6; /* leave reserved field behind */
857 *(BYTE *)pResult = entry.dwFileAttributes;
860 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
862 pResult->fileattr = entry.dwFileAttributes;
863 pResult->cluster = 0; /* what else? */
864 pResult->filesize = entry.nFileSizeLow;
865 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
866 FileTimeToDosDateTime( &entry.ftLastWriteTime,
867 &pResult->filedate, &pResult->filetime );
869 /* Convert file name to FCB format */
871 memset( pResult->filename, ' ', sizeof(pResult->filename) );
872 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
873 else if (!strcmp( entry.cAlternateFileName, ".." ))
874 pResult->filename[0] = pResult->filename[1] = '.';
877 char *p = strrchr( entry.cAlternateFileName, '.' );
878 if (p && p[1] && (p != entry.cAlternateFileName))
880 memcpy( pResult->filename, entry.cAlternateFileName,
881 min( (p - entry.cAlternateFileName), 8 ) );
882 memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
885 memcpy( pResult->filename, entry.cAlternateFileName,
886 min( strlen(entry.cAlternateFileName), 8 ) );
892 static void DeleteFileFCB( CONTEXT86 *context )
894 FIXME("(%p): stub\n", context);
897 static void RenameFileFCB( CONTEXT86 *context )
899 FIXME("(%p): stub\n", context);
904 static void fLock( CONTEXT86 * context )
907 switch ( AX_reg(context) & 0xff )
909 case 0x00: /* LOCK */
910 TRACE("lock handle %d offset %ld length %ld\n",
912 MAKELONG(DX_reg(context),CX_reg(context)),
913 MAKELONG(DI_reg(context),SI_reg(context))) ;
914 if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context)),
915 MAKELONG(DX_reg(context),CX_reg(context)), 0,
916 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
917 AX_reg(context) = GetLastError();
922 case 0x01: /* UNLOCK */
923 TRACE("unlock handle %d offset %ld length %ld\n",
925 MAKELONG(DX_reg(context),CX_reg(context)),
926 MAKELONG(DI_reg(context),SI_reg(context))) ;
927 if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context)),
928 MAKELONG(DX_reg(context),CX_reg(context)), 0,
929 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
930 AX_reg(context) = GetLastError();
935 AX_reg(context) = 0x0001;
942 INT21_networkfunc (CONTEXT86 *context)
944 switch (AL_reg(context)) {
945 case 0x00: /* Get machine name. */
947 char *dst = CTX_SEG_OFF_TO_LIN (context,context->SegDs,context->Edx);
948 TRACE("getting machine name to %p\n", dst);
949 if (gethostname (dst, 15))
952 SetLastError( ER_NoNetwork );
955 int len = strlen (dst);
959 CH_reg(context) = 1; /* Valid */
960 CL_reg(context) = 1; /* NETbios number??? */
961 TRACE("returning %s\n", debugstr_an (dst, 16));
967 SetLastError( ER_NoNetwork );
973 static void ASPI_DOS_HandleInt( CONTEXT86 *context )
975 if (!Dosvm.ASPIHandler && !DPMI_LoadDosSystem())
977 ERR("could not setup ASPI handler\n");
980 Dosvm.ASPIHandler( context );
983 /***********************************************************************
984 * INT21_GetExtendedError
986 static void INT21_GetExtendedError( CONTEXT86 *context )
988 BYTE class, action, locus;
989 WORD error = GetLastError();
994 class = action = locus = 0;
996 case ERROR_DIR_NOT_EMPTY:
1001 case ERROR_ACCESS_DENIED:
1002 class = EC_AccessDenied;
1006 case ERROR_CANNOT_MAKE:
1007 class = EC_AccessDenied;
1011 case ERROR_DISK_FULL:
1012 case ERROR_HANDLE_DISK_FULL:
1013 class = EC_MediaError;
1017 case ERROR_FILE_EXISTS:
1018 case ERROR_ALREADY_EXISTS:
1023 case ERROR_FILE_NOT_FOUND:
1024 class = EC_NotFound;
1028 case ER_GeneralFailure:
1029 class = EC_SystemFailure;
1033 case ERROR_INVALID_DRIVE:
1034 class = EC_MediaError;
1038 case ERROR_INVALID_HANDLE:
1039 class = EC_ProgramError;
1043 case ERROR_LOCK_VIOLATION:
1044 class = EC_AccessDenied;
1048 case ERROR_NO_MORE_FILES:
1049 class = EC_MediaError;
1054 class = EC_NotFound;
1058 case ERROR_NOT_ENOUGH_MEMORY:
1059 class = EC_OutOfResource;
1063 case ERROR_PATH_NOT_FOUND:
1064 class = EC_NotFound;
1069 class = EC_NotFound;
1073 case ERROR_SHARING_VIOLATION:
1074 class = EC_Temporary;
1078 case ERROR_TOO_MANY_OPEN_FILES:
1079 class = EC_ProgramError;
1084 FIXME("Unknown error %d\n", error );
1085 class = EC_SystemFailure;
1090 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1091 error, class, action, locus );
1092 AX_reg(context) = error;
1093 BH_reg(context) = class;
1094 BL_reg(context) = action;
1095 CH_reg(context) = locus;
1098 /***********************************************************************
1099 * DOS3Call (KERNEL.102)
1100 * INT_Int21Handler (WPROCS.133)
1102 void WINAPI DOS3Call( CONTEXT86 *context )
1104 BOOL bSetDOSExtendedError = FALSE;
1107 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1108 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1109 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1110 SI_reg(context), DI_reg(context),
1111 (WORD)context->SegDs, (WORD)context->SegEs,
1115 if (AH_reg(context) == 0x59) /* Get extended error info */
1117 INT21_GetExtendedError( context );
1121 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1123 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1124 /* no flush here yet */
1125 AH_reg(context) = AL_reg(context);
1128 if (AH_reg(context)>=0x2f) {
1129 /* extended error is used by (at least) functions 0x2f to 0x62 */
1132 RESET_CFLAG(context); /* Not sure if this is a good idea */
1134 switch(AH_reg(context))
1136 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1137 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1138 case 0x03: /* READ CHARACTER FROM STDAUX */
1139 case 0x04: /* WRITE CHARACTER TO STDAUX */
1140 case 0x05: /* WRITE CHARACTER TO PRINTER */
1141 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1142 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1143 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1144 case 0x0b: /* GET STDIN STATUS */
1145 case 0x0f: /* OPEN FILE USING FCB */
1146 case 0x10: /* CLOSE FILE USING FCB */
1147 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1148 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1149 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1150 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1151 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1152 case 0x23: /* GET FILE SIZE FOR FCB */
1153 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1154 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1155 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1156 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1157 case 0x4d: /* GET RETURN CODE */
1158 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1159 INT_BARF( context, 0x21 );
1162 case 0x00: /* TERMINATE PROGRAM */
1163 TRACE("TERMINATE PROGRAM\n");
1167 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1168 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1169 context->SegDs,DX_reg(context) );
1171 LPSTR data = CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx);
1173 /* do NOT use strchr() to calculate the string length,
1174 as '\0' is valid string content, too !
1175 Maybe we should check for non-'$' strings, but DOS doesn't. */
1176 while (*p != '$') p++;
1177 _hwrite16( 1, data, (int)p - (int)data);
1178 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1182 case 0x0a: /* BUFFERED INPUT */
1184 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1188 TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1190 TRACE("Handle old chars in buffer!\n");
1191 res=_lread16( 0, buffer+2,buffer[0]);
1193 if(buffer[res+1] == '\n')
1194 buffer[res+1] = '\r';
1198 case 0x2e: /* SET VERIFY FLAG */
1199 TRACE("SET VERIFY FLAG ignored\n");
1200 /* we cannot change the behaviour anyway, so just ignore it */
1203 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1207 case 0x6b: /* NULL FUNCTION */
1208 AL_reg(context) = 0;
1211 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1215 case 0x0d: /* DISK BUFFER FLUSH */
1216 TRACE("DISK BUFFER FLUSH ignored\n");
1217 RESET_CFLAG(context); /* dos 6+ only */
1220 case 0x0e: /* SELECT DEFAULT DRIVE */
1221 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1222 DRIVE_SetCurrentDrive( DL_reg(context) );
1223 AL_reg(context) = MAX_DOS_DRIVES;
1226 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1227 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1228 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1229 if (!INT21_FindFirstFCB(context))
1231 AL_reg(context) = 0xff;
1234 /* else fall through */
1236 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1237 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1240 case 0x13: /* DELETE FILE USING FCB */
1241 DeleteFileFCB(context);
1244 case 0x17: /* RENAME FILE USING FCB */
1245 RenameFileFCB(context);
1248 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1249 AL_reg(context) = DRIVE_GetCurrentDrive();
1252 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1254 TDB *pTask = TASK_GetCurrent();
1255 pTask->dta = MAKESEGPTR(context->SegDs,DX_reg(context));
1256 TRACE("Set DTA: %08lx\n", pTask->dta);
1260 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1261 DL_reg(context) = 0;
1262 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1265 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1266 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1269 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1270 GetDrivePB(context, DRIVE_GetCurrentDrive());
1273 case 0x25: /* SET INTERRUPT VECTOR */
1274 INT_SetPMHandler( AL_reg(context), (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
1277 case 0x29: /* PARSE FILENAME INTO FCB */
1278 INT21_ParseFileNameIntoFCB(context);
1281 case 0x2a: /* GET SYSTEM DATE */
1282 INT21_GetSystemDate(context);
1285 case 0x2b: /* SET SYSTEM DATE */
1286 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1287 DL_reg(context), DH_reg(context), CX_reg(context) );
1288 AL_reg(context) = 0; /* Let's pretend we succeeded */
1291 case 0x2c: /* GET SYSTEM TIME */
1292 INT21_GetSystemTime(context);
1295 case 0x2d: /* SET SYSTEM TIME */
1296 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1297 CH_reg(context), CL_reg(context),
1298 DH_reg(context), DL_reg(context) );
1299 AL_reg(context) = 0; /* Let's pretend we succeeded */
1302 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1303 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1305 TDB *pTask = TASK_GetCurrent();
1306 context->SegEs = SELECTOROF( pTask->dta );
1307 BX_reg(context) = OFFSETOF( pTask->dta );
1311 case 0x30: /* GET DOS VERSION */
1312 TRACE("GET DOS VERSION %s requested\n",
1313 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1314 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1315 (HIWORD(GetVersion16()) << 8);
1317 AH_reg(context) = 0x7;
1318 AL_reg(context) = 0xA;
1321 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1322 CX_reg(context) = 0x0000;
1325 case 0x31: /* TERMINATE AND STAY RESIDENT */
1326 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1329 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1330 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1331 INT21_DriveName( DL_reg(context)));
1332 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1335 case 0x33: /* MULTIPLEXED */
1336 switch (AL_reg(context))
1338 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1339 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1340 INT21_ReadConfigSys();
1341 DL_reg(context) = DOSCONF_config.brk_flag;
1344 case 0x01: /* SET EXTENDED BREAK STATE */
1345 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1346 INT21_ReadConfigSys();
1347 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1350 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1351 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1352 INT21_ReadConfigSys();
1353 /* ugly coding in order to stay reentrant */
1354 if (DL_reg(context))
1356 DL_reg(context) = DOSCONF_config.brk_flag;
1357 DOSCONF_config.brk_flag = 1;
1361 DL_reg(context) = DOSCONF_config.brk_flag;
1362 DOSCONF_config.brk_flag = 0;
1366 case 0x05: /* GET BOOT DRIVE */
1367 TRACE("GET BOOT DRIVE\n");
1368 DL_reg(context) = 3;
1369 /* c: is Wine's bootdrive (a: is 1)*/
1372 case 0x06: /* GET TRUE VERSION NUMBER */
1373 TRACE("GET TRUE VERSION NUMBER\n");
1374 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1375 (HIWORD(GetVersion16() << 8));
1376 DX_reg(context) = 0x00;
1380 INT_BARF( context, 0x21 );
1385 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1386 TRACE("GET ADDRESS OF INDOS FLAG\n");
1387 if (!heap) INT21_CreateHeap();
1388 context->SegEs = DosHeapHandle;
1389 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1392 case 0x35: /* GET INTERRUPT VECTOR */
1393 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1395 FARPROC16 addr = INT_GetPMHandler( AL_reg(context) );
1396 context->SegEs = SELECTOROF(addr);
1397 BX_reg(context) = OFFSETOF(addr);
1401 case 0x36: /* GET FREE DISK SPACE */
1402 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1403 INT21_DriveName( DL_reg(context)));
1404 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1409 unsigned char switchchar='/';
1410 switch (AL_reg(context))
1412 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1413 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1414 AL_reg(context) = 0x00; /* success*/
1415 DL_reg(context) = switchchar;
1417 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1418 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1419 switchchar = DL_reg(context);
1420 AL_reg(context) = 0x00; /* success*/
1422 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1423 INT_BARF( context, 0x21 );
1429 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1430 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1432 AX_reg(context) = 0x02; /* no country support available */
1436 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1438 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1439 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1440 context->Edx ), NULL));
1441 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1442 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1443 * denied), while CreateDirectory return several ones. remap some of
1446 if (bSetDOSExtendedError) {
1447 switch (GetLastError()) {
1448 case ERROR_ALREADY_EXISTS:
1449 case ERROR_FILENAME_EXCED_RANGE:
1450 case ERROR_DISK_FULL:
1451 SetLastError(ERROR_ACCESS_DENIED);
1458 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1460 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1461 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1465 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1467 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1468 bSetDOSExtendedError = !INT21_ChangeDir(context);
1471 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1472 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1473 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1474 bSetDOSExtendedError = INT21_CreateFile( context );
1477 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1478 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1479 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1480 OpenExistingFile(context);
1483 case 0x3e: /* "CLOSE" - CLOSE FILE */
1484 TRACE("CLOSE handle %d\n",BX_reg(context));
1485 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1488 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1489 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1490 context->SegDs,DX_reg(context),CX_reg(context) );
1494 result = _hread16( BX_reg(context),
1495 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1499 result = WIN16_hread( BX_reg(context),
1500 MAKESEGPTR( context->SegDs, context->Edx ),
1502 if (result == -1) bSetDOSExtendedError = TRUE;
1503 else AX_reg(context) = (WORD)result;
1507 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1508 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1509 context->SegDs,DX_reg(context),BX_reg(context),CX_reg(context) );
1511 LONG result = _hwrite16( BX_reg(context),
1512 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1515 if (result == -1) bSetDOSExtendedError = TRUE;
1516 else AX_reg(context) = (WORD)result;
1520 case 0x41: /* "UNLINK" - DELETE FILE */
1521 TRACE("UNLINK %s\n",
1522 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1523 bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1527 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1528 TRACE("LSEEK handle %d offset %ld from %s\n",
1529 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1530 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1531 "current file position":"end of file");
1533 LONG status = _llseek16( BX_reg(context),
1534 MAKELONG(DX_reg(context),CX_reg(context)),
1536 if (status == -1) bSetDOSExtendedError = TRUE;
1539 AX_reg(context) = LOWORD(status);
1540 DX_reg(context) = HIWORD(status);
1545 case 0x43: /* FILE ATTRIBUTES */
1546 switch (AL_reg(context))
1549 TRACE("GET FILE ATTRIBUTES for %s\n",
1550 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1551 AX_reg(context) = (WORD)GetFileAttributesA(
1552 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1554 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1555 else CX_reg(context) = AX_reg(context);
1559 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1560 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1561 bSetDOSExtendedError =
1562 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1567 FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1568 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1572 case 0x44: /* IOCTL */
1573 switch (AL_reg(context))
1576 ioctlGetDeviceInfo(context);
1582 const DOS_DEVICE *dev;
1583 if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )) &&
1584 !strcasecmp( dev->name, "SCSIMGR$" ))
1586 ASPI_DOS_HandleInt(context);
1590 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1591 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
1592 int drive = DOS_GET_DRIVE(BL_reg(context));
1594 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1595 /* for (i=0;i<CX_reg(context);i++)
1596 fprintf(stdnimp,"%02x ",dataptr[i]);
1597 fprintf(stdnimp,"\n");*/
1598 AX_reg(context)=CX_reg(context);
1601 case 0x08: /* Check if drive is removable. */
1602 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1603 INT21_DriveName( BL_reg(context)));
1604 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1607 SetLastError( ERROR_INVALID_DRIVE );
1608 AX_reg(context) = ERROR_INVALID_DRIVE;
1611 case DRIVE_REMOVABLE:
1612 AX_reg(context) = 0; /* removable */
1615 AX_reg(context) = 1; /* not removable */
1620 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1621 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1622 INT21_DriveName( BL_reg(context)));
1623 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1626 SetLastError( ERROR_INVALID_DRIVE );
1627 AX_reg(context) = ERROR_INVALID_DRIVE;
1631 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1634 DX_reg(context) = 0; /* FIXME: use driver attr here */
1639 case 0x0a: /* check if handle (BX) is remote */
1640 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1641 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1644 DX_reg(context) = 0;
1648 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1649 INT21_DriveName( BL_reg(context)));
1650 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1653 case 0x0e: /* get logical drive mapping */
1654 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1655 INT21_DriveName( BL_reg(context)));
1656 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1659 case 0x0F: /* Set logical drive mapping */
1662 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1663 INT21_DriveName( BL_reg(context)));
1664 drive = DOS_GET_DRIVE ( BL_reg(context) );
1665 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1668 AX_reg(context) = 0x000F; /* invalid drive */
1673 case 0xe0: /* Sun PC-NFS API */
1677 case 0x52: /* DR-DOS version */
1678 /* This is not DR-DOS */
1680 TRACE("GET DR-DOS VERSION requested\n");
1682 AX_reg(context) = 0x0001; /* Invalid function */
1683 SET_CFLAG(context); /* Error */
1684 SetLastError( ERROR_INVALID_FUNCTION );
1688 INT_BARF( context, 0x21 );
1693 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1696 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1697 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1698 DosFileHandleToWin32Handle(BX_reg(context)),
1699 GetCurrentProcess(), &handle,
1700 0, TRUE, DUPLICATE_SAME_ACCESS )))
1701 AX_reg(context) = HFILE_ERROR16;
1703 AX_reg(context) = Win32HandleToDosFileHandle(handle);
1707 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1708 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1709 BX_reg(context),CX_reg(context));
1710 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1713 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1714 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1715 INT21_DriveName( DL_reg(context)));
1716 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1719 case 0x48: /* ALLOCATE MEMORY */
1720 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1725 mem= DOSMEM_GetBlock((DWORD)BX_reg(context)<<4,NULL);
1727 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1731 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1733 AX_reg(context) = (DWORD)mem&0xffff;
1738 AX_reg(context) = 0x0008; /* insufficient memory */
1739 BX_reg(context) = DOSMEM_Available()>>4;
1744 case 0x49: /* FREE MEMORY */
1745 TRACE("FREE MEMORY segment %04lX\n", context->SegEs);
1749 ret= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(context->SegEs<<4));
1752 ret = !GlobalDOSFree16(context->SegEs);
1753 /* If we don't reset ES_reg, we will fail in the relay code */
1758 TRACE("FREE MEMORY failed\n");
1760 AX_reg(context) = 0x0009; /* memory block address invalid */
1765 case 0x4a: /* RESIZE MEMORY BLOCK */
1766 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", context->SegEs, BX_reg(context));
1767 if (!ISV86(context))
1768 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1770 LPVOID *mem = DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(context->SegEs<<4),
1771 BX_reg(context)<<4,NULL);
1773 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1776 AX_reg(context) = 0x0008; /* insufficient memory */
1777 BX_reg(context) = DOSMEM_Available()>>4; /* not quite right */
1782 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1783 TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
1784 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ),
1786 if (AX_reg(context) < 32) SET_CFLAG(context);
1789 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1790 TRACE("EXIT with return code %d\n",AL_reg(context));
1791 ExitThread( AL_reg(context) );
1794 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1795 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1796 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1797 if (!INT21_FindFirst(context)) break;
1800 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1801 TRACE("FINDNEXT\n");
1802 if (!INT21_FindNext(context))
1804 SetLastError( ERROR_NO_MORE_FILES );
1805 AX_reg(context) = ERROR_NO_MORE_FILES;
1808 else AX_reg(context) = 0; /* OK */
1810 case 0x51: /* GET PSP ADDRESS */
1811 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1812 /* FIXME: should we return the original DOS PSP upon */
1813 /* Windows startup ? */
1814 BX_reg(context) = GetCurrentPDB16();
1816 case 0x62: /* GET PSP ADDRESS */
1817 /* FIXME: should we return the original DOS PSP upon */
1818 /* Windows startup ? */
1819 BX_reg(context) = GetCurrentPDB16();
1822 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1823 TRACE("SYSVARS - GET LIST OF LISTS\n");
1825 context->SegEs = LOWORD(DOS_LOLSeg);
1826 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1830 case 0x54: /* Get Verify Flag */
1831 TRACE("Get Verify Flag - Not Supported\n");
1832 AL_reg(context) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1835 case 0x56: /* "RENAME" - RENAME FILE */
1836 TRACE("RENAME %s to %s\n",
1837 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1838 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi));
1839 bSetDOSExtendedError =
1840 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1841 CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi)));
1844 case 0x57: /* FILE DATE AND TIME */
1845 switch (AL_reg(context))
1847 case 0x00: /* Get */
1850 TRACE("GET FILE DATE AND TIME for handle %d\n",
1852 if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context)), NULL, NULL, &filetime ))
1853 bSetDOSExtendedError = TRUE;
1854 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1859 case 0x01: /* Set */
1862 TRACE("SET FILE DATE AND TIME for handle %d\n",
1864 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1866 bSetDOSExtendedError =
1867 (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context)),
1868 NULL, NULL, &filetime ));
1874 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1875 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1877 switch (AL_reg(context))
1880 AX_reg(context) = 1;
1883 AX_reg(context) = 0;
1889 RESET_CFLAG(context);
1892 case 0x5a: /* CREATE TEMPORARY FILE */
1893 TRACE("CREATE TEMPORARY FILE\n");
1894 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1897 case 0x5b: /* CREATE NEW FILE */
1898 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1899 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1900 bSetDOSExtendedError = ((AX_reg(context) =
1901 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1902 CX_reg(context) )) == (WORD)HFILE_ERROR16);
1905 case 0x5d: /* NETWORK */
1906 FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1907 /* Fix the following while you're at it. */
1908 SetLastError( ER_NoNetwork );
1909 bSetDOSExtendedError = TRUE;
1913 bSetDOSExtendedError = INT21_networkfunc (context);
1916 case 0x5f: /* NETWORK */
1917 switch (AL_reg(context))
1919 case 0x07: /* ENABLE DRIVE */
1920 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1921 if (!DRIVE_Enable( DL_reg(context) ))
1923 SetLastError( ERROR_INVALID_DRIVE );
1924 bSetDOSExtendedError = TRUE;
1928 case 0x08: /* DISABLE DRIVE */
1929 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1930 if (!DRIVE_Disable( DL_reg(context) ))
1932 SetLastError( ERROR_INVALID_DRIVE );
1933 bSetDOSExtendedError = TRUE;
1938 /* network software not installed */
1939 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1940 SetLastError( ER_NoNetwork );
1941 bSetDOSExtendedError = TRUE;
1946 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1947 TRACE("TRUENAME %s\n",
1948 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Esi));
1950 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1952 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1953 context->Edi),NULL))
1954 bSetDOSExtendedError = TRUE;
1955 else AX_reg(context) = 0;
1959 case 0x61: /* UNUSED */
1960 case 0x63: /* misc. language support */
1961 switch (AL_reg(context)) {
1962 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1963 INT21_GetDBCSLeadTable(context);
1967 case 0x64: /* OS/2 DOS BOX */
1968 INT_BARF( context, 0x21 );
1972 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1973 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
1974 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1975 BX_reg(context), DX_reg(context));
1976 switch (AL_reg(context)) {
1978 TRACE("\tget general internationalization info\n");
1980 *(WORD*)(dataptr+1) = 41;
1981 *(WORD*)(dataptr+3) = GetSystemDefaultLangID();
1982 *(WORD*)(dataptr+5) = CodePage;
1983 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1986 TRACE("\tget pointer to collating sequence table\n");
1988 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1989 CX_reg(context) = 258;/*FIXME: size of table?*/
1992 TRACE("\tConvert char to uppercase\n");
1993 DL_reg(context) = toupper(DL_reg(context));
1996 TRACE("\tconvert string to uppercase with length\n");
1998 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx);
1999 WORD len = CX_reg(context);
2000 while (len--) { *ptr = toupper(*ptr); ptr++; }
2004 TRACE("\tConvert ASCIIZ string to uppercase\n");
2005 _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx) );
2008 TRACE("\tunimplemented function %d\n",AL_reg(context));
2009 INT_BARF( context, 0x21 );
2015 case 0x66: /* GLOBAL CODE PAGE TABLE */
2016 switch (AL_reg(context))
2019 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2020 DX_reg(context) = BX_reg(context) = CodePage;
2021 RESET_CFLAG(context);
2024 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2025 BX_reg(context),DX_reg(context));
2026 CodePage = BX_reg(context);
2027 RESET_CFLAG(context);
2032 case 0x67: /* SET HANDLE COUNT */
2033 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2034 SetHandleCount16( BX_reg(context) );
2035 if (GetLastError()) bSetDOSExtendedError = TRUE;
2038 case 0x68: /* "FFLUSH" - COMMIT FILE */
2039 case 0x6a: /* COMMIT FILE */
2040 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2041 bSetDOSExtendedError = (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ));
2044 case 0x69: /* DISK SERIAL NUMBER */
2045 switch (AL_reg(context))
2048 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2049 INT21_DriveName(BL_reg(context)));
2050 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2051 else AX_reg(context) = 0;
2055 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2056 INT21_DriveName(BL_reg(context)));
2057 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2058 else AX_reg(context) = 1;
2063 case 0x6C: /* Extended Open/Create*/
2064 TRACE("EXTENDED OPEN/CREATE %s\n",
2065 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edi));
2066 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2069 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2070 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2071 /* not supported on anything but Win95 */
2072 TRACE("LONG FILENAME functions supported only by win95\n");
2074 AL_reg(context) = 0;
2076 switch(AL_reg(context))
2078 case 0x39: /* Create directory */
2079 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2080 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2081 bSetDOSExtendedError = (!CreateDirectoryA(
2082 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2083 context->Edx ), NULL));
2084 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2085 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2086 * denied), while CreateDirectory return several ones. remap some of
2089 if (bSetDOSExtendedError) {
2090 switch (GetLastError()) {
2091 case ERROR_ALREADY_EXISTS:
2092 case ERROR_FILENAME_EXCED_RANGE:
2093 case ERROR_DISK_FULL:
2094 SetLastError(ERROR_ACCESS_DENIED);
2100 case 0x3a: /* Remove directory */
2101 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2102 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2103 bSetDOSExtendedError = (!RemoveDirectoryA(
2104 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2107 case 0x43: /* Get/Set file attributes */
2108 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2109 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2110 switch (BL_reg(context))
2112 case 0x00: /* Get file attributes */
2113 TRACE("\tretrieve attributes\n");
2114 CX_reg(context) = (WORD)GetFileAttributesA(
2115 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2117 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2120 TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2121 bSetDOSExtendedError = (!SetFileAttributesA(
2122 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2124 CX_reg(context) ) );
2127 FIXME("Unimplemented long file name function:\n");
2128 INT_BARF( context, 0x21 );
2130 AL_reg(context) = 0;
2134 case 0x47: /* Get current directory */
2135 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2136 INT21_DriveName(DL_reg(context)));
2137 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2140 case 0x4e: /* Find first file */
2141 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2142 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2143 /* FIXME: use attributes in CX */
2144 if ((AX_reg(context) = FindFirstFile16(
2145 CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
2146 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2148 == INVALID_HANDLE_VALUE16)
2149 bSetDOSExtendedError = TRUE;
2151 case 0x4f: /* Find next file */
2152 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2154 if (!FindNextFile16( BX_reg(context),
2155 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2157 bSetDOSExtendedError = TRUE;
2161 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
2162 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
2163 DWORD filename_len, flags;
2165 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
2166 AX_reg(context) = 0;
2167 if (!GetVolumeInformationA( driveroot, NULL, 0, NULL, &filename_len,
2168 &flags, buffer, 8 ))
2170 INT_BARF( context, 0x21 );
2174 BX_reg(context) = flags | 0x4000; /* support for LFN functions */
2175 CX_reg(context) = filename_len;
2176 DX_reg(context) = MAX_PATH; /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2179 case 0xa1: /* Find close */
2180 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2182 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2185 switch(CL_reg(context))
2187 case 0x01: /* Get short filename or path */
2188 if (!GetShortPathNameA
2189 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2191 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2193 bSetDOSExtendedError = TRUE;
2194 else AX_reg(context) = 0;
2196 case 0x02: /* Get canonical long filename or path */
2197 if (!GetFullPathNameA
2198 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2200 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2201 context->Edi),NULL))
2202 bSetDOSExtendedError = TRUE;
2203 else AX_reg(context) = 0;
2206 FIXME("Unimplemented long file name function:\n");
2207 INT_BARF( context, 0x21 );
2209 AL_reg(context) = 0;
2213 case 0x6c: /* Create or open file */
2214 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2215 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi));
2216 /* translate Dos 7 action to Dos 6 action */
2217 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2220 case 0x3b: /* Change directory */
2221 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2222 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
2223 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2229 AL_reg(context) = GetLastError();
2232 case 0x41: /* Delete file */
2233 TRACE("LONG FILENAME - DELETE FILE %s\n",
2234 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
2235 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2240 AL_reg(context) = GetLastError();
2243 case 0x56: /* Move (rename) file */
2245 LPCSTR fn1 = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
2246 LPCSTR fn2 = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
2247 TRACE("LONG FILENAME - RENAME FILE %s to %s\n", fn1, fn2);
2248 if (!MoveFileA(fn1, fn2))
2251 AL_reg(context) = GetLastError();
2256 FIXME("Unimplemented long file name function:\n");
2257 INT_BARF( context, 0x21 );
2259 AL_reg(context) = 0;
2264 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2265 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2266 TRACE("windows95 function AX %04x\n",
2268 WARN(" returning unimplemented\n");
2270 AL_reg(context) = 0;
2273 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2274 TRACE("windows95 function AX %04x\n",
2277 switch (AL_reg(context))
2279 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
2280 /* ES:DI points to word with length of data (should be 0x3d) */
2284 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
2285 char root[] = "A:\\";
2287 buffer = (WORD *)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
2289 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer);
2291 /* validate passed-in buffer lengths */
2292 if ((*buffer != 0x3d) || (context->Ecx != 0x3f))
2294 WARN("Get Extended DPB: buffer lengths incorrect\n");
2295 WARN("CX = %lx, buffer[0] = %x\n", context->Ecx, *buffer);
2297 AL_reg(context) = 0x18; /* bad buffer length */
2300 /* buffer checks out */
2301 buffer++; /* skip over length word now */
2302 if (FillInDrivePB( DX_reg(context) ) )
2304 edpb = (struct EDPB *)buffer;
2306 /* copy down the old-style DPB portion first */
2307 memcpy(&edpb->dpb, &heap->dpb, sizeof(struct DPB));
2309 /* now fill in the extended entries */
2310 edpb->edpb_flags = 0;
2311 edpb->next_edpb = 0;
2312 edpb->free_cluster = edpb->free_cluster2 = 0;
2314 /* determine free disk space */
2315 *root += DOS_GET_DRIVE( DX_reg(context) );
2316 GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
2317 &free_clusters, &total_clusters );
2319 edpb->clusters_free = (free_clusters&0xffff);
2321 edpb->clusters_free_hi = free_clusters >> 16;
2322 edpb->mirroring_flags = 0;
2323 edpb->info_sector = 0xffff;
2324 edpb->spare_boot_sector = 0xffff;
2325 edpb->first_cluster = 0;
2326 edpb->max_cluster = total_clusters;
2327 edpb->fat_clusters = 32; /* made-up value */
2328 edpb->root_cluster = 0;
2330 RESET_CFLAG(context); /* clear carry */
2331 AX_reg(context) = 0;
2335 AX_reg(context) = 0x00ff;
2341 case 0x03: /* Get Extended free space on drive */
2342 case 0x04: /* Set DPB for formatting */
2343 case 0x05: /* extended absolute disk read/write */
2344 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context));
2346 AL_reg(context) = 0;
2353 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2354 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2358 INT_BARF( context, 0x21 );
2361 } /* END OF SWITCH */
2363 if( bSetDOSExtendedError ) /* set general error condition */
2365 AX_reg(context) = GetLastError();
2369 if ((context->EFlags & 0x0001))
2370 TRACE("failed, error %ld\n", GetLastError() );
2372 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2373 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2374 AX_reg(context), BX_reg(context), CX_reg(context),
2375 DX_reg(context), SI_reg(context), DI_reg(context),
2376 (WORD)context->SegDs, (WORD)context->SegEs,
2380 /***********************************************************************
2381 * GetSetKernelDOSProc (KERNEL.311)
2383 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2385 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);