123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 |
- {
- $Id$
- This file is part of the Free Pascal run time library.
- Copyright (c) 1999-2000 by the Free Pascal development team
- Disk functions from Delphi's sysutils.pas
- See the file COPYING.FPC, included in this distribution,
- for details about the copyright.
- This program 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.
- **********************************************************************}
- {$ifdef Int64}
- TYPE ExtendedFat32FreeSpaceRec=packed Record
- RetSize : WORD; { (ret) size of returned structure}
- Strucversion : WORD; {(call) structure version (0000h)
- (ret) actual structure version (0000h)}
- SecPerClus, {number of sectors per cluster}
- BytePerSec, {number of bytes per sector}
- AvailClusters, {number of available clusters}
- TotalClusters, {total number of clusters on the drive}
- AvailPhysSect, {physical sectors available on the drive}
- TotalPhysSect, {total physical sectors on the drive}
- AvailAllocUnits, {Available allocation units}
- TotalAllocUnits : DWORD; {Total allocation units}
- Dummy,Dummy2 : DWORD; {8 bytes reserved}
- END;
- function do_diskdata(drive : byte; Free : BOOLEAN) : Int64;
- VAR S : String;
- Rec : ExtendedFat32FreeSpaceRec;
- regs : registers;
- BEGIN
- if (swap(dosversion)>=$070A) AND LFNSupport then
- begin
- DosError:=0;
- S:='C:\'#0;
- if Drive=0 then
- begin
- GetDir(Drive,S);
- Setlength(S,4);
- S[4]:=#0;
- end
- else
- S[1]:=chr(Drive+64);
- Rec.Strucversion:=0;
- dosmemput(tb_segment,tb_offset,Rec,SIZEOF(ExtendedFat32FreeSpaceRec));
- dosmemput(tb_segment,tb_offset+Sizeof(ExtendedFat32FreeSpaceRec)+1,S[1],4);
- regs.dx:=tb_offset+Sizeof(ExtendedFat32FreeSpaceRec)+1;
- regs.ds:=tb_segment;
- regs.di:=tb_offset;
- regs.es:=tb_segment;
- regs.cx:=Sizeof(ExtendedFat32FreeSpaceRec);
- regs.ax:=$7303;
- msdos(regs);
- if regs.ax<>$ffff then
- begin
- copyfromdos(rec,Sizeof(ExtendedFat32FreeSpaceRec));
- if Free then
- Do_DiskData:=int64(rec.AvailAllocUnits)*rec.SecPerClus*rec.BytePerSec
- else
- Do_DiskData:=int64(rec.TotalAllocUnits)*rec.SecPerClus*rec.BytePerSec;
- end
- else
- Do_DiskData:=-1;
- end
- else
- begin
- DosError:=0;
- regs.dl:=drive;
- regs.ah:=$36;
- msdos(regs);
- if regs.ax<>$FFFF then
- begin
- if Free then
- Do_DiskData:=int64(regs.ax)*regs.bx*regs.cx
- else
- Do_DiskData:=int64(regs.ax)*regs.cx*regs.dx;
- end
- else
- do_diskdata:=-1;
- end;
- end;
- function diskfree(drive : byte) : int64;
- begin
- diskfree:=Do_DiskData(drive,TRUE);
- end;
- function disksize(drive : byte) : int64;
- begin
- disksize:=Do_DiskData(drive,false);
- end;
- {$else}
- Function DiskFree (Drive : Byte) : Longint;
- var
- Regs: Registers;
- begin
- Regs.Dl := Drive;
- Regs.Ah := $36;
- intr($21, Regs);
- if Regs.Ax <> $FFFF then
- result := Regs.Ax * Regs.Bx * Regs.Cx
- else
- result := -1;
- end;
- Function DiskSize (Drive : Byte) : Longint;
- var
- Regs: Registers;
- begin
- Regs.Dl := Drive;
- Regs.Ah := $36;
- Intr($21, Regs);
- if Regs.Ax <> $FFFF then
- result := Regs.Ax * Regs.Cx * Regs.Dx
- else
- result := -1;
- end;
- {$endif}
- Function GetCurrentDir : String;
- begin
- GetDir(0, result);
- end;
- Function SetCurrentDir (Const NewDir : String) : Boolean;
- begin
- {$I-}
- ChDir(NewDir);
- result := (IOResult = 0);
- {$I+}
- end;
- Function CreateDir (Const NewDir : String) : Boolean;
- begin
- {$I-}
- MkDir(NewDir);
- result := (IOResult = 0);
- {$I+}
- end;
- Function RemoveDir (Const Dir : String) : Boolean;
- begin
- {$I-}
- RmDir(Dir);
- result := (IOResult = 0);
- {$I+}
- end;
- {
- $Log$
- Revision 1.1 2000-07-13 06:30:35 michael
- + Initial import
- Revision 1.5 2000/05/15 19:28:41 peter
- * int64 support for diskfree,disksize
- Revision 1.4 2000/02/09 16:59:28 peter
- * truncated log
- Revision 1.3 2000/01/07 16:41:30 daniel
- * copyright 2000
- }
|