disk.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1998 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. var
  25. Drives : byte;
  26. DriveStr : array[0..26] of pchar;
  27. Procedure AddDisk(const path:string);
  28. begin
  29. if not (DriveStr[Drives]=nil) then
  30. FreeMem(DriveStr[Drives],StrLen(DriveStr[Drives])+1);
  31. GetMem(DriveStr[Drives],length(Path)+1);
  32. StrPCopy(DriveStr[Drives],path);
  33. inc(Drives);
  34. if Drives>26 then
  35. Drives:=4;
  36. end;
  37. Function DiskFree(Drive: Byte): Longint;
  38. var
  39. fs : statfs;
  40. Begin
  41. if (not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs) then
  42. Diskfree:=fs.bavail*fs.bsize
  43. else
  44. Diskfree:=-1;
  45. End;
  46. Function DiskSize(Drive: Byte): Longint;
  47. var
  48. fs : statfs;
  49. Begin
  50. if (not (drivestr[Drive]=nil)) and fsstat(StrPas(drivestr[drive]),fs) then
  51. DiskSize:=fs.blocks*fs.bsize
  52. else
  53. DiskSize:=-1;
  54. End;
  55. Function GetCurrentDir : String;
  56. begin
  57. GetDir (0,Result);
  58. end;
  59. Function SetCurrentDir (Const NewDir : String) : Boolean;
  60. begin
  61. ChDir (NewDir);
  62. end;
  63. Function CreateDir (Const NewDir : String) : Boolean;
  64. begin
  65. MkDir (NewDir);
  66. end;
  67. Function RemoveDir (Const Dir : String) : Boolean;
  68. begin
  69. ChDir (Dir);
  70. end;
  71. {
  72. $Log$
  73. Revision 1.1 1998-10-11 13:42:04 michael
  74. + Added disk and directory functions
  75. }