
Key takeaways
- Removable drives are keyed by both mount point and volume label so plugging a different pendrive into the same Windows drive letter never merges sessions.
- A Rust recursive filesystem watcher tracks only new writes after mount, ignoring OS housekeeping folders, deleted files and symbolic link targets.
- Transfer totals stay in Rust memory and poll every 3 seconds so even a quick copy-and-eject sends a final summary and synthetic connect/disconnect pair.
- Copied file names are omitted by default, sorted largest-first only when admins opt in, and never accompanied by file contents or local source folder paths.
Detecting when a pendrive is plugged in is easy; accurately counting what was copied onto it — especially if someone copies files and pulls the drive out seconds later — is full of subtle filesystem edge cases. In TIMO360, we built a dedicated Rust transfer watcher (usb_transfer.rs) paired with a fast TypeScript poll loop (TransferMonitor) that captures file counts, byte totals and file types while keeping file contents strictly off-limits.
Identifying Pendrives Reliably Across OSes
In device_signals.rs, TIMO360 inspects mounted volumes with sysinfo::Disks and filters on disk.is_removable(). Crucially, each drive is keyed by mount|name (for example, E:\|KINGSTON) rather than mount path alone. On Windows, drive letters such as E:\ get reused across different sticks; combining mount point and label keeps each physical drive's session distinct.
We also state the OS boundary openly in Preferences: if an external USB enclosure reports itself to the operating system as a fixed disk rather than removable media, is_removable() returns false and the drive is not tracked.
Watching Only New Writes After Plug-In
When an organization enables Detect files copied, UsbTransferState attaches an OS-native recursive file watcher (notify::recommended_watcher) to each mounted removable drive. Files already sitting on the pendrive before it was plugged in are never scanned or counted — only new creates, modifications and renames.
Real-world drives generate plenty of noise, so our Tracker cleans events before counting:
- Ignore OS housekeeping directories: Writes inside
System Volume Information,$RECYCLE.BIN,.Trashes,.fseventsd,.Spotlight-V100and.trash-1000are skipped automatically. - Do not follow symlinks: Using
std::fs::symlink_metadataensures a symbolic link on the drive never gets counted at the byte size of a file elsewhere on the laptop. - Refresh growing files: Large copies emit writes while a file is still streaming, so up to 1,000 tracked paths per drive are re-stated each poll to keep byte totals accurate.
- Subtract removed files: If a file is deleted or renamed off the drive before ejection,
on_removeremoves it from the count so temporary files do not inflate totals. - Bound memory safely: Individual path tracking caps at 20,000 files per drive while overflow counts and bytes still accumulate, and watcher buffer overflows set
incomplete: trueso admins know totals may be undercounted.
Surviving Quick Ejects With Dual Poll Intervals
If an employee plugs in a pendrive, copies a folder in four seconds and pulls the stick out, waiting on a slow timer would miss the drive completely — or fail trying to stat a path that is already unmounted.
- Two polling cadences:
DeviceMonitorpolls mounted drives every 10 seconds, whileTransferMonitorpolls Rust transfer summaries every 3 seconds. - In-memory final summary: Totals live in Rust memory, not on disk. When a drive disappears, Rust drops the OS watcher and returns the stored totals one final time flagged
ended: true. - Synthetic session bridging: If a drive was plugged in, written to and removed between two 10-second device polls,
TransferMonitordetects thatisDriveReportedis still false and emitsUSB_CONNECTED,USB_TRANSFER(final: true) andUSB_DISCONNECTEDtogether so the backend has a valid session to attach the transfer to.
Cumulative totals prevent double counting
Every
USB_TRANSFERevent carries cumulative totals rather than deltas, andTransferMonitorsuppresses unchanged signatures. Even if the network drops and an event retries from the local queue, totals on the server can never double-count.
Visible Status on the Employee's Desktop Agent
Just like activity monitoring, pendrive tracking is never invisible. Whenever an organization enables USB monitoring, file-transfer counting or optional file-name capture, the agent's status panel spells out the exact scope in plain text (including when file-transfer detection runs at all times) via describeUsbMonitoring().
Next, see how the backend safely ingests and cleans up these events in Inside the USB and VPN Monitoring Backend, or review our Privacy & Data Protection guarantees.