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

202 questions
25
votes
1 answer

My attributes are way too racy, what should I do?

In a linux device driver, creating sysfs attributes in probe is way too racy--specifically, it experiences a race condition with userspace. The recommended workaround is to add your attributes to various default attribute groups so they can be…
Gavin S. Yancey
  • 1,179
  • 1
  • 11
  • 29
20
votes
3 answers

How to create a simple sysfs class attribute in Linux kernel v3.2

I'm learning how to use sysfs in my Linux modules, but I'm having the hardest time finding current documentation on these topics. The Linux Device Drivers 3rd Edition book I've been using seems to be rather dated in this area unfortunately (e.g. the…
Vilhelm Gray
  • 10,078
  • 8
  • 55
  • 108
18
votes
1 answer

Linux driver: ioctl or sysfs?

I'm writing a driver to control some custom hardware. In the old days (i.e. 15yrs ago) I was doing this with ioctls, but am now digging into sysfs as a possible alternative. As I understand it, ioctls aren't totally deprecated, but sysfs is…
ColH
  • 363
  • 3
  • 10
17
votes
2 answers

In Linux, is there a way to find out which PCI card is plugged into which PCI slot?

In Linux, is there a way to find out which PCI card is plugged into which PCI slot? /sys/bus/pci/devices/ contains many devices (bridges, CPU channels, etc.) that are not cards and I was not able to find any information about slot-card mappings in…
magmabyte
  • 339
  • 1
  • 2
  • 10
11
votes
2 answers

How to test battery charging speed?

How can I detect battery charging speed in android device? I can detect battery status using below code. but not charging speed. IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); BatteryChangeReceiver…
Kishan Vaghela
  • 7,008
  • 3
  • 36
  • 63
11
votes
2 answers

Named GPIOs in DeviceTree

I am trying to create a device tree for an embedded system, and would like to expose a few GPIOs to userspace. These are not and should not be used by kernel drivers. For instance, there is a USB device soldered to the board that is controlled by…
FazJaxton
  • 6,437
  • 6
  • 22
  • 31
10
votes
2 answers

Android get charge rate in milliamps via sysfs

I am developing a informational android app where I want to read the charge rate in milli-amps when the device is charging. I have seen other apps that can do this such as Ampere. I believe the info should be in directory…
rosghub
  • 7,772
  • 4
  • 21
  • 31
10
votes
1 answer

Using the Linux sysfs_notify call

I am trying to communicate asynchronously between a kernel driver and a user-space program (I know there are lots of questions here that ask for similar information, but I could find none that deal with sysfs_notify). I am leaving Vilhelm's edit…
Digilee
  • 171
  • 1
  • 2
  • 10
9
votes
3 answers

How to attach file operations to sysfs attribute in platform driver?

I wrote a platform driver for a peripheral we developed and would like to expose some configuration options to the sysfs. I have managed to create the appropriate files using attribute structs (see below) and sysfs_create_file in the probe function,…
8
votes
2 answers

Raspberry PI, GPIO Pull UP/DOWN resistors with SYSFS

Just off the bat I'd like to state that I'm aware of Python and other high level implementations for manipulating GPIO on the Raspberry PI. I've also been using the WiringPI C API and am experiencing problems with it on Raspbian Jessie that I was…
os x nerd
  • 857
  • 1
  • 9
  • 17
8
votes
1 answer

SELinux rules for i2c files in sysfs in Android

I created kernel driver as loadable module for one of my I2C devices. The driver creates few sysfs file under I2C corresponding folder (/sys/devices/i2c/i2c-0/0-0008/) using instantiation through new_device file…
DmitryF.
  • 81
  • 4
8
votes
2 answers

In general, on ucLinux, is ioctl faster than writing to /sys filesystem?

I have an embedded system I'm working with, and it currently uses the sysfs to control certain features. However, there is function that we would like to speed up, if possible. I discovered that this subsystem also supports and ioctl interface, but…
Mike Crowe
  • 1,776
  • 2
  • 18
  • 36
7
votes
1 answer

Linux driver access through sysfs

I'm making a small kernel module to provide user-space access to some kernel-mode only features of an ARMv7 chip (specifically, cache control). I'm reading through Linux Device Drivers by Corbet, Rubini, and Hartman. In it they describe how to make…
Ted Middleton
  • 5,722
  • 9
  • 43
  • 64
6
votes
0 answers

Can't find kobject for use in sysfs_notify()

I am working on a driver that creates a sysfs attribute file. It is intended that an application be notified of changes to this attribute by using the poll() method. I intend to use the sysfs_notify() function for this. This is easy to do as long…
DJM
  • 61
  • 2
6
votes
1 answer

Under what conditions would /sys/kernel/debug/gpio be empty?

Summary My aim is to control the GPIO pins in Peppermint 4 Linux (Kernel version 3.8.0) on an Intel motherboard (NM70 chipset with C1037U processor). I'm debugging issues I'm having using the sysfs interface and am trying to understand the…
CalumJEadie
  • 179
  • 4
  • 12
1
2 3
13 14