Slow response to drive state(DVD,SD) if no disk in drive

Please report only one bug per message!

Moderators: Stefan2, sheep, white, Hacker

User avatar
BORG52
Junior Member
Junior Member
Posts: 24
Joined: 2011-04-23, 16:16 UTC

Slow response to drive state(DVD,SD) if no disk in drive

Post by BORG52 » 2018-06-02, 10:30 UTC

Hello,
If "no disk" in drive - after click to any removable drive icon(DVD,SD), TCMD has very slow response to drive state.(similar as link to network drive)
Windows explorer response is fast.

TCMD use history and trying link to latest(removed) medium inserted to removable drive. Restart TCMD solve problem with (no)linked medium, but this is not optimal solution - response to drive(no medium) state is always slow.
FDD drive(with no floppy) response is OK in TCMD.
TCMD912/XP32

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 35991
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by ghisler(Author) » 2018-06-03, 10:26 UTC

I don't think there is anything I can do. TC uses functions like FindFirstFile or SetCurrentDirectory, and they sometimes have a long timeout. TC should show a wait dialog after about 1 second where you can cancel the operation.
Author of Total Commander
http://www.ghisler.com

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by MarcinW » 2018-06-03, 20:18 UTC

I can confirm the problem.

My DVD drive is E: - when it is empty:

- when I call FindFirst('E:\*.*', ...) - it immediately returns ERROR_NOT_READY

- when I call SetCurrentDirectory('E:') - it immediately fails with ERROR_NOT_READY

- when I select E: in 32-bit or 64-bit TC, mouse cursor is changed to a waiting state and TC is thinking for about 3 seconds before displaying an error message.

Regards

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 35991
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by ghisler(Author) » 2018-06-05, 08:01 UTC

I cannot reproduce your report: When FindFirstFile and/or SetCurrentDirectory is fast, TC is fast too. Tried with two different CD drives, one internal and one connected via USB.
Author of Total Commander
http://www.ghisler.com

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by MarcinW » 2018-06-05, 14:53 UTC

I found the reason: TC assumes a default CDCloseDoor=1 configuration seting. After adding CDCloseDoor=0 to [Configuration] in wincmd.ini, the problem is solved.



For CDCloseDoor=1 setting (Totalcmd.exe, 9.20 Beta 5):

1) at 0x0041C20E, a call is executed: mciSendStringA('open e: type cdaudio alias ding', nil, 0, 0) - this call blocks execution for about 2 seconds

2) at 0x0041C20E, a call is executed: mciSendStringA('set ding door closed wait', nil, 0, 0) - this call blocks execution for about 0.5 second

3) at 0x0041C20E, a call is executed: mciSendStringA('close ding', nil, 0, 0)

4) at 0x0041C2EC, Sleep(500) is executed

5) at 0x0041C431, Sleep(1000) is executed



What is a purpose of these MCI calls?

Regards

User avatar
BORG52
Junior Member
Junior Member
Posts: 24
Joined: 2011-04-23, 16:16 UTC

Post by BORG52 » 2018-06-05, 18:03 UTC

With CDCloseDoor=0 is response the same as windows explorer. This solve problem with "response to drive state"
MarcinW: thank

MCI call: I also noticed it's. I am not programmer, but when testing TCMD in Dependency Walker i found MCI call, when make door closed/open .TCMD sounds are not associated with eject/close-here is no relation.
Here is relation with CD audio. TCMD tests if audioCD inserted and load/unload anytime mcicda.dll. Probably therefore is slow response(?). I mean, that TCMD first check for audioCD,no for data.This should be optimized.

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 35991
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by ghisler(Author) » 2018-06-06, 16:42 UTC

TC calls these to close an open CD drawer, so you can just open the drawer, put the CD/DVD in, and then switch to it in TC without closing the CD drawer manually.
Author of Total Commander
http://www.ghisler.com

User avatar
BORG52
Junior Member
Junior Member
Posts: 24
Joined: 2011-04-23, 16:16 UTC

Post by BORG52 » 2018-06-09, 14:32 UTC

OK, thank for ifo about MCI function in this case.
For me is this function here unnecessary, but in some cases this may be usefull.
Therefore any switch for CDCloseDoor in TCMD config bar is need.

When I have to strain my hand to the DVD mechanic to insert or remove the media, it will make it easier for me to press the button on the mechanics before somewhere to catch something with the mouse. :D

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by MarcinW » 2018-06-09, 20:58 UTC

It seems that the current TC behavior can be made much faster, without any compatibility loss. I'll investigate this and let you know here.

