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>
36 #ifdef HAVE_SYS_TIME_H
37 # include <sys/time.h>
39 #include <sys/types.h>
49 #include "winuser.h" /* SW_NORMAL */
50 #include "wine/winbase16.h"
58 #include "wine/debug.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(int21);
61 #if defined(__svr4__) || defined(_SCO_DS)
62 /* SVR4 DOESNT do locking the same way must implement properly */
69 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
71 /* Define the drive parameter block, as used by int21/1F
72 * and int21/32. This table can be accessed through the
73 * global 'dpb' pointer, which points into the local dos
78 BYTE drive_num; /* 0=A, etc. */
79 BYTE unit_num; /* Drive's unit number (?) */
80 WORD sector_size; /* Sector size in bytes */
81 BYTE high_sector; /* Highest sector in a cluster */
82 BYTE shift; /* Shift count (?) */
83 WORD reserved; /* Number of reserved sectors at start */
84 BYTE num_FAT; /* Number of FATs */
85 WORD dir_entries; /* Number of root dir entries */
86 WORD first_data; /* First data sector */
87 WORD high_cluster; /* Highest cluster number */
88 WORD sectors_in_FAT; /* Number of sectors per FAT */
89 WORD start_dir; /* Starting sector of first dir */
90 DWORD driver_head; /* Address of device driver header (?) */
91 BYTE media_ID; /* Media ID */
92 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
93 DWORD next; /* Pointer to next DPB in list */
94 WORD free_search; /* Free cluster search start */
95 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
98 struct EDPB /* FAT32 extended Drive Parameter Block */
99 { /* from Ralf Brown's Interrupt List */
100 struct DPB dpb; /* first 24 bytes = original DPB */
102 BYTE edpb_flags; /* undocumented/unknown flags */
103 DWORD next_edpb; /* pointer to next EDPB */
104 WORD free_cluster; /* cluster to start search for free space on write, typically
105 the last cluster allocated */
106 WORD clusters_free; /* number of free clusters on drive or FFFF = unknown */
107 WORD clusters_free_hi; /* hiword of clusters_free */
108 WORD mirroring_flags; /* mirroring flags: bit 7 set = do not mirror active FAT */
109 /* bits 0-3 = 0-based number of the active FAT */
110 WORD info_sector; /* sector number of file system info sector, or FFFF for none */
111 WORD spare_boot_sector; /* sector number of backup boot sector, or FFFF for none */
112 DWORD first_cluster; /* sector number of the first cluster */
113 DWORD max_cluster; /* sector number of the last cluster */
114 DWORD fat_clusters; /* number of clusters occupied by FAT */
115 DWORD root_cluster; /* cluster number of start of root directory */
116 DWORD free_cluster2; /* same as free_cluster: cluster at which to start
117 search for free space when writing */
129 BYTE DummyDBCSLeadTable[6];
131 static struct DosHeap *heap;
132 static WORD DosHeapHandle;
134 extern char TempDirectory[];
136 static void INT21_ReadConfigSys(void)
139 if (!done) DOSCONF_ReadConfig();
143 static BOOL INT21_CreateHeap(void)
145 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
147 WARN("Out of memory\n");
150 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
151 dpbsegptr = MAKESEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
153 strcpy(heap->biosdate, "01/01/80");
154 memset(heap->DummyDBCSLeadTable, 0, 6);
158 static BYTE *GetCurrentDTA( CONTEXT86 *context )
160 TDB *pTask = TASK_GetCurrent();
162 /* FIXME: This assumes DTA was set correctly! */
163 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
164 (DWORD)OFFSETOF(pTask->dta) );
168 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
169 /* limited == TRUE is used with INT 0x21/0x440d */
174 setword(&data[3], 0);
176 setword(&data[6], 240);
177 setword(&data[8], 64000);
179 setword(&data[0x0b], 40);
180 setword(&data[0x0d], 56);
181 setword(&data[0x0f], 2);
182 setword(&data[0x11], 0);
184 setword(&data[0x1f], 800);
186 setword(&data[0x22], 1);
188 } else { /* 1.44mb */
191 setword(&data[3], 0);
193 setword(&data[6], 240);
194 setword(&data[8], 2880);
196 setword(&data[0x0b], 6);
197 setword(&data[0x0d], 18);
198 setword(&data[0x0f], 2);
199 setword(&data[0x11], 0);
201 setword(&data[0x1f], 80);
203 setword(&data[0x22], 2);
208 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
210 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
211 char root[] = "A:\\";
213 *root += DOS_GET_DRIVE( DL_reg(context) );
214 if (!GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
215 &free_clusters, &total_clusters )) return 0;
216 AX_reg(context) = cluster_sectors;
217 BX_reg(context) = free_clusters;
218 CX_reg(context) = sector_bytes;
219 DX_reg(context) = total_clusters;
223 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
225 if (!INT21_GetFreeDiskSpace( context )) return 0;
226 if (!heap && !INT21_CreateHeap()) return 0;
227 heap->mediaID = 0xf0;
228 context->SegDs = DosHeapHandle;
229 BX_reg(context) = (int)&heap->mediaID - (int)heap;
233 static int FillInDrivePB( int drive )
235 if(!DRIVE_IsValid(drive))
237 SetLastError( ERROR_INVALID_DRIVE );
240 else if (heap || INT21_CreateHeap())
242 /* FIXME: I have no idea what a lot of this information should
243 * say or whether it even really matters since we're not allowing
244 * direct block access. However, some programs seem to depend on
245 * getting at least _something_ back from here. The 'next' pointer
246 * does worry me, though. Should we have a complete table of
247 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
249 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
250 heap->dpb.sector_size = 512;
251 heap->dpb.high_sector = 1;
252 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
253 heap->dpb.reserved = 0;
254 heap->dpb.num_FAT = 1;
255 heap->dpb.dir_entries = 2;
256 heap->dpb.first_data = 2;
257 heap->dpb.high_cluster = 64000;
258 heap->dpb.sectors_in_FAT = 1;
259 heap->dpb.start_dir = 1;
260 heap->dpb.driver_head = 0;
261 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
262 heap->dpb.access_flag = 0;
264 heap->dpb.free_search = 0;
265 heap->dpb.free_clusters = 0xFFFF; /* unknown */
272 static void GetDrivePB( CONTEXT86 *context, int drive )
274 if (FillInDrivePB( drive ))
276 AL_reg(context) = 0x00;
277 context->SegDs = SELECTOROF(dpbsegptr);
278 BX_reg(context) = OFFSETOF(dpbsegptr);
282 AX_reg(context) = 0x00ff;
287 static void ioctlGetDeviceInfo( CONTEXT86 *context )
290 const DOS_DEVICE *dev;
292 TRACE("(%d)\n", BX_reg(context));
294 RESET_CFLAG(context);
297 if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )))
299 DX_reg(context) = dev->flags;
303 /* it seems to be a file */
304 curr_drive = DRIVE_GetCurrentDrive();
305 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
307 /* bits 0-5 are current drive
308 * bit 6 - file has NOT been written..FIXME: correct?
309 * bit 8 - generate int24 if no diskspace on write/ read past end of file
310 * bit 11 - media not removable
311 * bit 14 - don't set file date/time on closing
312 * bit 15 - file is remote
316 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
318 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
319 int drive = DOS_GET_DRIVE( BL_reg(context) );
321 if (!DRIVE_IsValid(drive))
323 SetLastError( ERROR_FILE_NOT_FOUND );
327 if (CH_reg(context) != 0x08)
329 INT_BARF( context, 0x21 );
333 switch (CL_reg(context))
335 case 0x4a: /* lock logical volume */
336 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
339 case 0x60: /* get device parameters */
340 /* used by w4wgrp's winfile */
341 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
343 dataptr[6] = 0; /* media type */
346 dataptr[1] = 0x05; /* fixed disk */
347 setword(&dataptr[2], 0x01); /* non removable */
348 setword(&dataptr[4], 0x300); /* # of cylinders */
352 dataptr[1] = 0x07; /* block dev, floppy */
353 setword(&dataptr[2], 0x02); /* removable */
354 setword(&dataptr[4], 80); /* # of cylinders */
356 CreateBPB(drive, &dataptr[7], TRUE);
357 RESET_CFLAG(context);
360 case 0x41: /* write logical device track */
361 case 0x61: /* read logical device track */
363 BYTE drive = BL_reg(context) ?
364 BL_reg(context) : DRIVE_GetCurrentDrive();
365 WORD head = *(WORD *)dataptr+1;
366 WORD cyl = *(WORD *)dataptr+3;
367 WORD sect = *(WORD *)dataptr+5;
368 WORD nrsect = *(WORD *)dataptr+7;
369 BYTE *data = (BYTE *)dataptr+9;
370 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
372 raw_func = (CL_reg(context) == 0x41) ?
373 DRIVE_RawWrite : DRIVE_RawRead;
375 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
376 RESET_CFLAG(context);
379 AX_reg(context) = 0x1e; /* read fault */
384 case 0x66:/* get disk serial number */
386 char label[12],fsname[9],path[4];
389 strcpy(path,"x:\\");path[0]=drive+'A';
390 GetVolumeInformationA(
391 path,label,12,&serial,NULL,NULL,fsname,9
394 memcpy(dataptr+2,&serial,4);
395 memcpy(dataptr+6,label ,11);
396 memcpy(dataptr+17,fsname,8);
401 TRACE("logical volume %d unlocked.\n",drive);
405 memset(dataptr+1, '\0', dataptr[0]-1);
406 dataptr[1] = dataptr[0];
407 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
408 dataptr[3] = 0xFF; /* no physical drive */
412 /* Trail on error implementation */
413 AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_UNKNOWN ? 0x0f : 0x01;
414 SET_CFLAG(context); /* Seems to be set all the time */
418 INT_BARF( context, 0x21 );
423 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
426 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
428 CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi );
429 char *buffer, *s, *d;
431 AL_reg(context) = 0xff; /* failed */
433 TRACE("filename: '%s'\n", filename);
435 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
441 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
448 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
450 TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
452 HeapFree( GetProcessHeap(), 0, buffer);
455 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
457 /* point DS:SI to first unparsed character */
458 SI_reg(context) += (int)s - (int)filename;
461 static void INT21_GetSystemDate( CONTEXT86 *context )
464 GetLocalTime( &systime );
465 CX_reg(context) = systime.wYear;
466 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
467 AX_reg(context) = systime.wDayOfWeek;
470 static void INT21_GetSystemTime( CONTEXT86 *context )
473 GetLocalTime( &systime );
474 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
475 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
478 /* Many calls translate a drive argument like this:
479 drive number (00h = default, 01h = A:, etc)
481 static char drivestring[]="default";
483 char *INT21_DriveName(int drive)
488 drivestring[0]= (unsigned char)drive + '@';
494 static BOOL INT21_CreateFile( CONTEXT86 *context )
496 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
497 context->Edx ), CX_reg(context) );
498 return (AX_reg(context) == (WORD)HFILE_ERROR16);
501 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
503 /* Mask off all flags not explicitly allowed by the doc */
504 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
505 return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
506 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
507 CREATE_NEW, attr, 0 ));
510 static void OpenExistingFile( CONTEXT86 *context )
512 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
514 if (AX_reg(context) == (WORD)HFILE_ERROR16)
516 AX_reg(context) = GetLastError();
521 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
523 BOOL bExtendedError = FALSE;
524 BYTE action = DL_reg(context);
526 /* Shuffle arguments to call OpenExistingFile */
527 AL_reg(context) = BL_reg(context);
528 DX_reg(context) = SI_reg(context);
529 /* BX,CX and DX should be preserved */
530 OpenExistingFile(context);
532 if ((context->EFlags & 0x0001) == 0) /* File exists */
534 UINT16 uReturnCX = 0;
536 /* Now decide what do do */
538 if ((action & 0x07) == 0)
540 _lclose16( AX_reg(context) );
541 AX_reg(context) = 0x0050; /*File exists*/
543 WARN("extended open/create: failed because file exists \n");
545 else if ((action & 0x07) == 2)
547 /* Truncate it, but first check if opened for write */
548 if ((BL_reg(context) & 0x0007)== 0)
550 _lclose16( AX_reg(context) );
551 WARN("extended open/create: failed, trunc on ro file\n");
552 AX_reg(context) = 0x000C; /*Access code invalid*/
557 TRACE("extended open/create: Closing before truncate\n");
558 if (_lclose16( AX_reg(context) ))
560 WARN("extended open/create: close before trunc failed\n");
561 AX_reg(context) = 0x0019; /*Seek Error*/
565 /* Shuffle arguments to call CreateFile */
567 TRACE("extended open/create: Truncating\n");
568 AL_reg(context) = BL_reg(context);
569 /* CX is still the same */
570 DX_reg(context) = SI_reg(context);
571 bExtendedError = INT21_CreateFile(context);
573 if (context->EFlags & 0x0001) /*no file open, flags set */
575 WARN("extended open/create: trunc failed\n");
576 return bExtendedError;
581 else uReturnCX = 0x1;
583 CX_reg(context) = uReturnCX;
585 else /* file does not exist */
587 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
588 if ((action & 0xF0)== 0)
592 WARN("extended open/create: failed, file dosen't exist\n");
596 /* Shuffle arguments to call CreateFile */
597 TRACE("extended open/create: Creating\n");
598 AL_reg(context) = BL_reg(context);
599 /* CX should still be the same */
600 DX_reg(context) = SI_reg(context);
601 bExtendedError = INT21_CreateFile(context);
602 if (context->EFlags & 0x0001) /*no file open, flags set */
604 WARN("extended open/create: create failed\n");
605 return bExtendedError;
611 return bExtendedError;
615 static BOOL INT21_ChangeDir( CONTEXT86 *context )
618 char *dirname = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
620 TRACE("changedir %s\n", dirname);
621 if (dirname[0] && (dirname[1] == ':'))
623 drive = toupper(dirname[0]) - 'A';
626 else drive = DRIVE_GetCurrentDrive();
627 return DRIVE_Chdir( drive, dirname );
631 static int INT21_FindFirst( CONTEXT86 *context )
635 DOS_FULL_NAME full_name;
636 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
638 path = (const char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
639 dta->unixPath = NULL;
640 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
642 AX_reg(context) = GetLastError();
646 dta->unixPath = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
647 strcpy( dta->unixPath, full_name.long_name );
648 p = strrchr( dta->unixPath, '/' );
651 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
652 * (doesn't matter as it is set below anyway)
654 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
656 HeapFree( GetProcessHeap(), 0, dta->unixPath );
657 dta->unixPath = NULL;
658 SetLastError( ERROR_FILE_NOT_FOUND );
659 AX_reg(context) = ERROR_FILE_NOT_FOUND;
663 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
664 : DRIVE_GetCurrentDrive();
666 dta->search_attr = CL_reg(context);
671 static int INT21_FindNext( CONTEXT86 *context )
673 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
674 WIN32_FIND_DATAA entry;
677 if (!dta->unixPath) return 0;
678 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
679 dta->search_attr, dta->count, &entry )))
681 HeapFree( GetProcessHeap(), 0, dta->unixPath );
682 dta->unixPath = NULL;
685 if ((int)dta->count + count > 0xffff)
687 WARN("Too many directory entries in %s\n", dta->unixPath );
688 HeapFree( GetProcessHeap(), 0, dta->unixPath );
689 dta->unixPath = NULL;
693 dta->fileattr = entry.dwFileAttributes;
694 dta->filesize = entry.nFileSizeLow;
695 FileTimeToDosDateTime( &entry.ftLastWriteTime,
696 &dta->filedate, &dta->filetime );
697 strcpy( dta->filename, entry.cAlternateFileName );
698 if (!memchr(dta->mask,'?',11)) {
699 /* wildcardless search, release resources in case no findnext will
700 * be issued, and as a workaround in case file creation messes up
701 * findnext, as sometimes happens with pkunzip */
702 HeapFree( GetProcessHeap(), 0, dta->unixPath );
703 dta->unixPath = NULL;
709 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
711 static int counter = 0;
712 char *name = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx );
713 char *p = name + strlen(name);
715 /* despite what Ralf Brown says, some programs seem to call without
716 * ending backslash (DOS accepts that, so we accept it too) */
717 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
721 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
722 counter = (counter + 1) % 1000;
724 if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
726 TRACE("created %s\n", name );
729 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
734 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
736 int drive = DOS_GET_DRIVE( DL_reg(context) );
737 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
739 if (!DRIVE_IsValid(drive))
741 SetLastError( ERROR_INVALID_DRIVE );
744 lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
745 AX_reg(context) = 0x0100; /* success return code */
750 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
752 if (heap || INT21_CreateHeap())
753 { /* return an empty table just as DOS 4.0+ does */
754 context->SegDs = DosHeapHandle;
755 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
759 AX_reg(context) = 0x1; /* error */
765 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
767 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
768 int drive = DOS_GET_DRIVE( BL_reg(context) );
770 if (!DRIVE_IsValid(drive))
772 SetLastError( ERROR_INVALID_DRIVE );
776 *(WORD *)dataptr = 0;
777 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
778 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
779 strncpy(dataptr + 0x11, "FAT16 ", 8);
784 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
786 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
787 int drive = DOS_GET_DRIVE( BL_reg(context) );
789 if (!DRIVE_IsValid(drive))
791 SetLastError( ERROR_INVALID_DRIVE );
795 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
800 /* microsoft's programmers should be shot for using CP/M style int21
801 calls in Windows for Workgroup's winfile.exe */
803 static int INT21_FindFirstFCB( CONTEXT86 *context )
805 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
810 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
811 else pFCB = (FINDFILE_FCB *)fcb;
812 drive = DOS_GET_DRIVE( pFCB->drive );
813 if (!DRIVE_IsValid( drive )) return 0;
814 root = DRIVE_GetRoot( drive );
815 cwd = DRIVE_GetUnixCwd( drive );
816 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
817 strlen(root)+strlen(cwd)+2 );
818 if (!pFCB->unixPath) return 0;
819 strcpy( pFCB->unixPath, root );
820 strcat( pFCB->unixPath, "/" );
821 strcat( pFCB->unixPath, cwd );
827 static int INT21_FindNextFCB( CONTEXT86 *context )
829 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
831 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
832 WIN32_FIND_DATAA entry;
836 if (*fcb == 0xff) /* extended FCB ? */
839 pFCB = (FINDFILE_FCB *)(fcb + 7);
844 pFCB = (FINDFILE_FCB *)fcb;
847 if (!pFCB->unixPath) return 0;
848 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
849 DOS_GET_DRIVE( pFCB->drive ), attr,
850 pFCB->count, &entry )))
852 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
853 pFCB->unixPath = NULL;
856 pFCB->count += count;
858 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
859 *(BYTE *)pResult = 0xff;
860 (BYTE *)pResult +=6; /* leave reserved field behind */
861 *(BYTE *)pResult = entry.dwFileAttributes;
864 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
866 pResult->fileattr = entry.dwFileAttributes;
867 pResult->cluster = 0; /* what else? */
868 pResult->filesize = entry.nFileSizeLow;
869 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
870 FileTimeToDosDateTime( &entry.ftLastWriteTime,
871 &pResult->filedate, &pResult->filetime );
873 /* Convert file name to FCB format */
875 memset( pResult->filename, ' ', sizeof(pResult->filename) );
876 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
877 else if (!strcmp( entry.cAlternateFileName, ".." ))
878 pResult->filename[0] = pResult->filename[1] = '.';
881 char *p = strrchr( entry.cAlternateFileName, '.' );
882 if (p && p[1] && (p != entry.cAlternateFileName))
884 memcpy( pResult->filename, entry.cAlternateFileName,
885 min( (p - entry.cAlternateFileName), 8 ) );
886 memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
889 memcpy( pResult->filename, entry.cAlternateFileName,
890 min( strlen(entry.cAlternateFileName), 8 ) );
896 static void DeleteFileFCB( CONTEXT86 *context )
898 FIXME("(%p): stub\n", context);
901 static void RenameFileFCB( CONTEXT86 *context )
903 FIXME("(%p): stub\n", context);
908 static void fLock( CONTEXT86 * context )
911 switch ( AX_reg(context) & 0xff )
913 case 0x00: /* LOCK */
914 TRACE("lock handle %d offset %ld length %ld\n",
916 MAKELONG(DX_reg(context),CX_reg(context)),
917 MAKELONG(DI_reg(context),SI_reg(context))) ;
918 if (!LockFile(DosFileHandleToWin32Handle(BX_reg(context)),
919 MAKELONG(DX_reg(context),CX_reg(context)), 0,
920 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
921 AX_reg(context) = GetLastError();
926 case 0x01: /* UNLOCK */
927 TRACE("unlock handle %d offset %ld length %ld\n",
929 MAKELONG(DX_reg(context),CX_reg(context)),
930 MAKELONG(DI_reg(context),SI_reg(context))) ;
931 if (!UnlockFile(DosFileHandleToWin32Handle(BX_reg(context)),
932 MAKELONG(DX_reg(context),CX_reg(context)), 0,
933 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
934 AX_reg(context) = GetLastError();
939 AX_reg(context) = 0x0001;
946 INT21_networkfunc (CONTEXT86 *context)
948 switch (AL_reg(context)) {
949 case 0x00: /* Get machine name. */
951 char *dst = CTX_SEG_OFF_TO_LIN (context,context->SegDs,context->Edx);
952 TRACE("getting machine name to %p\n", dst);
953 if (gethostname (dst, 15))
956 SetLastError( ER_NoNetwork );
959 int len = strlen (dst);
963 CH_reg(context) = 1; /* Valid */
964 CL_reg(context) = 1; /* NETbios number??? */
965 TRACE("returning %s\n", debugstr_an (dst, 16));
971 SetLastError( ER_NoNetwork );
977 static void ASPI_DOS_HandleInt( CONTEXT86 *context )
979 if (!Dosvm.ASPIHandler && !DPMI_LoadDosSystem())
981 ERR("could not setup ASPI handler\n");
984 Dosvm.ASPIHandler( context );
987 /***********************************************************************
988 * INT21_GetExtendedError
990 static void INT21_GetExtendedError( CONTEXT86 *context )
992 BYTE class, action, locus;
993 WORD error = GetLastError();
998 class = action = locus = 0;
1000 case ERROR_DIR_NOT_EMPTY:
1005 case ERROR_ACCESS_DENIED:
1006 class = EC_AccessDenied;
1010 case ERROR_CANNOT_MAKE:
1011 class = EC_AccessDenied;
1015 case ERROR_DISK_FULL:
1016 case ERROR_HANDLE_DISK_FULL:
1017 class = EC_MediaError;
1021 case ERROR_FILE_EXISTS:
1022 case ERROR_ALREADY_EXISTS:
1027 case ERROR_FILE_NOT_FOUND:
1028 class = EC_NotFound;
1032 case ER_GeneralFailure:
1033 class = EC_SystemFailure;
1037 case ERROR_INVALID_DRIVE:
1038 class = EC_MediaError;
1042 case ERROR_INVALID_HANDLE:
1043 class = EC_ProgramError;
1047 case ERROR_LOCK_VIOLATION:
1048 class = EC_AccessDenied;
1052 case ERROR_NO_MORE_FILES:
1053 class = EC_MediaError;
1058 class = EC_NotFound;
1062 case ERROR_NOT_ENOUGH_MEMORY:
1063 class = EC_OutOfResource;
1067 case ERROR_PATH_NOT_FOUND:
1068 class = EC_NotFound;
1073 class = EC_NotFound;
1077 case ERROR_SHARING_VIOLATION:
1078 class = EC_Temporary;
1082 case ERROR_TOO_MANY_OPEN_FILES:
1083 class = EC_ProgramError;
1088 FIXME("Unknown error %d\n", error );
1089 class = EC_SystemFailure;
1094 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1095 error, class, action, locus );
1096 AX_reg(context) = error;
1097 BH_reg(context) = class;
1098 BL_reg(context) = action;
1099 CH_reg(context) = locus;
1102 /***********************************************************************
1103 * DOS3Call (KERNEL.102)
1104 * INT_Int21Handler (WPROCS.133)
1106 void WINAPI DOS3Call( CONTEXT86 *context )
1108 BOOL bSetDOSExtendedError = FALSE;
1111 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1112 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1113 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1114 SI_reg(context), DI_reg(context),
1115 (WORD)context->SegDs, (WORD)context->SegEs,
1119 if (AH_reg(context) == 0x59) /* Get extended error info */
1121 INT21_GetExtendedError( context );
1125 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1127 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1128 /* no flush here yet */
1129 AH_reg(context) = AL_reg(context);
1132 if (AH_reg(context)>=0x2f) {
1133 /* extended error is used by (at least) functions 0x2f to 0x62 */
1136 RESET_CFLAG(context); /* Not sure if this is a good idea */
1138 switch(AH_reg(context))
1140 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1141 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1142 case 0x03: /* READ CHARACTER FROM STDAUX */
1143 case 0x04: /* WRITE CHARACTER TO STDAUX */
1144 case 0x05: /* WRITE CHARACTER TO PRINTER */
1145 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1146 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1147 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1148 case 0x0b: /* GET STDIN STATUS */
1149 case 0x0f: /* OPEN FILE USING FCB */
1150 case 0x10: /* CLOSE FILE USING FCB */
1151 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1152 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1153 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1154 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1155 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1156 case 0x23: /* GET FILE SIZE FOR FCB */
1157 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1158 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1159 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1160 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1161 case 0x4d: /* GET RETURN CODE */
1162 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1163 INT_BARF( context, 0x21 );
1166 case 0x00: /* TERMINATE PROGRAM */
1167 TRACE("TERMINATE PROGRAM\n");
1171 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1172 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1173 context->SegDs,DX_reg(context) );
1175 LPSTR data = CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx);
1177 /* do NOT use strchr() to calculate the string length,
1178 as '\0' is valid string content, too !
1179 Maybe we should check for non-'$' strings, but DOS doesn't. */
1180 while (*p != '$') p++;
1181 _hwrite16( 1, data, (int)p - (int)data);
1182 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1186 case 0x0a: /* BUFFERED INPUT */
1188 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1192 TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1194 TRACE("Handle old chars in buffer!\n");
1195 res=_lread16( 0, buffer+2,buffer[0]);
1197 if(buffer[res+1] == '\n')
1198 buffer[res+1] = '\r';
1202 case 0x2e: /* SET VERIFY FLAG */
1203 TRACE("SET VERIFY FLAG ignored\n");
1204 /* we cannot change the behaviour anyway, so just ignore it */
1207 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1211 case 0x6b: /* NULL FUNCTION */
1212 AL_reg(context) = 0;
1215 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1219 case 0x0d: /* DISK BUFFER FLUSH */
1220 TRACE("DISK BUFFER FLUSH ignored\n");
1221 RESET_CFLAG(context); /* dos 6+ only */
1224 case 0x0e: /* SELECT DEFAULT DRIVE */
1225 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1226 DRIVE_SetCurrentDrive( DL_reg(context) );
1227 AL_reg(context) = MAX_DOS_DRIVES;
1230 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1231 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1232 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1233 if (!INT21_FindFirstFCB(context))
1235 AL_reg(context) = 0xff;
1238 /* else fall through */
1240 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1241 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1244 case 0x13: /* DELETE FILE USING FCB */
1245 DeleteFileFCB(context);
1248 case 0x17: /* RENAME FILE USING FCB */
1249 RenameFileFCB(context);
1252 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1253 AL_reg(context) = DRIVE_GetCurrentDrive();
1256 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1258 TDB *pTask = TASK_GetCurrent();
1259 pTask->dta = MAKESEGPTR(context->SegDs,DX_reg(context));
1260 TRACE("Set DTA: %08lx\n", pTask->dta);
1264 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1265 DL_reg(context) = 0;
1266 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1269 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1270 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1273 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1274 GetDrivePB(context, DRIVE_GetCurrentDrive());
1277 case 0x25: /* SET INTERRUPT VECTOR */
1278 INT_SetPMHandler( AL_reg(context), (FARPROC16)MAKESEGPTR( context->SegDs, DX_reg(context)));
1281 case 0x29: /* PARSE FILENAME INTO FCB */
1282 INT21_ParseFileNameIntoFCB(context);
1285 case 0x2a: /* GET SYSTEM DATE */
1286 INT21_GetSystemDate(context);
1289 case 0x2b: /* SET SYSTEM DATE */
1290 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1291 DL_reg(context), DH_reg(context), CX_reg(context) );
1292 AL_reg(context) = 0; /* Let's pretend we succeeded */
1295 case 0x2c: /* GET SYSTEM TIME */
1296 INT21_GetSystemTime(context);
1299 case 0x2d: /* SET SYSTEM TIME */
1300 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1301 CH_reg(context), CL_reg(context),
1302 DH_reg(context), DL_reg(context) );
1303 AL_reg(context) = 0; /* Let's pretend we succeeded */
1306 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1307 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1309 TDB *pTask = TASK_GetCurrent();
1310 context->SegEs = SELECTOROF( pTask->dta );
1311 BX_reg(context) = OFFSETOF( pTask->dta );
1315 case 0x30: /* GET DOS VERSION */
1316 TRACE("GET DOS VERSION %s requested\n",
1317 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1318 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1319 (HIWORD(GetVersion16()) << 8);
1321 AH_reg(context) = 0x7;
1322 AL_reg(context) = 0xA;
1325 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1326 CX_reg(context) = 0x0000;
1329 case 0x31: /* TERMINATE AND STAY RESIDENT */
1330 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1333 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1334 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1335 INT21_DriveName( DL_reg(context)));
1336 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1339 case 0x33: /* MULTIPLEXED */
1340 switch (AL_reg(context))
1342 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1343 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1344 INT21_ReadConfigSys();
1345 DL_reg(context) = DOSCONF_config.brk_flag;
1348 case 0x01: /* SET EXTENDED BREAK STATE */
1349 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1350 INT21_ReadConfigSys();
1351 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1354 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1355 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1356 INT21_ReadConfigSys();
1357 /* ugly coding in order to stay reentrant */
1358 if (DL_reg(context))
1360 DL_reg(context) = DOSCONF_config.brk_flag;
1361 DOSCONF_config.brk_flag = 1;
1365 DL_reg(context) = DOSCONF_config.brk_flag;
1366 DOSCONF_config.brk_flag = 0;
1370 case 0x05: /* GET BOOT DRIVE */
1371 TRACE("GET BOOT DRIVE\n");
1372 DL_reg(context) = 3;
1373 /* c: is Wine's bootdrive (a: is 1)*/
1376 case 0x06: /* GET TRUE VERSION NUMBER */
1377 TRACE("GET TRUE VERSION NUMBER\n");
1378 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1379 (HIWORD(GetVersion16() << 8));
1380 DX_reg(context) = 0x00;
1384 INT_BARF( context, 0x21 );
1389 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1390 TRACE("GET ADDRESS OF INDOS FLAG\n");
1391 if (!heap) INT21_CreateHeap();
1392 context->SegEs = DosHeapHandle;
1393 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1396 case 0x35: /* GET INTERRUPT VECTOR */
1397 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1399 FARPROC16 addr = INT_GetPMHandler( AL_reg(context) );
1400 context->SegEs = SELECTOROF(addr);
1401 BX_reg(context) = OFFSETOF(addr);
1405 case 0x36: /* GET FREE DISK SPACE */
1406 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1407 INT21_DriveName( DL_reg(context)));
1408 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1413 unsigned char switchchar='/';
1414 switch (AL_reg(context))
1416 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1417 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1418 AL_reg(context) = 0x00; /* success*/
1419 DL_reg(context) = switchchar;
1421 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1422 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1423 switchchar = DL_reg(context);
1424 AL_reg(context) = 0x00; /* success*/
1426 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1427 INT_BARF( context, 0x21 );
1433 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1434 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1436 AX_reg(context) = 0x02; /* no country support available */
1440 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1442 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1443 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1444 context->Edx ), NULL));
1445 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1446 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1447 * denied), while CreateDirectory return several ones. remap some of
1450 if (bSetDOSExtendedError) {
1451 switch (GetLastError()) {
1452 case ERROR_ALREADY_EXISTS:
1453 case ERROR_FILENAME_EXCED_RANGE:
1454 case ERROR_DISK_FULL:
1455 SetLastError(ERROR_ACCESS_DENIED);
1462 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1464 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1465 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1469 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1471 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1472 bSetDOSExtendedError = !INT21_ChangeDir(context);
1475 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1476 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1477 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1478 bSetDOSExtendedError = INT21_CreateFile( context );
1481 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1482 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1483 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1484 OpenExistingFile(context);
1487 case 0x3e: /* "CLOSE" - CLOSE FILE */
1488 TRACE("CLOSE handle %d\n",BX_reg(context));
1489 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1492 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1493 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1494 context->SegDs,DX_reg(context),CX_reg(context) );
1498 result = _hread16( BX_reg(context),
1499 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1503 result = WIN16_hread( BX_reg(context),
1504 MAKESEGPTR( context->SegDs, context->Edx ),
1506 if (result == -1) bSetDOSExtendedError = TRUE;
1507 else AX_reg(context) = (WORD)result;
1511 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1512 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1513 context->SegDs,DX_reg(context),BX_reg(context),CX_reg(context) );
1515 LONG result = _hwrite16( BX_reg(context),
1516 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1519 if (result == -1) bSetDOSExtendedError = TRUE;
1520 else AX_reg(context) = (WORD)result;
1524 case 0x41: /* "UNLINK" - DELETE FILE */
1525 TRACE("UNLINK %s\n",
1526 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1527 bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1531 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1532 TRACE("LSEEK handle %d offset %ld from %s\n",
1533 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1534 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1535 "current file position":"end of file");
1537 LONG status = _llseek16( BX_reg(context),
1538 MAKELONG(DX_reg(context),CX_reg(context)),
1540 if (status == -1) bSetDOSExtendedError = TRUE;
1543 AX_reg(context) = LOWORD(status);
1544 DX_reg(context) = HIWORD(status);
1549 case 0x43: /* FILE ATTRIBUTES */
1550 switch (AL_reg(context))
1553 TRACE("GET FILE ATTRIBUTES for %s\n",
1554 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1555 AX_reg(context) = (WORD)GetFileAttributesA(
1556 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1558 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1559 else CX_reg(context) = AX_reg(context);
1563 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1564 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1565 bSetDOSExtendedError =
1566 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1571 FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1572 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1576 case 0x44: /* IOCTL */
1577 switch (AL_reg(context))
1580 ioctlGetDeviceInfo(context);
1586 const DOS_DEVICE *dev;
1587 if ((dev = DOSFS_GetDeviceByHandle( DosFileHandleToWin32Handle(BX_reg(context)) )) &&
1588 !strcasecmp( dev->name, "SCSIMGR$" ))
1590 ASPI_DOS_HandleInt(context);
1594 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1595 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);*/
1596 int drive = DOS_GET_DRIVE(BL_reg(context));
1598 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1599 /* for (i=0;i<CX_reg(context);i++)
1600 fprintf(stdnimp,"%02x ",dataptr[i]);
1601 fprintf(stdnimp,"\n");*/
1602 AX_reg(context)=CX_reg(context);
1605 case 0x08: /* Check if drive is removable. */
1606 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1607 INT21_DriveName( BL_reg(context)));
1608 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1611 SetLastError( ERROR_INVALID_DRIVE );
1612 AX_reg(context) = ERROR_INVALID_DRIVE;
1615 case DRIVE_REMOVABLE:
1616 AX_reg(context) = 0; /* removable */
1619 AX_reg(context) = 1; /* not removable */
1624 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1625 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1626 INT21_DriveName( BL_reg(context)));
1627 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1630 SetLastError( ERROR_INVALID_DRIVE );
1631 AX_reg(context) = ERROR_INVALID_DRIVE;
1635 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1638 DX_reg(context) = 0; /* FIXME: use driver attr here */
1643 case 0x0a: /* check if handle (BX) is remote */
1644 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1645 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1648 DX_reg(context) = 0;
1652 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1653 INT21_DriveName( BL_reg(context)));
1654 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1657 case 0x0e: /* get logical drive mapping */
1658 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1659 INT21_DriveName( BL_reg(context)));
1660 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1663 case 0x0F: /* Set logical drive mapping */
1666 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1667 INT21_DriveName( BL_reg(context)));
1668 drive = DOS_GET_DRIVE ( BL_reg(context) );
1669 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1672 AX_reg(context) = 0x000F; /* invalid drive */
1677 case 0xe0: /* Sun PC-NFS API */
1681 case 0x52: /* DR-DOS version */
1682 /* This is not DR-DOS */
1684 TRACE("GET DR-DOS VERSION requested\n");
1686 AX_reg(context) = 0x0001; /* Invalid function */
1687 SET_CFLAG(context); /* Error */
1688 SetLastError( ERROR_INVALID_FUNCTION );
1692 INT_BARF( context, 0x21 );
1697 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1700 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1701 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1702 DosFileHandleToWin32Handle(BX_reg(context)),
1703 GetCurrentProcess(), &handle,
1704 0, TRUE, DUPLICATE_SAME_ACCESS )))
1705 AX_reg(context) = HFILE_ERROR16;
1707 AX_reg(context) = Win32HandleToDosFileHandle(handle);
1711 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1712 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1713 BX_reg(context),CX_reg(context));
1714 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1717 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1718 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1719 INT21_DriveName( DL_reg(context)));
1720 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1723 case 0x48: /* ALLOCATE MEMORY */
1724 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1729 mem= DOSMEM_GetBlock((DWORD)BX_reg(context)<<4,NULL);
1731 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1735 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1737 AX_reg(context) = (DWORD)mem&0xffff;
1742 AX_reg(context) = 0x0008; /* insufficient memory */
1743 BX_reg(context) = DOSMEM_Available()>>4;
1748 case 0x49: /* FREE MEMORY */
1749 TRACE("FREE MEMORY segment %04lX\n", context->SegEs);
1753 ret= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(context->SegEs<<4));
1756 ret = !GlobalDOSFree16(context->SegEs);
1757 /* If we don't reset ES_reg, we will fail in the relay code */
1762 TRACE("FREE MEMORY failed\n");
1764 AX_reg(context) = 0x0009; /* memory block address invalid */
1769 case 0x4a: /* RESIZE MEMORY BLOCK */
1770 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", context->SegEs, BX_reg(context));
1771 if (!ISV86(context))
1772 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1774 LPVOID *mem = DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(context->SegEs<<4),
1775 BX_reg(context)<<4,NULL);
1777 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1780 AX_reg(context) = 0x0008; /* insufficient memory */
1781 BX_reg(context) = DOSMEM_Available()>>4; /* not quite right */
1786 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1787 TRACE("EXEC %s\n", (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ));
1788 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx ),
1790 if (AX_reg(context) < 32) SET_CFLAG(context);
1793 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1794 TRACE("EXIT with return code %d\n",AL_reg(context));
1795 ExitThread( AL_reg(context) );
1798 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1799 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1800 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1801 if (!INT21_FindFirst(context)) break;
1804 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1805 TRACE("FINDNEXT\n");
1806 if (!INT21_FindNext(context))
1808 SetLastError( ERROR_NO_MORE_FILES );
1809 AX_reg(context) = ERROR_NO_MORE_FILES;
1812 else AX_reg(context) = 0; /* OK */
1814 case 0x51: /* GET PSP ADDRESS */
1815 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1816 /* FIXME: should we return the original DOS PSP upon */
1817 /* Windows startup ? */
1818 BX_reg(context) = GetCurrentPDB16();
1820 case 0x62: /* GET PSP ADDRESS */
1821 /* FIXME: should we return the original DOS PSP upon */
1822 /* Windows startup ? */
1823 BX_reg(context) = GetCurrentPDB16();
1826 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1827 TRACE("SYSVARS - GET LIST OF LISTS\n");
1829 context->SegEs = LOWORD(DOS_LOLSeg);
1830 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1834 case 0x54: /* Get Verify Flag */
1835 TRACE("Get Verify Flag - Not Supported\n");
1836 AL_reg(context) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1839 case 0x56: /* "RENAME" - RENAME FILE */
1840 TRACE("RENAME %s to %s\n",
1841 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1842 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi));
1843 bSetDOSExtendedError =
1844 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1845 CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi)));
1848 case 0x57: /* FILE DATE AND TIME */
1849 switch (AL_reg(context))
1851 case 0x00: /* Get */
1854 TRACE("GET FILE DATE AND TIME for handle %d\n",
1856 if (!GetFileTime( DosFileHandleToWin32Handle(BX_reg(context)), NULL, NULL, &filetime ))
1857 bSetDOSExtendedError = TRUE;
1858 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1863 case 0x01: /* Set */
1866 TRACE("SET FILE DATE AND TIME for handle %d\n",
1868 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1870 bSetDOSExtendedError =
1871 (!SetFileTime( DosFileHandleToWin32Handle(BX_reg(context)),
1872 NULL, NULL, &filetime ));
1878 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1879 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1881 switch (AL_reg(context))
1884 AX_reg(context) = 1;
1887 AX_reg(context) = 0;
1893 RESET_CFLAG(context);
1896 case 0x5a: /* CREATE TEMPORARY FILE */
1897 TRACE("CREATE TEMPORARY FILE\n");
1898 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1901 case 0x5b: /* CREATE NEW FILE */
1902 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1903 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
1904 bSetDOSExtendedError = ((AX_reg(context) =
1905 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
1906 CX_reg(context) )) == (WORD)HFILE_ERROR16);
1909 case 0x5d: /* NETWORK */
1910 FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1911 /* Fix the following while you're at it. */
1912 SetLastError( ER_NoNetwork );
1913 bSetDOSExtendedError = TRUE;
1917 bSetDOSExtendedError = INT21_networkfunc (context);
1920 case 0x5f: /* NETWORK */
1921 switch (AL_reg(context))
1923 case 0x07: /* ENABLE DRIVE */
1924 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1925 if (!DRIVE_Enable( DL_reg(context) ))
1927 SetLastError( ERROR_INVALID_DRIVE );
1928 bSetDOSExtendedError = TRUE;
1932 case 0x08: /* DISABLE DRIVE */
1933 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1934 if (!DRIVE_Disable( DL_reg(context) ))
1936 SetLastError( ERROR_INVALID_DRIVE );
1937 bSetDOSExtendedError = TRUE;
1942 /* network software not installed */
1943 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1944 SetLastError( ER_NoNetwork );
1945 bSetDOSExtendedError = TRUE;
1950 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1951 TRACE("TRUENAME %s\n",
1952 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Esi));
1954 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
1956 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
1957 context->Edi),NULL))
1958 bSetDOSExtendedError = TRUE;
1959 else AX_reg(context) = 0;
1963 case 0x61: /* UNUSED */
1964 case 0x63: /* misc. language support */
1965 switch (AL_reg(context)) {
1966 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1967 INT21_GetDBCSLeadTable(context);
1971 case 0x64: /* OS/2 DOS BOX */
1972 INT_BARF( context, 0x21 );
1976 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1977 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
1978 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1979 BX_reg(context), DX_reg(context));
1980 switch (AL_reg(context)) {
1982 TRACE("\tget general internationalization info\n");
1984 *(WORD*)(dataptr+1) = 41;
1985 *(WORD*)(dataptr+3) = GetSystemDefaultLangID();
1986 *(WORD*)(dataptr+5) = CodePage;
1987 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1990 TRACE("\tget pointer to collating sequence table\n");
1992 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1993 CX_reg(context) = 258;/*FIXME: size of table?*/
1996 TRACE("\tConvert char to uppercase\n");
1997 DL_reg(context) = toupper(DL_reg(context));
2000 TRACE("\tconvert string to uppercase with length\n");
2002 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx);
2003 WORD len = CX_reg(context);
2004 while (len--) { *ptr = toupper(*ptr); ptr++; }
2008 TRACE("\tConvert ASCIIZ string to uppercase\n");
2009 _strupr( (LPSTR)CTX_SEG_OFF_TO_LIN(context,context->SegDs,context->Edx) );
2012 TRACE("\tunimplemented function %d\n",AL_reg(context));
2013 INT_BARF( context, 0x21 );
2019 case 0x66: /* GLOBAL CODE PAGE TABLE */
2020 switch (AL_reg(context))
2023 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2024 DX_reg(context) = BX_reg(context) = CodePage;
2025 RESET_CFLAG(context);
2028 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2029 BX_reg(context),DX_reg(context));
2030 CodePage = BX_reg(context);
2031 RESET_CFLAG(context);
2036 case 0x67: /* SET HANDLE COUNT */
2037 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2038 SetHandleCount16( BX_reg(context) );
2039 if (GetLastError()) bSetDOSExtendedError = TRUE;
2042 case 0x68: /* "FFLUSH" - COMMIT FILE */
2043 case 0x6a: /* COMMIT FILE */
2044 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2045 bSetDOSExtendedError = (!FlushFileBuffers( DosFileHandleToWin32Handle(BX_reg(context)) ));
2048 case 0x69: /* DISK SERIAL NUMBER */
2049 switch (AL_reg(context))
2052 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2053 INT21_DriveName(BL_reg(context)));
2054 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2055 else AX_reg(context) = 0;
2059 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2060 INT21_DriveName(BL_reg(context)));
2061 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2062 else AX_reg(context) = 1;
2067 case 0x6C: /* Extended Open/Create*/
2068 TRACE("EXTENDED OPEN/CREATE %s\n",
2069 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edi));
2070 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2073 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2074 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2075 /* not supported on anything but Win95 */
2076 TRACE("LONG FILENAME functions supported only by win95\n");
2078 AL_reg(context) = 0;
2080 switch(AL_reg(context))
2082 case 0x39: /* Create directory */
2083 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2084 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2085 bSetDOSExtendedError = (!CreateDirectoryA(
2086 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2087 context->Edx ), NULL));
2088 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2089 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2090 * denied), while CreateDirectory return several ones. remap some of
2093 if (bSetDOSExtendedError) {
2094 switch (GetLastError()) {
2095 case ERROR_ALREADY_EXISTS:
2096 case ERROR_FILENAME_EXCED_RANGE:
2097 case ERROR_DISK_FULL:
2098 SetLastError(ERROR_ACCESS_DENIED);
2104 case 0x3a: /* Remove directory */
2105 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2106 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2107 bSetDOSExtendedError = (!RemoveDirectoryA(
2108 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2111 case 0x43: /* Get/Set file attributes */
2112 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2113 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2114 switch (BL_reg(context))
2116 case 0x00: /* Get file attributes */
2117 TRACE("\tretrieve attributes\n");
2118 CX_reg(context) = (WORD)GetFileAttributesA(
2119 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2121 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2124 TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2125 bSetDOSExtendedError = (!SetFileAttributesA(
2126 CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2128 CX_reg(context) ) );
2131 FIXME("Unimplemented long file name function:\n");
2132 INT_BARF( context, 0x21 );
2134 AL_reg(context) = 0;
2138 case 0x47: /* Get current directory */
2139 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2140 INT21_DriveName(DL_reg(context)));
2141 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2144 case 0x4e: /* Find first file */
2145 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2146 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
2147 /* FIXME: use attributes in CX */
2148 if ((AX_reg(context) = FindFirstFile16(
2149 CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
2150 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2152 == INVALID_HANDLE_VALUE16)
2153 bSetDOSExtendedError = TRUE;
2155 case 0x4f: /* Find next file */
2156 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2158 if (!FindNextFile16( BX_reg(context),
2159 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2161 bSetDOSExtendedError = TRUE;
2165 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
2166 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
2167 DWORD filename_len, flags;
2169 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
2170 AX_reg(context) = 0;
2171 if (!GetVolumeInformationA( driveroot, NULL, 0, NULL, &filename_len,
2172 &flags, buffer, 8 ))
2174 INT_BARF( context, 0x21 );
2178 BX_reg(context) = flags | 0x4000; /* support for LFN functions */
2179 CX_reg(context) = filename_len;
2180 DX_reg(context) = MAX_PATH; /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2183 case 0xa1: /* Find close */
2184 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2186 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2189 switch(CL_reg(context))
2191 case 0x01: /* Get short filename or path */
2192 if (!GetShortPathNameA
2193 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2195 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2197 bSetDOSExtendedError = TRUE;
2198 else AX_reg(context) = 0;
2200 case 0x02: /* Get canonical long filename or path */
2201 if (!GetFullPathNameA
2202 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
2204 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
2205 context->Edi),NULL))
2206 bSetDOSExtendedError = TRUE;
2207 else AX_reg(context) = 0;
2210 FIXME("Unimplemented long file name function:\n");
2211 INT_BARF( context, 0x21 );
2213 AL_reg(context) = 0;
2217 case 0x6c: /* Create or open file */
2218 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2219 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi));
2220 /* translate Dos 7 action to Dos 6 action */
2221 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2224 case 0x3b: /* Change directory */
2225 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2226 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
2227 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2233 AL_reg(context) = GetLastError();
2236 case 0x41: /* Delete file */
2237 TRACE("LONG FILENAME - DELETE FILE %s\n",
2238 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
2239 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2244 AL_reg(context) = GetLastError();
2247 case 0x56: /* Move (rename) file */
2249 LPCSTR fn1 = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
2250 LPCSTR fn2 = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
2251 TRACE("LONG FILENAME - RENAME FILE %s to %s\n", fn1, fn2);
2252 if (!MoveFileA(fn1, fn2))
2255 AL_reg(context) = GetLastError();
2260 FIXME("Unimplemented long file name function:\n");
2261 INT_BARF( context, 0x21 );
2263 AL_reg(context) = 0;
2268 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2269 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2270 TRACE("windows95 function AX %04x\n",
2272 WARN(" returning unimplemented\n");
2274 AL_reg(context) = 0;
2277 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2278 TRACE("windows95 function AX %04x\n",
2281 switch (AL_reg(context))
2283 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
2284 /* ES:DI points to word with length of data (should be 0x3d) */
2288 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
2289 char root[] = "A:\\";
2291 buffer = (WORD *)CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi);
2293 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer);
2295 /* validate passed-in buffer lengths */
2296 if ((*buffer != 0x3d) || (context->Ecx != 0x3f))
2298 WARN("Get Extended DPB: buffer lengths incorrect\n");
2299 WARN("CX = %lx, buffer[0] = %x\n", context->Ecx, *buffer);
2301 AL_reg(context) = 0x18; /* bad buffer length */
2304 /* buffer checks out */
2305 buffer++; /* skip over length word now */
2306 if (FillInDrivePB( DX_reg(context) ) )
2308 edpb = (struct EDPB *)buffer;
2310 /* copy down the old-style DPB portion first */
2311 memcpy(&edpb->dpb, &heap->dpb, sizeof(struct DPB));
2313 /* now fill in the extended entries */
2314 edpb->edpb_flags = 0;
2315 edpb->next_edpb = 0;
2316 edpb->free_cluster = edpb->free_cluster2 = 0;
2318 /* determine free disk space */
2319 *root += DOS_GET_DRIVE( DX_reg(context) );
2320 GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
2321 &free_clusters, &total_clusters );
2323 edpb->clusters_free = (free_clusters&0xffff);
2325 edpb->clusters_free_hi = free_clusters >> 16;
2326 edpb->mirroring_flags = 0;
2327 edpb->info_sector = 0xffff;
2328 edpb->spare_boot_sector = 0xffff;
2329 edpb->first_cluster = 0;
2330 edpb->max_cluster = total_clusters;
2331 edpb->fat_clusters = 32; /* made-up value */
2332 edpb->root_cluster = 0;
2334 RESET_CFLAG(context); /* clear carry */
2335 AX_reg(context) = 0;
2339 AX_reg(context) = 0x00ff;
2345 case 0x03: /* Get Extended free space on drive */
2346 case 0x04: /* Set DPB for formatting */
2347 case 0x05: /* extended absolute disk read/write */
2348 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context));
2350 AL_reg(context) = 0;
2357 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2358 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2362 INT_BARF( context, 0x21 );
2365 } /* END OF SWITCH */
2367 if( bSetDOSExtendedError ) /* set general error condition */
2369 AX_reg(context) = GetLastError();
2373 if ((context->EFlags & 0x0001))
2374 TRACE("failed, error %ld\n", GetLastError() );
2376 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2377 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2378 AX_reg(context), BX_reg(context), CX_reg(context),
2379 DX_reg(context), SI_reg(context), DI_reg(context),
2380 (WORD)context->SegDs, (WORD)context->SegEs,
2384 /***********************************************************************
2385 * GetSetKernelDOSProc (KERNEL.311)
2387 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2389 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);