19

Exactly what is the difference between devfs and sysfs? Both seem to maintain a list of hardwares attached to the system. Then why the need for 2 separate fs even arose? As far as I can get /sys maintains somewhat "raw" list of devices(like "ser0"). Udev acts on those devices, gets various informations and applies various rules to present them as recognizable names which are then mapped onto /dev(like "camera"). Is this the only reason? And then we mount the corresponding devices from the /dev fs(can't we do that from the /sys fs) into the /media fs.

I have read the answer at Difference between /dev and /sys/class?. But I cannot get the sys fs part where it states that

Sysfs contain the hierarchy of devices, as they are attached to the computer

Are the files in /sys not device node files? Then what type of files are they?

25

The /sys filesystem (sysfs) contains files that provide information about devices: whether it's powered on, the vendor name and model, what bus the device is plugged into, etc. It's of interest to applications that manage devices.

The /dev filesystem contains files that allow programs to access the devices themselves: write data to a serial port, read a hard disk, etc. It's of interest to applications that access devices.

A metaphor is that /sys provides access to the packaging, while /dev provides access to the content of the box.

The files in /sys are not device nodes, but symbolic links and regular files. Those regular files are special in that reading or writing to them invokes file-specific functions in the kernel, like device nodes. The difference is that files in /sys work this way because of the filesystem they are on, whereas device nodes work this way due to their device node characteristics (the file type indicating a (block or character) device, and the device major and minor number indicating which device it is).

The reason for /dev existing independently of /sys is partly historical: /dev dates back to the dawn of Unix, while /sys is a much more recent invention. If Linux was designed today with no historical background, /dev/sda might be /sys/block/sda/content.

  • 3
    See also: man hier. – HalosGhost Dec 30 '14 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.