Manipulating “Seq” Files
The process filesystem is a window into the mystical innards of the kernel. The seq file interface simplifies the job of process file creators.
Saturday, April 15th, 2006
The process filesystem, procfs, is a virtual filesystem that provides windows into the innards of the kernel. The data you see when you peek through procfs is generated by the kernel on-the-fly. Sometimes, especially when the amount of data is large, the corresponding procfs read() functions become complex. The seq file interface is a kernel helper mechanism designed to simplify such implementations. Seq files make procfs operations cleaner and easier.
Before delving into seq files, let’s take a brief look at procfs, then gradually introduce complexities to a procfs read() routine and see how the seq file interface simplifies the implementation. Finally, we’ll update one of the few remaining 2.6 drivers that does not yet take advantage of seq files.
procfs Basics
Files in procfs are used to configure kernel parameters, look at kernel structures, glean statistics from device drivers, and retrieve general system information.
Procfs is a pseudo-filesystem, meaning that files resident in procfs aren’t associated with a physical storage device, such as a hard disk. Instead, data in procfs’s files are dynamically created on demand by corresponding entry points in the kernel. Because of this, file sizes in procfs get shown as zero. Procfs is usually mounted under the /proc directory during kernel boot up; you can see this by invoking mount.