2000-05-06 21:34:20 +02:00
|
|
|
/****************************************************************/
|
|
|
|
/* */
|
|
|
|
/* ioctl.c */
|
|
|
|
/* */
|
|
|
|
/* DOS-C ioctl system call */
|
|
|
|
/* */
|
|
|
|
/* Copyright (c) 1995,1998 */
|
|
|
|
/* Pasquale J. Villani */
|
|
|
|
/* All Rights Reserved */
|
|
|
|
/* */
|
|
|
|
/* This file is part of DOS-C. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is free software; you can redistribute it and/or */
|
|
|
|
/* modify it under the terms of the GNU General Public License */
|
|
|
|
/* as published by the Free Software Foundation; either version */
|
|
|
|
/* 2, or (at your option) any later version. */
|
|
|
|
/* */
|
|
|
|
/* DOS-C is distributed in the hope that it will be useful, but */
|
|
|
|
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
|
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
|
|
|
|
/* the GNU General Public License for more details. */
|
|
|
|
/* */
|
|
|
|
/* You should have received a copy of the GNU General Public */
|
|
|
|
/* License along with DOS-C; see the file COPYING. If not, */
|
|
|
|
/* write to the Free Software Foundation, 675 Mass Ave, */
|
|
|
|
/* Cambridge, MA 02139, USA. */
|
|
|
|
/****************************************************************/
|
|
|
|
|
|
|
|
#include "portab.h"
|
|
|
|
#include "globals.h"
|
|
|
|
|
|
|
|
#ifdef VERSION_STRINGS
|
2001-11-18 15:01:12 +01:00
|
|
|
static BYTE *RcsId =
|
|
|
|
"$Id$";
|
2000-05-06 21:34:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING: this code is non-portable (8086 specific).
|
|
|
|
*/
|
|
|
|
|
2001-11-04 20:47:39 +01:00
|
|
|
/* TE 10/29/01
|
|
|
|
|
|
|
|
although device drivers have only 20 pushes available for them,
|
|
|
|
MS NET plays by its own rules
|
|
|
|
|
|
|
|
at least TE's network card driver DM9PCI (some 10$ NE2000 clone) does:
|
|
|
|
with SP=8DC before calling down to execrh, and SP=8CC when
|
|
|
|
callf [interrupt], DM9PCI touches DOSDS:792,
|
|
|
|
14 bytes into error stack :-(((
|
|
|
|
|
|
|
|
so some optimizations were made.
|
|
|
|
this uses the fact, that only CharReq device buffer is ever used.
|
|
|
|
fortunately, this saves some code as well :-)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2002-08-04 03:14:18 +02:00
|
|
|
COUNT DosDevIOctl(lregs * r)
|
2000-05-06 21:34:20 +02:00
|
|
|
{
|
|
|
|
sft FAR *s;
|
|
|
|
struct dpb FAR *dpbp;
|
2001-11-04 20:47:39 +01:00
|
|
|
COUNT nMode;
|
2004-05-28 15:15:22 +02:00
|
|
|
unsigned attr;
|
2004-05-28 14:57:41 +02:00
|
|
|
unsigned char al = r->AL;
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2004-05-28 14:57:41 +02:00
|
|
|
if (al > 0x11)
|
|
|
|
return DE_INVLDFUNC;
|
2001-11-04 20:47:39 +01:00
|
|
|
|
2004-05-28 14:57:41 +02:00
|
|
|
/* commonly used, shouldn't harm to do front up */
|
|
|
|
if (al == 0x0C || al == 0x0D || al >= 0x10) /* generic or query */
|
|
|
|
{
|
|
|
|
CharReqHdr.r_cat = r->CH; /* category (major) code */
|
|
|
|
CharReqHdr.r_fun = r->CL; /* function (minor) code */
|
|
|
|
CharReqHdr.r_io = MK_FP(r->DS, r->DX); /* parameter block */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CharReqHdr.r_count = r->CX;
|
|
|
|
CharReqHdr.r_trans = MK_FP(r->DS, r->DX);
|
|
|
|
}
|
2001-11-04 20:47:39 +01:00
|
|
|
CharReqHdr.r_length = sizeof(request);
|
|
|
|
CharReqHdr.r_status = 0;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
|
|
|
switch (r->AL)
|
|
|
|
{
|
2004-05-28 15:15:22 +02:00
|
|
|
case 0x0b:
|
|
|
|
/* skip, it's a special case. */
|
|
|
|
NetDelay = r->CX;
|
|
|
|
if (r->DX)
|
|
|
|
NetRetry = r->DX;
|
|
|
|
break;
|
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
case 0x00:
|
|
|
|
case 0x01:
|
|
|
|
case 0x02:
|
|
|
|
case 0x03:
|
|
|
|
case 0x06:
|
|
|
|
case 0x07:
|
|
|
|
case 0x0a:
|
|
|
|
case 0x0c:
|
2002-08-04 03:14:18 +02:00
|
|
|
case 0x10:
|
2004-01-27 13:42:45 +01:00
|
|
|
{
|
|
|
|
unsigned attr, flags;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-05-28 15:15:22 +02:00
|
|
|
/* Test that the handle is valid and */
|
|
|
|
/* get the SFT block that contains the SFT */
|
2000-05-06 21:34:20 +02:00
|
|
|
if ((s = get_sft(r->BX)) == (sft FAR *) - 1)
|
2001-04-15 05:21:50 +02:00
|
|
|
return DE_INVLDHNDL;
|
2004-01-27 13:42:45 +01:00
|
|
|
|
|
|
|
attr = s->sft_dev->dh_attr;
|
|
|
|
flags = s->sft_flags;
|
|
|
|
|
2002-08-04 03:14:18 +02:00
|
|
|
switch (r->AL)
|
2004-01-26 20:43:06 +01:00
|
|
|
{
|
2002-08-04 03:14:18 +02:00
|
|
|
case 0x00:
|
|
|
|
/* Get the flags from the SFT */
|
2004-01-26 20:43:06 +01:00
|
|
|
if (flags & SFT_FDEVICE)
|
|
|
|
r->AX = (attr & 0xff00) | (flags & 0xff);
|
2002-08-04 03:14:18 +02:00
|
|
|
else
|
2004-01-26 20:43:06 +01:00
|
|
|
r->AX = flags;
|
2002-08-04 03:14:18 +02:00
|
|
|
/* Undocumented result, Ax = Dx seen using Pcwatch */
|
|
|
|
r->DX = r->AX;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x01:
|
|
|
|
/* sft_flags is a file, return an error because you */
|
|
|
|
/* can't set the status of a file. */
|
2004-01-26 20:43:06 +01:00
|
|
|
if (!(flags & SFT_FDEVICE))
|
2002-08-04 03:14:18 +02:00
|
|
|
return DE_INVLDFUNC;
|
2004-04-13 22:37:30 +02:00
|
|
|
/* RBIL says this is only for DOS < 6, but MSDOS 7.10 */
|
|
|
|
/* returns this as well... and some buggy program relies*/
|
|
|
|
/* on it :( */
|
|
|
|
if (r->DH != 0)
|
|
|
|
return DE_INVLDDATA;
|
|
|
|
|
|
|
|
/* Undocumented: AL should get the old value */
|
|
|
|
r->AL = s->sft_flags_lo;
|
2002-08-04 03:14:18 +02:00
|
|
|
/* Set it to what we got in the DL register from the */
|
|
|
|
/* user. */
|
2004-04-13 22:37:30 +02:00
|
|
|
s->sft_flags_lo = SFT_FDEVICE | r->DL;
|
2002-08-04 03:14:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x02:
|
|
|
|
nMode = C_IOCTLIN;
|
|
|
|
goto IoCharCommon;
|
|
|
|
|
|
|
|
case 0x03:
|
|
|
|
nMode = C_IOCTLOUT;
|
|
|
|
goto IoCharCommon;
|
|
|
|
|
|
|
|
case 0x06:
|
2004-01-26 20:43:06 +01:00
|
|
|
if (flags & SFT_FDEVICE)
|
2004-01-26 20:40:13 +01:00
|
|
|
{
|
|
|
|
nMode = C_ISTAT;
|
|
|
|
goto IoCharCommon;
|
|
|
|
}
|
|
|
|
r->AL = s->sft_posit >= s->sft_size ? 0 : 0xFF;
|
2002-08-04 03:14:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x07:
|
2004-01-26 20:43:06 +01:00
|
|
|
if (flags & SFT_FDEVICE)
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
|
|
|
nMode = C_OSTAT;
|
|
|
|
goto IoCharCommon;
|
|
|
|
}
|
|
|
|
r->AL = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0a:
|
2004-01-26 20:43:06 +01:00
|
|
|
r->DX = flags;
|
2002-08-04 03:14:18 +02:00
|
|
|
r->AX = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0c:
|
|
|
|
nMode = C_GENIOCTL;
|
|
|
|
goto IoCharCommon;
|
|
|
|
|
2004-05-28 15:15:22 +02:00
|
|
|
default: /* 0x10 */
|
2002-08-04 03:14:18 +02:00
|
|
|
nMode = C_IOCTLQRY;
|
|
|
|
IoCharCommon:
|
2004-01-26 20:43:06 +01:00
|
|
|
if ((flags & SFT_FDEVICE) &&
|
2004-05-28 15:15:22 +02:00
|
|
|
( (r->AL <= 0x03 && (attr & ATTR_IOCTL))
|
|
|
|
|| r->AL == 0x06 || r->AL == 0x07
|
|
|
|
|| (r->AL == 0x10 && (attr & ATTR_QRYIOCTL))
|
|
|
|
|| (r->AL == 0x0c && (attr & ATTR_GENIOCTL))))
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
|
|
|
CharReqHdr.r_unit = 0;
|
|
|
|
CharReqHdr.r_command = nMode;
|
|
|
|
execrh((request FAR *) & CharReqHdr, s->sft_dev);
|
|
|
|
|
|
|
|
if (CharReqHdr.r_status & S_ERROR)
|
|
|
|
{
|
|
|
|
CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13;
|
|
|
|
return DE_DEVICE;
|
|
|
|
}
|
2004-05-23 20:28:18 +02:00
|
|
|
|
2004-05-28 15:15:22 +02:00
|
|
|
if (r->AL <= 0x03)
|
2002-08-04 03:14:18 +02:00
|
|
|
r->AX = CharReqHdr.r_count;
|
2004-05-28 15:15:22 +02:00
|
|
|
else if (r->AL == 0x06 || r->AL == 0x07)
|
|
|
|
r->AX = CharReqHdr.r_status & S_BUSY ? 0000 : 0x00ff;
|
|
|
|
else /* 0x0c or 0x10 */
|
2002-08-04 03:14:18 +02:00
|
|
|
r->AX = CharReqHdr.r_status;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return DE_INVLDFUNC;
|
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
break;
|
2004-01-27 13:42:45 +01:00
|
|
|
}
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2004-05-28 15:15:22 +02:00
|
|
|
default: /* block IOCTL: 4, 5, 8, 9, d, e, f, 11 */
|
2000-05-08 06:30:00 +02:00
|
|
|
|
2000-05-06 21:34:20 +02:00
|
|
|
/*
|
|
|
|
This line previously returned the deviceheader at r->bl. But,
|
|
|
|
DOS numbers its drives starting at 1, not 0. A=1, B=2, and so
|
|
|
|
on. Changed this line so it is now zero-based.
|
|
|
|
|
|
|
|
-SRM
|
|
|
|
*/
|
|
|
|
/* JPP - changed to use default drive if drive=0 */
|
2000-05-08 06:30:00 +02:00
|
|
|
/* JT Fixed it */
|
|
|
|
|
2002-11-09 20:34:04 +01:00
|
|
|
#define NDN_HACK
|
|
|
|
/* NDN feeds the actual ASCII drive letter to this function */
|
|
|
|
#ifdef NDN_HACK
|
|
|
|
CharReqHdr.r_unit = ((r->BL & 0x1f) == 0 ? default_drive :
|
|
|
|
(r->BL & 0x1f) - 1);
|
|
|
|
#else
|
2001-11-18 15:01:12 +01:00
|
|
|
CharReqHdr.r_unit = (r->BL == 0 ? default_drive : r->BL - 1);
|
2002-11-09 20:34:04 +01:00
|
|
|
#endif
|
2000-05-11 06:26:26 +02:00
|
|
|
|
2002-10-22 04:40:19 +02:00
|
|
|
dpbp = get_dpb(CharReqHdr.r_unit);
|
2004-05-28 15:15:22 +02:00
|
|
|
attr = dpbp->dpb_device->dh_attr;
|
2000-05-06 21:34:20 +02:00
|
|
|
|
2002-08-04 03:14:18 +02:00
|
|
|
switch (r->AL)
|
|
|
|
{
|
|
|
|
case 0x04:
|
|
|
|
nMode = C_IOCTLIN;
|
|
|
|
goto IoBlockCommon;
|
|
|
|
case 0x05:
|
|
|
|
nMode = C_IOCTLOUT;
|
|
|
|
goto IoBlockCommon;
|
|
|
|
case 0x08:
|
|
|
|
if (!dpbp)
|
|
|
|
{
|
|
|
|
return DE_INVLDDRV;
|
|
|
|
}
|
2004-05-28 15:15:22 +02:00
|
|
|
if (attr & ATTR_EXCALLS)
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
|
|
|
nMode = C_REMMEDIA;
|
|
|
|
goto IoBlockCommon;
|
|
|
|
}
|
|
|
|
return DE_INVLDFUNC;
|
|
|
|
case 0x09:
|
2002-11-09 20:34:04 +01:00
|
|
|
{
|
|
|
|
struct cds FAR *cdsp = get_cds(CharReqHdr.r_unit);
|
|
|
|
r->AX = S_DONE | S_BUSY;
|
|
|
|
if (cdsp != NULL && dpbp == NULL)
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
|
|
|
r->DX = ATTR_REMOTE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!dpbp)
|
|
|
|
{
|
|
|
|
return DE_INVLDDRV;
|
|
|
|
}
|
2004-05-28 15:15:22 +02:00
|
|
|
r->DX = attr;
|
2002-11-09 20:34:04 +01:00
|
|
|
}
|
|
|
|
if (cdsp->cdsFlags & CDSSUBST)
|
|
|
|
{
|
|
|
|
r->DX |= ATTR_SUBST;
|
2002-08-04 03:14:18 +02:00
|
|
|
}
|
|
|
|
break;
|
2002-11-09 20:34:04 +01:00
|
|
|
}
|
2002-08-04 03:14:18 +02:00
|
|
|
case 0x0d:
|
|
|
|
nMode = C_GENIOCTL;
|
|
|
|
goto IoBlockCommon;
|
|
|
|
case 0x11:
|
|
|
|
nMode = C_IOCTLQRY;
|
|
|
|
IoBlockCommon:
|
|
|
|
if (!dpbp)
|
|
|
|
{
|
|
|
|
return DE_INVLDDRV;
|
|
|
|
}
|
2004-03-07 14:07:05 +01:00
|
|
|
if (r->AL == 0x0D && (r->CX & ~(0x486B-0x084A)) == 0x084A)
|
|
|
|
{ /* 084A/484A, 084B/484B, 086A/486A, 086B/486B */
|
|
|
|
r->AX = 0; /* (lock/unlock logical/physical volume) */
|
|
|
|
break; /* simulate success for MS-DOS 7+ SCANDISK etc. --LG */
|
|
|
|
}
|
2004-05-28 15:15:22 +02:00
|
|
|
if ((r->AL <= 0x05 && !(attr & ATTR_IOCTL))
|
|
|
|
|| (r->AL == 0x11 && !(attr & ATTR_QRYIOCTL))
|
|
|
|
|| (r->AL == 0x0d && !(attr & ATTR_GENIOCTL)))
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
|
|
|
return DE_INVLDFUNC;
|
|
|
|
}
|
|
|
|
|
|
|
|
CharReqHdr.r_command = nMode;
|
|
|
|
execrh((request FAR *) & CharReqHdr, dpbp->dpb_device);
|
|
|
|
|
|
|
|
if (CharReqHdr.r_status & S_ERROR)
|
|
|
|
{
|
|
|
|
CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13;
|
|
|
|
return DE_DEVICE;
|
|
|
|
}
|
2004-05-28 15:15:22 +02:00
|
|
|
if (r->AL <= 0x05)
|
2002-08-04 03:14:18 +02:00
|
|
|
r->AX = CharReqHdr.r_count;
|
2004-05-28 15:15:22 +02:00
|
|
|
else if (r->AL == 0x08)
|
|
|
|
r->AX = (CharReqHdr.r_status & S_BUSY) ? 1 : 0;
|
|
|
|
else /* 0x0d or 0x11 */
|
2002-08-04 03:14:18 +02:00
|
|
|
r->AX = CharReqHdr.r_status;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0x0e:
|
|
|
|
nMode = C_GETLDEV;
|
|
|
|
goto IoLogCommon;
|
2004-05-28 15:15:22 +02:00
|
|
|
default: /* 0x0f */
|
2002-08-04 03:14:18 +02:00
|
|
|
nMode = C_SETLDEV;
|
|
|
|
IoLogCommon:
|
|
|
|
if (!dpbp)
|
|
|
|
{
|
|
|
|
return DE_INVLDDRV;
|
|
|
|
}
|
2004-05-28 15:15:22 +02:00
|
|
|
if (attr & ATTR_GENIOCTL)
|
2002-08-04 03:14:18 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
CharReqHdr.r_command = nMode;
|
|
|
|
execrh((request FAR *) & CharReqHdr, dpbp->dpb_device);
|
|
|
|
|
|
|
|
if (CharReqHdr.r_status & S_ERROR)
|
|
|
|
{
|
|
|
|
CritErrCode = (CharReqHdr.r_status & S_MASK) + 0x13;
|
|
|
|
return DE_ACCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r->AL = CharReqHdr.r_unit;
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
2004-05-28 15:15:22 +02:00
|
|
|
}
|
2002-08-04 03:14:18 +02:00
|
|
|
return DE_INVLDFUNC;
|
|
|
|
}
|
|
|
|
break;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
2001-04-15 05:21:50 +02:00
|
|
|
return SUCCESS;
|
2000-05-06 21:34:20 +02:00
|
|
|
}
|
|
|
|
|