Sequential Files

Before discussing any filesystem library, we need to have a look at the sequential file interface. Files in small filesystems will usually be read sequentially from start to end from userland, and their contents are created by iterating over several items. These could, for instance, be array elements. The kernel traverses the the whole array from start to end and creates a textual representation for each element. Put into kernel nomenclature, one could also call this making synthetic files from sequences of records.

The routines in fs/seq_file.c allow implementing such files with minimal effort. Despite their name, seeking is possible for sequential files, but the implementation is not very efficient. Sequential access — where one item is read after another — is clearly the preferred mode of access; simplicity in one aspect often comes with a price in other regards.

The kprobe mechanism contains an interface to the aforementioned debug filesystem. A sequential file presents all registered probes to userland. I consider the implementation to illustrate the idea of sequential files.

Continue reading here: Writing Sequential File Handlers

Was this article helpful?

0 0