How does the linux kernel create sysfs?

I started learning Linux kernel code for my OS course. In this I am interested in the sys file system (sysfs). I am interested to know when and how sysfs are created? What files in the Linux kernel code generate this file system?

I have a linux kernel installation on my system and code debugging has begun.

I mentioned this document to understand the sysfs file system: [sysfs]: https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt

But this document only explains the directory structure, the creation of directories and read / write attributes. I'm more interested in how the kernel creates these directories at boot time. I realized that the following method is responsible for creating directories in sysfs.

   int sysfs_create_file(struct kobject *kobj, struct attribute *attr);

This function takes a structure, kboject attributes and with their help creates a directory in sysfs.

I realized that at boot time, the kernel detects memory and creates directories in sys / devices / system / memory. I plan to change this directory structure as part of my homework. So, could you tell me the files and methods that are responsible for creating these specific memory directories?

+3
source share
2 answers

You should not use such functions directly. You should also avoid using it kobject(unless you touch the kernel core).

Typically, the sysfs attribute is associated with a structure device. So, when registering a device, the sysfs attribute is created.

device device.h 689.

const struct attribute_group **groups;

, device_register()

device_register(), , sysfs

+3

sysfs fs/sysfs/. sysfs sysfs_init sysfs_mount.

" sysfs" Patrick Mochel , , sysfs < > sysfs .

+1

Source: https://habr.com/ru/post/1618897/


All Articles