Regards

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 35991
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by ghisler(Author) » 2018-06-11, 13:37 UTC

You can disable it:
wincmd.ini
[Configuration]
CdCloseDoor=0
Author of Total Commander
http://www.ghisler.com

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by MarcinW » 2018-06-11, 14:03 UTC

I found some info here: https://ws0.org/windows-how-to-get-the-tray-status-of-the-optical-drive/

By using DeviceIoControl API with IOCTL_STORAGE_CHECK_VERIFY2 and IOCTL_SCSI_PASS_THROUGH_DIRECT control codes, we can check if:
- tray is ejected,
- tray is closed with some media inside,
- tray is closed with no media inside.

In opposite to MCI calls, IOCTL calls return immediately.


I created a piece of test code by using a sample code from the article mentioned above (I made some corrections though). Curently TC code looks like:

Code: Select all

if CDCloseDoor <> 0 then
  call MCI functions to close the CD tray
This could be improved in the following way:

Code: Select all

if CDCloseDoor <> 0 then
if IsCDTrayEjected&#40;DriveNum&#41; then
  call MCI functions to close the CD tray

Thanks to this change, TC could respond immediately, even for CDCloseDoor=1. The IsCDTrayEjected() function always returns True in case of any errors, so it will not break compatibility. It may even work on Win 9x systems, if the CD driver supports needed IOCTL codes (in other cases just True is returned). The code below has been sucessfully tested on two physical machines with DVD drives, where TC hangs for few seconds when accessing the drive - on Win 98, Win 2000 and Win 7 64-bit (both as 32-bit and 64-bit code).

Code: Select all

program CDTest;

uses
  Windows;

type
  SCSI_PASS_THROUGH_DIRECT = record
    Length &#58; Word;
    ScsiStatus &#58; Byte;
    PathId &#58; Byte;
    TargetId &#58; Byte;
    Lun &#58; Byte;
    CdbLength &#58; Byte;
    SenseInfoLength &#58; Byte;
    DataIn &#58; Byte;
    DataTransferLength &#58; Cardinal;
    TimeOutValue &#58; Cardinal;
    DataBuffer &#58; Pointer;
    SenseInfoOffset &#58; Cardinal;
    Cdb &#58; array&#91;0..15&#93; of Byte;
  end;

const
  IOCTL_STORAGE_CHECK_VERIFY2 = $002D0800;
  IOCTL_SCSI_PASS_THROUGH_DIRECT = $0004D014;

const
  SCSI_IOCTL_DATA_IN = 1;

const
  FILE_SHARE_DELETE = 4;

// DriveNum&#58; 0=A&#58;, 1=B&#58;, 2=C&#58;, ...
function IsCDTrayEjected&#40;DriveNum &#58; Byte&#41; &#58; Boolean;
var
  DeviceName &#58; array&#91;0..6&#93; of WideChar;
  HDevice &#58; THandle;
  BytesReturned &#58; DWORD;
  SCSIBuffer &#58; record
    SPTD &#58; SCSI_PASS_THROUGH_DIRECT;
    SenseBuffer &#58; array&#91;0..17&#93; of Byte;
  end;
  DataBuffer &#58; array&#91;0..7&#93; of Byte;
