Hi!

This is my (first) try to bugfix wrong INT21/1B, INT21/1C and INT21/36.
Sorry, tom, but there more than 1-2 lines of diff, and I doubt that this
diff may be (noticeably) reduced.

dosfns.c

- bugfix: DosGetFree(): *navc was accessed (read and write) without checking
  if navc!=NULL; instead "navc!=NULL" was used "*nc!=0xffff".

fcbfns.c

- bugfix: FatGetDrvData(): was changed UWORD *spc, but INT21/1B and INT21/1C
  should change only AL, not AX.
? FatGetDrvData(): when get_dpb()==NULL, as value for media ID was used
  high byte of *spc (sectors_per_cluster), but it always zero.
- static Dmatch moved nearer to FcbFindFirstNext() and added comment from tom.

inthndlr.c

- bugfix: INT21/1B, INT21/1C: FatGetDrvData() now called with &lr.AL, not AX.

--- Begin Message ---
diff -ruNp old/kernel/dosfns.c new/kernel/dosfns.c
--- old/kernel/dosfns.c 2004-07-24 21:22:54.000000000 +0000
+++ new/kernel/dosfns.c 2004-07-25 01:25:20.000000000 +0000
@@ -96,6 +96,13 @@ STATIC int remote_lock_unlock(sft FAR *s
 /* get current directory structure for drive
    return NULL if the CDS is not valid or the
    drive is not within range */
+struct cds FAR *get_cds1(unsigned drv)
+{
+  if (drv-- == 0) /* 0 = A:, 1 = B:, ... */
+    drv = default_drive;
+  return get_cds(drv);
+}
+
 struct cds FAR *get_cds(unsigned drive)
 {
   struct cds FAR *cdsp;
@@ -106,9 +113,9 @@ struct cds FAR *get_cds(unsigned drive)
   cdsp = &CDSp[drive];
   flags = cdsp->cdsFlags;
   /* Entry is disabled or JOINed drives are accessable by the path only */
-  if (!(flags & CDSVALID) || (flags & CDSJOINED) != 0)
-    return NULL;
-  if (!(flags & CDSNETWDRV) && cdsp->cdsDpb == NULL)
+  if ((flags & CDSVALID) == 0 ||
+      (flags & CDSJOINED) != 0 ||
+      (flags & CDSNETWDRV) == 0 && cdsp->cdsDpb == NULL)
     return NULL;
   return cdsp;
 }
@@ -763,28 +770,22 @@ COUNT DosClose(COUNT hndl)
   return ret;
 }
 
