disk.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. {$ASMMODE ATT}
  13. function DiskFree (Drive: byte): int64;
  14. var FI: TFSinfo;
  15. RC: longint;
  16. begin
  17. if (os_mode = osDOS) or (os_mode = osDPMI) then
  18. {Function 36 is not supported in OS/2.}
  19. asm
  20. movb 8(%ebp),%dl
  21. movb $0x36,%ah
  22. call syscall
  23. cmpw $-1,%ax
  24. je .LDISKFREE1
  25. mulw %cx
  26. mulw %bx
  27. shll $16,%edx
  28. movw %ax,%dx
  29. xchgl %edx,%eax
  30. leave
  31. ret
  32. .LDISKFREE1:
  33. cltd
  34. leave
  35. ret
  36. end
  37. else
  38. {In OS/2, we use the filesystem information.}
  39. begin
  40. RC := DosQueryFSInfo (Drive, 1, FI, SizeOf (FI));
  41. if RC = 0 then
  42. DiskFree := int64 (FI.Free_Clusters) *
  43. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  44. else
  45. DiskFree := -1;
  46. end;
  47. end;
  48. function DiskSize (Drive: byte): int64;
  49. var FI: TFSinfo;
  50. RC: longint;
  51. begin
  52. if (os_mode = osDOS) or (os_mode = osDPMI) then
  53. {Function 36 is not supported in OS/2.}
  54. asm
  55. movb 8(%ebp),%dl
  56. movb $0x36,%ah
  57. call syscall
  58. movw %dx,%bx
  59. cmpw $-1,%ax
  60. je .LDISKSIZE1
  61. mulw %cx
  62. mulw %bx
  63. shll $16,%edx
  64. movw %ax,%dx
  65. xchgl %edx,%eax
  66. leave
  67. ret
  68. .LDISKSIZE1:
  69. cltd
  70. leave
  71. ret
  72. end
  73. else
  74. {In OS/2, we use the filesystem information.}
  75. begin
  76. RC := DosQueryFSinfo (Drive, 1, FI, SizeOf (FI));
  77. if RC = 0 then
  78. DiskSize := int64 (FI.Total_Clusters) *
  79. int64 (FI.Sectors_Per_Cluster) * int64 (FI.Bytes_Per_Sector)
  80. else
  81. DiskSize := -1;
  82. end;
  83. end;
  84. function GetCurrentDir: string;
  85. begin
  86. GetDir (0, Result);
  87. end;
  88. function SetCurrentDir (const NewDir: string): boolean;
  89. begin
  90. {$I-}
  91. ChDir (NewDir);
  92. Result := (IOResult = 0);
  93. {$I+}
  94. end;
  95. function CreateDir (const NewDir: string): boolean;
  96. begin
  97. {$I-}
  98. MkDir (NewDir);
  99. Result := (IOResult = 0);
  100. {$I+}
  101. end;
  102. function RemoveDir (const Dir: string): boolean;
  103. begin
  104. {$I-}
  105. RmDir (Dir);
  106. Result := (IOResult = 0);
  107. {$I+}
  108. end;
  109. {
  110. $Log$
  111. Revision 1.3 2000-07-14 10:33:10 michael
  112. + Conditionals fixed
  113. Revision 1.2 2000/07/13 11:33:52 michael
  114. + removed logs
  115. }