do we really need sysfs?

I and my colleague were discussing sometime back about the kernel and how the data flow occurs from user to the hardware. How is the kernel driver api is called and in what sequence? Then He poped one question to me - why do we require the SYSFS when we already have DEVFS?

My first answer was - devfs is the one which actually talk to device driver and the using sysfs, we set or get the attributes for the device. But this answer was not convincing. He posted the question in stackoverflow.com and searched but it was not convincing. Even I wondered how two are different.

Searching the internet tells that the sysfs was originally developed to test the new device model which was being written for the kernel 2.5 version. That time the procfs was used primarily for the testing but since the procfs is basically fs for the information on process and other system related information. Due to this, procfs was cluttered with lots of non-process information. So the whole idea was to write a new file system which can aide to the development of new device model. Moreover, there was no mechanism for hotplug in linux kernel. So with the development of new sysfs (previously called ddfs which was based on in-memory fs, ramfs), these were achieved. 

Sysfs is a virtual filesystem which provides a userspace-visible representation of the device model. The sysfs filesystem is usually mounted on /sys. Sysfs is designed to export the information present in the device tree which would then no longer clutter up procfs. Sysfs is used by several utilities to access information about hardware and its driver  such as udev. Scripts have been written to access information and some scripts configure device drivers and devices via their attributes. For every kobject that is registered with the system, a directory is created for it in sysfs.

The device model and sysfs are sometimes confused with each other, but they are distinct entities. The device model functions just fine without sysfs (but the reverse is not true). Driver writers generally need not worry about sysfs; it is magically created and implemented by the driver model and bus driver code. The one exception comes about when it comes to exporting attributes via sysfs. These attributes represent some aspect of how the device and/or its driver operate; they may or may not be writeable from user space. Sysfs is now the preferred way (over /proc or ioctl()) to export these variables to user space. 




I think, this is a good point to start discussion on this topic. Hope, this clears some of the doubts. Still I have some doubts, which I am googling right now ;)


cya then...for now The Big Bang Theory (specially Penny) waiting for me...Bazingaaaa

No comments:

Post a Comment