ioctl | The missing tool to call arbitrary ioctls on devices
kandi X-RAY | ioctl Summary
kandi X-RAY | ioctl Summary
The missing tool to call arbitrary ioctl on devices. Since most data associated with ioctls are not human readable, this tool is intended for driver developers who want to do quick tests on their drivers.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of ioctl
ioctl Key Features
ioctl Examples and Code Snippets
Community Discussions
Trending Discussions on ioctl
QUESTION
I have a docker container with an XDP program loaded on it. I also have a batch file for the bpftool
to run. When I run bpftool batch file tmp_bpftool.txt
, I get Error: reading batch file failed: Operation not permitted
. I am the root in the container. So, what could possibly be the problem?
The batch file is as below: (512 updates on map 59 and 1 update on map 58)
...ANSWER
Answered 2022-Mar-29 at 00:11TL;DR: Your map update works fine. The message is a bug in bpftool.
Bpftool updates the maps just as you would expect; and then, after processing all the batch file, it checks errno
. If errno
is 0, it supposes that everything went fine, and it's good. If not, it prints strerror(errno)
so you can see what went wrong when processing the file.
errno
being set is not due to your map updates. I'm not entirely sure of what's happening to it. The bug was seemingly introduced with commit cf9bf714523d ("tools: bpftool: Allow unprivileged users to probe features"), where we manipulate process capabilities with libcap. Having a call to cap_get_proc()
in feature.c is apparently enough for the executable to pick it up and to run some checks on capabilities that are supported, or not, on the system even if we're not doing any probing. I'm observing the following calls with strace
:
QUESTION
I am trying to use the write protection feature of Linux's userfaultfd, but it does not appear to be enabled in my kernel even though I am using version 5.13 (write protection should be fully supported in 5.10+).
When I run
...ANSWER
Answered 2022-Mar-17 at 17:27The UFFD_API
ioctl does not seem to ever report _UFFD_WRITEPROTECT
as can be seen here in the kernel source code (1, 2). I assume that this is because whether this operation is supported or not depends on the kind of underlying mapping.
The feature is in fact reporeted on a per-registered-range basis. You will have to set the API with ioctl(uffd, UFFDIO_API, ...)
first, then register a range with ioctl(uffd, UFFDIO_REGISTER, ...)
and then check the uffdio_register.ioctls
field.
QUESTION
I have to modify a driver that runs on linux to add a callback function that is invoked from an external application. I already have the code implemented but when it is executed when the computer starts up, the system gives an error and is blocked.
This is my new code on the driver side:
...ANSWER
Answered 2022-Jan-14 at 13:42The crash image suggests that somewhere in your code you have an invalid pointer that you are trying to access. I am afraid I cannot debug your code with the little context provided, but I can give you some suggestions:
- Try to avoid casting until is strictly necessary.
- When you are casting to a pointer, double-check that this is exactly what you need to do.
- In the error message there is also the call stack: take a look at it in order to identify where is the error.
- You can simply add some printk("%p", pointer) in your code to debug the content of your variables.
QUESTION
I've got this power monitor that I'm attempting to interface with to retrieve it's fault log LTC2977 (data sheet: https://www.analog.com/media/en/technical-documentation/data-sheets/ltc2977.pdf)
I'm new to i2c / pmbus / smbus things so forgive my poor terminology or incorrect descriptions of how things work. On page 18 the data sheet states that I can interface with it like so:
The LTC2977 is a slave device. The master can communicate with the LTC2977 using the following formats:
- Master transmitter, slave receiver
- Master receiver, slave transmitter
The following SMBus protocols are supported:
- Write Byte, Write Word, Send Byte
- Read Byte, Read Word, Block Read
- Alert Response Address
Figure 1a-12 illustrate the aforementioned SMBus protocols. All transactions support PEC (packet error check) and GCP (group command protocol). The Block Read supports 255 bytes of returned data. For this reason, the PMBus timeout may be extended using the Mfr_config_all_ longer_pmbus_timeout setting.
The log in question can be accessed with SMBus (PMBus?) command 0xEE, wherein it will spit out 0xFF followed by 255 bytes containing the log data. Now I can see the device and all its internal commands/registers(?) by doing i2cdump
, and similarly if I do i2cget ... 0xEE
I get the output 0xff
, which is what the first entry in the log is supposed to be. I can also do i2cget ... 0xEE w
, so outputting as a word to get 0x--ff
where the '-'s are values changing everytime I call i2cget
, my log data perhaps?
My problem is I'm attempting to read this as a block like the document stated I could do above. I'm not entirely sure how to do this so I tried the following:
...ANSWER
Answered 2022-Jan-14 at 23:10okay, I've managed to figure out a solution, kind of a hybrid of the 2. setting I2C_SLAVE
is no longer done (could that cause a problem with other devices on the same I2C buffer? I have no idea) and instead a read is performed directly with I2C_RDWR
, where 2 i2c messages are passed, the first a write with the smbus command / sub address and the second a read of the data there.
QUESTION
I am trying to realize DMA in Xilinx, using DMA Engine. FPGA guys give me an AXI DMA IP-Core with DMA support, so I need to write a driver, which will transfer data from kernel to user space buffer. Here you can find an example of the driver and app, which works so:
...ANSWER
Answered 2022-Jan-14 at 07:14You probably want to implement mmap
method of struct file_operations
. Consider:
QUESTION
The following program uses a PF_PACKET
socket to send a TCP SYN
packet to web server read from a file which is a list of web server IPv4 addresses - one address per line. The code is quite long because it takes a lot of code to obtain the gateway router MAC and IP address necessary for filling in the ethernet and IP headers. The good news is you can just skip all the functions in the preamble and just go to main which is where the problem is.
My program works perfectly for the first iteration of the while loop in main. Here is the output:
...ANSWER
Answered 2022-Jan-11 at 23:42If you are going to use PACKET_TX_RING
, then you must play by its rules: that means you can't use the same buffer spot over and over: you must advance to the next buffer location within the ring buffer: build the first packet in slot 0, the second in slot 1, etc. (wrapping when you get to the end of the buffer).
But you're building every packet in slot 0 (i.e. at ps_header_start
) but after sending the first packet, the kernel is expecting the next frame in the subsequent slot. It will never find the (second) packet you created in slot 0 until it has processed all the other slots. But it's looking at slot 1 and seeing that the tp_status
in that slot hasn't been set to TP_STATUS_SEND_REQUEST
yet so... nothing to do.
Note that your sendto
call is not providing a buffer address to the kernel. That's because the kernel knows where the next packet will come from, it must be in the next slot in the ring buffer following the one you just sent.
This is why I suggested in your other question that you not use PACKET_TX_RING
unless you really need it: it's more complicated to do correctly. It's much easier to just create your frame in a static buffer and call sendto(fd, buffer_address, buffer_len, ...)
. And if you are going to call sendto
for each created frame, there is literally no advantage to using PACKET_TX_RING
anyway.
QUESTION
Hello experts i am using InAppWebView plugin for loading web from the assets folder when i run it on debug mode its working fine when used release mode app show blank page any expert know this issue i am trying find there solution everywhere but no solution fine if any friend can help i will appreciate him?
...ANSWER
Answered 2021-Aug-25 at 19:34I face the same problem you may need to put network permission for android:
QUESTION
You have done it a thousand times: you unplug some USB equipment and any device associated with that USB equipment is removed by the driver. Any program that uses some previously opened file handle will get an error. Somehow most Linux drivers take care of that.
I am currently struggling to implement the same in a simple driver. My driver creates a character device. When the device is opened, I set the private_data
member of struct file
to the address of some management data that exists once per character device. That management data also includes a mutex that I use to synchronize operations like read
, write
, and ioctl
.
The problem now arises when the USB equipment is unplugged. I must not free the memory where that management data lives. First, any currently running read
, write
, or ioctl
should finish. Any such running call will likely also hold a lock on the mutex and will attempt to unlock it. So the memory where the mutex lives will be accessed.
Any read
, write
, or ioctl
call subsequent to unplugging the equipment should fail, so every such call must read some variable telling whether the USB equipment is still plugged in or not. Again, that variable must live somewhere and the memory where it lives must stay allocated as long as there are open file handles.
Long story short, it seems to me that I must do some sort reference counting: The management data must stay allocated until all file handles have been closed. I could implement that myself, but I have the feeling that I would reinvent the wheel. Such a thing must already exist, I'm not the first to have this problem.
Does Linux internally keep track of the number of open file handles? Can I define a callback that is called when all file handles have been closed? Is that even a viable thing? What is the proper way to remove a character device from the system?
Global variables shall not be avoided, since any number of USB devices can be attached.
...ANSWER
Answered 2021-Dec-16 at 22:10As suggested by 0andriy, I have used reference counting to track the number of open file handles. Per character device, I have added a new struct containing a mutex
, a kref
, the cdev
struct, and a pointer to further data. I use kref_get
to increase the reference counter when a new file handle is opened. Accordingly, I use kref_put
when file handles are released or the USB equipment is unplugged.
Since all I/O operations (read
, write
, ioctl
, etc.) use the mutex, I can safely change the pointer to NULL
when the USB equipment is unplugged. The I/O operations then start reporting errors.
The kref
reference counter only returns to zero when the USB equipment is unplugged and all file handles are closed. So then I can also free the memory of the new struct.
This seems to work. It was a surprise that the cdev
struct is referenced by file handles. It seems to be needed as long as there are open file handles.
But I'm still surprised that I had to go down this route. It seems redundant to implement that in every driver.
UPDATE: As it turns out, doing reference counting yourself is dangerous. In particular counting the number of open file handles is wrong. There is a whole reference-count-based garbage collection system in Linux and you need to use it.
For example, Linux calls cdev_get
when a process opens a character device and cdev_put
when the process exists and the file handle is still open. Unfortunately, the call to cdev_put
would occur after the file handle's release function. As we would free the memory after the last file handle has been released, we would end up freeing the underlying memory of the cdev
and the mutex
before cdev_put
is called.
The solution is to assign a parent to the cdev
via cdev_set_parent
. The parent kobject
will have its reference counter increased whenever cdev_get
is called and decreased after cdev_put
is called. The kobject then can have its own release function which frees any memory required by the cdev. Basically I replaced the kref in my struct with a kobject.
Lesson learned: don't do reference counting on your own. Use the existing hierarchy of kobject
s, which is the kernel's way of doing garbage collection.
UPDATE2: It turns out, we reinvented the wheel again. The device
struct includes a release hook, which is called when the internal kobject reached a reference count of zero. This is the mechanism typically used in the kernel to release resources associated with an device - including the device struct itself.
I was looking for a release hook in the cdev
struct. There was none. But it turns out I should have looked one step up in the hierarchy for such a hook.
Long story short: Use cdev_device_add
in combination with the device
release hook. cdev_device_add
will internally call cdev_set_parent
, so the device
becomes the parent of the cdev
. Those are the mechanism other kernel drivers (e.g. evdev) use to release their resources.
QUESTION
I'm trying to use C/C++ to communicate with a CAN bus. I'm using sockets to read and write on the bus. I've created a write thread and a read thread. The read thread is constantly trying to read and the socket, and when a write request arrives, the write thread take control of the socket using a mutex and do the write.
I'm having a big issue with speed using this method, as a write request can sometimes take 500 ms to be completed (which is completely unfeasible for my application). I've tried to put a timeout on the read command to make it non-blocking when nothing comes on the bus, but if the timeout is too short, I have reliability issues with the read. On the other hand, if I make it too long, the speed increase is insufficient.
It's my first time working with CAN. Would you have some advices on implementation of fast, two-way CAN communication node in C/C++ ? Which library should I use to interface with the bus itself ? Which architecture would yield the lowest read and write latency ?
To give a few metrics for the application, the bus bitrate is 1MBits/sec, I'm using CAN-Open with 64 bits data packets (each message contains 32 bits for indexes and 32 bits of data). I would like a write frequency from 300 to 500hz, same for the read frequency.
Thanks a lot for your help !
EDIT :
Thanks a lot for all your comments. Here are some clarifications on my application and problems.
I'm working on a mobile robot project, and I'm using CAN-Open to communicate with motor drivers and sensors. The code will run on a Raspberry Pi CM4 running Raspbian OS mounted on a custom IO board integrating a MCP2515 CAN controller. I want to implement fast communication interface between the ROS architecture and the CAN bus. The language used could be either C or C++.
I'm currently using a homemade interface build around standard C sockets, but the speed is very low, and is a big bottleneck to the robot's performance. So I'm looking for a better solution, either:
- An open-source library build for this purpose
- Architecture suggestion to implement such a program
- A combination of both
Here are the socket creation, the read and the write functions I use. Read and write being each called in a while loop in different threads (I'm using pthread):
...ANSWER
Answered 2021-Dec-16 at 10:55Thanks to all comments on the question, I was able to solve the speed issue. I was not aware that SocketCan supports multiple socket on the same bus. Being able to create per process sockets for read and write allowed to reduce talk to the bus in a distributed manner, greatly improving speed.
QUESTION
Thank you for watching this.
I'm having difficulties with my BBB on CAN communication like for months... I'd be really pleased if you could give me just a little help!
I'm working on CAN protocol between BBB and another CAN device. The another device is confirmed to be working alright with CAN. I'm using my BBB with Cloud9 platform on windows laptop, and on the another device, it's using CAN0.
I have set the 'config-pin' on BBB like below using CAN1, and I tried 'cansend' utility. The bitratre value on the another device is also set to be equal.
...ANSWER
Answered 2021-Aug-07 at 03:47Some help on can or socketCAN will be found here for the BBB or other family board:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install ioctl
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page