delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/12/25/16:35:22

Date: Mon, 25 Dec 2000 16:35:05 -0500
Message-Id: <200012252135.QAA09926@envy.delorie.com>
X-Authentication-Warning: envy.delorie.com: dj set sender to dj AT envy DOT delorie DOT com using -f
From: DJ Delorie <dj AT delorie DOT com>
To: djgpp-workers AT delorie DOT com
Subject: [nbensa AT hotmail DOT com: Patch for statfs.c]
Reply-To: djgpp-workers AT delorie DOT com

------- Start of forwarded message -------
X-Originating-IP: [200.42.6.246]
Reply-To: "Norberto Alfredo Bensa" <ceo AT nbensacomputers DOT com>
From: "Norberto Alfredo Bensa" <nbensa AT hotmail DOT com>
To: <dj AT delorie DOT com>
Subject: Patch for statfs.c
Date: Mon, 25 Dec 2000 18:17:59 -0300
Organization: nBens@ Computers
Content-Type: multipart/mixed;	boundary="----=_NextPart_000_007F_01C06E9F.03190280"
X-Priority: 3
X-MSMail-Priority: Normal
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
X-OriginalArrivalTime: 25 Dec 2000 21:33:59.0789 (UTC) FILETIME=[64A521D0:01C06EBA]

This is a multi-part message in MIME format.

- ------=_NextPart_000_007F_01C06E9F.03190280
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit


This is a patch for statfs.c (from CVS). The original file in the CVS didn't
report the actual number of free clusters on a FAT32 drive when running
under Windows (I think that Int21/AX=7302 reports the largest block of free
clusters instead of the total number of free clusters)

I've changed statfs to use Int21/AX=7303 which does works under Windows, but
not under plain DOS (if 217303 fails, then 217302 is used)

I've checked this patch under Windows98 (4.10.1998) and plain DOS (actually
4DOS 6.02B) and it reports the same numbers as chkdsk does. Assuming chkdsk
is correct then this patch is correct as well.

Best regards,
Norberto





- ------=_NextPart_000_007F_01C06E9F.03190280
Content-Type: video/x-dv;
	name="statfs.dif"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="statfs.dif"

*** src/libc/compat/sys/vfs/statfs.c.~	Mon Jun 19 19:00:56 2000=0A=
- --- src/libc/compat/sys/vfs/statfs.c	Mon Dec 25 18:02:18 2000=0A=
***************=0A=
*** 13,18 ****=0A=
- --- 13,19 ----=0A=
  #include <fcntl.h>=0A=
  #include <sys/vfs.h>=0A=
  #include <libc/dosio.h>=0A=
+ #include <malloc.h>=0A=
  =0A=
  #if 0=0A=
  #include <stdio.h>=0A=
***************=0A=
*** 25,42 ****=0A=
    int drive_number;=0A=
    int cdrom_calls_used =3D 0;=0A=
    long blocks =3D 0;=0A=
!   long free =3D 0;=0A=
    long bsize =3D 0;=0A=
  =0A=
    /* Get the drive number, including the case of magic=0A=
       names like /dev/c/foo.  */=0A=
    _put_path(path);=0A=
    drive_number =3D (_farpeekb(_dos_ds, __tb) & 0x1f) - 1;=0A=
    if (_farpeekb(_dos_ds, __tb + 1) !=3D ':' || drive_number =3D=3D -1)=0A=
    {=0A=
      regs.h.ah =3D 0x19;=0A=
      __dpmi_int(0x21, &regs);=0A=
      drive_number =3D regs.h.al;=0A=
    }=0A=
  =0A=
    /* For a CD-ROM drive, 213600 gives incorrect info.=0A=
- --- 26,46 ----=0A=
    int drive_number;=0A=
    int cdrom_calls_used =3D 0;=0A=
    long blocks =3D 0;=0A=
!   long freec =3D 0;=0A=
    long bsize =3D 0;=0A=
+   char *curdrive;=0A=
  =0A=
    /* Get the drive number, including the case of magic=0A=
       names like /dev/c/foo.  */=0A=
    _put_path(path);=0A=
+   (const char *)curdrive =3D path;=0A=
    drive_number =3D (_farpeekb(_dos_ds, __tb) & 0x1f) - 1;=0A=
    if (_farpeekb(_dos_ds, __tb + 1) !=3D ':' || drive_number =3D=3D -1)=0A=
    {=0A=
      regs.h.ah =3D 0x19;=0A=
      __dpmi_int(0x21, &regs);=0A=
      drive_number =3D regs.h.al;=0A=
+ 	curdrive =3D getcwd (NULL, 256);=0A=
    }=0A=
  =0A=
    /* For a CD-ROM drive, 213600 gives incorrect info.=0A=
***************=0A=
*** 99,105 ****=0A=
  	  && _farpeekw (_dos_ds, __tb + 5 + 0x12) =3D=3D 5)=0A=
        {=0A=
  	/* bsize has been set some lines above. */=0A=
