Release 980726
[wine/multimedia.git] / msdos / int21.c
blobb39592fdae3d058d3500cb2820b457af74524a31
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdlib.h>
9 #include <sys/file.h>
10 #include <string.h>
11 #include <sys/stat.h>
12 #include <sys/time.h>
13 #include <sys/types.h>
14 #include <unistd.h>
15 #include <utime.h>
16 #include <ctype.h>
17 #include "windows.h"
18 #include "drive.h"
19 #include "file.h"
20 #include "heap.h"
21 #include "msdos.h"
22 #include "ldt.h"
23 #include "task.h"
24 #include "options.h"
25 #include "miscemu.h"
26 #include "debug.h"
27 #if defined(__svr4__) || defined(_SCO_DS)
28 /* SVR4 DOESNT do locking the same way must implement properly */
29 #define LOCK_EX 0
30 #define LOCK_SH 1
31 #define LOCK_NB 8
32 #endif
35 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
37 /* Define the drive parameter block, as used by int21/1F
38 * and int21/32. This table can be accessed through the
39 * global 'dpb' pointer, which points into the local dos
40 * heap.
42 struct DPB
44 BYTE drive_num; /* 0=A, etc. */
45 BYTE unit_num; /* Drive's unit number (?) */
46 WORD sector_size; /* Sector size in bytes */
47 BYTE high_sector; /* Highest sector in a cluster */
48 BYTE shift; /* Shift count (?) */
49 WORD reserved; /* Number of reserved sectors at start */
50 BYTE num_FAT; /* Number of FATs */
51 WORD dir_entries; /* Number of root dir entries */
52 WORD first_data; /* First data sector */
53 WORD high_cluster; /* Highest cluster number */
54 WORD sectors_in_FAT; /* Number of sectors per FAT */
55 WORD start_dir; /* Starting sector of first dir */
56 DWORD driver_head; /* Address of device driver header (?) */
57 BYTE media_ID; /* Media ID */
58 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
59 DWORD next; /* Pointer to next DPB in list */
60 WORD free_search; /* Free cluster search start */
61 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
64 WORD CodePage = 437;
65 DWORD dpbsegptr;
67 struct DosHeap {
68 BYTE InDosFlag;
69 BYTE mediaID;
70 BYTE biosdate[8];
71 struct DPB dpb;
73 static struct DosHeap *heap;
74 static WORD DosHeapHandle;
76 WORD sharing_retries = 3; /* number of retries at sharing violation */
77 WORD sharing_pause = 1; /* pause between retries */
79 extern char TempDirectory[];
81 static BOOL32 INT21_CreateHeap(void)
83 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
85 WARN(int21, "Out of memory\n");
86 return FALSE;
88 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
89 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
90 heap->InDosFlag = 0;
91 strcpy(heap->biosdate, "01/01/80");
92 return TRUE;
95 static BYTE *GetCurrentDTA(void)
97 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
98 return (BYTE *)PTR_SEG_TO_LIN( pTask->dta );
102 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
103 /* limited == TRUE is used with INT 0x21/0x440d */
105 if (drive > 1) {
106 setword(data, 512);
107 data[2] = 2;
108 setword(&data[3], 0);
109 data[5] = 2;
110 setword(&data[6], 240);
111 setword(&data[8], 64000);
112 data[0x0a] = 0xf8;
113 setword(&data[0x0b], 40);
114 setword(&data[0x0d], 56);
115 setword(&data[0x0f], 2);
116 setword(&data[0x11], 0);
117 if (!limited) {
118 setword(&data[0x1f], 800);
119 data[0x21] = 5;
120 setword(&data[0x22], 1);
122 } else { /* 1.44mb */
123 setword(data, 512);
124 data[2] = 2;
125 setword(&data[3], 0);
126 data[5] = 2;
127 setword(&data[6], 240);
128 setword(&data[8], 2880);
129 data[0x0a] = 0xf8;
130 setword(&data[0x0b], 6);
131 setword(&data[0x0d], 18);
132 setword(&data[0x0f], 2);
133 setword(&data[0x11], 0);
134 if (!limited) {
135 setword(&data[0x1f], 80);
136 data[0x21] = 7;
137 setword(&data[0x22], 2);
142 static int INT21_GetFreeDiskSpace( CONTEXT *context )
144 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
145 char root[] = "A:\\";
147 *root += DOS_GET_DRIVE( DL_reg(context) );
148 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
149 &free_clusters, &total_clusters )) return 0;
150 AX_reg(context) = cluster_sectors;
151 BX_reg(context) = free_clusters;
152 CX_reg(context) = sector_bytes;
153 DX_reg(context) = total_clusters;
154 return 1;
157 static int INT21_GetDriveAllocInfo( CONTEXT *context )
159 if (!INT21_GetFreeDiskSpace( context )) return 0;
160 if (!heap && !INT21_CreateHeap()) return 0;
161 heap->mediaID = 0xf0;
162 DS_reg(context) = DosHeapHandle;
163 BX_reg(context) = (int)&heap->mediaID - (int)heap;
164 return 1;
167 static void GetDrivePB( CONTEXT *context, int drive )
169 if(!DRIVE_IsValid(drive))
171 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
172 AX_reg(context) = 0x00ff;
174 else if (heap || INT21_CreateHeap())
176 FIXME(int21, "GetDrivePB not fully implemented.\n");
178 /* FIXME: I have no idea what a lot of this information should
179 * say or whether it even really matters since we're not allowing
180 * direct block access. However, some programs seem to depend on
181 * getting at least _something_ back from here. The 'next' pointer
182 * does worry me, though. Should we have a complete table of
183 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
185 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
186 heap->dpb.sector_size = 512;
187 heap->dpb.high_sector = 1;
188 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
189 heap->dpb.reserved = 0;
190 heap->dpb.num_FAT = 1;
191 heap->dpb.dir_entries = 2;
192 heap->dpb.first_data = 2;
193 heap->dpb.high_cluster = 64000;
194 heap->dpb.sectors_in_FAT = 1;
195 heap->dpb.start_dir = 1;
196 heap->dpb.driver_head = 0;
197 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
198 heap->dpb.access_flag = 0;
199 heap->dpb.next = 0;
200 heap->dpb.free_search = 0;
201 heap->dpb.free_clusters = 0xFFFF; /* unknown */
203 AL_reg(context) = 0x00;
204 DS_reg(context) = SELECTOROF(dpbsegptr);
205 BX_reg(context) = OFFSETOF(dpbsegptr);
210 static void ioctlGetDeviceInfo( CONTEXT *context )
212 int curr_drive, i;
213 FILE_OBJECT *file;
215 TRACE(int21, "(%d)\n", BX_reg(context));
217 RESET_CFLAG(context);
219 /* DOS device ? */
220 if ((file = FILE_GetFile( BX_reg(context) )))
222 const DOS_DEVICE *dev = DOSFS_GetDevice( file->unix_name );
223 FILE_ReleaseFile( file );
224 if (dev)
226 DX_reg(context) = dev->flags;
227 return;
231 /* it seems to be a file */
232 curr_drive = DRIVE_GetCurrentDrive();
233 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
234 /* no floppy */
235 /* bits 0-5 are current drive
236 * bit 6 - file has NOT been written..FIXME: correct?
237 * bit 8 - generate int24 if no diskspace on write/ read past end of file
238 * bit 11 - media not removable
239 * bit 14 - don't set file date/time on closing
240 * bit 15 - file is remote
244 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
246 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
247 int drive = DOS_GET_DRIVE( BL_reg(context) );
249 if (!DRIVE_IsValid(drive))
251 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
252 return TRUE;
255 if (CH_reg(context) != 0x08)
257 INT_BARF( context, 0x21 );
258 return FALSE;
261 switch (CL_reg(context))
263 case 0x4a: /* lock logical volume */
264 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
265 break;
267 case 0x60: /* get device parameters */
268 /* used by w4wgrp's winfile */
269 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
270 dataptr[0] = 0x04;
271 dataptr[6] = 0; /* media type */
272 if (drive > 1)
274 dataptr[1] = 0x05; /* fixed disk */
275 setword(&dataptr[2], 0x01); /* non removable */
276 setword(&dataptr[4], 0x300); /* # of cylinders */
278 else
280 dataptr[1] = 0x07; /* block dev, floppy */
281 setword(&dataptr[2], 0x02); /* removable */
282 setword(&dataptr[4], 80); /* # of cylinders */
284 CreateBPB(drive, &dataptr[7], TRUE);
285 RESET_CFLAG(context);
286 break;
288 case 0x66:/* get disk serial number */
290 char label[12],fsname[9],path[4];
291 DWORD serial;
293 strcpy(path,"x:\\");path[0]=drive+'A';
294 GetVolumeInformation32A(
295 path,label,12,&serial,NULL,NULL,fsname,9
297 *(WORD*)dataptr = 0;
298 memcpy(dataptr+2,&serial,4);
299 memcpy(dataptr+6,label ,11);
300 memcpy(dataptr+17,fsname,8);
302 break;
304 case 0x6a:
305 TRACE(int21,"logical volume %d unlocked.\n",drive);
306 break;
308 case 0x6f:
309 memset(dataptr+1, '\0', dataptr[0]-1);
310 dataptr[1] = dataptr[0];
311 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
312 dataptr[3] = 0xFF; /* no physical drive */
313 break;
315 default:
316 INT_BARF( context, 0x21 );
318 return FALSE;
321 static void INT21_GetSystemDate( CONTEXT *context )
323 SYSTEMTIME systime;
324 GetLocalTime( &systime );
325 CX_reg(context) = systime.wYear;
326 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
327 AX_reg(context) = systime.wDayOfWeek;
330 static void INT21_GetSystemTime( CONTEXT *context )
332 SYSTEMTIME systime;
333 GetLocalTime( &systime );
334 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
335 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
338 /* Many calls translate a drive argument like this:
339 drive number (00h = default, 01h = A:, etc)
341 static char drivestring[]="default";
343 char *INT21_DriveName(int drive)
346 if(drive >0)
348 drivestring[0]= (unsigned char)drive + '@';
349 drivestring[1]=':';
350 drivestring[2]=0;
352 return drivestring;
354 static BOOL32 INT21_CreateFile( CONTEXT *context )
356 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
357 DX_reg(context) ), CX_reg(context) );
358 return (AX_reg(context) == (WORD)HFILE_ERROR16);
362 static void OpenExistingFile( CONTEXT *context )
364 AX_reg(context) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
365 AL_reg(context) );
366 if (AX_reg(context) == (WORD)HFILE_ERROR16)
368 AX_reg(context) = DOS_ExtendedError;
369 SET_CFLAG(context);
371 #if 0
373 int handle;
374 int mode;
375 int lock;
377 switch (AX_reg(context) & 0x0070)
379 case 0x00: /* compatability mode */
380 case 0x40: /* DENYNONE */
381 lock = -1;
382 break;
384 case 0x30: /* DENYREAD */
385 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
386 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
387 case 0x10: /* DENYALL */
388 lock = LOCK_EX;
389 break;
391 case 0x20: /* DENYWRITE */
392 lock = LOCK_SH;
393 break;
395 default:
396 lock = -1;
399 if (lock != -1)
402 int result,retries=sharing_retries;
404 #if defined(__svr4__) || defined(_SCO_DS)
405 ERR(int21, "Should call flock and needs porting to lockf\n");
406 result = 0;
407 retries = 0;
408 #else
409 result = flock(handle, lock | LOCK_NB);
410 #endif
411 if ( retries && (!result) )
413 int i;
414 for(i=0;i<32768*((int)sharing_pause);i++)
415 result++; /* stop the optimizer */
416 for(i=0;i<32768*((int)sharing_pause);i++)
417 result--;
420 while( (!result) && (!(retries--)) );
422 if(result)
424 errno_to_doserr();
425 AX_reg(context) = DOS_ExtendedError;
426 close(handle);
427 SET_CFLAG(context);
428 return;
433 Error (0,0,0);
434 AX_reg(context) = handle;
435 RESET_CFLAG(context);
437 #endif
440 static void CloseFile( CONTEXT *context )
442 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
444 AX_reg(context) = DOS_ExtendedError;
445 SET_CFLAG(context);
449 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
451 BOOL32 bExtendedError = FALSE;
452 BYTE action = DL_reg(context);
454 /* Shuffle arguments to call OpenExistingFile */
455 AL_reg(context) = BL_reg(context);
456 DX_reg(context) = SI_reg(context);
457 /* BX,CX and DX should be preserved */
458 OpenExistingFile(context);
460 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
462 UINT16 uReturnCX = 0;
464 /* Now decide what do do */
466 if ((action & 0x07) == 0)
468 BX_reg(context) = AX_reg(context);
469 CloseFile(context);
470 AX_reg(context) = 0x0050; /*File exists*/
471 SET_CFLAG(context);
472 WARN(int21, "extended open/create: failed because file exists \n");
474 else if ((action & 0x07) == 2)
476 /* Truncate it, but first check if opened for write */
477 if ((BL_reg(context) & 0x0007)== 0)
479 BX_reg(context) = AX_reg(context);
480 CloseFile(context);
481 WARN(int21, "extended open/create: failed, trunc on ro file\n");
482 AX_reg(context) = 0x000C; /*Access code invalid*/
483 SET_CFLAG(context);
485 else
487 /* Shuffle arguments to call CloseFile while
488 * preserving BX and DX */
490 TRACE(int21, "extended open/create: Closing before truncate\n");
491 BX_reg(context) = AX_reg(context);
492 CloseFile(context);
493 if (EFL_reg(context) & 0x0001)
495 WARN(int21, "extended open/create: close before trunc failed\n");
496 AX_reg(context) = 0x0019; /*Seek Error*/
497 CX_reg(context) = 0;
498 SET_CFLAG(context);
500 /* Shuffle arguments to call CreateFile */
502 TRACE(int21, "extended open/create: Truncating\n");
503 AL_reg(context) = BL_reg(context);
504 /* CX is still the same */
505 DX_reg(context) = SI_reg(context);
506 bExtendedError = INT21_CreateFile(context);
508 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
510 WARN(int21, "extended open/create: trunc failed\n");
511 return bExtendedError;
513 uReturnCX = 0x3;
516 else uReturnCX = 0x1;
518 CX_reg(context) = uReturnCX;
520 else /* file does not exist */
522 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
523 if ((action & 0xF0)== 0)
525 CX_reg(context) = 0;
526 SET_CFLAG(context);
527 WARN(int21, "extended open/create: failed, file dosen't exist\n");
529 else
531 /* Shuffle arguments to call CreateFile */
532 TRACE(int21, "extended open/create: Creating\n");
533 AL_reg(context) = BL_reg(context);
534 /* CX should still be the same */
535 DX_reg(context) = SI_reg(context);
536 bExtendedError = INT21_CreateFile(context);
537 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
539 WARN(int21, "extended open/create: create failed\n");
540 return bExtendedError;
542 CX_reg(context) = 2;
546 return bExtendedError;
550 static BOOL32 INT21_ChangeDir( CONTEXT *context )
552 int drive;
553 char *dirname = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
555 TRACE(int21,"changedir %s\n", dirname);
556 if (dirname[0] && (dirname[1] == ':'))
558 drive = toupper(dirname[0]) - 'A';
559 dirname += 2;
561 else drive = DRIVE_GetCurrentDrive();
562 return DRIVE_Chdir( drive, dirname );
566 static int INT21_FindFirst( CONTEXT *context )
568 char *p;
569 const char *path;
570 DOS_FULL_NAME full_name;
571 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
573 path = (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
574 dta->unixPath = NULL;
575 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
577 AX_reg(context) = DOS_ExtendedError;
578 SET_CFLAG(context);
579 return 0;
581 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
582 p = strrchr( dta->unixPath, '/' );
583 *p = '\0';
585 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
586 * (doesn't matter as it is set below anyway)
588 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
590 HeapFree( GetProcessHeap(), 0, dta->unixPath );
591 dta->unixPath = NULL;
592 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
593 AX_reg(context) = ER_FileNotFound;
594 SET_CFLAG(context);
595 return 0;
597 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
598 : DRIVE_GetCurrentDrive();
599 dta->count = 0;
600 dta->search_attr = CL_reg(context);
601 return 1;
605 static int INT21_FindNext( CONTEXT *context )
607 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
608 WIN32_FIND_DATA32A entry;
609 int count;
611 if (!dta->unixPath) return 0;
612 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
613 dta->search_attr, dta->count, &entry )))
615 HeapFree( GetProcessHeap(), 0, dta->unixPath );
616 dta->unixPath = NULL;
617 return 0;
619 if ((int)dta->count + count > 0xffff)
621 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
622 HeapFree( GetProcessHeap(), 0, dta->unixPath );
623 dta->unixPath = NULL;
624 return 0;
626 dta->count += count;
627 dta->fileattr = entry.dwFileAttributes;
628 dta->filesize = entry.nFileSizeLow;
629 FileTimeToDosDateTime( &entry.ftLastWriteTime,
630 &dta->filedate, &dta->filetime );
631 strcpy( dta->filename, entry.cAlternateFileName );
632 return 1;
636 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
638 static int counter = 0;
639 char *name = PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context) );
640 char *p = name + strlen(name);
642 /* despite what Ralf Brown says, some programs seem to call without
643 * ending backslash (DOS accepts that, so we accept it too) */
644 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
646 for (;;)
648 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
649 counter = (counter + 1) % 1000;
651 if ((AX_reg(context) = _lcreat_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
653 TRACE(int21, "created %s\n", name );
654 return TRUE;
656 if (DOS_ExtendedError != ER_FileExists) return FALSE;
661 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
663 int drive = DOS_GET_DRIVE( DL_reg(context) );
664 char *ptr = (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context), SI_reg(context) );
666 if (!DRIVE_IsValid(drive))
668 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
669 return FALSE;
671 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
672 AX_reg(context) = 0x0100; /* success return code */
673 return TRUE;
677 static int INT21_GetDiskSerialNumber( CONTEXT *context )
679 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
680 int drive = DOS_GET_DRIVE( BL_reg(context) );
682 if (!DRIVE_IsValid(drive))
684 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
685 return 0;
688 *(WORD *)dataptr = 0;
689 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
690 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
691 strncpy(dataptr + 0x11, "FAT16 ", 8);
692 return 1;
696 static int INT21_SetDiskSerialNumber( CONTEXT *context )
698 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
699 int drive = DOS_GET_DRIVE( BL_reg(context) );
701 if (!DRIVE_IsValid(drive))
703 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
704 return 0;
707 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
708 return 1;
712 /* microsoft's programmers should be shot for using CP/M style int21
713 calls in Windows for Workgroup's winfile.exe */
715 static int INT21_FindFirstFCB( CONTEXT *context )
717 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
718 FINDFILE_FCB *pFCB;
719 LPCSTR root, cwd;
720 int drive;
722 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
723 else pFCB = (FINDFILE_FCB *)fcb;
724 drive = DOS_GET_DRIVE( pFCB->drive );
725 root = DRIVE_GetRoot( drive );
726 cwd = DRIVE_GetUnixCwd( drive );
727 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
728 strlen(root)+strlen(cwd)+2 );
729 if (!pFCB->unixPath) return 0;
730 strcpy( pFCB->unixPath, root );
731 strcat( pFCB->unixPath, "/" );
732 strcat( pFCB->unixPath, cwd );
733 pFCB->count = 0;
734 return 1;
738 static int INT21_FindNextFCB( CONTEXT *context )
740 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
741 FINDFILE_FCB *pFCB;
742 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA();
743 WIN32_FIND_DATA32A entry;
744 BYTE attr;
745 int count;
747 if (*fcb == 0xff) /* extended FCB ? */
749 attr = fcb[6];
750 pFCB = (FINDFILE_FCB *)(fcb + 7);
752 else
754 attr = 0;
755 pFCB = (FINDFILE_FCB *)fcb;
758 if (!pFCB->unixPath) return 0;
759 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
760 DOS_GET_DRIVE( pFCB->drive ), attr,
761 pFCB->count, &entry )))
763 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
764 pFCB->unixPath = NULL;
765 return 0;
767 pFCB->count += count;
769 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
770 *(BYTE *)pResult = 0xff;
771 (BYTE *)pResult +=6; /* leave reserved field behind */
772 *(BYTE *)pResult = entry.dwFileAttributes;
773 ((BYTE *)pResult)++;
775 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
776 ((BYTE *)pResult)++;
777 pResult->fileattr = entry.dwFileAttributes;
778 pResult->cluster = 0; /* what else? */
779 pResult->filesize = entry.nFileSizeLow;
780 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
781 FileTimeToDosDateTime( &entry.ftLastWriteTime,
782 &pResult->filedate, &pResult->filetime );
784 /* Convert file name to FCB format */
786 memset( pResult->filename, ' ', sizeof(pResult->filename) );
787 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
788 else if (!strcmp( entry.cAlternateFileName, ".." ))
789 pResult->filename[0] = pResult->filename[1] = '.';
790 else
792 char *p = strrchr( entry.cAlternateFileName, '.' );
793 if (p && p[1] && (p != entry.cAlternateFileName))
795 memcpy( pResult->filename, entry.cAlternateFileName,
796 MIN( (p - entry.cAlternateFileName), 8 ) );
797 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
799 else
800 memcpy( pResult->filename, entry.cAlternateFileName,
801 MIN( strlen(entry.cAlternateFileName), 8 ) );
803 return 1;
807 static void DeleteFileFCB( CONTEXT *context )
809 FIXME(int21, "(%p): not implemented yet\n", context);
812 static void RenameFileFCB( CONTEXT *context )
814 FIXME(int21, "(%p): not implemented yet\n", context);
819 static void fLock( CONTEXT * context )
822 switch ( AX_reg(context) & 0xff )
824 case 0x00: /* LOCK */
825 TRACE(int21,"lock handle %d offset %ld length %ld\n",
826 BX_reg(context),
827 MAKELONG(DX_reg(context),CX_reg(context)),
828 MAKELONG(DI_reg(context),SI_reg(context))) ;
829 if (!LockFile(BX_reg(context),
830 MAKELONG(DX_reg(context),CX_reg(context)), 0,
831 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
832 AX_reg(context) = DOS_ExtendedError;
833 SET_CFLAG(context);
835 break;
837 case 0x01: /* UNLOCK */
838 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
839 BX_reg(context),
840 MAKELONG(DX_reg(context),CX_reg(context)),
841 MAKELONG(DI_reg(context),SI_reg(context))) ;
842 if (!UnlockFile(BX_reg(context),
843 MAKELONG(DX_reg(context),CX_reg(context)), 0,
844 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
845 AX_reg(context) = DOS_ExtendedError;
846 SET_CFLAG(context);
848 return;
849 default:
850 AX_reg(context) = 0x0001;
851 SET_CFLAG(context);
852 return;
856 static BOOL32
857 INT21_networkfunc (CONTEXT *context)
859 switch (AL_reg(context)) {
860 case 0x00: /* Get machine name. */
862 char *dst = PTR_SEG_OFF_TO_LIN (DS_reg(context),DX_reg(context));
863 TRACE(int21, "getting machine name to %p\n", dst);
864 if (gethostname (dst, 15))
866 WARN(int21,"failed!\n");
867 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
868 return TRUE;
869 } else {
870 int len = strlen (dst);
871 while (len < 15)
872 dst[len++] = ' ';
873 dst[15] = 0;
874 CH_reg(context) = 1; /* Valid */
875 CL_reg(context) = 1; /* NETbios number??? */
876 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
877 return FALSE;
881 default:
882 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
883 return TRUE;
888 SEGPTR INT21_GetListOfLists()
890 static DOS_LISTOFLISTS *LOL;
891 static SEGPTR seg_LOL;
894 Output of DOS 6.22:
896 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
897 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
898 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
899 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
900 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
901 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
902 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
903 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
904 0133:00A0 D0 44 C8 FD D0 44 .D...D
906 if (!LOL) {
907 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
909 LOL->CX_Int21_5e01 = 0x0;
910 LOL->LRU_count_FCB_cache = 0x0;
911 LOL->LRU_count_FCB_open = 0x0;
912 LOL->OEM_func_handler = -1; /* not available */
913 LOL->INT21_offset = 0x0;
914 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
915 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
916 LOL->ptr_disk_buf = 0x0;
917 LOL->offs_unread_CON = 0x0;
918 LOL->seg_first_MCB = 0x0;
919 LOL->ptr_first_DPB = 0x0;
920 LOL->ptr_first_SysFileTable = 0x0;
921 LOL->ptr_clock_dev_hdr = 0x0;
922 LOL->ptr_CON_dev_hdr = 0x0;
923 LOL->max_byte_per_sec = 512;
924 LOL->ptr_disk_buf_info = 0x0;
925 LOL->ptr_array_CDS = 0x0;
926 LOL->ptr_sys_FCB = 0x0;
927 LOL->nr_protect_FCB = 0x0;
928 LOL->nr_block_dev = 0x0;
929 LOL->nr_avail_drive_letters = 26; /* A - Z */
930 LOL->nr_drives_JOINed = 0x0;
931 LOL->ptr_spec_prg_names = 0x0;
932 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
933 LOL->DOS_HIGH_A20_func_offs = 0x0;
934 LOL->PSP_last_exec = 0x0;
935 LOL->BUFFERS_val = 99; /* maximum: 99 */
936 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
937 LOL->boot_drive = 3; /* C: */
938 LOL->flag_DWORD_moves = 0x01; /* i386+ */
939 LOL->size_extended_mem = 0xf000; /* very high value */
941 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
942 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
945 /***********************************************************************
946 * DOS3Call (KERNEL.102)
948 void WINAPI DOS3Call( CONTEXT *context )
950 BOOL32 bSetDOSExtendedError = FALSE;
952 #if 0
953 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
954 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
955 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
956 SI_reg(context), DI_reg(context),
957 (WORD)DS_reg(context), (WORD)ES_reg(context),
958 EFL_reg(context) );
959 #endif
961 if (AH_reg(context) == 0x59) /* Get extended error info */
963 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
964 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
965 AX_reg(context) = DOS_ExtendedError;
966 BH_reg(context) = DOS_ErrorClass;
967 BL_reg(context) = DOS_ErrorAction;
968 CH_reg(context) = DOS_ErrorLocus;
969 return;
972 DOS_ERROR( 0, 0, 0, 0 );
973 RESET_CFLAG(context); /* Not sure if this is a good idea */
975 switch(AH_reg(context))
977 case 0x00: /* TERMINATE PROGRAM */
978 TRACE(int21,"TERMINATE PROGRAM\n");
979 TASK_KillCurrentTask( 0 );
980 break;
982 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
983 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
984 case 0x03: /* READ CHARACTER FROM STDAUX */
985 case 0x04: /* WRITE CHARACTER TO STDAUX */
986 case 0x05: /* WRITE CHARACTER TO PRINTER */
987 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
988 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
989 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
990 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
991 case 0x0a: /* BUFFERED INPUT */
992 case 0x0b: /* GET STDIN STATUS */
993 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
994 case 0x0f: /* OPEN FILE USING FCB */
995 case 0x10: /* CLOSE FILE USING FCB */
996 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
997 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
998 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
999 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
1000 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
1001 case 0x23: /* GET FILE SIZE FOR FCB */
1002 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
1003 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
1004 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
1005 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
1006 case 0x29: /* PARSE FILENAME INTO FCB */
1007 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
1008 "SWITCHAR" - SET SWITCH CHARACTER
1009 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
1010 case 0x54: /* GET VERIFY FLAG */
1011 case 0x48: /* ALLOCATE MEMORY */
1012 case 0x49: /* FREE MEMORY */
1013 case 0x4a: /* RESIZE MEMORY BLOCK */
1014 INT_BARF( context, 0x21 );
1015 break;
1016 case 0x2e: /* SET VERIFY FLAG */
1017 TRACE(int21,"SET VERIFY FLAG ignored\n");
1018 /* we cannot change the behaviour anyway, so just ignore it */
1019 break;
1021 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1022 case 0x1d:
1023 case 0x1e:
1024 case 0x20:
1025 case 0x6b: /* NULL FUNCTION */
1026 AL_reg(context) = 0;
1027 break;
1029 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1030 fLock(context);
1031 break;
1033 case 0x0d: /* DISK BUFFER FLUSH */
1034 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1035 RESET_CFLAG(context); /* dos 6+ only */
1036 break;
1038 case 0x0e: /* SELECT DEFAULT DRIVE */
1039 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1040 DRIVE_SetCurrentDrive( DL_reg(context) );
1041 AL_reg(context) = MAX_DOS_DRIVES;
1042 break;
1044 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1045 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1046 PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context)));
1047 if (!INT21_FindFirstFCB(context))
1049 AL_reg(context) = 0xff;
1050 break;
1052 /* else fall through */
1054 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1055 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1056 break;
1058 case 0x13: /* DELETE FILE USING FCB */
1059 DeleteFileFCB(context);
1060 break;
1062 case 0x17: /* RENAME FILE USING FCB */
1063 RenameFileFCB(context);
1064 break;
1066 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1067 AL_reg(context) = DRIVE_GetCurrentDrive();
1068 break;
1070 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1072 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1073 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1074 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1076 break;
1078 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1079 DL_reg(context) = 0;
1080 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1081 break;
1083 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1084 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1085 break;
1087 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1088 GetDrivePB(context, DRIVE_GetCurrentDrive());
1089 break;
1091 case 0x25: /* SET INTERRUPT VECTOR */
1092 INT_SetHandler( AL_reg(context),
1093 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1094 DX_reg(context)));
1095 break;
1097 case 0x2a: /* GET SYSTEM DATE */
1098 INT21_GetSystemDate(context);
1099 break;
1101 case 0x2b: /* SET SYSTEM DATE */
1102 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1103 DL_reg(context), DH_reg(context), CX_reg(context) );
1104 AL_reg(context) = 0; /* Let's pretend we succeeded */
1105 break;
1107 case 0x2c: /* GET SYSTEM TIME */
1108 INT21_GetSystemTime(context);
1109 break;
1111 case 0x2d: /* SET SYSTEM TIME */
1112 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1113 CH_reg(context), CL_reg(context),
1114 DH_reg(context), DL_reg(context) );
1115 AL_reg(context) = 0; /* Let's pretend we succeeded */
1116 break;
1118 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1119 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1121 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1122 ES_reg(context) = SELECTOROF( pTask->dta );
1123 BX_reg(context) = OFFSETOF( pTask->dta );
1125 break;
1127 case 0x30: /* GET DOS VERSION */
1128 TRACE(int21,"GET DOS VERSION %s requested\n",
1129 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1130 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1131 (HIWORD(GetVersion16()) << 8);
1132 BX_reg(context) = 0x0012; /* 0x123456 is Wine's serial # */
1133 CX_reg(context) = 0x3456;
1134 break;
1136 case 0x31: /* TERMINATE AND STAY RESIDENT */
1137 TRACE(int21,"TERMINATE AND STAY RESIDENT stub\n");
1138 INT_BARF( context, 0x21 );
1139 break;
1141 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1142 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1143 INT21_DriveName( DL_reg(context)));
1144 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1145 break;
1147 case 0x33: /* MULTIPLEXED */
1148 switch (AL_reg(context))
1150 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1151 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1152 DL_reg(context) = 0;
1153 break;
1155 case 0x01: /* SET EXTENDED BREAK STATE */
1156 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1157 break;
1159 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1160 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1161 DL_reg(context) = 0;
1162 break;
1164 case 0x05: /* GET BOOT DRIVE */
1165 TRACE(int21,"GET BOOT DRIVE\n");
1166 DL_reg(context) = 3;
1167 /* c: is Wine's bootdrive (a: is 1)*/
1168 break;
1170 case 0x06: /* GET TRUE VERSION NUMBER */
1171 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1172 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1173 (HIWORD(GetVersion16() << 8));
1174 DX_reg(context) = 0x00;
1175 break;
1177 default:
1178 INT_BARF( context, 0x21 );
1179 break;
1181 break;
1183 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1184 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1185 if (!heap) INT21_CreateHeap();
1186 ES_reg(context) = DosHeapHandle;
1187 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1188 break;
1190 case 0x35: /* GET INTERRUPT VECTOR */
1191 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1193 FARPROC16 addr = INT_GetHandler( AL_reg(context) );
1194 ES_reg(context) = SELECTOROF(addr);
1195 BX_reg(context) = OFFSETOF(addr);
1197 break;
1199 case 0x36: /* GET FREE DISK SPACE */
1200 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1201 INT21_DriveName( DL_reg(context)));
1202 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1203 break;
1205 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1206 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1207 AL_reg(context));
1208 AX_reg(context) = 0x02; /* no country support available */
1209 SET_CFLAG(context);
1210 break;
1212 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1213 TRACE(int21,"MKDIR %s\n",
1214 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1215 bSetDOSExtendedError = (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1216 DX_reg(context) ), NULL));
1217 break;
1219 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1220 TRACE(int21,"RMDIR %s\n",
1221 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1222 bSetDOSExtendedError = (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1223 DX_reg(context) )));
1224 break;
1226 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1227 TRACE(int21,"CHDIR %s\n",
1228 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1229 bSetDOSExtendedError = !INT21_ChangeDir(context);
1230 break;
1232 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1233 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1234 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1235 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1236 DX_reg(context) ), CX_reg(context) );
1237 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1238 break;
1240 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1241 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1242 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1243 OpenExistingFile(context);
1244 break;
1246 case 0x3e: /* "CLOSE" - CLOSE FILE */
1247 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1248 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1249 break;
1251 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1252 TRACE(int21,"READ from %d to %ld for %d byte\n",BX_reg(context),
1253 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),DX_reg(context)),CX_reg(context) );
1255 LONG result = WIN16_hread( BX_reg(context),
1256 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1257 DX_reg(context) ),
1258 CX_reg(context) );
1259 if (result == -1) bSetDOSExtendedError = TRUE;
1260 else AX_reg(context) = (WORD)result;
1262 break;
1264 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1265 TRACE(int21,"WRITE from %ld to handle %d for %d byte\n",
1266 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),DX_reg(context)),
1267 BX_reg(context),CX_reg(context) );
1269 LONG result = _hwrite16( BX_reg(context),
1270 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1271 DX_reg(context) ),
1272 CX_reg(context) );
1273 if (result == -1) bSetDOSExtendedError = TRUE;
1274 else AX_reg(context) = (WORD)result;
1276 break;
1278 case 0x41: /* "UNLINK" - DELETE FILE */
1279 TRACE(int21,"UNLINK%s\n",
1280 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1281 bSetDOSExtendedError = (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1282 DX_reg(context) )));
1283 break;
1285 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1286 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1287 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1288 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1289 "current file position":"end of file");
1291 LONG status = _llseek16( BX_reg(context),
1292 MAKELONG(DX_reg(context),CX_reg(context)),
1293 AL_reg(context) );
1294 if (status == -1) bSetDOSExtendedError = TRUE;
1295 else
1297 AX_reg(context) = LOWORD(status);
1298 DX_reg(context) = HIWORD(status);
1301 break;
1303 case 0x43: /* FILE ATTRIBUTES */
1304 switch (AL_reg(context))
1306 case 0x00:
1307 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1308 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1309 AX_reg(context) = (WORD)GetFileAttributes32A(
1310 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1311 DX_reg(context)));
1312 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1313 else CX_reg(context) = AX_reg(context);
1314 break;
1316 case 0x01:
1317 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1318 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1319 bSetDOSExtendedError =
1320 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1321 DX_reg(context)),
1322 CX_reg(context) ));
1323 break;
1324 case 0x02:
1325 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1326 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1328 break;
1330 case 0x44: /* IOCTL */
1331 switch (AL_reg(context))
1333 case 0x00:
1334 ioctlGetDeviceInfo(context);
1335 break;
1337 case 0x01:
1338 break;
1339 case 0x02:{
1340 FILE_OBJECT *file;
1341 file = FILE_GetFile(BX_reg(context));
1342 if (!strcasecmp(file->unix_name, "SCSIMGR$"))
1343 ASPI_DOS_HandleInt(context);
1344 FILE_ReleaseFile( file );
1345 break;
1347 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1348 /*BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));*/
1349 int drive = DOS_GET_DRIVE(BL_reg(context));
1351 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1352 /* for (i=0;i<CX_reg(context);i++)
1353 fprintf(stdnimp,"%02x ",dataptr[i]);
1354 fprintf(stdnimp,"\n");*/
1355 AX_reg(context)=CX_reg(context);
1356 break;
1358 case 0x08: /* Check if drive is removable. */
1359 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1360 INT21_DriveName( BL_reg(context)));
1361 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1363 case DRIVE_CANNOTDETERMINE:
1364 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1365 AX_reg(context) = ER_InvalidDrive;
1366 SET_CFLAG(context);
1367 break;
1368 case DRIVE_REMOVABLE:
1369 AX_reg(context) = 0; /* removable */
1370 break;
1371 default:
1372 AX_reg(context) = 1; /* not removable */
1373 break;
1375 break;
1377 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1378 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1379 INT21_DriveName( BL_reg(context)));
1380 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1382 case DRIVE_CANNOTDETERMINE:
1383 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1384 AX_reg(context) = ER_InvalidDrive;
1385 SET_CFLAG(context);
1386 break;
1387 case DRIVE_REMOTE:
1388 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1389 break;
1390 default:
1391 DX_reg(context) = 0; /* FIXME: use driver attr here */
1392 break;
1394 break;
1396 case 0x0a: /* check if handle (BX) is remote */
1397 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1398 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1399 * not set on close
1401 DX_reg(context) = 0;
1402 break;
1404 case 0x0b: /* SET SHARING RETRY COUNT */
1405 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1406 CX_reg(context), DX_reg(context));
1407 if (!CX_reg(context))
1409 AX_reg(context) = 1;
1410 SET_CFLAG(context);
1411 break;
1413 sharing_pause = CX_reg(context);
1414 if (!DX_reg(context))
1415 sharing_retries = DX_reg(context);
1416 RESET_CFLAG(context);
1417 break;
1419 case 0x0d:
1420 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1421 INT21_DriveName( BL_reg(context)));
1422 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1423 break;
1425 case 0x0e: /* get logical drive mapping */
1426 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1427 INT21_DriveName( BL_reg(context)));
1428 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1429 break;
1431 case 0x0F: /* Set logical drive mapping */
1433 int drive;
1434 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1435 INT21_DriveName( BL_reg(context)));
1436 drive = DOS_GET_DRIVE ( BL_reg(context) );
1437 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1439 SET_CFLAG(context);
1440 AX_reg(context) = 0x000F; /* invalid drive */
1442 break;
1445 default:
1446 INT_BARF( context, 0x21 );
1447 break;
1449 break;
1451 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1452 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1453 bSetDOSExtendedError = ((AX_reg(context) = FILE_Dup(BX_reg(context))) == (WORD)HFILE_ERROR16);
1454 break;
1456 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1457 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1458 BX_reg(context),CX_reg(context));
1459 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR32);
1460 break;
1462 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1463 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1464 INT21_DriveName( DL_reg(context)));
1465 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1466 break;
1468 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1469 TRACE(int21,"EXEC %s\n",
1470 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context) ));
1471 AX_reg(context) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1472 DX_reg(context) ),
1473 SW_NORMAL );
1474 if (AX_reg(context) < 32) SET_CFLAG(context);
1475 break;
1477 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1478 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1479 TASK_KillCurrentTask( AL_reg(context) );
1480 break;
1482 case 0x4d: /* GET RETURN CODE */
1483 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1484 AX_reg(context) = 0; /* normal exit */
1485 break;
1487 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1488 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1489 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1490 if (!INT21_FindFirst(context)) break;
1491 /* fall through */
1493 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1494 TRACE(int21,"FINDNEXT\n");
1495 if (!INT21_FindNext(context))
1497 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1498 AX_reg(context) = ER_NoMoreFiles;
1499 SET_CFLAG(context);
1501 else AX_reg(context) = 0; /* OK */
1502 break;
1504 case 0x51: /* GET PSP ADDRESS */
1505 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1506 /* FIXME: should we return the original DOS PSP upon */
1507 /* Windows startup ? */
1508 BX_reg(context) = GetCurrentPDB();
1509 break;
1510 case 0x62: /* GET PSP ADDRESS */
1511 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1512 /* FIXME: should we return the original DOS PSP upon */
1513 /* Windows startup ? */
1514 BX_reg(context) = GetCurrentPDB();
1515 break;
1517 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1518 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1520 SEGPTR lol;
1521 lol = INT21_GetListOfLists();
1522 ES_reg(context) = HIWORD(lol);
1523 BX_reg(context) = LOWORD(lol);
1525 break;
1527 case 0x56: /* "RENAME" - RENAME FILE */
1528 TRACE(int21,"RENAME %s to %s\n",
1529 (LPCSTR)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1530 (LPCSTR)PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context)));
1531 bSetDOSExtendedError =
1532 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1533 PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context))));
1534 break;
1536 case 0x57: /* FILE DATE AND TIME */
1537 switch (AL_reg(context))
1539 case 0x00: /* Get */
1541 FILETIME filetime;
1542 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1543 BX_reg(context));
1544 if (!GetFileTime( BX_reg(context), NULL, NULL, &filetime ))
1545 bSetDOSExtendedError = TRUE;
1546 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1547 &CX_reg(context) );
1549 break;
1551 case 0x01: /* Set */
1553 FILETIME filetime;
1554 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1555 BX_reg(context));
1556 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1557 &filetime );
1558 bSetDOSExtendedError =
1559 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1561 break;
1563 break;
1565 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1566 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1567 AL_reg(context));
1568 switch (AL_reg(context))
1570 case 0x00:
1571 AX_reg(context) = 1;
1572 break;
1573 case 0x02:
1574 AX_reg(context) = 0;
1575 break;
1576 case 0x01:
1577 case 0x03:
1578 break;
1580 RESET_CFLAG(context);
1581 break;
1583 case 0x5a: /* CREATE TEMPORARY FILE */
1584 TRACE(int21,"CREATE TEMPORARY FILE\n");
1585 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1586 break;
1588 case 0x5b: /* CREATE NEW FILE */
1589 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1590 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1591 bSetDOSExtendedError = ((AX_reg(context) =
1592 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)), 0 ))
1593 == (WORD)HFILE_ERROR16);
1594 break;
1596 case 0x5d: /* NETWORK */
1597 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1598 /* Fix the following while you're at it. */
1599 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1600 bSetDOSExtendedError = TRUE;
1601 break;
1603 case 0x5e:
1604 bSetDOSExtendedError = INT21_networkfunc (context);
1605 break;
1607 case 0x5f: /* NETWORK */
1608 switch (AL_reg(context))
1610 case 0x07: /* ENABLE DRIVE */
1611 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1612 if (!DRIVE_Enable( DL_reg(context) ))
1614 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1615 bSetDOSExtendedError = TRUE;
1617 break;
1619 case 0x08: /* DISABLE DRIVE */
1620 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1621 if (!DRIVE_Disable( DL_reg(context) ))
1623 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1624 bSetDOSExtendedError = TRUE;
1626 break;
1628 default:
1629 /* network software not installed */
1630 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1631 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1632 bSetDOSExtendedError = TRUE;
1633 break;
1635 break;
1637 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1638 TRACE(int21,"TRUENAME %s\n",
1639 (LPCSTR)PTR_SEG_OFF_TO_LIN(DS_reg(context),SI_reg(context)));
1641 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1642 SI_reg(context)), 128,
1643 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1644 DI_reg(context)),NULL))
1645 bSetDOSExtendedError = TRUE;
1646 else AX_reg(context) = 0;
1648 break;
1650 case 0x61: /* UNUSED */
1651 case 0x63: /* UNUSED */
1652 case 0x64: /* OS/2 DOS BOX */
1653 INT_BARF( context, 0x21 );
1654 SET_CFLAG(context);
1655 break;
1657 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1658 extern WORD WINE_LanguageId;
1659 BYTE *dataptr=PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context));
1660 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1661 BX_reg(context), DX_reg(context));
1662 switch (AL_reg(context)) {
1663 case 0x01:
1664 TRACE(int21,"\tget general internationalization info\n");
1665 dataptr[0] = 0x1;
1666 *(WORD*)(dataptr+1) = 41;
1667 *(WORD*)(dataptr+3) = WINE_LanguageId;
1668 *(WORD*)(dataptr+5) = CodePage;
1669 *(DWORD*)(dataptr+0x19) = 0; /* FIXME: ptr to case map routine */
1670 break;
1671 case 0x06:
1672 TRACE(int21,"\tget pointer to collating sequence table\n");
1673 dataptr[0] = 0x06;
1674 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1675 CX_reg(context) = 258;/*FIXME: size of table?*/
1676 break;
1677 default:
1678 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1679 INT_BARF( context, 0x21 );
1680 SET_CFLAG(context);
1681 break;
1683 break;
1685 case 0x66: /* GLOBAL CODE PAGE TABLE */
1686 switch (AL_reg(context))
1688 case 0x01:
1689 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1690 DX_reg(context) = BX_reg(context) = CodePage;
1691 RESET_CFLAG(context);
1692 break;
1693 case 0x02:
1694 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1695 BX_reg(context),DX_reg(context));
1696 CodePage = BX_reg(context);
1697 RESET_CFLAG(context);
1698 break;
1700 break;
1702 case 0x67: /* SET HANDLE COUNT */
1703 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1704 SetHandleCount16( BX_reg(context) );
1705 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1706 break;
1708 case 0x68: /* "FFLUSH" - COMMIT FILE */
1709 case 0x6a: /* COMMIT FILE */
1710 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
1711 bSetDOSExtendedError = (!FlushFileBuffers( BX_reg(context) ));
1712 break;
1714 case 0x69: /* DISK SERIAL NUMBER */
1715 switch (AL_reg(context))
1717 case 0x00:
1718 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
1719 INT21_DriveName(BL_reg(context)));
1720 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1721 else AX_reg(context) = 0;
1722 break;
1724 case 0x01:
1725 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
1726 INT21_DriveName(BL_reg(context)));
1727 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1728 else AX_reg(context) = 1;
1729 break;
1731 break;
1733 case 0x6C: /* Extended Open/Create*/
1734 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
1735 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DI_reg(context)));
1736 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1737 break;
1739 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1740 switch(AL_reg(context))
1742 case 0x39: /* Create directory */
1743 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
1744 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1745 bSetDOSExtendedError = (!CreateDirectory32A(
1746 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1747 DX_reg(context) ), NULL));
1748 break;
1749 case 0x3a: /* Remove directory */
1750 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1751 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1752 bSetDOSExtendedError = (!RemoveDirectory32A(
1753 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1754 DX_reg(context) )));
1755 break;
1756 case 0x43: /* Get/Set file attributes */
1757 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1758 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1759 switch (BL_reg(context))
1761 case 0x00: /* Get file attributes */
1762 TRACE(int21,"\tretrieve attributes\n");
1763 CX_reg(context) = (WORD)GetFileAttributes32A(
1764 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1765 DX_reg(context)));
1766 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1767 break;
1768 case 0x01:
1769 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
1770 bSetDOSExtendedError = (!SetFileAttributes32A(
1771 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1772 DX_reg(context)),
1773 CX_reg(context) ) );
1774 break;
1775 default:
1776 FIXME(int21, "Unimplemented long file name function:\n");
1777 INT_BARF( context, 0x21 );
1778 SET_CFLAG(context);
1779 AL_reg(context) = 0;
1780 break;
1782 break;
1783 case 0x47: /* Get current directory */
1784 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1785 INT21_DriveName(DL_reg(context)));
1786 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1787 break;
1789 case 0x4e: /* Find first file */
1790 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1791 (LPCSTR)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
1792 /* FIXME: use attributes in CX */
1793 if ((AX_reg(context) = FindFirstFile16(
1794 PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1795 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1796 DI_reg(context))))
1797 == INVALID_HANDLE_VALUE16)
1798 bSetDOSExtendedError = TRUE;
1799 break;
1800 case 0x4f: /* Find next file */
1801 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1802 BX_reg(context));
1803 if (!FindNextFile16( BX_reg(context),
1804 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1805 DI_reg(context))))
1806 bSetDOSExtendedError = TRUE;
1807 break;
1808 case 0xa1: /* Find close */
1809 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
1810 BX_reg(context));
1811 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1812 break;
1813 case 0xa0:
1814 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
1815 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1816 break;
1817 case 0x60:
1818 switch(CL_reg(context))
1820 case 0x02: /*Get canonical long filename or path */
1821 if (!GetFullPathName32A
1822 ( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1823 SI_reg(context)), 128,
1824 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1825 DI_reg(context)),NULL))
1826 bSetDOSExtendedError = TRUE;
1827 else AX_reg(context) = 0;
1828 break;
1829 default:
1830 FIXME(int21, "Unimplemented long file name function:\n");
1831 INT_BARF( context, 0x21 );
1832 SET_CFLAG(context);
1833 AL_reg(context) = 0;
1834 break;
1836 break;
1837 case 0x6c: /* Create or open file */
1838 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
1839 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), SI_reg(context)));
1840 /* translate Dos 7 action to Dos 6 action */
1841 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1842 break;
1844 case 0x3b: /* Change directory */
1845 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
1846 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1847 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1848 DS_reg(context),
1849 DX_reg(context)
1852 SET_CFLAG(context);
1853 AL_reg(context) = DOS_ExtendedError;
1855 break;
1856 case 0x41: /* Delete file */
1857 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
1858 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1859 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1860 DS_reg(context),
1861 DX_reg(context))
1862 )) {
1863 SET_CFLAG(context);
1864 AL_reg(context) = DOS_ExtendedError;
1866 break;
1867 case 0x56: /* Move (rename) file */
1868 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
1869 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)),
1870 (LPCSTR)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context)));
1871 default:
1872 FIXME(int21, "Unimplemented long file name function:\n");
1873 INT_BARF( context, 0x21 );
1874 SET_CFLAG(context);
1875 AL_reg(context) = 0;
1876 break;
1878 break;
1880 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1881 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1882 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1883 TRACE(int21,"windows95 function AX %04x\n",
1884 AX_reg(context));
1885 WARN(int21, " returning unimplemented\n");
1886 SET_CFLAG(context);
1887 AL_reg(context) = 0;
1888 break;
1890 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1891 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1892 break;
1894 default:
1895 INT_BARF( context, 0x21 );
1896 break;
1898 } /* END OF SWITCH */
1900 if( bSetDOSExtendedError ) /* set general error condition */
1902 AX_reg(context) = DOS_ExtendedError;
1903 SET_CFLAG(context);
1906 if ((EFL_reg(context) & 0x0001))
1907 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1908 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1910 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1911 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1912 AX_reg(context), BX_reg(context), CX_reg(context),
1913 DX_reg(context), SI_reg(context), DI_reg(context),
1914 (WORD)DS_reg(context), (WORD)ES_reg(context),
1915 EFL_reg(context));
1918 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
1920 FIXME(int21, "(DosProc=%08x);\n", (UINT32)DosProc);
1921 return NULL;