Release 971012
[wine.git] / msdos / int21.c
blob94ab5edd3383b0bdd3449aa64d7b4143c348613e
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 "xmalloc.h"
28 #include "stddebug.h"
29 #include "debug.h"
30 #if defined(__svr4__) || defined(_SCO_DS)
31 /* SVR4 DOESNT do locking the same way must implement properly */
32 #define LOCK_EX 0
33 #define LOCK_SH 1
34 #define LOCK_NB 8
35 #endif
38 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
40 /* Define the drive parameter block, as used by int21/1F
41 * and int21/32. This table can be accessed through the
42 * global 'dpb' pointer, which points into the local dos
43 * heap.
45 struct DPB
47 BYTE drive_num; /* 0=A, etc. */
48 BYTE unit_num; /* Drive's unit number (?) */
49 WORD sector_size; /* Sector size in bytes */
50 BYTE high_sector; /* Highest sector in a cluster */
51 BYTE shift; /* Shift count (?) */
52 WORD reserved; /* Number of reserved sectors at start */
53 BYTE num_FAT; /* Number of FATs */
54 WORD dir_entries; /* Number of root dir entries */
55 WORD first_data; /* First data sector */
56 WORD high_cluster; /* Highest cluster number */
57 WORD sectors_in_FAT; /* Number of sectors per FAT */
58 WORD start_dir; /* Starting sector of first dir */
59 DWORD driver_head; /* Address of device driver header (?) */
60 BYTE media_ID; /* Media ID */
61 BYTE access_flag; /* Prev. accessed flag (0=yes,0xFF=no) */
62 DWORD next; /* Pointer to next DPB in list */
63 WORD free_search; /* Free cluster search start */
64 WORD free_clusters; /* Number of free clusters (0xFFFF=unknown) */
67 WORD CodePage = 437;
68 DWORD dpbsegptr;
70 struct DosHeap {
71 BYTE InDosFlag;
72 BYTE mediaID;
73 BYTE biosdate[8];
74 struct DPB dpb;
76 static struct DosHeap *heap;
77 static WORD DosHeapHandle;
79 WORD sharing_retries = 3; /* number of retries at sharing violation */
80 WORD sharing_pause = 1; /* pause between retries */
82 extern char TempDirectory[];
84 static BOOL32 INT21_CreateHeap(void)
86 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
88 fprintf( stderr, "INT21_Init: Out of memory\n");
89 return FALSE;
91 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
92 dpbsegptr = PTR_SEG_OFF_TO_SEGPTR(DosHeapHandle,(int)&heap->dpb-(int)heap);
93 heap->InDosFlag = 0;
94 strcpy(heap->biosdate, "01/01/80");
95 return TRUE;
98 static BYTE *GetCurrentDTA(void)
100 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
101 return (BYTE *)PTR_SEG_TO_LIN( pTask->dta );
105 void CreateBPB(int drive, BYTE *data)
107 if (drive > 1) {
108 setword(data, 512);
109 data[2] = 2;
110 setword(&data[3], 0);
111 data[5] = 2;
112 setword(&data[6], 240);
113 setword(&data[8], 64000);
114 data[0x0a] = 0xf8;
115 setword(&data[0x0b], 40);
116 setword(&data[0x0d], 56);
117 setword(&data[0x0f], 2);
118 setword(&data[0x11], 0);
119 setword(&data[0x1f], 800);
120 data[0x21] = 5;
121 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 setword(&data[0x1f], 80);
135 data[0x21] = 7;
136 setword(&data[0x22], 2);
140 static int INT21_GetFreeDiskSpace( CONTEXT *context )
142 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
143 char root[] = "A:\\";
145 *root += DOS_GET_DRIVE( DL_reg(context) );
146 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
147 &free_clusters, &total_clusters )) return 0;
148 AX_reg(context) = cluster_sectors;
149 BX_reg(context) = free_clusters;
150 CX_reg(context) = sector_bytes;
151 DX_reg(context) = total_clusters;
152 return 1;
155 static int INT21_GetDriveAllocInfo( CONTEXT *context )
157 if (!INT21_GetFreeDiskSpace( context )) return 0;
158 if (!heap && !INT21_CreateHeap()) return 0;
159 heap->mediaID = 0xf0;
160 DS_reg(context) = DosHeapHandle;
161 BX_reg(context) = (int)&heap->mediaID - (int)heap;
162 return 1;
165 static void GetDrivePB( CONTEXT *context, int drive )
167 if(!DRIVE_IsValid(drive))
169 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
170 AX_reg(context) = 0x00ff;
172 else if (heap || INT21_CreateHeap())
174 dprintf_int(stddeb, "int21: GetDrivePB not fully implemented.\n");
176 /* FIXME: I have no idea what a lot of this information should
177 * say or whether it even really matters since we're not allowing
178 * direct block access. However, some programs seem to depend on
179 * getting at least _something_ back from here. The 'next' pointer
180 * does worry me, though. Should we have a complete table of
181 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
183 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
184 heap->dpb.sector_size = 512;
185 heap->dpb.high_sector = 1;
186 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
187 heap->dpb.reserved = 0;
188 heap->dpb.num_FAT = 1;
189 heap->dpb.dir_entries = 2;
190 heap->dpb.first_data = 2;
191 heap->dpb.high_cluster = 64000;
192 heap->dpb.sectors_in_FAT = 1;
193 heap->dpb.start_dir = 1;
194 heap->dpb.driver_head = 0;
195 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
196 heap->dpb.access_flag = 0;
197 heap->dpb.next = 0;
198 heap->dpb.free_search = 0;
199 heap->dpb.free_clusters = 0xFFFF; /* unknown */
201 AL_reg(context) = 0x00;
202 DS_reg(context) = SELECTOROF(dpbsegptr);
203 BX_reg(context) = OFFSETOF(dpbsegptr);
208 static void ioctlGetDeviceInfo( CONTEXT *context )
210 int curr_drive;
211 dprintf_int (stddeb, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context));
213 curr_drive = DRIVE_GetCurrentDrive();
214 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0); /* no floppy */
215 /* bits 0-5 are current drive
216 * bit 6 - file has NOT been written..FIXME: correct?
217 * bit 8 - generate int24 if no diskspace on write/ read past end of file
218 * bit 11 - media not removable
220 RESET_CFLAG(context);
223 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
225 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
226 int drive = DOS_GET_DRIVE( BL_reg(context) );
228 if (!DRIVE_IsValid(drive))
230 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
231 return TRUE;
234 if (CH_reg(context) != 0x08)
236 INT_BARF( context, 0x21 );
237 return FALSE;
240 switch (CL_reg(context))
242 case 0x4a: /* lock logical volume */
243 dprintf_int(stddeb,"int21: lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
244 break;
246 case 0x60: /* get device parameters */
247 /* used by w4wgrp's winfile */
248 memset(dataptr, 0, 0x26);
249 dataptr[0] = 0x04;
250 dataptr[6] = 0; /* media type */
251 if (drive > 1)
253 dataptr[1] = 0x05; /* fixed disk */
254 setword(&dataptr[2], 0x01); /* non removable */
255 setword(&dataptr[4], 0x300); /* # of cylinders */
257 else
259 dataptr[1] = 0x07; /* block dev, floppy */
260 setword(&dataptr[2], 0x02); /* removable */
261 setword(&dataptr[4], 80); /* # of cylinders */
263 CreateBPB(drive, &dataptr[7]);
264 RESET_CFLAG(context);
265 break;
267 case 0x66:/* get disk serial number */
269 char label[12],fsname[9],path[4];
270 DWORD serial;
272 strcpy(path,"x:\\");path[0]=drive+'A';
273 GetVolumeInformation32A(
274 path,label,12,&serial,NULL,NULL,fsname,9
276 *(WORD*)dataptr = 0;
277 memcpy(dataptr+2,&serial,4);
278 memcpy(dataptr+6,label ,11);
279 memcpy(dataptr+17,fsname,8);
281 break;
283 case 0x6a:
284 dprintf_int(stddeb,"int21: logical volume %d unlocked.\n",drive);
285 break;
287 default:
288 INT_BARF( context, 0x21 );
290 return FALSE;
293 static void INT21_GetSystemDate( CONTEXT *context )
295 SYSTEMTIME systime;
296 GetLocalTime( &systime );
297 CX_reg(context) = systime.wYear;
298 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
299 AX_reg(context) = systime.wDayOfWeek;
302 static void INT21_GetSystemTime( CONTEXT *context )
304 SYSTEMTIME systime;
305 GetLocalTime( &systime );
306 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
307 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
310 static BOOL32 INT21_CreateFile( CONTEXT *context )
312 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
313 DX_reg(context) ), CX_reg(context) );
314 return (AX_reg(context) == (WORD)HFILE_ERROR16);
318 static void OpenExistingFile( CONTEXT *context )
320 AX_reg(context) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
321 AL_reg(context) );
322 if (AX_reg(context) == (WORD)HFILE_ERROR16)
324 AX_reg(context) = DOS_ExtendedError;
325 SET_CFLAG(context);
327 #if 0
329 int handle;
330 int mode;
331 int lock;
333 switch (AX_reg(context) & 0x0070)
335 case 0x00: /* compatability mode */
336 case 0x40: /* DENYNONE */
337 lock = -1;
338 break;
340 case 0x30: /* DENYREAD */
341 dprintf_int(stddeb,
342 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
343 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
344 case 0x10: /* DENYALL */
345 lock = LOCK_EX;
346 break;
348 case 0x20: /* DENYWRITE */
349 lock = LOCK_SH;
350 break;
352 default:
353 lock = -1;
356 if (lock != -1)
359 int result,retries=sharing_retries;
361 #if defined(__svr4__) || defined(_SCO_DS)
362 printf("Should call flock and needs porting to lockf\n");
363 result = 0;
364 retries = 0;
365 #else
366 result = flock(handle, lock | LOCK_NB);
367 #endif
368 if ( retries && (!result) )
370 int i;
371 for(i=0;i<32768*((int)sharing_pause);i++)
372 result++; /* stop the optimizer */
373 for(i=0;i<32768*((int)sharing_pause);i++)
374 result--;
377 while( (!result) && (!(retries--)) );
379 if(result)
381 errno_to_doserr();
382 AX_reg(context) = DOS_ExtendedError;
383 close(handle);
384 SET_CFLAG(context);
385 return;
390 Error (0,0,0);
391 AX_reg(context) = handle;
392 RESET_CFLAG(context);
394 #endif
397 static void CloseFile( CONTEXT *context )
399 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
401 AX_reg(context) = DOS_ExtendedError;
402 SET_CFLAG(context);
406 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
408 BOOL32 bExtendedError = FALSE;
409 BYTE action = DL_reg(context);
411 /* Shuffle arguments to call OpenExistingFile */
412 AL_reg(context) = BL_reg(context);
413 DX_reg(context) = SI_reg(context);
414 /* BX,CX and DX should be preserved */
415 OpenExistingFile(context);
417 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
419 UINT16 uReturnCX = 0;
421 /* Now decide what do do */
423 if ((action & 0x07) == 0)
425 BX_reg(context) = AX_reg(context);
426 CloseFile(context);
427 AX_reg(context) = 0x0050; /*File exists*/
428 SET_CFLAG(context);
429 dprintf_int(stddeb, "int21: extended open/create: failed because file exists \n");
431 else if ((action & 0x07) == 2)
433 /* Truncate it, but first check if opened for write */
434 if ((BL_reg(context) & 0x0007)== 0)
436 BX_reg(context) = AX_reg(context);
437 CloseFile(context);
438 dprintf_int(stddeb, "int21: extended open/create: failed, trunc on ro file");
439 AX_reg(context) = 0x000C; /*Access code invalid*/
440 SET_CFLAG(context);
442 else
444 /* Shuffle arguments to call CloseFile while
445 * preserving BX and DX */
447 dprintf_int(stddeb, "int21: extended open/create: Closing before truncate\n");
448 BX_reg(context) = AX_reg(context);
449 CloseFile(context);
450 if (EFL_reg(context) & 0x0001)
452 dprintf_int(stddeb, "int21: extended open/create: close before trunc failed");
453 AX_reg(context) = 0x0019; /*Seek Error*/
454 CX_reg(context) = 0;
455 SET_CFLAG(context);
457 /* Shuffle arguments to call CreateFile */
459 dprintf_int(stddeb, "int21: extended open/create: Truncating\n");
460 AL_reg(context) = BL_reg(context);
461 /* CX is still the same */
462 DX_reg(context) = SI_reg(context);
463 bExtendedError = INT21_CreateFile(context);
465 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
467 dprintf_int(stddeb, "int21: extended open/create: trunc failed");
468 return bExtendedError;
470 uReturnCX = 0x3;
473 else uReturnCX = 0x1;
475 CX_reg(context) = uReturnCX;
477 else /* file does not exist */
479 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
480 if ((action & 0xF0)== 0)
482 CX_reg(context) = 0;
483 SET_CFLAG(context);
484 dprintf_int(stddeb, "int21: extended open/create: failed, file dosen't exist\n");
486 else
488 /* Shuffle arguments to call CreateFile */
489 dprintf_int(stddeb, "int21: extended open/create: Creating\n");
490 AL_reg(context) = BL_reg(context);
491 /* CX should still be the same */
492 DX_reg(context) = SI_reg(context);
493 bExtendedError = INT21_CreateFile(context);
494 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
496 dprintf_int(stddeb, "int21: extended open/create: create failed\n");
497 return bExtendedError;
499 CX_reg(context) = 2;
503 return bExtendedError;
507 static BOOL32 INT21_ChangeDir( CONTEXT *context )
509 int drive;
510 char *dirname = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
512 dprintf_int(stddeb,"int21: changedir %s\n", dirname);
513 if (dirname[0] && (dirname[1] == ':'))
515 drive = toupper(dirname[0]) - 'A';
516 dirname += 2;
518 else drive = DRIVE_GetCurrentDrive();
519 return DRIVE_Chdir( drive, dirname );
523 static int INT21_FindFirst( CONTEXT *context )
525 char *p;
526 const char *path;
527 DOS_FULL_NAME full_name;
528 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
530 path = (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
531 dta->unixPath = NULL;
532 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
534 AX_reg(context) = DOS_ExtendedError;
535 SET_CFLAG(context);
536 return 0;
538 dta->unixPath = xstrdup( full_name.long_name );
539 p = strrchr( dta->unixPath, '/' );
540 *p = '\0';
542 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
543 * (doesn't matter as it is set below anyway)
545 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
547 free( dta->unixPath );
548 dta->unixPath = NULL;
549 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
550 AX_reg(context) = ER_FileNotFound;
551 SET_CFLAG(context);
552 return 0;
554 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
555 : DRIVE_GetCurrentDrive();
556 dta->count = 0;
557 dta->search_attr = CL_reg(context);
558 return 1;
562 static int INT21_FindNext( CONTEXT *context )
564 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
565 WIN32_FIND_DATA32A entry;
566 int count;
568 if (!dta->unixPath) return 0;
569 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
570 dta->search_attr, dta->count, &entry )))
572 free( dta->unixPath );
573 dta->unixPath = NULL;
574 return 0;
576 if ((int)dta->count + count > 0xffff)
578 fprintf( stderr, "Too many directory entries in %s\n", dta->unixPath );
579 free( dta->unixPath );
580 dta->unixPath = NULL;
581 return 0;
583 dta->count += count;
584 dta->fileattr = entry.dwFileAttributes;
585 dta->filesize = entry.nFileSizeLow;
586 FileTimeToDosDateTime( &entry.ftLastWriteTime,
587 &dta->filedate, &dta->filetime );
588 strcpy( dta->filename, entry.cAlternateFileName );
589 return 1;
593 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
595 static int counter = 0;
596 char *name = PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context) );
597 char *p = name + strlen(name);
599 for (;;)
601 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
602 counter = (counter + 1) % 1000;
604 if ((AX_reg(context) = _lcreat_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
606 dprintf_int( stddeb, "INT21_CreateTempFile: created %s\n", name );
607 return TRUE;
609 if (DOS_ExtendedError != ER_FileExists) return FALSE;
614 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
616 int drive = DOS_GET_DRIVE( DL_reg(context) );
617 char *ptr = (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context), SI_reg(context) );
619 if (!DRIVE_IsValid(drive))
621 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
622 return FALSE;
624 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
625 AX_reg(context) = 0x0100; /* success return code */
626 return TRUE;
630 static int INT21_GetDiskSerialNumber( CONTEXT *context )
632 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
633 int drive = DOS_GET_DRIVE( BL_reg(context) );
635 if (!DRIVE_IsValid(drive))
637 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
638 return 0;
641 *(WORD *)dataptr = 0;
642 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
643 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
644 strncpy(dataptr + 0x11, "FAT16 ", 8);
645 return 1;
649 static int INT21_SetDiskSerialNumber( CONTEXT *context )
651 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
652 int drive = DOS_GET_DRIVE( BL_reg(context) );
654 if (!DRIVE_IsValid(drive))
656 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
657 return 0;
660 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
661 return 1;
665 /* microsoft's programmers should be shot for using CP/M style int21
666 calls in Windows for Workgroup's winfile.exe */
668 static int INT21_FindFirstFCB( CONTEXT *context )
670 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
671 FINDFILE_FCB *pFCB;
672 LPCSTR root, cwd;
673 int drive;
675 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
676 else pFCB = (FINDFILE_FCB *)fcb;
677 drive = DOS_GET_DRIVE( pFCB->drive );
678 root = DRIVE_GetRoot( drive );
679 cwd = DRIVE_GetUnixCwd( drive );
680 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
681 strlen(root)+strlen(cwd)+2 );
682 if (!pFCB->unixPath) return 0;
683 strcpy( pFCB->unixPath, root );
684 strcat( pFCB->unixPath, "/" );
685 strcat( pFCB->unixPath, cwd );
686 pFCB->count = 0;
687 return 1;
691 static int INT21_FindNextFCB( CONTEXT *context )
693 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
694 FINDFILE_FCB *pFCB;
695 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA();
696 WIN32_FIND_DATA32A entry;
697 BYTE attr;
698 int count;
700 if (*fcb == 0xff)
702 attr = fcb[6];
703 pFCB = (FINDFILE_FCB *)(fcb + 7);
705 else
707 attr = 0;
708 pFCB = (FINDFILE_FCB *)fcb;
711 if (!pFCB->unixPath) return 0;
712 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
713 DOS_GET_DRIVE( pFCB->drive ), attr,
714 pFCB->count, &entry )))
716 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
717 pFCB->unixPath = NULL;
718 return 0;
720 pFCB->count += count;
722 pResult->fileattr = entry.dwFileAttributes;
723 pResult->cluster = 0; /* what else? */
724 pResult->filesize = entry.nFileSizeLow;
725 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
726 FileTimeToDosDateTime( &entry.ftLastWriteTime,
727 &pResult->filedate, &pResult->filetime );
729 /* Convert file name to FCB format */
731 memset( pResult->filename, ' ', sizeof(pResult->filename) );
732 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
733 else if (!strcmp( entry.cAlternateFileName, ".." ))
734 pResult->filename[0] = pResult->filename[1] = '.';
735 else
737 char *p = strrchr( entry.cAlternateFileName, '.' );
738 if (p && p[1] && (p != entry.cAlternateFileName))
740 memcpy( pResult->filename, entry.cAlternateFileName,
741 MIN( (p - entry.cAlternateFileName), 8 ) );
742 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
744 else
745 memcpy( pResult->filename, entry.cAlternateFileName,
746 MIN( strlen(entry.cAlternateFileName), 8 ) );
748 return 1;
752 static void DeleteFileFCB( CONTEXT *context )
754 fprintf( stderr, "DeleteFileFCB: not implemented yet\n" );
757 static void RenameFileFCB( CONTEXT *context )
759 fprintf( stderr, "RenameFileFCB: not implemented yet\n" );
764 static void fLock( CONTEXT * context )
767 switch ( AX_reg(context) & 0xff )
769 case 0x00: /* LOCK */
770 if (!LockFile(BX_reg(context),
771 MAKELONG(DX_reg(context),CX_reg(context)), 0,
772 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
773 AX_reg(context) = DOS_ExtendedError;
774 SET_CFLAG(context);
776 break;
778 case 0x01: /* UNLOCK */
779 if (!UnlockFile(BX_reg(context),
780 MAKELONG(DX_reg(context),CX_reg(context)), 0,
781 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
782 AX_reg(context) = DOS_ExtendedError;
783 SET_CFLAG(context);
785 return;
786 default:
787 AX_reg(context) = 0x0001;
788 SET_CFLAG(context);
789 return;
794 extern void LOCAL_PrintHeap (WORD ds);
796 /***********************************************************************
797 * DOS3Call (KERNEL.102)
799 void WINAPI DOS3Call( CONTEXT *context )
801 BOOL32 bSetDOSExtendedError = FALSE;
803 dprintf_int( stddeb, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
804 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
805 AX_reg(context), BX_reg(context), CX_reg(context),
806 DX_reg(context), SI_reg(context), DI_reg(context),
807 (WORD)DS_reg(context), (WORD)ES_reg(context),
808 EFL_reg(context) );
810 if (AH_reg(context) == 0x59) /* Get extended error info */
812 AX_reg(context) = DOS_ExtendedError;
813 BH_reg(context) = DOS_ErrorClass;
814 BL_reg(context) = DOS_ErrorAction;
815 CH_reg(context) = DOS_ErrorLocus;
816 return;
819 DOS_ERROR( 0, 0, 0, 0 );
820 RESET_CFLAG(context); /* Not sure if this is a good idea */
822 switch(AH_reg(context))
824 case 0x00: /* TERMINATE PROGRAM */
825 TASK_KillCurrentTask( 0 );
826 break;
828 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
829 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
830 case 0x03: /* READ CHARACTER FROM STDAUX */
831 case 0x04: /* WRITE CHARACTER TO STDAUX */
832 case 0x05: /* WRITE CHARACTER TO PRINTER */
833 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
834 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
835 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
836 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
837 case 0x0a: /* BUFFERED INPUT */
838 case 0x0b: /* GET STDIN STATUS */
839 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
840 case 0x0f: /* OPEN FILE USING FCB */
841 case 0x10: /* CLOSE FILE USING FCB */
842 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
843 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
844 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
845 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
846 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
847 case 0x23: /* GET FILE SIZE FOR FCB */
848 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
849 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
850 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
851 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
852 case 0x29: /* PARSE FILENAME INTO FCB */
853 case 0x2e: /* SET VERIFY FLAG */
854 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
855 "SWITCHAR" - SET SWITCH CHARACTER
856 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
857 case 0x54: /* GET VERIFY FLAG */
858 INT_BARF( context, 0x21 );
859 break;
861 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
862 case 0x1d:
863 case 0x1e:
864 case 0x20:
865 case 0x6b: /* NULL FUNCTION */
866 AL_reg(context) = 0;
867 break;
869 case 0x5c: /* "FLOCK" - RECORD LOCKING */
870 fLock(context);
871 break;
873 case 0x0d: /* DISK BUFFER FLUSH */
874 RESET_CFLAG(context); /* dos 6+ only */
875 break;
877 case 0x0e: /* SELECT DEFAULT DRIVE */
878 DRIVE_SetCurrentDrive( DL_reg(context) );
879 AL_reg(context) = MAX_DOS_DRIVES;
880 break;
882 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
883 if (!INT21_FindFirstFCB(context))
885 AL_reg(context) = 0xff;
886 break;
888 /* else fall through */
890 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
891 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
892 break;
894 case 0x13: /* DELETE FILE USING FCB */
895 DeleteFileFCB(context);
896 break;
898 case 0x17: /* RENAME FILE USING FCB */
899 RenameFileFCB(context);
900 break;
902 case 0x19: /* GET CURRENT DEFAULT DRIVE */
903 AL_reg(context) = DRIVE_GetCurrentDrive();
904 break;
906 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
908 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
909 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
910 dprintf_int(stddeb, "int21: Set DTA: %08lx\n", pTask->dta);
912 break;
914 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
915 DL_reg(context) = 0;
916 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
917 break;
919 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
920 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
921 break;
923 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
924 GetDrivePB(context, DRIVE_GetCurrentDrive());
925 break;
927 case 0x25: /* SET INTERRUPT VECTOR */
928 INT_SetHandler( AL_reg(context),
929 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
930 DX_reg(context)));
931 break;
933 case 0x2a: /* GET SYSTEM DATE */
934 INT21_GetSystemDate(context);
935 break;
937 case 0x2b: /* SET SYSTEM DATE */
938 fprintf( stdnimp, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
939 DL_reg(context), DH_reg(context), CX_reg(context) );
940 AL_reg(context) = 0; /* Let's pretend we succeeded */
941 break;
943 case 0x2c: /* GET SYSTEM TIME */
944 INT21_GetSystemTime(context);
945 break;
947 case 0x2d: /* SET SYSTEM TIME */
948 fprintf( stdnimp, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
949 CH_reg(context), CL_reg(context),
950 DH_reg(context), DL_reg(context) );
951 AL_reg(context) = 0; /* Let's pretend we succeeded */
952 break;
954 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
956 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
957 ES_reg(context) = SELECTOROF( pTask->dta );
958 BX_reg(context) = OFFSETOF( pTask->dta );
960 break;
962 case 0x30: /* GET DOS VERSION */
963 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
964 (HIWORD(GetVersion16()) << 8);
965 BX_reg(context) = 0x0012; /* 0x123456 is Wine's serial # */
966 CX_reg(context) = 0x3456;
967 break;
969 case 0x31: /* TERMINATE AND STAY RESIDENT */
970 INT_BARF( context, 0x21 );
971 break;
973 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
974 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
975 break;
977 case 0x33: /* MULTIPLEXED */
978 switch (AL_reg(context))
980 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
981 DL_reg(context) = 0;
982 break;
984 case 0x01: /* SET EXTENDED BREAK STATE */
985 break;
987 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
988 DL_reg(context) = 0;
989 break;
991 case 0x05: /* GET BOOT DRIVE */
992 DL_reg(context) = 3;
993 /* c: is Wine's bootdrive (a: is 1)*/
994 break;
996 case 0x06: /* GET TRUE VERSION NUMBER */
997 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
998 (HIWORD(GetVersion16() << 8));
999 DX_reg(context) = 0x00;
1000 break;
1002 default:
1003 INT_BARF( context, 0x21 );
1004 break;
1006 break;
1008 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1009 if (!heap) INT21_CreateHeap();
1010 ES_reg(context) = DosHeapHandle;
1011 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1012 break;
1014 case 0x35: /* GET INTERRUPT VECTOR */
1016 FARPROC16 addr = INT_GetHandler( AL_reg(context) );
1017 ES_reg(context) = SELECTOROF(addr);
1018 BX_reg(context) = OFFSETOF(addr);
1020 break;
1022 case 0x36: /* GET FREE DISK SPACE */
1023 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1024 break;
1026 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1027 AX_reg(context) = 0x02; /* no country support available */
1028 SET_CFLAG(context);
1029 break;
1031 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1032 bSetDOSExtendedError = (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1033 DX_reg(context) ), NULL));
1034 break;
1036 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1037 bSetDOSExtendedError = (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1038 DX_reg(context) )));
1039 break;
1041 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1042 bSetDOSExtendedError = !INT21_ChangeDir(context);
1043 break;
1045 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1046 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1047 DX_reg(context) ), CX_reg(context) );
1048 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1049 break;
1051 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1052 OpenExistingFile(context);
1053 break;
1055 case 0x3e: /* "CLOSE" - CLOSE FILE */
1056 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1057 break;
1059 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1061 LONG result = WIN16_hread( BX_reg(context),
1062 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1063 DX_reg(context) ),
1064 CX_reg(context) );
1065 if (result == -1) bSetDOSExtendedError = TRUE;
1066 else AX_reg(context) = (WORD)result;
1068 break;
1070 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1072 LONG result = _hwrite16( BX_reg(context),
1073 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1074 DX_reg(context) ),
1075 CX_reg(context) );
1076 if (result == -1) bSetDOSExtendedError = TRUE;
1077 else AX_reg(context) = (WORD)result;
1079 break;
1081 case 0x41: /* "UNLINK" - DELETE FILE */
1082 bSetDOSExtendedError = (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1083 DX_reg(context) )));
1084 break;
1086 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1088 LONG status = _llseek16( BX_reg(context),
1089 MAKELONG(DX_reg(context),CX_reg(context)),
1090 AL_reg(context) );
1091 if (status == -1) bSetDOSExtendedError = TRUE;
1092 else
1094 AX_reg(context) = LOWORD(status);
1095 DX_reg(context) = HIWORD(status);
1098 break;
1100 case 0x43: /* FILE ATTRIBUTES */
1101 switch (AL_reg(context))
1103 case 0x00:
1104 AX_reg(context) = (WORD)GetFileAttributes32A(
1105 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1106 DX_reg(context)));
1107 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1108 else CX_reg(context) = AX_reg(context);
1109 break;
1111 case 0x01:
1112 bSetDOSExtendedError =
1113 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1114 DX_reg(context)),
1115 CX_reg(context) ));
1116 break;
1118 break;
1120 case 0x44: /* IOCTL */
1121 switch (AL_reg(context))
1123 case 0x00:
1124 ioctlGetDeviceInfo(context);
1125 break;
1127 case 0x01:
1128 break;
1129 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1130 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
1131 int i;
1132 int drive = DOS_GET_DRIVE(BL_reg(context));
1134 fprintf(stdnimp,"int21: program tried to write to block device control channel of drive %d:\n",drive);
1135 for (i=0;i<CX_reg(context);i++)
1136 fprintf(stdnimp,"%02x ",dataptr[i]);
1137 fprintf(stdnimp,"\n");
1138 AX_reg(context)=CX_reg(context);
1139 break;
1141 case 0x08: /* Check if drive is removable. */
1142 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1144 case DRIVE_CANNOTDETERMINE:
1145 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1146 AX_reg(context) = ER_InvalidDrive;
1147 SET_CFLAG(context);
1148 break;
1149 case DRIVE_REMOVABLE:
1150 AX_reg(context) = 0; /* removable */
1151 break;
1152 default:
1153 AX_reg(context) = 1; /* not removable */
1154 break;
1156 break;
1158 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1159 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1161 case DRIVE_CANNOTDETERMINE:
1162 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1163 AX_reg(context) = ER_InvalidDrive;
1164 SET_CFLAG(context);
1165 break;
1166 case DRIVE_REMOTE:
1167 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1168 break;
1169 default:
1170 DX_reg(context) = 0; /* FIXME: use driver attr here */
1171 break;
1173 break;
1175 case 0x0a: /* check if handle (BX) is remote */
1176 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1177 * not set on close
1179 DX_reg(context) = 0;
1180 break;
1182 case 0x0b: /* SET SHARING RETRY COUNT */
1183 if (!CX_reg(context))
1185 AX_reg(context) = 1;
1186 SET_CFLAG(context);
1187 break;
1189 sharing_pause = CX_reg(context);
1190 if (!DX_reg(context))
1191 sharing_retries = DX_reg(context);
1192 RESET_CFLAG(context);
1193 break;
1195 case 0x0d:
1196 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1197 break;
1199 case 0x0e: /* get logical drive mapping */
1200 AL_reg(context) = 0; /* drive has no mapping */
1201 break;
1203 case 0x0F: /* Set logical drive mapping */
1204 /* FIXME: Not implemented at the moment, always returns error
1206 INT_BARF( context, 0x21 );
1207 AX_reg(context) = 0x0001; /* invalid function */
1208 SET_CFLAG(context);
1209 break;
1211 default:
1212 INT_BARF( context, 0x21 );
1213 break;
1215 break;
1217 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1218 bSetDOSExtendedError = ((AX_reg(context) = FILE_Dup(BX_reg(context))) == (WORD)HFILE_ERROR16);
1219 break;
1221 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1222 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR32);
1223 break;
1225 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1226 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1227 break;
1229 case 0x48: /* ALLOCATE MEMORY */
1230 case 0x49: /* FREE MEMORY */
1231 case 0x4a: /* RESIZE MEMORY BLOCK */
1232 INT_BARF( context, 0x21 );
1233 break;
1235 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1236 AX_reg(context) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1237 DX_reg(context) ),
1238 SW_NORMAL );
1239 if (AX_reg(context) < 32) SET_CFLAG(context);
1240 break;
1242 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1243 TASK_KillCurrentTask( AL_reg(context) );
1244 break;
1246 case 0x4d: /* GET RETURN CODE */
1247 AX_reg(context) = 0; /* normal exit */
1248 break;
1250 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1251 if (!INT21_FindFirst(context)) break;
1252 /* fall through */
1254 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1255 if (!INT21_FindNext(context))
1257 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1258 AX_reg(context) = ER_NoMoreFiles;
1259 SET_CFLAG(context);
1261 break;
1263 case 0x51: /* GET PSP ADDRESS */
1264 case 0x62: /* GET PSP ADDRESS */
1265 /* FIXME: should we return the original DOS PSP upon */
1266 /* Windows startup ? */
1267 BX_reg(context) = GetCurrentPDB();
1268 break;
1270 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1271 ES_reg(context) = 0x0;
1272 BX_reg(context) = 0x0;
1273 INT_BARF( context, 0x21 );
1274 break;
1276 case 0x56: /* "RENAME" - RENAME FILE */
1277 bSetDOSExtendedError =
1278 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1279 PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context))));
1280 break;
1282 case 0x57: /* FILE DATE AND TIME */
1283 switch (AL_reg(context))
1285 case 0x00: /* Get */
1287 FILETIME filetime;
1288 if (!GetFileTime( BX_reg(context), NULL, NULL, &filetime ))
1289 bSetDOSExtendedError = TRUE;
1290 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1291 &CX_reg(context) );
1293 break;
1295 case 0x01: /* Set */
1297 FILETIME filetime;
1298 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1299 &filetime );
1300 bSetDOSExtendedError =
1301 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1303 break;
1305 break;
1307 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1308 switch (AL_reg(context))
1310 case 0x00:
1311 AX_reg(context) = 1;
1312 break;
1313 case 0x02:
1314 AX_reg(context) = 0;
1315 break;
1316 case 0x01:
1317 case 0x03:
1318 break;
1320 RESET_CFLAG(context);
1321 break;
1323 case 0x5a: /* CREATE TEMPORARY FILE */
1324 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1325 break;
1327 case 0x5b: /* CREATE NEW FILE */
1328 bSetDOSExtendedError = ((AX_reg(context) =
1329 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)), 0 ))
1330 == (WORD)HFILE_ERROR16);
1331 break;
1333 case 0x5d: /* NETWORK */
1334 case 0x5e:
1335 /* network software not installed */
1336 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1337 bSetDOSExtendedError = TRUE;
1338 break;
1340 case 0x5f: /* NETWORK */
1341 switch (AL_reg(context))
1343 case 0x07: /* ENABLE DRIVE */
1344 if (!DRIVE_Enable( DL_reg(context) ))
1346 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1347 bSetDOSExtendedError = TRUE;
1349 break;
1351 case 0x08: /* DISABLE DRIVE */
1352 if (!DRIVE_Disable( DL_reg(context) ))
1354 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1355 bSetDOSExtendedError = TRUE;
1357 break;
1359 default:
1360 /* network software not installed */
1361 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1362 bSetDOSExtendedError = TRUE;
1363 break;
1365 break;
1367 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1369 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1370 SI_reg(context)), 128,
1371 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1372 DI_reg(context)),NULL))
1373 bSetDOSExtendedError = TRUE;
1374 else AX_reg(context) = 0;
1376 break;
1378 case 0x61: /* UNUSED */
1379 case 0x63: /* UNUSED */
1380 case 0x64: /* OS/2 DOS BOX */
1381 INT_BARF( context, 0x21 );
1382 SET_CFLAG(context);
1383 break;
1385 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1386 extern WORD WINE_LanguageId;
1387 BYTE *dataptr=PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context));;
1388 switch (AL_reg(context)) {
1389 case 0x01:
1390 dataptr[0] = 0x1;
1391 *(WORD*)(dataptr+1) = 41;
1392 *(WORD*)(dataptr+3) = WINE_LanguageId;
1393 *(WORD*)(dataptr+5) = CodePage;
1394 break;
1395 case 0x06:
1396 dataptr[0] = 0x06;
1397 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1398 CX_reg(context) = 258;/*FIXME: size of table?*/
1399 break;
1400 default:
1401 INT_BARF( context, 0x21 );
1402 SET_CFLAG(context);
1403 break;
1405 break;
1407 case 0x66: /* GLOBAL CODE PAGE TABLE */
1408 switch (AL_reg(context))
1410 case 0x01:
1411 DX_reg(context) = BX_reg(context) = CodePage;
1412 RESET_CFLAG(context);
1413 break;
1414 case 0x02:
1415 CodePage = BX_reg(context);
1416 RESET_CFLAG(context);
1417 break;
1419 break;
1421 case 0x67: /* SET HANDLE COUNT */
1422 SetHandleCount16( BX_reg(context) );
1423 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1424 break;
1426 case 0x68: /* "FFLUSH" - COMMIT FILE */
1427 case 0x6a: /* COMMIT FILE */
1428 bSetDOSExtendedError = (!FlushFileBuffers( BX_reg(context) ));
1429 break;
1431 case 0x69: /* DISK SERIAL NUMBER */
1432 switch (AL_reg(context))
1434 case 0x00:
1435 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1436 else AX_reg(context) = 0;
1437 break;
1439 case 0x01:
1440 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1441 else AX_reg(context) = 1;
1442 break;
1444 break;
1446 case 0x6C: /* Extended Open/Create*/
1447 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1448 break;
1450 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1451 switch(AL_reg(context))
1453 case 0x39: /* Create directory */
1454 bSetDOSExtendedError = (!CreateDirectory32A(
1455 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1456 DX_reg(context) ), NULL));
1457 break;
1458 case 0x3a: /* Remove directory */
1459 bSetDOSExtendedError = (!RemoveDirectory32A(
1460 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1461 DX_reg(context) )));
1462 break;
1463 case 0x43: /* Get/Set file attributes */
1464 switch (BL_reg(context))
1466 case 0x00: /* Get file attributes */
1467 CX_reg(context) = (WORD)GetFileAttributes32A(
1468 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1469 DX_reg(context)));
1470 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1471 break;
1472 case 0x01:
1473 bSetDOSExtendedError = (!SetFileAttributes32A(
1474 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1475 DX_reg(context)),
1476 CX_reg(context) ) );
1477 break;
1478 default:
1479 fprintf( stderr,
1480 "Unimplemented int21 long file name function:\n");
1481 INT_BARF( context, 0x21 );
1482 SET_CFLAG(context);
1483 AL_reg(context) = 0;
1484 break;
1486 break;
1487 case 0x47: /* Get current directory */
1488 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1489 break;
1491 case 0x4e: /* Find first file */
1492 /* FIXME: use attributes in CX */
1493 if ((AX_reg(context) = FindFirstFile16(
1494 PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1495 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1496 DI_reg(context))))
1497 == INVALID_HANDLE_VALUE16)
1498 bSetDOSExtendedError = TRUE;
1499 break;
1500 case 0x4f: /* Find next file */
1501 if (!FindNextFile16( BX_reg(context),
1502 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1503 DI_reg(context))))
1504 bSetDOSExtendedError = TRUE;
1505 break;
1506 case 0xa1: /* Find close */
1507 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1508 break;
1509 case 0xa0:
1510 break;
1511 case 0x60:
1512 switch(CL_reg(context))
1514 case 0x02: /*Get canonical long filename or path */
1515 if (!GetFullPathName32A
1516 ( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1517 SI_reg(context)), 128,
1518 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1519 DI_reg(context)),NULL))
1520 bSetDOSExtendedError = TRUE;
1521 else AX_reg(context) = 0;
1522 break;
1523 default:
1524 fprintf( stderr,
1525 "Unimplemented int21 long file name function:\n");
1526 INT_BARF( context, 0x21 );
1527 SET_CFLAG(context);
1528 AL_reg(context) = 0;
1529 break;
1531 break;
1532 case 0x6c: /* Create or open file */
1533 /* translate Dos 7 action to Dos 6 action */
1534 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1535 break;
1537 case 0x3b: /* Change directory */
1538 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1539 DS_reg(context),
1540 DX_reg(context)
1543 SET_CFLAG(context);
1544 AL_reg(context) = DOS_ExtendedError;
1546 break;
1547 case 0x41: /* Delete file */
1548 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1549 DS_reg(context),
1550 DX_reg(context))
1551 )) {
1552 SET_CFLAG(context);
1553 AL_reg(context) = DOS_ExtendedError;
1555 break;
1556 case 0x56: /* Move (rename) file */
1557 default:
1558 fprintf( stderr, "Unimplemented int21 long file name function:\n");
1559 INT_BARF( context, 0x21 );
1560 SET_CFLAG(context);
1561 AL_reg(context) = 0;
1562 break;
1564 break;
1566 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1567 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1568 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1569 dprintf_int(stddeb,"int21: windows95 function AX %04x\n",
1570 AX_reg(context));
1571 dprintf_int(stddeb, " returning unimplemented\n");
1572 SET_CFLAG(context);
1573 AL_reg(context) = 0;
1574 break;
1576 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1577 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1578 break;
1580 default:
1581 INT_BARF( context, 0x21 );
1582 break;
1584 } /* END OF SWITCH */
1586 if( bSetDOSExtendedError ) /* set general error condition */
1588 AX_reg(context) = DOS_ExtendedError;
1589 SET_CFLAG(context);
1592 dprintf_int( stddeb, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1593 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1594 AX_reg(context), BX_reg(context), CX_reg(context),
1595 DX_reg(context), SI_reg(context), DI_reg(context),
1596 (WORD)DS_reg(context), (WORD)ES_reg(context),
1597 EFL_reg(context));