Release 980301
[wine/hacks.git] / msdos / int21.c
blob04df4e1e734f5c213c0adaa395b2905165bed57c
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 fprintf( stderr, "INT21_Init: 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)
105 if (drive > 1) {
106 setword(data, 512);
107 data[2] = 2;
108 setword(&data[3], 0);
109 data[5] = 2;
110 setword(&data[6], 240);
111 setword(&data[8], 64000);
112 data[0x0a] = 0xf8;
113 setword(&data[0x0b], 40);
114 setword(&data[0x0d], 56);
115 setword(&data[0x0f], 2);
116 setword(&data[0x11], 0);
117 setword(&data[0x1f], 800);
118 data[0x21] = 5;
119 setword(&data[0x22], 1);
120 } else { /* 1.44mb */
121 setword(data, 512);
122 data[2] = 2;
123 setword(&data[3], 0);
124 data[5] = 2;
125 setword(&data[6], 240);
126 setword(&data[8], 2880);
127 data[0x0a] = 0xf8;
128 setword(&data[0x0b], 6);
129 setword(&data[0x0d], 18);
130 setword(&data[0x0f], 2);
131 setword(&data[0x11], 0);
132 setword(&data[0x1f], 80);
133 data[0x21] = 7;
134 setword(&data[0x22], 2);
138 static int INT21_GetFreeDiskSpace( CONTEXT *context )
140 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
141 char root[] = "A:\\";
143 *root += DOS_GET_DRIVE( DL_reg(context) );
144 if (!GetDiskFreeSpace32A( root, &cluster_sectors, &sector_bytes,
145 &free_clusters, &total_clusters )) return 0;
146 AX_reg(context) = cluster_sectors;
147 BX_reg(context) = free_clusters;
148 CX_reg(context) = sector_bytes;
149 DX_reg(context) = total_clusters;
150 return 1;
153 static int INT21_GetDriveAllocInfo( CONTEXT *context )
155 if (!INT21_GetFreeDiskSpace( context )) return 0;
156 if (!heap && !INT21_CreateHeap()) return 0;
157 heap->mediaID = 0xf0;
158 DS_reg(context) = DosHeapHandle;
159 BX_reg(context) = (int)&heap->mediaID - (int)heap;
160 return 1;
163 static void GetDrivePB( CONTEXT *context, int drive )
165 if(!DRIVE_IsValid(drive))
167 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
168 AX_reg(context) = 0x00ff;
170 else if (heap || INT21_CreateHeap())
172 dprintf_fixme(int, "int21: GetDrivePB not fully implemented.\n");
174 /* FIXME: I have no idea what a lot of this information should
175 * say or whether it even really matters since we're not allowing
176 * direct block access. However, some programs seem to depend on
177 * getting at least _something_ back from here. The 'next' pointer
178 * does worry me, though. Should we have a complete table of
179 * separate DPBs per drive? Probably, but I'm lazy. :-) -CH
181 heap->dpb.drive_num = heap->dpb.unit_num = drive; /*The same?*/
182 heap->dpb.sector_size = 512;
183 heap->dpb.high_sector = 1;
184 heap->dpb.shift = drive < 2 ? 0 : 6; /*6 for HD, 0 for floppy*/
185 heap->dpb.reserved = 0;
186 heap->dpb.num_FAT = 1;
187 heap->dpb.dir_entries = 2;
188 heap->dpb.first_data = 2;
189 heap->dpb.high_cluster = 64000;
190 heap->dpb.sectors_in_FAT = 1;
191 heap->dpb.start_dir = 1;
192 heap->dpb.driver_head = 0;
193 heap->dpb.media_ID = (drive > 1) ? 0xF8 : 0xF0;
194 heap->dpb.access_flag = 0;
195 heap->dpb.next = 0;
196 heap->dpb.free_search = 0;
197 heap->dpb.free_clusters = 0xFFFF; /* unknown */
199 AL_reg(context) = 0x00;
200 DS_reg(context) = SELECTOROF(dpbsegptr);
201 BX_reg(context) = OFFSETOF(dpbsegptr);
206 static void ioctlGetDeviceInfo( CONTEXT *context )
208 int curr_drive;
209 dprintf_info(int, "int21: ioctl (%d, GetDeviceInfo)\n", BX_reg(context));
211 curr_drive = DRIVE_GetCurrentDrive();
212 DX_reg(context) = 0x0140 + curr_drive + ((curr_drive > 1) ? 0x0800 : 0); /* no floppy */
213 /* bits 0-5 are current drive
214 * bit 6 - file has NOT been written..FIXME: correct?
215 * bit 8 - generate int24 if no diskspace on write/ read past end of file
216 * bit 11 - media not removable
218 RESET_CFLAG(context);
221 static BOOL32 ioctlGenericBlkDevReq( CONTEXT *context )
223 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
224 int drive = DOS_GET_DRIVE( BL_reg(context) );
226 if (!DRIVE_IsValid(drive))
228 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
229 return TRUE;
232 if (CH_reg(context) != 0x08)
234 INT_BARF( context, 0x21 );
235 return FALSE;
238 switch (CL_reg(context))
240 case 0x4a: /* lock logical volume */
241 dprintf_info(int,"int21: lock logical volume (%d) level %d mode %d\n",drive,BH_reg(context),DX_reg(context));
242 break;
244 case 0x60: /* get device parameters */
245 /* used by w4wgrp's winfile */
246 memset(dataptr, 0, 0x26);
247 dataptr[0] = 0x04;
248 dataptr[6] = 0; /* media type */
249 if (drive > 1)
251 dataptr[1] = 0x05; /* fixed disk */
252 setword(&dataptr[2], 0x01); /* non removable */
253 setword(&dataptr[4], 0x300); /* # of cylinders */
255 else
257 dataptr[1] = 0x07; /* block dev, floppy */
258 setword(&dataptr[2], 0x02); /* removable */
259 setword(&dataptr[4], 80); /* # of cylinders */
261 CreateBPB(drive, &dataptr[7]);
262 RESET_CFLAG(context);
263 break;
265 case 0x66:/* get disk serial number */
267 char label[12],fsname[9],path[4];
268 DWORD serial;
270 strcpy(path,"x:\\");path[0]=drive+'A';
271 GetVolumeInformation32A(
272 path,label,12,&serial,NULL,NULL,fsname,9
274 *(WORD*)dataptr = 0;
275 memcpy(dataptr+2,&serial,4);
276 memcpy(dataptr+6,label ,11);
277 memcpy(dataptr+17,fsname,8);
279 break;
281 case 0x6a:
282 dprintf_info(int,"int21: logical volume %d unlocked.\n",drive);
283 break;
285 default:
286 INT_BARF( context, 0x21 );
288 return FALSE;
291 static void INT21_GetSystemDate( CONTEXT *context )
293 SYSTEMTIME systime;
294 GetLocalTime( &systime );
295 CX_reg(context) = systime.wYear;
296 DX_reg(context) = (systime.wMonth << 8) | systime.wDay;
297 AX_reg(context) = systime.wDayOfWeek;
300 static void INT21_GetSystemTime( CONTEXT *context )
302 SYSTEMTIME systime;
303 GetLocalTime( &systime );
304 CX_reg(context) = (systime.wHour << 8) | systime.wMinute;
305 DX_reg(context) = (systime.wSecond << 8) | (systime.wMilliseconds / 10);
308 static BOOL32 INT21_CreateFile( CONTEXT *context )
310 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
311 DX_reg(context) ), CX_reg(context) );
312 return (AX_reg(context) == (WORD)HFILE_ERROR16);
316 static void OpenExistingFile( CONTEXT *context )
318 AX_reg(context) = _lopen16( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
319 AL_reg(context) );
320 if (AX_reg(context) == (WORD)HFILE_ERROR16)
322 AX_reg(context) = DOS_ExtendedError;
323 SET_CFLAG(context);
325 #if 0
327 int handle;
328 int mode;
329 int lock;
331 switch (AX_reg(context) & 0x0070)
333 case 0x00: /* compatability mode */
334 case 0x40: /* DENYNONE */
335 lock = -1;
336 break;
338 case 0x30: /* DENYREAD */
339 dprintf_info(int,
340 "OpenExistingFile (%s): DENYREAD changed to DENYALL\n",
341 (char *)PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)));
342 case 0x10: /* DENYALL */
343 lock = LOCK_EX;
344 break;
346 case 0x20: /* DENYWRITE */
347 lock = LOCK_SH;
348 break;
350 default:
351 lock = -1;
354 if (lock != -1)
357 int result,retries=sharing_retries;
359 #if defined(__svr4__) || defined(_SCO_DS)
360 printf("Should call flock and needs porting to lockf\n");
361 result = 0;
362 retries = 0;
363 #else
364 result = flock(handle, lock | LOCK_NB);
365 #endif
366 if ( retries && (!result) )
368 int i;
369 for(i=0;i<32768*((int)sharing_pause);i++)
370 result++; /* stop the optimizer */
371 for(i=0;i<32768*((int)sharing_pause);i++)
372 result--;
375 while( (!result) && (!(retries--)) );
377 if(result)
379 errno_to_doserr();
380 AX_reg(context) = DOS_ExtendedError;
381 close(handle);
382 SET_CFLAG(context);
383 return;
388 Error (0,0,0);
389 AX_reg(context) = handle;
390 RESET_CFLAG(context);
392 #endif
395 static void CloseFile( CONTEXT *context )
397 if ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0)
399 AX_reg(context) = DOS_ExtendedError;
400 SET_CFLAG(context);
404 static BOOL32 INT21_ExtendedOpenCreateFile(CONTEXT *context )
406 BOOL32 bExtendedError = FALSE;
407 BYTE action = DL_reg(context);
409 /* Shuffle arguments to call OpenExistingFile */
410 AL_reg(context) = BL_reg(context);
411 DX_reg(context) = SI_reg(context);
412 /* BX,CX and DX should be preserved */
413 OpenExistingFile(context);
415 if ((EFL_reg(context) & 0x0001) == 0) /* File exists */
417 UINT16 uReturnCX = 0;
419 /* Now decide what do do */
421 if ((action & 0x07) == 0)
423 BX_reg(context) = AX_reg(context);
424 CloseFile(context);
425 AX_reg(context) = 0x0050; /*File exists*/
426 SET_CFLAG(context);
427 dprintf_warn(int, "int21: extended open/create: failed because file exists \n");
429 else if ((action & 0x07) == 2)
431 /* Truncate it, but first check if opened for write */
432 if ((BL_reg(context) & 0x0007)== 0)
434 BX_reg(context) = AX_reg(context);
435 CloseFile(context);
436 dprintf_warn(int, "int21: extended open/create: failed, trunc on ro file\n");
437 AX_reg(context) = 0x000C; /*Access code invalid*/
438 SET_CFLAG(context);
440 else
442 /* Shuffle arguments to call CloseFile while
443 * preserving BX and DX */
445 dprintf_info(int, "int21: extended open/create: Closing before truncate\n");
446 BX_reg(context) = AX_reg(context);
447 CloseFile(context);
448 if (EFL_reg(context) & 0x0001)
450 dprintf_warn(int, "int21: extended open/create: close before trunc failed\n");
451 AX_reg(context) = 0x0019; /*Seek Error*/
452 CX_reg(context) = 0;
453 SET_CFLAG(context);
455 /* Shuffle arguments to call CreateFile */
457 dprintf_info(int, "int21: extended open/create: Truncating\n");
458 AL_reg(context) = BL_reg(context);
459 /* CX is still the same */
460 DX_reg(context) = SI_reg(context);
461 bExtendedError = INT21_CreateFile(context);
463 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
465 dprintf_warn(int, "int21: extended open/create: trunc failed\n");
466 return bExtendedError;
468 uReturnCX = 0x3;
471 else uReturnCX = 0x1;
473 CX_reg(context) = uReturnCX;
475 else /* file does not exist */
477 RESET_CFLAG(context); /* was set by OpenExistingFile(context) */
478 if ((action & 0xF0)== 0)
480 CX_reg(context) = 0;
481 SET_CFLAG(context);
482 dprintf_warn(int, "int21: extended open/create: failed, file dosen't exist\n");
484 else
486 /* Shuffle arguments to call CreateFile */
487 dprintf_info(int, "int21: extended open/create: Creating\n");
488 AL_reg(context) = BL_reg(context);
489 /* CX should still be the same */
490 DX_reg(context) = SI_reg(context);
491 bExtendedError = INT21_CreateFile(context);
492 if (EFL_reg(context) & 0x0001) /*no file open, flags set */
494 dprintf_warn(int, "int21: extended open/create: create failed\n");
495 return bExtendedError;
497 CX_reg(context) = 2;
501 return bExtendedError;
505 static BOOL32 INT21_ChangeDir( CONTEXT *context )
507 int drive;
508 char *dirname = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
510 dprintf_info(int,"int21: changedir %s\n", dirname);
511 if (dirname[0] && (dirname[1] == ':'))
513 drive = toupper(dirname[0]) - 'A';
514 dirname += 2;
516 else drive = DRIVE_GetCurrentDrive();
517 return DRIVE_Chdir( drive, dirname );
521 static int INT21_FindFirst( CONTEXT *context )
523 char *p;
524 const char *path;
525 DOS_FULL_NAME full_name;
526 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
528 path = (const char *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
529 dta->unixPath = NULL;
530 if (!DOSFS_GetFullName( path, FALSE, &full_name ))
532 AX_reg(context) = DOS_ExtendedError;
533 SET_CFLAG(context);
534 return 0;
536 dta->unixPath = HEAP_strdupA( GetProcessHeap(), 0, full_name.long_name );
537 p = strrchr( dta->unixPath, '/' );
538 *p = '\0';
540 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
541 * (doesn't matter as it is set below anyway)
543 if (!DOSFS_ToDosFCBFormat( p + 1, dta->mask ))
545 HeapFree( GetProcessHeap(), 0, dta->unixPath );
546 dta->unixPath = NULL;
547 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
548 AX_reg(context) = ER_FileNotFound;
549 SET_CFLAG(context);
550 return 0;
552 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
553 : DRIVE_GetCurrentDrive();
554 dta->count = 0;
555 dta->search_attr = CL_reg(context);
556 return 1;
560 static int INT21_FindNext( CONTEXT *context )
562 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA();
563 WIN32_FIND_DATA32A entry;
564 int count;
566 if (!dta->unixPath) return 0;
567 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
568 dta->search_attr, dta->count, &entry )))
570 HeapFree( GetProcessHeap(), 0, dta->unixPath );
571 dta->unixPath = NULL;
572 return 0;
574 if ((int)dta->count + count > 0xffff)
576 fprintf( stderr, "Too many directory entries in %s\n", dta->unixPath );
577 HeapFree( GetProcessHeap(), 0, dta->unixPath );
578 dta->unixPath = NULL;
579 return 0;
581 dta->count += count;
582 dta->fileattr = entry.dwFileAttributes;
583 dta->filesize = entry.nFileSizeLow;
584 FileTimeToDosDateTime( &entry.ftLastWriteTime,
585 &dta->filedate, &dta->filetime );
586 strcpy( dta->filename, entry.cAlternateFileName );
587 return 1;
591 static BOOL32 INT21_CreateTempFile( CONTEXT *context )
593 static int counter = 0;
594 char *name = PTR_SEG_OFF_TO_LIN( DS_reg(context), DX_reg(context) );
595 char *p = name + strlen(name);
597 /* despite what Ralf Brown says, some programs seem to call without
598 * ending backslash (DOS accepts that, so we accept it too) */
599 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
601 for (;;)
603 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
604 counter = (counter + 1) % 1000;
606 if ((AX_reg(context) = _lcreat_uniq( name, 0 )) != (WORD)HFILE_ERROR16)
608 dprintf_info(int, "INT21_CreateTempFile: created %s\n", name );
609 return TRUE;
611 if (DOS_ExtendedError != ER_FileExists) return FALSE;
616 static BOOL32 INT21_GetCurrentDirectory( CONTEXT *context )
618 int drive = DOS_GET_DRIVE( DL_reg(context) );
619 char *ptr = (char *)PTR_SEG_OFF_TO_LIN( DS_reg(context), SI_reg(context) );
621 if (!DRIVE_IsValid(drive))
623 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
624 return FALSE;
626 lstrcpyn32A( ptr, DRIVE_GetDosCwd(drive), 64 );
627 AX_reg(context) = 0x0100; /* success return code */
628 return TRUE;
632 static int INT21_GetDiskSerialNumber( CONTEXT *context )
634 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
635 int drive = DOS_GET_DRIVE( BL_reg(context) );
637 if (!DRIVE_IsValid(drive))
639 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
640 return 0;
643 *(WORD *)dataptr = 0;
644 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
645 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
646 strncpy(dataptr + 0x11, "FAT16 ", 8);
647 return 1;
651 static int INT21_SetDiskSerialNumber( CONTEXT *context )
653 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
654 int drive = DOS_GET_DRIVE( BL_reg(context) );
656 if (!DRIVE_IsValid(drive))
658 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
659 return 0;
662 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
663 return 1;
667 /* microsoft's programmers should be shot for using CP/M style int21
668 calls in Windows for Workgroup's winfile.exe */
670 static int INT21_FindFirstFCB( CONTEXT *context )
672 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
673 FINDFILE_FCB *pFCB;
674 LPCSTR root, cwd;
675 int drive;
677 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
678 else pFCB = (FINDFILE_FCB *)fcb;
679 drive = DOS_GET_DRIVE( pFCB->drive );
680 root = DRIVE_GetRoot( drive );
681 cwd = DRIVE_GetUnixCwd( drive );
682 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
683 strlen(root)+strlen(cwd)+2 );
684 if (!pFCB->unixPath) return 0;
685 strcpy( pFCB->unixPath, root );
686 strcat( pFCB->unixPath, "/" );
687 strcat( pFCB->unixPath, cwd );
688 pFCB->count = 0;
689 return 1;
693 static int INT21_FindNextFCB( CONTEXT *context )
695 BYTE *fcb = (BYTE *)PTR_SEG_OFF_TO_LIN(DS_reg(context), DX_reg(context));
696 FINDFILE_FCB *pFCB;
697 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA();
698 WIN32_FIND_DATA32A entry;
699 BYTE attr;
700 int count;
702 if (*fcb == 0xff) /* extended FCB ? */
704 attr = fcb[6];
705 pFCB = (FINDFILE_FCB *)(fcb + 7);
707 else
709 attr = 0;
710 pFCB = (FINDFILE_FCB *)fcb;
713 if (!pFCB->unixPath) return 0;
714 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
715 DOS_GET_DRIVE( pFCB->drive ), attr,
716 pFCB->count, &entry )))
718 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
719 pFCB->unixPath = NULL;
720 return 0;
722 pFCB->count += count;
724 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
725 *(BYTE *)pResult = 0xff;
726 (BYTE *)pResult +=6; /* leave reserved field behind */
727 *(BYTE *)pResult = entry.dwFileAttributes;
728 ((BYTE *)pResult)++;
730 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
731 ((BYTE *)pResult)++;
732 pResult->fileattr = entry.dwFileAttributes;
733 pResult->cluster = 0; /* what else? */
734 pResult->filesize = entry.nFileSizeLow;
735 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
736 FileTimeToDosDateTime( &entry.ftLastWriteTime,
737 &pResult->filedate, &pResult->filetime );
739 /* Convert file name to FCB format */
741 memset( pResult->filename, ' ', sizeof(pResult->filename) );
742 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
743 else if (!strcmp( entry.cAlternateFileName, ".." ))
744 pResult->filename[0] = pResult->filename[1] = '.';
745 else
747 char *p = strrchr( entry.cAlternateFileName, '.' );
748 if (p && p[1] && (p != entry.cAlternateFileName))
750 memcpy( pResult->filename, entry.cAlternateFileName,
751 MIN( (p - entry.cAlternateFileName), 8 ) );
752 memcpy( pResult->filename + 8, p + 1, MIN( strlen(p), 3 ) );
754 else
755 memcpy( pResult->filename, entry.cAlternateFileName,
756 MIN( strlen(entry.cAlternateFileName), 8 ) );
758 return 1;
762 static void DeleteFileFCB( CONTEXT *context )
764 fprintf( stderr, "DeleteFileFCB: not implemented yet\n" );
767 static void RenameFileFCB( CONTEXT *context )
769 fprintf( stderr, "RenameFileFCB: not implemented yet\n" );
774 static void fLock( CONTEXT * context )
777 switch ( AX_reg(context) & 0xff )
779 case 0x00: /* LOCK */
780 if (!LockFile(BX_reg(context),
781 MAKELONG(DX_reg(context),CX_reg(context)), 0,
782 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
783 AX_reg(context) = DOS_ExtendedError;
784 SET_CFLAG(context);
786 break;
788 case 0x01: /* UNLOCK */
789 if (!UnlockFile(BX_reg(context),
790 MAKELONG(DX_reg(context),CX_reg(context)), 0,
791 MAKELONG(DI_reg(context),SI_reg(context)), 0)) {
792 AX_reg(context) = DOS_ExtendedError;
793 SET_CFLAG(context);
795 return;
796 default:
797 AX_reg(context) = 0x0001;
798 SET_CFLAG(context);
799 return;
804 extern void LOCAL_PrintHeap (WORD ds);
806 /***********************************************************************
807 * DOS3Call (KERNEL.102)
809 void WINAPI DOS3Call( CONTEXT *context )
811 BOOL32 bSetDOSExtendedError = FALSE;
813 dprintf_info(int, "int21: AX=%04x BX=%04x CX=%04x DX=%04x "
814 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
815 AX_reg(context), BX_reg(context), CX_reg(context),
816 DX_reg(context), SI_reg(context), DI_reg(context),
817 (WORD)DS_reg(context), (WORD)ES_reg(context),
818 EFL_reg(context) );
820 if (AH_reg(context) == 0x59) /* Get extended error info */
822 AX_reg(context) = DOS_ExtendedError;
823 BH_reg(context) = DOS_ErrorClass;
824 BL_reg(context) = DOS_ErrorAction;
825 CH_reg(context) = DOS_ErrorLocus;
826 return;
829 DOS_ERROR( 0, 0, 0, 0 );
830 RESET_CFLAG(context); /* Not sure if this is a good idea */
832 switch(AH_reg(context))
834 case 0x00: /* TERMINATE PROGRAM */
835 TASK_KillCurrentTask( 0 );
836 break;
838 case 0x01: /* READ CHARACTER FROM STANDARD INPUT, WITH ECHO */
839 case 0x02: /* WRITE CHARACTER TO STANDARD OUTPUT */
840 case 0x03: /* READ CHARACTER FROM STDAUX */
841 case 0x04: /* WRITE CHARACTER TO STDAUX */
842 case 0x05: /* WRITE CHARACTER TO PRINTER */
843 case 0x06: /* DIRECT CONSOLE IN/OUTPUT */
844 case 0x07: /* DIRECT CHARACTER INPUT, WITHOUT ECHO */
845 case 0x08: /* CHARACTER INPUT WITHOUT ECHO */
846 case 0x09: /* WRITE STRING TO STANDARD OUTPUT */
847 case 0x0a: /* BUFFERED INPUT */
848 case 0x0b: /* GET STDIN STATUS */
849 case 0x0c: /* FLUSH BUFFER AND READ STANDARD INPUT */
850 case 0x0f: /* OPEN FILE USING FCB */
851 case 0x10: /* CLOSE FILE USING FCB */
852 case 0x14: /* SEQUENTIAL READ FROM FCB FILE */
853 case 0x15: /* SEQUENTIAL WRITE TO FCB FILE */
854 case 0x16: /* CREATE OR TRUNCATE FILE USING FCB */
855 case 0x21: /* READ RANDOM RECORD FROM FCB FILE */
856 case 0x22: /* WRITE RANDOM RECORD TO FCB FILE */
857 case 0x23: /* GET FILE SIZE FOR FCB */
858 case 0x24: /* SET RANDOM RECORD NUMBER FOR FCB */
859 case 0x26: /* CREATE NEW PROGRAM SEGMENT PREFIX */
860 case 0x27: /* RANDOM BLOCK READ FROM FCB FILE */
861 case 0x28: /* RANDOM BLOCK WRITE TO FCB FILE */
862 case 0x29: /* PARSE FILENAME INTO FCB */
863 case 0x37: /* "SWITCHAR" - GET SWITCH CHARACTER
864 "SWITCHAR" - SET SWITCH CHARACTER
865 "AVAILDEV" - SPECIFY \DEV\ PREFIX USE */
866 case 0x54: /* GET VERIFY FLAG */
867 INT_BARF( context, 0x21 );
868 break;
869 case 0x2e: /* SET VERIFY FLAG */
870 /* we cannot change the behaviour anyway, so just ignore it */
871 break;
873 case 0x18: /* NULL FUNCTIONS FOR CP/M COMPATIBILITY */
874 case 0x1d:
875 case 0x1e:
876 case 0x20:
877 case 0x6b: /* NULL FUNCTION */
878 AL_reg(context) = 0;
879 break;
881 case 0x5c: /* "FLOCK" - RECORD LOCKING */
882 fLock(context);
883 break;
885 case 0x0d: /* DISK BUFFER FLUSH */
886 RESET_CFLAG(context); /* dos 6+ only */
887 break;
889 case 0x0e: /* SELECT DEFAULT DRIVE */
890 DRIVE_SetCurrentDrive( DL_reg(context) );
891 AL_reg(context) = MAX_DOS_DRIVES;
892 break;
894 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
895 if (!INT21_FindFirstFCB(context))
897 AL_reg(context) = 0xff;
898 break;
900 /* else fall through */
902 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
903 AL_reg(context) = INT21_FindNextFCB(context) ? 0x00 : 0xff;
904 break;
906 case 0x13: /* DELETE FILE USING FCB */
907 DeleteFileFCB(context);
908 break;
910 case 0x17: /* RENAME FILE USING FCB */
911 RenameFileFCB(context);
912 break;
914 case 0x19: /* GET CURRENT DEFAULT DRIVE */
915 AL_reg(context) = DRIVE_GetCurrentDrive();
916 break;
918 case 0x1a: /* SET DISK TRANSFER AREA ADDRESS */
920 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
921 pTask->dta = PTR_SEG_OFF_TO_SEGPTR(DS_reg(context),DX_reg(context));
922 dprintf_info(int, "int21: Set DTA: %08lx\n", pTask->dta);
924 break;
926 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
927 DL_reg(context) = 0;
928 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
929 break;
931 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
932 if (!INT21_GetDriveAllocInfo(context)) AX_reg(context) = 0xffff;
933 break;
935 case 0x1f: /* GET DRIVE PARAMETER BLOCK FOR DEFAULT DRIVE */
936 GetDrivePB(context, DRIVE_GetCurrentDrive());
937 break;
939 case 0x25: /* SET INTERRUPT VECTOR */
940 INT_SetHandler( AL_reg(context),
941 (FARPROC16)PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
942 DX_reg(context)));
943 break;
945 case 0x2a: /* GET SYSTEM DATE */
946 INT21_GetSystemDate(context);
947 break;
949 case 0x2b: /* SET SYSTEM DATE */
950 fprintf( stdnimp, "SetSystemDate(%02d/%02d/%04d): not allowed\n",
951 DL_reg(context), DH_reg(context), CX_reg(context) );
952 AL_reg(context) = 0; /* Let's pretend we succeeded */
953 break;
955 case 0x2c: /* GET SYSTEM TIME */
956 INT21_GetSystemTime(context);
957 break;
959 case 0x2d: /* SET SYSTEM TIME */
960 fprintf( stdnimp, "SetSystemTime(%02d:%02d:%02d.%02d): not allowed\n",
961 CH_reg(context), CL_reg(context),
962 DH_reg(context), DL_reg(context) );
963 AL_reg(context) = 0; /* Let's pretend we succeeded */
964 break;
966 case 0x2f: /* GET DISK TRANSFER AREA ADDRESS */
968 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
969 ES_reg(context) = SELECTOROF( pTask->dta );
970 BX_reg(context) = OFFSETOF( pTask->dta );
972 break;
974 case 0x30: /* GET DOS VERSION */
975 AX_reg(context) = (HIWORD(GetVersion16()) >> 8) |
976 (HIWORD(GetVersion16()) << 8);
977 BX_reg(context) = 0x0012; /* 0x123456 is Wine's serial # */
978 CX_reg(context) = 0x3456;
979 break;
981 case 0x31: /* TERMINATE AND STAY RESIDENT */
982 INT_BARF( context, 0x21 );
983 break;
985 case 0x32: /* GET DOS DRIVE PARAMETER BLOCK FOR SPECIFIC DRIVE */
986 GetDrivePB(context, DOS_GET_DRIVE( DL_reg(context) ) );
987 break;
989 case 0x33: /* MULTIPLEXED */
990 switch (AL_reg(context))
992 case 0x00: /* GET CURRENT EXTENDED BREAK STATE */
993 DL_reg(context) = 0;
994 break;
996 case 0x01: /* SET EXTENDED BREAK STATE */
997 break;
999 case 0x02: /* GET AND SET EXTENDED CONTROL-BREAK CHECKING STATE*/
1000 DL_reg(context) = 0;
1001 break;
1003 case 0x05: /* GET BOOT DRIVE */
1004 DL_reg(context) = 3;
1005 /* c: is Wine's bootdrive (a: is 1)*/
1006 break;
1008 case 0x06: /* GET TRUE VERSION NUMBER */
1009 BX_reg(context) = (HIWORD(GetVersion16() >> 8)) |
1010 (HIWORD(GetVersion16() << 8));
1011 DX_reg(context) = 0x00;
1012 break;
1014 default:
1015 INT_BARF( context, 0x21 );
1016 break;
1018 break;
1020 case 0x34: /* GET ADDRESS OF INDOS FLAG */
1021 if (!heap) INT21_CreateHeap();
1022 ES_reg(context) = DosHeapHandle;
1023 BX_reg(context) = (int)&heap->InDosFlag - (int)heap;
1024 break;
1026 case 0x35: /* GET INTERRUPT VECTOR */
1028 FARPROC16 addr = INT_GetHandler( AL_reg(context) );
1029 ES_reg(context) = SELECTOROF(addr);
1030 BX_reg(context) = OFFSETOF(addr);
1032 break;
1034 case 0x36: /* GET FREE DISK SPACE */
1035 if (!INT21_GetFreeDiskSpace(context)) AX_reg(context) = 0xffff;
1036 break;
1038 case 0x38: /* GET COUNTRY-SPECIFIC INFORMATION */
1039 AX_reg(context) = 0x02; /* no country support available */
1040 SET_CFLAG(context);
1041 break;
1043 case 0x39: /* "MKDIR" - CREATE SUBDIRECTORY */
1044 bSetDOSExtendedError = (!CreateDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1045 DX_reg(context) ), NULL));
1046 break;
1048 case 0x3a: /* "RMDIR" - REMOVE SUBDIRECTORY */
1049 bSetDOSExtendedError = (!RemoveDirectory16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1050 DX_reg(context) )));
1051 break;
1053 case 0x3b: /* "CHDIR" - SET CURRENT DIRECTORY */
1054 bSetDOSExtendedError = !INT21_ChangeDir(context);
1055 break;
1057 case 0x3c: /* "CREAT" - CREATE OR TRUNCATE FILE */
1058 AX_reg(context) = _lcreat16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1059 DX_reg(context) ), CX_reg(context) );
1060 bSetDOSExtendedError = (AX_reg(context) == (WORD)HFILE_ERROR16);
1061 break;
1063 case 0x3d: /* "OPEN" - OPEN EXISTING FILE */
1064 OpenExistingFile(context);
1065 break;
1067 case 0x3e: /* "CLOSE" - CLOSE FILE */
1068 bSetDOSExtendedError = ((AX_reg(context) = _lclose16( BX_reg(context) )) != 0);
1069 break;
1071 case 0x3f: /* "READ" - READ FROM FILE OR DEVICE */
1073 LONG result = WIN16_hread( BX_reg(context),
1074 PTR_SEG_OFF_TO_SEGPTR( DS_reg(context),
1075 DX_reg(context) ),
1076 CX_reg(context) );
1077 if (result == -1) bSetDOSExtendedError = TRUE;
1078 else AX_reg(context) = (WORD)result;
1080 break;
1082 case 0x40: /* "WRITE" - WRITE TO FILE OR DEVICE */
1084 LONG result = _hwrite16( BX_reg(context),
1085 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1086 DX_reg(context) ),
1087 CX_reg(context) );
1088 if (result == -1) bSetDOSExtendedError = TRUE;
1089 else AX_reg(context) = (WORD)result;
1091 break;
1093 case 0x41: /* "UNLINK" - DELETE FILE */
1094 bSetDOSExtendedError = (!DeleteFile32A( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1095 DX_reg(context) )));
1096 break;
1098 case 0x42: /* "LSEEK" - SET CURRENT FILE POSITION */
1100 LONG status = _llseek16( BX_reg(context),
1101 MAKELONG(DX_reg(context),CX_reg(context)),
1102 AL_reg(context) );
1103 if (status == -1) bSetDOSExtendedError = TRUE;
1104 else
1106 AX_reg(context) = LOWORD(status);
1107 DX_reg(context) = HIWORD(status);
1110 break;
1112 case 0x43: /* FILE ATTRIBUTES */
1113 switch (AL_reg(context))
1115 case 0x00:
1116 AX_reg(context) = (WORD)GetFileAttributes32A(
1117 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1118 DX_reg(context)));
1119 if (AX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1120 else CX_reg(context) = AX_reg(context);
1121 break;
1123 case 0x01:
1124 bSetDOSExtendedError =
1125 (!SetFileAttributes32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1126 DX_reg(context)),
1127 CX_reg(context) ));
1128 break;
1130 break;
1132 case 0x44: /* IOCTL */
1133 switch (AL_reg(context))
1135 case 0x00:
1136 ioctlGetDeviceInfo(context);
1137 break;
1139 case 0x01:
1140 break;
1141 case 0x05:{ /* IOCTL - WRITE TO BLOCK DEVICE CONTROL CHANNEL */
1142 BYTE *dataptr = PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context));
1143 int i;
1144 int drive = DOS_GET_DRIVE(BL_reg(context));
1146 fprintf(stdnimp,"int21: program tried to write to block device control channel of drive %d:\n",drive);
1147 for (i=0;i<CX_reg(context);i++)
1148 fprintf(stdnimp,"%02x ",dataptr[i]);
1149 fprintf(stdnimp,"\n");
1150 AX_reg(context)=CX_reg(context);
1151 break;
1153 case 0x08: /* Check if drive is removable. */
1154 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1156 case DRIVE_CANNOTDETERMINE:
1157 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1158 AX_reg(context) = ER_InvalidDrive;
1159 SET_CFLAG(context);
1160 break;
1161 case DRIVE_REMOVABLE:
1162 AX_reg(context) = 0; /* removable */
1163 break;
1164 default:
1165 AX_reg(context) = 1; /* not removable */
1166 break;
1168 break;
1170 case 0x09: /* CHECK IF BLOCK DEVICE REMOTE */
1171 switch(GetDriveType16( DOS_GET_DRIVE( BL_reg(context) )))
1173 case DRIVE_CANNOTDETERMINE:
1174 DOS_ERROR( ER_InvalidDrive, EC_NotFound, SA_Abort, EL_Disk );
1175 AX_reg(context) = ER_InvalidDrive;
1176 SET_CFLAG(context);
1177 break;
1178 case DRIVE_REMOTE:
1179 DX_reg(context) = (1<<9) | (1<<12); /* remote */
1180 break;
1181 default:
1182 DX_reg(context) = 0; /* FIXME: use driver attr here */
1183 break;
1185 break;
1187 case 0x0a: /* check if handle (BX) is remote */
1188 /* returns DX, bit 15 set if remote, bit 14 set if date/time
1189 * not set on close
1191 DX_reg(context) = 0;
1192 break;
1194 case 0x0b: /* SET SHARING RETRY COUNT */
1195 if (!CX_reg(context))
1197 AX_reg(context) = 1;
1198 SET_CFLAG(context);
1199 break;
1201 sharing_pause = CX_reg(context);
1202 if (!DX_reg(context))
1203 sharing_retries = DX_reg(context);
1204 RESET_CFLAG(context);
1205 break;
1207 case 0x0d:
1208 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
1209 break;
1211 case 0x0e: /* get logical drive mapping */
1212 AL_reg(context) = 0; /* drive has no mapping - FIXME: may be wrong*/
1213 break;
1215 case 0x0F: /* Set logical drive mapping */
1217 int drive;
1218 drive = DOS_GET_DRIVE ( BL_reg(context) );
1219 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
1221 SET_CFLAG(context);
1222 AX_reg(context) = 0x000F; /* invalid drive */
1224 break;
1227 default:
1228 INT_BARF( context, 0x21 );
1229 break;
1231 break;
1233 case 0x45: /* "DUP" - DUPLICATE FILE HANDLE */
1234 bSetDOSExtendedError = ((AX_reg(context) = FILE_Dup(BX_reg(context))) == (WORD)HFILE_ERROR16);
1235 break;
1237 case 0x46: /* "DUP2", "FORCEDUP" - FORCE DUPLICATE FILE HANDLE */
1238 bSetDOSExtendedError = (FILE_Dup2( BX_reg(context), CX_reg(context) ) == HFILE_ERROR32);
1239 break;
1241 case 0x47: /* "CWD" - GET CURRENT DIRECTORY */
1242 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1243 break;
1245 case 0x48: /* ALLOCATE MEMORY */
1246 case 0x49: /* FREE MEMORY */
1247 case 0x4a: /* RESIZE MEMORY BLOCK */
1248 INT_BARF( context, 0x21 );
1249 break;
1251 case 0x4b: /* "EXEC" - LOAD AND/OR EXECUTE PROGRAM */
1252 AX_reg(context) = WinExec16( PTR_SEG_OFF_TO_LIN( DS_reg(context),
1253 DX_reg(context) ),
1254 SW_NORMAL );
1255 if (AX_reg(context) < 32) SET_CFLAG(context);
1256 break;
1258 case 0x4c: /* "EXIT" - TERMINATE WITH RETURN CODE */
1259 TASK_KillCurrentTask( AL_reg(context) );
1260 break;
1262 case 0x4d: /* GET RETURN CODE */
1263 AX_reg(context) = 0; /* normal exit */
1264 break;
1266 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
1267 if (!INT21_FindFirst(context)) break;
1268 /* fall through */
1270 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
1271 if (!INT21_FindNext(context))
1273 DOS_ERROR( ER_NoMoreFiles, EC_MediaError, SA_Abort, EL_Disk );
1274 AX_reg(context) = ER_NoMoreFiles;
1275 SET_CFLAG(context);
1277 else AX_reg(context) = 0; /* OK */
1278 break;
1280 case 0x51: /* GET PSP ADDRESS */
1281 case 0x62: /* GET PSP ADDRESS */
1282 /* FIXME: should we return the original DOS PSP upon */
1283 /* Windows startup ? */
1284 BX_reg(context) = GetCurrentPDB();
1285 break;
1287 case 0x52: /* "SYSVARS" - GET LIST OF LISTS */
1288 ES_reg(context) = 0x0;
1289 BX_reg(context) = 0x0;
1290 INT_BARF( context, 0x21 );
1291 break;
1293 case 0x56: /* "RENAME" - RENAME FILE */
1294 bSetDOSExtendedError =
1295 (!MoveFile32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1296 PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context))));
1297 break;
1299 case 0x57: /* FILE DATE AND TIME */
1300 switch (AL_reg(context))
1302 case 0x00: /* Get */
1304 FILETIME filetime;
1305 if (!GetFileTime( BX_reg(context), NULL, NULL, &filetime ))
1306 bSetDOSExtendedError = TRUE;
1307 else FileTimeToDosDateTime( &filetime, &DX_reg(context),
1308 &CX_reg(context) );
1310 break;
1312 case 0x01: /* Set */
1314 FILETIME filetime;
1315 DosDateTimeToFileTime( DX_reg(context), CX_reg(context),
1316 &filetime );
1317 bSetDOSExtendedError =
1318 (!SetFileTime( BX_reg(context), NULL, NULL, &filetime ));
1320 break;
1322 break;
1324 case 0x58: /* GET OR SET MEMORY/UMB ALLOCATION STRATEGY */
1325 switch (AL_reg(context))
1327 case 0x00:
1328 AX_reg(context) = 1;
1329 break;
1330 case 0x02:
1331 AX_reg(context) = 0;
1332 break;
1333 case 0x01:
1334 case 0x03:
1335 break;
1337 RESET_CFLAG(context);
1338 break;
1340 case 0x5a: /* CREATE TEMPORARY FILE */
1341 bSetDOSExtendedError = !INT21_CreateTempFile(context);
1342 break;
1344 case 0x5b: /* CREATE NEW FILE */
1345 bSetDOSExtendedError = ((AX_reg(context) =
1346 _lcreat_uniq( PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)), 0 ))
1347 == (WORD)HFILE_ERROR16);
1348 break;
1350 case 0x5d: /* NETWORK */
1351 case 0x5e:
1352 /* network software not installed */
1353 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1354 bSetDOSExtendedError = TRUE;
1355 break;
1357 case 0x5f: /* NETWORK */
1358 switch (AL_reg(context))
1360 case 0x07: /* ENABLE DRIVE */
1361 if (!DRIVE_Enable( DL_reg(context) ))
1363 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1364 bSetDOSExtendedError = TRUE;
1366 break;
1368 case 0x08: /* DISABLE DRIVE */
1369 if (!DRIVE_Disable( DL_reg(context) ))
1371 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
1372 bSetDOSExtendedError = TRUE;
1374 break;
1376 default:
1377 /* network software not installed */
1378 DOS_ERROR( ER_NoNetwork, EC_NotFound, SA_Abort, EL_Network );
1379 bSetDOSExtendedError = TRUE;
1380 break;
1382 break;
1384 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
1386 if (!GetFullPathName32A( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1387 SI_reg(context)), 128,
1388 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1389 DI_reg(context)),NULL))
1390 bSetDOSExtendedError = TRUE;
1391 else AX_reg(context) = 0;
1393 break;
1395 case 0x61: /* UNUSED */
1396 case 0x63: /* UNUSED */
1397 case 0x64: /* OS/2 DOS BOX */
1398 INT_BARF( context, 0x21 );
1399 SET_CFLAG(context);
1400 break;
1402 case 0x65:{/* GET EXTENDED COUNTRY INFORMATION */
1403 extern WORD WINE_LanguageId;
1404 BYTE *dataptr=PTR_SEG_OFF_TO_LIN(ES_reg(context),DI_reg(context));;
1405 switch (AL_reg(context)) {
1406 case 0x01:
1407 dataptr[0] = 0x1;
1408 *(WORD*)(dataptr+1) = 41;
1409 *(WORD*)(dataptr+3) = WINE_LanguageId;
1410 *(WORD*)(dataptr+5) = CodePage;
1411 break;
1412 case 0x06:
1413 dataptr[0] = 0x06;
1414 *(DWORD*)(dataptr+1) = MAKELONG(DOSMEM_CollateTable & 0xFFFF,DOSMEM_AllocSelector(DOSMEM_CollateTable>>16));
1415 CX_reg(context) = 258;/*FIXME: size of table?*/
1416 break;
1417 default:
1418 INT_BARF( context, 0x21 );
1419 SET_CFLAG(context);
1420 break;
1422 break;
1424 case 0x66: /* GLOBAL CODE PAGE TABLE */
1425 switch (AL_reg(context))
1427 case 0x01:
1428 DX_reg(context) = BX_reg(context) = CodePage;
1429 RESET_CFLAG(context);
1430 break;
1431 case 0x02:
1432 CodePage = BX_reg(context);
1433 RESET_CFLAG(context);
1434 break;
1436 break;
1438 case 0x67: /* SET HANDLE COUNT */
1439 SetHandleCount16( BX_reg(context) );
1440 if (DOS_ExtendedError) bSetDOSExtendedError = TRUE;
1441 break;
1443 case 0x68: /* "FFLUSH" - COMMIT FILE */
1444 case 0x6a: /* COMMIT FILE */
1445 bSetDOSExtendedError = (!FlushFileBuffers( BX_reg(context) ));
1446 break;
1448 case 0x69: /* DISK SERIAL NUMBER */
1449 switch (AL_reg(context))
1451 case 0x00:
1452 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1453 else AX_reg(context) = 0;
1454 break;
1456 case 0x01:
1457 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
1458 else AX_reg(context) = 1;
1459 break;
1461 break;
1463 case 0x6C: /* Extended Open/Create*/
1464 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1465 break;
1467 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
1468 switch(AL_reg(context))
1470 case 0x39: /* Create directory */
1471 bSetDOSExtendedError = (!CreateDirectory32A(
1472 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1473 DX_reg(context) ), NULL));
1474 break;
1475 case 0x3a: /* Remove directory */
1476 bSetDOSExtendedError = (!RemoveDirectory32A(
1477 PTR_SEG_OFF_TO_LIN( DS_reg(context),
1478 DX_reg(context) )));
1479 break;
1480 case 0x43: /* Get/Set file attributes */
1481 switch (BL_reg(context))
1483 case 0x00: /* Get file attributes */
1484 CX_reg(context) = (WORD)GetFileAttributes32A(
1485 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1486 DX_reg(context)));
1487 if (CX_reg(context) == 0xffff) bSetDOSExtendedError = TRUE;
1488 break;
1489 case 0x01:
1490 bSetDOSExtendedError = (!SetFileAttributes32A(
1491 PTR_SEG_OFF_TO_LIN(DS_reg(context),
1492 DX_reg(context)),
1493 CX_reg(context) ) );
1494 break;
1495 default:
1496 fprintf( stderr,
1497 "Unimplemented int21 long file name function:\n");
1498 INT_BARF( context, 0x21 );
1499 SET_CFLAG(context);
1500 AL_reg(context) = 0;
1501 break;
1503 break;
1504 case 0x47: /* Get current directory */
1505 bSetDOSExtendedError = !INT21_GetCurrentDirectory(context);
1506 break;
1508 case 0x4e: /* Find first file */
1509 /* FIXME: use attributes in CX */
1510 if ((AX_reg(context) = FindFirstFile16(
1511 PTR_SEG_OFF_TO_LIN(DS_reg(context),DX_reg(context)),
1512 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1513 DI_reg(context))))
1514 == INVALID_HANDLE_VALUE16)
1515 bSetDOSExtendedError = TRUE;
1516 break;
1517 case 0x4f: /* Find next file */
1518 if (!FindNextFile16( BX_reg(context),
1519 (WIN32_FIND_DATA32A *)PTR_SEG_OFF_TO_LIN(ES_reg(context),
1520 DI_reg(context))))
1521 bSetDOSExtendedError = TRUE;
1522 break;
1523 case 0xa1: /* Find close */
1524 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
1525 break;
1526 case 0xa0:
1527 break;
1528 case 0x60:
1529 switch(CL_reg(context))
1531 case 0x02: /*Get canonical long filename or path */
1532 if (!GetFullPathName32A
1533 ( PTR_SEG_OFF_TO_LIN(DS_reg(context),
1534 SI_reg(context)), 128,
1535 PTR_SEG_OFF_TO_LIN(ES_reg(context),
1536 DI_reg(context)),NULL))
1537 bSetDOSExtendedError = TRUE;
1538 else AX_reg(context) = 0;
1539 break;
1540 default:
1541 fprintf( stderr,
1542 "Unimplemented int21 long file name function:\n");
1543 INT_BARF( context, 0x21 );
1544 SET_CFLAG(context);
1545 AL_reg(context) = 0;
1546 break;
1548 break;
1549 case 0x6c: /* Create or open file */
1550 /* translate Dos 7 action to Dos 6 action */
1551 bSetDOSExtendedError = INT21_ExtendedOpenCreateFile(context);
1552 break;
1554 case 0x3b: /* Change directory */
1555 if (!SetCurrentDirectory32A(PTR_SEG_OFF_TO_LIN(
1556 DS_reg(context),
1557 DX_reg(context)
1560 SET_CFLAG(context);
1561 AL_reg(context) = DOS_ExtendedError;
1563 break;
1564 case 0x41: /* Delete file */
1565 if (!DeleteFile32A(PTR_SEG_OFF_TO_LIN(
1566 DS_reg(context),
1567 DX_reg(context))
1568 )) {
1569 SET_CFLAG(context);
1570 AL_reg(context) = DOS_ExtendedError;
1572 break;
1573 case 0x56: /* Move (rename) file */
1574 default:
1575 fprintf( stderr, "Unimplemented int21 long file name function:\n");
1576 INT_BARF( context, 0x21 );
1577 SET_CFLAG(context);
1578 AL_reg(context) = 0;
1579 break;
1581 break;
1583 case 0x70: /* MS-DOS 7 (Windows95) - ??? (country-specific?)*/
1584 case 0x72: /* MS-DOS 7 (Windows95) - ??? */
1585 case 0x73: /* MS-DOS 7 (Windows95) - DRIVE LOCKING ??? */
1586 dprintf_info(int,"int21: windows95 function AX %04x\n",
1587 AX_reg(context));
1588 dprintf_warn(int, " returning unimplemented\n");
1589 SET_CFLAG(context);
1590 AL_reg(context) = 0;
1591 break;
1593 case 0xdc: /* CONNECTION SERVICES - GET CONNECTION NUMBER */
1594 case 0xea: /* NOVELL NETWARE - RETURN SHELL VERSION */
1595 break;
1597 default:
1598 INT_BARF( context, 0x21 );
1599 break;
1601 } /* END OF SWITCH */
1603 if( bSetDOSExtendedError ) /* set general error condition */
1605 AX_reg(context) = DOS_ExtendedError;
1606 SET_CFLAG(context);
1609 dprintf_info(int, "ret21: AX=%04x BX=%04x CX=%04x DX=%04x "
1610 "SI=%04x DI=%04x DS=%04x ES=%04x EFL=%08lx\n",
1611 AX_reg(context), BX_reg(context), CX_reg(context),
1612 DX_reg(context), SI_reg(context), DI_reg(context),
1613 (WORD)DS_reg(context), (WORD)ES_reg(context),
1614 EFL_reg(context));
1617 FARPROC16 WINAPI GetSetKernelDOSProc(FARPROC16 DosProc)
1619 fprintf(stderr, "GetSetKernelDOSProc(DosProc: %08x);\n", (UINT32)DosProc);
1620 return NULL;