Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forced disk unmount causes hung drive handle in Windows 10 #75

Closed
calston opened this issue May 28, 2020 · 8 comments
Closed

Forced disk unmount causes hung drive handle in Windows 10 #75

calston opened this issue May 28, 2020 · 8 comments

Comments

@calston
Copy link

calston commented May 28, 2020

Not sure what extra information to provide but when the disk is automatically i mounted after writing in Windows 10, the drive letter handle isn’t removed. Re-connecting the USB card reader does recognize the drive but future ejects no longer work properly.

I tested this with two different SD card readers and had the same experience. The automatic ejection should probably have some toggle for if you want to edit files afterwards or whatever mechanism is being used does not seem to be safe. A sync could be triggered rather than an automatic ejection or whatever mechanism Rufus uses because that works fine for me

@lurch
Copy link
Contributor

lurch commented May 28, 2020

I wonder if this might be the same thing as #31 ?

@calston
Copy link
Author

calston commented May 28, 2020

Sounds like it could be, except the only way I found to recover from the situation is a reboot.

@calston
Copy link
Author

calston commented Jun 27, 2020

This does seem to work now in 1.3, I have no idea if anything changed.

I still think it would be better to make ejecting after write optional and letting people do this on their own terms.

@calston calston closed this as completed Jun 27, 2020
@calston
Copy link
Author

calston commented Jun 28, 2020

Actually, no. I'm still getting strange after effects of the forced ejection. Again I have a device letter that won't un-map from the drive. Usually it just took a few seconds for Explorer to refresh the drive list, but again on ejection the drive letter remains at least until the physical device is removed - but this makes it impossible to know if the ejection was successful.

This is a known issue in the mountutils library used balena-io-modules/mountutils#74

@calston calston reopened this Jun 28, 2020
@maxnet
Copy link
Collaborator

maxnet commented Jul 2, 2020

Usually it just took a few seconds for Explorer

You did close Imager completely before starting explorer?
(while Imager is running we stop the ShellHWDetection Windows service, as it causes popups to appear on screen in which Windows offers the user to format the ext4 partition. Could be Explorer does like to have that service running.)

Could also be that something is still accessing the drive preventing proper unmount, like a virus scanner or the Windows indexer stuff (can run "net stop wsearch" from an admin command prompt before starting imager to see if the last one may be the problem).

@calston
Copy link
Author

calston commented Jul 3, 2020

Since the issue persists long after raspberry pi imager is closed I doubt that's the issue. Explorer is the shell too, so having such a requirement to use this seems impractical, as is disabling search indexing to use it.

That said, looking at the code it appears although the ShellHWDetection service is stopped during a write, it is not started again in the same class instantiation. This could be a mistake.

@maxnet
Copy link
Collaborator

maxnet commented Jul 3, 2020

That said, looking at the code it appears although the ShellHWDetection service is stopped during a write, it is not started again
in the same class instantiation.

It is started again in the class destructor.
Which will get invoked when you close Imager:

rpi-imager/imagewriter.cpp

Lines 100 to 104 in 755d7dc

ImageWriter::~ImageWriter()
{
#ifdef Q_OS_WIN
QProcess *p = new QProcess(this);
p->startDetached("net start ShellHWDetection");

Issue itself is not reproducible to me, so could be timing or other software specific.
I may have a look at what other service we may need to shutdown just during write. Right now it does create a "system volume information" folder on the card for me, which is an indication other services running do are still accessing the SD card and writing to it.

maxnet added a commit that referenced this issue Jul 3, 2020
The moment we write the block containing the partition table
Windows services will start accessing the SD card and write data
to "System volume information" folder.

If others are writing to disk concurrently this may or may not
affect our ability to eject the drive.
Stop StorSvc temporarily between us writing the partition table
(saved for last) and ejecting the SD card, just in case.

Ref #75
@tdewey-rpi
Copy link
Collaborator

Closing as stale. Please raise a new issue if you think this still applies.

@tdewey-rpi tdewey-rpi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants