Quantcast
Channel: Active questions tagged kernel - Stack Overflow
Viewing all articles
Browse latest Browse all 6334

Write data from kernel to file

$
0
0

I know that we should avoid writing into a file from the kernel. But out of curiosity, I'm still trying to write data but the kernel is crashing.

int file_write(char *filename, unsigned long long offset, unsigned char *data, unsigned int size)
{
    mm_segment_t oldfs;
    int ret;
    struct file *filp;

    oldfs = get_fs();
    set_fs(KERNEL_DS);

    filp = filp_open(filename, O_CREAT | O_RDWR, 0644);

    ret = vfs_write(filp, data, size, &offset);

    set_fs(oldfs);
    filp_close(filp,NULL);
    return ret;
}

vfs_write function restarting the system.


Viewing all articles
Browse latest Browse all 6334

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>