## semfs

#### OS/161 Reference Manual

### Name

semfs - semaphore filesystem

### Synopsis

options semfs

### Description

semfs is a simple "fake" (memory-only) file system that provides synchronization facilities to userland in the form of counting semaphores. There is one semfs instance, called "sem:", which is created and mounted during system boot.

Semaphores in semfs appear as files in "sem:". To create a semaphore, open such a file using `O_CREAT`. To destroy it, remove it with `remove()`.

To use the semaphore, write one byte to increase the semaphore count by one (the "V" operation) and write one byte to decrease the semaphore count by one (the "P" operation). The count will not decrease below zero; attempts to do so will block until other concurrent write operations raise the count again. You can also set the count explicitly using `ftruncate()`; this is useful for initializing a semaphore to a nonzero value. Note that no data is actually transferred by the read and write calls; it is acceptable to pass NULL as the data pointer.

You can create as many semaphores as you want (until memory runs out or the directory reaches 2^32 entries); however, semfs does not support subdirectories, hard links of semaphores, or renaming.

### Files

`sem:`