Release 980503
[wine.git] / msdos / int21.c
blob5ccf18faf3aae7478f41425a1560493ba4f4cc5a
1 /*
2 * DOS interrupt 21h handler
3 */
5 #include <time.h>
6 #include <fcntl.h>
7 #include <errno.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <sys/file.h>
11 #include <string.h>
12 #include <sys/stat.h>
13 #include <sys/time.h>
14 #include <sys/types.h>
15 #include <unistd.h>
16 #include <utime.h>
17 #include <ctype.h>
18 #include "windows.h"
19 #include "drive.h"
20 #include "file.h"
21 #include "heap.h"
22 #include "msdos.h"
23 #include "ldt.h"
24 #include "task.h"
25 #include "options.h"
26 #include "miscemu.h"
27 #include "debug.h"
28 #if defined(__svr4__) || defined(_SCO_DS)
29 /* SVR4 DOESNT do locking the same way must implement properly */
30 #define LOCK_EX 0
31 #define LOCK_SH 1
32 #define LOCK_NB 8
33 #endif
36 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
38 /* Define the drive parameter block, as used by int21/1F
39 * and int21/32. This table can be accessed through the
40 * global 'dpb' pointer, which points into the local dos
41 * heap.
43 struct DPB
45 BYTE drive_num; /* 0=A, etc. */
46 BYTE unit_num; /* Drive's unit number (?) */
47 WORD sector_size; /* Sector size in bytes */
48 BYTE high_sector; /* Highest sector in a cluster */
49 BYTE shift; /* Shift count (?) */
50 WORD reserved; /* Number of reserved sectors at start */
51 BYTE num_FAT; /* Number of FATs */
52 WORD dir_entries; /* Number of root dir entries */
53 WORD first_data; /* First data sector */
54 WORD high_cluster; /* Highest cluster number */
55 WORD sectors_in_FAT; /* Number of sectors per FAT */
56 WORD start_dir; /* Starting sector of first dir */
57 DWORD driver_head; /* Address of device driver header (?) */
58 BYTE media_ID; /* Media ID */
59 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
60 DWORD next; /* Pointer to next DPB in list */
61 WORD free_search; /* Free cluster search start */
62 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
65 WORD CodePage = 437;
66 DWORD dpbsegptr;
68 struct DosHeap {
69 BYTE InDosFlag;
70 BYTE mediaID;
71 BYTE biosdate[8];
72 struct DPB dpb;
74 static struct DosHeap *heap;
75 static WORD DosHeapHandle;
77 WORD sharing_retries = 3; /* number of retries at sharing violation */
78 WORD sharing_pause = 1; /* pause between retries */
80 extern char TempDirectory[];
82 static BOOL32 INT21_CreateHeap(void)
84 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
86 WARN(int21, "Out of memory\n");
87 return FALSE;
89 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
90 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
91 heap->InDosFlag = 0;
92 strcpy(heap->biosdate, "01/01/80");
93 return TRUE;
96 static BYTE *GetCurrentDTA(void)
98 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
99 return (BYTE *)PTR_SEG_TO_LIN( pTask->dta );
103 void CreateBPB(int drive, BYTE *data, BOOL16 limited)
104 /* limited == TRUE is used with INT 0x21/0x440d */
106 if (drive > 1) {
107 setword(data, 512);
108 data[2] = 2;
109 setword(&data[3], 0);
110 data[5] = 2;
111 setword(&data[6], 240);
112 setword(&data[8], 64000);
113 data[0x0a] = 0xf8;
114 setword(&data[0x0b], 40);
115 setword(&data[0x0d], 56);
116 setword(&data[0x0f], 2);
117 setword(&data[0x11], 0);
118 if (!limited) {
119 setword(&data[0x1f], 800);
120 data[0x21] = 5;
121 setword(&data[0x22], 1);
123 } else { /* 1.44mb */
124 setword(data, 512);
125 data[2] = 2;
126 setword(&data[3], 0);
127 data[5] = 2;
128 setword(&data[6], 240);
129 setword(&data[8], 2880);
130 data[0x0a] = 0xf8;
131 setword(&data[0x0b], 6);
132 setword(&data[0x0d], 18);
133 setword(&data[0x0f], 2);
134 setword(&data[0x11], 0);
135 if (!limited) {
136 setword(&data[0x1f], 80);
137 data[0x21] = 7;
138 setword(&data[0x22], 2);
143 static int INT21_GetFreeDiskSpace( CONTEXT *context )
145 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
146 char root[] = "A:\\";
148 *root += DOS_GET_DRIVE( DL_reg(context) );
149 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
150 &free_clusters, &total_clusters )) return 0;
151 AX_reg(context) = cluster_sectors;
152 BX_reg(context) = free_clusters;
153 CX_reg(context) = sector_bytes;
154 DX_reg(context) = total_clusters;
155 return 1;
158 static int INT21_GetDriveAllocInfo( CONTEXT *context )
160 if (!INT21_GetFreeDiskSpace( context )) return 0;
161 if (!heap && !INT21_CreateHeap()) return 0;
162 heap->mediaID = 0xf0;
163 DS_reg(context) = DosHeapHandle;
164 BX_reg(context) = (int)&heap->mediaID - (int)heap;
165 return 1;
168 static void GetDrivePB( CONTEXT *context, int drive )
170 if(!DRIVE_IsValid(drive))
172 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
173 AX_reg(context) = 0x00ff;
175 else if (heap || INT21_CreateHeap())
177 FIXME(int21, "GetDrivePB not fully implemented.\n");
179 /* FIXME: I have no idea what a lot of this information should
180 * say or whether it even really matters since we're not allowing
181 * direct block access. However, some programs seem to depend on
182 * getting at least _something_ back from here. The 'next' pointer
183 * does worry me, though. Should we have a complete table of
184 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
186 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
187 heap->dpb.sector_size = 512;
188 heap->dpb.high_sector = 1;
189 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
190 heap->dpb.reserved = 0;
191 heap->dpb.num_FAT = 1;
192 heap->dpb.dir_entries = 2;
193 heap->dpb.first_data = 2;
194 heap->dpb.high_cluster = 64000;
195 heap->dpb.sectors_in_FAT = 1;
196 heap->dpb.start_dir = 1;
197 heap->dpb.driver_head = 0;
198 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
199 heap->dpb.access_flag = 0;
200 heap->dpb.next = 0;
201 heap->dpb.free_search = 0;
202 heap->dpb.free_clusters = 0xFFFF; /* unknown */
204 AL_reg(context) = 0x00;
205 DS_reg(context) = SELECTOROF(dpbsegptr);
206 BX_reg(context) = OFFSETOF(dpbsegptr);
211 static void ioctlGetDeviceInfo( CONTEXT *context )
213 int curr_drive;
214 TRACE(int21, "(%d)\n", BX_reg(context));
216 curr_drive = DRIVE_GetCurrentDrive();
217 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0);
218 /* no floppy */
219 /* bits 0-5 are current drive
220 * bit 6 - file has NOT been written..FIXME: correct?
221 * bit 8 - generate int24 if no diskspace on write/ read past end of file
222 * bit 11 - media not removable
223 * bit 14 - don't set file date/time on closing
224 * bit 15 - file is remote
226 RESET_CFLAG(context);
229 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
231 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
232 int drive = DOS_GET_DRIVE( BL_reg(context) );
234 if (!DRIVE_IsValid(drive))
236 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
237 return TRUE;
240 if (CH_reg(context) != 0x08)
242 INT_BARF( context, 0x21 );
243 return FALSE;
246 switch (CL_reg(context))
248 case 0x4a: /* lock logical volume */
249 TRACE(int21,"lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
250 break;
252 case 0x60: /* get device parameters */
253 /* used by w4wgrp's winfile */
254 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
255 dataptr[0] = 0x04;
256 dataptr[6] = 0; /* media type */
257 if (drive > 1)
259 dataptr[1] = 0x05; /* fixed disk */
260 setword(&dataptr[2], 0x01); /* non removable */
261 setword(&dataptr[4], 0x300); /* # of cylinders */
263 else
265 dataptr[1] = 0x07; /* block dev, floppy */
266 setword(&dataptr[2], 0x02); /* removable */
267 setword(&dataptr[4], 80); /* # of cylinders */
269 CreateBPB(drive, &dataptr[7], TRUE);
270 RESET_CFLAG(context);
271 break;
273 case 0x66:/* get disk serial number */
275 char label[12],fsname[9],path[4];
276 DWORD serial;
278 strcpy(path,"x:\\");path[0]=drive+'A';
279 GetVolumeInformation32A(
280 path,label,12,&serial,NULL,NULL,fsname,9
282 *(WORD*)dataptr = 0;
283 memcpy(dataptr+2,&serial,4);
284 memcpy(dataptr+6,label ,11);
285 memcpy(dataptr+17,fsname,8);
287 break;
289 case 0x6a:
290 TRACE(int21,"logical volume %d unlocked.\n",drive);
291 break;
293 default:
294 INT_BARF( context, 0x21 );
296 return FALSE;
299 static void INT21_GetSystemDate( CONTEXT *context )
301 SYSTEMTIME systime;
302 GetLocalTime( &systime );
303 CX_reg(context) = systime.wYear;
304 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
305 AX_reg(context) = systime.wDayOfWeek;
308 static void INT21_GetSystemTime( CONTEXT *context )
310 SYSTEMTIME systime;
311 GetLocalTime( &systime );
312 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
313 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
316 /* Many calls translate a drive argument like this:
317 drive number (00h = default, 01h = A:, etc)
319 static char drivestring[]="default";
321 char *INT21_DriveName(int drive)
324 if(drive >0)
326 drivestring[0]= (unsigned char)drive + '@';
327 drivestring[1]=':';
328 drivestring[2]=0;
330 return drivestring;
332 static BOOL32 INT21_CreateFile( CONTEXT *context )
334 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
335 DX_reg(context) ), CX_reg(context) );
336 return (AX_reg(context) == (WORD)HFILE_ERROR16);
340 static void OpenExistingFile( CONTEXT *context )
342 AX_reg(context) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
343 AL_reg(context) );
344 if (AX_reg(context) == (WORD)HFILE_ERROR16)
346 AX_reg(context) = DOS_ExtendedError;
347 SET_CFLAG(context);
349 #if 0
351 int handle;
352 int mode;
353 int lock;
355 switch (AX_reg(context) & 0x0070)
357 case 0x00: /* compatability mode */
358 case 0x40: /* DENYNONE */
359 lock = -1;
360 break;
362 case 0x30: /* DENYREAD */
363 TRACE(int21, "(%s): DENYREAD changed to DENYALL\n",
364 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
365 case 0x10: /* DENYALL */
366 lock = LOCK_EX;
367 break;
369 case 0x20: /* DENYWRITE */
370 lock = LOCK_SH;
371 break;
373 default:
374 lock = -1;
377 if (lock != -1)
380 int result,retries=sharing_retries;
382 #if defined(__svr4__) || defined(_SCO_DS)
383 ERR(int21, "Should call flock and needs porting to lockf\n");
384 result = 0;
385 retries = 0;
386 #else
387 result = flock(handle, lock | LOCK_NB);
388 #endif
389 if ( retries && (!result) )
391 int i;
392 for(i=0;i<32768*((int)sharing_pause);i++)
393 result++; /* stop the optimizer */
394 for(i=0;i<32768*((int)sharing_pause);i++)
395 result--;
398 while( (!result) && (!(retries--)) );
400 if(result)
402 errno_to_doserr();
403 AX_reg(context) = DOS_ExtendedError;
404 close(handle);
405 SET_CFLAG(context);
406 return;
411 Error (0,0,0);
412 AX_reg(context) = handle;
413 RESET_CFLAG(context);
415 #endif
418 static void CloseFile( CONTEXT *context )
420 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
422 AX_reg(context) = DOS_ExtendedError;
423 SET_CFLAG(context);
427 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
429 BOOL32 bExtendedError = FALSE;
430 BYTE action = DL_reg(context);
432 /* Shuffle arguments to call OpenExistingFile */
433 AL_reg(context) = BL_reg(context);
434 DX_reg(context) = SI_reg(context);
435 /* BX,CX and DX should be preserved */
436 OpenExistingFile(context);
438 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
440 UINT16 uReturnCX = 0;
442 /* Now decide what do do */
444 if ((action & 0x07) == 0)
446 BX_reg(context) = AX_reg(context);
447 CloseFile(context);
448 AX_reg(context) = 0x0050; /*File exists*/
449 SET_CFLAG(context);
450 WARN(int21, "extended open/create: failed because file exists \n");
452 else if ((action & 0x07) == 2)
454 /* Truncate it, but first check if opened for write */
455 if ((BL_reg(context) & 0x0007)== 0)
457 BX_reg(context) = AX_reg(context);
458 CloseFile(context);
459 WARN(int21, "extended open/create: failed, trunc on ro file\n");
460 AX_reg(context) = 0x000C; /*Access code invalid*/
461 SET_CFLAG(context);
463 else
465 /* Shuffle arguments to call CloseFile while
466 * preserving BX and DX */
468 TRACE(int21, "extended open/create: Closing before truncate\n");
469 BX_reg(context) = AX_reg(context);
470 CloseFile(context);
471 if (EFL_reg(context) & 0x0001)
473 WARN(int21, "extended open/create: close before trunc failed\n");
474 AX_reg(context) = 0x0019; /*Seek Error*/
475 CX_reg(context) = 0;
476 SET_CFLAG(context);
478 /* Shuffle arguments to call CreateFile */
480 TRACE(int21, "extended open/create: Truncating\n");
481 AL_reg(context) = BL_reg(context);
482 /* CX is still the same */
483 DX_reg(context) = SI_reg(context);
484 bExtendedError = INT21_CreateFile(context);
486 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
488 WARN(int21, "extended open/create: trunc failed\n");
489 return bExtendedError;
491 uReturnCX = 0x3;
494 else uReturnCX = 0x1;
496 CX_reg(context) = uReturnCX;
498 else /* file does not exist */
500 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
501 if ((action & 0xF0)== 0)
503 CX_reg(context) = 0;
504 SET_CFLAG(context);
505 WARN(int21, "extended open/create: failed, file dosen't exist\n");
507 else
509 /* Shuffle arguments to call CreateFile */
510 TRACE(int21, "extended open/create: Creating\n");
511 AL_reg(context) = BL_reg(context);
512 /* CX should still be the same */
513 DX_reg(context) = SI_reg(context);
514 bExtendedError = INT21_CreateFile(context);
515 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
517 WARN(int21, "extended open/create: create failed\n");
518 return bExtendedError;
520 CX_reg(context) = 2;
524 return bExtendedError;
528 static BOOL32 INT21_ChangeDir( CONTEXT *context )
530 int drive;
531 char *dirname = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
533 TRACE(int21,"changedir %s\n", dirname);
534 if (dirname[0] && (dirname[1] == ':'))
536 drive = toupper(dirname[0]) - 'A';
537 dirname += 2;
539 else drive = DRIVE_GetCurrentDrive();
540 return DRIVE_Chdir( drive, dirname );
544 static int INT21_FindFirst( CONTEXT *context )
546 char *p;
547 const char *path;
548 DOS_FULL_NAME full_name;
549 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
551 path = (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
552 dta->unixPath = NULL;
553 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
555 AX_reg(context) = DOS_ExtendedError;
556 SET_CFLAG(context);
557 return 0;
559 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
560 p = strrchr( dta->unixPath, '/' );
561 *p = '\0';
563 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
564 * (doesn't matter as it is set below anyway)
566 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
568 HeapFree( GetProcessHeap(), 0, dta->unixPath );
569 dta->unixPath = NULL;
570 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
571 AX_reg(context) = ER_FileNotFound;
572 SET_CFLAG(context);
573 return 0;
575 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
576 : DRIVE_GetCurrentDrive();
577 dta->count = 0;
578 dta->search_attr = CL_reg(context);
579 return 1;
583 static int INT21_FindNext( CONTEXT *context )
585 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
586 WIN32_FIND_DATA32A entry;
587 int count;
589 if (!dta->unixPath) return 0;
590 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
591 dta->search_attr, dta->count, &entry )))
593 HeapFree( GetProcessHeap(), 0, dta->unixPath );
594 dta->unixPath = NULL;
595 return 0;
597 if ((int)dta->count + count > 0xffff)
599 WARN(int21, "Too many directory entries in %s\n", dta->unixPath );
600 HeapFree( GetProcessHeap(), 0, dta->unixPath );
601 dta->unixPath = NULL;
602 return 0;
604 dta->count += count;
605 dta->fileattr = entry.dwFileAttributes;
606 dta->filesize = entry.nFileSizeLow;
607 FileTimeToDosDateTime( &entry.ftLastWriteTime,
608 &dta->filedate, &dta->filetime );
609 strcpy( dta->filename, entry.cAlternateFileName );
610 return 1;
614 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
616 static int counter = 0;
617 char *name = PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context) );
618 char *p = name + strlen(name);
620 /* despite what Ralf Brown says, some programs seem to call without
621 * ending backslash (DOS accepts that, so we accept it too) */
622 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
624 for (;;)
626 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
627 counter = (counter + 1) % 1000;
629 if ((AX_reg(context) = _lcreat_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
631 TRACE(int21, "created %s\n", name );
632 return TRUE;
634 if (DOS_ExtendedError != ER_FileExists) return FALSE;
639 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
641 int drive = DOS_GET_DRIVE( DL_reg(context) );
642 char *ptr = (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context), SI_reg(context) );
644 if (!DRIVE_IsValid(drive))
646 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
647 return FALSE;
649 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
650 AX_reg(context) = 0x0100; /* success return code */
651 return TRUE;
655 static int INT21_GetDiskSerialNumber( CONTEXT *context )
657 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
658 int drive = DOS_GET_DRIVE( BL_reg(context) );
660 if (!DRIVE_IsValid(drive))
662 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
663 return 0;
666 *(WORD *)dataptr = 0;
667 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
668 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
669 strncpy(dataptr + 0x11, "FAT16 ", 8);
670 return 1;
674 static int INT21_SetDiskSerialNumber( CONTEXT *context )
676 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
677 int drive = DOS_GET_DRIVE( BL_reg(context) );
679 if (!DRIVE_IsValid(drive))
681 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
682 return 0;
685 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
686 return 1;
690 /* microsoft's programmers should be shot for using CP/M style int21
691 calls in Windows for Workgroup's winfile.exe */
693 static int INT21_FindFirstFCB( CONTEXT *context )
695 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
696 FINDFILE_FCB *pFCB;
697 LPCSTR root, cwd;
698 int drive;
700 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
701 else pFCB = (FINDFILE_FCB *)fcb;
702 drive = DOS_GET_DRIVE( pFCB->drive );
703 root = DRIVE_GetRoot( drive );
704 cwd = DRIVE_GetUnixCwd( drive );
705 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
706 strlen(root)+strlen(cwd)+2 );
707 if (!pFCB->unixPath) return 0;
708 strcpy( pFCB->unixPath, root );
709 strcat( pFCB->unixPath, "/" );
710 strcat( pFCB->unixPath, cwd );
711 pFCB->count = 0;
712 return 1;
716 static int INT21_FindNextFCB( CONTEXT *context )
718 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
719 FINDFILE_FCB *pFCB;
720 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA();
721 WIN32_FIND_DATA32A entry;
722 BYTE attr;
723 int count;
725 if (*fcb == 0xff) /* extended FCB ? */
727 attr = fcb[6];
728 pFCB = (FINDFILE_FCB *)(fcb + 7);
730 else
732 attr = 0;
733 pFCB = (FINDFILE_FCB *)fcb;
736 if (!pFCB->unixPath) return 0;
737 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
738 DOS_GET_DRIVE( pFCB->drive ), attr,
739 pFCB->count, &entry )))
741 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
742 pFCB->unixPath = NULL;
743 return 0;
745 pFCB->count += count;
747 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
748 *(BYTE *)pResult = 0xff;
749 (BYTE *)pResult +=6; /* leave reserved field behind */
750 *(BYTE *)pResult = entry.dwFileAttributes;
751 ((BYTE *)pResult)++;
753 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
754 ((BYTE *)pResult)++;
755 pResult->fileattr = entry.dwFileAttributes;
756 pResult->cluster = 0; /* what else? */
757 pResult->filesize = entry.nFileSizeLow;
758 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
759 FileTimeToDosDateTime( &entry.ftLastWriteTime,
760 &pResult->filedate, &pResult->filetime );
762 /* Convert file name to FCB format */
764 memset( pResult->filename, ' ', sizeof(pResult->filename) );
765 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
766 else if (!strcmp( entry.cAlternateFileName, ".." ))
767 pResult->filename[0] = pResult->filename[1] = '.';
768 else
770 char *p = strrchr( entry.cAlternateFileName, '.' );
771 if (p && p[1] && (p != entry.cAlternateFileName))
773 memcpy( pResult->filename, entry.cAlternateFileName,
774 MIN( (p - entry.cAlternateFileName), 8 ) );
775 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
777 else
778 memcpy( pResult->filename, entry.cAlternateFileName,
779 MIN( strlen(entry.cAlternateFileName), 8 ) );
781 return 1;
785 static void DeleteFileFCB( CONTEXT *context )
787 FIXME(int21, "(%p): not implemented yet\n", context);
790 static void RenameFileFCB( CONTEXT *context )
792 FIXME(int21, "(%p): not implemented yet\n", context);
797 static void fLock( CONTEXT * context )
800 switch ( AX_reg(context) & 0xff )
802 case 0x00: /* LOCK */
803 TRACE(int21,"lock handle %d offset %ld length %ld\n",
804 BX_reg(context),
805 MAKELONG(DX_reg(context),CX_reg(context)),
806 MAKELONG(DI_reg(context),SI_reg(context))) ;
807 if (!LockFile(BX_reg(context),
808 MAKELONG(DX_reg(context),CX_reg(context)), 0,
809 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
810 AX_reg(context) = DOS_ExtendedError;
811 SET_CFLAG(context);
813 break;
815 case 0x01: /* UNLOCK */
816 TRACE(int21,"unlock handle %d offset %ld length %ld\n",
817 BX_reg(context),
818 MAKELONG(DX_reg(context),CX_reg(context)),
819 MAKELONG(DI_reg(context),SI_reg(context))) ;
820 if (!UnlockFile(BX_reg(context),
821 MAKELONG(DX_reg(context),CX_reg(context)), 0,
822 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
823 AX_reg(context) = DOS_ExtendedError;
824 SET_CFLAG(context);
826 return;
827 default:
828 AX_reg(context) = 0x0001;
829 SET_CFLAG(context);
830 return;
834 static BOOL32
835 INT21_networkfunc (CONTEXT *context)
837 switch (AL_reg(context)) {
838 case 0x00: /* Get machine name. */
840 char *dst = PTR_SEG_OFF_TO_LIN (DS_reg(context),DX_reg(context));
841 TRACE(int21, "getting machine name to %p\n", dst);
842 if (gethostname (dst, 15))
844 WARN(int21,"failed!\n");
845 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
846 return TRUE;
847 } else {
848 int len = strlen (dst);
849 while (len < 15)
850 dst[len++] = ' ';
851 dst[15] = 0;
852 CH_reg(context) = 1; /* Valid */
853 CL_reg(context) = 1; /* NETbios number??? */
854 TRACE(int21, "returning %s\n", debugstr_an (dst, 16));
855 return FALSE;
859 default:
860 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
861 return TRUE;
866 SEGPTR INT21_GetListOfLists()
868 static DOS_LISTOFLISTS *LOL;
869 static SEGPTR seg_LOL;
872 Output of DOS 6.22:
874 0133:0020 6A 13-33 01 CC 00 33 01 59 00 j.3...3.Y.
875 0133:0030 70 00 00 00 72 02 00 02-6D 00 33 01 00 00 2E 05 p...r...m.3.....
876 0133:0040 00 00 FC 04 00 00 03 08-92 21 11 E0 04 80 C6 0D .........!......
877 0133:0050 CC 0D 4E 55 4C 20 20 20-20 20 00 00 00 00 00 00 ..NUL ......
878 0133:0060 00 4B BA C1 06 14 00 00-00 03 01 00 04 70 CE FF .K...........p..
879 0133:0070 FF 00 00 00 00 00 00 00-00 01 00 00 0D 05 00 00 ................
880 0133:0080 00 FF FF 00 00 00 00 FE-00 00 F8 03 FF 9F 70 02 ..............p.
881 0133:0090 D0 44 C8 FD D4 44 C8 FD-D4 44 C8 FD D0 44 C8 FD .D...D...D...D..
882 0133:00A0 D0 44 C8 FD D0 44 .D...D
884 if (!LOL) {
885 LOL = SEGPTR_ALLOC(sizeof(DOS_LISTOFLISTS));
887 LOL->CX_Int21_5e01 = 0x0;
888 LOL->LRU_count_FCB_cache = 0x0;
889 LOL->LRU_count_FCB_open = 0x0;
890 LOL->OEM_func_handler = -1; /* not available */
891 LOL->INT21_offset = 0x0;
892 LOL->sharing_retry_count = sharing_retries; /* default value: 3 */
893 LOL->sharing_retry_delay = sharing_pause; /* default value: 1 */
894 LOL->ptr_disk_buf = 0x0;
895 LOL->offs_unread_CON = 0x0;
896 LOL->seg_first_MCB = 0x0;
897 LOL->ptr_first_DPB = 0x0;
898 LOL->ptr_first_SysFileTable = 0x0;
899 LOL->ptr_clock_dev_hdr = 0x0;
900 LOL->ptr_CON_dev_hdr = 0x0;
901 LOL->max_byte_per_sec = 512;
902 LOL->ptr_disk_buf_info = 0x0;
903 LOL->ptr_array_CDS = 0x0;
904 LOL->ptr_sys_FCB = 0x0;
905 LOL->nr_protect_FCB = 0x0;
906 LOL->nr_block_dev = 0x0;
907 LOL->nr_avail_drive_letters = 26; /* A - Z */
908 LOL->nr_drives_JOINed = 0x0;
909 LOL->ptr_spec_prg_names = 0x0;
910 LOL->ptr_SETVER_prg_list = 0x0; /* no SETVER list */
911 LOL->DOS_HIGH_A20_func_offs = 0x0;
912 LOL->PSP_last_exec = 0x0;
913 LOL->BUFFERS_val = 99; /* maximum: 99 */
914 LOL->BUFFERS_nr_lookahead = 8; /* maximum: 8 */
915 LOL->boot_drive = 3; /* C: */
916 LOL->flag_DWORD_moves = 0x01; /* i386+ */
917 LOL->size_extended_mem = 0xf000; /* very high value */
919 if (!seg_LOL) seg_LOL = SEGPTR_GET(LOL);
920 return seg_LOL+(WORD)&((DOS_LISTOFLISTS*)0)->ptr_first_DPB;
924 extern void LOCAL_PrintHeap (WORD ds);
926 /***********************************************************************
927 * DOS3Call (KERNEL.102)
929 void WINAPI DOS3Call( CONTEXT *context )
931 BOOL32 bSetDOSExtendedError = FALSE;
933 #if 0
934 TRACE(int21, "AX=%04x BX=%04x CX=%04x DX=%04x "
935 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
936 AX_reg(context), BX_reg(context), CX_reg(context), DX_reg(context),
937 SI_reg(context), DI_reg(context),
938 (WORD)DS_reg(context), (WORD)ES_reg(context),
939 EFL_reg(context) );
940 #endif
942 if (AH_reg(context) == 0x59) /* Get extended error info */
944 TRACE(int21, "GET EXTENDED ERROR code 0x%02x class 0x%02x action 0x%02x locus %02x\n",
945 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
946 AX_reg(context) = DOS_ExtendedError;
947 BH_reg(context) = DOS_ErrorClass;
948 BL_reg(context) = DOS_ErrorAction;
949 CH_reg(context) = DOS_ErrorLocus;
950 return;
953 DOS_ERROR( 0, 0, 0, 0 );
954 RESET_CFLAG(context); /* Not sure if this is a good idea */
956 switch(AH_reg(context))
958 case 0x00: /* TERMINATE PROGRAM */
959 TRACE(int21,"TERMINATE PROGRAM\n");
960 TASK_KillCurrentTask( 0 );
961 break;
963 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
964 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
965 case 0x03: /* READ CHARACTER FROM STDAUX */
966 case 0x04: /* WRITE CHARACTER TO STDAUX */
967 case 0x05: /* WRITE CHARACTER TO PRINTER */
968 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
969 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
970 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
971 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
972 case 0x0a: /* BUFFERED INPUT */
973 case 0x0b: /* GET STDIN STATUS */
974 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
975 case 0x0f: /* OPEN FILE USING FCB */
976 case 0x10: /* CLOSE FILE USING FCB */
977 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
978 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
979 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
980 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
981 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
982 case 0x23: /* GET FILE SIZE FOR FCB */
983 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
984 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
985 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
986 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
987 case 0x29: /* PARSE FILENAME INTO FCB */
988 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
989 "SWITCHAR" - SET SWITCH CHARACTER
990 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
991 case 0x54: /* GET VERIFY FLAG */
992 case 0x48: /* ALLOCATE MEMORY */
993 case 0x49: /* FREE MEMORY */
994 case 0x4a: /* RESIZE MEMORY BLOCK */
995 INT_BARF( context, 0x21 );
996 break;
997 case 0x2e: /* SET VERIFY FLAG */
998 TRACE(int21,"SET VERIFY FLAG ignored\n");
999 /* we cannot change the behaviour anyway, so just ignore it */
1000 break;
1002 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
1003 case 0x1d:
1004 case 0x1e:
1005 case 0x20:
1006 case 0x6b: /* NULL FUNCTION */
1007 AL_reg(context) = 0;
1008 break;
1010 case 0x5c: /* "FLOCK" - RECORD LOCKING */
1011 fLock(context);
1012 break;
1014 case 0x0d: /* DISK BUFFER FLUSH */
1015 TRACE(int21,"DISK BUFFER FLUSH ignored\n");
1016 RESET_CFLAG(context); /* dos 6+ only */
1017 break;
1019 case 0x0e: /* SELECT DEFAULT DRIVE */
1020 TRACE(int21,"SELECT DEFAULT DRIVE %d\n", DL_reg(context));
1021 DRIVE_SetCurrentDrive( DL_reg(context) );
1022 AL_reg(context) = MAX_DOS_DRIVES;
1023 break;
1025 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
1026 TRACE(int21,"FIND FIRST MATCHING FILE USING FCB %p\n",
1027 PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context)));
1028 if (!INT21_FindFirstFCB(context))
1030 AL_reg(context) = 0xff;
1031 break;
1033 /* else fall through */
1035 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
1036 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
1037 break;
1039 case 0x13: /* DELETE FILE USING FCB */
1040 DeleteFileFCB(context);
1041 break;
1043 case 0x17: /* RENAME FILE USING FCB */
1044 RenameFileFCB(context);
1045 break;
1047 case 0x19: /* GET CURRENT DEFAULT DRIVE */
1048 AL_reg(context) = DRIVE_GetCurrentDrive();
1049 break;
1051 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
1053 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1054 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
1055 TRACE(int21, "Set DTA: %08lx\n", pTask->dta);
1057 break;
1059 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
1060 DL_reg(context) = 0;
1061 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1062 break;
1064 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
1065 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
1066 break;
1068 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
1069 GetDrivePB(context, DRIVE_GetCurrentDrive());
1070 break;
1072 case 0x25: /* SET INTERRUPT VECTOR */
1073 INT_SetHandler( AL_reg(context),
1074 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1075 DX_reg(context)));
1076 break;
1078 case 0x2a: /* GET SYSTEM DATE */
1079 INT21_GetSystemDate(context);
1080 break;
1082 case 0x2b: /* SET SYSTEM DATE */
1083 FIXME(int21, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
1084 DL_reg(context), DH_reg(context), CX_reg(context) );
1085 AL_reg(context) = 0; /* Let's pretend we succeeded */
1086 break;
1088 case 0x2c: /* GET SYSTEM TIME */
1089 INT21_GetSystemTime(context);
1090 break;
1092 case 0x2d: /* SET SYSTEM TIME */
1093 FIXME(int21, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
1094 CH_reg(context), CL_reg(context),
1095 DH_reg(context), DL_reg(context) );
1096 AL_reg(context) = 0; /* Let's pretend we succeeded */
1097 break;
1099 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
1100 TRACE(int21,"GET DISK TRANSFER AREA ADDRESS\n");
1102 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
1103 ES_reg(context) = SELECTOROF( pTask->dta );
1104 BX_reg(context) = OFFSETOF( pTask->dta );
1106 break;
1108 case 0x30: /* GET DOS VERSION */
1109 TRACE(int21,"GET DOS VERSION %s requested\n",
1110 (AL_reg(context) == 0x00)?"OEM number":"version flag");
1111 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
1112 (HIWORD(GetVersion16()) << 8);
1113 BX_reg(context) = 0x0012; /* 0x123456 is Wine's serial # */
1114 CX_reg(context) = 0x3456;
1115 break;
1117 case 0x31: /* TERMINATE AND STAY RESIDENT */
1118 TRACE(int21,"TERMINATE AND STAY RESIDENT stub\n");
1119 INT_BARF( context, 0x21 );
1120 break;
1122 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
1123 TRACE(int21,"GET DOS DRIVE PARAMETER BLOCK FOR DRIVE %s\n",
1124 INT21_DriveName( DL_reg(context)));
1125 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
1126 break;
1128 case 0x33: /* MULTIPLEXED */
1129 switch (AL_reg(context))
1131 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
1132 TRACE(int21,"GET CURRENT EXTENDED BREAK STATE stub\n");
1133 DL_reg(context) = 0;
1134 break;
1136 case 0x01: /* SET EXTENDED BREAK STATE */
1137 TRACE(int21,"SET CURRENT EXTENDED BREAK STATE stub\n");
1138 break;
1140 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1141 TRACE(int21,"GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE stub\n");
1142 DL_reg(context) = 0;
1143 break;
1145 case 0x05: /* GET BOOT DRIVE */
1146 TRACE(int21,"GET BOOT DRIVE\n");
1147 DL_reg(context) = 3;
1148 /* c: is Wine's bootdrive (a: is 1)*/
1149 break;
1151 case 0x06: /* GET TRUE VERSION NUMBER */
1152 TRACE(int21,"GET TRUE VERSION NUMBER\n");
1153 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1154 (HIWORD(GetVersion16() << 8));
1155 DX_reg(context) = 0x00;
1156 break;
1158 default:
1159 INT_BARF( context, 0x21 );
1160 break;
1162 break;
1164 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1165 TRACE(int21,"GET ADDRESS OF INDOS FLAG\n");
1166 if (!heap) INT21_CreateHeap();
1167 ES_reg(context) = DosHeapHandle;
1168 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1169 break;
1171 case 0x35: /* GET INTERRUPT VECTOR */
1172 TRACE(int21,"GET INTERRUPT VECTOR 0x%02x\n",AL_reg(context));
1174 FARPROC16 addr = INT_GetHandler( AL_reg(context) );
1175 ES_reg(context) = SELECTOROF(addr);
1176 BX_reg(context) = OFFSETOF(addr);
1178 break;
1180 case 0x36: /* GET FREE DISK SPACE */
1181 TRACE(int21,"GET FREE DISK SPACE FOR DRIVE %s\n",
1182 INT21_DriveName( DL_reg(context)));
1183 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1184 break;
1186 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1187 TRACE(int21,"GET COUNTRY-SPECIFIC INFORMATION for country 0x%02x\n",
1188 AL_reg(context));
1189 AX_reg(context) = 0x02; /* no country support available */
1190 SET_CFLAG(context);
1191 break;
1193 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1194 TRACE(int21,"MKDIR %s\n",
1195 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1196 bSetDOSExtendedError = (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1197 DX_reg(context) ), NULL));
1198 break;
1200 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1201 TRACE(int21,"RMDIR %s\n",
1202 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1203 bSetDOSExtendedError = (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1204 DX_reg(context) )));
1205 break;
1207 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1208 TRACE(int21,"CHDIR %s\n",
1209 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1210 bSetDOSExtendedError = !INT21_ChangeDir(context);
1211 break;
1213 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1214 TRACE(int21,"CREAT flag 0x%02x %s\n",CX_reg(context),
1215 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1216 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1217 DX_reg(context) ), CX_reg(context) );
1218 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1219 break;
1221 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1222 TRACE(int21,"OPEN mode 0x%02x %s\n",AL_reg(context),
1223 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1224 OpenExistingFile(context);
1225 break;
1227 case 0x3e: /* "CLOSE" - CLOSE FILE */
1228 TRACE(int21,"CLOSE handle %d\n",BX_reg(context));
1229 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1230 break;
1232 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1233 TRACE(int21,"READ from %d to %ld for %d byte\n",BX_reg(context),
1234 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),DX_reg(context)),CX_reg(context) );
1236 LONG result = WIN16_hread( BX_reg(context),
1237 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1238 DX_reg(context) ),
1239 CX_reg(context) );
1240 if (result == -1) bSetDOSExtendedError = TRUE;
1241 else AX_reg(context) = (WORD)result;
1243 break;
1245 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1246 TRACE(int21,"WRITE from %ld to handle %d for %d byte\n",
1247 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),DX_reg(context)),
1248 BX_reg(context),CX_reg(context) );
1250 LONG result = _hwrite16( BX_reg(context),
1251 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1252 DX_reg(context) ),
1253 CX_reg(context) );
1254 if (result == -1) bSetDOSExtendedError = TRUE;
1255 else AX_reg(context) = (WORD)result;
1257 break;
1259 case 0x41: /* "UNLINK" - DELETE FILE */
1260 TRACE(int21,"UNLINK%s\n",
1261 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1262 bSetDOSExtendedError = (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1263 DX_reg(context) )));
1264 break;
1266 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1267 TRACE(int21,"LSEEK handle %d offset %ld from %s\n",
1268 BX_reg(context), MAKELONG(DX_reg(context),CX_reg(context)),
1269 (AL_reg(context)==0)?"start of file":(AL_reg(context)==1)?
1270 "current file position":"end of file");
1272 LONG status = _llseek16( BX_reg(context),
1273 MAKELONG(DX_reg(context),CX_reg(context)),
1274 AL_reg(context) );
1275 if (status == -1) bSetDOSExtendedError = TRUE;
1276 else
1278 AX_reg(context) = LOWORD(status);
1279 DX_reg(context) = HIWORD(status);
1282 break;
1284 case 0x43: /* FILE ATTRIBUTES */
1285 switch (AL_reg(context))
1287 case 0x00:
1288 TRACE(int21,"GET FILE ATTRIBUTES for %s\n",
1289 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1290 AX_reg(context) = (WORD)GetFileAttributes32A(
1291 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1292 DX_reg(context)));
1293 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1294 else CX_reg(context) = AX_reg(context);
1295 break;
1297 case 0x01:
1298 TRACE(int21,"SET FILE ATTRIBUTES 0x%02x for %s\n", CX_reg(context),
1299 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1300 bSetDOSExtendedError =
1301 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1302 DX_reg(context)),
1303 CX_reg(context) ));
1304 break;
1305 case 0x02:
1306 TRACE(int21,"GET COMPRESSED FILE SIZE for %s stub\n",
1307 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1309 break;
1311 case 0x44: /* IOCTL */
1312 switch (AL_reg(context))
1314 case 0x00:
1315 ioctlGetDeviceInfo(context);
1316 break;
1318 case 0x01:
1319 break;
1320 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1321 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
1322 int drive = DOS_GET_DRIVE(BL_reg(context));
1324 FIXME(int21,"program tried to write to block device control channel of drive %d:\n",drive);
1325 /* for (i=0;i<CX_reg(context);i++)
1326 fprintf(stdnimp,"%02x ",dataptr[i]);
1327 fprintf(stdnimp,"\n");*/
1328 AX_reg(context)=CX_reg(context);
1329 break;
1331 case 0x08: /* Check if drive is removable. */
1332 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOVABLE for drive %s\n",
1333 INT21_DriveName( BL_reg(context)));
1334 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1336 case DRIVE_CANNOTDETERMINE:
1337 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1338 AX_reg(context) = ER_InvalidDrive;
1339 SET_CFLAG(context);
1340 break;
1341 case DRIVE_REMOVABLE:
1342 AX_reg(context) = 0; /* removable */
1343 break;
1344 default:
1345 AX_reg(context) = 1; /* not removable */
1346 break;
1348 break;
1350 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1351 TRACE(int21,"IOCTL - CHECK IF BLOCK DEVICE REMOTE for drive %s\n",
1352 INT21_DriveName( BL_reg(context)));
1353 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1355 case DRIVE_CANNOTDETERMINE:
1356 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1357 AX_reg(context) = ER_InvalidDrive;
1358 SET_CFLAG(context);
1359 break;
1360 case DRIVE_REMOTE:
1361 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1362 break;
1363 default:
1364 DX_reg(context) = 0; /* FIXME: use driver attr here */
1365 break;
1367 break;
1369 case 0x0a: /* check if handle (BX) is remote */
1370 TRACE(int21,"IOCTL - CHECK IF HANDLE %d IS REMOTE\n",BX_reg(context));
1371 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1372 * not set on close
1374 DX_reg(context) = 0;
1375 break;
1377 case 0x0b: /* SET SHARING RETRY COUNT */
1378 TRACE(int21,"IOCTL - SET SHARING RETRY COUNT pause %d retries %d\n",
1379 CX_reg(context), DX_reg(context));
1380 if (!CX_reg(context))
1382 AX_reg(context) = 1;
1383 SET_CFLAG(context);
1384 break;
1386 sharing_pause = CX_reg(context);
1387 if (!DX_reg(context))
1388 sharing_retries = DX_reg(context);
1389 RESET_CFLAG(context);
1390 break;
1392 case 0x0d:
1393 TRACE(int21,"IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
1394 INT21_DriveName( BL_reg(context)));
1395 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1396 break;
1398 case 0x0e: /* get logical drive mapping */
1399 TRACE(int21,"IOCTL - GET LOGICAL DRIVE MAP for drive %s\n",
1400 INT21_DriveName( BL_reg(context)));
1401 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1402 break;
1404 case 0x0F: /* Set logical drive mapping */
1406 int drive;
1407 TRACE(int21,"IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
1408 INT21_DriveName( BL_reg(context)));
1409 drive = DOS_GET_DRIVE ( BL_reg(context) );
1410 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1412 SET_CFLAG(context);
1413 AX_reg(context) = 0x000F; /* invalid drive */
1415 break;
1418 default:
1419 INT_BARF( context, 0x21 );
1420 break;
1422 break;
1424 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1425 TRACE(int21,"DUP - DUPLICATE FILE HANDLE %d\n",BX_reg(context));
1426 bSetDOSExtendedError = ((AX_reg(context) = FILE_Dup(BX_reg(context))) == (WORD)HFILE_ERROR16);
1427 break;
1429 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1430 TRACE(int21,"FORCEDUP - FORCE DUPLICATE FILE HANDLE %d to %d\n",
1431 BX_reg(context),CX_reg(context));
1432 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR32);
1433 break;
1435 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1436 TRACE(int21,"CWD - GET CURRENT DIRECTORY for drive %s\n",
1437 INT21_DriveName( DL_reg(context)));
1438 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1439 break;
1441 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1442 TRACE(int21,"EXEC %s\n",
1443 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context) ));
1444 AX_reg(context) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1445 DX_reg(context) ),
1446 SW_NORMAL );
1447 if (AX_reg(context) < 32) SET_CFLAG(context);
1448 break;
1450 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1451 TRACE(int21,"EXIT with return code %d\n",AL_reg(context));
1452 TASK_KillCurrentTask( AL_reg(context) );
1453 break;
1455 case 0x4d: /* GET RETURN CODE */
1456 TRACE(int21,"GET RETURN CODE (ERRORLEVEL)\n");
1457 AX_reg(context) = 0; /* normal exit */
1458 break;
1460 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1461 TRACE(int21,"FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
1462 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1463 if (!INT21_FindFirst(context)) break;
1464 /* fall through */
1466 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1467 TRACE(int21,"FINDNEXT\n");
1468 if (!INT21_FindNext(context))
1470 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1471 AX_reg(context) = ER_NoMoreFiles;
1472 SET_CFLAG(context);
1474 else AX_reg(context) = 0; /* OK */
1475 break;
1477 case 0x51: /* GET PSP ADDRESS */
1478 TRACE(int21,"GET CURRENT PROCESS ID (GET PSP ADDRESS)\n");
1479 /* FIXME: should we return the original DOS PSP upon */
1480 /* Windows startup ? */
1481 BX_reg(context) = GetCurrentPDB();
1482 break;
1483 case 0x62: /* GET PSP ADDRESS */
1484 TRACE(int21,"GET CURRENT PSP ADDRESS\n");
1485 /* FIXME: should we return the original DOS PSP upon */
1486 /* Windows startup ? */
1487 BX_reg(context) = GetCurrentPDB();
1488 break;
1490 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1491 TRACE(int21,"SYSVARS - GET LIST OF LISTS\n");
1493 SEGPTR lol;
1494 lol = INT21_GetListOfLists();
1495 ES_reg(context) = HIWORD(lol);
1496 BX_reg(context) = LOWORD(lol);
1498 break;
1500 case 0x56: /* "RENAME" - RENAME FILE */
1501 TRACE(int21,"RENAME %s to %s\n",
1502 (LPCSTR)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1503 (LPCSTR)PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context)));
1504 bSetDOSExtendedError =
1505 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1506 PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context))));
1507 break;
1509 case 0x57: /* FILE DATE AND TIME */
1510 switch (AL_reg(context))
1512 case 0x00: /* Get */
1514 FILETIME filetime;
1515 TRACE(int21,"GET FILE DATE AND TIME for handle %d\n",
1516 BX_reg(context));
1517 if (!GetFileTime( BX_reg(context), NULL, NULL, &filetime ))
1518 bSetDOSExtendedError = TRUE;
1519 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1520 &CX_reg(context) );
1522 break;
1524 case 0x01: /* Set */
1526 FILETIME filetime;
1527 TRACE(int21,"SET FILE DATE AND TIME for handle %d\n",
1528 BX_reg(context));
1529 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1530 &filetime );
1531 bSetDOSExtendedError =
1532 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1534 break;
1536 break;
1538 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1539 TRACE(int21,"GET OR SET MEMORY/UMB ALLOCATION STRATEGY subfunction %d\n",
1540 AL_reg(context));
1541 switch (AL_reg(context))
1543 case 0x00:
1544 AX_reg(context) = 1;
1545 break;
1546 case 0x02:
1547 AX_reg(context) = 0;
1548 break;
1549 case 0x01:
1550 case 0x03:
1551 break;
1553 RESET_CFLAG(context);
1554 break;
1556 case 0x5a: /* CREATE TEMPORARY FILE */
1557 TRACE(int21,"CREATE TEMPORARY FILE\n");
1558 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1559 break;
1561 case 0x5b: /* CREATE NEW FILE */
1562 TRACE(int21,"CREATE NEW FILE 0x%02x for %s\n", CX_reg(context),
1563 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1564 bSetDOSExtendedError = ((AX_reg(context) =
1565 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)), 0 ))
1566 == (WORD)HFILE_ERROR16);
1567 break;
1569 case 0x5d: /* NETWORK */
1570 FIXME(int21,"Function 0x%04x not implemented.\n", AX_reg (context));
1571 /* Fix the following while you're at it. */
1572 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1573 bSetDOSExtendedError = TRUE;
1574 break;
1576 case 0x5e:
1577 bSetDOSExtendedError = INT21_networkfunc (context);
1578 break;
1580 case 0x5f: /* NETWORK */
1581 switch (AL_reg(context))
1583 case 0x07: /* ENABLE DRIVE */
1584 TRACE(int21,"ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1585 if (!DRIVE_Enable( DL_reg(context) ))
1587 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1588 bSetDOSExtendedError = TRUE;
1590 break;
1592 case 0x08: /* DISABLE DRIVE */
1593 TRACE(int21,"DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
1594 if (!DRIVE_Disable( DL_reg(context) ))
1596 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1597 bSetDOSExtendedError = TRUE;
1599 break;
1601 default:
1602 /* network software not installed */
1603 TRACE(int21,"NETWORK function AX=%04x not implemented\n",AX_reg(context));
1604 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1605 bSetDOSExtendedError = TRUE;
1606 break;
1608 break;
1610 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1611 TRACE(int21,"TRUENAME %s\n",
1612 (LPCSTR)PTR_SEG_OFF_TO_LIN(DS_reg(context),SI_reg(context)));
1614 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1615 SI_reg(context)), 128,
1616 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1617 DI_reg(context)),NULL))
1618 bSetDOSExtendedError = TRUE;
1619 else AX_reg(context) = 0;
1621 break;
1623 case 0x61: /* UNUSED */
1624 case 0x63: /* UNUSED */
1625 case 0x64: /* OS/2 DOS BOX */
1626 INT_BARF( context, 0x21 );
1627 SET_CFLAG(context);
1628 break;
1630 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1631 extern WORD WINE_LanguageId;
1632 BYTE *dataptr=PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context));
1633 TRACE(int21,"GET EXTENDED COUNTRY INFORMATION code page %d country %d\n",
1634 BX_reg(context), DX_reg(context));
1635 switch (AL_reg(context)) {
1636 case 0x01:
1637 TRACE(int21,"\tget general internationalization info\n");
1638 dataptr[0] = 0x1;
1639 *(WORD*)(dataptr+1) = 41;
1640 *(WORD*)(dataptr+3) = WINE_LanguageId;
1641 *(WORD*)(dataptr+5) = CodePage;
1642 *(DWORD*)(dataptr+0x19) = NULL; /* FIXME: ptr to case map routine */
1643 break;
1644 case 0x06:
1645 TRACE(int21,"\tget pointer to collating sequence table\n");
1646 dataptr[0] = 0x06;
1647 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1648 CX_reg(context) = 258;/*FIXME: size of table?*/
1649 break;
1650 default:
1651 TRACE(int21,"\tunimplemented function %d\n",AL_reg(context));
1652 INT_BARF( context, 0x21 );
1653 SET_CFLAG(context);
1654 break;
1656 break;
1658 case 0x66: /* GLOBAL CODE PAGE TABLE */
1659 switch (AL_reg(context))
1661 case 0x01:
1662 TRACE(int21,"GET GLOBAL CODE PAGE TABLE\n");
1663 DX_reg(context) = BX_reg(context) = CodePage;
1664 RESET_CFLAG(context);
1665 break;
1666 case 0x02:
1667 TRACE(int21,"SET GLOBAL CODE PAGE TABLE active page %d system page %d\n",
1668 BX_reg(context),DX_reg(context));
1669 CodePage = BX_reg(context);
1670 RESET_CFLAG(context);
1671 break;
1673 break;
1675 case 0x67: /* SET HANDLE COUNT */
1676 TRACE(int21,"SET HANDLE COUNT to %d\n",BX_reg(context) );
1677 SetHandleCount16( BX_reg(context) );
1678 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1679 break;
1681 case 0x68: /* "FFLUSH" - COMMIT FILE */
1682 case 0x6a: /* COMMIT FILE */
1683 TRACE(int21,"FFLUSH/COMMIT handle %d\n",BX_reg(context));
1684 bSetDOSExtendedError = (!FlushFileBuffers( BX_reg(context) ));
1685 break;
1687 case 0x69: /* DISK SERIAL NUMBER */
1688 switch (AL_reg(context))
1690 case 0x00:
1691 TRACE(int21,"GET DISK SERIAL NUMBER for drive %s\n",
1692 INT21_DriveName(BL_reg(context)));
1693 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1694 else AX_reg(context) = 0;
1695 break;
1697 case 0x01:
1698 TRACE(int21,"SET DISK SERIAL NUMBER for drive %s\n",
1699 INT21_DriveName(BL_reg(context)));
1700 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1701 else AX_reg(context) = 1;
1702 break;
1704 break;
1706 case 0x6C: /* Extended Open/Create*/
1707 TRACE(int21,"EXTENDED OPEN/CREATE %s\n",
1708 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DI_reg(context)));
1709 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1710 break;
1712 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1713 switch(AL_reg(context))
1715 case 0x39: /* Create directory */
1716 TRACE(int21,"LONG FILENAME - MAKE DIRECTORY %s\n",
1717 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1718 bSetDOSExtendedError = (!CreateDirectory32A(
1719 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1720 DX_reg(context) ), NULL));
1721 break;
1722 case 0x3a: /* Remove directory */
1723 TRACE(int21,"LONG FILENAME - REMOVE DIRECTORY %s\n",
1724 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1725 bSetDOSExtendedError = (!RemoveDirectory32A(
1726 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1727 DX_reg(context) )));
1728 break;
1729 case 0x43: /* Get/Set file attributes */
1730 TRACE(int21,"LONG FILENAME -EXTENDED GET/SET FILE ATTRIBUTES %s\n",
1731 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1732 switch (BL_reg(context))
1734 case 0x00: /* Get file attributes */
1735 TRACE(int21,"\tretrieve attributes\n");
1736 CX_reg(context) = (WORD)GetFileAttributes32A(
1737 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1738 DX_reg(context)));
1739 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1740 break;
1741 case 0x01:
1742 TRACE(int21,"\tset attributes 0x%04x\n",CX_reg(context));
1743 bSetDOSExtendedError = (!SetFileAttributes32A(
1744 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1745 DX_reg(context)),
1746 CX_reg(context) ) );
1747 break;
1748 default:
1749 FIXME(int21, "Unimplemented long file name function:\n");
1750 INT_BARF( context, 0x21 );
1751 SET_CFLAG(context);
1752 AL_reg(context) = 0;
1753 break;
1755 break;
1756 case 0x47: /* Get current directory */
1757 TRACE(int21," LONG FILENAME - GET CURRENT DIRECTORY for drive %s\n",
1758 INT21_DriveName(DL_reg(context)));
1759 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1760 break;
1762 case 0x4e: /* Find first file */
1763 TRACE(int21," LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
1764 (LPCSTR)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
1765 /* FIXME: use attributes in CX */
1766 if ((AX_reg(context) = FindFirstFile16(
1767 PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1768 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1769 DI_reg(context))))
1770 == INVALID_HANDLE_VALUE16)
1771 bSetDOSExtendedError = TRUE;
1772 break;
1773 case 0x4f: /* Find next file */
1774 TRACE(int21,"LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
1775 BX_reg(context));
1776 if (!FindNextFile16( BX_reg(context),
1777 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1778 DI_reg(context))))
1779 bSetDOSExtendedError = TRUE;
1780 break;
1781 case 0xa1: /* Find close */
1782 TRACE(int21,"LONG FILENAME - FINDCLOSE for handle %d\n",
1783 BX_reg(context));
1784 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1785 break;
1786 case 0xa0:
1787 TRACE(int21,"LONG FILENAME - GET VOLUME INFORMATION for drive %s stub\n",
1788 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context),DX_reg(context)));
1789 break;
1790 case 0x60:
1791 switch(CL_reg(context))
1793 case 0x02: /*Get canonical long filename or path */
1794 if (!GetFullPathName32A
1795 ( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1796 SI_reg(context)), 128,
1797 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1798 DI_reg(context)),NULL))
1799 bSetDOSExtendedError = TRUE;
1800 else AX_reg(context) = 0;
1801 break;
1802 default:
1803 FIXME(int21, "Unimplemented long file name function:\n");
1804 INT_BARF( context, 0x21 );
1805 SET_CFLAG(context);
1806 AL_reg(context) = 0;
1807 break;
1809 break;
1810 case 0x6c: /* Create or open file */
1811 TRACE(int21,"LONG FILENAME - CREATE OR OPEN FILE %s\n",
1812 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), SI_reg(context)));
1813 /* translate Dos 7 action to Dos 6 action */
1814 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1815 break;
1817 case 0x3b: /* Change directory */
1818 TRACE(int21,"LONG FILENAME - CHANGE DIRECTORY %s\n",
1819 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1820 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1821 DS_reg(context),
1822 DX_reg(context)
1825 SET_CFLAG(context);
1826 AL_reg(context) = DOS_ExtendedError;
1828 break;
1829 case 0x41: /* Delete file */
1830 TRACE(int21,"LONG FILENAME - DELETE FILE %s\n",
1831 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)));
1832 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1833 DS_reg(context),
1834 DX_reg(context))
1835 )) {
1836 SET_CFLAG(context);
1837 AL_reg(context) = DOS_ExtendedError;
1839 break;
1840 case 0x56: /* Move (rename) file */
1841 TRACE(int21,"LONG FILENAME - RENAME FILE %s to %s stub\n",
1842 (LPCSTR)PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context)),
1843 (LPCSTR)PTR_SEG_OFF_TO_LIN( ES_reg(context), DI_reg(context)));
1844 default:
1845 FIXME(int21, "Unimplemented long file name function:\n");
1846 INT_BARF( context, 0x21 );
1847 SET_CFLAG(context);
1848 AL_reg(context) = 0;
1849 break;
1851 break;
1853 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1854 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1855 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1856 TRACE(int21,"windows95 function AX %04x\n",
1857 AX_reg(context));
1858 WARN(int21, " returning unimplemented\n");
1859 SET_CFLAG(context);
1860 AL_reg(context) = 0;
1861 break;
1863 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1864 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1865 break;
1867 default:
1868 INT_BARF( context, 0x21 );
1869 break;
1871 } /* END OF SWITCH */
1873 if( bSetDOSExtendedError ) /* set general error condition */
1875 AX_reg(context) = DOS_ExtendedError;
1876 SET_CFLAG(context);
1879 if ((EFL_reg(context) & 0x0001))
1880 TRACE(int21, "failed, errorcode 0x%02x class 0x%02x action 0x%02x locus %02x\n",
1881 DOS_ExtendedError, DOS_ErrorClass, DOS_ErrorAction, DOS_ErrorLocus);
1883 TRACE(int21, "returning: AX=%04x BX=%04x CX=%04x DX=%04x "
1884 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1885 AX_reg(context), BX_reg(context), CX_reg(context),
1886 DX_reg(context), SI_reg(context), DI_reg(context),
1887 (WORD)DS_reg(context), (WORD)ES_reg(context),
1888 EFL_reg(context));
1891 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
1893 FIXME(int21, "(DosProc=%08x);\n", (UINT32)DosProc);
1894 return NULL;