cdromlin.inc 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. uses
  2. {$ifdef ver1_0}
  3. linux,
  4. {$else}
  5. baseunix,
  6. unix,
  7. {$endif}
  8. lincd;
  9. Function ReadCDTOC(Device : String; Var CDTOC : Array of TTocEntry) : Integer;
  10. Var
  11. I,Drive : Integer;
  12. tochdr : Tcdrom_tochdr;
  13. tocentry : tcdrom_tocentry;
  14. begin
  15. drive:={$ifdef ver1_0}fdopen{$else}fpOpen{$endif}(Device, Open_RDONLY or Open_NONBLOCK);
  16. if drive<0 then
  17. begin
  18. Result:=-1;
  19. Exit;
  20. end;
  21. {$Ifdef ver1_0}
  22. if not ioctl(drive, CDROMREADTOCHDR, @tochdr) then
  23. {$else}
  24. if fpioctl(drive, CDROMREADTOCHDR, @tochdr)<>0 then
  25. {$endif}
  26. begin
  27. Result:=-1;
  28. Exit;
  29. end;
  30. If (tochdr.cdth_trk1-tochdr.cdth_trk0)>High(CDToc) then
  31. Result:=-2
  32. else
  33. begin
  34. Result:=0;
  35. for i := tochdr.cdth_trk0 to tochdr.cdth_trk1 do
  36. begin
  37. tocentry.cdte_track := i;
  38. tocentry.cdte_format := CDROM_MSF;
  39. {$ifdef ver1_0}ioctl{$else}fpIOCtl{$endif}(drive, CDROMREADTOCENTRY, @tocentry);
  40. // We should do some error checking here actually.
  41. With cdtoc[result] do
  42. begin
  43. min := tocentry.cdte_addr.msf.minute;
  44. sec := tocentry.cdte_addr.msf.second;
  45. frame := tocentry.cdte_addr.msf.frame;
  46. inc(frame,min*60*75);
  47. inc(frame,sec*75);
  48. end;
  49. Inc(result);
  50. end;
  51. tocentry.cdte_track := $AA;
  52. tocentry.cdte_format := CDROM_MSF;
  53. {$ifdef ver1_0}ioctl{$else}fpIOCtl{$endif}(drive, CDROMREADTOCENTRY, @tocentry);
  54. With cdtoc[Result] do
  55. begin
  56. Min := tocentry.cdte_addr.msf.minute;
  57. sec := tocentry.cdte_addr.msf.second;
  58. frame := tocentry.cdte_addr.msf.frame;
  59. inc(frame, min*60*75);
  60. inc(frame, sec*75);
  61. end;
  62. end;
  63. {$ifdef ver1_0}fdclose{$else}fpClose{$endif}(drive);
  64. end;
  65. { ---------------------------------------------------------------------
  66. /etc/fstab scanning.
  67. ---------------------------------------------------------------------}
  68. Function ExtractDevice(S : String) : String;
  69. Var
  70. P,L : Integer;
  71. begin
  72. Result:='';
  73. P:=Pos('#',S);
  74. If P<>0 then
  75. S:=Copy(S,1,P-1);
  76. If Length(S)>0 then
  77. begin
  78. P:=1;
  79. While (P<=Length(S)) and (S[P] in [#9,' ']) do
  80. Inc(p);
  81. L:=P;
  82. While (L<=Length(S)) and (Not (S[L] in [#9,' '])) do
  83. Inc(L);
  84. If L>P then
  85. Result:=Copy(S,P,L-P);
  86. end;
  87. end;
  88. Function TestFSTab(var Devices : Array of String) : Integer;
  89. Var
  90. fstab : text;
  91. Line : String;
  92. begin
  93. Result:=0;
  94. Assign(FSTab,'/etc/fstab');
  95. {$i-}
  96. Reset(fstab);
  97. {$i+}
  98. If IOResult=0 then
  99. begin
  100. While Not EOF(fstab) do
  101. begin
  102. ReadLn(fsTab,Line);
  103. Line:=ExtractDevice(Line);
  104. If IsCdDevice(Line) and (Result<=High(Devices)) then
  105. begin
  106. Devices[Result]:=Line;
  107. inc(Result);
  108. end;
  109. end;
  110. Close(fstab);
  111. end
  112. else
  113. Result:=-1;
  114. end;
  115. Function GetCDRomDevices(Var Devices : Array of string) : Integer;
  116. Var
  117. S : String;
  118. begin
  119. Result:=TestFSTab(Devices);
  120. If (Result<1) then
  121. begin
  122. S:=DetectCD;
  123. If (S<>'') then
  124. begin
  125. Devices[0]:=S;
  126. Result:=1;
  127. end;
  128. end
  129. end;