2 * DOS interrupt 21h handler
11 #ifdef HAVE_SYS_FILE_H
12 # include <sys/file.h>
17 #include <sys/types.h>
24 #include "winuser.h" /* SW_NORMAL */
25 #include "wine/winbase16.h"
35 #include "dosexe.h" /* for the MZ_SUPPORTED define */
36 #include "debugtools.h"
39 DEFAULT_DEBUG_CHANNEL(int21)
40 #if defined(__svr4__) || defined(_SCO_DS)
41 /* SVR4 DOESNT do locking the same way must implement properly */
48 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
50 /* Define the drive parameter block, as used by int21/1F
51 * and int21/32. This table can be accessed through the
52 * global 'dpb' pointer, which points into the local dos
57 BYTE drive_num; /* 0=A, etc. */
58 BYTE unit_num; /* Drive's unit number (?) */
59 WORD sector_size; /* Sector size in bytes */
60 BYTE high_sector; /* Highest sector in a cluster */
61 BYTE shift; /* Shift count (?) */
62 WORD reserved; /* Number of reserved sectors at start */
63 BYTE num_FAT; /* Number of FATs */
64 WORD dir_entries; /* Number of root dir entries */
65 WORD first_data; /* First data sector */
66 WORD high_cluster; /* Highest cluster number */
67 WORD sectors_in_FAT; /* Number of sectors per FAT */
68 WORD start_dir; /* Starting sector of first dir */
69 DWORD driver_head; /* Address of device driver header (?) */
70 BYTE media_ID; /* Media ID */
71 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
72 DWORD next; /* Pointer to next DPB in list */
73 WORD free_search; /* Free cluster search start */
74 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
77 struct EDPB /* FAT32 extended Drive Parameter Block */
78 { /* from Ralf Brown's Interrupt List */
79 struct DPB dpb; /* first 24 bytes = original DPB */
81 BYTE edpb_flags; /* undocumented/unknown flags */
82 DWORD next_edpb; /* pointer to next EDPB */
83 WORD free_cluster; /* cluster to start search for free space on write, typically
84 the last cluster allocated */
85 WORD clusters_free; /* number of free clusters on drive or FFFF = unknown */
86 WORD clusters_free_hi; /* hiword of clusters_free */
87 WORD mirroring_flags; /* mirroring flags: bit 7 set = do not mirror active FAT */
88 /* bits 0-3 = 0-based number of the active FAT */
89 WORD info_sector; /* sector number of file system info sector, or FFFF for none */
90 WORD spare_boot_sector; /* sector number of backup boot sector, or FFFF for none */
91 DWORD first_cluster; /* sector number of the first cluster */
92 DWORD max_cluster; /* sector number of the last cluster */
93 DWORD fat_clusters; /* number of clusters occupied by FAT */
94 DWORD root_cluster; /* cluster number of start of root directory */
95 DWORD free_cluster2; /* same as free_cluster: cluster at which to start
96 search for free space when writing */
108 BYTE DummyDBCSLeadTable[6];
110 static struct DosHeap *heap;
111 static WORD DosHeapHandle;
113 extern char TempDirectory[];
115 static BOOL INT21_CreateHeap(void)
117 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
119 WARN("Out of memory\n");
122 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
123 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
125 strcpy(heap->biosdate, "01/01/80");
126 memset(heap->DummyDBCSLeadTable, 0, 6);
130 static BYTE *GetCurrentDTA( CONTEXT86 *context )
132 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
134 /* FIXME: This assumes DTA was set correctly! */
135 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
136 (DWORD)OFFSETOF(pTask->dta) );
140 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
141 /* limited == TRUE is used with INT 0x21/0x440d */
146 setword(&data[3], 0);
148 setword(&data[6], 240);
149 setword(&data[8], 64000);
151 setword(&data[0x0b], 40);
152 setword(&data[0x0d], 56);
153 setword(&data[0x0f], 2);
154 setword(&data[0x11], 0);
156 setword(&data[0x1f], 800);
158 setword(&data[0x22], 1);
160 } else { /* 1.44mb */
163 setword(&data[3], 0);
165 setword(&data[6], 240);
166 setword(&data[8], 2880);
168 setword(&data[0x0b], 6);
169 setword(&data[0x0d], 18);
170 setword(&data[0x0f], 2);
171 setword(&data[0x11], 0);
173 setword(&data[0x1f], 80);
175 setword(&data[0x22], 2);
180 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
182 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
183 char root[] = "A:\\";
185 *root += DOS_GET_DRIVE( DL_reg(context) );
186 if (!GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
187 &free_clusters, &total_clusters )) return 0;
188 AX_reg(context) = cluster_sectors;
189 BX_reg(context) = free_clusters;
190 CX_reg(context) = sector_bytes;
191 DX_reg(context) = total_clusters;
195 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
197 if (!INT21_GetFreeDiskSpace( context )) return 0;
198 if (!heap && !INT21_CreateHeap()) return 0;
199 heap->mediaID = 0xf0;
200 DS_reg(context) = DosHeapHandle;
201 BX_reg(context) = (int)&heap->mediaID - (int)heap;
205 static int FillInDrivePB( int drive )
207 if(!DRIVE_IsValid(drive))
209 SetLastError( ERROR_INVALID_DRIVE );
212 else if (heap || INT21_CreateHeap())
214 /* FIXME: I have no idea what a lot of this information should
215 * say or whether it even really matters since we're not allowing
216 * direct block access. However, some programs seem to depend on
217 * getting at least _something_ back from here. The 'next' pointer
218 * does worry me, though. Should we have a complete table of
219 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
221 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
222 heap->dpb.sector_size = 512;
223 heap->dpb.high_sector = 1;
224 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
225 heap->dpb.reserved = 0;
226 heap->dpb.num_FAT = 1;
227 heap->dpb.dir_entries = 2;
228 heap->dpb.first_data = 2;
229 heap->dpb.high_cluster = 64000;
230 heap->dpb.sectors_in_FAT = 1;
231 heap->dpb.start_dir = 1;
232 heap->dpb.driver_head = 0;
233 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
234 heap->dpb.access_flag = 0;
236 heap->dpb.free_search = 0;
237 heap->dpb.free_clusters = 0xFFFF; /* unknown */
244 static void GetDrivePB( CONTEXT86 *context, int drive )
246 if (FillInDrivePB( drive ))
248 AL_reg(context) = 0x00;
249 DS_reg(context) = SELECTOROF(dpbsegptr);
250 BX_reg(context) = OFFSETOF(dpbsegptr);
254 AX_reg(context) = 0x00ff;
259 static void ioctlGetDeviceInfo( CONTEXT86 *context )
262 const DOS_DEVICE *dev;
264 TRACE("(%d)\n", BX_reg(context));
266 RESET_CFLAG(context);
269 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )))
271 DX_reg(context) = dev->flags;
275 /* it seems to be a file */
276 curr_drive = DRIVE_GetCurrentDrive();
277 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
279 /* bits 0-5 are current drive
280 * bit 6 - file has NOT been written..FIXME: correct?
281 * bit 8 - generate int24 if no diskspace on write/ read past end of file
282 * bit 11 - media not removable
283 * bit 14 - don't set file date/time on closing
284 * bit 15 - file is remote
288 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
290 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
291 int drive = DOS_GET_DRIVE( BL_reg(context) );
293 if (!DRIVE_IsValid(drive))
295 SetLastError( ERROR_FILE_NOT_FOUND );
299 if (CH_reg(context) != 0x08)
301 INT_BARF( context, 0x21 );
305 switch (CL_reg(context))
307 case 0x4a: /* lock logical volume */
308 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
311 case 0x60: /* get device parameters */
312 /* used by w4wgrp's winfile */
313 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
315 dataptr[6] = 0; /* media type */
318 dataptr[1] = 0x05; /* fixed disk */
319 setword(&dataptr[2], 0x01); /* non removable */
320 setword(&dataptr[4], 0x300); /* # of cylinders */
324 dataptr[1] = 0x07; /* block dev, floppy */
325 setword(&dataptr[2], 0x02); /* removable */
326 setword(&dataptr[4], 80); /* # of cylinders */
328 CreateBPB(drive, &dataptr[7], TRUE);
329 RESET_CFLAG(context);
332 case 0x41: /* write logical device track */
333 case 0x61: /* read logical device track */
335 BYTE drive = BL_reg(context) ?
336 BL_reg(context) : DRIVE_GetCurrentDrive();
337 WORD head = *(WORD *)dataptr+1;
338 WORD cyl = *(WORD *)dataptr+3;
339 WORD sect = *(WORD *)dataptr+5;
340 WORD nrsect = *(WORD *)dataptr+7;
341 BYTE *data = (BYTE *)dataptr+9;
342 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
344 raw_func = (CL_reg(context) == 0x41) ?
345 DRIVE_RawWrite : DRIVE_RawRead;
347 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
348 RESET_CFLAG(context);
351 AX_reg(context) = 0x1e; /* read fault */
356 case 0x66:/* get disk serial number */
358 char label[12],fsname[9],path[4];
361 strcpy(path,"x:\\");path[0]=drive+'A';
362 GetVolumeInformationA(
363 path,label,12,&serial,NULL,NULL,fsname,9
366 memcpy(dataptr+2,&serial,4);
367 memcpy(dataptr+6,label ,11);
368 memcpy(dataptr+17,fsname,8);
373 TRACE("logical volume %d unlocked.\n",drive);
377 memset(dataptr+1, '\0', dataptr[0]-1);
378 dataptr[1] = dataptr[0];
379 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
380 dataptr[3] = 0xFF; /* no physical drive */
384 /* Trail on error implementation */
385 AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_CANNOTDETERMINE ? 0x0f : 0x01;
386 SET_CFLAG(context); /* Seems to be set all the time */
390 INT_BARF( context, 0x21 );
395 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
398 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
400 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context) );
401 char *buffer, *s, *d;
403 AL_reg(context) = 0xff; /* failed */
405 TRACE("filename: '%s'\n", filename);
407 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
413 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
420 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
422 TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
424 HeapFree( GetProcessHeap(), 0, buffer);
427 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
429 /* point DS:SI to first unparsed character */
430 SI_reg(context) += (int)s - (int)filename;
433 static void INT21_GetSystemDate( CONTEXT86 *context )
436 GetLocalTime( &systime );
437 CX_reg(context) = systime.wYear;
438 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
439 AX_reg(context) = systime.wDayOfWeek;
442 static void INT21_GetSystemTime( CONTEXT86 *context )
445 GetLocalTime( &systime );
446 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
447 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
450 /* Many calls translate a drive argument like this:
451 drive number (00h = default, 01h = A:, etc)
453 static char drivestring[]="default";
455 char *INT21_DriveName(int drive)
460 drivestring[0]= (unsigned char)drive + '@';
466 static BOOL INT21_CreateFile( CONTEXT86 *context )
468 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
469 EDX_reg(context) ), CX_reg(context) );
470 return (AX_reg(context) == (WORD)HFILE_ERROR16);
473 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
475 /* Mask off all flags not explicitly allowed by the doc */
476 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
477 return FILE_AllocDosHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
478 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
479 CREATE_NEW, attr, -1 ));
482 static void OpenExistingFile( CONTEXT86 *context )
484 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
486 if (AX_reg(context) == (WORD)HFILE_ERROR16)
488 AX_reg(context) = GetLastError();
493 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
495 BOOL bExtendedError = FALSE;
496 BYTE action = DL_reg(context);
498 /* Shuffle arguments to call OpenExistingFile */
499 AL_reg(context) = BL_reg(context);
500 DX_reg(context) = SI_reg(context);
501 /* BX,CX and DX should be preserved */
502 OpenExistingFile(context);
504 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
506 UINT16 uReturnCX = 0;
508 /* Now decide what do do */
510 if ((action & 0x07) == 0)
512 _lclose16( AX_reg(context) );
513 AX_reg(context) = 0x0050; /*File exists*/
515 WARN("extended open/create: failed because file exists \n");
517 else if ((action & 0x07) == 2)
519 /* Truncate it, but first check if opened for write */
520 if ((BL_reg(context) & 0x0007)== 0)
522 _lclose16( AX_reg(context) );
523 WARN("extended open/create: failed, trunc on ro file\n");
524 AX_reg(context) = 0x000C; /*Access code invalid*/
529 TRACE("extended open/create: Closing before truncate\n");
530 if (_lclose16( AX_reg(context) ))
532 WARN("extended open/create: close before trunc failed\n");
533 AX_reg(context) = 0x0019; /*Seek Error*/
537 /* Shuffle arguments to call CreateFile */
539 TRACE("extended open/create: Truncating\n");
540 AL_reg(context) = BL_reg(context);
541 /* CX is still the same */
542 DX_reg(context) = SI_reg(context);
543 bExtendedError = INT21_CreateFile(context);
545 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
547 WARN("extended open/create: trunc failed\n");
548 return bExtendedError;
553 else uReturnCX = 0x1;
555 CX_reg(context) = uReturnCX;
557 else /* file does not exist */
559 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
560 if ((action & 0xF0)== 0)
564 WARN("extended open/create: failed, file dosen't exist\n");
568 /* Shuffle arguments to call CreateFile */
569 TRACE("extended open/create: Creating\n");
570 AL_reg(context) = BL_reg(context);
571 /* CX should still be the same */
572 DX_reg(context) = SI_reg(context);
573 bExtendedError = INT21_CreateFile(context);
574 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
576 WARN("extended open/create: create failed\n");
577 return bExtendedError;
583 return bExtendedError;
587 static BOOL INT21_ChangeDir( CONTEXT86 *context )
590 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
592 TRACE("changedir %s\n", dirname);
593 if (dirname[0] && (dirname[1] == ':'))
595 drive = toupper(dirname[0]) - 'A';
598 else drive = DRIVE_GetCurrentDrive();
599 return DRIVE_Chdir( drive, dirname );
603 static int INT21_FindFirst( CONTEXT86 *context )
607 DOS_FULL_NAME full_name;
608 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
610 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
611 dta->unixPath = NULL;
612 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
614 AX_reg(context) = GetLastError();
618 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
619 p = strrchr( dta->unixPath, '/' );
622 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
623 * (doesn't matter as it is set below anyway)
625 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
627 HeapFree( GetProcessHeap(), 0, dta->unixPath );
628 dta->unixPath = NULL;
629 SetLastError( ERROR_FILE_NOT_FOUND );
630 AX_reg(context) = ERROR_FILE_NOT_FOUND;
634 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
635 : DRIVE_GetCurrentDrive();
637 dta->search_attr = CL_reg(context);
642 static int INT21_FindNext( CONTEXT86 *context )
644 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
645 WIN32_FIND_DATAA entry;
648 if (!dta->unixPath) return 0;
649 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
650 dta->search_attr, dta->count, &entry )))
652 HeapFree( GetProcessHeap(), 0, dta->unixPath );
653 dta->unixPath = NULL;
656 if ((int)dta->count + count > 0xffff)
658 WARN("Too many directory entries in %s\n", dta->unixPath );
659 HeapFree( GetProcessHeap(), 0, dta->unixPath );
660 dta->unixPath = NULL;
664 dta->fileattr = entry.dwFileAttributes;
665 dta->filesize = entry.nFileSizeLow;
666 FileTimeToDosDateTime( &entry.ftLastWriteTime,
667 &dta->filedate, &dta->filetime );
668 strcpy( dta->filename, entry.cAlternateFileName );
669 if (!memchr(dta->mask,'?',11)) {
670 /* wildcardless search, release resources in case no findnext will
671 * be issued, and as a workaround in case file creation messes up
672 * findnext, as sometimes happens with pkunzip */
673 HeapFree( GetProcessHeap(), 0, dta->unixPath );
674 dta->unixPath = NULL;
680 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
682 static int counter = 0;
683 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
684 char *p = name + strlen(name);
686 /* despite what Ralf Brown says, some programs seem to call without
687 * ending backslash (DOS accepts that, so we accept it too) */
688 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
692 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
693 counter = (counter + 1) % 1000;
695 if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
697 TRACE("created %s\n", name );
700 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
705 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
707 int drive = DOS_GET_DRIVE( DL_reg(context) );
708 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
710 if (!DRIVE_IsValid(drive))
712 SetLastError( ERROR_INVALID_DRIVE );
715 lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
716 AX_reg(context) = 0x0100; /* success return code */
721 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
723 if (heap || INT21_CreateHeap())
724 { /* return an empty table just as DOS 4.0+ does */
725 DS_reg(context) = DosHeapHandle;
726 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
730 AX_reg(context) = 0x1; /* error */
736 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
738 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
739 int drive = DOS_GET_DRIVE( BL_reg(context) );
741 if (!DRIVE_IsValid(drive))
743 SetLastError( ERROR_INVALID_DRIVE );
747 *(WORD *)dataptr = 0;
748 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
749 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
750 strncpy(dataptr + 0x11, "FAT16 ", 8);
755 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
757 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
758 int drive = DOS_GET_DRIVE( BL_reg(context) );
760 if (!DRIVE_IsValid(drive))
762 SetLastError( ERROR_INVALID_DRIVE );
766 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
771 /* microsoft's programmers should be shot for using CP/M style int21
772 calls in Windows for Workgroup's winfile.exe */
774 static int INT21_FindFirstFCB( CONTEXT86 *context )
776 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
781 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
782 else pFCB = (FINDFILE_FCB *)fcb;
783 drive = DOS_GET_DRIVE( pFCB->drive );
784 if (!DRIVE_IsValid( drive )) return 0;
785 root = DRIVE_GetRoot( drive );
786 cwd = DRIVE_GetUnixCwd( drive );
787 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
788 strlen(root)+strlen(cwd)+2 );
789 if (!pFCB->unixPath) return 0;
790 strcpy( pFCB->unixPath, root );
791 strcat( pFCB->unixPath, "/" );
792 strcat( pFCB->unixPath, cwd );
798 static int INT21_FindNextFCB( CONTEXT86 *context )
800 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
802 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
803 WIN32_FIND_DATAA entry;
807 if (*fcb == 0xff) /* extended FCB ? */
810 pFCB = (FINDFILE_FCB *)(fcb + 7);
815 pFCB = (FINDFILE_FCB *)fcb;
818 if (!pFCB->unixPath) return 0;
819 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
820 DOS_GET_DRIVE( pFCB->drive ), attr,
821 pFCB->count, &entry )))
823 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
824 pFCB->unixPath = NULL;
827 pFCB->count += count;
829 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
830 *(BYTE *)pResult = 0xff;
831 (BYTE *)pResult +=6; /* leave reserved field behind */
832 *(BYTE *)pResult = entry.dwFileAttributes;
835 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
837 pResult->fileattr = entry.dwFileAttributes;
838 pResult->cluster = 0; /* what else? */
839 pResult->filesize = entry.nFileSizeLow;
840 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
841 FileTimeToDosDateTime( &entry.ftLastWriteTime,
842 &pResult->filedate, &pResult->filetime );
844 /* Convert file name to FCB format */
846 memset( pResult->filename, ' ', sizeof(pResult->filename) );
847 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
848 else if (!strcmp( entry.cAlternateFileName, ".." ))
849 pResult->filename[0] = pResult->filename[1] = '.';
852 char *p = strrchr( entry.cAlternateFileName, '.' );
853 if (p && p[1] && (p != entry.cAlternateFileName))
855 memcpy( pResult->filename, entry.cAlternateFileName,
856 min( (p - entry.cAlternateFileName), 8 ) );
857 memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
860 memcpy( pResult->filename, entry.cAlternateFileName,
861 min( strlen(entry.cAlternateFileName), 8 ) );
867 static void DeleteFileFCB( CONTEXT86 *context )
869 FIXME("(%p): stub\n", context);
872 static void RenameFileFCB( CONTEXT86 *context )
874 FIXME("(%p): stub\n", context);
879 static void fLock( CONTEXT86 * context )
882 switch ( AX_reg(context) & 0xff )
884 case 0x00: /* LOCK */
885 TRACE("lock handle %d offset %ld length %ld\n",
887 MAKELONG(DX_reg(context),CX_reg(context)),
888 MAKELONG(DI_reg(context),SI_reg(context))) ;
889 if (!LockFile(FILE_GetHandle(BX_reg(context)),
890 MAKELONG(DX_reg(context),CX_reg(context)), 0,
891 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
892 AX_reg(context) = GetLastError();
897 case 0x01: /* UNLOCK */
898 TRACE("unlock handle %d offset %ld length %ld\n",
900 MAKELONG(DX_reg(context),CX_reg(context)),
901 MAKELONG(DI_reg(context),SI_reg(context))) ;
902 if (!UnlockFile(FILE_GetHandle(BX_reg(context)),
903 MAKELONG(DX_reg(context),CX_reg(context)), 0,
904 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
905 AX_reg(context) = GetLastError();
910 AX_reg(context) = 0x0001;
917 INT21_networkfunc (CONTEXT86 *context)
919 switch (AL_reg(context)) {
920 case 0x00: /* Get machine name. */
922 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
923 TRACE("getting machine name to %p\n", dst);
924 if (gethostname (dst, 15))
927 SetLastError( ER_NoNetwork );
930 int len = strlen (dst);
934 CH_reg(context) = 1; /* Valid */
935 CL_reg(context) = 1; /* NETbios number??? */
936 TRACE("returning %s\n", debugstr_an (dst, 16));
942 SetLastError( ER_NoNetwork );
947 static void INT21_SetCurrentPSP(WORD psp)
949 LPDOSTASK lpDosTask = MZ_Current();
951 lpDosTask->psp_seg = psp;
953 ERR("Cannot change PSP for non-DOS task!\n");
956 static WORD INT21_GetCurrentPSP()
958 LPDOSTASK lpDosTask = MZ_Current();
960 return lpDosTask->psp_seg;
962 return GetCurrentPDB16();
966 /***********************************************************************
967 * INT21_GetExtendedError
969 static void INT21_GetExtendedError( CONTEXT86 *context )
971 BYTE class, action, locus;
972 WORD error = GetLastError();
977 class = action = locus = 0;
979 case ERROR_DIR_NOT_EMPTY:
984 case ERROR_ACCESS_DENIED:
985 class = EC_AccessDenied;
989 case ERROR_CANNOT_MAKE:
990 class = EC_AccessDenied;
994 case ERROR_DISK_FULL:
995 case ERROR_HANDLE_DISK_FULL:
996 class = EC_MediaError;
1000 case ERROR_FILE_EXISTS:
1001 case ERROR_ALREADY_EXISTS:
1006 case ERROR_FILE_NOT_FOUND:
1007 class = EC_NotFound;
1011 case ER_GeneralFailure:
1012 class = EC_SystemFailure;
1016 case ERROR_INVALID_DRIVE:
1017 class = EC_MediaError;
1021 case ERROR_INVALID_HANDLE:
1022 class = EC_ProgramError;
1026 case ERROR_LOCK_VIOLATION:
1027 class = EC_AccessDenied;
1031 case ERROR_NO_MORE_FILES:
1032 class = EC_MediaError;
1037 class = EC_NotFound;
1041 case ERROR_NOT_ENOUGH_MEMORY:
1042 class = EC_OutOfResource;
1046 case ERROR_PATH_NOT_FOUND:
1047 class = EC_NotFound;
1052 class = EC_NotFound;
1056 case ERROR_SHARING_VIOLATION:
1057 class = EC_Temporary;
1061 case ERROR_TOO_MANY_OPEN_FILES:
1062 class = EC_ProgramError;
1067 FIXME("Unknown error %d\n", error );
1068 class = EC_SystemFailure;
1073 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1074 error, class, action, locus );
1075 AX_reg(context) = error;
1076 BH_reg(context) = class;
1077 BL_reg(context) = action;
1078 CH_reg(context) = locus;
1081 /***********************************************************************
1082 * DOS3Call (KERNEL.102)
1084 void WINAPI DOS3Call( CONTEXT86 *context )
1086 BOOL bSetDOSExtendedError = FALSE;
1089 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1090 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1091 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1092 SI_reg(context), DI_reg(context),
1093 (WORD)DS_reg(context), (WORD)ES_reg(context),
1097 if (AH_reg(context) == 0x59) /* Get extended error info */
1099 INT21_GetExtendedError( context );
1103 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1105 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1106 /* no flush here yet */
1107 AH_reg(context) = AL_reg(context);
1110 if (AH_reg(context)>=0x2f) {
1111 /* extended error is used by (at least) functions 0x2f to 0x62 */
1114 RESET_CFLAG(context); /* Not sure if this is a good idea */
1116 switch(AH_reg(context))
1118 case 0x03: /* READ CHARACTER FROM STDAUX */
1119 case 0x04: /* WRITE CHARACTER TO STDAUX */
1120 case 0x05: /* WRITE CHARACTER TO PRINTER */
1121 case 0x0f: /* OPEN FILE USING FCB */
1122 case 0x10: /* CLOSE FILE USING FCB */
1123 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1124 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1125 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1126 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1127 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1128 case 0x23: /* GET FILE SIZE FOR FCB */
1129 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1130 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1131 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1132 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1133 INT_BARF( context, 0x21 );
1136 case 0x00: /* TERMINATE PROGRAM */
1137 TRACE("TERMINATE PROGRAM\n");
1141 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1142 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1143 AL_reg(context) = CONSOLE_GetCharacter();
1144 /* FIXME: no echo */
1147 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1148 TRACE("Write Character to Standard Output\n");
1149 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1152 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1153 /* FIXME: Use DOSDEV_Peek/Read/Write(DOSDEV_Console(),...) !! */
1154 if (DL_reg(context) == 0xff) {
1155 static char scan = 0;
1156 TRACE("Direct Console Input\n");
1158 /* return pending scancode */
1159 AL_reg(context) = scan;
1160 RESET_ZFLAG(context);
1164 if (INT_Int16ReadChar(&ascii,&scan,TRUE)) {
1165 INT_Int16ReadChar(&ascii,&scan,FALSE);
1166 /* return ASCII code */
1167 AL_reg(context) = ascii;
1168 RESET_ZFLAG(context);
1169 /* return scan code on next call only if ascii==0 */
1170 if (ascii) scan = 0;
1172 /* nothing pending, clear everything */
1173 AL_reg(context) = 0;
1175 scan = 0; /* just in case */
1179 TRACE("Direct Console Output\n");
1180 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1184 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1185 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
1186 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1187 INT_Int16ReadChar(&AL_reg(context), NULL, FALSE);
1190 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1191 /* FIXME: Use DOSDEV_Peek/Read(DOSDEV_Console(),...) !! */
1192 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1193 INT_Int16ReadChar(&AL_reg(context), NULL, FALSE);
1196 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1197 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1198 DS_reg(context),DX_reg(context) );
1200 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1202 /* do NOT use strchr() to calculate the string length,
1203 as '\0' is valid string content, too !
1204 Maybe we should check for non-'$' strings, but DOS doesn't. */
1205 while (*p != '$') p++;
1206 _hwrite16( 1, data, (int)p - (int)data);
1207 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1211 case 0x0a: /* BUFFERED INPUT */
1213 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1214 EDX_reg(context) ));
1217 TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1219 TRACE("Handle old chars in buffer!\n");
1220 res=_lread16( 0, buffer+2,buffer[0]);
1222 if(buffer[res+1] == '\n')
1223 buffer[res+1] = '\r';
1227 case 0x0b: {/* GET STDIN STATUS */
1230 if (CONSOLE_CheckForKeystroke(&x1,&x2))
1231 AL_reg(context) = 0xff;
1233 AL_reg(context) = 0;
1236 case 0x2e: /* SET VERIFY FLAG */
1237 TRACE("SET VERIFY FLAG ignored\n");
1238 /* we cannot change the behaviour anyway, so just ignore it */
1241 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1245 case 0x6b: /* NULL FUNCTION */
1246 AL_reg(context) = 0;
1249 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1253 case 0x0d: /* DISK BUFFER FLUSH */
1254 TRACE("DISK BUFFER FLUSH ignored\n");
1255 RESET_CFLAG(context); /* dos 6+ only */
1258 case 0x0e: /* SELECT DEFAULT DRIVE */
1259 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1260 DRIVE_SetCurrentDrive( DL_reg(context) );
1261 AL_reg(context) = MAX_DOS_DRIVES;
1264 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1265 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1266 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1267 if (!INT21_FindFirstFCB(context))
1269 AL_reg(context) = 0xff;
1272 /* else fall through */
1274 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1275 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1278 case 0x13: /* DELETE FILE USING FCB */
1279 DeleteFileFCB(context);
1282 case 0x17: /* RENAME FILE USING FCB */
1283 RenameFileFCB(context);
1286 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1287 AL_reg(context) = DRIVE_GetCurrentDrive();
1290 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1292 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1293 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1294 TRACE("Set DTA: %08lx\n", pTask->dta);
1298 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1299 DL_reg(context) = 0;
1300 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1303 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1304 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1307 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1308 GetDrivePB(context, DRIVE_GetCurrentDrive());
1311 case 0x25: /* SET INTERRUPT VECTOR */
1312 INT_CtxSetHandler( context, AL_reg(context),
1313 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1317 case 0x29: /* PARSE FILENAME INTO FCB */
1318 INT21_ParseFileNameIntoFCB(context);
1321 case 0x2a: /* GET SYSTEM DATE */
1322 INT21_GetSystemDate(context);
1325 case 0x2b: /* SET SYSTEM DATE */
1326 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1327 DL_reg(context), DH_reg(context), CX_reg(context) );
1328 AL_reg(context) = 0; /* Let's pretend we succeeded */
1331 case 0x2c: /* GET SYSTEM TIME */
1332 INT21_GetSystemTime(context);
1335 case 0x2d: /* SET SYSTEM TIME */
1336 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1337 CH_reg(context), CL_reg(context),
1338 DH_reg(context), DL_reg(context) );
1339 AL_reg(context) = 0; /* Let's pretend we succeeded */
1342 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1343 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1345 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1346 ES_reg(context) = SELECTOROF( pTask->dta );
1347 BX_reg(context) = OFFSETOF( pTask->dta );
1351 case 0x30: /* GET DOS VERSION */
1352 TRACE("GET DOS VERSION %s requested\n",
1353 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1354 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1355 (HIWORD(GetVersion16()) << 8);
1357 AH_reg(context) = 0x7;
1358 AL_reg(context) = 0xA;
1361 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1362 CX_reg(context) = 0x0000;
1365 case 0x31: /* TERMINATE AND STAY RESIDENT */
1366 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1369 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1370 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1371 INT21_DriveName( DL_reg(context)));
1372 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1375 case 0x33: /* MULTIPLEXED */
1376 switch (AL_reg(context))
1378 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1379 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1380 DL_reg(context) = DOSCONF_config.brk_flag;
1383 case 0x01: /* SET EXTENDED BREAK STATE */
1384 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1385 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1388 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1389 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1390 /* ugly coding in order to stay reentrant */
1391 if (DL_reg(context))
1393 DL_reg(context) = DOSCONF_config.brk_flag;
1394 DOSCONF_config.brk_flag = 1;
1398 DL_reg(context) = DOSCONF_config.brk_flag;
1399 DOSCONF_config.brk_flag = 0;
1403 case 0x05: /* GET BOOT DRIVE */
1404 TRACE("GET BOOT DRIVE\n");
1405 DL_reg(context) = 3;
1406 /* c: is Wine's bootdrive (a: is 1)*/
1409 case 0x06: /* GET TRUE VERSION NUMBER */
1410 TRACE("GET TRUE VERSION NUMBER\n");
1411 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1412 (HIWORD(GetVersion16() << 8));
1413 DX_reg(context) = 0x00;
1417 INT_BARF( context, 0x21 );
1422 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1423 TRACE("GET ADDRESS OF INDOS FLAG\n");
1424 if (!heap) INT21_CreateHeap();
1425 ES_reg(context) = DosHeapHandle;
1426 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1429 case 0x35: /* GET INTERRUPT VECTOR */
1430 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1432 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1433 ES_reg(context) = SELECTOROF(addr);
1434 BX_reg(context) = OFFSETOF(addr);
1438 case 0x36: /* GET FREE DISK SPACE */
1439 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1440 INT21_DriveName( DL_reg(context)));
1441 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1446 unsigned char switchchar='/';
1447 switch (AL_reg(context))
1449 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1450 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1451 AL_reg(context) = 0x00; /* success*/
1452 DL_reg(context) = switchchar;
1454 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1455 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1456 switchchar = DL_reg(context);
1457 AL_reg(context) = 0x00; /* success*/
1459 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1460 INT_BARF( context, 0x21 );
1466 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1467 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1469 AX_reg(context) = 0x02; /* no country support available */
1473 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1475 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1476 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1477 EDX_reg(context) ), NULL));
1478 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1479 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1480 * denied), while CreateDirectory return several ones. remap some of
1483 if (bSetDOSExtendedError) {
1484 switch (GetLastError()) {
1485 case ERROR_ALREADY_EXISTS:
1486 case ERROR_FILENAME_EXCED_RANGE:
1487 case ERROR_DISK_FULL:
1488 SetLastError(ERROR_ACCESS_DENIED);
1495 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1497 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1498 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1499 EDX_reg(context) )));
1502 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1504 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1505 bSetDOSExtendedError = !INT21_ChangeDir(context);
1508 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1509 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1510 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1511 bSetDOSExtendedError = INT21_CreateFile( context );
1514 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1515 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1516 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1517 OpenExistingFile(context);
1520 case 0x3e: /* "CLOSE" - CLOSE FILE */
1521 TRACE("CLOSE handle %d\n",BX_reg(context));
1522 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1525 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1526 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1527 DS_reg(context),DX_reg(context),CX_reg(context) );
1531 result = _hread16( BX_reg(context),
1532 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1536 result = WIN16_hread( BX_reg(context),
1537 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1540 if (result == -1) bSetDOSExtendedError = TRUE;
1541 else AX_reg(context) = (WORD)result;
1545 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1546 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1547 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1549 LONG result = _hwrite16( BX_reg(context),
1550 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1553 if (result == -1) bSetDOSExtendedError = TRUE;
1554 else AX_reg(context) = (WORD)result;
1558 case 0x41: /* "UNLINK" - DELETE FILE */
1559 TRACE("UNLINK %s\n",
1560 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1561 bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1562 EDX_reg(context) )));
1565 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1566 TRACE("LSEEK handle %d offset %ld from %s\n",
1567 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1568 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1569 "current file position":"end of file");
1571 LONG status = _llseek16( BX_reg(context),
1572 MAKELONG(DX_reg(context),CX_reg(context)),
1574 if (status == -1) bSetDOSExtendedError = TRUE;
1577 AX_reg(context) = LOWORD(status);
1578 DX_reg(context) = HIWORD(status);
1583 case 0x43: /* FILE ATTRIBUTES */
1584 switch (AL_reg(context))
1587 TRACE("GET FILE ATTRIBUTES for %s\n",
1588 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1589 AX_reg(context) = (WORD)GetFileAttributesA(
1590 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1592 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1593 else CX_reg(context) = AX_reg(context);
1597 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1598 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1599 bSetDOSExtendedError =
1600 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1605 FIXME("GET COMPRESSED FILE SIZE for %s stub\n",
1606 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1610 case 0x44: /* IOCTL */
1611 switch (AL_reg(context))
1614 ioctlGetDeviceInfo(context);
1620 const DOS_DEVICE *dev;
1621 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )) &&
1622 !strcasecmp( dev->name, "SCSIMGR$" ))
1624 ASPI_DOS_HandleInt(context);
1628 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1629 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1630 int drive = DOS_GET_DRIVE(BL_reg(context));
1632 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1633 /* for (i=0;i<CX_reg(context);i++)
1634 fprintf(stdnimp,"%02x ",dataptr[i]);
1635 fprintf(stdnimp,"\n");*/
1636 AX_reg(context)=CX_reg(context);
1639 case 0x08: /* Check if drive is removable. */
1640 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1641 INT21_DriveName( BL_reg(context)));
1642 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1644 case DRIVE_CANNOTDETERMINE:
1645 SetLastError( ERROR_INVALID_DRIVE );
1646 AX_reg(context) = ERROR_INVALID_DRIVE;
1649 case DRIVE_REMOVABLE:
1650 AX_reg(context) = 0; /* removable */
1653 AX_reg(context) = 1; /* not removable */
1658 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1659 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1660 INT21_DriveName( BL_reg(context)));
1661 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1663 case DRIVE_CANNOTDETERMINE:
1664 SetLastError( ERROR_INVALID_DRIVE );
1665 AX_reg(context) = ERROR_INVALID_DRIVE;
1669 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1672 DX_reg(context) = 0; /* FIXME: use driver attr here */
1677 case 0x0a: /* check if handle (BX) is remote */
1678 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1679 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1682 DX_reg(context) = 0;
1685 case 0x0b: /* SET SHARING RETRY COUNT */
1686 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1687 CX_reg(context), DX_reg(context));
1688 if (!CX_reg(context))
1690 AX_reg(context) = 1;
1694 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
1695 if (!DX_reg(context))
1696 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
1697 RESET_CFLAG(context);
1701 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1702 INT21_DriveName( BL_reg(context)));
1703 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1706 case 0x0e: /* get logical drive mapping */
1707 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1708 INT21_DriveName( BL_reg(context)));
1709 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1712 case 0x0F: /* Set logical drive mapping */
1715 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1716 INT21_DriveName( BL_reg(context)));
1717 drive = DOS_GET_DRIVE ( BL_reg(context) );
1718 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1721 AX_reg(context) = 0x000F; /* invalid drive */
1726 case 0xe0: /* Sun PC-NFS API */
1731 INT_BARF( context, 0x21 );
1736 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1739 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1740 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1741 FILE_GetHandle(BX_reg(context)),
1742 GetCurrentProcess(), &handle,
1743 0, TRUE, DUPLICATE_SAME_ACCESS )))
1744 AX_reg(context) = HFILE_ERROR16;
1746 AX_reg(context) = FILE_AllocDosHandle(handle);
1750 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1751 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1752 BX_reg(context),CX_reg(context));
1753 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1756 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1757 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1758 INT21_DriveName( DL_reg(context)));
1759 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1762 case 0x48: /* ALLOCATE MEMORY */
1763 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1768 mem= DOSMEM_GetBlock((DWORD)BX_reg(context)<<4,NULL);
1770 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1774 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1776 AX_reg(context) = (DWORD)mem&0xffff;
1781 AX_reg(context) = 0x0008; /* insufficient memory */
1782 BX_reg(context) = DOSMEM_Available()>>4;
1787 case 0x49: /* FREE MEMORY */
1788 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context));
1792 ret= DOSMEM_FreeBlock(DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1795 ret = !GlobalDOSFree16(ES_reg(context));
1796 /* If we don't reset ES_reg, we will fail in the relay code */
1797 ES_reg(context)=ret;
1801 TRACE("FREE MEMORY failed\n");
1803 AX_reg(context) = 0x0009; /* memory block address invalid */
1808 case 0x4a: /* RESIZE MEMORY BLOCK */
1809 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1810 if (!ISV86(context))
1811 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1813 LPVOID *mem = DOSMEM_ResizeBlock(DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1814 BX_reg(context)<<4,NULL);
1816 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1819 AX_reg(context) = 0x0008; /* insufficient memory */
1820 BX_reg(context) = DOSMEM_Available()>>4; /* not quite right */
1825 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1827 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1828 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1831 if (AX_reg(context) < 32) SET_CFLAG(context);
1834 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1835 TRACE("EXIT with return code %d\n",AL_reg(context));
1836 ExitThread( AL_reg(context) );
1839 case 0x4d: /* GET RETURN CODE */
1840 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1841 AX_reg(context) = 0; /* normal exit */
1844 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1845 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1846 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1847 if (!INT21_FindFirst(context)) break;
1850 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1851 TRACE("FINDNEXT\n");
1852 if (!INT21_FindNext(context))
1854 SetLastError( ERROR_NO_MORE_FILES );
1855 AX_reg(context) = ERROR_NO_MORE_FILES;
1858 else AX_reg(context) = 0; /* OK */
1860 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1861 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1862 INT21_SetCurrentPSP(BX_reg(context));
1864 case 0x51: /* GET PSP ADDRESS */
1865 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1866 /* FIXME: should we return the original DOS PSP upon */
1867 /* Windows startup ? */
1868 BX_reg(context) = INT21_GetCurrentPSP();
1870 case 0x62: /* GET PSP ADDRESS */
1871 TRACE("GET CURRENT PSP ADDRESS\n");
1872 /* FIXME: should we return the original DOS PSP upon */
1873 /* Windows startup ? */
1874 BX_reg(context) = INT21_GetCurrentPSP();
1877 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1878 TRACE("SYSVARS - GET LIST OF LISTS\n");
1880 ES_reg(context) = ISV86(context) ? HIWORD(DOS_LOLSeg) : LOWORD(DOS_LOLSeg);
1881 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1885 case 0x54: /* Get Verify Flag */
1886 TRACE("Get Verify Flag - Not Supported\n");
1887 AL_reg(context) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1890 case 0x56: /* "RENAME" - RENAME FILE */
1891 TRACE("RENAME %s to %s\n",
1892 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1893 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1894 bSetDOSExtendedError =
1895 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1896 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1899 case 0x57: /* FILE DATE AND TIME */
1900 switch (AL_reg(context))
1902 case 0x00: /* Get */
1905 TRACE("GET FILE DATE AND TIME for handle %d\n",
1907 if (!GetFileTime( FILE_GetHandle(BX_reg(context)), NULL, NULL, &filetime ))
1908 bSetDOSExtendedError = TRUE;
1909 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1914 case 0x01: /* Set */
1917 TRACE("SET FILE DATE AND TIME for handle %d\n",
1919 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1921 bSetDOSExtendedError =
1922 (!SetFileTime( FILE_GetHandle(BX_reg(context)),
1923 NULL, NULL, &filetime ));
1929 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1930 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1932 switch (AL_reg(context))
1935 AX_reg(context) = 1;
1938 AX_reg(context) = 0;
1944 RESET_CFLAG(context);
1947 case 0x5a: /* CREATE TEMPORARY FILE */
1948 TRACE("CREATE TEMPORARY FILE\n");
1949 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1952 case 0x5b: /* CREATE NEW FILE */
1953 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1954 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1955 bSetDOSExtendedError = ((AX_reg(context) =
1956 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1957 CX_reg(context) )) == (WORD)HFILE_ERROR16);
1960 case 0x5d: /* NETWORK */
1961 FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1962 /* Fix the following while you're at it. */
1963 SetLastError( ER_NoNetwork );
1964 bSetDOSExtendedError = TRUE;
1968 bSetDOSExtendedError = INT21_networkfunc (context);
1971 case 0x5f: /* NETWORK */
1972 switch (AL_reg(context))
1974 case 0x07: /* ENABLE DRIVE */
1975 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1976 if (!DRIVE_Enable( DL_reg(context) ))
1978 SetLastError( ERROR_INVALID_DRIVE );
1979 bSetDOSExtendedError = TRUE;
1983 case 0x08: /* DISABLE DRIVE */
1984 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1985 if (!DRIVE_Disable( DL_reg(context) ))
1987 SetLastError( ERROR_INVALID_DRIVE );
1988 bSetDOSExtendedError = TRUE;
1993 /* network software not installed */
1994 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1995 SetLastError( ER_NoNetwork );
1996 bSetDOSExtendedError = TRUE;
2001 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
2002 TRACE("TRUENAME %s\n",
2003 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
2005 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2006 ESI_reg(context)), 128,
2007 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2008 EDI_reg(context)),NULL))
2009 bSetDOSExtendedError = TRUE;
2010 else AX_reg(context) = 0;
2014 case 0x61: /* UNUSED */
2015 case 0x63: /* misc. language support */
2016 switch (AL_reg(context)) {
2017 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
2018 INT21_GetDBCSLeadTable(context);
2022 case 0x64: /* OS/2 DOS BOX */
2023 INT_BARF( context, 0x21 );
2027 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
2028 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
2029 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2030 BX_reg(context), DX_reg(context));
2031 switch (AL_reg(context)) {
2033 TRACE("\tget general internationalization info\n");
2035 *(WORD*)(dataptr+1) = 41;
2036 *(WORD*)(dataptr+3) = GetSystemDefaultLangID();
2037 *(WORD*)(dataptr+5) = CodePage;
2038 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
2041 TRACE("\tget pointer to collating sequence table\n");
2043 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
2044 CX_reg(context) = 258;/*FIXME: size of table?*/
2047 TRACE("\tConvert char to uppercase\n");
2048 DL_reg(context) = toupper(DL_reg(context));
2051 TRACE("\tconvert string to uppercase with length\n");
2052 CharUpperBuffA( (LPSTR)CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context)),
2056 TRACE("\tConvert ASCIIZ string to uppercase\n");
2057 CharUpperA( (LPSTR)CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context)) );
2060 TRACE("\tunimplemented function %d\n",AL_reg(context));
2061 INT_BARF( context, 0x21 );
2067 case 0x66: /* GLOBAL CODE PAGE TABLE */
2068 switch (AL_reg(context))
2071 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2072 DX_reg(context) = BX_reg(context) = CodePage;
2073 RESET_CFLAG(context);
2076 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2077 BX_reg(context),DX_reg(context));
2078 CodePage = BX_reg(context);
2079 RESET_CFLAG(context);
2084 case 0x67: /* SET HANDLE COUNT */
2085 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2086 SetHandleCount16( BX_reg(context) );
2087 if (GetLastError()) bSetDOSExtendedError = TRUE;
2090 case 0x68: /* "FFLUSH" - COMMIT FILE */
2091 case 0x6a: /* COMMIT FILE */
2092 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2093 bSetDOSExtendedError = (!FlushFileBuffers( FILE_GetHandle(BX_reg(context)) ));
2096 case 0x69: /* DISK SERIAL NUMBER */
2097 switch (AL_reg(context))
2100 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2101 INT21_DriveName(BL_reg(context)));
2102 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2103 else AX_reg(context) = 0;
2107 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2108 INT21_DriveName(BL_reg(context)));
2109 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2110 else AX_reg(context) = 1;
2115 case 0x6C: /* Extended Open/Create*/
2116 TRACE("EXTENDED OPEN/CREATE %s\n",
2117 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
2118 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2121 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2122 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2123 /* not supported on anything but Win95 */
2124 TRACE("LONG FILENAME functions supported only by win95\n");
2126 AL_reg(context) = 0;
2128 switch(AL_reg(context))
2130 case 0x39: /* Create directory */
2131 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2132 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2133 bSetDOSExtendedError = (!CreateDirectoryA(
2134 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2135 EDX_reg(context) ), NULL));
2136 /* FIXME: CreateDirectory's LastErrors will clash with the ones
2137 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
2138 * denied), while CreateDirectory return several ones. remap some of
2141 if (bSetDOSExtendedError) {
2142 switch (GetLastError()) {
2143 case ERROR_ALREADY_EXISTS:
2144 case ERROR_FILENAME_EXCED_RANGE:
2145 case ERROR_DISK_FULL:
2146 SetLastError(ERROR_ACCESS_DENIED);
2152 case 0x3a: /* Remove directory */
2153 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2154 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2155 bSetDOSExtendedError = (!RemoveDirectoryA(
2156 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2157 EDX_reg(context) )));
2159 case 0x43: /* Get/Set file attributes */
2160 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2161 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2162 switch (BL_reg(context))
2164 case 0x00: /* Get file attributes */
2165 TRACE("\tretrieve attributes\n");
2166 CX_reg(context) = (WORD)GetFileAttributesA(
2167 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2169 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2172 TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2173 bSetDOSExtendedError = (!SetFileAttributesA(
2174 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2176 CX_reg(context) ) );
2179 FIXME("Unimplemented long file name function:\n");
2180 INT_BARF( context, 0x21 );
2182 AL_reg(context) = 0;
2186 case 0x47: /* Get current directory */
2187 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2188 INT21_DriveName(DL_reg(context)));
2189 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2192 case 0x4e: /* Find first file */
2193 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2194 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2195 /* FIXME: use attributes in CX */
2196 if ((AX_reg(context) = FindFirstFile16(
2197 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2198 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2200 == INVALID_HANDLE_VALUE16)
2201 bSetDOSExtendedError = TRUE;
2203 case 0x4f: /* Find next file */
2204 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2206 if (!FindNextFile16( BX_reg(context),
2207 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2209 bSetDOSExtendedError = TRUE;
2213 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
2214 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
2218 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
2219 AX_reg(context) = 0;
2222 INT_BARF( context, 0x21 );
2226 drive = toupper(driveroot[0]) - 'A';
2227 flags = DRIVE_GetFlags(toupper(driveroot[0]) - 'A');
2228 BX_reg(context) = 0x4000; /* support for LFN functions */
2229 if (flags & DRIVE_CASE_SENSITIVE)
2230 BX_reg(context) |= 1;
2231 if (flags & DRIVE_CASE_PRESERVING)
2232 BX_reg(context) |= 2;
2233 /***** FIXME: not supported yet (needed ?)
2234 if (flags & DRIVE_UNICODE)
2235 BX_reg(context) |= 4;
2236 if (flags & DRIVE_COMPRESSED)
2237 BX_reg(context) |= 0x8000;
2239 CX_reg(context) = (flags & DRIVE_SHORT_NAMES) ? 11 : 255; /* FIXME: 12 ? */
2240 DX_reg(context) = MAX_PATH; /* FIXME: which len if DRIVE_SHORT_NAMES ? */
2241 if (DRIVE_GetType(drive) == TYPE_CDROM)
2242 /* valid for data _and_ audio */
2243 strcpy(buffer, "CDFS"); /* FIXME: fail if no CD in drive */
2245 strcpy(buffer, "FAT");
2248 case 0xa1: /* Find close */
2249 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2251 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2254 switch(CL_reg(context))
2256 case 0x01: /*Get short filename or path */
2257 if (!GetShortPathNameA
2258 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2260 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2261 EDI_reg(context)), 67))
2262 bSetDOSExtendedError = TRUE;
2263 else AX_reg(context) = 0;
2265 case 0x02: /*Get canonical long filename or path */
2266 if (!GetFullPathNameA
2267 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2268 ESI_reg(context)), 128,
2269 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2270 EDI_reg(context)),NULL))
2271 bSetDOSExtendedError = TRUE;
2272 else AX_reg(context) = 0;
2275 FIXME("Unimplemented long file name function:\n");
2276 INT_BARF( context, 0x21 );
2278 AL_reg(context) = 0;
2282 case 0x6c: /* Create or open file */
2283 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2284 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2285 /* translate Dos 7 action to Dos 6 action */
2286 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2289 case 0x3b: /* Change directory */
2290 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2291 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2292 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2298 AL_reg(context) = GetLastError();
2301 case 0x41: /* Delete file */
2302 TRACE("LONG FILENAME - DELETE FILE %s\n",
2303 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2304 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2309 AL_reg(context) = GetLastError();
2312 case 0x56: /* Move (rename) file */
2313 FIXME("LONG FILENAME - RENAME FILE %s to %s stub\n",
2314 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2315 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2317 FIXME("Unimplemented long file name function:\n");
2318 INT_BARF( context, 0x21 );
2320 AL_reg(context) = 0;
2325 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2326 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2327 TRACE("windows95 function AX %04x\n",
2329 WARN(" returning unimplemented\n");
2331 AL_reg(context) = 0;
2334 case 0x73: /* MULTIPLEXED: Win95 OSR2/Win98 FAT32 calls */
2335 TRACE("windows95 function AX %04x\n",
2338 switch (AL_reg(context))
2340 case 0x02: /* Get Extended Drive Parameter Block for specific drive */
2341 /* ES:DI points to word with length of data (should be 0x3d) */
2345 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
2346 char root[] = "A:\\";
2348 buffer = (WORD *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context));
2350 TRACE("Get Extended DPB: linear buffer address is %p\n", buffer);
2352 /* validate passed-in buffer lengths */
2353 if ((*buffer != 0x3d) || (ECX_reg(context) != 0x3f))
2355 WARN("Get Extended DPB: buffer lengths incorrect\n");
2356 WARN("CX = %lx, buffer[0] = %x\n", ECX_reg(context), *buffer);
2358 AL_reg(context) = 0x18; /* bad buffer length */
2361 /* buffer checks out */
2362 buffer++; /* skip over length word now */
2363 if (FillInDrivePB( DX_reg(context) ) )
2365 edpb = (struct EDPB *)buffer;
2367 /* copy down the old-style DPB portion first */
2368 memcpy(&edpb->dpb, &heap->dpb, sizeof(struct DPB));
2370 /* now fill in the extended entries */
2371 edpb->edpb_flags = 0;
2372 edpb->next_edpb = 0;
2373 edpb->free_cluster = edpb->free_cluster2 = 0;
2375 /* determine free disk space */
2376 *root += DOS_GET_DRIVE( DX_reg(context) );
2377 GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
2378 &free_clusters, &total_clusters );
2380 edpb->clusters_free = (free_clusters&0xffff);
2382 edpb->clusters_free_hi = free_clusters >> 16;
2383 edpb->mirroring_flags = 0;
2384 edpb->info_sector = 0xffff;
2385 edpb->spare_boot_sector = 0xffff;
2386 edpb->first_cluster = 0;
2387 edpb->max_cluster = total_clusters;
2388 edpb->fat_clusters = 32; /* made-up value */
2389 edpb->root_cluster = 0;
2391 RESET_CFLAG(context); /* clear carry */
2392 AX_reg(context) = 0;
2396 AX_reg(context) = 0x00ff;
2402 case 0x03: /* Get Extended free space on drive */
2403 case 0x04: /* Set DPB for formatting */
2404 case 0x05: /* extended absolute disk read/write */
2405 FIXME("Unimplemented FAT32 int32 function %04x\n", AX_reg(context));
2407 AL_reg(context) = 0;
2414 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2415 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2419 INT_BARF( context, 0x21 );
2422 } /* END OF SWITCH */
2424 if( bSetDOSExtendedError ) /* set general error condition */
2426 AX_reg(context) = GetLastError();
2430 if ((EFL_reg(context) & 0x0001))
2431 TRACE("failed, error 0x%04lx\n", GetLastError() );
2433 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2434 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2435 AX_reg(context), BX_reg(context), CX_reg(context),
2436 DX_reg(context), SI_reg(context), DI_reg(context),
2437 (WORD)DS_reg(context), (WORD)ES_reg(context),
2441 /***********************************************************************
2442 * GetSetKernelDOSProc
2444 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2446 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);