LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/)
-   -   Open and write data to binary file in Kernel (https://www.linuxquestions.org/questions/linux-kernel-70/open-and-write-data-to-binary-file-in-kernel-4175667420/)

Ashok Selvaraj 01-10-2020 01:47 AM

Open and write data to binary file in Kernel
 
Hi All,

My Ask is to write data to a binary file in Kernel code.Is there any option in kernel to save data as binary file.

In userspace we have functions like fwrite() and fread() to operate on binary file, Similarly need some functions in kernel.

Used vfs_write() in order to store the data as hex. Similarly need function to store it as bin.

file = file_open(log_file, O_CREAT | O_BINARY | O_RDWR | O_APPEND, 00644);
vfs_write(file, data, size, &offset);

Used this O_BINARY option, but this doesn't help. Is there any other way to write it as binary data.?
Any help is much appreciated.

#linux #binary #vfs_write #O_BINARY

Thanks in Advance,
Ashok

phantom_cyph 01-10-2020 06:21 AM

Chances are if you're editing the kernel in this way.. you should stop and ask yourself.. "why?"..

That being said, you have not mentioned what your actual goal/use case is, the distribution of Linux or even the kernel/version you're attempting to do this with.

Should also mention that adding "binaries" to Linux .. anywhere.. generally won't be seen with much appeal.

Try and give more info and you might get some more replies.


All times are GMT -5. The time now is 09:45 PM.