Add block form of the file lock

A wrapper for locking that simplifies the code on a few places.