2 * DOS interrupt 21h handler
10 # include <sys/file.h>
15 #include <sys/types.h>
21 #include "winuser.h" /* SW_NORMAL */
22 #include "wine/winbase16.h"
32 #include "dosexe.h" /* for the MZ_SUPPORTED define */
34 #include "debugtools.h"
37 DEFAULT_DEBUG_CHANNEL(int21)
38 #if defined(__svr4__) || defined(_SCO_DS)
39 /* SVR4 DOESNT do locking the same way must implement properly */
46 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
48 /* Define the drive parameter block, as used by int21/1F
49 * and int21/32. This table can be accessed through the
50 * global 'dpb' pointer, which points into the local dos
55 BYTE drive_num; /* 0=A, etc. */
56 BYTE unit_num; /* Drive's unit number (?) */
57 WORD sector_size; /* Sector size in bytes */
58 BYTE high_sector; /* Highest sector in a cluster */
59 BYTE shift; /* Shift count (?) */
60 WORD reserved; /* Number of reserved sectors at start */
61 BYTE num_FAT; /* Number of FATs */
62 WORD dir_entries; /* Number of root dir entries */
63 WORD first_data; /* First data sector */
64 WORD high_cluster; /* Highest cluster number */
65 WORD sectors_in_FAT; /* Number of sectors per FAT */
66 WORD start_dir; /* Starting sector of first dir */
67 DWORD driver_head; /* Address of device driver header (?) */
68 BYTE media_ID; /* Media ID */
69 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
70 DWORD next; /* Pointer to next DPB in list */
71 WORD free_search; /* Free cluster search start */
72 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
83 BYTE DummyDBCSLeadTable[6];
85 static struct DosHeap *heap;
86 static WORD DosHeapHandle;
88 extern char TempDirectory[];
90 static BOOL INT21_CreateHeap(void)
92 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
94 WARN("Out of memory\n");
97 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
98 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
100 strcpy(heap->biosdate, "01/01/80");
101 memset(heap->DummyDBCSLeadTable, 0, 6);
105 static BYTE *GetCurrentDTA( CONTEXT86 *context )
107 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
109 /* FIXME: This assumes DTA was set correctly! */
110 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
111 (DWORD)OFFSETOF(pTask->dta) );
115 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
116 /* limited == TRUE is used with INT 0x21/0x440d */
121 setword(&data[3], 0);
123 setword(&data[6], 240);
124 setword(&data[8], 64000);
126 setword(&data[0x0b], 40);
127 setword(&data[0x0d], 56);
128 setword(&data[0x0f], 2);
129 setword(&data[0x11], 0);
131 setword(&data[0x1f], 800);
133 setword(&data[0x22], 1);
135 } else { /* 1.44mb */
138 setword(&data[3], 0);
140 setword(&data[6], 240);
141 setword(&data[8], 2880);
143 setword(&data[0x0b], 6);
144 setword(&data[0x0d], 18);
145 setword(&data[0x0f], 2);
146 setword(&data[0x11], 0);
148 setword(&data[0x1f], 80);
150 setword(&data[0x22], 2);
155 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
157 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
158 char root[] = "A:\\";
160 *root += DOS_GET_DRIVE( DL_reg(context) );
161 if (!GetDiskFreeSpaceA( root, &cluster_sectors, §or_bytes,
162 &free_clusters, &total_clusters )) return 0;
163 AX_reg(context) = cluster_sectors;
164 BX_reg(context) = free_clusters;
165 CX_reg(context) = sector_bytes;
166 DX_reg(context) = total_clusters;
170 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
172 if (!INT21_GetFreeDiskSpace( context )) return 0;
173 if (!heap && !INT21_CreateHeap()) return 0;
174 heap->mediaID = 0xf0;
175 DS_reg(context) = DosHeapHandle;
176 BX_reg(context) = (int)&heap->mediaID - (int)heap;
180 static void GetDrivePB( CONTEXT86 *context, int drive )
182 if(!DRIVE_IsValid(drive))
184 SetLastError( ERROR_INVALID_DRIVE );
185 AX_reg(context) = 0x00ff;
187 else if (heap || INT21_CreateHeap())
189 FIXME("GetDrivePB not fully implemented.\n");
191 /* FIXME: I have no idea what a lot of this information should
192 * say or whether it even really matters since we're not allowing
193 * direct block access. However, some programs seem to depend on
194 * getting at least _something_ back from here. The 'next' pointer
195 * does worry me, though. Should we have a complete table of
196 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
198 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
199 heap->dpb.sector_size = 512;
200 heap->dpb.high_sector = 1;
201 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
202 heap->dpb.reserved = 0;
203 heap->dpb.num_FAT = 1;
204 heap->dpb.dir_entries = 2;
205 heap->dpb.first_data = 2;
206 heap->dpb.high_cluster = 64000;
207 heap->dpb.sectors_in_FAT = 1;
208 heap->dpb.start_dir = 1;
209 heap->dpb.driver_head = 0;
210 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
211 heap->dpb.access_flag = 0;
213 heap->dpb.free_search = 0;
214 heap->dpb.free_clusters = 0xFFFF; /* unknown */
216 AL_reg(context) = 0x00;
217 DS_reg(context) = SELECTOROF(dpbsegptr);
218 BX_reg(context) = OFFSETOF(dpbsegptr);
223 static void ioctlGetDeviceInfo( CONTEXT86 *context )
226 const DOS_DEVICE *dev;
228 TRACE("(%d)\n", BX_reg(context));
230 RESET_CFLAG(context);
233 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )))
235 DX_reg(context) = dev->flags;
239 /* it seems to be a file */
240 curr_drive = DRIVE_GetCurrentDrive();
241 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
243 /* bits 0-5 are current drive
244 * bit 6 - file has NOT been written..FIXME: correct?
245 * bit 8 - generate int24 if no diskspace on write/ read past end of file
246 * bit 11 - media not removable
247 * bit 14 - don't set file date/time on closing
248 * bit 15 - file is remote
252 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
254 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
255 int drive = DOS_GET_DRIVE( BL_reg(context) );
257 if (!DRIVE_IsValid(drive))
259 SetLastError( ERROR_FILE_NOT_FOUND );
263 if (CH_reg(context) != 0x08)
265 INT_BARF( context, 0x21 );
269 switch (CL_reg(context))
271 case 0x4a: /* lock logical volume */
272 TRACE("lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
275 case 0x60: /* get device parameters */
276 /* used by w4wgrp's winfile */
277 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
279 dataptr[6] = 0; /* media type */
282 dataptr[1] = 0x05; /* fixed disk */
283 setword(&dataptr[2], 0x01); /* non removable */
284 setword(&dataptr[4], 0x300); /* # of cylinders */
288 dataptr[1] = 0x07; /* block dev, floppy */
289 setword(&dataptr[2], 0x02); /* removable */
290 setword(&dataptr[4], 80); /* # of cylinders */
292 CreateBPB(drive, &dataptr[7], TRUE);
293 RESET_CFLAG(context);
296 case 0x41: /* write logical device track */
297 case 0x61: /* read logical device track */
299 BYTE drive = BL_reg(context) ?
300 BL_reg(context) : DRIVE_GetCurrentDrive();
301 WORD head = *(WORD *)dataptr+1;
302 WORD cyl = *(WORD *)dataptr+3;
303 WORD sect = *(WORD *)dataptr+5;
304 WORD nrsect = *(WORD *)dataptr+7;
305 BYTE *data = (BYTE *)dataptr+9;
306 int (*raw_func)(BYTE, DWORD, DWORD, BYTE *, BOOL);
308 raw_func = (CL_reg(context) == 0x41) ?
309 DRIVE_RawWrite : DRIVE_RawRead;
311 if (raw_func(drive, head*cyl*sect, nrsect, data, FALSE))
312 RESET_CFLAG(context);
315 AX_reg(context) = 0x1e; /* read fault */
320 case 0x66:/* get disk serial number */
322 char label[12],fsname[9],path[4];
325 strcpy(path,"x:\\");path[0]=drive+'A';
326 GetVolumeInformationA(
327 path,label,12,&serial,NULL,NULL,fsname,9
330 memcpy(dataptr+2,&serial,4);
331 memcpy(dataptr+6,label ,11);
332 memcpy(dataptr+17,fsname,8);
337 TRACE("logical volume %d unlocked.\n",drive);
341 memset(dataptr+1, '\0', dataptr[0]-1);
342 dataptr[1] = dataptr[0];
343 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
344 dataptr[3] = 0xFF; /* no physical drive */
348 /* Trail on error implementation */
349 AX_reg(context) = GetDriveType16(BL_reg(context)) == DRIVE_CANNOTDETERMINE ? 0x0f : 0x01;
350 SET_CFLAG(context); /* Seems to be set all the time */
354 INT_BARF( context, 0x21 );
359 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
362 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
364 CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context) );
365 char *buffer, *s, *d;
367 AL_reg(context) = 0xff; /* failed */
369 TRACE("filename: '%s'\n", filename);
371 buffer = HeapAlloc( GetProcessHeap(), 0, strlen(filename) + 1);
377 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
384 DOSFS_ToDosFCBFormat(buffer, fcb + 1);
386 TRACE("FCB: '%s'\n", ((CHAR *)fcb + 1));
388 HeapFree( GetProcessHeap(), 0, buffer);
391 ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0;
393 /* point DS:SI to first unparsed character */
394 SI_reg(context) += (int)s - (int)filename;
397 static void INT21_GetSystemDate( CONTEXT86 *context )
400 GetLocalTime( &systime );
401 CX_reg(context) = systime.wYear;
402 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
403 AX_reg(context) = systime.wDayOfWeek;
406 static void INT21_GetSystemTime( CONTEXT86 *context )
409 GetLocalTime( &systime );
410 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
411 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
414 /* Many calls translate a drive argument like this:
415 drive number (00h = default, 01h = A:, etc)
417 static char drivestring[]="default";
419 char *INT21_DriveName(int drive)
424 drivestring[0]= (unsigned char)drive + '@';
430 static BOOL INT21_CreateFile( CONTEXT86 *context )
432 AX_reg(context) = _lcreat16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
433 EDX_reg(context) ), CX_reg(context) );
434 return (AX_reg(context) == (WORD)HFILE_ERROR16);
437 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
439 /* Mask off all flags not explicitly allowed by the doc */
440 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
441 return FILE_AllocDosHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
442 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
443 CREATE_NEW, attr, -1 ));
446 static void OpenExistingFile( CONTEXT86 *context )
448 AX_reg(context) = _lopen16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
450 if (AX_reg(context) == (WORD)HFILE_ERROR16)
452 AX_reg(context) = GetLastError();
457 static BOOL INT21_ExtendedOpenCreateFile(CONTEXT86 *context )
459 BOOL bExtendedError = FALSE;
460 BYTE action = DL_reg(context);
462 /* Shuffle arguments to call OpenExistingFile */
463 AL_reg(context) = BL_reg(context);
464 DX_reg(context) = SI_reg(context);
465 /* BX,CX and DX should be preserved */
466 OpenExistingFile(context);
468 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
470 UINT16 uReturnCX = 0;
472 /* Now decide what do do */
474 if ((action & 0x07) == 0)
476 _lclose16( AX_reg(context) );
477 AX_reg(context) = 0x0050; /*File exists*/
479 WARN("extended open/create: failed because file exists \n");
481 else if ((action & 0x07) == 2)
483 /* Truncate it, but first check if opened for write */
484 if ((BL_reg(context) & 0x0007)== 0)
486 _lclose16( AX_reg(context) );
487 WARN("extended open/create: failed, trunc on ro file\n");
488 AX_reg(context) = 0x000C; /*Access code invalid*/
493 TRACE("extended open/create: Closing before truncate\n");
494 if (_lclose16( AX_reg(context) ))
496 WARN("extended open/create: close before trunc failed\n");
497 AX_reg(context) = 0x0019; /*Seek Error*/
501 /* Shuffle arguments to call CreateFile */
503 TRACE("extended open/create: Truncating\n");
504 AL_reg(context) = BL_reg(context);
505 /* CX is still the same */
506 DX_reg(context) = SI_reg(context);
507 bExtendedError = INT21_CreateFile(context);
509 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
511 WARN("extended open/create: trunc failed\n");
512 return bExtendedError;
517 else uReturnCX = 0x1;
519 CX_reg(context) = uReturnCX;
521 else /* file does not exist */
523 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
524 if ((action & 0xF0)== 0)
528 WARN("extended open/create: failed, file dosen't exist\n");
532 /* Shuffle arguments to call CreateFile */
533 TRACE("extended open/create: Creating\n");
534 AL_reg(context) = BL_reg(context);
535 /* CX should still be the same */
536 DX_reg(context) = SI_reg(context);
537 bExtendedError = INT21_CreateFile(context);
538 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
540 WARN("extended open/create: create failed\n");
541 return bExtendedError;
547 return bExtendedError;
551 static BOOL INT21_ChangeDir( CONTEXT86 *context )
554 char *dirname = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));
556 TRACE("changedir %s\n", dirname);
557 if (dirname[0] && (dirname[1] == ':'))
559 drive = toupper(dirname[0]) - 'A';
562 else drive = DRIVE_GetCurrentDrive();
563 return DRIVE_Chdir( drive, dirname );
567 static int INT21_FindFirst( CONTEXT86 *context )
571 DOS_FULL_NAME full_name;
572 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
574 path = (const char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
575 dta->unixPath = NULL;
576 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
578 AX_reg(context) = GetLastError();
582 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
583 p = strrchr( dta->unixPath, '/' );
586 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
587 * (doesn't matter as it is set below anyway)
589 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
591 HeapFree( GetProcessHeap(), 0, dta->unixPath );
592 dta->unixPath = NULL;
593 SetLastError( ERROR_FILE_NOT_FOUND );
594 AX_reg(context) = ERROR_FILE_NOT_FOUND;
598 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
599 : DRIVE_GetCurrentDrive();
601 dta->search_attr = CL_reg(context);
606 static int INT21_FindNext( CONTEXT86 *context )
608 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
609 WIN32_FIND_DATAA entry;
612 if (!dta->unixPath) return 0;
613 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
614 dta->search_attr, dta->count, &entry )))
616 HeapFree( GetProcessHeap(), 0, dta->unixPath );
617 dta->unixPath = NULL;
620 if ((int)dta->count + count > 0xffff)
622 WARN("Too many directory entries in %s\n", dta->unixPath );
623 HeapFree( GetProcessHeap(), 0, dta->unixPath );
624 dta->unixPath = NULL;
628 dta->fileattr = entry.dwFileAttributes;
629 dta->filesize = entry.nFileSizeLow;
630 FileTimeToDosDateTime( &entry.ftLastWriteTime,
631 &dta->filedate, &dta->filetime );
632 strcpy( dta->filename, entry.cAlternateFileName );
633 if (!memchr(dta->mask,'?',11)) {
634 /* wildcardless search, release resources in case no findnext will
635 * be issued, and as a workaround in case file creation messes up
636 * findnext, as sometimes happens with pkunzip */
637 HeapFree( GetProcessHeap(), 0, dta->unixPath );
638 dta->unixPath = NULL;
644 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
646 static int counter = 0;
647 char *name = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context) );
648 char *p = name + strlen(name);
650 /* despite what Ralf Brown says, some programs seem to call without
651 * ending backslash (DOS accepts that, so we accept it too) */
652 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
656 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
657 counter = (counter + 1) % 1000;
659 if ((AX_reg(context) = _lcreat16_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
661 TRACE("created %s\n", name );
664 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
669 static BOOL INT21_GetCurrentDirectory( CONTEXT86 *context )
671 int drive = DOS_GET_DRIVE( DL_reg(context) );
672 char *ptr = (char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context) );
674 if (!DRIVE_IsValid(drive))
676 SetLastError( ERROR_INVALID_DRIVE );
679 lstrcpynA( ptr, DRIVE_GetDosCwd(drive), 64 );
680 AX_reg(context) = 0x0100; /* success return code */
685 static void INT21_GetDBCSLeadTable( CONTEXT86 *context )
687 if (heap || INT21_CreateHeap())
688 { /* return an empty table just as DOS 4.0+ does */
689 DS_reg(context) = DosHeapHandle;
690 SI_reg(context) = (int)&heap->DummyDBCSLeadTable - (int)heap;
694 AX_reg(context) = 0x1; /* error */
700 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
702 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
703 int drive = DOS_GET_DRIVE( BL_reg(context) );
705 if (!DRIVE_IsValid(drive))
707 SetLastError( ERROR_INVALID_DRIVE );
711 *(WORD *)dataptr = 0;
712 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
713 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
714 strncpy(dataptr + 0x11, "FAT16 ", 8);
719 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
721 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
722 int drive = DOS_GET_DRIVE( BL_reg(context) );
724 if (!DRIVE_IsValid(drive))
726 SetLastError( ERROR_INVALID_DRIVE );
730 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
735 /* microsoft's programmers should be shot for using CP/M style int21
736 calls in Windows for Workgroup's winfile.exe */
738 static int INT21_FindFirstFCB( CONTEXT86 *context )
740 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
745 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
746 else pFCB = (FINDFILE_FCB *)fcb;
747 drive = DOS_GET_DRIVE( pFCB->drive );
748 if (!DRIVE_IsValid( drive )) return 0;
749 root = DRIVE_GetRoot( drive );
750 cwd = DRIVE_GetUnixCwd( drive );
751 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
752 strlen(root)+strlen(cwd)+2 );
753 if (!pFCB->unixPath) return 0;
754 strcpy( pFCB->unixPath, root );
755 strcat( pFCB->unixPath, "/" );
756 strcat( pFCB->unixPath, cwd );
762 static int INT21_FindNextFCB( CONTEXT86 *context )
764 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context));
766 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
767 WIN32_FIND_DATAA entry;
771 if (*fcb == 0xff) /* extended FCB ? */
774 pFCB = (FINDFILE_FCB *)(fcb + 7);
779 pFCB = (FINDFILE_FCB *)fcb;
782 if (!pFCB->unixPath) return 0;
783 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
784 DOS_GET_DRIVE( pFCB->drive ), attr,
785 pFCB->count, &entry )))
787 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
788 pFCB->unixPath = NULL;
791 pFCB->count += count;
793 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
794 *(BYTE *)pResult = 0xff;
795 (BYTE *)pResult +=6; /* leave reserved field behind */
796 *(BYTE *)pResult = entry.dwFileAttributes;
799 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
801 pResult->fileattr = entry.dwFileAttributes;
802 pResult->cluster = 0; /* what else? */
803 pResult->filesize = entry.nFileSizeLow;
804 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
805 FileTimeToDosDateTime( &entry.ftLastWriteTime,
806 &pResult->filedate, &pResult->filetime );
808 /* Convert file name to FCB format */
810 memset( pResult->filename, ' ', sizeof(pResult->filename) );
811 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
812 else if (!strcmp( entry.cAlternateFileName, ".." ))
813 pResult->filename[0] = pResult->filename[1] = '.';
816 char *p = strrchr( entry.cAlternateFileName, '.' );
817 if (p && p[1] && (p != entry.cAlternateFileName))
819 memcpy( pResult->filename, entry.cAlternateFileName,
820 MIN( (p - entry.cAlternateFileName), 8 ) );
821 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
824 memcpy( pResult->filename, entry.cAlternateFileName,
825 MIN( strlen(entry.cAlternateFileName), 8 ) );
831 static void DeleteFileFCB( CONTEXT86 *context )
833 FIXME("(%p): stub\n", context);
836 static void RenameFileFCB( CONTEXT86 *context )
838 FIXME("(%p): stub\n", context);
843 static void fLock( CONTEXT86 * context )
846 switch ( AX_reg(context) & 0xff )
848 case 0x00: /* LOCK */
849 TRACE("lock handle %d offset %ld length %ld\n",
851 MAKELONG(DX_reg(context),CX_reg(context)),
852 MAKELONG(DI_reg(context),SI_reg(context))) ;
853 if (!LockFile(FILE_GetHandle(BX_reg(context)),
854 MAKELONG(DX_reg(context),CX_reg(context)), 0,
855 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
856 AX_reg(context) = GetLastError();
861 case 0x01: /* UNLOCK */
862 TRACE("unlock handle %d offset %ld length %ld\n",
864 MAKELONG(DX_reg(context),CX_reg(context)),
865 MAKELONG(DI_reg(context),SI_reg(context))) ;
866 if (!UnlockFile(FILE_GetHandle(BX_reg(context)),
867 MAKELONG(DX_reg(context),CX_reg(context)), 0,
868 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
869 AX_reg(context) = GetLastError();
874 AX_reg(context) = 0x0001;
881 INT21_networkfunc (CONTEXT86 *context)
883 switch (AL_reg(context)) {
884 case 0x00: /* Get machine name. */
886 char *dst = CTX_SEG_OFF_TO_LIN (context,DS_reg(context),EDX_reg(context));
887 TRACE("getting machine name to %p\n", dst);
888 if (gethostname (dst, 15))
891 SetLastError( ER_NoNetwork );
894 int len = strlen (dst);
898 CH_reg(context) = 1; /* Valid */
899 CL_reg(context) = 1; /* NETbios number??? */
900 TRACE("returning %s\n", debugstr_an (dst, 16));
906 SetLastError( ER_NoNetwork );
911 static void INT21_SetCurrentPSP(WORD psp)
914 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
915 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
917 GlobalUnlock16( GetCurrentTask() );
918 if (pModule->lpDosTask)
919 pModule->lpDosTask->psp_seg = psp;
922 ERR("Cannot change PSP for non-DOS task!\n");
925 static WORD INT21_GetCurrentPSP()
928 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
929 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
931 GlobalUnlock16( GetCurrentTask() );
932 if (pModule->lpDosTask)
933 return pModule->lpDosTask->psp_seg;
936 return GetCurrentPDB16();
940 /***********************************************************************
941 * INT21_GetExtendedError
943 static void INT21_GetExtendedError( CONTEXT86 *context )
945 BYTE class, action, locus;
946 WORD error = GetLastError();
951 class = action = locus = 0;
953 case ERROR_DIR_NOT_EMPTY:
958 case ERROR_ACCESS_DENIED:
959 class = EC_AccessDenied;
963 case ERROR_CANNOT_MAKE:
964 class = EC_AccessDenied;
968 case ERROR_DISK_FULL:
969 case ERROR_HANDLE_DISK_FULL:
970 class = EC_MediaError;
974 case ERROR_FILE_EXISTS:
975 case ERROR_ALREADY_EXISTS:
980 case ERROR_FILE_NOT_FOUND:
985 case ER_GeneralFailure:
986 class = EC_SystemFailure;
990 case ERROR_INVALID_DRIVE:
991 class = EC_MediaError;
995 case ERROR_INVALID_HANDLE:
996 class = EC_ProgramError;
1000 case ERROR_LOCK_VIOLATION:
1001 class = EC_AccessDenied;
1005 case ERROR_NO_MORE_FILES:
1006 class = EC_MediaError;
1011 class = EC_NotFound;
1015 case ERROR_NOT_ENOUGH_MEMORY:
1016 class = EC_OutOfResource;
1020 case ERROR_PATH_NOT_FOUND:
1021 class = EC_NotFound;
1026 class = EC_NotFound;
1030 case ERROR_SHARING_VIOLATION:
1031 class = EC_Temporary;
1035 case ERROR_TOO_MANY_OPEN_FILES:
1036 class = EC_ProgramError;
1041 FIXME("Unknown error %d\n", error );
1042 class = EC_SystemFailure;
1047 TRACE("GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1048 error, class, action, locus );
1049 AX_reg(context) = error;
1050 BH_reg(context) = class;
1051 BL_reg(context) = action;
1052 CH_reg(context) = locus;
1055 /***********************************************************************
1056 * DOS3Call (KERNEL.102)
1058 void WINAPI DOS3Call( CONTEXT86 *context )
1060 BOOL bSetDOSExtendedError = FALSE;
1063 TRACE("AX=%04x BX=%04x CX=%04x DX=%04x "
1064 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1065 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
1066 SI_reg(context), DI_reg(context),
1067 (WORD)DS_reg(context), (WORD)ES_reg(context),
1071 if (AH_reg(context) == 0x59) /* Get extended error info */
1073 INT21_GetExtendedError( context );
1077 if (AH_reg(context) == 0x0C) /* Flush buffer and read standard input */
1079 TRACE("FLUSH BUFFER AND READ STANDARD INPUT\n");
1080 /* no flush here yet */
1081 AH_reg(context) = AL_reg(context);
1084 if (AH_reg(context)>=0x2f) {
1085 /* extended error is used by (at least) functions 0x2f to 0x62 */
1088 RESET_CFLAG(context); /* Not sure if this is a good idea */
1090 switch(AH_reg(context))
1092 case 0x03: /* READ CHARACTER FROM STDAUX */
1093 case 0x04: /* WRITE CHARACTER TO STDAUX */
1094 case 0x05: /* WRITE CHARACTER TO PRINTER */
1095 case 0x0f: /* OPEN FILE USING FCB */
1096 case 0x10: /* CLOSE FILE USING FCB */
1097 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
1098 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
1099 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
1100 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1101 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1102 case 0x23: /* GET FILE SIZE FOR FCB */
1103 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1104 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1105 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1106 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1107 INT_BARF( context, 0x21 );
1110 case 0x00: /* TERMINATE PROGRAM */
1111 TRACE("TERMINATE PROGRAM\n");
1115 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
1116 TRACE("DIRECT CHARACTER INPUT WITH ECHO\n");
1117 AL_reg(context) = CONSOLE_GetCharacter();
1118 /* FIXME: no echo */
1121 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
1122 TRACE("Write Character to Standard Output\n");
1123 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1126 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
1127 if (DL_reg(context) == 0xff) {
1128 static char scan = 0;
1129 TRACE("Direct Console Input\n");
1131 /* return pending scancode */
1132 AL_reg(context) = scan;
1133 EFL_reg(context) &= ~0x40; /* clear ZF */
1137 if (CONSOLE_CheckForKeystroke(&scan,&ascii)) {
1138 CONSOLE_GetKeystroke(&scan,&ascii);
1139 /* return ASCII code */
1140 AL_reg(context) = ascii;
1141 EFL_reg(context) &= ~0x40; /* clear ZF */
1142 /* return scan code on next call only if ascii==0 */
1143 if (ascii) scan = 0;
1145 /* nothing pending, clear everything */
1146 AL_reg(context) = 0;
1147 EFL_reg(context) |= 0x40; /* set ZF */
1148 scan = 0; /* just in case */
1152 TRACE("Direct Console Output\n");
1153 CONSOLE_Write(DL_reg(context), 0, 0, 0);
1157 case 0x07: /* DIRECT CHARACTER INPUT WITHOUT ECHO */
1158 TRACE("DIRECT CHARACTER INPUT WITHOUT ECHO\n");
1159 AL_reg(context) = CONSOLE_GetCharacter();
1162 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
1163 TRACE("CHARACTER INPUT WITHOUT ECHO\n");
1164 AL_reg(context) = CONSOLE_GetCharacter();
1167 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
1168 TRACE("WRITE '$'-terminated string from %04lX:%04X to stdout\n",
1169 DS_reg(context),DX_reg(context) );
1171 LPSTR data = CTX_SEG_OFF_TO_LIN(context,DS_reg(context),EDX_reg(context));
1173 /* do NOT use strchr() to calculate the string length,
1174 as '\0' is valid string content, too !
1175 Maybe we should check for non-'$' strings, but DOS doesn't. */
1176 while (*p != '$') p++;
1177 _hwrite16( 1, data, (int)p - (int)data);
1178 AL_reg(context) = '$'; /* yes, '$' (0x24) gets returned in AL */
1182 case 0x0a: /* BUFFERED INPUT */
1184 char *buffer = ((char *)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1185 EDX_reg(context) ));
1188 TRACE("BUFFERED INPUT (size=%d)\n",buffer[0]);
1190 TRACE("Handle old chars in buffer!\n");
1191 res=_lread16( 0, buffer+2,buffer[0]);
1193 if(buffer[res+1] == '\n')
1194 buffer[res+1] = '\r';
1198 case 0x0b: {/* GET STDIN STATUS */
1201 if (CONSOLE_CheckForKeystroke(&x1,&x2))
1202 AL_reg(context) = 0xff;
1204 AL_reg(context) = 0;
1207 case 0x2e: /* SET VERIFY FLAG */
1208 TRACE("SET VERIFY FLAG ignored\n");
1209 /* we cannot change the behaviour anyway, so just ignore it */
1212 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1216 case 0x6b: /* NULL FUNCTION */
1217 AL_reg(context) = 0;
1220 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1224 case 0x0d: /* DISK BUFFER FLUSH */
1225 TRACE("DISK BUFFER FLUSH ignored\n");
1226 RESET_CFLAG(context); /* dos 6+ only */
1229 case 0x0e: /* SELECT DEFAULT DRIVE */
1230 TRACE("SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1231 DRIVE_SetCurrentDrive( DL_reg(context) );
1232 AL_reg(context) = MAX_DOS_DRIVES;
1235 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1236 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
1237 CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1238 if (!INT21_FindFirstFCB(context))
1240 AL_reg(context) = 0xff;
1243 /* else fall through */
1245 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1246 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1249 case 0x13: /* DELETE FILE USING FCB */
1250 DeleteFileFCB(context);
1253 case 0x17: /* RENAME FILE USING FCB */
1254 RenameFileFCB(context);
1257 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1258 AL_reg(context) = DRIVE_GetCurrentDrive();
1261 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1263 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1264 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1265 TRACE("Set DTA: %08lx\n", pTask->dta);
1269 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1270 DL_reg(context) = 0;
1271 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1274 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1275 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1278 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1279 GetDrivePB(context, DRIVE_GetCurrentDrive());
1282 case 0x25: /* SET INTERRUPT VECTOR */
1283 INT_CtxSetHandler( context, AL_reg(context),
1284 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1288 case 0x29: /* PARSE FILENAME INTO FCB */
1289 INT21_ParseFileNameIntoFCB(context);
1292 case 0x2a: /* GET SYSTEM DATE */
1293 INT21_GetSystemDate(context);
1296 case 0x2b: /* SET SYSTEM DATE */
1297 FIXME("SetSystemDate(%02d/%02d/%04d): not allowed\n",
1298 DL_reg(context), DH_reg(context), CX_reg(context) );
1299 AL_reg(context) = 0; /* Let's pretend we succeeded */
1302 case 0x2c: /* GET SYSTEM TIME */
1303 INT21_GetSystemTime(context);
1306 case 0x2d: /* SET SYSTEM TIME */
1307 FIXME("SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1308 CH_reg(context), CL_reg(context),
1309 DH_reg(context), DL_reg(context) );
1310 AL_reg(context) = 0; /* Let's pretend we succeeded */
1313 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1314 TRACE("GET DISK TRANSFER AREA ADDRESS\n");
1316 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1317 ES_reg(context) = SELECTOROF( pTask->dta );
1318 BX_reg(context) = OFFSETOF( pTask->dta );
1322 case 0x30: /* GET DOS VERSION */
1323 TRACE("GET DOS VERSION %s requested\n",
1324 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1325 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1326 (HIWORD(GetVersion16()) << 8);
1328 AH_reg(context) = 0x7;
1329 AL_reg(context) = 0xA;
1332 BX_reg(context) = 0x00FF; /* 0x123456 is Wine's serial # */
1333 CX_reg(context) = 0x0000;
1336 case 0x31: /* TERMINATE AND STAY RESIDENT */
1337 FIXME("TERMINATE AND STAY RESIDENT stub\n");
1340 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1341 TRACE("GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1342 INT21_DriveName( DL_reg(context)));
1343 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1346 case 0x33: /* MULTIPLEXED */
1347 switch (AL_reg(context))
1349 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1350 TRACE("GET CURRENT EXTENDED BREAK STATE\n");
1351 DL_reg(context) = DOSCONF_config.brk_flag;
1354 case 0x01: /* SET EXTENDED BREAK STATE */
1355 TRACE("SET CURRENT EXTENDED BREAK STATE\n");
1356 DOSCONF_config.brk_flag = (DL_reg(context) > 0);
1359 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1360 TRACE("GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE\n");
1361 /* ugly coding in order to stay reentrant */
1362 if (DL_reg(context))
1364 DL_reg(context) = DOSCONF_config.brk_flag;
1365 DOSCONF_config.brk_flag = 1;
1369 DL_reg(context) = DOSCONF_config.brk_flag;
1370 DOSCONF_config.brk_flag = 0;
1374 case 0x05: /* GET BOOT DRIVE */
1375 TRACE("GET BOOT DRIVE\n");
1376 DL_reg(context) = 3;
1377 /* c: is Wine's bootdrive (a: is 1)*/
1380 case 0x06: /* GET TRUE VERSION NUMBER */
1381 TRACE("GET TRUE VERSION NUMBER\n");
1382 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1383 (HIWORD(GetVersion16() << 8));
1384 DX_reg(context) = 0x00;
1388 INT_BARF( context, 0x21 );
1393 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1394 TRACE("GET ADDRESS OF INDOS FLAG\n");
1395 if (!heap) INT21_CreateHeap();
1396 ES_reg(context) = DosHeapHandle;
1397 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1400 case 0x35: /* GET INTERRUPT VECTOR */
1401 TRACE("GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1403 FARPROC16 addr = INT_CtxGetHandler( context, AL_reg(context) );
1404 ES_reg(context) = SELECTOROF(addr);
1405 BX_reg(context) = OFFSETOF(addr);
1409 case 0x36: /* GET FREE DISK SPACE */
1410 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
1411 INT21_DriveName( DL_reg(context)));
1412 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1417 unsigned char switchchar='/';
1418 switch (AL_reg(context))
1420 case 0x00: /* "SWITCHAR" - GET SWITCH CHARACTER */
1421 TRACE("SWITCHAR - GET SWITCH CHARACTER\n");
1422 AL_reg(context) = 0x00; /* success*/
1423 DL_reg(context) = switchchar;
1425 case 0x01: /*"SWITCHAR" - SET SWITCH CHARACTER*/
1426 TRACE("SWITCHAR - SET SWITCH CHARACTER\n");
1427 switchchar = DL_reg(context);
1428 AL_reg(context) = 0x00; /* success*/
1430 default: /*"AVAILDEV" - SPECIFY \DEV\ PREFIX USE*/
1431 INT_BARF( context, 0x21 );
1437 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1438 TRACE("GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1440 AX_reg(context) = 0x02; /* no country support available */
1444 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1446 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1447 bSetDOSExtendedError = (!CreateDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1448 EDX_reg(context) ), NULL));
1449 /* FIXME: CreateDirectory's LastErrors will clash with the ones
1450 * used by dos. AH=39 only returns 3 (path not found) and 5 (access
1451 * denied), while CreateDirectory return several ones. remap some of
1454 if (bSetDOSExtendedError) {
1455 switch (GetLastError()) {
1456 case ERROR_ALREADY_EXISTS:
1457 case ERROR_FILENAME_EXCED_RANGE:
1458 case ERROR_DISK_FULL:
1459 SetLastError(ERROR_ACCESS_DENIED);
1466 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1468 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1469 bSetDOSExtendedError = (!RemoveDirectory16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1470 EDX_reg(context) )));
1473 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1475 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1476 bSetDOSExtendedError = !INT21_ChangeDir(context);
1479 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1480 TRACE("CREAT flag 0x%02x %s\n",CX_reg(context),
1481 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1482 bSetDOSExtendedError = INT21_CreateFile( context );
1485 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1486 TRACE("OPEN mode 0x%02x %s\n",AL_reg(context),
1487 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1488 OpenExistingFile(context);
1491 case 0x3e: /* "CLOSE" - CLOSE FILE */
1492 TRACE("CLOSE handle %d\n",BX_reg(context));
1493 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1496 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1497 TRACE("READ from %d to %04lX:%04X for %d byte\n",BX_reg(context),
1498 DS_reg(context),DX_reg(context),CX_reg(context) );
1502 result = _hread16( BX_reg(context),
1503 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1507 result = WIN16_hread( BX_reg(context),
1508 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1511 if (result == -1) bSetDOSExtendedError = TRUE;
1512 else AX_reg(context) = (WORD)result;
1516 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1517 TRACE("WRITE from %04lX:%04X to handle %d for %d byte\n",
1518 DS_reg(context),DX_reg(context),BX_reg(context),CX_reg(context) );
1520 LONG result = _hwrite16( BX_reg(context),
1521 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1524 if (result == -1) bSetDOSExtendedError = TRUE;
1525 else AX_reg(context) = (WORD)result;
1529 case 0x41: /* "UNLINK" - DELETE FILE */
1531 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1532 bSetDOSExtendedError = (!DeleteFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1533 EDX_reg(context) )));
1536 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1537 TRACE("LSEEK handle %d offset %ld from %s\n",
1538 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1539 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1540 "current file position":"end of file");
1542 LONG status = _llseek16( BX_reg(context),
1543 MAKELONG(DX_reg(context),CX_reg(context)),
1545 if (status == -1) bSetDOSExtendedError = TRUE;
1548 AX_reg(context) = LOWORD(status);
1549 DX_reg(context) = HIWORD(status);
1554 case 0x43: /* FILE ATTRIBUTES */
1555 switch (AL_reg(context))
1558 TRACE("GET FILE ATTRIBUTES for %s\n",
1559 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1560 AX_reg(context) = (WORD)GetFileAttributesA(
1561 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1563 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1564 else CX_reg(context) = AX_reg(context);
1568 TRACE("SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1569 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1570 bSetDOSExtendedError =
1571 (!SetFileAttributesA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1576 TRACE("GET COMPRESSED FILE SIZE for %s stub\n",
1577 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1581 case 0x44: /* IOCTL */
1582 switch (AL_reg(context))
1585 ioctlGetDeviceInfo(context);
1591 const DOS_DEVICE *dev;
1592 if ((dev = DOSFS_GetDeviceByHandle( FILE_GetHandle(BX_reg(context)) )) &&
1593 !strcasecmp( dev->name, "SCSIMGR$" ))
1595 ASPI_DOS_HandleInt(context);
1599 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1600 /*BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context));*/
1601 int drive = DOS_GET_DRIVE(BL_reg(context));
1603 FIXME("program tried to write to block device control channel of drive %d:\n",drive);
1604 /* for (i=0;i<CX_reg(context);i++)
1605 fprintf(stdnimp,"%02x ",dataptr[i]);
1606 fprintf(stdnimp,"\n");*/
1607 AX_reg(context)=CX_reg(context);
1610 case 0x08: /* Check if drive is removable. */
1611 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1612 INT21_DriveName( BL_reg(context)));
1613 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1615 case DRIVE_CANNOTDETERMINE:
1616 SetLastError( ERROR_INVALID_DRIVE );
1617 AX_reg(context) = ERROR_INVALID_DRIVE;
1620 case DRIVE_REMOVABLE:
1621 AX_reg(context) = 0; /* removable */
1624 AX_reg(context) = 1; /* not removable */
1629 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1630 TRACE("IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1631 INT21_DriveName( BL_reg(context)));
1632 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1634 case DRIVE_CANNOTDETERMINE:
1635 SetLastError( ERROR_INVALID_DRIVE );
1636 AX_reg(context) = ERROR_INVALID_DRIVE;
1640 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1643 DX_reg(context) = 0; /* FIXME: use driver attr here */
1648 case 0x0a: /* check if handle (BX) is remote */
1649 TRACE("IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1650 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1653 DX_reg(context) = 0;
1656 case 0x0b: /* SET SHARING RETRY COUNT */
1657 TRACE("IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1658 CX_reg(context), DX_reg(context));
1659 if (!CX_reg(context))
1661 AX_reg(context) = 1;
1665 DOSMEM_LOL()->sharing_retry_delay = CX_reg(context);
1666 if (!DX_reg(context))
1667 DOSMEM_LOL()->sharing_retry_count = DX_reg(context);
1668 RESET_CFLAG(context);
1672 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1673 INT21_DriveName( BL_reg(context)));
1674 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1677 case 0x0e: /* get logical drive mapping */
1678 TRACE("IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1679 INT21_DriveName( BL_reg(context)));
1680 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1683 case 0x0F: /* Set logical drive mapping */
1686 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1687 INT21_DriveName( BL_reg(context)));
1688 drive = DOS_GET_DRIVE ( BL_reg(context) );
1689 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1692 AX_reg(context) = 0x000F; /* invalid drive */
1697 case 0xe0: /* Sun PC-NFS API */
1702 INT_BARF( context, 0x21 );
1707 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1710 TRACE("DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1711 if ((bSetDOSExtendedError = !DuplicateHandle( GetCurrentProcess(),
1712 FILE_GetHandle(BX_reg(context)),
1713 GetCurrentProcess(), &handle,
1714 0, TRUE, DUPLICATE_SAME_ACCESS )))
1715 AX_reg(context) = HFILE_ERROR16;
1717 AX_reg(context) = FILE_AllocDosHandle(handle);
1721 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1722 TRACE("FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1723 BX_reg(context),CX_reg(context));
1724 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR16);
1727 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1728 TRACE("CWD - GET CURRENT DIRECTORY for drive %s\n",
1729 INT21_DriveName( DL_reg(context)));
1730 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1733 case 0x48: /* ALLOCATE MEMORY */
1734 TRACE("ALLOCATE MEMORY for %d paragraphs\n", BX_reg(context));
1739 mem= DOSMEM_GetBlock(0,(DWORD)BX_reg(context)<<4,NULL);
1741 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1745 mem = (LPVOID)GlobalDOSAlloc16(BX_reg(context)<<4);
1747 AX_reg(context) = (DWORD)mem&0xffff;
1752 AX_reg(context) = 0x0008; /* insufficient memory */
1753 BX_reg(context) = DOSMEM_Available(0)>>4;
1758 case 0x49: /* FREE MEMORY */
1759 TRACE("FREE MEMORY segment %04lX\n", ES_reg(context));
1763 ret= DOSMEM_FreeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4));
1766 ret = !GlobalDOSFree16(ES_reg(context));
1767 /* If we don't reset ES_reg, we will fail in the relay code */
1768 ES_reg(context)=ret;
1772 TRACE("FREE MEMORY failed\n");
1774 AX_reg(context) = 0x0009; /* memory block address invalid */
1779 case 0x4a: /* RESIZE MEMORY BLOCK */
1780 TRACE("RESIZE MEMORY segment %04lX to %d paragraphs\n", ES_reg(context), BX_reg(context));
1781 if (!ISV86(context))
1782 FIXME("RESIZE MEMORY probably insufficient implementation. Expect crash soon\n");
1784 LPVOID *mem = DOSMEM_ResizeBlock(0,DOSMEM_MapDosToLinear(ES_reg(context)<<4),
1785 BX_reg(context)<<4,NULL);
1787 AX_reg(context) = DOSMEM_MapLinearToDos(mem)>>4;
1790 AX_reg(context) = 0x0008; /* insufficient memory */
1791 BX_reg(context) = DOSMEM_Available(0)>>4; /* not quite right */
1796 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1798 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context) ));
1799 AX_reg(context) = WinExec16( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1802 if (AX_reg(context) < 32) SET_CFLAG(context);
1805 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1806 TRACE("EXIT with return code %d\n",AL_reg(context));
1807 ExitProcess( AL_reg(context) );
1810 case 0x4d: /* GET RETURN CODE */
1811 TRACE("GET RETURN CODE (ERRORLEVEL)\n");
1812 AX_reg(context) = 0; /* normal exit */
1815 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1816 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1817 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1818 if (!INT21_FindFirst(context)) break;
1821 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1822 TRACE("FINDNEXT\n");
1823 if (!INT21_FindNext(context))
1825 SetLastError( ERROR_NO_MORE_FILES );
1826 AX_reg(context) = ERROR_NO_MORE_FILES;
1829 else AX_reg(context) = 0; /* OK */
1831 case 0x50: /* SET CURRENT PROCESS ID (SET PSP ADDRESS) */
1832 TRACE("SET CURRENT PROCESS ID (SET PSP ADDRESS)\n");
1833 INT21_SetCurrentPSP(BX_reg(context));
1835 case 0x51: /* GET PSP ADDRESS */
1836 TRACE("GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1837 /* FIXME: should we return the original DOS PSP upon */
1838 /* Windows startup ? */
1839 BX_reg(context) = INT21_GetCurrentPSP();
1841 case 0x62: /* GET PSP ADDRESS */
1842 TRACE("GET CURRENT PSP ADDRESS\n");
1843 /* FIXME: should we return the original DOS PSP upon */
1844 /* Windows startup ? */
1845 BX_reg(context) = INT21_GetCurrentPSP();
1848 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1849 TRACE("SYSVARS - GET LIST OF LISTS\n");
1851 ES_reg(context) = ISV86(context) ? HIWORD(DOS_LOLSeg) : LOWORD(DOS_LOLSeg);
1852 BX_reg(context) = FIELD_OFFSET(DOS_LISTOFLISTS, ptr_first_DPB);
1856 case 0x54: /* Get Verify Flag */
1857 TRACE("Get Verify Flag - Not Supported\n");
1858 AL_reg(context) = 0x00; /* pretend we can tell. 00h = off 01h = on */
1861 case 0x56: /* "RENAME" - RENAME FILE */
1862 TRACE("RENAME %s to %s\n",
1863 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1864 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context)));
1865 bSetDOSExtendedError =
1866 (!MoveFileA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1867 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context))));
1870 case 0x57: /* FILE DATE AND TIME */
1871 switch (AL_reg(context))
1873 case 0x00: /* Get */
1876 TRACE("GET FILE DATE AND TIME for handle %d\n",
1878 if (!GetFileTime( FILE_GetHandle(BX_reg(context)), NULL, NULL, &filetime ))
1879 bSetDOSExtendedError = TRUE;
1880 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1885 case 0x01: /* Set */
1888 TRACE("SET FILE DATE AND TIME for handle %d\n",
1890 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1892 bSetDOSExtendedError =
1893 (!SetFileTime( FILE_GetHandle(BX_reg(context)),
1894 NULL, NULL, &filetime ));
1900 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1901 TRACE("GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1903 switch (AL_reg(context))
1906 AX_reg(context) = 1;
1909 AX_reg(context) = 0;
1915 RESET_CFLAG(context);
1918 case 0x5a: /* CREATE TEMPORARY FILE */
1919 TRACE("CREATE TEMPORARY FILE\n");
1920 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1923 case 0x5b: /* CREATE NEW FILE */
1924 TRACE("CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1925 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
1926 bSetDOSExtendedError = ((AX_reg(context) =
1927 _lcreat16_uniq( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
1928 CX_reg(context) )) == (WORD)HFILE_ERROR16);
1931 case 0x5d: /* NETWORK */
1932 FIXME("Function 0x%04x not implemented.\n", AX_reg (context));
1933 /* Fix the following while you're at it. */
1934 SetLastError( ER_NoNetwork );
1935 bSetDOSExtendedError = TRUE;
1939 bSetDOSExtendedError = INT21_networkfunc (context);
1942 case 0x5f: /* NETWORK */
1943 switch (AL_reg(context))
1945 case 0x07: /* ENABLE DRIVE */
1946 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1947 if (!DRIVE_Enable( DL_reg(context) ))
1949 SetLastError( ERROR_INVALID_DRIVE );
1950 bSetDOSExtendedError = TRUE;
1954 case 0x08: /* DISABLE DRIVE */
1955 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1956 if (!DRIVE_Disable( DL_reg(context) ))
1958 SetLastError( ERROR_INVALID_DRIVE );
1959 bSetDOSExtendedError = TRUE;
1964 /* network software not installed */
1965 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
1966 SetLastError( ER_NoNetwork );
1967 bSetDOSExtendedError = TRUE;
1972 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1973 TRACE("TRUENAME %s\n",
1974 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),ESI_reg(context)));
1976 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
1977 ESI_reg(context)), 128,
1978 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
1979 EDI_reg(context)),NULL))
1980 bSetDOSExtendedError = TRUE;
1981 else AX_reg(context) = 0;
1985 case 0x61: /* UNUSED */
1986 case 0x63: /* misc. language support */
1987 switch (AL_reg(context)) {
1988 case 0x00: /* GET DOUBLE BYTE CHARACTER SET LEAD-BYTE TABLE */
1989 INT21_GetDBCSLeadTable(context);
1993 case 0x64: /* OS/2 DOS BOX */
1994 INT_BARF( context, 0x21 );
1998 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1999 extern WORD WINE_LanguageId;
2000 BYTE *dataptr=CTX_SEG_OFF_TO_LIN(context, ES_reg(context),EDI_reg(context));
2001 TRACE("GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
2002 BX_reg(context), DX_reg(context));
2003 switch (AL_reg(context)) {
2005 TRACE("\tget general internationalization info\n");
2007 *(WORD*)(dataptr+1) = 41;
2008 *(WORD*)(dataptr+3) = WINE_LanguageId;
2009 *(WORD*)(dataptr+5) = CodePage;
2010 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
2013 TRACE("\tget pointer to collating sequence table\n");
2015 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
2016 CX_reg(context) = 258;/*FIXME: size of table?*/
2019 TRACE("\tunimplemented function %d\n",AL_reg(context));
2020 INT_BARF( context, 0x21 );
2026 case 0x66: /* GLOBAL CODE PAGE TABLE */
2027 switch (AL_reg(context))
2030 TRACE("GET GLOBAL CODE PAGE TABLE\n");
2031 DX_reg(context) = BX_reg(context) = CodePage;
2032 RESET_CFLAG(context);
2035 TRACE("SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
2036 BX_reg(context),DX_reg(context));
2037 CodePage = BX_reg(context);
2038 RESET_CFLAG(context);
2043 case 0x67: /* SET HANDLE COUNT */
2044 TRACE("SET HANDLE COUNT to %d\n",BX_reg(context) );
2045 SetHandleCount16( BX_reg(context) );
2046 if (GetLastError()) bSetDOSExtendedError = TRUE;
2049 case 0x68: /* "FFLUSH" - COMMIT FILE */
2050 case 0x6a: /* COMMIT FILE */
2051 TRACE("FFLUSH/COMMIT handle %d\n",BX_reg(context));
2052 bSetDOSExtendedError = (!FlushFileBuffers( FILE_GetHandle(BX_reg(context)) ));
2055 case 0x69: /* DISK SERIAL NUMBER */
2056 switch (AL_reg(context))
2059 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
2060 INT21_DriveName(BL_reg(context)));
2061 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2062 else AX_reg(context) = 0;
2066 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
2067 INT21_DriveName(BL_reg(context)));
2068 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
2069 else AX_reg(context) = 1;
2074 case 0x6C: /* Extended Open/Create*/
2075 TRACE("EXTENDED OPEN/CREATE %s\n",
2076 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDI_reg(context)));
2077 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2080 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
2081 if ((GetVersion()&0xC0000004)!=0xC0000004) {
2082 /* not supported on anything but Win95 */
2083 TRACE("LONG FILENAME functions supported only by win95\n");
2085 AL_reg(context) = 0;
2087 switch(AL_reg(context))
2089 case 0x39: /* Create directory */
2090 TRACE("LONG FILENAME - MAKE DIRECTORY %s\n",
2091 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2092 bSetDOSExtendedError = (!CreateDirectoryA(
2093 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2094 EDX_reg(context) ), NULL));
2096 case 0x3a: /* Remove directory */
2097 TRACE("LONG FILENAME - REMOVE DIRECTORY %s\n",
2098 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2099 bSetDOSExtendedError = (!RemoveDirectoryA(
2100 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2101 EDX_reg(context) )));
2103 case 0x43: /* Get/Set file attributes */
2104 TRACE("LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
2105 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2106 switch (BL_reg(context))
2108 case 0x00: /* Get file attributes */
2109 TRACE("\tretrieve attributes\n");
2110 CX_reg(context) = (WORD)GetFileAttributesA(
2111 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2113 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
2116 TRACE("\tset attributes 0x%04x\n",CX_reg(context));
2117 bSetDOSExtendedError = (!SetFileAttributesA(
2118 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2120 CX_reg(context) ) );
2123 FIXME("Unimplemented long file name function:\n");
2124 INT_BARF( context, 0x21 );
2126 AL_reg(context) = 0;
2130 case 0x47: /* Get current directory */
2131 TRACE(" LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
2132 INT21_DriveName(DL_reg(context)));
2133 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
2136 case 0x4e: /* Find first file */
2137 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
2138 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2139 /* FIXME: use attributes in CX */
2140 if ((AX_reg(context) = FindFirstFile16(
2141 CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)),
2142 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2144 == INVALID_HANDLE_VALUE16)
2145 bSetDOSExtendedError = TRUE;
2147 case 0x4f: /* Find next file */
2148 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
2150 if (!FindNextFile16( BX_reg(context),
2151 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2153 bSetDOSExtendedError = TRUE;
2155 case 0xa1: /* Find close */
2156 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
2158 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
2161 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
2162 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context),EDX_reg(context)));
2165 switch(CL_reg(context))
2167 case 0x01: /*Get short filename or path */
2168 if (!GetShortPathNameA
2169 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2171 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2172 EDI_reg(context)), 67))
2173 bSetDOSExtendedError = TRUE;
2174 else AX_reg(context) = 0;
2176 case 0x02: /*Get canonical long filename or path */
2177 if (!GetFullPathNameA
2178 ( CTX_SEG_OFF_TO_LIN(context, DS_reg(context),
2179 ESI_reg(context)), 128,
2180 CTX_SEG_OFF_TO_LIN(context, ES_reg(context),
2181 EDI_reg(context)),NULL))
2182 bSetDOSExtendedError = TRUE;
2183 else AX_reg(context) = 0;
2186 FIXME("Unimplemented long file name function:\n");
2187 INT_BARF( context, 0x21 );
2189 AL_reg(context) = 0;
2193 case 0x6c: /* Create or open file */
2194 TRACE("LONG FILENAME - CREATE OR OPEN FILE %s\n",
2195 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), ESI_reg(context)));
2196 /* translate Dos 7 action to Dos 6 action */
2197 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
2200 case 0x3b: /* Change directory */
2201 TRACE("LONG FILENAME - CHANGE DIRECTORY %s\n",
2202 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2203 if (!SetCurrentDirectoryA(CTX_SEG_OFF_TO_LIN(context,
2209 AL_reg(context) = GetLastError();
2212 case 0x41: /* Delete file */
2213 TRACE("LONG FILENAME - DELETE FILE %s\n",
2214 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)));
2215 if (!DeleteFileA(CTX_SEG_OFF_TO_LIN(context,
2220 AL_reg(context) = GetLastError();
2223 case 0x56: /* Move (rename) file */
2224 TRACE("LONG FILENAME - RENAME FILE %s to %s stub\n",
2225 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, DS_reg(context), EDX_reg(context)),
2226 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EDI_reg(context)));
2228 FIXME("Unimplemented long file name function:\n");
2229 INT_BARF( context, 0x21 );
2231 AL_reg(context) = 0;
2236 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
2237 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
2238 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
2239 TRACE("windows95 function AX %04x\n",
2241 WARN(" returning unimplemented\n");
2243 AL_reg(context) = 0;
2246 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
2247 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
2251 INT_BARF( context, 0x21 );
2254 } /* END OF SWITCH */
2256 if( bSetDOSExtendedError ) /* set general error condition */
2258 AX_reg(context) = GetLastError();
2262 if ((EFL_reg(context) & 0x0001))
2263 TRACE("failed, error 0x%04lx\n", GetLastError() );
2265 TRACE("returning: AX=%04x BX=%04x CX=%04x DX=%04x "
2266 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
2267 AX_reg(context), BX_reg(context), CX_reg(context),
2268 DX_reg(context), SI_reg(context), DI_reg(context),
2269 (WORD)DS_reg(context), (WORD)ES_reg(context),
2273 FARPROC16 WINAPI GetSetKernelDOSProc16(FARPROC16 DosProc)
2275 FIXME("(DosProc=0x%08x): stub\n", (UINT)DosProc);