Get free space on a drive 
Author Message
 Get free space on a drive

I have much experiance with Turbo Pascal 7, but have never had to use
DIskfree .
Are there any conflicts known with DiskFree, such as Fat32 or very large
HD's?
Also, lets say I'm about to write a file to the definded TEMP dir
(assume my program has
already gotten this as a PathStr ) How do I check this unknown drive for
free room?


Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive
Hi Mr,

TP7 simply uses a BIOS call (Int $21, function $36). So, TP7 has
little to do with the actual code to get the size of a disk. In my
experience the DiskFree() function does work, and simply limits the
size to a maximum of 2 MB which is acceptable in most cases.

There was one exception; when DiskFree() has to report the free space
of a Novell Network disk it generates an overflow. To prevent this I
had to rewrite the DiskFree() routine:

FUNCTION DiskFree(Drive:BYTE):LONGINT;
{DiskFree returns the number of free bytes on the specified
 drive number (0=Default,1=A,2=B,..). DiskFree returns -1 if
 the drive number is invalid.}
VAR Regs:TREGISTERS;
BEGIN
  FillChar(Regs,SizeOf(Regs),#0);
  WITH Regs DO
  BEGIN
    DL := Drive;
    AH := $36;
    Intr($21,Regs);
    IF AX = $0FFFF THEN
    BEGIN
      DiskFree := 0;
    END
    ELSE
    BEGIN
      DiskFree := LONGINT(AX)*LONGINT(BX)*LONGINT(CX);
    END;
  END;
END; {DiskFree}

This is basically the same code as TP7 uses, except for the multiple
LONGINT castings. This one has worked for me in all cases, but still
limits the results to 2 MB. This is a DOS (BIOS) problem, not a TP7
problem.

Best Regards,

Peter de Jong

Quote:

>I have much experiance with Turbo Pascal 7, but have never had to use
>DIskfree .
>Are there any conflicts known with DiskFree, such as Fat32 or very large
>HD's?
>Also, lets say I'm about to write a file to the definded TEMP dir
>(assume my program has
>already gotten this as a PathStr ) How do I check this unknown drive for
>free room?



Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive

|Hi Mr,

|TP7 simply uses a BIOS call (Int $21, function $36). So, TP7 has
|little to do with the actual code to get the size of a disk. In my
|experience the DiskFree() function does work, and simply limits the
|size to a maximum of 2 MB which is acceptable in most cases.

Remember to check if the result is negative.  This should be
interpreted as free space > 2 GB

Phil



Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive

Quote:

> Remember to check if the result is negative.  This should be
> interpreted as free space > 2 GB

No. On my 4.3 GB disk, DiskSize and DiskFree did not return negative
values. They returned something around 2,147,000,000 bytes. The
following functions reported the correct size of my hard disk. For
whatever reason, they do not always work, that is, they might return the
same garbage as Borland's functions. Even the DIR command sometimes
returns such garbage.

program ExtendedDiskFree;
var
  Struc : array[1..10] of longint;

function DiskSize(Path: string): comp; assembler;
asm
  push   ds
  push   ds
  lds    si, Path
  les    di, Path
  cld
  lodsb
  mov    cl, al
  xor    ch, ch
  rep    movsb
  xor    al, al
  stosb
  mov    ax, 7303h
  lds    dx, Path
  pop    es
  lea    di, Struc
  mov    cx, 44
  int    21h
  fild   dword ptr es:[di+4]
  fild   dword ptr es:[di+8]
  fild   dword ptr es:[di+10h]
  fmulp
  fmulp
  pop    ds
end;

function DiskFree(Path: string): comp; assembler;
asm
  push   ds
  push   ds
  lds    si, Path
  les    di, Path
  cld
  lodsb
  mov    cl, al
  xor    ch, ch
  rep    movsb
  xor    al, al
  stosb
  mov    ax, 7303h
  lds    dx, Path
  pop    es
  lea    di, Struc
  mov    cx, 44
  int    21h
  fild   dword ptr es:[di+4]
  fild   dword ptr es:[di+8]
  fild   dword ptr es:[di+0Ch]
  fmulp
  fmulp
  pop    ds
end;

begin
  writeln('Total: ', DiskSize('C:\'):1:0, ' Bytes');
  writeln('In use: ', DiskSize('C:\') - DiskFree('C:\'):1:0, ' Bytes');
  writeln('Free : ', DiskFree('C:\'):1:0, ' Bytes')
end.



Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive

Quote:

> No. On my 4.3 GB disk, DiskSize and DiskFree did not return negative
> values. They returned something around 2,147,000,000 bytes. The
> following functions reported the correct size of my hard disk. For
> whatever reason, they do not always work, that is, they might return the
> same garbage as Borland's functions. Even the DIR command sometimes
> returns such garbage.

I compiled and executed the program you provided with BP 7.01 under
Windows 95, a 500 MB FAT-16 disk.  It printed out several lines of
garbage.  They weren't even numbers, just random characters.  On the
same system, DIR works perfectly.

     - Rich



Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive


Quote:

>TP7 simply uses a BIOS call (Int $21, function $36). So, TP7 has
>little to do with the actual code to get the size of a disk. In my
>experience the DiskFree() function does work, and simply limits the
>size to a maximum of 2 MB which is acceptable in most cases.

                      2 GB

--

  Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.



Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive

Quote:

> I compiled and executed the program you provided with BP 7.01 under
> Windows 95, a 500 MB FAT-16 disk.  It printed out several lines of
> garbage.  They weren't even numbers, just random characters.  On the
> same system, DIR works perfectly.

It worked fine under BP 7.0, Windows 95b, both FAT16 (an old 1 GB disk)
and FAT32 (a new 4.3 GB disk). On the latter, DIR sometimes only shows
up
to MaxLongint Bytes.

How can it display characters? Comps hold numeric values...



Wed, 18 Jun 1902 08:00:00 GMT  
 Get free space on a drive

Quote:


> > I compiled and executed the program you provided with BP 7.01 under
> > Windows 95, a 500 MB FAT-16 disk.  It printed out several lines of
> > garbage.  They weren't even numbers, just random characters.  On the
> > same system, DIR works perfectly.

> It worked fine under BP 7.0, Windows 95b, both FAT16 (an old 1 GB disk)
> and FAT32 (a new 4.3 GB disk). On the latter, DIR sometimes only shows
> up
> to MaxLongint Bytes.

> How can it display characters? Comps hold numeric values...

Probably because something in the assembler part messed up the code
which is needed to print comp.

     - Rich



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Free space on network drives

2. Help wanted, space on drive

3. BDE and free disk space

4. Returning wrong free disk space?

5. Deleted records not freeing disk space

6. utility for finding free space!

7. Q Free space on large disks ( > 2GB )

8. Getting drive sizes larger than 2 gigs...

9. Diplay Free Hard Disks' Space On SCSI Hard Drives

10. Diplay Free Hard Disks' Space On SCSI Hard Drives

11. Display Free Hard Disk Size Of SCSI Hard Drive

12. Relation logical drive - physical drive

 

 
Powered by phpBB® Forum Software