Implement metafile writing and locking.