Replace old BSD locking API with POSIX 1

This allows mandatory locking if underneath fs is configured for it.
Also fixed operations there were done on an invalid fs.