Questions tagged [character-device]

Character special files or character devices.

Character special files or character devices provide unbuffered, direct access to the hardware device. They do not necessarily allow programs to read or write single characters at a time; that is up to the device in question. The character device for a hard disk, for example, will normally require that all reads and writes be aligned to block boundaries and most certainly will not allow reading a single byte.

Character devices are sometimes known as raw devices to avoid the confusion surrounding the fact that a character device for a piece of block-based hardware will typically require programs to read and write aligned blocks.

https://en.wikipedia.org/wiki/Device_file

27 questions
4
votes
1 answer

Is a device being a block or character device determined purely by hardware?

From https://unix.stackexchange.com/a/472920/674 A "character device" and "block device" are abstractions, usually used in Unix-style systems in classifying various devices. Is a device being a block or character device determined by hardware…
Tim
  • 98,580
  • 191
  • 570
  • 977
3
votes
0 answers

What is the modern way of creating devices files in /dev/?

tl;dr If I want my module do adhere to modern practices, should I create devices in /dev/ via mknod in a shell script or via class_create and device_create C functions directly in the module source code? What are the advantages of one approach over…
Enlico
  • 1,471
  • 16
  • 35
2
votes
1 answer

What's inside a character device file?

A character device file is a special linux file where you can read from and write to an infinite number of chars and other file operations that you can define inside a kernel device driver. But does this file actually exist? If we look at it as…
2
votes
0 answers

May a character device only handle blocking I/O?

Let's consider the following (imaginary) device: a clock which takes 1 second to query, then returns the current time. We want to write a character device driver for it, which supports read operations only. I believe non-blocking reads would not…
marcv81
  • 620
  • 2
  • 7
  • 15
2
votes
1 answer

what will the kernel do when an USB mouse inserted in Linux PC?

I am trying to write a kernel module which loads upon detection of USB Mouse. I am new to this stuff, I googled for this issue but couldn't find any appropriate solution. can anyone please explain flow of this?
2
votes
1 answer

Kernel throws error while writing to the character device file in 4.9.82-ti-r102 debian 9.3

I created the device file under /dev folder successfully, but writing to that device file makes kernel to throw following error messages. Message from syslogd@beaglebone at Feb 26 15:40:10 ... kernel:[10090.943733] Internal error: : 1b [#3] PREEMPT…
1
vote
1 answer

How to open and read a character device as binary file?

I'm working with USB and I want to read the content of usb device descriptor in /dev/bus/usb/00x/00y - it is a character device. I used fopen to open it as a binary file with "rb" parameter. But when I do the seek and tell to get file size, it…
Manh Huynh
  • 13
  • 2
1
vote
0 answers

MITM / Proxy for Character devices

I have a character devices file, say /dev/X and I would like to capture every interaction which goes in and out of /dev/X. I'm looking for a way to create some kind of MITM/Proxy to that file. Edit: Regarding what X is, it is FM interface over…
1
vote
1 answer

How are the TTY and serial_core related?

I need to write a new character device file for the UART, which allows a few more file operations than usually allowed (not just open, write, etc..) I'm on an embedded mainline linux kernel (v 5.4). I started looking at the UART drivers and notice…
Mölp
  • 31
  • 3
1
vote
2 answers

Is keyboard driver a character device driver?

I am learning device drivers and I got this doubt , is keyboard driver a character device driver in Linux?
Franc
  • 229
  • 3
  • 15
1
vote
0 answers

Nvme not showing up in /dev on Ubuntu 19.04 (5.0.0-13)

I have an Ubuntu 19.04 on a machine with an nvme drive. However, the drive is not found in /dev/nvme*. cat /proc/devices shows that nvme is loaded as a character device and not a block device and lsmod shows two loaded modules nvme and nvme_core.…
Dhruv
  • 11
  • 1
  • 2
1
vote
2 answers

Do "serial ports" or "parallel ports" apply to character devices only, but not to block devices?

From http://haifux.org/lectures/86-sil/kernel-modules-drivers/node10.html A Character ('c') Device is one with which the Driver communicates by sending and receiving single characters (bytes, octets). A Block ('b') Device is one with which the…
Tim
  • 98,580
  • 191
  • 570
  • 977
1
vote
1 answer

Can filesystems be created only on block devices, but not on character devices?

Can filesystems be created only on block devices, but not on character devices? Can a filesystem be viewed as a block device itself (for example, when programming to use a file system)? My guess is yes, not very surely based on the…
Tim
  • 98,580
  • 191
  • 570
  • 977
0
votes
0 answers

Why piping cat into head -c 5 for a chardev results in many more calls to the driver's read than just calling head -c 5 on the chardev?

Taking inspiration from this blog post, I'm playing around with linux device drivers (which I'm studying from ). The read field of the file_operations associated with the driver is initialized to the function below: static ssize_t…
Enlico
  • 1,471
  • 16
  • 35
0
votes
1 answer

Is there any difference between #include and #include ?

I have to write a device driver code for temperature sensor using IOCTL, when I was going through a lot of sample codes, I found while surfing the net, I came across this difference in header file, I counldn't get an accurate answer for it, hence…
hari
  • 9
  • 1
1
2