begin
  Result&#58;=True; // Return True in case of any errors

  DeviceName&#91;0&#93;&#58;='\';
  DeviceName&#91;1&#93;&#58;='\';
  DeviceName&#91;2&#93;&#58;='.';
  DeviceName&#91;3&#93;&#58;='\';
  DeviceName&#91;4&#93;&#58;=WideChar&#40;Ord&#40;'A'&#41;+DriveNum&#41;;
  DeviceName&#91;5&#93;&#58;='&#58;';
  DeviceName&#91;6&#93;&#58;=#0;

  HDevice&#58;=CreateFileW&#40;DeviceName,0,FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0&#41;;
  if HDevice = INVALID_HANDLE_VALUE then
    Exit;
  try
    Result&#58;=not DeviceIoControl&#40;HDevice,IOCTL_STORAGE_CHECK_VERIFY2,nil,0,nil,0,BytesReturned,nil&#41;;
  finally
    CloseHandle&#40;hDevice&#41;;
  end;

  if not Result then // Tray closed, media present
    Exit;

  HDevice&#58;=CreateFileW&#40;DeviceName,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE or FILE_SHARE_DELETE,nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0&#41;;
  if HDevice = INVALID_HANDLE_VALUE then
    Exit;
  try
    FillChar&#40;SCSIBuffer,SizeOf&#40;SCSIBuffer&#41;,0&#41;;
    with SCSIBuffer do
    begin
      SPTD.Length&#58;=SizeOf&#40;SPTD&#41;;
      SPTD.CdbLength&#58;=10;
      SPTD.SenseInfoLength&#58;=SizeOf&#40;SenseBuffer&#41;;
      SPTD.DataIn&#58;=SCSI_IOCTL_DATA_IN;
      SPTD.DataTransferLength&#58;=SizeOf&#40;DataBuffer&#41;;
      SPTD.TimeOutValue&#58;=1;
      SPTD.DataBuffer&#58;=@DataBuffer;
      SPTD.SenseInfoOffset&#58;=HINST&#40;@SenseBuffer&#41;-HINST&#40;@SCSIBuffer&#41;;
      SPTD.Cdb&#91;0&#93;&#58;=$4A;
      SPTD.Cdb&#91;1&#93;&#58;=$01;
      SPTD.Cdb&#91;4&#93;&#58;=$10;
      SPTD.Cdb&#91;8&#93;&#58;=$08;
    end;
    FillChar&#40;DataBuffer,SizeOf&#40;DataBuffer&#41;,0&#41;;

    BytesReturned&#58;=0;
    Result&#58;=DeviceIoControl&#40;HDevice,IOCTL_SCSI_PASS_THROUGH_DIRECT,@SCSIBuffer,SizeOf&#40;SCSIBuffer&#41;,@SCSIBuffer,SizeOf&#40;SCSIBuffer&#41;,BytesReturned,nil&#41;;
  finally
    CloseHandle&#40;hDevice&#41;;
  end;

  if &#40;not Result&#41; or &#40;BytesReturned < SizeOf&#40;SCSIBuffer.SPTD&#41;&#41; then // Error
  begin
    Result&#58;=True;
    Exit;
  end;

  case DataBuffer&#91;5&#93; of
    0  &#58; Result&#58;=False; // Tray closed, no media
    1  &#58; Result&#58;=True;  // Tray ejected
    else Result&#58;=False; // Tray closed, media present
  end;
end;

var
  DriveNum &#58; Byte; // 0=A&#58;, 1=B&#58;, 2=C&#58;, ...
begin
  DriveNum&#58;=0;
  while True do
  begin
    if GetDriveType&#40;PChar&#40;string&#40;Char&#40;Ord&#40;'A'&#41;+DriveNum&#41;&#41;+'&#58;'&#41;&#41; = DRIVE_CDROM then
      Break;
    if DriveNum = 26 then
    begin
      MessageBox&#40;0,'No CD drive found','Error',MB_ICONSTOP&#41;;
      Exit;
    end;
    Inc&#40;DriveNum&#41;;
  end;

  if IsCDTrayEjected&#40;DriveNum&#41; then
    MessageBox&#40;0,'Tray ejected &#40;or error occured&#41;',PChar&#40;'Drive '+Char&#40;Ord&#40;'A'&#41;+DriveNum&#41;+'&#58;'&#41;,MB_ICONINFORMATION&#41;
  else
    MessageBox&#40;0,'Tray closed',PChar&#40;'Drive '+Char&#40;Ord&#40;'A'&#41;+DriveNum&#41;+'&#58;'&#41;,MB_ICONINFORMATION&#41;;
end.
Regards

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 35991
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by ghisler(Author) » 2018-06-11, 14:15 UTC

Unfortunately I have had mixed results with ioctl calls, it really depends on the driver and hardware. I'm using some calls to check whether a medium is in the drive or not when using HideRemovableNoMedia options. But I had to disable this because some users had complete lockups or long delays when this was enabled. The functions I use with CDCloseDoor have worked for many years. I prefer not to change them. The user can just set CdCloseDoor=0 if he doesn't need this function.
Author of Total Commander
http://www.ghisler.com

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by MarcinW » 2018-06-11, 14:19 UTC

Ok, thanks for your explanation.

Maybe it would be good to move this thread to the English forum?

Regards

User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 35991
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Post by ghisler(Author) » 2018-06-11, 14:22 UTC

Or to suggestions?
Author of Total Commander
http://www.ghisler.com

User avatar
MarcinW
Power Member
Power Member
Posts: 852
Joined: 2012-01-23, 15:58 UTC
Location: Poland

Post by MarcinW » 2018-06-11, 14:27 UTC

Well, both places are good, but I suppose that most of the users read just English forum, not the Suggestions forum - so English forum might be a better place to find a solution for a slow CD/DVD response.

Post Reply