-BOOL DosGetFree(UBYTE drive, UWORD * spc, UWORD * navc,
-                UWORD * bps, UWORD * nc)
+UWORD DosGetFree(UBYTE drive, UWORD * navc, UWORD * bps, UWORD * nc)
 {
-  /* navc==NULL means: called from FatGetDrvData, fcbfns.c */
-  struct dpb FAR *dpbp;
+  /* navc==NULL means: called from FatGetDrvData, fcbfns.c     */
   struct cds FAR *cdsp;
-  COUNT rg[4];
-
-  /* next - "log" in the drive            */
-  drive = (drive == 0 ? default_drive : drive - 1);
-
-  /* first check for valid drive          */
-  *spc = -1;
-  cdsp = get_cds(drive);
+  struct dpb FAR *dpbp;
+  UWORD spc;
 
-  if (cdsp == NULL)
-    return FALSE;
+  /* first check for valid drive                               */
+  if ((cdsp = get_cds1(drive)) == NULL)
+    return -1;
 
   if (cdsp->cdsFlags & CDSNETWDRV)
   {
+    COUNT rg[4];
     if (remote_getfree(cdsp, rg) != SUCCESS)
-      return FALSE;
+      return -1;
 
     /* for int21/ah=1c:
        Undoc DOS says, its not supported for
@@ -793,21 +794,15 @@ BOOL DosGetFree(UBYTE drive, UWORD * spc
        the redirector can provide all info
        - Bart, 2002 Apr 1 */
 
-    if (navc != NULL)
-    {
-      *navc = (COUNT) rg[3];
-      *spc &= 0xff; /* zero out media ID byte */
-    }
-
-    *spc = (COUNT) rg[0];
-    *nc = (COUNT) rg[1];
-    *bps = (COUNT) rg[2];
-    return TRUE;
+    *bps = rg[2];
+    *nc = rg[1];
+    if (navc)
+      *navc = rg[3];
+    return rg[0];
   }
 
-  dpbp = cdsp->cdsDpb;
-  if (dpbp == NULL)
-    return FALSE;
+  if ((dpbp = cdsp->cdsDpb) == NULL)
+    return -1;
 
   if (navc == NULL)
   {
@@ -815,56 +810,60 @@ BOOL DosGetFree(UBYTE drive, UWORD * spc
     flush_buffers(dpbp->dpb_unit);
     dpbp->dpb_flags = M_CHANGED;
   }
-
   if (media_check(dpbp) < 0)
-    return FALSE;
-  /* get the data available from dpb      */
-  *spc = (dpbp->dpb_clsmask + 1);
+    return -1;
+
+  /* get the data available from dpb                           */
+  spc = dpbp->dpb_clsmask + 1;
   *bps = dpbp->dpb_secsize;
 
-  /* now tell fs to give us free cluster  */
-  /* count                                */
 #ifdef WITHFAT32
   if (ISFAT32(dpbp))
   {
     ULONG cluster_size, ntotal, nfree;
 
-    /* we shift ntotal until it is equal to or below 0xfff6 */
     cluster_size = (ULONG) dpbp->dpb_secsize << dpbp->dpb_shftcnt;
     ntotal = dpbp->dpb_xsize - 1;
-    if (navc != NULL)
+    /* now tell fs to give us free cluster count               */
+    if (navc)
       nfree = dos_free(dpbp);
+
+    /* we shift ntotal until it is equal to or below 0xfff6    */
     while (ntotal > FAT_MAGIC16 && cluster_size < 0x8000)
     {
       cluster_size <<= 1;
-      *spc <<= 1;
+      spc <<= 1;
       ntotal >>= 1;
       nfree >>= 1;
     }
-    /* get the data available from dpb      */
-    *nc = ntotal > FAT_MAGIC16 ? FAT_MAGIC16 : (UCOUNT) ntotal;
 
-    /* now tell fs to give us free cluster  */
-    /* count                                */
-    if (navc != NULL)
-      *navc = nfree > FAT_MAGIC16 ? FAT_MAGIC16 : (UCOUNT) nfree;
-    return TRUE;
+    *nc = ntotal > FAT_MAGIC16 ? FAT_MAGIC16 : (UWORD) ntotal;
+    if (navc)
+      *navc = nfree > FAT_MAGIC16 ? FAT_MAGIC16 : (UWORD) nfree;
+    return spc;
   }
 #endif
-  /* a passed nc of 0xffff means: skip free; see FatGetDrvData
-     fcbfns.c */
-  if (*nc != 0xffff)
-    *navc = (COUNT) dos_free(dpbp);
+
+  /* now tell fs to give us free cluster count                 */
   *nc = dpbp->dpb_size - 1;
-  if (*spc > 64)
+  if (navc)
+    *navc = (UWORD) dos_free(dpbp);
+  if (spc > 64)
   {
     /* fake for 64k clusters do confuse some DOS programs, but let
        others work without overflowing */
-    *spc >>= 1;
-    *navc = ((unsigned)*navc < FAT_MAGIC16 / 2) ? ((unsigned)*navc << 1) : 
FAT_MAGIC16;
-    *nc = ((unsigned)*nc < FAT_MAGIC16 / 2) ? ((unsigned)*nc << 1) : FAT_MAGIC16;
+    spc >>= 1;
+    if (*nc > FAT_MAGIC16 / 2)
+      *nc = FAT_MAGIC16;
+    else
+      *nc <<= 1;
+    if (navc)
+      if (*navc > FAT_MAGIC16 / 2)
+        *navc = FAT_MAGIC16;
+      else
+        *navc <<= 1;
   }
-  return TRUE;
+  return spc;
 }
 
 #ifdef WITHFAT32
diff -ruNp old/kernel/fcbfns.c new/kernel/fcbfns.c
--- old/kernel/fcbfns.c 2004-07-24 22:04:40.000000000 +0000
+++ new/kernel/fcbfns.c 2004-07-25 00:21:02.000000000 +0000
@@ -50,29 +50,27 @@ STATIC void FcbCalcRec(xfcb FAR * lpXfcb
 #define TestCmnSeps(lpFileName) (*lpFileName && strchr(":<|>+=,", *lpFileName) != 
NULL)
 #define TestFieldSeps(lpFileName) ((unsigned char)*lpFileName <= ' ' || 
strchr("/\"[]<>|.", *lpFileName) != NULL)
 
