cdromlin.inc 2.8 KB

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