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, and save them to the media together to a certain extent, such
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, after accumulating data to a certain extent and then saving it to the media, if there is no umount, the USB flash drive will be illegally pulled out, and the program will not know. fopen, fwrite, and other functions will still return correct results, i/O errors are reported only when the operating system writes the media. However, many data is lost due to this untimely error report.
In fact, the USB driver modifies the system configuration file during USB flash drive insertion and removal.
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 independent of whether it is mounted.