Is it safe to remove USB media when a computer is suspended?

7,456

Solution 1

While there are indeed no transfers going on, the reason you do the Safely Remove Hardware dance is not because of the transfers.

You are doing this to cleanly unmount the file system — programs may be still using the drive, and some files may be still unwritten to the disk even after the application using them is closed. This is the same reason why you don’t just hibernate and switch operating systems — a mounted filesystem is never guaranteed to be in a consistent state.

Ever wondered why the OS slows down to a crawl when using floppies? It is because the cache is flushed after the write of each sector, so the floppy can be removed at any time when not in use.

(Still, you will get a dialog and your program will hang if you try to access a floppy that got removed behind your back. Just insert the floppy back and be done. This won’t work with USB drives because they get a different identifier each time — the program will just crash, and the OS may too if a driver was accessing a file)

Solution 2

There are two options in Windows that affect the ability to simply unplug at will. 1) Optimize for fast file writes (technically a lie) by caching on the hard drive before writing to the USB device. 2) optimize for quick removal by ensuring Windows flushes every write to the USB drive immediately.

Back when USB drives were first introduced, you had to use the safely remove hardware feature because the operating system would cache any files you wrote to the hard drive first in order to present a high speed experience. USB 1.0 devices were exceptionally slow. When you click to safely remove hardware the operating system would ensure that it finished copying is local cache to the USB drive before unmounting it.

Web USB 2.0 drives came along they were fast enough to write dukes in nearly real time. Windows preferences changed to default to the USB quick removal option. Since then, if you plug in a USB device and don't manually change the option to cache mode, your drive is already set for quick removal. That means you can take it out as soon as it's stopped writing (light on drive quits flashing).

Share:
7,456

Related videos on Youtube

IQAndreas
Author by

IQAndreas

SOreadytohelp Developer with multiple languages under my belt; primarily ActionScript 3, but also includes PHP, Java, and JavaScript. Just to be clear, I hate JavaScript: it's weakly typed, and its inheritance system is a joke. PHP isn't big on my list either. Yet, since the web uses them, I'm forced to work in them. IQAndreas.com - Main Website blog.iqandreas.com - Programming Blog GitHub.com/IQAndreas - GitHub Account and Repositories @IQAndreas - Twitter

Updated on September 18, 2022

Comments

  • IQAndreas
    IQAndreas almost 2 years

    We are often cautioned against unplugging USB drives in case it is currently being read from or written to. When a computer is suspended, hibernated, or asleep is it obviously not writing any data; it may have been in the middle of a read/write, however, it will have put such an operation on hold.

    Since no arms are moving (for USB hard-drives), or bytes on the drive flickering on and off (for flash drives), is it then "safe" to unplug a drive?

    Is this true even if data is being written to it, but the operation temporarily "suspended"? (assuming you don't mind that specific file only having been half-written to the drive)

  • Ilmari Karonen
    Ilmari Karonen over 10 years
    Desktop computers can generally hibernate just fine, it's just not as commonly used, and the option to do it may be hidden by default.
  • tomasz
    tomasz over 10 years
    People still use floppies!?
  • Marcks Thomas
    Marcks Thomas over 10 years
    "While there are indeed no transfers going on, the reason you do the Safely Remove Hardware dance is not because of the tranfers." Do you have any sources to support this? It contradicts both Windows's description of the Safely Remove Hardware feature and Microsoft's online documentation.
  • kinokijuf
    kinokijuf over 10 years
    Are you serious? I use hibernation on my desktop computer several times a week.
  • kinokijuf
    kinokijuf over 10 years
    If a program has handles to files open on the drive, the next time it tries to write, it will crash if you yanked the drive off.
  • MSalters
    MSalters over 10 years
    @kinokijuf: That would be a bug. Any modern OS will just return an error code to the application, and an application which properly handles error codes will just show an error message to you. "Failed to write H:\thesis.doc" may be a scary message, but it's not a crash.
  • Wyzard
    Wyzard over 10 years
    Citation needed.
  • Canadian Luke
    Canadian Luke over 10 years
    Agreed. This information is false and misleading