The only solution I know is to encrypt the drive. Then only those having the decryption key / password can access the drive.
Instead of writing your own tools use existing ones. You can buy drives that have built-in encryption or use an encrypting software like
VeraCrypt - Home[
^]). Such software usually provides portable versions which can be stored on not encrypted parts of the drive and started from there.