OpenSource For You

Talking to the Kernel through Sysfs

The Linux kernel provides a virtual file system called sysfs. By providing virtual files, sysfs is able to export informatio­n about various kernel sub-systems, hardware devices and associated device drivers from the kernel’s device model to user space. To

-

T here is a need to provide informatio­n related to each process, to the user space, which can then be used by programs such as ps. The /proc file system was created for this purpose. Through the proc file system, each process has its directory in the /proc folder. It was originally designed to provide process related informatio­n to user space. Adding directorie­s and files to the /proc file system is easier; so, many kernel sub-systems started using this file system for displaying informatio­n to the user space. It is also used to take inputs from the user space to control settings inside the kernel modules. But the /proc file system is getting cluttered with lots of non-process related informatio­n.

From the Linux 2.5 developmen­t cycle, a new interface called the /sys file system has been introduced. Sysfs is a RAM based file system. It is designed to export the kernel data structures and their attributes from the kernel to the user space, which then avoids cluttering the /proc file system. The advantages of sysfs over procfs are as follows: ƒ A cleaner, well-documented programmin­g interface ƒ Automatic clean-up of directorie­s and files, when the device is removed from the system ƒ The enforced one item per file rule, which makes for a cleaner user interface The ‘one item per file’ rule mandates that in each file of sysfs, there will be only one value that can be put in or read from it. This feature really makes it a cleaner interface. Through sysfs, user space programs can get informatio­n from the kernel sub-system like device drivers. Programs

 ??  ??

Newspapers in English

Newspapers from India