This is the mail archive of the
mailing list for the Cygwin project.
Re: Ejecting a USB drive using Cygwin (sync)?
- From: Brian Inglis <Brian dot Inglis at SystematicSw dot ab dot ca>
- To: cygwin at cygwin dot com
- Date: Tue, 23 Jan 2018 14:13:24 -0700
- Subject: Re: Ejecting a USB drive using Cygwin (sync)?
- Authentication-results: sourceware.org; auth=none
- References: <1516706057.3270332.1245015392.5FE803A3@webmail.messagingengine.com>
- Reply-to: Brian dot Inglis at SystematicSw dot ab dot ca
On 2018-01-23 04:14, Ronald Fischer wrote:
> I'm looking for a command, which would allow me from a shell script to
> prepare the removal of a USB device (stick, external hard drive etc.). With
> other words, after issuing the command, I should be able to physically remove
> the USB device.
> Can the `sync` command be used, for instance
> sync -f /cygdrive/e
> assuming that the USB device is on drive E:? The man page of *sync* is a bit
> vague in this respect. Or is there another Cygwin command which can be used
> for this purpose?
Running sync as above, and umount are always advisable.
Some ejection utilities detach the device, leaving it unusable until the device
is attached by forcing enumeration, or the system restarted.
I found the following utility works well without elevation - Windows code from
// eject -- Allow safe removal of USB thumb drive.
// - Command line tool to flush/dismount/eject USB drive.
// - Simpler than mouse clicking through taskbar "Safely Remove Hardware" icon.
// - Usable in batch file scripts.
// 02-Nov-2012 Tom Van Baak (tvb) www.LeapSecond.com/tools
// Per MSDN, follow procedure for safe removal of USB drive.
int drive_eject (char *drive)
// Convert vintage DOS drive letter to weird Windows object pathname.
sprintf(path, "\\\\.\\%s", drive);
// Open (with write, but no lock) to flush pending writes.
DEV_OPEN(path, GENERIC_READ | GENERIC_WRITE);
// Open (with read, and lock) to dismount and eject.
Cygwin does not appear to use ioctls that perform the same Windows functions
except for floppy lock volume.
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada
Problem reports: http://cygwin.com/problems.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple