* Ejecting a USB drive using Cygwin (sync)? @ 2018-01-23 11:14 Ronald Fischer 2018-01-23 15:41 ` Nem W Schlecht ` (2 more replies) 0 siblings, 3 replies; 11+ messages in thread From: Ronald Fischer @ 2018-01-23 11:14 UTC (permalink / raw) To: cygwin 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? Ronald -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-23 11:14 Ejecting a USB drive using Cygwin (sync)? Ronald Fischer @ 2018-01-23 15:41 ` Nem W Schlecht 2018-01-23 18:50 ` Andrey Repin 2018-01-23 21:13 ` Brian Inglis 2 siblings, 0 replies; 11+ messages in thread From: Nem W Schlecht @ 2018-01-23 15:41 UTC (permalink / raw) To: The Cygwin Mailing List On Tue, Jan 23, 2018 at 5:14 AM, Ronald Fischer <ynnor@mm.st> 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 > sync is not quite what you want to do the eject (wouldn't hurt to do so beforehand, but any good 'eject' program will do a sync for you). There are several solutions listed here: https://superuser.com/questions/443162/remove-usb-device-from-command-line RemoveDrive and devcon look like the best bets for what you're looking for. -- Nem W Schlecht "Perl did the magic. I just waved the wand." -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-23 11:14 Ejecting a USB drive using Cygwin (sync)? Ronald Fischer 2018-01-23 15:41 ` Nem W Schlecht @ 2018-01-23 18:50 ` Andrey Repin 2018-01-23 21:13 ` Brian Inglis 2 siblings, 0 replies; 11+ messages in thread From: Andrey Repin @ 2018-01-23 18:50 UTC (permalink / raw) To: Ronald Fischer, cygwin Greetings, Ronald Fischer! > 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.). Windows device disconnect option syncs the device. Just find a tool that plays right. > 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? There's no "eject" implementation, to my knowledge. Also, please keep in mind that ejecting drive vs. detaching a device is a distinctive operation. I.e. detaching a multi-mode card reader may leave system unable to access newly inserted cards. -- With best regards, Andrey Repin Tuesday, January 23, 2018 21:33:21 Sorry for my terrible english... -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-23 11:14 Ejecting a USB drive using Cygwin (sync)? Ronald Fischer 2018-01-23 15:41 ` Nem W Schlecht 2018-01-23 18:50 ` Andrey Repin @ 2018-01-23 21:13 ` Brian Inglis 2018-01-23 23:36 ` Steven Penny 2 siblings, 1 reply; 11+ messages in thread From: Brian Inglis @ 2018-01-23 21:13 UTC (permalink / raw) To: cygwin 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 http://www.leapsecond.com/tools/eject.{c,exe}: // 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) { HANDLE hDev; // Convert vintage DOS drive letter to weird Windows object pathname. char path[10]; sprintf(path, "\\\\.\\%s", drive); // Open (with write, but no lock) to flush pending writes. DEV_OPEN(path, GENERIC_READ | GENERIC_WRITE); FlushFileBuffers(hDev); CloseHandle(hDev); // Open (with read, and lock) to dismount and eject. DEV_OPEN(path, GENERIC_READ); DEV_IOCTL(FSCTL_LOCK_VOLUME); DEV_IOCTL(FSCTL_DISMOUNT_VOLUME); DEV_IOCTL(IOCTL_STORAGE_EJECT_MEDIA); DEV_IOCTL(FSCTL_UNLOCK_VOLUME); CloseHandle(hDev); return 0; } 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 FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-23 21:13 ` Brian Inglis @ 2018-01-23 23:36 ` Steven Penny 2018-01-25 3:02 ` Brian Inglis 2018-01-25 12:45 ` Marco Atzeri 0 siblings, 2 replies; 11+ messages in thread From: Steven Penny @ 2018-01-23 23:36 UTC (permalink / raw) To: cygwin On Tue, 23 Jan 2018 14:13:24, Brian Inglis wrote: > I found the following utility works well without elevation - Windows code from > http://www.leapsecond.com/tools/eject.{c,exe}: > > // 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) > { > HANDLE hDev; > // Convert vintage DOS drive letter to weird Windows object pathname. > char path[10]; > sprintf(path, "\\\\.\\%s", drive); > // Open (with write, but no lock) to flush pending writes. > DEV_OPEN(path, GENERIC_READ | GENERIC_WRITE); > FlushFileBuffers(hDev); > CloseHandle(hDev); > // Open (with read, and lock) to dismount and eject. > DEV_OPEN(path, GENERIC_READ); > DEV_IOCTL(FSCTL_LOCK_VOLUME); > DEV_IOCTL(FSCTL_DISMOUNT_VOLUME); > DEV_IOCTL(IOCTL_STORAGE_EJECT_MEDIA); > DEV_IOCTL(FSCTL_UNLOCK_VOLUME); > CloseHandle(hDev); > return 0; > } No, this is not the code from that site. The code is similar, but I see you have at least removed some empty lines. If you are going to do so, you need to clearly present said changes to the community - something like "adapted from http://..." or "modified from http://...", etc. Software copyright - even open source license is serious, and you should give it due respect. -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-23 23:36 ` Steven Penny @ 2018-01-25 3:02 ` Brian Inglis 2018-01-25 9:58 ` David Allsopp 2018-01-25 12:45 ` Marco Atzeri 1 sibling, 1 reply; 11+ messages in thread From: Brian Inglis @ 2018-01-25 3:02 UTC (permalink / raw) To: cygwin On 2018-01-23 16:36, Steven Penny wrote: > On Tue, 23 Jan 2018 14:13:24, Brian Inglis wrote: >> I found the following utility works well without elevation - Windows code from >> http://www.leapsecond.com/tools/eject.{c,exe}: >> >> // 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) >> { >> Â Â Â HANDLE hDev; >> Â Â Â // Convert vintage DOS drive letter to weird Windows object pathname. >> Â Â Â char path[10]; >> Â Â Â sprintf(path, "\\\\.\\%s", drive); >> Â Â Â // Open (with write, but no lock) to flush pending writes. >> Â Â Â DEV_OPEN(path, GENERIC_READ | GENERIC_WRITE); >> Â Â Â FlushFileBuffers(hDev); >> Â Â Â CloseHandle(hDev); >> Â Â Â // Open (with read, and lock) to dismount and eject. >> Â Â Â DEV_OPEN(path, GENERIC_READ); >> Â Â Â DEV_IOCTL(FSCTL_LOCK_VOLUME); >> Â Â Â DEV_IOCTL(FSCTL_DISMOUNT_VOLUME); >> Â Â Â DEV_IOCTL(IOCTL_STORAGE_EJECT_MEDIA); >> Â Â Â DEV_IOCTL(FSCTL_UNLOCK_VOLUME); >> Â Â Â CloseHandle(hDev); >> Â Â Â return 0; >> } > > No, this is not the code from that site. The code is similar, but I see you have > at least removed some empty lines. If you are going to do so, you need to > clearly present said changes to the community - something like "adapted from > http://..." or "modified from http://...", etc. > > Software copyright - even open source license is serious, and you should give it > due respect. I was providing information, that's why I said /from/, gave the link to the original, and included the copyright, which does not include a link to the MSDN article it mentions: checking any licences are left as an exercise for any reader who wants to make use of the program or code other than for their own private use. What do you mean by "/even/ open source licence"?! You sound like the early Bill Gates ;^> -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* RE: Ejecting a USB drive using Cygwin (sync)? 2018-01-25 3:02 ` Brian Inglis @ 2018-01-25 9:58 ` David Allsopp 2018-01-25 20:37 ` Brian Inglis 0 siblings, 1 reply; 11+ messages in thread From: David Allsopp @ 2018-01-25 9:58 UTC (permalink / raw) To: cygwin Brian Inglis wrote: > On 2018-01-23 16:36, Steven Penny wrote: > > On Tue, 23 Jan 2018 14:13:24, Brian Inglis wrote: > >> I found the following utility works well without elevation - Windows > >> code from > >> http://www.leapsecond.com/tools/eject.{c,exe}: > >> > >> // 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) > >> { > >> HANDLE hDev; > >> // Convert vintage DOS drive letter to weird Windows object > >> pathname. > >> char path[10]; > >> sprintf(path, "\\\\.\\%s", drive); > >> // Open (with write, but no lock) to flush pending writes. > >> DEV_OPEN(path, GENERIC_READ | GENERIC_WRITE); > >> FlushFileBuffers(hDev); > >> CloseHandle(hDev); > >> // Open (with read, and lock) to dismount and eject. > >> DEV_OPEN(path, GENERIC_READ); > >> DEV_IOCTL(FSCTL_LOCK_VOLUME); > >> DEV_IOCTL(FSCTL_DISMOUNT_VOLUME); > >> DEV_IOCTL(IOCTL_STORAGE_EJECT_MEDIA); > >> DEV_IOCTL(FSCTL_UNLOCK_VOLUME); > >> CloseHandle(hDev); > >> return 0; > >> } > > > > No, this is not the code from that site. The code is similar, but I > > see you have at least removed some empty lines. If you are going to do > > so, you need to clearly present said changes to the community - > > something like "adapted from http://..." or "modified from http://...", > > etc. > > > > Software copyright - even open source license is serious, and you > > should give it due respect. > > I was providing information, that's why I said /from/, gave the link to > the original, and included the copyright, which does not include a link > to the MSDN article it mentions: I expect it's referring to this article: https://support.microsoft.com/en-us/help/165721. There's another quite good article on it at https://www.codeproject.com/Articles/259577/How-to-flush-a-storage-volumes-t he-file-cache-lock > checking any licences are left as an > exercise for any reader who wants to make use of the program or code > other than for their own private use. What licence is the ellipsis you added to the copyright line released under? ;o) --dra -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-25 9:58 ` David Allsopp @ 2018-01-25 20:37 ` Brian Inglis 2018-01-25 21:43 ` Doug Henderson 0 siblings, 1 reply; 11+ messages in thread From: Brian Inglis @ 2018-01-25 20:37 UTC (permalink / raw) To: cygwin On 2018-01-25 02:58, David Allsopp wrote: > What licence is the ellipsis you added to the copyright line released under? > ;o) Probably sourceware.org DWTFYW from link obfuscation ;^> -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-25 20:37 ` Brian Inglis @ 2018-01-25 21:43 ` Doug Henderson 2018-01-26 1:31 ` Brian Inglis 0 siblings, 1 reply; 11+ messages in thread From: Doug Henderson @ 2018-01-25 21:43 UTC (permalink / raw) To: cygwin On 25 January 2018 at 13:37, Brian Inglis <Brian.Inglis@systematicsw.ab.ca> wrote: > > On 2018-01-25 02:58, David Allsopp wrote: > > > What licence is the ellipsis you added to the copyright line released under? > > ;o) > > Probably sourceware.org DWTFYW from link obfuscation ;^> > If you compare the content of the referenced source file [ http://www.leapsecond.com/tools/eject.c ] and the snippet from the OP, it is clear that the ellipsis indicates that several lines from the original source were removed. It would have been clearer to have the ellipsis on a new line. There was no copyright claim in the original source. HTH Doug -- Doug Henderson, Calgary, Alberta, Canada - from gmail.com -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-25 21:43 ` Doug Henderson @ 2018-01-26 1:31 ` Brian Inglis 0 siblings, 0 replies; 11+ messages in thread From: Brian Inglis @ 2018-01-26 1:31 UTC (permalink / raw) To: cygwin On 2018-01-25 14:42, Doug Henderson wrote: > On 25 January 2018 at 13:37, Brian Inglis > <Brian.Inglis@systematicsw.ab.ca> wrote: >> On 2018-01-25 02:58, David Allsopp wrote: >>> What licence is the ellipsis you added to the copyright line released >>> under? ;o) >> Probably sourceware.org DWTFYW from link obfuscation ;^> > If you compare the content of the referenced source file > [ http://www.leapsecond.com/tools/eject.c ] > and the snippet from the OP, it is clear that the ellipsis indicates that > several lines from the original source were removed. It would have been > clearer to have the ellipsis on a new line. There was no copyright claim in > the original source. In my OP on Tue and most subsequent responses on Wed, the ellipsis is clearly on a separate line. Some later replies seem to have warped^Wwrapped it up on to the previous line. There is a date, name, and link, so when I make fair use of a quote I include available credit, as publication establishes a copyright, regardless of any claim. IANAL but neither has anyone posting about this topic claimed to be. When that author TVB refers to his tools code, he sometimes uses the term free, and I would consider that as a scientist, he expects his content would be treated as public domain research tools and results, and credit be given. As for removing blank lines, I mostly trim (and often rewrap) content, as some lists require that. -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Ejecting a USB drive using Cygwin (sync)? 2018-01-23 23:36 ` Steven Penny 2018-01-25 3:02 ` Brian Inglis @ 2018-01-25 12:45 ` Marco Atzeri 1 sibling, 0 replies; 11+ messages in thread From: Marco Atzeri @ 2018-01-25 12:45 UTC (permalink / raw) To: cygwin On 24/01/2018 07:36, Steven Penny wrote: > On Tue, 23 Jan 2018 14:13:24, Brian Inglis wrote: >> I found the following utility works well without elevation - Windows >> code from >> http://www.leapsecond.com/tools/eject.{c,exe}: the original code location is reported >> >> // 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 >> ... The proper copyright is reported, the "..." are clearly showing an extract posted in line. >> // Per MSDN, follow procedure for safe removal of USB drive. > > No, this is not the code from that site. The code is similar, but I see > you have > at least removed some empty lines. If you are going to do so, you need to > clearly present said changes to the community - something like "adapted > from > http://..." or "modified from http://...", etc. > > Software copyright - even open source license is serious, and you should > give it > due respect. > he was not providing a full functional code, not claiming ownership, just highlighting the key calls. It seems to me that you are barking to the wrong tree. Marco -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2018-01-26 1:31 UTC | newest] Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-01-23 11:14 Ejecting a USB drive using Cygwin (sync)? Ronald Fischer 2018-01-23 15:41 ` Nem W Schlecht 2018-01-23 18:50 ` Andrey Repin 2018-01-23 21:13 ` Brian Inglis 2018-01-23 23:36 ` Steven Penny 2018-01-25 3:02 ` Brian Inglis 2018-01-25 9:58 ` David Allsopp 2018-01-25 20:37 ` Brian Inglis 2018-01-25 21:43 ` Doug Henderson 2018-01-26 1:31 ` Brian Inglis 2018-01-25 12:45 ` Marco Atzeri
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).