! 	free =3D 0;		/* no free space: cannot add data to CD-ROM */=0A=
  	blocks  =3D _farpeekl (_dos_ds, __tb + 1);=0A=
  	cdrom_calls_used =3D 1;=0A=
        }=0A=
- --- 103,109 ----=0A=
  	  && _farpeekw (_dos_ds, __tb + 5 + 0x12) =3D=3D 5)=0A=
        {=0A=
  	/* bsize has been set some lines above. */=0A=
! 	freec =3D 0;		/* no free space: cannot add data to CD-ROM */=0A=
  	blocks  =3D _farpeekl (_dos_ds, __tb + 1);=0A=
  	cdrom_calls_used =3D 1;=0A=
        }=0A=
***************=0A=
*** 120,131 ****=0A=
        return -1;=0A=
      }=0A=
      bsize =3D regs.x.cx * regs.x.ax;=0A=
!     free =3D regs.x.bx;=0A=
      blocks =3D regs.x.dx;=0A=
  #if 0=0A=
      printf("First: bsize =3D %ld, free =3D %ld, blocks =3D %ld.\n"=0A=
  	 , bsize=0A=
! 	 , free=0A=
           , blocks=0A=
  	   );=0A=
  #endif=0A=
- --- 124,135 ----=0A=
        return -1;=0A=
      }=0A=
      bsize =3D regs.x.cx * regs.x.ax;=0A=
!     freec =3D regs.x.bx;=0A=
      blocks =3D regs.x.dx;=0A=
  #if 0=0A=
      printf("First: bsize =3D %ld, free =3D %ld, blocks =3D %ld.\n"=0A=
  	 , bsize=0A=
! 	 , freec=0A=
           , blocks=0A=
  	   );=0A=
  #endif=0A=
***************=0A=
*** 134,196 ****=0A=
       && _is_fat32(drive_number + 1) /* Is it a FAT32 drive? */=0A=
         )=0A=
      {=0A=
!       /* Get free space info from Extended Drive Parameter Block. */=0A=
!       regs.x.ax =3D 0x7302;=0A=
!       regs.h.dl =3D drive_number + 1;=0A=
!       regs.x.es =3D __tb_segment;=0A=
!       regs.x.di =3D __tb_offset;=0A=
        regs.x.cx =3D 0x100; /* 256 bytes should be enough (RBIL says =
0x3f). */=0A=
!       __dpmi_int(0x21, &regs);=0A=
!       =0A=
!       /* Errors? */=0A=
!       if( regs.x.flags & 1 )=0A=
!       {=0A=
! 	errno =3D ENODEV;=0A=
! 	return( -1 );=0A=
!       }=0A=
  =0A=
!       /* We trust previous int21 call more if free hasn't maxed out. */=0A=
!       if( free < blocks )=0A=
!       {=0A=
! 	/* Previous bsize is a multiple of this bsize, so the multiplication=0A=
! 	   and division here is really a rescaling of the previous free=0A=
! 	   value. */=0A=
! 	free *=3D bsize;=0A=
! 	bsize =3D _farpeekw (_dos_ds, __tb + 0x2 + 0x2) *=0A=
! 	  ( _farpeekb (_dos_ds, __tb + 0x2 + 0x4) + 1 );=0A=
! 	free /=3D bsize;=0A=
!       }=0A=
!       else=0A=
        {=0A=
! 	free =3D _farpeekw (_dos_ds, __tb + 0x2 + 0x1f) +=0A=
  	  65536 * _farpeekw (_dos_ds, __tb + 0x2 + 0x21);=0A=
  	bsize =3D _farpeekw (_dos_ds, __tb + 0x2 + 0x2) *=0A=
  	  ( _farpeekb (_dos_ds, __tb + 0x2 + 0x4) + 1 );=0A=
- -       }=0A=
        =0A=
!       blocks =3D _farpeekl( _dos_ds, __tb + 0x2 + 0x2d);=0A=
  #if 0=0A=
!       printf("Second: bsize =3D %ld, free =3D %ld, blocks =3D %ld.\n"=0A=
! 	   , bsize=0A=
! 	   , free=0A=
!           , blocks=0A=
! 	     );=0A=
  #endif=0A=
      }=0A=
    }=0A=
  =0A=
    /* Fill in the structure */=0A=