-static dmatch Dmatch;
-
-BYTE FAR *FatGetDrvData(UBYTE drive, UWORD * spc, UWORD * bps, UWORD * nc)
+UBYTE FAR *FatGetDrvData(UBYTE drive, UBYTE * pspc, UWORD * bps, UWORD * nc)
 {
-  static BYTE mdb;
+  /* get the data available from dpb                           */
+  UWORD spc = DosGetFree(drive, NULL, bps, nc);
+  if ((*pspc = lobyte(spc)) == 0xff)
+    return NULL;
+
+  if (drive-- == 0) /* 0 = A:, 1 = B:, ... */
+    drive = default_drive;
 
-  /* get the data available from dpb                       */
-  if (DosGetFree(drive, spc, NULL, bps, nc))
+  /* Point to the media desctriptor for this drive             */
   {
-    struct dpb FAR *dpbp = get_dpb(drive == 0 ? default_drive : drive - 1);
-    /* Point to the media desctriptor for this drive               */
-    if (dpbp == NULL)
-    {
-      mdb = *spc >> 8;
-      *spc &= 0xff;
-      return &mdb;
-    }
-    else
-    {
-      return (BYTE FAR *) & (dpbp->dpb_mdb);
-    }
+    struct dpb FAR *dpbp;
+    if ((dpbp = get_dpb(drive)) != NULL)
+      return &dpbp->dpb_mdb;
+  }
+
+  {
+    static UBYTE mdb = 0;
+    return &mdb;
   }
-  return NULL;
 }
 
 #define PARSE_SEP_STOP          0x01
@@ -633,6 +631,10 @@ VOID FcbCloseAll()
       DosCloseSft(idx, FALSE);
 }
 
