disk.inc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team
  5. Disk functions from Delphi's sysutils.pas
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {$ifdef Int64}
  13. TYPE ExtendedFat32FreeSpaceRec=packed Record
  14. RetSize : WORD; { (ret) size of returned structure}
  15. Strucversion : WORD; {(call) structure version (0000h)
  16. (ret) actual structure version (0000h)}
  17. SecPerClus, {number of sectors per cluster}
  18. BytePerSec, {number of bytes per sector}
  19. AvailClusters, {number of available clusters}
  20. TotalClusters, {total number of clusters on the drive}
  21. AvailPhysSect, {physical sectors available on the drive}
  22. TotalPhysSect, {total physical sectors on the drive}
  23. AvailAllocUnits, {Available allocation units}
  24. TotalAllocUnits : DWORD; {Total allocation units}
  25. Dummy,Dummy2 : DWORD; {8 bytes reserved}
  26. END;
  27. function do_diskdata(drive : byte; Free : BOOLEAN) : Int64;
  28. VAR S : String;
  29. Rec : ExtendedFat32FreeSpaceRec;
  30. regs : registers;
  31. BEGIN
  32. if (swap(dosversion)>=$070A) AND LFNSupport then
  33. begin
  34. DosError:=0;
  35. S:='C:\'#0;
  36. if Drive=0 then
  37. begin
  38. GetDir(Drive,S);
  39. Setlength(S,4);
  40. S[4]:=#0;
  41. end
  42. else
  43. S[1]:=chr(Drive+64);
  44. Rec.Strucversion:=0;
  45. dosmemput(tb_segment,tb_offset,Rec,SIZEOF(ExtendedFat32FreeSpaceRec));
  46. dosmemput(tb_segment,tb_offset+Sizeof(ExtendedFat32FreeSpaceRec)+1,S[1],4);
  47. regs.dx:=tb_offset+Sizeof(ExtendedFat32FreeSpaceRec)+1;
  48. regs.ds:=tb_segment;
  49. regs.di:=tb_offset;
  50. regs.es:=tb_segment;
  51. regs.cx:=Sizeof(ExtendedFat32FreeSpaceRec);
  52. regs.ax:=$7303;
  53. msdos(regs);
  54. if regs.ax<>$ffff then
  55. begin
  56. copyfromdos(rec,Sizeof(ExtendedFat32FreeSpaceRec));
  57. if Free then
  58. Do_DiskData:=int64(rec.AvailAllocUnits)*rec.SecPerClus*rec.BytePerSec
  59. else
  60. Do_DiskData:=int64(rec.TotalAllocUnits)*rec.SecPerClus*rec.BytePerSec;
  61. end
  62. else
  63. Do_DiskData:=-1;
  64. end
  65. else
  66. begin
  67. DosError:=0;
  68. regs.dl:=drive;
  69. regs.ah:=$36;
  70. msdos(regs);
  71. if regs.ax<>$FFFF then
  72. begin
  73. if Free then
  74. Do_DiskData:=int64(regs.ax)*regs.bx*regs.cx
  75. else
  76. Do_DiskData:=int64(regs.ax)*regs.cx*regs.dx;
  77. end
  78. else
  79. do_diskdata:=-1;
  80. end;
  81. end;
  82. function diskfree(drive : byte) : int64;
  83. begin
  84. diskfree:=Do_DiskData(drive,TRUE);
  85. end;
  86. function disksize(drive : byte) : int64;
  87. begin
  88. disksize:=Do_DiskData(drive,false);
  89. end;
  90. {$else}
  91. Function DiskFree (Drive : Byte) : Longint;
  92. var
  93. Regs: Registers;
  94. begin
  95. Regs.Dl := Drive;
  96. Regs.Ah := $36;
  97. intr($21, Regs);
  98. if Regs.Ax <> $FFFF then
  99. result := Regs.Ax * Regs.Bx * Regs.Cx
  100. else
  101. result := -1;
  102. end;
  103. Function DiskSize (Drive : Byte) : Longint;
  104. var
  105. Regs: Registers;
  106. begin
  107. Regs.Dl := Drive;
  108. Regs.Ah := $36;
  109. Intr($21, Regs);
  110. if Regs.Ax <> $FFFF then
  111. result := Regs.Ax * Regs.Cx * Regs.Dx
  112. else
  113. result := -1;
  114. end;
  115. {$endif}
  116. Function GetCurrentDir : String;
  117. begin
  118. GetDir(0, result);
  119. end;
  120. Function SetCurrentDir (Const NewDir : String) : Boolean;
  121. begin
  122. {$I-}
  123. ChDir(NewDir);
  124. result := (IOResult = 0);
  125. {$I+}
  126. end;
  127. Function CreateDir (Const NewDir : String) : Boolean;
  128. begin
  129. {$I-}
  130. MkDir(NewDir);
  131. result := (IOResult = 0);
  132. {$I+}
  133. end;
  134. Function RemoveDir (Const Dir : String) : Boolean;
  135. begin
  136. {$I-}
  137. RmDir(Dir);
  138. result := (IOResult = 0);
  139. {$I+}
  140. end;
  141. {
  142. $Log$
  143. Revision 1.1 2000-07-13 06:30:35 michael
  144. + Initial import
  145. Revision 1.5 2000/05/15 19:28:41 peter
  146. * int64 support for diskfree,disksize
  147. Revision 1.4 2000/02/09 16:59:28 peter
  148. * truncated log
  149. Revision 1.3 2000/01/07 16:41:30 daniel
  150. * copyright 2000
  151. }