- stupid typos fixes on software vertex shader operands
[wine/testsucceed.git] / msdos / int21.c
blob4115a5f95b00b41d7c901a1e1fb63d1bc1c8a1fa
1 /*
2 * DOS interrupt 21h handler
4 * Copyright 1993, 1994 Erik Bos
5 * Copyright 1996 Alexandre Julliard
6 * Copyright 1997 Andreas Mohr
7 * Copyright 1998 Uwe Bonnes
8 * Copyright 1998, 1999 Ove Kaaven
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <time.h>
29 #include <fcntl.h>
30 #include <stdlib.h>
31 #include <stdarg.h>
32 #include <stdio.h>
33 #ifdef HAVE_SYS_FILE_H
34 # include <sys/file.h>
35 #endif
36 #include <string.h>
37 #ifdef HAVE_SYS_TIME_H
38 # include <sys/time.h>
39 #endif
40 #include <sys/types.h>
41 #ifdef HAVE_UNISTD_H
42 # include <unistd.h>
43 #endif
44 #ifdef HAVE_UTIME_H
45 # include <utime.h>
46 #endif
47 #include <ctype.h>
48 #include "windef.h"
49 #include "winbase.h"
50 #include "winreg.h"
51 #include "winternl.h"
52 #include "wingdi.h"
53 #include "winuser.h" /* SW_NORMAL */
54 #include "wine/winbase16.h"
55 #include "winerror.h"
56 #include "drive.h"
57 #include "file.h"
58 #include "callback.h"
59 #include "msdos.h"
60 #include "miscemu.h"
61 #include "task.h"
62 #include "wine/unicode.h"
63 #include "wine/debug.h"
65 WINE_DEFAULT_DEBUG_CHANNEL(int21);
66 #if defined(__svr4__) || defined(_SCO_DS)
67 /* SVR4 DOESNT do locking the same way must implement properly */
68 #define LOCK_EX 0
69 #define LOCK_SH 1
70 #define LOCK_NB 8
71 #endif
74 #define DOS_GET_DRIVE(reg) ((reg) ? (reg) - 1 : DRIVE_GetCurrentDrive())
76 struct DosHeap {
77 BYTE mediaID;
78 BYTE biosdate[8];
80 static struct DosHeap *heap;
81 static WORD DosHeapHandle;
83 extern char TempDirectory[];
85 static BOOL INT21_CreateHeap(void)
87 if (!(DosHeapHandle = GlobalAlloc16(GMEM_FIXED,sizeof(struct DosHeap))))
89 WARN("Out of memory\n");
90 return FALSE;
92 heap = (struct DosHeap *) GlobalLock16(DosHeapHandle);
93 strcpy(heap->biosdate, "01/01/80");
94 return TRUE;
97 static BYTE *GetCurrentDTA( CONTEXT86 *context )
99 TDB *pTask = GlobalLock16(GetCurrentTask());
101 /* FIXME: This assumes DTA was set correctly! */
102 return (BYTE *)CTX_SEG_OFF_TO_LIN( context, SELECTOROF(pTask->dta),
103 (DWORD)OFFSETOF(pTask->dta) );
107 static void CreateBPB(int drive, BYTE *data, BOOL16 limited)
108 /* limited == TRUE is used with INT 0x21/0x440d */
110 if (drive > 1) {
111 setword(data, 512);
112 data[2] = 2;
113 setword(&data[3], 0);
114 data[5] = 2;
115 setword(&data[6], 240);
116 setword(&data[8], 64000);
117 data[0x0a] = 0xf8;
118 setword(&data[0x0b], 40);
119 setword(&data[0x0d], 56);
120 setword(&data[0x0f], 2);
121 setword(&data[0x11], 0);
122 if (!limited) {
123 setword(&data[0x1f], 800);
124 data[0x21] = 5;
125 setword(&data[0x22], 1);
127 } else { /* 1.44mb */
128 setword(data, 512);
129 data[2] = 2;
130 setword(&data[3], 0);
131 data[5] = 2;
132 setword(&data[6], 240);
133 setword(&data[8], 2880);
134 data[0x0a] = 0xf8;
135 setword(&data[0x0b], 6);
136 setword(&data[0x0d], 18);
137 setword(&data[0x0f], 2);
138 setword(&data[0x11], 0);
139 if (!limited) {
140 setword(&data[0x1f], 80);
141 data[0x21] = 7;
142 setword(&data[0x22], 2);
147 static int INT21_GetFreeDiskSpace( CONTEXT86 *context )
149 DWORD cluster_sectors, sector_bytes, free_clusters, total_clusters;
150 char root[] = "A:\\";
152 *root += DOS_GET_DRIVE( DL_reg(context) );
153 if (!GetDiskFreeSpaceA( root, &cluster_sectors, &sector_bytes,
154 &free_clusters, &total_clusters )) return 0;
155 SET_AX( context, cluster_sectors );
156 SET_BX( context, free_clusters );
157 SET_CX( context, sector_bytes );
158 SET_DX( context, total_clusters );
159 return 1;
162 static int INT21_GetDriveAllocInfo( CONTEXT86 *context )
164 if (!INT21_GetFreeDiskSpace( context )) return 0;
165 if (!heap && !INT21_CreateHeap()) return 0;
166 heap->mediaID = 0xf0;
167 context->SegDs = DosHeapHandle;
168 SET_BX( context, (int)&heap->mediaID - (int)heap );
169 return 1;
172 static BOOL ioctlGenericBlkDevReq( CONTEXT86 *context )
174 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
175 int drive = DOS_GET_DRIVE( BL_reg(context) );
177 if (!DRIVE_IsValid(drive))
179 SetLastError( ERROR_FILE_NOT_FOUND );
180 return TRUE;
183 if (CH_reg(context) != 0x08)
185 INT_BARF( context, 0x21 );
186 return FALSE;
189 switch (CL_reg(context))
191 case 0x60: /* get device parameters */
192 /* used by w4wgrp's winfile */
193 memset(dataptr, 0, 0x20); /* DOS 6.22 uses 0x20 bytes */
194 dataptr[0] = 0x04;
195 dataptr[6] = 0; /* media type */
196 if (drive > 1)
198 dataptr[1] = 0x05; /* fixed disk */
199 setword(&dataptr[2], 0x01); /* non removable */
200 setword(&dataptr[4], 0x300); /* # of cylinders */
202 else
204 dataptr[1] = 0x07; /* block dev, floppy */
205 setword(&dataptr[2], 0x02); /* removable */
206 setword(&dataptr[4], 80); /* # of cylinders */
208 CreateBPB(drive, &dataptr[7], TRUE);
209 RESET_CFLAG(context);
210 break;
212 case 0x66:/* get disk serial number */
214 char label[12],fsname[9],path[4];
215 DWORD serial;
217 strcpy(path,"x:\\");path[0]=drive+'A';
218 GetVolumeInformationA(
219 path,label,12,&serial,NULL,NULL,fsname,9
221 *(WORD*)dataptr = 0;
222 memcpy(dataptr+2,&serial,4);
223 memcpy(dataptr+6,label ,11);
224 memcpy(dataptr+17,fsname,8);
226 break;
228 case 0x6f:
229 memset(dataptr+1, '\0', dataptr[0]-1);
230 dataptr[1] = dataptr[0];
231 dataptr[2] = 0x07; /* protected mode driver; no eject; no notification */
232 dataptr[3] = 0xFF; /* no physical drive */
233 break;
235 case 0x72:
236 /* Trail on error implementation */
237 SET_AX( context, GetDriveType16(BL_reg(context)) == DRIVE_UNKNOWN ? 0x0f : 0x01 );
238 SET_CFLAG(context); /* Seems to be set all the time */
239 break;
241 default:
242 INT_BARF( context, 0x21 );
244 return FALSE;
247 static void INT21_ParseFileNameIntoFCB( CONTEXT86 *context )
249 char *filename =
250 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Esi );
251 char *fcb =
252 CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Edi );
253 char *s;
254 WCHAR *buffer;
255 WCHAR fcbW[12];
256 INT buffer_len, len;
258 SET_AL( context, 0xff ); /* failed */
260 TRACE("filename: '%s'\n", filename);
262 s = filename;
263 len = 0;
264 while (*s)
266 if ((*s != ' ') && (*s != '\r') && (*s != '\n'))
268 s++;
269 len++;
271 else
272 break;
275 buffer_len = MultiByteToWideChar(CP_OEMCP, 0, filename, len, NULL, 0);
276 buffer = HeapAlloc( GetProcessHeap(), 0, (buffer_len + 1) * sizeof(WCHAR));
277 len = MultiByteToWideChar(CP_OEMCP, 0, filename, len, buffer, buffer_len);
278 buffer[len] = 0;
279 DOSFS_ToDosFCBFormat(buffer, fcbW);
280 HeapFree(GetProcessHeap(), 0, buffer);
281 WideCharToMultiByte(CP_OEMCP, 0, fcbW, 12, fcb + 1, 12, NULL, NULL);
282 *fcb = 0;
283 TRACE("FCB: '%s'\n", fcb + 1);
285 SET_AL( context, ((strchr(filename, '*')) || (strchr(filename, '$'))) != 0 );
287 /* point DS:SI to first unparsed character */
288 SET_SI( context, context->Esi + (int)s - (int)filename );
292 /* Many calls translate a drive argument like this:
293 drive number (00h = default, 01h = A:, etc)
295 static const char *INT21_DriveName(int drive)
297 if (drive > 0) return wine_dbg_sprintf( "%c:", 'A' + drive - 1 );
298 return "default";
301 static HFILE16 _lcreat16_uniq( LPCSTR path, INT attr )
303 /* Mask off all flags not explicitly allowed by the doc */
304 attr &= FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM;
305 return Win32HandleToDosFileHandle( CreateFileA( path, GENERIC_READ | GENERIC_WRITE,
306 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
307 CREATE_NEW, attr, 0 ));
311 static int INT21_FindFirst( CONTEXT86 *context )
313 char *p;
314 const char *path;
315 DOS_FULL_NAME full_name;
316 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
317 WCHAR pathW[MAX_PATH];
318 WCHAR maskW[12];
320 path = (const char *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
321 MultiByteToWideChar(CP_OEMCP, 0, path, -1, pathW, MAX_PATH);
323 dta->unixPath = NULL;
324 if (!DOSFS_GetFullName( pathW, FALSE, &full_name ))
326 SET_AX( context, GetLastError() );
327 SET_CFLAG(context);
328 return 0;
330 dta->unixPath = HeapAlloc( GetProcessHeap(), 0, strlen(full_name.long_name)+1 );
331 strcpy( dta->unixPath, full_name.long_name );
332 p = strrchr( dta->unixPath, '/' );
333 *p = '\0';
335 MultiByteToWideChar(CP_OEMCP, 0, p + 1, -1, pathW, MAX_PATH);
337 /* Note: terminating NULL in dta->mask overwrites dta->search_attr
338 * (doesn't matter as it is set below anyway)
340 if (!DOSFS_ToDosFCBFormat( pathW, maskW ))
342 HeapFree( GetProcessHeap(), 0, dta->unixPath );
343 dta->unixPath = NULL;
344 SetLastError( ERROR_FILE_NOT_FOUND );
345 SET_AX( context, ERROR_FILE_NOT_FOUND );
346 SET_CFLAG(context);
347 return 0;
349 WideCharToMultiByte(CP_OEMCP, 0, maskW, 12, dta->mask, sizeof(dta->mask), NULL, NULL);
350 dta->drive = (path[0] && (path[1] == ':')) ? toupper(path[0]) - 'A'
351 : DRIVE_GetCurrentDrive();
352 dta->count = 0;
353 dta->search_attr = CL_reg(context);
354 return 1;
358 static int INT21_FindNext( CONTEXT86 *context )
360 FINDFILE_DTA *dta = (FINDFILE_DTA *)GetCurrentDTA(context);
361 WIN32_FIND_DATAA entry;
362 int count;
364 if (!dta->unixPath) return 0;
365 if (!(count = DOSFS_FindNext( dta->unixPath, dta->mask, NULL, dta->drive,
366 dta->search_attr, dta->count, &entry )))
368 HeapFree( GetProcessHeap(), 0, dta->unixPath );
369 dta->unixPath = NULL;
370 return 0;
372 if ((int)dta->count + count > 0xffff)
374 WARN("Too many directory entries in %s\n", dta->unixPath );
375 HeapFree( GetProcessHeap(), 0, dta->unixPath );
376 dta->unixPath = NULL;
377 return 0;
379 dta->count += count;
380 dta->fileattr = entry.dwFileAttributes;
381 dta->filesize = entry.nFileSizeLow;
382 FileTimeToDosDateTime( &entry.ftLastWriteTime,
383 &dta->filedate, &dta->filetime );
384 strcpy( dta->filename, entry.cAlternateFileName );
385 if (!memchr(dta->mask,'?',11)) {
386 /* wildcardless search, release resources in case no findnext will
387 * be issued, and as a workaround in case file creation messes up
388 * findnext, as sometimes happens with pkunzip */
389 HeapFree( GetProcessHeap(), 0, dta->unixPath );
390 dta->unixPath = NULL;
392 return 1;
396 static BOOL INT21_CreateTempFile( CONTEXT86 *context )
398 static int counter = 0;
399 char *name = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx );
400 char *p = name + strlen(name);
402 /* despite what Ralf Brown says, some programs seem to call without
403 * ending backslash (DOS accepts that, so we accept it too) */
404 if ((p == name) || (p[-1] != '\\')) *p++ = '\\';
406 for (;;)
408 sprintf( p, "wine%04x.%03d", (int)getpid(), counter );
409 counter = (counter + 1) % 1000;
411 SET_AX( context, _lcreat16_uniq( name, 0 ) );
412 if (AX_reg(context) != HFILE_ERROR16)
414 TRACE("created %s\n", name );
415 return TRUE;
417 if (GetLastError() != ERROR_FILE_EXISTS) return FALSE;
422 static int INT21_GetDiskSerialNumber( CONTEXT86 *context )
424 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
425 int drive = DOS_GET_DRIVE( BL_reg(context) );
427 if (!DRIVE_IsValid(drive))
429 SetLastError( ERROR_INVALID_DRIVE );
430 return 0;
433 *(WORD *)dataptr = 0;
434 *(DWORD *)(dataptr + 2) = DRIVE_GetSerialNumber( drive );
435 memcpy( dataptr + 6, DRIVE_GetLabel( drive ), 11 );
436 strncpy(dataptr + 0x11, "FAT16 ", 8);
437 return 1;
441 static int INT21_SetDiskSerialNumber( CONTEXT86 *context )
443 BYTE *dataptr = CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
444 int drive = DOS_GET_DRIVE( BL_reg(context) );
446 if (!DRIVE_IsValid(drive))
448 SetLastError( ERROR_INVALID_DRIVE );
449 return 0;
452 DRIVE_SetSerialNumber( drive, *(DWORD *)(dataptr + 2) );
453 return 1;
457 /* microsoft's programmers should be shot for using CP/M style int21
458 calls in Windows for Workgroup's winfile.exe */
460 static int INT21_FindFirstFCB( CONTEXT86 *context )
462 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
463 FINDFILE_FCB *pFCB;
464 LPCSTR root, cwd;
465 int drive;
467 if (*fcb == 0xff) pFCB = (FINDFILE_FCB *)(fcb + 7);
468 else pFCB = (FINDFILE_FCB *)fcb;
469 drive = DOS_GET_DRIVE( pFCB->drive );
470 if (!DRIVE_IsValid( drive )) return 0;
471 root = DRIVE_GetRoot( drive );
472 cwd = DRIVE_GetUnixCwd( drive );
473 pFCB->unixPath = HeapAlloc( GetProcessHeap(), 0,
474 strlen(root)+strlen(cwd)+2 );
475 if (!pFCB->unixPath) return 0;
476 strcpy( pFCB->unixPath, root );
477 strcat( pFCB->unixPath, "/" );
478 strcat( pFCB->unixPath, cwd );
479 pFCB->count = 0;
480 return 1;
484 static int INT21_FindNextFCB( CONTEXT86 *context )
486 BYTE *fcb = (BYTE *)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx);
487 FINDFILE_FCB *pFCB;
488 DOS_DIRENTRY_LAYOUT *pResult = (DOS_DIRENTRY_LAYOUT *)GetCurrentDTA(context);
489 WIN32_FIND_DATAA entry;
490 BYTE attr;
491 int count;
493 if (*fcb == 0xff) /* extended FCB ? */
495 attr = fcb[6];
496 pFCB = (FINDFILE_FCB *)(fcb + 7);
498 else
500 attr = 0;
501 pFCB = (FINDFILE_FCB *)fcb;
504 if (!pFCB->unixPath) return 0;
505 if (!(count = DOSFS_FindNext( pFCB->unixPath, pFCB->filename, NULL,
506 DOS_GET_DRIVE( pFCB->drive ), attr,
507 pFCB->count, &entry )))
509 HeapFree( GetProcessHeap(), 0, pFCB->unixPath );
510 pFCB->unixPath = NULL;
511 return 0;
513 pFCB->count += count;
515 if (*fcb == 0xff) { /* place extended FCB header before pResult if called with extended FCB */
516 *(BYTE *)pResult = 0xff;
517 (BYTE *)pResult +=6; /* leave reserved field behind */
518 *(BYTE *)pResult = entry.dwFileAttributes;
519 ((BYTE *)pResult)++;
521 *(BYTE *)pResult = DOS_GET_DRIVE( pFCB->drive ); /* DOS_DIRENTRY_LAYOUT after current drive number */
522 ((BYTE *)pResult)++;
523 pResult->fileattr = entry.dwFileAttributes;
524 pResult->cluster = 0; /* what else? */
525 pResult->filesize = entry.nFileSizeLow;
526 memset( pResult->reserved, 0, sizeof(pResult->reserved) );
527 FileTimeToDosDateTime( &entry.ftLastWriteTime,
528 &pResult->filedate, &pResult->filetime );
530 /* Convert file name to FCB format */
532 memset( pResult->filename, ' ', sizeof(pResult->filename) );
533 if (!strcmp( entry.cAlternateFileName, "." )) pResult->filename[0] = '.';
534 else if (!strcmp( entry.cAlternateFileName, ".." ))
535 pResult->filename[0] = pResult->filename[1] = '.';
536 else
538 char *p = strrchr( entry.cAlternateFileName, '.' );
539 if (p && p[1] && (p != entry.cAlternateFileName))
541 memcpy( pResult->filename, entry.cAlternateFileName,
542 min( (p - entry.cAlternateFileName), 8 ) );
543 memcpy( pResult->filename + 8, p + 1, min( strlen(p), 3 ) );
545 else
546 memcpy( pResult->filename, entry.cAlternateFileName,
547 min( strlen(entry.cAlternateFileName), 8 ) );
549 return 1;
553 static BOOL
554 INT21_networkfunc (CONTEXT86 *context)
556 switch (AL_reg(context)) {
557 case 0x00: /* Get machine name. */
559 char *dst = CTX_SEG_OFF_TO_LIN (context,context->SegDs,context->Edx);
560 TRACE("getting machine name to %p\n", dst);
561 if (gethostname (dst, 15))
563 WARN("failed!\n");
564 SetLastError( ER_NoNetwork );
565 return TRUE;
566 } else {
567 int len = strlen (dst);
568 while (len < 15)
569 dst[len++] = ' ';
570 dst[15] = 0;
571 SET_CH( context, 1 ); /* Valid */
572 SET_CL( context, 1 ); /* NETbios number??? */
573 TRACE("returning %s\n", debugstr_an (dst, 16));
574 return FALSE;
578 default:
579 SetLastError( ER_NoNetwork );
580 return TRUE;
585 /***********************************************************************
586 * INT_Int21Handler
588 void WINAPI INT_Int21Handler( CONTEXT86 *context )
590 BOOL bSetDOSExtendedError = FALSE;
592 switch(AH_reg(context))
594 case 0x11: /* FIND FIRST MATCHING FILE USING FCB */
595 TRACE("FIND FIRST MATCHING FILE USING FCB %p\n",
596 CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
597 if (!INT21_FindFirstFCB(context))
599 SET_AL( context, 0xff );
600 break;
602 /* else fall through */
604 case 0x12: /* FIND NEXT MATCHING FILE USING FCB */
605 SET_AL( context, INT21_FindNextFCB(context) ? 0x00 : 0xff );
606 break;
608 case 0x1b: /* GET ALLOCATION INFORMATION FOR DEFAULT DRIVE */
609 SET_DL( context, 0 );
610 if (!INT21_GetDriveAllocInfo(context)) SET_AX( context, 0xffff );
611 break;
613 case 0x1c: /* GET ALLOCATION INFORMATION FOR SPECIFIC DRIVE */
614 if (!INT21_GetDriveAllocInfo(context)) SET_AX( context, 0xffff );
615 break;
617 case 0x29: /* PARSE FILENAME INTO FCB */
618 INT21_ParseFileNameIntoFCB(context);
619 break;
621 case 0x36: /* GET FREE DISK SPACE */
622 TRACE("GET FREE DISK SPACE FOR DRIVE %s\n",
623 INT21_DriveName( DL_reg(context)));
624 if (!INT21_GetFreeDiskSpace(context)) SET_AX( context, 0xffff );
625 break;
627 case 0x44: /* IOCTL */
628 switch (AL_reg(context))
630 case 0x0d:
631 TRACE("IOCTL - GENERIC BLOCK DEVICE REQUEST %s\n",
632 INT21_DriveName( BL_reg(context)));
633 bSetDOSExtendedError = ioctlGenericBlkDevReq(context);
634 break;
636 case 0x0F: /* Set logical drive mapping */
638 int drive;
639 TRACE("IOCTL - SET LOGICAL DRIVE MAP for drive %s\n",
640 INT21_DriveName( BL_reg(context)));
641 drive = DOS_GET_DRIVE ( BL_reg(context) );
642 if ( ! DRIVE_SetLogicalMapping ( drive, drive+1 ) )
644 SET_CFLAG(context);
645 SET_AX( context, 0x000F ); /* invalid drive */
647 break;
650 break;
652 case 0x4e: /* "FINDFIRST" - FIND FIRST MATCHING FILE */
653 TRACE("FINDFIRST mask 0x%04x spec %s\n",CX_reg(context),
654 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs, context->Edx));
655 if (!INT21_FindFirst(context)) break;
656 /* fall through */
658 case 0x4f: /* "FINDNEXT" - FIND NEXT MATCHING FILE */
659 TRACE("FINDNEXT\n");
660 if (!INT21_FindNext(context))
662 SetLastError( ERROR_NO_MORE_FILES );
663 SET_AX( context, ERROR_NO_MORE_FILES );
664 SET_CFLAG(context);
666 else SET_AX( context, 0 ); /* OK */
667 break;
669 case 0x5a: /* CREATE TEMPORARY FILE */
670 TRACE("CREATE TEMPORARY FILE\n");
671 bSetDOSExtendedError = !INT21_CreateTempFile(context);
672 break;
674 case 0x5e:
675 bSetDOSExtendedError = INT21_networkfunc (context);
676 break;
678 case 0x5f: /* NETWORK */
679 switch (AL_reg(context))
681 case 0x07: /* ENABLE DRIVE */
682 TRACE("ENABLE DRIVE %c:\n",(DL_reg(context)+'A'));
683 if (!DRIVE_Enable( DL_reg(context) ))
685 SetLastError( ERROR_INVALID_DRIVE );
686 bSetDOSExtendedError = TRUE;
688 break;
690 case 0x08: /* DISABLE DRIVE */
691 TRACE("DISABLE DRIVE %c:\n",(DL_reg(context)+'A'));
692 if (!DRIVE_Disable( DL_reg(context) ))
694 SetLastError( ERROR_INVALID_DRIVE );
695 bSetDOSExtendedError = TRUE;
697 break;
699 default:
700 /* network software not installed */
701 TRACE("NETWORK function AX=%04x not implemented\n",AX_reg(context));
702 SetLastError( ER_NoNetwork );
703 bSetDOSExtendedError = TRUE;
704 break;
706 break;
708 case 0x60: /* "TRUENAME" - CANONICALIZE FILENAME OR PATH */
709 TRACE("TRUENAME %s\n",
710 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Esi));
712 if (!GetFullPathNameA( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
713 context->Esi), 128,
714 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
715 context->Edi),NULL))
716 bSetDOSExtendedError = TRUE;
717 else SET_AX( context, 0 );
719 break;
721 case 0x69: /* DISK SERIAL NUMBER */
722 switch (AL_reg(context))
724 case 0x00:
725 TRACE("GET DISK SERIAL NUMBER for drive %s\n",
726 INT21_DriveName(BL_reg(context)));
727 if (!INT21_GetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
728 else SET_AX( context, 0 );
729 break;
731 case 0x01:
732 TRACE("SET DISK SERIAL NUMBER for drive %s\n",
733 INT21_DriveName(BL_reg(context)));
734 if (!INT21_SetDiskSerialNumber(context)) bSetDOSExtendedError = TRUE;
735 else SET_AX( context, 1 );
736 break;
738 break;
740 case 0x71: /* MS-DOS 7 (Windows95) - LONG FILENAME FUNCTIONS */
741 switch(AL_reg(context))
743 case 0x4e: /* Find first file */
744 TRACE(" LONG FILENAME - FIND FIRST MATCHING FILE for %s\n",
745 (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx));
746 /* FIXME: use attributes in CX */
747 SET_AX( context, FindFirstFile16(
748 CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx),
749 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
750 context->Edi)));
751 if (AX_reg(context) == INVALID_HANDLE_VALUE16)
752 bSetDOSExtendedError = TRUE;
753 break;
754 case 0x4f: /* Find next file */
755 TRACE("LONG FILENAME - FIND NEXT MATCHING FILE for handle %d\n",
756 BX_reg(context));
757 if (!FindNextFile16( BX_reg(context),
758 (WIN32_FIND_DATAA *)CTX_SEG_OFF_TO_LIN(context, context->SegEs,
759 context->Edi)))
760 bSetDOSExtendedError = TRUE;
761 break;
762 case 0xa0:
764 LPCSTR driveroot = (LPCSTR)CTX_SEG_OFF_TO_LIN(context, context->SegDs,context->Edx);
765 LPSTR buffer = (LPSTR)CTX_SEG_OFF_TO_LIN(context, context->SegEs,context->Edi);
766 DWORD filename_len, flags;
768 TRACE("LONG FILENAME - GET VOLUME INFORMATION for drive having root dir '%s'.\n", driveroot);
769 SET_AX( context, 0 );
770 if (!GetVolumeInformationA( driveroot, NULL, 0, NULL, &filename_len,
771 &flags, buffer, 8 ))
773 INT_BARF( context, 0x21 );
774 SET_CFLAG(context);
775 break;
777 SET_BX( context, flags | 0x4000 ); /* support for LFN functions */
778 SET_CX( context, filename_len );
779 SET_DX( context, MAX_PATH ); /* FIXME: which len if DRIVE_SHORT_NAMES ? */
781 break;
782 case 0xa1: /* Find close */
783 TRACE("LONG FILENAME - FINDCLOSE for handle %d\n",
784 BX_reg(context));
785 bSetDOSExtendedError = (!FindClose16( BX_reg(context) ));
786 break;
787 case 0x60:
788 switch(CL_reg(context))
790 case 0x01: /* Get short filename or path */
791 if (!GetShortPathNameA
792 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
793 context->Esi),
794 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
795 context->Edi), 67))
796 bSetDOSExtendedError = TRUE;
797 else SET_AX( context, 0 );
798 break;
799 case 0x02: /* Get canonical long filename or path */
800 if (!GetFullPathNameA
801 ( CTX_SEG_OFF_TO_LIN(context, context->SegDs,
802 context->Esi), 128,
803 CTX_SEG_OFF_TO_LIN(context, context->SegEs,
804 context->Edi),NULL))
805 bSetDOSExtendedError = TRUE;
806 else SET_AX( context, 0 );
807 break;
808 default:
809 FIXME("Unimplemented long file name function:\n");
810 INT_BARF( context, 0x21 );
811 SET_CFLAG(context);
812 SET_AL( context, 0 );
813 break;
815 break;
817 default:
818 FIXME("Unimplemented long file name function:\n");
819 INT_BARF( context, 0x21 );
820 SET_CFLAG(context);
821 SET_AL( context, 0 );
822 break;
824 break;
826 default:
827 INT_BARF( context, 0x21 );
828 break;
830 } /* END OF SWITCH */
832 if( bSetDOSExtendedError ) /* set general error condition */
834 SET_AX( context, GetLastError() );
835 SET_CFLAG(context);