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
3
votes
1 answer

Create sysfs entry from kernel module

I want to pass a string > 1024 chars to my module (filesystem). As kernel parameters are limited to 1024 chars, someone recommended to use sysfs instead. I tried to include this example in my super.c class to create a string 'filename' & string…
goose999
  • 73
  • 1
  • 5
3
votes
2 answers

GPIO/Analog programming for BeagleBone Black on Angstrom Linux, what compiler for cross development on Windows?

I'm working on a BeagleBone Black (BBB from now on) with its stock Angstrom Linux. I'm able to do GPIO/Analog programming using JavaScript, but I want to do it in C/C++. I know the sysfs thing and /dev/mem, I want to know how to configure the GPIO…
Imran Munshi
  • 53
  • 1
  • 7
3
votes
1 answer

What is the command used in Linux to know info about memory interleaving?

I am working on the Linux Kernel as part of my course homework and this is the information I seek: In the latest systems, memory is split up into ranks under which which memory is interleaved among the different ranks in a non-contiguous way. This…
Srikanth Kandalam
  • 965
  • 3
  • 15
  • 26
3
votes
2 answers

How is userspace able to write to sysfs

Recently I was looking through the kernel at kobjects and sysfs. I know/understand the following.. All kernel objects use addresses > 0x80000000 kobjects should be no exception to this rule The sysfs is nothing but a hierarchy of kobjects (maybe…
Guru Prasad
  • 4,053
  • 2
  • 25
  • 43
3
votes
1 answer

Why a store function in the sysfs API of the Linux Kernel needs to return used bytes?

From the documentation: store() should return the number of bytes used from the buffer. If the entire buffer has been used, just return the count argument. What does it do with this value? What's the difference if from a buffer of size FOO I…
maayank
  • 4,200
  • 2
  • 24
  • 23
3
votes
1 answer

Linux, sysfs, usb sticks and usb hard drives

Is there a way to distinguish between USB sticks (flash memory) and USB hard drives via libudev / sysfs in Linux? If not, is there a way to query the hardware directly? Thank you.
Zaur Nasibov
  • 22,280
  • 12
  • 56
  • 83
3
votes
3 answers

Beaglebone gpio input not working

I am using beaglebone to access digital input from specific pin using sysfs interface. And I can change the output states but not the input :(. What I did is, I have two pins pinA and pinB. pinA I made it output and pinB I made input. Connected pinA…
duslabo
  • 1,487
  • 4
  • 20
  • 33
2
votes
1 answer

How do I make my kernel module's sysfs entry be owned by a non-root user?

I have the following code: static struct kobj_attribute my_attribute =__ATTR(my_node, 0444, my_show_fn, my_store_fn); ... kobject_init(&my_module->kobj, &ktype_my_module); ret = kobject_add(&my_module->kobj, kernel_kobj, "%s",…
fadedbee
  • 42,671
  • 44
  • 178
  • 308
2
votes
2 answers

Listening for sysfs battery events

I'm writing a daemon which checks the battery capacity. This is for a solar powered embedded device running Linux. I've read that it's a bad idea to use sleep() in daemons, thus I'm trying to use events. So I wrote some PoCs, but I'm not getting any…
pan
  • 121
  • 1
  • 4
2
votes
1 answer

Using sysfs_notify_dirent() correctly

I've some trouble understanding how to use sysfs_notify_dirent() correctly. Basically, I'm writing a device driver, and I need one of the sysfs attributes exported by the driver to be "pollable" from user-space. Since I know when new data will be…
Twoism
  • 33
  • 4
2
votes
0 answers

cpufreq_get returns 0 in linux kernel module

I have written the following code to get current CPU frequency in my kernel module C file: #include void func() { printk(KERN_ALERT "CPU Freq in KHz: %d\n", cpufreq_get(3)); } I am getting CPU Freq in KHz: 0 I have checked that…
sal_guy
  • 199
  • 2
  • 14
2
votes
2 answers

How can I detect a USB port being used for charging in Linux?

I'm using a USB port on the Raspberry Pi 3 Model B to charge an accessory via a USB magnetic charging cable. I want to detect when the cable is plugged in and removed from the Pi. I've been plugging in and removing this cable and looking for any…
liamzebedee
  • 14,010
  • 21
  • 72
  • 118
2
votes
2 answers

Cannot set Attribute Permissions to 0666 in sysfs

I am working with sysfs and I need to create a file under sysfs, the file should be readable and writable by all users, for which I set the Permissions in '__ATTR' to 0666. But the module does not compile, the moment I change the permissions to…
2
votes
1 answer

Get triggered by GPIO state change in bash

I have a GPIO pin, that value of which is represented in the sysfs node /sys/class/gpio/gpioXXXX/value) and I want to detect a change to the value of this GPIO pin. According to the sysfs documentation you should use poll(2) or select(2) for…
Jasper
  • 11,590
  • 6
  • 38
  • 55
2
votes
1 answer

Creating a file under /sys/devices in Linux

I want to create a file under /sys/devices directory in Linux. What is the best way to do this?
hussain
  • 51
  • 1
  • 6