Does Safely Ejecting From A USB Port Actually Do Anything?

Does Safely Ejecting From a USB Port Actually Do Anything?

Is there any harm to be incurred by just pulling a flash drive out? Why do we need safe removal at all?

Historically, Operating Systems treat disks as objects that can be trusted not to change state suddenly. When reading or writing files, the OS expects the files to remain accessible and not suddenly disappear in mid-read or mid-write.

If a file is open, a program reading the file expects to be able to return to it and continue reading. Similarly, write commands may be dispatched to a writing subroutine and forgotten by the main program. If a drive disappears between the time the subroutine is called and the data is written to disk, that data is lost forever.

In ye olde days, there were formal processes to physically "mount" and "unmount" storage media, and the physical act of mounting a tape or a disk pack triggered some mechanical switch to detect the presence or absence of media. Once the mechanism was engaged, the software could start to use the media (a "soft mount."). Some media even had mechanical interlock to prevent media from being ejected or removed until the software processes using the media released the lock.

The Macintosh floppy and optical disk provide more modern examples of an interlocked physical and soft mount. One could only eject media through a software command, but that command might fail if some program was holding a file open on the medium. Enter USB connected storage. There is no mechanical interlock in a USB connection to coordinate the hard and soft mount. The user can decide to rip the disk out from under the operating system at any time, and endure all manner of programs freaking out about the sudden loss of media. "Hey! I was using that!"

Symptoms could include: Lost data, corrupted filesystems, crashing programs, or hanging computers requiring a reboot. A safe removal executes the "soft unmount" needed to prevent any unexpected Bad Things that may happen if a program loses its access to media.

A safe removal does a few things:

  • It flushes all active writes to disk.
  • It alerts all programs (that know how to be alerted) that the disk is going away, and to take appropriate action.
  • It alerts the user when programs have failed to take action, and still are holding files open.

You can remove a disk at any time, but you are at the mercy of how well programs using the disk cope with the sudden disappearance of that disk.

In the modern computer, many steps have been taken to defend against the capricious and careless removal of media. For example, Windows even introduced a feature called "Optimise for Quick Removal" that makes sure data is written quickly instead of batched up and written efficiently. It is very hard to get people to change habits. If you are doing exclusively reads on a media, safe removal is probably not needed. If you are doing writes, you are probably OK to skip safe removal if you haven't written recently and you aren't doing something silly like indexing that disk.

As a good friend of mine once said: Life is too short to safely eject the disk.

However, Safe Removal does a number of important things and is, in fact, the only assuredly safe way to remove a disk. You probably don't need it most of the time, but it is a good habit to have since data loss sucks.

About the author: Phillip Remaker, connected since 1986

Does safely ejecting from a USB port actually do anything? originally appeared on Quora. You can follow Quora on Twitter, Facebook, and Google+.


