Comments on Reading Files From The Linux Kernel Space (Module/Driver) (Fedora 14)

Reading Files From The Linux Kernel Space (Module/Driver) (Fedora 14) It seems like operations that communicate with userspace are really discouraged. And I am not arguing with that. Although it doesn't mean that they cannot be accomplished. A driver loads configuration that could be stored only on HDD. When MS Windows XP boots up it remembers that I have turned Bluetooth off so it is not powered on, unlike even the latest Linux (Fedora 14 at the moment of writing) – such functionality in many drivers was not implemented. When developer uses procfs or character devices there should be another software or script in boot sequence that is actually sending information from a file to particular device. After some time looking over the internet I have managed to write such module that reads a file.

8 Comment(s)

Add comment

Please register in our forum first to comment.

Comments

By: Lawrence D'Oliveiro

The kernel should be small and support a basic core of general functionality, not be large and weighed down with features.

 A corollary of this is that the kernel should not implement policy, but only mechanisms to allow userland to implement policy.

An example of mechanism is userland being able to enable or disable the kernel Bluetooth driver. An example of policy is that the state at shutdown should be saved and restored on boot.

By: veena hosur

hi...i want to read file in kernel mode.i am using f->f_op->read (above code)to read the file.but its reading till size of buffer but i want to read till end of file.please tell me to read till end of file

By: Marvin

thanks , it worked perfectly to me.

By: eyal yehuda

there is an issue with checking

f = filp_open("/etc/fedora-release", O_RDONLY, 0); if(f == NULL)it is totaly incorrect it should be replaces with f = filp_open("/etc/fedora-release", O_RDONLY, 0); if (IS_ERR(f)) continue; Thanks Eyal Yehuda

By: Mike Ruano

Thank you so much... it worked..

By: sasna

I tried the same on fedora 24.But i am getting an error ./arch/x86/include/asm/uaccess.h:error:dereferencing pointer to type 'struct task-struct' .Where will have gone wrong? Could someone please help me out

By: sasna

THe erropr was fixed by changing the header file to <linux/uaccess.h> but when i tried to insmod, it displays "killed" what i sthe reason for that?

By: dikra

dont work