Linux Kernel Module : Invalid output in the file for kernel_write function

165 Views Asked by At

I'm printing a sample string using kernel_write function and getting the output but I'm not sure about the format that it's printing in the file

Here is my code:

    char* res = "xyz";
    
    char* buffer = kmalloc(PAGE_SIZE, GFP_KERNEL);

    loff_t pos = 0;
    
    size_t resw;

    char* file i_fp = filp_open("input.txt",O_WRONLY | O_CREAT | O_APPEND, 0777);

    if (!IS_ERR(i_fp)) {
        resw = kernel_write(i_fp, (void *)buffer, strlen(res), &pos);
        printk("%ld",resw);
        printk("ff");
    }

output of the file

I want a sample string to be print in the output file

I'm getting the output in the file but the for each character it's showing '\00'. Is there some issue with my code?

Any suggestion is appreciated. Thanks in advance.

0

There are 0 best solutions below