flock: Add BSD flock functionality to FUZIX
System 5 has its own rather more convoluted locking so for once we'll favour
BSD over System 5.
This is an initial patch for testing.
Theory:
We recover spare bits from the inode c_busy, which is now a set of flags not
a bool with 7 wasted bits. Z80 has cheap bit ops, and the dirty bit is the top
bit which is cheap on most other processors too.
The file can be in one of 16 lock states kept in four of the recovered bits
(CFLOCK bits)
0 - unlocked
1 - 14 that many shared locks (15+ gives you an ENOLCKS error)
15 - exclusive
We use one of the spare O_ bits in each file object to keep a single bit
telling us this handle has a lock. The BSD API only allows one lock per file
table entry so that one bit is sufficient because we know that
- if our lock bit is set and the file handle is exclusive lock
then we must own the lock (as its exclusive) so we drop to 0 locks
- if our lock bit is set and the handle is not exclusive locked
then we can't own an exclusive lock so we must therefore be one of
the shared locks
Total cost about 450 bytes of kernel memory and no extra data.