!   buf->f_bavail =3D free;=0A=
!   buf->f_bfree =3D free;=0A=
    buf->f_blocks =3D blocks;=0A=
    buf->f_bsize =3D bsize;=0A=
!   buf->f_ffree =3D free;=0A=
    buf->f_files =3D blocks;=0A=
    buf->f_type =3D 0;=0A=
    buf->f_fsid[0] =3D drive_number;=0A=
    buf->f_fsid[1] =3D MOUNT_UFS;=0A=
    buf->f_magic =3D FS_MAGIC;=0A=
  =0A=
    return 0;=0A=
  }=0A=
  =0A=
- --- 138,209 ----=0A=
       && _is_fat32(drive_number + 1) /* Is it a FAT32 drive? */=0A=
         )=0A=
      {=0A=
!       /* First try 217303 as 217302 reports fake free space=0A=
!          (largest block of free clusters?) */=0A=
!       _put_path (curdrive);=0A=
!       regs.x.ax =3D 0x7303;=0A=
!       regs.x.ds =3D regs.x.es =3D __tb_segment;=0A=
!       regs.x.dx =3D regs.x.di =3D __tb_offset;=0A=
        regs.x.cx =3D 0x100; /* 256 bytes should be enough (RBIL says =
0x3f). */=0A=
!       __dpmi_int (0x21, &regs);=0A=
  =0A=
!       /* Errors? (217303 seams to fail under plain DOS) */=0A=
!       if (regs.x.flags & 1)=0A=
        {=0A=
! 	/* Get free space info from Extended Drive Parameter Block. */=0A=
! 	regs.x.ax =3D 0x7302;=0A=
! 	regs.h.dl =3D drive_number + 1;=0A=
! 	regs.x.es =3D __tb_segment;=0A=
! 	regs.x.di =3D __tb_offset;=0A=
! 	regs.x.cx =3D 0x100; /* 256 bytes should be enough (RBIL says 0x3f). =
*/=0A=
! 	__dpmi_int(0x21, &regs);=0A=
!       =0A=
! 	/* Errors? */=0A=
! 	if( regs.x.flags & 1 )=0A=
! 	{=0A=
! 	  errno =3D ENODEV;=0A=
! 	  return( -1 );=0A=
! 	}=0A=
! =0A=
! 	freec =3D _farpeekw (_dos_ds, __tb + 0x2 + 0x1f) +=0A=
  	  65536 * _farpeekw (_dos_ds, __tb + 0x2 + 0x21);=0A=
  	bsize =3D _farpeekw (_dos_ds, __tb + 0x2 + 0x2) *=0A=
  	  ( _farpeekb (_dos_ds, __tb + 0x2 + 0x4) + 1 );=0A=
        =0A=
! 	blocks =3D _farpeekl( _dos_ds, __tb + 0x2 + 0x2d) - 1;=0A=
  #if 0=0A=
! 	printf("Second: bsize =3D %ld, free =3D %ld, blocks =3D %ld.\n"=0A=
! 	  , bsize=0A=
! 	  , freec=0A=
! 	  , blocks=0A=
! 		);=0A=
  #endif=0A=
+       }=0A=
+       else=0A=
+       {=0A=
+ 	freec  =3D _farpeekl (_dos_ds, __tb + 0x0c);=0A=
+ 	bsize  =3D _farpeekl (_dos_ds, __tb + 0x08)=0A=
+ 		* _farpeekl (_dos_ds, __tb + 0x04);=0A=
+ 	blocks =3D _farpeekl (_dos_ds, __tb + 0x10);=0A=
+       }=0A=
      }=0A=
    }=0A=
  =0A=
    /* Fill in the structure */=0A=
!   buf->f_bavail =3D freec;=0A=
!   buf->f_bfree =3D freec;=0A=
    buf->f_blocks =3D blocks;=0A=
    buf->f_bsize =3D bsize;=0A=
!   buf->f_ffree =3D freec;=0A=
    buf->f_files =3D blocks;=0A=
    buf->f_type =3D 0;=0A=
    buf->f_fsid[0] =3D drive_number;=0A=
    buf->f_fsid[1] =3D MOUNT_UFS;=0A=
    buf->f_magic =3D FS_MAGIC;=0A=
  =0A=
+   if (curdrive !=3D path)=0A=
+     free (curdrive);=0A=
+ =0A=
    return 0;=0A=
  }=0A=
  =0A=

- ------=_NextPart_000_007F_01C06E9F.03190280--
------- End of forwarded message -------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019