syfs question

Greg KH greg at
Wed Feb 26 12:54:45 EST 2020

On Wed, Feb 26, 2020 at 10:15:43AM -0500, Sadanand Warrier wrote:
> If I call device_create with a existing class the device lands up in
> /sys/devices/virtual.

Yes, think of that as a "class device" (we used to have them as a
separate structure, now we don't).

> Using device_add I could populate the parent of the device and leave
> the class empty or provide a class and get the device to be created in
> the parent directory.

I don't understand what you mean here.

> What exactly is the significance of the" /sys/devices/virtual"  directory?
> Is this meant to carry devices of a specific type say something that is
> divorced from actual hardware?

Yes.  These are devices that do not have a "real" device backing them,
they are "virtual" devices in that the kernel creates them usually
because it needs a way for userspace to interact with the device.

A good example of this are tty "devices".  They are attached to a "real"
device in the system (pci, usb, platform, etc.) but the tty device
itself is just there to provide the common interaction with userspace
that userspace expects.

> Secondly a device created under /sys/devices/virtual has a uevent file that
> is populated like this.
> -bash-4.2$ cat uevent
> MAJOR=13
> MINOR=63
> DEVNAME=input/mice

Nice device.

> -bash-4.2$
> A device in a specific PCI slot has something like this instead..
> -bash-4.2$ cat
> /sys/devices/pci0000:00/0000:00:02.2/0000:03:00.3/net/eth1/uevent
> How is this file populated? Is it done by udev or is this done via a kernel
> call?

The uevent file is not written to (well, it can, but that does something
different), it is read from to show what the attributes that are set
when the uevent happens for that device.  It is populated by the
bus or class for that device by a bus/class specific callback to that

Have you read the LDD3 chapter on the driver model for the kernel?  It's
a bit out of date (well, really out of date), but the basics should
still be semi-relevant and might answer some of your questions here.

hope this helps,

greg k-h

More information about the Kernelnewbies mailing list