Comments

    Yes it does... As anyone who's corrupted an open file on a USB stick will attest to.

      +1 I have experienced lost data as a result of an ejected USB disk.

      Long story short, I had to ask for a file restore at work on 8Gb of data (maybe more, it was a long time ago, I forget) and get approval to have those files restored so I could copy them to another USB.

      This whole ejecting USB thing also applies to portable hard drives, where the risk of losing data or even your whole disk is much greater.

      It's not always easy to recover the files either, especially if the files are large (multi-gigabytes)

      Last edited 10/07/15 4:42 pm

        Be water my fwiend.
        https://www.youtube.com/watch?v=pGFf3SRP1bE

        Last edited 10/07/15 11:07 pm

      This literally only happened to me a little over a month ago, and I have been working in the I.T. industry professionally for 10 years, not to mention being surrounded by computers my entire life!

      Needless to say, I safely eject every time now.

    im with cameron.
    ive had corrupted data before and also fudged a usb stick.

    the same goes for micro sd cards in phones, I have seen so many people who have corrupted their sd card and lost all their photos. (yes, I can usually retrieve them but still.)

      Bless you. You do the same good work as doctors who patch us up after our xtreme sporting injuries.

      Continue facilitating our recklessness!

    So, when it says that it can't safely eject because some program is still using it, how can I find which program is still using it (assuming it is not obvious which program is using it)?

      Sometimes it's easy. Look at what applications you have open and chances you might find the one still using the USB.

      If it's a background task though, it gets a bit harder and requires the Task Manager to terminate the task yet even then doing so will cause corruption anyway if you happen the interrupt the task (process) while it's performing a write.

      Just yank out the USB, and the program accessing it will bring up an error dialog. I like to call this the "burn the alleged witch, and if she dies she's not a witch" method.

      Process Explorer

      Nice little guide including pictures here:

      http://superuser.com/questions/399659/how-can-i-identify-what-application-is-using-a-given-file

      This is the great windows mystery.

      Sometimes the fastest solution is shut down the machine and wait - the program still wanting to use your USB disk will finish it up and then allow windows to shut down.

    I read somewhere (probably here) that modern Windows is smart enough to not worry about the safely remove thing.

    For a USB I'm either reading (safe to remove) or writing some files to it. So a few seconds after the write, pull it out. I think one even has a read/write LED on it.

      If you wait a few seconds after writing, your data should be safe. But windows/Mac will never get smart enough to not corrupt a file you are currently writing to if you rip out the key while still writing.

        Oh yeah, not while you are writing a file. But after you have stopped, it's fine. It knows its a removable device and leaves it be.

      It's not always Windows that's the problem. A program may be using buffered writes (where the buffering is in the code library rather than the OS). Windows may have flushed any data that it has, but that doesn't help with the data that the program itself is holding onto in the name of efficiency.

    I love the rush of just yanking a usb and not knowing what could happen! YOLO

      I, too, like to live dangerously.

      Why... I don't even use a protective case on my phone.
      *cocky nod*

        pfft no case and I chuck my keys in the same pocket.

          No case, I chuck my keys in the same pocket, AND I use it to play music in the bathroom while I'm having a steamy shower! Top THAT for risk-taking, yellerbelly!

    http://www.howtogeek.com/howto/windows-vista/create-a-shortcut-or-hotkey-to-immediately-eject-a-specific-usb-drive/

    Would often get corrupted USB sticks/drives from not safely removing from a Windows XP machine, and the only way to fix was to return to that same PC (hoping it hadn't been rebooted), reinsert the drive, and safely remove it.

    Never "safely removed" a usb drive/stick since Windows 7 and have never had an issue. As long as you don't try removing while its in the middle of writing a file you should be fine.

    Last edited 07/07/15 11:48 am

    Yes I have corrupted the data on a USB stick more than once by just yanking it from the port.

    I had one of the first large capacity MP3 players. 40Gb on a spinning hard drive hidden inside a weird little box with a screen. some idiot pulled the USB cable out during a read and it bricked the entire system. I was making a backup of my whole music collection. I lost it all.

    FWIW I safely eject (or unmount on Unix-like OS') to mitigate against file corruption.

    Last edited 07/07/15 11:43 pm

    Windows 7+ You can force eject using File Explorer rather than the taskbar icon. Right click on the drive and click eject. Windows will then force eject even if you have programs using it.

      Pretty sure that's just the same Eject function as from the System Tray - it doesn't do any extra "forcing".

    I remember using that a lot with OS's especially prior to XP, as the file transfer time took so long, even for small files (remember having to have a pile of floppies for big files). But since USB 3 came out, it has mostly been a mute point, just keep an eye on the file copy notification for when it finishes (I use SSD's externally now most of the time - eg:- msata are quite cheap for a good size, so stick one in a adapter case and you have a reasonably sized and very quick external drive).
    With the newer high speed ports like USB 3.1 and faster, it will only be very large files that will still take a little while.
    The rest of my data normally goes straight to a NAS for backup

    I used to have a cdrom you could eject with its button at any time. Was always fun dodging the flying cd.

    I have the same problem with floppy disks. Nothing worse than flipping the drive latch on that sucker halfway through a write operation. Eject Safely people!

    Excuse me for a few moments... I just need to back up the contents of my USB hard drives that I regularly use and yank out at will...

    And I will remember to safely remove the backup drive

Join the discussion!

Trending Stories Right Now