How It Works

Pendrive and USB File-Transfer Detection Engineering

Inside TIMO360's Rust and TypeScript USB watcher: tracking removable drives, copied file counts and quick ejects without ever reading file contents.

TIMO360 logoTIMO360 Team3 min read
Pendrive and USB File-Transfer Detection Engineering

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-V100 and .trash-1000 are skipped automatically.
  • Do not follow symlinks: Using std::fs::symlink_metadata ensures 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_remove removes 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: true so 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.

  1. Two polling cadences: DeviceMonitor polls mounted drives every 10 seconds, while TransferMonitor polls Rust transfer summaries every 3 seconds.
  2. 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.
  3. Synthetic session bridging: If a drive was plugged in, written to and removed between two 10-second device polls, TransferMonitor detects that isDriveReported is still false and emits USB_CONNECTED, USB_TRANSFER (final: true) and USB_DISCONNECTED together so the backend has a valid session to attach the transfer to.

Cumulative totals prevent double counting

Every USB_TRANSFER event carries cumulative totals rather than deltas, and TransferMonitor suppresses 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.

Ready for Attendance & Presence Tracking That Respects Your Team?

Set up your organization, install the agent, and start seeing attendance and presence data in minutes — without a single keystroke or screenshot recorded.

Windows, macOS & Linux Pay per employee license Zero keystroke or screen capture
Chat with us