The invention discloses a
USB flash disk transmission monitoring method based on a Fanotify mechanism, and the method comprises the following steps: 1, carrying out
system initialization, including Netlink initialization and Fanotify initialization; 2, when the
USB flash disk is inserted into a
system, a Netlink thread receives a
USB equipment Add message, a table item is established with the USB flash disk equipment name as a Key and used for identifying the USB flash disk, the state is Adding, and the table item is inserted into a USB flash disk
list; 3, traversing the USB flash disk
list by the
timer, comparing the USB flash disk
list with / proc / mouts to find a
directory from the USB flash disk
Mount to the
file system, and calling a Fanotify interface fanotifymark to monitor the
directory; 4, when a user performs copy operation on the file in the U disk, triggering a Fanotify event; 5, when the USB flash disk is pulled out, searching the USB flash disk list by taking the USB flash disk equipment name as the Key, and performing corresponding
processing according to the state after the USB flash disk list is found; and 6, traversing the USB flash disk list by the
timer, and comparing the USB flash disk list with / proc / mouts. According to the method, an
application layer scheme can be used for replacing a kernel scheme on a Linux
system, the
adaptation workload can be remarkably reduced, and the stability is improved.