Questions tagged [chardev]

A character device is a custom kernel module communicating with user space in an unstructured way.

Character devices allows communication between user space and the kernel in a way that is not structured around any specific predetermined way. /dev/null, /dev/maps and the TTY are all examples of character devices.

The above is in contrast to block devices, which communicate with user space through blocks of data, usually destined to some non-volatile storage.

28 questions
4
votes
1 answer

Automatic unloading of an OS X driver

it's my first question here :) I'm currently writing a generic kext which provides a character device and targets OSX 10.7+. It's pure C, with zero IOKit/C++. (In case this matters, I'm testing the driver on 10.11.) I want the driver to be unloaded…
dimkr
  • 41
  • 3
3
votes
1 answer

why Variable has incomplete type 'struct file_operations' though importing fs.h?

I try to import the struct of file_operations and get this error: Variable has incomplete type 'struct file_operations' my imports are #include /* We're doing kernel work */ #include /* Specifically, a module…
oki doki
  • 39
  • 2
3
votes
1 answer

Getting ENOTTY on ioctl for a Linux Kernel Module

I have the following chardev defined: .h #define MAJOR_NUM 245 #define MINOR_NUM 0 #define IOCTL_MY_DEV1 _IOW(MAJOR_NUM, 0, unsigned long) #define IOCTL_MY_DEV2 _IOW(MAJOR_NUM, 1, unsigned long) #define IOCTL_MY_DEV3 _IOW(MAJOR_NUM, 2, unsigned…
Mugen
  • 8,301
  • 10
  • 62
  • 140
3
votes
4 answers

Linux kernel : Setting the permissions for a /dev file that was created via create_device()

I am making a small linux module that is a driver to a char device. In my code i create the device class, than the device it self and thus a /dev file is created in my system. the problem is that the /dev file has only root permissions and the…
user3595668
  • 31
  • 1
  • 2
2
votes
1 answer

Why does cat call read() twice when once was enough?

I am new to Linux kernel module. I am learning char driver module based on a web course. I have a very simple module that creates a /dev/chardevexample, and I have a question for my understanding: When I do echo "hello4" > /dev/chardevexample, I see…
Dsrivast
  • 39
  • 1
  • 10
2
votes
2 answers

Should Linux character devices terminate read() with newline

POSIX defines a text file as: A file that contains characters organized into one or more lines. POSIX defines a line as A sequence of zero or more non-newline characters plus a terminating newline character. Given this, should the read()…
retrodev
  • 2,323
  • 6
  • 24
  • 48
2
votes
1 answer

map reserver memory at boot to user space using remap_pfn_range

I am trying to map reserved memory (30M with offset of 2G) at boot time (boot kernel parameters mem=2G memmap=30M$2G) to user space using the remap_pfn_range, bellow is my driver code: #include #include #include…
Mondher123
  • 67
  • 1
  • 9
2
votes
1 answer

How stable are major and minor mode of a chardev?

I'm working on a serial port library, and I am thinking on using the major/minor mode of the character device to check whether the given file is a platform serial port, a pty or a usb serial port, in complement of using other frameworks that exist…
zmo
  • 24,463
  • 4
  • 54
  • 90
1
vote
1 answer

mmap more than one buffer in kernel is crashing please help (using dma_mmap_coherent)

I'm developing a Linux kernel module that allocates more than one buffer per char device and then the user-space application maps those buffers to the user-space. My character device class has around ten or more buffers and on open time I allocate…
Mathieeo
  • 23
  • 3
1
vote
0 answers

Why does module failed to load? (/dev/scull0 : no such device or address)

From my previous question: How to build external modules in ubuntu? I thought I cannot load module due to loading out-of-tree or tainting kernel, but to my scull_init_module (source below) I have added printk so I know I get loaded from kern log.…
autistic456
  • 183
  • 1
  • 10
1
vote
0 answers

Replacing `chardev` by `mmap`

I am looking for a way to synchronize a kernel driver and some user-land code (without any copy_to_user or polling on a mmap) More explanation: My user side code read some data in a shared mmap, but it needs to know when the data are ready from the…
Cijay
  • 51
  • 5
1
vote
0 answers

Simple character device not working as expected

I have been writing code for a simple character device and test script. Everything compiles properly. The character device has a device file, the make command, insmod and rmmod commands, etc. all work fine, and have expected output when checking…
Cassie H.
  • 373
  • 2
  • 7
  • 24
1
vote
1 answer

character device: choose the device to read/write

I found a good code as example for a character device module : https://github.com/euspectre/kedr/blob/master/sources/examples/sample_target/cfake.c I do not modified the code and I tested it. I obtained two devices (/dev/cfake0 and /dev/cfake1) but…
PierreOlivier
  • 1,387
  • 9
  • 23
1
vote
1 answer

Registering Mapped Linux Character Device Memory with cudaHostRegister Results in Invalid Argument

I'm trying to boost DMA<->CPU<->GPU data transfer by: 1. Mapping my (proprietary) device Linux Kernel allocated memory to user space 2. Registering the later (mapped memory) to Cuda with cudaHostRegister API function. While mapping User Space…
Yoelson
  • 31
  • 7
1
vote
0 answers

Why doesn't device_create return error when a file already exists?

I am writing a PCI driver with a character device for an interface (Linux 4.9.13). Here's the scenario that bothers me: Run touch /dev/foo0 which creates a normal file in the /dev directory. Load the driver module. Here's a pseudo code representing…
1
2