If you have used a flash drive since… well, since they existed, really, you are probably aware that you should first eject them before physically removing them. Given that ejecting a flash drive does not physically send it flying from the computer, or “come out”, as with CD/DVD players, it must do something else… but what?
Furthermore, there is a good chance you were naughty. You physically removed a flash drive, but didn’t eject it. And, much like when you attempted to fly by flapping your arms (back when you thought you were a bird), nothing happened. When you later use your flash drive, it works as expected. Why, then, is it seemingly not actually required to eject it?
Before getting to these questions, we will explore (I got a map from a guy in an alley, he says it is legit) the basic mechanics of flash drives to understand why things are the way they are.
What Is A Flash Drive?
A flash drive is basically a stick, roughly the size of your thumb. Which is, of course, why it is also called a thumbstick. Anyway, flash drives are a form of storage, like hard drives, but are much more portable, connecting to the USB interface. Presumably you know this already, otherwise this article will not be very helpful for you. If you came here looking for a driveway with flashing lights or some other nonsense, you have come to the wrong place.
Flash drives, like hard drives, contain files.
Files
A file is kind of like a piece of paper. You can write on it, and you can read what you wrote – I am going to assume you know how to read if you are at this point in the article. If you want to add information (data) to paper, you write on it with a pencil. Or, in your case, get distracted and draw a cat on your face, but I digress. To read it, you… uh, read it, with those eyeball thingies (that is a technical term) that are kind of important.
When it comes to files on computers, programs read and write data to and from files. Programs reference files with file handles. It is kind of like an ID number. For example, to a billing system, you aren’t so much “Bob Bobbington” as a specific ID number. That specific ID number happens to be associated to the entity known as the person Bob, but in the system you are a number. In the same way, your file isn’t “Why cats are awsum essay”, but instead a specific number associated with that file.
Here comes an important bit: only one program can have a handle to a specific file at once (*generally). For example, if one program is writing to a file, another program cannot delete the file out from under it, because it is locked until the first process is done using it. In our paper analogy, if you are busy drawing a unicorn, I will be polite and wait until you are done before erasing it and drawing something that actually exists.
What Does Eject Do?
So there you are, wanting to take out your flash drive. You save your document and pull out the flash drive. You didn’t eject it, because that is just the kind of person you are. You later access your document, and it cannot be opened because it is corrupt. Obviously, you screwed up, but what happened?
When you saved your document, the program started writing the new contents to the file. It was in the middle of doing this when you rudely pulled out the flash drive. Suffice it to say, interrupting file operations rarely ends well. The eject functionality is intended to protect files from idiots prevent this from happening.
When you eject a flash drive, the computer checks if there are any open file handles to files on the flash drive. That is, it checks if any programs are currently using the files on there. As the hypothetical you discovered, if there are any programs using it, you don’t want to take it out. If there are no open file handles, it lets you eject it. This lets you know you can physically take it out, and also hides it so programs don’t see it, otherwise they might open new file handles between when you ejected and when you took it out.
If there are open file handles, it cannot eject it, and it informs you of this. It cannot automatically eject itself, because manually closing all the open file handles would make programs using them not work. It would be like yanking the paper from somebody who was writing on it. Instead, it is up to you to figure out what programs still have open handles, close them, and then eject again. In the case of editing your document, this is likely your word processor.
Sometimes you close all the things you can think of, and it still doesn’t eject. You may have closed every single running program, related or otherwise, in attempts to free your drive, and even this fails. Generally speaking, this is the result of a buggy program somewhere that just cannot let go – you know how emotional they can be sometimes. Frequently this is done by your file browser (i.e. what you use to look at your files). In order to know what files are where, it too opens file handles. It often seems to have trouble closing them when they are no longer needed. Part of the problem is, at least in Windows, the program (File Explorer) that access files also controls a bunch of other stuff, like the start menu, and so it is always running.
Why Is Not Ejecting Usually Safe?
In the above situation, you would likely decide to just take the flash drive out. And, odds are, nothing bad is going to happen. At least, nothing bad will happen to the flash drive. Maybe you will spontaneously combust or something. Recall that the risk of not ejecting is that files are still being used when you take it out. If no files are being actively used when you take it out, nothing will happen. Note that this is true even if there are still open file handles. The danger isn’t the file handles themselves, it is what is done with them – reads and writes. If file handles are still open, but never get used, taking the drive out is still safe. For this reason, if you have closed everything that had reason to modify the files (e.g. word processor), it should be safe to physically remove it if it fails to eject.