Hi!
(replaces previous patch)
- 3 nested switch splitted into 2 switch (1st prepares parameters for
2nd, which calls execrh()).
- device attribute word checked through table lookup.
- CharReqHdr.r_command computed through table lookup.
- removed all goto, except one.
Result:
DGROUP increased from 1646 to 167c (54 bytes),
TGROUP decreased from de6e to dd4e (288 bytes).
_DATA segment increased from 248 to 27e (54 bytes),
HMA_DATA segment decreased from a482 to a36e (276 bytes).
---BeginMessage---
diff -ruNp old/kernel/ioctl.c new/kernel/ioctl.c
--- old/kernel/ioctl.c 2004-05-29 02:51:30.0 +
+++ new/kernel/ioctl.c 2004-06-02 03:20:14.0 +
@@ -56,38 +56,55 @@ static BYTE *RcsId =
COUNT DosDevIOctl(lregs * r)
{
- sft FAR *s;
- struct dpb FAR *dpbp;
- COUNT nMode;
- unsigned attr;
- unsigned char al = r-AL;
-
- if (al 0x11)
-return DE_INVLDFUNC;
+ static UBYTE cmds [] = {
+ 0, 0,
+ /* 0x02 */ C_IOCTLIN,
+ /* 0x03 */ C_IOCTLOUT,
+ /* 0x04 */ C_IOCTLIN,
+ /* 0x05 */ C_IOCTLOUT,
+ /* 0x06 */ C_ISTAT,
+ /* 0x07 */ C_OSTAT,
+ /* 0x08 */ C_REMMEDIA,
+ 0, 0, 0,
+ /* 0x0c */ C_GENIOCTL,
+ /* 0x0d */ C_GENIOCTL,
+ /* 0x0e */ C_GETLDEV,
+ /* 0x0f */ C_SETLDEV,
+ /* 0x10 */ C_IOCTLQRY,
+ /* 0x11 */ C_IOCTLQRY,
+ };
+ static UWORD required_attr [] = {
+ 0, 0,
+ /* 0x02 */ ATTR_IOCTL,
+ /* 0x03 */ ATTR_IOCTL,
+ /* 0x04 */ ATTR_IOCTL,
+ /* 0x05 */ ATTR_IOCTL,
+ 0, 0,
+ /* 0x08 */ ATTR_EXCALLS,
+ 0, 0, 0,
+ /* 0x0c */ ATTR_GENIOCTL,
+ /* 0x0d */ ATTR_GENIOCTL,
+ /* 0x0e */ ATTR_GENIOCTL,
+ /* 0x0f */ ATTR_GENIOCTL,
+ /* 0x10 */ ATTR_QRYIOCTL,
+ /* 0x11 */ ATTR_QRYIOCTL,
+ };
- /* 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);
- }
- CharReqHdr.r_length = sizeof(request);
- CharReqHdr.r_status = 0;
+ sft FAR *s;
+ struct dhdr FAR *dev;
+ unsigned attr, flags;
+ UBYTE cmd;
switch (r-AL)
{
+default: /* 0x12+ */
+ return DE_INVLDFUNC;
+
case 0x0b:
- /* skip, it's a special case. */
- NetDelay = r-CX;
- if (r-DX)
+ if (r-DX) /* skip, it's a special case*/
NetRetry = r-DX;
- break;
+ NetDelay = r-CX;
+ return SUCCESS;
case 0x00:
case 0x01:
@@ -98,31 +115,86 @@ COUNT DosDevIOctl(lregs * r)
case 0x0a:
case 0x0c:
case 0x10:
-{
- unsigned flags;
-
/* Test that the handle is valid and*/
/* get the SFT block that contains the SFT */
- if ((s = get_sft(r-BX)) == (sft FAR *) - 1)
+ if ((s = get_sft(r-BX)) == (sft FAR *)-1)
return DE_INVLDHNDL;
-
- attr = s-sft_dev-dh_attr;
flags = s-sft_flags;
+ attr = (dev = s-sft_dev)-dh_attr;
+ break;
+
+case 0x04:
+case 0x05:
+case 0x08:
+case 0x09:
+case 0x0d:
+case 0x0e:
+case 0x0f:
+case 0x11:
+{
+ struct dpb FAR *dpbp;
+/*
+ Line below 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
+ */
+/* changed to use default drive if drive=0. --JPP */
+/* Fixed it. --JT */
- switch (r-AL)
+#define NDN_HACK
+#ifdef NDN_HACK
+/* NDN feeds the actual ASCII drive letter to this function */
+ UBYTE unit = (r-BL 0x1f) - 1;
+#else
+ UBYTE unit = r-BL - 1;
+#endif
+ if (unit == 0xff)
+ unit = default_drive;
+ CharReqHdr.r_unit = unit;
+
+ if ((dpbp = get_dpb(unit)) == NULL)
{
-case 0x00:
+if (r-AL != 0x09)
+ return DE_INVLDDRV;
+attr = ATTR_REMOTE;
+ }
+ else
+attr = (dev = dpbp-dpb_device)-dh_attr;
+}
+ } /* switch */
+
+ /* required_attr[] may be zero and in this case attr ignored */
+ if (~attr required_attr [r-AL])
+return DE_INVLDFUNC;
+
+ /* commonly used, shouldn't harm to do front up */
+ CharReqHdr.r_command = cmd = cmds [r-AL];
+ if (cmd == C_GENIOCTL || cmd == C_IOCTLQRY)
+ {
+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);
+ }
+ CharReqHdr.r_length = sizeof(request);
+ CharReqHdr.r_status = 0;
+
+ switch (r-AL)
+ {
+case 0x00: