2 * DOS interrupt 21h handler
13 #include <sys/types.h>
28 #if defined(__svr4__) || defined(_SCO_DS)
29 /* SVR4 DOESNT do locking the same way must implement properly */
36 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
38 /* Define the drive parameter block, as used by int21/1F
39 * and int21/32. This table can be accessed through the
40 * global 'dpb' pointer, which points into the local dos
45 BYTE drive_num; /* 0=A, etc. */
46 BYTE unit_num; /* Drive's unit number (?) */
47 WORD sector_size; /* Sector size in bytes */
48 BYTE high_sector; /* Highest sector in a cluster */
49 BYTE shift; /* Shift count (?) */
50 WORD reserved; /* Number of reserved sectors at start */
51 BYTE num_FAT; /* Number of FATs */
52 WORD dir_entries; /* Number of root dir entries */
53 WORD first_data; /* First data sector */
54 WORD high_cluster; /* Highest cluster number */
55 WORD sectors_in_FAT; /* Number of sectors per FAT */
56 WORD start_dir; /* Starting sector of first dir */
57 DWORD driver_head; /* Address of device driver header (?) */
58 BYTE media_ID; /* Media ID */
59 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
60 DWORD next; /* Pointer to next DPB in list */
61 WORD free_search; /* Free cluster search start */
62 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
73 BYTE DummyDBCSLeadTable[6];
75 static struct DosHeap *heap;
76 static WORD DosHeapHandle;
78 WORD sharing_retries = 3; /* number of retries at sharing violation */
79 WORD sharing_pause = 1; /* pause between retries */
81 extern char TempDirectory[];
83 static BOOL32 INT21_CreateHeap(void)
85 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
87 WARN(int21, "Out of memory\n");
90 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
91 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
93 strcpy(heap->biosdate, "01/01/80");
94 memset(heap->DummyDBCSLeadTable, 0, 6);
98 static BYTE *GetCurrentDTA( CONTEXT *context )
100 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
102 /* FIXME: This assumes DTA was set correctly! */
103 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
104 (DWORD)OFFSETOF(pTask->dta) );
108 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
109 /* limited == TRUE is used with INT 0x21/0x440d */
114 setword(&data[3], 0);
116 setword(&data[6], 240);
117 setword(&data[8], 64000);
119 setword(&data[0x0b], 40);
120 setword(&data[0x0d], 56);
121 setword(&data[0x0f], 2);
122 setword(&data[0x11], 0);
124 setword(&data[0x1f], 800);
126 setword(&data[0x22], 1);
128 } else { /* 1.44mb */
131 setword(&data[3], 0);
133 setword(&data[6], 240);
134 setword(&data[8], 2880);
136 setword(&data[0x0b], 6);
137 setword(&data[0x0d], 18);
138 setword(&data[0x0f], 2);
139 setword(&data[0x11], 0);
141 setword(&data[0x1f], 80);
143 setword(&data[0x22], 2);
148 static int INT21_GetFreeDiskSpace( CONTEXT *context )
150 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
151 char root[] = "A:\\";
153 *root += DOS_GET_DRIVE( DL_reg(context) );
154 if (!GetDiskFreeSpace32A( root, &cluster_sectors, §or_bytes,
155 &free_clusters, &total_clusters )) return 0;
156 AX_reg(context) = cluster_sectors;
157 BX_reg(context) = free_clusters;
158 CX_reg(context) = sector_bytes;
159 DX_reg(context) = total_clusters;
163 static int INT21_GetDriveAllocInfo( CONTEXT *context )
165 if (!INT21_GetFreeDiskSpace( context )) return 0;
166 if (!heap && !INT21_CreateHeap()) return 0;
167 heap->mediaID = 0xf0;
168 DS_reg(context) = DosHeapHandle;
169 BX_reg(context) = (int)&heap->mediaID - (int)heap;
173 static void GetDrivePB( CONTEXT *context, int drive )
175 if(!DRIVE_IsValid(drive))
177 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
178 AX_reg(context) = 0x00ff;
180 else if (heap || INT21_CreateHeap())
182 FIXME(int21, "GetDrivePB not fully implemented.\n");
184 /* FIXME: I have no idea what a lot of this information should
185 * say or whether it even really matters since we're not allowing
186 * direct block access. However, some programs seem to depend on
187 * getting at least _something_ back from here. The 'next' pointer
188 * does worry me, though. Should we have a complete table of
189 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
191 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
192 heap->dpb.sector_size = 512;
193 heap->dpb.high_sector = 1;
194 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
195 heap->dpb.reserved = 0;
196 heap->dpb.num_FAT = 1;
197 heap->dpb.dir_entries = 2;
198 heap->dpb.first_data = 2;
199 heap->dpb.high_cluster = 64000;
200 heap->dpb.sectors_in_FAT = 1;
201 heap->dpb.start_dir = 1;
202 heap->dpb.driver_head = 0;
203 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
204 heap->dpb.access_flag = 0;
206 heap->dpb.free_search = 0;
207 heap->dpb.free_clusters = 0xFFFF; /* unknown */
209 AL_reg(context) = 0x00;
210 DS_reg(context) = SELECTOROF(dpbsegptr);
211 BX_reg(context) = OFFSETOF(dpbsegptr);
216 static void ioctlGetDeviceInfo( CONTEXT *context )
221 TRACE(int21, "(%d)\n", BX_reg(context));
223 RESET_CFLAG(context);
226 if ((file = FILE_GetFile( HFILE16_TO_HFILE32(BX_reg(context)), 0, NULL )))
228 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
229 FILE_ReleaseFile( file );
232 DX_reg(context) = dev->flags;
237 /* it seems to be a file */
238 curr_drive = DRIVE_GetCurrentDrive();
239 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
241 /* bits 0-5 are current drive
242 * bit 6 - file has NOT been written..FIXME: correct?
243 * bit 8 - generate int24 if no diskspace on write/ read past end of file
244 * bit 11 - media not removable
245 * bit 14 - don't set file date/time on closing
246 * bit 15 - file is remote
250 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
252 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
253 int drive = DOS_GET_DRIVE( BL_reg(context) );
255 if (!DRIVE_IsValid(drive))
257 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
261 if (CH_reg(context) != 0x08)
263 INT_BARF( context, 0x21 );
267 switch (CL_reg(context))
269 case 0x4a: /* lock logical volume */
270 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
273 case 0x60: /* get device parameters */
274 /* used by w4wgrp's winfile */
275 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
277 dataptr[6] = 0; /* media type */
280 dataptr[1] = 0x05; /* fixed disk */
281 setword(&dataptr[2], 0x01); /* non removable */
282 setword(&dataptr[4], 0x300); /* # of cylinders */
286 dataptr[1] = 0x07; /* block dev, floppy */
287 setword(&dataptr[2], 0x02); /* removable */
288 setword(&dataptr[4], 80); /* # of cylinders */
290 CreateBPB(drive, &dataptr[7], TRUE);
291 RESET_CFLAG(context);
294 case 0x41: /* write logical device track */
295 case 0x61: /* read logical device track */
297 BYTE drive = BL_reg(context) ?
298 BL_reg(context) : DRIVE_GetCurrentDrive();
299 WORD head = *(WORD *)dataptr+1;
300 WORD cyl = *(WORD *)dataptr+3;
301 WORD sect = *(WORD *)dataptr+5;
302 WORD nrsect = *(WORD *)dataptr+7;
303 BYTE *data = (BYTE **)dataptr+9;
304 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL32);
306 raw_func = (CL_reg(context) == 0x41) ?
307 DRIVE_RawWrite : DRIVE_RawRead;
309 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
310 RESET_CFLAG(context);
313 AX_reg(context) = 0x1e; /* read fault */
318 case 0x66:/* get disk serial number */
320 char label[12],fsname[9],path[4];
323 strcpy(path,"x:\\");path[0]=drive+'A';
324 GetVolumeInformation32A(
325 path,label,12,&serial,NULL,NULL,fsname,9
328 memcpy(dataptr+2,&serial,4);
329 memcpy(dataptr+6,label ,11);
330 memcpy(dataptr+17,fsname,8);
335 TRACE(int21,"logical volume %d unlocked.\n",drive);
339 memset(dataptr+1, '\0', dataptr[0]-1);
340 dataptr[1] = dataptr[0];
341 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
342 dataptr[3] = 0xFF; /* no physical drive */
346 INT_BARF( context, 0x21 );
351 static void INT21_ParseFileNameIntoFCB( CONTEXT *context )
354 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
356 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context) );
357 char *buffer, *s, *d;
359 AL_reg(context) = 0xff; /* failed */
361 TRACE(int21, "filename: '%s'\n", filename);
363 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
369 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
376 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
378 TRACE(int21, "FCB: '%s'\n", ((CHAR *)fcb + 1));
380 HeapFree( GetProcessHeap(), 0, buffer);
383 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
385 /* point DS:SI to first unparsed character */
386 SI_reg(context) += (int)s - (int)filename;
389 static void INT21_GetSystemDate( CONTEXT *context )
392 GetLocalTime( &systime );
393 CX_reg(context) = systime.wYear;
394 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
395 AX_reg(context) = systime.wDayOfWeek;
398 static void INT21_GetSystemTime( CONTEXT *context )
401 GetLocalTime( &systime );
402 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
403 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
406 /* Many calls translate a drive argument like this:
407 drive number (00h = default, 01h = A:, etc)
409 static char drivestring[]="default";
411 char *INT21_DriveName(int drive)
416 drivestring[0]= (unsigned char)drive + '@';
422 static BOOL32 INT21_CreateFile( CONTEXT *context )
424 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
425 EDX_reg(context) ), CX_reg(context) );
426 return (AX_reg(context) == (WORD)HFILE_ERROR16);
430 static void OpenExistingFile( CONTEXT *context )
432 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
434 if (AX_reg(context) == (WORD)HFILE_ERROR16)
436 AX_reg(context) = DOS_ExtendedError;
445 switch (AX_reg(context) & 0x0070)
447 case 0x00: /* compatability mode */
448 case 0x40: /* DENYNONE */
452 case 0x30: /* DENYREAD */
453 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
454 (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
455 case 0x10: /* DENYALL */
459 case 0x20: /* DENYWRITE */
470 int result,retries=sharing_retries;
472 #if defined(__svr4__) || defined(_SCO_DS)
473 ERR(int21, "Should call flock and needs porting to lockf\n");
477 result = flock(handle, lock | LOCK_NB);
479 if ( retries && (!result) )
482 for(i=0;i<32768*((int)sharing_pause);i++)
483 result++; /* stop the optimizer */
484 for(i=0;i<32768*((int)sharing_pause);i++)
488 while( (!result) && (!(retries--)) );
493 AX_reg(context) = DOS_ExtendedError;
502 AX_reg(context) = handle;
503 RESET_CFLAG(context);
508 static void CloseFile( CONTEXT *context )
510 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
512 AX_reg(context) = DOS_ExtendedError;
517 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
519 BOOL32 bExtendedError = FALSE;
520 BYTE action = DL_reg(context);
522 /* Shuffle arguments to call OpenExistingFile */
523 AL_reg(context) = BL_reg(context);
524 DX_reg(context) = SI_reg(context);
525 /* BX,CX and DX should be preserved */
526 OpenExistingFile(context);
528 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
530 UINT16 uReturnCX = 0;
532 /* Now decide what do do */
534 if ((action & 0x07) == 0)
536 BX_reg(context) = AX_reg(context);
538 AX_reg(context) = 0x0050; /*File exists*/
540 WARN(int21, "extended open/create: failed because file exists \n");
542 else if ((action & 0x07) == 2)
544 /* Truncate it, but first check if opened for write */
545 if ((BL_reg(context) & 0x0007)== 0)
547 BX_reg(context) = AX_reg(context);
549 WARN(int21, "extended open/create: failed, trunc on ro file\n");
550 AX_reg(context) = 0x000C; /*Access code invalid*/
555 /* Shuffle arguments to call CloseFile while
556 * preserving BX and DX */
558 TRACE(int21, "extended open/create: Closing before truncate\n");
559 BX_reg(context) = AX_reg(context);
561 if (EFL_reg(context) & 0x0001)
563 WARN(int21, "extended open/create: close before trunc failed\n");
564 AX_reg(context) = 0x0019; /*Seek Error*/
568 /* Shuffle arguments to call CreateFile */
570 TRACE(int21, "extended open/create: Truncating\n");
571 AL_reg(context) = BL_reg(context);
572 /* CX is still the same */
573 DX_reg(context) = SI_reg(context);
574 bExtendedError = INT21_CreateFile(context);
576 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
578 WARN(int21, "extended open/create: trunc failed\n");
579 return bExtendedError;
584 else uReturnCX = 0x1;
586 CX_reg(context) = uReturnCX;
588 else /* file does not exist */
590 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
591 if ((action & 0xF0)== 0)
595 WARN(int21, "extended open/create: failed, file dosen't exist\n");
599 /* Shuffle arguments to call CreateFile */
600 TRACE(int21, "extended open/create: Creating\n");
601 AL_reg(context) = BL_reg(context);
602 /* CX should still be the same */
603 DX_reg(context) = SI_reg(context);
604 bExtendedError = INT21_CreateFile(context);
605 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
607 WARN(int21, "extended open/create: create failed\n");
608 return bExtendedError;
614 return bExtendedError;
618 static BOOL32 INT21_ChangeDir( CONTEXT *context )
621 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
623 TRACE(int21,"changedir %s\n", dirname);
624 if (dirname[0] && (dirname[1] == ':'))
626 drive = toupper(dirname[0]) - 'A';
629 else drive = DRIVE_GetCurrentDrive();
630 return DRIVE_Chdir( drive, dirname );
634 static int INT21_FindFirst( CONTEXT *context )
638 DOS_FULL_NAME full_name;
639 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
641 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
642 dta->unixPath = NULL;
643 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
645 AX_reg(context) = DOS_ExtendedError;
649 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
650 p = strrchr( dta->unixPath, '/' );
653 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
654 * (doesn't matter as it is set below anyway)
656 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
658 HeapFree( GetProcessHeap(), 0, dta->unixPath );
659 dta->unixPath = NULL;
660 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
661 AX_reg(context) = ER_FileNotFound;
665 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
666 : DRIVE_GetCurrentDrive();
668 dta->search_attr = CL_reg(context);
673 static int INT21_FindNext( CONTEXT *context )
675 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
676 WIN32_FIND_DATA32A entry;
679 if (!dta->unixPath) return 0;
680 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
681 dta->search_attr, dta->count, &entry )))
683 HeapFree( GetProcessHeap(), 0, dta->unixPath );
684 dta->unixPath = NULL;
687 if ((int)dta->count + count > 0xffff)
689 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
690 HeapFree( GetProcessHeap(), 0, dta->unixPath );
691 dta->unixPath = NULL;
695 dta->fileattr = entry.dwFileAttributes;
696 dta->filesize = entry.nFileSizeLow;
697 FileTimeToDosDateTime( &entry.ftLastWriteTime,
698 &dta->filedate, &dta->filetime );
699 strcpy( dta->filename, entry.cAlternateFileName );
700 if (!memchr(dta->mask,'?',11)) {
701 /* wildcardless search, release resources in case no findnext will
702 * be issued, and as a workaround in case file creation messes up
703 * findnext, as sometimes happens with pkunzip */
704 HeapFree( GetProcessHeap(), 0, dta->unixPath );
705 dta->unixPath = NULL;
711 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
713 static int counter = 0;
714 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
715 char *p = name + strlen(name);
717 /* despite what Ralf Brown says, some programs seem to call without
718 * ending backslash (DOS accepts that, so we accept it too) */
719 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
723 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
724 counter = (counter + 1) % 1000;
726 if ((AX_reg(context) = HFILE32_TO_HFILE16(_lcreat_uniq( name, 0 ))) != (WORD)HFILE_ERROR16)
728 TRACE(int21, "created %s\n", name );
731 if (DOS_ExtendedError != ER_FileExists) return FALSE;
736 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
738 int drive = DOS_GET_DRIVE( DL_reg(context) );
739 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
741 if (!DRIVE_IsValid(drive))
743 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
746 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
747 AX_reg(context) = 0x0100; /* success return code */
752 static void INT21_GetDBCSLeadTable( CONTEXT *context )
754 if (heap || INT21_CreateHeap())
755 { /* return an empty table just as DOS 4.0+ does */
756 DS_reg(context) = DosHeapHandle;
757 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
761 AX_reg(context) = 0x1; /* error */
767 static int INT21_GetDiskSerialNumber( CONTEXT *context )
769 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
770 int drive = DOS_GET_DRIVE( BL_reg(context) );
772 if (!DRIVE_IsValid(drive))
774 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
778 *(WORD *)dataptr = 0;
779 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
780 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
781 strncpy(dataptr + 0x11, "FAT16 ", 8);
786 static int INT21_SetDiskSerialNumber( CONTEXT *context )
788 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
789 int drive = DOS_GET_DRIVE( BL_reg(context) );
791 if (!DRIVE_IsValid(drive))
793 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
797 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
802 /* microsoft's programmers should be shot for using CP/M style int21
803 calls in Windows for Workgroup's winfile.exe */
805 static int INT21_FindFirstFCB( CONTEXT *context )
807 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
812 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
813 else pFCB = (FINDFILE_FCB *)fcb;
814 drive = DOS_GET_DRIVE( pFCB->drive );
815 if (!DRIVE_IsValid( drive )) return 0;
816 root = DRIVE_GetRoot( drive );
817 cwd = DRIVE_GetUnixCwd( drive );
818 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
819 strlen(root)+strlen(cwd)+2 );
820 if (!pFCB->unixPath) return 0;
821 strcpy( pFCB->unixPath, root );
822 strcat( pFCB->unixPath, "/" );
823 strcat( pFCB->unixPath, cwd );
829 static int INT21_FindNextFCB( CONTEXT *context )
831 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
833 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
834 WIN32_FIND_DATA32A entry;
838 if (*fcb == 0xff) /* extended FCB ? */
841 pFCB = (FINDFILE_FCB *)(fcb + 7);
846 pFCB = (FINDFILE_FCB *)fcb;
849 if (!pFCB->unixPath) return 0;
850 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
851 DOS_GET_DRIVE( pFCB->drive ), attr,
852 pFCB->count, &entry )))
854 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
855 pFCB->unixPath = NULL;
858 pFCB->count += count;
860 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
861 *(BYTE *)pResult = 0xff;
862 (BYTE *)pResult +=6; /* leave reserved field behind */
863 *(BYTE *)pResult = entry.dwFileAttributes;
866 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
868 pResult->fileattr = entry.dwFileAttributes;
869 pResult->cluster = 0; /* what else? */
870 pResult->filesize = entry.nFileSizeLow;
871 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
872 FileTimeToDosDateTime( &entry.ftLastWriteTime,
873 &pResult->filedate, &pResult->filetime );
875 /* Convert file name to FCB format */
877 memset( pResult->filename, ' ', sizeof(pResult->filename) );
878 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
879 else if (!strcmp( entry.cAlternateFileName, ".." ))
880 pResult->filename[0] = pResult->filename[1] = '.';
883 char *p = strrchr( entry.cAlternateFileName, '.' );
884 if (p && p[1] && (p != entry.cAlternateFileName))
886 memcpy( pResult->filename, entry.cAlternateFileName,
887 MIN( (p - entry.cAlternateFileName), 8 ) );
888 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
891 memcpy( pResult->filename, entry.cAlternateFileName,
892 MIN( strlen(entry.cAlternateFileName), 8 ) );
898 static void DeleteFileFCB( CONTEXT *context )
900 FIXME(int21, "(%p): stub\n", context);
903 static void RenameFileFCB( CONTEXT *context )
905 FIXME(int21, "(%p): stub\n", context);
910 static void fLock( CONTEXT * context )
913 switch ( AX_reg(context) & 0xff )
915 case 0x00: /* LOCK */
916 TRACE(int21,"lock handle %d offset %ld length %ld\n",
918 MAKELONG(DX_reg(context),CX_reg(context)),
919 MAKELONG(DI_reg(context),SI_reg(context))) ;
920 if (!LockFile(HFILE16_TO_HFILE32(BX_reg(context)),
921 MAKELONG(DX_reg(context),CX_reg(context)), 0,
922 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
923 AX_reg(context) = DOS_ExtendedError;
928 case 0x01: /* UNLOCK */
929 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
931 MAKELONG(DX_reg(context),CX_reg(context)),
932 MAKELONG(DI_reg(context),SI_reg(context))) ;
933 if (!UnlockFile(HFILE16_TO_HFILE32(BX_reg(context)),
934 MAKELONG(DX_reg(context),CX_reg(context)), 0,
935 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
936 AX_reg(context) = DOS_ExtendedError;
941 AX_reg(context) = 0x0001;
948 INT21_networkfunc (CONTEXT *context)
950 switch (AL_reg(context)) {
951 case 0x00: /* Get machine name. */
953 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
954 TRACE(int21, "getting machine name to %p\n", dst);
955 if (gethostname (dst, 15))
957 WARN(int21,"failed!\n");
958 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
961 int len = strlen (dst);
965 CH_reg(context) = 1; /* Valid */
966 CL_reg(context) = 1; /* NETbios number??? */
967 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
973 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
978 static void INT21_SetCurrentPSP(WORD psp)
981 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
982 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
984 GlobalUnlock16( GetCurrentTask() );
985 if (pModule->lpDosTask)
986 pModule->lpDosTask->psp_seg = psp;
989 ERR(int21, "Cannot change PSP for non-DOS task!\n");
992 static WORD INT21_GetCurrentPSP()
995 TDB *pTask = hModule ? NULL : (TDB *)GlobalLock16( GetCurrentTask() );
996 NE_MODULE *pModule = (hModule || pTask) ? NE_GetPtr( hModule ? hModule : pTask->hModule ) : NULL;
998 GlobalUnlock16( GetCurrentTask() );
999 if (pModule->lpDosTask)
1000 return pModule->lpDosTask->psp_seg;
1003 return GetCurrentPDB();
1007 SEGPTR INT21_GetListOfLists()
1009 static DOS_LISTOFLISTS *LOL;
1010 static SEGPTR seg_LOL;
1015 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
1016 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
1017 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
1018 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
1019 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
1020 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
1021 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
1022 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
1023 0133:00A0 D0 44 C8 FD D0 44 .D...D
1026 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
1028 LOL->CX_Int21_5e01 = 0x0;
1029 LOL->LRU_count_FCB_cache = 0x0;
1030 LOL->LRU_count_FCB_open = 0x0;
1031 LOL->OEM_func_handler = -1; /* not available */
1032 LOL->INT21_offset = 0x0;
1033 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
1034 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
1035 LOL->ptr_disk_buf = 0x0;
1036 LOL->offs_unread_CON = 0x0;
1037 LOL->seg_first_MCB = 0x0;
1038 LOL->ptr_first_DPB = 0x0;
1039 LOL->ptr_first_SysFileTable = 0x0;
1040 LOL->ptr_clock_dev_hdr = 0x0;
1041 LOL->ptr_CON_dev_hdr = 0x0;
1042 LOL->max_byte_per_sec = 512;
1043 LOL->ptr_disk_buf_info = 0x0;
1044 LOL->ptr_array_CDS = 0x0;
1045 LOL->ptr_sys_FCB = 0x0;
1046 LOL->nr_protect_FCB = 0x0;
1047 LOL->nr_block_dev = 0x0;
1048 LOL->nr_avail_drive_letters = 26; /* A - Z */
1049 LOL->nr_drives_JOINed = 0x0;
1050 LOL->ptr_spec_prg_names = 0x0;
1051 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
1052 LOL->DOS_HIGH_A20_func_offs = 0x0;
1053 LOL->PSP_last_exec = 0x0;
1054 LOL->BUFFERS_val = 99; /* maximum: 99 */
1055 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
1056 LOL->boot_drive = 3; /* C: */
1057 LOL->flag_DWORD_moves = 0x01; /* i386+ */
1058 LOL->size_extended_mem = 0xf000; /* very high value */
1060 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
1061 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
1064 /***********************************************************************
1065 * DOS3Call (KERNEL.102)
1067 void WINAPI DOS3Call( CONTEXT *context )
1069 BOOL32 bSetDOSExtendedError = FALSE;
1072 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
1073 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1074 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1075 SI_reg(context), DI_reg(context),
1076 (WORD)DS_reg(context), (WORD)ES_reg(context),
1080 if (AH_reg(context) == 0x59) /* Get extended error info */
1082 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1083 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1084 AX_reg(context) = DOS_ExtendedError;
1085 BH_reg(context) = DOS_ErrorClass;
1086 BL_reg(context) = DOS_ErrorAction;
1087 CH_reg(context) = DOS_ErrorLocus;
1091 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1093 TRACE(int21, "FLUSH BUFFER AND READ STANDARD INPUT\n");
1094 /* no flush here yet */
1095 AH_reg(context) = AL_reg(context);
1098 DOS_ERROR( 0, 0, 0, 0 );
1099 RESET_CFLAG(context); /* Not sure if this is a good idea */
1101 switch(AH_reg(context))
1103 case 0x00: /* TERMINATE PROGRAM */
1104 TRACE(int21,"TERMINATE PROGRAM\n");
1108 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1109 _lread16(1, (BYTE *)&context->Eax, 1);
1112 case 0x03: /* READ CHARACTER FROM STDAUX */
1113 case 0x04: /* WRITE CHARACTER TO STDAUX */
1114 case 0x05: /* WRITE CHARACTER TO PRINTER */
1115 case 0x0b: /* GET STDIN STATUS */
1116 case 0x0f: /* OPEN FILE USING FCB */
1117 case 0x10: /* CLOSE FILE USING FCB */
1118 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1119 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1120 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1121 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1122 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1123 case 0x23: /* GET FILE SIZE FOR FCB */
1124 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1125 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1126 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1127 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1128 case 0x54: /* GET VERIFY FLAG */
1129 INT_BARF( context, 0x21 );
1132 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1133 TRACE(int21, "Write Character to Standard Output\n");
1134 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1137 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1138 TRACE(int21, "Direct Console Input/Output\n");
1139 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1142 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1143 TRACE(int21,"DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1144 AL_reg(context) = CONSOLE_GetCharacter();
1147 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1148 TRACE(int21,"CHARACTER INPUT WITHOUT ECHO\n");
1149 AL_reg(context) = CONSOLE_GetCharacter();
1152 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1153 TRACE(int21,"WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1154 DS_reg(context),DX_reg(context) );
1156 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1157 LONG length = strchr(data,'$')-data;
1158 _hwrite16( 1, data, length);
1159 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1163 case 0x0a: /* BUFFERED INPUT */
1165 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1166 EDX_reg(context) ));
1169 TRACE(int21,"BUFFERED INPUT (size=%d)\n",buffer[0]);
1171 TRACE(int21,"Handle old chars in buffer!\n");
1172 res=_lread16( 0, buffer+2,buffer[0]);
1174 if(buffer[res+1] == '\n')
1175 buffer[res+1] = '\r';
1179 case 0x2e: /* SET VERIFY FLAG */
1180 TRACE(int21,"SET VERIFY FLAG ignored\n");
1181 /* we cannot change the behaviour anyway, so just ignore it */
1184 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1188 case 0x6b: /* NULL FUNCTION */
1189 AL_reg(context) = 0;
1192 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1196 case 0x0d: /* DISK BUFFER FLUSH */
1197 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1198 RESET_CFLAG(context); /* dos 6+ only */
1201 case 0x0e: /* SELECT DEFAULT DRIVE */
1202 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1203 DRIVE_SetCurrentDrive( DL_reg(context) );
1204 AL_reg(context) = MAX_DOS_DRIVES;
1207 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1208 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1209 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1210 if (!INT21_FindFirstFCB(context))
1212 AL_reg(context) = 0xff;
1215 /* else fall through */
1217 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1218 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1221 case 0x13: /* DELETE FILE USING FCB */
1222 DeleteFileFCB(context);
1225 case 0x17: /* RENAME FILE USING FCB */
1226 RenameFileFCB(context);
1229 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1230 AL_reg(context) = DRIVE_GetCurrentDrive();
1233 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1235 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1236 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1237 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1241 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1242 DL_reg(context) = 0;
1243 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1246 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1247 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1250 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1251 GetDrivePB(context, DRIVE_GetCurrentDrive());
1254 case 0x25: /* SET INTERRUPT VECTOR */
1255 INT_CtxSetHandler( context, AL_reg(context),
1256 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1260 case 0x29: /* PARSE FILENAME INTO FCB */
1261 INT21_ParseFileNameIntoFCB(context);
1264 case 0x2a: /* GET SYSTEM DATE */
1265 INT21_GetSystemDate(context);
1268 case 0x2b: /* SET SYSTEM DATE */
1269 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1270 DL_reg(context), DH_reg(context), CX_reg(context) );
1271 AL_reg(context) = 0; /* Let's pretend we succeeded */
1274 case 0x2c: /* GET SYSTEM TIME */
1275 INT21_GetSystemTime(context);
1278 case 0x2d: /* SET SYSTEM TIME */
1279 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1280 CH_reg(context), CL_reg(context),
1281 DH_reg(context), DL_reg(context) );
1282 AL_reg(context) = 0; /* Let's pretend we succeeded */
1285 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1286 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1288 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1289 ES_reg(context) = SELECTOROF( pTask->dta );
1290 BX_reg(context) = OFFSETOF( pTask->dta );
1294 case 0x30: /* GET DOS VERSION */
1295 TRACE(int21,"GET DOS VERSION %s requested\n",
1296 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1297 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1298 (HIWORD(GetVersion16()) << 8);
1300 AH_reg(context) = 0x7;
1301 AL_reg(context) = 0xA;
1304 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1305 CX_reg(context) = 0x0000;
1308 case 0x31: /* TERMINATE AND STAY RESIDENT */
1309 FIXME(int21,"TERMINATE AND STAY RESIDENT stub\n");
1312 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1313 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1314 INT21_DriveName( DL_reg(context)));
1315 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1318 case 0x33: /* MULTIPLEXED */
1319 switch (AL_reg(context))
1321 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1322 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1323 DL_reg(context) = 0;
1326 case 0x01: /* SET EXTENDED BREAK STATE */
1327 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1330 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1331 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1332 DL_reg(context) = 0;
1335 case 0x05: /* GET BOOT DRIVE */
1336 TRACE(int21,"GET BOOT DRIVE\n");
1337 DL_reg(context) = 3;
1338 /* c: is Wine's bootdrive (a: is 1)*/
1341 case 0x06: /* GET TRUE VERSION NUMBER */
1342 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1343 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1344 (HIWORD(GetVersion16() << 8));
1345 DX_reg(context) = 0x00;
1349 INT_BARF( context, 0x21 );
1354 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1355 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1356 if (!heap) INT21_CreateHeap();
1357 ES_reg(context) = DosHeapHandle;
1358 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1361 case 0x35: /* GET INTERRUPT VECTOR */
1362 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1364 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1365 ES_reg(context) = SELECTOROF(addr);
1366 BX_reg(context) = OFFSETOF(addr);
1370 case 0x36: /* GET FREE DISK SPACE */
1371 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1372 INT21_DriveName( DL_reg(context)));
1373 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1378 unsigned char switchchar='/';
1379 switch (AL_reg(context))
1381 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1382 TRACE(int21,"SWITCHAR - GET SWITCH CHARACTER\n");
1383 AL_reg(context) = 0x00; /* success*/
1384 DL_reg(context) = switchchar;
1386 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1387 TRACE(int21,"SWITCHAR - SET SWITCH CHARACTER\n");
1388 switchchar = DL_reg(context);
1389 AL_reg(context) = 0x00; /* success*/
1391 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1392 INT_BARF( context, 0x21 );
1398 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1399 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1401 AX_reg(context) = 0x02; /* no country support available */
1405 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1406 TRACE(int21,"MKDIR %s\n",
1407 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1408 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1409 EDX_reg(context) ), NULL));
1412 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1413 TRACE(int21,"RMDIR %s\n",
1414 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1415 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1416 EDX_reg(context) )));
1419 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1420 TRACE(int21,"CHDIR %s\n",
1421 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1422 bSetDOSExtendedError = !INT21_ChangeDir(context);
1425 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1426 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1427 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1428 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1429 EDX_reg(context) ), CX_reg(context) );
1430 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1433 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1434 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1435 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1436 OpenExistingFile(context);
1439 case 0x3e: /* "CLOSE" - CLOSE FILE */
1440 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1441 if ((BX_reg(context)<5)||
1442 /* FIXME: need to improve on those handle conversion macros */
1443 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_INPUT_HANDLE)))||
1444 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_OUTPUT_HANDLE)))||
1445 (BX_reg(context)==HFILE32_TO_HFILE16(GetStdHandle(STD_ERROR_HANDLE)))) {
1446 /* hack to make sure stdio isn't closed */
1447 FIXME(int21, "stdio handle closed, need proper conversion\n");
1448 DOS_ExtendedError = 0x06;
1449 bSetDOSExtendedError = TRUE;
1451 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1454 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1455 TRACE(int21,"READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1456 DS_reg(context),DX_reg(context),CX_reg(context) );
1460 result = _hread16( BX_reg(context),
1461 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1465 result = WIN16_hread( BX_reg(context),
1466 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1469 if (result == -1) bSetDOSExtendedError = TRUE;
1470 else AX_reg(context) = (WORD)result;
1474 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1475 TRACE(int21,"WRITE from %04lX:%04X to handle %d for %d byte\n",
1476 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1478 LONG result = _hwrite16( BX_reg(context),
1479 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1482 if (result == -1) bSetDOSExtendedError = TRUE;
1483 else AX_reg(context) = (WORD)result;
1487 case 0x41: /* "UNLINK" - DELETE FILE */
1488 TRACE(int21,"UNLINK%s\n",
1489 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1490 bSetDOSExtendedError = (!DeleteFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1491 EDX_reg(context) )));
1494 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1495 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1496 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1497 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1498 "current file position":"end of file");
1500 LONG status = _llseek16( BX_reg(context),
1501 MAKELONG(DX_reg(context),CX_reg(context)),
1503 if (status == -1) bSetDOSExtendedError = TRUE;
1506 AX_reg(context) = LOWORD(status);
1507 DX_reg(context) = HIWORD(status);
1512 case 0x43: /* FILE ATTRIBUTES */
1513 switch (AL_reg(context))
1516 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1517 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1518 AX_reg(context) = (WORD)GetFileAttributes32A(
1519 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1521 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1522 else CX_reg(context) = AX_reg(context);
1526 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1527 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1528 bSetDOSExtendedError =
1529 (!SetFileAttributes32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1534 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1535 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1539 case 0x44: /* IOCTL */
1540 switch (AL_reg(context))
1543 ioctlGetDeviceInfo(context);
1550 file = FILE_GetFile(HFILE16_TO_HFILE32(BX_reg(context)),0,NULL);
1551 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1552 ASPI_DOS_HandleInt(context);
1553 FILE_ReleaseFile( file );
1556 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1557 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1558 int drive = DOS_GET_DRIVE(BL_reg(context));
1560 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1561 /* for (i=0;i<CX_reg(context);i++)
1562 fprintf(stdnimp,"%02x ",dataptr[i]);
1563 fprintf(stdnimp,"\n");*/
1564 AX_reg(context)=CX_reg(context);
1567 case 0x08: /* Check if drive is removable. */
1568 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1569 INT21_DriveName( BL_reg(context)));
1570 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1572 case DRIVE_CANNOTDETERMINE:
1573 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1574 AX_reg(context) = ER_InvalidDrive;
1577 case DRIVE_REMOVABLE:
1578 AX_reg(context) = 0; /* removable */
1581 AX_reg(context) = 1; /* not removable */
1586 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1587 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1588 INT21_DriveName( BL_reg(context)));
1589 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1591 case DRIVE_CANNOTDETERMINE:
1592 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1593 AX_reg(context) = ER_InvalidDrive;
1597 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1600 DX_reg(context) = 0; /* FIXME: use driver attr here */
1605 case 0x0a: /* check if handle (BX) is remote */
1606 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1607 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1610 DX_reg(context) = 0;
1613 case 0x0b: /* SET SHARING RETRY COUNT */
1614 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1615 CX_reg(context), DX_reg(context));
1616 if (!CX_reg(context))
1618 AX_reg(context) = 1;
1622 sharing_pause = CX_reg(context);
1623 if (!DX_reg(context))
1624 sharing_retries = DX_reg(context);
1625 RESET_CFLAG(context);
1629 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1630 INT21_DriveName( BL_reg(context)));
1631 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1634 case 0x0e: /* get logical drive mapping */
1635 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1636 INT21_DriveName( BL_reg(context)));
1637 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1640 case 0x0F: /* Set logical drive mapping */
1643 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1644 INT21_DriveName( BL_reg(context)));
1645 drive = DOS_GET_DRIVE ( BL_reg(context) );
1646 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1649 AX_reg(context) = 0x000F; /* invalid drive */
1654 case 0xe0: /* Sun PC-NFS API */
1659 INT_BARF( context, 0x21 );
1664 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1667 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1668 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1669 HFILE16_TO_HFILE32(BX_reg(context)),
1670 GetCurrentProcess(), &handle,
1671 0, TRUE, DUPLICATE_SAME_ACCESS )))
1672 AX_reg(context) = HFILE_ERROR16;
1674 AX_reg(context) = HFILE32_TO_HFILE16(handle);
1678 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1679 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1680 BX_reg(context),CX_reg(context));
1681 bSetDOSExtendedError = (FILE_Dup2( HFILE16_TO_HFILE32(BX_reg(context)), HFILE16_TO_HFILE32(CX_reg(context)) ) == HFILE_ERROR32);
1684 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1685 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1686 INT21_DriveName( DL_reg(context)));
1687 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1690 case 0x48: /* ALLOCATE MEMORY */
1691 TRACE(int21,"ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1696 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1698 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1702 mem = (LPVOID)GlobalDOSAlloc(BX_reg(context)<<4);
1704 AX_reg(context) = (DWORD)mem&0xffff;
1709 AX_reg(context) = 0x0008; /* insufficient memory */
1710 BX_reg(context) = DOSMEM_Available(0)>>4;
1715 case 0x49: /* FREE MEMORY */
1716 TRACE(int21,"FREE MEMORY segment %04lX\n", ES_reg(context));
1720 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1723 ret = !GlobalDOSFree(ES_reg(context));
1724 /* If we don't reset ES_reg, we will fail in the relay code */
1725 ES_reg(context)=ret;
1729 TRACE(int21,"FREE MEMORY failed\n");
1731 AX_reg(context) = 0x0009; /* memory block address invalid */
1736 case 0x4a: /* RESIZE MEMORY BLOCK */
1737 TRACE(int21,"RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1738 if (!ISV86(context))
1739 FIXME(int21,"RESIZE MEMORY probably insufficent implementation. Expect crash soon\n");
1741 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1742 BX_reg(context)<<4,NULL);
1744 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1747 AX_reg(context) = 0x0008; /* insufficient memory */
1748 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1753 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1754 TRACE(int21,"EXEC %s\n",
1755 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1756 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1759 if (AX_reg(context) < 32) SET_CFLAG(context);
1762 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1763 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1764 ExitProcess( AL_reg(context) );
1767 case 0x4d: /* GET RETURN CODE */
1768 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1769 AX_reg(context) = 0; /* normal exit */
1772 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1773 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1774 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1775 if (!INT21_FindFirst(context)) break;
1778 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1779 TRACE(int21,"FINDNEXT\n");
1780 if (!INT21_FindNext(context))
1782 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1783 AX_reg(context) = ER_NoMoreFiles;
1786 else AX_reg(context) = 0; /* OK */
1788 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1789 TRACE(int21, "SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1790 INT21_SetCurrentPSP(BX_reg(context));
1792 case 0x51: /* GET PSP ADDRESS */
1793 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1794 /* FIXME: should we return the original DOS PSP upon */
1795 /* Windows startup ? */
1796 BX_reg(context) = INT21_GetCurrentPSP();
1798 case 0x62: /* GET PSP ADDRESS */
1799 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1800 /* FIXME: should we return the original DOS PSP upon */
1801 /* Windows startup ? */
1802 BX_reg(context) = INT21_GetCurrentPSP();
1805 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1806 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1809 lol = INT21_GetListOfLists();
1810 ES_reg(context) = HIWORD(lol);
1811 BX_reg(context) = LOWORD(lol);
1815 case 0x56: /* "RENAME" - RENAME FILE */
1816 TRACE(int21,"RENAME %s to %s\n",
1817 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1818 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1819 bSetDOSExtendedError =
1820 (!MoveFile32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1821 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1824 case 0x57: /* FILE DATE AND TIME */
1825 switch (AL_reg(context))
1827 case 0x00: /* Get */
1830 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1832 if (!GetFileTime( HFILE16_TO_HFILE32(BX_reg(context)), NULL, NULL, &filetime ))
1833 bSetDOSExtendedError = TRUE;
1834 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1839 case 0x01: /* Set */
1842 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1844 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1846 bSetDOSExtendedError =
1847 (!SetFileTime( HFILE16_TO_HFILE32(BX_reg(context)),
1848 NULL, NULL, &filetime ));
1854 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1855 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1857 switch (AL_reg(context))
1860 AX_reg(context) = 1;
1863 AX_reg(context) = 0;
1869 RESET_CFLAG(context);
1872 case 0x5a: /* CREATE TEMPORARY FILE */
1873 TRACE(int21,"CREATE TEMPORARY FILE\n");
1874 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1877 case 0x5b: /* CREATE NEW FILE */
1878 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1879 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1880 bSetDOSExtendedError = ((AX_reg(context) =
1881 HFILE32_TO_HFILE16(_lcreat_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)), 0 )))
1882 == (WORD)HFILE_ERROR16);
1885 case 0x5d: /* NETWORK */
1886 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1887 /* Fix the following while you're at it. */
1888 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1889 bSetDOSExtendedError = TRUE;
1893 bSetDOSExtendedError = INT21_networkfunc (context);
1896 case 0x5f: /* NETWORK */
1897 switch (AL_reg(context))
1899 case 0x07: /* ENABLE DRIVE */
1900 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1901 if (!DRIVE_Enable( DL_reg(context) ))
1903 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1904 bSetDOSExtendedError = TRUE;
1908 case 0x08: /* DISABLE DRIVE */
1909 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1910 if (!DRIVE_Disable( DL_reg(context) ))
1912 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1913 bSetDOSExtendedError = TRUE;
1918 /* network software not installed */
1919 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1920 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1921 bSetDOSExtendedError = TRUE;
1926 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1927 TRACE(int21,"TRUENAME %s\n",
1928 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
1930 if (!GetFullPathName32A( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1931 ESI_reg(context)), 128,
1932 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1933 EDI_reg(context)),NULL))
1934 bSetDOSExtendedError = TRUE;
1935 else AX_reg(context) = 0;
1939 case 0x61: /* UNUSED */
1940 case 0x63: /* misc. language support */
1941 switch (AL_reg(context)) {
1942 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1943 INT21_GetDBCSLeadTable(context);
1947 case 0x64: /* OS/2 DOS BOX */
1948 INT_BARF( context, 0x21 );
1952 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1953 extern WORD WINE_LanguageId;
1954 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
1955 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1956 BX_reg(context), DX_reg(context));
1957 switch (AL_reg(context)) {
1959 TRACE(int21,"\tget general internationalization info\n");
1961 *(WORD*)(dataptr+1) = 41;
1962 *(WORD*)(dataptr+3) = WINE_LanguageId;
1963 *(WORD*)(dataptr+5) = CodePage;
1964 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1967 TRACE(int21,"\tget pointer to collating sequence table\n");
1969 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1970 CX_reg(context) = 258;/*FIXME: size of table?*/
1973 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1974 INT_BARF( context, 0x21 );
1980 case 0x66: /* GLOBAL CODE PAGE TABLE */
1981 switch (AL_reg(context))
1984 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1985 DX_reg(context) = BX_reg(context) = CodePage;
1986 RESET_CFLAG(context);
1989 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1990 BX_reg(context),DX_reg(context));
1991 CodePage = BX_reg(context);
1992 RESET_CFLAG(context);
1997 case 0x67: /* SET HANDLE COUNT */
1998 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1999 SetHandleCount16( BX_reg(context) );
2000 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
2003 case 0x68: /* "FFLUSH" - COMMIT FILE */
2004 case 0x6a: /* COMMIT FILE */
2005 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
2006 bSetDOSExtendedError = (!FlushFileBuffers( HFILE16_TO_HFILE32(BX_reg(context)) ));
2009 case 0x69: /* DISK SERIAL NUMBER */
2010 switch (AL_reg(context))
2013 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
2014 INT21_DriveName(BL_reg(context)));
2015 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2016 else AX_reg(context) = 0;
2020 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
2021 INT21_DriveName(BL_reg(context)));
2022 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2023 else AX_reg(context) = 1;
2028 case 0x6C: /* Extended Open/Create*/
2029 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
2030 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
2031 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2034 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2035 if ((GetVersion32()&0xC0000004)!=0xC0000004) {
2036 /* not supported on anything but Win95 */
2037 TRACE(int21,"LONG FILENAME functions supported only by win95\n");
2039 AL_reg(context) = 0;
2041 switch(AL_reg(context))
2043 case 0x39: /* Create directory */
2044 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
2045 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2046 bSetDOSExtendedError = (!CreateDirectory32A(
2047 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2048 EDX_reg(context) ), NULL));
2050 case 0x3a: /* Remove directory */
2051 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
2052 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2053 bSetDOSExtendedError = (!RemoveDirectory32A(
2054 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2055 EDX_reg(context) )));
2057 case 0x43: /* Get/Set file attributes */
2058 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2059 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2060 switch (BL_reg(context))
2062 case 0x00: /* Get file attributes */
2063 TRACE(int21,"\tretrieve attributes\n");
2064 CX_reg(context) = (WORD)GetFileAttributes32A(
2065 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2067 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2070 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
2071 bSetDOSExtendedError = (!SetFileAttributes32A(
2072 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2074 CX_reg(context) ) );
2077 FIXME(int21, "Unimplemented long file name function:\n");
2078 INT_BARF( context, 0x21 );
2080 AL_reg(context) = 0;
2084 case 0x47: /* Get current directory */
2085 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2086 INT21_DriveName(DL_reg(context)));
2087 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2090 case 0x4e: /* Find first file */
2091 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2092 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2093 /* FIXME: use attributes in CX */
2094 if ((AX_reg(context) = FindFirstFile16(
2095 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2096 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2098 == INVALID_HANDLE_VALUE16)
2099 bSetDOSExtendedError = TRUE;
2101 case 0x4f: /* Find next file */
2102 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2104 if (!FindNextFile16( BX_reg(context),
2105 (WIN32_FIND_DATA32A *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2107 bSetDOSExtendedError = TRUE;
2109 case 0xa1: /* Find close */
2110 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
2112 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2115 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2116 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2119 switch(CL_reg(context))
2121 case 0x01: /*Get short filename or path */
2122 if (!GetShortPathName32A
2123 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2125 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2126 EDI_reg(context)), 67))
2127 bSetDOSExtendedError = TRUE;
2128 else AX_reg(context) = 0;
2130 case 0x02: /*Get canonical long filename or path */
2131 if (!GetFullPathName32A
2132 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2133 ESI_reg(context)), 128,
2134 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2135 EDI_reg(context)),NULL))
2136 bSetDOSExtendedError = TRUE;
2137 else AX_reg(context) = 0;
2140 FIXME(int21, "Unimplemented long file name function:\n");
2141 INT_BARF( context, 0x21 );
2143 AL_reg(context) = 0;
2147 case 0x6c: /* Create or open file */
2148 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
2149 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2150 /* translate Dos 7 action to Dos 6 action */
2151 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2154 case 0x3b: /* Change directory */
2155 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
2156 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2157 if (!SetCurrentDirectory32A(CTX_SEG_OFF_TO_LIN(context,
2163 AL_reg(context) = DOS_ExtendedError;
2166 case 0x41: /* Delete file */
2167 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
2168 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2169 if (!DeleteFile32A(CTX_SEG_OFF_TO_LIN(context,
2174 AL_reg(context) = DOS_ExtendedError;
2177 case 0x56: /* Move (rename) file */
2178 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
2179 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2180 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2182 FIXME(int21, "Unimplemented long file name function:\n");
2183 INT_BARF( context, 0x21 );
2185 AL_reg(context) = 0;
2190 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2191 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2192 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2193 TRACE(int21,"windows95 function AX %04x\n",
2195 WARN(int21, " returning unimplemented\n");
2197 AL_reg(context) = 0;
2200 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2201 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2205 INT_BARF( context, 0x21 );
2208 } /* END OF SWITCH */
2210 if( bSetDOSExtendedError ) /* set general error condition */
2212 AX_reg(context) = DOS_ExtendedError;
2216 if ((EFL_reg(context) & 0x0001))
2217 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
2218 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
2220 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2221 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2222 AX_reg(context), BX_reg(context), CX_reg(context),
2223 DX_reg(context), SI_reg(context), DI_reg(context),
2224 (WORD)DS_reg(context), (WORD)ES_reg(context),
2228 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
2230 FIXME(int21, "(DosProc=0x%08x): stub\n", (UINT32)DosProc);