linux-kernel

Writing to a “application/octet-stream” file on linux

拜拜、爱过 提交于 2021-02-11 18:21:39
问题 I am working on application which should block some USB devices. I have found a way how could be blocking done. Problem is, as it's written here, that I need to write some string into /sys/bus/usb/drivers_probe file. Mentioned file is application/octet-stream and I can't find a way how to read or write to this file. I have tried vim , echo , hexdump with sudo or as root, but every time I get "Permission denied" or "No such device" message. I did not tried it in C/C++, which is my app using,

Writing to a “application/octet-stream” file on linux

試著忘記壹切 提交于 2021-02-11 18:21:20
问题 I am working on application which should block some USB devices. I have found a way how could be blocking done. Problem is, as it's written here, that I need to write some string into /sys/bus/usb/drivers_probe file. Mentioned file is application/octet-stream and I can't find a way how to read or write to this file. I have tried vim , echo , hexdump with sudo or as root, but every time I get "Permission denied" or "No such device" message. I did not tried it in C/C++, which is my app using,

Passing linked list via copy_from_user

若如初见. 提交于 2021-02-11 16:43:38
问题 I'm working on a linux project. I need to pass a linked list to the kernel from a userspace program. I have used the kernel way of implementing linked lists in userspace. I have defined a structure as follows: struct time{ int val; struct list_head* list; }; The variable for this strucure would be: struct time mylist; I have given the input data and used list_add function found in linux/include/list.h to link the structures. This mylist is a part of another structure: struct params{ int data1

Passing linked list via copy_from_user

人盡茶涼 提交于 2021-02-11 16:43:26
问题 I'm working on a linux project. I need to pass a linked list to the kernel from a userspace program. I have used the kernel way of implementing linked lists in userspace. I have defined a structure as follows: struct time{ int val; struct list_head* list; }; The variable for this strucure would be: struct time mylist; I have given the input data and used list_add function found in linux/include/list.h to link the structures. This mylist is a part of another structure: struct params{ int data1

Passing linked list via copy_from_user

自古美人都是妖i 提交于 2021-02-11 16:43:20
问题 I'm working on a linux project. I need to pass a linked list to the kernel from a userspace program. I have used the kernel way of implementing linked lists in userspace. I have defined a structure as follows: struct time{ int val; struct list_head* list; }; The variable for this strucure would be: struct time mylist; I have given the input data and used list_add function found in linux/include/list.h to link the structures. This mylist is a part of another structure: struct params{ int data1

Naming a variable `current` in a kernel module leads to “function declaration isn’t a prototype” error

删除回忆录丶 提交于 2021-02-11 15:01:33
问题 I'm learning to write kernel modules for linux as a beginner. What I'm trying to do is to write every task and its child process into the kernel log using DFS algorithm. But when I compile the code using Makefile , it shows the above error: function declaration isn’t a prototype [-Werror=strict-prototypes] struct task_struct *current; It points out the task_struct keyword at the function DFS. Here's my code: # include <linux/init.h> # include <linux/kernel.h> # include <linux/module.h> #

Get userspace RBP register from kernel syscall

孤者浪人 提交于 2021-02-11 15:01:31
问题 I am writing a kernel system call and I want to read the base pointer register (RBP) of the user. Maybe I can do that using the pt_regs struct that is passed for parameter, isn't it? Example code: unsigned long int data; asmlinkage int my_read(int d) { get_rbp_of_userStack(&data);#or somthing like that } I know this data saved somewhere for the context switch, how can I get to it? this is my user code void rar() {//rbp here should be rsp when it call so it basically the return addres of the

Can the data=journal mode of EXT4 avoid user data loss?

筅森魡賤 提交于 2021-02-11 14:25:20
问题 journal mode data=journal mode provides full data and metadata journaling. All new data is written to the journal first, and then to its final location. In the event of a crash, the journal can be replayed, bringing both data and metadata into a consistent state. This mode is the slowest except when data needs to be read from and written to disk at the same time where it outperforms all others modes. Enabling this mode will disable delayed allocation and O_DIRECT support. Here I have a few

Does asmlinkage mean stack or register?

别说谁变了你拦得住时间么 提交于 2021-02-11 12:32:00
问题 In most languages, C included the stack is used for function calls. That's why you get a "Stack Overflow" error if you are not careful in recursion. (Pun not intended). If that is true then what is so special about the asmlinkage GCC directive. It says, from #kernelnewbies The asmlinkage tag is one other thing that we should observe about this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in

How to extract entire packet from skb including ethernet header, ip, and tcp plus pay load in poll method of device driver

孤街浪徒 提交于 2021-02-11 12:10:03
问题 in r8169 driver from realtek it does rx_buf = page_address(tp->Rx_databuff[entry]); dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); prefetch(rx_buf); skb_copy_to_linear_data(skb, rx_buf, pkt_size);<----//Do I get packet at this???? skb->tail += pkt_size; skb->len = pkt_size; dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); //csum... skb->protocol = eth_type_trans(skb, dev); napi_gro_receive(&tp->napi, skb); this is inside rtl_rx function called from poll of driver.