disk.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. {
  13. The Diskfree and Disksize functions need a file on the specified drive, since this
  14. is required for the statfs system call.
  15. These filenames are set in drivestr[0..26], and have been preset to :
  16. 0 - '.' (default drive - hence current dir is ok.)
  17. 1 - '/fd0/.' (floppy drive 1 - should be adapted to local system )
  18. 2 - '/fd1/.' (floppy drive 2 - should be adapted to local system )
  19. 3 - '/' (C: equivalent of dos is the root partition)
  20. 4..26 (can be set by your own applications)
  21. ! Use AddDisk() to Add new drives !
  22. They both return -1 when a failure occurs.
  23. }
  24. Const
  25. FixDriveStr : array[0..3] of pchar=(
  26. '.',
  27. '/fd0/.',
  28. '/fd1/.',
  29. '/.'
  30. );
  31. var
  32. Drives : byte;
  33. DriveStr : array[4..26] of pchar;
  34. Procedure AddDisk(const path:string);
  35. begin
  36. if not (DriveStr[Drives]=nil) then
  37. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  38. GetMem(DriveStr[Drives],length(Path)+1);
  39. StrPCopy(DriveStr[Drives],path);
  40. inc(Drives);
  41. if Drives>26 then
  42. Drives:=4;
  43. end;
  44. Function DiskFree(Drive: Byte): Longint;
  45. var
  46. fs : statfs;
  47. Begin
  48. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  49. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  50. Diskfree:=fs.bavail*fs.bsize
  51. else
  52. Diskfree:=-1;
  53. End;
  54. Function DiskSize(Drive: Byte): Longint;
  55. var
  56. fs : statfs;
  57. Begin
  58. if ((Drive<4) and (not (fixdrivestr[Drive]=nil)) and fsstat(StrPas(fixdrivestr[drive]),fs)) or
  59. ((not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs)) then
  60. DiskSize:=fs.blocks*fs.bsize
  61. else
  62. DiskSize:=-1;
  63. End;
  64. Function GetCurrentDir : String;
  65. begin
  66. GetDir (0,Result);
  67. end;
  68. Function SetCurrentDir (Const NewDir : String) : Boolean;
  69. begin
  70. {$I-}
  71. ChDir(NewDir);
  72. result := (IOResult = 0);
  73. {$I+}
  74. end;
  75. Function CreateDir (Const NewDir : String) : Boolean;
  76. begin
  77. {$I-}
  78. MkDir(NewDir);
  79. result := (IOResult = 0);
  80. {$I+}
  81. end;
  82. Function RemoveDir (Const Dir : String) : Boolean;
  83. begin
  84. {$I-}
  85. RmDir(Dir);
  86. result := (IOResult = 0);
  87. {$I+}
  88. end;
  89. {
  90. $Log$
  91. Revision 1.5 2000-01-07 16:41:40 daniel
  92. * copyright 2000
  93. Revision 1.4 1999/04/26 09:34:32 peter
  94. * fixed diskfree,disksize
  95. * dir functions now return error status instead of true
  96. Revision 1.3 1999/04/26 07:40:40 michael
  97. + Fixed removedir
  98. Revision 1.2 1999/04/08 11:31:00 peter
  99. * removed warnings
  100. Revision 1.1 1998/10/11 13:42:04 michael
  101. + Added disk and directory functions
  102. }