+/* TE suggest, that there was not enough space on stack for
+   Dmatch in FcbFindFirstNext() --avb */
+static dmatch Dmatch;
+
 UBYTE FcbFindFirstNext(xfcb FAR * lpXfcb, BOOL First)
 {
   void FAR *orig_dta = dta;
diff -ruNp old/kernel/inthndlr.c new/kernel/inthndlr.c
--- old/kernel/inthndlr.c       2004-07-24 21:26:42.000000000 +0000
+++ new/kernel/inthndlr.c       2004-07-25 00:22:58.000000000 +0000
@@ -609,14 +609,12 @@ dispatch:
 
       /* Get Drive Data                                               */
     case 0x1c:
-      {
-        BYTE FAR *p;
-
-        p = FatGetDrvData(lr.DL, &lr.AX, &lr.CX, &lr.DX);
-        lr.DS = FP_SEG(p);
-        lr.BX = FP_OFF(p);
-      }
+    {
+      UBYTE FAR *p = FatGetDrvData(lr.DL, &lr.AL, &lr.CX, &lr.DX);
+      lr.DS = FP_SEG(p);
+      lr.BX = FP_OFF(p);
       break;
+    }
 
       /* Get default DPB                                              */
       /* case 0x1f: see case 0x32 */
@@ -792,7 +790,7 @@ dispatch:
 
       /* Dos Get Disk Free Space                                      */
     case 0x36:
-      DosGetFree(lr.DL, &lr.AX, &lr.BX, &lr.CX, &lr.DX);
+      lr.AX = DosGetFree(lr.DL, &lr.BX, &lr.CX, &lr.DX);
       break;
 
       /* Undocumented Get/Set Switchar                                */
diff -ruNp old/kernel/proto.h new/kernel/proto.h
--- old/kernel/proto.h  2004-07-24 22:04:26.000000000 +0000
+++ new/kernel/proto.h  2004-07-25 00:28:04.000000000 +0000
@@ -102,8 +102,7 @@ long DosOpenSft(char FAR * fname, unsign
 COUNT DosClose(COUNT hndl);
 COUNT DosCloseSft(int sft_idx, BOOL commitonly);
 #define DosCommit(hndl) DosCloseSft(get_sft_idx(hndl), TRUE)
-BOOL DosGetFree(UBYTE drive, UWORD * spc, UWORD * navc,
-                UWORD * bps, UWORD * nc);
+UWORD DosGetFree(UBYTE drive, UWORD * navc, UWORD * bps, UWORD * nc);
 COUNT DosGetCuDir(UBYTE drive, BYTE FAR * s);
 COUNT DosChangeDir(BYTE FAR * s);
 COUNT DosFindFirst(UCOUNT attr, const char FAR * name);
@@ -124,7 +123,8 @@ COUNT DosLockUnlock(COUNT hndl, LONG pos
 int idx_to_sft_(int SftIndex);
 sft FAR *idx_to_sft(int SftIndex);
 int get_sft_idx(UCOUNT hndl);
-struct cds FAR *get_cds(unsigned dsk);
+struct cds FAR *get_cds1(unsigned drv);
+struct cds FAR *get_cds(unsigned drv);
 COUNT DosTruename(const char FAR * src, char FAR * dest);
 
 /*dosidle.asm */
@@ -214,8 +214,7 @@ int DosCharInput(VOID);
 VOID DosDirectConsoleIO(iregs FAR * r);
 VOID DosCharOutput(COUNT c);
 VOID DosDisplayOutput(COUNT c);
-BYTE FAR *FatGetDrvData(UBYTE drive, UWORD * spc, UWORD * bps,
-                   UWORD * nc);
+UBYTE FAR *FatGetDrvData(UBYTE drive, UBYTE * spc, UWORD * bps, UWORD * nc);
 ofs_t FcbParseFname(UBYTE *wTestMode, const char FAR * lpFileName, fcb FAR * lpFcb);
 const BYTE FAR *ParseSkipWh(const BYTE FAR * lpFileName);
 BOOL TestCmnSeps(BYTE FAR * lpFileName);
diff -ruNp old/kernel/task.c new/kernel/task.c
--- old/kernel/task.c   2004-07-14 21:41:12.000000000 +0000
+++ new/kernel/task.c   2004-07-25 00:27:24.000000000 +0000
@@ -214,13 +214,6 @@ void child_psp(seg_t para, seg_t cur_psp
   }
 }
 
-struct cds FAR *get_cds1(unsigned drv)
-{
-  if (drv-- == 0) /* 0 = A:, 1 = B:, ... */
-    drv = default_drive;
-  return get_cds(drv);
-}
-
 STATIC void makePSP(seg_t pspseg, seg_t envseg, size_t asize, const char FAR * path)
 {
   psp _seg *p = MK_SEG_PTR(psp, pspseg);

--- End Message ---

Reply via email to