Article Title: checks whether a USB flash disk is inserted in a Linux operating system. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
The Linux File System is asynchronous. That is to say, writing a file is not saved to the media (hard disk, USB flash disk, etc.) immediately, but saved to the buffer zone, to a certain extent and then stored together in the media. If you do not have umount, you will be unable to undo the USB flash drive. The program does not know that fopen, fwrite, and other functions still return correct results. When you know that the operating system needs to write the media, the I/O error is returned. However, a lot of data will be lost due to this untimely Error Report.
In fact, the USB driver modifies the system configuration file when the USB flash drive is inserted and pulled out.
For example, the USB flash drive records Attached: Yes or No in/proc/scsi/usb-storage-0/0 during insertion or removal.
By checking this file, it is not difficult to check whether the USB flash drive is inserted or unplugged.
Note: whether the USB flash drive is inserted is not related to whether it is mounted.