Questions tagged [sysfs]

Sysfs is a virtual file system provided by Linux. It is a ram-based file-system initially based on ramfs. It provides a means to export kernel data structures, their attributes, and the linkages between them to userspace.

Sysfs exports information about devices and drivers from the kernel device model to user space, and is also used for configuration. The Linux 2.6 kernel introduced this. It is similar to the sysctl mechanism found in BSD systems, but implemented as a file system instead of a separate mechanism.

It provides a view of the kobject object hierarchy. It enables users to view the device topology of their system as a simple filesystem.

The sysfs file system is mounted at /sys/ and contains directories that organize the devices attached to the system in several different ways. The /sysfs/ subdirectories include:

  • The /devices/ directory - represent all the subchannels detected by the Linux kernel and configuration options for the device
  • The /bus/ directory - contains contains a symbolic link to the device directories and for each device driver currently loaded on the system.
  • The /class/ directory - contains directories that group together similar devices such as ttys, SCSI tape drives, network devices, and other miscellaneous devices.
  • The /block/ directory - contains directories for each of the block devices on the system.

Read more

230 questions
1
vote
0 answers

Reading file in the Linux Kernel

so before I get the barrage of "you shouldn't be doing that", I know I shouldn't. But it is for a dirty, quick proof of concept for some research work. If the concept works I will look at proper exporting of information to my module. My knowledge of…
Alex Hoffmann
  • 355
  • 4
  • 20
1
vote
2 answers

sysfs cpu information missing

I'm trying to get hold of CPU architecture information under Linux. I understand the information is available via the sysfs filesystem. I have CentOS 5 running in a Xen VM. The sysfs filesystem is mounted. However, the…
user82238
1
vote
0 answers

Multiple subsequent writes to sysfs cause invalid module behavior. How to workaround?

my team is writing software interacting with a Linux kernel module. We write to sysfs to manage the module. Recently, we've been battling a problem in which the module occasionally does not behave as expected. One of my colleagues noticed that if we…
user44168
  • 365
  • 1
  • 4
  • 13
1
vote
0 answers

Why this udev rule is not being applied on startup but applied using udevadm test /sys/module/printk?

Context I need to disable Serial Console as wakeup source so that while connected over serial keypress on PC will not wake up a device from standby/hibernate. I found that /sys/module/printk/parameters/console_suspend attribute file's value can be…
1
vote
0 answers

unexport doesn't work on BBB GPIOs

When entering the /sys/class/gpio/ directory on a beagle bone running Linux beaglebone 4.9.82-ti-r102 #1 SMP PREEMPT Thu Feb 22 01:16:12 UTC 2018 armv7l, already several GPIOs get displayed, without me exporting them first. Trying to unexport them…
bjoekeldude
  • 338
  • 3
  • 11
1
vote
2 answers

How do I calculate memory bandwidth on a given (Linux) system, from the shell?

I want to write a shell script/command which uses commonly-available binaries, the /sys fileystem or other facilities to calculate the theoretical maximum bandwidth for the RAM available on a given machine. Notes: I don't care about latency, just…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
1
vote
3 answers

How can a Linux cpuset be iterated over with shell?

Linux's sys filesystem represents sets of CPU ids with the syntax: 0,2,8: Set of CPUs containing 0, 2 and 8. 4-6: Set of CPUs containing 4, 5 and 6. Both syntaxes can be mixed and matched, for example: 0,2,4-6,8 For example, running cat…
Ryan
  • 2,378
  • 1
  • 19
  • 29
1
vote
2 answers

How can I create lots of similar functions for sysfs attributes?

I have a generic AXI-slave device with several I/O registers in my FPGA. I want to access my registers with a sysfs interface. For each register I want to access, I create a _show and a _store function, but that would be a lot of code. static…
Franz Forstmayr
  • 1,219
  • 1
  • 15
  • 31
1
vote
1 answer

Setting GPIO using sysfs fails in i.MX6

I have a custom i.MX6 board, and I want to turn on a particular GPIO. From the schematic, the GPIO pin is connected to KEY_COL2 pad, and the KEY_COL2 has the following options. So, I have to export the following GPIO as per the calculation: linux…
md.jamal
  • 4,067
  • 8
  • 45
  • 108
1
vote
1 answer

Interpretation of `KEY` property of keyboards in udev

In udev/sysfs, keyboards have a KEY property. For example, I have an external Mac keyboard that has two "interfaces": /sys/bus/usb/devices/1-1.2.3.2:1.0 ID_INPUT_KEY: 1 ID_INPUT_KEYBOARD: 1 KEY: 10000 0 0 0 1007b00001007 ff9f207ac14057ff…
jdm
  • 9,470
  • 12
  • 58
  • 110
1
vote
1 answer

set/reset GPIO though command line is not working as expected

I am trying to set/reset the GPIO value through sysfs. I took this document as reference. At one point I am little confused, the scenario is given below exported gpio 200 to test mx6q:/sys/class/gpio/gpio200# echo "out" > direction <-- set the…
zappy
  • 1,864
  • 3
  • 18
  • 36
1
vote
1 answer

Confused on creation of binary sysfs entry

On kernel 4.0, when stepping through the kernel source for sysfs_create_bin_file, I notice it passes to sysfs_add_file(kobj->sd, &attr->attr, true); The &attr->attr being the struct attribute struct within the bin_attribute struct. This makes sense…
d4r3llo5
  • 112
  • 11
1
vote
1 answer

Reading Long Values From Sysfs Path With Escape Characters

I am using C file IO to read value from a sysfs interface in linux. Path and sample value of the register is as follows: cat /sys/class/powercap/intel-rapl/intel-rapl\:0/energy_uj 56039694184 Code: Added \ after intel-rapl\ to take into account…
Chetan Arvind Patil
  • 854
  • 1
  • 11
  • 31
1
vote
1 answer

Linux I2C Kernel Driver

I have a requirement to create a Linux Kernel Driver to interface with a bunch of MCU's over I2C, through an Interface Board. Because they would be many in number, i.e around 1-18, we are utilising a NXP / TI I2C Multiplexer. I have imported the NXP…
1
vote
0 answers

What is the relation in sysfs, udev and user space

I had a small confusion about creation of nodes, while writing a simple char driver. So I tried to find a way to make a node when my driver is inserted using class_create(THIS_MODULE, CLASS_NAME); device_create(charClass, NULL, MKDEV(majorNumber,…