kernel-module

human readable timestamp in linux kernel

时间秒杀一切 提交于 2019-12-01 03:30:44
How can I write human readable timestamp in linux kernel? I think do_gettimeofday returns epoch but I don't want to try to convert it to readable time. I just want a format like Hour:Min:Sec:Msec . Thanks Fred Later kernels have a function time_to_tm to break epoch time into human readable format. Here's an example: struct timeval t; struct tm broken; do_gettimeofday(&t); time_to_tm(t.tv_sec, 0, &broken); printk("%d:%d:%d:%ld\n", broken.tm_hour, broken.tm_min, broken.tm_sec, t.tv_usec); Again, this is only available in later kernels. The second parameter time_to_tm is an offset to the epoch

error: implicit declaration of function 'create_proc_read_entry' [-Werror=implicit-function-declaration]

笑着哭i 提交于 2019-12-01 01:00:53
问题 I'm trying to compile a kernel module on kernel 3.13 and I get this error: error: implicit declaration of function 'create_proc_read_entry' [-Werror=implicit-function-declaration] I google it and did not found any response. Here is the part of the code which refers to this error: #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)) proc = proc_net_create(KAODV_QUEUE_PROC_FS_NAME, 0, kaodv_queue_get_info); #else proc = create_proc_read_entry(KAODV_QUEUE_PROC_FS_NAME, 0, init_net.proc_net, kaodv

Unable to understand working of read_proc in Linux kernel module

喜夏-厌秋 提交于 2019-12-01 00:18:32
I am reviewing the kernel module example at this page The read_proc used in the program is as follows: int fortune_read( char *page, char **start, off_t off, int count, int *eof, void *data ) { int len; if (off > 0) { *eof = 1; return 0; } /* Wrap-around */ if (next_fortune >= cookie_index) next_fortune = 0; len = sprintf(page, "%s\n", &cookie_pot[next_fortune]); next_fortune += len; return len; } Can someone explain why off is checked to be greater than 0. Moreover can someone explain what is the importance of the off and count arguments. My understanding so far is that we have to write data

Unable to understand working of read_proc in Linux kernel module

£可爱£侵袭症+ 提交于 2019-11-30 18:49:57
问题 I am reviewing the kernel module example at this page The read_proc used in the program is as follows: int fortune_read( char *page, char **start, off_t off, int count, int *eof, void *data ) { int len; if (off > 0) { *eof = 1; return 0; } /* Wrap-around */ if (next_fortune >= cookie_index) next_fortune = 0; len = sprintf(page, "%s\n", &cookie_pot[next_fortune]); next_fortune += len; return len; } Can someone explain why off is checked to be greater than 0. Moreover can someone explain what

Can't Unload Kernel Extension; Classes Have Instances

老子叫甜甜 提交于 2019-11-30 18:29:50
I'm writing an OSX kernel extension for an audio device driver (it's software, but emulates a hardware device). During development, it'd be convenient to completely uninstall existing old versions and then build and install the new version from scratch. However, this occasionally seems to not be possible without a system restart. The program itself is not running and the source files have been deleted from the /System/Library/Extensions/ dir. But kextstat reveals a single instance: $ kextstat | grep 'com.foo.driver.bar' 219 0 0xfff123 0x5000 0x5000 com.foo.driver.bar (0.0.1) <102 5 4 3> (..

Can kernel module take initiative to send message to user space with netlink?

你。 提交于 2019-11-30 16:00:50
问题 I am trying to run following code, which was copied from here. I have made few changes to run it with older kernel versions. When I insert kernel module, nlmsg_multicast() fails and logs as nlmsg_multicast() error: -3 in /var/log/messages . While running user space program, socket() fails. What exactly I want to do is, kernel module creates a socket, regardless of any process in user space kernel module send some events to user space If any process in user space reply to an event, kernel

Can kernel module take initiative to send message to user space with netlink?

有些话、适合烂在心里 提交于 2019-11-30 15:22:16
I am trying to run following code, which was copied from here . I have made few changes to run it with older kernel versions. When I insert kernel module, nlmsg_multicast() fails and logs as nlmsg_multicast() error: -3 in /var/log/messages . While running user space program, socket() fails. What exactly I want to do is, kernel module creates a socket, regardless of any process in user space kernel module send some events to user space If any process in user space reply to an event, kernel module process on that reply Since, It may happen that no process in user space available to reply on

Insert linux kernel module statically

不想你离开。 提交于 2019-11-30 14:44:54
问题 When building the Linux kernel from sources one could decide if a certain functionality is statically built into the kernel or packed into a module for dynamic insertion by .config. If on the other hand I have sources for any 3rd party module, like for example a packaged device driver, is it possible to programmatically integrate this code into the kernel statically instead? And not load the kernel module from the root filesystem? 回答1: Sure, you just need to do a bit of hacking to move the

insmod error: inserting './hello.ko': -1 Invalid module format\"

和自甴很熟 提交于 2019-11-30 12:39:50
I have just made my first driver module, the hello world module following LDD3. However unfortunately encountered this error: insmod: error inserting './hello.ko': -1 Invalid module format. I am doing this on Ubuntu 11.04, and my environment: $ uname -r 2.6.38-8-generic I get the kernel source like this: sudo apt-cache search linux-source linux-source - Linux kernel source with Ubuntu patches linux-source-2.6.38 - Linux kernel source for version 2.6.38 with Ubuntu patches $sudo apt-get install linux-source-2.6.38 my /usr/src: $ls /usr/src/ linux-headers-2.6.38-8 linux-source-2.6.38 vboxguest-5

How can I obtain battery level inside a Linux kernel module?

梦想与她 提交于 2019-11-30 11:50:15
I am trying to get the battery level inside a Linux kernel module (the module is inserted via modprobe). I would ideally like to use a kernel API call to get the battery information. I have searched on the web for solutions, and I have also explored Linux kernel source and the source of program "acpi" by Michael Meskes for ideas. These are some of the techniques I think I can use: Read and parse /proc/acpi/battery/BAT0/state and /proc/acpi/battery/BAT0/info Read from /sys/class/power_supply/BAT0/charge_now and charge_full with no parsing involved. I could try using the calls from Linux kernel